Skip to content

Commit f4c1867

Browse files
authored
Merge pull request #2 from amrikarisma/bugfix/delay
Bugfix/delay
2 parents 40d3a8f + 0b99ed9 commit f4c1867

1 file changed

Lines changed: 96 additions & 84 deletions

File tree

src/ESP32_DevkitC_3.5_SPI.ino

Lines changed: 96 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool clientConnected = true;
5454

5555
uint8_t iat = 0, clt = 0;
5656
uint8_t refreshRate = 0;
57-
unsigned int rpm = 6000, lastRpm, vss = 0;
57+
unsigned int rpm = 0, lastRpm, vss = 0;
5858
int mapData, tps, adv, fp;
5959
float bat = 0.0, afrConv = 0.0;
6060
bool syncStatus, fan, ase, wue, rev, launch, airCon, dfco;
@@ -96,19 +96,14 @@ void setup()
9696
CAN0.begin(1000000); // 1Mbps
9797
CAN0.watchFor(0x360); // RPM, MAP, TPS
9898
CAN0.watchFor(0x361); // Fuel Pressure
99+
CAN0.watchFor(0x362); // Ignition Angle (Leading)
99100
CAN0.watchFor(0x368); // AFR 01
100-
// CAN0.watchFor(0x370); // VSS
101+
CAN0.watchFor(0x370); // VSS
101102
CAN0.watchFor(0x372); // Voltage
102103
CAN0.watchFor(0x3E0); // CLT, IAT
103-
xTaskCreatePinnedToCore(
104-
canTask,
105-
"CAN Task",
106-
4096,
107-
NULL,
108-
1,
109-
NULL,
110-
0
111-
);
104+
CAN0.watchFor(0x3E4); // Indicator
105+
106+
xTaskCreatePinnedToCore(canTask, "CAN Task", 4096, NULL, 1, NULL, 0);
112107

113108
Serial.println("CAN mode aktif.");
114109
}
@@ -118,38 +113,38 @@ void setup()
118113
Serial.println("Serial mode aktif.");
119114
}
120115

121-
WiFi.mode(WIFI_MODE_AP);
122-
WiFi.softAPConfig(ip, ip, netmask);
123-
WiFi.softAP(ssid, password);
124-
125-
server.on("/", HTTP_GET, handleRoot);
126-
server.on(
127-
"/update", HTTP_POST, []()
128-
{
129-
server.send(200, "text/plain", (Update.hasError()) ? "Gagal update!" : "Update berhasil! MAZDUINO Display akan restart.");
130-
delay(1000);
131-
ESP.restart(); },
132-
handleUpdate);
133-
server.on("/toggle", HTTP_POST, handleToggle); // Endpoint untuk toggle
134-
server.on("/setMode", HTTP_POST, []()
135-
{
136-
String mode = server.arg("mode");
137-
if (mode == "serial")
138-
{
139-
commMode = COMM_SERIAL;
140-
}
141-
else if (mode == "can")
142-
{
143-
commMode = COMM_CAN;
144-
}
145-
EEPROM.write(1, commMode);
146-
EEPROM.commit();
147-
server.send(200, "text/plain", "Mode updated");
148-
ESP.restart(); // Restart untuk menerapkan perubahan
149-
});
150-
server.begin();
151-
Serial.println("Web server aktif.");
152-
esp_wifi_set_max_tx_power(78);
116+
// WiFi.mode(WIFI_MODE_AP);
117+
// WiFi.softAPConfig(ip, ip, netmask);
118+
// WiFi.softAP(ssid, password);
119+
120+
// server.on("/", HTTP_GET, handleRoot);
121+
// server.on(
122+
// "/update", HTTP_POST, []()
123+
// {
124+
// server.send(200, "text/plain", (Update.hasError()) ? "Gagal update!" : "Update berhasil! MAZDUINO Display akan restart.");
125+
// delay(1000);
126+
// ESP.restart(); },
127+
// handleUpdate);
128+
// server.on("/toggle", HTTP_POST, handleToggle); // Endpoint untuk toggle
129+
// server.on("/setMode", HTTP_POST, []()
130+
// {
131+
// String mode = server.arg("mode");
132+
// if (mode == "serial")
133+
// {
134+
// commMode = COMM_SERIAL;
135+
// }
136+
// else if (mode == "can")
137+
// {
138+
// commMode = COMM_CAN;
139+
// }
140+
// EEPROM.write(1, commMode);
141+
// EEPROM.commit();
142+
// server.send(200, "text/plain", "Mode updated");
143+
// ESP.restart(); // Restart untuk menerapkan perubahan
144+
// });
145+
// server.begin();
146+
// Serial.println("Web server aktif.");
147+
// esp_wifi_set_max_tx_power(78);
153148

154149
EEPROM.write(0, 1);
155150
delay(500);
@@ -179,12 +174,12 @@ void loop()
179174
handleSerialCommunication();
180175
}
181176

182-
static uint32_t lastDraw = 0;
183-
if (millis() - lastDraw > 25)
184-
{ // Update every 100ms
185-
drawData();
186-
lastDraw = millis();
187-
}
177+
// static uint32_t lastDraw = 0;
178+
// if (millis() - lastDraw > 25)
179+
// { // Update every 100ms
180+
drawData();
181+
// lastDraw = millis();
182+
// }
188183

