* AM2321的取温度间隔得大于2s,否则,i2c会不工作了 * SimpleTimer有个bug,会导致两次快速的读温度,现在读温度函数里加了保护 * Blynk有个bug,会导致无法把数据传到服务器 * 现在可以正常工作了

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Adafruit_GFX.h Source File

Adafruit_GFX.h

00001 /***********************************
00002 This is a our graphics core library, for all our displays. 
00003 We'll be adapting all the
00004 existing libaries to use this core to make updating, support 
00005 and upgrading easier!
00006 
00007 Adafruit invests time and resources providing this open source code, 
00008 please support Adafruit and open-source hardware by purchasing 
00009 products from Adafruit!
00010 
00011 Written by Limor Fried/Ladyada  for Adafruit Industries.  
00012 BSD license, check license.txt for more information
00013 All text above must be included in any redistribution
00014 ****************************************/
00015 
00016 /*
00017  *  Modified by Neal Horman 7/14/2012 for use in mbed
00018  */
00019 
00020 #ifndef _ADAFRUIT_GFX_H_
00021 #define _ADAFRUIT_GFX_H_
00022 
00023 #include "Adafruit_GFX_Config.h"
00024 
00025 static inline void swap(int16_t &a, int16_t &b)
00026 {
00027     int16_t t = a;
00028     
00029     a = b;
00030     b = t;
00031 }
00032 
00033 #ifndef _BV
00034 #define _BV(bit) (1<<(bit))
00035 #endif
00036 
00037 #define BLACK 0
00038 #define WHITE 1
00039 
00040 /**
00041  * This is a Text and Graphics element drawing class.
00042  * These functions draw to the display buffer.
00043  *
00044  * Display drivers should be derived from here.
00045  * The Display drivers push the display buffer to the
00046  * hardware based on application control.
00047  *
00048  */
00049 class Adafruit_GFX : public Stream
00050 {
00051  public:
00052     Adafruit_GFX(int16_t w, int16_t h)
00053         : _rawWidth(w)
00054         , _rawHeight(h)
00055         , _width(w)
00056         , _height(h)
00057         , cursor_x(0)
00058         , cursor_y(0)
00059         , textcolor(WHITE)
00060         , textbgcolor(BLACK)
00061         , textsize(1)
00062         , rotation(0)
00063         , wrap(true)
00064         {};
00065 
00066     /// Paint one BLACK or WHITE pixel in the display buffer
00067     // this must be defined by the subclass
00068     virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
00069     // this is optional
00070     virtual void invertDisplay(bool i) {};
00071     
00072     // Stream implementation - provides printf() interface
00073     // You would otherwise be forced to use writeChar()
00074     virtual int _putc(int value) { return writeChar(value); };
00075     virtual int _getc() { return -1; };
00076 
00077 #ifdef GFX_WANT_ABSTRACTS
00078     // these are 'generic' drawing functions, so we can share them!
00079     
00080     /** Draw a Horizontal Line
00081      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00082      */
00083     virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
00084     /** Draw a rectangle
00085      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00086      */
00087     virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
00088     /** Fill the entire display
00089      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00090      */
00091     virtual void fillScreen(uint16_t color);
00092 
00093     /** Draw a circle
00094      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00095      */
00096     void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
00097     void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
00098     
00099     /** Draw and fill a circle
00100      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00101      */
00102     void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
00103     void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
00104 
00105     /** Draw a triangle
00106      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00107      */
00108     void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
00109     /** Draw and fill a triangle
00110      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00111      */
00112     void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
00113     
00114     /** Draw a rounded rectangle
00115      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00116      */
00117     void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
00118     /** Draw and fill a rounded rectangle
00119      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00120      */
00121     void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
00122     /** Draw a bitmap
00123      * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
00124      */
00125     void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
00126 #endif
00127 
00128 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
00129     /** Draw a line
00130      * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
00131      */
00132     virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
00133     /** Draw a vertical line
00134      * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
00135      */
00136     virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
00137     /** Draw and fill a rectangle
00138      * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
00139      */
00140     virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
00141 #endif
00142 
00143     /// Draw a text character at a specified pixel location
00144     void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
00145     /// Draw a text character at the text cursor location
00146     size_t writeChar(uint8_t);
00147 
00148     /// Get the width of the display in pixels
00149     inline int16_t width(void) { return _width; };
00150     /// Get the height of the display in pixels
00151     inline int16_t height(void) { return _height; };
00152 
00153     /// Set the text cursor location, based on the size of the text
00154     inline void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; };
00155 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
00156     /** Set the size of the text to be drawn
00157      * @note Make sure to enable either GFX_SIZEABLE_TEXT or GFX_WANT_ABSTRACTS
00158      */
00159     inline void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; };
00160 #endif
00161     /// Set the text foreground and background colors to be the same
00162     inline void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; }
00163     /// Set the text foreground and background colors independantly
00164     inline void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; };
00165     /// Set text wraping mode true or false
00166     inline void setTextWrap(bool w) { wrap = w; };
00167 
00168     /// Set the display rotation, 1, 2, 3, or 4
00169     void setRotation(uint8_t r);
00170     /// Get the current rotation
00171     inline uint8_t getRotation(void) { rotation %= 4; return rotation; };
00172 
00173 protected:
00174     int16_t  _rawWidth, _rawHeight;   // this is the 'raw' display w/h - never changes
00175     int16_t  _width, _height; // dependent on rotation
00176     int16_t  cursor_x, cursor_y;
00177     uint16_t textcolor, textbgcolor;
00178     uint8_t  textsize;
00179     uint8_t  rotation;
00180     bool  wrap; // If set, 'wrap' text at right edge of display
00181 };
00182 
00183 #endif