add duration to custompage

This commit is contained in:
Stephan Mühl
2023-04-01 18:32:20 +02:00
parent 01cf81397f
commit 058e9d1ba8
18 changed files with 234 additions and 425 deletions

View File

@@ -29,8 +29,16 @@
#ifdef ULANZI
Adafruit_SHT31 sht31;
#else
class Mp3Notify
{
};
Adafruit_BME280 bme280;
SoftwareSerial mySoftwareSerial(D7, D5); // RX, TX
typedef DFMiniMp3<SoftwareSerial, Mp3Notify> DfMp3;
DfMp3 dfmp3(mySoftwareSerial);
#endif
EasyButton button_left(BUTTON_UP_PIN);
EasyButton button_right(BUTTON_DOWN_PIN);
EasyButton button_select(BUTTON_SELECT_PIN);
@@ -59,6 +67,11 @@ float sampleSum = 0.0;
float sampleAverage = 0.0;
float brightnessPercent = 0.0;
#ifdef awrtrix_upgrade
class Mp3Notify;
SoftwareSerial mySoftwareSerial(D7, D5); // RX, TX
#endif
// The getter for the instantiated singleton instance
PeripheryManager_ &PeripheryManager_::getInstance()
{
@@ -71,14 +84,36 @@ PeripheryManager_ &PeripheryManager = PeripheryManager.getInstance();
void left_button_pressed()
{
DisplayManager.leftButton();
MenuManager.leftButton();
if (AP_MODE)
{
--MATRIX_LAYOUT;
if (MATRIX_LAYOUT < 0)
MATRIX_LAYOUT = 2;
saveSettings();
ESP.restart();
}
else
{
DisplayManager.leftButton();
MenuManager.leftButton();
}
}
void right_button_pressed()
{
DisplayManager.rightButton();
MenuManager.rightButton();
if (AP_MODE)
{
++MATRIX_LAYOUT;
if (MATRIX_LAYOUT > 2)
MATRIX_LAYOUT = 0;
saveSettings();
ESP.restart();
}
else
{
DisplayManager.rightButton();
MenuManager.rightButton();
}
}
void select_button_pressed()
@@ -111,35 +146,61 @@ void PeripheryManager_::playBootSound()
return;
if (BOOT_SOUND == "")
{
#ifdef ULANZI
const int nNotes = 6;
String notes[nNotes] = {"E5", "C5", "G4", "E4", "G4", "C5"};
const int timeUnit = 150;
Melody melody = MelodyFactory.load("Bootsound", timeUnit, notes, nNotes);
player.playAsync(melody);
#else
// no standardsound
#endif
}
else
{
#ifdef ULANZI
playFromFile("/MELODIES/" + BOOT_SOUND + ".txt");
#else
dfmp3.playMp3FolderTrack(BOOT_SOUND.toInt());
#endif
}
}
void PeripheryManager_::stopSound()
{
#ifdef ULANZI
player.stop();
#else
dfmp3.stop();
#endif
}
void PeripheryManager_::setVolume(uint8_t vol)
{
#ifdef AWTRIX_UPGRADE
dfmp3.setVolume(vol);
#endif
}
void PeripheryManager_::playFromFile(String file)
{
if (!SOUND_ACTIVE)
return;
#ifdef ULANZI
Melody melody = MelodyFactory.loadRtttlFile(file);
player.playAsync(melody);
#else
dfmp3.playMp3FolderTrack(file.toInt());
#endif
}
bool PeripheryManager_::isPlaying()
{
#ifdef ULANZI
return player.isPlaying();
#else
return false;
#endif
}
void fistStart()
@@ -152,7 +213,7 @@ void fistStart()
CURRENT_TEMP -= 9.0;
#else
CURRENT_TEMP = bme280.readTemperature();
CURRENT_HUM = 0;
CURRENT_HUM = bme280.readHumidity();
#endif
uint16_t LDRVALUE = analogRead(LDR_PIN);
@@ -180,6 +241,7 @@ void PeripheryManager_::setup()
sht31.begin(0x44);
#else
bme280.begin();
dfmp3.begin();
#endif
photocell.setPhotocellPositionOnGround(false);
fistStart();
@@ -300,7 +362,6 @@ void PeripheryManager_::checkAlarms()
}
}
const char *PeripheryManager_::readUptime()
{
static char uptime[25]; // Make the array static to keep it from being destroyed when the function returns