2025-01-24 01:25:30 +03:00
|
|
|
/**********************
|
|
|
|
Dmitry Isaenko
|
|
|
|
License: GNU GPL v.3
|
|
|
|
redrise.ru, github.com/developersu
|
|
|
|
2025, Russia
|
|
|
|
***********************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2025-01-28 23:24:25 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <argp.h>
|
|
|
|
#include <regex.h>
|
|
|
|
|
2025-01-24 01:25:30 +03:00
|
|
|
#include "libusb-1.0/libusb.h"
|
|
|
|
|
2025-01-28 23:24:25 +03:00
|
|
|
|
2025-01-27 01:55:17 +03:00
|
|
|
#include "configuration.h"
|
|
|
|
#include "device_setup.c"
|
2025-01-24 01:25:30 +03:00
|
|
|
#include "init_terminate.c"
|
|
|
|
#include "commands.c"
|
2025-01-28 23:24:25 +03:00
|
|
|
#include "iousb.c"
|
|
|
|
const char *argp_program_version = "argbColor 0.1";
|
|
|
|
const char *argp_program_bug_address = "https://github.com/developersu/argbColors/issues/";
|
|
|
|
static char doc[] = "TODO \
|
|
|
|
TODO \
|
|
|
|
there should be a well structed description one day";
|
2025-01-24 01:25:30 +03:00
|
|
|
|
2025-01-28 23:24:25 +03:00
|
|
|
static char args_doc[] = "ARG1";
|
|
|
|
static struct argp_option options[] = {
|
|
|
|
{"sync", 's', "COMMAND", 0, "Bypass synchronized command" },
|
|
|
|
{"separate", 'e', "COMMAND", 0, "Bypass separate command(s)" },
|
|
|
|
{"color", 'c', "RGB_COLOR", 0, "Define color" },
|
|
|
|
{"brightness", 'b', "VALUE", 0, "Define brightness" },
|
|
|
|
{"quiet", 'q', 0, 0, "Don't produce any output" },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct arguments{
|
|
|
|
char *args[1];
|
|
|
|
int quiet;
|
|
|
|
char *sync;
|
|
|
|
char *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 = arg;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
arguments->separate = arg;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
arguments->color = arg;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
arguments->brightness = 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;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct argp argp = { options, parse_opt, args_doc, doc };
|
|
|
|
|
|
|
|
int parse_color(char *color, unsigned int *red, unsigned int *green, unsigned int *blue ){
|
|
|
|
printf("%s\n", color);
|
|
|
|
if (strlen(color) != 6)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
regex_t reg;
|
|
|
|
regcomp(®, "^[0-9a-fA-F]{6}$", REG_EXTENDED);
|
|
|
|
if (regexec(®, color, 0, NULL, 0) != 0)
|
|
|
|
return -1;
|
|
|
|
regfree(®);
|
2025-01-26 19:08:12 +03:00
|
|
|
|
2025-01-28 23:24:25 +03:00
|
|
|
if (sscanf(color, "%2x%2x%2x", red, green, blue) == 3)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int parse_brightness(){
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
struct arguments arguments;
|
|
|
|
/* Default values. */
|
|
|
|
arguments.quiet = 0;
|
|
|
|
arguments.sync = "-";
|
|
|
|
arguments.separate = "-";
|
|
|
|
arguments.color = "ff2fff";
|
|
|
|
arguments.brightness = "5";
|
|
|
|
|
|
|
|
/* Parse our arguments; every option seen by parse_opt will
|
|
|
|
be reflected in arguments. */
|
|
|
|
argp_parse(&argp, argc, argv, 0, 0, &arguments);
|
|
|
|
|
|
|
|
printf("ARG1 = %s\nSYNC = %s\nSEPARATE = %s\nCOLOR = %s\n"
|
|
|
|
"QUIET = %s\n",
|
|
|
|
arguments.args[0], arguments.args[1],
|
|
|
|
arguments.sync,
|
|
|
|
arguments.separate,
|
|
|
|
arguments.color,
|
|
|
|
arguments.quiet ? "yes" : "no");
|
|
|
|
|
|
|
|
unsigned int red, green, blue;
|
|
|
|
|
|
|
|
if (parse_color(arguments.color, &red, &green, &blue) != 0){
|
|
|
|
printf("Color parse failure\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
// - - -
|
2025-01-27 01:55:17 +03:00
|
|
|
int ret = configure_device();
|
|
|
|
if (ret != 0){
|
|
|
|
printf("%s - %d\n", libusb_error_name(ret), ret);
|
|
|
|
return -1;
|
2025-01-26 00:54:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (init_sequence()){
|
|
|
|
printf("Initial sequence transfer failure\n");
|
|
|
|
libusb_close(dev_handle);
|
|
|
|
return -1;
|
|
|
|
}
|
2025-01-27 01:55:17 +03:00
|
|
|
/*
|
2025-01-27 00:50:59 +03:00
|
|
|
if (cycle(0, 4)){
|
|
|
|
printf("Command transfer failure\n");
|
|
|
|
libusb_close(dev_handle);
|
|
|
|
return -1;
|
|
|
|
}
|
2025-01-27 01:55:17 +03:00
|
|
|
|
2025-01-26 19:08:12 +03:00
|
|
|
if (impulse(0, 0xff, 0x2f, 0xff)){
|
|
|
|
printf("Command transfer failure\n");
|
|
|
|
libusb_close(dev_handle);
|
|
|
|
return -1;
|
|
|
|
}
|
2025-01-27 01:55:17 +03:00
|
|
|
//*/
|
2025-01-28 23:24:25 +03:00
|
|
|
if(staticColorSync(red, green, blue)){
|
2025-01-26 00:54:18 +03:00
|
|
|
printf("Command transfer failure\n");
|
|
|
|
libusb_close(dev_handle);
|
|
|
|
return -1;
|
|
|
|
}
|
2025-01-27 01:55:17 +03:00
|
|
|
|
2025-01-26 00:54:18 +03:00
|
|
|
if (terminate_sequence()){
|
|
|
|
printf("Termination sequence transfer failure\n");
|
|
|
|
libusb_close(dev_handle);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
libusb_close(dev_handle);
|
|
|
|
|
|
|
|
return 0;
|
2025-01-24 01:25:30 +03:00
|
|
|
}
|