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