[Firmware] Add Combined Alarm and Climate Functionality

This commit is contained in:
seiichiro 2020-06-21 21:29:24 +02:00
parent a4c40b1b5d
commit 4e25baf91e
2 changed files with 49 additions and 16 deletions

View file

@ -58,18 +58,33 @@
#endif #endif
// Create Sensor Class // Create Sensor Class
#if defined HAS_BME280 || defined HAS_BME280_BRIGHTNESS #if defined HAS_BME280 || defined HAS_BME280_BRIGHTNESS || defined HAS_BME280_ALARM
#include <BME280.h> #include <BME280.h>
BME280 sensor; BME280 sensor;
#endif #endif
#if defined HAS_SHT21 || defined HAS_SHT21_BRIGHTNESS #if defined HAS_SHT21 || defined HAS_SHT21_BRIGHTNESS || defined HAS_SHT21_ALARM
#include <SHT21.h> #include <SHT21.h>
SHT21 sensor; SHT21 sensor;
#endif #endif
#ifdef HAS_ALARM #if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
volatile boolean alarm = false; volatile boolean alarm = false;
// Get the Interrupt Mask for the selected Alarm PIN
#if ALARM_PIN == PIN_A0
#define ALARM_INT PCINT0
#elif ALARM_PIN == PIN_A1
#define ALARM_INT PCINT1
#elif ALARM_PIN == PIN_A2
#define ALARM_INT PCINT2HAS_BME280_ALARM
#elif ALARM_PIN == PIN_A3
#define ALARM_INT PCINT3
#elif ALARM_PIN == PIN_A7
#define ALARM_INT PCINT7
#elif ALARM_PIN == PIN_B1
#define ALARM_INT PCINT9
#endif
#endif #endif
// Global Variable to Track Deep Sleep // Global Variable to Track Deep Sleep
@ -133,7 +148,7 @@ void sleep(uint16_t s)
sleep_interval = 0; sleep_interval = 0;
while (sleep_interval < s) { while (sleep_interval < s) {
// in case of alarm, break loop and transmit immediatly // in case of alarm, break loop and transmit immediatly
#ifdef HAS_ALARM #if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
if( alarm == true){ if( alarm == true){
return; return;
} }
@ -154,13 +169,15 @@ ISR(WATCHDOG_vect) {
WDTCSR = (1<<WDIE)|(1<<WDP3)|(1<<WDP0); WDTCSR = (1<<WDIE)|(1<<WDP3)|(1<<WDP0);
} }
#ifdef HAS_ALARM #if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
// innterrupt handler pin change // innterrupt handler pin change
ISR(PCINT0_vect) ISR(PCINT0_vect)
{ {
sleep_disable(); sleep_disable();
blink(1); #ifdef HAS_LED
alarm = true; blink(1);
#endif
alarm = true;
} }
#endif #endif
@ -243,10 +260,10 @@ void setup()
radio.sleep(); radio.sleep();
#endif #endif
#ifdef HAS_ALARM #if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
MCUCR = (MCUCR & ~(bit(ISC01)|bit(ISC00))) | bit(ISC01); // fallende Flanke MCUCR = (MCUCR & ~(bit(ISC01)|bit(ISC00))) | bit(ISC01); // fallende Flanke
GIMSK = (1<<PCIE0); GIMSK = (1<<PCIE0);
PCMSK0 = (1<<PCINT0); // PCINT(PA0) PCMSK0 = (1<<ALARM_INT);
pinMode(ALARM_PIN, INPUT_PULLUP); pinMode(ALARM_PIN, INPUT_PULLUP);
#endif #endif
@ -297,14 +314,29 @@ void loop()
int32_t pressure; int32_t pressure;
int16_t brightness; int16_t brightness;
} __attribute__ ((packed)) data; } __attribute__ ((packed)) data;
#elif defined HAS_SHT21_ALARM
struct lora_data {
uint8_t bat;
int32_t temperature;
int32_t humidity;
uint8_t alarm;
} __attribute__ ((packed)) data;
#elif defined HAS_BME280_ALARM
struct lora_data {
uint8_t bat;
int32_t temperature;
int32_t humidity;
int32_t pressure;
uint8_t alarm;
} __attribute__ ((packed)) data;
#endif #endif
// Get Sensor Data // Get Sensor Data
#if defined HAS_BME280 || defined HAS_BME280_BRIGHTNESS #if defined HAS_BME280 || defined HAS_BME280_BRIGHTNESS || defined HAS_BME280_ALARM
sensor.getData(&data.temperature, &data.pressure, &data.humidity); sensor.getData(&data.temperature, &data.pressure, &data.humidity);
#endif #endif
#if defined HAS_SHT21 || defined HAS_SHT21_BRIGHTNESS #if defined HAS_SHT21 || defined HAS_SHT21_BRIGHTNESS || defined HAS_SHT21_ALARM
data.temperature = (int32_t)(sensor.getTemperature()*100); data.temperature = (int32_t)(sensor.getTemperature()*100);
data.humidity = (int32_t)(sensor.getHumidity()*100); data.humidity = (int32_t)(sensor.getHumidity()*100);
#endif #endif
@ -313,8 +345,8 @@ void loop()
data.brightness = (int16_t)(brightness()); data.brightness = (int16_t)(brightness());
#endif #endif
#if defined HAS_ALARM #if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
data.alarm = (uint8_t)alarm; data.alarm = alarm;
alarm = false; alarm = false;
#endif #endif

View file

@ -12,6 +12,8 @@
#define HAS_SHT21_BRIGHTNESS - SHT21 + Brightness via LED #define HAS_SHT21_BRIGHTNESS - SHT21 + Brightness via LED
#define HAS_BME280_BRIGHTNESS - BME280 + Brightness via LED #define HAS_BME280_BRIGHTNESS - BME280 + Brightness via LED
#define HAS_ALARM - send message when pin is triggered #define HAS_ALARM - send message when pin is triggered
#define HAS_SHT21_ALARM - combined Sensor with SHT21 and Alarm trigger
#define HAS_BME280_ALARM - combined Sensor with BME280 and Alarm trigger
* LED Support * LED Support
#define LED_PIN PIN_A7 - LED is connected to ATTiny84 Pin A7 on TinyTX SMD / TinyLora #define LED_PIN PIN_A7 - LED is connected to ATTiny84 Pin A7 on TinyTX SMD / TinyLora
@ -22,8 +24,7 @@
#define LED_A PIN_B2 - LED Anode #define LED_A PIN_B2 - LED Anode
* Alarm * Alarm
#define ALARM_PIN PIN_A0 #define ALARM_PIN PIN_A0 - The pin defined here will trigger an immideate send if pulled low.
if pin changed , change also PCMSK0 = (1<<PCINT0); to corrent PCINT
* Time between Measurements * Time between Measurements
#define SLEEP_TIME 528 - Time in Seconds between Measurements. Try it out to get a good Approximation #define SLEEP_TIME 528 - Time in Seconds between Measurements. Try it out to get a good Approximation