1. 修改文件 lv_drv_conf.h,使用 linux下的触摸屏文件节点 /dev/input/event0
????????将 # ?define USE_EVDEV??0? ? ?改为? ??# ?define USE_EVDEV? ?1
2. 修改文件 lv_drivers/input/evdev.c,添加使用 tslib库代码。修改后的 evdev.c如下
/**
* @file evdev.c
*
*/
/*********************
* INCLUDES
*********************/
#include "evdev.h"
#if USE_EVDEV != 0
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
//添加tslib头文件
#include "../../tslib.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
int map(int x, int in_min, int in_max, int out_min, int out_max);
/**********************
* STATIC VARIABLES
**********************/
int evdev_fd;
int evdev_root_x;
int evdev_root_y;
int evdev_button;
int evdev_key_val;
//添加tslib结构体
struct tsdev *ts;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the evdev interface
*/
void evdev_init(void)
{
//使用tslib库
ts = ts_setup(NULL, 1);
if (!ts)
{
perror("ts_setup");
return;;
}
evdev_root_x = 0;
evdev_root_y = 0;
evdev_key_val = 0;
evdev_button = LV_INDEV_STATE_REL;
}
/**
* reconfigure the device file for evdev
* @param dev_name set the evdev device filename
* @return true: the device file set complete
* false: the device file doesn't exist current system
*/
bool evdev_set_file(char* dev_name)
{
if(evdev_fd != -1) {
close(evdev_fd);
}
evdev_fd = open(dev_name, O_RDWR | O_NOCTTY | O_NDELAY);
if(evdev_fd == -1) {
perror("unable open evdev interface:");
return false;
}
fcntl(evdev_fd, F_SETFL, O_ASYNC | O_NONBLOCK);
evdev_root_x = 0;
evdev_root_y = 0;
evdev_key_val = 0;
evdev_button = LV_INDEV_STATE_REL;
return true;
}
/**
* Get the current position and state of the evdev
* @param data store the evdev data here
* @return false: because the points are not buffered, so no more data to be read
*/
bool evdev_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
{
// tslib
struct ts_sample samp;
int ret;
/* 修改自tslib ts_print.c */
while (ts_read(ts, &samp, 1) == 1)
{
//printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec, samp.x, samp.y, samp.pressure);
#if EVDEV_SWAP_AXES
evdev_root_x = samp.y;
evdev_root_y = samp.x;
#else
evdev_root_x = samp.x;
evdev_root_y = samp.y;
#endif
if(samp.pressure == 0)
evdev_button = LV_INDEV_STATE_REL; //抬起
else if(samp.pressure < 255 && samp.pressure > 0)
evdev_button = LV_INDEV_STATE_PR; //按下
}
if(drv->type == LV_INDEV_TYPE_KEYPAD) {
/* No data retrieved */
data->key = evdev_key_val;
data->state = evdev_button;
return false;
}
if(drv->type != LV_INDEV_TYPE_POINTER)
return false;
/*Store the collected data*/
#if EVDEV_CALIBRATE
data->point.x = map(evdev_root_x, EVDEV_HOR_MIN, EVDEV_HOR_MAX, 0, lv_disp_get_hor_res(drv->disp));
data->point.y = map(evdev_root_y, EVDEV_VER_MIN, EVDEV_VER_MAX, 0, lv_disp_get_ver_res(drv->disp));
#else
data->point.x = evdev_root_x;
data->point.y = evdev_root_y;
#endif
data->state = evdev_button;
if(data->point.x < 0)
data->point.x = 0;
if(data->point.y < 0)
data->point.y = 0;
if(data->point.x >= lv_disp_get_hor_res(drv->disp))
data->point.x = lv_disp_get_hor_res(drv->disp) - 1;
if(data->point.y >= lv_disp_get_ver_res(drv->disp))
data->point.y = lv_disp_get_ver_res(drv->disp) - 1;
return false;
}
/**********************
* STATIC FUNCTIONS
**********************/
int map(int x, int in_min, int in_max, int out_min, int out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
#endif
|