Skip to content

Commit 81dabe5

Browse files
committed
Alarm clock with or without bell
1 parent 8111587 commit 81dabe5

File tree

3 files changed

+74
-35
lines changed

3 files changed

+74
-35
lines changed

src/common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// created: 10.Feb.2022
2-
// updated: 11.Jun 2024
2+
// updated: 13.Jun 2024
33

44
#pragma once
55
#pragma GCC optimize("Os") // optimize for code size
@@ -227,7 +227,7 @@ bool SD_newFolder(const char* folderPathName);
227227
bool SD_delete(const char* itemPath);
228228
bool preparePlaylistFromDLNAFolder();
229229
bool preparePlaylistFromFile(const char* path);
230-
bool preparePlaylistFromFolder(const char* path);
230+
bool preparePlaylistFromSDFolder(const char* path);
231231
void sortPlayListAlphabetical();
232232
void sortPlayListRandom();
233233
void processPlaylist(boolean first = false);
@@ -2894,7 +2894,7 @@ inline void GetRunTimeStats( char *pcWriteBuffer ){
28942894
strcat(pcWriteBuffer, "\n");
28952895
}
28962896
free(tmpBuff);
2897-
}
2897+
}
28982898
// The array is no longer needed, free the memory it consumes.
28992899
vPortFree( pxTaskStatusArray );
29002900
}

