}
}
+static int read_int(char const *path)
+{
+ int fd;
+ char buffer[2];
+
+ fd = open(path, O_RDONLY);
+
+ if (fd >= 0) {
+ read(fd, buffer, 1);
+ }
+ close(fd);
+
+ return atoi(buffer);
+}
+
static int write_str(char const *path, const char* value)
{
int fd;
struct light_state_t const *state)
{
int err = 0;
- static int s_previous_brightness = -1;
int brightness = rgb_to_brightness(state);
+ int previous_brightness = read_int(PANEL_FILE);
pthread_mutex_lock(&g_lock);
+
err = write_int(PANEL_FILE, brightness);
- if (!s_previous_brightness && (brightness > 0)) {
+ if (!previous_brightness && (brightness > 0)) {
err = write_int(BUTTON_FILE, brightness > 0 ? 1 : 2);
- s_previous_brightness = brightness;
}
pthread_mutex_unlock(&g_lock);