# HG changeset patch # User Malte Bayer # Date 1323362781 -3600 # Node ID 6b26d7e3ecd05544294a9d502d953326d96e9605 # Parent ec9e8cc27012a90a0af338f321167740959c75c8 simplified do_controller function diff -r ec9e8cc27012 -r 6b26d7e3ecd0 blackbox/main.c --- a/blackbox/main.c Thu Dec 08 17:40:40 2011 +0100 +++ b/blackbox/main.c Thu Dec 08 17:46:21 2011 +0100 @@ -199,70 +199,47 @@ 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)); + + if (controller < 4) { + 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; + } else { + if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; + if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; + tmp = tmp << 1; + if (trackchange || slot[controller].trackswitch) tmp |= (1<<5); + } } switch (controller) { case 0: - //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 (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 (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 (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 (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 (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 (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 (trackchange != 0) { tmp |= (1<<5); if (mode == 0) LED(5,0); } else if (mode == 0) LED(5,1); break; - case 4: // virtual car #1 - if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; - if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; - tmp = tmp << 1; - 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 (trackchange || slot[controller].trackswitch) tmp |= (1<<5); - break; + } - } tmp |= (0b1000000000 | (controller << 6)); if ( (PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) tmp |= 1; // benzinstand aktiv - tankmodusschalter return insert_queue(tmp, 9);