From 0159a9c68e1b21ce9fc17cbe527818e77ece780e Mon Sep 17 00:00:00 2001 From: Stefan Brand Date: Tue, 16 Mar 2021 16:36:16 +0100 Subject: [PATCH] Make WS2812B CO2 Indication work with Multisensor Some Small Bugfixes --- lib/MHZ19C/MHZ19C.cpp | 2 +- lib/SENSAIRS8/SENSAIRS8.cpp | 2 +- lib/SG112A/SG112A.h | 2 +- lib/SHT21/SHT21.h | 3 +-- src/main.cpp | 25 ++++++++++++++----------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/MHZ19C/MHZ19C.cpp b/lib/MHZ19C/MHZ19C.cpp index b8bc2b5..a43b7db 100644 --- a/lib/MHZ19C/MHZ19C.cpp +++ b/lib/MHZ19C/MHZ19C.cpp @@ -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; diff --git a/lib/SENSAIRS8/SENSAIRS8.cpp b/lib/SENSAIRS8/SENSAIRS8.cpp index d850c53..3aa3879 100644 --- a/lib/SENSAIRS8/SENSAIRS8.cpp +++ b/lib/SENSAIRS8/SENSAIRS8.cpp @@ -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; } diff --git a/lib/SG112A/SG112A.h b/lib/SG112A/SG112A.h index 93f365b..7bb0368 100644 --- a/lib/SG112A/SG112A.h +++ b/lib/SG112A/SG112A.h @@ -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]; diff --git a/lib/SHT21/SHT21.h b/lib/SHT21/SHT21.h index ee49859..27bff71 100644 --- a/lib/SHT21/SHT21.h +++ b/lib/SHT21/SHT21.h @@ -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); diff --git a/src/main.cpp b/src/main.cpp index 959944e..cc65c66 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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();