Skip to content

Commit

Permalink
Alarm clock with or without bell
Browse files Browse the repository at this point in the history
  • Loading branch information
schreibfaul1 committed Jun 13, 2024
1 parent 8111587 commit 81dabe5
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// created: 10.Feb.2022
// updated: 11.Jun 2024
// updated: 13.Jun 2024

#pragma once
#pragma GCC optimize("Os") // optimize for code size
Expand Down Expand Up @@ -227,7 +227,7 @@ bool SD_newFolder(const char* folderPathName);
bool SD_delete(const char* itemPath);
bool preparePlaylistFromDLNAFolder();
bool preparePlaylistFromFile(const char* path);
bool preparePlaylistFromFolder(const char* path);
bool preparePlaylistFromSDFolder(const char* path);
void sortPlayListAlphabetical();
void sortPlayListRandom();
void processPlaylist(boolean first = false);
Expand Down Expand Up @@ -2894,7 +2894,7 @@ inline void GetRunTimeStats( char *pcWriteBuffer ){
strcat(pcWriteBuffer, "\n");
}
free(tmpBuff);
}
}
// The array is no longer needed, free the memory it consumes.
vPortFree( pxTaskStatusArray );
}
Expand Down
53 changes: 37 additions & 16 deletions src/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* index.h
*
* Created on: 04.10.2018
* Updated on: 06.04.2024
* Updated on: 13.06.2024
* Author: Wolle
*
* successfully tested with Chrome and Firefox
Expand Down Expand Up @@ -414,6 +414,7 @@ function connect() {
socket.send("change_state=" + "RADIO")
socket.send("getTimeFormat")
socket.send("getSleepMode")
socket.send("getAlarmMode") // with bell and radio or with radio only

setInterval(ping, 20000)
};
Expand Down Expand Up @@ -542,6 +543,10 @@ function connect() {
else if(val == '1') radiobtn = document.getElementById("sleepMode1")
radiobtn.checked = true;
break;
case "alarmMode": if (val == '0') radiobtn = document.getElementById("alarmMode0")
else if(val == '1') radiobtn = document.getElementById("alarmMode1")
radiobtn.checked = true;
break;
case "changeState": if (val == 'RADIO' && state != 'RADIO') showTab1();
if (val == 'PLAYER'&& state != 'PLAYER') showTab3();
if (val == 'BLUETOOTH'&& state != 'BT') showTab8();
Expand Down Expand Up @@ -2260,6 +2265,24 @@ function clear_BT_memItems(){
<label for="label-infopic" onclick="socket.send('hardcopy')">
<img id="label-infopic" src="SD/png/MiniWebRadioV3.png" alt="img">
</label>

<h3>
Connected WiFi network
<select class="boxstyle" id="ssid" ></select>
</h3>

<h3>
Timezone
<select class="boxstyle" onchange="setTimeZone(this)" id="TimeZoneSelect"></select>
</h3>

<h3>
Time announcement on the hour
<input type="checkbox" id="chk_timeSpeech"
onclick="socket.send('set_timeAnnouncement=' + document.getElementById('chk_timeSpeech').checked);">
</h3>


</td>
<td>
<div style="display: flex;">
Expand Down Expand Up @@ -2303,25 +2326,23 @@ function clear_BT_memItems(){
<label for="sleepMode1">show the time</label>
</div>
</fieldset>
<br>
<fieldset>
<legend> alarm clock </legend>
<div>
<input type="radio" id="alarmMode0" name="alarmMode" value="only with radio" onclick="socket.send('setAlarmMode=0');">
<label for="alarmMode0">with radio only</label>
</div>
<div>
<input type="radio" id="alarmMode1" name="alarmMode" value="with bell and radio" checked onclick="socket.send('setAlarmMode=1');">
<label for="alarmMode1">with bell and radio</label>
</div>
</fieldset>
</td>
</tr>
</table>

<h3>
Connected WiFi network
<select class="boxstyle" id="ssid" ></select>
</h3>

<h3>
Timezone
<select class="boxstyle" onchange="setTimeZone(this)" id="TimeZoneSelect"></select>
</h3>

<h3>
Time announcement on the hour
<input type="checkbox" id="chk_timeSpeech"
onclick="socket.send('set_timeAnnouncement=' + document.getElementById('chk_timeSpeech').checked);">
</h3>

</div>
<!--===============================================================================================================================================-->
<div id="tab-content7"> <!-- IR Settings -->
Expand Down
50 changes: 34 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
MiniWebRadio -- Webradio receiver for ESP32

first release on 03/2017 */String Version ="\
Version 3.1e Jun 11/2024 ";
Version 3.2 Jun 13/2024 ";

/* 2.8" color display (320x240px) with controller ILI9341 or HX8347D (SPI) or
3.5" color display (480x320px) wiht controller ILI9486 or ILI9488 (SPI)
Expand Down Expand Up @@ -72,7 +72,8 @@ uint8_t _cur_Codec = 0;
uint8_t _numServers = 0; //
uint8_t _level = 0;
uint8_t _timeFormat = 24; // 24 or 12
uint8_t _sleepMode = 0; // 0 display off, 1 show the clock
uint8_t _sleepMode = 0; // 0 display off, 1 show the clock
uint8_t _alarmMode = 1; // 0 with radio only, 1 with bell and radio
uint8_t _staListPos = 0;
uint8_t _semaphore = 0;
uint8_t _reconnectCnt = 0;
Expand Down Expand Up @@ -427,7 +428,8 @@ boolean defaultsettings(){
strcat(jO, "\"toneHP\":"); strcat(jO, "0,"); // -40 ... +6 (dB) audioI2S
strcat(jO, "\"balance\":"); strcat(jO, "0,"); // -16 ... +16 audioI2S
strcat(jO, "\"timeFormat\":"); strcat(jO, "24,");
strcat(jO, "\"sleepMode\":"); strcat(jO, "0}"); // 0 display off, 1 clock
strcat(jO, "\"sleepMode\":"); strcat(jO, "0,"); // 0 display off, 1 clock
strcat(jO, "\"alarmMode\":"); strcat(jO, "1}"); // 0 with radio only, 1 with bell and radio
file.print(jO);
if(jO){free(jO); jO = NULL;}
}
Expand Down Expand Up @@ -483,6 +485,7 @@ boolean defaultsettings(){
_TZString = parseJson("\"Timezone_String\":");
_lastconnectedhost = parseJson("\"lastconnectedhost\":");
_sleepMode = atoi( parseJson("\"sleepMode\":"));
_alarmMode = atoi( parseJson("\"alarmMode\":"));


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

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

bool preparePlaylistFromFile(const char* path) {
bool preparePlaylistFromFile(const char* path) { // *.m3u
File playlistFile = SD_MMC.open(path);
if(!playlistFile) {
log_e("playlistfile path not found");
Expand Down Expand Up @@ -1084,7 +1088,7 @@ bool preparePlaylistFromFile(const char* path) {
}
//____________________________________________________________________________________________________________________________________________________

bool preparePlaylistFromFolder(const char* path) { // all files whithin a folder
bool preparePlaylistFromSDFolder(const char* path) { // all files whithin a SD folder
if(!SD_MMC.exists(path)) {
SerialPrintfln(ANSI_ESC_RED "SD_MMC/%s not exist", path);
return false;
Expand Down Expand Up @@ -2510,13 +2514,19 @@ void loop() {
dispHeader.updateItem("ALARM");
dispHeader.updateTime(rtc.gettime_s());
dispFooter.show();
showFileName("ALARM");
drawImage("/common/Alarm.jpg", _winLogo.x, _winLogo.y);
setTFTbrightness(_brightness);
SerialPrintfln(ANSI_ESC_MAGENTA "Alarm");
audioSetVolume(21);
muteChanged(false);
connecttoFS("/ring/alarm_clock.mp3");
if(_alarmMode == 1){ // alarm with bell
showFileName("ALARM");
drawImage("/common/Alarm.jpg", _winLogo.x, _winLogo.y);
setTFTbrightness(_brightness);
SerialPrintfln(ANSI_ESC_MAGENTA "Alarm");
audioSetVolume(21);
muteChanged(false);
connecttoFS("/ring/alarm_clock.mp3");
}
else{ // alarm without bell
_f_eof_alarm = true;
return;
}
}
if(_f_eof_alarm) { // AFTER RINGING
_f_eof_alarm = false;
Expand Down Expand Up @@ -3315,7 +3325,7 @@ void WEBSRV_onCommand(const String cmd, const String param, const String arg){

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

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

if(cmd == "getAlarmMode"){ webSrv.send("alarmMode=", String(_alarmMode, 10));
return;}

if(cmd == "setAlarmMode"){ _alarmMode = param.toInt();
if(_alarmMode == 0) SerialPrintfln("AlarmMode: " ANSI_ESC_YELLOW "with radio only");
if(_alarmMode == 1) SerialPrintfln("AlarmMode: " ANSI_ESC_YELLOW "with bell and radio");
return;}

if(cmd == "loadIRbuttons"){ loadIRbuttonsFromNVS(); // update IR buttons in ir.cpp
char buf[150];
uint8_t* buttons = ir.get_irButtons();
Expand Down Expand Up @@ -3661,8 +3679,8 @@ void graphicObjects_OnRelease(const char* name, releasedArg ra) {
if(strcmp(name, "btn_PL_prevFile") == 0) {return;}
if(strcmp(name, "btn_PL_nextFile") == 0) {return;}
if(strcmp(name, "btn_PL_ready") == 0) {_playerSubmenue = 1; SD_playFile(_curAudioFolder, _SD_content.getIndex(_cur_AudioFileNr)); changeState(PLAYER); showAudioFileNumber(); return;}
if(strcmp(name, "btn_PL_playAll") == 0) {_playerSubmenue = 1; _f_shuffle = false; preparePlaylistFromFolder(_curAudioFolder); processPlaylist(true); changeState(PLAYER); return;}
if(strcmp(name, "btn_PL_shuffle") == 0) {_playerSubmenue = 1; _f_shuffle = true; preparePlaylistFromFolder(_curAudioFolder); processPlaylist(true); changeState(PLAYER); return;}
if(strcmp(name, "btn_PL_playAll") == 0) {_playerSubmenue = 1; _f_shuffle = false; preparePlaylistFromSDFolder(_curAudioFolder); processPlaylist(true); changeState(PLAYER); return;}
if(strcmp(name, "btn_PL_shuffle") == 0) {_playerSubmenue = 1; _f_shuffle = true; preparePlaylistFromSDFolder(_curAudioFolder); processPlaylist(true); changeState(PLAYER); return;}
if(strcmp(name, "btn_PL_fileList") == 0) {_playerSubmenue = 1; _SD_content.listDir(_curAudioFolder, true, false); changeState(AUDIOFILESLIST); return;}
if(strcmp(name, "btn_PL_radio") == 0) {_playerSubmenue = 0; setStation(_cur_station); changeState(RADIO); return;}
}
Expand Down

0 comments on commit 81dabe5

Please sign in to comment.