Skip to content

Commit 41f10d2

Browse files
authored
EHU32 v0.9.5
Reverted back to 255 bytes max payload for display messages, seems that Delphi-Grundig GID doesn't like longer messages Changed the AC toggle to trigger on long presses instead Tweaked the logic for blocking Aux frames that are send in the same ISO 15765-2 as status messages (ID 5000)
1 parent 1fe89e1 commit 41f10d2

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/A2DP.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void a2dp_init(){
7272
setFlag(a2dp_started);
7373
DEBUG_PRINTLN("A2DP: Started!");
7474
disp_mode=0; // set display mode to audio metadata on boot
75-
writeTextToDisplay(1, "EHU32 v0.9.4", "Bluetooth on", "Waiting for connection...");
75+
writeTextToDisplay(1, "EHU32 v0.9.5", "Bluetooth on", "Waiting for connection...");
7676
}
7777

7878
// handles events such as connecion/disconnection and audio play/pause

src/CAN.ino

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
void OTAhandleTask(void* pvParameters);
44

55
// CAN-related variables
6-
volatile uint8_t canISO_frameSpacing=1; // simple implementation of ISO 15765-2 variable frame spacing, based on flow control frames by the receiving node
6+
volatile uint8_t canISO_frameSpacing=0; // simple implementation of ISO 15765-2 variable frame spacing, based on flow control frames by the receiving node
77

