blackbox/main.c

Sat, 17 Dec 2011 13:24:20 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Sat, 17 Dec 2011 13:24:20 +0100
changeset 89
4b5b4c7ba03d
parent 83
c8e7a69a318a
child 90
7ed95dbadf1f
permissions
-rw-r--r--

added panic mode, shortcircuit can be resumed now

0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
1 #include <avr/interrupt.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
2 #include <avr/io.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
3 #include <avr/wdt.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
4 #include <avr/eeprom.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
5 #include <stdlib.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
6 #include <stdint.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
7 #include <avr/pgmspace.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
8 #include <util/delay.h>
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
9
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
10 #include "driver/rs232.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
11 #include "driver/adc.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
12
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
13 #include "main.h"
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
14 #include "lowlevel.h"
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
15
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
16 char ok[] PROGMEM="OK\n";
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
17 char busy[] PROGMEM="BUSY\n";
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
18 char prepare[] PROGMEM="!RACE PREPARE\n";
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
19 char countdownstart[] PROGMEM="!COUNTDOWN\n";
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
20 char racestart[] PROGMEM="!RACE START\n";
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
21
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
22 char SHORTCUT[] PROGMEM="!SHORTCUT\n";
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
23 char PANIC[] PROGMEM="!PANIC\n";
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
24 char RESUME[] PROGMEM="!RESUME\n";
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
25
45
da820f138498 switched sysclk to u32
Malte Bayer <mbayer@neo-soft.org>
parents: 44
diff changeset
26 typedef union {
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
27 uint32_t value;
45
da820f138498 switched sysclk to u32
Malte Bayer <mbayer@neo-soft.org>
parents: 44
diff changeset
28 uint16_t word[2]; // high, low word
da820f138498 switched sysclk to u32
Malte Bayer <mbayer@neo-soft.org>
parents: 44
diff changeset
29 uint8_t byte[4]; // all four bytes
da820f138498 switched sysclk to u32
Malte Bayer <mbayer@neo-soft.org>
parents: 44
diff changeset
30 } u32;
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
31
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
32 #define FUEL_FULL 10000
81
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
33 #define FUEL_JUMPSTART 5000
75
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
34 #define FUEL_DIV_DEFAULT 25
83
c8e7a69a318a added pitlane speedlimit
Malte Bayer <mbayer@neo-soft.org>
parents: 81
diff changeset
35 #define PITLANE_SPEEDLIMIT 4
75
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
36 volatile uint8_t fuel_divisor = FUEL_DIV_DEFAULT; // default, can be set via serial command
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
37
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
38 typedef struct {
49
3957ff8e86c6 more memsave through packed structure#
Malte Bayer <mbayer@neo-soft.org>
parents: 48
diff changeset
39 unsigned speedlimit:4; // 4bits speedlimit
3957ff8e86c6 more memsave through packed structure#
Malte Bayer <mbayer@neo-soft.org>
parents: 48
diff changeset
40 unsigned speedminimum:4; // 4bits speedminimum
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
41 unsigned seccnt:4; // 4 bits tenth seconds counter
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
42 unsigned accel:4; // 4 bits last configured acceleration
49
3957ff8e86c6 more memsave through packed structure#
Malte Bayer <mbayer@neo-soft.org>
parents: 48
diff changeset
43 unsigned trackswitch:1; // 1bit bool
60
bfc2f2d6913c added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents: 59
diff changeset
44 unsigned canrefuel:1; // 1bit bool
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
45 uint16_t jumpstart_time, laps, fuel;
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
46 u32 lap_time_start, lap_time;
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
47 } cardata;
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
48
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
49 static char s[8];
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
50 static uint8_t countdown, countdown_loops;
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
51 extern uint8_t mode = 0;
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
52 // valid race modes:
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
53 // 0: free drive / idle
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
54 // 1: waiting for countdown start
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
55 // 2: race countdown initiated
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
56 // 3: Race start condition
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
57 // 255 PANIC MODE -> TURN OFF TRACK POWER
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
58
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
59 extern uint8_t btn_start = _BV(SW_START);
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
60 extern uint8_t old_start = _BV(SW_START);
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
61
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
62
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
63 uint8_t liveinfo = 0;
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
64 uint8_t fuel_enabled = 1;
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
65
45
da820f138498 switched sysclk to u32
Malte Bayer <mbayer@neo-soft.org>
parents: 44
diff changeset
66 volatile u32 sysclk;
42
018d4d63ad3b implemented 500ns timer and set jumpstart time
Malte Bayer <mbayer@neo-soft.org>
parents: 41
diff changeset
67 volatile uint8_t sysclk_packettimer = 0;
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
68 volatile cardata slot[MAX_SLOTS];
44
4f4326794ba4 implemented lap time, there is some bug in 32bit substraction yet
Malte Bayer <mbayer@neo-soft.org>
parents: 43
diff changeset
69
48
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
70 volatile uint8_t car0, car1;
41
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
71 volatile uint16_t car0_new, car0_old;
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
72 volatile uint16_t car1_new, car1_old;
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
73 uint8_t car0_state, car1_state;
36
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
74
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
75 volatile uint8_t program_count = 0;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
76 volatile uint8_t program_id;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
77 volatile uint8_t program_command;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
78 volatile uint8_t program_parameter;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
79
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
80 volatile uint8_t datalen = 0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
81 char data[10]; // 8 bytes data buffer + string termination
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
82
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
83 static char buffer[RS232_BUFSIZE+1];
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
84 static uint8_t buffer_len;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
85
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
86 volatile uint16_t transmit_buffer;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
87 volatile uint16_t transmit_buffer_queue;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
88 volatile uint8_t transmit_len;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
89 volatile uint8_t transmit_len_next;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
90 volatile uint8_t transmit_len_queue;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
91
69
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 64
diff changeset
92 volatile uint16_t responsewire_data = 0;
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
93 volatile uint16_t response;
33
c261350bb394 fixed shortcut detection
Malte Bayer <mbayer@neo-soft.org>
parents: 11
diff changeset
94 volatile uint8_t response_len;
6
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
95 volatile uint8_t timer0_delay;
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
96
2405aff29a51 added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents: 5
diff changeset
97
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
98 /* RESPONSEWIRE frame format:
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
99 1 startbit
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
100 2 car id bit 1
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
101 3 car id bit 2
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
102 4 car id bit 3
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
103 5 track change status bit 1
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
104 6 track change status bit 2
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
105 7 track change status bit 3
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
106 8 track change status bit 4
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
107 9 sender id bit 1
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
108 10 sender id bit 2
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
109 11 sender id bit 3
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
110 12 sender id bit 4
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
111 13 device type bit 1
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
112 14 device type bit 2
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
113 15 device type bit 3
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
114 16 stopbit
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
115 */
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
116
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
117 /* PITLANE/TRACKSWITCH STATUS DEFINITION
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
118 1 = AA
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
119 2 = AB
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
120 3 = BB
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
121 4 = BA
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
122 5 = BC
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
123 6 = ZZ -> pitlane exit
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
124 */
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
125
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
126 #define STARTSTOP 0b1000000000000001
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
127 void decode_responsewire(void) {
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
128 // ATTENTION: THIS IS CALLED IN AN INTERRUPT, KEEP AS SHORT AS POSSIBLE
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
129
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
130 uint16_t data = responsewire_data;
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
131 // first check if start + stopbit are set
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
132 // todo future: unsure but last bit doesnt get set?!
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
133 /*
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
134 if ((data & STARTSTOP) != STARTSTOP) {
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
135 RS232_puts("RW BAD\n");
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
136 return; // incomplete response
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
137 }
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
138 */
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
139 // now extract the car id, track change status
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
140 data >>= 1;
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
141 uint8_t car = (data & 0b111);
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
142 data >>= 3;
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
143 uint8_t status = (data & 0b1111);
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
144 data >>= 4;
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
145 uint8_t sender = (data & 0b1111);
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
146 data >>= 4;
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
147 uint8_t type = (data & 0b111);
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
148 if (type == 4) {
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
149 // pitlane response
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
150 if (status == 5) slot[car].canrefuel = 1;
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
151 if (status == 6) for (data=0; data<MAX_SLOTS; data++) slot[data].canrefuel = 0;
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
152 }
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
153 RS232_puts("RW:");
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
154 RS232_putc(car + '0');
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
155 RS232_putc(':');
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
156 RS232_putc(type + '0');
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
157 RS232_putc(':');
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
158 itoa(sender, s, 16);
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
159 RS232_puts(s);
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
160 RS232_putc(':');
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
161 itoa(status, s, 16);
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
162 RS232_puts(s);
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
163 RS232_putc(':');
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
164 ultoa(sysclk.value, s, 16);
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
165 RS232_puts(s);
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
166 RS232_putc('\n');
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
167 }
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
168
35
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
169 int insert_queue(uint16_t tmp, uint8_t len) {
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
170 if (transmit_buffer_queue == 0) {
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
171 transmit_buffer_queue = tmp;
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
172 transmit_len_queue = len;
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
173 return 1;
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
174 }
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
175 return 0;
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
176 }
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
177
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
178 ISR ( USART_RXC_vect ) {
36
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
179 uint8_t tmp;
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
180 char c = UDR;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
181
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
182 // check for buffer overflow
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
183 if (buffer_len==sizeof(buffer)) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
184 buffer_len=0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
185 } else {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
186 // collect characters until end of line
35
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 34
diff changeset
187 if ( (c=='\n') ) {
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
188 buffer[buffer_len]=0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
189
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
190 // packet end received, parse the received packet
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
191 switch (buffer[0]) {
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
192 case 'P': // inject a program data word to the rails
5
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
193 if (program_count == 0) {
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
194 program_id = buffer[3]-'0';
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
195 program_command = buffer[1]-'0';
10
6d6e982bbc41 meeting2 stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 8
diff changeset
196 if (program_command > 9)
6d6e982bbc41 meeting2 stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 8
diff changeset
197 program_command = buffer[1]-'A'+10;
5
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
198 program_parameter = buffer[2]-'0';
10
6d6e982bbc41 meeting2 stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 8
diff changeset
199 if (program_parameter > 9)
6d6e982bbc41 meeting2 stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 8
diff changeset
200 program_parameter = buffer[2]-'A'+10;
5
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
201 if (program_command < 4)
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
202 program_count = 0x02; // send commands twice (fuel, speed, brake)
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
203 else
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
204 program_count = 0x01;
36
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
205 RS232_puts_p(ok);
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
206 } else RS232_puts_p(busy);
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
207 break;
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
208
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
209 case 'L': // Limit maximum speed for a car
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
210 tmp = buffer[2]-'0';
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
211 if (tmp > 9)
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
212 tmp = buffer[2]-'A'+10;
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
213 slot[buffer[1]-'0'].speedlimit = tmp;
36
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
214 RS232_puts_p(ok);
5
7319de27d44a added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents: 4
diff changeset
215 break;
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
216
48
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
217 case 'S': // set minimum speed for a car
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
218 tmp = buffer[2]-'0';
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
219 if (tmp > 9)
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
220 tmp = buffer[2]-'A'+10;
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
221 slot[buffer[1]-'0'].speedminimum = tmp;
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
222 RS232_puts_p(ok);
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
223 break;
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
224
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
225 case 'F': // set fuel enabled
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
226 fuel_enabled = buffer[1]-'0';
75
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
227 if (buffer[2] == ':') {
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
228 // convert fuel divisor
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
229 buffer[0] = '0'; // atoi expects zeros!
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
230 buffer[1] = '0';
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
231 buffer[2] = '0';
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
232 RS232_puts("DivisorChange: ");
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
233 itoa(fuel_divisor, s, 10);
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
234 RS232_puts(s);
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
235 RS232_putc('>');
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
236 fuel_divisor = atoi(buffer);
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
237 itoa(fuel_divisor, s, 10);
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
238 RS232_puts(s);
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
239 RS232_putc(' ');
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
240 }
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
241 RS232_puts_p(ok);
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
242 break;
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
243
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
244 case '*': // set live information
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
245 liveinfo = buffer[1]-'0';
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
246 RS232_puts_p(ok);
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
247 break;
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
248
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
249 case '+': // toggle panic mode
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
250 RS232_puts_p(ok);
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
251 if (mode != 0xff) {
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
252 mode = 0xff;
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
253 RS232_puts_p(PANIC);
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
254 } else {
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
255 mode = 0;
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
256 RS232_puts_p(RESUME);
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
257 }
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
258 break;
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
259
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
260 case 'I': // get Information data (incl. important global parameter dump)
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
261 RS232_puts(VERSION);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
262 RS232_putc(':');
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
263 for (tmp=0;tmp<MAX_SLOTS;tmp++) RS232_putc(slot[tmp].speedlimit); // output speed limits
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
264 RS232_putc(':');
48
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
265 for (tmp=0;tmp<MAX_SLOTS;tmp++) RS232_putc(slot[tmp].speedminimum); // output minimum speed
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
266 RS232_putc(':');
43
4e5d389f7b83 jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents: 42
diff changeset
267 for (tmp=0;tmp<MAX_SLOTS;tmp++) {
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
268 itoa(slot[tmp].fuel, s, 16);
43
4e5d389f7b83 jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents: 42
diff changeset
269 RS232_putc(s); // output fuel levels (0=empty, 100=full, 0xff=no fuel option)
4e5d389f7b83 jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents: 42
diff changeset
270 RS232_putc(',');
4e5d389f7b83 jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents: 42
diff changeset
271 }
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
272 RS232_putc(':');
43
4e5d389f7b83 jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents: 42
diff changeset
273 for (tmp=0;tmp<MAX_SLOTS;tmp++) {
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
274 itoa(slot[tmp].jumpstart_time, s, 16);
43
4e5d389f7b83 jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents: 42
diff changeset
275 RS232_puts(s); // output jumpstart times
4e5d389f7b83 jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents: 42
diff changeset
276 RS232_putc(',');
4e5d389f7b83 jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents: 42
diff changeset
277 }
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
278 RS232_putc(':');
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
279 RS232_putc('\n');
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
280 break;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
281
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
282 }
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
283
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
284 // wait for the next packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
285 buffer_len=0;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
286 } else {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
287 buffer[buffer_len++]=c;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
288 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
289 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
290 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
291
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
292
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
293 void jumpstart(uint8_t controller) {
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
294 if (slot[controller].jumpstart_time == 0) {
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
295 slot[controller].jumpstart_time = sysclk.word[0]; // low word
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
296 RS232_putc('~');
81
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
297 RS232_putc('0'+controller);
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
298 RS232_putc(':');
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
299 itoa(slot[controller].jumpstart_time, s, 16);
43
4e5d389f7b83 jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents: 42
diff changeset
300 RS232_puts(s);
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
301 RS232_putc('\n');
81
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
302 slot[controller].fuel = FUEL_JUMPSTART; // suck 50% off that bitch!
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
303 }
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
304
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
305 }
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
306
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
307 uint8_t do_controller(uint8_t controller) {
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
308 // read controller X speed & encode controller data packet
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
309 uint16_t tmp = 0;
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
310 uint8_t speed;
51
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
311 uint8_t trackchange = 0xff;
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
312
48
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
313 if ( (PIN(SW_PACECAR_PORT) & _BV(SW_PACECAR)) == 0 ) {
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
314 // map controller 1+2 to 5+6
51
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
315 if (controller == 4) tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F);
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
316 if (controller == 5) tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F);
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
317 if (controller == 4) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW));
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
318 if (controller == 5) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW));
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
319 speed = tmp;
51
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
320 } else {
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
321 // read speeds
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
322 if ((controller == 0) && (mode!=1)) tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F);
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
323 if ((controller == 1) && (mode!=1)) tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F);
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
324 if ((controller == 2) && (mode!=1)) tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F);
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
325 if ((controller == 3) && (mode!=1)) tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F);
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
326 if (controller == 0) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW));
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
327 if (controller == 1) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW));
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
328 if (controller == 2) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW));
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
329 if (controller == 3) trackchange = (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW));
52
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
330
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
331 if (controller < 4) {
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
332 if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum;
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
333 if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; }
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
334 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit;
83
c8e7a69a318a added pitlane speedlimit
Malte Bayer <mbayer@neo-soft.org>
parents: 81
diff changeset
335 if (slot[controller].canrefuel && (tmp > PITLANE_SPEEDLIMIT)) tmp = PITLANE_SPEEDLIMIT;
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
336 speed = tmp;
52
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
337 tmp = tmp << 1;
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
338 } else {
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
339 if ((mode == 0) && (tmp < slot[controller].speedminimum)) tmp = slot[controller].speedminimum;
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
340 if (tmp > slot[controller].speedlimit) tmp = slot[controller].speedlimit;
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
341 speed = tmp;
52
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
342 tmp = tmp << 1;
81
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
343 //if ( (trackchange!=0) || (slot[controller].trackswitch)) tmp |= (1<<5);
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
344 if (trackchange!=0) tmp |= (1<<5);
52
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
345 }
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
346
48
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
347 }
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
348
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
349 switch (controller) {
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
350 case 0:
51
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
351 if (trackchange != 0) {
10
6d6e982bbc41 meeting2 stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 8
diff changeset
352 tmp |= (1<<5);
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
353 if (mode == 0) LED(1,0);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
354 } else if (mode == 0) LED(1,1);
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
355 break;
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
356 case 1:
51
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
357 if (trackchange != 0) {
10
6d6e982bbc41 meeting2 stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 8
diff changeset
358 tmp |= (1<<5);
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
359 if (mode == 0) LED(2,0);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
360 } else if (mode == 0) LED(2,1);
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
361 break;
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
362 case 2:
51
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
363 if (trackchange != 0) {
10
6d6e982bbc41 meeting2 stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 8
diff changeset
364 tmp |= (1<<5);
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
365 if (mode == 0) LED(4,0);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
366 } else if (mode == 0) LED(4,1);
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
367 break;
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
368 case 3:
51
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
369 if (trackchange != 0) {
10
6d6e982bbc41 meeting2 stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 8
diff changeset
370 tmp |= (1<<5);
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
371 if (mode == 0) LED(5,0);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
372 } else if (mode == 0) LED(5,1);
3
1a0ef40ef458 fixed track change keys
Malte Bayer <mbayer@neo-soft.org>
parents: 2
diff changeset
373 break;
52
6b26d7e3ecd0 simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents: 51
diff changeset
374 }
48
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
375
34
d12d095e3282 some code cleanup
Malte Bayer <mbayer@neo-soft.org>
parents: 33
diff changeset
376 tmp |= (0b1000000000 | (controller << 6));
60
bfc2f2d6913c added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents: 59
diff changeset
377 // FUEL BIT GETS SET WHEN FUEL == 0,
bfc2f2d6913c added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents: 59
diff changeset
378 // THIS REQUIRES PHYSICAL CAR FUEL LEVEL SET TO ZERO BEFORE!
bfc2f2d6913c added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents: 59
diff changeset
379 if ( ((PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) | (slot[controller].fuel == 0)) tmp |= 1; // benzinstand aktiv - tankmodusschalter
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
380 if (insert_queue(tmp, 9)) {
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
381 if (fuel_enabled) {
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
382 if (speed != 0) {
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
383 // do the fuel calculation, regardless if fuel logic active or not
75
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
384 tmp = (uint8_t)(((slot[controller].accel * speed) + 1) / fuel_divisor);
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
385 if (tmp == 0) tmp = 1;
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
386 if (slot[controller].fuel > 0) {
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
387 // enough fuel left to decrement?
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
388 if (slot[controller].fuel > tmp) {
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
389 slot[controller].fuel -= tmp; // decrement fuel level
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
390 } else slot[controller].fuel = 0;
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
391 }
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
392 } else if (slot[controller].canrefuel) {
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
393 // increase fuel by 5%/sec, this equals by adding 50 to the counter
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
394 slot[controller].fuel += 50;
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
395 if (slot[controller].fuel > FUEL_FULL) slot[controller].fuel = FUEL_FULL;
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
396 }
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
397 return 1;
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
398 }
75
0b38de31ad5d made fuel divisor configurable
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
399 return 1;
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
400 } else return 0;
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
401 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
402
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
403 uint8_t mirror( uint8_t n ) {
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
404 n = ((n >> 1) & 0x55) | ((n << 1) & 0xaa);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
405 n = ((n >> 2) & 0x33) | ((n << 2) & 0xcc);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
406 n = ((n >> 4) & 0x0f) | ((n << 4) & 0xf0);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
407 return n;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
408 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
409
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
410 int do_program(uint8_t controller, uint8_t command, uint8_t parameter) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
411 // send program data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
412 uint16_t tmp;
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
413 parameter = mirror(parameter);
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
414 controller = mirror(controller);
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
415 command = mirror(command);
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
416 tmp = 0b1000000000000 | (parameter << 4) | command | (controller >> 5);
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
417 return insert_queue(tmp, 12);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
418 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
419
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
420 int do_active(void) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
421 // send controller active data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
422 uint16_t tmp = 0b10000000;
51
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
423 if ( (PIN(SW_PACECAR_PORT) & _BV(SW_PACECAR)) == 0 ) {
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
424 // map controller 1+2 to 5+6
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
425 if ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10000101;
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
426 if ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) > 0) tmp |= 0b10000011;
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
427 } else {
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
428 if ((slot[0].speedminimum != 0) || ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b11000001;
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
429 if ((slot[1].speedminimum != 0) || ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10100001;
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
430 if ((slot[2].speedminimum != 0) || ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10010001;
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
431 if ((slot[3].speedminimum != 0) || ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) > 0)) tmp |= 0b10001001;
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
432 if (slot[4].speedminimum != 0) tmp |= 0b10000101;
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
433 if (slot[5].speedminimum != 0) tmp |= 0b10000011;
ec9e8cc27012 car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents: 49
diff changeset
434 }
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
435 // todo: wenn Daten enpfangen wurden hier eine Quittierung senden anstatt dem Active Word
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
436
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
437 return insert_queue(tmp, 7);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
438 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
439
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
440 int do_pace_ghost(void) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
441 // send ghost and pacecar data packet
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
442 // todo: at the moment, both disabled!
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
443 uint16_t tmp = 0b1111100000;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
444 if ( (PIN(SW_FUEL_PORT) & _BV(SW_FUEL)) != 0) tmp |= 1; // benzinstand aktiv - tankmodusschalter
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
445 // todo: PC, NH, TK, (KFR, FR)
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
446
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
447 return insert_queue(tmp, 9);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
448 }
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
449
53
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents: 52
diff changeset
450 #include "interrupts.c"
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
451
36
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
452 void reset_vars(void) {
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
453 uint8_t i;
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
454 for (i=0; i<MAX_SLOTS; i++) {
48
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
455 slot[i].speedlimit = 15;
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
456 slot[i].speedminimum = 0;
5bba01aad0a6 memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents: 47
diff changeset
457 slot[i].trackswitch = 0;
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
458 slot[i].fuel = FUEL_FULL;
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
459 slot[i].jumpstart_time = 0;
47
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
460 slot[i].laps = 0;
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
461 slot[i].seccnt = 0;
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
462 slot[i].accel = 15; // full acceleration per default - TODO
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
463 slot[i].canrefuel = 0;
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
464 slot[i].lap_time_start.value = 0;
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
465 slot[i].lap_time.value = 0;
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
466 }
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
467 sysclk.value = 0;
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
468 }
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
469
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
470 void countdown_progress(void) {
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
471 // decrement COUNTDOWN_LOOPS
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
472 if (countdown_loops>0) {
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
473 countdown_loops--;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
474 } else {
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
475 countdown--;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
476 countdown_loops = COUNTDOWN_DELAY;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
477 }
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
478 switch (countdown) {
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
479 case 5: LED(1, 1); break;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
480 case 4: LED(2, 1); break;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
481 case 3: LED(3, 1); break;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
482 case 2: LED(4, 1); break;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
483 case 1: LED(5, 1); break;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
484 case 0: { // RACE START!
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
485 sysclk.value = 0;
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
486 LEDS_OFF();
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
487 LED(3, 1);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
488 mode = 3;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
489 } break;
36
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
490 }
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
491 }
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
492
41
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
493 void check_cars(void) {
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
494 u32 clk, diff;
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
495 clk.value = sysclk.value; // freeze system clock time
44
4f4326794ba4 implemented lap time, there is some bug in 32bit substraction yet
Malte Bayer <mbayer@neo-soft.org>
parents: 43
diff changeset
496
41
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
497 if (car0 != car0_state) {
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
498 car0_state = car0;
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
499 if (car0_state != 0) {
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
500 diff.value = clk.value - slot[car0-1].lap_time_start.value;
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
501 if ( diff.value > 3000 ) { // minimum 1.5 second for 1 lap!
47
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
502 if (slot[car0-1].lap_time_start.value != 0) {
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
503 slot[car0-1].lap_time.value = diff.value;
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
504 slot[car0-1].laps++;
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
505 RS232_puts("L:3:"); // 3 = BB
47
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
506 itoa(slot[car0-1].laps, s, 16);
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
507 RS232_puts(s);
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
508 RS232_putc(':');
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
509 RS232_putc('0'+car0_state);
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
510 RS232_putc(':');
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
511 ultoa(diff.value, s, 16);
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
512 RS232_puts(s);
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
513 RS232_putc(':');
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
514 ultoa(clk.value, s, 16);
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
515 RS232_puts(s);
47
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
516 RS232_putc('\n');
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
517 }
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
518 slot[car0-1].lap_time_start.value = clk.value;
44
4f4326794ba4 implemented lap time, there is some bug in 32bit substraction yet
Malte Bayer <mbayer@neo-soft.org>
parents: 43
diff changeset
519 }
41
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
520 }
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
521 } car0 = 0;
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
522
83
c8e7a69a318a added pitlane speedlimit
Malte Bayer <mbayer@neo-soft.org>
parents: 81
diff changeset
523
41
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
524 if (car1 != car1_state) {
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
525 car1_state = car1;
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
526 if (car1_state != 0) {
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
527 diff.value = clk.value - slot[car1-1].lap_time_start.value;
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
528 if ( diff.value > 3000 ) { // minimum 1.5 second for 1 lap!
47
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
529 if (slot[car1-1].lap_time_start.value != 0) {
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
530 slot[car1-1].lap_time.value = diff.value;
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
531 slot[car1-1].laps++;
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
532 RS232_puts("L:1:"); // 1 = AA
47
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
533 itoa(slot[car1-1].laps, s, 16);
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
534 RS232_puts(s);
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
535 RS232_putc(':');
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
536 RS232_putc('0'+car1_state);
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
537 RS232_putc(':');
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
538 ultoa(diff.value, s, 16);
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
539 RS232_puts(s);
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
540 RS232_putc(':');
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
541 ultoa(clk.value, s, 16);
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
542 RS232_puts(s);
47
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
543 RS232_putc('\n');
34ac9f92bc1e implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents: 46
diff changeset
544 }
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
545 slot[car1-1].lap_time_start.value = clk.value;
44
4f4326794ba4 implemented lap time, there is some bug in 32bit substraction yet
Malte Bayer <mbayer@neo-soft.org>
parents: 43
diff changeset
546 }
41
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
547 }
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
548 } car1 = 0;
83
c8e7a69a318a added pitlane speedlimit
Malte Bayer <mbayer@neo-soft.org>
parents: 81
diff changeset
549
41
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
550 }
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
551
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
552 void slot_liveinfo(uint8_t idx) {
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
553 if (liveinfo == 0) return;
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
554 // increment packet counter, if == 10 output some live info
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
555 if (slot[idx].seccnt == 10) {
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
556 // output current fuel status
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
557 RS232_putc('F');
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
558 RS232_putc(':');
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
559 RS232_putc(idx + '0');
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
560 RS232_putc(':');
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
561 itoa(slot[idx].fuel, s, 16);
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
562 RS232_puts(s);
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
563 RS232_putc(':');
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
564 ultoa(sysclk.value, s, 16);
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
565 RS232_puts(s);
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
566 RS232_putc('\n');
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
567
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
568 slot[idx].seccnt = 0;
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
569 } else slot[idx].seccnt++;
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
570 }
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
571
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
572 int main(void)
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
573 {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
574
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
575 uint8_t packet_index = 1;
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
576
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
577
41
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
578
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
579 init_hardware();
36
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
580 reset_vars();
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
581 LED(3, 1); // enable middle led == idle mode
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
582
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
583 // switch on rails power
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
584 RAIL_POWER_PORT |= _BV(RAIL_POWER);
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
585
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
586 while (1) {
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
587 // check for short circuit on the rails
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
588 check_rails_shortcut();
41
9857c18c5e64 implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents: 37
diff changeset
589 check_cars();
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 83
diff changeset
590 while (mode == 0xff) panic_mode();
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
591
33
c261350bb394 fixed shortcut detection
Malte Bayer <mbayer@neo-soft.org>
parents: 11
diff changeset
592 if (response_len > 0) {
c261350bb394 fixed shortcut detection
Malte Bayer <mbayer@neo-soft.org>
parents: 11
diff changeset
593 itoa(response, s, 2);
c261350bb394 fixed shortcut detection
Malte Bayer <mbayer@neo-soft.org>
parents: 11
diff changeset
594 response_len = 0;
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
595 //RS232_puts("ANSWER RX: ");
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
596 //RS232_puts(s);
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 75
diff changeset
597 //RS232_putc('\n');
33
c261350bb394 fixed shortcut detection
Malte Bayer <mbayer@neo-soft.org>
parents: 11
diff changeset
598 }
c261350bb394 fixed shortcut detection
Malte Bayer <mbayer@neo-soft.org>
parents: 11
diff changeset
599
c261350bb394 fixed shortcut detection
Malte Bayer <mbayer@neo-soft.org>
parents: 11
diff changeset
600
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
601 // read in button presses
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
602 btn_start = (PIN(SW_START_PORT) & _BV(SW_START));
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
603 if (old_start != btn_start) {
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
604 // start button changed
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
605 if (btn_start == 0) {
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
606 // start button press active
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
607 if (mode == 0) {
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
608 mode = 1; // set wait for race start mode
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
609 reset_vars();
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
610 LED(1, 1);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
611 LED(2, 1);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
612 LED(3, 1);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
613 LED(4, 1);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
614 LED(5, 1);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
615 RS232_puts_p(prepare);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
616 } else if (mode == 1) {
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
617 // Initiate race countdown
46
d200e3d8a550 corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents: 45
diff changeset
618 sysclk.value = 0;
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
619 countdown = 5;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
620 countdown_loops = COUNTDOWN_DELAY;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
621 mode = 2;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
622 LED(1, 0);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
623 LED(2, 0);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
624 LED(3, 0);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
625 LED(4, 0);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
626 LED(5, 0);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
627 RS232_puts_p(countdownstart);
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
628 }
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
629 }
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
630 old_start = btn_start;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
631 }
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
632
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
633 if (mode==3) {
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
634 // RACE START!
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
635 // issue reset command to lap counter
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
636 mode = 0;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
637 RS232_puts_p(racestart);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
638 program_command = 6;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
639 program_parameter = 9;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
640 program_id = 0;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
641 program_count = 1;
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
642 LAP_COUNTER_PORT |= _BV(LAP_COUNTER);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
643 // TODO: beep long
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
644 _delay_us(50);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
645 LAP_COUNTER_PORT &= ~_BV(LAP_COUNTER);
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
646 }
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
647
7
f4e250d5402b fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents: 6
diff changeset
648
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
649 switch (packet_index) {
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
650 case 1:
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
651 if (program_count > 0) {
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
652 // command in queue
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
653 if (do_program(program_id, program_command, program_parameter)) {
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
654 packet_index++;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
655 program_count--;
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
656 }
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
657 } else {
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
658 // output idle command
11
69c2a1408619 done code for sniffing the rails
Malte Bayer <mbayer@neo-soft.org>
parents: 10
diff changeset
659 if (do_program(7, 19, 0)) packet_index++; // reset
8
84249ab5d691 debugging stuff
Malte Bayer <mbayer@neo-soft.org>
parents: 7
diff changeset
660 //if (do_program(7, 20, 15)) packet_index++; // reset / pitstop detect
11
69c2a1408619 done code for sniffing the rails
Malte Bayer <mbayer@neo-soft.org>
parents: 10
diff changeset
661 //if (insert_queue(0, 0)) packet_index++; // null command
4
58529e14c45c implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents: 3
diff changeset
662 }
37
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
663
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
664 if ( (packet_index>1) && (mode == 2) ) countdown_progress();
136a79772098 implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
665
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
666 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
667 case 2:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
668 if (do_pace_ghost()) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
669 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
670 case 3:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
671 if (do_active()) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
672 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
673 case 4:
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
674 if (do_controller(0)) { packet_index++;
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
675 slot_liveinfo(0);
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
676 }
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
677 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
678 case 5:
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
679 if (do_controller(4)) { packet_index++;
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
680 slot_liveinfo(4);
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
681 }
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
682 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
683 case 6:
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
684 if (do_controller(1)) { packet_index++;
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
685 slot_liveinfo(1);
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
686 }
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
687 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
688 case 7:
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
689 if (do_controller(5)) { packet_index++;
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
690 slot_liveinfo(5);
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
691 }
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
692 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
693 case 8:
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
694 if (do_controller(2)) { packet_index++;
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
695 slot_liveinfo(2);
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
696 }
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
697 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
698 case 9:
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
699 if (do_active()) packet_index++;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
700 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
701 case 10:
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
702 if (do_controller(3)) { packet_index = 1;
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
703 slot_liveinfo(3);
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
704 }
2
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
705 // last packet, so reset packet index
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
706 break;
6c59b4293fa9 finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents: 0
diff changeset
707 }
0
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
708
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
709
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
710 } // main loop end
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
711 };
9b7de464f0ea initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
712

mercurial