diff options
author | Koushik Dutta <koushd@gmail.com> | 2011-11-20 21:58:36 -0800 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2011-11-20 21:58:36 -0800 |
commit | 4aefda8d63e0cc887366adf3cc1347af84dfb729 (patch) | |
tree | b2c88ec0192b222f12e2d9b78ddf625142d116f5 /liblight | |
parent | 16754dd56552e914576971ddc53ef852ca84244c (diff) | |
download | device_samsung_crespo-4aefda8d63e0cc887366adf3cc1347af84dfb729.tar.gz device_samsung_crespo-4aefda8d63e0cc887366adf3cc1347af84dfb729.tar.bz2 device_samsung_crespo-4aefda8d63e0cc887366adf3cc1347af84dfb729.zip |
squash changes
Diffstat (limited to 'liblight')
-rwxr-xr-x | liblight/lights.c | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/liblight/lights.c b/liblight/lights.c index ee6416a..28b7599 100755 --- a/liblight/lights.c +++ b/liblight/lights.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2011 <kang@insecure.ws> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,6 +15,7 @@ * limitations under the License. */ +// #define LOG_NDEBUG 0 #define LOG_TAG "lights" #include <cutils/log.h> #include <stdint.h> @@ -29,13 +31,12 @@ static pthread_once_t g_init = PTHREAD_ONCE_INIT; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; char const *const LCD_FILE = "/sys/class/backlight/s5p_bl/brightness"; +char const *const LED_FILE = "/sys/class/misc/notification/led"; static int write_int(char const *path, int value) { int fd; - static int already_warned; - - already_warned = 0; + static int already_warned = 0; LOGV("write_int: path %s, value %d", path, value); fd = open(path, O_RDWR); @@ -55,6 +56,32 @@ static int write_int(char const *path, int value) } } +static int read_int(char const *path) +{ + int fd; + static int already_warned = 0; + + LOGV("read_int: path %s", path); + fd = open(path, O_RDWR); + + if (fd >= 0) { + char cValor; + int amt = read(fd, &cValor, 1); + close(fd); + if (amt == -1 ) + return -errno; + else + return atoi(&cValor); + return amt == -1 ? -errno : 0; + } else { + if (already_warned == 0) { + LOGE("read_int failed to open %s\n", path); + already_warned = 1; + } + return -errno; + } +} + static int rgb_to_brightness(struct light_state_t const *state) { int color = state->color & 0x00ffffff; @@ -63,6 +90,30 @@ static int rgb_to_brightness(struct light_state_t const *state) + (150*((color>>8) & 0x00ff)) + (29*(color & 0x00ff))) >> 8; } +static int set_light_notifications(struct light_device_t* dev, + struct light_state_t const* state) +{ + int brightness = rgb_to_brightness(state); + int v = 0; + int ret = 0; + int iAct; + + pthread_mutex_lock(&g_lock); + if (brightness+state->color == 0 || brightness > 100) { + if (state->color & 0x00ffffff) + v = 1; + } else + v = 0; + iAct = read_int(LED_FILE); + LOGI("color %u fm %u status %u is lit %u brightness iAct: %d", state->color, state->flashMode, v, (state->color & 0x00ffffff), brightness, iAct); + if ( iAct == 2 && v == 1 ) + v = 2; + ret = write_int(LED_FILE, v); + pthread_mutex_unlock(&g_lock); + + return ret; +} + static int set_light_backlight(struct light_device_t *dev, struct light_state_t const *state) { @@ -95,6 +146,8 @@ static int open_lights(const struct hw_module_t *module, char const *name, if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) set_light = set_light_backlight; + else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) + set_light = set_light_notifications; else return -EINVAL; |