Compare commits

...

2 commits

Author SHA1 Message Date
seiichiro ac60546eab Enable Remote Calibration 2021-04-06 20:05:57 +02:00
seiichiro 36963daac6 Enable Calibration on Sensair S8 2021-04-06 16:09:08 +02:00
4 changed files with 46 additions and 12 deletions

View file

@ -53,7 +53,7 @@ void MHZ19C::calibrate(void) {
digitalWrite(calpin, LOW);
delay(7500);
digitalWrite(calpin, HIGH);
pinMode(PIN_PB4, INPUT_PULLUP);
pinMode(calpin, INPUT_PULLUP);
}
uint8_t MHZ19C::getSensorData(char * payload, uint8_t startbyte) {

View file

@ -49,6 +49,22 @@ uint8_t SENSAIRS8::getSensorData(char *payload, uint8_t startbyte) {
return startbyte+2;
}
void SENSAIRS8::calibrate(void) {
pinMode(calpin, OUTPUT);
digitalWrite(calpin, LOW);
delay(6000);
digitalWrite(calpin, HIGH);
pinMode(calpin, INPUT_PULLUP);
}
void SENSAIRS8::initialize(void) {
// Disable Auto Background Calibration
uint8_t _cmd[8] = {0xFE, 0x06, 0x00, 0x01F, 0x00, 0x00, 0xAC, 0x03};
while (Serial.available() > 0) Serial.read();
Serial.write(_cmd, 8);
Serial.flush();
}
// Read a Sensor Response
uint8_t SENSAIRS8::read() {
// Number of returned Bytes

View file

@ -35,6 +35,7 @@
class SENSAIRS8 : public AttSensor {
private:
uint8_t buffer[SER_BUF_LEN];
pin_size_t calpin = PIN_PB4; // PB4 is the Calibration Pin on the Addon PCB
uint8_t read();
void zeroBuffer(void);
@ -43,8 +44,8 @@ class SENSAIRS8 : public AttSensor {
public:
SENSAIRS8(void);
uint8_t getSensorData(char *payload, uint8_t startbyte);
void calibrate(void) {};
void initialize(void) {};
void calibrate(void);
void initialize(void);
uint8_t numBytes(void) {return 2;};
};

View file

@ -157,15 +157,32 @@ void onEvent(ev_t ev) {
// Check for Downlink
DEBUG_PRINTLN("LoRa Packet Sent");
WS2812B_BLINK(1,0,127,0,1000);
if ((int)LMIC.dataLen == 2) {
// We got a Packet with the right size - lets assemble it into a uint16_t
DEBUG_PRINTLN("Received Downlink")
uint16_t tmpslp = (LMIC.frame[LMIC.dataBeg] << 8) | LMIC.frame[LMIC.dataBeg+1];
DEBUG_PRINT("Setting Sleep Time to: ");
DEBUG_PRINTLN(tmpslp);
sleep_time = tmpslp;
EEPROM.put(ADDR_SLP, tmpslp);
WS2812B_BLINK(1,0,0,127,250);
if ((int)LMIC.dataLen > 0) {
// Check for Downlinks
// Function based in Ports:
// Port 1
// Set Sending Interval
// Port 2
// Do Calibration
switch((uint8_t)LMIC.frame[LMIC.dataBeg-1]) {
case 1:
if ((int)LMIC.dataLen == 2) {
// We got a Packet with the right size - lets assemble it into a uint16_t
DEBUG_PRINTLN("Received Downlink")
uint16_t tmpslp = (LMIC.frame[LMIC.dataBeg] << 8) | LMIC.frame[LMIC.dataBeg+1];
DEBUG_PRINT("Setting Sleep Time to: ");
DEBUG_PRINTLN(tmpslp);
sleep_time = tmpslp;
EEPROM.put(ADDR_SLP, tmpslp);
WS2812B_BLINK(1,0,0,127,250);
}
break;
case 2:
for (uint8_t i=0; i<NUM_SENSORS; i++)
sensors[i]->calibrate();
BLINK_LED(3);
break;
}
}
// Got to sleep for specified Time