Revert "powermgmt: Remove an unnecessary function"

This reverts commit 6ff1a935b9.

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
This commit is contained in:
Aidan MacDonald 2021-12-11 16:18:30 +00:00
parent 1a313dc9bf
commit 22d0c4da70
4 changed files with 29 additions and 9 deletions

View file

@ -849,7 +849,7 @@ static bool tsc2100_debug(void)
static bool view_battery(void)
{
int view = 0;
int i, x, y, y1, y2, grid, graph;
int i, x, y, z, y1, y2, grid, graph;
unsigned short maxv, minv;
lcd_setfont(FONT_SYSFIXED);
@ -944,12 +944,11 @@ static bool view_battery(void)
#else
lcd_puts(0, 0, "Power status: unknown");
#endif
y = _battery_voltage();
battery_read_info(&y, &z);
if (y > 0)
lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, battery_level());
else
lcd_putsf(0, 1, "Battery: %d %%", _battery_level());
lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, z);
else if (z > 0)
lcd_putsf(0, 1, "Battery: %d %%", z);
#ifdef ADC_EXT_POWER
y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);

View file

@ -143,6 +143,10 @@ unsigned int input_millivolts(void); /* voltage that device is running from */
void reset_battery_filter(int millivolts);
#endif /* HAVE_BATTERY_SWITCH || HAVE_RESET_BATTERY_FILTER */
/* read unfiltered battery info */
void battery_read_info(int *voltage, int *level);
/* Tells if the battery level is safe for disk writes */
bool battery_level_safe(void);

View file

@ -392,6 +392,24 @@ static void battery_status_update(void)
send_battery_level_event(level);
}
void battery_read_info(int *voltage, int *level)
{
int millivolts = _battery_voltage();
if (voltage)
*voltage = millivolts;
if (level) {
#if (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
*level = _battery_level();
#elif (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
*level = voltage_to_battery_level(millivolts);
#else
*level = -1;
#endif
}
}
#if BATTERY_TYPES_COUNT > 1
void set_battery_type(int type)
{

View file

@ -144,7 +144,7 @@ bool dbg_ports(void)
adc_buttons = adc_read(ADC_BUTTONS);
adc_remote = adc_read(ADC_REMOTE);
battery_read_info(&adc_battery_voltage, &adc_battery_level);
#if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
lcd_putsf(0, line++, "ADC_BUTTONS (%c): %02x",
button_scan_enabled() ? '+' : '-', adc_buttons);
@ -162,8 +162,7 @@ bool dbg_ports(void)
adc_read(ADC_REMOTEDETECT));
#endif
adc_battery_voltage = _battery_voltage();
adc_battery_level = battery_level();
battery_read_info(&adc_battery_voltage, &adc_battery_level);
lcd_putsf(0, line++, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
adc_battery_voltage % 1000, adc_battery_level);