# HG changeset patch # User Malte Bayer # Date 1322918706 -3600 # Node ID aea84f4f5a12927b1c032cb72a5dcb860584a861 # Parent 00166228a4199c77e333dea54cb07ab191cddd16 feature: program a specific controller speed limit without changing the car's acceleration diff -r 00166228a419 -r aea84f4f5a12 blackbox/main.c --- a/blackbox/main.c Sat Dec 03 13:53:44 2011 +0100 +++ b/blackbox/main.c Sat Dec 03 14:25:06 2011 +0100 @@ -13,6 +13,9 @@ #include "main.h" #include "lowlevel.h" +#define MAX_SLOTS 5 +uint8_t speedlimit[MAX_SLOTS]; + volatile uint8_t program_count = 0; volatile uint8_t program_id; volatile uint8_t program_command; @@ -45,8 +48,12 @@ return 0; } +char ok[] PROGMEM="OK\n"; +char busy[] PROGMEM="BUSY\n"; + ISR ( USART_RXC_vect ) { + uint8_t tmp; char c = UDR; // check for buffer overflow @@ -72,8 +79,16 @@ program_count = 0x02; // send commands twice (fuel, speed, brake) else program_count = 0x01; - RS232_puts_p(PSTR("OK\n")); - } else RS232_puts_p(PSTR("BUSY\n")); + RS232_puts_p(ok); + } else RS232_puts_p(busy); + break; + + case 'L': // Limit maximum speed for a car + tmp = buffer[2]-'0'; + if (tmp > 9) + tmp = buffer[2]-'A'+10; + speedlimit[buffer[1]-'0'] = tmp; + RS232_puts_p(ok); break; } @@ -95,28 +110,36 @@ uint16_t tmp; switch (controller) { case 0: - tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1; + tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if (tmp > speedlimit[controller]) tmp = speedlimit[controller]; + tmp = tmp << 1; if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) { tmp |= (1<<5); LED(1,0); } else LED(1,1); break; case 1: - tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1; + tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if (tmp > speedlimit[controller]) tmp = speedlimit[controller]; + tmp = tmp << 1; if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) { tmp |= (1<<5); LED(2,0); } else LED(2,1); break; case 2: - tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1; + tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if (tmp > speedlimit[controller]) tmp = speedlimit[controller]; + tmp = tmp << 1; if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) { tmp |= (1<<5); LED(3,0); } else LED(3,1); break; case 3: - tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1; + tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F); + if (tmp > speedlimit[controller]) tmp = speedlimit[controller]; + tmp = tmp << 1; if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) { tmp |= (1<<5); LED(4,0); @@ -260,6 +283,13 @@ LED(5,2); } +void reset_vars(void) { + uint8_t i; + for (i=0; i 5): + return "ERR - invalid carid" + if (value<0) or (value>15): + return "ERR - invalid value" + # transform value 10..15 to A..F + if (value>9): + value = chr(ord("A") + (value-10)) + return self.com.query( "L%i%s" % (carid, value) ) + def setmode(self, mode): """ Switch the Blackbox mode