Android(安卓)Lights
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:
- Backlight
- Keyboard
- Buttons
- Battery
- Notifications
- Attention
Building a Lights Library
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.
Interface
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.
lights.h File Reference
Data Structures
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 Project00003 *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 at00007 *00008 * http://www.apache.org/licenses/LICENSE-2.000009 *00010 * Unless required by applicable law or agreed to in writing, software00011 * 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 and00014 * limitations under the License.00015 */00016 00017 #ifndef ANDROID_LIGHTS_INTERFACE_H00018 #define ANDROID_LIGHTS_INTERFACE_H00019 00020 #include00021 #include 00022 #include 00023 00024 #include 00025 00026 __BEGIN_DECLS00027 00028 /**00029 * The id of this module00030 */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 your00036 * BUTTONS, it might make sense to also light the INDICATOR00037 * 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 higher00048 * layers, but could be someday, so we have the constants00049 * 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 000059 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 turn00063 * the light on, followed by the number of milliseconds to turn the light00064 * off.00065 */00066 #define LIGHT_FLASH_TIMED 100067 00068 /**00069 * To flash the light using hardware assist, set flashMode to00070 * the hardware mode.00071 */00072 #define LIGHT_FLASH_HARDWARE 200073 00074 /**00075 * Light brightness is managed by a user setting.00076 */00077 #define BRIGHTNESS_MODE_USER 000078 00079 /**00080 * Light brightness is managed by a light sensor.00081 */00082 #define BRIGHTNESS_MODE_SENSOR 100083 00084 /**00085 * The parameters that can be set for a given light.00086 *00087 * Not all lights must support all parameters. If you00088 * 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 (which00103 * would correspond to 255 alpha).00104 */00105 unsigned int color;00106 00107 /**00108 * See the LIGHT_FLASH_* constants00109 */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_DECLS00135 00136 #endif // ANDROID_LIGHTS_INTERFACE_H00137
原文:http://source.android.com/porting/lights.html
更多相关文章
- android 图片设置圆角
- android dumpsys
- android仿今日头条App、多种漂亮加载效果、选择器汇总、记事本Ap
- Android: 上传图片到服务器
- android切换效果、Flutter信息类App、仿饿了么点餐、仿爱壁纸应
- Android样式开发
- android小说阅读源码、bilibili源码、MVP新闻源码等
- android小说阅读源码、bilibili源码、MVP新闻源码等
- android android API Level