-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2024_Dash_Code_TK.ino
289 lines (234 loc) · 9.62 KB
/
2024_Dash_Code_TK.ino
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#include <CAN_config.h> // LOOK INTO -> not sure where this is, or if it is required. Will test.
#include <ESP32CAN.h>
// ------------------- PIN Definitions ----------------------------------------------------------------------------------------------------------------------
// LOOK INTO -> Pins may not be accurate, not sure if gpio or schematic pins should be used. Currently schematic pin numbers are used with the corresponding gpio pins commented out
#define CANLOW 39 // GPIO 43
#define CANHIGH 40 // GPIO 44
#define radiator_Out_Sig 5 // GPIO 1, Analog input, LOOK INTO -> Rad temps may need calibrated due to no thermocouple circuitry
#define radiator_In_Sig 6 // GPIO 2, Analog input ^
#define rotor_FR_Sig 7 // GPIO 3 LOOK INTO -> Not sure what kind of sensor this is
#define rotor_FL_Sig 8 // GPIO 4 ^
#define pitot_Sig 9 // GPIO 5 , Analog Input, LOOK INTO -> Not entirerly sure what kind of output this will give. I think its a linearly varying voltage w/ air speed
#define flow_Out_Sig 10 // GPIO 6, Note, this one will be a bitch b/c we need to measure the frequency. I will add notes about a test plan for this
#define flow_In_Sig 11 // GPIO 7 ^
#define eight_V_Sense 12 // GPIO 8 Note, this is currently not connected on the board due to KiCAD being shit and creating stupid fucking shorts going against its entire fucking purpose... sore subject sorry
#define five_V_Sense 13 // GPIO 9 , Used for removing any offset in signal measurements usin 5V divider
#define three_V3_Sense 14 // GPIO 10, ^ except with 3V3 divider
#define shiftFive 15 // GPIO 11
#define shiftFour 16 // GPIO 12
#define shiftThree 17 // GPIO 13
#define shiftTwo 18 // GPIO 14
#define shiftOne 21 // GPIO 17
#define allShift 18 // GPIO 18
#define page 25 // This is not connected cause i am a lazy piece of shit.... this can be ignored, only here for debugging...heaven forbid
#define MISO 33 // GPIO 37
#define SCLK 32 // GPIO 36
#define MOSI 31 // GPIO 35
#define lcdCS 29 // GPIO 34
#define lcdINT 28 // GPIO 33
#define adc1CS 19 // GPIO 15
#define adc2CS 20 // GPIO 16
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
// ------------------------ Initializations --------------------------------
// ESP32 dual Core
TaskHandle_t CoreA;
TaskHandle_t CoreB;
// --------------------- Global Definitions --------------------
int dutyCycle = 255; // between 0 & 255 -> value/255 * 100 -> Percent of time lights are on.... aka brightness ----- May need debugging
bool shiftLightsActive = false;
unsigned long previousMillis = 0;
bool instage6 = true; // LOOK INTO -> i dont remember what this was for
int ledState = LOW; // LOOK INTO -> ^
const long interval = 200; // RPM Blink interval (in millis)
// ------------------------------------------------------ Functions ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// --------- Shift Lights --------
void stage0() { // Turns off all lights
analogWrite(shiftOne, 0);
analogWrite(shiftTwo, 0);
analogWrite(shiftThree, 0);
analogWrite(shiftFour, 0);
analogWrite(shiftFive, 0);
analogWrite(shiftAll, 0);
shiftLightsActive = false;
}
void stage1() {
analogWrite(shiftOne, dutyCycle);
analogWrite(shiftTwo, 0);
analogWrite(shiftThree, 0);
analogWrite(shiftFour, 0);
analogWrite(shiftFive, 0);
analogWrite(shiftAll, 0);
shiftLightsActive = true;
}
void stage2() {
analogWrite(shiftOne, dutyCycle);
analogWrite(shiftTwo, dutyCycle);
analogWrite(shiftThree, 0);
analogWrite(shiftFour, 0);
analogWrite(shiftFive, 0);
analogWrite(shiftAll, 0);
shiftLightsActive = true;
}
void stage3() {
analogWrite(shiftOne, dutyCycle);
analogWrite(shiftTwo, dutyCycle);
analogWrite(shiftThree, dutyCycle);
analogWrite(shiftFour, 0);
analogWrite(shiftFive, 0);
analogWrite(shiftAll, 0);
shiftLightsActive = true;
}
void stage4() {
analogWrite(shiftOne, dutyCycle);
analogWrite(shiftTwo, dutyCycle);
analogWrite(shiftThree, dutyCycle);
analogWrite(shiftFour, dutyCycle);
analogWrite(shiftFive, 0);
analogWrite(shiftAll, 0);
shiftLightsActive = true;
}
void stage5() {
analogWrite(shiftOne, dutyCycle);
analogWrite(shiftTwo, dutyCycle);
analogWrite(shiftThree, dutyCycle);
analogWrite(shiftFour, dutyCycle);
analogWrite(shiftFive, dutyCycle);
analogWrite(shiftAll, 0);
shiftLightsActive = true;
}
void stage6() {// this is the blinking red stage
// executes while in stage 6
int currentMillis = millis(); // Blinks lights without holding up code or using interrupt
if(currentMillis - previousMillis >= interval){
previousMillis = millis();
if(ledState == LOW){
analogWrite(shiftOne, 0);
analogWrite(shiftTwo, 0);
analogWrite(shiftThree, 0);
analogWrite(shiftFour, 0);
analogWrite(shiftFive, dutyCycle);
analogWrite(shiftAll, dutyCycle);
ledState = HIGH;
}
else {
analogWrite(shiftOne, 0);
analogWrite(shiftTwo, 0);
analogWrite(shiftThree, 0);
analogWrite(shiftFour, 0);
analogWrite(shiftFive, 0);
analogWrite(shiftAll, 0);
ledState = LOW;
}
}
shiftLightsActive = true;
}
void set_light_stage(uint16_t current_rpm, char current_gear) { // Determines the shift light stage based on current engine RPM
current_rpm = (FlipBytes_2B(current_rpm));
current_gear = current_gear & 0x0F;
if (current_gear == 0b00001111) {
if ((current_rpm >= 11000) && (current_rpm < 11400)) {
stage1();
} else if ((current_rpm >= 11400) && (current_rpm < 11800)) {
stage2();
} else if ((current_rpm >= 11800) && (current_rpm < 12200)) {
stage3();
} else if ((current_rpm >= 12200) && (current_rpm < 12600)) {
stage4();
} else if ((current_rpm >= 12600) && (current_rpm < 13000)) {
stage5();
} else if ((current_rpm >= 13000)) {
stage6();
} else {
stage0();
}
}
else if (current_gear == 0b00000001){
if ((current_rpm >= 11000) && (current_rpm < 11400)) {
stage1();
} else if ((current_rpm >= 11400) && (current_rpm < 11800)) {
stage2();
} else if ((current_rpm >= 11800) && (current_rpm < 12200)) {
stage3();
} else if ((current_rpm >= 12200) && (current_rpm < 12600)) {
stage4();
} else if ((current_rpm >= 12600) && (current_rpm < 13000)) {
stage5();
} else if ((current_rpm >= 13000)) {
stage6();
} else {
stage0();
}
}
else if (current_gear == 0b00000010){
if ((current_rpm > 10200) && (current_rpm < 10600)) {
stage1();
} else if ((current_rpm >= 10600) && (current_rpm < 11000)) {
stage2();
} else if ((current_rpm >= 11000) && (current_rpm < 11400)) {
stage3();
} else if ((current_rpm >= 11400) && (current_rpm < 11800)) {
stage4();
} else if ((current_rpm >= 11800) && (current_rpm < 12200)) {
stage5();
} else if (current_rpm >= 12200) {
stage6();
} else {
stage0();
}
}
else if (current_gear == 0b00000011){
if ((current_rpm > 12000) && (current_rpm < 12500)) {
stage1();
} else if ((current_rpm >= 12500) && (current_rpm < 13000)) {
stage2();
} else if ((current_rpm >= 13000) && (current_rpm < 13500)) {
stage3();
} else if ((current_rpm >= 13500) && (current_rpm < 14000)) {
stage4();
} else if ((current_rpm >= 14000) && (current_rpm < 14500)) {
stage5();
} else if (current_rpm >= 14500) {
stage6();
} else {
stage0();
}
}
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// ------------------------------------------------- SETUP --------------------------------------------
void setup() {
// -------------------------- Multi Core Setup -------------------------------
TaskCreatePinnedToCore(
CoreACode, /* Task function. */
"CoreA", /* name of task. */
10000, /* Stack size of task */ // LOOK INTO THIS
NULL, /* parameter of the task */
1, /* priority of the task */
&TaskA, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(500);
//create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
xTaskCreatePinnedToCore(
CoreBCode, /* Task function. */
"CoreB", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&TaskB, /* Task handle to keep track of created task */
1); /* pin task to core 1 */
delay(500);
// -------------------------------------------------------------------------------------------------------
}// end of Void Setup
// ------------------------------------ MAIN LOOPS -----------------------------------------------
void CoreACode( void * pvParameters )
{
// Core A Code
}
//Code running on core 2
void CoreBCode( void * pvParameters )
{
// Core B Code
}
void loop() {
// put your main code here, to run repeatedly:
}