-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·163 lines (138 loc) · 4.51 KB
/
main.cpp
File metadata and controls
executable file
·163 lines (138 loc) · 4.51 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
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
#include "ReaderScenario.h"
#include "TagsManager.h"
#include "LocalisationManager.h"
#include "ScenarioData.h"
#include "Time.h"
#include "InputManager.h"
#include "SoundManager.h"
#include "ArduinoManager.h"
#include "window.h"
#include "led-matrix.h"
#include <getopt.h>
#include <iostream>
#include <signal.h>
#include <string>
#include <string.h>
#include <time.h>
#include <unistd.h>
using namespace std;
using namespace rgb_matrix;
ReaderScenario* ReaderScenario::m_instance = nullptr;
TagsManager* TagsManager::m_instance = nullptr;
LocalisationManager* LocalisationManager::m_instance = nullptr;
Time* Time::m_instance = nullptr;
InputManager* InputManager::m_instance = nullptr;
SoundManager* SoundManager::m_instance = nullptr;
ArduinoManager* ArduinoManager::m_instance = nullptr;
#if 1
static int usage(const char *progname)
{
fprintf(stderr, "usage: %s [options]\n", progname);
fprintf(stderr, "Reads text from stdin and displays it. "
"Empty string: clear screen\n");
fprintf(stderr, "Options:\n");
rgb_matrix::PrintMatrixFlags(stderr);
fprintf(stderr,
"\t-f <font-file> : Use given font.\n"
"\t-s <scenario> : Use given scenario.\n"
"\t-l <localisation> : Use given localisation.\n"
);
return 1;
}
volatile bool interrupt_received = false;
static void InterruptHandler(int signo)
{
interrupt_received = true;
}
int main(int argc, char *argv[])
{
RGBMatrix::Options matrix_options;
rgb_matrix::RuntimeOptions runtime_opt;
if (!rgb_matrix::ParseOptionsFromFlags(&argc, &argv, &matrix_options, &runtime_opt))
return usage(argv[0]);
runtime_opt.drop_privileges = -1;
const char* bdf_font_file = NULL;
const char* scenario_file = NULL;
const char* localisation_file = NULL;
int opt;
while ((opt = getopt(argc, argv, "f:s:l:")) != -1)
{
switch (opt)
{
case 'f': bdf_font_file = strdup(optarg); break;
case 's': scenario_file = strdup(optarg); break;
case 'l': localisation_file = strdup(optarg); break;
default:
return usage(argv[0]);
}
}
// Font
if (bdf_font_file == NULL)
{
fprintf(stderr, "Need to specify BDF font-file with -f\n");
return usage(argv[0]);
}
rgb_matrix::Font font;
if (!font.LoadFont(bdf_font_file))
{
fprintf(stderr, "Couldn't load font '%s'\n", bdf_font_file);
return 1;
}
// Initialize matrix
RGBMatrix* matrix = rgb_matrix::CreateMatrixFromOptions(matrix_options, runtime_opt);
if (matrix == NULL)
return 1;
matrix->SetBrightness(70);
FrameCanvas* offscreen = matrix->CreateFrameCanvas();
struct timespec next_time;
next_time.tv_sec = time(NULL);
next_time.tv_nsec = 0;
struct tm tm;
signal(SIGTERM, InterruptHandler);
signal(SIGINT, InterruptHandler);
try
{
window* windows = new window();
SoundManager::Instance()->init();
ArduinoManager::Instance()->init();
Time::Instance()->init();
string pathLoc(localisation_file);
LocalisationManager::Instance()->loadTSV(pathLoc);
string pathScenario(scenario_file);
ScenarioData scenario(pathScenario);
ReaderScenario::Instance()->start(matrix, offscreen, &font, &scenario);
while (!interrupt_received && !InputManager::Instance()->isClosing())
{
localtime_r(&next_time.tv_sec, &tm);
offscreen->Clear();
InputManager::Instance()->update();
ReaderScenario::Instance()->update();
windows->draw();
// Wait until we're ready to show it.
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &next_time, NULL);
// Atomic swap with double buffer
//usleep(30);
offscreen = matrix->SwapOnVSync(offscreen);
ReaderScenario::Instance()->setOffscreen(offscreen);
Time::Instance()->update();
next_time.tv_nsec += 1000/15;
}
delete windows;
}
catch ( const InitError & err )
{
cerr << "Error while initializing SDL: " << err.what() << endl;
}
delete ArduinoManager::Instance();
delete SoundManager::Instance();
delete InputManager::Instance();
delete Time::Instance();
delete LocalisationManager::Instance();
delete TagsManager::Instance();
delete ReaderScenario::Instance();
// Finished. Shut down the RGB matrix.
matrix->Clear();
delete matrix;
return 0;
}
#endif