forked from TheDIYGuy999/Rc_Engine_Sound_ESP32
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashboard.h
186 lines (161 loc) · 5.79 KB
/
dashboard.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* dashboard.h - Library to drive a 80x160px color LCD as rc truck dashboard
*
* https://github.com/Gamadril/ESP32_LASE
* MIT License
*/
#ifndef DASHBOARD_h
#define DASHBOARD_h
//#include "Arduino.h"
#include <TFT_eSPI.h>
#define SCREEN_WIDTH 160
#define SCREEN_HEIGHT 80
#define DEG2RAD 0.0174532925
#define SPEED_MIN 0
#define SPEED_MAX 120
#define RPM_MIN 0
#define RPM_MAX 500
#define FUEL_MIN 0
#define FUEL_MAX 100
#define ADBLUE_MIN 0
#define ADBLUE_MAX 100
#define SPEED_CIRCLE_CENTER_X 40
#define SPEED_CIRCLE_CENTER_Y 35
#define SPEED_CIRCLE_RADIUS 25
#define SPEED_NEEDLE_LENGTH 20
#define SPEED_CIRCLE_ANGLE_START -203 // -180 - 23
#define SPEED_CIRCLE_SEGMENTS 12
#define SPEED_CIRCLE_SEGMENT_ANGLE 18.95
#define SPEED_CIRCLE_ANGLE_END \
SPEED_CIRCLE_ANGLE_START + SPEED_CIRCLE_SEGMENTS *SPEED_CIRCLE_SEGMENT_ANGLE
#define RPM_CIRCLE_CENTER_X SCREEN_WIDTH - 40
#define RPM_CIRCLE_CENTER_Y 35
#define RPM_CIRCLE_RADIUS 25
#define RPM_CIRCLE_ANGLE_START -202 // -180 - 22
#define RPM_CIRCLE_SEGMENTS 25
#define RPM_CIRCLE_SEGMENT_ANGLE 9
#define RPM_CIRCLE_ANGLE_END RPM_CIRCLE_ANGLE_START + RPM_CIRCLE_SEGMENTS *RPM_CIRCLE_SEGMENT_ANGLE
#define FUEL_CIRCLE_CENTER_X 30
#define FUEL_CIRCLE_CENTER_Y 60
#define FUEL_CIRCLE_RADIUS 14
#define FUEL_CIRCLE_ANGLE_START -202 // -180 - 22
#define FUEL_CIRCLE_SEGMENTS 16
#define FUEL_CIRCLE_SEGMENT_ANGLE 14
#define FUEL_CIRCLE_ANGLE_END \
FUEL_CIRCLE_ANGLE_START + FUEL_CIRCLE_SEGMENTS *FUEL_CIRCLE_SEGMENT_ANGLE
#define ADBLUE_CIRCLE_CENTER_X SCREEN_WIDTH - 30
#define ADBLUE_CIRCLE_CENTER_Y 60
#define ADBLUE_CIRCLE_RADIUS 14
#define ADBLUE_CIRCLE_ANGLE_START -202 // -180 - 22
#define ADBLUE_CIRCLE_SEGMENTS 16
#define ADBLUE_CIRCLE_SEGMENT_ANGLE 14
#define ADBLUE_CIRCLE_ANGLE_END \
ADBLUE_CIRCLE_ANGLE_START + ADBLUE_CIRCLE_SEGMENTS *ADBLUE_CIRCLE_SEGMENT_ANGLE
#define INDICATOR_LEFT_CENTER_X SCREEN_WIDTH / 2 - 20
#define INDICATOR_LEFT_CENTER_Y 9
#define INDICATOR_RIGHT_CENTER_X SCREEN_WIDTH / 2 + 20
#define INDICATOR_RIGHT_CENTER_Y 9
const uint8_t LOW_BEAM_ICON[7][13] PROGMEM = {
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
{0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0},
{0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0},
{1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1},
{0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0},
{0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0},
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}};
const uint8_t HIGH_BEAM_ICON[7][13] PROGMEM = {
{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0}};
const uint8_t PUMP_ICON[6][7] PROGMEM = {
{0, 1, 1, 1, 1, 0, 0},
{0, 1, 0, 0, 1, 1, 0},
{0, 1, 0, 0, 1, 0, 1},
{0, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 1, 0}};
/**
* @brief Class acts as a wrapper around TFT_eSPI routines to draw dashboard elements.
*
*/
class Dashboard {
public:
/**
* Default constructor
*/
Dashboard();
/**
* Performs initialization of the display, rotates the coordinate system of the screen
* (0,0) is the upper left corner if the connector is on the top.
* Draws static dashboard elements and sets all values to 0.
*/
void init();
/**
* Sets the state of the left turn signal.
* @param on - true to show the signal, false to deactivate it
*/
void setLeftIndicator(boolean on);
/**
* Sets the state of the right turn signal.
* @param on - true to show the signal, false to deactivate it
*/
void setRightIndicator(boolean on);
/**
* Sets the state of the low beam lights.
* @param on - true to show the indicator, false to deactivate it
*/
void setLowBeamIndicator(boolean on);
/**
* Sets the state of the high beam lights.
* @param on - true to show the indicator, false to deactivate it
*/
void setHighBeamIndicator(boolean on);
/**
* Sets the speed to show by rotating the needle to the right position.
* @param value - speed value between SPEED_MIN and SPEED_MAX
*/
void setSpeed(uint16_t value);
/**
* Sets the RPM to show by rotating the needle to the right position.
* @param value - RPM value between RPM_MIN and RPM_MAX
*/
void setRPM(uint16_t value);
/**
* Sets the fuel level to show by rotating the needle to the right position.
* @param value - fuel value between FUEL_MIN and FUEL_MAX
*/
void setFuelLevel(uint16_t value);
/**
* Sets the AdBlue level to show by rotating the needle to the right position.
* @param value - AdBlue value between ADBLUE_MIN and ADBLUE_MAX
*/
void setAdBlueLevel(uint16_t value);
/**
* Sets the gear to show.
* @param value - -1 for R, 0 for N, > 0 for gear number
*/
void setGear(int8_t value);
private:
TFT_eSPI _tft = TFT_eSPI();
void drawFrame();
void drawArc(int16_t cx, int16_t cy, int16_t r, int16_t deg_start, int16_t deg_end,
uint32_t color);
void drawSep(int16_t cx, int16_t cy, uint16_t len, int16_t deg_pos, uint16_t r, uint32_t color);
void drawNeedle(int16_t cx, int16_t cy, uint16_t len, int16_t deg_pos, uint16_t radius_holder,
uint32_t color_needle);
void drawLeftIndicator(uint32_t color);
void drawRightIndicator(uint32_t color);
void drawLowBeamIndicator(uint32_t color);
void drawHighBeamIndicator(uint32_t color);
void drawSpeed(uint16_t value);
void drawRPM(uint16_t value);
void drawFuel(uint16_t value);
void drawAdBlue(uint16_t value);
void drawPump(uint16_t x, uint16_t y, uint32_t color);
void drawGear(char gear);
};
#endif