Mon, 23 Nov 2020 21:55:40 +0100
Small fixes in main
- toggle the shift indicator when the key is pressed while already on
- attempt to fix the restart-while-shuting-down bug
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); | |
55 | 83 | virtual uint16_t foreground() {return _foreground;}; |
5 | 84 | |
85 | /** set the background color | |
86 | * @note this method may be overridden in a derived class. | |
87 | * @param color is color to use for background drawing. | |
88 | */ | |
89 | virtual void background(uint16_t colour); | |
55 | 90 | virtual uint16_t background() {return _background;}; |
5 | 91 | |
92 | // putc (from Stream) | |
93 | // printf (from Stream) | |
28
424d792fea4f
compile for nucleo f446re & f303re with mbed 6
David Douard <david.douard@sdfa3.org>
parents:
5
diff
changeset
|
94 | |
5 | 95 | protected: |
96 | ||
97 | virtual int _putc(int value); | |
98 | virtual int _getc(); | |
99 | ||
100 | // character location | |
101 | int _column; | |
102 | int _row; | |
103 | ||
104 | // colours | |
105 | volatile uint16_t _foreground; | |
106 | volatile uint16_t _background; | |
107 | char *_path; | |
108 | }; | |
109 | ||
110 | #endif |