Android LCD和键盘 背光亮度设置(3)

setLight_native对应的jni C/C++代码是:

文件:frameworks/base/services/jni/com_Android_server_HardwareService.cpp

static void setLight_native(JNIEnv *env, jobject clazz, int ptr,

int light, int colorARGB, int flashMode, int onMS, int offMS, int brightnessMode)

{

Devices* devices = (Devices*)ptr;

light_state_t state;

if (light < 0 || light >= LIGHT_COUNT || devices->lights[light] == NULL) {

return ;

}

memset(&state, 0, sizeof(light_state_t));

state.color = colorARGB;

state.flashMode = flashMode;

state.flashOnMS = onMS;

state.flashOffMS = offMS;

state.brightnessMode = brightnessMode;

devices->lights[light]->set_light(devices->lights[light], &state);

}

通过light标识找到对应的light设备,然后再设置亮度。

3.3 硬件原型
msm7k的lights对应的硬件原型是在:hardware/msm7k/liblights

文件:hardware/msm7k/liblights/Android.mk

LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw

LOCAL_MODULE := lights.$(TARGET_BOARD_PLATFORM)

也就是生成模块:/system/lib/hw/lights. msm7k.so

文件:hardware/msm7k/liblights/lights.c

/** Open a new instance of a lights device using name */

static int open_lights(const struct hw_module_t* module, char const* name,

struct hw_device_t** device)

{

int (*set_light)(struct light_device_t* dev,

struct light_state_t const* state);

if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) {

set_light = set_light_backlight;

}

else if (0 == strcmp(LIGHT_ID_KEYBOARD, name)) {

set_light = set_light_keyboard;

}

else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) {

set_light = set_light_buttons;

}

else if (0 == strcmp(LIGHT_ID_BATTERY, name)) {

set_light = set_light_battery;

}

else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) {

set_light = set_light_notifications;

}

else if (0 == strcmp(LIGHT_ID_ATTENTION, name)) {

set_light = set_light_attention;

}

else {

return -EINVAL;

}

pthread_once(&g_init, init_globals);

struct light_device_t *dev = malloc(sizeof(struct light_device_t));

memset(dev, 0, sizeof(*dev));

dev->common.tag = HARDWARE_DEVICE_TAG;

dev->common.version = 0;

dev->common.module = (struct hw_module_t*)module;

dev->common.close = (int (*)(struct hw_device_t*))close_lights;

dev->set_light = set_light;

*device = (struct hw_device_t*)dev;

return 0;

}

static struct hw_module_methods_t lights_module_methods = {

.open =  open_lights,

};

以上代码对应的是:

devices->lights[LIGHT_INDEX_BACKLIGHT]

= get_device(module, LIGHT_ID_BACKLIGHT);

devices->lights[LIGHT_INDEX_KEYBOARD]

= get_device(module, LIGHT_ID_KEYBOARD);

devices->lights[LIGHT_INDEX_BUTTONS]

= get_device(module, LIGHT_ID_BUTTONS);

devices->lights[LIGHT_INDEX_BATTERY]

= get_device(module, LIGHT_ID_BATTERY);

devices->lights[LIGHT_INDEX_NOTIFICATIONS]

= get_device(module, LIGHT_ID_NOTIFICATIONS);

devices->lights[LIGHT_INDEX_ATTENTION]

= get_device(module, LIGHT_ID_ATTENTION);

也就是说,对不同的亮度设置给予了不同的设置函数。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwxsww.html