Sync pin stuff
authorCameron Ball <c.ball1729@gmail.com>
Thu, 9 Apr 2015 14:13:44 +0000 (14:13 +0000)
committerCameron Ball <c.ball1729@gmail.com>
Thu, 9 Apr 2015 14:13:44 +0000 (14:13 +0000)
main.c

diff --git a/main.c b/main.c
index 4de6e4b..32b928c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -7,6 +7,7 @@
 
 #define COIN_BUTTON 7 //physically pin 7
 #define SYNC_PIN 4 //physically pin 16
+#define PULSE_PIN 1 //physically pin 12
 
 configuration config;
 int expires = -1;
@@ -18,6 +19,9 @@ void init_gpio()
   wiringPiSetup();
   pinMode(COIN_BUTTON, INPUT);
   pinMode(SYNC_PIN, INPUT);
+  pinMode(PULSE_PIN, OUTPUT);
+  digitalWrite(PULSE_PIN, 0); //just to be sure
+
   pullUpDnControl(COIN_BUTTON, PUD_UP);
   pullUpDnControl(SYNC_PIN, PUD_UP);
 }
@@ -25,7 +29,10 @@ void init_gpio()
 void pulse_switch()
 {
   delay(config.sync_switch_delay); //wait
-  // do the biz
+  digitalWrite(PULSE_PIN, 1);
+  delay(10);
+  digitalWrite(PULSE_PIN, 0);
+  delay(10);
 }
 
 int validate_switch_state()
@@ -57,6 +64,10 @@ int time_over()
     printf("It's all ogre now\n");
     expires = -1;
     switch_state = 1 - switch_state;
+
+    if(config.sync_switch == 0) //naively pulse
+      pulse_switch();
+
     return 1;
   }
 
@@ -84,6 +95,9 @@ int read_button()
       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.sync_switch == 0) //naively pulse the switch
+          pulse_switch();
     }
 
     if(config.external_timer != 1)