mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-05 06:21:53 +00:00
battery/max17055: Process negative current/temperature right
On max17055, current/temperature register values are in 2's complement format. Therefore we need to consider the case of negative values before doing bitwise operation. BUG=b:63870414 BRANCH=none TEST=run 'battery' command and confirm the reported discharge current looks reasonable. Change-Id: Iea0c554aecf2b410fc27b547e01ee7a583a0dd00 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/617654 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
@@ -237,7 +237,7 @@ void battery_get_params(struct batt_params *batt)
|
||||
if (max17055_read(REG_TEMPERATURE, ®))
|
||||
batt->flags |= BATT_FLAG_BAD_TEMPERATURE;
|
||||
|
||||
batt->temperature = TEMPERATURE_CONV(reg);
|
||||
batt->temperature = TEMPERATURE_CONV((int16_t)reg);
|
||||
|
||||
if (max17055_read(REG_STATE_OF_CHARGE, ®) &&
|
||||
fake_state_of_charge < 0)
|
||||
@@ -254,7 +254,7 @@ void battery_get_params(struct batt_params *batt)
|
||||
if (max17055_read(REG_AVERAGE_CURRENT, ®))
|
||||
batt->flags |= BATT_FLAG_BAD_CURRENT;
|
||||
|
||||
batt->current = CURRENT_CONV(reg);
|
||||
batt->current = CURRENT_CONV((int16_t)reg);
|
||||
|
||||
/* Default to not desiring voltage and current */
|
||||
batt->desired_voltage = batt->desired_current = 0;
|
||||
|
||||
Reference in New Issue
Block a user