Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-liblights: Commit

hardware/liblights


Commit MetaInfo

Revision1b56f57da510b43bd2c9c9f77e88e793b672186b (tree)
Time2013-02-28 02:06:49
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

search brightness under /sys/class/backlight automatically

Change Summary

Incremental Difference

--- a/lights.c
+++ b/lights.c
@@ -18,6 +18,8 @@
1818
1919 #include <cutils/log.h>
2020
21+#include <sys/types.h>
22+#include <dirent.h>
2123 #include <stdint.h>
2224 #include <string.h>
2325 #include <unistd.h>
@@ -39,9 +41,6 @@ char const*const LLP_BRIGHTNESS_FILE = "backlight.brightness_file";
3941 char const*const LLP_MAX_BRIGHTNESS_FILE = "backlight.max_brightness_file";
4042 char const*const LLP_MAX_BRIGHTNESS = "backlight.max_brightness";
4143
42-char const*const DEF_LLP_BRIGHTNESS_FILE = "/sys/class/backlight/acpi_video0/brightness";
43-char const*const DEF_LLP_MAX_BRIGHTNESS_FILE = "/sys/class/backlight/acpi_video0/max_brightness";
44-
4544 void init_globals(void)
4645 {
4746 pthread_mutex_init(&g_lock, NULL);
@@ -110,6 +109,44 @@ static int close_lights(struct light_device_t *dev)
110109 return 0;
111110 }
112111
112+static int check_backlight_file(char const* name, char* path)
113+{
114+ int ret;
115+ if (access(name, F_OK)) {
116+ ret = 0;
117+ } else {
118+ ALOGD("Detect %s", name);
119+ strcpy(path, name);
120+ ret = 1; // found
121+ }
122+ return ret;
123+}
124+
125+static int find_backlight_file(char const* file, char* path)
126+{
127+ int ret;
128+ char name[PATH_MAX];
129+ const char* dirname = "/sys/class/backlight";
130+
131+ // Check acpi_video0 first. It seems to work in most cases.
132+ snprintf(name, PATH_MAX, "%s/acpi_video0/%s", dirname, file);
133+ if (!(ret = check_backlight_file(name, path))) {
134+ DIR* dir = opendir(dirname);
135+ if (dir != NULL) {
136+ struct dirent* de;
137+ while ((de = readdir(dir))) {
138+ if (de->d_name[0] != '.') {
139+ snprintf(name, PATH_MAX, "%s/%s/%s", dirname, de->d_name, file);
140+ if ((ret = check_backlight_file(name, path))) {
141+ break;
142+ }
143+ }
144+ }
145+ closedir(dir);
146+ }
147+ }
148+ return ret;
149+}
113150
114151 static int open_lights(const struct hw_module_t* module, char const* name, struct hw_device_t** device)
115152 {
@@ -125,10 +162,11 @@ static int open_lights(const struct hw_module_t* module, char const* name, struc
125162 return -EINVAL;
126163 }
127164 } else {
128- if (property_get(LLP_MAX_BRIGHTNESS_FILE, max_b_file, DEF_LLP_MAX_BRIGHTNESS_FILE)) {
165+ if (property_get(LLP_MAX_BRIGHTNESS_FILE, max_b_file, NULL) ||
166+ find_backlight_file("max_brightness", max_b_file)) {
129167 max_brightness = read_int(max_b_file);
130168 } else {
131- ALOGE("%s system property not set", LLP_MAX_BRIGHTNESS_FILE);
169+ ALOGE("Unable to detect max_brightness. Try to set %s", LLP_MAX_BRIGHTNESS_FILE);
132170 return -EINVAL;
133171 }
134172 }
@@ -136,7 +174,8 @@ static int open_lights(const struct hw_module_t* module, char const* name, struc
136174 if (max_brightness < 1) {
137175 max_brightness = 255;
138176 }
139- if (!property_get(LLP_BRIGHTNESS_FILE, brightness_file, DEF_LLP_BRIGHTNESS_FILE)) {
177+ if (!property_get(LLP_BRIGHTNESS_FILE, brightness_file, NULL) &&
178+ !find_backlight_file("brightness", brightness_file)) {
140179 ALOGE("%s system property not set", LLP_BRIGHTNESS_FILE);
141180 return -EINVAL;
142181 }
Show on old repository browser