aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/flashlight.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/flashlight.c b/src/flashlight.c
index a5d7f97..55a108a 100644
--- a/src/flashlight.c
+++ b/src/flashlight.c
@@ -34,6 +34,8 @@ const char* const qcom_sysfs[] = {"/sys/class/leds/torch-light/brightness",
"/sys/class/leds/torch-light0/brightness",
"/sys/class/leds/torch-light1/brightness"};
+const char* qcom_torch_enable = "/sys/class/leds/led:switch/brightness";
+
char* flash_sysfs_path = NULL;
gboolean activated = 0;
@@ -61,7 +63,9 @@ toggle_flashlight_action(GAction *action,
gpointer data G_GNUC_UNUSED)
{
GVariant *state;
- FILE* fd;
+ FILE *fd1 = NULL, *fd2 = NULL;
+
+ int needs_enable;
if (!set_sysfs_path())
return;
@@ -69,14 +73,25 @@ toggle_flashlight_action(GAction *action,
state = g_action_get_state(action);
activated = g_variant_get_boolean(state);
g_variant_unref(state);
- fd = fopen(flash_sysfs_path, "w");
- if (fd != NULL){
- if (activated)
- fprintf(fd, QCOM_DISABLE);
+ fd1 = fopen(flash_sysfs_path, "w");
+ if (fd1 != NULL) {
+ needs_enable = access(qcom_torch_enable, F_OK ) != -1;
+ if (needs_enable)
+ fd2 = fopen(qcom_torch_enable, "w");
+ if (activated)
+ if (needs_enable && fd2 != NULL)
+ fprintf(fd2, "0");
else
- fprintf(fd, QCOM_ENABLE);
- fclose(fd);
- g_action_change_state(action, g_variant_new_boolean(!activated));
+ fprintf(fd1, QCOM_DISABLE);
+ else {
+ fprintf(fd1, QCOM_ENABLE);
+ if (needs_enable && fd2 != NULL)
+ fprintf(fd2, "1");
+ }
+ fclose(fd1);
+ if (fd2 !=NULL)
+ fclose(fd2);
+ g_action_change_state(action, g_variant_new_boolean(!activated));
}
}