@@ -68,6 +68,15 @@ uint32_t startupTime;
6868uint32_t lazyUpdateTime;
6969uint16_t spr_width = 0 ;
7070
71+ void canTask (void *pvParameters)
72+ {
73+ while (1 )
74+ {
75+ handleCANCommunication ();
76+ vTaskDelay (1 );
77+ }
78+ }
79+
7180void setup ()
7281{
7382 EEPROM .begin (EEPROM_SIZE );
@@ -84,13 +93,23 @@ void setup()
8493 {
8594
8695 CAN0 .setCANPins (GPIO_NUM_17 , GPIO_NUM_16 ); // RX, TX
87- CAN0 .begin (1000000 ); // 1Mbps
88- CAN0 .watchFor (0x360 ); // RPM, MAP, TPS
89- CAN0 .watchFor (0x361 ); // Fuel Pressure
90- CAN0 .watchFor (0x368 ); // AFR 01
96+ CAN0 .begin (1000000 ); // 1Mbps
97+ CAN0 .watchFor (0x360 ); // RPM, MAP, TPS
98+ CAN0 .watchFor (0x361 ); // Fuel Pressure
99+ CAN0 .watchFor (0x368 ); // AFR 01
91100 // CAN0.watchFor(0x370); // VSS
92101 CAN0 .watchFor (0x372 ); // Voltage
93102 CAN0 .watchFor (0x3E0 ); // CLT, IAT
103+ xTaskCreatePinnedToCore (
104+ canTask,
105+ " CAN Task" ,
106+ 4096 ,
107+ NULL ,
108+ 1 ,
109+ NULL ,
110+ 0
111+ );
112+
94113 Serial.println (" CAN mode aktif." );
95114 }
96115 else
@@ -155,17 +174,14 @@ void loop()
155174 // }
156175 // Serial.printf("RPM: %d, MAP: %d, TPS: %d, VSS: %.2f, CLT: %.2f, IAT: %.2f, FP: %d, AFR: %.2f, Bat: %.2f\n", rpm, mapData, tps, vss, clt, iat, fp, afrConv, bat);
157176 // }
158- if (commMode == COMM_CAN )
159- {
160- handleCANCommunication ();
161- }
162- else
177+ if (commMode != COMM_CAN )
163178 {
164179 handleSerialCommunication ();
165180 }
166181
167182 static uint32_t lastDraw = 0 ;
168- if (millis () - lastDraw > 100 ) { // Update every 100ms
183+ if (millis () - lastDraw > 25 )
184+ { // Update every 100ms
169185 drawData ();
170186 lastDraw = millis ();
171187 }
@@ -237,11 +253,11 @@ void handleCANCommunication()
237253 switch (can_message.id )
238254 {
239255 case 0x360 :
240- { // RPM, MAP, TPS
241- rpm = (can_message.data .byte [0 ] << 8 ) | can_message.data .byte [1 ]; // Byte 0-1
242- uint16_t map = (can_message.data .byte [2 ] << 8 ) | can_message.data .byte [3 ]; // Byte 2-3
256+ { // RPM, MAP, TPS
257+ rpm = (can_message.data .byte [0 ] << 8 ) | can_message.data .byte [1 ]; // Byte 0-1
258+ uint16_t map = (can_message.data .byte [2 ] << 8 ) | can_message.data .byte [3 ]; // Byte 2-3
243259 uint16_t tps_raw = (can_message.data .byte [4 ] << 8 ) | can_message.data .byte [5 ]; // Byte 4-5
244- mapData = map / 10.0 ; // Konversi ke kPa
260+ mapData = map / 10.0 ; // Konversi ke kPa
245261 tps = tps_raw / 10.0 ; // Konversi ke kPa
246262 break ;
247263 }
@@ -587,7 +603,7 @@ void drawDataBox(int x, int y, const char *label, const float value, uint16_t la
587603 spr_width = spr.textWidth (" 333" );
588604 spr.setTextColor (labelColor, TFT_BLACK , true );
589605 if (decimal > 0 )
590- {
606+ {
591607 spr.drawFloat (value, decimal, 50 , 5 );
592608 }
593609 else
0 commit comments