#include "screen.h" void Screen::next() { Serial.println("unhandled next"); } void Screen::previous() { Serial.println("unhandled previous"); } uint8_t Screen::select() { Serial.println("unhandled select"); } SelectionList::SelectionList() {} SelectionList::SelectionList(const char* title, uint8_t start_pos, const char* string_list) {} void SelectionList::draw() { uint8_t item_x_offset = 15; uint8_t header_height = 12; uint8_t item_height = 12; uint8_t num_active_item = current_pos - top_item; u8g2.clearBuffer(); /* draw Title */ u8g2.setFont(u8g2_font_guildenstern_nbp_tr); u8g2.drawUTF8(2,header_height-2,title); u8g2.drawLine(0,header_height,u8g2.getDisplayWidth(),header_height); /* draw menu items */ u8g2.setFont(u8g2_font_9x18B_tr); int length = std::min(visible, (uint8_t)string_list.size()); for (int i=0; i top_item+length-1) top_item++; } void SelectionList::previous() { if (current_pos > 0 ) current_pos--; if (current_pos < top_item) top_item--; } uint8_t SelectionList::select() { switch (current_pos) { // case 0: // break; default: Serial.println("unknown entry selected"); break; } menuChange = eMainScreen; return current_pos; } MainMenu::MainMenu() { string_list = { "PLAY", "80s Planet", "Left Coast 70s", "laradio Ska", "French Quarter Jams", "test", "test3", "Radio Kol Yavne", "ROCKIN626.COM", "Jive Time Radio", "Live Ireland", "Ye Ol Celtic Pub", "Gone Country - NZCMR", "Return"}; if (mp3.playing) { string_list[0] = "STOP"; } } uint8_t MainMenu::select() { String topic = "esp32-node/stat/" + iot.hostname + "/blabla"; switch (current_pos) { case 0: if (mp3.playing) { mp3.stop(); } else { mp3.start(); } break; case 1: mp3.start("http://streaming.shoutcast.com/80sPlanet?lang=en-US"); break; case 2: mp3.start("http://ice1.somafm.com/seventies-128-mp3"); break; case 3: mp3.start("http://streaming.radionomy.com/laradiostrong?lang=de"); break; case 4: mp3.start("http://184.171.163.20:8162/stream"); break; case 5: iot.mqtt.publish(topic.c_str(), 1, true, "test" ); case 6: iot.mqtt.publish(topic.c_str(), 1, true, "foo" ); case 7: mp3.start("http://212.83.129.92:8028/;?type=http&nocache=683"); break; case 8: mp3.start("http://192.99.4.210:3574/stream"); break; case 9: mp3.start("http://188.165.192.5:8279/stream?icy=http"); break; case 10: mp3.start("http://69.167.190.234:8080/stream"); break; case 11: mp3.start("http://192.240.102.133:11790/stream"); break; case 12: mp3.start("http://192.99.41.102:5044/stream"); break; default: Serial.println("unknown entry selected"); break; } menuChange = eMainScreen; return current_pos; } namespace { /* anonymous namespace for helper functions */ } void MainScreen::draw() { u8g2.clearBuffer(); // clear the internal memory if(millis() - lastVolumeChange <= 1000) { //u8g2.drawXBMP(0,0, IMG_1872_width, IMG_1872_height, IMG_1872_bits); u8g2.setFont(u8g2_font_inb19_mf); u8g2.drawStr(20, 20, "Volume"); u8g2.drawRBox(10, 28, 108, 22, 5); u8g2.setDrawColor(0); u8g2.drawBox(14+volume, 31, 100-volume, 14); char volumeStr[6]; sprintf(volumeStr, "%d %%", volume); u8g2.setFont(u8g2_font_crox3cb_mf); u8g2.setFontMode(1); u8g2.setDrawColor(2); u8g2.drawStr(40, 45, volumeStr); u8g2.setFontMode(0); u8g2.setDrawColor(1); } else { u8g2.setFont(u8g2_font_inb19_mf); u8g2.drawStr(0, 20, timeStr); char weather[32]; u8g2.setFont(u8g2_font_profont12_mf); // choose a suitable font sprintf(weather, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); u8g2.drawUTF8(0, 30, weather); u8g2.setFont(u8g2_font_prospero_bold_nbp_tf); // choose a suitable font u8g2_uint_t width = u8g2.getUTF8Width(titleStr); // calculate the pixel width of the text // repeated drawing of the scrolling text... u8g2.drawUTF8(titleStr_offset, 54, titleStr); // draw the scolling text titleStr_offset-=4; // scroll by one pixel if ( (u8g2_uint_t)titleStr_offset < (u8g2_uint_t)-width ) titleStr_offset = 0; // start over again // u8g2.getDisplayWidth() } u8g2.sendBuffer(); // bme280.printValues(); } uint8_t MainScreen::select() { menuChange = eMainMenu; } void MainScreen::next() { if (volume < 100) volume++; lastVolumeChange = millis(); mp3.setVolume(volume); Serial.printf("volume: %d\n", volume); } void MainScreen::previous() { if (volume > 0) volume--; lastVolumeChange = millis(); mp3.setVolume(volume); Serial.printf("volume: %d\n", volume); }