|
|
@ -60,9 +60,9 @@ MainMenu::MainMenu() { |
|
|
|
string_list = { |
|
|
|
"PLAY", |
|
|
|
"Radio Stations", |
|
|
|
"Toggle Light", |
|
|
|
"Test2", |
|
|
|
"AlarmClock", |
|
|
|
"Toggle Light", |
|
|
|
"Wohnzimmer L", |
|
|
|
"SLEEP", |
|
|
|
"\xAB Return"}; |
|
|
|
if (mp3.playing) { |
|
|
@ -71,7 +71,6 @@ MainMenu::MainMenu() { |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t MainMenu::select() { |
|
|
|
String topic = "esp32-node/cmd/" + iot.hostname + "/button"; |
|
|
|
switch (current_pos) { |
|
|
|
case 0: |
|
|
|
if (mp3.playing) { |
|
|
@ -87,13 +86,15 @@ uint8_t MainMenu::select() { |
|
|
|
return current_pos; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
iot.mqtt.publish(topic.c_str(), 0, false, "light" ); |
|
|
|
menuChange = eAlarmClockScreen; |
|
|
|
return current_pos; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
iot.mqtt.publish(topic.c_str(), 0, false, "test2" ); |
|
|
|
if (!led.isOn()) led.changeAnimation(3, 0); |
|
|
|
else led.changeAnimation(255, 0); |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
menuChange = eAlarmClockScreen; |
|
|
|
menuChange = eLightScreen; |
|
|
|
return current_pos; |
|
|
|
break; |
|
|
|
case 5: |
|
|
@ -371,3 +372,62 @@ uint8_t AlarmClockScreen::select() { |
|
|
|
void SuspendScreen::draw() { |
|
|
|
suspend(30); |
|
|
|
} |
|
|
|
|
|
|
|
LightScreen::LightScreen() { |
|
|
|
brightness = 50; |
|
|
|
} |
|
|
|
|
|
|
|
void LightScreen::draw() { |
|
|
|
uint8_t header_height = 12; |
|
|
|
u8g2.clearBuffer(); |
|
|
|
|
|
|
|
/* draw Title */ |
|
|
|
u8g2.setFont(u8g2_font_inb19_mf); |
|
|
|
u8g2.drawStr(15, 20, "Brightness"); |
|
|
|
|
|
|
|
u8g2.drawRBox(10, 28, 108, 22, 5); |
|
|
|
u8g2.setDrawColor(0); |
|
|
|
uint32_t percent = (uint32_t)brightness*100 / 255; |
|
|
|
u8g2.drawBox(14+percent, 31, 100-percent, 16); |
|
|
|
char valueStr[6]; |
|
|
|
sprintf(valueStr, "%3d", brightness); |
|
|
|
u8g2.setFont(u8g2_font_profont17_mf); |
|
|
|
u8g2.setFontMode(1); |
|
|
|
u8g2.setDrawColor(2); |
|
|
|
u8g2.drawStr(40, 45, valueStr); |
|
|
|
u8g2.setFontMode(0); |
|
|
|
u8g2.setDrawColor(1); |
|
|
|
|
|
|
|
u8g2.sendBuffer(); // transfer internal memory to the display
|
|
|
|
} |
|
|
|
|
|
|
|
void LightScreen::next() { |
|
|
|
if (millis() - lastRotary <= 40) brightness+=20; |
|
|
|
else if (millis() - lastRotary <= 80) brightness+=5; |
|
|
|
else brightness++; |
|
|
|
if (brightness > 255) brightness = 255; |
|
|
|
lastRotary = millis(); |
|
|
|
} |
|
|
|
|
|
|
|
void LightScreen::previous() { |
|
|
|
if (millis() - lastRotary <= 40) brightness-=20; |
|
|
|
else if (millis() - lastRotary <= 80) brightness-=5; |
|
|
|
else brightness--; |
|
|
|
if (brightness < 0) brightness = 0; |
|
|
|
lastRotary = millis(); |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t LightScreen::select() { |
|
|
|
String topic = "esp32-node/cmd/" + iot.hostname + "/button"; |
|
|
|
|
|
|
|
StaticJsonBuffer<200> jsonBuffer; |
|
|
|
JsonObject& root = jsonBuffer.createObject(); |
|
|
|
root["brightness"] = brightness; |
|
|
|
root["light"] = brightness > 0 ? "ON" : "OFF"; |
|
|
|
|
|
|
|
char publishBuf[root.measureLength()+1]; |
|
|
|
root.printTo(publishBuf, sizeof(publishBuf)); |
|
|
|
iot.mqtt.publish(topic.c_str(), 0, false, publishBuf ); |
|
|
|
|
|
|
|
menuChange = eMainScreen; |
|
|
|
} |
|
|
|