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