# HG changeset patch # User Malte Bayer # Date 1323360842 -3600 # Node ID 5bba01aad0a6bbd06b35326444cc4b9d10610fee # Parent 34ac9f92bc1e0a6776e47f6597d18068faf3bfe0 memsave and implemented minimum slot speed for virtual cars diff -r 34ac9f92bc1e -r 5bba01aad0a6 blackbox/driver/rs232.h --- a/blackbox/driver/rs232.h Thu Dec 08 15:56:20 2011 +0100 +++ b/blackbox/driver/rs232.h Thu Dec 08 17:14:02 2011 +0100 @@ -1,7 +1,7 @@ #ifndef __RS232_H__ #define __RS232_H__ -#define RS232_BUFSIZE 15 +#define RS232_BUFSIZE 10 extern void RS232_init(void); extern void RS232_putc(char c); diff -r 34ac9f92bc1e -r 5bba01aad0a6 blackbox/main.c --- a/blackbox/main.c Thu Dec 08 15:56:20 2011 +0100 +++ b/blackbox/main.c Thu Dec 08 17:14:02 2011 +0100 @@ -27,12 +27,15 @@ #define MAX_SLOTS 6 typedef struct { - uint8_t speedlimit, fuel; + uint8_t speedlimit; // 4bits speedlimit + uint8_t speedminimum; // 4bits speedminimum + uint8_t fuel; uint16_t jumpstart_time, laps; u32 lap_time_start, lap_time; + uint8_t trackswitch; // 1bit bool } cardata; -static unsigned char s[10]; +static unsigned char s[8]; static uint8_t countdown, countdown_loops; uint8_t mode = 0; // valid race modes: @@ -45,7 +48,7 @@ volatile uint8_t sysclk_packettimer = 0; volatile cardata slot[MAX_SLOTS]; -volatile uint16_t car0, car1; +volatile uint8_t car0, car1; volatile uint16_t car0_new, car0_old; volatile uint16_t car1_new, car1_old; uint8_t car0_state, car1_state; @@ -120,11 +123,21 @@ RS232_puts_p(ok); break; + case 'S': // set minimum speed for a car + tmp = buffer[2]-'0'; + if (tmp > 9) + tmp = buffer[2]-'A'+10; + slot[buffer[1]-'0'].speedminimum = tmp; + RS232_puts_p(ok); + break; + case 'I': // get Information data (incl. important global parameter dump) RS232_puts(VERSION); RS232_putc(':'); for (tmp=0;tmp slot[controller].speedlimit) tmp = slot[controller].speedlimit; tmp = tmp << 1; @@ -181,6 +199,7 @@ 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; @@ -191,6 +210,7 @@ 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; @@ -201,6 +221,7 @@ 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; @@ -209,12 +230,22 @@ if (mode == 0) LED(5,0); } else if (mode == 0) LED(5,1); break; - case 4: tmp = (1<<5); break; // todo regler 5 - case 5: tmp = (1<<5); break; // todo regler 6 + 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 (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 (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); } @@ -238,11 +269,12 @@ int do_active(void) { // send controller active data packet uint16_t tmp = 0b10000000; - if ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b11000001; - if ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10100001; - if ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10010001; - if ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10001001; - // todo: regler 5 und 6 + if ((slot[0].speedminimum != 0) || ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b11000001; + if ((slot[1].speedminimum != 0) || ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10100001; + if ((slot[2].speedminimum != 0) || ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10010001; + if ((slot[3].speedminimum != 0) || ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10001001; + if (slot[4].speedminimum != 0) tmp |= 0b10000101; + if (slot[5].speedminimum != 0) tmp |= 0b10000011; // todo: wenn Daten enpfangen wurden hier eine Quittierung senden anstatt dem Active Word return insert_queue(tmp, 7); @@ -387,7 +419,9 @@ void reset_vars(void) { uint8_t i; for (i=0; i