summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/driver/sen5x.h12
-rw-r--r--src/app/datalogger/main.cc20
-rw-r--r--src/driver/sen5x.cc29
3 files changed, 61 insertions, 0 deletions
diff --git a/include/driver/sen5x.h b/include/driver/sen5x.h
index 64e116b..47d92a0 100644
--- a/include/driver/sen5x.h
+++ b/include/driver/sen5x.h
@@ -22,6 +22,15 @@ class SEN5x {
signed short const VOC_INVALID = 0x7fff;
signed short const NOX_INVALID = 0x7fff;
+ struct {
+ unsigned int fan_speed_warning : 1;
+ unsigned int fan_cleaning_active : 1;
+ unsigned int gas_sensor_error : 1;
+ unsigned int rht_sensor_error : 1;
+ unsigned int laser_failure : 1;
+ unsigned int fan_failure : 1;
+ };
+
/*
* PM1.0 value, scaled by 10.
* PM1.0 [µg/m³] = pm10 / 10
@@ -73,7 +82,10 @@ class SEN5x {
void start();
void stop();
+ void cleanFan();
+
bool read();
+ bool readStatus();
};
extern SEN5x sen5x;
diff --git a/src/app/datalogger/main.cc b/src/app/datalogger/main.cc
index fd016e7..251d1fa 100644
--- a/src/app/datalogger/main.cc
+++ b/src/app/datalogger/main.cc
@@ -235,6 +235,26 @@ void loop(void)
} else {
kout << "SEN5x error" << endl;
}
+ if (sen5x.readStatus()) {
+ if (sen5x.fan_speed_warning) {
+ kout << "SEN5x warning: fan speed out of range" << endl;
+ }
+ if (sen5x.fan_cleaning_active) {
+ kout << "SEN5x info: fan cleaning active" << endl;
+ }
+ if (sen5x.gas_sensor_error) {
+ kout << "SEN5x error: gas sensor" << endl;
+ }
+ if (sen5x.rht_sensor_error) {
+ kout << "SEN5x error: RHT sensor" << endl;
+ }
+ if (sen5x.laser_failure) {
+ kout << "SEN5x error: laser current out of range" << endl;
+ }
+ if (sen5x.fan_failure) {
+ kout << "SEN5x error: fan failure" << endl;
+ }
+ }
#endif
#ifdef CONFIG_driver_veml6075
diff --git a/src/driver/sen5x.cc b/src/driver/sen5x.cc
index 2a5d6b8..9edbcd0 100644
--- a/src/driver/sen5x.cc
+++ b/src/driver/sen5x.cc
@@ -11,6 +11,13 @@
#include "driver/soft_i2c.h"
#endif
+void SEN5x::cleanFan()
+{
+ txbuf[0] = 0x56;
+ txbuf[1] = 0x07;
+ i2c.xmit(address, 2, txbuf, 0, rxbuf);
+}
+
void SEN5x::start()
{
txbuf[0] = 0x00;
@@ -48,4 +55,26 @@ bool SEN5x::read()
return true;
}
+bool SEN5x::readStatus()
+{
+ txbuf[0] = 0xd2;
+ txbuf[1] = 0x06;
+ if (i2c.xmit(address, 2, txbuf, 0, rxbuf)) {
+ return false;
+ }
+ arch.delay_ms(20);
+ if (i2c.xmit(address, 0, txbuf, 6, rxbuf)) {
+ return false;
+ }
+
+ fan_speed_warning = rxbuf[1] & 0x20;
+ fan_cleaning_active = rxbuf[1] & 0x08;
+ gas_sensor_error = rxbuf[4] & 0x80;
+ rht_sensor_error = rxbuf[4] & 0x40;
+ laser_failure = rxbuf[4] & 0x20;
+ fan_failure = rxbuf[4] & 0x10;
+
+ return true;
+}
+
SEN5x sen5x;