添加触摸屏
This commit is contained in:
1 parent
d8854fea10
commit
4f8260accc
16 files changed
+306
-313
No files matched your search
@@ -11,6 +11,7 @@
|
||||
#include <rtdevice.h>
|
||||
#include <board.h>
|
||||
#include "lvgl.h"
|
||||
#include "lv_demo_widgets.h"
|
||||
|
||||
#define DBG_TAG "gui"
|
||||
#define DBG_LVL DBG_LOG
|
||||
@@ -43,7 +44,8 @@ static void btn_led_off_evt_handler(lv_event_t *e)
|
||||
|
||||
void lv_user_gui_init(void)
|
||||
{
|
||||
lv_obj_t *scr = lv_scr_act();
|
||||
lv_demo_widgets();
|
||||
/* lv_obj_t *scr = lv_scr_act();
|
||||
|
||||
// 创建“按钮” —— 实际是一个可点击的普通对象
|
||||
lv_obj_t *btn_on = lv_obj_create(scr);
|
||||
@@ -69,5 +71,5 @@ void lv_user_gui_init(void)
|
||||
lv_label_set_text(label_off, "LED OFF");
|
||||
lv_obj_center(label_off);
|
||||
|
||||
lv_obj_add_event_cb(btn_off, btn_led_off_evt_handler, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_add_event_cb(btn_off, btn_led_off_evt_handler, LV_EVENT_CLICKED, NULL);*/
|
||||
}
|
||||
+145
-101
@@ -11,7 +11,11 @@
|
||||
*********************/
|
||||
#include "lv_port_indev.h"
|
||||
#include "../../lvgl.h"
|
||||
#include "ft5426.h"
|
||||
|
||||
#define DBG_TAG "LVGL_DEV"
|
||||
#define DBG_LVL DBG_LOG
|
||||
#include <rtdbg.h>
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
@@ -29,18 +33,18 @@ static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static bool touchpad_is_pressed(void);
|
||||
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
|
||||
|
||||
static void mouse_init(void);
|
||||
static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static bool mouse_is_pressed(void);
|
||||
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
|
||||
//static void mouse_init(void);
|
||||
//static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
//static bool mouse_is_pressed(void);
|
||||
//static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
|
||||
|
||||
static void keypad_init(void);
|
||||
static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static uint32_t keypad_get_key(void);
|
||||
//static void keypad_init(void);
|
||||
//static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
//static uint32_t keypad_get_key(void);
|
||||
|
||||
static void encoder_init(void);
|
||||
static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static void encoder_handler(void);
|
||||
//static void encoder_init(void);
|
||||
//static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
//static void encoder_handler(void);
|
||||
|
||||
static void button_init(void);
|
||||
static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
@@ -51,13 +55,13 @@ static bool button_is_pressed(uint8_t id);
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
lv_indev_t * indev_touchpad;
|
||||
lv_indev_t * indev_mouse;
|
||||
lv_indev_t * indev_keypad;
|
||||
lv_indev_t * indev_encoder;
|
||||
//lv_indev_t * indev_mouse;
|
||||
//lv_indev_t * indev_keypad;
|
||||
//lv_indev_t * indev_encoder;
|
||||
lv_indev_t * indev_button;
|
||||
|
||||
static int32_t encoder_diff;
|
||||
static lv_indev_state_t encoder_state;
|
||||
//static int32_t encoder_diff;
|
||||
//static lv_indev_state_t encoder_state;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@@ -81,7 +85,7 @@ void lv_port_indev_init(void)
|
||||
* You should shape them according to your hardware
|
||||
*/
|
||||
|
||||
static lv_indev_drv_t indev_drv;
|
||||
static lv_indev_drv_t indev_touch_drv ,indev_button_drv;
|
||||
|
||||
/*------------------
|
||||
* Touchpad
|
||||
@@ -91,41 +95,41 @@ void lv_port_indev_init(void)
|
||||
touchpad_init();
|
||||
|
||||
/*Register a touchpad input device*/
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read_cb = touchpad_read;
|
||||
indev_touchpad = lv_indev_drv_register(&indev_drv);
|
||||
lv_indev_drv_init(&indev_touch_drv);
|
||||
indev_touch_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_touch_drv.read_cb = touchpad_read;
|
||||
indev_touchpad = lv_indev_drv_register(&indev_touch_drv);
|
||||
|
||||
/*------------------
|
||||
* Mouse
|
||||
* -----------------*/
|
||||
|
||||
/*Initialize your mouse if you have*/
|
||||
mouse_init();
|
||||
//mouse_init();
|
||||
|
||||
/*Register a mouse input device*/
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read_cb = mouse_read;
|
||||
indev_mouse = lv_indev_drv_register(&indev_drv);
|
||||
//lv_indev_drv_init(&indev_drv);
|
||||
//indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
//indev_drv.read_cb = mouse_read;
|
||||
//indev_mouse = lv_indev_drv_register(&indev_drv);
|
||||
|
||||
/*Set cursor. For simplicity set a HOME symbol now.*/
|
||||
lv_obj_t * mouse_cursor = lv_img_create(lv_scr_act());
|
||||
lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME);
|
||||
lv_indev_set_cursor(indev_mouse, mouse_cursor);
|
||||
//lv_obj_t * mouse_cursor = lv_img_create(lv_scr_act());
|
||||
//lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME);
|
||||
//lv_indev_set_cursor(indev_mouse, mouse_cursor);
|
||||
|
||||
/*------------------
|
||||
* Keypad
|
||||
* -----------------*/
|
||||
|
||||
/*Initialize your keypad or keyboard if you have*/
|
||||
keypad_init();
|
||||
//keypad_init();
|
||||
|
||||
/*Register a keypad input device*/
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
|
||||
indev_drv.read_cb = keypad_read;
|
||||
indev_keypad = lv_indev_drv_register(&indev_drv);
|
||||
//lv_indev_drv_init(&indev_drv);
|
||||
//indev_drv.type = LV_INDEV_TYPE_KEYPAD;
|
||||
//indev_drv.read_cb = keypad_read;
|
||||
//indev_keypad = lv_indev_drv_register(&indev_drv);
|
||||
|
||||
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
||||
*add objects to the group with `lv_group_add_obj(group, obj)`
|
||||
@@ -137,13 +141,13 @@ void lv_port_indev_init(void)
|
||||
* -----------------*/
|
||||
|
||||
/*Initialize your encoder if you have*/
|
||||
encoder_init();
|
||||
//encoder_init();
|
||||
|
||||
/*Register a encoder input device*/
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_ENCODER;
|
||||
indev_drv.read_cb = encoder_read;
|
||||
indev_encoder = lv_indev_drv_register(&indev_drv);
|
||||
//lv_indev_drv_init(&indev_drv);
|
||||
//indev_drv.type = LV_INDEV_TYPE_ENCODER;
|
||||
//indev_drv.read_cb = encoder_read;
|
||||
//indev_encoder = lv_indev_drv_register(&indev_drv);
|
||||
|
||||
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
||||
*add objects to the group with `lv_group_add_obj(group, obj)`
|
||||
@@ -158,10 +162,10 @@ void lv_port_indev_init(void)
|
||||
button_init();
|
||||
|
||||
/*Register a button input device*/
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_BUTTON;
|
||||
indev_drv.read_cb = button_read;
|
||||
indev_button = lv_indev_drv_register(&indev_drv);
|
||||
lv_indev_drv_init(&indev_button_drv);
|
||||
indev_button_drv.type = LV_INDEV_TYPE_BUTTON;
|
||||
indev_button_drv.read_cb = button_read;
|
||||
indev_button = lv_indev_drv_register(&indev_button_drv);
|
||||
|
||||
/*Assign buttons to points on the screen*/
|
||||
static const lv_point_t btn_points[2] = {
|
||||
@@ -180,6 +184,42 @@ void lv_port_indev_init(void)
|
||||
* -----------------*/
|
||||
|
||||
/*Initialize your touchpad*/
|
||||
struct rt_touch_data *read_data;
|
||||
rt_device_t touch;
|
||||
|
||||
void touchpad_thread_entry(void *parameter)
|
||||
{
|
||||
read_data = (struct rt_touch_data *)rt_calloc(1, sizeof(struct rt_touch_data));
|
||||
|
||||
while(1)
|
||||
{
|
||||
rt_device_read(touch, 0, read_data, 1);
|
||||
|
||||
rt_thread_delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
int touchpad_example(void)
|
||||
{
|
||||
struct rt_touch_config cfg;
|
||||
|
||||
cfg.dev_name = "i2c1";
|
||||
rt_hw_ft5426_init("touch", &cfg);
|
||||
touch = rt_device_find("touch");
|
||||
rt_device_open(touch, RT_DEVICE_FLAG_RDONLY);
|
||||
|
||||
rt_thread_t touchpad_thread = rt_thread_create("touch", touchpad_thread_entry, RT_NULL, 800, 10, 20);
|
||||
if (touchpad_thread == RT_NULL)
|
||||
{
|
||||
LOG_D("create touchpad thread err");
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
rt_thread_startup(touchpad_thread);
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_APP_EXPORT(touchpad_example);
|
||||
|
||||
static void touchpad_init(void)
|
||||
{
|
||||
/*Your code comes here*/
|
||||
@@ -194,15 +234,16 @@ static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
/*Save the pressed coordinates and the state*/
|
||||
if(touchpad_is_pressed()) {
|
||||
touchpad_get_xy(&last_x, &last_y);
|
||||
|
||||
/*Set the last pressed coordinates*/
|
||||
data->point.x = last_y;
|
||||
data->point.y = last_x;
|
||||
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
}
|
||||
else {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
/*Set the last pressed coordinates*/
|
||||
data->point.x = last_x;
|
||||
data->point.y = last_y;
|
||||
}
|
||||
|
||||
/*Return true is the touchpad is pressed*/
|
||||
@@ -210,6 +251,9 @@ static bool touchpad_is_pressed(void)
|
||||
{
|
||||
/*Your code comes here*/
|
||||
|
||||
if (read_data->event == RT_TOUCH_EVENT_DOWN) return true;
|
||||
if (read_data->event == RT_TOUCH_EVENT_MOVE) return true;
|
||||
if (read_data->event == RT_TOUCH_EVENT_UP) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -217,78 +261,78 @@ static bool touchpad_is_pressed(void)
|
||||
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
|
||||
{
|
||||
/*Your code comes here*/
|
||||
|
||||
(*x) = 0;
|
||||
(*y) = 0;
|
||||
(*x) = read_data->x_coordinate;
|
||||
(*y) = read_data->y_coordinate;
|
||||
}
|
||||
|
||||
|
||||
/*------------------
|
||||
* Mouse
|
||||
* -----------------*/
|
||||
|
||||
/*Initialize your mouse*/
|
||||
static void mouse_init(void)
|
||||
{
|
||||
//static void mouse_init(void)
|
||||
//{
|
||||
/*Your code comes here*/
|
||||
}
|
||||
//}
|
||||
|
||||
/*Will be called by the library to read the mouse*/
|
||||
static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
//static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
//{
|
||||
/*Get the current x and y coordinates*/
|
||||
mouse_get_xy(&data->point.x, &data->point.y);
|
||||
// mouse_get_xy(&data->point.x, &data->point.y);
|
||||
|
||||
/*Get whether the mouse button is pressed or released*/
|
||||
if(mouse_is_pressed()) {
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
}
|
||||
else {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
}
|
||||
// if(mouse_is_pressed()) {
|
||||
// data->state = LV_INDEV_STATE_PR;
|
||||
// }
|
||||
// else {
|
||||
// data->state = LV_INDEV_STATE_REL;
|
||||
// }
|
||||
//}
|
||||
|
||||
/*Return true is the mouse button is pressed*/
|
||||
static bool mouse_is_pressed(void)
|
||||
{
|
||||
//static bool mouse_is_pressed(void)
|
||||
//{
|
||||
/*Your code comes here*/
|
||||
|
||||
return false;
|
||||
}
|
||||
// return false;
|
||||
//}
|
||||
|
||||
/*Get the x and y coordinates if the mouse is pressed*/
|
||||
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y)
|
||||
{
|
||||
//static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y)
|
||||
//{
|
||||
/*Your code comes here*/
|
||||
|
||||
(*x) = 0;
|
||||
(*y) = 0;
|
||||
}
|
||||
// (*x) = 0;
|
||||
// (*y) = 0;
|
||||
//}
|
||||
|
||||
/*------------------
|
||||
* Keypad
|
||||
* -----------------*/
|
||||
|
||||
/*Initialize your keypad*/
|
||||
static void keypad_init(void)
|
||||
{
|
||||
//static void keypad_init(void)
|
||||
//{
|
||||
/*Your code comes here*/
|
||||
}
|
||||
//}
|
||||
|
||||
/*Will be called by the library to read the mouse*/
|
||||
static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
static uint32_t last_key = 0;
|
||||
//static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
//{
|
||||
// static uint32_t last_key = 0;
|
||||
|
||||
/*Get the current x and y coordinates*/
|
||||
mouse_get_xy(&data->point.x, &data->point.y);
|
||||
// mouse_get_xy(&data->point.x, &data->point.y);
|
||||
|
||||
/*Get whether the a key is pressed and save the pressed key*/
|
||||
uint32_t act_key = keypad_get_key();
|
||||
if(act_key != 0) {
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
// uint32_t act_key = keypad_get_key();
|
||||
// if(act_key != 0) {
|
||||
// data->state = LV_INDEV_STATE_PR;
|
||||
|
||||
/*Translate the keys to LVGL control characters according to your key definitions*/
|
||||
switch(act_key) {
|
||||
/* switch(act_key) {
|
||||
case 1:
|
||||
act_key = LV_KEY_NEXT;
|
||||
break;
|
||||
@@ -312,43 +356,43 @@ static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
data->key = last_key;
|
||||
}
|
||||
data->key = last_key;*/
|
||||
//}
|
||||
|
||||
/*Get the currently being pressed key. 0 if no key is pressed*/
|
||||
static uint32_t keypad_get_key(void)
|
||||
{
|
||||
//static uint32_t keypad_get_key(void)
|
||||
//{
|
||||
/*Your code comes here*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
/*------------------
|
||||
* Encoder
|
||||
* -----------------*/
|
||||
|
||||
/*Initialize your keypad*/
|
||||
static void encoder_init(void)
|
||||
{
|
||||
//static void encoder_init(void)
|
||||
//{
|
||||
/*Your code comes here*/
|
||||
}
|
||||
//}
|
||||
|
||||
/*Will be called by the library to read the encoder*/
|
||||
static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
//static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
//{
|
||||
|
||||
data->enc_diff = encoder_diff;
|
||||
data->state = encoder_state;
|
||||
}
|
||||
// data->enc_diff = encoder_diff;
|
||||
// data->state = encoder_state;
|
||||
//}
|
||||
|
||||
/*Call this function in an interrupt to process encoder events (turn, press)*/
|
||||
static void encoder_handler(void)
|
||||
{
|
||||
//static void encoder_handler(void)
|
||||
//{
|
||||
/*Your code comes here*/
|
||||
|
||||
encoder_diff += 0;
|
||||
encoder_state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
// encoder_diff += 0;
|
||||
// encoder_state = LV_INDEV_STATE_REL;
|
||||
//}
|
||||
|
||||
/*------------------
|
||||
* Button
|
||||
|
||||
Reference in new issue
Block a user