diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..37e82ff --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/librares/Watchdog"] + path = vendor/librares/Watchdog + url = git@github.com:janelia-arduino/Watchdog.git diff --git a/hsldz_totp_lock/hsldz_totp_lock.ino b/hsldz_totp_lock/hsldz_totp_lock.ino index d8ee949..3b0b608 100644 --- a/hsldz_totp_lock/hsldz_totp_lock.ino +++ b/hsldz_totp_lock/hsldz_totp_lock.ino @@ -4,7 +4,8 @@ #include #include #include -#include +#include +#include #define BUZZER_PIN 10 @@ -49,6 +50,7 @@ Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS // RTC RTClib RTC; +Watchdog watchdog; const bool morseKeys[10][5] = { @@ -92,12 +94,14 @@ String userInputPrev = ""; void setup(){ + watchdog.reset(); Serial.begin(9600); Wire.begin(); eeprom.initialize(); pinMode(BUTTON_OPEN_PIN, INPUT); pinMode(BUZZER_PIN, OUTPUT); pinMode(LOCK_PIN, OUTPUT); + watchdog.enable(Watchdog::TIMEOUT_8S); int size = sizeof(melodyMain) / sizeof(int); playMaintenanceMelody(melodyMain, size); } @@ -111,6 +115,7 @@ void echo_morse_reversed_int(unsigned long value) { // Serial.println(digit); delay(MORSE_SOUND_TIME * MORSE_PAUSE); for(int i =0; i < 5; i++ ) { + watchdog.reset(); if (morseKeys[digit][i]) { tone(BUZZER_PIN, MORSE_FREQ, MORSE_SOUND_TIME); delay(MORSE_SOUND_TIME + MORSE_SOUND_TIME); @@ -263,6 +268,7 @@ void buzz(int targetPin, long frequency, long length) { void playMaintenanceMelody(int melody[], int size) { int melodyPin = BUZZER_PIN; for (int thisNote = 0; thisNote < size; thisNote++) { + watchdog.reset(); // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. @@ -349,7 +355,7 @@ void makeMaintenance(String userInputPrev) { void loop(){ - + watchdog.reset(); digitalWrite(LOCK_PIN, LOW); boolean openButtonIsDown = digitalRead(BUTTON_OPEN_PIN); if (openButtonIsDown) { @@ -359,6 +365,7 @@ void loop(){ int limit = 7; int press_counter = 0; for (int i = 0; i < iterations; i++) { + watchdog.reset(); tone(BUZZER_PIN, FREQ_OPEN_BUTTON_PRESS, timeout - 10); delay(timeout); if (digitalRead(BUTTON_OPEN_PIN) == HIGH) { @@ -374,6 +381,7 @@ void loop(){ char customKey = customKeypad.getKey(); if (customKey){ + watchdog.reset(); tone(BUZZER_PIN, FREQ_BUTTON_PRESS, SOUND_TIME_BUTTON_PRESS); if (customKey == '*') { userInput = ""; diff --git a/vendor/librares/Watchdog b/vendor/librares/Watchdog new file mode 160000 index 0000000..7cbbb1b --- /dev/null +++ b/vendor/librares/Watchdog @@ -0,0 +1 @@ +Subproject commit 7cbbb1b017131973f8d762bb0eec0531f288a08c