Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 1 | /* |
Ch Ganesh Kumar | 71f50f3 | 2018-03-14 16:51:43 +0530 | [diff] [blame] | 2 | * Copyright (C) 2014, 2017-2018 The Linux Foundation. All rights reserved. |
Sathish Ambley | 4342f27 | 2017-01-04 10:57:05 -0800 | [diff] [blame] | 3 | * Not a contribution |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 4 | * Copyright (C) 2008 The Android Open Source Project |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | |
| 20 | // #define LOG_NDEBUG 0 |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 21 | |
Naseer Ahmed | 79dc3b0 | 2018-03-06 20:41:14 -0500 | [diff] [blame] | 22 | #include <log/log.h> |
Xu Yang | 586c6d5 | 2016-09-19 17:54:16 +0800 | [diff] [blame] | 23 | #include <cutils/properties.h> |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 24 | #include <stdint.h> |
Arun Kumar K.R | 6203161 | 2015-07-30 11:38:19 -0700 | [diff] [blame] | 25 | #include <stdlib.h> |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <unistd.h> |
| 28 | #include <errno.h> |
| 29 | #include <fcntl.h> |
| 30 | #include <pthread.h> |
| 31 | |
| 32 | #include <sys/ioctl.h> |
| 33 | #include <sys/types.h> |
| 34 | |
| 35 | #include <hardware/lights.h> |
| 36 | |
Sathish Ambley | 4342f27 | 2017-01-04 10:57:05 -0800 | [diff] [blame] | 37 | #ifndef DEFAULT_LOW_PERSISTENCE_MODE_BRIGHTNESS |
| 38 | #define DEFAULT_LOW_PERSISTENCE_MODE_BRIGHTNESS 0x80 |
| 39 | #endif |
| 40 | |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 41 | /* #define ARIMA_DEBUG */ |
| 42 | |
| 43 | #ifdef ARIMA_DEBUG |
| 44 | #define LIGHT_DBG(fmt,args...) ALOGE("[ARIMA][%s] " fmt, __FUNCTION__, ##args) |
| 45 | #else |
| 46 | #define LIGHT_DBG(fmt,args...) do {} while (0) |
| 47 | #endif |
| 48 | |
| 49 | #define LED_FIRST_NOTIFICATION 1 |
| 50 | |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 51 | /******************************************************************************/ |
| 52 | |
| 53 | static pthread_once_t g_init = PTHREAD_ONCE_INIT; |
| 54 | static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; |
| 55 | static struct light_state_t g_notification; |
| 56 | static struct light_state_t g_battery; |
Sathish Ambley | 4342f27 | 2017-01-04 10:57:05 -0800 | [diff] [blame] | 57 | static int g_last_backlight_mode = BRIGHTNESS_MODE_USER; |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 58 | static int g_attention = 0; |
| 59 | |
| 60 | char const*const RED_LED_FILE |
| 61 | = "/sys/class/leds/red/brightness"; |
| 62 | |
| 63 | char const*const GREEN_LED_FILE |
| 64 | = "/sys/class/leds/green/brightness"; |
| 65 | |
| 66 | char const*const BLUE_LED_FILE |
| 67 | = "/sys/class/leds/blue/brightness"; |
| 68 | |
| 69 | char const*const LCD_FILE |
| 70 | = "/sys/class/leds/lcd-backlight/brightness"; |
| 71 | |
Saurabh Shah | 8b021cf | 2017-03-14 12:16:43 -0700 | [diff] [blame] | 72 | char const*const LCD_FILE2 |
| 73 | = "/sys/class/backlight/panel0-backlight/brightness"; |
| 74 | |
HuiWang | f73bc57 | 2013-07-31 10:48:36 +0800 | [diff] [blame] | 75 | char const*const BUTTON_FILE |
| 76 | = "/sys/class/leds/button-backlight/brightness"; |
| 77 | |
samin.ryu | d57c7d5 | 2012-08-03 23:59:41 +0900 | [diff] [blame] | 78 | char const*const RED_BLINK_FILE |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 79 | = "/sys/class/leds/red/breath"; |
samin.ryu | d57c7d5 | 2012-08-03 23:59:41 +0900 | [diff] [blame] | 80 | |
Ameya Thakur | 192c8ac | 2013-08-12 16:50:01 -0700 | [diff] [blame] | 81 | char const*const GREEN_BLINK_FILE |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 82 | = "/sys/class/leds/green/breath"; |
Ameya Thakur | 192c8ac | 2013-08-12 16:50:01 -0700 | [diff] [blame] | 83 | |
| 84 | char const*const BLUE_BLINK_FILE |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 85 | = "/sys/class/leds/blue/breath"; |
Ameya Thakur | 192c8ac | 2013-08-12 16:50:01 -0700 | [diff] [blame] | 86 | |
Sathish Ambley | 4342f27 | 2017-01-04 10:57:05 -0800 | [diff] [blame] | 87 | char const*const PERSISTENCE_FILE |
| 88 | = "/sys/class/graphics/fb0/msm_fb_persist_mode"; |
| 89 | |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 90 | /** |
| 91 | * device methods |
| 92 | */ |
| 93 | |
| 94 | void init_globals(void) |
| 95 | { |
| 96 | // init the mutex |
| 97 | pthread_mutex_init(&g_lock, NULL); |
| 98 | } |
| 99 | |
| 100 | static int |
| 101 | write_int(char const* path, int value) |
| 102 | { |
| 103 | int fd; |
| 104 | static int already_warned = 0; |
| 105 | |
| 106 | fd = open(path, O_RDWR); |
| 107 | if (fd >= 0) { |
| 108 | char buffer[20]; |
Manoj Kumar AVM | 001b309 | 2014-04-29 22:08:51 -0700 | [diff] [blame] | 109 | int bytes = snprintf(buffer, sizeof(buffer), "%d\n", value); |
Dileep Kumar Reddi | bf333c7 | 2014-02-25 14:32:51 +0530 | [diff] [blame] | 110 | ssize_t amt = write(fd, buffer, (size_t)bytes); |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 111 | close(fd); |
| 112 | return amt == -1 ? -errno : 0; |
| 113 | } else { |
| 114 | if (already_warned == 0) { |
| 115 | ALOGE("write_int failed to open %s\n", path); |
| 116 | already_warned = 1; |
| 117 | } |
| 118 | return -errno; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | static int |
| 123 | is_lit(struct light_state_t const* state) |
| 124 | { |
| 125 | return state->color & 0x00ffffff; |
| 126 | } |
| 127 | |
| 128 | static int |
| 129 | rgb_to_brightness(struct light_state_t const* state) |
| 130 | { |
| 131 | int color = state->color & 0x00ffffff; |
| 132 | return ((77*((color>>16)&0x00ff)) |
| 133 | + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8; |
| 134 | } |
| 135 | |
| 136 | static int |
| 137 | set_light_backlight(struct light_device_t* dev, |
| 138 | struct light_state_t const* state) |
| 139 | { |
| 140 | int err = 0; |
| 141 | int brightness = rgb_to_brightness(state); |
Sathish Ambley | 4342f27 | 2017-01-04 10:57:05 -0800 | [diff] [blame] | 142 | unsigned int lpEnabled = |
| 143 | state->brightnessMode == BRIGHTNESS_MODE_LOW_PERSISTENCE; |
Arun Kumar K.R | 0efad60 | 2014-01-21 21:32:36 -0800 | [diff] [blame] | 144 | if(!dev) { |
| 145 | return -1; |
| 146 | } |
Sathish Ambley | 4342f27 | 2017-01-04 10:57:05 -0800 | [diff] [blame] | 147 | |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 148 | pthread_mutex_lock(&g_lock); |
Sathish Ambley | 4342f27 | 2017-01-04 10:57:05 -0800 | [diff] [blame] | 149 | // Toggle low persistence mode state |
| 150 | if ((g_last_backlight_mode != state->brightnessMode && lpEnabled) || |
| 151 | (!lpEnabled && |
| 152 | g_last_backlight_mode == BRIGHTNESS_MODE_LOW_PERSISTENCE)) { |
| 153 | if ((err = write_int(PERSISTENCE_FILE, lpEnabled)) != 0) { |
| 154 | ALOGE("%s: Failed to write to %s: %s\n", __FUNCTION__, |
| 155 | PERSISTENCE_FILE, strerror(errno)); |
| 156 | } |
| 157 | if (lpEnabled != 0) { |
| 158 | brightness = DEFAULT_LOW_PERSISTENCE_MODE_BRIGHTNESS; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | g_last_backlight_mode = state->brightnessMode; |
| 163 | |
| 164 | if (!err) { |
Saurabh Shah | 8b021cf | 2017-03-14 12:16:43 -0700 | [diff] [blame] | 165 | if (!access(LCD_FILE, F_OK)) { |
| 166 | err = write_int(LCD_FILE, brightness); |
| 167 | } else { |
| 168 | err = write_int(LCD_FILE2, brightness); |
| 169 | } |
Sathish Ambley | 4342f27 | 2017-01-04 10:57:05 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 172 | pthread_mutex_unlock(&g_lock); |
| 173 | return err; |
| 174 | } |
| 175 | |
| 176 | static int |
| 177 | set_speaker_light_locked(struct light_device_t* dev, |
| 178 | struct light_state_t const* state) |
| 179 | { |
Arun Kumar K.R | 0efad60 | 2014-01-21 21:32:36 -0800 | [diff] [blame] | 180 | int red, green, blue; |
Yulian Shandorov | 784d739 | 2013-06-20 04:28:59 -0700 | [diff] [blame] | 181 | int blink; |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 182 | int onMS, offMS; |
| 183 | unsigned int colorRGB; |
| 184 | |
Arun Kumar K.R | 0efad60 | 2014-01-21 21:32:36 -0800 | [diff] [blame] | 185 | if(!dev) { |
| 186 | return -1; |
| 187 | } |
| 188 | |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 189 | switch (state->flashMode) { |
| 190 | case LIGHT_FLASH_TIMED: |
| 191 | onMS = state->flashOnMS; |
| 192 | offMS = state->flashOffMS; |
| 193 | break; |
| 194 | case LIGHT_FLASH_NONE: |
| 195 | default: |
| 196 | onMS = 0; |
| 197 | offMS = 0; |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | colorRGB = state->color; |
| 202 | |
| 203 | #if 0 |
samin.ryu | d57c7d5 | 2012-08-03 23:59:41 +0900 | [diff] [blame] | 204 | ALOGD("set_speaker_light_locked mode %d, colorRGB=%08X, onMS=%d, offMS=%d\n", |
| 205 | state->flashMode, colorRGB, onMS, offMS); |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 206 | #endif |
| 207 | |
| 208 | red = (colorRGB >> 16) & 0xFF; |
| 209 | green = (colorRGB >> 8) & 0xFF; |
| 210 | blue = colorRGB & 0xFF; |
| 211 | |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 212 | if (onMS > 0 && offMS > 0) { |
Ashay Jaiswal | 26f0b53 | 2015-05-03 17:58:58 +0530 | [diff] [blame] | 213 | /* |
| 214 | * if ON time == OFF time |
| 215 | * use blink mode 2 |
| 216 | * else |
| 217 | * use blink mode 1 |
| 218 | */ |
| 219 | if (onMS == offMS) |
| 220 | blink = 2; |
| 221 | else |
| 222 | blink = 1; |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 223 | } else { |
| 224 | blink = 0; |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 225 | } |
| 226 | |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 227 | LIGHT_DBG("red=%02X, green=%02X, blue=%02X, blink=%d\n", red, green, blue, blink); |
| 228 | |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 229 | if (blink) { |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 230 | write_int(RED_BLINK_FILE, 0); |
| 231 | write_int(GREEN_BLINK_FILE, 0); |
| 232 | write_int(BLUE_BLINK_FILE, 0); |
| 233 | /* Delay 6ms for off effective and complete */ |
| 234 | usleep(6000); |
| 235 | |
Mao Li | 728ee0b | 2014-07-01 23:06:16 +0800 | [diff] [blame] | 236 | if (red) { |
| 237 | if (write_int(RED_BLINK_FILE, blink)) |
| 238 | write_int(RED_LED_FILE, 0); |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 239 | } else { |
| 240 | write_int(RED_LED_FILE, 0); |
Ch Ganesh Kumar | 71f50f3 | 2018-03-14 16:51:43 +0530 | [diff] [blame] | 241 | } |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 242 | |
Mao Li | 728ee0b | 2014-07-01 23:06:16 +0800 | [diff] [blame] | 243 | if (green) { |
| 244 | if (write_int(GREEN_BLINK_FILE, blink)) |
| 245 | write_int(GREEN_LED_FILE, 0); |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 246 | } else { |
| 247 | write_int(GREEN_LED_FILE, 0); |
Ch Ganesh Kumar | 71f50f3 | 2018-03-14 16:51:43 +0530 | [diff] [blame] | 248 | } |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 249 | |
Mao Li | 728ee0b | 2014-07-01 23:06:16 +0800 | [diff] [blame] | 250 | if (blue) { |
| 251 | if (write_int(BLUE_BLINK_FILE, blink)) |
| 252 | write_int(BLUE_LED_FILE, 0); |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 253 | } else { |
| 254 | write_int(BLUE_LED_FILE, 0); |
Ch Ganesh Kumar | 71f50f3 | 2018-03-14 16:51:43 +0530 | [diff] [blame] | 255 | } |
Yulian Shandorov | 784d739 | 2013-06-20 04:28:59 -0700 | [diff] [blame] | 256 | } else { |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 257 | write_int(RED_LED_FILE, 0); |
| 258 | write_int(GREEN_LED_FILE, 0); |
| 259 | write_int(BLUE_LED_FILE, 0); |
| 260 | /* Delay 6ms for off effective and complete */ |
| 261 | usleep(6000); |
| 262 | |
Yulian Shandorov | 784d739 | 2013-06-20 04:28:59 -0700 | [diff] [blame] | 263 | write_int(RED_LED_FILE, red); |
| 264 | write_int(GREEN_LED_FILE, green); |
| 265 | write_int(BLUE_LED_FILE, blue); |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 266 | } |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 267 | usleep(5000); /* 5ms */ |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static void |
| 273 | handle_speaker_battery_locked(struct light_device_t* dev) |
| 274 | { |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 275 | #if LED_FIRST_NOTIFICATION |
| 276 | if (is_lit(&g_notification)) { |
| 277 | LIGHT_DBG("Notification\n"); |
| 278 | set_speaker_light_locked(dev, &g_notification); |
| 279 | } else { |
| 280 | LIGHT_DBG("Battery\n"); |
| 281 | set_speaker_light_locked(dev, &g_battery); |
| 282 | } |
| 283 | #else /* Default */ |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 284 | if (is_lit(&g_battery)) { |
| 285 | set_speaker_light_locked(dev, &g_battery); |
| 286 | } else { |
| 287 | set_speaker_light_locked(dev, &g_notification); |
| 288 | } |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 289 | #endif |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static int |
Mao Li | a4e053a | 2014-06-16 23:05:17 +0530 | [diff] [blame] | 293 | set_light_battery(struct light_device_t* dev, |
| 294 | struct light_state_t const* state) |
| 295 | { |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 296 | LIGHT_DBG("Enter...\n"); |
Mao Li | a4e053a | 2014-06-16 23:05:17 +0530 | [diff] [blame] | 297 | pthread_mutex_lock(&g_lock); |
| 298 | g_battery = *state; |
| 299 | handle_speaker_battery_locked(dev); |
| 300 | pthread_mutex_unlock(&g_lock); |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static int |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 305 | set_light_notifications(struct light_device_t* dev, |
| 306 | struct light_state_t const* state) |
| 307 | { |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 308 | LIGHT_DBG("Enter...\n"); |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 309 | pthread_mutex_lock(&g_lock); |
| 310 | g_notification = *state; |
| 311 | handle_speaker_battery_locked(dev); |
| 312 | pthread_mutex_unlock(&g_lock); |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int |
| 317 | set_light_attention(struct light_device_t* dev, |
| 318 | struct light_state_t const* state) |
| 319 | { |
| 320 | pthread_mutex_lock(&g_lock); |
| 321 | if (state->flashMode == LIGHT_FLASH_HARDWARE) { |
| 322 | g_attention = state->flashOnMS; |
| 323 | } else if (state->flashMode == LIGHT_FLASH_NONE) { |
| 324 | g_attention = 0; |
| 325 | } |
| 326 | handle_speaker_battery_locked(dev); |
| 327 | pthread_mutex_unlock(&g_lock); |
| 328 | return 0; |
| 329 | } |
| 330 | |
HuiWang | f73bc57 | 2013-07-31 10:48:36 +0800 | [diff] [blame] | 331 | static int |
| 332 | set_light_buttons(struct light_device_t* dev, |
| 333 | struct light_state_t const* state) |
| 334 | { |
| 335 | int err = 0; |
Arun Kumar K.R | 0efad60 | 2014-01-21 21:32:36 -0800 | [diff] [blame] | 336 | if(!dev) { |
| 337 | return -1; |
| 338 | } |
HuiWang | f73bc57 | 2013-07-31 10:48:36 +0800 | [diff] [blame] | 339 | pthread_mutex_lock(&g_lock); |
| 340 | err = write_int(BUTTON_FILE, state->color & 0xFF); |
| 341 | pthread_mutex_unlock(&g_lock); |
| 342 | return err; |
| 343 | } |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 344 | |
| 345 | /** Close the lights device */ |
| 346 | static int |
| 347 | close_lights(struct light_device_t *dev) |
| 348 | { |
| 349 | if (dev) { |
| 350 | free(dev); |
| 351 | } |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | |
| 356 | /******************************************************************************/ |
| 357 | |
| 358 | /** |
| 359 | * module methods |
| 360 | */ |
| 361 | |
| 362 | /** Open a new instance of a lights device using name */ |
| 363 | static int open_lights(const struct hw_module_t* module, char const* name, |
| 364 | struct hw_device_t** device) |
| 365 | { |
| 366 | int (*set_light)(struct light_device_t* dev, |
| 367 | struct light_state_t const* state); |
| 368 | |
yutingshih | 706133f | 2020-04-21 15:56:11 +0800 | [diff] [blame] | 369 | LIGHT_DBG("Enter...\n"); |
Xu Yang | 586c6d5 | 2016-09-19 17:54:16 +0800 | [diff] [blame] | 370 | if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) { |
Ch Ganesh Kumar | 71f50f3 | 2018-03-14 16:51:43 +0530 | [diff] [blame] | 371 | set_light = set_light_backlight; |
Xu Yang | 586c6d5 | 2016-09-19 17:54:16 +0800 | [diff] [blame] | 372 | } else if (0 == strcmp(LIGHT_ID_BATTERY, name)) |
Mao Li | a4e053a | 2014-06-16 23:05:17 +0530 | [diff] [blame] | 373 | set_light = set_light_battery; |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 374 | else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) |
| 375 | set_light = set_light_notifications; |
Arun Kumar K.R | 9e35f2b | 2017-08-23 13:46:03 +0530 | [diff] [blame] | 376 | else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) { |
| 377 | if (!access(BUTTON_FILE, F_OK)) { |
| 378 | // enable light button when the file is present |
| 379 | set_light = set_light_buttons; |
| 380 | } else { |
| 381 | return -EINVAL; |
| 382 | } |
| 383 | } |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 384 | else if (0 == strcmp(LIGHT_ID_ATTENTION, name)) |
| 385 | set_light = set_light_attention; |
| 386 | else |
| 387 | return -EINVAL; |
| 388 | |
| 389 | pthread_once(&g_init, init_globals); |
| 390 | |
| 391 | struct light_device_t *dev = malloc(sizeof(struct light_device_t)); |
Manoj Kumar AVM | 001b309 | 2014-04-29 22:08:51 -0700 | [diff] [blame] | 392 | |
| 393 | if(!dev) |
| 394 | return -ENOMEM; |
| 395 | |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 396 | memset(dev, 0, sizeof(*dev)); |
| 397 | |
| 398 | dev->common.tag = HARDWARE_DEVICE_TAG; |
Sathish Ambley | 4342f27 | 2017-01-04 10:57:05 -0800 | [diff] [blame] | 399 | dev->common.version = LIGHTS_DEVICE_API_VERSION_2_0; |
Sungmin Choi | b514889 | 2012-07-02 17:00:07 -0700 | [diff] [blame] | 400 | dev->common.module = (struct hw_module_t*)module; |
| 401 | dev->common.close = (int (*)(struct hw_device_t*))close_lights; |
| 402 | dev->set_light = set_light; |
| 403 | |
| 404 | *device = (struct hw_device_t*)dev; |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static struct hw_module_methods_t lights_module_methods = { |
| 409 | .open = open_lights, |
| 410 | }; |
| 411 | |
| 412 | /* |
| 413 | * The lights Module |
| 414 | */ |
| 415 | struct hw_module_t HAL_MODULE_INFO_SYM = { |
| 416 | .tag = HARDWARE_MODULE_TAG, |
| 417 | .version_major = 1, |
| 418 | .version_minor = 0, |
| 419 | .id = LIGHTS_HARDWARE_MODULE_ID, |
| 420 | .name = "lights Module", |
| 421 | .author = "Google, Inc.", |
| 422 | .methods = &lights_module_methods, |
| 423 | }; |