# HG changeset patch # User Malte Bayer # Date 1324124660 -3600 # Node ID 4b5b4c7ba03dc4ef9f35980284fe276f5db300c7 # Parent c889aa0be7e2124ec7d522661a9bed22c14c800d added panic mode, shortcircuit can be resumed now diff -r c889aa0be7e2 -r 4b5b4c7ba03d blackbox/interrupts.c --- a/blackbox/interrupts.c Fri Dec 16 01:05:37 2011 +0100 +++ b/blackbox/interrupts.c Sat Dec 17 13:24:20 2011 +0100 @@ -1,4 +1,5 @@ ISR ( TIMER1_COMPA_vect ) { + if (mode==0xff) return; // panic mode, drop rest of routine // trigger packet transfer: if (sysclk_packettimer == 14) { // 15*500 = 7500 NS transmit_len = transmit_len_next; @@ -6,6 +7,7 @@ } else sysclk_packettimer++; // here is some more time to do something else... + // reset both car counters to overflow car0_old = TIMER1_500NS; car1_old = TIMER1_500NS; @@ -14,6 +16,8 @@ } ISR ( TIMER2_COMP_vect ) { + if (mode==0xff) return; // panic mode, drop rest of routine + uint8_t i; //OCR2 = TIMER2_50US; // make sure that timer2 is 50µs !!! // data packet timer 100µs pro bit... @@ -83,6 +87,7 @@ ISR ( TIMER0_OVF_vect ) { + if (mode==0xff) return; // panic mode, drop rest of routine // TODO: last bit should be set by the sender, not from us! TCNT0 = TIMER0_250US; if (timer0_delay == 0) { diff -r c889aa0be7e2 -r 4b5b4c7ba03d blackbox/lowlevel.c --- a/blackbox/lowlevel.c Fri Dec 16 01:05:37 2011 +0100 +++ b/blackbox/lowlevel.c Sat Dec 17 13:24:20 2011 +0100 @@ -131,6 +131,23 @@ } +void panic_mode(void) { + RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // disable rails power + LEDS_OFF(); + LED(1, 2); + blinkdelay(); + LED(1, 2); + LED(2, 2); + blinkdelay(); + LED(2, 2); + LED(3, 2); + blinkdelay(); + LED(3, 2); + LED(4, 2); + blinkdelay(); + LED(4, 2); + LED(5, 2); +} uint8_t check_rails_shortcut(void) { @@ -143,15 +160,20 @@ i--; } if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) { - cli(); // disable ALL Interrupts + // set panic mode + mode = 0xff; RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // disable rails power - RS232_puts_p(PSTR("!!! SHORT CIRCUIT ON RAILS, POWERED OFF !!!\n")); + // wait a little to all interrupts complete + //cli(); // disable ALL Interrupts + _delay_ms(2); + RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // disable rails power + RS232_puts_p(SHORTCUT); LED(1, 1); LED(2, 1); LED(3, 0); LED(4, 0); LED(5, 0); - while (1) { + while (mode == 0xff) { LED(1, 2); LED(2, 2); LED(4, 2); @@ -164,7 +186,19 @@ LED(3, 2); blinkdelay(); LED(3, 2); + btn_start = (PIN(SW_START_PORT) & _BV(SW_START)); + if (old_start != btn_start) { + // start button changed + if (btn_start == 0) { + mode = 0; + RS232_puts_p(RESUME); + } + old_start = btn_start; + } + } + LEDS_OFF(); + LED(3, 1); } } return 0; diff -r c889aa0be7e2 -r 4b5b4c7ba03d blackbox/lowlevel.h --- a/blackbox/lowlevel.h Fri Dec 16 01:05:37 2011 +0100 +++ b/blackbox/lowlevel.h Sat Dec 17 13:24:20 2011 +0100 @@ -5,6 +5,7 @@ void LED(uint8_t num, uint8_t state); void LEDS_OFF(void); void init_hardware(void); +void panic_mode(void); uint8_t check_rails_shortcut(void); #endif diff -r c889aa0be7e2 -r 4b5b4c7ba03d blackbox/main.c --- a/blackbox/main.c Fri Dec 16 01:05:37 2011 +0100 +++ b/blackbox/main.c Sat Dec 17 13:24:20 2011 +0100 @@ -19,6 +19,10 @@ char countdownstart[] PROGMEM="!COUNTDOWN\n"; char racestart[] PROGMEM="!RACE START\n"; +char SHORTCUT[] PROGMEM="!SHORTCUT\n"; +char PANIC[] PROGMEM="!PANIC\n"; +char RESUME[] PROGMEM="!RESUME\n"; + typedef union { uint32_t value; uint16_t word[2]; // high, low word @@ -44,12 +48,18 @@ static char s[8]; static uint8_t countdown, countdown_loops; -uint8_t mode = 0; +extern uint8_t mode = 0; // valid race modes: // 0: free drive / idle // 1: waiting for countdown start // 2: race countdown initiated // 3: Race start condition +// 255 PANIC MODE -> TURN OFF TRACK POWER + +extern uint8_t btn_start = _BV(SW_START); +extern uint8_t old_start = _BV(SW_START); + + uint8_t liveinfo = 0; uint8_t fuel_enabled = 1; @@ -236,6 +246,16 @@ RS232_puts_p(ok); break; + case '+': // toggle panic mode + RS232_puts_p(ok); + if (mode != 0xff) { + mode = 0xff; + RS232_puts_p(PANIC); + } else { + mode = 0; + RS232_puts_p(RESUME); + } + break; case 'I': // get Information data (incl. important global parameter dump) RS232_puts(VERSION); @@ -554,8 +574,6 @@ uint8_t packet_index = 1; - uint8_t btn_start = _BV(SW_START); - uint8_t old_start = btn_start; init_hardware(); @@ -569,6 +587,7 @@ // check for short circuit on the rails check_rails_shortcut(); check_cars(); + while (mode == 0xff) panic_mode(); if (response_len > 0) { itoa(response, s, 2); diff -r c889aa0be7e2 -r 4b5b4c7ba03d blackbox/main.h --- a/blackbox/main.h Fri Dec 16 01:05:37 2011 +0100 +++ b/blackbox/main.h Sat Dec 17 13:24:20 2011 +0100 @@ -96,6 +96,15 @@ // constants #define MAX_SLOTS 6 +// external variabled +extern uint8_t mode; +extern uint8_t btn_start; +extern uint8_t old_start; +extern char SHORTCUT[]; +extern char PANIC[]; +extern char RESUME[]; + + // MAYBE USELESS STUFF: diff -r c889aa0be7e2 -r 4b5b4c7ba03d slotUI/SlotCli.py --- a/slotUI/SlotCli.py Fri Dec 16 01:05:37 2011 +0100 +++ b/slotUI/SlotCli.py Sat Dec 17 13:24:20 2011 +0100 @@ -167,7 +167,7 @@ while 1: key = self.scr.getch() if key == ord('q'): break - elif key == ord(' '): self.cyclemode() + elif key == ord(' '): self.box.query("+") # panic / resume elif key == ord('1'): self.readName(0) elif key == ord('2'): self.readName(1) elif key == ord('3'): self.readName(2) @@ -289,6 +289,20 @@ self.slot[slot]["status"] = "~~~~~~~~~~" trigger_sound("countdown_start") + if rx == "!PANIC": + # panic mode + trigger_sound("panic") + + if rx == "!SHORTCUT": + # panic mode + trigger_sound("panic_shortcircuit") + + if rx == "!RESUME": + # panic mode + trigger_sound("resume") + + + self.scr.addstr(17,31, "Race Timer: %7.3f min" % (self.sysclk / 60), curses.color_pair(2))