-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzicPixel.cpp
83 lines (67 loc) · 2.05 KB
/
zicPixel.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
#define ZIC_LOG_LEVEL ZIC_LOG_DEBUG
#define DRAW_ST7789
#ifndef IS_RPI
#define USE_DRAW_WITH_SDL
#endif
#include "config.h"
#include "draw/ST7789/draw.h"
#include "helpers/getTicks.h"
#include "host.h"
#include "plugins/controllers/PixelController.h"
#include "styles.h"
#include "viewManager.h"
// Make from scratch UI
void* uiThread(void* = NULL)
{
ViewManager& viewManager = ViewManager::get();
viewManager.init();
if (!viewManager.render()) {
printf("No view were initialized to be rendered.");
return NULL;
}
// int ms = 50;
int ms = 80;
#ifdef USE_DRAW_WITH_SDL
logInfo("Rendering with SDL.");
unsigned long lastUpdate = getTicks();
while (viewManager.draw.handleEvent(viewManager.view)) {
unsigned long now = getTicks();
if (now - lastUpdate > ms) {
lastUpdate = now;
viewManager.renderComponents(now);
}
usleep(1);
}
#else
int us = ms * 1000;
while (true) {
unsigned long now = getTicks();
viewManager.renderComponents(now);
usleep(us);
}
#endif
viewManager.draw.quit();
return NULL;
}
int main(int argc, char* argv[])
{
loadHostPlugin();
// styles.colors.primary = { 0x3a, 0x7d, 0x80 }; // #3a7d80
// styles.colors.secondary = { 0xff, 0xa0, 0xad }; // #ffa0ad
// styles.colors.tertiary = { 0xa0, 0xb4, 0x97 }; // #A0B497
// styles.colors.quaternary = { 0xe6, 0xc3, 0x4a }; // #e6c34a
styles.colors.primary = { 0x4f, 0xbf, 0xc5 }; // #4fbfc5
styles.colors.secondary = { 0xff, 0x8a, 0x94 }; // #ff8a94
styles.colors.tertiary = { 0xc5, 0xd8, 0xb2 }; // #c5d8b2
styles.colors.quaternary = { 0xf7, 0xda, 0x6d }; // #f7da6d
lastPluginControllerInstance = new PixelController(controllerProps, 0);
loadJsonConfig(argc >= 2 ? argv[1] : "config.json");
showLogLevel();
startHostThread();
pthread_t ptid;
pthread_create(&ptid, NULL, &uiThread, NULL);
pthread_setname_np(ptid, "ui");
// wait for uiThread to finish
pthread_join(ptid, NULL);
return 0;
}