Skip to content

Commit ed3ee68

Browse files
committed
fix tire temp calulation + buzzer sound onf DPF regen
1 parent eb2509d commit ed3ee68

File tree

5 files changed

+81
-51
lines changed

5 files changed

+81
-51
lines changed

.vscode/settings.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"unordered_set": "cpp",
2020
"vector": "cpp",
2121
"memory": "cpp",
22-
"gt_main.h": "c"
22+
"gt_main.h": "c",
23+
"new": "cpp",
24+
"initializer_list": "cpp"
2325
}
2426
}

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ Secondary screen:
2323
- Battery voltage (V)
2424
- Battery IBS (%)
2525
- Engine oil degradation (%)
26-
- Tires temperatures (°C) - *validation in progress*
26+
- Tires temperatures (°C)
2727
- Gearbox oil temperature (°C)
2828

2929
On first boot a touch screen calibration display wizard will start and calibration data will be persisted. On the devices screen, after scanning, you can pick an adapter to connect to.
3030

31+
If you have a buzzer connected you will get a 5 beeps warning when DPF regeneration process starts.
32+
3133
## Screenshots on 3.5'' and 2.8'' TFT displays (values are random):
3234

3335
| Screen | 2.8'' | 3.5'' |
@@ -58,6 +60,7 @@ Relevant `build_flags`:
5860
- `GT_VERBOSE_LOG`: enable verbose serial logging
5961
- `SPI_FREQUENCY`: display refresh frequency; the TFT I'm using for this project is serial and it' pretty slow but good enough
6062
- `ELM_DEBUG`: enable VERY verbose ELM protocol logs
63+
- `GT_BUZZER_PIN`: buzzer connection GPIO
6164

6265
# Right-Hand Drive models
6366

@@ -77,10 +80,10 @@ Libraries:
7780

