Forked para SNOCC
Fork of RA8875 by
TextDisplay.h@76:c981284eb513, 2014-11-28 (annotated)
- Committer:
- WiredHome
- Date:
- Fri Nov 28 22:53:35 2014 +0000
- Revision:
- 76:c981284eb513
- Parent:
- 61:8f3153bf0baa
- Child:
- 103:7e0464ca6c5c
Second pass - documentation improvements only.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:de9d1462a835 | 1 | /* mbed TextDisplay Library Base Class |
dreschpe | 0:de9d1462a835 | 2 | * Copyright (c) 2007-2009 sford |
dreschpe | 0:de9d1462a835 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
dreschpe | 0:de9d1462a835 | 4 | * |
dreschpe | 0:de9d1462a835 | 5 | * A common base class for Text displays |
dreschpe | 0:de9d1462a835 | 6 | * To port a new display, derive from this class and implement |
dreschpe | 0:de9d1462a835 | 7 | * the constructor (setup the display), character (put a character |
dreschpe | 0:de9d1462a835 | 8 | * at a location), rows and columns (number of rows/cols) functions. |
dreschpe | 0:de9d1462a835 | 9 | * Everything else (locate, printf, putc, cls) will come for free |
dreschpe | 0:de9d1462a835 | 10 | * |
dreschpe | 0:de9d1462a835 | 11 | * The model is the display will wrap at the right and bottom, so you can |
WiredHome | 19:3f82c1161fd2 | 12 | * keep writing and will always get valid characters. The location is |
dreschpe | 0:de9d1462a835 | 13 | * maintained internally to the class to make this easy |
dreschpe | 0:de9d1462a835 | 14 | */ |
dreschpe | 0:de9d1462a835 | 15 | |
dreschpe | 0:de9d1462a835 | 16 | #ifndef MBED_TEXTDISPLAY_H |
dreschpe | 0:de9d1462a835 | 17 | #define MBED_TEXTDISPLAY_H |
dreschpe | 0:de9d1462a835 | 18 | |
dreschpe | 0:de9d1462a835 | 19 | #include "mbed.h" |
dreschpe | 0:de9d1462a835 | 20 | |
WiredHome | 31:c72e12cd5c67 | 21 | #include "DisplayDefs.h" |
WiredHome | 19:3f82c1161fd2 | 22 | |
WiredHome | 37:f19b7e7449dc | 23 | /// A text display class that supports character based |
WiredHome | 37:f19b7e7449dc | 24 | /// presentation. |
WiredHome | 37:f19b7e7449dc | 25 | /// |
WiredHome | 19:3f82c1161fd2 | 26 | class TextDisplay : public Stream |
WiredHome | 19:3f82c1161fd2 | 27 | { |
dreschpe | 0:de9d1462a835 | 28 | public: |
dreschpe | 0:de9d1462a835 | 29 | |
WiredHome | 19:3f82c1161fd2 | 30 | // functions needing implementation in derived implementation class |
WiredHome | 37:f19b7e7449dc | 31 | /// Create a TextDisplay interface |
WiredHome | 37:f19b7e7449dc | 32 | /// |
WiredHome | 37:f19b7e7449dc | 33 | /// @param name The name used in the path to access the display through |
WiredHome | 37:f19b7e7449dc | 34 | /// the stdio stream. |
WiredHome | 37:f19b7e7449dc | 35 | /// |
dreschpe | 0:de9d1462a835 | 36 | TextDisplay(const char *name = NULL); |
dreschpe | 0:de9d1462a835 | 37 | |
WiredHome | 37:f19b7e7449dc | 38 | /// output a character at the given position |
WiredHome | 37:f19b7e7449dc | 39 | /// |
WiredHome | 37:f19b7e7449dc | 40 | /// @note this method may be overridden in a derived class. |
WiredHome | 37:f19b7e7449dc | 41 | /// |
WiredHome | 76:c981284eb513 | 42 | /// @param[in] x position in pixels |
WiredHome | 76:c981284eb513 | 43 | /// @param[in] y position in pixels |
WiredHome | 76:c981284eb513 | 44 | /// @param[in] c the character to be written to the TextDisplay |
WiredHome | 37:f19b7e7449dc | 45 | /// @returns number of pixels to advance the cursor which could be the cell width |
WiredHome | 37:f19b7e7449dc | 46 | /// for non-proportional characters, or the actual character width for |
WiredHome | 37:f19b7e7449dc | 47 | /// proportional characters. |
WiredHome | 37:f19b7e7449dc | 48 | /// |
WiredHome | 29:422616aa04bd | 49 | virtual int character(int x, int y, int c) = 0; |
dreschpe | 0:de9d1462a835 | 50 | |
WiredHome | 37:f19b7e7449dc | 51 | /// return number of rows on TextDisplay |
WiredHome | 37:f19b7e7449dc | 52 | /// |
WiredHome | 37:f19b7e7449dc | 53 | /// @note this method may be overridden in a derived class. |
WiredHome | 37:f19b7e7449dc | 54 | /// |
WiredHome | 37:f19b7e7449dc | 55 | /// @returns number of text rows for the display for the currently |
WiredHome | 37:f19b7e7449dc | 56 | /// active font. |
WiredHome | 37:f19b7e7449dc | 57 | /// |
dreschpe | 0:de9d1462a835 | 58 | virtual int rows() = 0; |
dreschpe | 0:de9d1462a835 | 59 | |
WiredHome | 37:f19b7e7449dc | 60 | /// return number if columns on TextDisplay |
WiredHome | 37:f19b7e7449dc | 61 | /// |
WiredHome | 37:f19b7e7449dc | 62 | /// @note this method may be overridden in a derived class. |
WiredHome | 37:f19b7e7449dc | 63 | /// |
WiredHome | 37:f19b7e7449dc | 64 | /// @returns number of text rows for the display for the currently |
WiredHome | 37:f19b7e7449dc | 65 | /// active font. |
WiredHome | 37:f19b7e7449dc | 66 | /// |
dreschpe | 0:de9d1462a835 | 67 | virtual int columns() = 0; |
WiredHome | 19:3f82c1161fd2 | 68 | |
dreschpe | 0:de9d1462a835 | 69 | // functions that come for free, but can be overwritten |
dreschpe | 0:de9d1462a835 | 70 | |
WiredHome | 37:f19b7e7449dc | 71 | /// redirect output from a stream (stoud, sterr) to display |
WiredHome | 37:f19b7e7449dc | 72 | /// |
WiredHome | 37:f19b7e7449dc | 73 | /// @note this method may be overridden in a derived class. |
WiredHome | 37:f19b7e7449dc | 74 | /// |
WiredHome | 76:c981284eb513 | 75 | /// @param[in] stream that shall be redirected to the TextDisplay |
WiredHome | 37:f19b7e7449dc | 76 | /// @returns true if the claim succeeded. |
WiredHome | 37:f19b7e7449dc | 77 | /// |
dreschpe | 0:de9d1462a835 | 78 | virtual bool claim (FILE *stream); |
dreschpe | 0:de9d1462a835 | 79 | |
WiredHome | 37:f19b7e7449dc | 80 | /// clear screen |
WiredHome | 37:f19b7e7449dc | 81 | /// |
WiredHome | 37:f19b7e7449dc | 82 | /// @note this method may be overridden in a derived class. |
WiredHome | 76:c981284eb513 | 83 | /// |
WiredHome | 76:c981284eb513 | 84 | /// @param[in] layers is ignored, but supports maintaining the same |
WiredHome | 61:8f3153bf0baa | 85 | /// API for the graphics layer. |
WiredHome | 37:f19b7e7449dc | 86 | /// @returns error code. |
WiredHome | 37:f19b7e7449dc | 87 | /// |
WiredHome | 61:8f3153bf0baa | 88 | virtual RetCode_t cls(uint16_t layers = 0) = 0; |
WiredHome | 37:f19b7e7449dc | 89 | |
WiredHome | 37:f19b7e7449dc | 90 | /// locate the cursor at a character position. |
WiredHome | 37:f19b7e7449dc | 91 | /// |
WiredHome | 37:f19b7e7449dc | 92 | /// Based on the currently active font, locate the cursor on screen. |
WiredHome | 37:f19b7e7449dc | 93 | /// |
WiredHome | 37:f19b7e7449dc | 94 | /// @note this method may be overridden in a derived class. |
WiredHome | 37:f19b7e7449dc | 95 | /// |
WiredHome | 76:c981284eb513 | 96 | /// @param[in] column is the horizontal offset from the left side. |
WiredHome | 76:c981284eb513 | 97 | /// @param[in] row is the vertical offset from the top. |
WiredHome | 37:f19b7e7449dc | 98 | /// @returns error code. |
WiredHome | 37:f19b7e7449dc | 99 | /// |
WiredHome | 37:f19b7e7449dc | 100 | virtual RetCode_t locate(textloc_t column, textloc_t row) = 0; |
WiredHome | 37:f19b7e7449dc | 101 | |
WiredHome | 37:f19b7e7449dc | 102 | /// set the foreground color |
WiredHome | 37:f19b7e7449dc | 103 | /// |
WiredHome | 37:f19b7e7449dc | 104 | /// @note this method may be overridden in a derived class. |
WiredHome | 37:f19b7e7449dc | 105 | /// |
WiredHome | 76:c981284eb513 | 106 | /// @param[in] color is color to use for foreground drawing. |
WiredHome | 37:f19b7e7449dc | 107 | /// @returns error code. |
WiredHome | 37:f19b7e7449dc | 108 | /// |
WiredHome | 37:f19b7e7449dc | 109 | virtual RetCode_t foreground(color_t color) = 0; |
WiredHome | 37:f19b7e7449dc | 110 | |
WiredHome | 37:f19b7e7449dc | 111 | /// set the background color |
WiredHome | 37:f19b7e7449dc | 112 | /// |
WiredHome | 37:f19b7e7449dc | 113 | /// @note this method may be overridden in a derived class. |
WiredHome | 37:f19b7e7449dc | 114 | /// |
WiredHome | 76:c981284eb513 | 115 | /// @param[in] color is color to use for background drawing. |
WiredHome | 37:f19b7e7449dc | 116 | /// @returns error code. |
WiredHome | 37:f19b7e7449dc | 117 | /// |
WiredHome | 37:f19b7e7449dc | 118 | virtual RetCode_t background(color_t color) = 0; |
dreschpe | 0:de9d1462a835 | 119 | // putc (from Stream) |
dreschpe | 0:de9d1462a835 | 120 | // printf (from Stream) |
dreschpe | 0:de9d1462a835 | 121 | |
WiredHome | 19:3f82c1161fd2 | 122 | protected: |
dreschpe | 0:de9d1462a835 | 123 | virtual int _putc(int value); |
dreschpe | 0:de9d1462a835 | 124 | virtual int _getc(); |
dreschpe | 0:de9d1462a835 | 125 | |
dreschpe | 0:de9d1462a835 | 126 | // character location |
dreschpe | 0:de9d1462a835 | 127 | uint16_t _column; |
dreschpe | 0:de9d1462a835 | 128 | uint16_t _row; |
dreschpe | 0:de9d1462a835 | 129 | |
WiredHome | 33:b6b710758ab3 | 130 | // colors |
WiredHome | 37:f19b7e7449dc | 131 | color_t _foreground; |
WiredHome | 37:f19b7e7449dc | 132 | color_t _background; |
dreschpe | 0:de9d1462a835 | 133 | char *_path; |
dreschpe | 0:de9d1462a835 | 134 | }; |
dreschpe | 0:de9d1462a835 | 135 | |
dreschpe | 0:de9d1462a835 | 136 | #endif |