diff options
-rw-r--r-- | firmware/export/config/ibassodx50.h | 2 | ||||
-rw-r--r-- | firmware/export/config/ibassodx90.h | 2 | ||||
-rw-r--r-- | firmware/target/hosted/android/dx50/powermgmt-dx50.c | 31 |
3 files changed, 30 insertions, 5 deletions
diff --git a/firmware/export/config/ibassodx50.h b/firmware/export/config/ibassodx50.h index 652377cc6c..5bbb515c1c 100644 --- a/firmware/export/config/ibassodx50.h +++ b/firmware/export/config/ibassodx50.h | |||
@@ -99,7 +99,7 @@ | |||
99 | 99 | ||
100 | #define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE | 100 | #define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE |
101 | 101 | ||
102 | #define CONFIG_CHARGING CHARGING_SIMPLE | 102 | #define CONFIG_CHARGING CHARGING_MONITOR |
103 | 103 | ||
104 | #define NO_LOW_BATTERY_SHUTDOWN | 104 | #define NO_LOW_BATTERY_SHUTDOWN |
105 | 105 | ||
diff --git a/firmware/export/config/ibassodx90.h b/firmware/export/config/ibassodx90.h index d560f3e10b..68a728eab4 100644 --- a/firmware/export/config/ibassodx90.h +++ b/firmware/export/config/ibassodx90.h | |||
@@ -99,7 +99,7 @@ | |||
99 | 99 | ||
100 | #define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE | 100 | #define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE |
101 | 101 | ||
102 | #define CONFIG_CHARGING CHARGING_SIMPLE | 102 | #define CONFIG_CHARGING CHARGING_MONITOR |
103 | 103 | ||
104 | #define NO_LOW_BATTERY_SHUTDOWN | 104 | #define NO_LOW_BATTERY_SHUTDOWN |
105 | 105 | ||
diff --git a/firmware/target/hosted/android/dx50/powermgmt-dx50.c b/firmware/target/hosted/android/dx50/powermgmt-dx50.c index 45756cb8e8..713e8a977e 100644 --- a/firmware/target/hosted/android/dx50/powermgmt-dx50.c +++ b/firmware/target/hosted/android/dx50/powermgmt-dx50.c | |||
@@ -21,10 +21,12 @@ | |||
21 | 21 | ||
22 | #include <stdbool.h> | 22 | #include <stdbool.h> |
23 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | #include <stdlib.h> | ||
24 | #include "config.h" | 25 | #include "config.h" |
25 | #include "power.h" | 26 | #include "power.h" |
26 | #include "powermgmt.h" | 27 | #include "powermgmt.h" |
27 | 28 | ||
29 | |||
28 | unsigned int power_input_status(void) | 30 | unsigned int power_input_status(void) |
29 | { | 31 | { |
30 | int val; | 32 | int val; |
@@ -34,8 +36,31 @@ unsigned int power_input_status(void) | |||
34 | return val?POWER_INPUT_MAIN_CHARGER:POWER_INPUT_NONE; | 36 | return val?POWER_INPUT_MAIN_CHARGER:POWER_INPUT_NONE; |
35 | } | 37 | } |
36 | 38 | ||
37 | /* Values for stock PISEN battery. TODO: Needs optimization */ | ||
38 | 39 | ||
40 | /* Returns true, if battery is charging, false else. */ | ||
41 | bool charging_state( void ) | ||
42 | { | ||
43 | /* Full, Charging, Discharging */ | ||
44 | char state[9]; | ||
45 | |||
46 | /* true if charging. */ | ||
47 | bool charging = false; | ||
48 | |||
49 | FILE *f = fopen( "/sys/class/power_supply/battery/status", "r" ); | ||
50 | if( f != NULL ) | ||
51 | { | ||
52 | if( fgets( state, 9, f ) != NULL ) | ||
53 | { | ||
54 | charging = ( strcmp( state, "Charging" ) == 0 ); | ||
55 | } | ||
56 | } | ||
57 | fclose( f ); | ||
58 | |||
59 | return charging; | ||
60 | } | ||
61 | |||
62 | |||
63 | /* Values for stock PISEN battery. TODO: Needs optimization */ | ||
39 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | 64 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = |
40 | { | 65 | { |
41 | 3380 | 66 | 3380 |
@@ -52,10 +77,10 @@ const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | |||
52 | { 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4090, 4190 } | 77 | { 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4090, 4190 } |
53 | }; | 78 | }; |
54 | 79 | ||
55 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | 80 | /* Voltages (millivolt) of 0%, 10%, ... 100% when charging is enabled. */ |
56 | const unsigned short percent_to_volt_charge[11] = | 81 | const unsigned short percent_to_volt_charge[11] = |
57 | { | 82 | { |
58 | 3540, 3860, 3930, 3980, 4000, 4020, 4040, 4080, 4130, 4180, 4220 /* LiPo */ | 83 | 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4090, 4190 |
59 | }; | 84 | }; |
60 | 85 | ||
61 | 86 | ||