第4課第3節_Android燈光系統_編寫HAL_lights.c
阿新 • • 發佈:2017-06-22
name java values delay use 進行 ipc col drive
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