├── Android.mk └── lights.c /Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | LOCAL_PATH:= $(call my-dir) 17 | # HAL module implemenation stored in 18 | # hw/..so 19 | include $(CLEAR_VARS) 20 | 21 | LOCAL_SRC_FILES := lights.c 22 | 23 | 24 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 25 | 26 | LOCAL_SHARED_LIBRARIES := liblog 27 | 28 | LOCAL_MODULE_TAGS := optional 29 | LOCAL_MODULE := lights.$(TARGET_BOARD_PLATFORM) 30 | 31 | include $(BUILD_SHARED_LIBRARY) 32 | -------------------------------------------------------------------------------- /lights.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | // #define LOG_NDEBUG 0 19 | #define LOG_TAG "lights" 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | /******************************************************************************/ 35 | 36 | char const*const LCD_FILE 37 | = "/sys/class/backlight/lemote/brightness"; 38 | 39 | /** 40 | * device methods 41 | */ 42 | 43 | static int 44 | write_int(char const* path, int value) 45 | { 46 | int fd; 47 | static int already_warned = 0; 48 | 49 | fd = open(path, O_RDWR); 50 | if (fd >= 0) { 51 | char buffer[20]; 52 | int bytes = sprintf(buffer, "%d\n", value); 53 | int amt = write(fd, buffer, bytes); 54 | close(fd); 55 | return amt == -1 ? -errno : 0; 56 | } else { 57 | if (already_warned == 0) { 58 | LOGE("write_int failed to open %s\n", path); 59 | already_warned = 1; 60 | } 61 | return -errno; 62 | } 63 | } 64 | 65 | static int 66 | rgb_to_brightness(struct light_state_t const* state) 67 | { 68 | return (state->color & 0x000000ff); 69 | } 70 | 71 | static int 72 | set_light_backlight(struct light_device_t* dev, 73 | struct light_state_t const* state) 74 | { 75 | int brightness = rgb_to_brightness(state); 76 | brightness = (int)((float)brightness/256.0 * 10); 77 | return write_int(LCD_FILE, brightness); 78 | } 79 | 80 | /** Close the lights device */ 81 | static int 82 | close_lights(struct light_device_t *dev) 83 | { 84 | if (dev) { 85 | free(dev); 86 | } 87 | return 0; 88 | } 89 | 90 | 91 | /******************************************************************************/ 92 | 93 | /** 94 | * module methods 95 | */ 96 | 97 | /** Open a new instance of a lights device using name */ 98 | static int open_lights(const struct hw_module_t* module, char const* name, 99 | struct hw_device_t** device) 100 | { 101 | int (*set_light)(struct light_device_t* dev, 102 | struct light_state_t const* state); 103 | 104 | if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) { 105 | set_light = set_light_backlight; 106 | } 107 | else { 108 | return -EINVAL; 109 | } 110 | 111 | struct light_device_t *dev = malloc(sizeof(struct light_device_t)); 112 | memset(dev, 0, sizeof(*dev)); 113 | 114 | dev->common.tag = HARDWARE_DEVICE_TAG; 115 | dev->common.version = 0; 116 | dev->common.module = (struct hw_module_t*)module; 117 | dev->common.close = (int (*)(struct hw_device_t*))close_lights; 118 | dev->set_light = set_light; 119 | 120 | *device = (struct hw_device_t*)dev; 121 | return 0; 122 | } 123 | 124 | 125 | static struct hw_module_methods_t lights_module_methods = { 126 | .open = open_lights, 127 | }; 128 | 129 | /* 130 | * The lights Module 131 | */ 132 | const struct hw_module_t HAL_MODULE_INFO_SYM = { 133 | .tag = HARDWARE_MODULE_TAG, 134 | .version_major = 1, 135 | .version_minor = 0, 136 | .id = LIGHTS_HARDWARE_MODULE_ID, 137 | .name = "Lemote LS3A laptop lights Module", 138 | .author = "Lemote, Inc.", 139 | .methods = &lights_module_methods, 140 | }; 141 | --------------------------------------------------------------------------------