summaryrefslogtreecommitdiff
path: root/driver/als_si114x.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-08-31 11:12:32 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-01 01:28:00 -0700
commit1dfaf92f3a440456b4fc796b2f7a134fd4b83a19 (patch)
tree43149e7127cb11deabeacc4f566020739586e496 /driver/als_si114x.c
parentc2cf0fb198feea043a331e5d2156979d23f1aa46 (diff)
downloadchrome-ec-1dfaf92f3a440456b4fc796b2f7a134fd4b83a19.tar.gz
driver: si114x: Convert unit to distance
Instead of returning the amount of light returned, convert the data into distance (cm). It can be adjust via range. BRANCH=smaug BUG=chrome-os-partner:42526 TEST=check the data is usable by HAL. Change-Id: I97510246ce054af4e61325d7e295ca09cc536457 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/296472 Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Diffstat (limited to 'driver/als_si114x.c')
-rw-r--r--driver/als_si114x.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/driver/als_si114x.c b/driver/als_si114x.c
index 3be0c68d67..1ddb098ce9 100644
--- a/driver/als_si114x.c
+++ b/driver/als_si114x.c
@@ -93,10 +93,17 @@ static int si114x_read_results(struct motion_sensor_t *s, int nb)
if (ret)
break;
/* Add offset, calibration */
- if (val + type_data->offset < 0) {
- val = 0;
+ if (val + type_data->offset <= 0) {
+ val = 1;
} else {
val += type_data->offset;
+ /*
+ * Proxmitiy sensor data is inverse of the distance.
+ * Return back something proportional to distance,
+ * we affine with the scale parmeter.
+ */
+ if (s->type == MOTIONSENSE_TYPE_PROX)
+ val = SI114X_PS_INVERSION(val);
val = val * type_data->scale +
val * type_data->uscale / 10000;
}