#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <wiringPi.h>
#include <time.h>
#include "config.h"
{
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);
}
}
- // 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;