197 if ((controller == 3) && (mode!=1)) tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F); |
197 if ((controller == 3) && (mode!=1)) tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F); |
198 if (controller == 0) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)); |
198 if (controller == 0) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)); |
199 if (controller == 1) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)); |
199 if (controller == 1) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)); |
200 if (controller == 2) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)); |
200 if (controller == 2) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)); |
201 if (controller == 3) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)); |
201 if (controller == 3) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)); |
202 } |
202 |
203 |
203 if (controller < 4) { |
204 switch (controller) { |
|
205 case 0: |
|
206 //if (mode!=1) tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F); |
|
207 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; |
204 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; |
208 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } |
205 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } |
209 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
206 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
210 tmp = tmp << 1; |
207 tmp = tmp << 1; |
|
208 } else { |
|
209 if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; |
|
210 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
|
211 tmp = tmp << 1; |
|
212 if (trackchange || slot[controller].trackswitch) tmp |= (1<<5); |
|
213 } |
|
214 } |
|
215 |
|
216 switch (controller) { |
|
217 case 0: |
211 if (trackchange != 0) { |
218 if (trackchange != 0) { |
212 tmp |= (1<<5); |
219 tmp |= (1<<5); |
213 if (mode == 0) LED(1,0); |
220 if (mode == 0) LED(1,0); |
214 } else if (mode == 0) LED(1,1); |
221 } else if (mode == 0) LED(1,1); |
215 break; |
222 break; |
216 case 1: |
223 case 1: |
217 //if (mode!=1) tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F); |
|
218 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; |
|
219 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } |
|
220 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
|
221 tmp = tmp << 1; |
|
222 //if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) { |
|
223 if (trackchange != 0) { |
224 if (trackchange != 0) { |
224 tmp |= (1<<5); |
225 tmp |= (1<<5); |
225 if (mode == 0) LED(2,0); |
226 if (mode == 0) LED(2,0); |
226 } else if (mode == 0) LED(2,1); |
227 } else if (mode == 0) LED(2,1); |
227 break; |
228 break; |
228 case 2: |
229 case 2: |
229 //if (mode!=1) tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F); |
|
230 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; |
|
231 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } |
|
232 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
|
233 tmp = tmp << 1; |
|
234 //if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) { |
|
235 if (trackchange != 0) { |
230 if (trackchange != 0) { |
236 tmp |= (1<<5); |
231 tmp |= (1<<5); |
237 if (mode == 0) LED(4,0); |
232 if (mode == 0) LED(4,0); |
238 } else if (mode == 0) LED(4,1); |
233 } else if (mode == 0) LED(4,1); |
239 break; |
234 break; |
240 case 3: |
235 case 3: |
241 //if (mode!=1) tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F); |
|
242 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; |
|
243 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } |
|
244 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
|
245 tmp = tmp << 1; |
|
246 //if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) { |
|
247 if (trackchange != 0) { |
236 if (trackchange != 0) { |
248 tmp |= (1<<5); |
237 tmp |= (1<<5); |
249 if (mode == 0) LED(5,0); |
238 if (mode == 0) LED(5,0); |
250 } else if (mode == 0) LED(5,1); |
239 } else if (mode == 0) LED(5,1); |
251 break; |
240 break; |
252 case 4: // virtual car #1 |
241 } |
253 if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; |
242 |
254 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
|
255 tmp = tmp << 1; |
|
256 if (trackchange || slot[controller].trackswitch) tmp |= (1<<5); |
|
257 break; |
|
258 case 5: // virtual car #2 |
|
259 if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum; |
|
260 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit; |
|
261 tmp = tmp << 1; |
|
262 if (trackchange || slot[controller].trackswitch) tmp |= (1<<5); |
|
263 break; |
|
264 |
|
265 } |
|
266 tmp |= (0b1000000000 | (controller << 6)); |
243 tmp |= (0b1000000000 | (controller << 6)); |
267 if ( (PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) tmp |= 1; // benzinstand aktiv - tankmodusschalter |
244 if ( (PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) tmp |= 1; // benzinstand aktiv - tankmodusschalter |
268 return insert_queue(tmp, 9); |
245 return insert_queue(tmp, 9); |
269 } |
246 } |
270 |
247 |