88
// defining static CAN frames for simulation
99
const twai_message_t simulate_scroll_up={ .identifier=0x201, .data_length_code=3, .data={0x08, 0x6A, 0x01}},
@@ -65,7 +65,7 @@ void canReceiveTask(void *pvParameters){
6565
switch(Recvd_CAN_MSG.identifier){
6666
case 0x6C1: {
6767
if(disp_mode!=-1){ // don't bother checking the data if there's no need to update the display
68-
if(Recvd_CAN_MSG.data[0]==0x10 && (Recvd_CAN_MSG.data[2]==0x40 || Recvd_CAN_MSG.data[2]==0xC0) && Recvd_CAN_MSG.data[5]==0x03 && (disp_mode!=0 || allowDisplayBlocking)){ // another task processes the data since we can't do that here
68+
if(Recvd_CAN_MSG.data[0]==0x10 && (Recvd_CAN_MSG.data[2]==0x40 || Recvd_CAN_MSG.data[2]==0xC0 || (Recvd_CAN_MSG.data[2]==0x50 && Recvd_CAN_MSG.data[1]==0x4A)) && Recvd_CAN_MSG.data[5]==0x03 && (disp_mode!=0 || allowDisplayBlocking)){ // another task processes the data since we can't do that here
6969
twai_transmit(&Msg_PreventDisplayUpdate, pdMS_TO_TICKS(30)); // radio blocking msg has to be transmitted ASAP, which is why we skip the queue
7070
DEBUG_PRINTLN("CAN: Received display update, trying to block");
7171
twai_read_alerts(&alerts_FlowCtl, pdMS_TO_TICKS(10)); // read stats to a local alert buffer
@@ -77,7 +77,7 @@ void canReceiveTask(void *pvParameters){
7777
DEBUG_PRINTLN("CAN: Blocking failed!");
7878
}
7979
overwriteAttemped=1; // if the display message retransmission was intended to mask the radio's message
80-
if(eTaskGetState(canDisplayTaskHandle)==eRunning){
80+
if(eTaskGetState(canDisplayTaskHandle)!=eSuspended){
8181
if(Recvd_CAN_MSG.data[0]==0x10) setFlag(CAN_abortMultiPacket); // let the transmission task know that the radio has transmissed a new first frame -> any ongoing transmission is no longer valid
8282
}
8383
vTaskResume(canDisplayTaskHandle); // only retransmit the msg for audio metadata mode and single line coolant, since these don't update frequently
@@ -128,6 +128,7 @@ void canReceiveTask(void *pvParameters){
128128
void canProcessTask(void *pvParameters){
129129
static twai_message_t RxMsg;
130130
bool badVoltage_VectraC_bypass=0;
131+
unsigned long millis_EccKnobPressed;
131132
while(1){
132133
xQueueReceive(canRxQueue, &RxMsg, portMAX_DELAY); // receives data from the internal queue
133134
switch(RxMsg.identifier){
@@ -186,9 +187,21 @@ void canProcessTask(void *pvParameters){
186187
break;
187188
}
188189
case 0x208: { // AC panel button event
189-
if(RxMsg.data[0]==0x0 && RxMsg.data[1]==0x17 && RxMsg.data[2]<0x03){ // FIXME!
190-
vTaskResume(canAirConMacroTaskHandle); // start AC macro
191-
}
190+
if(eTaskGetState(canAirConMacroTaskHandle)==eSuspended){
191+
if(RxMsg.data[0]==0x01 && RxMsg.data[1]==0x17 && RxMsg.data[2]==0x0){ // button pressed, start save timestamp
192+
millis_EccKnobPressed=millis();
193+
} else {
194+
if(RxMsg.data[0]==0x0 && RxMsg.data[1]==0x17 && (RxMsg.data[2]==0x0 || RxMsg.data[2]>=0x05)){
195+
if(RxMsg.data[2]>=0x05){ // properly implemented ECC button counting (such as Vectra C) does not require stupid workarounds
196+
vTaskResume(canAirConMacroTaskHandle);
197+
} else {
198+
if((millis_EccKnobPressed+400)<=millis()){ // late Astra/Corsa/Zafira ECCs don't follow the standard, as these only report the initial press and release (saying it was released after being held for 0ms lol)
199+
vTaskResume(canAirConMacroTaskHandle); // so we count the time on our own, and if the time elapsed
200+
}
201+
}
202+
}
203+
}
204+
} // should be an else here to implement something to stop the macro task, can't be bothered to implement this now
192205
break;
193206
}
194207
case 0x2C1: {
@@ -299,7 +312,7 @@ void canProcessTask(void *pvParameters){
299312
a2dp_sink.reconnect();
300313
setFlag(ehu_started);
301314
}
302-
if(disp_mode==0){ // if not a consecutive frame, then we queue that data for decoding by another task
315+
if(disp_mode==0){ // queue that data for decoding by another task
303316
for(int i=1; i<=7; i++){
304317
xQueueSend(canDispQueue, &RxMsg.data[i], portMAX_DELAY); // send a continuous byte stream
305318
}
@@ -567,7 +580,7 @@ void canMessageDecoder(void *pvParameters){
567580
}
568581
patternFound=0;
569582
}
570-
vTaskDelay(pdMS_TO_TICKS(5));
583+
vTaskDelay(pdMS_TO_TICKS(2));
571584
}
572585
}
573586

@@ -580,7 +593,7 @@ void prepareMultiPacket(int bytesProcessed, char* buffer_to_read){ /
580593
frameIndex=(frameIndex==0x2F)? 0x20: frameIndex+1; // reset back to 0x20 after 0x2F, otherwise increment the frameIndex (consecutive frame index)
581594
memcpy(&CAN_MsgArray[i][1], &buffer_to_read[i*7], 7); // copy 7 bytes at a time to fill consecutive frames with data
582595
}
583-
if(bytesProcessed<=255){
596+
if(bytesProcessed<=255){ // TODO: implement proper 255+ byte DoCAN handling
584597
CAN_MsgArray[0][0]=0x10; // first frame index is always 0x10 for datasets smaller than 255 bytes
585598
} else {
586599
CAN_MsgArray[0][0]=0x11;
@@ -670,7 +683,7 @@ void canActionEhuButton8(bool btn_state, unsigned int btn_ms_held){
670683
if(!checkFlag(OTA_begin) && btn_ms_held>=1000){
671684
setFlag(OTA_begin);
672685
} else {
673-
if(btn_ms_held>=5000) setFlag(OTA_abort);
686+
if(btn_ms_held>=5000) setFlag(OTA_abort); // allows to break out of OTA mode
674687
}
675688
}
676689

@@ -680,7 +693,7 @@ void canActionEhuButton9(bool btn_state, unsigned int btn_ms_held){
680693
disp_mode=-1;
681694
DEBUG_PRINTLN("Screen updates disabled");
682695
}
683-
if(btn_ms_held>=5000){
696+
if(btn_ms_held>=5000){ // this will perform a full reset, including clearing settings, so the next boot will take some time
684697
if(!checkFlag(OTA_begin)){
685698
vTaskDelay(pdMS_TO_TICKS(1000));
686699
prefs_clear();

src/TextHandler.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ int processDisplayMessage(char* upper_line_buffer, char* middle_line_buffer, cha
156156
last_byte_written+=2;
157157
}
158158
if(last_byte_written>254){ // message size can't be larger than 255 bytes, as the character specifying total payload is an 8 bit value
159-
//last_byte_written=254; // we can send that data though, it will just be ignored, no damage is done
159+
last_byte_written=254; // we can send that data though, it will just be ignored, no damage is done
160160
}
161-
DisplayMsg[0]=((last_byte_written%254)+1); // TOTAL PAYLOAD SIZE based on how many bytes have been written
161+
DisplayMsg[0]=last_byte_written+1; // TOTAL PAYLOAD SIZE based on how many bytes have been written
162162
DisplayMsg[3]=DisplayMsg[0]-3; // payload size written as part of the 4000 command
163163
return last_byte_written+1; // return the total message size
164164
}

0 commit comments

Comments
 (0)