Rev 6 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 6 | Rev 7 | ||
|---|---|---|---|
| Line 92... | Line 92... | ||
| 92 | } |
92 | } |
| 93 | 93 | ||
| 94 | display_t::display_t (int const width, int const height, int const ramwidth, |
94 | display_t::display_t (int const width, int const height, int const ramwidth, |
| 95 | uint8_t *const data) : |
95 | uint8_t *const data) : |
| 96 | m_width (width), m_height (height), m_ramwidth (ramwidth), m_cursor_x (0), m_cursor_y ( |
96 | m_width (width), m_height (height), m_ramwidth (ramwidth), m_cursor_x (0), m_cursor_y ( |
| 97 | 0), m_rotation (0), m_data (data) |
97 | 0), m_rotation (0), m_colour (WHITE), m_data (data) |
| 98 | { |
98 | { |
| 99 | } |
99 | } |
| 100 | 100 | ||
| 101 | display_t::~display_t () |
101 | display_t::~display_t () |
| 102 | { |
102 | { |
| 103 | 103 | ||
| 104 | } |
104 | } |
| 105 | 105 | ||
| - | 106 | void display_t::reset() |
|
| - | 107 | { |
|
| - | 108 | oledReset(); |
|
| - | 109 | } |
|
| - | 110 | ||
| 106 | void |
111 | void |
| 107 | display_t::display_t::init () |
112 | display_t::init () |
| 108 | { |
113 | { |
| 109 | uint8_t const vccstate = SSD1306_EXTERNALVCC; |
114 | uint8_t const vccstate = SSD1306_EXTERNALVCC; |
| 110 | 115 | ||
| 111 | oledReset (); |
- | |
| 112 | 116 | ||
| 113 | oledSetCD (0); |
117 | oledSetCD (0); |
| 114 | 118 | ||
| 115 | // Init sequence for 128x32 or 128x64 OLED module |
119 | // Init sequence for 128x32 or 128x64 OLED module |
| 116 | oledWrite (SSD1306_DISPLAYOFF); // 0xAE |
120 | oledWrite (SSD1306_DISPLAYOFF); // 0xAE |
| Line 192... | Line 196... | ||
| 192 | return 0; |
196 | return 0; |
| 193 | } |
197 | } |
| 194 | 198 | ||
| 195 | // the most basic function, set a single pixel |
199 | // the most basic function, set a single pixel |
| 196 | void |
200 | void |
| 197 | display_t::drawPixel (int16_t x, int16_t y, colour_t color) |
201 | display_t::drawPixel (int16_t x, int16_t y, bool pixel) |
| 198 | { |
202 | { |
| 199 | if ((x < 0) || (x >= m_width) || (y < 0) || (y >= m_height)) |
203 | if ((x < 0) || (x >= m_width) || (y < 0) || (y >= m_height)) |
| 200 | return; |
204 | return; |
| 201 | 205 | ||
| 202 | // check rotation, move pixel around if necessary |
206 | // check rotation, move pixel around if necessary |
| Line 215... | Line 219... | ||
| 215 | y = m_height - y - 1; |
219 | y = m_height - y - 1; |
| 216 | break; |
220 | break; |
| 217 | } |
221 | } |
| 218 | 222 | ||
| 219 | // x is which column |
223 | // x is which column |
| - | 224 | // BLACK, and 0, invert 0 |
|
| - | 225 | // WHITE, and 0, invert 1 |
|
| - | 226 | // OVERLAY, and 1 (preserve) , invert 0/ |
|
| - | 227 | // INVERT, and 1, (preserve) , invert 1 |
|
| - | 228 | ||
| 220 | switch (color) |
229 | switch (m_colour) |
| 221 | { |
230 | { |
| 222 | case BLACK: |
231 | case BLACK: |
| - | 232 | case WHITE: |
|
| 223 | m_data[x + (y / 8) * m_width] &= ~(1 << (y & 7)); |
233 | m_data[x + (y / 8) * m_width] &= ~(1 << (y & 7)); |
| 224 | break; |
234 | break; |
| 225 | - | ||
| 226 | default: |
235 | default: |
| 227 | case WHITE: |
- | |
| 228 | m_data[x + (y / 8) * m_width] |= (1 << (y & 7)); |
- | |
| 229 | break; |
236 | break; |
| - | 237 | } |
|
| - | 238 | uint8_t pixData = 0; |
|
| - | 239 | switch (m_colour) |
|
| 230 | 240 | { |
|
| - | 241 | case BLACK: |
|
| 231 | case INVERT: |
242 | case INVERT: |
| - | 243 | pixData = pixel ? 0 : 1; |
|
| - | 244 | break; |
|
| - | 245 | default: |
|
| 232 | m_data[x + (y / 8) * m_width] ^= (1 << (y & 7)); |
246 | pixData = pixel ? 1 : 0; |
| 233 | break; |
247 | break; |
| 234 | } |
248 | } |
| - | 249 | ||
| - | 250 | m_data[x + (y / 8) * m_width] ^= (pixData << (y & 7)); |
|
| - | 251 | ||
| 235 | } |
252 | } |
| 236 | 253 | ||
| 237 | void |
254 | void |
| 238 | display_t::invertDisplay (uint8_t i) |
255 | display_t::invertDisplay (uint8_t i) |
| 239 | { |
256 | { |
| Line 372... | Line 389... | ||
| 372 | 389 | ||
| 373 | // clear everything |
390 | // clear everything |
| 374 | void |
391 | void |
| 375 | display_t::clearDisplay (colour_t colour) |
392 | display_t::clearDisplay (colour_t colour) |
| 376 | { |
393 | { |
| - | 394 | switch (colour) |
|
| - | 395 | { |
|
| - | 396 | case WHITE: |
|
| - | 397 | case OVERLAY: |
|
| 377 | memset (m_data, colour == WHITE ? 255 : 0, dataSize (m_width, m_height)); |
398 | memset (m_data, 255, dataSize (m_width, m_height)); |
| - | 399 | break; |
|
| - | 400 | case BLACK: |
|
| - | 401 | memset (m_data, 0, dataSize (m_width, m_height)); |
|
| - | 402 | break; |
|
| - | 403 | case INVERT: |
|
| - | 404 | for (size_t i = 0; i < dataSize (m_width, m_height); i++) |
|
| - | 405 | m_data[i] ^= 255; |
|
| - | 406 | break; |
|
| - | 407 | } |
|
| - | 408 | ||
| 378 | } |
409 | } |
| 379 | 410 | ||
| - | 411 | void |
|
| 380 | void display_t::drawRectangle (int16_t x1, int16_t y1, int16_t x2, int16_t y2, |
412 | display_t::drawRectangle (int16_t x1, int16_t y1, int16_t x2, int16_t y2, |
| 381 | colour_t color) |
413 | colour_t color) |
| 382 | { |
414 | { |
| 383 | for (int16_t x = x1; x <= x2; x++) |
415 | for (int16_t x = x1; x <= x2; x++) |
| 384 | for (int16_t y = y1; y < y2; y++) |
416 | for (int16_t y = y1; y < y2; y++) |
| 385 | { |
417 | { |
| Line 389... | Line 421... | ||
| 389 | m_data[x + (y / 8) * m_width] &= ~(1 << (y & 7)); |
421 | m_data[x + (y / 8) * m_width] &= ~(1 << (y & 7)); |
| 390 | break; |
422 | break; |
| 391 | 423 | ||
| 392 | default: |
424 | default: |
| 393 | case WHITE: |
425 | case WHITE: |
| - | 426 | case OVERLAY: |
|
| 394 | m_data[x + (y / 8) * m_width] |= (1 << (y & 7)); |
427 | m_data[x + (y / 8) * m_width] |= (1 << (y & 7)); |
| 395 | break; |
428 | break; |
| 396 | 429 | ||
| 397 | case INVERT: |
430 | case INVERT: |
| 398 | m_data[x + (y / 8) * m_width] ^= (1 << (y & 7)); |
431 | m_data[x + (y / 8) * m_width] ^= (1 << (y & 7)); |