Add --pin argument for easier pairing using frontends (#853)

* Add --pin flag to make pair easier for frontends

* Fix lint errors
This commit is contained in:
kkoshelev 2022-06-28 18:22:07 -07:00 committed by GitHub
parent 543dc087fc
commit b9703e7a1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -72,6 +72,7 @@ static struct option long_options[] = {
{"verbose", no_argument, NULL, 'z'}, {"verbose", no_argument, NULL, 'z'},
{"debug", no_argument, NULL, 'Z'}, {"debug", no_argument, NULL, 'Z'},
{"nomouseemulation", no_argument, NULL, '4'}, {"nomouseemulation", no_argument, NULL, '4'},
{"pin", required_argument, NULL, '5'},
{0, 0, 0, 0}, {0, 0, 0, 0},
}; };
@ -244,6 +245,9 @@ static void parse_argument(int c, char* value, PCONFIGURATION config) {
case '4': case '4':
config->mouse_emulation = false; config->mouse_emulation = false;
break; break;
case '5':
config->pin = atoi(value);
break;
case 1: case 1:
if (config->action == NULL) if (config->action == NULL)
config->action = value; config->action = value;
@ -364,6 +368,7 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
config->mouse_emulation = true; config->mouse_emulation = true;
config->rotate = 0; config->rotate = 0;
config->codec = CODEC_UNSPECIFIED; config->codec = CODEC_UNSPECIFIED;
config->pin = 0;
config->inputsCount = 0; config->inputsCount = 0;
config->mapping = get_path("gamecontrollerdb.txt", getenv("XDG_DATA_DIRS")); config->mapping = get_path("gamecontrollerdb.txt", getenv("XDG_DATA_DIRS"));
@ -381,7 +386,7 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
} else { } else {
int option_index = 0; int option_index = 0;
int c; int c;
while ((c = getopt_long_only(argc, argv, "-abc:d:efg:h:i:j:k:lm:no:p:q:r:s:tu:v:w:xy4", long_options, &option_index)) != -1) { while ((c = getopt_long_only(argc, argv, "-abc:d:efg:h:i:j:k:lm:no:p:q:r:s:tu:v:w:xy45:", long_options, &option_index)) != -1) {
parse_argument(c, optarg, config); parse_argument(c, optarg, config);
} }
} }

View File

@ -47,6 +47,7 @@ typedef struct _CONFIGURATION {
char* inputs[MAX_INPUTS]; char* inputs[MAX_INPUTS];
int inputsCount; int inputsCount;
enum codecs codec; enum codecs codec;
int pin;
} CONFIGURATION, *PCONFIGURATION; } CONFIGURATION, *PCONFIGURATION;
extern bool inputAdded; extern bool inputAdded;

View File

@ -373,7 +373,11 @@ int main(int argc, char* argv[]) {
stream(&server, &config, system); stream(&server, &config, system);
} else if (strcmp("pair", config.action) == 0) { } else if (strcmp("pair", config.action) == 0) {
char pin[5]; char pin[5];
if (config.pin > 0 && config.pin <= 9999) {
sprintf(pin, "%04d", config.pin);
} else {
sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10); sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10);
}
printf("Please enter the following PIN on the target PC: %s\n", pin); printf("Please enter the following PIN on the target PC: %s\n", pin);
fflush(stdout); fflush(stdout);
if (gs_pair(&server, &pin[0]) != GS_OK) { if (gs_pair(&server, &pin[0]) != GS_OK) {