Android defines a user space C abstraction interface for LED hardware. The interface header is defined inhardware/libhardware/include/hardware/lights.h
. In order to integrate LEDs with Android you need to build a shared library that implements this interface. The types of logical lights currently supported by Android include:
To implement a Lights driver, create a shared library that implements the interface defined in lights.h
. You must name your shared library liblights.so
so that it will get loaded from /system/lib
at runtime.
Note: This document relies on some Doxygen-generated content that appears in an iFrame below. To return to the Doxygen default content for this page, click here.
struct light_device_
tstruct light_state_t
The parameters that can be set for a given light. More...
00001 /* 00002 * Copyright (C) 2008 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef ANDROID_LIGHTS_INTERFACE_H 00018 #define ANDROID_LIGHTS_INTERFACE_H 00019 00020 #include <stdint.h> 00021 #include <sys/cdefs.h> 00022 #include <sys/types.h> 00023 00024 #include <hardware/hardware.h> 00025 00026 __BEGIN_DECLS 00027 00028 /** 00029 * The id of this module 00030 */ 00031 #define LIGHTS_HARDWARE_MODULE_ID "lights" 00032 00033 /* 00034 * These light IDs correspond to logical lights, not physical. 00035 * So for example, if your INDICATOR light is in line with your 00036 * BUTTONS, it might make sense to also light the INDICATOR 00037 * light to a reasonable color when the BUTTONS are lit. 00038 */ 00039 #define LIGHT_ID_BACKLIGHT "backlight" 00040 #define LIGHT_ID_KEYBOARD "keyboard" 00041 #define LIGHT_ID_BUTTONS "buttons" 00042 #define LIGHT_ID_BATTERY "battery" 00043 #define LIGHT_ID_NOTIFICATIONS "notifications" 00044 #define LIGHT_ID_ATTENTION "attention" 00045 00046 /* 00047 * These lights aren't currently supported by the higher 00048 * layers, but could be someday, so we have the constants 00049 * here now. 00050 */ 00051 #define LIGHT_ID_BLUETOOTH "bluetooth" 00052 #define LIGHT_ID_WIFI "wifi" 00053 00054 /* ************************************************************************ 00055 * Flash modes for the flashMode field of light_state_t. 00056 */ 00057 00058 #define LIGHT_FLASH_NONE 0 00059 00060 /** 00061 * To flash the light at a given rate, set flashMode to LIGHT_FLASH_TIMED, 00062 * and then flashOnMS should be set to the number of milliseconds to turn 00063 * the light on, followed by the number of milliseconds to turn the light 00064 * off. 00065 */ 00066 #define LIGHT_FLASH_TIMED 1 00067 00068 /** 00069 * To flash the light using hardware assist, set flashMode to 00070 * the hardware mode. 00071 */ 00072 #define LIGHT_FLASH_HARDWARE 2 00073 00074 /** 00075 * Light brightness is managed by a user setting. 00076 */ 00077 #define BRIGHTNESS_MODE_USER 0 00078 00079 /** 00080 * Light brightness is managed by a light sensor. 00081 */ 00082 #define BRIGHTNESS_MODE_SENSOR 1 00083 00084 /** 00085 * The parameters that can be set for a given light. 00086 * 00087 * Not all lights must support all parameters. If you 00088 * can do something backward-compatible, you should. 00089 */ 00090 struct light_state_t { 00091 /** 00092 * The color of the LED in ARGB. 00093 * 00094 * Do your best here. 00095 * - If your light can only do red or green, if they ask for blue, 00096 * you should do green. 00097 * - If you can only do a brightness ramp, then use this formula: 00098 * unsigned char brightness = ((77*((color>>16)&0x00ff)) 00099 * + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8; 00100 * - If you can only do on or off, 0 is off, anything else is on. 00101 * 00102 * The high byte should be ignored. Callers will set it to 0xff (which 00103 * would correspond to 255 alpha). 00104 */ 00105 unsigned int color; 00106 00107 /** 00108 * See the LIGHT_FLASH_* constants 00109 */ 00110 int flashMode; 00111 int flashOnMS; 00112 int flashOffMS; 00113 00114 /** 00115 * Policy used by the framework to manage the light's brightness. 00116 * Currently the values are BRIGHTNESS_MODE_USER and BRIGHTNESS_MODE_SENSOR. 00117 */ 00118 int brightnessMode; 00119 }; 00120 00121 struct light_device_t { 00122 struct hw_device_t common; 00123 00124 /** 00125 * Set the provided lights to the provided values. 00126 * 00127 * Returns: 0 on succes, error code on failure. 00128 */ 00129 int (*set_light)(struct light_device_t* dev, 00130 struct light_state_t const* state); 00131 }; 00132 00133 00134 __END_DECLS 00135 00136 #endif // ANDROID_LIGHTS_INTERFACE_H 00137
原文:http://source.android.com/porting/lights.html