Rev 9 | Rev 11 | 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 | |
10 | mjames | 12 | inline int constexpr dataSize(int const width, int const height) |
2 | mjames | 13 | { |
4 | mjames | 14 | return (width * height / 8); |
2 | mjames | 15 | } |
16 | |||
17 | enum colour_t |
||
18 | { |
||
10 | mjames | 19 | BLACK, /* and 0, invert 0 */ |
20 | WHITE, /* and 0, invert 1 */ |
||
7 | mjames | 21 | OVERLAY, /* and 1, invert 0 */ |
10 | mjames | 22 | INVERT, /* and 1, invert 1 */ |
2 | mjames | 23 | }; |
24 | |||
25 | class display_t |
||
26 | { |
||
27 | public: |
||
10 | mjames | 28 | display_t(int const width, int const height, int const ramwidth, |
29 | uint8_t *const data); |
||
2 | mjames | 30 | |
10 | mjames | 31 | virtual ~display_t(); |
2 | mjames | 32 | |
10 | mjames | 33 | /// \brief get the current rotation of the display |
4 | mjames | 34 | uint8_t |
10 | mjames | 35 | getRotation(); |
36 | |||
4 | mjames | 37 | int16_t |
10 | mjames | 38 | width(); |
4 | mjames | 39 | int16_t |
10 | mjames | 40 | height(); |
2 | mjames | 41 | |
7 | mjames | 42 | // common hardware reset . |
9 | mjames | 43 | void |
10 | mjames | 44 | reset(); |
7 | mjames | 45 | |
4 | mjames | 46 | void |
10 | mjames | 47 | init(); |
2 | mjames | 48 | |
6 | mjames | 49 | /// \brief Clear display to colour |
4 | mjames | 50 | void |
10 | mjames | 51 | clearDisplay(colour_t colour = colour_t::BLACK); |
4 | mjames | 52 | void |
10 | mjames | 53 | invertDisplay(uint8_t i); |
4 | mjames | 54 | void |
10 | mjames | 55 | display(); |
2 | mjames | 56 | |
4 | mjames | 57 | void |
10 | mjames | 58 | startscrollright(uint8_t start, uint8_t stop); |
4 | mjames | 59 | void |
10 | mjames | 60 | startscrollleft(uint8_t start, uint8_t stop); |
2 | mjames | 61 | |
4 | mjames | 62 | void |
10 | mjames | 63 | startscrolldiagright(uint8_t start, uint8_t stop); |
4 | mjames | 64 | void |
10 | mjames | 65 | startscrolldiagleft(uint8_t start, uint8_t stop); |
4 | mjames | 66 | void |
10 | mjames | 67 | stopscroll(void); |
2 | mjames | 68 | |
4 | mjames | 69 | void |
10 | mjames | 70 | dim(uint8_t contrast); |
2 | mjames | 71 | |
7 | mjames | 72 | // set drawing mode |
9 | mjames | 73 | void |
10 | mjames | 74 | setPixelMode(colour_t colour) |
9 | mjames | 75 | { |
76 | m_colour = colour; |
||
77 | } |
||
7 | mjames | 78 | |
4 | mjames | 79 | void |
10 | mjames | 80 | drawPixel(int16_t x, int16_t y, bool pixel); |
2 | mjames | 81 | |
4 | mjames | 82 | void |
10 | mjames | 83 | drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, colour_t color); |
2 | mjames | 84 | |
9 | mjames | 85 | void |
10 | mjames | 86 | drawRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, |
87 | colour_t color); |
||
6 | mjames | 88 | |
10 | mjames | 89 | // position cursor absolute |
4 | mjames | 90 | void |
10 | mjames | 91 | gotoxy(int x, int y) |
4 | mjames | 92 | { |
93 | m_cursor_x = x; |
||
94 | m_cursor_y = y; |
||
95 | } |
||
2 | mjames | 96 | |
9 | mjames | 97 | // position cursor relative |
98 | void |
||
10 | mjames | 99 | moveby(int x, int y) |
9 | mjames | 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 |
||
10 | mjames | 111 | printString(font_t &font, char const *string, uint16_t length, |
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 |
||
10 | 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 | |||
10 | mjames | 126 | /// \brief Display signed integer value with expected field width, and optional |
127 | /// decimal point position |
||
128 | /// \param font Reference to font in use |
||
129 | /// \param digits Number of digits to display (not including decimal point) |
||
130 | /// \param dp_pos If less than 10, attempt to place decimal point in given position. |
||
131 | /// set to > 10 to not try to display decimal point |
||
132 | /// \param val value to display |
||
133 | /// \param colour Drawing colour for font. |
||
4 | mjames | 134 | void |
10 | mjames | 135 | fontDigits(font_t &font, uint8_t digits, uint8_t dp_pos, int val, |
136 | colour_t colour = WHITE); |
||
2 | mjames | 137 | |
10 | mjames | 138 | /// \brief Calculate the length of the numeric string, and display it justified or padded |
139 | /// \return The formatted width : returned as signed so calculations which have negative results |
||
140 | /// can be performed using width without type casting. |
||
141 | int8_t |
||
142 | fontSigDigits(font_t &font, uint8_t x, uint8_t y, bool right_justify, |
||
143 | uint8_t dp_pos, int val, colour_t colour = WHITE); |
||
5 | mjames | 144 | |
10 | mjames | 145 | int cursor_x() |
4 | mjames | 146 | { |
147 | return m_cursor_x; |
||
10 | mjames | 148 | }; |
2 | mjames | 149 | |
10 | mjames | 150 | int cursor_y() |
4 | mjames | 151 | { |
152 | return m_cursor_y; |
||
10 | mjames | 153 | }; |
2 | mjames | 154 | |
155 | private: |
||
156 | // set=1 means send data set=0 means send control |
||
4 | mjames | 157 | virtual void |
10 | mjames | 158 | oledSetCD(uint8_t set) = 0; |
2 | mjames | 159 | |
4 | mjames | 160 | virtual void |
10 | mjames | 161 | oledWrite(uint8_t d) = 0; |
2 | mjames | 162 | |
4 | mjames | 163 | virtual void |
10 | mjames | 164 | oledReset() = 0; |
2 | mjames | 165 | |
4 | mjames | 166 | virtual void |
10 | mjames | 167 | oledWrite(uint8_t *buff, uint8_t len) = 0; |
2 | mjames | 168 | |
9 | mjames | 169 | uint8_t |
10 | mjames | 170 | formatNum(char *buff, uint8_t siz, uint8_t digits, uint8_t dp_pos, int val); |
5 | mjames | 171 | |
10 | mjames | 172 | int const m_width; // pixel width |
173 | int const m_height; // pixel height |
||
2 | mjames | 174 | int const m_ramwidth; // OLED controller ram pixel width |
175 | |||
176 | int m_cursor_x; |
||
4 | mjames | 177 | int m_cursor_y; |
178 | int m_rotation; |
||
2 | mjames | 179 | |
7 | mjames | 180 | // currently selected colour mode |
181 | colour_t m_colour; |
||
182 | |||
4 | mjames | 183 | uint8_t *const m_data; |
184 | }; |