Sat, 10 Dec 2011 14:43:34 +0100
finished trackswitch firmware
pitlane/main.c | file | annotate | diff | comparison | revisions | |
trackswitch/main.c | file | annotate | diff | comparison | revisions |
--- a/pitlane/main.c Sat Dec 10 14:12:09 2011 +0100 +++ b/pitlane/main.c Sat Dec 10 14:43:34 2011 +0100 @@ -24,7 +24,10 @@ #define SOLENOID_A_PIN PB1 #define SOLENOID_B_PIN PB2 -#define TRACKSWITCH_TYPE 4 // 1=double, 2=single, 4=pitlane +#define TRACKSWITCH_TYPE 4 // 1=double, 2=single left, 3=single right, 4=pitlane +#define TYPE_DOUBLE 1 +#define TYPE_SINGLE_L 2 +#define TYPE_SINGLE_R 3 #define TYPE_PITLANE 4 #define MAX_SENSORS 3
--- a/trackswitch/main.c Sat Dec 10 14:12:09 2011 +0100 +++ b/trackswitch/main.c Sat Dec 10 14:43:34 2011 +0100 @@ -15,6 +15,14 @@ ISR ( USART_RXC_vect ) { } +// TODO: TYPE should be configured somewhere else +#define TRACKSWITCH_TYPE 1 // 1=double, 2=single left, 3=single right, 4=pitlane +#define TYPE_DOUBLE 1 +#define TYPE_SINGLE_L 2 +#define TYPE_SINGLE_R 3 +#define TYPE_PITLANE 4 + + #define PULSE_PORT PORTD #define PULSE_BIT PD2 @@ -24,10 +32,16 @@ #define SOLENOID_A_PORT PORTB #define SOLENOID_B_PORT PORTB -#define TRACKSWITCH_TYPE 1 // 1=double, 2=single - -#define SOLENOID_A_PIN PB1 -#define SOLENOID_B_PIN PB2 +#ifdef WE_HAVE_TO_REVERSE_PORTS_ON_DOUBLE_SWITCH +//#if (TRACKSWITCH_TYPE == TYPE_DOUBLE) + // switch outputs - note: car0+1 have also be swapped! + // todo in future + #define SOLENOID_A_PIN PB2 + #define SOLENOID_B_PIN PB1 +#else + #define SOLENOID_A_PIN PB1 + #define SOLENOID_B_PIN PB2 +#endif // internal analog comparator doesnt work well //#define ANALOG_COMPARATOR 1 @@ -270,6 +284,7 @@ */ if (car0 != car0_state) { car0_state = car0; +#if (TRACKSWITCH_TYPE == TYPE_DOUBLE) || (TRACKSWITCH_TYPE == TYPE_SINGLE_R) if ( (car0_state != 0) && (car_switch[car0_state-1] == 0) && (car_speed[car0_state-1]>0) ) { response = (1 | ((car0_state-1)<<1) | (1 << 4)); // trigger solenoid A @@ -282,7 +297,8 @@ solenoid_delay(); SOLENOID_A_PORT &= ~_BV(SOLENOID_A_PIN); solenoid_delay(); - } + } else +#endif if (car0_state != 0) { response = (1 | ((car0_state-1)<<1)); RS232_putc('A'); @@ -295,6 +311,7 @@ if (car1 != car1_state) { car1_state = car1; +#if (TRACKSWITCH_TYPE == TYPE_DOUBLE) || (TRACKSWITCH_TYPE == TYPE_SINGLE_L) if ( (car1_state != 0) && (car_switch[car1_state-1] == 0) && (car_speed[car1_state-1]>0) ) { response = (1 | ((car1_state-1)<<1) | (3 << 4)); // trigger solenoid B @@ -307,7 +324,8 @@ solenoid_delay(); SOLENOID_B_PORT &= ~_BV(SOLENOID_B_PIN); solenoid_delay(); - } + } else +#endif if (car1_state != 0) { response = (1 | ((car1_state-1)<<1) | (2 << 4)); RS232_putc('B');