Rev 5 | Rev 7 | 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 | { |
||
4 | mjames | 20 | BLACK, WHITE, INVERT |
2 | mjames | 21 | }; |
22 | |||
23 | class display_t |
||
24 | { |
||
25 | public: |
||
4 | mjames | 26 | display_t (int const width, int const height, int const ramwidth, |
27 | uint8_t *const data); |
||
2 | mjames | 28 | |
4 | mjames | 29 | virtual |
30 | ~display_t (); |
||
2 | mjames | 31 | |
4 | mjames | 32 | uint8_t |
33 | getRotation (); |
||
34 | int16_t |
||
35 | width (); |
||
36 | int16_t |
||
37 | height (); |
||
2 | mjames | 38 | |
4 | mjames | 39 | void |
40 | init (); |
||
2 | mjames | 41 | |
6 | mjames | 42 | /// \brief Clear display to colour |
4 | mjames | 43 | void |
6 | mjames | 44 | clearDisplay (colour_t colour = colour_t::BLACK); |
4 | mjames | 45 | void |
46 | invertDisplay (uint8_t i); |
||
47 | void |
||
48 | display (); |
||
2 | mjames | 49 | |
4 | mjames | 50 | void |
51 | startscrollright (uint8_t start, uint8_t stop); |
||
52 | void |
||
53 | startscrollleft (uint8_t start, uint8_t stop); |
||
2 | mjames | 54 | |
4 | mjames | 55 | void |
56 | startscrolldiagright (uint8_t start, uint8_t stop); |
||
57 | void |
||
58 | startscrolldiagleft (uint8_t start, uint8_t stop); |
||
59 | void |
||
60 | stopscroll (void); |
||
2 | mjames | 61 | |
4 | mjames | 62 | void |
63 | dim (uint8_t contrast); |
||
2 | mjames | 64 | |
4 | mjames | 65 | void |
66 | drawPixel (int16_t x, int16_t y, colour_t color); |
||
2 | mjames | 67 | |
4 | mjames | 68 | void |
69 | drawLine (int16_t x1, int16_t y1, int16_t x2, int16_t y2, colour_t color); |
||
2 | mjames | 70 | |
6 | mjames | 71 | void drawRectangle (int16_t x1, int16_t y1, int16_t x2, int16_t y2, colour_t color); |
72 | |||
73 | |||
4 | mjames | 74 | void |
75 | gotoxy (int x, int y) |
||
76 | { |
||
77 | m_cursor_x = x; |
||
78 | m_cursor_y = y; |
||
79 | } |
||
80 | ; |
||
2 | mjames | 81 | |
4 | mjames | 82 | // pixel to pixel plotting |
83 | /// \param font The font to use |
||
84 | /// \param string The characters to plot |
||
85 | /// \param length The length of the string |
||
86 | /// \param colour |
||
87 | void |
||
88 | printString (font_t &font, char const *string, uint16_t length, |
||
89 | colour_t colour); |
||
2 | mjames | 90 | |
4 | mjames | 91 | // scaled plotting |
92 | /// \param font The font to use |
||
93 | /// \param string The characters to plot |
||
94 | /// \param length The length of the string |
||
95 | /// \param scale The scale factor is 256/scale so 256 is 1:1, 128 is twice the size |
||
96 | /// \param colour |
||
97 | void |
||
98 | printScaledString (font_t &font, char const *string, |
||
99 | uint16_t length, uint16_t scale, |
||
100 | colour_t colour); |
||
2 | mjames | 101 | |
4 | mjames | 102 | void |
5 | mjames | 103 | fontDigits (font_t &font, uint8_t digits, uint8_t dp_pos, int val); |
2 | mjames | 104 | |
5 | mjames | 105 | void |
106 | fontSigDigits (font_t &font,uint8_t x, uint8_t y, bool right_justify, uint8_t dp_pos, |
||
107 | int val); |
||
108 | |||
4 | mjames | 109 | int |
110 | cursor_x () |
||
111 | { |
||
112 | return m_cursor_x; |
||
113 | } |
||
114 | ; |
||
2 | mjames | 115 | |
4 | mjames | 116 | int |
117 | cursor_y () |
||
118 | { |
||
119 | return m_cursor_y; |
||
120 | } |
||
121 | ; |
||
2 | mjames | 122 | |
123 | private: |
||
124 | |||
125 | // set=1 means send data set=0 means send control |
||
4 | mjames | 126 | virtual void |
127 | oledSetCD (uint8_t set) =0; |
||
2 | mjames | 128 | |
4 | mjames | 129 | virtual void |
130 | oledWrite (uint8_t d) =0; |
||
2 | mjames | 131 | |
4 | mjames | 132 | virtual void |
133 | oledReset () = 0; |
||
2 | mjames | 134 | |
4 | mjames | 135 | virtual void |
136 | oledWrite (uint8_t *buff, uint8_t len) = 0; |
||
2 | mjames | 137 | |
5 | mjames | 138 | |
139 | uint8_t formatNum (char *buff, uint8_t siz, uint8_t digits, uint8_t dp_pos, int val); |
||
140 | |||
141 | |||
2 | mjames | 142 | int const m_width; // pixel width |
143 | int const m_height; // pixel height |
||
144 | int const m_ramwidth; // OLED controller ram pixel width |
||
145 | |||
146 | int m_cursor_x; |
||
4 | mjames | 147 | int m_cursor_y; |
148 | int m_rotation; |
||
2 | mjames | 149 | |
4 | mjames | 150 | uint8_t *const m_data; |
2 | mjames | 151 | |
4 | mjames | 152 | }; |