Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
abstractarduboy.h@1:c53e766082b4, 2017-01-06 (annotated)
- Committer:
- lmayencou
- Date:
- Fri Jan 06 22:10:20 2017 +0000
- Revision:
- 1:c53e766082b4
- Child:
- 3:df305b314063
display circle and hello on SPI screen !
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lmayencou | 1:c53e766082b4 | 1 | #ifndef ABSTRACTARDUBOY_H |
lmayencou | 1:c53e766082b4 | 2 | #define ABSTRACTARDUBOY_H |
lmayencou | 1:c53e766082b4 | 3 | |
lmayencou | 1:c53e766082b4 | 4 | #include <stdint.h> |
lmayencou | 1:c53e766082b4 | 5 | #include "glcdfont.h" |
lmayencou | 1:c53e766082b4 | 6 | |
lmayencou | 1:c53e766082b4 | 7 | #define WIDTH 128 |
lmayencou | 1:c53e766082b4 | 8 | #define HEIGHT 64 |
lmayencou | 1:c53e766082b4 | 9 | |
lmayencou | 1:c53e766082b4 | 10 | #define WHITE 1 |
lmayencou | 1:c53e766082b4 | 11 | #define BLACK 0 |
lmayencou | 1:c53e766082b4 | 12 | |
lmayencou | 1:c53e766082b4 | 13 | #define COLUMN_ADDRESS_END (WIDTH - 1) & 0x7F |
lmayencou | 1:c53e766082b4 | 14 | #define PAGE_ADDRESS_END ((HEIGHT/8)-1) & 0x07 |
lmayencou | 1:c53e766082b4 | 15 | |
lmayencou | 1:c53e766082b4 | 16 | class AbstractArduboy |
lmayencou | 1:c53e766082b4 | 17 | { |
lmayencou | 1:c53e766082b4 | 18 | public: |
lmayencou | 1:c53e766082b4 | 19 | AbstractArduboy(); |
lmayencou | 1:c53e766082b4 | 20 | |
lmayencou | 1:c53e766082b4 | 21 | // pure virtual function |
lmayencou | 1:c53e766082b4 | 22 | virtual void start() = 0; |
lmayencou | 1:c53e766082b4 | 23 | |
lmayencou | 1:c53e766082b4 | 24 | virtual long getTime() = 0; |
lmayencou | 1:c53e766082b4 | 25 | |
lmayencou | 1:c53e766082b4 | 26 | virtual void LCDDataMode() = 0; |
lmayencou | 1:c53e766082b4 | 27 | virtual void LCDCommandMode() = 0; |
lmayencou | 1:c53e766082b4 | 28 | virtual void drawScreen(const unsigned char *image) = 0; |
lmayencou | 1:c53e766082b4 | 29 | |
lmayencou | 1:c53e766082b4 | 30 | virtual uint8_t getInput() = 0; |
lmayencou | 1:c53e766082b4 | 31 | |
lmayencou | 1:c53e766082b4 | 32 | // virtual |
lmayencou | 1:c53e766082b4 | 33 | virtual void idle(); |
lmayencou | 1:c53e766082b4 | 34 | virtual void saveMuchPower(); |
lmayencou | 1:c53e766082b4 | 35 | |
lmayencou | 1:c53e766082b4 | 36 | // frame management |
lmayencou | 1:c53e766082b4 | 37 | void setFrameRate(uint8_t rate); |
lmayencou | 1:c53e766082b4 | 38 | bool nextFrame(); |
lmayencou | 1:c53e766082b4 | 39 | bool everyXFrames(uint8_t frames); |
lmayencou | 1:c53e766082b4 | 40 | |
lmayencou | 1:c53e766082b4 | 41 | // info |
lmayencou | 1:c53e766082b4 | 42 | int cpuLoad(); |
lmayencou | 1:c53e766082b4 | 43 | |
lmayencou | 1:c53e766082b4 | 44 | // buttons |
lmayencou | 1:c53e766082b4 | 45 | void poll(); |
lmayencou | 1:c53e766082b4 | 46 | bool pressed(uint8_t buttons); |
lmayencou | 1:c53e766082b4 | 47 | bool notPressed(uint8_t buttons); |
lmayencou | 1:c53e766082b4 | 48 | bool justPressed(uint8_t buttons); |
lmayencou | 1:c53e766082b4 | 49 | |
lmayencou | 1:c53e766082b4 | 50 | // graphics |
lmayencou | 1:c53e766082b4 | 51 | void blank(); |
lmayencou | 1:c53e766082b4 | 52 | void clearDisplay(); |
lmayencou | 1:c53e766082b4 | 53 | void display(); |
lmayencou | 1:c53e766082b4 | 54 | void drawPixel(int x, int y, uint8_t color); |
lmayencou | 1:c53e766082b4 | 55 | uint8_t getPixel(uint8_t x, uint8_t y); |
lmayencou | 1:c53e766082b4 | 56 | void drawCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color); |
lmayencou | 1:c53e766082b4 | 57 | void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint8_t color); |
lmayencou | 1:c53e766082b4 | 58 | void fillCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color); |
lmayencou | 1:c53e766082b4 | 59 | void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint8_t color); |
lmayencou | 1:c53e766082b4 | 60 | void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color); |
lmayencou | 1:c53e766082b4 | 61 | void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color); |
lmayencou | 1:c53e766082b4 | 62 | void drawFastVLine(int16_t x, int16_t y, int16_t h, uint8_t color); |
lmayencou | 1:c53e766082b4 | 63 | void drawFastHLine(int16_t x, int16_t y, int16_t w, uint8_t color); |
lmayencou | 1:c53e766082b4 | 64 | void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color); |
lmayencou | 1:c53e766082b4 | 65 | void fillScreen(uint8_t color); |
lmayencou | 1:c53e766082b4 | 66 | void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint8_t color); |
lmayencou | 1:c53e766082b4 | 67 | void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint8_t color); |
lmayencou | 1:c53e766082b4 | 68 | void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint8_t color); |
lmayencou | 1:c53e766082b4 | 69 | void drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap, uint8_t color); |
lmayencou | 1:c53e766082b4 | 70 | |
lmayencou | 1:c53e766082b4 | 71 | /// Draw a text character at a specified pixel location |
lmayencou | 1:c53e766082b4 | 72 | void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size); |
lmayencou | 1:c53e766082b4 | 73 | /// Draw a text character at the text cursor location |
lmayencou | 1:c53e766082b4 | 74 | uint8_t writeChar(uint8_t); |
lmayencou | 1:c53e766082b4 | 75 | /// Set the text cursor location, based on the size of the text |
lmayencou | 1:c53e766082b4 | 76 | inline void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; }; |
lmayencou | 1:c53e766082b4 | 77 | |
lmayencou | 1:c53e766082b4 | 78 | static inline void swap(int16_t &a, int16_t &b); |
lmayencou | 1:c53e766082b4 | 79 | |
lmayencou | 1:c53e766082b4 | 80 | protected: |
lmayencou | 1:c53e766082b4 | 81 | uint8_t frameRate; |
lmayencou | 1:c53e766082b4 | 82 | uint16_t frameCount; |
lmayencou | 1:c53e766082b4 | 83 | uint8_t eachFrameMillis; |
lmayencou | 1:c53e766082b4 | 84 | long lastFrameStart; |
lmayencou | 1:c53e766082b4 | 85 | long nextFrameStart ; |
lmayencou | 1:c53e766082b4 | 86 | bool post_render; |
lmayencou | 1:c53e766082b4 | 87 | uint8_t lastFrameDurationMs; |
lmayencou | 1:c53e766082b4 | 88 | |
lmayencou | 1:c53e766082b4 | 89 | uint8_t currentButtonState; |
lmayencou | 1:c53e766082b4 | 90 | uint8_t previousButtonState; |
lmayencou | 1:c53e766082b4 | 91 | |
lmayencou | 1:c53e766082b4 | 92 | uint8_t sBuffer[(HEIGHT * WIDTH) / 8]; |
lmayencou | 1:c53e766082b4 | 93 | |
lmayencou | 1:c53e766082b4 | 94 | int16_t cursor_x, cursor_y; |
lmayencou | 1:c53e766082b4 | 95 | uint16_t textcolor, textbgcolor; |
lmayencou | 1:c53e766082b4 | 96 | uint8_t textsize; |
lmayencou | 1:c53e766082b4 | 97 | uint8_t rotation; |
lmayencou | 1:c53e766082b4 | 98 | bool wrap; // If set, 'wrap' text at right edge of display |
lmayencou | 1:c53e766082b4 | 99 | }; |
lmayencou | 1:c53e766082b4 | 100 | |
lmayencou | 1:c53e766082b4 | 101 | #endif // ABSTRACTARDUBOY_H |