diff options
author | Ziyan <jaraidaniel@gmail.com> | 2016-09-25 14:24:51 +0200 |
---|---|---|
committer | Andreas Blaesius <skate4life@gmx.de> | 2016-09-26 19:54:38 +0200 |
commit | 2b99edd8aa47e00870d9043e0d1f93b6348e21fc (patch) | |
tree | cf0a41b67376ee575181276ed16fe5231e8e95da /liblights | |
parent | fab470995f7b448a60f5bec27b33b28ec9c26061 (diff) | |
download | device_samsung_espressowifi-2b99edd8aa47e00870d9043e0d1f93b6348e21fc.zip device_samsung_espressowifi-2b99edd8aa47e00870d9043e0d1f93b6348e21fc.tar.gz device_samsung_espressowifi-2b99edd8aa47e00870d9043e0d1f93b6348e21fc.tar.bz2 |
liblights: minor improvements and cleanups
Change-Id: Ie7acfa95351487b543b7dd51ddcb767736c6849d
Diffstat (limited to 'liblights')
-rwxr-xr-x | liblights/Android.mk | 14 | ||||
-rw-r--r-- | liblights/lights.c | 94 |
2 files changed, 54 insertions, 54 deletions
diff --git a/liblights/Android.mk b/liblights/Android.mk index d694fc0..5f4cffa 100755 --- a/liblights/Android.mk +++ b/liblights/Android.mk @@ -1,5 +1,5 @@ # -# Copyright (C) 2012 The Android Open Source Project +# Copyright (C) 2016 The Android Open Source Project # Copyright (C) 2012 The CyanogenMod Project # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,20 +15,16 @@ # limitations under the License. LOCAL_PATH:= $(call my-dir) + # HAL module implemenation stored in -# hw/<COPYPIX_HARDWARE_MODULE_ID>.<ro.board.platform>.so +# hw/<LIGHTS_HARDWARE_MODULE_ID>.<ro.board.platform>.so include $(CLEAR_VARS) LOCAL_SRC_FILES := lights.c - LOCAL_CFLAGS := -Wall -Werror - -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw - +LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_SHARED_LIBRARIES := liblog - -LOCAL_MODULE := lights.piranha - +LOCAL_MODULE := lights.omap4 LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) diff --git a/liblights/lights.c b/liblights/lights.c index fa55178..0838206 100644 --- a/liblights/lights.c +++ b/liblights/lights.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 The Android Open Source Project + * Copyright (C) 2016 The Android Open Source Project * Copyright (C) 2012 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,17 @@ #define LOG_TAG "lights" #include <cutils/log.h> + +#include <malloc.h> #include <stdint.h> -#include <stdlib.h> #include <string.h> #include <errno.h> #include <fcntl.h> #include <pthread.h> + #include <sys/ioctl.h> #include <sys/types.h> + #include <hardware/lights.h> static pthread_once_t g_init = PTHREAD_ONCE_INIT; @@ -33,18 +36,18 @@ static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; char const *const LCD_FILE = "/sys/class/backlight/panel/brightness"; -void -init_g_lock(void) +void init_globals(void) { - pthread_mutex_init(&g_lock, NULL); + pthread_mutex_init(&g_lock, NULL); } -static int -write_int(char const *path, int value) +static int write_int(char const *path, int value) { int fd; static int already_warned = 0; + ALOGV("%s: path %s, value %d", __func__, path, value); + fd = open(path, O_RDWR); if (fd >= 0) { char buffer[20]; @@ -54,82 +57,83 @@ write_int(char const *path, int value) return amt == -1 ? -errno : 0; } else { if (already_warned == 0) { - ALOGE("write_int failed to open %s\n", path); + ALOGE("%s: failed to open %s\n", __func__, path); already_warned = 1; } return -errno; } } -static int -rgb_to_brightness(struct light_state_t const *state) +static int rgb_to_brightness(struct light_state_t const *state) { - int color = state->color & 0x00ffffff; + int color = state->color & 0x00ffffff; - return ((77*((color>>16) & 0x00ff)) - + (150*((color>>8) & 0x00ff)) + (29*(color & 0x00ff))) >> 8; + return ((77 * ((color >> 16) & 0x00ff)) + + (150 * ((color >> 8) & 0x00ff)) + (29 * (color & 0x00ff))) >> 8; } -static int -set_light_backlight(struct light_device_t *dev __unused, - struct light_state_t const *state) +static int set_light_backlight(struct light_device_t *dev __unused, + struct light_state_t const* state) { - int err = 0; - int brightness = rgb_to_brightness(state); + int err; + int brightness = rgb_to_brightness(state); - pthread_mutex_lock(&g_lock); - ALOGV("set_light_backlight brightness=%d\n", brightness); - err = write_int(LCD_FILE, brightness); - pthread_mutex_unlock(&g_lock); + pthread_mutex_lock(&g_lock); + err = write_int(LCD_FILE, brightness); + pthread_mutex_unlock(&g_lock); - return err; + return err; } static int close_lights(struct light_device_t *dev) { - if (dev) - free(dev); + if (dev) + free(dev); - return 0; + return 0; } static int open_lights(const struct hw_module_t *module, char const *name, - struct hw_device_t **device) + struct hw_device_t** device) { -int (*set_light)(struct light_device_t* dev, + int (*set_light)(struct light_device_t* dev, struct light_state_t const* state); - if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) { + if (!strcmp(LIGHT_ID_BACKLIGHT, name)) set_light = set_light_backlight; - } - else { + else return -EINVAL; - } - pthread_once(&g_init, init_g_lock); + pthread_once(&g_init, init_globals); struct light_device_t *dev = malloc(sizeof(struct light_device_t)); + + if (!dev) + return -ENOMEM; + 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->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;} + *device = (struct hw_device_t*) dev; + + return 0; +} static struct hw_module_methods_t lights_module_methods = { - .open = open_lights, + .open = open_lights, }; struct hw_module_t HAL_MODULE_INFO_SYM = { - .tag = HARDWARE_MODULE_TAG, - .version_major = 1, - .version_minor = 0, - .id = LIGHTS_HARDWARE_MODULE_ID, - .name = "Espresso10 Lights Module", - .author = "The CyanogenMod Project", - .methods = &lights_module_methods, + .tag = HARDWARE_MODULE_TAG, + .version_major = 1, + .version_minor = 0, + .id = LIGHTS_HARDWARE_MODULE_ID, + .name = "Galaxy Tab 2 Lights Module", + .author = "The CyanogenMod Project", + .methods = &lights_module_methods, }; |