pitlane/main.c

changeset 65
8960bfa02f63
parent 64
61f88f973eba
child 66
1e220602b7a7
--- a/pitlane/main.c	Fri Dec 09 21:17:36 2011 +0100
+++ b/pitlane/main.c	Fri Dec 09 22:02:34 2011 +0100
@@ -27,6 +27,10 @@
 #define TRACKSWITCH_TYPE 2 // 1=double, 2=single, 3=pitlane
 #define MAX_SENSORS 3
 
+#define PIT_PORT        PORTC
+#define PIT_CONNECT_PIN PC3
+#define PIT_GROUND_PIN  PC2 // low active
+
 // internal analog comparator doesnt work well
 //#define ANALOG_COMPARATOR       1
 
@@ -189,7 +193,6 @@
     detect_car(0);
 }
 
-// ISR (TIMER1_CAPT_vect) {
 #ifdef ANALOG_COMPARATOR
 ISR (ANA_COMP_vect) {
     // car1 detector
@@ -247,6 +250,13 @@
     DDR(RESPONSE_PORT) &= ~_BV(RESPONSE_PIN); // switch response off
     RESPONSE_PORT &= ~_BV(RESPONSE_PIN); // switch response off
 
+    // setup pitlane output
+    DDR(PIT_PORT) |= _BV(PIT_CONNECT_PIN) | _BV(PIT_GROUND_PIN);
+
+    // CONNECT PITLANE TO MAIN TRACK
+    PIT_PORT &= ~_BV(PIT_CONNECT_PIN);
+    PIT_PORT |= _BV(PIT_GROUND_PIN);
+
     while (1) {
         // main loop
 
@@ -255,11 +265,16 @@
         1 = AB
         2 = BB
         3 = BA
+        4 = ZZ -> pitlane exit
     */
         if (sens[0].car != sens[0].state) {
             sens[0].state = sens[0].car;
             if ( (sens[0].state != 0) && (slot[sens[0].state-1].trackswitch == 0) && (slot[sens[0].state-1].speed>0) ) {
                 response = (1 | ((sens[0].state-1)<<1) | (1 << 4));
+
+                // set inside status
+                slot[sens[0].state].inside = 1;
+
                 // trigger solenoid A
                 RS232_putc('A');
                 RS232_putc('B');
@@ -285,6 +300,10 @@
             sens[1].state = sens[1].car;
             if ( (sens[1].state != 0) && (slot[sens[1].state-1].trackswitch == 0) && (slot[sens[1].state-1].speed>0) ) {
                 response = (1 | ((sens[1].state-1)<<1) | (3 << 4));
+
+                // set inside status
+                slot[sens[1].state-1].inside = 1;
+
                 // trigger solenoid B
                 RS232_putc('B');
                 RS232_putc('A');
@@ -303,7 +322,23 @@
                 RS232_putc('0'+sens[1].state);
                 RS232_putc('\n');
             }
-        } sens[0].car = 0;
+        } sens[1].car = 0;
+
+
+        if (sens[2].car != sens[2].state) {
+            sens[2].state = sens[2].car;
+            if (sens[2].state != 0) {
+                response = (1 | ((sens[2].state-1)<<1) | (4 << 4));
+
+                // set inside status
+                slot[sens[2].state-1].inside = 0;
+
+                RS232_putc('Z');
+                RS232_putc('Z');
+                RS232_putc('0'+sens[2].state);
+                RS232_putc('\n');
+            }
+        } sens[2].car = 0;
 
 
     } // main loop end

mercurial