diff options
author | Douglas Anderson <dianders@chromium.org> | 2017-05-01 16:27:37 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2017-05-01 23:59:43 +0000 |
commit | 01ceab68cd6b542f8c6355425e6ac6da698e0ebf (patch) | |
tree | 6438b5796c7550b3a6094235ec00c3576dd94155 | |
parent | c1c322de021123c167369ae99efdb09f717c3ffd (diff) | |
download | chrome-ec-01ceab68cd6b542f8c6355425e6ac6da698e0ebf.tar.gz |
virtual_battery: Fix energy readings
The virtual battery "energy" readings were totally broken. Rather
than reporting things in units of "10 mW" they were reporting things
in units of "10 uW". That's because they were doing this math:
result = mV * mA / 10
Said another way:
result = (V / 1000) * (A / 1000) / 10
result = (V * A) / (100000) / 10
result = W / 1000000 / 10
result = uW / 10
Aside from the fact that clients were expecting things in "10 mW"
instead of "10 uW", we got even more random results. That's because
we return to the client in a 16-bit variable, so we were kinda
randomly truncating things.
Doh.
BRANCH=ToT
BUG=chromium:717304
TEST=power_supply_info
Unfortunately when you try to report sane values for "10 uA" in a
16-bit result, it doesn't work too well (
Change-Id: I8075dffd7ab6b372be5b8fdf293acc96c5878036
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/492546
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | common/virtual_battery.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/common/virtual_battery.c b/common/virtual_battery.c index 4deff8c402..4bc87c04db 100644 --- a/common/virtual_battery.c +++ b/common/virtual_battery.c @@ -231,7 +231,7 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head, case SB_FULL_CHARGE_CAPACITY: val = curr_batt->full_capacity; if (batt_mode_cache & MODE_CAPACITY) - val = val * curr_batt->voltage / 10; + val = val * curr_batt->voltage / 10000; memcpy(dest, &val, read_len); break; case SB_BATTERY_STATUS: @@ -244,7 +244,7 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head, case SB_DESIGN_CAPACITY: val = *(int *)host_get_memmap(EC_MEMMAP_BATT_DCAP); if (batt_mode_cache & MODE_CAPACITY) - val = val * curr_batt->voltage / 10; + val = val * curr_batt->voltage / 10000; memcpy(dest, &val, read_len); break; case SB_DESIGN_VOLTAGE: @@ -254,7 +254,7 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head, case SB_REMAINING_CAPACITY: val = curr_batt->remaining_capacity; if (batt_mode_cache & MODE_CAPACITY) - val = val * curr_batt->voltage / 10; + val = val * curr_batt->voltage / 10000; memcpy(dest, &val, read_len); break; default: |