From 4bd0a060d100c7fb9ad657c939b954b081b62016 Mon Sep 17 00:00:00 2001 From: EnricoGuccii Date: Tue, 23 Dec 2025 16:59:20 +0100 Subject: eee --- firmware/lib/oled/oled.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 firmware/lib/oled/oled.cpp (limited to 'firmware/lib/oled/oled.cpp') diff --git a/firmware/lib/oled/oled.cpp b/firmware/lib/oled/oled.cpp new file mode 100644 index 0000000..2054b8f --- /dev/null +++ b/firmware/lib/oled/oled.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include "settings.h" +#include "oled.h" + +OLED::OLED() + : display(OLED_WIDTH, OLED_HEIGHT, &Wire, -1) {} + +void OLED::init() +{ + Wire.begin(SDA_PIN, SCL_PIN); + display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR); + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(SSD1306_WHITE); +} + +void OLED::showMessage(const String &msg, int size, int x, int y) +{ + display.clearDisplay(); + display.setCursor(x, y); + display.setTextSize(size); + display.setTextColor(SSD1306_WHITE); + display.println(msg); + display.display(); +} + +void OLED::drawFullBitmap(const uint8_t *bitmap) +{ + display.clearDisplay(); + display.drawBitmap(0, 0, bitmap, OLED_WIDTH, OLED_HEIGHT, SSD1306_WHITE); + display.display(); +} + +void OLED::showAnimation(const byte *frames, int frameCount, int frameWidth, int frameHeight, int frameDelay) +{ + int x = 64 - (frameWidth / 2); + int y = 32 - (frameHeight / 2); + + for (int i = 0; i < frameCount; i++) + { + display.clearDisplay(); + display.drawBitmap( + x, y, + frames + i * (frameWidth * frameHeight / 8), + frameWidth, frameHeight, 1); + display.display(); + delay(frameDelay); + } +} + +void OLED::clear() +{ + display.clearDisplay(); + display.display(); +} -- cgit v1.2.3