[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
// 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>
BME280 sensor;
#endif
#if defined HAS_SHT21 || defined HAS_SHT21_BRIGHTNESS
#if defined HAS_SHT21 || defined HAS_SHT21_BRIGHTNESS || defined HAS_SHT21_ALARM
#include <SHT21.h>
SHT21 sensor;
#endif
#ifdef HAS_ALARM
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
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
// Global Variable to Track Deep Sleep
@ -133,7 +148,7 @@ void sleep(uint16_t s)
sleep_interval = 0;
while (sleep_interval < s) {
// 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){
return;
}
@ -154,13 +169,15 @@ ISR(WATCHDOG_vect) {
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
ISR(PCINT0_vect)
{
sleep_disable();
blink(1);
alarm = true;
sleep_disable();
#ifdef HAS_LED
blink(1);
#endif
alarm = true;
}
#endif
@ -243,10 +260,10 @@ void setup()
radio.sleep();
#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
GIMSK = (1<<PCIE0);
PCMSK0 = (1<<PCINT0); // PCINT(PA0)
PCMSK0 = (1<<ALARM_INT);
pinMode(ALARM_PIN, INPUT_PULLUP);
#endif
@ -297,14 +314,29 @@ void loop()
int32_t pressure;
int16_t brightness;
} __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
// 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);
#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.humidity = (int32_t)(sensor.getHumidity()*100);
#endif
@ -313,8 +345,8 @@ void loop()
data.brightness = (int16_t)(brightness());
#endif
#if defined HAS_ALARM
data.alarm = (uint8_t)alarm;
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
data.alarm = alarm;
alarm = false;
#endif

View file

@ -12,6 +12,8 @@
#define HAS_SHT21_BRIGHTNESS - SHT21 + Brightness via LED
#define HAS_BME280_BRIGHTNESS - BME280 + Brightness via LED
#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
#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
* Alarm
#define ALARM_PIN PIN_A0
if pin changed , change also PCMSK0 = (1<<PCINT0); to corrent PCINT
#define ALARM_PIN PIN_A0 - The pin defined here will trigger an immideate send if pulled low.
* Time between Measurements
#define SLEEP_TIME 528 - Time in Seconds between Measurements. Try it out to get a good Approximation