diff options
author | Douglas Anderson <dianders@chromium.org> | 2017-05-01 16:27:37 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-05-01 21:54:05 -0700 |
commit | f1e98218776de9380141384af4ffc9611f6f4adc (patch) | |
tree | fc935da84b1872dd062efdcfbe7b5af0ed8e6260 /common | |
parent | 98b8d8c840bfb2679ba0eb716233cafc9c47a536 (diff) | |
download | chrome-ec-f1e98218776de9380141384af4ffc9611f6f4adc.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>
(cherry picked from commit 01ceab68cd6b542f8c6355425e6ac6da698e0ebf)
Reviewed-on: https://chromium-review.googlesource.com/492568
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common')
-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 d2f1115b33..d5a9ad2124 100644 --- a/common/virtual_battery.c +++ b/common/virtual_battery.c @@ -229,7 +229,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: @@ -242,7 +242,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: @@ -252,7 +252,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: |