blackbox/main.c

changeset 90
7ed95dbadf1f
parent 89
4b5b4c7ba03d
child 91
e0738355b517
equal deleted inserted replaced
89:4b5b4c7ba03d 90:7ed95dbadf1f
173 return 1; 173 return 1;
174 } 174 }
175 return 0; 175 return 0;
176 } 176 }
177 177
178 void startbutton(void) {
179 // start button press active
180 if (mode == 0) {
181 mode = 1; // set wait for race start mode
182 reset_vars();
183 LED(1, 1);
184 LED(2, 1);
185 LED(3, 1);
186 LED(4, 1);
187 LED(5, 1);
188 RS232_puts_p(prepare);
189 } else if (mode == 1) {
190 // Initiate race countdown
191 sysclk.value = 0;
192 countdown = 5;
193 countdown_loops = COUNTDOWN_DELAY;
194 mode = 2;
195 LED(1, 0);
196 LED(2, 0);
197 LED(3, 0);
198 LED(4, 0);
199 LED(5, 0);
200 RS232_puts_p(countdownstart);
201 }
202 }
203
178 ISR ( USART_RXC_vect ) { 204 ISR ( USART_RXC_vect ) {
179 uint8_t tmp; 205 uint8_t tmp;
180 char c = UDR; 206 char c = UDR;
181 207
182 // check for buffer overflow 208 // check for buffer overflow
242 break; 268 break;
243 269
244 case '*': // set live information 270 case '*': // set live information
245 liveinfo = buffer[1]-'0'; 271 liveinfo = buffer[1]-'0';
246 RS232_puts_p(ok); 272 RS232_puts_p(ok);
273 break;
274
275 case '#': // remote start button press
276 RS232_puts_p(ok);
277 startbutton();
247 break; 278 break;
248 279
249 case '+': // toggle panic mode 280 case '+': // toggle panic mode
250 RS232_puts_p(ok); 281 RS232_puts_p(ok);
251 if (mode != 0xff) { 282 if (mode != 0xff) {
567 598
568 slot[idx].seccnt = 0; 599 slot[idx].seccnt = 0;
569 } else slot[idx].seccnt++; 600 } else slot[idx].seccnt++;
570 } 601 }
571 602
603
572 int main(void) 604 int main(void)
573 { 605 {
574 606
575 uint8_t packet_index = 1; 607 uint8_t packet_index = 1;
576 608
600 632
601 // read in button presses 633 // read in button presses
602 btn_start = (PIN(SW_START_PORT) & _BV(SW_START)); 634 btn_start = (PIN(SW_START_PORT) & _BV(SW_START));
603 if (old_start != btn_start) { 635 if (old_start != btn_start) {
604 // start button changed 636 // start button changed
605 if (btn_start == 0) { 637 if (btn_start == 0) startbutton();
606 // start button press active
607 if (mode == 0) {
608 mode = 1; // set wait for race start mode
609 reset_vars();
610 LED(1, 1);
611 LED(2, 1);
612 LED(3, 1);
613 LED(4, 1);
614 LED(5, 1);
615 RS232_puts_p(prepare);
616 } else if (mode == 1) {
617 // Initiate race countdown
618 sysclk.value = 0;
619 countdown = 5;
620 countdown_loops = COUNTDOWN_DELAY;
621 mode = 2;
622 LED(1, 0);
623 LED(2, 0);
624 LED(3, 0);
625 LED(4, 0);
626 LED(5, 0);
627 RS232_puts_p(countdownstart);
628 }
629 }
630 old_start = btn_start; 638 old_start = btn_start;
631 } 639 }
632 640
633 if (mode==3) { 641 if (mode==3) {
634 // RACE START! 642 // RACE START!

mercurial