src/index.h

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* index.h
33
*
44
* Created on: 04.10.2018
5-
* Updated on: 06.04.2024
5+
* Updated on: 13.06.2024
66
* Author: Wolle
77
*
88
* successfully tested with Chrome and Firefox
@@ -414,6 +414,7 @@ function connect() {
414414
socket.send("change_state=" + "RADIO")
415415
socket.send("getTimeFormat")
416416
socket.send("getSleepMode")
417+
socket.send("getAlarmMode") // with bell and radio or with radio only
417418

418419
setInterval(ping, 20000)
419420
};
@@ -542,6 +543,10 @@ function connect() {
542543
else if(val == '1') radiobtn = document.getElementById("sleepMode1")
543544
radiobtn.checked = true;
544545
break;
546+
case "alarmMode": if (val == '0') radiobtn = document.getElementById("alarmMode0")
547+
else if(val == '1') radiobtn = document.getElementById("alarmMode1")
548+
radiobtn.checked = true;
549+
break;
545550
case "changeState": if (val == 'RADIO' && state != 'RADIO') showTab1();
546551
if (val == 'PLAYER'&& state != 'PLAYER') showTab3();
547552
if (val == 'BLUETOOTH'&& state != 'BT') showTab8();
@@ -2260,6 +2265,24 @@ function clear_BT_memItems(){
22602265
<label for="label-infopic" onclick="socket.send('hardcopy')">
22612266
<img id="label-infopic" src="SD/png/MiniWebRadioV3.png" alt="img">
22622267
</label>
2268+
2269+
<h3>
2270+
Connected WiFi network
2271+
<select class="boxstyle" id="ssid" ></select>
2272+
</h3>
2273+
2274+
<h3>
2275+
Timezone
2276+
<select class="boxstyle" onchange="setTimeZone(this)" id="TimeZoneSelect"></select>
2277+
</h3>
2278+
2279+
<h3>
2280+
Time announcement on the hour
2281+
<input type="checkbox" id="chk_timeSpeech"
2282+
onclick="socket.send('set_timeAnnouncement=' + document.getElementById('chk_timeSpeech').checked);">
2283+
</h3>
2284+
2285+
22632286
</td>
22642287
<td>
22652288
<div style="display: flex;">
@@ -2303,25 +2326,23 @@ function clear_BT_memItems(){
23032326
<label for="sleepMode1">show the time</label>
23042327
</div>
23052328
</fieldset>
2329+
<br>
2330+
<fieldset>
2331+
<legend> alarm clock </legend>
2332+
<div>
2333+
<input type="radio" id="alarmMode0" name="alarmMode" value="only with radio" onclick="socket.send('setAlarmMode=0');">
2334+
<label for="alarmMode0">with radio only</label>
2335+
</div>
2336+
<div>
2337+
<input type="radio" id="alarmMode1" name="alarmMode" value="with bell and radio" checked onclick="socket.send('setAlarmMode=1');">
2338+
<label for="alarmMode1">with bell and radio</label>
2339+
</div>
2340+
</fieldset>
23062341
</td>
23072342
</tr>
23082343
</table>
23092344

2310-
<h3>
2311-
Connected WiFi network
2312-
<select class="boxstyle" id="ssid" ></select>
2313-
</h3>
2314-
2315-
<h3>
2316-
Timezone
2317-
<select class="boxstyle" onchange="setTimeZone(this)" id="TimeZoneSelect"></select>
2318-
</h3>
2319-
2320-
<h3>
2321-
Time announcement on the hour
2322-
<input type="checkbox" id="chk_timeSpeech"
2323-
onclick="socket.send('set_timeAnnouncement=' + document.getElementById('chk_timeSpeech').checked);">
2324-
</h3>
2345+
23252346
</div>
23262347
<!--===============================================================================================================================================-->
23272348
<div id="tab-content7"> <!-- IR Settings -->

src/main.cpp

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
MiniWebRadio -- Webradio receiver for ESP32
55
66
first release on 03/2017 */String Version ="\
7-
Version 3.1e Jun 11/2024 ";
7+
Version 3.2 Jun 13/2024 ";
88

99
/* 2.8" color display (320x240px) with controller ILI9341 or HX8347D (SPI) or
1010
3.5" color display (480x320px) wiht controller ILI9486 or ILI9488 (SPI)
@@ -72,7 +72,8 @@ uint8_t _cur_Codec = 0;
7272
uint8_t _numServers = 0; //
7373
uint8_t _level = 0;
7474
uint8_t _timeFormat = 24; // 24 or 12
75-
uint8_t _sleepMode = 0; // 0 display off, 1 show the clock
75+
uint8_t _sleepMode = 0; // 0 display off, 1 show the clock
76+
uint8_t _alarmMode = 1; // 0 with radio only, 1 with bell and radio
7677
uint8_t _staListPos = 0;
7778
uint8_t _semaphore = 0;
7879
uint8_t _reconnectCnt = 0;
@@ -427,7 +428,8 @@ boolean defaultsettings(){
427428
strcat(jO, "\"toneHP\":"); strcat(jO, "0,"); // -40 ... +6 (dB) audioI2S
428429
strcat(jO, "\"balance\":"); strcat(jO, "0,"); // -16 ... +16 audioI2S
429430
strcat(jO, "\"timeFormat\":"); strcat(jO, "24,");
430-
strcat(jO, "\"sleepMode\":"); strcat(jO, "0}"); // 0 display off, 1 clock
431+
strcat(jO, "\"sleepMode\":"); strcat(jO, "0,"); // 0 display off, 1 clock
432+
strcat(jO, "\"alarmMode\":"); strcat(jO, "1}"); // 0 with radio only, 1 with bell and radio
431433
file.print(jO);
432434
if(jO){free(jO); jO = NULL;}
433435
}
@@ -483,6 +485,7 @@ boolean defaultsettings(){
483485
_TZString = parseJson("\"Timezone_String\":");
484486
_lastconnectedhost = parseJson("\"lastconnectedhost\":");
485487
_sleepMode = atoi( parseJson("\"sleepMode\":"));
488+
_alarmMode = atoi( parseJson("\"alarmMode\":"));
486489

487490

488491
if(!pref.isKey("stations_filled")|| _sum_stations == 0) saveStationsToNVS(); // first init
@@ -638,7 +641,8 @@ void updateSettings(){
638641
sprintf(tmp, ",\"toneHP\":%i", _toneHP); strcat(jO, tmp);
639642
sprintf(tmp, ",\"balance\":%i", _toneBAL); strcat(jO, tmp);
640643
sprintf(tmp, ",\"timeFormat\":%i", _timeFormat); strcat(jO, tmp);
641-
sprintf(tmp, ",\"sleepMode\":%i}", _sleepMode); strcat(jO, tmp);
644+
sprintf(tmp, ",\"sleepMode\":%i", _sleepMode); strcat(jO, tmp);
645+
sprintf(tmp, ",\"alarmMode\":%i}", _alarmMode); strcat(jO, tmp);
642646

643647
if(_settingsHash != simpleHash(jO)) {
644648
File file = SD_MMC.open("/settings.json", "w", false);
@@ -1021,7 +1025,7 @@ boolean isPlaylist(File file) {
10211025
* P L A Y L I S T *
10221026
*****************************************************************************************************************************************************/
10231027

1024-
bool preparePlaylistFromFile(const char* path) {
1028+
bool preparePlaylistFromFile(const char* path) { // *.m3u
10251029
File playlistFile = SD_MMC.open(path);
10261030
if(!playlistFile) {
10271031
log_e("playlistfile path not found");
@@ -1084,7 +1088,7 @@ bool preparePlaylistFromFile(const char* path) {
10841088
}
10851089
//____________________________________________________________________________________________________________________________________________________
10861090

1087-
bool preparePlaylistFromFolder(const char* path) { // all files whithin a folder
1091+
bool preparePlaylistFromSDFolder(const char* path) { // all files whithin a SD folder
10881092
if(!SD_MMC.exists(path)) {
10891093
SerialPrintfln(ANSI_ESC_RED "SD_MMC/%s not exist", path);
10901094
return false;
@@ -2510,13 +2514,19 @@ void loop() {
25102514
dispHeader.updateItem("ALARM");
25112515
dispHeader.updateTime(rtc.gettime_s());
25122516
dispFooter.show();
2513-
showFileName("ALARM");
2514-
drawImage("/common/Alarm.jpg", _winLogo.x, _winLogo.y);
2515-
setTFTbrightness(_brightness);
2516-
SerialPrintfln(ANSI_ESC_MAGENTA "Alarm");
2517-
audioSetVolume(21);
2518-
muteChanged(false);
2519-
connecttoFS("/ring/alarm_clock.mp3");
2517+
if(_alarmMode == 1){ // alarm with bell
2518+
showFileName("ALARM");
2519+
drawImage("/common/Alarm.jpg", _winLogo.x, _winLogo.y);
2520+
setTFTbrightness(_brightness);
2521+
SerialPrintfln(ANSI_ESC_MAGENTA "Alarm");
2522+
audioSetVolume(21);
2523+
muteChanged(false);
2524+
connecttoFS("/ring/alarm_clock.mp3");
2525+
}
2526+
else{ // alarm without bell
2527+
_f_eof_alarm = true;
2528+
return;
2529+
}
25202530
}
25212531
if(_f_eof_alarm) { // AFTER RINGING
25222532
_f_eof_alarm = false;
@@ -3315,7 +3325,7 @@ void WEBSRV_onCommand(const String cmd, const String param, const String arg){
33153325

33163326
if(cmd == "SD_playAllFiles"){ webSrv.send("SD_playFolder=", "" + param);
33173327
SerialPrintfln("webSrv: ... " ANSI_ESC_YELLOW "Play Folder" ANSI_ESC_ORANGE "\"%s\"", param.c_str());
3318-
preparePlaylistFromFolder(param.c_str());
3328+
preparePlaylistFromSDFolder(param.c_str());
33193329
processPlaylist(true);
33203330
return;}
33213331

@@ -3369,6 +3379,14 @@ void WEBSRV_onCommand(const String cmd, const String param, const String arg){
33693379
if(_sleepMode == 1) SerialPrintfln("SleepMode: " ANSI_ESC_YELLOW "Show the time");
33703380
return;}
33713381

3382+
if(cmd == "getAlarmMode"){ webSrv.send("alarmMode=", String(_alarmMode, 10));
3383+
return;}
3384+
3385+
if(cmd == "setAlarmMode"){ _alarmMode = param.toInt();
3386+
if(_alarmMode == 0) SerialPrintfln("AlarmMode: " ANSI_ESC_YELLOW "with radio only");
3387+
if(_alarmMode == 1) SerialPrintfln("AlarmMode: " ANSI_ESC_YELLOW "with bell and radio");
3388+
return;}
3389+
33723390
if(cmd == "loadIRbuttons"){ loadIRbuttonsFromNVS(); // update IR buttons in ir.cpp
33733391
char buf[150];
33743392
uint8_t* buttons = ir.get_irButtons();
@@ -3661,8 +3679,8 @@ void graphicObjects_OnRelease(const char* name, releasedArg ra) {
36613679
if(strcmp(name, "btn_PL_prevFile") == 0) {return;}
36623680
if(strcmp(name, "btn_PL_nextFile") == 0) {return;}
36633681
if(strcmp(name, "btn_PL_ready") == 0) {_playerSubmenue = 1; SD_playFile(_curAudioFolder, _SD_content.getIndex(_cur_AudioFileNr)); changeState(PLAYER); showAudioFileNumber(); return;}
3664-
if(strcmp(name, "btn_PL_playAll") == 0) {_playerSubmenue = 1; _f_shuffle = false; preparePlaylistFromFolder(_curAudioFolder); processPlaylist(true); changeState(PLAYER); return;}
3665-
if(strcmp(name, "btn_PL_shuffle") == 0) {_playerSubmenue = 1; _f_shuffle = true; preparePlaylistFromFolder(_curAudioFolder); processPlaylist(true); changeState(PLAYER); return;}
3682+
if(strcmp(name, "btn_PL_playAll") == 0) {_playerSubmenue = 1; _f_shuffle = false; preparePlaylistFromSDFolder(_curAudioFolder); processPlaylist(true); changeState(PLAYER); return;}
3683+
if(strcmp(name, "btn_PL_shuffle") == 0) {_playerSubmenue = 1; _f_shuffle = true; preparePlaylistFromSDFolder(_curAudioFolder); processPlaylist(true); changeState(PLAYER); return;}
36663684
if(strcmp(name, "btn_PL_fileList") == 0) {_playerSubmenue = 1; _SD_content.listDir(_curAudioFolder, true, false); changeState(AUDIOFILESLIST); return;}
36673685
if(strcmp(name, "btn_PL_radio") == 0) {_playerSubmenue = 0; setStation(_cur_station); changeState(RADIO); return;}
36683686
}

0 commit comments

Comments
 (0)