Skip to content

Commit 1a765d6

Browse files
committed
v4.1.0
- add tones for buzzer - add rtc 8563 for Elecrow C3 - fix #11 compile error - add face selector
1 parent e521305 commit 1a765d6

File tree

8 files changed

+254
-12
lines changed

8 files changed

+254
-12
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"75_2_dial.h": "c",
55
"radar.h": "c",
66
"79_2_dial.h": "c",
7-
"racing.h": "c"
7+
"racing.h": "c",
8+
"chrono": "cpp"
89
}
910
}

hal/esp32/app_hal.cpp

Lines changed: 120 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include <Wire.h>
4343
#include "app_hal.h"
4444

45+
#include "tone.h"
46+
4547
#include <lvgl.h>
4648
#include "ui/ui.h"
4749

@@ -59,6 +61,11 @@
5961
#define QMI8658C_I2C_FREQUENCY 40000 // Define I2C frequency as 80kHz (in Hz)
6062
#endif
6163

64+
#ifdef ENABLE_RTC
65+
#include <RtcPCF8563.h>
66+
RtcPCF8563<TwoWire> Rtc(Wire);
67+
#endif
68+
6269
#define FLASH FFat
6370
#define F_NAME "FATFS"
6471
#define buf_size 10
@@ -355,6 +362,71 @@ void set_pin_io(uint8_t pin_number, bool value)
355362
}
356363
#endif
357364

365+
#ifdef ENABLE_RTC
366+
bool wasError(const char *errorTopic = "")
367+
{
368+
uint8_t error = Rtc.LastError();
369+
if (error != 0)
370+
{
371+
// we have a communications error
372+
// see https://www.arduino.cc/reference/en/language/functions/communication/wire/endtransmission/
373+
// for what the number means
374+
Serial.print("[");
375+
Serial.print(errorTopic);
376+
Serial.print("] WIRE communications error (");
377+
Serial.print(error);
378+
Serial.print(") : ");
379+
380+
switch (error)
381+
{
382+
case Rtc_Wire_Error_None:
383+
Serial.println("(none?!)");
384+
break;
385+
case Rtc_Wire_Error_TxBufferOverflow:
386+
Serial.println("transmit buffer overflow");
387+
break;
388+
case Rtc_Wire_Error_NoAddressableDevice:
389+
Serial.println("no device responded");
390+
break;
391+
case Rtc_Wire_Error_UnsupportedRequest:
392+
Serial.println("device doesn't support request");
393+
break;
394+
case Rtc_Wire_Error_Unspecific:
395+
Serial.println("unspecified error");
396+
break;
397+
case Rtc_Wire_Error_CommunicationTimeout:
398+
Serial.println("communications timed out");
399+
break;
400+
}
401+
return true;
402+
}
403+
return false;
404+
}
405+
#endif
406+
407+
408+
void toneOut(int pitch, int duration)
409+
{ // pitch in Hz, duration in ms
410+
#if defined(BUZZER) && (BUZZER != -1)
411+
int delayPeriod;
412+
long cycles, i;
413+
414+
pinMode(BUZZER, OUTPUT); // turn on output pin
415+
delayPeriod = (500000 / pitch) - 7; // calc 1/2 period in us -7 for overhead
416+
cycles = ((long)pitch * (long)duration) / 1000; // calc. number of cycles for loop
417+
418+
for (i = 0; i <= cycles; i++)
419+
{ // play note for duration ms
420+
digitalWrite(BUZZER, HIGH);
421+
delayMicroseconds(delayPeriod);
422+
digitalWrite(BUZZER, LOW);
423+
delayMicroseconds(delayPeriod - 1); // - 1 to make up for digitaWrite overhead
424+
}
425+
pinMode(BUZZER, INPUT); // shut off pin to avoid noise from other operations
426+
#endif
427+
}
428+
429+
358430
String heapUsage()
359431
{
360432
String usage;
@@ -504,6 +576,14 @@ void checkLocal()
504576
}
505577
}
506578

