-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cpp
110 lines (87 loc) · 2.68 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
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
#include <Arduino.h>
#include <M5Unified.h>
#define LV_CONF_INCLUDE_SIMPLE
#include <lvgl.h>
#include <esp_timer.h>
constexpr int32_t HOR_RES=320;
constexpr int32_t VER_RES=240;
lv_display_t *display;
lv_indev_t *indev;
void my_display_flush(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map) {
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
lv_draw_sw_rgb565_swap(px_map, w*h);
M5.Display.pushImageDMA<uint16_t>(area->x1, area->y1, w, h, (uint16_t *)px_map);
lv_disp_flush_ready(disp);
}
uint32_t my_tick_function() {
return (esp_timer_get_time() / 1000LL);
}
void my_touchpad_read(lv_indev_t * drv, lv_indev_data_t * data) {
M5.update();
auto count = M5.Touch.getCount();
if ( count == 0 ) {
data->state = LV_INDEV_STATE_RELEASED;
} else {
auto touch = M5.Touch.getDetail(0);
data->state = LV_INDEV_STATE_PRESSED;
data->point.x = touch.x;
data->point.y = touch.y;
}
}
// LVGL code - Handle multiple events demo
static void event_cb(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *label = reinterpret_cast<lv_obj_t *>(lv_event_get_user_data(e));
switch (code)
{
case LV_EVENT_PRESSED:
lv_label_set_text(label, "The last button event:\nLV_EVENT_PRESSED");
break;
case LV_EVENT_CLICKED:
lv_label_set_text(label, "The last button event:\nLV_EVENT_CLICKED");
break;
case LV_EVENT_LONG_PRESSED:
lv_label_set_text(label, "The last button event:\nLV_EVENT_LONG_PRESSED");
break;
case LV_EVENT_LONG_PRESSED_REPEAT:
lv_label_set_text(label, "The last button event:\nLV_EVENT_LONG_PRESSED_REPEAT");
break;
default:
break;
}
}
/**
* Handle multiple events
*/
void lv_example_event_2(void)
{
lv_obj_t *btn = lv_button_create(lv_screen_active());
lv_obj_set_size(btn, 100, 50);
lv_obj_center(btn);
lv_obj_t *btn_label = lv_label_create(btn);
lv_label_set_text(btn_label, "Click me!");
lv_obj_center(btn_label);
lv_obj_t *info_label = lv_label_create(lv_screen_active());
lv_label_set_text(info_label, "The last button event:\nNone");
lv_obj_add_event_cb(btn, event_cb, LV_EVENT_ALL, info_label);
}
// continue setup code
void setup() {
M5.begin();
lv_init();
lv_tick_set_cb(my_tick_function);
display = lv_display_create(HOR_RES, VER_RES);
lv_display_set_flush_cb(display, my_display_flush);
static lv_color_t buf1[HOR_RES * 15];
lv_display_set_buffers(display, buf1, nullptr, sizeof(buf1), LV_DISPLAY_RENDER_MODE_PARTIAL);
indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, my_touchpad_read);
lv_example_event_2();
}
void loop() {
lv_task_handler();
vTaskDelay(1);
}