For 24bar graph support

Dependents:   toastboard_integrated

Fork of Adafruit_LEDBackpack_2 by Daniel Drew

Committer:
ddrew73
Date:
Tue Nov 18 01:19:49 2014 +0000
Revision:
2:0491b3f9a639
Parent:
0:e81a6274acce
Edited to include the Adafruit 24 bicolor bargraph functionality.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
luizhespanha 0:e81a6274acce 1 /***********************************
luizhespanha 0:e81a6274acce 2 This is a our graphics core library, for all our displays.
luizhespanha 0:e81a6274acce 3 We'll be adapting all the
luizhespanha 0:e81a6274acce 4 existing libaries to use this core to make updating, support
luizhespanha 0:e81a6274acce 5 and upgrading easier!
luizhespanha 0:e81a6274acce 6
luizhespanha 0:e81a6274acce 7 Adafruit invests time and resources providing this open source code,
luizhespanha 0:e81a6274acce 8 please support Adafruit and open-source hardware by purchasing
luizhespanha 0:e81a6274acce 9 products from Adafruit!
luizhespanha 0:e81a6274acce 10
luizhespanha 0:e81a6274acce 11 Written by Limor Fried/Ladyada for Adafruit Industries.
luizhespanha 0:e81a6274acce 12 BSD license, check license.txt for more information
luizhespanha 0:e81a6274acce 13 All text above must be included in any redistribution
luizhespanha 0:e81a6274acce 14 ****************************************/
luizhespanha 0:e81a6274acce 15
luizhespanha 0:e81a6274acce 16 /*
luizhespanha 0:e81a6274acce 17 * Modified by Neal Horman 7/14/2012 for use in LPC1768
luizhespanha 0:e81a6274acce 18 */
luizhespanha 0:e81a6274acce 19
luizhespanha 0:e81a6274acce 20 #ifndef _ADAFRUIT_GFX_H_
luizhespanha 0:e81a6274acce 21 #define _ADAFRUIT_GFX_H_
luizhespanha 0:e81a6274acce 22
luizhespanha 0:e81a6274acce 23 static inline void swap(int16_t &a, int16_t &b)
luizhespanha 0:e81a6274acce 24 {
luizhespanha 0:e81a6274acce 25 int16_t t = a;
luizhespanha 0:e81a6274acce 26
luizhespanha 0:e81a6274acce 27 a = b;
luizhespanha 0:e81a6274acce 28 b = t;
luizhespanha 0:e81a6274acce 29 }
luizhespanha 0:e81a6274acce 30
luizhespanha 0:e81a6274acce 31 #ifndef _BV
luizhespanha 0:e81a6274acce 32 #define _BV(bit) (1<<(bit))
luizhespanha 0:e81a6274acce 33 #endif
luizhespanha 0:e81a6274acce 34
luizhespanha 0:e81a6274acce 35 #define BLACK 0
luizhespanha 0:e81a6274acce 36 #define WHITE 1
luizhespanha 0:e81a6274acce 37
luizhespanha 0:e81a6274acce 38 class Adafruit_GFX : public Stream
luizhespanha 0:e81a6274acce 39 {
luizhespanha 0:e81a6274acce 40 public:
luizhespanha 0:e81a6274acce 41 Adafruit_GFX(int16_t w, int16_t h)
luizhespanha 0:e81a6274acce 42 : _rawWidth(w)
luizhespanha 0:e81a6274acce 43 , _rawHeight(h)
luizhespanha 0:e81a6274acce 44 , _width(w)
luizhespanha 0:e81a6274acce 45 , _height(h)
luizhespanha 0:e81a6274acce 46 , cursor_x(0)
luizhespanha 0:e81a6274acce 47 , cursor_y(0)
luizhespanha 0:e81a6274acce 48 , textcolor(WHITE)
luizhespanha 0:e81a6274acce 49 , textbgcolor(BLACK)
luizhespanha 0:e81a6274acce 50 , textsize(1)
luizhespanha 0:e81a6274acce 51 , rotation(0)
luizhespanha 0:e81a6274acce 52 , wrap(true)
luizhespanha 0:e81a6274acce 53 {};
luizhespanha 0:e81a6274acce 54
luizhespanha 0:e81a6274acce 55 // this must be defined by the subclass
luizhespanha 0:e81a6274acce 56 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
luizhespanha 0:e81a6274acce 57 // this is optional
luizhespanha 0:e81a6274acce 58 virtual void invertDisplay(bool i) {};
luizhespanha 0:e81a6274acce 59
luizhespanha 0:e81a6274acce 60 // Stream implementation - provides printf() interface
luizhespanha 0:e81a6274acce 61 // You would otherwise be forced to use writeChar()
luizhespanha 0:e81a6274acce 62 virtual int _putc(int value) { return writeChar(value); };
luizhespanha 0:e81a6274acce 63 virtual int _getc() { return -1; };
luizhespanha 0:e81a6274acce 64
luizhespanha 0:e81a6274acce 65 #ifdef WANT_ABSTRACTS
luizhespanha 0:e81a6274acce 66 // these are 'generic' drawing functions, so we can share them!
luizhespanha 0:e81a6274acce 67 virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
luizhespanha 0:e81a6274acce 68 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
luizhespanha 0:e81a6274acce 69 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
luizhespanha 0:e81a6274acce 70 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
luizhespanha 0:e81a6274acce 71 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
luizhespanha 0:e81a6274acce 72 virtual void fillScreen(uint16_t color);
luizhespanha 0:e81a6274acce 73
luizhespanha 0:e81a6274acce 74 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
luizhespanha 0:e81a6274acce 75 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
luizhespanha 0:e81a6274acce 76 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
luizhespanha 0:e81a6274acce 77 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
luizhespanha 0:e81a6274acce 78
luizhespanha 0:e81a6274acce 79 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
luizhespanha 0:e81a6274acce 80 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
luizhespanha 0:e81a6274acce 81 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
luizhespanha 0:e81a6274acce 82 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
luizhespanha 0:e81a6274acce 83 #endif
luizhespanha 0:e81a6274acce 84
luizhespanha 0:e81a6274acce 85 void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
luizhespanha 0:e81a6274acce 86 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
luizhespanha 0:e81a6274acce 87 size_t writeChar(uint8_t);
luizhespanha 0:e81a6274acce 88
luizhespanha 0:e81a6274acce 89 int16_t width(void) { return _width; };
luizhespanha 0:e81a6274acce 90 int16_t height(void) { return _height; };
luizhespanha 0:e81a6274acce 91
luizhespanha 0:e81a6274acce 92 void setCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; };
luizhespanha 0:e81a6274acce 93 void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; };
luizhespanha 0:e81a6274acce 94 void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; }
luizhespanha 0:e81a6274acce 95 void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; };
luizhespanha 0:e81a6274acce 96 void setTextWrap(bool w) { wrap = w; };
luizhespanha 0:e81a6274acce 97
luizhespanha 0:e81a6274acce 98 void setRotation(uint8_t r);
luizhespanha 0:e81a6274acce 99 uint8_t getRotation(void) { rotation %= 4; return rotation; };
luizhespanha 0:e81a6274acce 100
luizhespanha 0:e81a6274acce 101 protected:
luizhespanha 0:e81a6274acce 102 int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes
luizhespanha 0:e81a6274acce 103 int16_t _width, _height; // dependent on rotation
luizhespanha 0:e81a6274acce 104 int16_t cursor_x, cursor_y;
luizhespanha 0:e81a6274acce 105 uint16_t textcolor, textbgcolor;
luizhespanha 0:e81a6274acce 106 uint8_t textsize;
luizhespanha 0:e81a6274acce 107 uint8_t rotation;
luizhespanha 0:e81a6274acce 108 bool wrap; // If set, 'wrap' text at right edge of display
luizhespanha 0:e81a6274acce 109 };
luizhespanha 0:e81a6274acce 110
luizhespanha 0:e81a6274acce 111 #endif