pitlane/main.c

changeset 67
369487be7c65
parent 66
1e220602b7a7
child 68
c3460121ad8b
equal deleted inserted replaced
66:1e220602b7a7 67:369487be7c65
22 #define SOLENOID_A_PORT PORTB 22 #define SOLENOID_A_PORT PORTB
23 #define SOLENOID_B_PORT PORTB 23 #define SOLENOID_B_PORT PORTB
24 #define SOLENOID_A_PIN PB1 24 #define SOLENOID_A_PIN PB1
25 #define SOLENOID_B_PIN PB2 25 #define SOLENOID_B_PIN PB2
26 26
27 #define TRACKSWITCH_TYPE 2 // 1=double, 2=single, 3=pitlane 27 #define TRACKSWITCH_TYPE 4 // 1=double, 2=single, 4=pitlane
28 #define TYPE_PITLANE 4
29
28 #define MAX_SENSORS 3 30 #define MAX_SENSORS 3
29 31
30 #define PIT_PORT PORTC 32 #define PIT_PORT PORTC
31 #define PIT_CONNECT_PIN PC3 33 #define PIT_CONNECT_PIN PC3
32 #define PIT_GROUND_PIN PC2 // low active 34 #define PIT_GROUND_PIN PC2 // low active
34 #define SENS2_PORT PORTD 36 #define SENS2_PORT PORTD
35 #define SENS2_PIN PD5 37 #define SENS2_PIN PD5
36 38
37 #define LED_PORT PORTB 39 #define LED_PORT PORTB
38 #define LED_PIN PB5 40 #define LED_PIN PB5
41
39 42
40 // internal analog comparator doesnt work well 43 // internal analog comparator doesnt work well
41 //#define ANALOG_COMPARATOR 1 44 //#define ANALOG_COMPARATOR 1
42 45
43 typedef struct { 46 typedef struct {
276 0 = AA 279 0 = AA
277 1 = AB 280 1 = AB
278 2 = BB 281 2 = BB
279 3 = BA 282 3 = BA
280 4 = ZZ -> pitlane exit 283 4 = ZZ -> pitlane exit
284 5 = BC
281 */ 285 */
282 if (sens[0].car != sens[0].state) { 286 if (sens[0].car != sens[0].state) {
283 sens[0].state = sens[0].car; 287 sens[0].state = sens[0].car;
288 #if TRACKSWITCH_TYPE != TYPE_PITLANE
284 if ( (sens[0].state != 0) && (slot[sens[0].state-1].trackswitch == 0) && (slot[sens[0].state-1].speed>0) ) { 289 if ( (sens[0].state != 0) && (slot[sens[0].state-1].trackswitch == 0) && (slot[sens[0].state-1].speed>0) ) {
285 response = (1 | ((sens[0].state-1)<<1) | (1 << 4)); 290 response = (1 | ((sens[0].state-1)<<1) | (1 << 4));
286 291
287 // set inside status 292 // set inside status
288 slot[sens[0].state].inside = 1; 293 slot[sens[0].state].inside = 1;
296 SOLENOID_A_PORT |= _BV(SOLENOID_A_PIN); 301 SOLENOID_A_PORT |= _BV(SOLENOID_A_PIN);
297 solenoid_delay(); 302 solenoid_delay();
298 SOLENOID_A_PORT &= ~_BV(SOLENOID_A_PIN); 303 SOLENOID_A_PORT &= ~_BV(SOLENOID_A_PIN);
299 solenoid_delay(); 304 solenoid_delay();
300 } 305 }
306 #endif
301 if (sens[0].state != 0) { 307 if (sens[0].state != 0) {
302 response = (1 | ((sens[0].state-1)<<1)); 308 response = (1 | ((sens[0].state-1)<<1));
303 RS232_putc('A'); 309 RS232_putc('A');
304 RS232_putc('A'); 310 RS232_putc('A');
305 RS232_putc('0'+sens[0].state); 311 RS232_putc('0'+sens[0].state);
309 315
310 316
311 if (sens[1].car != sens[1].state) { 317 if (sens[1].car != sens[1].state) {
312 sens[1].state = sens[1].car; 318 sens[1].state = sens[1].car;
313 if ( (sens[1].state != 0) && (slot[sens[1].state-1].trackswitch == 0) && (slot[sens[1].state-1].speed>0) ) { 319 if ( (sens[1].state != 0) && (slot[sens[1].state-1].trackswitch == 0) && (slot[sens[1].state-1].speed>0) ) {
314 response = (1 | ((sens[1].state-1)<<1) | (3 << 4)); 320 response = (1 | ((sens[1].state-1)<<1) | (5 << 4));
315 321
316 // set inside status 322 // set inside status
317 slot[sens[1].state-1].inside = 1; 323 slot[sens[1].state-1].inside = 1;
318 324
319 // trigger solenoid B 325 // trigger solenoid B
320 RS232_putc('B'); 326 RS232_putc('B');
321 RS232_putc('A'); 327 RS232_putc('C');
322 RS232_putc('0'+sens[1].state); 328 RS232_putc('0'+sens[1].state);
323 RS232_putc('\n'); 329 RS232_putc('\n');
324 330
325 SOLENOID_B_PORT |= _BV(SOLENOID_B_PIN); 331 SOLENOID_B_PORT |= _BV(SOLENOID_B_PIN);
326 solenoid_delay(); 332 solenoid_delay();

mercurial