KSM edits to RA8875

Dependents:   Liz_Test_Code

Committer:
kerrysmartin
Date:
Thu Jul 11 14:02:46 2019 +0000
Revision:
177:8620cdfcdbf2
Parent:
167:8aa3fb2a5a31
Initial check in

Who changed what in which revision?

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