diff --git a/examples/SSD1306Demo/SSD1306Demo.ino b/examples/SSD1306Demo/SSD1306Demo.ino index df7eb61a125bd839a3360d3b39031c0452943c09..721e02a96a72ea3a1bb2541cbfc2d67cfd95a916 100644 --- a/examples/SSD1306Demo/SSD1306Demo.ino +++ b/examples/SSD1306Demo/SSD1306Demo.ino @@ -1,5 +1,3 @@ -#include <ArduinoJson.h> - /**The MIT License (MIT) Copyright (c) 2015 by Daniel Eichhorn @@ -26,6 +24,7 @@ See more at http://blog.squix.ch */ #include <Wire.h> #include "ssd1306_i2c.h" +#include "SSD1306Ui.h" #include "images.h" // if you are using a ESP8266 module with NodeMCU @@ -48,105 +47,125 @@ See more at http://blog.squix.ch // Initialize the oled display for address 0x3c // sda-pin=14 and sdc-pin=12 -SSD1306 display(0x3c, NODEMCU_D6, NODEMCU_D5); +SSD1306 display(0x3c, NODEMCU_D6, NODEMCU_D5); +SSD1306Ui ui ( &display ); // this array keeps function pointers to all frames // frames are the single views that slide from right to left -void (*frameCallbacks[])(int x, int y) = {drawFrame1, drawFrame2, drawFrame3, drawFrame4}; +bool (*frames[])(SSD1306 *display, int x, int y) = { drawFrame1, drawFrame2, drawFrame3, drawFrame4 }; // how many frames are there? int frameCount = 4; +bool (*overlays[])(SSD1306 *display) = { msOverlay }; +int overlaysCount = 1; + void setup() { Serial.begin(115200); Serial.println(); Serial.println(); - - // initialize dispaly - display.init(); + + + ui.setTargetFPS(30); + + ui.setActiveSymbole(activeSymbole); + ui.setInactiveSymbole(inactiveSymbole); + + // You can change this to + // TOP, LEFT, BOTTOM, RIGHT + ui.setIndicatorPosition(BOTTOM); + + // Defines where the first frame is located in the bar. + ui.setIndicatorDirection(LEFT_RIGHT); + + // You can change the transition that is used + // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN + ui.setFrameAnimation(SLIDE_LEFT); + + // Add frames + ui.setFrames(frames, frameCount); + + // Add overlays + ui.setOverlays(overlays, overlaysCount); + + // Inital UI takes care of initalising the display too. + ui.init(); + display.flipScreenVertically(); - // set the drawing functions - display.setFrameCallbacks(frameCount, frameCallbacks); - // how many ticks does a slide of a frame take? - display.setFrameTransitionTicks(10); - // defines how many ticks the driver waits between frame transitions - display.setFrameWaitTicks(150); - - display.clear(); - display.display(); - + } void loop() { - if (display.getFrameState() == display.FRAME_STATE_FIX) { - // do something which consumes a lot of time in a moment - // when there is no transition between frames going on. - // This will keep transitions smooth; - } - - // clear the frame - display.clear(); - - // Tell the driver to render the next frame. - // This enables the frame mode including the transition - // and the drawing of the frame indicators - display.nextFrameTick(); + int remainingTimeBudget = ui.update(); - // Even in frame mode you can draw static elements. - // But they won't be transitioned - display.setFont(ArialMT_Plain_10); - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.drawString(0, 54, "20:54"); + if (remainingTimeBudget > 0) { + // You can do some work here + // Don't do stuff if you are below your + // time budget. + delay(remainingTimeBudget); + } +} - // copy the buffer to the display - display.display(); +bool msOverlay(SSD1306 *display) { + display->setTextAlignment(TEXT_ALIGN_RIGHT); + display->setFont(ArialMT_Plain_10); + display->drawString(128, 0, String(millis())); + return true; } -void drawFrame1(int x, int y) { +bool drawFrame1(SSD1306 *display, int x, int y) { // draw an xbm image. // Please note that everything that should be transitioned // needs to be drawn relative to x and y - display.drawXbm(x + 34, y + 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits); - } - void drawFrame2(int x, int y) { + // if this frame need to be refreshed at the targetFPS you need to + // return true + display->drawXbm(x + 34, y + 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits); + return false; +} + +bool drawFrame2(SSD1306 *display, int x, int y) { // Demonstrates the 3 included default sizes. The fonts come from SSD1306Fonts.h file // Besides the default fonts there will be a program to convert TrueType fonts into this format - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.setFont(ArialMT_Plain_10); - display.drawString(0 + x, 0 + y, "Arial 10"); + display->setTextAlignment(TEXT_ALIGN_LEFT); + display->setFont(ArialMT_Plain_10); + display->drawString(0 + x, 10 + y, "Arial 10"); + + display->setFont(ArialMT_Plain_16); + display->drawString(0 + x, 20 + y, "Arial 16"); - display.setFont(ArialMT_Plain_16); - display.drawString(0 + x, 10 + y, "Arial 16"); + display->setFont(ArialMT_Plain_24); + display->drawString(0 + x, 34 + y, "Arial 24"); - display.setFont(ArialMT_Plain_24); - display.drawString(0 + x, 24 + y, "Arial 24"); + return false; } -void drawFrame3(int x, int y) { +bool drawFrame3(SSD1306 *display, int x, int y) { // Text alignment demo - display.setFont(ArialMT_Plain_10); + display->setFont(ArialMT_Plain_10); // The coordinates define the left starting point of the text - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.drawString(0 + x, 0 + y, "Left aligned (0,0)"); + display->setTextAlignment(TEXT_ALIGN_LEFT); + display->drawString(0 + x, 11 + y, "Left aligned (0,10)"); // The coordinates define the center of the text - display.setTextAlignment(TEXT_ALIGN_CENTER); - display.drawString(64 + x, 20, "Center aligned (64,20)"); + display->setTextAlignment(TEXT_ALIGN_CENTER); + display->drawString(64 + x, 22, "Center aligned (64,22)"); // The coordinates define the right end of the text - display.setTextAlignment(TEXT_ALIGN_RIGHT); - display.drawString(128 + x, 40, "Right aligned (128,40)"); + display->setTextAlignment(TEXT_ALIGN_RIGHT); + display->drawString(128 + x, 33, "Right aligned (128,33)"); + return false; } -void drawFrame4(int x, int y) { - // Demo for drawStringMaxWidth: +bool drawFrame4(SSD1306 *display, int x, int y) { + // Demo for drawStringMaxWidth: // with the third parameter you can define the width after which words will be wrapped. // Currently only spaces and "-" are allowed for wrapping - display.setTextAlignment(TEXT_ALIGN_LEFT); - display.setFont(ArialMT_Plain_10); - display.drawStringMaxWidth(0 + x, 0 + y, 128, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore."); + display->setTextAlignment(TEXT_ALIGN_LEFT); + display->setFont(ArialMT_Plain_10); + display->drawStringMaxWidth(0 + x, 10 + y, 128, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore."); + return false; } diff --git a/examples/SSD1306Demo/images.h b/examples/SSD1306Demo/images.h index 8f5de149d1733553de8cbd7d3dbef167b9551aec..c280b555ce6010e5879f757fb4abff7bd090f466 100644 --- a/examples/SSD1306Demo/images.h +++ b/examples/SSD1306Demo/images.h @@ -1,28 +1,50 @@ #define WiFi_Logo_width 60 #define WiFi_Logo_height 36 const char WiFi_Logo_bits[] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, - 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, - 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, - 0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF, - 0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00, - 0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C, - 0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00, - 0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C, - 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00, - 0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, - 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, - 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C, - 0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00, - 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F, - 0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00, - 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF, - 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, - 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, - 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }; + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, + 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00, + 0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C, + 0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00, + 0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C, + 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00, + 0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, + 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, + 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C, + 0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00, + 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F, + 0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00, + 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF, + 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, + 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, + 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + +const char activeSymbole[] PROGMEM = { + B00000000, + B00000000, + B00011000, + B00100100, + B01000010, + B01000010, + B00100100, + B00011000 +}; + +const char inactiveSymbole[] PROGMEM = { + B00000000, + B00000000, + B00000000, + B00000000, + B00011000, + B00011000, + B00000000, + B00000000 +}; \ No newline at end of file