TextDisplay.h@0:ea1b1135bb4e, 2012-04-10 (annotated)
- Committer:
- apm_litoral
- Date:
- Tue Apr 10 03:33:49 2012 +0000
- Revision:
- 0:ea1b1135bb4e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
apm_litoral | 0:ea1b1135bb4e | 1 | /* mbed TextDisplay Library Base Class |
apm_litoral | 0:ea1b1135bb4e | 2 | * Copyright (c) 2007-2009 sford |
apm_litoral | 0:ea1b1135bb4e | 3 | * Released under the MIT License: http://mbed.org/license/mit |
apm_litoral | 0:ea1b1135bb4e | 4 | * |
apm_litoral | 0:ea1b1135bb4e | 5 | * A common base class for Text displays |
apm_litoral | 0:ea1b1135bb4e | 6 | * To port a new display, derive from this class and implement |
apm_litoral | 0:ea1b1135bb4e | 7 | * the constructor (setup the display), character (put a character |
apm_litoral | 0:ea1b1135bb4e | 8 | * at a location), rows and columns (number of rows/cols) functions. |
apm_litoral | 0:ea1b1135bb4e | 9 | * Everything else (locate, printf, putc, cls) will come for free |
apm_litoral | 0:ea1b1135bb4e | 10 | * |
apm_litoral | 0:ea1b1135bb4e | 11 | * The model is the display will wrap at the right and bottom, so you can |
apm_litoral | 0:ea1b1135bb4e | 12 | * keep writing and will always get valid characters. The location is |
apm_litoral | 0:ea1b1135bb4e | 13 | * maintained internally to the class to make this easy |
apm_litoral | 0:ea1b1135bb4e | 14 | */ |
apm_litoral | 0:ea1b1135bb4e | 15 | |
apm_litoral | 0:ea1b1135bb4e | 16 | #ifndef MBED_TEXTDISPLAY_H |
apm_litoral | 0:ea1b1135bb4e | 17 | #define MBED_TEXTDISPLAY_H |
apm_litoral | 0:ea1b1135bb4e | 18 | |
apm_litoral | 0:ea1b1135bb4e | 19 | #include "mbed.h" |
apm_litoral | 0:ea1b1135bb4e | 20 | |
apm_litoral | 0:ea1b1135bb4e | 21 | class TextDisplay : public Stream { |
apm_litoral | 0:ea1b1135bb4e | 22 | public: |
apm_litoral | 0:ea1b1135bb4e | 23 | |
apm_litoral | 0:ea1b1135bb4e | 24 | // functions needing implementation in derived implementation class |
apm_litoral | 0:ea1b1135bb4e | 25 | /** Create a TextDisplay interface |
apm_litoral | 0:ea1b1135bb4e | 26 | * |
apm_litoral | 0:ea1b1135bb4e | 27 | * @param name The name used in the path to access the strean through the filesystem |
apm_litoral | 0:ea1b1135bb4e | 28 | */ |
apm_litoral | 0:ea1b1135bb4e | 29 | TextDisplay(const char *name = NULL); |
apm_litoral | 0:ea1b1135bb4e | 30 | |
apm_litoral | 0:ea1b1135bb4e | 31 | /** output a character at the given position |
apm_litoral | 0:ea1b1135bb4e | 32 | * |
apm_litoral | 0:ea1b1135bb4e | 33 | * @param column column where charater must be written |
apm_litoral | 0:ea1b1135bb4e | 34 | * @param row where character must be written |
apm_litoral | 0:ea1b1135bb4e | 35 | * @param c the character to be written to the TextDisplay |
apm_litoral | 0:ea1b1135bb4e | 36 | */ |
apm_litoral | 0:ea1b1135bb4e | 37 | virtual void character(int column, int row, int c) = 0; |
apm_litoral | 0:ea1b1135bb4e | 38 | |
apm_litoral | 0:ea1b1135bb4e | 39 | /** return number if rows on TextDisplay |
apm_litoral | 0:ea1b1135bb4e | 40 | * @result number of rows |
apm_litoral | 0:ea1b1135bb4e | 41 | */ |
apm_litoral | 0:ea1b1135bb4e | 42 | virtual int rows() = 0; |
apm_litoral | 0:ea1b1135bb4e | 43 | |
apm_litoral | 0:ea1b1135bb4e | 44 | /** return number if columns on TextDisplay |
apm_litoral | 0:ea1b1135bb4e | 45 | * @result number of rows |
apm_litoral | 0:ea1b1135bb4e | 46 | */ |
apm_litoral | 0:ea1b1135bb4e | 47 | virtual int columns() = 0; |
apm_litoral | 0:ea1b1135bb4e | 48 | |
apm_litoral | 0:ea1b1135bb4e | 49 | // functions that come for free, but can be overwritten |
apm_litoral | 0:ea1b1135bb4e | 50 | |
apm_litoral | 0:ea1b1135bb4e | 51 | /** redirect output from a stream (stoud, sterr) to display |
apm_litoral | 0:ea1b1135bb4e | 52 | * @param stream stream that shall be redirected to the TextDisplay |
apm_litoral | 0:ea1b1135bb4e | 53 | */ |
apm_litoral | 0:ea1b1135bb4e | 54 | virtual bool claim (FILE *stream); |
apm_litoral | 0:ea1b1135bb4e | 55 | |
apm_litoral | 0:ea1b1135bb4e | 56 | /** clear screen |
apm_litoral | 0:ea1b1135bb4e | 57 | */ |
apm_litoral | 0:ea1b1135bb4e | 58 | virtual void cls(); |
apm_litoral | 0:ea1b1135bb4e | 59 | virtual void locate(int column, int row); |
apm_litoral | 0:ea1b1135bb4e | 60 | virtual void foreground(uint16_t colour); |
apm_litoral | 0:ea1b1135bb4e | 61 | virtual void background(uint16_t colour); |
apm_litoral | 0:ea1b1135bb4e | 62 | // putc (from Stream) |
apm_litoral | 0:ea1b1135bb4e | 63 | // printf (from Stream) |
apm_litoral | 0:ea1b1135bb4e | 64 | |
apm_litoral | 0:ea1b1135bb4e | 65 | protected: |
apm_litoral | 0:ea1b1135bb4e | 66 | |
apm_litoral | 0:ea1b1135bb4e | 67 | virtual int _putc(int value); |
apm_litoral | 0:ea1b1135bb4e | 68 | virtual int _getc(); |
apm_litoral | 0:ea1b1135bb4e | 69 | |
apm_litoral | 0:ea1b1135bb4e | 70 | // character location |
apm_litoral | 0:ea1b1135bb4e | 71 | uint16_t _column; |
apm_litoral | 0:ea1b1135bb4e | 72 | uint16_t _row; |
apm_litoral | 0:ea1b1135bb4e | 73 | |
apm_litoral | 0:ea1b1135bb4e | 74 | // colours |
apm_litoral | 0:ea1b1135bb4e | 75 | uint16_t _foreground; |
apm_litoral | 0:ea1b1135bb4e | 76 | uint16_t _background; |
apm_litoral | 0:ea1b1135bb4e | 77 | char *_path; |
apm_litoral | 0:ea1b1135bb4e | 78 | }; |
apm_litoral | 0:ea1b1135bb4e | 79 | |
apm_litoral | 0:ea1b1135bb4e | 80 | #endif |