Compare commits

..

2 commits

Author SHA1 Message Date
ac60546eab Enable Remote Calibration 2021-04-06 20:05:57 +02:00
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); digitalWrite(calpin, LOW);
delay(7500); delay(7500);
digitalWrite(calpin, HIGH); digitalWrite(calpin, HIGH);
pinMode(PIN_PB4, INPUT_PULLUP); pinMode(calpin, INPUT_PULLUP);
} }
uint8_t MHZ19C::getSensorData(char * payload, uint8_t startbyte) { 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; 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 // Read a Sensor Response
uint8_t SENSAIRS8::read() { uint8_t SENSAIRS8::read() {
// Number of returned Bytes // Number of returned Bytes

View file

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

View file

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