From 9c84dc5b65caf8440b64209f5334d158ab307e64 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Fri, 27 Mar 2015 07:20:11 +0000 Subject: [PATCH] Refoctor code. Add version output --- main.c | 38 +++++++++++++++++++++++++++----------- start.sh | 1 + 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/main.c b/main.c index 35519e1..4de6e4b 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "config.h" @@ -66,6 +67,25 @@ int read_button() { if(digitalRead(COIN_BUTTON) == LOW) { + // Don't do anything until button is released + while(digitalRead(COIN_BUTTON) == LOW) + { + //I don't see this happening, but in principle if the button is held down + //It would be possible to stop the switch happening after time runs out + //So we must check for that here. + time_over(); + delay(10); + } + + // Flip internal switch state, but only if we are in the default state + // i.e., waiting for a credit + if(config.default_switch_state == switch_state) + { + printf("Changing internal switch state from %d\n", switch_state); + switch_state = 1 - switch_state; + printf("Switch state is now %d\n", switch_state); + } + if(config.external_timer != 1) { printf("Nice! I just added %d to your time.\n", config.credit_value); @@ -91,24 +111,20 @@ int read_button() } } - // Flip switch state - // But only if we are in the default state (IE waiting for a credit) - if(config.default_switch_state == switch_state) - { - printf("Changing internal switch state from %d\n", switch_state); - switch_state = 1 - switch_state; - printf("Switch state is now %d\n", switch_state); - } - return 1; } return 0; } -int main (void) +int main (int argc, char *argv[]) { - printf("hdmi-switcher %s\n", VERSION); + if(argc == 2 && strcmp("version", argv[1]) == 0) + { + printf("hdmi-switcher %s\n", VERSION); + exit(1); + } + init_config(&config); init_gpio(); switch_state = config.default_switch_state; diff --git a/start.sh b/start.sh index ece8387..8f67f44 100755 --- a/start.sh +++ b/start.sh @@ -1,4 +1,5 @@ #!/bin/bash +/home/pi/hdmi-switcher/hdmi-switcher version /home/pi/hdmi-switcher/update.sh printf "Starting video... " sleep 5 -- 2.11.0