From 9ec77c2f10e798013f1ac18f20c5ef3b9509aadc Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 3 Aug 2022 09:32:59 +0100 Subject: [PATCH] LTR559: Lux as float. Avoid truncating Lux to uint16_t. --- drivers/ltr559/ltr559.cpp | 2 +- drivers/ltr559/ltr559.hpp | 2 +- examples/breakout_ltr559/demo.cpp | 2 +- micropython/modules/breakout_ltr559/breakout_ltr559.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/ltr559/ltr559.cpp b/drivers/ltr559/ltr559.cpp index 796176c8..43b36a05 100644 --- a/drivers/ltr559/ltr559.cpp +++ b/drivers/ltr559/ltr559.cpp @@ -148,7 +148,7 @@ namespace pimoroni { float lux = ((int32_t)data.als0 * ch0_c[ch_idx]) - ((int32_t)data.als1 * ch1_c[ch_idx]); lux /= (float)this->data.integration_time / 100.0f; lux /= (float)this->data.gain; - data.lux = (uint16_t)(lux / 10000.0f); + data.lux = lux / 10000.0f; } return has_updated; diff --git a/drivers/ltr559/ltr559.hpp b/drivers/ltr559/ltr559.hpp index e9511d01..a7927055 100644 --- a/drivers/ltr559/ltr559.hpp +++ b/drivers/ltr559/ltr559.hpp @@ -94,7 +94,7 @@ namespace pimoroni { uint16_t integration_time; uint16_t gain; float ratio; - uint16_t lux; + float lux; } ltr559_reading; class lookup { diff --git a/examples/breakout_ltr559/demo.cpp b/examples/breakout_ltr559/demo.cpp index 276f6690..16b418db 100644 --- a/examples/breakout_ltr559/demo.cpp +++ b/examples/breakout_ltr559/demo.cpp @@ -25,7 +25,7 @@ int main() { while(true){ bool new_data = ltr559.get_reading(); if(new_data) { - printf("Lux: %d Prox: %d\n", ltr559.data.lux, ltr559.data.proximity); + printf("Lux: %.2f Prox: %d\n", ltr559.data.lux, ltr559.data.proximity); } sleep_ms(100); }; diff --git a/micropython/modules/breakout_ltr559/breakout_ltr559.cpp b/micropython/modules/breakout_ltr559/breakout_ltr559.cpp index 8b03efe2..4d30734a 100644 --- a/micropython/modules/breakout_ltr559/breakout_ltr559.cpp +++ b/micropython/modules/breakout_ltr559/breakout_ltr559.cpp @@ -72,7 +72,7 @@ mp_obj_t BreakoutLTR559_get_reading(mp_obj_t self_in) { tuple[INTEGRATION_TIME] = mp_obj_new_int(data.integration_time); tuple[GAIN] = mp_obj_new_int(data.gain); tuple[RATIO] = mp_obj_new_float(data.ratio); - tuple[LUX] = mp_obj_new_int(data.lux); + tuple[LUX] = mp_obj_new_float(data.lux); return mp_obj_new_tuple(7, tuple); }