Browse Source

alarmClock

main
Hendrik Langer 7 years ago
parent
commit
5dc5f18de8
  1. 30
      src/led.cpp
  2. 3
      src/led.h
  3. 22
      src/main.cpp
  4. 1
      src/main.h
  5. 19
      src/screen.cpp

30
src/led.cpp

@ -10,6 +10,7 @@ using namespace std;
Led::Led(void) { Led::Led(void) {
index = 0; index = 0;
duration = 0; duration = 0;
wakeupIndex = 0;
} }
void Led::loop_rainbow(void) { void Led::loop_rainbow(void) {
@ -35,6 +36,22 @@ void Led::loop_steady(void) {
fill_solid(leds, NUM_LEDS, color); fill_solid(leds, NUM_LEDS, color);
} }
void Led::loop_off(void) {
if (wakeupIndex == 0) {
fill_solid(leds, NUM_LEDS, CRGB::Black);
} else {
fill_solid(leds, NUM_LEDS, CRGB::White);
FastLED.setBrightness(wakeupIndex);
}
}
void Led::wakeUpLight(uint8_t i) {
fill_solid(leds, NUM_LEDS, CRGB::White);
FastLED.setBrightness(i);
Serial.printf("wakeuplight(%d)\n", i);
wakeupIndex = i;
}
void Led::changeAnimation(uint8_t num, uint16_t duration) { void Led::changeAnimation(uint8_t num, uint16_t duration) {
if (duration == 0) this->duration = UINT16_MAX; if (duration == 0) this->duration = UINT16_MAX;
else this->duration = duration; else this->duration = duration;
@ -42,6 +59,7 @@ void Led::changeAnimation(uint8_t num, uint16_t duration) {
else if (num == 1) refresh = &Led::loop_sweep; else if (num == 1) refresh = &Led::loop_sweep;
else if (num == 2) refresh = &Led::loop_confetti; else if (num == 2) refresh = &Led::loop_confetti;
else if (num == 3) refresh = &Led::loop_rainbow; else if (num == 3) refresh = &Led::loop_rainbow;
else if (num == 255) refresh = &Led::loop_off;
} }
void Led::changeColor(uint8_t r, uint8_t g, uint8_t b) { void Led::changeColor(uint8_t r, uint8_t g, uint8_t b) {
@ -68,10 +86,10 @@ void Led::setup(void) {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS); FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(96); FastLED.setBrightness(96);
FastLED.setCorrection(0xFF5050); FastLED.setCorrection(0xFF5050);
fill_solid(leds, NUM_LEDS, CRGB::White); fill_solid(leds, NUM_LEDS, CRGB::Black);
color = CRGB::Orange; color = CRGB::Orange;
refresh = &Led::loop_rainbow; refresh = &Led::loop_off;
delay(100); delay(100);
xTaskCreate( xTaskCreate(
&cTaskWrapper, /* Task function. */ &cTaskWrapper, /* Task function. */
@ -91,16 +109,16 @@ void Led::animationTask(void* parameters) {
// EVERY_N_MILLISECONDS ( 20) { index++; } // EVERY_N_MILLISECONDS ( 20) { index++; }
index++; index++;
if (duration == 0) { if (duration == 0) {
refresh = &Led::loop_rainbow; refresh = &Led::loop_off;
} else if (duration == UINT16_MAX) { } else if (duration == UINT16_MAX) {
} else { } else {
duration--; duration--;
} }
EVERY_N_SECONDS(30) { // EVERY_N_SECONDS(30) {
// FastLED.clear(); // FastLED.clear();
// delay(200); // delay(200);
changeAnimation(2, 2000); // changeAnimation(2, 2000);
} // }
} }
vTaskDelay(50 / portTICK_PERIOD_MS); vTaskDelay(50 / portTICK_PERIOD_MS);
} }

3
src/led.h

@ -16,6 +16,7 @@ class Led {
void changeColor(uint8_t, uint8_t, uint8_t); void changeColor(uint8_t, uint8_t, uint8_t);
void setBrightness(uint8_t); void setBrightness(uint8_t);
void stop(void); void stop(void);
void wakeUpLight(uint8_t);
private: private:
CRGB leds[NUM_LEDS]; CRGB leds[NUM_LEDS];
void animationTask(void*); void animationTask(void*);
@ -26,8 +27,10 @@ class Led {
void loop_rainbow(void); void loop_rainbow(void);
void loop_confetti(void); void loop_confetti(void);
void loop_sweep(void); void loop_sweep(void);
void loop_off(void);
uint16_t duration; uint16_t duration;
uint8_t index; uint8_t index;
uint8_t wakeupIndex;
CRGB color; CRGB color;
bool runTask; bool runTask;
}; };

22
src/main.cpp

@ -41,6 +41,7 @@ char timeStr[20];
char weatherStr[32]; char weatherStr[32];
RTC_DATA_ATTR static int boot_count = 0; RTC_DATA_ATTR static int boot_count = 0;
RTC_DATA_ATTR struct tm alarmTime; RTC_DATA_ATTR struct tm alarmTime;
RTC_DATA_ATTR bool alarmArmed = false;
//Create a new Basecamp instance called iot //Create a new Basecamp instance called iot
Basecamp iot; Basecamp iot;
@ -112,7 +113,7 @@ void setup() {
if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER) { if (wakeup_reason == ESP_SLEEP_WAKEUP_TIMER) {
double seconds = difftime(now, mktime(&alarmTime)); double seconds = difftime(now, mktime(&alarmTime));
Serial.printf("seconds to alarm: %f\n", seconds); Serial.printf("alarm in %f seconds\n", seconds);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime); strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime);
Serial.print(" Alarm time: "); Serial.println(strftime_buf); Serial.print(" Alarm time: "); Serial.println(strftime_buf);
@ -226,11 +227,16 @@ void suspend() {
void setAlarmTime(struct tm time) { void setAlarmTime(struct tm time) {
alarmTime = time; alarmTime = time;
alarmArmed = true;
char strftime_buf[64]; char strftime_buf[64];
strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime); strftime(strftime_buf, sizeof(strftime_buf), "%c", &alarmTime);
Serial.print("Setting Alarm time: "); Serial.println(strftime_buf); Serial.print("Setting Alarm time: "); Serial.println(strftime_buf);
} }
struct tm getAlarmTime() {
return alarmTime;
}
void obtain_time(void) { void obtain_time(void) {
sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setoperatingmode(SNTP_OPMODE_POLL);
@ -271,6 +277,20 @@ void loop()
time(&now); time(&now);
localtime_r(&now, &timeinfo); localtime_r(&now, &timeinfo);
double seconds = difftime(now, mktime(&alarmTime));
Serial.printf("alarm in %f seconds (%d)\n", seconds, alarmArmed);
if (seconds >= 0 && alarmArmed) {
alarmArmed = false;
led.wakeUpLight(0);
Serial.println("WAKEUP TIME!!!!!");
mp3.setVolume(2);
mp3.start();
led.changeAnimation(2, 0);
}
if (seconds >= -5*60 && seconds <= 0) {
led.wakeUpLight(255*(seconds+300)/300);
}
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());

1
src/main.h

@ -6,6 +6,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
void suspend(uint32_t secondsToSleep); void suspend(uint32_t secondsToSleep);
void suspend(); void suspend();
void setAlarmTime(struct tm time); void setAlarmTime(struct tm time);
struct tm getAlarmTime();
void loop(); void loop();
void rotation(int i, int direction, int buttonPressed); void rotation(int i, int direction, int buttonPressed);
void obtain_time(void); void obtain_time(void);

19
src/screen.cpp

@ -76,8 +76,10 @@ uint8_t MainMenu::select() {
case 0: case 0:
if (mp3.playing) { if (mp3.playing) {
mp3.stop(); mp3.stop();
led.changeAnimation(255, 0);
} else { } else {
mp3.start(); mp3.start();
led.changeAnimation(2, 0);
} }
break; break;
case 1: case 1:
@ -131,39 +133,51 @@ 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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
led.changeAnimation(2, 0);
break; break;
case 12: case 12:
menuChange = eMainMenu; menuChange = eMainMenu;
@ -281,9 +295,13 @@ void MainScreen::previous() {
} }
AlarmClockScreen::AlarmClockScreen() { AlarmClockScreen::AlarmClockScreen() {
if (getAlarmTime().tm_year < (2016 - 1900)) {
time_t now; time_t now;
time(&now); time(&now);
localtime_r(&now, &alarmTime); localtime_r(&now, &alarmTime);
} else {
alarmTime = getAlarmTime();
}
} }
void AlarmClockScreen::draw() { void AlarmClockScreen::draw() {
@ -332,6 +350,7 @@ void AlarmClockScreen::previous() {
uint8_t AlarmClockScreen::select() { uint8_t AlarmClockScreen::select() {
time_t now; time_t now;
time(&now); time(&now);
alarmTime.tm_sec = 0;
while(difftime(now, mktime(&alarmTime)) >= 0) alarmTime.tm_mday++; while(difftime(now, mktime(&alarmTime)) >= 0) alarmTime.tm_mday++;
setAlarmTime(alarmTime); setAlarmTime(alarmTime);
menuChange = eMainScreen; menuChange = eMainScreen;

Loading…
Cancel
Save