Repository navigation
Expand file tree
/
Copy pathui.cpp
More file actions
96 lines (80 loc) · 3.22 KB
/
Copy pathui.cpp
File metadata and controls
96 lines (80 loc) · 3.22 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
#include "ui.h"
#include <lvgl.h>
#include "board.h"
static constexpr int DEGREES_PER_DETENT = 15;
static constexpr int DIAL_SEGMENT_DEGREES = 30;
static lv_obj_t *dial;
static lv_obj_t *linkLabel;
static lv_obj_t *modeLabel;
static lv_obj_t *valueLabel;
static lv_obj_t *hintLabel;
static int dialAngle = 270; // 12 o'clock in LVGL's arc coordinates
static void drawDial() {
lv_arc_set_angles(dial, dialAngle, dialAngle + DIAL_SEGMENT_DEGREES);
}
void uiBegin() {
const bool large = boardModel() == BoardModel::CrowPanel146;
const int screenSize = boardScreenSize();
const int dialMargin = large ? 12 : 8;
const int arcWidth = large ? 14 : 10;
lv_obj_t *screen = lv_screen_active();
lv_obj_set_style_bg_color(screen, lv_color_black(), 0);
dial = lv_arc_create(screen);
lv_obj_set_size(dial, screenSize - dialMargin, screenSize - dialMargin);
lv_obj_center(dial);
lv_obj_remove_style(dial, nullptr, LV_PART_KNOB);
lv_obj_remove_flag(dial, LV_OBJ_FLAG_CLICKABLE);
lv_arc_set_bg_angles(dial, 0, 360);
lv_obj_set_style_arc_width(dial, arcWidth, LV_PART_MAIN);
lv_obj_set_style_arc_width(dial, arcWidth, LV_PART_INDICATOR);
lv_obj_set_style_arc_color(dial, lv_color_hex(0x202020), LV_PART_MAIN);
drawDial();
linkLabel = lv_label_create(screen);
lv_obj_set_style_text_font(linkLabel, large ? &lv_font_montserrat_18 : &lv_font_montserrat_12, 0);
lv_obj_align(linkLabel, LV_ALIGN_TOP_MID, 0, large ? 42 : 28);
modeLabel = lv_label_create(screen);
lv_obj_set_style_text_font(modeLabel, large ? &lv_font_montserrat_28 : &lv_font_montserrat_20, 0);
lv_obj_align(modeLabel, LV_ALIGN_TOP_MID, 0, large ? 75 : 50);
valueLabel = lv_label_create(screen);
lv_obj_set_style_text_font(valueLabel, large ? &lv_font_montserrat_40 : &lv_font_montserrat_28, 0);
lv_obj_set_style_text_color(valueLabel, lv_color_white(), 0);
lv_obj_align(valueLabel, LV_ALIGN_CENTER, 0, 0);
hintLabel = lv_label_create(screen);
lv_obj_set_style_text_font(hintLabel, large ? &lv_font_montserrat_20 : &lv_font_montserrat_14, 0);
lv_obj_set_style_text_align(hintLabel, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(hintLabel, LV_ALIGN_BOTTOM_MID, 0, large ? -68 : -45);
}
void uiSetMode(const char *name, const char *hint, uint32_t color) {
lv_label_set_text(modeLabel, name);
lv_obj_set_style_text_color(modeLabel, lv_color_hex(color), 0);
lv_obj_set_style_arc_color(dial, lv_color_hex(color), LV_PART_INDICATOR);
lv_label_set_text(hintLabel, hint);
lv_obj_set_style_text_color(hintLabel, lv_color_hex(0x909090), 0);
}
void uiSetValue(const char *text) { lv_label_set_text(valueLabel, text); }
void uiTurn(int detents) {
dialAngle = ((dialAngle + detents * DEGREES_PER_DETENT) % 360 + 360) % 360;
drawDial();
}
void uiSetLink(hid::Link link) {
const char *text = "No connection";
uint32_t color = 0xE74C3C;
switch (link) {
case hid::Link::Usb:
text = "USB";
color = 0x20C878;
break;
case hid::Link::Bluetooth:
text = "Bluetooth";
color = 0x3498DB;
break;
case hid::Link::Pairing:
text = "Bluetooth pairing...";
color = 0xF39C12;
break;
case hid::Link::None:
break;
}
lv_label_set_text(linkLabel, text);
lv_obj_set_style_text_color(linkLabel, lv_color_hex(color), 0);
}