Android模拟器学framework和driver之传感器篇2(生成测试tool)

之前我们已经写好了自己的driver,现在我们要在android下测试我们的tool。

 

这里我使用extern下面去编译生成一个tool,在adb shell中可以执行的,来抓取我们的温度值。

 

这一步相对简单,可以看做是linux的应用程序,附代码:

/external/temperature/temperature.c

 

  1. <strong><span style="color:#cc33cc;">#include <stdio.h>  
  2. #include <stdlib.h>  
  3. #include <fcntl.h>    
  4. #include <linux/input.h>  
  5.   
  6. /* 
  7. struct input_event 
  8. { 
  9.     struct timeval time; 
  10.     __u16 type; 
  11.     __u16 code; 
  12.     __s32 value; 
  13. };*/  
  14.   
  15. int main(void)  
  16. {  
  17.     struct input_event ev_temp;  
  18.     int fd = open("/dev/input/event2", O_RDWR);  
  19.   
  20.     while(1)  
  21.     {  
  22.         int count = read(fd, &ev_temp, sizeof(struct input_event));  
  23.         if(EV_ABS == ev_temp.type && ABS_PRESSURE == ev_temp.code)  
  24.         {  
  25.             printf("time : %ld, %d", ev_temp.time.tv_sec, ev_temp.time.tv_usec);  
  26.             printf(" Current Temperature: %d \n", ev_temp.value);  
  27.         }  
  28.     }  
  29.     return 0;  
  30. }</span></strong>  
  31. 这边我就不多说了,大家都能看懂,接下来是android的makefile,  
  1. /external/temperature/Android.mk  
  1. <pre name="code" class="cpp"><strong><span style="color:#cc33cc;">LOCAL_PATH := $(call my-dir)  
  2.   
  3. include $(CLEAR_VARS)  
  4.   
  5. LOCAL_MODULE_TAGS := optional  
  6.   
  7. LOCAL_MODULE := temperature  
  8.   
  9. LOCAL_SRC_FILES := $(call all-subdir-c-files)  
  10.   
  11. include $(BUILD_EXECUTABLE)</span></strong>  
  1.   

然后编译一下之后会在out/.../generic/system/bin下生成这个tool,

 


  1. 进入adb shell执行就可以了如下:  
  1. <pre name="code" class="cpp"><span style="color:#cc33cc;"><strong>root@jay:/home/jay# adb shell  
  2.   
  3.   
  4.   
  5.   
  6. # temperature  
  7. time : 81, 292520 Current Temperature: 1   
  8. time : 84, 40953 Current Temperature: 2   
  9. time : 86, 61726 Current Temperature: 3   
  10. time : 88, 42323 Current Temperature: 4   
  11. time : 90, 61805 Current Temperature: 5   
  12. ^C  
  13. # </strong></span>  

这样就完成了,接下来是我们temperature 的HAL,敬请期待。。。

posted on 2012-03-31 11:52  猪君  阅读(625)  评论(0编辑  收藏  举报