From fb7fbfe6c438a240657472c93828d626faa6ac64 Mon Sep 17 00:00:00 2001 From: Zvonimir Rudinski Date: Fri, 24 Apr 2026 15:46:48 +0200 Subject: [PATCH] feat(display): add display class --- include/display.hpp | 15 +++++++++++++++ src/display.cpp | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 include/display.hpp create mode 100644 src/display.cpp diff --git a/include/display.hpp b/include/display.hpp new file mode 100644 index 0000000..ba3680f --- /dev/null +++ b/include/display.hpp @@ -0,0 +1,15 @@ +#pragma once +#include +#include + +/* + * A helper class to facilitate drawing on the SSD1306 OLED display using the U8g2 library. + */ +class Display { + public: + Display(); + + bool begin(); + private: + U8G2_SSD1306_128X64_NONAME_F_HW_I2C oled; +}; diff --git a/src/display.cpp b/src/display.cpp new file mode 100644 index 0000000..338ba33 --- /dev/null +++ b/src/display.cpp @@ -0,0 +1,17 @@ +#include "display.hpp" + +// Initialize the OLED display with the appropriate settings for the SSD1306 128x64 display utilizing hardware I2C. +// The constructor initializes the U8g2 library with the correct parameters for the display and communication method. +Display::Display() : oled(U8G2_R0, U8X8_PIN_NONE) {} + +// Try to initialize the OLED display. If initialization fails, print an error message to the serial console and return false. +// Otherwise, set the default font and return true. +bool Display::begin() { + if (!oled.begin()) { + Serial.println("Failed to initialize OLED display"); + return false; + } + + oled.setFont(u8g2_font_profont22_mn); + return true; +}