summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/driver/max44006.h18
-rw-r--r--src/driver/max44006.cc23
2 files changed, 27 insertions, 14 deletions
diff --git a/include/driver/max44006.h b/include/driver/max44006.h
index ae5ad12..7421914 100644
--- a/include/driver/max44006.h
+++ b/include/driver/max44006.h
@@ -15,20 +15,20 @@
class MAX44006 {
public:
- enum registers {
+ enum Registers {
interruptStatusReg = 0x00,
mainConfigReg = 0x01,
ambientConfigReg = 0x02,
};
- enum interruptStatus {
+ enum InterruptStatus {
AMBINTS = 0b00000001,
PWRON = 0b00000010,
SHDN = 0b00001000,
RESET = 0b00010000,
};
- enum mainConfig {
+ enum MainConfig {
AMBINTE = 0b00000001,
AMBSEL_00 = 0b00000000,
AMBSEL_01 = 0b00000100,
@@ -39,7 +39,7 @@ class MAX44006 {
MODE_10 = 0b00100000,
};
- enum ambientConfig {
+ enum AmbientConfig {
AMBPGA_00 = 0b00000000,
AMBPGA_01 = 0b00000001,
AMBPGA_10 = 0b00000010,
@@ -51,23 +51,25 @@ class MAX44006 {
AMBTIM_100 = 0b00010000,
TEMPEN = 0b00100000,
COMPPEN = 0b01000000,
- TRIm = 0b10000000,
+ TRIM = 0b10000000,
};
+ const unsigned char AMBPGA_MASK = 0b00000011;
+ const unsigned char AMBTIM_MASK = 0b00011100;
+
private:
MAX44006(const MAX44006 &copy);
unsigned char const address;
unsigned char txbuf[2];
unsigned char rxbuf[10];
- unsigned char ambtim;
- unsigned char ambpga;
+ AmbientConfig ambientConfig;
uint16_t clear, red, green, blue, ir;
public:
- MAX44006(unsigned char const addr = 0x45) : address(addr) {}
+ MAX44006(unsigned char const addr = 0x45) : address(addr), ambientConfig(TEMPEN) {}
uint8_t init();
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;
}