Sat, 15 Dec 2012 23:46:10 +0100
mem save ;-P
blackbox/main.c | file | annotate | diff | comparison | revisions |
--- a/blackbox/main.c Sat Dec 15 23:21:19 2012 +0100 +++ b/blackbox/main.c Sat Dec 15 23:46:10 2012 +0100 @@ -47,7 +47,8 @@ unsigned canrefuel:1; // 1bit bool unsigned unlimitedfuel:1; // 1bit bool unsigned trackchange:1; // 1bit bool - uint16_t jumpstart_time, laps, fuel; + uint16_t jumpstart_time, fuel; + uint8_t laps; u32 lap_time_start, lap_time; } cardata; @@ -65,9 +66,13 @@ extern uint8_t old_start = _BV(SW_START); // todo: pack as bit structure: -uint8_t liveinfo = 0; -uint8_t fuel_enabled = 1; -uint8_t pitlane_finishline = 0; + +typedef struct { + unsigned fuel_enabled:1; + unsigned pitlane_finishline:1; + unsigned liveinfo:6; +} switches_s; +switches_s switches; volatile u32 sysclk; volatile uint8_t sysclk_packettimer = 0; @@ -155,7 +160,7 @@ // pitlane response if (status == 5) { slot[car].canrefuel = 1; - if (pitlane_finishline) slot[car].laps++; + if (switches.pitlane_finishline) slot[car].laps++; } if (status == 6) for (data=0; data<MAX_SLOTS; data++) slot[data].canrefuel = 0; if (status == 7) slot[car].canrefuel = 0; @@ -259,7 +264,7 @@ break; case 'F': // set fuel enabled - fuel_enabled = buffer[1]-'0'; + switches.fuel_enabled = buffer[1]-'0'; if (buffer[2] == ':') { // convert fuel divisor buffer[0] = '0'; // atoi expects zeros! @@ -278,13 +283,13 @@ break; case '*': // set live information - liveinfo = buffer[1]-'0'; + switches.liveinfo = buffer[1]-'0'; RS232_puts_p(ok); break; case 'X': // set Pitlane act as finish line // this can be used if pitlane exit comes after finish line while pitlane entry is before finish line - pitlane_finishline = buffer[1]-'0'; + switches.pitlane_finishline = buffer[1]-'0'; RS232_puts_p(ok); break; @@ -421,7 +426,7 @@ // 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; if (insert_queue(tmp, 9)) { - if ((fuel_enabled) && (slot[controller].unlimitedfuel == 0)) { + if ((switches.fuel_enabled) && (slot[controller].unlimitedfuel == 0)) { if ((speed != 0) && (fuel_divisor > 0)) { // do the fuel calculation, regardless if fuel logic active or not tmp = (uint8_t)(((slot[controller].accel * speed) + 1) / fuel_divisor); @@ -598,9 +603,9 @@ } void slot_liveinfo(uint8_t idx) { - if (liveinfo == 0) return; + if (switches.liveinfo == 0) return; - if (liveinfo == 1) { + if (switches.liveinfo == 1) { // increment packet counter, if == 10 output some live info if (slot[idx].seccnt == 10) { // output current fuel status @@ -616,7 +621,7 @@ RS232_putc('\n'); slot[idx].seccnt = 0; } else slot[idx].seccnt++; - } else if ( (liveinfo - 2) == idx ) { + } else if ( (switches.liveinfo - 2) == idx ) { // output controller status LIVEINFO-2 for remote learning RS232_putc('L'); RS232_putc('N'); @@ -635,6 +640,10 @@ { uint8_t packet_index = 1; + switches.fuel_enabled = 1; + switches.pitlane_finishline = 0; + switches.liveinfo = 0; + init_hardware(); reset_vars(); LED(3, 1); // enable middle led == idle mode