Skip to content

Commit 1a49ee9

Browse files
authored
Add files via upload
1 parent c48fc18 commit 1a49ee9

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

src/A2DP.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void A2DP_EventHandler(){
7777
a2dp_init();
7878
}
7979

80-
if(audio_state_changed){ // mute external DAC when not playing
80+
if(audio_state_changed && bt_connected){ // mute external DAC when not playing; bt_connected ensures no "Connected, paused" is displayed, seems that the audio_state_changed callback comes late
8181
if(bt_audio_playing){
8282
digitalWrite(PCM_MUTE_CTL, HIGH);
8383
DIS_autoupdate=1;
@@ -110,5 +110,6 @@ void a2dp_shutdown(){
110110
if(a2dp_started && RxMessage.data[3]==0x18){
111111
a2dp_sink.disconnect();
112112
ehu_started=0; // so it is possible to restart and reconnect the source afterwards in the rare case radio is shutdown but ESP32 is still powered up
113+
a2dp_started=0; // while extremely unlikely to happen in the vehicle, this comes handy for debugging on my desk setup
113114
}
114115
}

src/BusReceive.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,17 @@ void canUpdateBodyData(){
172172
}
173173
}
174174

175-
// fallback to read coolant temperatures from ECU in case reading from ECC fails
175+
// fallback to read coolant temperatures from ECU in case reading from ECC fails; to be implemented sometime in the future
176176
void canUpdateCoolant(){
177177
CAN_data_coolant=(RxMessage.data[3]-40);
178178
CAN_coolant_recvd=1;
179179
}
180180

181-
// decides what function to call when a button on the factory radio has been pressed for 2 seconds
181+
// decides what function to call when a button on the factory radio has been held down for about one second
182182
void canDecodeEhuButtons(){
183-
if(RxMessage.data[0]==0x01 && RxMessage.data[2]==20){
183+
if(RxMessage.data[0]==0x01 && RxMessage.data[2]>=10){
184184
switch(RxMessage.data[1]){
185-
case 0x30: canActionEhuButton0();
185+
case 0x30: canActionEhuButton0(); // CD30 has no '0' button!
186186
break;
187187
case 0x31: canActionEhuButton1();
188188
break;

src/EHU32.ino

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
bool DEBUGGING_ON=0;
1818
// pin definitions
19-
const int DIS_SEL0_PIN=16, DIS_SEL1_PIN=17, PCM_MUTE_CTL=23;
19+
const int PCM_MUTE_CTL=23; // this pin controls PCM5102s soft-mute function
2020
// CAN buffers
2121
uint32_t alerts_triggered;
2222
static twai_message_t RxMessage, TxMessage;
2323
twai_status_info_t status_info;
24-
// CAN related switches
24+
// CAN related flags
2525
bool DIS_forceUpdate=0, DIS_autoupdate=0, CAN_MessageReady=0, CAN_prevTxFail=0, CAN_speed_recvd=0, CAN_coolant_recvd=0, CAN_voltage_recvd=0, CAN_new_dataSet_recvd=0;
2626
// body data
2727
int CAN_data_speed=0, CAN_data_rpm=0;
2828
float CAN_data_coolant=0, CAN_data_voltage=0;
29-
// global bluetooth switches
29+
// global bluetooth flags
3030
bool ehu_started=0, a2dp_started=0, bt_connected=0, bt_state_changed=0, bt_audio_playing=0, audio_state_changed=0;
3131
// data buffers
3232
static char utf16buffer[384], utf16_title[128], utf16_artist[128], utf16_album[128], CAN_MsgArray[64][8], title_buffer[64], artist_buffer[64], album_buffer[64], coolant_buffer[32], speed_buffer[32], voltage_buffer[32];
@@ -39,8 +39,6 @@ unsigned int last_millis=0;
3939
void sendMultiPacketData();
4040

4141
void setup() {
42-
pinMode(DIS_SEL0_PIN, INPUT_PULLUP); // LSB
43-
pinMode(DIS_SEL1_PIN, INPUT_PULLUP); // MSB
4442
pinMode(PCM_MUTE_CTL, OUTPUT);
4543
digitalWrite(PCM_MUTE_CTL, HIGH);
4644
delay(100);
@@ -52,7 +50,7 @@ void setup() {
5250
void processDataBuffer(bool disp_mode_override=0, char* up_line_text=nullptr, char* mid_line_text=nullptr, char* low_line_text=nullptr){ // disp_mode_override exists as a simple way to print one-off messages (like board status, errors and such)
5351
if(!CAN_MessageReady){ // only prepare new buffers once the previously prepared message has been sent. DIS_forceUpdate is still 1, so this function should be called again next loop
5452
if(!disp_mode_override){
55-
if(disp_mode==0){
53+
if(disp_mode==0 && (album_buffer[0]!='\0' || title_buffer[0]!='\0' || artist_buffer[0]!='\0')){
5654
prepareMultiPacket(utf8_conversion(album_buffer, title_buffer, artist_buffer)); // prepare a 3-line message (audio Title, Album and Artist)
5755
}
5856
if(disp_mode==1){
@@ -88,11 +86,11 @@ void loop() {
8886
CAN_prevTxFail=0;
8987
}
9088
if(CAN_MessageReady){ // CAN_MessageReady is set after the display has been requested is sent. This waits for the display to reply with an ACK (id 0x2C1)
91-
delay(10);
89+
delay(5); // waits a bit because sometimes stuff happens so fast we get the ACK meant for the radio, we need to wait for the radio to stop talking
9290
RxMessage.identifier=0x0; // workaround for debugging when the bus is not on
9391
while(!RxMessage.identifier==0x2C1){
9492
if(DEBUGGING_ON) Serial.println("CAN: Waiting for 0x2C1 ACK...");
95-
while(twai_receive(&RxMessage, pdMS_TO_TICKS(10))!=ESP_OK){ // wait for the desired message
93+
while(twai_receive(&RxMessage, pdMS_TO_TICKS(5))!=ESP_OK){ // wait for the desired message
9694
delay(1); // I've honestly tried everything, refreshing status and alerts. This shit just doesn't work properly
9795
}
9896
}
@@ -102,7 +100,6 @@ void loop() {
102100
canReceive(); // read data from RX buffer
103101
}
104102

105-
106103
if(disp_mode_changed_with_delay){ // ensure the "one-off" status message is displayed for some time, then go back to regular messages based on disp_mode
107104
DIS_autoupdate=0;
108105
if((last_millis+3000)<millis()){
@@ -117,12 +114,12 @@ void loop() {
117114
disp_mode_changed=0;
118115
}
119116

120-
if(disp_mode==1){
117+
if(disp_mode==1){ // if running in measurement block mode, check time and if enough time has elapsed ask for new data
121118
if((last_millis+250)<millis()){
122119
requestMeasurementBlocks();
123120
last_millis=millis();
124121
}
125-
if(CAN_new_dataSet_recvd){
122+
if(CAN_new_dataSet_recvd){ // print new data if it has arrived
126123
CAN_new_dataSet_recvd=0;
127124
processDataBuffer();
128125
}
@@ -132,5 +129,5 @@ void loop() {
132129
processDataBuffer();
133130
}
134131

135-
A2DP_EventHandler();
132+
A2DP_EventHandler(); // process bluetooth and audio flags set by interrupt callbacks
136133
}

src/OTA.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
bool OTA_running=0;
22

3-
const char* host = "Asterka";
4-
const char* ssid = "AsterkaEHU32";
3+
const char* ssid = "EHU32-OTA";
54
const char* password = "ehu32updater";
65
volatile bool OTA_Finished=0;
76

0 commit comments

Comments
 (0)