summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2014-04-22 14:18:06 +0200
committerPaul Kocialkowski <contact@paulk.fr>2014-04-23 12:08:33 +0200
commitdfd8f7142fd290bfd1160c5b5cea755ddc32b70a (patch)
treebd7a36e227d59788a1452d3259f2ef33376ddfc7
parentdc8b83974476cd4e114dcf2b9937fbd716a279cc (diff)
downloaddevice_goldelico_gta04-dfd8f7142fd290bfd1160c5b5cea755ddc32b70a.zip
device_goldelico_gta04-dfd8f7142fd290bfd1160c5b5cea755ddc32b70a.tar.gz
device_goldelico_gta04-dfd8f7142fd290bfd1160c5b5cea755ddc32b70a.tar.bz2
lights: Cleanup implementation
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--lights/Android.mk2
-rw-r--r--lights/gta04_lights.c (renamed from lights/lights.c)94
2 files changed, 56 insertions, 40 deletions
diff --git a/lights/Android.mk b/lights/Android.mk
index 9dc66f6..ac90572 100644
--- a/lights/Android.mk
+++ b/lights/Android.mk
@@ -15,7 +15,7 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := lights.c
+LOCAL_SRC_FILES := gta04_lights.c
LOCAL_SHARED_LIBRARIES := liblog
diff --git a/lights/lights.c b/lights/gta04_lights.c
index 418c5ef..b0f4194 100644
--- a/lights/lights.c
+++ b/lights/gta04_lights.c
@@ -23,8 +23,9 @@
#include <sys/ioctl.h>
#include <sys/types.h>
-#define LOG_TAG "lights"
+#define LOG_TAG "gta04_lights"
#include <cutils/log.h>
+
#include <hardware/lights.h>
/*
@@ -124,16 +125,19 @@ complete:
}
/*
- * Lights
+ * GTA04 Lights
*/
-int set_light_notifications(struct light_device_t *dev,
+int gta04_lights_set_light_notifications(struct light_device_t *device,
const struct light_state_t *state)
{
int red, green;
int max;
int rc = 0;
+ if (state == NULL)
+ return -EINVAL;
+
// GTA04 only has red and green
red = state->color & 0x00ff0000;
green = state->color & 0x0000ff00;
@@ -142,12 +146,12 @@ int set_light_notifications(struct light_device_t *dev,
// Red max
max = sysfs_value_read(notifications_red_max_brightness);
- if(max > 0)
+ if (max > 0)
red = (red * max) / 0xff;
// Green max
max = sysfs_value_read(notifications_green_max_brightness);
- if(max > 0)
+ if (max > 0)
green = (green * max) / 0xff;
rc |= sysfs_value_write(notifications_red_brightness, red);
@@ -158,13 +162,16 @@ int set_light_notifications(struct light_device_t *dev,
return rc;
}
-int set_light_battery(struct light_device_t *dev,
+int gta04_lights_set_light_battery(struct light_device_t *device,
const struct light_state_t *state)
{
int red, green;
int max;
int rc = 0;
+ if (state == NULL)
+ return -EINVAL;
+
// GTA04 only has red and green
red = state->color & 0x00ff0000;
green = state->color & 0x0000ff00;
@@ -173,12 +180,12 @@ int set_light_battery(struct light_device_t *dev,
// Red max
max = sysfs_value_read(battery_red_max_brightness);
- if(max > 0)
+ if (max > 0)
red = (red * max) / 0xff;
// Green max
max = sysfs_value_read(battery_green_max_brightness);
- if(max > 0)
+ if (max > 0)
green = (green * max) / 0xff;
rc |= sysfs_value_write(battery_red_brightness, red);
@@ -189,7 +196,7 @@ int set_light_battery(struct light_device_t *dev,
return rc;
}
-int set_light_backlight(struct light_device_t *dev,
+int gta04_lights_set_light_backlight(struct light_device_t *device,
const struct light_state_t *state)
{
int brightness;
@@ -197,14 +204,17 @@ int set_light_backlight(struct light_device_t *dev,
int max;
int rc;
- pthread_mutex_lock(&lights_mutex);
+ if (state == NULL)
+ return -EINVAL;
color = state->color & 0x00ffffff;
brightness = ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) + (29 * (color & 0xff))) >> 8;
+ pthread_mutex_lock(&lights_mutex);
+
// Brightness max
max = sysfs_value_read(backlight_max_brightness);
- if(max > 0)
+ if (max > 0)
brightness = (brightness * max) / 0xff;
rc = sysfs_value_write(backlight_brightness, brightness);
@@ -218,51 +228,57 @@ int set_light_backlight(struct light_device_t *dev,
* Interface
*/
-int close_lights(struct light_device_t *dev)
+int gta04_lights_close(struct light_device_t *device)
{
- ALOGD("%s()", __func__);
+ ALOGD("%s(%p)", __func__, device);
+
+ if (device == NULL)
+ return -EINVAL;
- if(dev != NULL)
- free(dev);
+ pthread_mutex_destroy(&lights_mutex);
+
+ free(device);
return 0;
}
-int open_lights(const struct hw_module_t *module, char const *name,
+int gta04_lights_open(const struct hw_module_t *module, char const *light_id,
struct hw_device_t **device)
{
- struct light_device_t *dev = NULL;
- int (*set_light)(struct light_device_t *dev,
+ struct light_device_t *light_device;
+ int (*set_light)(struct light_device_t *light_device,
const struct light_state_t *state);
- ALOGD("%s(%s)", __func__, name);
+ ALOGD("%s(%p, %s, %p)", __func__, module, light_id, device);
+
+ if (module == NULL || light_id == NULL || device == NULL)
+ return -EINVAL;
- if(strcmp(LIGHT_ID_BACKLIGHT, name) == 0) {
- set_light = set_light_backlight;
- } else if(strcmp(LIGHT_ID_BATTERY, name) == 0) {
- set_light = set_light_battery;
- } else if(strcmp(LIGHT_ID_NOTIFICATIONS, name) == 0) {
- set_light = set_light_notifications;
- } else {
- return -1;
- }
+ if (strcmp(LIGHT_ID_BACKLIGHT, light_id) == 0)
+ set_light = gta04_lights_set_light_backlight;
+ else if (strcmp(LIGHT_ID_BATTERY, light_id) == 0)
+ set_light = gta04_lights_set_light_battery;
+ else if (strcmp(LIGHT_ID_NOTIFICATIONS, light_id) == 0)
+ set_light = gta04_lights_set_light_notifications;
+ else
+ return -EINVAL;
pthread_mutex_init(&lights_mutex, NULL);
- dev = (struct light_device_t *) calloc(1, sizeof(struct light_device_t));
- 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;
+ light_device = (struct light_device_t *) calloc(1, sizeof(struct light_device_t));
+ light_device->common.tag = HARDWARE_DEVICE_TAG;
+ light_device->common.version = 0;
+ light_device->common.module = (struct hw_module_t *) module;
+ light_device->common.close = (int (*)(struct hw_device_t *)) gta04_lights_close;
+ light_device->set_light = set_light;
- *device = (struct hw_device_t *) dev;
+ *device = (struct hw_device_t *) light_device;
return 0;
}
-struct hw_module_methods_t lights_module_methods = {
- .open = open_lights,
+struct hw_module_methods_t gta04_lights_module_methods = {
+ .open = gta04_lights_open,
};
struct hw_module_t HAL_MODULE_INFO_SYM = {
@@ -270,7 +286,7 @@ struct hw_module_t HAL_MODULE_INFO_SYM = {
.version_major = 1,
.version_minor = 0,
.id = LIGHTS_HARDWARE_MODULE_ID,
- .name = "Goldelico GTA04 lights",
+ .name = "GTA04 Lights",
.author = "Paul Kocialkowski",
- .methods = &lights_module_methods,
+ .methods = &gta04_lights_module_methods,
};