blackbox/main.c

Tue, 25 Jun 2013 23:52:29 +0200

author
Malte Bayer <mbayer@neo-soft.org>
date
Tue, 25 Jun 2013 23:52:29 +0200
changeset 139
7127e7082ee0
parent 126
0d6fbfaae49b
child 140
f910ad6ed0b6
permissions
-rw-r--r--

switched firmware to binary protocol, TODO: client implementation

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

mercurial