Wed, 16 Nov 2011 13:38:03 +0100
debugging stuff
blackbox/main.c | file | annotate | diff | comparison | revisions |
--- a/blackbox/main.c Wed Nov 16 12:29:09 2011 +0100 +++ b/blackbox/main.c Wed Nov 16 13:38:03 2011 +0100 @@ -211,21 +211,23 @@ LED(1,2); if (timer0_delay == 0) { RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // pull rails low - _delay_us(25); // wait some cycles - if ((PIN(RAIL_POWER_PORT) & _BV(RAIL_POWER)) == 0) { // check for logic zero + _delay_us(28); // wait some cycles + if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) != 0) { // check for logic zero if (response == 0) { // there is no start bit, so stop the timer and cancel response receiving TIMSK &= ~_BV(TOIE0); } else { - // we received a logic low + // we received a bit (logic low) response = response << 1; } } else { // okay, we have logic high response = response << 1; response |= 1; + //debug: + RS232_puts("ANSWER RX\n"); } - _delay_us(23); // wait some cycles + _delay_us(20); // wait some cycles RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power } else timer0_delay--; // 2.3 ms delay not reached yet } @@ -243,6 +245,20 @@ uint16_t tmp; uint8_t packet_index = 1; + uint8_t btn_start = _BV(SW_START); + uint8_t old_start = btn_start; + uint8_t mode = 0; + // valid race modes: + // 0: free drive + // 1: race countdown initiated + // 2: countdown 5 + // 3: countdown 4 + // 4: countdown 3 + // 5: countdown 2 + // 6: countdown 1 + // 7: race start initiated (next mode will be zero = free drive) + + init_hardware(); @@ -254,10 +270,32 @@ check_rails_shortcut(); // read in button presses - if ( (PIN(SW_START_PORT) & _BV(SW_START)) == 0 ) { - // start button press active - LAP_COUNTER_PORT |= _BV(LAP_COUNTER); - } else LAP_COUNTER_PORT &= ~_BV(LAP_COUNTER); + btn_start = (PIN(SW_START_PORT) & _BV(SW_START)); + if (old_start != btn_start) { + // start button changed + if (btn_start == 0) { + // start button press active + if (mode == 0) { + // Initiate race countdown + mode = 0; // todo: set to 1 + // issue reset command to lap counter + program_command = 6; + program_parameter = 9; + program_id = 0; + program_count = 1; + } else { + // do a reset, switch back to free drive mode 0 + mode = 0; + // issue reset command + program_command = 19; + program_parameter = 0; + program_id = 7; + program_count = 1; + } + } + //LAP_COUNTER_PORT |= _BV(LAP_COUNTER); + } else old_start = btn_start; + // LAP_COUNTER_PORT &= ~_BV(LAP_COUNTER); switch (packet_index) { case 1: @@ -270,7 +308,8 @@ } else { // output idle command //if (do_program(7, 19, 0)) packet_index++; // reset - if (do_program(7, 20, 15)) packet_index++; // reset / pitstop detect + //if (do_program(7, 20, 15)) packet_index++; // reset / pitstop detect + if (insert_queue(0, 0)) packet_index++; // null command } break; case 2: