Added get and list commands
This commit is contained in:
parent
dda74af557
commit
8df38899e1
5
TODO
5
TODO
@ -1,4 +1,5 @@
|
||||
#Individual device control
|
||||
List devices
|
||||
Query backlight percentage (get)
|
||||
#List devices
|
||||
#Query backlight percentage (get)
|
||||
allow fade in and fade out
|
||||
a lot of cleanup
|
||||
|
||||
@ -26,17 +26,6 @@
|
||||
#define OP_GET 128
|
||||
#define OP_NONE 0
|
||||
|
||||
#define GET_LONG_OPT "--get"
|
||||
#define GET_SHORT_OPT "-g"
|
||||
#define FADE_LONG_OPT "--fade"
|
||||
#define FADE_SHORT_OPT "-f"
|
||||
#define DEVICE_LONG_OPT "--device"
|
||||
#define DEVICE_SHORT_OPT "-d"
|
||||
#define LIST_LONG_OPT "--list"
|
||||
#define LIST_SHORT_OPT "-l"
|
||||
#define HELP_LONG_OPT "--help"
|
||||
#define HELP_SHORT_OPT "-h"
|
||||
|
||||
struct cmd_arg{
|
||||
const char* lopt;
|
||||
const char* sopt;
|
||||
|
||||
16
src/cmd.c
16
src/cmd.c
@ -23,13 +23,25 @@
|
||||
#include "cmd.h"
|
||||
#include "common.h"
|
||||
|
||||
#define GET_LONG_OPT "--get"
|
||||
#define GET_SHORT_OPT "-g"
|
||||
#define FADE_LONG_OPT "--fade"
|
||||
#define FADE_SHORT_OPT "-f"
|
||||
#define DEVICE_LONG_OPT "--device"
|
||||
#define DEVICE_SHORT_OPT "-d"
|
||||
#define LIST_LONG_OPT "--list"
|
||||
#define LIST_SHORT_OPT "-l"
|
||||
#define HELP_LONG_OPT "--help"
|
||||
#define HELP_SHORT_OPT "-h"
|
||||
|
||||
|
||||
#define CHECK_OPTION(opt, arg) (!strcmp(opt##_LONG_OPT, arg) || !strcmp(opt##_SHORT_OPT, arg))
|
||||
|
||||
struct cmd_arg rexbacklight_args[] = {
|
||||
{DEVICE_LONG_OPT, DEVICE_SHORT_OPT, "select which device to control"},
|
||||
{FADE_LONG_OPT, FADE_SHORT_OPT, "TODO: change brightness over time interval"},
|
||||
{GET_LONG_OPT, GET_SHORT_OPT, "TODO: print current brightness level to stdout"},
|
||||
{LIST_LONG_OPT, LIST_SHORT_OPT, "TODO: print device names to stdout and exit"},
|
||||
{GET_LONG_OPT, GET_SHORT_OPT, "print current brightness level to stdout"},
|
||||
{LIST_LONG_OPT, LIST_SHORT_OPT, "print device names to stdout and exit"},
|
||||
{HELP_LONG_OPT, HELP_SHORT_OPT, "print this help message and exit"}
|
||||
};
|
||||
int rexbacklight_args_length = sizeof(rexbacklight_args) / sizeof(rexbacklight_args[0]);
|
||||
|
||||
@ -170,16 +170,45 @@ int main(int argc, char** argv){
|
||||
fprintf(stderr, "Unable to open backlight directory \"%s%s\"!\n", backlight_dir, curr->device);
|
||||
continue;
|
||||
}
|
||||
write_delta(curr);
|
||||
switch(curr->operation){
|
||||
case OP_SET:
|
||||
case OP_INC:
|
||||
case OP_DEC:
|
||||
write_delta(curr);
|
||||
break;
|
||||
case OP_GET:
|
||||
fprintf(stdout, "%s: %f\n", curr->device, get_brightness(backlight_file));
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Otherise, apply delta to all backlights
|
||||
}else{
|
||||
for(int i = 0;i < backlight_names.size;i++){
|
||||
if(chdir(backlight_names.list[i])){
|
||||
fprintf(stderr, "Unable to open backlight directory \"%s%s\"!\n", backlight_dir, backlight_names.list[i]);
|
||||
continue;
|
||||
}
|
||||
write_delta(&args);
|
||||
switch(args.operation){
|
||||
case OP_SET:
|
||||
case OP_INC:
|
||||
case OP_DEC:
|
||||
for(int i = 0;i < backlight_names.size;i++){
|
||||
if(chdir(backlight_names.list[i])){
|
||||
fprintf(stderr, "Unable to open backlight directory \"%s%s\"!\n", backlight_dir, backlight_names.list[i]);
|
||||
continue;
|
||||
}
|
||||
write_delta(&args);
|
||||
}
|
||||
break;
|
||||
case OP_LIST:
|
||||
for(int i = 0;i < backlight_names.size;i++){
|
||||
fprintf(stdout, "%s\n", backlight_names.list[i]);
|
||||
}
|
||||
break;
|
||||
case OP_GET:
|
||||
for(int i = 0;i < backlight_names.size;i++){
|
||||
if(chdir(backlight_names.list[i])){
|
||||
fprintf(stderr, "Unable to open backlight directory \"%s%s\"!\n", backlight_dir, backlight_names.list[i]);
|
||||
continue;
|
||||
}
|
||||
fprintf(stdout, "%s: %f\n", backlight_names.list[i], get_brightness(backlight_file));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Return to start directory
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user