diff options
author | Aseda Aboagye <aaboagye@google.com> | 2018-03-06 23:14:43 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-03-14 04:07:08 -0700 |
commit | e325981c7d39f7160fafd4681384e410a137fa92 (patch) | |
tree | 4692ee2808d7ae10ee166c0c004bf04e6a4969cd /driver | |
parent | 2cc7923423f95949a7e4f769ec8e3c8b02177d93 (diff) | |
download | chrome-ec-e325981c7d39f7160fafd4681384e410a137fa92.tar.gz |
driver: OPT3001: Re-order application of scale.
This commit simply reorders the application of scale in order to
preserve the sensor precision.
BUG=b:72985601
BRANCH=stabilize-meowth-10444.B
TEST=Flash meowth; Set scale to 1000; Verify that more significant
digits are present compared to before.
Change-Id: Ibf46e574fccdde50ceb5f8174f9b4a29e60bfbfe
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/955967
Commit-Ready: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/als_opt3001.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/driver/als_opt3001.c b/driver/als_opt3001.c index b3ab198496..af6d07b06d 100644 --- a/driver/als_opt3001.c +++ b/driver/als_opt3001.c @@ -147,12 +147,15 @@ int opt3001_read_lux(const struct motion_sensor_t *s, vector_3_t v) /* * lux = 2EXP[3:0] × R[11:0] / 100 */ - data = (1 << (data >> 12)) * (data & 0x0FFF) / 100; - data += drv_data->offset; + data = (1 << (data >> 12)) * (data & 0x0FFF); + data += drv_data->offset * 100; + data = data * drv_data->scale + data * drv_data->uscale / 10000; + data /= 100; + if (data < 0) data = 1; - v[0] = data * drv_data->scale + data * drv_data->uscale / 10000; + v[0] = data; v[1] = 0; v[2] = 0; |