-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
52 lines (39 loc) · 1.12 KB
/
main.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
#include <csignal>
#include <initializer_list>
#include <functional>
#include <algorithm>
#include <u8g2.h>
#include <wiringPi.h>
#include "U8G2_SSD1322_NHD_256X64_F_8080_RPi.h"
#include "SLDisplay.h"
#include "Argparser.h"
// https://stackoverflow.com/questions/68100462/signal-handling-c
sigset_t make_sigset(std::initializer_list<int32_t> signals)
{
sigset_t set;
const int32_t result = sigemptyset(&set);
std::for_each(signals.begin(), signals.end(),
[sigset = &set](auto& signal) {
sigaddset(sigset, signal);
});
return set;
}
int main(int argc, char** argv) {
wiringPiSetup();
U8G2_SSD1322_NHD_256X64_F_8080_RPI pi{
U8G2_R0,
16, 1, 0, 2, 3, 4, 5, 6,
28, 27, 25
};
pi.begin();
pi.setFlipMode(1);
auto config = Argparser::parse_arguments(argc, argv);
auto display = SLDisplay(pi, config);
display.start();
auto sigset = make_sigset({SIGTERM, SIGINT, SIGABRT});
pthread_sigmask(SIG_BLOCK, &sigset, nullptr);
int32_t last_signal;
sigwait(&sigset, &last_signal);
display.stop();
return 0;
}