aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2018-07-14 11:46:12 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2018-07-14 11:46:12 +0800
commitea652045bb38651d99bcc53972a524f602c3b306 (patch)
treeea7bf5f5b3f0a76faf07bfeb944b3a56f6afd527 /tools
parente5aac499a8a2026af5d5176f45be3ac2576d75cc (diff)
downloadlightsd-ea652045bb38651d99bcc53972a524f602c3b306.tar.xz
Added a simple tool to create a fake sysfs backlight interface
that invokes external commands. Some changes in the utility module to accomodate the new tool. Added an option to watch ALS readings.
Diffstat (limited to 'tools')
-rw-r--r--tools/fakebl.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/tools/fakebl.c b/tools/fakebl.c
new file mode 100644
index 0000000..dc2d9b9
--- /dev/null
+++ b/tools/fakebl.c
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+char *path;
+char *brpath;
+char *mbrpath;
+char *cmd;
+char *rcmd;
+FILE *brf;
+int setup_dir()
+{
+ int r=mkdir(path,0755);
+ brpath=malloc(strlen(path)+12);
+ mbrpath=malloc(strlen(path)+16);
+ strcpy(brpath,path);
+ strcpy(mbrpath,path);
+ strcat(brpath,"/brightness");
+ strcat(mbrpath,"/max_brightness");
+ r|=mkfifo(brpath,0666);
+ FILE* mbrf=fopen(mbrpath,"w");
+ r|=(mbrf==NULL);
+ if(mbrf)fputs("100\n",mbrf);
+ fclose(mbrf);
+ return r;
+}
+void remove_dir()
+{
+ unlink(brpath);
+ unlink(mbrpath);
+ rmdir(path);
+ free(brpath);
+ free(mbrpath);
+}
+void usage(char* s)
+{
+ printf("usage: %s -c <cmd> -p <path>\n",s);
+ _exit(1);
+}
+int main(int argc,char **argv)
+{
+ if(argc<5)usage(argv[0]);
+ for(int i=1;i<argc-1;++i)
+ {
+ if(!strcmp(argv[i],"-c"))cmd=strdup(argv[i+1]);
+ if(!strcmp(argv[i],"-p"))path=strdup(argv[i+1]);
+ }
+ if(!cmd||!path)
+ {
+ if(cmd)free(cmd);
+ if(path)free(path);
+ usage(argv[0]);
+ }
+ if(setup_dir())return puts("error setting up fake brightness interface"),1;
+ rcmd=malloc(strlen(cmd)+16);
+ while((brf=fopen(brpath,"r")))
+ {
+ char dat[64],*eptr;
+ eptr=fgets(dat,64,brf);//unused return value
+ int v=strtol(dat,&eptr,10),r;
+ if(eptr==dat)break;
+ snprintf(rcmd,strlen(cmd)+16,cmd,v);
+ if((r=system(rcmd)))
+ printf("%s returned %d\n",rcmd,r);
+ fclose(brf);
+ }
+ remove_dir();
+ free(path);
+ free(cmd);
+ free(rcmd);
+ return 0;
+}