Unverified Commit f2e4095b authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

sen5x: add cleanfan and readstatus commands

parent 1cb46c9d
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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;
+20 −0
Original line number Diff line number Diff line
@@ -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
+29 −0
Original line number Diff line number Diff line
@@ -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;