| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,98 @@ |
| 1 |
+/* |
|
| 2 |
+ * Author: Pawel Jablonski |
|
| 3 |
+ * E-mail: pj@xirx.net |
|
| 4 |
+ * WWW: xirx.net |
|
| 5 |
+ * GIT: git.xirx.net |
|
| 6 |
+ * |
|
| 7 |
+ * License: You can use this code however you like |
|
| 8 |
+ * but leave information about the original author. |
|
| 9 |
+ * Code is free for non-commercial and commercial use. |
|
| 10 |
+ */ |
|
| 11 |
+ |
|
| 12 |
+#include "lcd.h" |
|
| 13 |
+ |
|
| 14 |
+/** |
|
| 15 |
+ * Constructor for the LCD class |
|
| 16 |
+ * |
|
| 17 |
+ * @param parent Parent object |
|
| 18 |
+ */ |
|
| 19 |
+LCD::LCD(QObject *parent) : QObject(parent) |
|
| 20 |
+{
|
|
| 21 |
+ this->reset(); |
|
| 22 |
+} |
|
| 23 |
+ |
|
| 24 |
+//! Reset the LCD buffers and clear the screen |
|
| 25 |
+void LCD::reset() |
|
| 26 |
+{
|
|
| 27 |
+ this->clear(); |
|
| 28 |
+ this->refresh(); |
|
| 29 |
+} |
|
| 30 |
+ |
|
| 31 |
+//! Copy data from the canvas painting buffer to the ready to show buffer |
|
| 32 |
+void LCD::refresh() |
|
| 33 |
+{
|
|
| 34 |
+ for(int i = 0; i < HEIGHT; i++) |
|
| 35 |
+ {
|
|
| 36 |
+ for(int j = 0; j < WIDTH; j++) |
|
| 37 |
+ {
|
|
| 38 |
+ this->buffer[1].charData[i][j] = this->buffer[0].charData[i][j]; |
|
| 39 |
+ this->buffer[1].colorData[i][j] = this->buffer[0].colorData[i][j]; |
|
| 40 |
+ } |
|
| 41 |
+ } |
|
| 42 |
+} |
|
| 43 |
+ |
|
| 44 |
+//! Clear the canvas painting buffer |
|
| 45 |
+void LCD::clear() |
|
| 46 |
+{
|
|
| 47 |
+ for(int i = 0; i < HEIGHT; i++) |
|
| 48 |
+ {
|
|
| 49 |
+ for(int j = 0; j < WIDTH; j++) |
|
| 50 |
+ {
|
|
| 51 |
+ this->buffer[0].charData[i][j] = 0; |
|
| 52 |
+ this->buffer[0].colorData[i][j] = 0; |
|
| 53 |
+ } |
|
| 54 |
+ } |
|
| 55 |
+} |
|
| 56 |
+ |
|
| 57 |
+/** |
|
| 58 |
+ * Set char in the buffer |
|
| 59 |
+ * |
|
| 60 |
+ * @param c Char to set |
|
| 61 |
+ * @param x Horizontal position in range 0-WIDTH |
|
| 62 |
+ * @param y Vertical position in range 0-HEIGHT |
|
| 63 |
+ * @param charColor Foreground color code in range 0-15 |
|
| 64 |
+ * @param backgroundColor Background color code in range 0-15 |
|
| 65 |
+ */ |
|
| 66 |
+void LCD::setChar(unsigned char c, int x, int y, unsigned char charColor, unsigned char backgroundColor) |
|
| 67 |
+{
|
|
| 68 |
+ if((x >= 0) && (x < WIDTH) && (y >= 0) && (y < HEIGHT)) |
|
| 69 |
+ {
|
|
| 70 |
+ this->buffer[0].charData[y][x] = c; |
|
| 71 |
+ this->buffer[0].colorData[y][x] = static_cast<unsigned char>((charColor & COLOR_MASK) | ((backgroundColor & COLOR_MASK) << 4)); |
|
| 72 |
+ } |
|
| 73 |
+} |
|
| 74 |
+ |
|
| 75 |
+//! Scroll the canvas painting buffer one line up |
|
| 76 |
+void LCD::scroll() |
|
| 77 |
+{
|
|
| 78 |
+ for(int y = 0; y < (HEIGHT - 1); y++) |
|
| 79 |
+ {
|
|
| 80 |
+ for(int x = 0; x < WIDTH; x++) |
|
| 81 |
+ {
|
|
| 82 |
+ this->buffer[0].charData[y][x] = this->buffer[0].charData[y + 1][x]; |
|
| 83 |
+ this->buffer[0].colorData[y][x] = this->buffer[0].colorData[y + 1][x]; |
|
| 84 |
+ } |
|
| 85 |
+ } |
|
| 86 |
+ |
|
| 87 |
+ for(int x = 0; x < WIDTH; x++) |
|
| 88 |
+ {
|
|
| 89 |
+ this->buffer[0].charData[HEIGHT - 1][x] = 0; |
|
| 90 |
+ this->buffer[0].colorData[HEIGHT - 1][x] = 0; |
|
| 91 |
+ } |
|
| 92 |
+} |
|
| 93 |
+ |
|
| 94 |
+//! Emit the update signal with ready to show buffer data |
|
| 95 |
+void LCD::update() |
|
| 96 |
+{
|
|
| 97 |
+ emit updateBufferSignal(this->buffer[1]); |
|
| 98 |
+} |