diff --git a/src/main.cpp b/src/main.cpp index 3b1a52d..c05b364 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ #include "rotary.h" #include "screen.h" -U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16); +U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 15, /* data=*/ 4); //Create a new Basecamp instance called iot Basecamp iot; @@ -62,6 +62,7 @@ Basecamp iot; WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "de.pool.ntp.org", 3600, 60000); char timeStr[20]; +char weatherStr[32]; BME280 bme280; MP3 mp3; @@ -70,6 +71,7 @@ Screen* screen; menuType menuChange = eNone; uint32_t lastButtonPress = 0; +uint32_t lastUpdate = 0; //Variables for the sensor and the battery static const int buttonPin = 0; @@ -283,17 +285,24 @@ void rotation(int i, int direction, int buttonPressed) { void loop() { - timeClient.update(); - timeClient.getFormattedTime().toCharArray(timeStr, 50); + if(millis() - lastUpdate >= 1000) { + lastUpdate = millis(); + timeClient.update(); + timeClient.getFormattedTime().toCharArray(timeStr, 50); + + sprintf(weatherStr, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); + } if (menuChange != eNone) { delete screen; if (menuChange == eMainScreen) screen = new MainScreen(); - if (menuChange == eMainMenu) screen = new MainMenu(); + else if (menuChange == eMainMenu) screen = new MainMenu(); + else if (menuChange == eStationMenu) screen = new StationMenu(); + else screen = new MainScreen(); menuChange = eNone; } screen->draw(); - delay(200); + delay(100); } diff --git a/src/screen.cpp b/src/screen.cpp index 3032732..a4e3d91 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -22,7 +22,7 @@ void SelectionList::draw() { u8g2.drawLine(0,header_height,u8g2.getDisplayWidth(),header_height); /* draw menu items */ - u8g2.setFont(u8g2_font_9x18B_tr); + u8g2.setFont(u8g2_font_8x13B_tr); int length = std::min(visible, (uint8_t)string_list.size()); for (int i=0; i u8g2.getDisplayWidth()) { + u8g2_uint_t x = titleStr_offset; + do { // repeated drawing of the scrolling text... + u8g2.drawUTF8(x, 54, titleStr); // draw the scolling text + x += width; // add the pixel width of the scrolling text + } while( x < u8g2.getDisplayWidth() ); // draw again until the complete display is filled + // 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() + titleStr_offset-=4; // scroll by one pixel + if ( (u8g2_uint_t)titleStr_offset < (u8g2_uint_t)-width ) + titleStr_offset = 0; // start over again + } else { + u8g2.drawUTF8((u8g2.getDisplayWidth()-width)/2, 54, titleStr); + } } u8g2.sendBuffer(); // bme280.printValues(); diff --git a/src/screen.h b/src/screen.h index 8271cbe..76c552f 100644 --- a/src/screen.h +++ b/src/screen.h @@ -20,10 +20,11 @@ #include "BME280.h" #include "image.h" -enum menuType { eNone=0, eMainScreen, eMainMenu }; +enum menuType { eNone=0, eMainScreen, eMainMenu, eStationMenu }; -extern U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2; +extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2; extern char timeStr[]; +extern char weatherStr[]; extern BME280 bme280; extern MP3 mp3; extern menuType menuChange; @@ -67,13 +68,6 @@ class SelectionList : public Screen { uint8_t visible = 4; }; -class MainMenu : public SelectionList { - public: - MainMenu(); - uint8_t select(void) override; - private: -}; - class MainScreen : public Screen { public: void draw(void) override; @@ -87,4 +81,18 @@ class MainScreen : public Screen { uint8_t volume = 20; }; +class MainMenu : public SelectionList { + public: + MainMenu(); + uint8_t select(void) override; + private: +}; + +class StationMenu : public SelectionList { + public: + StationMenu(); + uint8_t select(void) override; + private: +}; + #endif /* _SCREEN_H */