码迷,mamicode.com
首页 > 移动开发 > 详细

第4课第3节_Android灯光系统_编写HAL_lights.c

时间:2017-06-22 21:43:23      阅读:960      评论:0      收藏:0      [点我收藏+]

标签:timer   nes   attribute   work   and   gen   oca   services   androi   

JNI文件:com_Android_server_LedService.cpp

 

技术分享

 

注册本地方法,会加载HAL文件:

技术分享

 

技术分享

 


3. 编写android灯光系统的hal程序


Java: frameworks/base/services/core/java/com/android/server/lights/LightsService.java
JNI: frameworks/base/services/core/jni/com_android_server_lights_LightsService.cpp
Hal: lights.c

默认配色:frameworks/base/core/res/res/values/config.xml
电池灯:frameworks/base/services/core/java/com/android/server/BatteryService.java
通知灯:frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java

怎么写LIGHTS HAL
a. 实现一个名为HMI的hw_module_t结构体
b. 实现一个open函数, 它会根据name返回一个light_device_t结构体
c. 实现多个light_device_t结构体,每一个对应一个DEVICE
light_device_t结构体里第1个成员是hw_device_t结构体, 紧接着一个set_light函数

 

HAL: lights.c


技术分享

把新文件上传到服务器, 所在目录:
hardware/libhardware/modules/lights/led_hal.c
hardware/libhardware/modules/lights/Android.mk

技术分享

Android.mk内容如下: LOCAL_PATH :
= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := lights.tiny4412 LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_C_INCLUDES := hardware/libhardware LOCAL_SRC_FILES := lights.c LOCAL_SHARED_LIBRARIES := liblog LOCAL_MODULE_TAGS := eng include $(BUILD_SHARED_LIBRARY) 修改 vi vendor/friendly-arm/tiny4412/device-tiny4412.mk ifeq ($(BOARD_USES_PWMLIGHTS),false) #PRODUCT_COPY_FILES += # $(VENDOR_PATH)/proprietary/lights.tiny4412.so:system/lib/hw/lights.tiny4412.so endif 技术分享

 


编译:
执行mmm命令之前先执行这几个命令:

技术分享

 

技术分享

技术分享

$ mmm hardware/libhardware/modules/lights
$ make snod
$ ./gen-img.sh
用这个命令确保我们提供的lights.c已经编进system.img:
diff vendor/friendly-arm/tiny4412/proprietary/lights.tiny4412.so out/target/product/tiny4412/system/lib/hw/lights.tiny4412.so
技术分享

没有修改代码进行强制编译 -B
技术分享

 

技术分享

 

技术分享
内核也需要修改:修改权限
1. drivers/leds/led-class.c: 0644 改为 0666
static struct device_attribute led_class_attrs[] = {
    __ATTR(brightness, 0666, led_brightness_show, led_brightness_store),
    __ATTR(max_brightness, 0444, led_max_brightness_show, NULL),
#ifdef CONFIG_LEDS_TRIGGERS
    __ATTR(trigger, 0666, led_trigger_show, led_trigger_store),
#endif
    __ATTR_NULL,
};

2. drivers/leds/ledtrig-timer.c: 0644 改为 0666
#if defined(CONFIG_MACH_IPCAM)
static DEVICE_ATTR(delay_on, 0666, led_delay_on_show, led_delay_on_store);
static DEVICE_ATTR(delay_off, 0666, led_delay_off_show, led_delay_off_store);
#else
static DEVICE_ATTR(delay_on, 0666, led_delay_on_show, led_delay_on_store);
static DEVICE_ATTR(delay_off, 0666, led_delay_off_show, led_delay_off_store);
#endif

make zImage



用这个命令确保我们提供的lights.c已经编进system.img:
diff vendor/friendly-arm/tiny4412/proprietary/lights.tiny4412.so out/target/product/tiny4412/system/lib/hw/lights.tiny4412.so


logcat lights:V *:S

技术分享

 


 

第4课第3节_Android灯光系统_编写HAL_lights.c

标签:timer   nes   attribute   work   and   gen   oca   services   androi   

原文地址:http://www.cnblogs.com/zhulinhaibao/p/7067104.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!