Skip to content

Commit

Permalink
added screensaver feature and cmd (pr3y#64), fixed mp3 playback
Browse files Browse the repository at this point in the history
  • Loading branch information
eadmaster committed Jul 19, 2024
1 parent 6c977d6 commit 3ea8617
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 10 deletions.
38 changes: 38 additions & 0 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void loopOptions(const std::vector<std::pair<std::string, std::function<void()>>
int index = 0;
while(1){
if (redraw) {
reset_screensaver_timer();
if(submenu) drawSubmenu(index, options, subText);
else drawOptions(index, options, FGCOLOR, BGCOLOR);
if(bright){
Expand Down Expand Up @@ -489,3 +490,40 @@ void drawOther(int x, int y) {
tft.drawArc(40+x,40+y,32,29,240,360,FGCOLOR,BGCOLOR);
}


esp_timer_handle_t screensaver_timer;

static void screensaver_timer_callback(void* arg) {
// turn off TFT backlight
analogWrite(BACKLIGHT, 0);
// TODO: add an option to show a big clock instead
}

void init_screensaver_timer() {
// setup screensaver timer
const esp_timer_create_args_t screensaver_timer_args = {
.callback = &screensaver_timer_callback,
/* argument specified here will be passed to timer callback function */
.arg = (void*) screensaver_timer,
/* name is optional, but may help identify the timer when debugging */
.name = "screensaver"
};
esp_timer_create(&screensaver_timer_args, &screensaver_timer);
esp_timer_start_once(screensaver_timer, 1000000 * SCREENSAVER_TIMEOUT_IN_SECONDS); // timer timeout, in microseconds relative to the current moment

}

void reset_screensaver_timer() {
// if a key was pressed in prev loop
if(esp_timer_is_active(screensaver_timer)) {
// screen is already on, reset the screensaver timer
//MISSING IN OLD SDK: esp_timer_restart(screensaver_timer, 1000000 * SCREENSAVER_TIMEOUT_IN_SECONDS) // Restart a currently running timer.
esp_timer_stop(screensaver_timer);
} else {
// screen is off, reinit brightness
getBrightness();
}
//else
esp_timer_start_once(screensaver_timer, 1000000 * SCREENSAVER_TIMEOUT_IN_SECONDS); // restart a stopped/not running timer

}
8 changes: 8 additions & 0 deletions src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

void initDisplay(int i = 0); // Início da função e mostra bootscreen


#include "esp_timer.h"
const int SCREENSAVER_TIMEOUT_IN_SECONDS = 60;
extern esp_timer_handle_t screensaver_timer;
void init_screensaver_timer();
void reset_screensaver_timer();


//Funções para economizar linhas nas outras funções
void resetTftDisplay(int x = 0, int y = 0, uint16_t fc = FGCOLOR, int size = FM, uint16_t bg = BGCOLOR, uint16_t screen = BGCOLOR);
void setTftDisplay(int x = 0, int y = 0, uint16_t fc = tft.textcolor, int size = tft.textsize, uint16_t bg = tft.textbgcolor);
Expand Down
1 change: 1 addition & 0 deletions src/evil_portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) {
redraw=true;
while(1) {
if(redraw) {
reset_screensaver_timer();
drawMainBorder();

tft.setTextSize(FM);
Expand Down
8 changes: 5 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ void setup() {
#if defined(BACKLIGHT)
pinMode(BACKLIGHT, OUTPUT);
#endif


init_screensaver_timer();
getBrightness();
gsetIrTxPin();
gsetIrRxPin();
Expand Down Expand Up @@ -184,13 +185,14 @@ void loop() {
tft.fillScreen(BGCOLOR); //fix any problem with the mainMenu screen when coming back from submenus or functions
redraw=true;
}

if (redraw) {
reset_screensaver_timer();
drawMainMenu(index);
redraw = false;
delay(200);
}

if(checkPrevPress()) {
if(index==0) index = opt - 1;
else if(index>0) index--;
Expand Down
1 change: 1 addition & 0 deletions src/sd_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ String loopSD(FS &fs, bool filePicker) {
if(returnToMenu) break; // stop this loop and retur to the previous loop

if(redraw) {
reset_screensaver_timer();
if(strcmp(PreFolder.c_str(),Folder.c_str()) != 0 || reload){
index=0;
readFs(fs, Folder, fileList);
Expand Down
35 changes: 28 additions & 7 deletions src/serialcmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <ESP8266Audio.h>
#include <ESP8266SAM.h>
#include "sd_functions.h"
#include "settings.h"
#include "display.h"


void SerialPrintHexString(uint64_t val) {
Expand Down Expand Up @@ -219,7 +221,7 @@ void handleSerialCommands() {
source = new AudioFileSourcePROGMEM( song.c_str(), song.length() );
} else if(song.indexOf(".") != -1) {
// try to open "song" as a file
// e.g. music_player music/Axel-F.txt
// e.g. music_player audio/Axel-F.txt
if(!song.startsWith("/")) song = "/" + song; // add "/" if missing
// try opening on SD
//if(setupSdCard()) source = new AudioFileSourceFS(SD, song.c_str());
Expand All @@ -236,21 +238,25 @@ void handleSerialCommands() {
// switch on extension
song.toLowerCase(); // case-insensitive match
if(song.endsWith(".txt") || song.endsWith(".rtttl")) generator = new AudioGeneratorRTTTL();
/*
/* 2FIX: compilation issues
if(song.endsWith(".mid")) {
// need to load a soundfont
AudioFileSource* sf2 = NULL;
if(setupSdCard()) sf2 = new AudioFileSourceFS(SD, "1mgm.sf2"); // TODO: make configurable
if(!sf2) sf2 = new AudioFileSourceFS(LittleFS, "1mgm.sf2"); // TODO: make configurable
if(setupSdCard()) sf2 = new AudioFileSourceSD("audio/1mgm.sf2"); // TODO: make configurable
if(!sf2) sf2 = new AudioFileSourceLittleFS("audio/1mgm.sf2"); // TODO: make configurable
if(sf2) {
// a soundfount was found
generator = new AudioGeneratorMIDI();
AudioGeneratorMIDI* midi = new AudioGeneratorMIDI();
generator->SetSoundfont(sf2);
generator = midi;
}
}*/
if(song.endsWith(".wav")) generator = new AudioGeneratorWAV();
if(song.endsWith(".mod")) generator = new AudioGeneratorMOD();
if(song.endsWith(".mp3")) generator = new AudioGeneratorMP3();
if(song.endsWith(".mp3")) {
generator = new AudioGeneratorMP3();
source = new AudioFileSourceID3(source);
}
if(song.endsWith(".opus")) generator = new AudioGeneratorOpus();
// TODO: more formats
}
Expand All @@ -266,7 +272,10 @@ void handleSerialCommands() {
}*/

//TODO: tone
// https://github.com/earlephilhower/ESP8266Audio/blob/master/examples/PlayWAVFromFunction/PlayWAVFromFunction.ino
// https://github.com/earlephilhower/ESP8266Audio/issues/643

//TODO: webradio
// https://github.com/earlephilhower/ESP8266Audio/tree/master/examples/WebRadio

if(cmd_str.startsWith("tts " ) || cmd_str.startsWith("say " )) {
// https://github.com/earlephilhower/ESP8266SAM/blob/master/examples/Speak/Speak.ino
Expand All @@ -292,6 +301,18 @@ void handleSerialCommands() {
// https://github.com/earlephilhower/ESP8266Audio/issues/70
// https://github.com/earlephilhower/ESP8266Audio/pull/118

if(cmd_str.startsWith("lcd " ) || cmd_str.startsWith("tft" ) ) {
String new_status = cmd_str.substring(strlen("lcd "), cmd_str.length());
if(new_status=="off") {
analogWrite(BACKLIGHT, 0);
esp_timer_stop(screensaver_timer);
} else if(new_status=="on") {
getBrightness(); // reinit brightness
reset_screensaver_timer();
}
return;
}

Serial.println("unsupported serial command: " + cmd_str);


Expand Down

0 comments on commit 3ea8617

Please sign in to comment.