diff options
author | Aseda Aboagye <aaboagye@google.com> | 2018-03-12 15:55:20 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2018-03-13 00:17:13 +0000 |
commit | 74dc1e55c091a98fdf9d2cd11a92311a8a54e252 (patch) | |
tree | 2a46534df119f1ebf21a76191801d7a59732a449 | |
parent | 3c895ef86501e323825361e24c192ba42918eabc (diff) | |
download | chrome-ec-stabilize-meowth-10444.B.tar.gz |
driver: OPT3001: Re-order application of scale.stabilize-meowth-10444.B
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: I0f04191a552c0ac3514f02bc2b7dd61b38a3629c
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/959631
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@google.com>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
-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; |