We have prepared our own driver before, and now we want to test our tool in android.
Here, I use extern to compile and generate a tool, which can be executed in the adb shell to capture our temperature value.
This step is relatively simple and can be seen as a linux application with code:
/External/temperature. c
<Strong> <span style = "color: # cc33cc;" >#include <stdio. h>
# Include <stdlib. h>
# Include <fcntl. h>
# Include <linux/input. h>
/*
Struct input_event
{
Struct timeval time;
_ 2010type;
_ 2010code;
_ 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;
} </Span> </strong>
I won't talk much about it here. Everyone can understand it. Next is the makefile for android,
<Strong> <span style = "color: # cc33cc;" >#include <stdio. h>
# Include <stdlib. h>
# Include <fcntl. h>
# Include <linux/input. h>
/*
Struct input_event
{
Struct timeval time;
_ 2010type;
_ 2010code;
_ 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;
} </Span> </strong>
I won't talk much about it here. Everyone can understand it. Next we will talk about makefile for android,/external/temperature/Android. mk.
/External/temperature/Android. mk <pre name = "code" class = "cpp"> <strong> <span style = "color: # cc33cc;"> 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) </span> </strong>
<Pre name = "code" class = "cpp"> <strong> <span style = "color: # cc33cc;"> 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) </span> </strong>
After compilation, the tool will be generated under out/.../generic/system/bin,
Run the following command in the adb shell:
Run the following command on the adb shell: <pre name = "code" class = "cpp"> <span style = "color: # cc33cc; "> <strong> root @ jay:/home/jay # adb shell
#
#
#
#
# Temperature
Time: 81,292 520 Current Temperature: 1
Time: 84,409 53 Current Temperature: 2
Time: 86,617 26 Current Temperature: 3
Time: 88,423 23 Current Temperature: 4
Time: 90,618 05 Current Temperature: 5
^ C
# </Strong> </span>
<Pre name = "code" class = "cpp"> <span style = "color: # cc33cc;"> <strong> root @ jay:/home/jay # adb shell
#
#
#
#
# Temperature
Time: 81,292 520 Current Temperature: 1
Time: 84,409 53 Current Temperature: 2
Time: 86,617 26 Current Temperature: 3
Time: 88,423 23 Current Temperature: 4
Time: 90,618 05 Current Temperature: 5
^ C
# </Strong> </span>
This is done. The following is the HAL of temperature, so stay tuned...
From the column zhangjie201412