7881
- [TFT_eSPI](https://github.com/Bodmer/TFT_eSPI) licensed [MIT](https://github.com/Bodmer/TFT_eSPI/blob/master/license.txt)
7982
- [ELMDuino](https://github.com/PowerBroker2/ELMduino) licensed [MIT](https://github.com/PowerBroker2/ELMduino/blob/master/LICENSE.md)
83+
- [ESP32-Buzzer](https://github.com/hammikb/ESP32-Buzzer) licensed [MIT](https://github.com/hammikb/ESP32-Buzzer/blob/main/LICENSE)
8084
- [LVGL](https://github.com/lvgl/lvgl) licensed [MIT](https://github.com/lvgl/lvgl/blob/master/LICENCE.txt)
8185
- [TFT_eWidget](https://github.com/Bodmer/TFT_eWidget) licensed [0BSD](https://github.com/Bodmer/TFT_eWidget/blob/main/license.txt)
8286
- [log4arduino](https://github.com/jandelgado/log4arduino) licensed [MIT](https://github.com/jandelgado/log4arduino/blob/master/LICENSE)
83-
- [XTronical_XT_DAC_Audio](https://github.com/WeekendWarrior1/XTronical_XT_DAC_Audio_Mirror) licensed [GPLv3](https://www.gnu.org/licenses/gpl-3.0.txt)
8487
- [lv_drivers](https://github.com/lvgl/lv_drivers) emulator only - licensed [MIT](https://github.com/lvgl/lv_drivers/blob/master/LICENSE)
8588

8689
# Support

platformio.ini

+7-6
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ build_flags =
3333
-D GT_FONT_SEGMENTS_96=0
3434
'-D GT_FONT_SEGMENTS=&gt_font_segments_128'
3535
-D GT_FONT_SEGMENTS_SIZE=128
36-
; -D GT_DEMO=true
37-
; -D GT_VERBOSE_LOG
36+
; -D GT_BUZZER_PIN=25
37+
; -D GT_DEMO=true
38+
; -D GT_VERBOSE_LOG
3839
-D LV_USE_CHECKBOX=0
3940
-D LV_USE_DROPDOWN=0
4041
-D LV_USE_SLIDER=0
@@ -82,15 +83,15 @@ build_flags =
8283
-D SD_SCK=18
8384
-D SD_CS=5
8485
-D ENABLE_LOG4ARDUINO
86+
-D DPF_AUDIO_NOTIFICATION
8587
; -D ELM_DEBUG=true
86-
; -D DPF_AUDIO_NOTIFICATION
8788
lib_deps =
8889
bodmer/TFT_eSPI@^2.5.34
89-
powerbroker2/ELMDuino@^3.1.0
90-
https://github.com/lvgl/lvgl/archive/refs/tags/v8.3.11.zip
90+
https://github.com/PowerBroker2/ELMduino#3.3.1
91+
https://github.com/lvgl/lvgl/archive/refs/tags/v8.3.11.zip
92+
https://github.com/hammikb/ESP32-Buzzer
9193
bodmer/TFT_eWidget@^0.0.6
9294
jandelgado/log4arduino@^1.1.0
93-
; https://github.com/WeekendWarrior1/XTronical_XT_DAC_Audio_Mirror/archive/master.zip
9495

9596
[env:lv]
9697
build_unflags = -Os

src/main.cpp

+62-38
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include <log4arduino.h>
1010

1111
#ifdef DPF_AUDIO_NOTIFICATION
12-
#include <MusicDefinitions.h>
13-
#include <XT_DAC_Audio.h>
12+
#include "ESP32S3Buzzer.h"
1413
#endif
1514

1615
#include "Free_Fonts.h"
@@ -26,21 +25,19 @@
2625
#ifndef GT_DEMO
2726
#define GT_DEMO false // show demo random data
2827
#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
3430
#endif
3531

3632
#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
4036
#define SWITCHED_STATE_DELAY 1000
4137
#define ELM_QUERY_TIMEOUT 2000
4238
#define RECONNECTION_DELAY 5000
43-
#define NON_RT_SENSORS_DELAY 10000
39+
#define NON_RT_SENSORS_DELAY 1000
40+
#define VALUES_SENSORS_DELAY 1000
4441
#define QUERY_OFFSET 300 // to time-distribute data loading on main screen
4542
#define NO_DATA_TIMEOUT 60000
4643
#define DEEPSLEEP_DURATION_US 15000000L // 15s
@@ -61,6 +58,11 @@ XT_MusicScore_Class Beep(NOTE, TEMPO_PRESTO, INSTRUMENT_PIANO);
6158
BluetoothSerial SerialBT;
6259
ELM327 btELM327;
6360

61+
#ifdef DPF_AUDIO_NOTIFICATION
62+
ESP32S3Buzzer buzzer(GT_BUZZER_PIN, 0);
63+
#endif
64+
65+
6466
static lv_disp_draw_buf_t _draw_buf;
6567
static lv_color_t _screen_buffer[GT_SCREEN_WIDTH * GT_SCREEN_HEIGTH / 10];
6668
static uint16_t _touchX, _touchY;
@@ -92,7 +94,7 @@ static int _airTemp = -1;
9294
static int _dpfClogging = -1;
9395
static int _dpfTemperature = -1;
9496
static int _dpfRegeneration = -1;
95-
static bool _shouldPlayDPFSound = true;
97+
static bool _shouldInitDPFSound = true;
9698
static int _dpfDistance = -1;
9799
static int _dpfCount = -1;
98100
static float _batteryVoltage = -1;
@@ -123,7 +125,7 @@ void _onStateChange(int screenId, bool active)
123125
_dpfClogging = -1;
124126
_dpfTemperature = -1;
125127
_dpfRegeneration = -1;
126-
_shouldPlayDPFSound = true;
128+
_shouldInitDPFSound = true;
127129
_dpfDistance = -1;
128130

129131
unsigned long now = millis();
@@ -193,8 +195,11 @@ static int _get_demo_v(int pid)
193195
case 0x40B2:
194196
case 0x40B3:
195197
case 0x30B4:
198+
return -1;
196199
case 0x04FE:
197200
return 70 + (int)(((float)rand() / (float)(RAND_MAX)) * 10) - 10;
201+
case 0x194D:
202+
return 7;
198203
default:
199204
return -1;
200205
}
@@ -271,7 +276,7 @@ static bool _gt_elmConnect()
271276

272277
if (SerialBT.connect(BTAddress(_mac)))
273278
{
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))
275280
{
276281
LOG("Can't init connection to ELM327 device %s", _mac);
277282
}
@@ -324,7 +329,7 @@ static int _gt_setHeader(int headerId, const char *header)
324329
/**
325330
* process PID in blocking mode
326331
*/
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)
328333
{
329334
unsigned long timeoutAt = millis() + (ELM_QUERY_TIMEOUT * 2);
330335
while (millis() < timeoutAt)
@@ -335,7 +340,7 @@ static float _gt_processPID(const uint8_t &service, const uint16_t &pid, const u
335340
delay(ELM_LOOP_DELAY);
336341
return _get_demo_v(pid);
337342
}
338-
float value = btELM327.processPID(service, pid, numResponses, numExpectedBytes, scaleFactor, bias);
343+
double value = btELM327.processPID(service, pid, numResponses, numExpectedBytes, scaleFactor, bias);
339344
if (btELM327.nb_rx_state == ELM_SUCCESS)
340345
{
341346
VLOG("Value for %x is %.2f", pid, value);
@@ -569,10 +574,22 @@ void _gt_elmLoop(void *pvParameters)
569574

570575
if (_currentHeaderId == HEADER_DAC7F1_ID)
571576
{
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+
}
576593
}
577594

578595
if (_currentHeaderId != HEADER_DA18F1_ID)
@@ -609,19 +626,12 @@ void _gt_elmLoop(void *pvParameters)
609626
if (_currentHeaderId == HEADER_DB33F1_ID)
610627
{
611628
_batteryVoltage = _gt_processPID(0x01, 0x42, 1, 2, 0.001, 0);
629+
if (_batteryVoltage != -1)
630+
{
631+
_valuesNonRtLastQueringMs = millis() + NON_RT_SENSORS_DELAY;
632+
}
612633
}
613634

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-
}
625635
}
626636
}
627637
}
@@ -940,13 +950,27 @@ void loop()
940950
gt_setDpfTemperature(_dpfTemperature);
941951

942952
#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;
950974
}
951975
#endif
952976

src/screens/gt_values.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void gt_setTireTemperatureFL(int celsius)
8989
_currentTireTempFL = celsius;
9090
if (_currentTireTempFL != -1 && lv_obj_is_valid(_tire_temp_fl_label))
9191
{
92-
char str[8];
92+
char str[32];
9393
sprintf(str, "%d °C", celsius % 1000); // module is for overflow protection
9494
lv_label_set_text(_tire_temp_fl_label, str);
9595
}
@@ -103,7 +103,7 @@ void gt_setTireTemperatureFR(int celsius)
103103
_currentTireTempFR = celsius;
104104
if (_currentTireTempFR != -1 && lv_obj_is_valid(_tire_temp_fr_label))
105105
{
106-
char str[8];
106+
char str[32];
107107
sprintf(str, "%d °C", celsius % 1000); // module is for overflow protection
108108
lv_label_set_text(_tire_temp_fr_label, str);
109109
}
@@ -117,7 +117,7 @@ void gt_setTireTemperatureRL(int celsius)
117117
_currentTireTempRL = celsius;
118118
if (_currentTireTempRL != -1 && lv_obj_is_valid(_tire_temp_rl_label))
119119
{
120-
char str[8];
120+
char str[32];
121121
sprintf(str, "%d °C", celsius % 1000); // module is for overflow protection
122122
lv_label_set_text(_tire_temp_rl_label, str);
123123
}
@@ -131,7 +131,7 @@ void gt_setTireTemperatureRR(int celsius)
131131
_currentTireTempRR = celsius;
132132
if (_currentTireTempRR != -1 && lv_obj_is_valid(_tire_temp_rr_label))
133133
{
134-
char str[8];
134+
char str[32];
135135
sprintf(str, "%d °C", celsius % 1000); // module is for overflow protection
136136
lv_label_set_text(_tire_temp_rr_label, str);
137137
}

0 commit comments

Comments
 (0)