-
Notifications
You must be signed in to change notification settings - Fork 0
/
RaceLogic.h
134 lines (107 loc) · 3.17 KB
/
RaceLogic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef _RACELOGIC_H_
#define _RACELOGIC_H_
namespace RaceLogicEnum {
enum RaceStatus {
IDLE,
COUNTDOWN,
START,
FINISH,
FALSE_START,
SYSTEM_STATUS,
TOGGLE_MODE,
LAP
};
enum SystemStatus {
OK,
ERROR_OPTIC_START,
ERROR_OPTIC_FINISH
};
enum LogicMode {
MODE_TRACK,
MODE_LAP
};
}
struct DataPackage {
RaceLogicEnum::RaceStatus race_status;
RaceLogicEnum::SystemStatus system_status;
RaceLogicEnum::LogicMode logic_mode;
double velocity;
int lap_count;
unsigned long lap_time;
unsigned long best_time;
unsigned long timestamp; // timestamp to make RF24 packets different each time
};
class RaceLogic {
public:
virtual void loop();
virtual void rc_command(unsigned long hex) {}
virtual void process_radio_data (DataPackage data);
protected:
virtual void event_idle() {}
virtual void event_countdown() {}
virtual void event_start() {}
virtual void event_finish() {}
virtual void event_false_start() {}
virtual void event_passthrough() {}
virtual void event_system_status() {}
virtual void event_toggle_mode() {}
virtual bool event_lap() {}
void set_time_idle_reset(unsigned long timeout = RACE_DEFAULT_TIMEOUT);
void send_radio_data();
RaceLogicEnum::RaceStatus race_status = RaceLogicEnum::IDLE;
RaceLogicEnum::SystemStatus system_status = RaceLogicEnum::OK;
RaceLogicEnum::LogicMode logic_mode = RaceLogicEnum::MODE_TRACK;
unsigned long time_idle_reset = 0;
unsigned long time_start = 0;
unsigned long time_finish = 0;
unsigned long time_lap_start = 0;
double velocity;
int lap_count;
unsigned long lap_time;
unsigned long best_time;
};
extern RaceLogic *s_pRaceLogic;
class RaceLogicStart : public RaceLogic {
public:
void rc_command(unsigned long hex);
void loop();
protected:
virtual void event_idle();
virtual void event_countdown();
virtual void event_start();
virtual void event_finish();
virtual void event_false_start();
virtual void event_passthrough();
virtual void event_system_status();
virtual void event_toggle_mode();
virtual bool event_lap();
private:
int start_signal_type = 0;
void toggle_start_pattern();
void toggle_logic_mode();
unsigned long time_rc = 0;
};
class RaceLogicFinish : public RaceLogic {
public:
void loop();
protected:
virtual void event_idle();
virtual void event_countdown();
virtual void event_start();
virtual void event_finish();
virtual void event_false_start();
virtual void event_passthrough();
virtual void event_system_status();
virtual void event_toggle_mode();
virtual bool event_lap();
private:
double start_velocity = 0;
void print_velocity(String title, double velocity);
void print_time(String title, unsigned long time);
void print_right_with_space(String str, int row);
String time_to_str(unsigned long time);
int finish_display = 0;
unsigned long time_next_toggle = 0;
void toggle_finish_display();
};
#endif