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 ++++++++++++++++++++++++++++++++++++++++++++++ firmware/lib/oled/oled.h | 18 ++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 firmware/lib/oled/oled.cpp create mode 100644 firmware/lib/oled/oled.h (limited to 'firmware/lib/oled') 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(); +} diff --git a/firmware/lib/oled/oled.h b/firmware/lib/oled/oled.h new file mode 100644 index 0000000..2d5ff14 --- /dev/null +++ b/firmware/lib/oled/oled.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include "settings.h" + + +class OLED { +public: + OLED(); + + void init(); + void showMessage(const String& msg,int size = 1 ,int x = 0, int y = 0); + void drawFullBitmap(const uint8_t* bitmap); + void showAnimation(const byte* frames, int frameCount, int frameWidth, int frameHeight, int frameDelay); + void clear(); + +private: + Adafruit_SSD1306 display; +}; -- cgit v1.2.3