|
9 | 9 | #include "DataTypes.h" |
10 | 10 | #include "BacklightControl.h" |
11 | 11 | #include "CANHandler.h" |
| 12 | +#include "SerialHandler.h" |
12 | 13 | #include "DisplayManager.h" |
13 | 14 | #include "WebServerHandler.h" |
14 | 15 | #include "GlobalVariables.h" |
|
24 | 25 | // Web server |
25 | 26 | WebServer server(80); |
26 | 27 |
|
27 | | -// Serial communication handling |
28 | | -void handleSerialCommunication() |
29 | | -{ |
30 | | - static uint32_t lastUpdate = millis(); |
31 | | - // Reduce serial communication frequency from 10ms to 20ms for better performance |
32 | | - if (millis() - lastUpdate > 20) |
33 | | - { |
34 | | - requestData(50); |
35 | | - lastUpdate = millis(); |
36 | | - } |
37 | | - |
38 | | - isCANMode = false; // We're in Serial mode when this function is called |
39 | | - |
40 | | - static uint32_t lastRefresh = millis(); |
41 | | - uint32_t elapsed = millis() - lastRefresh; |
42 | | - refreshRate = (elapsed > 0) ? (1000 / elapsed) : 0; |
43 | | - lastRefresh = millis(); |
44 | | - |
45 | | - // Reduce lazy update frequency from 100ms to 200ms for better performance |
46 | | - if (lastRefresh - lazyUpdateTime > 200 || rpm < 100) |
47 | | - { |
48 | | - clt = getByte(7) - 40; |
49 | | - iat = getByte(6) - 40; |
50 | | - bat = getByte(9)* 0.1; |
51 | | - } |
52 | | - |
53 | | - rpm = getWord(14); |
54 | | - mapData = getWord(4) / 10; |
55 | | - afrConv = getByte(10) *0.1; |
56 | | - tps = getByte(24) / 2; |
57 | | - adv = (int8_t)getByte(23); |
58 | | - fp = getByte(103); |
59 | | - |
60 | | - syncStatus = getBit(31, 7); |
61 | | - ase = getBit(2, 2); |
62 | | - wue = getBit(2, 3); |
63 | | - rev = getBit(31, 2); |
64 | | - launch = getBit(31, 0); |
65 | | - airCon = getByte(122); |
66 | | - fan = getBit(106, 3); |
67 | | - dfco = getBit(1, 4); |
68 | | - |
69 | | - // Debug: Print data values occasionally |
70 | | - static uint32_t lastDataDebug = 0; |
71 | | - if (millis() - lastDataDebug > 5000) { // Print every 5 seconds |
72 | | - Serial.printf("[SERIAL] RPM: %d, MAP: %.1f, TPS: %.1f, CLT: %d, IAT: %d\n", |
73 | | - rpm, mapData, tps, clt, iat); |
74 | | - lastDataDebug = millis(); |
75 | | - } |
76 | | -} |
77 | | - |
78 | 28 | // Handle all serial commands in a single function to avoid conflicts |
79 | 29 | void handleSerialCommands() |
80 | 30 | { |
@@ -285,14 +235,19 @@ void setup() |
285 | 235 | // Initialize CAN communication |
286 | 236 | setupCAN(); |
287 | 237 |
|
288 | | - // Create CAN task |
| 238 | + // Create CAN task on core 0 |
289 | 239 | xTaskCreatePinnedToCore(canTask, "CAN Task", 4096, NULL, 1, NULL, 0); |
290 | 240 |
|
291 | 241 | Serial.println("CAN mode aktif."); |
292 | 242 | } |
293 | 243 | else |
294 | 244 | { |
295 | | - Serial1.begin(UART_BAUD, SERIAL_8N1, RXD, TXD); |
| 245 | + // Initialize Serial communication |
| 246 | + setupSerial(); |
| 247 | + |
| 248 | + // Create Serial task on core 0 |
| 249 | + xTaskCreatePinnedToCore(serialTask, "Serial Task", 4096, NULL, 1, NULL, 0); |
| 250 | + |
296 | 251 | Serial.println("Serial mode aktif."); |
297 | 252 | } |
298 | 253 |
|
@@ -371,11 +326,7 @@ void loop() |
371 | 326 | #if ENABLE_SIMULATOR |
372 | 327 | if (getSimulatorMode() == SIMULATOR_MODE_OFF) { |
373 | 328 | #endif |
374 | | - // Handle serial communication if not in CAN mode |
375 | | - if (commMode != COMM_CAN) |
376 | | - { |
377 | | - handleSerialCommunication(); |
378 | | - } |
| 329 | + |
379 | 330 | #if ENABLE_SIMULATOR |
380 | 331 | } |
381 | 332 | #endif |
|
0 commit comments