Thu, 08 Dec 2011 17:40:40 +0100
car id setting for slot 5+6 working via pressing pacecar button
blackbox/main.c | file | annotate | diff | comparison | revisions |
--- a/blackbox/main.c Thu Dec 08 17:22:14 2011 +0100 +++ b/blackbox/main.c Thu Dec 08 17:40:40 2011 +0100 @@ -181,51 +181,70 @@ int do_controller(uint8_t controller) { // read controller X speed & encode controller data packet uint16_t tmp = 0; + uint8_t trackchange = 0xff; + if ( (PIN(SW_PACECAR_PORT) & _BV(SW_PACECAR)) == 0 ) { // map controller 1+2 to 5+6 + if (controller == 4) tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if (controller == 5) tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if (controller == 4) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)); + if (controller == 5) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)); + } else { + // read speeds + if ((controller == 0) && (mode!=1)) tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if ((controller == 1) && (mode!=1)) tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if ((controller == 2) && (mode!=1)) tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if ((controller == 3) && (mode!=1)) tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if (controller == 0) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)); + if (controller == 1) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)); + if (controller == 2) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)); + if (controller == 3) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)); } switch (controller) { case 0: - if (mode!=1) tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + //if (mode!=1) tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F); if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; tmp = tmp << 1; - if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) { + if (trackchange != 0) { tmp |= (1<<5); if (mode == 0) LED(1,0); } else if (mode == 0) LED(1,1); break; case 1: - if (mode!=1) tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + //if (mode!=1) tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F); if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; tmp = tmp << 1; - if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) { + //if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) { + if (trackchange != 0) { tmp |= (1<<5); if (mode == 0) LED(2,0); } else if (mode == 0) LED(2,1); break; case 2: - if (mode!=1) tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + //if (mode!=1) tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F); if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; tmp = tmp << 1; - if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) { + //if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) { + if (trackchange != 0) { tmp |= (1<<5); if (mode == 0) LED(4,0); } else if (mode == 0) LED(4,1); break; case 3: - if (mode!=1) tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + //if (mode!=1) tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F); if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; tmp = tmp << 1; - if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) { + //if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) { + if (trackchange != 0) { tmp |= (1<<5); if (mode == 0) LED(5,0); } else if (mode == 0) LED(5,1); @@ -234,13 +253,13 @@ if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; tmp = tmp << 1; - if (slot[controller].trackswitch) tmp |= (1<<5); + if (trackchange || slot[controller].trackswitch) tmp |= (1<<5); break; case 5: // virtual car #2 if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; tmp = tmp << 1; - if (slot[controller].trackswitch) tmp |= (1<<5); + if (trackchange || slot[controller].trackswitch) tmp |= (1<<5); break; } @@ -269,12 +288,18 @@ int do_active(void) { // send controller active data packet uint16_t tmp = 0b10000000; - if ((slot[0].speedminimum != 0) || ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b11000001; - if ((slot[1].speedminimum != 0) || ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10100001; - if ((slot[2].speedminimum != 0) || ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10010001; - if ((slot[3].speedminimum != 0) || ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10001001; - if (slot[4].speedminimum != 0) tmp |= 0b10000101; - if (slot[5].speedminimum != 0) tmp |= 0b10000011; + if ( (PIN(SW_PACECAR_PORT) & _BV(SW_PACECAR)) == 0 ) { + // map controller 1+2 to 5+6 + if ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10000101; + if ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10000011; + } else { + if ((slot[0].speedminimum != 0) || ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b11000001; + if ((slot[1].speedminimum != 0) || ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10100001; + if ((slot[2].speedminimum != 0) || ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10010001; + if ((slot[3].speedminimum != 0) || ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10001001; + if (slot[4].speedminimum != 0) tmp |= 0b10000101; + if (slot[5].speedminimum != 0) tmp |= 0b10000011; + } // todo: wenn Daten enpfangen wurden hier eine Quittierung senden anstatt dem Active Word return insert_queue(tmp, 7);