23 #define TRACKSWITCH_TYPE 2 // 1=double, 2=single |
23 #define TRACKSWITCH_TYPE 2 // 1=double, 2=single |
24 |
24 |
25 #define SOLENOID_A_PIN PB1 |
25 #define SOLENOID_A_PIN PB1 |
26 #define SOLENOID_B_PIN PB2 |
26 #define SOLENOID_B_PIN PB2 |
27 |
27 |
|
28 // internal analog comparator doesnt work well |
|
29 //#define ANALOG_COMPARATOR 1 |
28 |
30 |
29 volatile uint16_t data = 0; |
31 volatile uint16_t data = 0; |
30 volatile uint8_t data_len = 0; |
32 volatile uint8_t data_len = 0; |
31 volatile uint8_t bitbuf_len = 0; |
33 volatile uint8_t bitbuf_len = 0; |
32 volatile uint16_t bitbuf = 0; |
34 volatile uint16_t bitbuf = 0; |
196 while (1) { |
198 while (1) { |
197 // main loop |
199 // main loop |
198 |
200 |
199 if (car0 != car0_state) { |
201 if (car0 != car0_state) { |
200 car0_state = car0; |
202 car0_state = car0; |
201 if ( (car0_state != 0) && (car_switch[car0_state-1] == 0) ) { |
203 if ( (car0_state != 0) && (car_switch[car0_state-1] == 0) && (car_speed[car0_state-1]>0) ) { |
202 // trigger solenoid A |
204 // trigger solenoid A |
203 RS232_putc('A'); |
205 RS232_putc('A'); |
|
206 RS232_putc('B'); |
204 RS232_putc('0'+car0_state); |
207 RS232_putc('0'+car0_state); |
205 RS232_putc('\n'); |
208 RS232_putc('\n'); |
206 |
209 |
207 SOLENOID_A_PORT |= _BV(SOLENOID_A_PIN); |
210 SOLENOID_A_PORT |= _BV(SOLENOID_A_PIN); |
208 solenoid_delay(); |
211 solenoid_delay(); |
209 SOLENOID_A_PORT &= ~_BV(SOLENOID_A_PIN); |
212 SOLENOID_A_PORT &= ~_BV(SOLENOID_A_PIN); |
210 solenoid_delay(); |
213 solenoid_delay(); |
|
214 } |
|
215 if (car0_state != 0) { |
|
216 RS232_putc('A'); |
|
217 RS232_putc('A'); |
|
218 RS232_putc('0'+car0_state); |
|
219 RS232_putc('\n'); |
211 } |
220 } |
212 } car0 = 0; |
221 } car0 = 0; |
213 |
222 |
214 |
223 |
215 if (car1 != car1_state) { |
224 if (car1 != car1_state) { |
216 car1_state = car1; |
225 car1_state = car1; |
217 if ( (car1_state != 0) && (car_switch[car1_state-1] == 0) ) { |
226 if ( (car1_state != 0) && (car_switch[car1_state-1] == 0) && (car_speed[car1_state-1]>0) ) { |
218 // trigger solenoid A |
227 // trigger solenoid A |
219 RS232_putc('B'); |
228 RS232_putc('B'); |
|
229 RS232_putc('A'); |
220 RS232_putc('0'+car1_state); |
230 RS232_putc('0'+car1_state); |
221 RS232_putc('\n'); |
231 RS232_putc('\n'); |
222 |
232 |
223 SOLENOID_B_PORT |= _BV(SOLENOID_B_PIN); |
233 SOLENOID_B_PORT |= _BV(SOLENOID_B_PIN); |
224 solenoid_delay(); |
234 solenoid_delay(); |
225 SOLENOID_B_PORT &= ~_BV(SOLENOID_B_PIN); |
235 SOLENOID_B_PORT &= ~_BV(SOLENOID_B_PIN); |
226 solenoid_delay(); |
236 solenoid_delay(); |
|
237 } |
|
238 if (car1_state != 0) { |
|
239 RS232_putc('B'); |
|
240 RS232_putc('B'); |
|
241 RS232_putc('0'+car1_state); |
|
242 RS232_putc('\n'); |
227 } |
243 } |
228 } car1 = 0; |
244 } car1 = 0; |
229 |
245 |
230 |
246 |
231 } // main loop end |
247 } // main loop end |