求助,input子系统报点失败,在线等

dededee 2012-12-26 10:59:15
我想些一个自动报点的驱动,大虾指教为什么报点失败:
code:
button_dev = input_allocate_device(); /*alloc a device*/

set_bit(EV_ABS, button_dev->evbit);
set_bit(ABS_X, button_dev->absbit);
set_bit(ABS_Y, button_dev->absbit);
set_bit(ABS_PRESSURE, button_dev->absbit);

input_set_abs_params(button_dev, ABS_X, -240, 240, 2, 0);
input_set_abs_params(button_dev, ABS_Y, -400, 400, 2, 0);

error = input_register_device(button_dev);
while(1)
{
input_report_abs(button_dev, ABS_X, x);
input_report_abs(button_dev, ABS_Y, y);
input_report_key(button_dev, BTN_0, 1);
msleep(30);
input_sync(button_dev);
input_report_key(button_dev, BTN_0, 0);

//input_mt_sync(button_dev);
input_sync(button_dev);
msleep(50);
}
...全文
330 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dededee 2012-12-27
  • 打赏
  • 举报
回复
修改后的code: 现在的问题是不管报什么坐标,总是在屏幕中间打点,但log里显示的坐标是对的 /************************************************************** This file was added a Module to linux kernel to report piont automatic. **************************************************************/ #include <linux/input.h> #include <linux/init.h> #include <linux/module.h> #include <linux/wait.h> #include <linux/unistd.h> #include <linux/delay.h> #define MAX_X 480 #define MAX_Y 800 #define PRESS_MAX 3 #define STEP 200 static struct input_dev *button_dev; /*input device struct*/ static int __init button_init(void) { int error; int x = 0; int y = 0; int tmp_x = 0; int tmp_y = 0; int flag = 0; int count = 200; button_dev = input_allocate_device(); /*alloc a device*/ if(!button_dev) { printk(KERN_ERR "********Can not allocate device!*********\n"); error = -ENOMEM; return error; } button_dev->name="My_DEV"; /*announce that the device will generate relative coordinates*/ set_bit(EV_KEY, button_dev->keybit); set_bit(EV_ABS, button_dev->evbit); set_bit(ABS_X, button_dev->absbit); set_bit(ABS_Y, button_dev->absbit); set_bit(ABS_PRESSURE, button_dev->absbit); set_bit(BTN_TOUCH, button_dev->keybit); set_bit(ABS_MT_TOUCH_MAJOR, button_dev->absbit); set_bit(ABS_MT_POSITION_X, button_dev->absbit); set_bit(ABS_MT_POSITION_Y, button_dev->absbit); set_bit(ABS_MT_WIDTH_MAJOR, button_dev->absbit); input_set_abs_params(button_dev, ABS_MT_POSITION_X, -MAX_X/2, MAX_X/2, 0, 0); input_set_abs_params(button_dev, ABS_MT_POSITION_Y, -MAX_Y/2, MAX_Y/2, 0, 0); input_set_abs_params(button_dev, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0); error = input_register_device(button_dev); if(error) { printk(KERN_ERR "*********Failed to register device!***************\n"); return error; } while(count--) { input_report_key(button_dev, BTN_TOUCH, 1); input_report_abs(button_dev, ABS_MT_TOUCH_MAJOR, 1); input_report_abs(button_dev, ABS_MT_POSITION_X, x); input_report_abs(button_dev, ABS_MT_POSITION_Y, y); input_mt_sync(button_dev); input_sync(button_dev); //if delete this,no press msleep(100); input_report_key(button_dev, BTN_TOUCH, 0); input_mt_sync(button_dev); input_sync(button_dev); msleep(100); if(!flag) { x+=2; y+=3; } else { x = -x; y = -y; } if ((x == MAX_X/2) || (y == MAX_Y/2)) { flag = 1; } else { flag = 0; } printk("************x: %d y:%d count: %d*****************\n", x, y, count); } input_report_key(button_dev, BTN_TOUCH, 0); input_mt_sync(button_dev); input_sync(button_dev); return error; } static void __exit button_exit(void) { input_unregister_device(button_dev); printk("***********Exit kernel*************\n"); } module_init(button_init); module_exit(button_exit);
dededee 2012-12-27
  • 打赏
  • 举报
回复
引用 7 楼 weiqing1981127 的回复:
你再把你应用层测试代码贴出来看看
我通过input子系统向上报点,测试软件是用android的测试工具,之前不能报点是因为我少添加了支持的时间 set_bit(EV_ABS, button_dev->evbit); set_bit(ABS_X, button_dev->absbit); set_bit(ABS_Y, button_dev->absbit); 现在添加上后能报点,但是不管报什么坐标,总是显示在屏幕中间
流水恋歌 2012-12-26
  • 打赏
  • 举报
