test
This commit is contained in:
parent
616a3af2c0
commit
6d4965095d
|
@ -66,7 +66,7 @@
|
|||
SHT21 sensor;
|
||||
#endif
|
||||
|
||||
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM || defined HAS_MANNLCOUNTER
|
||||
#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
|
||||
|
@ -93,9 +93,23 @@
|
|||
#endif
|
||||
|
||||
#ifdef HAS_MANNLCOUNTER
|
||||
volatile uint16_t count_min = 0;
|
||||
volatile uint32_t count_all = 0;
|
||||
volatile unsigned long alteZeit=0, entprellZeit=20; //ms
|
||||
#include <util/delay.h>
|
||||
uint16_t count_min = 0;
|
||||
uint32_t count_all = 0;
|
||||
unsigned long lastTime = millis();
|
||||
|
||||
void entprellung( volatile uint8_t *port, uint8_t maske ) {
|
||||
uint8_t port_puffer;
|
||||
uint8_t entprellungs_puffer;
|
||||
|
||||
for( entprellungs_puffer=0 ; entprellungs_puffer!=0xff ; ) {
|
||||
entprellungs_puffer<<=1;
|
||||
port_puffer = *port;
|
||||
_delay_us(150);
|
||||
if( (*port & maske) == (port_puffer & maske) )
|
||||
entprellungs_puffer |= 0x01;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Global Variable to Track Deep Sleep
|
||||
|
@ -140,6 +154,7 @@ int16_t brightness()
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAS_MANNLCOUNTER
|
||||
// Setup Wakeup Interrupt Timer
|
||||
void init_wdt()
|
||||
{
|
||||
|
@ -179,29 +194,20 @@ ISR(WATCHDOG_vect) {
|
|||
// enable WDT interrupt
|
||||
WDTCSR = (1<<WDIE)|(1<<WDP3)|(1<<WDP0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM || defined HAS_MANNLCOUNTER
|
||||
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM
|
||||
// innterrupt handler pin change
|
||||
ISR(PCINT0_vect)
|
||||
{
|
||||
#ifdef HAS_MANNLCOUNTER //counter mode
|
||||
if((millis() - alteZeit) > entprellZeit) {
|
||||
// innerhalb der entprellZeit nichts machen
|
||||
count_min++;
|
||||
count_all++;
|
||||
alteZeit = millis(); // last button push
|
||||
}
|
||||
|
||||
#else //Alarm mode
|
||||
sleep_disable();
|
||||
#ifdef HAS_LED
|
||||
blink(1);
|
||||
#endif
|
||||
alarm = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Get Battery Voltage
|
||||
int32_t readVcc() {
|
||||
bitClear(PRR, PRADC);
|
||||
|
@ -237,9 +243,11 @@ uint8_t calcEepromAddr(uint16_t framecounter) {
|
|||
|
||||
void setup()
|
||||
{
|
||||
#ifndef HAS_MANNLCOUNTER
|
||||
// Initialize Sleep Timer
|
||||
init_wdt();
|
||||
PRR = bit(PRTIM1);
|
||||
#endif
|
||||
|
||||
#ifdef RF_LORA
|
||||
// Setup LoraWAN
|
||||
|
@ -281,7 +289,7 @@ void setup()
|
|||
radio.sleep();
|
||||
#endif
|
||||
|
||||
#if defined HAS_ALARM || defined HAS_SHT21_ALARM || defined HAS_BME280_ALARM || defined HAS_MANNLCOUNTER
|
||||
#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<<ALARM_INT);
|
||||
|
@ -388,11 +396,6 @@ void loop()
|
|||
alarm = false;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_MANNLCOUNTER
|
||||
data.count_all=count_all;
|
||||
data.count_min=count_min;
|
||||
#endif
|
||||
|
||||
#if defined DS18B20_PIN
|
||||
|
||||
#ifdef DS18B20_POWER
|
||||
|
@ -411,6 +414,23 @@ void loop()
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAS_MANNLCOUNTER
|
||||
|
||||
while(millis() - lastTime < 60000){
|
||||
entprellung( &PINA, (1<<PINA0) ); // ggf. Prellen abwarten
|
||||
if( PINA & (1<<PINA0) ) // dann stabilen Wert einlesen
|
||||
{
|
||||
count_all++;
|
||||
count_min++;
|
||||
}
|
||||
}
|
||||
lastTime = millis();
|
||||
// nach 60 sek
|
||||
data.count_all=count_all;
|
||||
data.count_min=count_min;
|
||||
#endif
|
||||
|
||||
|
||||
// Add Battery Voltage, 20mv steps, encoded into 1 Byte
|
||||
uint32_t batv = readVcc();
|
||||
data.bat = (uint8_t)(batv/20);
|
||||
|
@ -436,9 +456,6 @@ void loop()
|
|||
#else
|
||||
// Send LoRa Packet, Increment Frame Counter
|
||||
lora.Send_Data((unsigned char *)&data, sizeof(data), Frame_Counter_Tx, SF7BW125, 0x01);
|
||||
#ifdef HAS_MANNLCOUNTER
|
||||
count_min = 0;
|
||||
#endif
|
||||
#endif
|
||||
// Save the next FrameCounter to EEPROM
|
||||
Frame_Counter_Tx++;
|
||||
|
@ -455,6 +472,8 @@ void loop()
|
|||
digitalWrite(LED_PIN, 0);
|
||||
#endif
|
||||
|
||||
#ifndef HAS_MANNLCOUNTER
|
||||
// Sleep until next Measurement
|
||||
sleep(SLEEP_TIME);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue