-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRgbMatrixLuas.cpp
More file actions
129 lines (95 loc) · 2.21 KB
/
Copy pathRgbMatrixLuas.cpp
File metadata and controls
129 lines (95 loc) · 2.21 KB
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
// Copyright (c) 2013 Matt Hill
// Use of this source code is governed by The MIT License
// that can be found in the LICENSE file.
//
// This class is for controlling a 32x32 RGB LED Matrix panel using
// the Raspberry Pi GPIO.
//
// This code is based on a cool example found at:
// https://github.com/mattdh666/rpi-led-matrix-panel
#include "DisplayUpdater.h"
#include "RgbMatrix.h"
#include "RgbMatrixContainer.h"
#include "Thread.h"
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <unistd.h>
#define _USE_MATH_DEFINES
char **text;
int textc;
// Draw some shapes on the RGB Matrix.
class RgbMatrixLuasTimes : public RgbMatrixContainer
{
public:
RgbMatrixLuasTimes(RgbMatrix *m) : RgbMatrixContainer(m) {}
void run()
{
// Color red;
// red.red = 255;
Color green;
green.green = 5;
Color blue;
blue.blue = 5;
_matrix->setFontSize(2); // Medium (4x6) Font
_matrix->setTextCursor(1, 8);
_matrix->setFontColor(green);
int idx = 1;
display_time(idx);
idx += text[1][0] - '0' + 1;
_matrix->setTextCursor(1, 18);
_matrix->setFontColor(blue);
display_time(idx);
}
void display_time(int idx) {
if (text[idx][0] > '0')
display(text[idx+1]);
if (text[idx][0] == '2') {
_matrix->writeChar(' ');
display(text[idx+2]);
}
}
void display(char *text) {
int i = 0;
while (text[i] != '\0') {
_matrix->writeChar(text[i++]);
}
}
};
RgbMatrix *m = NULL;
RgbMatrixContainer *display = NULL;
RgbMatrixContainer *updater = NULL;
void runProgram()
{
updater->start(10);
display->start();
// getchar();
sleep(13);
delete display;
delete updater;
display = NULL;
updater = NULL;
m->clearDisplay();
m->updateDisplay();
}
int main(int argc, char *argv[])
{
textc = argc;
text = argv;
GpioProxy io;
if (!io.initialize())
return 1;
m = new RgbMatrix(&io);
display = new RgbMatrixLuasTimes(m);
updater = new DisplayUpdater(m);
runProgram();
// Stop threads and wait for them to join.
if (display) delete display;
if (updater) delete updater;
// Clear and refresh the display.
m->clearDisplay();
m->updateDisplay();
delete m;
return 0;
}