Skip to content

Commit

Permalink
Merge pull request #8 from hakierspejs/watchdog
Browse files Browse the repository at this point in the history
Add watchdog
  • Loading branch information
cb4b1fd915 committed Jun 30, 2024
2 parents 28f1b36 + 635257a commit 1833667
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/librares/Watchdog"]
path = vendor/librares/Watchdog
url = [email protected]:janelia-arduino/Watchdog.git
12 changes: 10 additions & 2 deletions hsldz_totp_lock/hsldz_totp_lock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <DS3231.h>
#include <Wire.h>
#include <Eeprom24C32_64.h>
#include <Eeprom24C04_16.h>
#include <Eeprom24C04_16.h>
#include <Watchdog.h>


#define BUZZER_PIN 10
Expand Down Expand Up @@ -49,6 +50,7 @@ Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS
// RTC
RTClib RTC;

Watchdog watchdog;


const bool morseKeys[10][5] = {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -349,7 +355,7 @@ void makeMaintenance(String userInputPrev) {


void loop(){

watchdog.reset();
digitalWrite(LOCK_PIN, LOW);
boolean openButtonIsDown = digitalRead(BUTTON_OPEN_PIN);
if (openButtonIsDown) {
Expand All @@ -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) {
Expand All @@ -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 = "";
Expand Down
1 change: 1 addition & 0 deletions vendor/librares/Watchdog
Submodule Watchdog added at 7cbbb1

0 comments on commit 1833667

Please sign in to comment.