Skip to content

Commit

Permalink
Fixed integrated GPIO dashcam save trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Sep 2, 2024
1 parent 5acd8f3 commit 5e7e4e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions dashcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,12 @@
last_trigger_file_created = 0
def create_trigger_file():
global last_trigger_file_created
if (time.time() - last_trigger_file_created < 1):
if (time.time() - last_trigger_file_created > 1): # Check to see if the time that has passed since the last trigger file is more than 1 second.
if (os.path.isdir(config["general"]["interface_directory"]) == False): # Check to see if the interface directory has not yet been created.
os.system("mkdir -p '" + str(config["general"]["interface_directory"]) + "'")
os.system("chmod -R 777 '" + str(config["general"]["interface_directory"]) + "'")
os.system("touch '" + trigger_file_location + "'")
else:
print("Supressed duplicate trigger file")
last_strigger_file_created
last_trigger_file_created = time.time()

def watch_button(pin, hold_time=0.2, event=create_trigger_file):
print("Watching pin " + str(pin))
Expand All @@ -178,6 +176,7 @@ def watch_button(pin, hold_time=0.2, event=create_trigger_file):
time_pressed = time.time()
elif (button.is_pressed and time.time() - time_pressed >= hold_time): # Check to see if the button is being held, and the time threshold has been reached.
print("Triggered " + str(pin))
last_triggered = 0
event()
elif (button.is_pressed == False): # If the button is not pressed, reset the timer.
time_pressed = 0
Expand Down
4 changes: 2 additions & 2 deletions tools/gpio_dashcam_save_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ def watch_button(pin, hold_time=0.2, event=create_trigger_file):
last_triggered = 0
while True:
if (button.is_pressed and time_pressed == 0): # Check to see if the button was just pressed.
print("Pressed" + str(pin))
#print("Pressed" + str(pin))
time_pressed = time.time()
elif (button.is_pressed and time.time() - time_pressed < hold_time): # Check to see if the button is being held, but the time threshold hasn't been reached.
pass
#print("Holding")
elif (button.is_pressed and time.time() - time_pressed >= hold_time): # Check to see if the button is being held, and the time threshold has been reached.
if (time.time() - last_triggered > 1):
print("Triggered " + str(pin))
#print("Triggered " + str(pin))
event()
last_triggered = time.time()
elif (button.is_pressed == False): # If the button is not pressed, reset the timer.
Expand Down

0 comments on commit 5e7e4e5

Please sign in to comment.