input device return 都是一個 input_event 的 structure:
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
type 就定義在 linux/input.h所以 driver 只能借用用input.h 的值:
#define INPUT_EVENT_TYPE EV_MSC #define INPUT_EVENT_X MSC_SERIAL #define INPUT_EVENT_Y MSC_PULSELED #define INPUT_EVENT_Z MSC_GESTURE #define INPUT_EVENT_TIME_MSB MSC_SCAN #define INPUT_EVENT_TIME_LSB MSC_MAXg sensor 中,report data 的 function:
static void lis2dw12_report_3axes_event(struct lis2dw12_sensor_data *sdata,
s32 *xyz, s64 timestamp)
{
struct input_dev *input = sdata->input_dev;
if (!sdata->enabled)
return;
input_event(input, INPUT_EVENT_TYPE, INPUT_EVENT_X, xyz[0]);
input_event(input, INPUT_EVENT_TYPE, INPUT_EVENT_Y, xyz[1]);
input_event(input, INPUT_EVENT_TYPE, INPUT_EVENT_Z, xyz[2]);
input_event(input, INPUT_EVENT_TYPE, INPUT_EVENT_TIME_MSB,
timestamp >> 32);
input_event(input, INPUT_EVENT_TYPE, INPUT_EVENT_TIME_LSB,
timestamp & 0xffffffff);
input_sync(input);
}
所以 read( ) 讀進來的...就是...
ev.type = INPUT_EVENT_TYPE ev.code = INPUT_EVENT_X ev.value = x acceleration value所以參考前面的reading input device 的程式,修改一下..
const char *dev="/dev/input/event0";
..
..
if(ev.type == INPUT_EVENT_TYPE) {
switch(ev.code) {
case INPUT_EVENT_X:
printf("X: %d\n",ev.value);
break;
case INPUT_EVENT_Y:
printf("Y: %d\n",ev.value);
break;
case INPUT_EVENT_Z:
printf("Z: %d\n",ev.value);
break;
default:
printf("NOT VALID code: %d\n",ev.code);
}
}else{
printf("NOT VALID TYPE: %d\n",ev.type);
}
driver 的控制界面在sysfs 裡...enale it..
# ls /sys/class/input/event0/device/accel enable polling_rate resolution scale scale_avail # echo 1 > /sys/class/input/event0/device/accel/enable執行..
# ./gmonitor X: -25376 Y: -14640 Z: 973072 NOT VALID code: 4 NOT VALID code: 7 NOT VALID TYPE: 0 X: -22448 Y: -18544 Z: 967216 NOT VALID code: 4 NOT VALID code: 7 NOT VALID TYPE: 0 X: -26352 Y: -17568 Z: 968192 NOT VALID code: 4 NOT VALID code: 7 NOT VALID TYPE: 0查一下 code 4,7 和 type 0..
uapi/linux/input-event-code.h:
/* * Event types */ #define EV_SYN 0x00 ... /* * Misc events */ #define MSC_SERIAL 0x00 #define MSC_PULSELED 0x01 #define MSC_GESTURE 0x02 #define MSC_RAW 0x03 #define MSC_SCAN 0x04 #define MSC_TIMESTAMP 0x05 #define MSC_MAX 0x07 #define MSC_CNT (MSC_MAX+1)所以 type 是 EV_SYN,
code 是 INPUT_EVENT_TIME_MSB/LSB
type 是 __s64
對照上面的 driver function : lis2dw12_report_3axes_event
* fixed -- gsensormonitor
沒有留言:
張貼留言