Browse Source

suspend

main
Hendrik Langer 7 years ago
parent
commit
090abfe6d3
  1. 28
      src/main.cpp
  2. 2
      src/mp3.cpp
  3. 16
      src/screen.cpp

28
src/main.cpp

@ -118,6 +118,7 @@ void setup() {
Serial.print(" Alarm time: "); Serial.println(strftime_buf); Serial.print(" Alarm time: "); Serial.println(strftime_buf);
if (-seconds > secondsToSleep) suspend(); if (-seconds > secondsToSleep) suspend();
else if (-seconds > 5*60) suspend(5*60);
} }
u8g2.begin(); u8g2.begin();
@ -160,6 +161,7 @@ void setup() {
mp3.begin(); mp3.begin();
led.setup(); led.setup();
lastButtonPress = millis();
rotary.registerCallback(rotation); rotary.registerCallback(rotation);
rotary.begin(rotaryPinA, rotaryPinB, rotaryPinButton); rotary.begin(rotaryPinA, rotaryPinB, rotaryPinButton);
} }
@ -205,6 +207,15 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
void suspend(uint32_t secondsToSleep) { void suspend(uint32_t secondsToSleep) {
DEBUG_PRINTLN("Entering deep sleep"); DEBUG_PRINTLN("Entering deep sleep");
mp3.stop();
led.stop();
delay(1000);
u8g2.setPowerSave(1);
//properly disconnect from the MQTT broker
iot.mqtt.disconnect();
esp_sleep_enable_timer_wakeup(1000000LL * secondsToSleep); esp_sleep_enable_timer_wakeup(1000000LL * secondsToSleep);
const uint64_t ext_wakeup_rotarybtn_mask = 1ULL << rotaryPinButton; const uint64_t ext_wakeup_rotarybtn_mask = 1ULL << rotaryPinButton;
esp_sleep_enable_ext1_wakeup(ext_wakeup_rotarybtn_mask, ESP_EXT1_WAKEUP_ANY_HIGH); esp_sleep_enable_ext1_wakeup(ext_wakeup_rotarybtn_mask, ESP_EXT1_WAKEUP_ANY_HIGH);
@ -215,14 +226,17 @@ void suspend(uint32_t secondsToSleep) {
//// esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, ESP_EXT1_WAKEUP_ANY_HIGH); //// esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, ESP_EXT1_WAKEUP_ANY_HIGH);
// //
////esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); // power down all peripherals ////esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); // power down all peripherals
//properly disconnect from the MQTT broker
iot.mqtt.disconnect();
//send the ESP into deep sleep //send the ESP into deep sleep
esp_deep_sleep_start(); esp_deep_sleep_start();
} }
void suspend() { void suspend() {
suspend(secondsToSleep); time_t now;
time(&now);
double seconds = difftime(now, mktime(&alarmTime));
if (-seconds > secondsToSleep) suspend(secondsToSleep);
else if (-seconds > 5*60) suspend(5*60);
} }
void setAlarmTime(struct tm time) { void setAlarmTime(struct tm time) {
@ -284,13 +298,17 @@ void loop()
led.wakeUpLight(0); led.wakeUpLight(0);
Serial.println("WAKEUP TIME!!!!!"); Serial.println("WAKEUP TIME!!!!!");
mp3.setVolume(2); mp3.setVolume(2);
mp3.start(); mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3");
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
} }
if (seconds >= -5*60 && seconds <= 0) { if (alarmArmed && seconds >= -5*60 && seconds <= 0) {
led.wakeUpLight(255*(seconds+300)/300); led.wakeUpLight(255*(seconds+300)/300);
} }
bool stayAwake = false;
if (alarmArmed && seconds >= -2*5*60) stayAwake = true;
if (!mp3.playing && millis() - lastButtonPress >= 60*1000 && !stayAwake) suspend();
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo); strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo);
sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure());

2
src/mp3.cpp

@ -95,7 +95,7 @@ void MP3::mp3_decoder_task(void *pvParameters) {
AudioOutputI2S *out = nullptr; AudioOutputI2S *out = nullptr;
strcpy(titleStr, "loading..."); // strcpy(titleStr, "loading...");
file = new AudioFileSourceICYStream(URL); file = new AudioFileSourceICYStream(URL);
file->RegisterMetadataCB(MDCallback, (void*)"ICY"); file->RegisterMetadataCB(MDCallback, (void*)"ICY");
buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize); buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize);

16
src/screen.cpp

@ -133,50 +133,62 @@ uint8_t StationMenu::select() {
switch (current_pos) { switch (current_pos) {
case 0: case 0:
mp3.start("http://streaming.shoutcast.com/80sPlanet?lang=en-US"); mp3.start("http://streaming.shoutcast.com/80sPlanet?lang=en-US");
strcpy(titleStr, string_list[0].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 1: case 1:
mp3.start("http://ice1.somafm.com/seventies-128-mp3"); mp3.start("http://ice1.somafm.com/seventies-128-mp3");
strcpy(titleStr, string_list[1].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 2: case 2:
mp3.start("http://streaming.radionomy.com/laradiostrong?lang=de"); mp3.start("http://streaming.radionomy.com/laradiostrong?lang=de");
strcpy(titleStr, string_list[2].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 3: case 3:
mp3.start("http://184.171.163.20:8162/stream"); mp3.start("http://184.171.163.20:8162/stream");
strcpy(titleStr, string_list[3].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 4: case 4:
mp3.start("http://212.83.129.92:8028/;?type=http&nocache=683"); mp3.start("http://212.83.129.92:8028/;?type=http&nocache=683");
strcpy(titleStr, string_list[4].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 5: case 5:
mp3.start("http://192.99.4.210:3574/stream"); mp3.start("http://192.99.4.210:3574/stream");
strcpy(titleStr, string_list[5].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 6: case 6:
mp3.start("http://188.165.192.5:8279/stream?icy=http"); mp3.start("http://188.165.192.5:8279/stream?icy=http");
strcpy(titleStr, string_list[6].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 7: case 7:
mp3.start("http://69.167.190.234:8080/stream"); mp3.start("http://69.167.190.234:8080/stream");
strcpy(titleStr, string_list[7].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 8: case 8:
mp3.start("http://192.240.102.133:11790/stream"); mp3.start("http://192.240.102.133:11790/stream");
strcpy(titleStr, string_list[8].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 9: case 9:
mp3.start("http://192.99.41.102:5044/stream"); mp3.start("http://192.99.41.102:5044/stream");
strcpy(titleStr, string_list[9].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 10: case 10:
mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3"); mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3");
strcpy(titleStr, string_list[10].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 11: case 11:
mp3.start("http://172.16.75.17:8000/mopidy"); mp3.start("http://172.16.75.17:8000/mopidy");
strcpy(titleStr, string_list[11].c_str());
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
break; break;
case 12: case 12:
@ -357,9 +369,5 @@ uint8_t AlarmClockScreen::select() {
} }
void SuspendScreen::draw() { void SuspendScreen::draw() {
mp3.stop();
led.stop();
delay(1000);
u8g2.setPowerSave(1);
suspend(30); suspend(30);
} }

Loading…
Cancel
Save