-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlv_port_indev.cpp
81 lines (63 loc) · 1.79 KB
/
lv_port_indev.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
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright 2024 mzyy94
#include "lv_port_indev.h"
#include <M5Unified.hpp>
#include "encoder.hpp"
static void touchpad_init(void);
static void touchpad_read(lv_indev_t *indev, lv_indev_data_t *data);
static bool touchpad_is_pressed(void);
static void touchpad_get_xy(int32_t *x, int32_t *y);
static void encoder_init(void);
static void encoder_read(lv_indev_t *indev, lv_indev_data_t *data);
lv_indev_t *indev_touchpad;
lv_indev_t *indev_encoder;
Encoder encoder;
void lv_port_indev_init(void)
{
touchpad_init();
indev_touchpad = lv_indev_create();
lv_indev_set_type(indev_touchpad, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev_touchpad, touchpad_read);
//encoder_init();
//indev_encoder = lv_indev_create();
//lv_indev_set_type(indev_encoder, LV_INDEV_TYPE_ENCODER);
//lv_indev_set_read_cb(indev_encoder, encoder_read);
}
static void touchpad_init(void)
{
}
static void touchpad_read(lv_indev_t *indev_drv, lv_indev_data_t *data)
{
static int32_t last_x = 0;
static int32_t last_y = 0;
if (touchpad_is_pressed())
{
touchpad_get_xy(&last_x, &last_y);
data->state = LV_INDEV_STATE_PR;
}
else
{
data->state = LV_INDEV_STATE_REL;
}
data->point.x = last_x;
data->point.y = last_y;
}
static bool touchpad_is_pressed(void)
{
return M5.Touch.getCount() > 0;
}
static void touchpad_get_xy(int32_t *x, int32_t *y)
{
auto detail = M5.Touch.getDetail();
(*x) = detail.x;
(*y) = detail.y;
}
static void encoder_init(void)
{
encoder.setup();
}
static void encoder_read(lv_indev_t *indev_drv, lv_indev_data_t *data)
{
data->enc_diff = encoder.getCount(true);
data->state = M5.BtnA.isPressed() ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
}