之前我们已经写好了自己的driver,现在我们要在android下测试我们的tool。
这里我使用extern下面去编译生成一个tool,在adb shell中可以执行的,来抓取我们的温度值。
这一步相对简单,可以看做是linux的应用程序,附代码:
/external/temperature/temperature.c
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/input.h>
/*
struct input_event
{
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};*/
int main(void)
{
struct input_event ev_temp;
int fd = open("/dev/input/event2", O_RDWR);
while(1)
{
int count = read(fd, &ev_temp, sizeof(struct input_event));
if(EV_ABS == ev_temp.type && ABS_PRESSURE == ev_temp.code)
{
printf("time : %ld, %d", ev_temp.time.tv_sec, ev_temp.time.tv_usec);
printf(" Current Temperature: %d \n", ev_temp.value);
}
}
return 0;
}
这边我就不多说了,大家都能看懂,接下来是android的makefile,
/external/temperature/Android.mk
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_MODULE := temperature LOCAL_SRC_FILES := $(call all-subdir-c-files) include $(BUILD_EXECUTABLE)
然后编译一下之后会在out/.../generic/system/bin下生成这个tool,
进入adb shell执行就可以了如下:
这样就完成了,接下来是我们temperature 的HAL,敬请期待。。。root@jay:/home/jay# adb shell # # # # # temperature time : 81, 292520 Current Temperature: 1 time : 84, 40953 Current Temperature: 2 time : 86, 61726 Current Temperature: 3 time : 88, 42323 Current Temperature: 4 time : 90, 61805 Current Temperature: 5 ^C #