Add separate options support
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Dmitry Isaenko 2025-02-02 01:16:14 +03:00
parent 5d8c9c94c3
commit 4a63e76551
3 changed files with 201 additions and 76 deletions

View file

@ -13,6 +13,7 @@
#include "libusb-1.0/libusb.h" #include "libusb-1.0/libusb.h"
#include "argbColors.h"
#include "configuration.h" #include "configuration.h"
#include "device_setup.c" #include "device_setup.c"
#include "init_terminate.c" #include "init_terminate.c"
@ -21,72 +22,6 @@
unsigned int red, green, blue; unsigned int red, green, blue;
const char *argp_program_version = "argbColor 0.1";
const char *argp_program_bug_address = "https://github.com/developersu/argbColors/issues/";
static char doc[] = "-s COMMAND\n-e SOMETHING-SOMETHING";
static char doc1[] = "apply sync or separate command\vFIXME LATER ON PLEASE";
static struct argp_option options[] = {
{"sync", 's', 0, 0, "Synchronized command" },
{"separate", 'e', 0, 0, "Separate command(s)" },
{"color", 'c', "RGB_COLOR", 0, "Define color (000000..ffffff)" },
{"brightness", 'b', "VALUE", 0, "Define brightness (0..5)" },
{"quiet", 'q', 0, 0, "Mute output" },
{"verbose", 'v', 0, 0, "Verbose output" },
{ 0 }
};
struct arguments{
char *args[1];
int quiet;
int sync;
int separate;
char *color;
char *brightness;
};
static error_t parse_opt(int key, char *arg, struct argp_state *state){
/* Get the input argument from argp_parse, which we
know is a pointer to our arguments structure. */
struct arguments *arguments = state->input;
switch (key) {
case 'q':
arguments->quiet = 1;
break;
case 's':
arguments->sync = 1;
break;
case 'e':
arguments->separate = 1;
break;
case 'c':
arguments->color = arg;
break;
case 'b':
arguments->brightness = arg;
break;
case 'v':
verbose_output = 1;
case ARGP_KEY_ARG:
if (state->arg_num >= 1) // Too many arguments
argp_usage (state);
arguments->args[state->arg_num] = arg;
break;
/*
case ARGP_KEY_END:
if (state->arg_num < 1) // Not enough arguments
argp_usage (state);
break;
*/
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = { options, parse_opt, doc, doc1 };
int parse_color(char *color, unsigned int *red, unsigned int *green, unsigned int *blue ){ int parse_color(char *color, unsigned int *red, unsigned int *green, unsigned int *blue ){
if (strlen(color) != 6) if (strlen(color) != 6)
return -1; return -1;
@ -114,12 +49,15 @@ int sync_flow(char* directive){
return turnOffBacklightSync(); return turnOffBacklightSync();
else{ else{
printf("Command not recognized\n" printf("Command not recognized\n"
"Possible values are: wave wave2 color off\n"); "Possible values are: color wave wave2 off\n");
return staticColorSync(red, green, blue); // TODO: refactor; leave information block and nothing instead return staticColorSync(red, green, blue); // TODO: refactor; leave information block and nothing instead
} }
} }
int separate_flow(){
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -139,19 +77,24 @@ int main(int argc, char *argv[]) {
if (arguments.quiet) if (arguments.quiet)
freopen("/dev/null", "a", stdout); freopen("/dev/null", "a", stdout);
if (arguments.sync == arguments.separate == 1){ if (arguments.sync && arguments.separate){
printf("Only one option must be defined: '-s' or '-e'\n"); printf("Only one option must be defined: '-s' or '-e'\n");
return -1; return -1;
} }
/*
if (arguments.separate && ){
printf("In separate flow each zone has to be defined: '-z1=color -z2=impulse ... -z6=color'\n");
return -1;
}
*/
if (parse_color(arguments.color, &red, &green, &blue) != 0){ if (parse_color(arguments.color, &red, &green, &blue) != 0){
printf("Color parse failure\n"); printf("Color parse failure\n");
return -1; return -1;
} }
int brightness = atoi(arguments.brightness); int brightness = atoi(arguments.brightness);
if (brightness > 5) if (brightness > 5)
brightness = 0; brightness = 0;
// - - - // - - -
int ret = configure_device(); int ret = configure_device();

183
src/argbColors.h Normal file
View file

@ -0,0 +1,183 @@
int verbose_output = 0;
enum separate_options {
Z1 = 0x100,
Z2, Z3, Z4, Z5, Z6,
C1, C2, C3, C4, C5, C6,
I1, I2, I3, I4, I5, I6,
B1, B2, B3, B4, B5, B6
};
const char *argp_program_version = "argbColor 0.1";
const char *argp_program_bug_address = "https://github.com/developersu/argbColors/issues/";
static char doc[] = "-s [color|wave|wave2|off]\n-e -z1=[color|off|impulse|flash|flash2|cycle] ... -z6=[...]";
static char doc1[] = "Apply same effect to every connected device or configure each device separately\v\
Command's related options:\n\
Synchronized\n\
* color: color (-c ...)\n\
Separate\n\
* color: color (-cN ...), brightness (-bN ...)\n\
* impulse: color (-cN ...), intensity (-iN ...)\n\
* flash: color (-cN ...), brightness (-bN ...), frequency (-iN ...)\n\
* flash2: color (-cN ...), brightness (-bN ...), frequency (-iN ...)\n\
* cycle: intensity (-iN ...), brightness (-bN ...)\n\n\
Zones description:\n\
||1| \n\
| 6| || |||| | \n\
| | |||| | \n\
|__| || | \n\
| |_4_| | \n\
|___2_3_5_______| \n";
static struct argp_option options[] = {
{"sync", 's', 0, 0, "Synchronized command flow" , 0},
{"separate", 'e', 0, 0, "Separate commands flow" , 1},
{"color", 'c', "RGB_color", 0, "Color (000000..ffffff)" , 2},
{"brightness", 'b', "value", 0, "Brightness (0..5)" , 2},
{"z1", Z1, "command", 0, "Command for zone 1", 3 },
{"z2", Z2, "command", 0, "Command for zone 2", 3 },
{"z3", Z3, "command", 0, "Command for zone 3", 3 },
{"z4", Z4, "command", 0, "Command for zone 4", 3 },
{"z5", Z5, "command", 0, "Command for zone 5", 3 },
{"z6", Z6, "command", 0, "Command for zone 6", 3 },
{"c1", C1, "RGB_color", 0, "Color for zone 1", 4 },
{"c2", C2, "RGB_color", 0, "Color for zone 2", 4 },
{"c3", C3, "RGB_color", 0, "Color for zone 3", 4 },
{"c4", C4, "RGB_color", 0, "Color for zone 4", 4 },
{"c5", C5, "RGB_color", 0, "Color for zone 5", 4 },
{"c6", C6, "RGB_color", 0, "Color for zone 6", 4 },
{"i1", I1, "value", 0, "Intensity/frequency for zone 1", 4 },
{"i2", I2, "value", 0, "Intensity/frequency for zone 2", 4 },
{"i3", I3, "value", 0, "Intensity/frequency for zone 3", 4 },
{"i4", I4, "value", 0, "Intensity/frequency for zone 4", 4 },
{"i5", I5, "value", 0, "Intensity/frequency for zone 5", 4 },
{"i6", I6, "value", 0, "Intensity/frequency for zone 6", 4 },
{"b1", B1, "value", 0, "Brightness for zone 1", 4 },
{"b2", B2, "value", 0, "Brightness for zone 2", 4 },
{"b3", B3, "value", 0, "Brightness for zone 3", 4 },
{"b4", B4, "value", 0, "Brightness for zone 4", 4 },
{"b5", B5, "value", 0, "Brightness for zone 5", 4 },
{"b6", B6, "value", 0, "Brightness for zone 6", 4 },
{"quiet", 'q', 0, 0, "Mute output" , 7},
{"verbose", 'v', 0, 0, "Verbose output" , 7},
{ 0 }
};
struct arguments{
char *args[1];
int quiet;
int sync;
int separate;
char *color,
*brightness,
*z1, *z2, *z3, *z4, *z5, *z6,
*c1, *c2, *c3, *c4, *c5, *c6,
*i1, *i2, *i3, *i4, *i5, *i6,
*b1, *b2, *b3, *b4, *b5, *b6;
};
static error_t parse_opt(int key, char *arg, struct argp_state *state){
/* Get the input argument from argp_parse, which we
know is a pointer to our arguments structure. */
struct arguments *arguments = state->input;
switch (key) {
case 'q':
arguments->quiet = 1;
break;
case 's':
arguments->sync = 1;
break;
case 'e':
arguments->separate = 1;
break;
case 'c':
arguments->color = arg;
break;
case 'b':
arguments->brightness = arg;
break;
case 'v':
verbose_output = 1;
case Z1:
arguments->z1 = arg;
break;
case Z2:
arguments->z2 = arg;
break;
case Z3:
arguments->z3 = arg;
break;
case Z4:
arguments->z4 = arg;
break;
case Z5:
arguments->z5 = arg;
break;
case Z6:
arguments->z6 = arg;
break;
case C1:
arguments->z1 = arg;
break;
case C2:
arguments->z2 = arg;
break;
case C3:
arguments->z3 = arg;
break;
case C4:
arguments->z4 = arg;
break;
case C5:
arguments->z5 = arg;
break;
case C6:
arguments->z6 = arg;
break;
case I1:
arguments->z1 = arg;
break;
case I2:
arguments->z2 = arg;
break;
case I3:
arguments->z3 = arg;
break;
case I4:
arguments->z4 = arg;
break;
case I5:
arguments->z5 = arg;
break;
case I6:
arguments->z6 = arg;
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 1) // Too many arguments
argp_usage (state);
arguments->args[state->arg_num] = arg;
break;
/*
case ARGP_KEY_END:
if (state->arg_num < 1) // Not enough arguments
argp_usage (state);
break;
*/
default:
return ARGP_ERR_UNKNOWN;
}
printf("%03x = %s\n", key, arg);
return 0;
}
static struct argp argp = { options, parse_opt, doc, doc1 };

View file

@ -13,4 +13,3 @@ const uint16_t PID = 0x5711; // REAL
unsigned int TIMEOUT = 2000; unsigned int TIMEOUT = 2000;
int counter; int counter;
int limit; int limit;
int verbose_output = 0;