Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

hosted: consolidate sysfs-based battery measurement code

Several hosted targets read their battery state from a fixed
sysfs path. Get rid of the duplicated code by handling this
common case in power-linux.c.

Some targets use non-standard units in sysfs instead of the
typical microvolts / microamps, so allow the scale factors
to be overridden by the target.

Change-Id: I31dc4ffc7a2d2c066d00a74070f9f9849c1663d0

+74 -454
-5
firmware/SOURCES
··· 153 153 #if defined(AGPTEK_ROCKER) && !defined(SIMULATOR) 154 154 target/hosted/agptek/button-agptek.c 155 155 target/hosted/agptek/debug-agptek.c 156 - target/hosted/agptek/power-agptek.c 157 156 target/hosted/agptek/powermgmt-agptek.c 158 157 #endif 159 158 160 159 #if defined(SURFANS_F28) && !defined(SIMULATOR) 161 160 target/hosted/surfans/button-f28.c 162 161 target/hosted/surfans/debug-f28.c 163 - target/hosted/surfans/power-f28.c 164 162 target/hosted/surfans/powermgmt-f28.c 165 163 #endif 166 164 167 165 #if (defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(SIMULATOR) 168 166 target/hosted/xduoo/button-xduoo.c 169 167 target/hosted/xduoo/debug-xduoo.c 170 - target/hosted/xduoo/power-xduoo.c 171 168 target/hosted/xduoo/powermgmt-xduoo.c 172 169 #endif 173 170 ··· 180 177 target/hosted/fiio/buttonlight-fiio.c 181 178 target/hosted/fiio/button-fiio.c 182 179 target/hosted/fiio/debug-fiio.c 183 - target/hosted/fiio/power-fiio.c 184 180 target/hosted/fiio/powermgmt-fiio.c 185 181 target/hosted/fiio/system-fiio.c 186 182 target/hosted/fiio/usb-fiio.c ··· 233 229 target/hosted/power-linux.c 234 230 target/hosted/backlight-unix.c 235 231 target/hosted/anbernic/instant_play.c 236 - target/hosted/anbernic/power-rgnano.c 237 232 target/hosted/anbernic/button-rgnano.c 238 233 target/hosted/anbernic/powermgmt-rgnano.c 239 234 #endif /* RG_NANO */
+8
firmware/export/config/fiiom3klinux.h
··· 125 125 #define BATTERY_CAPACITY_MAX 1100 /* max. capacity selectable */ 126 126 #define BATTERY_CAPACITY_INC 0 /* capacity increment */ 127 127 128 + /* Voltage reported in millivolts */ 129 + #define BATTERY_VOLTAGE_SCALE_MUL 1 130 + #define BATTERY_VOLTAGE_SCALE_DIV 1 131 + 132 + /* Capacity reported as a value 0-5, 20% increments */ 133 + #define BATTERY_LEVEL_SCALE_MUL 20 134 + #define BATTERY_LEVEL_SCALE_DIV 1 135 + 128 136 /* ROLO */ 129 137 #define BOOTFILE_EXT "m3k" 130 138 #define BOOTFILE "rockbox." BOOTFILE_EXT
+4
firmware/export/config/rgnano.h
··· 70 70 #define BATTERY_CAPACITY_MAX 1050 /* max. capacity selectable */ 71 71 #define BATTERY_CAPACITY_INC 0 /* capacity increment */ 72 72 73 + /* Voltage reported in millivolts */ 74 + #define BATTERY_VOLTAGE_SCALE_MUL 1 75 + #define BATTERY_VOLTAGE_SCALE_DIV 1 76 + 73 77 /* Define this for LCD backlight available */ 74 78 #define BACKLIGHT_RG_NANO 75 79 #define HAVE_BACKLIGHT
-41
firmware/target/hosted/agptek/power-agptek.c
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2017 by Marcin Bukat 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #include <sys/types.h> 21 - #include <fcntl.h> 22 - #include <string.h> 23 - #include <unistd.h> 24 - #include <stdio.h> 25 - 26 - #include "system.h" 27 - #include "power-agptek.h" 28 - #include "power.h" 29 - #include "panic.h" 30 - #include "sysfs.h" 31 - 32 - const char * const sysfs_bat_voltage = 33 - "/sys/class/power_supply/battery/voltage_now"; 34 - 35 - unsigned int agptek_power_get_battery_voltage(void) 36 - { 37 - int battery_voltage; 38 - sysfs_get_int(sysfs_bat_voltage, &battery_voltage); 39 - 40 - return battery_voltage/1000; 41 - }
-27
firmware/target/hosted/agptek/power-agptek.h
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2017 by Marcin Bukat 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #ifndef _POWER_AGPTEK_H_ 21 - #define _POWER_AGPTEK_H_ 22 - 23 - #include <stdbool.h> 24 - #include "config.h" 25 - 26 - unsigned int agptek_power_get_battery_voltage(void); 27 - #endif /* _POWER_AGPTEK_H_ */
-6
firmware/target/hosted/agptek/powermgmt-agptek.c
··· 19 19 ****************************************************************************/ 20 20 #include "powermgmt.h" 21 21 #include "power.h" 22 - #include "power-agptek.h" 23 22 24 23 unsigned short battery_level_disksafe = 3470; 25 24 ··· 37 36 { 38 37 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 39 38 }; 40 - 41 - int _battery_voltage(void) 42 - { 43 - return agptek_power_get_battery_voltage(); 44 - }
-64
firmware/target/hosted/anbernic/power-rgnano.c
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2025 Hairo R. Carela 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #include <sys/types.h> 21 - #include <fcntl.h> 22 - #include <string.h> 23 - #include <unistd.h> 24 - #include <stdio.h> 25 - 26 - #include "system.h" 27 - #include "power-rgnano.h" 28 - #include "power.h" 29 - #include "panic.h" 30 - #include "sysfs.h" 31 - 32 - const char * const sysfs_bat_voltage = 33 - "/sys/class/power_supply/axp20x-battery/voltage_now"; 34 - 35 - const char * const sysfs_bat_current = 36 - "/sys/class/power_supply/axp20x-battery/current_now"; 37 - 38 - const char * const sysfs_bat_level = 39 - "/sys/class/power_supply/axp20x-battery/capacity"; 40 - 41 - unsigned int rgnano_power_get_battery_voltage(void) 42 - { 43 - int battery_voltage; 44 - sysfs_get_int(sysfs_bat_voltage, &battery_voltage); 45 - 46 - return battery_voltage; 47 - } 48 - 49 - unsigned int rgnano_power_get_battery_current(void) 50 - { 51 - int battery_current; 52 - sysfs_get_int(sysfs_bat_current, &battery_current); 53 - 54 - /* Current is in microamps */ 55 - return (battery_current / 1000); 56 - } 57 - 58 - unsigned int rgnano_power_get_battery_capacity(void) 59 - { 60 - int battery_level; 61 - sysfs_get_int(sysfs_bat_level, &battery_level); 62 - 63 - return battery_level; 64 - }
-29
firmware/target/hosted/anbernic/power-rgnano.h
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2025 Hairo R. Carela 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #ifndef _POWER_RGNANO_H_ 21 - #define _POWER_RGNANO_H_ 22 - 23 - #include <stdbool.h> 24 - #include "config.h" 25 - 26 - unsigned int rgnano_power_get_battery_voltage(void); 27 - unsigned int rgnano_power_get_battery_current(void); 28 - unsigned int rgnano_power_get_battery_capacity(void); 29 - #endif /* _POWER_RGNANO_H_ */
-16
firmware/target/hosted/anbernic/powermgmt-rgnano.c
··· 20 20 ****************************************************************************/ 21 21 #include "powermgmt.h" 22 22 #include "power.h" 23 - #include "power-rgnano.h" 24 23 25 24 /* System handles powering off at 2% */ 26 25 unsigned short battery_level_disksafe = 0; ··· 39 38 { 40 39 3512, 3729, 3795, 3831, 3865, 3906, 3953, 4010, 4072, 4150, 4186 41 40 }; 42 - 43 - int _battery_voltage(void) 44 - { 45 - return rgnano_power_get_battery_voltage(); 46 - } 47 - 48 - int _battery_current(void) 49 - { 50 - return rgnano_power_get_battery_current(); 51 - } 52 - 53 - int _battery_level(void) 54 - { 55 - return rgnano_power_get_battery_capacity(); 56 - }
-54
firmware/target/hosted/fiio/power-fiio.c
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2017 by Marcin Bukat 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #include <sys/types.h> 21 - #include <fcntl.h> 22 - #include <string.h> 23 - #include <unistd.h> 24 - #include <stdio.h> 25 - 26 - #include "system.h" 27 - #include "power.h" 28 - #include "panic.h" 29 - #include "sysfs.h" 30 - #include "usb.h" 31 - 32 - #include "power-fiio.h" 33 - 34 - const char * const sysfs_bat_voltage = 35 - "/sys/class/power_supply/battery/voltage_now"; 36 - 37 - const char * const sysfs_bat_capacity = 38 - "/sys/class/power_supply/battery/capacity"; 39 - 40 - unsigned int fiio_power_get_battery_voltage(void) 41 - { 42 - int battery_voltage; 43 - sysfs_get_int(sysfs_bat_voltage, &battery_voltage); 44 - 45 - return battery_voltage; 46 - } 47 - 48 - unsigned int fiio_power_get_battery_capacity(void) 49 - { 50 - int battery_capacity; 51 - sysfs_get_int(sysfs_bat_capacity, &battery_capacity); 52 - 53 - return battery_capacity * 20; 54 - }
-28
firmware/target/hosted/fiio/power-fiio.h
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2017 by Marcin Bukat 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #ifndef _POWER_FIIO_H_ 21 - #define _POWER_FIIO_H_ 22 - 23 - #include <stdbool.h> 24 - #include "config.h" 25 - 26 - unsigned int fiio_power_get_battery_voltage(void); 27 - unsigned int fiio_power_get_battery_capacity(void); 28 - #endif /* _POWER_FIIO_H_ */
-13
firmware/target/hosted/fiio/powermgmt-fiio.c
··· 19 19 ****************************************************************************/ 20 20 #include "powermgmt.h" 21 21 #include "power.h" 22 - #include "power-fiio.h" 23 22 24 23 unsigned short battery_level_disksafe = 3470; 25 24 ··· 37 36 { 38 37 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 39 38 }; 40 - 41 - int _battery_voltage(void) 42 - { 43 - return fiio_power_get_battery_voltage(); 44 - } 45 - 46 - #if 0 47 - int _battery_level(void) 48 - { 49 - return fiio_power_get_battery_capacity(); 50 - } 51 - #endif
-1
firmware/target/hosted/fiio/usb-fiio.c
··· 26 26 #include "usb.h" 27 27 #include "sysfs.h" 28 28 #include "power.h" 29 - #include "power-fiio.h" 30 29 31 30 #ifdef HAVE_MULTIDRIVE 32 31 void cleanup_rbhome(void);
+62 -1
firmware/target/hosted/power-linux.c
··· 34 34 #endif 35 35 36 36 #ifdef BATTERY_DEV_NAME 37 - #define BATTERY_STATUS_PATH "/sys/class/power_supply/" BATTERY_DEV_NAME "/status" 37 + # define BATTERY_SYSFS_PATH "/sys/class/power_supply/" BATTERY_DEV_NAME 38 + # define BATTERY_STATUS_PATH BATTERY_SYSFS_PATH "/status" 39 + # define BATTERY_VOLTAGE_PATH BATTERY_SYSFS_PATH "/voltage_now" 40 + # define BATTERY_CURRENT_PATH BATTERY_SYSFS_PATH "/current_now" 41 + # define BATTERY_LEVEL_PATH BATTERY_SYSFS_PATH "/capacity" 42 + #endif 43 + 44 + /* Voltage is normally in microvolts */ 45 + #ifndef BATTERY_VOLTAGE_SCALE_MUL 46 + # define BATTERY_VOLTAGE_SCALE_MUL 1 47 + #endif 48 + 49 + #ifndef BATTERY_VOLTAGE_SCALE_DIV 50 + # define BATTERY_VOLTAGE_SCALE_DIV 1000 51 + #endif 52 + 53 + /* Current is normally in microamps */ 54 + #ifndef BATTERY_CURRENT_SCALE_MUL 55 + # define BATTERY_CURRENT_SCALE_MUL 1 56 + #endif 57 + 58 + #ifndef BATTERY_CURRENT_SCALE_DIV 59 + # define BATTERY_CURRENT_SCALE_DIV 1000 60 + #endif 61 + 62 + /* Level is normally in whole percentage points (0-100) */ 63 + #ifndef BATTERY_LEVEL_SCALE_MUL 64 + # define BATTERY_LEVEL_SCALE_MUL 1 65 + #endif 66 + 67 + #ifndef BATTERY_LEVEL_SCALE_DIV 68 + # define BATTERY_LEVEL_SCALE_DIV 1 38 69 #endif 39 70 40 71 #define POWER_STATUS_PATH "/sys/class/power_supply/" POWER_DEV_NAME "/online" ··· 55 86 } 56 87 return last_power; 57 88 } 89 + 90 + #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE) 91 + int _battery_voltage(void) 92 + { 93 + int voltage = 0; 94 + sysfs_get_int(BATTERY_VOLTAGE_PATH, &voltage); 95 + 96 + return (voltage * BATTERY_VOLTAGE_SCALE_MUL) / BATTERY_VOLTAGE_SCALE_DIV; 97 + } 98 + #endif 99 + 100 + #if (CONFIG_BATTERY_MEASURE & CURRENT_MEASURE) 101 + int _battery_current(void) 102 + { 103 + int current = 0; 104 + sysfs_get_int(BATTERY_CURRENT_PATH, &current); 105 + 106 + return (current * BATTERY_CURRENT_SCALE_MUL) / BATTERY_CURRENT_SCALE_DIV; 107 + } 108 + #endif 109 + 110 + #if (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE) 111 + int _battery_level(void) 112 + { 113 + int level = 0; 114 + sysfs_get_int(BATTERY_LEVEL_PATH, &level); 115 + 116 + return (level * BATTERY_LEVEL_SCALE_MUL) / BATTERY_LEVEL_SCALE_DIV; 117 + } 118 + #endif 58 119 #endif 59 120 60 121 unsigned int power_input_status(void)
-41
firmware/target/hosted/surfans/power-f28.c
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2017 by Marcin Bukat 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #include <sys/types.h> 21 - #include <fcntl.h> 22 - #include <string.h> 23 - #include <unistd.h> 24 - #include <stdio.h> 25 - 26 - #include "system.h" 27 - #include "power-f28.h" 28 - #include "power.h" 29 - #include "panic.h" 30 - #include "sysfs.h" 31 - 32 - const char * const sysfs_bat_voltage = 33 - "/sys/class/power_supply/battery/voltage_now"; 34 - 35 - unsigned int f28_power_get_battery_voltage(void) 36 - { 37 - int battery_voltage; 38 - sysfs_get_int(sysfs_bat_voltage, &battery_voltage); 39 - 40 - return battery_voltage/1000; 41 - }
-27
firmware/target/hosted/surfans/power-f28.h
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2017 by Marcin Bukat 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #ifndef _POWER_F28_H_ 21 - #define _POWER_F28_H_ 22 - 23 - #include <stdbool.h> 24 - #include "config.h" 25 - 26 - unsigned int f28_power_get_battery_voltage(void); 27 - #endif /* _POWER_F28_H_ */
-6
firmware/target/hosted/surfans/powermgmt-f28.c
··· 19 19 ****************************************************************************/ 20 20 #include "powermgmt.h" 21 21 #include "power.h" 22 - #include "power-f28.h" 23 22 24 23 // XXX all of this... blabla 25 24 // max voltage is 4360 apparently ··· 40 39 { 41 40 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 42 41 }; 43 - 44 - int _battery_voltage(void) 45 - { 46 - return f28_power_get_battery_voltage(); 47 - }
-52
firmware/target/hosted/xduoo/power-xduoo.c
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2017 by Marcin Bukat 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #include <sys/types.h> 21 - #include <fcntl.h> 22 - #include <string.h> 23 - #include <unistd.h> 24 - #include <stdio.h> 25 - 26 - #include "system.h" 27 - #include "power-xduoo.h" 28 - #include "power.h" 29 - #include "panic.h" 30 - #include "sysfs.h" 31 - 32 - const char * const sysfs_bat_voltage = 33 - "/sys/class/power_supply/battery/voltage_now"; 34 - 35 - const char * const sysfs_bat_capacity = 36 - "/sys/class/power_supply/battery/capacity"; 37 - 38 - unsigned int xduoo_power_get_battery_voltage(void) 39 - { 40 - int battery_voltage; 41 - sysfs_get_int(sysfs_bat_voltage, &battery_voltage); 42 - 43 - return battery_voltage/1000; 44 - } 45 - 46 - unsigned int xduoo_power_get_battery_capacity(void) 47 - { 48 - int battery_capacity; 49 - sysfs_get_int(sysfs_bat_capacity, &battery_capacity); 50 - 51 - return battery_capacity; 52 - }
-28
firmware/target/hosted/xduoo/power-xduoo.h
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * 9 - * Copyright (C) 2017 by Marcin Bukat 10 - * 11 - * This program is free software; you can redistribute it and/or 12 - * modify it under the terms of the GNU General Public License 13 - * as published by the Free Software Foundation; either version 2 14 - * of the License, or (at your option) any later version. 15 - * 16 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 - * KIND, either express or implied. 18 - * 19 - ****************************************************************************/ 20 - #ifndef _POWER_XDUOO_H_ 21 - #define _POWER_XDUOO_H_ 22 - 23 - #include <stdbool.h> 24 - #include "config.h" 25 - 26 - unsigned int xduoo_power_get_battery_voltage(void); 27 - unsigned int xduoo_power_get_battery_capacity(void); 28 - #endif /* _POWER_XDUOO_H_ */
-15
firmware/target/hosted/xduoo/powermgmt-xduoo.c
··· 19 19 ****************************************************************************/ 20 20 #include "powermgmt.h" 21 21 #include "power.h" 22 - #include "power-xduoo.h" 23 22 24 23 unsigned short battery_level_disksafe = 3443; /* 5% */ 25 24 ··· 37 36 { 38 37 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 39 38 }; 40 - 41 - #if defined(XDUOO_X3II) 42 - int _battery_voltage(void) 43 - { 44 - return xduoo_power_get_battery_voltage(); 45 - } 46 - #endif 47 - 48 - #if defined(XDUOO_X20) 49 - int _battery_level(void) 50 - { 51 - return xduoo_power_get_battery_capacity(); 52 - } 53 - #endif