You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/A2DP.ino
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ void A2DP_EventHandler(){
77
77
a2dp_init();
78
78
}
79
79
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
81
81
if(bt_audio_playing){
82
82
digitalWrite(PCM_MUTE_CTL, HIGH);
83
83
DIS_autoupdate=1;
@@ -110,5 +110,6 @@ void a2dp_shutdown(){
110
110
if(a2dp_started && RxMessage.data[3]==0x18){
111
111
a2dp_sink.disconnect();
112
112
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
voidprocessDataBuffer(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)
53
51
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
prepareMultiPacket(utf8_conversion(album_buffer, title_buffer, artist_buffer)); // prepare a 3-line message (audio Title, Album and Artist)
57
55
}
58
56
if(disp_mode==1){
@@ -88,11 +86,11 @@ void loop() {
88
86
CAN_prevTxFail=0;
89
87
}
90
88
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
92
90
RxMessage.identifier=0x0; // workaround for debugging when the bus is not on
93
91
while(!RxMessage.identifier==0x2C1){
94
92
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
96
94
delay(1); // I've honestly tried everything, refreshing status and alerts. This shit just doesn't work properly
97
95
}
98
96
}
@@ -102,7 +100,6 @@ void loop() {
102
100
canReceive(); // read data from RX buffer
103
101
}
104
102
105
-
106
103
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
107
104
DIS_autoupdate=0;
108
105
if((last_millis+3000)<millis()){
@@ -117,12 +114,12 @@ void loop() {
117
114
disp_mode_changed=0;
118
115
}
119
116
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
121
118
if((last_millis+250)<millis()){
122
119
requestMeasurementBlocks();
123
120
last_millis=millis();
124
121
}
125
-
if(CAN_new_dataSet_recvd){
122
+
if(CAN_new_dataSet_recvd){// print new data if it has arrived
126
123
CAN_new_dataSet_recvd=0;
127
124
processDataBuffer();
128
125
}
@@ -132,5 +129,5 @@ void loop() {
132
129
processDataBuffer();
133
130
}
134
131
135
-
A2DP_EventHandler();
132
+
A2DP_EventHandler();// process bluetooth and audio flags set by interrupt callbacks
0 commit comments