Android模擬器學framework和driver之傳感器篇2(生成測試tool)

之前我們已經寫好瞭自己的driver,現在我們要在android下測試我們的tool。
 
 
 
 
這裡我使用extern下面去編譯生成一個tool,在adb shell中可以執行的,來抓取我們的溫度值。
 
 
 
 
這一步相對簡單,可以看做是linux的應用程序,附代碼:
 
/external/temperature/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;
    __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; 
}</span></strong> 
這邊我就不多說瞭,大傢都能看懂,接下來是android的makefile, 
<strong><span style="color:#cc33cc;">#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;
}</span></strong>
這邊我就不多說瞭,大傢都能看懂,接下來是android的makefile,/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> 
然後編譯一下之後會在out/…/generic/system/bin下生成這個tool,
 
 
進入adb shell執行就可以瞭如下: 
進入adb shell執行就可以瞭如下:<pre name="code" class="cpp"><span style="color:#cc33cc;"><strong>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 
# </strong></span> 
<pre name="code" class="cpp"><span style="color:#cc33cc;"><strong>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
# </strong></span>
這樣就完成瞭,接下來是我們temperature 的HAL,敬請期待。。。
 

摘自 zhangjie201412的專欄

發佈留言