13 |
13 |
14 |
14 |
15 ISR ( USART_RXC_vect ) { |
15 ISR ( USART_RXC_vect ) { |
16 } |
16 } |
17 |
17 |
|
18 // TODO: TYPE should be configured somewhere else |
|
19 #define TRACKSWITCH_TYPE 1 // 1=double, 2=single left, 3=single right, 4=pitlane |
|
20 #define TYPE_DOUBLE 1 |
|
21 #define TYPE_SINGLE_L 2 |
|
22 #define TYPE_SINGLE_R 3 |
|
23 #define TYPE_PITLANE 4 |
|
24 |
|
25 |
18 #define PULSE_PORT PORTD |
26 #define PULSE_PORT PORTD |
19 #define PULSE_BIT PD2 |
27 #define PULSE_BIT PD2 |
20 |
28 |
21 #define RESPONSE_PORT PORTC |
29 #define RESPONSE_PORT PORTC |
22 #define RESPONSE_PIN PC1 |
30 #define RESPONSE_PIN PC1 |
23 |
31 |
24 #define SOLENOID_A_PORT PORTB |
32 #define SOLENOID_A_PORT PORTB |
25 #define SOLENOID_B_PORT PORTB |
33 #define SOLENOID_B_PORT PORTB |
26 |
34 |
27 #define TRACKSWITCH_TYPE 1 // 1=double, 2=single |
35 #ifdef WE_HAVE_TO_REVERSE_PORTS_ON_DOUBLE_SWITCH |
28 |
36 //#if (TRACKSWITCH_TYPE == TYPE_DOUBLE) |
29 #define SOLENOID_A_PIN PB1 |
37 // switch outputs - note: car0+1 have also be swapped! |
30 #define SOLENOID_B_PIN PB2 |
38 // todo in future |
|
39 #define SOLENOID_A_PIN PB2 |
|
40 #define SOLENOID_B_PIN PB1 |
|
41 #else |
|
42 #define SOLENOID_A_PIN PB1 |
|
43 #define SOLENOID_B_PIN PB2 |
|
44 #endif |
31 |
45 |
32 // internal analog comparator doesnt work well |
46 // internal analog comparator doesnt work well |
33 //#define ANALOG_COMPARATOR 1 |
47 //#define ANALOG_COMPARATOR 1 |
34 |
48 |
35 volatile uint16_t data = 0; |
49 volatile uint16_t data = 0; |
268 2 = BB |
282 2 = BB |
269 3 = BA |
283 3 = BA |
270 */ |
284 */ |
271 if (car0 != car0_state) { |
285 if (car0 != car0_state) { |
272 car0_state = car0; |
286 car0_state = car0; |
|
287 #if (TRACKSWITCH_TYPE == TYPE_DOUBLE) || (TRACKSWITCH_TYPE == TYPE_SINGLE_R) |
273 if ( (car0_state != 0) && (car_switch[car0_state-1] == 0) && (car_speed[car0_state-1]>0) ) { |
288 if ( (car0_state != 0) && (car_switch[car0_state-1] == 0) && (car_speed[car0_state-1]>0) ) { |
274 response = (1 | ((car0_state-1)<<1) | (1 << 4)); |
289 response = (1 | ((car0_state-1)<<1) | (1 << 4)); |
275 // trigger solenoid A |
290 // trigger solenoid A |
276 RS232_putc('A'); |
291 RS232_putc('A'); |
277 RS232_putc('B'); |
292 RS232_putc('B'); |
280 |
295 |
281 SOLENOID_A_PORT |= _BV(SOLENOID_A_PIN); |
296 SOLENOID_A_PORT |= _BV(SOLENOID_A_PIN); |
282 solenoid_delay(); |
297 solenoid_delay(); |
283 SOLENOID_A_PORT &= ~_BV(SOLENOID_A_PIN); |
298 SOLENOID_A_PORT &= ~_BV(SOLENOID_A_PIN); |
284 solenoid_delay(); |
299 solenoid_delay(); |
285 } |
300 } else |
|
301 #endif |
286 if (car0_state != 0) { |
302 if (car0_state != 0) { |
287 response = (1 | ((car0_state-1)<<1)); |
303 response = (1 | ((car0_state-1)<<1)); |
288 RS232_putc('A'); |
304 RS232_putc('A'); |
289 RS232_putc('A'); |
305 RS232_putc('A'); |
290 RS232_putc('0'+car0_state); |
306 RS232_putc('0'+car0_state); |
293 } car0 = 0; |
309 } car0 = 0; |
294 |
310 |
295 |
311 |
296 if (car1 != car1_state) { |
312 if (car1 != car1_state) { |
297 car1_state = car1; |
313 car1_state = car1; |
|
314 #if (TRACKSWITCH_TYPE == TYPE_DOUBLE) || (TRACKSWITCH_TYPE == TYPE_SINGLE_L) |
298 if ( (car1_state != 0) && (car_switch[car1_state-1] == 0) && (car_speed[car1_state-1]>0) ) { |
315 if ( (car1_state != 0) && (car_switch[car1_state-1] == 0) && (car_speed[car1_state-1]>0) ) { |
299 response = (1 | ((car1_state-1)<<1) | (3 << 4)); |
316 response = (1 | ((car1_state-1)<<1) | (3 << 4)); |
300 // trigger solenoid B |
317 // trigger solenoid B |
301 RS232_putc('B'); |
318 RS232_putc('B'); |
302 RS232_putc('A'); |
319 RS232_putc('A'); |
305 |
322 |
306 SOLENOID_B_PORT |= _BV(SOLENOID_B_PIN); |
323 SOLENOID_B_PORT |= _BV(SOLENOID_B_PIN); |
307 solenoid_delay(); |
324 solenoid_delay(); |
308 SOLENOID_B_PORT &= ~_BV(SOLENOID_B_PIN); |
325 SOLENOID_B_PORT &= ~_BV(SOLENOID_B_PIN); |
309 solenoid_delay(); |
326 solenoid_delay(); |
310 } |
327 } else |
|
328 #endif |
311 if (car1_state != 0) { |
329 if (car1_state != 0) { |
312 response = (1 | ((car1_state-1)<<1) | (2 << 4)); |
330 response = (1 | ((car1_state-1)<<1) | (2 << 4)); |
313 RS232_putc('B'); |
331 RS232_putc('B'); |
314 RS232_putc('B'); |
332 RS232_putc('B'); |
315 RS232_putc('0'+car1_state); |
333 RS232_putc('0'+car1_state); |