579+
void screenBrightness(uint8_t value)
580+
{
581+
tft.setBrightness(value);
582+
#ifdef ELECROW_C3
583+
set_pin_io(2, value > 0); // ELECROW C3, no brightness control
584+
#endif
585+
}
586+
507587
String readFile(const char *path)
508588
{
509589
String result;
@@ -897,6 +977,14 @@ void configCallback(Config config, uint32_t a, uint32_t b)
897977
{
898978
switch (config)
899979
{
980+
case CF_TIME:
981+
// time has been synced from BLE
982+
#ifdef ENABLE_RTC
983+
// set the RTC time
984+
Rtc.SetDateTime(RtcDateTime(watch.getYear(), watch.getMonth() + 1, watch.getDay(), watch.getHour(true), watch.getMinute(), watch.getSecond()));
985+
986+
#endif
987+
break;
900988
case CF_RST:
901989

902990
Serial.println("Reset request, formating storage");
@@ -1104,7 +1192,7 @@ void onBrightnessChange(lv_event_t *e)
11041192
// Your code here
11051193
lv_obj_t *slider = lv_event_get_target(e);
11061194
int v = lv_slider_get_value(slider);
1107-
tft.setBrightness(v);
1195+
screenBrightness(v);
11081196

11091197
prefs.putInt("brightness", v);
11101198
}
@@ -1422,7 +1510,7 @@ void loadSplash()
14221510
int xOffset = 63;
14231511
int yOffset = 55;
14241512
tft.fillScreen(TFT_BLACK);
1425-
tft.setBrightness(200);
1513+
screenBrightness(200);
14261514
for (int y = 0; y < h; y++)
14271515
{
14281516
for (int x = 0; x < w; x++)
@@ -1460,6 +1548,10 @@ void hal_setup()
14601548
tft.fillScreen(TFT_BLACK);
14611549
loadSplash();
14621550

1551+
toneOut(TONE_EN * 2, 170);
1552+
toneOut(TONE_FS * 2, 170);
1553+
toneOut(TONE_GN * 2, 170);
1554+
14631555
Serial.println(heapUsage());
14641556

14651557
lv_init();
@@ -1566,7 +1658,7 @@ void hal_setup()
15661658
tm = 0;
15671659
}
15681660

1569-
tft.setBrightness(br);
1661+
screenBrightness(br);
15701662

15711663
lv_dropdown_set_selected(ui_timeoutSelect, tm);
15721664
lv_slider_set_value(ui_brightnessSlider, br, LV_ANIM_OFF);
@@ -1615,6 +1707,28 @@ void hal_setup()
16151707

16161708
#endif
16171709

1710+
#ifdef ENABLE_RTC
1711+
Rtc.Begin();
1712+
1713+
if (!Rtc.GetIsRunning())
1714+
{
1715+
uint8_t error = Rtc.LastError();
1716+
if (error != 0)
1717+
{
1718+
showError("RTC", "Error on RTC");
1719+
}
1720+
Rtc.SetIsRunning(true);
1721+
}
1722+
1723+
RtcDateTime now = Rtc.GetDateTime();
1724+
1725+
watch.setTime(now.Second(), now.Minute(), now.Hour(), now.Day(), now.Month(), now.Year());
1726+
1727+
Rtc.StopAlarm();
1728+
Rtc.StopTimer();
1729+
Rtc.SetSquareWavePin(PCF8563SquareWavePinMode_None);
1730+
#endif
1731+
16181732
Timber.i("Setup done");
16191733
Timber.i(about);
16201734
}
@@ -1685,7 +1799,7 @@ void hal_loop()
16851799
if (screenTimer.active)
16861800
{
16871801
uint8_t lvl = lv_slider_get_value(ui_brightnessSlider);
1688-
tft.setBrightness(lvl);
1802+
screenBrightness(lvl);
16891803

16901804
if (screenTimer.duration < 0)
16911805
{
@@ -1701,7 +1815,7 @@ void hal_loop()
17011815
Timber.w("Screen timeout");
17021816
screenTimer.active = false;
17031817

1704-
tft.setBrightness(0);
1818+
screenBrightness(0);
17051819
lv_disp_load_scr(ui_home);
17061820
}
17071821
}
@@ -1712,7 +1826,7 @@ void hal_loop()
17121826
{
17131827
if (start)
17141828
{
1715-
tft.setBrightness(200);
1829+
screenBrightness(200);
17161830
tft.fillScreen(TFT_BLUE);
17171831

17181832
tft.drawRoundRect(70, 120, 100, 20, 5, TFT_WHITE);

hal/esp32/app_hal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// 240x240 watchfaces
2121

2222
#define ENABLE_FACE_34_2_DIAL // (Shadow)
23-
// #define ENABLE_FACE_75_2_DIAL // (Analog)
23+
#define ENABLE_FACE_75_2_DIAL // (Analog)
2424
// #define ENABLE_FACE_79_2_DIAL // (Blue)
2525
// #define ENABLE_FACE_116_2_DIAL // (Outline)
2626
#define ENABLE_FACE_756_2_DIAL // (Red)
@@ -38,6 +38,9 @@
3838
#define ENABLE_APP_QMI8658C
3939
#endif
4040

41+
#if defined(ELECROW_C3)
42+
#define ENABLE_RTC
43+
#endif
4144

4245
// #define ENABLE_GAME_RACING
4346

hal/esp32/tone.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
3+
#ifndef TONE_H
4+
#define TONE_H
5+
6+
#define TONE_AN 220 // 440 Hz
7+
#define TONE_AS 233 // 466 Hz
8+
#define TONE_BN 247 // 493 Hz
9+
#define TONE_CN 261 // 523 Hz
10+
#define TONE_CS 277 // 554 Hz
11+
#define TONE_DN 294 // 588 Hz
12+
#define TONE_DS 311 // 622 Hz
13+
#define TONE_EN 330 // 658 Hz
14+
#define TONE_FN 349 // 698 Hz
15+
#define TONE_FS 370 // 740 Hz
16+
#define TONE_GN 392 // 784 Hz
17+
#define TONE_GS 415 // 830 Hz
18+
// defines for the duration of the notes (in ms)
19+
// #define WH 1024
20+
// #define H1 100
21+
// #define DQ 448
22+
// #define Q 256
23+
// #define qt 170
24+
// #define de 192
25+
// #define e 128
26+
// #define et 85
27+
28+
29+
#endif

include/main.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959

6060
#define BL -1 // unused (connected on IO extender)
6161

62+
#define BUZZER 3
63+
6264
#define MAX_FILE_OPEN 10
6365

6466
#elif ESPC3
@@ -88,6 +90,8 @@
8890

8991
#define BL 3
9092

93+
#define BUZZER -1
94+
9195
#define MAX_FILE_OPEN 10
9296

9397
#elif ESPS3_1_28
@@ -117,6 +121,8 @@
117121

118122
#define BL 2
119123

124+
#define BUZZER -1
125+
120126
#define MAX_FILE_OPEN 50
121127

122128
#elif ESPS3_1_69
@@ -146,6 +152,8 @@
146152

147153
#define BL 15
148154

155+
#define BUZZER 33
156+
149157
#define MAX_FILE_OPEN 20
150158

151159
#define CS_CONFIG CS_240x296_191_RTF
@@ -177,6 +185,8 @@
177185

178186
#define BL 2
179187

188+
#define BUZZER -1
189+
180190
#define MAX_FILE_OPEN 10
181191

182192
#endif

platformio.ini

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ framework = arduino
110110
board_build.partitions = partitions.csv ;noota_ffat.csv
111111
lib_deps =
112112
${esp32.lib_deps}
113+
makuna/RTC@^2.4.3
113114
build_flags =
114115
${esp32.build_flags}
115116
-D ELECROW_C3=1
@@ -132,7 +133,7 @@ lib_deps =
132133
build_flags =
133134
${esp32.build_flags}
134135
-D ESPC3=1
135-
-D LV_MEM_SIZE=(120U*1024U)
136+
-D LV_MEM_SIZE=120U*1024U
136137
-D LV_USE_QRCODE=1
137138
; -D NO_WATCHFACES
138139
-D ENABLE_CUSTOM_FACE=1
@@ -155,7 +156,7 @@ lib_deps =
155156
build_flags =
156157
${esp32.build_flags}
157158
-D ESPS3_1_28=1
158-
-D LV_MEM_SIZE=(120U*1024U)
159+
-D LV_MEM_SIZE=120U*1024U
159160
-D ENABLE_CUSTOM_FACE=1
160161
-D LV_USE_QRCODE=1
161162
build_src_filter =
@@ -178,7 +179,7 @@ lib_deps =
178179
build_flags =
179180
${esp32.build_flags}
180181
-D ESPS3_1_69=1
181-
-D LV_MEM_SIZE=(120U*1024U)
182+
-D LV_MEM_SIZE=120U*1024U
182183
; -D ENABLE_CUSTOM_FACE=1 ; custom watchface crashes firmware, disable it
183184
-D LV_USE_QRCODE=1
184185
build_src_filter =
@@ -193,7 +194,7 @@ lib_deps =
193194
${esp32.lib_deps}
194195
build_flags =
195196
${esp32.build_flags}
196-
-D LV_MEM_SIZE=(60U*1024U)
197+
-D LV_MEM_SIZE=60U*1024U
197198
-D LV_MEM_ADR=0
198199
; -D NO_WATCHFACES
199200
build_src_filter =

0 commit comments

Comments
 (0)