/* * Display.cpp * * Wrapper class for Adafruit OLED display. * * Created on: 28.01.2022 * Author: FSmilari */ #include "Display.h" /***************** ** Constructors. ****************/ Display::Display() { ssd1306 = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT); } /****************** ** Public methods *****************/ void Display::init() { if (!ssd1306.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, true, true)) { Serial.println(F("SSD1306 allocation failed")); for (;;) ; // Don't proceed, loop forever } } void Display::display() { ssd1306.display(); } void Display::clearDisplay() { ssd1306.clearDisplay(); } void Display::showBrand() { ssd1306.clearDisplay(); ssd1306.drawBitmap(0, 0, epd_bitmap_SFTools_Logo, 128, 34, SSD1306_WHITE); ssd1306.setFont(&titillium_web_semibold12pt7b); ssd1306.setTextSize(1); ssd1306.setTextColor(SSD1306_WHITE); uint16_t w = 0, h = 0; calculateWH("Fraestisch N172", w, h); ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 63 - (30 - h) / 2); ssd1306.println("Fraestisch N172"); display(); } void Display::showInitialization() { ssd1306.clearDisplay(); ssd1306.setFont(&titillium_web_semibold12pt7b); ssd1306.setTextSize(1); ssd1306.setTextColor(SSD1306_WHITE); uint16_t w = 0, h = 0; calculateWH("Initialisieren", w, h); ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 30); ssd1306.println("Initialisieren"); calculateWH(". . . . .", w, h); ssd1306.setCursor((SCREEN_WIDTH - w) / 2, 50); String s = ""; for (int i = 0; i < 6; i++) { ssd1306.print(s); display(); delay(500); if (i < 5) { ssd1306.print(s + ". "); } else { ssd1306.println(s + "."); } } } /******************************** ** Private methods *******************************/ void Display::calculateWH(String units, uint16_t &w, uint16_t &h) { int x = 0; int y = 0; int16_t x1, y1; uint16_t w1, h1; ssd1306.getTextBounds(units, x, y, &x1, &y1, &w1, &h1); w = w1; h = h1; }