Make WS2812B CO2 Indication work with Multisensor

Some Small Bugfixes
This commit is contained in:
seiichiro 2021-03-16 16:36:16 +01:00
parent c970e4a8ee
commit 0159a9c68e
5 changed files with 18 additions and 16 deletions

View file

@ -51,7 +51,7 @@ uint8_t MHZ19C::getSensorData(char * payload, uint8_t startbyte) {
if (readBytes > 0) {
switch(buffer[1]) {
case 0x86:
int16_t value = (buffer[2]*256) + buffer[3];
uint16_t value = (buffer[2]*256) + buffer[3];
payload[startbyte] = (value) & 0xFF;
payload[startbyte+1] = (value >> 8) & 0xFF;
break;

View file

@ -44,7 +44,7 @@ uint8_t SENSAIRS8::getSensorData(char *payload, uint8_t startbyte) {
payload[startbyte] = 0x00;
payload[startbyte+1] = 0x00;
if (readBytes > 0) {
int16_t value = (buffer[3]*256) + buffer[4];
uint16_t value = (buffer[3]*256) + buffer[4];
payload[startbyte] = (value) & 0xFF;
payload[startbyte+1] = (value >> 8) & 0xFF;
}

View file

@ -36,7 +36,7 @@
#define CMD_GET_SER 0x12 // Get Sensor Serial
#define CMD_GET_PPM 0x14 // Get Current PPM Reading
class SG112A {
class SG112A : public AttSensor {
private:
uint8_t buffer[SER_BUF_LEN];

View file

@ -37,8 +37,7 @@
#define SHT21_HUMINOHOLD 0xF5
#define SHT21_SOFTRESET 0xFE
class SHT21
{
class SHT21 : public AttSensor {
private:
uint16_t sensorRead(uint8_t command);

View file

@ -212,30 +212,32 @@ void do_send(osjob_t* j) {
for (int i=0; i < NUM_SENSORS; i++)
curByte = sensors[i]->getSensorData(payload, curByte);
// Queue Packet for Sending
DEBUG_PRINTLN("LoRa-Packet Queued");
LMIC_setTxData2(1, payload, sizeof(payload), 0);
#if defined WS2812B_PIN && (defined HAS_SG112A || defined HAS_MHZ19C)
#if defined WS2812B_PIN && (defined HAS_SG112A || defined HAS_MHZ19C || defined HAS_SENSAIRS8)
// CO2 PPM Levels and LED Colors
// < 1000 ppm green
// < 1800 ppm yellow
// > 1000 ppm red
if (data.ppm > 0 && data.ppm <= 1000) {
// Get PPM from Payload:
uint16_t ppm = word(payload[2], payload[1]);
// Set WS2812B-LED accodring to PPM Value
if (ppm > 0 && ppm <= 1000) {
WS2812B_SETLED(0,0,127,0);
} else if (data.ppm > 1000 && data.ppm <= 1800) {
} else if (ppm > 1000 && ppm <= 1800) {
WS2812B_SETLED(0,127,127,0);
} else if (data.ppm > 1800) {
} else if (ppm > 1800) {
WS2812B_SETLED(0,127,0,0);
} else {
WS2812B_SETLED(0,0,0,0);
}
#endif // WS2812B
#endif // #infdef HAS_NO_SENSOR
#endif // HAS_NO_SENSOR
// Queue Packet for Sending
DEBUG_PRINTLN("LoRa-Packet Queued");
LMIC_setTxData2(1, payload, sizeof(payload), 0);
}
}
@ -263,6 +265,7 @@ void setup()
#endif
// Setup all Sensors
// Order of the Sensors here is Order in the Payload
uint8_t i = 0;
#ifdef HAS_MHZ19C
sensors[i] = new MHZ19C();