回复
input_report_abs(button_dev, ABS_X, x); x是怎么定义的?
流水恋歌 2012-12-26
  • 打赏
  • 举报
回复
你现在的驱动编译能通过么
流水恋歌 2012-12-26
  • 打赏
  • 举报
回复
你再把你应用层测试代码贴出来看看
dededee 2012-12-26
  • 打赏
  • 举报
回复
可以向上报点,只是上层没有处理好
dededee 2012-12-26
  • 打赏
  • 举报
回复
引用 3 楼 weiqing1981127 的回复:
你把你完整的所有代码都贴出来,我看看
还望高手赐教
dededee 2012-12-26
  • 打赏
  • 举报
回复
引用 3 楼 weiqing1981127 的回复:
你把你完整的所有代码都贴出来,我看看
我的想法是通过触摸屏事件把点报上去 /************************************************************** This file was added a Module to linux kernel to report piont automatic. **************************************************************/ #include <linux/input.h> #include <linux/init.h> #include <linux/module.h> #include <linux/wait.h> #include <linux/unistd.h> #include <linux/delay.h> #define MAX_X 480 #define MAX_Y 800 #define PRESS_MAX 3 static struct input_dev *button_dev; /*input device struct*/ static int __init button_init(void) { int error; int x = 10; int y = 10; int flag = 0; int count = 5; button_dev = input_allocate_device(); /*alloc a device*/ if(!button_dev) { printk(KERN_ERR "********Can not allocate device!*********\n"); error = -ENOMEM; return error; } /*announce that the device will generate relative coordinates*/ /* set_bit(BTN_TOUCH, button_dev->keybit); set_bit(BTN_0, button_dev->keybit); set_bit(EV_ABS, button_dev->evbit); set_bit(ABS_X, button_dev->absbit); set_bit(ABS_Y, button_dev->absbit); set_bit(ABS_PRESSURE, button_dev->absbit); input_set_abs_params(button_dev, ABS_X, -240, 240, 2, 0); input_set_abs_params(button_dev, ABS_Y, -400, 400, 2, 0); */ set_bit(BTN_TOUCH, button_dev->keybit); set_bit(ABS_MT_TOUCH_MAJOR, button_dev->absbit); set_bit(ABS_MT_POSITION_X, button_dev->absbit); set_bit(ABS_MT_POSITION_Y, button_dev->absbit); set_bit(ABS_MT_WIDTH_MAJOR, button_dev->absbit); input_set_abs_params(button_dev, ABS_MT_POSITION_X, -MAX_X, MAX_X, 0, 0); input_set_abs_params(button_dev, ABS_MT_POSITION_Y, -MAX_Y, MAX_Y, 0, 0); input_set_abs_params(button_dev, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0); error = input_register_device(button_dev); if(error) { printk(KERN_ERR "*********Failed to register device!***************\n"); return error; } while(1) { input_report_key(button_dev, BTN_TOUCH, 1); input_report_abs(button_dev, ABS_MT_TOUCH_MAJOR, 1); input_report_abs(button_dev, ABS_MT_POSITION_X, x); input_report_abs(button_dev, ABS_MT_POSITION_Y, y); input_mt_sync(button_dev); msleep(100); /* input_report_abs(button_dev, ABS_X, x); input_report_abs(button_dev, ABS_Y, y); input_report_key(button_dev, BTN_0, 1); input_sync(button_dev); */ // input_report_key(button_dev, BTN_0, 0); input_report_key(button_dev, BTN_TOUCH, 0); input_mt_sync(button_dev); input_sync(button_dev); msleep(30); /* x += MAX_X/10; y += MAX_Y/10; */ if(!flag) { x++; y++; } else { x--; y--; } if ((x > MAX_X) || (y > MAX_Y)) { flag = 1; } else if((x < -MAX_Y) || (y < -MAX_Y)) { flag = 0; } printk("************x: %d y:%d *****************\n", x, y); } return error; } static void __exit button_exit(void) { input_unregister_device(button_dev); } module_init(button_init); module_exit(button_exit);
流水恋歌 2012-12-26
  • 打赏
  • 举报
回复
你把你完整的所有代码都贴出来,我看看
dededee 2012-12-26
  • 打赏
  • 举报
回复
引用 1 楼 weiqing1981127 的回复:
input_report_abs(button_dev, ABS_X, x); x是怎么定义的?
我自己定义int型的

21,600

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