189184
// if (millis() - lastClientCheck >= 1000)
190185
// {
@@ -239,15 +234,15 @@ void handleCANCommunication()
239234
CAN_FRAME can_message;
240235
if (CAN0.read(can_message))
241236
{
242-
Serial.print("ID: ");
243-
Serial.print(can_message.id, HEX);
244-
Serial.print(" Data: ");
245-
for (int i = 0; i < can_message.length; i++)
246-
{
247-
Serial.print(can_message.data.byte[i], HEX);
248-
Serial.print(" ");
249-
}
250-
Serial.println();
237+
// Serial.print("ID: ");
238+
// Serial.print(can_message.id, HEX);
239+
// Serial.print(" Data: ");
240+
// for (int i = 0; i < can_message.length; i++)
241+
// {
242+
// Serial.print(can_message.data.byte[i], HEX);
243+
// Serial.print(" ");
244+
// }
245+
// Serial.println();
251246

252247
// Proses data berdasarkan ID
253248
switch (can_message.id)
@@ -289,14 +284,29 @@ void handleCANCommunication()
289284
case 0x3E0:
290285
{ // CLT
291286
uint16_t clt_raw = (can_message.data.byte[0] << 8) | can_message.data.byte[1]; // Byte 0-1
292-
uint16_t iat_raw = (can_message.data.byte[2] << 8) | can_message.data.byte[3]; // Byte 0-1
287+
uint16_t iat_raw = (can_message.data.byte[2] << 8) | can_message.data.byte[3]; // Byte 2-3
293288
float clt_k = clt_raw / 10.0;
294289
float iat_k = iat_raw / 10.0;
295290

296291
clt = clt_k - 273.15;
297292
iat = iat_k - 273.15;
298293
break;
299294
}
295+
case 0x3E4:
296+
{ // Indicator
297+
launch = (can_message.data.byte[2] << 8) | can_message.data.byte[6]; // Byte 2-6
298+
airCon = (can_message.data.byte[3] << 8) | can_message.data.byte[4]; // Byte 3-4
299+
fan = (can_message.data.byte[3] << 8) | can_message.data.byte[0]; // Byte 3-0
300+
rev = (can_message.data.byte[2] << 8) | can_message.data.byte[5]; // Byte 2-5
301+
break;
302+
}
303+
case 0x362:
304+
{ // Ignition Advance
305+
uint16_t adv_raw = (can_message.data.byte[4] << 8) | can_message.data.byte[5]; // Byte 4-5
306+
adv = adv_raw / 10.0;
307+
break;
308+
}
309+
300310
default:
301311
break;
302312
}
@@ -307,30 +317,32 @@ void handleCANCommunication()
307317
}
308318
}
309319

310-
// if (currentTime - lastPrintTime >= 1000)
311-
// { // Interval 1000ms
312-
// Serial.print("RPM: ");
313-
// Serial.print(rpm);
314-
// Serial.print(" MAP: ");
315-
// Serial.print(mapData);
316-
// Serial.print(" kPa TPS: ");
317-
// Serial.print(tps);
318-
// Serial.print(" % Fuel Pressure: ");
319-
// Serial.print(fp);
320-
// Serial.print(" kPa AFR: ");
321-
// Serial.print(afrConv, 2);
322-
// Serial.print(" VSS: ");
323-
// Serial.print(vss);
324-
// Serial.print(" km/h Voltage: ");
325-
// Serial.print(bat, 2);
326-
// Serial.print(" V CLT: ");
327-
// Serial.print(clt);
328-
// Serial.print(" °C IAT: ");
329-
// Serial.print(iat);
330-
// Serial.println(" °C");
331-
332-
// lastPrintTime = currentTime;
333-
// }
320+
if (currentTime - lastPrintTime >= 1000)
321+
{ // Interval 1000ms
322+
Serial.print("RPM: ");
323+
Serial.print(rpm);
324+
Serial.print(" MAP: ");
325+
Serial.print(mapData);
326+
Serial.print(" kPa TPS: ");
327+
Serial.print(tps);
328+
Serial.print(" % ADV:");
329+
Serial.print(adv);
330+
Serial.print(" ° Fuel Pressure: ");
331+
Serial.print(fp);
332+
Serial.print(" kPa AFR: ");
333+
Serial.print(afrConv, 2);
334+
Serial.print(" VSS: ");
335+
Serial.print(vss);
336+
Serial.print(" km/h Voltage: ");
337+
Serial.print(bat, 2);
338+
Serial.print(" V CLT: ");
339+
Serial.print(clt);
340+
Serial.print(" °C IAT: ");
341+
Serial.print(iat);
342+
Serial.println(" °C");
343+
344+
lastPrintTime = currentTime;
345+
}
334346
}
335347

336348
void handleSerialCommunication()
@@ -560,7 +572,7 @@ void startUpDisplay()
560572
display.drawString("RPM", 190, 120);
561573
itemDraw(true);
562574
spr.loadFont(AA_FONT_LARGE);
563-
for (int i = rpm; i >= 0; i -= 250)
575+
for (int i = 6000; i >= 0; i -= 250)
564576
{
565577
drawRPMBarBlocks(i);
566578
spr.createSprite(100, 50);

0 commit comments

Comments
 (0)