From be6670b982893936ccfd415c9a1ad719b53cf751 Mon Sep 17 00:00:00 2001 From: jarnokie Date: Mon, 22 Jun 2026 17:29:41 +0300 Subject: [PATCH] Just as a test, added a third screen with graphics. --- docs/hardware-notes.md | 13 ------------- include/screens.h | 10 ++++++++++ src/carousel.cpp | 6 +++--- src/main.cpp | 29 +++++++++------------------- src/screens.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 36 deletions(-) create mode 100644 include/screens.h create mode 100644 src/screens.cpp diff --git a/docs/hardware-notes.md b/docs/hardware-notes.md index 63454fc..7bebd2c 100644 --- a/docs/hardware-notes.md +++ b/docs/hardware-notes.md @@ -69,16 +69,3 @@ The physical wiring is already assembled. Current documented wiring is: ## Ground All component ground pins are connected to common `GND`. - -## Assumptions To Verify Later - -- The SH1106 module is compatible with the MKR1000 voltage levels -- The AM2302 is powered within its supported operating range -- The button pull-up arrangement matches the intended firmware logic -- Available pins are sufficient for the display, sensor, and both buttons - -## Risks To Keep In Mind - -- OLED modules may vary by interface and initialization details -- Sensor timing can be sensitive depending on the library used -- Network-based features may require retry logic and fallback screen states diff --git a/include/screens.h b/include/screens.h new file mode 100644 index 0000000..a90bf77 --- /dev/null +++ b/include/screens.h @@ -0,0 +1,10 @@ +#ifndef SCREENS_H +#define SCREENS_H + +#include + +void drawScreen1(U8G2 &u8g2); +void drawScreen2(U8G2 &u8g2); +void drawWeatherIconScreen(U8G2 &u8g2); + +#endif diff --git a/src/carousel.cpp b/src/carousel.cpp index ffa2921..37e9e81 100644 --- a/src/carousel.cpp +++ b/src/carousel.cpp @@ -5,9 +5,9 @@ const unsigned long pageInterval = 5000; Carousel::Carousel(Screen *screens, size_t screenCount) : screens_(screens), screenCount_(screenCount), - dirty_(true), currentIndex_(0), - nextUpdate_(pageInterval) {} + nextUpdate_(pageInterval), + dirty_(true) {} void Carousel::draw(U8G2 &u8g2) { @@ -33,4 +33,4 @@ void Carousel::update(unsigned long now) { if (now > nextUpdate_) { nextScreen(); } -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index 2989963..9f05b1a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,32 +3,22 @@ #include #include "carousel.h" +#include "screens.h" U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, U8X8_PIN_NONE); -int lastButtonState = LOW; -uint8_t buttonOne = A3; - -int number = 0; -bool dirty = true; - -void drawScreen1(U8G2 &u8g2) { - u8g2.setFont(u8g2_font_ncenB14_tr); - u8g2.drawStr(0, 20, "Screen 1"); -} -void drawScreen2(U8G2 &u8g2) { - u8g2.setFont(u8g2_font_ncenB14_tr); - u8g2.drawStr(0, 40, "Screen 2"); -} +int lastButtonNextState = LOW; +uint8_t buttonNext = A3; Screen screens[] = { { drawScreen1 }, - { drawScreen2 } + { drawScreen2 }, + { drawWeatherIconScreen } }; Carousel carousel(screens, sizeof(screens) / sizeof(screens[0])); void setup() { - pinMode(buttonOne, INPUT); + pinMode(buttonNext, INPUT); u8g2.begin(); u8g2.clearBuffer(); @@ -39,12 +29,11 @@ void loop(){ const unsigned long now = millis(); carousel.update(now); - const int currentButtonState = digitalRead(buttonOne); - if (lastButtonState == LOW && currentButtonState == HIGH) { - number += 10; + const int currentButtonState = digitalRead(buttonNext); + if (lastButtonNextState == LOW && currentButtonState == HIGH) { carousel.nextScreen(); } - lastButtonState = currentButtonState; + lastButtonNextState = currentButtonState; if (carousel.consumeDirty()) { u8g2.clearBuffer(); diff --git a/src/screens.cpp b/src/screens.cpp new file mode 100644 index 0000000..dbfa157 --- /dev/null +++ b/src/screens.cpp @@ -0,0 +1,44 @@ +#include "screens.h" + +namespace +{ +void drawSun(U8G2 &u8g2, uint8_t x, uint8_t y) +{ + u8g2.drawDisc(x, y, 11); + u8g2.drawLine(x, y - 18, x, y - 14); + u8g2.drawLine(x, y + 14, x, y + 18); + u8g2.drawLine(x - 18, y, x - 14, y); + u8g2.drawLine(x + 14, y, x + 18, y); + u8g2.drawLine(x - 13, y - 13, x - 10, y - 10); + u8g2.drawLine(x + 10, y - 10, x + 13, y - 13); + u8g2.drawLine(x - 13, y + 13, x - 10, y + 10); + u8g2.drawLine(x + 10, y + 10, x + 13, y + 13); +} + +void drawCloud(U8G2 &u8g2, uint8_t x, uint8_t y) +{ + u8g2.drawDisc(x + 18, y + 14, 12); + u8g2.drawDisc(x + 34, y + 8, 17); + u8g2.drawDisc(x + 52, y + 15, 13); + u8g2.drawBox(x + 17, y + 15, 38, 14); + u8g2.drawRBox(x + 8, y + 18, 58, 15, 7); +} +} + +void drawScreen1(U8G2 &u8g2) +{ + u8g2.setFont(u8g2_font_ncenB14_tr); + u8g2.drawStr(0, 20, "Screen 1"); +} + +void drawScreen2(U8G2 &u8g2) +{ + u8g2.setFont(u8g2_font_ncenB14_tr); + u8g2.drawStr(0, 40, "Screen 2"); +} + +void drawWeatherIconScreen(U8G2 &u8g2) +{ + drawSun(u8g2, 78, 22); + drawCloud(u8g2, 29, 24); +}