From b02df7d69bcc433e7e74a17971e0121c4ee31a51 Mon Sep 17 00:00:00 2001 From: Stefan Brand Date: Wed, 31 Mar 2021 20:15:13 +0200 Subject: [PATCH] Fix Calibration Routines --- include/attsensor.h | 4 ++-- lib/BME280/BME280.h | 1 + lib/DS18B20/DS18B20.h | 1 + lib/SCD30/SCD30.cpp | 2 +- lib/SCD30/SCD30.h | 3 ++- lib/SENSAIRS8/SENSAIRS8.h | 1 + lib/SG112A/SG112A.h | 1 + lib/SHT21/SHT21.h | 1 + src/main.cpp | 6 +++++- 9 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/attsensor.h b/include/attsensor.h index 76055af..912d08b 100644 --- a/include/attsensor.h +++ b/include/attsensor.h @@ -40,8 +40,8 @@ class AttSensor { // Return the number of Bytes added to the Payload virtual uint8_t numBytes(void) = 0; - // Calibrate a Sensor. Needs to be Implemented in the Child Class if supported - void calibrate(void) {}; + // Calibrate a Sensor. Needs to be Implemented in the Child Class + virtual void calibrate(void) = 0; // Helper Functions to Put Values Into the Payload Array static void int32ToPayload(int32_t value, char *payload, uint8_t startbyte) { diff --git a/lib/BME280/BME280.h b/lib/BME280/BME280.h index 85c0fe8..e20fcdc 100644 --- a/lib/BME280/BME280.h +++ b/lib/BME280/BME280.h @@ -33,6 +33,7 @@ private: public: BME280(void); uint8_t getSensorData(char *payload, uint8_t startbyte); + void calibrate(void) {}; void initialize(void) {getCalData();}; uint8_t numBytes(void) {return 12;}; }; diff --git a/lib/DS18B20/DS18B20.h b/lib/DS18B20/DS18B20.h index db988b6..3d5d58f 100644 --- a/lib/DS18B20/DS18B20.h +++ b/lib/DS18B20/DS18B20.h @@ -50,6 +50,7 @@ class DS18B20 : public AttSensor { public: DS18B20(uint8_t owpin, uint8_t resbits = 12, bool para = false); uint8_t getSensorData(char *payload, uint8_t startbyte); + void calibrate(void) {}; void initialize(void); uint8_t numBytes(void); }; diff --git a/lib/SCD30/SCD30.cpp b/lib/SCD30/SCD30.cpp index ea8657d..be2612d 100644 --- a/lib/SCD30/SCD30.cpp +++ b/lib/SCD30/SCD30.cpp @@ -85,7 +85,7 @@ uint8_t SCD30::getSensorData(char *payload, uint8_t startbyte) { } // Calibrate the Sensor to 400ppm (Outside Level) -void SCD30::calibrate() { +void SCD30::calibrate(void) { sendCmd(SCD30_SET_RECALIB, 400); } diff --git a/lib/SCD30/SCD30.h b/lib/SCD30/SCD30.h index 39e3b53..3cfea3c 100644 --- a/lib/SCD30/SCD30.h +++ b/lib/SCD30/SCD30.h @@ -61,9 +61,10 @@ class SCD30 : public AttSensor { SCD30(); SCD30(uint8_t interval, bool selfcalib); void initialize(void); + void calibrate(void); uint8_t numBytes(void) {return 6;}; uint8_t getSensorData(char *payload, uint8_t startbyte); - void calibrate(); + }; #endif \ No newline at end of file diff --git a/lib/SENSAIRS8/SENSAIRS8.h b/lib/SENSAIRS8/SENSAIRS8.h index 3702ca1..2a8c0e9 100644 --- a/lib/SENSAIRS8/SENSAIRS8.h +++ b/lib/SENSAIRS8/SENSAIRS8.h @@ -43,6 +43,7 @@ class SENSAIRS8 : public AttSensor { public: SENSAIRS8(void); uint8_t getSensorData(char *payload, uint8_t startbyte); + void calibrate(void) {}; void initialize(void) {}; uint8_t numBytes(void) {return 2;}; }; diff --git a/lib/SG112A/SG112A.h b/lib/SG112A/SG112A.h index 7bb0368..b0a09b7 100644 --- a/lib/SG112A/SG112A.h +++ b/lib/SG112A/SG112A.h @@ -49,6 +49,7 @@ class SG112A : public AttSensor { public: SG112A(void); uint8_t getSensorData(char *payload, uint8_t startbyte); + void calibrate(void) {}; void initialize(void) {}; uint8_t numBytes(void) {return 2;}; }; diff --git a/lib/SHT21/SHT21.h b/lib/SHT21/SHT21.h index 27bff71..8755898 100644 --- a/lib/SHT21/SHT21.h +++ b/lib/SHT21/SHT21.h @@ -44,6 +44,7 @@ class SHT21 : public AttSensor { public: SHT21(void); uint8_t getSensorData(char *payload, uint8_t startbyte); + void calibrate(void) {}; void initialize(void) {}; uint8_t numBytes(void) {return 8;}; }; diff --git a/src/main.cpp b/src/main.cpp index 76dcc83..3632584 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -149,6 +149,7 @@ void onEvent(ev_t ev) { case EV_JOINED: // Disable LinkCheck LMIC_setLinkCheckMode(0); + BLINK_LED(2); WS2812B_BLINK(1,0,127,0,1000); DEBUG_PRINTLN("OTAA Join Succeeded"); break; @@ -172,7 +173,7 @@ void onEvent(ev_t ev) { for (uint16_t i = 0; i < sleep_time*2; i++) { // Cancel sleep Cycle if Button was Pressed #ifdef BTN_PIN - if (btn_pressed) { + if (btn_pressed && digitalRead(BTN_PIN) == HIGH) { i = sleep_time*2; btn_pressed = 0; } else { @@ -370,8 +371,11 @@ void loop() unsigned long loop_millis = millis(); if ((unsigned long)(loop_millis - btn_millis) >= 4000) { WS2812B_SETLED(1,153,0,153); + BLINK_LED(3); + delay(1000); for (uint8_t i=0; icalibrate(); + BLINK_LED(1); WS2812B_SETLED(1,0,0,0); } else { delay(500);