Rev 7 | Rev 10 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* |
2 | * displayclass.H |
||
3 | * |
||
4 | * Created on: 31 Oct 2020 |
||
5 | * Author: mike |
||
6 | */ |
||
7 | |||
8 | #pragma once |
||
9 | #include <cstdint> |
||
3 | mjames | 10 | #include "libOLED/fontclass.H" |
2 | mjames | 11 | |
4 | mjames | 12 | inline int constexpr |
13 | dataSize (int const width, int const height) |
||
2 | mjames | 14 | { |
4 | mjames | 15 | return (width * height / 8); |
2 | mjames | 16 | } |
17 | |||
18 | enum colour_t |
||
19 | { |
||
9 | mjames | 20 | BLACK, /* and 0, invert 0 */ |
21 | WHITE, /* and 0, invert 1 */ |
||
7 | mjames | 22 | OVERLAY, /* and 1, invert 0 */ |
9 | mjames | 23 | INVERT, /* and 1, invert 1 */ |
2 | mjames | 24 | }; |
25 | |||
26 | class display_t |
||
27 | { |
||
28 | public: |
||
4 | mjames | 29 | display_t (int const width, int const height, int const ramwidth, |
30 | uint8_t *const data); |
||
2 | mjames | 31 | |
4 | mjames | 32 | virtual |
33 | ~display_t (); |
||
2 | mjames | 34 | |
4 | mjames | 35 | uint8_t |
36 | getRotation (); |
||
37 | int16_t |
||
38 | width (); |
||
39 | int16_t |
||
40 | height (); |
||
2 | mjames | 41 | |
7 | mjames | 42 | // common hardware reset . |
9 | mjames | 43 | void |
44 | reset (); |
||
7 | mjames | 45 | |
4 | mjames | 46 | void |
47 | init (); |
||
2 | mjames | 48 | |
6 | mjames | 49 | /// \brief Clear display to colour |
4 | mjames | 50 | void |
6 | mjames | 51 | clearDisplay (colour_t colour = colour_t::BLACK); |
4 | mjames | 52 | void |
53 | invertDisplay (uint8_t i); |
||
54 | void |
||
55 | display (); |
||
2 | mjames | 56 | |
4 | mjames | 57 | void |
58 | startscrollright (uint8_t start, uint8_t stop); |
||
59 | void |
||
60 | startscrollleft (uint8_t start, uint8_t stop); |
||
2 | mjames | 61 | |
4 | mjames | 62 | void |
63 | startscrolldiagright (uint8_t start, uint8_t stop); |
||
64 | void |
||
65 | startscrolldiagleft (uint8_t start, uint8_t stop); |
||
66 | void |
||
67 | stopscroll (void); |
||
2 | mjames | 68 | |
4 | mjames | 69 | void |
70 | dim (uint8_t contrast); |
||
2 | mjames | 71 | |
7 | mjames | 72 | // set drawing mode |
9 | mjames | 73 | void |
74 | setPixelMode (colour_t colour) |
||
75 | { |
||
76 | m_colour = colour; |
||
77 | } |
||
7 | mjames | 78 | |
4 | mjames | 79 | void |
7 | mjames | 80 | drawPixel (int16_t x, int16_t y, bool pixel); |
2 | mjames | 81 | |
4 | mjames | 82 | void |
83 | drawLine (int16_t x1, int16_t y1, int16_t x2, int16_t y2, colour_t color); |
||
2 | mjames | 84 | |
9 | mjames | 85 | void |
86 | drawRectangle (int16_t x1, int16_t y1, int16_t x2, int16_t y2, |
||
87 | colour_t color); |
||
6 | mjames | 88 | |
9 | mjames | 89 | // position cursor absolute |
4 | mjames | 90 | void |
91 | gotoxy (int x, int y) |
||
92 | { |
||
93 | m_cursor_x = x; |
||
94 | m_cursor_y = y; |
||
95 | } |
||
2 | mjames | 96 | |
9 | mjames | 97 | // position cursor relative |
98 | void |
||
99 | moveby (int x, int y) |
||
100 | { |
||
101 | m_cursor_x += x; |
||
102 | m_cursor_y += y; |
||
103 | } |
||
104 | |||
4 | mjames | 105 | // pixel to pixel plotting |
106 | /// \param font The font to use |
||
107 | /// \param string The characters to plot |
||
108 | /// \param length The length of the string |
||
109 | /// \param colour |
||
110 | void |
||
111 | printString (font_t &font, char const *string, uint16_t length, |
||
9 | mjames | 112 | colour_t colour = WHITE); |
2 | mjames | 113 | |
4 | mjames | 114 | // scaled plotting |
115 | /// \param font The font to use |
||
116 | /// \param string The characters to plot |
||
117 | /// \param length The length of the string |
||
118 | /// \param scale The scale factor is 256/scale so 256 is 1:1, 128 is twice the size |
||
119 | /// \param colour |
||
120 | void |
||
9 | mjames | 121 | printScaledString (font_t &font, char const *string, uint16_t length, |
122 | uint16_t scale, colour_t colour = WHITE); |
||
2 | mjames | 123 | |
7 | mjames | 124 | static const uint8_t NO_DECIMAL = 255; |
125 | |||
4 | mjames | 126 | void |
9 | mjames | 127 | fontDigits (font_t &font, uint8_t digits, uint8_t dp_pos, int val, |
128 | colour_t colour = WHITE); |
||
2 | mjames | 129 | |
5 | mjames | 130 | void |
9 | mjames | 131 | fontSigDigits (font_t &font, uint8_t x, uint8_t y, bool right_justify, |
132 | uint8_t dp_pos, int val, colour_t colour = WHITE); |
||
5 | mjames | 133 | |
4 | mjames | 134 | int |
135 | cursor_x () |
||
136 | { |
||
137 | return m_cursor_x; |
||
138 | } |
||
139 | ; |
||
2 | mjames | 140 | |
4 | mjames | 141 | int |
142 | cursor_y () |
||
143 | { |
||
144 | return m_cursor_y; |
||
145 | } |
||
146 | ; |
||
2 | mjames | 147 | |
148 | private: |
||
149 | |||
150 | // set=1 means send data set=0 means send control |
||
4 | mjames | 151 | virtual void |
152 | oledSetCD (uint8_t set) =0; |
||
2 | mjames | 153 | |
4 | mjames | 154 | virtual void |
155 | oledWrite (uint8_t d) =0; |
||
2 | mjames | 156 | |
4 | mjames | 157 | virtual void |
158 | oledReset () = 0; |
||
2 | mjames | 159 | |
4 | mjames | 160 | virtual void |
161 | oledWrite (uint8_t *buff, uint8_t len) = 0; |
||
2 | mjames | 162 | |
9 | mjames | 163 | uint8_t |
164 | formatNum (char *buff, uint8_t siz, uint8_t digits, uint8_t dp_pos, int val); |
||
5 | mjames | 165 | |
2 | mjames | 166 | int const m_width; // pixel width |
167 | int const m_height; // pixel height |
||
168 | int const m_ramwidth; // OLED controller ram pixel width |
||
169 | |||
170 | int m_cursor_x; |
||
4 | mjames | 171 | int m_cursor_y; |
172 | int m_rotation; |
||
2 | mjames | 173 | |
7 | mjames | 174 | // currently selected colour mode |
175 | colour_t m_colour; |
||
176 | |||
4 | mjames | 177 | uint8_t *const m_data; |
2 | mjames | 178 | |
4 | mjames | 179 | }; |