Please run it on your NUCLEO-L152

Dependencies:   mbed

Committer:
davidprentice
Date:
Wed Sep 18 10:38:19 2019 +0000
Revision:
1:d88d2ad55fac
Parent:
0:b608c7f02f80
Added messages to Serial Terminal (9600 baud)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidprentice 0:b608c7f02f80 1 #ifndef _ADAFRUIT_GFX_H
davidprentice 0:b608c7f02f80 2 #define _ADAFRUIT_GFX_H
davidprentice 0:b608c7f02f80 3
davidprentice 0:b608c7f02f80 4 //#define USE_VFONTS
davidprentice 0:b608c7f02f80 5
davidprentice 0:b608c7f02f80 6 #include "Arduino.h"
davidprentice 0:b608c7f02f80 7 #define boolean bool
davidprentice 0:b608c7f02f80 8
davidprentice 0:b608c7f02f80 9 #ifndef HEX
davidprentice 0:b608c7f02f80 10 #define HEX 1
davidprentice 0:b608c7f02f80 11 #endif
davidprentice 0:b608c7f02f80 12
davidprentice 0:b608c7f02f80 13 #define swap(a, b) { int16_t t = a; a = b; b = t; }
davidprentice 0:b608c7f02f80 14
davidprentice 0:b608c7f02f80 15 class Adafruit_GFX { //: public Stream { // requires an interface
davidprentice 0:b608c7f02f80 16
davidprentice 0:b608c7f02f80 17 public:
davidprentice 0:b608c7f02f80 18
davidprentice 0:b608c7f02f80 19 Adafruit_GFX(int16_t w, int16_t h); // Constructor
davidprentice 0:b608c7f02f80 20
davidprentice 0:b608c7f02f80 21 // This MUST be defined by the subclass:
davidprentice 0:b608c7f02f80 22 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
davidprentice 0:b608c7f02f80 23
davidprentice 0:b608c7f02f80 24 // These MAY be overridden by the subclass to provide device-specific
davidprentice 0:b608c7f02f80 25 // optimized code. Otherwise 'generic' versions are used.
davidprentice 0:b608c7f02f80 26 virtual void
davidprentice 0:b608c7f02f80 27 drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
davidprentice 0:b608c7f02f80 28 drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
davidprentice 0:b608c7f02f80 29 drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
davidprentice 0:b608c7f02f80 30 drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
davidprentice 0:b608c7f02f80 31 fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
davidprentice 0:b608c7f02f80 32 fillScreen(uint16_t color),
davidprentice 0:b608c7f02f80 33 invertDisplay(boolean i);
davidprentice 0:b608c7f02f80 34
davidprentice 0:b608c7f02f80 35 // These exist only with Adafruit_GFX (no subclass overrides)
davidprentice 0:b608c7f02f80 36 void
davidprentice 0:b608c7f02f80 37 drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
davidprentice 0:b608c7f02f80 38 drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
davidprentice 0:b608c7f02f80 39 uint16_t color),
davidprentice 0:b608c7f02f80 40 fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
davidprentice 0:b608c7f02f80 41 fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
davidprentice 0:b608c7f02f80 42 int16_t delta, uint16_t color),
davidprentice 0:b608c7f02f80 43 drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
davidprentice 0:b608c7f02f80 44 int16_t x2, int16_t y2, uint16_t color),
davidprentice 0:b608c7f02f80 45 fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
davidprentice 0:b608c7f02f80 46 int16_t x2, int16_t y2, uint16_t color),
davidprentice 0:b608c7f02f80 47 drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
davidprentice 0:b608c7f02f80 48 int16_t radius, uint16_t color),
davidprentice 0:b608c7f02f80 49 fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
davidprentice 0:b608c7f02f80 50 int16_t radius, uint16_t color),
davidprentice 0:b608c7f02f80 51 drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
davidprentice 0:b608c7f02f80 52 int16_t w, int16_t h, uint16_t color),
davidprentice 0:b608c7f02f80 53 drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
davidprentice 0:b608c7f02f80 54 uint16_t bg, uint8_t size),
davidprentice 0:b608c7f02f80 55 setCursor(int16_t x, int16_t y),
davidprentice 0:b608c7f02f80 56 setTextColor(uint16_t c),
davidprentice 0:b608c7f02f80 57 setTextColor(uint16_t c, uint16_t bg),
davidprentice 0:b608c7f02f80 58 setTextSize(uint8_t s),
davidprentice 0:b608c7f02f80 59 setTextWrap(boolean w),
davidprentice 0:b608c7f02f80 60 setRotation(uint8_t r);
davidprentice 0:b608c7f02f80 61
davidprentice 0:b608c7f02f80 62 #if defined(ARDUINO) && ARDUINO < 100
davidprentice 0:b608c7f02f80 63 virtual void write(uint8_t);
davidprentice 0:b608c7f02f80 64 #else
davidprentice 0:b608c7f02f80 65 virtual size_t write(uint8_t);
davidprentice 0:b608c7f02f80 66 #endif
davidprentice 0:b608c7f02f80 67 int printf(const char* format, ...);
davidprentice 0:b608c7f02f80 68 void print(const char *s) { printf("%s", s); }
davidprentice 0:b608c7f02f80 69 void print(char *s) { printf("%s", s); }
davidprentice 0:b608c7f02f80 70 void print(char c) { printf("%c", c); }
davidprentice 0:b608c7f02f80 71 void print(int16_t v) { printf("%d", v); }
davidprentice 0:b608c7f02f80 72 void print(int32_t vl) { printf("%ld", vl); }
davidprentice 0:b608c7f02f80 73 void print(double vd, int =2) { printf("%0.2f", vd); }
davidprentice 0:b608c7f02f80 74 void println(uint8_t u, int fmt=0) { if (fmt == 0) printf("%u\n", u); else printf("%04X\n", u); }
davidprentice 0:b608c7f02f80 75 void println(uint16_t u, int fmt=0) { if (fmt == 0) printf("%u\n", u); else printf("%04X\n", u); }
davidprentice 0:b608c7f02f80 76 void println(uint32_t ul, int fmt=0) { if (fmt == 0) printf("%lu\n", ul); else printf("%04lX\n", ul); }
davidprentice 0:b608c7f02f80 77 void println(const char *s="") { printf("%s\n", s); }
davidprentice 0:b608c7f02f80 78 void println(double vd, int prec=2) { printf("%0.2f\n", vd); }
davidprentice 0:b608c7f02f80 79
davidprentice 0:b608c7f02f80 80 int16_t
davidprentice 0:b608c7f02f80 81 height(void),
davidprentice 0:b608c7f02f80 82 width(void);
davidprentice 0:b608c7f02f80 83
davidprentice 0:b608c7f02f80 84 uint8_t getRotation(void);
davidprentice 0:b608c7f02f80 85
davidprentice 0:b608c7f02f80 86 protected:
davidprentice 0:b608c7f02f80 87 const int16_t
davidprentice 0:b608c7f02f80 88 WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
davidprentice 0:b608c7f02f80 89 int16_t
davidprentice 0:b608c7f02f80 90 _width, _height, // Display w/h as modified by current rotation
davidprentice 0:b608c7f02f80 91 cursor_x, cursor_y;
davidprentice 0:b608c7f02f80 92 uint16_t
davidprentice 0:b608c7f02f80 93 textcolor, textbgcolor;
davidprentice 0:b608c7f02f80 94 uint8_t
davidprentice 0:b608c7f02f80 95 textsize,
davidprentice 0:b608c7f02f80 96 rotation;
davidprentice 0:b608c7f02f80 97 boolean
davidprentice 0:b608c7f02f80 98 wrap; // If set, 'wrap' text at right edge of display
davidprentice 0:b608c7f02f80 99
davidprentice 0:b608c7f02f80 100 #if defined USE_VFONTS
davidprentice 0:b608c7f02f80 101 public:
davidprentice 0:b608c7f02f80 102 void setFont(const PROGMEM uint8_t *ads, uint8_t mode = 0);
davidprentice 0:b608c7f02f80 103 void drawFontChar(int16_t x, int16_t y, uint8_t c, uint16_t color, uint16_t bg, uint8_t size);
davidprentice 0:b608c7f02f80 104 int8_t charWidth(uint8_t c);
davidprentice 0:b608c7f02f80 105 private:
davidprentice 0:b608c7f02f80 106 uint8_t *vfont_ads, vfont_wid, vfont_ht, vfont_ofs, vfont_siz, vfont_mode, *vfont_letter_ads;
davidprentice 0:b608c7f02f80 107 #endif
davidprentice 0:b608c7f02f80 108
davidprentice 0:b608c7f02f80 109 };
davidprentice 0:b608c7f02f80 110
davidprentice 0:b608c7f02f80 111 #endif // _ADAFRUIT_GFX_H