ThingPulse OLED SSD1306

Dependents:   Turtle_RadioShuttle

Committer:
Helmut Tschemernjak
Date:
Thu Jun 06 09:29:02 2019 +0200
Revision:
3:99a409809366
Parent:
2:4ed55dfe5be7
Updated with latest version for github

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Helmut64 0:56dd5df33ab4 1 /**
Helmut64 0:56dd5df33ab4 2 * The MIT License (MIT)
Helmut64 0:56dd5df33ab4 3 *
Helmut64 0:56dd5df33ab4 4 * Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
Helmut64 0:56dd5df33ab4 5 * Copyright (c) 2018 by Fabrice Weinberg
Helmut64 0:56dd5df33ab4 6 * Copyright (c) 2019 by Helmut Tschemernjak - www.radioshuttle.de
Helmut64 0:56dd5df33ab4 7 *
Helmut64 0:56dd5df33ab4 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
Helmut64 0:56dd5df33ab4 9 * of this software and associated documentation files (the "Software"), to deal
Helmut64 0:56dd5df33ab4 10 * in the Software without restriction, including without limitation the rights
Helmut64 0:56dd5df33ab4 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Helmut64 0:56dd5df33ab4 12 * copies of the Software, and to permit persons to whom the Software is
Helmut64 0:56dd5df33ab4 13 * furnished to do so, subject to the following conditions:
Helmut64 0:56dd5df33ab4 14 *
Helmut64 0:56dd5df33ab4 15 * The above copyright notice and this permission notice shall be included in all
Helmut64 0:56dd5df33ab4 16 * copies or substantial portions of the Software.
Helmut64 0:56dd5df33ab4 17 *
Helmut64 0:56dd5df33ab4 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Helmut64 0:56dd5df33ab4 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Helmut64 0:56dd5df33ab4 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Helmut64 0:56dd5df33ab4 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Helmut64 0:56dd5df33ab4 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Helmut64 0:56dd5df33ab4 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Helmut64 0:56dd5df33ab4 24 * SOFTWARE.
Helmut64 0:56dd5df33ab4 25 *
Helmut64 0:56dd5df33ab4 26 * ThingPulse invests considerable time and money to develop these open source libraries.
Helmut64 0:56dd5df33ab4 27 * Please support us by buying our products (and not the clones) from
Helmut64 0:56dd5df33ab4 28 * https://thingpulse.com
Helmut64 0:56dd5df33ab4 29 *
Helmut64 0:56dd5df33ab4 30 */
Helmut64 0:56dd5df33ab4 31
Helmut64 0:56dd5df33ab4 32 #ifndef OLEDDISPLAY_h
Helmut64 0:56dd5df33ab4 33 #define OLEDDISPLAY_h
Helmut64 0:56dd5df33ab4 34
Helmut64 0:56dd5df33ab4 35 #ifdef ARDUINO
Helmut64 0:56dd5df33ab4 36 #include <Arduino.h>
Helmut64 0:56dd5df33ab4 37 #elif __MBED__
Helmut64 0:56dd5df33ab4 38 #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
Helmut64 0:56dd5df33ab4 39
Helmut64 0:56dd5df33ab4 40 #include <mbed.h>
Helmut64 0:56dd5df33ab4 41 #define delay(x) wait_ms(x)
Helmut64 0:56dd5df33ab4 42 #define yield() void()
Helmut64 0:56dd5df33ab4 43
Helmut64 0:56dd5df33ab4 44 /*
Helmut64 0:56dd5df33ab4 45 * This is a little Arduino String emulation to keep the OLEDDisplay
Helmut64 0:56dd5df33ab4 46 * library code in common between Arduino and mbed-os
Helmut64 0:56dd5df33ab4 47 */
Helmut64 0:56dd5df33ab4 48 class String {
Helmut64 0:56dd5df33ab4 49 public:
Helmut64 0:56dd5df33ab4 50 String(const char *s) { _str = s; };
Helmut64 0:56dd5df33ab4 51 int length() { return strlen(_str); };
Helmut64 0:56dd5df33ab4 52 const char *c_str() { return _str; };
Helmut64 0:56dd5df33ab4 53 void toCharArray(char *buf, unsigned int bufsize, unsigned int index = 0) const {
Helmut64 0:56dd5df33ab4 54 memcpy(buf, _str + index, std::min(bufsize, strlen(_str)));
Helmut64 0:56dd5df33ab4 55 };
Helmut64 0:56dd5df33ab4 56 private:
Helmut64 0:56dd5df33ab4 57 const char *_str;
Helmut64 0:56dd5df33ab4 58 };
Helmut64 0:56dd5df33ab4 59
Helmut64 0:56dd5df33ab4 60 #else
Helmut64 0:56dd5df33ab4 61 #error "Unkown operating system"
Helmut64 0:56dd5df33ab4 62 #endif
Helmut64 0:56dd5df33ab4 63
Helmut64 0:56dd5df33ab4 64 #include "OLEDDisplayFonts.h"
Helmut64 0:56dd5df33ab4 65
Helmut64 0:56dd5df33ab4 66 //#define DEBUG_OLEDDISPLAY(...) Serial.printf( __VA_ARGS__ )
Helmut64 0:56dd5df33ab4 67 //#define DEBUG_OLEDDISPLAY(...) dprintf("%s", __VA_ARGS__ )
Helmut64 0:56dd5df33ab4 68
Helmut64 0:56dd5df33ab4 69 #ifndef DEBUG_OLEDDISPLAY
Helmut64 0:56dd5df33ab4 70 #define DEBUG_OLEDDISPLAY(...)
Helmut64 0:56dd5df33ab4 71 #endif
Helmut64 0:56dd5df33ab4 72
Helmut64 0:56dd5df33ab4 73 // Use DOUBLE BUFFERING by default
Helmut64 0:56dd5df33ab4 74 #ifndef OLEDDISPLAY_REDUCE_MEMORY
Helmut64 0:56dd5df33ab4 75 #define OLEDDISPLAY_DOUBLE_BUFFER
Helmut64 0:56dd5df33ab4 76 #endif
Helmut64 0:56dd5df33ab4 77
Helmut64 0:56dd5df33ab4 78 // Header Values
Helmut64 0:56dd5df33ab4 79 #define JUMPTABLE_BYTES 4
Helmut64 0:56dd5df33ab4 80
Helmut64 0:56dd5df33ab4 81 #define JUMPTABLE_LSB 1
Helmut64 0:56dd5df33ab4 82 #define JUMPTABLE_SIZE 2
Helmut64 0:56dd5df33ab4 83 #define JUMPTABLE_WIDTH 3
Helmut64 0:56dd5df33ab4 84 #define JUMPTABLE_START 4
Helmut64 0:56dd5df33ab4 85
Helmut64 0:56dd5df33ab4 86 #define WIDTH_POS 0
Helmut64 0:56dd5df33ab4 87 #define HEIGHT_POS 1
Helmut64 0:56dd5df33ab4 88 #define FIRST_CHAR_POS 2
Helmut64 0:56dd5df33ab4 89 #define CHAR_NUM_POS 3
Helmut64 0:56dd5df33ab4 90
Helmut64 0:56dd5df33ab4 91
Helmut64 0:56dd5df33ab4 92 // Display commands
Helmut64 0:56dd5df33ab4 93 #define CHARGEPUMP 0x8D
Helmut64 0:56dd5df33ab4 94 #define COLUMNADDR 0x21
Helmut64 0:56dd5df33ab4 95 #define COMSCANDEC 0xC8
Helmut64 0:56dd5df33ab4 96 #define COMSCANINC 0xC0
Helmut64 0:56dd5df33ab4 97 #define DISPLAYALLON 0xA5
Helmut64 0:56dd5df33ab4 98 #define DISPLAYALLON_RESUME 0xA4
Helmut64 0:56dd5df33ab4 99 #define DISPLAYOFF 0xAE
Helmut64 0:56dd5df33ab4 100 #define DISPLAYON 0xAF
Helmut64 0:56dd5df33ab4 101 #define EXTERNALVCC 0x1
Helmut64 0:56dd5df33ab4 102 #define INVERTDISPLAY 0xA7
Helmut64 0:56dd5df33ab4 103 #define MEMORYMODE 0x20
Helmut64 0:56dd5df33ab4 104 #define NORMALDISPLAY 0xA6
Helmut64 0:56dd5df33ab4 105 #define PAGEADDR 0x22
Helmut64 0:56dd5df33ab4 106 #define SEGREMAP 0xA0
Helmut64 0:56dd5df33ab4 107 #define SETCOMPINS 0xDA
Helmut64 0:56dd5df33ab4 108 #define SETCONTRAST 0x81
Helmut64 0:56dd5df33ab4 109 #define SETDISPLAYCLOCKDIV 0xD5
Helmut64 0:56dd5df33ab4 110 #define SETDISPLAYOFFSET 0xD3
Helmut64 0:56dd5df33ab4 111 #define SETHIGHCOLUMN 0x10
Helmut64 0:56dd5df33ab4 112 #define SETLOWCOLUMN 0x00
Helmut64 0:56dd5df33ab4 113 #define SETMULTIPLEX 0xA8
Helmut64 0:56dd5df33ab4 114 #define SETPRECHARGE 0xD9
Helmut64 0:56dd5df33ab4 115 #define SETSEGMENTREMAP 0xA1
Helmut64 0:56dd5df33ab4 116 #define SETSTARTLINE 0x40
Helmut64 0:56dd5df33ab4 117 #define SETVCOMDETECT 0xDB
Helmut64 0:56dd5df33ab4 118 #define SWITCHCAPVCC 0x2
Helmut64 0:56dd5df33ab4 119
Helmut64 0:56dd5df33ab4 120 #ifndef _swap_int16_t
Helmut64 0:56dd5df33ab4 121 #define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; }
Helmut64 0:56dd5df33ab4 122 #endif
Helmut64 0:56dd5df33ab4 123
Helmut64 0:56dd5df33ab4 124 enum OLEDDISPLAY_COLOR {
Helmut64 0:56dd5df33ab4 125 BLACK = 0,
Helmut64 0:56dd5df33ab4 126 WHITE = 1,
Helmut64 0:56dd5df33ab4 127 INVERSE = 2
Helmut64 0:56dd5df33ab4 128 };
Helmut64 0:56dd5df33ab4 129
Helmut64 0:56dd5df33ab4 130 enum OLEDDISPLAY_TEXT_ALIGNMENT {
Helmut64 0:56dd5df33ab4 131 TEXT_ALIGN_LEFT = 0,
Helmut64 0:56dd5df33ab4 132 TEXT_ALIGN_RIGHT = 1,
Helmut64 0:56dd5df33ab4 133 TEXT_ALIGN_CENTER = 2,
Helmut64 0:56dd5df33ab4 134 TEXT_ALIGN_CENTER_BOTH = 3
Helmut64 0:56dd5df33ab4 135 };
Helmut64 0:56dd5df33ab4 136
Helmut64 0:56dd5df33ab4 137
Helmut64 0:56dd5df33ab4 138 enum OLEDDISPLAY_GEOMETRY {
Helmut64 0:56dd5df33ab4 139 GEOMETRY_128_64 = 0,
Helmut Tschemernjak 2:4ed55dfe5be7 140 GEOMETRY_128_32,
Helmut Tschemernjak 2:4ed55dfe5be7 141 GEOMETRY_RAWMODE,
Helmut64 0:56dd5df33ab4 142 };
Helmut64 0:56dd5df33ab4 143
Helmut Tschemernjak 2:4ed55dfe5be7 144 typedef char (*FontTableLookupFunction)(const uint8_t ch);
Helmut Tschemernjak 2:4ed55dfe5be7 145 char DefaultFontTableLookup(const uint8_t ch);
Helmut64 0:56dd5df33ab4 146
Helmut64 0:56dd5df33ab4 147
Helmut64 0:56dd5df33ab4 148 #ifdef ARDUINO
Helmut64 0:56dd5df33ab4 149 class OLEDDisplay : public Print {
Helmut64 0:56dd5df33ab4 150 #elif __MBED__
Helmut64 0:56dd5df33ab4 151 class OLEDDisplay : public Stream {
Helmut64 0:56dd5df33ab4 152 #else
Helmut64 0:56dd5df33ab4 153 #error "Unkown operating system"
Helmut64 0:56dd5df33ab4 154 #endif
Helmut64 0:56dd5df33ab4 155
Helmut64 0:56dd5df33ab4 156 public:
Helmut64 0:56dd5df33ab4 157 OLEDDisplay();
Helmut64 0:56dd5df33ab4 158 virtual ~OLEDDisplay();
Helmut64 0:56dd5df33ab4 159
Helmut64 0:56dd5df33ab4 160 uint16_t width(void) const { return displayWidth; };
Helmut64 0:56dd5df33ab4 161 uint16_t height(void) const { return displayHeight; };
Helmut64 0:56dd5df33ab4 162
Helmut64 0:56dd5df33ab4 163 // Initialize the display
Helmut64 0:56dd5df33ab4 164 bool init();
Helmut64 0:56dd5df33ab4 165
Helmut64 0:56dd5df33ab4 166 // Free the memory used by the display
Helmut64 0:56dd5df33ab4 167 void end();
Helmut64 0:56dd5df33ab4 168
Helmut64 0:56dd5df33ab4 169 // Cycle through the initialization
Helmut64 0:56dd5df33ab4 170 void resetDisplay(void);
Helmut64 0:56dd5df33ab4 171
Helmut64 0:56dd5df33ab4 172 /* Drawing functions */
Helmut64 0:56dd5df33ab4 173 // Sets the color of all pixel operations
Helmut64 0:56dd5df33ab4 174 void setColor(OLEDDISPLAY_COLOR color);
Helmut64 0:56dd5df33ab4 175
Helmut64 0:56dd5df33ab4 176 // Returns the current color.
Helmut64 0:56dd5df33ab4 177 OLEDDISPLAY_COLOR getColor();
Helmut64 0:56dd5df33ab4 178
Helmut64 0:56dd5df33ab4 179 // Draw a pixel at given position
Helmut64 0:56dd5df33ab4 180 void setPixel(int16_t x, int16_t y);
Helmut64 0:56dd5df33ab4 181
Helmut Tschemernjak 3:99a409809366 182 // Clear a pixel at given position FIXME: INVERSE is untested with this function
Helmut Tschemernjak 3:99a409809366 183 void clearPixel(int16_t x, int16_t y);
Helmut Tschemernjak 3:99a409809366 184
Helmut64 0:56dd5df33ab4 185 // Draw a line from position 0 to position 1
Helmut64 0:56dd5df33ab4 186 void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
Helmut64 0:56dd5df33ab4 187
Helmut64 0:56dd5df33ab4 188 // Draw the border of a rectangle at the given location
Helmut64 0:56dd5df33ab4 189 void drawRect(int16_t x, int16_t y, int16_t width, int16_t height);
Helmut64 0:56dd5df33ab4 190
Helmut64 0:56dd5df33ab4 191 // Fill the rectangle
Helmut64 0:56dd5df33ab4 192 void fillRect(int16_t x, int16_t y, int16_t width, int16_t height);
Helmut64 0:56dd5df33ab4 193
Helmut64 0:56dd5df33ab4 194 // Draw the border of a circle
Helmut64 0:56dd5df33ab4 195 void drawCircle(int16_t x, int16_t y, int16_t radius);
Helmut64 0:56dd5df33ab4 196
Helmut64 0:56dd5df33ab4 197 // Draw all Quadrants specified in the quads bit mask
Helmut64 0:56dd5df33ab4 198 void drawCircleQuads(int16_t x0, int16_t y0, int16_t radius, uint8_t quads);
Helmut64 0:56dd5df33ab4 199
Helmut64 0:56dd5df33ab4 200 // Fill circle
Helmut64 0:56dd5df33ab4 201 void fillCircle(int16_t x, int16_t y, int16_t radius);
Helmut64 0:56dd5df33ab4 202
Helmut64 0:56dd5df33ab4 203 // Draw a line horizontally
Helmut64 0:56dd5df33ab4 204 void drawHorizontalLine(int16_t x, int16_t y, int16_t length);
Helmut64 0:56dd5df33ab4 205
Helmut64 0:56dd5df33ab4 206 // Draw a line vertically
Helmut64 0:56dd5df33ab4 207 void drawVerticalLine(int16_t x, int16_t y, int16_t length);
Helmut64 0:56dd5df33ab4 208
Helmut64 0:56dd5df33ab4 209 // Draws a rounded progress bar with the outer dimensions given by width and height. Progress is
Helmut64 0:56dd5df33ab4 210 // a unsigned byte value between 0 and 100
Helmut64 0:56dd5df33ab4 211 void drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t progress);
Helmut64 0:56dd5df33ab4 212
Helmut64 0:56dd5df33ab4 213 // Draw a bitmap in the internal image format
Helmut64 0:56dd5df33ab4 214 void drawFastImage(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t *image);
Helmut64 0:56dd5df33ab4 215
Helmut64 0:56dd5df33ab4 216 // Draw a XBM
Helmut64 0:56dd5df33ab4 217 void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t *xbm);
Helmut64 0:56dd5df33ab4 218
Helmut64 0:56dd5df33ab4 219 /* Text functions */
Helmut64 0:56dd5df33ab4 220
Helmut64 0:56dd5df33ab4 221 // Draws a string at the given location
Helmut64 0:56dd5df33ab4 222 void drawString(int16_t x, int16_t y, String text);
Helmut64 0:56dd5df33ab4 223
Helmut64 0:56dd5df33ab4 224 // Draws a String with a maximum width at the given location.
Helmut64 0:56dd5df33ab4 225 // If the given String is wider than the specified width
Helmut64 0:56dd5df33ab4 226 // The text will be wrapped to the next line at a space or dash
Helmut64 0:56dd5df33ab4 227 void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, String text);
Helmut64 0:56dd5df33ab4 228
Helmut64 0:56dd5df33ab4 229 // Returns the width of the const char* with the current
Helmut64 0:56dd5df33ab4 230 // font settings
Helmut64 0:56dd5df33ab4 231 uint16_t getStringWidth(const char* text, uint16_t length);
Helmut64 0:56dd5df33ab4 232
Helmut64 0:56dd5df33ab4 233 // Convencience method for the const char version
Helmut64 0:56dd5df33ab4 234 uint16_t getStringWidth(String text);
Helmut64 0:56dd5df33ab4 235
Helmut64 0:56dd5df33ab4 236 // Specifies relative to which anchor point
Helmut64 0:56dd5df33ab4 237 // the text is rendered. Available constants:
Helmut64 0:56dd5df33ab4 238 // TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER_BOTH
Helmut64 0:56dd5df33ab4 239 void setTextAlignment(OLEDDISPLAY_TEXT_ALIGNMENT textAlignment);
Helmut64 0:56dd5df33ab4 240
Helmut64 0:56dd5df33ab4 241 // Sets the current font. Available default fonts
Helmut64 0:56dd5df33ab4 242 // ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24
Helmut64 0:56dd5df33ab4 243 void setFont(const uint8_t *fontData);
Helmut64 0:56dd5df33ab4 244
Helmut64 0:56dd5df33ab4 245 // Set the function that will convert utf-8 to font table index
Helmut64 0:56dd5df33ab4 246 void setFontTableLookupFunction(FontTableLookupFunction function);
Helmut64 0:56dd5df33ab4 247
Helmut64 0:56dd5df33ab4 248 /* Display functions */
Helmut64 0:56dd5df33ab4 249
Helmut64 0:56dd5df33ab4 250 // Turn the display on
Helmut64 0:56dd5df33ab4 251 void displayOn(void);
Helmut64 0:56dd5df33ab4 252
Helmut64 0:56dd5df33ab4 253 // Turn the display offs
Helmut64 0:56dd5df33ab4 254 void displayOff(void);
Helmut64 0:56dd5df33ab4 255
Helmut64 0:56dd5df33ab4 256 // Inverted display mode
Helmut64 0:56dd5df33ab4 257 void invertDisplay(void);
Helmut64 0:56dd5df33ab4 258
Helmut64 0:56dd5df33ab4 259 // Normal display mode
Helmut64 0:56dd5df33ab4 260 void normalDisplay(void);
Helmut64 0:56dd5df33ab4 261
Helmut64 0:56dd5df33ab4 262 // Set display contrast
Helmut64 0:56dd5df33ab4 263 // really low brightness & contrast: contrast = 10, precharge = 5, comdetect = 0
Helmut64 0:56dd5df33ab4 264 // normal brightness & contrast: contrast = 100
Helmut64 0:56dd5df33ab4 265 void setContrast(uint8_t contrast, uint8_t precharge = 241, uint8_t comdetect = 64);
Helmut64 0:56dd5df33ab4 266
Helmut64 0:56dd5df33ab4 267 // Convenience method to access
Helmut64 0:56dd5df33ab4 268 void setBrightness(uint8_t);
Helmut64 0:56dd5df33ab4 269
Helmut64 0:56dd5df33ab4 270 // Reset display rotation or mirroring
Helmut64 0:56dd5df33ab4 271 void resetOrientation();
Helmut64 0:56dd5df33ab4 272
Helmut64 0:56dd5df33ab4 273 // Turn the display upside down
Helmut64 0:56dd5df33ab4 274 void flipScreenVertically();
Helmut64 0:56dd5df33ab4 275
Helmut64 0:56dd5df33ab4 276 // Mirror the display (to be used in a mirror or as a projector)
Helmut64 0:56dd5df33ab4 277 void mirrorScreen();
Helmut64 0:56dd5df33ab4 278
Helmut64 0:56dd5df33ab4 279 // Write the buffer to the display memory
Helmut64 0:56dd5df33ab4 280 virtual void display(void) = 0;
Helmut64 0:56dd5df33ab4 281
Helmut64 0:56dd5df33ab4 282 // Clear the local pixel buffer
Helmut64 0:56dd5df33ab4 283 void clear(void);
Helmut64 0:56dd5df33ab4 284
Helmut64 0:56dd5df33ab4 285 // Log buffer implementation
Helmut64 0:56dd5df33ab4 286
Helmut64 0:56dd5df33ab4 287 // This will define the lines and characters you can
Helmut64 0:56dd5df33ab4 288 // print to the screen. When you exeed the buffer size (lines * chars)
Helmut64 0:56dd5df33ab4 289 // the output may be truncated due to the size constraint.
Helmut64 0:56dd5df33ab4 290 bool setLogBuffer(uint16_t lines, uint16_t chars);
Helmut64 0:56dd5df33ab4 291
Helmut64 0:56dd5df33ab4 292 // Draw the log buffer at position (x, y)
Helmut64 0:56dd5df33ab4 293 void drawLogBuffer(uint16_t x, uint16_t y);
Helmut64 0:56dd5df33ab4 294
Helmut64 0:56dd5df33ab4 295 // Get screen geometry
Helmut64 0:56dd5df33ab4 296 uint16_t getWidth(void);
Helmut64 0:56dd5df33ab4 297 uint16_t getHeight(void);
Helmut64 0:56dd5df33ab4 298
Helmut64 0:56dd5df33ab4 299 // Implement needed function to be compatible with Print class
Helmut64 0:56dd5df33ab4 300 size_t write(uint8_t c);
Helmut64 0:56dd5df33ab4 301 size_t write(const char* s);
Helmut64 0:56dd5df33ab4 302
Helmut64 0:56dd5df33ab4 303 // Implement needed function to be compatible with Stream class
Helmut64 0:56dd5df33ab4 304 #ifdef __MBED__
Helmut64 0:56dd5df33ab4 305 int _putc(int c);
Helmut64 0:56dd5df33ab4 306 int _getc() { return -1; };
Helmut64 0:56dd5df33ab4 307 #endif
Helmut64 0:56dd5df33ab4 308
Helmut64 0:56dd5df33ab4 309
Helmut64 0:56dd5df33ab4 310 uint8_t *buffer;
Helmut64 0:56dd5df33ab4 311
Helmut64 0:56dd5df33ab4 312 #ifdef OLEDDISPLAY_DOUBLE_BUFFER
Helmut64 0:56dd5df33ab4 313 uint8_t *buffer_back;
Helmut64 0:56dd5df33ab4 314 #endif
Helmut64 0:56dd5df33ab4 315
Helmut64 0:56dd5df33ab4 316 protected:
Helmut64 0:56dd5df33ab4 317
Helmut64 0:56dd5df33ab4 318 OLEDDISPLAY_GEOMETRY geometry;
Helmut64 0:56dd5df33ab4 319
Helmut64 0:56dd5df33ab4 320 uint16_t displayWidth;
Helmut64 0:56dd5df33ab4 321 uint16_t displayHeight;
Helmut64 0:56dd5df33ab4 322 uint16_t displayBufferSize;
Helmut64 0:56dd5df33ab4 323
Helmut64 0:56dd5df33ab4 324 // Set the correct height, width and buffer for the geometry
Helmut Tschemernjak 2:4ed55dfe5be7 325 void setGeometry(OLEDDISPLAY_GEOMETRY g, uint16_t width = 0, uint16_t height = 0);
Helmut64 0:56dd5df33ab4 326
Helmut64 0:56dd5df33ab4 327 OLEDDISPLAY_TEXT_ALIGNMENT textAlignment;
Helmut64 0:56dd5df33ab4 328 OLEDDISPLAY_COLOR color;
Helmut64 0:56dd5df33ab4 329
Helmut64 0:56dd5df33ab4 330 const uint8_t *fontData;
Helmut64 0:56dd5df33ab4 331
Helmut64 0:56dd5df33ab4 332 // State values for logBuffer
Helmut64 0:56dd5df33ab4 333 uint16_t logBufferSize;
Helmut64 0:56dd5df33ab4 334 uint16_t logBufferFilled;
Helmut64 0:56dd5df33ab4 335 uint16_t logBufferLine;
Helmut64 0:56dd5df33ab4 336 uint16_t logBufferMaxLines;
Helmut64 0:56dd5df33ab4 337 char *logBuffer;
Helmut64 0:56dd5df33ab4 338
Helmut64 0:56dd5df33ab4 339
Helmut64 0:56dd5df33ab4 340 // the header size of the buffer used, e.g. for the SPI command header
Helmut64 0:56dd5df33ab4 341 virtual int getBufferOffset(void) = 0;
Helmut64 0:56dd5df33ab4 342
Helmut64 0:56dd5df33ab4 343 // Send a command to the display (low level function)
Helmut64 0:56dd5df33ab4 344 virtual void sendCommand(uint8_t com) {(void)com;};
Helmut64 0:56dd5df33ab4 345
Helmut64 0:56dd5df33ab4 346 // Connect to the display
Helmut64 0:56dd5df33ab4 347 virtual bool connect() { return false; };
Helmut64 0:56dd5df33ab4 348
Helmut64 0:56dd5df33ab4 349 // Send all the init commands
Helmut64 0:56dd5df33ab4 350 void sendInitCommands();
Helmut64 0:56dd5df33ab4 351
Helmut64 0:56dd5df33ab4 352 // converts utf8 characters to extended ascii
Helmut64 0:56dd5df33ab4 353 char* utf8ascii(String s);
Helmut64 0:56dd5df33ab4 354
Helmut64 0:56dd5df33ab4 355 void inline drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const uint8_t *data, uint16_t offset, uint16_t bytesInData) __attribute__((always_inline));
Helmut64 0:56dd5df33ab4 356
Helmut64 0:56dd5df33ab4 357 void drawStringInternal(int16_t xMove, int16_t yMove, char* text, uint16_t textLength, uint16_t textWidth);
Helmut64 0:56dd5df33ab4 358
Helmut64 0:56dd5df33ab4 359 FontTableLookupFunction fontTableLookupFunction;
Helmut64 0:56dd5df33ab4 360 };
Helmut64 0:56dd5df33ab4 361
Helmut64 0:56dd5df33ab4 362 #endif