Subversion Repositories libOLED

Rev

Rev 9 | Rev 11 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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