summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-01-15 17:51:42 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2024-01-15 17:51:42 +0100
commit7f1f4aeee136c006ae16f4207eb7589af80e9d31 (patch)
tree974c3a261e264a2d51cde877986047a0b99ff12a
parent480c55a52673f555ab774233fa482b700278cdd4 (diff)
MAX444006: Implement setAmbientConfig
-rw-r--r--include/driver/max44006.h3
-rw-r--r--src/app/datalogger/main.cc8
-rw-r--r--src/driver/max44006.cc28
3 files changed, 27 insertions, 12 deletions
diff --git a/include/driver/max44006.h b/include/driver/max44006.h
index 4aac90f..4b3a519 100644
--- a/include/driver/max44006.h
+++ b/include/driver/max44006.h
@@ -69,10 +69,11 @@ class MAX44006 {
MAX44006(unsigned char const addr = 0x45) : address(addr), ambientConfig(TEMPEN) {}
- uint8_t init();
+ bool init();
uint16_t getTemperature();
bool getLight(float *red, float *green, float *blue, float *clear, float *ir);
+ bool setAmbientConfig(AmbientConfig config);
};
extern MAX44006 max44006;
diff --git a/src/app/datalogger/main.cc b/src/app/datalogger/main.cc
index 5e3208f..de0a782 100644
--- a/src/app/datalogger/main.cc
+++ b/src/app/datalogger/main.cc
@@ -365,9 +365,11 @@ int main(void)
#endif
#ifdef CONFIG_driver_max44006
- unsigned char ret;
- if ((ret = max44006.init()) != 0) {
- kout << "MAX44006 Initialization failed: " << ret << endl;
+ if (!max44006.init()) {
+ kout << "MAX44006 Initialization failed" << endl;
+ }
+ if (!max44006.setAmbientConfig(max44006.AMBPGA_11)) {
+ kout << "MAX44006 setAmbientConfig failed" << endl;
}
#endif
diff --git a/src/driver/max44006.cc b/src/driver/max44006.cc
index 3d8d206..6de2c4d 100644
--- a/src/driver/max44006.cc
+++ b/src/driver/max44006.cc
@@ -15,41 +15,53 @@
#include "arch.h"
-uint8_t MAX44006::init()
+bool MAX44006::init()
{
txbuf[0] = interruptStatusReg;
if (i2c.xmit(address, 1, txbuf, 1, rxbuf) != 0) {
- return 1;
+ return false;
}
if (rxbuf[0] & ~PWRON) {
// reset sensor
txbuf[1] = 0x10;
if (i2c.xmit(address, 2, txbuf, 0, rxbuf) != 0) {
- return 1;
+ return false;
}
arch.delay_ms(200);
if (i2c.xmit(address, 1, txbuf, 1, rxbuf) != 0) {
- return 1;
+ return false;
}
if (rxbuf[0] & ~PWRON) {
- return 2;
+ return false;
}
}
txbuf[0] = ambientConfigReg;
txbuf[1] = ambientConfig;
if (i2c.xmit(address, 2, txbuf, 0, rxbuf) != 0) {
- return 1;
+ return false;
}
txbuf[0] = mainConfigReg;
txbuf[1] = MODE_10; // MODE = 10 -> Clear + RGB + IR measurement
if (i2c.xmit(address, 2, txbuf, 0, rxbuf) != 0) {
- return 1;
+ return false;
}
- return 0;
+ return true;
+}
+
+bool MAX44006::setAmbientConfig(AmbientConfig config)
+{
+
+ txbuf[0] = ambientConfigReg;
+ txbuf[1] = config;
+ if (i2c.xmit(address, 2, txbuf, 0, rxbuf) != 0) {
+ return false;
+ }
+ ambientConfig = config;
+ return true;
}
uint16_t MAX44006::getTemperature()