diff options
author | qctecmdr <qctecmdr@localhost> | 2021-08-23 06:36:00 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2021-08-23 06:36:00 -0700 |
commit | 9fd9fbe2962025d8b3b780009704eaa1e3583176 (patch) | |
tree | 024758753ceef2beadab22ec4421ddd79913cce5 | |
parent | 9cc7717c320771b5997d17c04817568a4b100807 (diff) | |
parent | 87f4058dc3c5d217e5d1ba97ac735fca05248a9a (diff) |
Merge "liblight: set "timer" trigger before setting delay for blinking"
-rw-r--r-- | liblight/lights.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/liblight/lights.c b/liblight/lights.c index f74fb542..16387db2 100644 --- a/liblight/lights.c +++ b/liblight/lights.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014, 2017-2018 The Linux Foundation. All rights reserved. + * Copyright (C) 2014, 2017-2018, 2020, The Linux Foundation. All rights reserved. * Not a contribution * Copyright (C) 2008 The Android Open Source Project * @@ -81,6 +81,21 @@ void init_globals(void) pthread_mutex_init(&g_lock, NULL); } +static int write_str(char const* path, char const* str) +{ + int fd; + + fd = open(path, O_RDWR); + if (fd >= 0) { + ssize_t amt = write(fd, str, strlen(str)); + close(fd); + return amt == -1 ? -errno : 0; + } + + ALOGE("write_str failed to open %s, errno = %d\n", path, errno); + return -errno; +} + static int write_int(char const* path, int value) { int fd; @@ -176,9 +191,21 @@ set_light_backlight(struct light_device_t* dev, static int set_rgb_led_brightness(enum rgb_led led, int brightness) { char file[48]; + int rc; snprintf(file, sizeof(file), "/sys/class/leds/%s/brightness", led_names[led]); - return write_int(file, brightness); + rc = write_int(file, brightness); + if (rc < 0) + return rc; + + if (!brightness) { + snprintf(file, sizeof(file), "/sys/class/leds/%s/trigger", led_names[led]); + rc = write_str(file, "timer"); + if (rc < 0) + ALOGE("Couldn't set trigger to timer for %s, rc=%d\n", led_names[led], rc); + } + + return rc; } static int set_rgb_led_timer_trigger(enum rgb_led led, int onMS, int offMS) @@ -208,7 +235,7 @@ static int set_rgb_led_hw_blink(enum rgb_led led, int blink) snprintf(file, sizeof(file), "/sys/class/leds/%s/breath", led_names[led]); if (!file_exists(file)) - snprintf(file, sizeof(file), "/sys/class/leds/%s/blink", led_names[led]); + return -1; return write_int(file, blink); } |