aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2016-05-05 21:07:37 +0200
committerjaseg <code@jaseg.net>2016-05-05 21:31:02 +0200
commit65aaea23bfa1dc131589134563224ca4f4dc2789 (patch)
tree4e889e3d677c853372cc5cd31b904408bceb58d4
parentf49a062cf261e70af5b045e5ae63a14dd80f452b (diff)
downloadcccb-klingel-65aaea23bfa1dc131589134563224ca4f4dc2789.tar.gz
cccb-klingel-65aaea23bfa1dc131589134563224ca4f4dc2789.tar.bz2
cccb-klingel-65aaea23bfa1dc131589134563224ca4f4dc2789.zip
Add thursday mode timeout
-rw-r--r--main.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/main.c b/main.c
index 6d8639d..21864d1 100644
--- a/main.c
+++ b/main.c
@@ -10,11 +10,13 @@
#define MIN_PULSE_WIDTH_MS 50
#define RING_DURATION_SEC 20
#define OPEN_DURATION_SEC 3
+#define THURSDAY_TIMEOUT_MIN 90UL
-#define PRESSED_MIN_MS 250
-#define RELEASED_MIN_MS 250
+#define PRESSED_MIN_MS 250UL
+#define RELEASED_MIN_MS 250UL
-uint8_t global_thursday_mode = 0;
+static uint8_t global_thursday_mode = 0;
+static uint16_t global_thursday_timectr_sec = 0;
void tx_str(const char * PROGMEM s) {
uint8_t c;
@@ -64,6 +66,7 @@ uint8_t handle_open_button(void) {
void ring(void) {
if (global_thursday_mode) {
tx_str(PSTR("THUA Thursday mode auto open\r\n"));
+ global_thursday_timectr_sec = 0;
open();
} else {
tx_str(PSTR("RING Ringing\r\n"));
@@ -83,6 +86,7 @@ void code(void) {
void set_thursday_mode(uint8_t mode) {
global_thursday_mode = mode;
+ global_thursday_timectr_sec = 0;
tx_str(mode ? PSTR("THU1 Thursday mode set to on\r\n") : PSTR("THU0 Thursday mode set to off\r\n"));
@@ -164,6 +168,12 @@ int main(void) {
codefail = 0;
thursday_toggle_timeout = 0;
TCNT1 = 0;
+
+ global_thursday_timectr_sec += TIMEOUT_SEC;
+ if (global_thursday_timectr_sec >= THURSDAY_TIMEOUT_MIN*60) {
+ tx_str(PSTR("TOUT Thursday mode timeout\r\n"));
+ set_thursday_mode(0);
+ }
} else {
uint8_t st = PINC&1;
if (st == (pidx&1)) {