diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-12-11 16:18:30 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-12-23 11:40:22 +0000 |
commit | 22d0c4da7085610136939ffe82bb3877a4fd8d5b (patch) | |
tree | f45d267c37796e83c73449fa4708e219e193bb16 | |
parent | 1a313dc9bff109d155e35bac79c475ea65198aea (diff) | |
download | rockbox-22d0c4da7085610136939ffe82bb3877a4fd8d5b.tar.gz rockbox-22d0c4da7085610136939ffe82bb3877a4fd8d5b.zip |
Revert "powermgmt: Remove an unnecessary function"
This reverts commit 6ff1a935b923b69d34d18e68af612297912c806b.
Reason: it created a mismatch between the displayed voltage
and percent since the voltage was unfiltered but percentage
was based off the filtered voltage.
Change-Id: I4cba099f2e1edf0ef7c4e17a32f566aa66f5b933
-rw-r--r-- | apps/debug_menu.c | 11 | ||||
-rw-r--r-- | firmware/export/powermgmt.h | 4 | ||||
-rw-r--r-- | firmware/powermgmt.c | 18 | ||||
-rw-r--r-- | firmware/target/coldfire/debug-coldfire.c | 5 |
4 files changed, 29 insertions, 9 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index b11458fef8..3a9218bc84 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -849,7 +849,7 @@ static bool tsc2100_debug(void) | |||
849 | static bool view_battery(void) | 849 | static bool view_battery(void) |
850 | { | 850 | { |
851 | int view = 0; | 851 | int view = 0; |
852 | int i, x, y, y1, y2, grid, graph; | 852 | int i, x, y, z, y1, y2, grid, graph; |
853 | unsigned short maxv, minv; | 853 | unsigned short maxv, minv; |
854 | 854 | ||
855 | lcd_setfont(FONT_SYSFIXED); | 855 | lcd_setfont(FONT_SYSFIXED); |
@@ -944,12 +944,11 @@ static bool view_battery(void) | |||
944 | #else | 944 | #else |
945 | lcd_puts(0, 0, "Power status: unknown"); | 945 | lcd_puts(0, 0, "Power status: unknown"); |
946 | #endif | 946 | #endif |
947 | 947 | battery_read_info(&y, &z); | |
948 | y = _battery_voltage(); | ||
949 | if (y > 0) | 948 | if (y > 0) |
950 | lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, battery_level()); | 949 | lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, z); |
951 | else | 950 | else if (z > 0) |
952 | lcd_putsf(0, 1, "Battery: %d %%", _battery_level()); | 951 | lcd_putsf(0, 1, "Battery: %d %%", z); |
953 | #ifdef ADC_EXT_POWER | 952 | #ifdef ADC_EXT_POWER |
954 | y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000; | 953 | y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000; |
955 | lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000); | 954 | lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000); |
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h index 9d4d4e06aa..77177e61af 100644 --- a/firmware/export/powermgmt.h +++ b/firmware/export/powermgmt.h | |||
@@ -143,6 +143,10 @@ unsigned int input_millivolts(void); /* voltage that device is running from */ | |||
143 | void reset_battery_filter(int millivolts); | 143 | void reset_battery_filter(int millivolts); |
144 | #endif /* HAVE_BATTERY_SWITCH || HAVE_RESET_BATTERY_FILTER */ | 144 | #endif /* HAVE_BATTERY_SWITCH || HAVE_RESET_BATTERY_FILTER */ |
145 | 145 | ||
146 | |||
147 | /* read unfiltered battery info */ | ||
148 | void battery_read_info(int *voltage, int *level); | ||
149 | |||
146 | /* Tells if the battery level is safe for disk writes */ | 150 | /* Tells if the battery level is safe for disk writes */ |
147 | bool battery_level_safe(void); | 151 | bool battery_level_safe(void); |
148 | 152 | ||
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 30d37927ca..55da2a5a44 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -392,6 +392,24 @@ static void battery_status_update(void) | |||
392 | send_battery_level_event(level); | 392 | send_battery_level_event(level); |
393 | } | 393 | } |
394 | 394 | ||
395 | void battery_read_info(int *voltage, int *level) | ||
396 | { | ||
397 | int millivolts = _battery_voltage(); | ||
398 | |||
399 | if (voltage) | ||
400 | *voltage = millivolts; | ||
401 | |||
402 | if (level) { | ||
403 | #if (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE) | ||
404 | *level = _battery_level(); | ||
405 | #elif (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE) | ||
406 | *level = voltage_to_battery_level(millivolts); | ||
407 | #else | ||
408 | *level = -1; | ||
409 | #endif | ||
410 | } | ||
411 | } | ||
412 | |||
395 | #if BATTERY_TYPES_COUNT > 1 | 413 | #if BATTERY_TYPES_COUNT > 1 |
396 | void set_battery_type(int type) | 414 | void set_battery_type(int type) |
397 | { | 415 | { |
diff --git a/firmware/target/coldfire/debug-coldfire.c b/firmware/target/coldfire/debug-coldfire.c index 56f1bbe1a7..ef44a82176 100644 --- a/firmware/target/coldfire/debug-coldfire.c +++ b/firmware/target/coldfire/debug-coldfire.c | |||
@@ -144,7 +144,7 @@ bool dbg_ports(void) | |||
144 | 144 | ||
145 | adc_buttons = adc_read(ADC_BUTTONS); | 145 | adc_buttons = adc_read(ADC_BUTTONS); |
146 | adc_remote = adc_read(ADC_REMOTE); | 146 | adc_remote = adc_read(ADC_REMOTE); |
147 | 147 | battery_read_info(&adc_battery_voltage, &adc_battery_level); | |
148 | #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES) | 148 | #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES) |
149 | lcd_putsf(0, line++, "ADC_BUTTONS (%c): %02x", | 149 | lcd_putsf(0, line++, "ADC_BUTTONS (%c): %02x", |
150 | button_scan_enabled() ? '+' : '-', adc_buttons); | 150 | button_scan_enabled() ? '+' : '-', adc_buttons); |
@@ -162,8 +162,7 @@ bool dbg_ports(void) | |||
162 | adc_read(ADC_REMOTEDETECT)); | 162 | adc_read(ADC_REMOTEDETECT)); |
163 | #endif | 163 | #endif |
164 | 164 | ||
165 | adc_battery_voltage = _battery_voltage(); | 165 | battery_read_info(&adc_battery_voltage, &adc_battery_level); |
166 | adc_battery_level = battery_level(); | ||
167 | lcd_putsf(0, line++, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000, | 166 | lcd_putsf(0, line++, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000, |
168 | adc_battery_voltage % 1000, adc_battery_level); | 167 | adc_battery_voltage % 1000, adc_battery_level); |
169 | 168 | ||