9
9
#include < log4arduino.h>
10
10
11
11
#ifdef DPF_AUDIO_NOTIFICATION
12
- #include < MusicDefinitions.h>
13
- #include < XT_DAC_Audio.h>
12
+ #include " ESP32S3Buzzer.h"
14
13
#endif
15
14
16
15
#include " Free_Fonts.h"
26
25
#ifndef GT_DEMO
27
26
#define GT_DEMO false // show demo random data
28
27
#endif
29
-
30
- #ifdef DPF_AUDIO_NOTIFICATION
31
- int8_t PROGMEM NOTE[] = { NOTE_A4, SCORE_END};
32
- XT_DAC_Audio_Class DacAudio (26 , 0 );
33
- XT_MusicScore_Class Beep (NOTE, TEMPO_PRESTO, INSTRUMENT_PIANO);
28
+ #ifndef GT_BUZZER_PIN
29
+ #define GT_BUZZER_PIN 25
34
30
#endif
35
31
36
32
#define BT_DISCOVER_TIME 3000
37
- #define LOOP_DELAY 5
38
- #define ELM_LOOP_DELAY 5
39
- #define RT_SENSORS_DELAY 250
33
+ #define LOOP_DELAY 3
34
+ #define ELM_LOOP_DELAY 3
35
+ #define RT_SENSORS_DELAY 20
40
36
#define SWITCHED_STATE_DELAY 1000
41
37
#define ELM_QUERY_TIMEOUT 2000
42
38
#define RECONNECTION_DELAY 5000
43
- #define NON_RT_SENSORS_DELAY 10000
39
+ #define NON_RT_SENSORS_DELAY 1000
40
+ #define VALUES_SENSORS_DELAY 1000
44
41
#define QUERY_OFFSET 300 // to time-distribute data loading on main screen
45
42
#define NO_DATA_TIMEOUT 60000
46
43
#define DEEPSLEEP_DURATION_US 15000000L // 15s
@@ -61,6 +58,11 @@ XT_MusicScore_Class Beep(NOTE, TEMPO_PRESTO, INSTRUMENT_PIANO);
61
58
BluetoothSerial SerialBT;
62
59
ELM327 btELM327;
63
60
61
+ #ifdef DPF_AUDIO_NOTIFICATION
62
+ ESP32S3Buzzer buzzer (GT_BUZZER_PIN, 0 );
63
+ #endif
64
+
65
+
64
66
static lv_disp_draw_buf_t _draw_buf;
65
67
static lv_color_t _screen_buffer[GT_SCREEN_WIDTH * GT_SCREEN_HEIGTH / 10 ];
66
68
static uint16_t _touchX, _touchY;
@@ -92,7 +94,7 @@ static int _airTemp = -1;
92
94
static int _dpfClogging = -1 ;
93
95
static int _dpfTemperature = -1 ;
94
96
static int _dpfRegeneration = -1 ;
95
- static bool _shouldPlayDPFSound = true ;
97
+ static bool _shouldInitDPFSound = true ;
96
98
static int _dpfDistance = -1 ;
97
99
static int _dpfCount = -1 ;
98
100
static float _batteryVoltage = -1 ;
@@ -123,7 +125,7 @@ void _onStateChange(int screenId, bool active)
123
125
_dpfClogging = -1 ;
124
126
_dpfTemperature = -1 ;
125
127
_dpfRegeneration = -1 ;
126
- _shouldPlayDPFSound = true ;
128
+ _shouldInitDPFSound = true ;
127
129
_dpfDistance = -1 ;
128
130
129
131
unsigned long now = millis ();
@@ -193,8 +195,11 @@ static int _get_demo_v(int pid)
193
195
case 0x40B2 :
194
196
case 0x40B3 :
195
197
case 0x30B4 :
198
+ return -1 ;
196
199
case 0x04FE :
197
200
return 70 + (int )(((float )rand () / (float )(RAND_MAX)) * 10 ) - 10 ;
201
+ case 0x194D :
202
+ return 7 ;
198
203
default :
199
204
return -1 ;
200
205
}
@@ -271,7 +276,7 @@ static bool _gt_elmConnect()
271
276
272
277
if (SerialBT.connect (BTAddress (_mac)))
273
278
{
274
- if (!btELM327.begin (SerialBT, ELM_DEBUG, ELM_QUERY_TIMEOUT))
279
+ if (!btELM327.begin (SerialBT, ELM_DEBUG, ELM_QUERY_TIMEOUT, ISO_15765_29_BIT_500_KBAUD ))
275
280
{
276
281
LOG (" Can't init connection to ELM327 device %s" , _mac);
277
282
}
@@ -324,7 +329,7 @@ static int _gt_setHeader(int headerId, const char *header)
324
329
/* *
325
330
* process PID in blocking mode
326
331
*/
327
- static float _gt_processPID (const uint8_t &service, const uint16_t &pid, const uint8_t &numResponses, const uint8_t &numExpectedBytes, const double &scaleFactor, const float &bias)
332
+ static double _gt_processPID (const uint8_t &service, const uint16_t &pid, const uint8_t &numResponses, const uint8_t &numExpectedBytes, const double &scaleFactor, const float &bias)
328
333
{
329
334
unsigned long timeoutAt = millis () + (ELM_QUERY_TIMEOUT * 2 );
330
335
while (millis () < timeoutAt)
@@ -335,7 +340,7 @@ static float _gt_processPID(const uint8_t &service, const uint16_t &pid, const u
335
340
delay (ELM_LOOP_DELAY);
336
341
return _get_demo_v (pid);
337
342
}
338
- float value = btELM327.processPID (service, pid, numResponses, numExpectedBytes, scaleFactor, bias);
343
+ double value = btELM327.processPID (service, pid, numResponses, numExpectedBytes, scaleFactor, bias);
339
344
if (btELM327.nb_rx_state == ELM_SUCCESS)
340
345
{
341
346
VLOG (" Value for %x is %.2f" , pid, value);
@@ -569,10 +574,22 @@ void _gt_elmLoop(void *pvParameters)
569
574
570
575
if (_currentHeaderId == HEADER_DAC7F1_ID)
571
576
{
572
- _tireTempFL = _gt_processPID (0x22 , 0x40B1 , 1 , 3 , 0.0000305 , 0 .0f );
573
- _tireTempFR = _gt_processPID (0x22 , 0x40B2 , 1 , 3 , 0.0000305 , 0 .0f );
574
- _tireTempRL = _gt_processPID (0x22 , 0x40B3 , 1 , 3 , 0.0000305 , 0 .0f );
575
- _tireTempRR = _gt_processPID (0x22 , 0x40B4 , 1 , 3 , 0.0000305 , 0 .0f );
577
+ int r = (int ) _gt_processPID (0x22 , 0x40B1 , 2 , 7 , 1 , 0 );
578
+ if (r>0 ) {
579
+ _tireTempFL = btELM327.responseByte_5 - 50 ;
580
+ }
581
+ r = (int ) _gt_processPID (0x22 , 0x40B2 , 2 , 7 , 1 , 0 );
582
+ if (r>0 ) {
583
+ _tireTempFR = btELM327.responseByte_5 - 50 ;
584
+ }
585
+ r = (int ) _gt_processPID (0x22 , 0x40B3 , 2 , 7 , 1 , 0 );
586
+ if (r>0 ) {
587
+ _tireTempRL = btELM327.responseByte_5 - 50 ;
588
+ }
589
+ r = (int ) _gt_processPID (0x22 , 0x40B4 , 2 , 7 , 1 , 0 );
590
+ if (r>0 ) {
591
+ _tireTempRR = btELM327.responseByte_5 - 50 ;
592
+ }
576
593
}
577
594
578
595
if (_currentHeaderId != HEADER_DA18F1_ID)
@@ -609,19 +626,12 @@ void _gt_elmLoop(void *pvParameters)
609
626
if (_currentHeaderId == HEADER_DB33F1_ID)
610
627
{
611
628
_batteryVoltage = _gt_processPID (0x01 , 0x42 , 1 , 2 , 0.001 , 0 );
629
+ if (_batteryVoltage != -1 )
630
+ {
631
+ _valuesNonRtLastQueringMs = millis () + NON_RT_SENSORS_DELAY;
632
+ }
612
633
}
613
634
614
- if (_batteryIBS != -1 &&
615
- _engineOilDegradation != -1 &&
616
- _tireTempFL != -1 &&
617
- _tireTempFR != -1 &&
618
- _tireTempRL != -1 &&
619
- _tireTempRR != -1 &&
620
- _gearboxOilTemp != -1 &&
621
- _batteryVoltage != -1 )
622
- {
623
- _valuesNonRtLastQueringMs = millis () + NON_RT_SENSORS_DELAY;
624
- }
625
635
}
626
636
}
627
637
}
@@ -940,13 +950,27 @@ void loop()
940
950
gt_setDpfTemperature (_dpfTemperature);
941
951
942
952
#ifdef DPF_AUDIO_NOTIFICATION
943
- DacAudio.FillBuffer ();
944
- if (_dpfRegeneration > 0 && !DacAudio.AlreadyPlaying (&Beep) && _shouldPlayDPFSound) {
945
- _shouldPlayDPFSound = false ;
946
- DacAudio.DacVolume = 100 ;
947
- DacAudio.Play (&Beep, false );
948
- } else if (_dpfRegeneration == 0 ) {
949
- _shouldPlayDPFSound = true ;
953
+ if (_dpfRegeneration > 0 && _shouldInitDPFSound)
954
+ {
955
+ buzzer.begin ();
956
+
957
+ // Add a tone to the queue
958
+ uint32_t freq = 1000 ;
959
+ uint32_t onDuration = 200 ;
960
+ uint32_t offDuration = 200 ;
961
+ uint16_t cycles = 5 ;
962
+ buzzer.tone (freq, onDuration, offDuration, cycles);
963
+ _shouldInitDPFSound = false ;
964
+ }
965
+
966
+ if (_dpfRegeneration > 0 && !_shouldInitDPFSound)
967
+ {
968
+ buzzer.update ();
969
+ }
970
+ else if (_dpfRegeneration == 0 )
971
+ {
972
+ buzzer.end ();
973
+ _shouldInitDPFSound = true ;
950
974
}
951
975
#endif
952
976
0 commit comments