Add Calibration for SCD30
This commit is contained in:
parent
98893c2894
commit
c455a7c7a7
4 changed files with 28 additions and 10 deletions
|
@ -40,6 +40,9 @@ class AttSensor {
|
||||||
// Return the number of Bytes added to the Payload
|
// Return the number of Bytes added to the Payload
|
||||||
virtual uint8_t numBytes(void) = 0;
|
virtual uint8_t numBytes(void) = 0;
|
||||||
|
|
||||||
|
// Calibrate a Sensor. Needs to be Implemented in the Child Class if supported
|
||||||
|
void calibrate(void) {};
|
||||||
|
|
||||||
// Helper Functions to Put Values Into the Payload Array
|
// Helper Functions to Put Values Into the Payload Array
|
||||||
static void int32ToPayload(int32_t value, char *payload, uint8_t startbyte) {
|
static void int32ToPayload(int32_t value, char *payload, uint8_t startbyte) {
|
||||||
payload[startbyte] = (value) & 0XFF;
|
payload[startbyte] = (value) & 0XFF;
|
||||||
|
|
|
@ -33,6 +33,13 @@ MHZ19C::MHZ19C(void) {
|
||||||
Serial.setTimeout(MHZ19C_READ_TIMEOUT);
|
Serial.setTimeout(MHZ19C_READ_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MHZ19C::MHZ19C(pin_size_t calpin) {
|
||||||
|
this->calpin = calpin;
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
Serial.setTimeout(MHZ19C_READ_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
void MHZ19C::initialize(void) {
|
void MHZ19C::initialize(void) {
|
||||||
#ifdef MHZ19C_ENABLE_AUTOCAL
|
#ifdef MHZ19C_ENABLE_AUTOCAL
|
||||||
setSelfCalibration(1);
|
setSelfCalibration(1);
|
||||||
|
@ -41,6 +48,14 @@ void MHZ19C::initialize(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MHZ19C::calibrate(void) {
|
||||||
|
pinMode(calpin, OUTPUT);
|
||||||
|
digitalWrite(calpin, LOW);
|
||||||
|
delay(7500);
|
||||||
|
digitalWrite(calpin, HIGH);
|
||||||
|
pinMode(PIN_PB4, INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t MHZ19C::getSensorData(char * payload, uint8_t startbyte) {
|
uint8_t MHZ19C::getSensorData(char * payload, uint8_t startbyte) {
|
||||||
write(MHZ19C_CMD_GET_PPM, 0x00);
|
write(MHZ19C_CMD_GET_PPM, 0x00);
|
||||||
delay(50);
|
delay(50);
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
class MHZ19C : public AttSensor {
|
class MHZ19C : public AttSensor {
|
||||||
private:
|
private:
|
||||||
uint8_t buffer[MHZ19C_SER_BUF_LEN];
|
uint8_t buffer[MHZ19C_SER_BUF_LEN];
|
||||||
|
pin_size_t calpin = PIN_PB4; // PB4 is the Calibration Pin on the Addon PCB
|
||||||
|
|
||||||
void write(byte cmd, byte arg);
|
void write(byte cmd, byte arg);
|
||||||
uint8_t read();
|
uint8_t read();
|
||||||
|
@ -47,7 +48,9 @@ class MHZ19C : public AttSensor {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MHZ19C(void);
|
MHZ19C(void);
|
||||||
|
MHZ19C(pin_size_t calpin);
|
||||||
void initialize(void);
|
void initialize(void);
|
||||||
|
void calibrate(void);
|
||||||
uint8_t numBytes(void) {return 2;};
|
uint8_t numBytes(void) {return 2;};
|
||||||
uint8_t getSensorData(char *payload, uint8_t startbyte);
|
uint8_t getSensorData(char *payload, uint8_t startbyte);
|
||||||
void setSelfCalibration(bool state);
|
void setSelfCalibration(bool state);
|
||||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -364,17 +364,14 @@ void setup()
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// Handle long Button Press for Calibration with MH-Z19C Sensor
|
// Handle long Button Press for Calibration with MH-Z19C Sensor
|
||||||
#if defined HAS_MHZ19C && defined BTN_PIN
|
#ifdef BTN_PIN
|
||||||
if (digitalRead(BTN_PIN) == LOW) {
|
if (digitalRead(BTN_PIN) == LOW) {
|
||||||
// Press Button longer than 4 Seconds -> Start MH-Z19C Calibration Routine
|
// Press Button longer than 4 Seconds -> Start Sensor Calibration Routine (if applicable)
|
||||||
unsigned long loop_millis = millis();
|
unsigned long loop_millis = millis();
|
||||||
if ((unsigned long)(loop_millis - btn_millis) >= 4000) {
|
if ((unsigned long)(loop_millis - btn_millis) >= 4000) {
|
||||||
WS2812B_SETLED(1,153,0,153);
|
WS2812B_SETLED(1,153,0,153);
|
||||||
pinMode(PIN_PB4, OUTPUT);
|
for (uint8_t i=0; i<NUM_SENSORS; i++)
|
||||||
digitalWrite(PIN_PB4, LOW);
|
sensors[i]->calibrate();
|
||||||
delay(7500);
|
|
||||||
digitalWrite(PIN_PB4, HIGH);
|
|
||||||
pinMode(PIN_PB4, INPUT_PULLUP);
|
|
||||||
WS2812B_SETLED(1,0,0,0);
|
WS2812B_SETLED(1,0,0,0);
|
||||||
} else {
|
} else {
|
||||||
delay(500);
|
delay(500);
|
||||||
|
@ -383,7 +380,7 @@ void loop()
|
||||||
#endif
|
#endif
|
||||||
// Only Run the LMIC loop here. Actual Sending Code is in do_send()
|
// Only Run the LMIC loop here. Actual Sending Code is in do_send()
|
||||||
os_runloop_once();
|
os_runloop_once();
|
||||||
#if defined HAS_MHZ19C && defined BTN_PIN
|
#ifdef BTN_PIN
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
Loading…
Reference in a new issue