Skip to content

Commit a96af37

Browse files
committed
add indicator, FAN, AC, LAUNCH, REV Limiter, disable wifi and web server temporary
1 parent fd90fd3 commit a96af37

1 file changed

Lines changed: 93 additions & 75 deletions

File tree

src/ESP32_DevkitC_3.5_SPI.ino

Lines changed: 93 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ void setup()
100100
// CAN0.watchFor(0x370); // VSS
101101
CAN0.watchFor(0x372); // Voltage
102102
CAN0.watchFor(0x3E0); // CLT, IAT
103+
CAN0.watchFor(0x3E4); // Indicator
104+
103105
xTaskCreatePinnedToCore(
104106
canTask,
105-
"CAN Task",
107+
"CAN Task",
106108
4096,
107109
NULL,
108110
1,
109111
NULL,
110-
0
111-
);
112+
0);
112113

113114
Serial.println("CAN mode aktif.");
114115
}
@@ -118,38 +119,38 @@ void setup()
118119
Serial.println("Serial mode aktif.");
119120
}
120121

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

154155
EEPROM.write(0, 1);
155156
delay(500);
@@ -179,12 +180,12 @@ void loop()
179180
handleSerialCommunication();
180181
}
181182

182-
static uint32_t lastDraw = 0;
183-
if (millis() - lastDraw > 25)
184-
{ // Update every 100ms
185-
drawData();
186-
lastDraw = millis();
187-
}
183+
// static uint32_t lastDraw = 0;
184+
// if (millis() - lastDraw > 25)
185+
// { // Update every 100ms
186+
drawData();
187+
// lastDraw = millis();
188+
// }
188189

189190
// if (millis() - lastClientCheck >= 1000)
190191
// {
@@ -239,15 +240,15 @@ void handleCANCommunication()
239240
CAN_FRAME can_message;
240241
if (CAN0.read(can_message))
241242
{
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();
243+
// Serial.print("ID: ");
244+
// Serial.print(can_message.id, HEX);
245+
// Serial.print(" Data: ");
246+
// for (int i = 0; i < can_message.length; i++)
247+
// {
248+
// Serial.print(can_message.data.byte[i], HEX);
249+
// Serial.print(" ");
250+
// }
251+
// Serial.println();
251252

252253
// Proses data berdasarkan ID
253254
switch (can_message.id)
@@ -289,14 +290,29 @@ void handleCANCommunication()
289290
case 0x3E0:
290291
{ // CLT
291292
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
293+
uint16_t iat_raw = (can_message.data.byte[2] << 8) | can_message.data.byte[3]; // Byte 2-3
293294
float clt_k = clt_raw / 10.0;
294295
float iat_k = iat_raw / 10.0;
295296

296297
clt = clt_k - 273.15;
297298
iat = iat_k - 273.15;
298299
break;
299300
}
301+
case 0x3E4:
302+
{ // Indicator
303+
launch = (can_message.data.byte[2] << 8) | can_message.data.byte[6]; // Byte 2-6
304+
airCon = (can_message.data.byte[3] << 8) | can_message.data.byte[4]; // Byte 3-4
305+
fan = (can_message.data.byte[3] << 8) | can_message.data.byte[0]; // Byte 3-0
306+
rev = (can_message.data.byte[2] << 8) | can_message.data.byte[5]; // Byte 2-5
307+
break;
308+
}
309+
case 0x362:
310+
{ // Ignition Advance
311+
uint16_t adv_raw = (can_message.data.byte[4] << 8) | can_message.data.byte[5]; // Byte 2-3
312+
adv = adv_raw / 10.0;
313+
break;
314+
}
315+
300316
default:
301317
break;
302318
}
@@ -307,30 +323,32 @@ void handleCANCommunication()
307323
}
308324
}
309325

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-
// }
326+
if (currentTime - lastPrintTime >= 1000)
327+
{ // Interval 1000ms
328+
Serial.print("RPM: ");
329+
Serial.print(rpm);
330+
Serial.print(" MAP: ");
331+
Serial.print(mapData);
332+
Serial.print(" kPa TPS: ");
333+
Serial.print(tps);
334+
Serial.print(" % ADV:");
335+
Serial.print(adv);
336+
Serial.print(" ° Fuel Pressure: ");
337+
Serial.print(fp);
338+
Serial.print(" kPa AFR: ");
339+
Serial.print(afrConv, 2);
340+
Serial.print(" VSS: ");
341+
Serial.print(vss);
342+
Serial.print(" km/h Voltage: ");
343+
Serial.print(bat, 2);
344+
Serial.print(" V CLT: ");
345+
Serial.print(clt);
346+
Serial.print(" °C IAT: ");
347+
Serial.print(iat);
348+
Serial.println(" °C");
349+
350+
lastPrintTime = currentTime;
351+
}
334352
}
335353

336354
void handleSerialCommunication()

0 commit comments

Comments
 (0)