Compare commits

...

2 Commits

Author SHA1 Message Date
andreask 4dfb136693 Merge branch 'mannl-counter' of https://www.seiichiro0185.org/git/IOT/tinylora into mannl-counter 2020-09-06 00:10:17 +02:00
andreask f5ae34863b working sample 2020-09-06 00:06:11 +02:00
1 changed files with 48 additions and 20 deletions

View File

@ -98,18 +98,42 @@
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;
#define debounce( port, pin ) \
({ \
static uint8_t flag = 0; /* new variable on every macro usage */ \
uint8_t i = 0; \
\
if( flag ){ /* check for key release: */ \
for(;;){ /* loop ... */ \
if( !(port & 1<<pin) ){ /* ... until key pressed or ... */ \
i = 0; /* 0 = bounce */ \
break; \
} \
_delay_us( 98 ); /* * 256 = 25ms */ \
if( --i == 0 ){ /* ... until key >25ms released */ \
flag = 0; /* clear press flag */ \
i = 0; /* 0 = key release debounced */ \
break; \
} \
} \
}else{ /* else check for key press: */ \
for(;;){ /* loop ... */ \
if( (port & 1<<pin) ){ /* ... until key released or ... */ \
i = 0; /* 0 = bounce */ \
break; \
} \
_delay_us( 98 ); /* * 256 = 25ms */ \
if( --i == 0 ){ /* ... until key >25ms pressed */ \
flag = 1; /* set press flag */ \
i = 1; /* 1 = key press debounced */ \
break; \
} \
} \
} \
i; /* return value of Macro */ \
})
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
@ -244,9 +268,9 @@ uint8_t calcEepromAddr(uint16_t framecounter) {
void setup()
{
#ifndef HAS_MANNLCOUNTER
// Initialize Sleep Timer
init_wdt();
PRR = bit(PRTIM1);
// Initialize Sleep Timer
init_wdt();
PRR = bit(PRTIM1);
#endif
#ifdef RF_LORA
@ -415,19 +439,23 @@ void loop()
#endif
#ifdef HAS_MANNLCOUNTER
pinMode(ALARM_PIN, INPUT_PULLUP);
// FIXME Timer interrupt
while(millis() - lastTime < 60000){
entprellung( &PINA, (1<<PINA0) ); // ggf. Prellen abwarten
if( PINA & (1<<PINA0) ) // dann stabilen Wert einlesen
{
count_all++;
if( debounce( PINA, PA0 ) ){
count_min++;
count_all++;
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
}
}
lastTime = millis();
// nach 60 sek
data.count_all=count_all;
data.count_min=count_min;
count_min=0;
// nach 60 sek
#endif