--- a/blackbox/main.c Fri Dec 09 14:08:24 2011 +0100 +++ b/blackbox/main.c Fri Dec 09 14:33:07 2011 +0100 @@ -27,12 +27,15 @@ #define MAX_SLOTS 6 #define FUEL_FULL 10000 +//#define FUEL_DIVISOR 25 +#define FUEL_DIVISOR 10 typedef struct { unsigned speedlimit:4; // 4bits speedlimit unsigned speedminimum:4; // 4bits speedminimum unsigned seccnt:4; // 4 bits tenth seconds counter unsigned accel:4; // 4 bits last configured acceleration unsigned trackswitch:1; // 1bit bool + unsigned canrefuel:1; // 1bit bool uint16_t jumpstart_time, laps, fuel; u32 lap_time_start, lap_time; } cardata; @@ -247,11 +250,13 @@ } tmp |= (0b1000000000 | (controller << 6)); - if ( (PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) tmp |= 1; // benzinstand aktiv - tankmodusschalter + // FUEL BIT GETS SET WHEN FUEL == 0, + // THIS REQUIRES PHYSICAL CAR FUEL LEVEL SET TO ZERO BEFORE! + if ( ((PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) | (slot[controller].fuel == 0)) tmp |= 1; // benzinstand aktiv - tankmodusschalter if (insert_queue(tmp, 9)) { if (speed != 0) { // do the fuel calculation, regardless if fuel logic active or not - tmp = (uint8_t)(((slot[controller].accel * speed) + 1) / 25); + tmp = (uint8_t)(((slot[controller].accel * speed) + 1) / FUEL_DIVISOR); if (tmp == 0) tmp = 1; if (slot[controller].fuel > 0) { // enough fuel left to decrement? @@ -259,6 +264,10 @@ slot[controller].fuel -= tmp; // decrement fuel level } else slot[controller].fuel = 0; } + } else if (slot[controller].canrefuel) { + // increase fuel by 5%/sec, this equals by adding 50 to the counter + slot[controller].fuel += 50; + if (slot[controller].fuel > FUEL_FULL) slot[controller].fuel = FUEL_FULL; } return 1; } else return 0; @@ -324,6 +333,7 @@ slot[i].laps = 0; slot[i].seccnt = 0; slot[i].accel = 15; // full acceleration per default - TODO + slot[i].canrefuel = 1; // TODO: only set to 1 when on a pitlane } sysclk.value = 0; }