Thu, 08 Dec 2011 17:46:21 +0100
simplified do_controller function
blackbox/main.c | file | annotate | diff | comparison | revisions |
--- 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);