Fri, 09 Dec 2011 20:02:17 +0100
added pitlane skeleton based on trackswitch
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 | |
45 | 22 | typedef union { |
46
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
23 | uint32_t value; |
45 | 24 | uint16_t word[2]; // high, low word |
25 | uint8_t byte[4]; // all four bytes | |
26 | } u32; | |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
27 | |
46
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
28 | #define MAX_SLOTS 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
|
29 | #define FUEL_FULL 10000 |
62
66dd5763dfb3
added car5+6 to trackswitch detector
Malte Bayer <mbayer@neo-soft.org>
parents:
60
diff
changeset
|
30 | #define FUEL_DIVISOR 25 |
66dd5763dfb3
added car5+6 to trackswitch detector
Malte Bayer <mbayer@neo-soft.org>
parents:
60
diff
changeset
|
31 | //#define FUEL_DIVISOR 10 |
46
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
32 | typedef struct { |
49
3957ff8e86c6
more memsave through packed structure#
Malte Bayer <mbayer@neo-soft.org>
parents:
48
diff
changeset
|
33 | unsigned speedlimit:4; // 4bits speedlimit |
3957ff8e86c6
more memsave through packed structure#
Malte Bayer <mbayer@neo-soft.org>
parents:
48
diff
changeset
|
34 | 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
|
35 | 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
|
36 | 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
|
37 | unsigned trackswitch:1; // 1bit bool |
60
bfc2f2d6913c
added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents:
59
diff
changeset
|
38 | 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
|
39 | 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
|
40 | 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
|
41 | } cardata; |
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
42 | |
59
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
43 | static char s[8]; |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
44 | static uint8_t countdown, countdown_loops; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
45 | uint8_t mode = 0; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
46 | // valid race modes: |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
47 | // 0: free drive / idle |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
48 | // 1: waiting for countdown start |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
49 | // 2: race countdown initiated |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
50 | // 3: Race start condition |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
51 | |
45 | 52 | volatile u32 sysclk; |
42
018d4d63ad3b
implemented 500ns timer and set jumpstart time
Malte Bayer <mbayer@neo-soft.org>
parents:
41
diff
changeset
|
53 | 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
|
54 | 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
|
55 | |
48
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
56 | volatile uint8_t car0, car1; |
41
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
57 | volatile uint16_t car0_new, car0_old; |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
58 | volatile uint16_t car1_new, car1_old; |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
59 | 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
|
60 | |
4
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
61 | volatile uint8_t program_count = 0; |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
62 | volatile uint8_t program_id; |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
63 | volatile uint8_t program_command; |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
64 | volatile uint8_t program_parameter; |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
65 | |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
66 | volatile uint8_t datalen = 0; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
67 | char data[10]; // 8 bytes data buffer + string termination |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
68 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
69 | static char buffer[RS232_BUFSIZE+1]; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
70 | static uint8_t buffer_len; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
71 | |
6
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
72 | volatile uint16_t transmit_buffer; |
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
73 | volatile uint16_t transmit_buffer_queue; |
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
74 | volatile uint8_t transmit_len; |
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
75 | volatile uint8_t transmit_len_next; |
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
76 | volatile uint8_t transmit_len_queue; |
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
77 | |
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
78 | volatile uint16_t response; |
33 | 79 | volatile uint8_t response_len; |
6
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
80 | volatile uint8_t timer0_delay; |
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
81 | |
2405aff29a51
added response receiver timer
Malte Bayer <mbayer@neo-soft.org>
parents:
5
diff
changeset
|
82 | |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
34
diff
changeset
|
83 | 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
|
84 | 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
|
85 | 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
|
86 | 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
|
87 | return 1; |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
34
diff
changeset
|
88 | } |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
34
diff
changeset
|
89 | return 0; |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
34
diff
changeset
|
90 | } |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
34
diff
changeset
|
91 | |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
92 | 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
|
93 | uint8_t tmp; |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
94 | char c = UDR; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
95 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
96 | // check for buffer overflow |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
97 | if (buffer_len==sizeof(buffer)) { |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
98 | buffer_len=0; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
99 | } else { |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
100 | // 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
|
101 | if ( (c=='\n') ) { |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
102 | buffer[buffer_len]=0; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
103 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
104 | // packet end received, parse the received packet |
4
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
105 | switch (buffer[0]) { |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
106 | 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
|
107 | if (program_count == 0) { |
7319de27d44a
added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents:
4
diff
changeset
|
108 | program_id = buffer[3]-'0'; |
7319de27d44a
added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents:
4
diff
changeset
|
109 | program_command = buffer[1]-'0'; |
10 | 110 | if (program_command > 9) |
111 | 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
|
112 | program_parameter = buffer[2]-'0'; |
10 | 113 | if (program_parameter > 9) |
114 | 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
|
115 | if (program_command < 4) |
7319de27d44a
added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents:
4
diff
changeset
|
116 | 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
|
117 | else |
7319de27d44a
added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents:
4
diff
changeset
|
118 | 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
|
119 | 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
|
120 | } 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
|
121 | 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
|
122 | |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
123 | 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
|
124 | 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
|
125 | 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
|
126 | 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
|
127 | 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
|
128 | RS232_puts_p(ok); |
5
7319de27d44a
added queue busy response on command injection
Malte Bayer <mbayer@neo-soft.org>
parents:
4
diff
changeset
|
129 | break; |
4
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
130 | |
48
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
131 | 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
|
132 | tmp = buffer[2]-'0'; |
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
133 | if (tmp > 9) |
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
134 | 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
|
135 | 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
|
136 | RS232_puts_p(ok); |
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
137 | break; |
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
138 | |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
139 | 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
|
140 | RS232_puts(VERSION); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
141 | RS232_putc(':'); |
46
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
142 | 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
|
143 | RS232_putc(':'); |
48
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
144 | 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
|
145 | RS232_putc(':'); |
43
4e5d389f7b83
jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents:
42
diff
changeset
|
146 | 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
|
147 | itoa(slot[tmp].fuel, s, 16); |
43
4e5d389f7b83
jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents:
42
diff
changeset
|
148 | 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
|
149 | RS232_putc(','); |
4e5d389f7b83
jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents:
42
diff
changeset
|
150 | } |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
151 | RS232_putc(':'); |
43
4e5d389f7b83
jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents:
42
diff
changeset
|
152 | 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
|
153 | itoa(slot[tmp].jumpstart_time, s, 16); |
43
4e5d389f7b83
jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents:
42
diff
changeset
|
154 | RS232_puts(s); // output jumpstart times |
4e5d389f7b83
jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents:
42
diff
changeset
|
155 | RS232_putc(','); |
4e5d389f7b83
jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents:
42
diff
changeset
|
156 | } |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
157 | RS232_putc(':'); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
158 | RS232_putc('\n'); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
159 | break; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
160 | |
4
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
161 | } |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
162 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
163 | // wait for the next packet |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
164 | buffer_len=0; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
165 | } else { |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
166 | buffer[buffer_len++]=c; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
167 | } |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
168 | } |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
169 | } |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
170 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
171 | |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
172 | 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
|
173 | 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
|
174 | 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
|
175 | RS232_putc('~'); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
176 | 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
|
177 | RS232_putc(':'); |
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
178 | itoa(slot[controller].jumpstart_time, s, 16); |
43
4e5d389f7b83
jumpstart time output via interface
Malte Bayer <mbayer@neo-soft.org>
parents:
42
diff
changeset
|
179 | RS232_puts(s); |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
180 | RS232_putc('\n'); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
181 | } |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
182 | |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
183 | } |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
184 | |
59
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
185 | uint8_t do_controller(uint8_t controller) { |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
186 | // 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
|
187 | 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
|
188 | 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
|
189 | 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
|
190 | |
48
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
191 | 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
|
192 | // 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
|
193 | 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
|
194 | 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
|
195 | 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
|
196 | 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
|
197 | 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
|
198 | } else { |
ec9e8cc27012
car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents:
49
diff
changeset
|
199 | // 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
|
200 | 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
|
201 | 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
|
202 | 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
|
203 | 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
|
204 | 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
|
205 | 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
|
206 | 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
|
207 | 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
|
208 | |
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
209 | if (controller < 4) { |
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
210 | if (tmp < slot[controller].speedminimum) tmp = slot[controller].speedminimum; |
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
211 | if ((mode == 2) && (tmp != 0)) { jumpstart(controller); tmp = 0; } |
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
212 | 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
|
213 | speed = tmp; |
52
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
214 | tmp = tmp << 1; |
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
215 | } else { |
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
216 | 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
|
217 | 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
|
218 | speed = tmp; |
52
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
219 | tmp = tmp << 1; |
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
220 | if (trackchange || slot[controller].trackswitch) tmp |= (1<<5); |
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
221 | } |
59
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
222 | |
48
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
223 | } |
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
224 | |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
225 | switch (controller) { |
3 | 226 | 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
|
227 | if (trackchange != 0) { |
10 | 228 | tmp |= (1<<5); |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
229 | 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
|
230 | } else if (mode == 0) LED(1,1); |
3 | 231 | break; |
232 | 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
|
233 | if (trackchange != 0) { |
10 | 234 | tmp |= (1<<5); |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
235 | 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
|
236 | } else if (mode == 0) LED(2,1); |
3 | 237 | break; |
238 | 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
|
239 | if (trackchange != 0) { |
10 | 240 | tmp |= (1<<5); |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
241 | 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
|
242 | } else if (mode == 0) LED(4,1); |
3 | 243 | break; |
244 | 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
|
245 | if (trackchange != 0) { |
10 | 246 | tmp |= (1<<5); |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
247 | 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
|
248 | } else if (mode == 0) LED(5,1); |
3 | 249 | break; |
52
6b26d7e3ecd0
simplified do_controller function
Malte Bayer <mbayer@neo-soft.org>
parents:
51
diff
changeset
|
250 | } |
48
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
251 | |
34 | 252 | tmp |= (0b1000000000 | (controller << 6)); |
60
bfc2f2d6913c
added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents:
59
diff
changeset
|
253 | // 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
|
254 | // 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
|
255 | 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
|
256 | if (insert_queue(tmp, 9)) { |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
257 | if (speed != 0) { |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
258 | // do the fuel calculation, regardless if fuel logic active or not |
60
bfc2f2d6913c
added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents:
59
diff
changeset
|
259 | tmp = (uint8_t)(((slot[controller].accel * speed) + 1) / FUEL_DIVISOR); |
59
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
260 | if (tmp == 0) tmp = 1; |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
261 | if (slot[controller].fuel > 0) { |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
262 | // enough fuel left to decrement? |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
263 | if (slot[controller].fuel > tmp) { |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
264 | slot[controller].fuel -= tmp; // decrement fuel level |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
265 | } else slot[controller].fuel = 0; |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
266 | } |
60
bfc2f2d6913c
added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents:
59
diff
changeset
|
267 | } else if (slot[controller].canrefuel) { |
bfc2f2d6913c
added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents:
59
diff
changeset
|
268 | // increase fuel by 5%/sec, this equals by adding 50 to the counter |
bfc2f2d6913c
added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents:
59
diff
changeset
|
269 | slot[controller].fuel += 50; |
bfc2f2d6913c
added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents:
59
diff
changeset
|
270 | 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
|
271 | } |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
272 | return 1; |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
273 | } else return 0; |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
274 | } |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
275 | |
4
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
276 | uint8_t mirror( uint8_t n ) { |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
277 | n = ((n >> 1) & 0x55) | ((n << 1) & 0xaa); |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
278 | n = ((n >> 2) & 0x33) | ((n << 2) & 0xcc); |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
279 | n = ((n >> 4) & 0x0f) | ((n << 4) & 0xf0); |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
280 | return n; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
281 | } |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
282 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
283 | 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
|
284 | // send program data packet |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
285 | uint16_t tmp; |
4
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
286 | parameter = mirror(parameter); |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
287 | controller = mirror(controller); |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
288 | command = mirror(command); |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
289 | tmp = 0b1000000000000 | (parameter << 4) | command | (controller >> 5); |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
290 | return insert_queue(tmp, 12); |
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 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
293 | int do_active(void) { |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
294 | // send controller active data packet |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
295 | 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
|
296 | 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
|
297 | // 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
|
298 | 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
|
299 | 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
|
300 | } else { |
ec9e8cc27012
car id setting for slot 5+6 working via pressing pacecar button
Malte Bayer <mbayer@neo-soft.org>
parents:
49
diff
changeset
|
301 | 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
|
302 | 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
|
303 | 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
|
304 | 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
|
305 | 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
|
306 | 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
|
307 | } |
4
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
308 | // 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
|
309 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
310 | return insert_queue(tmp, 7); |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
311 | } |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
312 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
313 | int do_pace_ghost(void) { |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
314 | // send ghost and pacecar data packet |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
315 | // todo: at the moment, both disabled! |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
316 | uint16_t tmp = 0b1111100000; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
317 | 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
|
318 | // todo: PC, NH, TK, (KFR, FR) |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
319 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
320 | return insert_queue(tmp, 9); |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
321 | } |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
322 | |
53
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
52
diff
changeset
|
323 | #include "interrupts.c" |
7
f4e250d5402b
fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents:
6
diff
changeset
|
324 | |
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
|
325 | 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
|
326 | 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
|
327 | 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
|
328 | slot[i].speedlimit = 15; |
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
329 | slot[i].speedminimum = 0; |
5bba01aad0a6
memsave and implemented minimum slot speed for virtual cars
Malte Bayer <mbayer@neo-soft.org>
parents:
47
diff
changeset
|
330 | 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
|
331 | 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
|
332 | 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
|
333 | 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
|
334 | 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
|
335 | slot[i].accel = 15; // full acceleration per default - TODO |
60
bfc2f2d6913c
added refueling mechanism by stopping the car
Malte Bayer <mbayer@neo-soft.org>
parents:
59
diff
changeset
|
336 | slot[i].canrefuel = 1; // TODO: only set to 1 when on a pitlane |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
337 | } |
46
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
338 | sysclk.value = 0; |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
339 | } |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
340 | |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
341 | void countdown_progress(void) { |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
342 | // decrement COUNTDOWN_LOOPS |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
343 | if (countdown_loops>0) { |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
344 | countdown_loops--; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
345 | } else { |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
346 | countdown--; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
347 | countdown_loops = COUNTDOWN_DELAY; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
348 | } |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
349 | switch (countdown) { |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
350 | 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
|
351 | 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
|
352 | 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
|
353 | 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
|
354 | 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
|
355 | 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
|
356 | sysclk.value = 0; |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
357 | LEDS_OFF(); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
358 | LED(3, 1); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
359 | mode = 3; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
360 | } 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
|
361 | } |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
362 | } |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
363 | |
41
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
364 | 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
|
365 | u32 clk, diff; |
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
366 | 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
|
367 | |
41
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
368 | if (car0 != car0_state) { |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
369 | car0_state = car0; |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
370 | 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
|
371 | 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
|
372 | 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
|
373 | 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
|
374 | 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
|
375 | slot[car0-1].laps++; |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
376 | RS232_putc('L'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
377 | RS232_putc(':'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
378 | RS232_putc('A'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
379 | RS232_putc(':'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
380 | 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
|
381 | RS232_puts(s); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
382 | RS232_putc(':'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
383 | RS232_putc('0'+car0_state); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
384 | RS232_putc(':'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
385 | ultoa(diff.value, s, 16); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
386 | RS232_puts(s); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
387 | RS232_putc('\n'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
388 | } |
46
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
389 | 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
|
390 | } |
41
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
391 | } |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
392 | } car0 = 0; |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
393 | |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
394 | if (car1 != car1_state) { |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
395 | car1_state = car1; |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
396 | 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
|
397 | 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
|
398 | 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
|
399 | 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
|
400 | 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
|
401 | slot[car1-1].laps++; |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
402 | RS232_putc('L'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
403 | RS232_putc(':'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
404 | RS232_putc('B'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
405 | RS232_putc(':'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
406 | 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
|
407 | RS232_puts(s); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
408 | RS232_putc(':'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
409 | RS232_putc('0'+car1_state); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
410 | RS232_putc(':'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
411 | ultoa(diff.value, s, 16); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
412 | RS232_puts(s); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
413 | RS232_putc('\n'); |
34ac9f92bc1e
implemented lap counter, doesnt count first sensor touch
Malte Bayer <mbayer@neo-soft.org>
parents:
46
diff
changeset
|
414 | } |
46
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
415 | 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
|
416 | } |
41
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
417 | } |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
418 | } car1 = 0; |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
419 | } |
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
420 | |
59
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
421 | void slot_liveinfo(uint8_t idx) { |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
422 | // 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
|
423 | 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
|
424 | // 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
|
425 | 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
|
426 | 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
|
427 | 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
|
428 | 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
|
429 | 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
|
430 | RS232_puts(s); |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
431 | 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
|
432 | |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
53
diff
changeset
|
433 | 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
|
434 | } 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
|
435 | } |
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 | int main(void) |
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 | uint8_t packet_index = 1; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
441 | |
8 | 442 | uint8_t btn_start = _BV(SW_START); |
443 | uint8_t old_start = btn_start; | |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
444 | |
41
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
445 | |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
446 | 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
|
447 | reset_vars(); |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
448 | LED(3, 1); // enable middle led == idle mode |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
449 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
450 | // switch on rails power |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
451 | RAIL_POWER_PORT |= _BV(RAIL_POWER); |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
452 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
453 | while (1) { |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
454 | // check for short circuit on the rails |
2
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
455 | check_rails_shortcut(); |
41
9857c18c5e64
implemented car detection to cu
Malte Bayer <mbayer@neo-soft.org>
parents:
37
diff
changeset
|
456 | check_cars(); |
0
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
457 | |
33 | 458 | if (response_len > 0) { |
459 | itoa(response, s, 2); | |
460 | response_len = 0; | |
461 | RS232_puts("ANSWER RX: "); | |
462 | RS232_puts(s); | |
463 | RS232_putc('\n'); | |
464 | } | |
465 | ||
466 | ||
7
f4e250d5402b
fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents:
6
diff
changeset
|
467 | // read in button presses |
8 | 468 | btn_start = (PIN(SW_START_PORT) & _BV(SW_START)); |
469 | if (old_start != btn_start) { | |
470 | // start button changed | |
471 | if (btn_start == 0) { | |
472 | // start button press active | |
473 | if (mode == 0) { | |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
474 | 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
|
475 | reset_vars(); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
476 | LED(1, 1); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
477 | LED(2, 1); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
478 | LED(3, 1); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
479 | LED(4, 1); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
480 | LED(5, 1); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
481 | RS232_puts_p(prepare); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
482 | } else if (mode == 1) { |
8 | 483 | // Initiate race countdown |
46
d200e3d8a550
corrected lap times, packed data struct for each slotcar
Malte Bayer <mbayer@neo-soft.org>
parents:
45
diff
changeset
|
484 | sysclk.value = 0; |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
485 | countdown = 5; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
486 | countdown_loops = COUNTDOWN_DELAY; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
487 | mode = 2; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
488 | LED(1, 0); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
489 | LED(2, 0); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
490 | LED(3, 0); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
491 | LED(4, 0); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
492 | LED(5, 0); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
493 | RS232_puts_p(countdownstart); |
8 | 494 | } |
495 | } | |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
496 | old_start = btn_start; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
497 | } |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
498 | |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
499 | if (mode==3) { |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
500 | // RACE START! |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
501 | // 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
|
502 | mode = 0; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
503 | RS232_puts_p(racestart); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
504 | program_command = 6; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
505 | program_parameter = 9; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
506 | program_id = 0; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
507 | program_count = 1; |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
508 | 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
|
509 | // TODO: beep long |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
510 | _delay_us(50); |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
511 | 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
|
512 | } |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
513 | |
7
f4e250d5402b
fixes, bound lap counter reset to race start button
Malte Bayer <mbayer@neo-soft.org>
parents:
6
diff
changeset
|
514 | |
2
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
515 | switch (packet_index) { |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
516 | case 1: |
4
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
517 | if (program_count > 0) { |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
518 | // command in queue |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
519 | 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
|
520 | packet_index++; |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
521 | program_count--; |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
522 | } |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
523 | } else { |
58529e14c45c
implemented rs232 program word injection
Malte Bayer <mbayer@neo-soft.org>
parents:
3
diff
changeset
|
524 | // output idle command |
11
69c2a1408619
done code for sniffing the rails
Malte Bayer <mbayer@neo-soft.org>
parents:
10
diff
changeset
|
525 | if (do_program(7, 19, 0)) packet_index++; // reset |
8 | 526 | //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
|
527 | //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
|
528 | } |
37
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
529 | |
136a79772098
implemented race prepare phase, countdown and jumpstart detection
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
530 | 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
|
531 | |
2
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
532 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
533 | case 2: |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
534 | if (do_pace_ghost()) packet_index++; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
535 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
536 | case 3: |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
537 | if (do_active()) packet_index++; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
538 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
539 | 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
|
540 | 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
|
541 | 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
|
542 | } |
2
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
543 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
544 | 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
|
545 | 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
|
546 | 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
|
547 | } |
2
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
548 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
549 | 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
|
550 | 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
|
551 | 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
|
552 | } |
2
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
553 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
554 | 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
|
555 | 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
|
556 | 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
|
557 | } |
2
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
558 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
559 | 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
|
560 | 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
|
561 | 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
|
562 | } |
2
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
563 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
564 | case 9: |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
565 | if (do_active()) packet_index++; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
566 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
567 | 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
|
568 | 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
|
569 | 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
|
570 | } |
2
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
571 | // last packet, so reset packet index |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
572 | break; |
6c59b4293fa9
finished: rails short circuit check
Malte Bayer <mbayer@neo-soft.org>
parents:
0
diff
changeset
|
573 | } |
0
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 | |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
576 | } // main loop end |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
577 | }; |
9b7de464f0ea
initial commit - controller1 working
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
578 |