Sun, 25 Oct 2020 23:00:17 +0100
Add support for the shift flag
5 | 1 | /* mbed TextDisplay Library Base Class |
2 | * Copyright (c) 2007-2009 sford | |
3 | * Released under the MIT License: http://mbed.org/license/mit | |
4 | * | |
5 | * A common base class for Text displays | |
6 | * To port a new display, derive from this class and implement | |
7 | * the constructor (setup the display), character (put a character | |
8 | * at a location), rows and columns (number of rows/cols) functions. | |
9 | * Everything else (locate, printf, putc, cls) will come for free | |
10 | * | |
11 | * The model is the display will wrap at the right and bottom, so you can | |
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
5
diff
changeset
|
12 | * keep writing and will always get valid characters. The location is |
5 | 13 | * maintained internally to the class to make this easy |
14 | */ | |
15 | ||
16 | #ifndef MBED_TEXTDISPLAY_H | |
17 | #define MBED_TEXTDISPLAY_H | |
18 | ||
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
5
diff
changeset
|
19 | #include <mbed.h> |
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
5
diff
changeset
|
20 | #include <Stream.h> |
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
5
diff
changeset
|
21 | |
5 | 22 | |
23 | /** A common base class for Text displays | |
24 | */ | |
25 | class TextDisplay : public Stream { | |
26 | public: | |
27 | ||
28 | // functions needing implementation in derived implementation class | |
29 | // ---------------------------------------------------------------- | |
30 | /** Create a TextDisplay interface | |
31 | * @param name The name used in the path to access the strean through the filesystem | |
32 | */ | |
33 | TextDisplay(const char *name = NULL); | |
34 | ||
35 | /** output a character at the given position | |
36 | * | |
37 | * @param column column where charater must be written | |
38 | * @param row where character must be written | |
39 | * @param c the character to be written to the TextDisplay | |
40 | * @note this method may be overridden in a derived class. | |
41 | */ | |
42 | virtual void character(int column, int row, int c) = 0; | |
43 | ||
44 | /** return number of rows on TextDisplay | |
45 | * @result number of rows | |
46 | * @note this method must be supported in the derived class. | |
47 | */ | |
48 | virtual int rows() = 0; | |
49 | ||
50 | /** return number of columns on TextDisplay | |
51 | * @result number of columns | |
52 | * @note this method must be supported in the derived class. | |
53 | */ | |
54 | virtual int columns() = 0; | |
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
5
diff
changeset
|
55 | |
5 | 56 | // functions that come for free, but can be overwritten |
57 | // ---------------------------------------------------- | |
58 | /** redirect output from a stream (stoud, sterr) to display | |
59 | * @param stream stream that shall be redirected to the TextDisplay | |
60 | * @note this method may be overridden in a derived class. | |
61 | * @returns true if the claim succeeded. | |
62 | */ | |
63 | virtual bool claim (FILE *stream); | |
64 | ||
65 | /** clear the entire screen | |
66 | * @note this method may be overridden in a derived class. | |
67 | */ | |
68 | virtual void cls(); | |
69 | ||
70 | /** locate the cursor at a character position. | |
71 | * Based on the currently active font, locate the cursor on screen. | |
72 | * @note this method may be overridden in a derived class. | |
73 | * @param column is the horizontal offset from the left side. | |
74 | * @param row is the vertical offset from the top. | |
75 | */ | |
76 | virtual void locate(int column, int row); | |
77 | ||
78 | /** set the foreground color | |
79 | * @note this method may be overridden in a derived class. | |
80 | * @param color is color to use for foreground drawing. | |
81 | */ | |
82 | virtual void foreground(uint16_t colour); | |
83 | ||
84 | /** set the background color | |
85 | * @note this method may be overridden in a derived class. | |
86 | * @param color is color to use for background drawing. | |
87 | */ | |
88 | virtual void background(uint16_t colour); | |
89 | ||
90 | // putc (from Stream) | |
91 | // printf (from Stream) | |
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
5
diff
changeset
|
92 | |
5 | 93 | protected: |
94 | ||
95 | virtual int _putc(int value); | |
96 | virtual int _getc(); | |
97 | ||
98 | // character location | |
99 | int _column; | |
100 | int _row; | |
101 | ||
102 | // colours | |
103 | volatile uint16_t _foreground; | |
104 | volatile uint16_t _background; | |
105 | char *_path; | |
106 | }; | |
107 | ||
108 | #endif |