Rev 3 | Rev 5 | 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 | |
| 4 | mjames | 42 | void |
| 43 | clearDisplay (); |
||
| 44 | void |
||
| 45 | invertDisplay (uint8_t i); |
||
| 46 | void |
||
| 47 | display (); |
||
| 2 | mjames | 48 | |
| 4 | mjames | 49 | void |
| 50 | startscrollright (uint8_t start, uint8_t stop); |
||
| 51 | void |
||
| 52 | startscrollleft (uint8_t start, uint8_t stop); |
||
| 2 | mjames | 53 | |
| 4 | mjames | 54 | void |
| 55 | startscrolldiagright (uint8_t start, uint8_t stop); |
||
| 56 | void |
||
| 57 | startscrolldiagleft (uint8_t start, uint8_t stop); |
||
| 58 | void |
||
| 59 | stopscroll (void); |
||
| 2 | mjames | 60 | |
| 4 | mjames | 61 | void |
| 62 | dim (uint8_t contrast); |
||
| 2 | mjames | 63 | |
| 4 | mjames | 64 | void |
| 65 | drawPixel (int16_t x, int16_t y, colour_t color); |
||
| 2 | mjames | 66 | |
| 4 | mjames | 67 | void |
| 68 | drawLine (int16_t x1, int16_t y1, int16_t x2, int16_t y2, colour_t color); |
||
| 2 | mjames | 69 | |
| 4 | mjames | 70 | void |
| 71 | gotoxy (int x, int y) |
||
| 72 | { |
||
| 73 | m_cursor_x = x; |
||
| 74 | m_cursor_y = y; |
||
| 75 | } |
||
| 76 | ; |
||
| 2 | mjames | 77 | |
| 4 | mjames | 78 | // pixel to pixel plotting |
| 79 | /// \param font The font to use |
||
| 80 | /// \param string The characters to plot |
||
| 81 | /// \param length The length of the string |
||
| 82 | /// \param colour |
||
| 83 | void |
||
| 84 | printString (font_t &font, char const *string, uint16_t length, |
||
| 85 | colour_t colour); |
||
| 2 | mjames | 86 | |
| 4 | mjames | 87 | // scaled plotting |
| 88 | /// \param font The font to use |
||
| 89 | /// \param string The characters to plot |
||
| 90 | /// \param length The length of the string |
||
| 91 | /// \param scale The scale factor is 256/scale so 256 is 1:1, 128 is twice the size |
||
| 92 | /// \param colour |
||
| 93 | void |
||
| 94 | printScaledString (font_t &font, char const *string, |
||
| 95 | uint16_t length, uint16_t scale, |
||
| 96 | colour_t colour); |
||
| 2 | mjames | 97 | |
| 4 | mjames | 98 | void |
| 99 | printChar (font_t &font, char c, colour_t colour); |
||
| 2 | mjames | 100 | |
| 4 | mjames | 101 | int |
| 102 | cursor_x () |
||
| 103 | { |
||
| 104 | return m_cursor_x; |
||
| 105 | } |
||
| 106 | ; |
||
| 2 | mjames | 107 | |
| 4 | mjames | 108 | int |
| 109 | cursor_y () |
||
| 110 | { |
||
| 111 | return m_cursor_y; |
||
| 112 | } |
||
| 113 | ; |
||
| 2 | mjames | 114 | |
| 115 | private: |
||
| 116 | |||
| 117 | // set=1 means send data set=0 means send control |
||
| 4 | mjames | 118 | virtual void |
| 119 | oledSetCD (uint8_t set) =0; |
||
| 2 | mjames | 120 | |
| 4 | mjames | 121 | virtual void |
| 122 | oledWrite (uint8_t d) =0; |
||
| 2 | mjames | 123 | |
| 4 | mjames | 124 | virtual void |
| 125 | oledReset () = 0; |
||
| 2 | mjames | 126 | |
| 4 | mjames | 127 | virtual void |
| 128 | oledWrite (uint8_t *buff, uint8_t len) = 0; |
||
| 2 | mjames | 129 | |
| 130 | int const m_width; // pixel width |
||
| 131 | int const m_height; // pixel height |
||
| 132 | int const m_ramwidth; // OLED controller ram pixel width |
||
| 133 | |||
| 134 | int m_cursor_x; |
||
| 4 | mjames | 135 | int m_cursor_y; |
| 136 | int m_rotation; |
||
| 2 | mjames | 137 | |
| 4 | mjames | 138 | uint8_t *const m_data; |
| 2 | mjames | 139 | |
| 4 | mjames | 140 | }; |