-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayApp.cpp
175 lines (150 loc) · 4.81 KB
/
DisplayApp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* DisplayApp.cpp
*
* Created on: Dec 4, 2018
* Author: Vishal
*/
#include "DisplayApp.hpp"
#include "string.h"
#include "stdint.h"
#include "string.h"
#include <stdio.h>
#include <vector>
extern char small_digits[10][5][3];
extern char big_digits[10][7][5];
extern char big_letters[26][7][5];
void getDigitsFromNumber(int num, std::vector<int>&digits)
{
do {
digits.insert(digits.begin(), num % 10);
num /= 10;
} while(num);
}
void DisplayApp::initDisplay(LEDMatrixDisplayPincon &pincon)
{
display.init(pincon);
}
void DisplayApp::updateDisplay()
{
display.updateDisplay();
}
void DisplayApp::displayGridBorders(Color color)
{
uint64_t columns_borders = 0x0001000100010000;
uint64_t row_borders = 0xFFFFFFFFFFFFFFFE;
for(int i = 0; i < 23; i++) {
if((i == 5) || (i == 11) || (i == 17)) {
display.setRowData(i, color, row_borders);
} else {
display.setRowData(i, color, columns_borders);
}
}
}
void DisplayApp::displayNumber(int number, Color color, int start_row, int start_pixel, FontType font)
{
if(font == SmallFont) {
displayNumberSmallFont(number, color, start_row, start_pixel);
} else if(font == BigFont) {
displayNumberBigFont(number, color, start_row, start_pixel);
} else {
printf("Invalid Font Type\n");
}
}
void DisplayApp::displayDigit(int digit, Color color, int start_row, int start_pixel, FontType font)
{
if(font == SmallFont) {
displayDigitSmallFont(digit, color, start_row, start_pixel);
} else if(font == BigFont) {
displayDigitBigFont(digit, color, start_row, start_pixel);
} else {
printf("Invalid Font Type\n");
}
}
void DisplayApp::displayDigitSmallFont(int digit, Color color, int start_row, int start_pixel)
{
int row, pixel;
for(int i = 0; i < 5; i++) {
row = start_row + i;
for(int j = 0; j < 3; j++) {
pixel = 63 - (start_pixel + j);
(small_digits[digit][i][j]) ? display.setPixel(row, pixel, color) : display.clearPixel(row, pixel);
}
}
}
void DisplayApp::displayNumberSmallFont(int num, Color color, int start_row, int start_pixel)
{
std::vector<int> digits;
std::vector<int>::iterator it;
getDigitsFromNumber(num, digits);
for(it = digits.begin(); it != digits.end(); it++) {
displayDigitSmallFont(*it, color, start_row, start_pixel);
start_pixel += 4; //Each digit takes up 3 columns +1 blank space
}
}
void DisplayApp::displayDigitBigFont(int digit, Color color, int start_row, int start_pixel)
{
int row, pixel;
for(int i = 0; i < 7; i++) {
row = start_row + i;
for(int j = 0; j < 5; j++) {
pixel = 63 - (start_pixel + j);
(big_digits[digit][i][j]) ? display.setPixel(row, pixel, color) : display.clearPixel(row, pixel);
}
}
}
void DisplayApp::displayNumberBigFont(int num, Color color, int start_row, int start_pixel)
{
std::vector<int> digits;
std::vector<int>::iterator it;
getDigitsFromNumber(num, digits);
for(it = digits.begin(); it != digits.end(); it++) {
displayDigitBigFont(*it, color, start_row, start_pixel);
start_pixel += 6; //Each digit takes up 5 columns +1 blank space
}
}
void DisplayApp::displayGrid(int (*grid)[4], ColorMap &colorMap)
{
int start_row, start_pixel;
display.clearFrameBuffer();
displayGridBorders(White);
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
start_row = i * 6; //New block at every 6th row
start_pixel = j * 16; //New block at every 16th Column
displayNumberSmallFont(grid[i][j], colorMap[grid[i][j]], start_row, start_pixel);
}
}
}
void DisplayApp::drawBox(int xMin, int yMin, int xMax, int yMax, Color color)
{
uint64_t row_data = 0xFFFFFFFFFFFFFFFF;
row_data = (row_data << xMin) & (row_data >> (64 - xMax - 1));
display.setRowData(yMin, color, row_data);
display.setRowData(yMax, color, row_data);
for(int i = yMin + 1; i < yMax; i++) {
display.setPixel(i, xMin, color);
display.setPixel(i, xMax, color);
}
}
void DisplayApp::displayCharacter(char c, Color color, int start_row, int start_pixel)
{
int row, pixel;
for(int i = 0; i < 7; i++) {
row = start_row + i;
for(int j = 0; j < 5; j++) {
pixel = 63 - (start_pixel + j);
(big_letters[c - 65][i][j]) ? display.setPixel(row, pixel, color) : display.clearPixel(row, pixel);
}
}
}
void DisplayApp::displayString(string s, Color color, int start_row, int start_pixel)
{
for(unsigned i = 0; i < s.size(); i++) {
if(s[i] == ' ') {
start_pixel += 5;
continue;
}
displayCharacter(s[i], color, start_row, start_pixel);
start_pixel += 6;
}
}