diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-12-26 16:18:53 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-12-26 16:18:53 +0100 |
commit | aa51f780fb72969006f96bbd18e9260b8452913e (patch) | |
tree | a57fdfc849948fc55142d018f75f9db13d1931e9 /src | |
parent | 0b0bcc80bf689592dcb3236eed3e166d82cd7802 (diff) |
max44006: getLight: respect AMBPGA setting
Diffstat (limited to 'src')
-rw-r--r-- | src/driver/max44006.cc | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/driver/max44006.cc b/src/driver/max44006.cc index e9b9467..50eaf0f 100644 --- a/src/driver/max44006.cc +++ b/src/driver/max44006.cc @@ -38,7 +38,7 @@ uint8_t MAX44006::init() } txbuf[0] = ambientConfigReg; - txbuf[1] = TEMPEN; // TEMPEN = 1 + txbuf[1] = ambientConfig; if (i2c.xmit(address, 2, txbuf, 0, rxbuf) != 0) { return 1; } @@ -69,11 +69,22 @@ bool MAX44006::getLight(float *red, float *green, float *blue, float *clear, flo return false; } - *clear = (float)(((uint16_t)rxbuf[0] << 8) + rxbuf[1]) * 0.002; - *red = (float)(((uint16_t)rxbuf[2] << 8) + rxbuf[3]) * 0.002; - *green = (float)(((uint16_t)rxbuf[4] << 8) + rxbuf[5]) * 0.002; - *blue = (float)(((uint16_t)rxbuf[6] << 8) + rxbuf[7]) * 0.004; - *ir = (float)(((uint16_t)rxbuf[8] << 8) + rxbuf[9]) * 0.002; + float multiplier = 0.002; + if ((ambientConfig & AMBPGA_MASK) == AMBPGA_01) { + multiplier = 0.008; + } + else if ((ambientConfig & AMBPGA_MASK) == AMBPGA_10) { + multiplier = 0.032; + } + else if ((ambientConfig & AMBPGA_MASK) == AMBPGA_11) { + multiplier = 0.512; + } + + *clear = (float)(((uint16_t)rxbuf[0] << 8) + rxbuf[1]) * multiplier; + *red = (float)(((uint16_t)rxbuf[2] << 8) + rxbuf[3]) * multiplier; + *green = (float)(((uint16_t)rxbuf[4] << 8) + rxbuf[5]) * multiplier; + *blue = (float)(((uint16_t)rxbuf[6] << 8) + rxbuf[7]) * multiplier * 2; + *ir = (float)(((uint16_t)rxbuf[8] << 8) + rxbuf[9]) * multiplier; return true; } |