24 uint16_t word[2]; // high, low word |
24 uint16_t word[2]; // high, low word |
25 uint8_t byte[4]; // all four bytes |
25 uint8_t byte[4]; // all four bytes |
26 } u32; |
26 } u32; |
27 |
27 |
28 #define FUEL_FULL 10000 |
28 #define FUEL_FULL 10000 |
29 #define FUEL_DIVISOR 25 |
29 #define FUEL_DIV_DEFAULT 25 |
30 //#define FUEL_DIVISOR 10 |
30 volatile uint8_t fuel_divisor = FUEL_DIV_DEFAULT; // default, can be set via serial command |
|
31 |
31 typedef struct { |
32 typedef struct { |
32 unsigned speedlimit:4; // 4bits speedlimit |
33 unsigned speedlimit:4; // 4bits speedlimit |
33 unsigned speedminimum:4; // 4bits speedminimum |
34 unsigned speedminimum:4; // 4bits speedminimum |
34 unsigned seccnt:4; // 4 bits tenth seconds counter |
35 unsigned seccnt:4; // 4 bits tenth seconds counter |
35 unsigned accel:4; // 4 bits last configured acceleration |
36 unsigned accel:4; // 4 bits last configured acceleration |
202 RS232_puts_p(ok); |
203 RS232_puts_p(ok); |
203 break; |
204 break; |
204 |
205 |
205 case 'F': // set fuel enabled |
206 case 'F': // set fuel enabled |
206 fuel_enabled = buffer[1]-'0'; |
207 fuel_enabled = buffer[1]-'0'; |
|
208 if (buffer[2] == ':') { |
|
209 // convert fuel divisor |
|
210 buffer[0] = '0'; // atoi expects zeros! |
|
211 buffer[1] = '0'; |
|
212 buffer[2] = '0'; |
|
213 RS232_puts("DivisorChange: "); |
|
214 itoa(fuel_divisor, s, 10); |
|
215 RS232_puts(s); |
|
216 RS232_putc('>'); |
|
217 fuel_divisor = atoi(buffer); |
|
218 itoa(fuel_divisor, s, 10); |
|
219 RS232_puts(s); |
|
220 RS232_putc(' '); |
|
221 } |
207 RS232_puts_p(ok); |
222 RS232_puts_p(ok); |
208 break; |
223 break; |
209 |
224 |
210 case '*': // set live information |
225 case '*': // set live information |
211 liveinfo = buffer[1]-'0'; |
226 liveinfo = buffer[1]-'0'; |
332 if ( ((PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) | (slot[controller].fuel == 0)) tmp |= 1; // benzinstand aktiv - tankmodusschalter |
347 if ( ((PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) | (slot[controller].fuel == 0)) tmp |= 1; // benzinstand aktiv - tankmodusschalter |
333 if (insert_queue(tmp, 9)) { |
348 if (insert_queue(tmp, 9)) { |
334 if (fuel_enabled) { |
349 if (fuel_enabled) { |
335 if (speed != 0) { |
350 if (speed != 0) { |
336 // do the fuel calculation, regardless if fuel logic active or not |
351 // do the fuel calculation, regardless if fuel logic active or not |
337 tmp = (uint8_t)(((slot[controller].accel * speed) + 1) / FUEL_DIVISOR); |
352 tmp = (uint8_t)(((slot[controller].accel * speed) + 1) / fuel_divisor); |
338 if (tmp == 0) tmp = 1; |
353 if (tmp == 0) tmp = 1; |
339 if (slot[controller].fuel > 0) { |
354 if (slot[controller].fuel > 0) { |
340 // enough fuel left to decrement? |
355 // enough fuel left to decrement? |
341 if (slot[controller].fuel > tmp) { |
356 if (slot[controller].fuel > tmp) { |
342 slot[controller].fuel -= tmp; // decrement fuel level |
357 slot[controller].fuel -= tmp; // decrement fuel level |