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'},
{"debug", no_argument, NULL, 'Z'},
{"nomouseemulation", no_argument, NULL, '4'},
{"pin", required_argument, NULL, '5'},
{0, 0, 0, 0},
};
@ -244,6 +245,9 @@ static void parse_argument(int c, char* value, PCONFIGURATION config) {
case '4':
config->mouse_emulation = false;
break;
case '5':
config->pin = atoi(value);
break;
case 1:
if (config->action == NULL)
config->action = value;
@ -364,6 +368,7 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
config->mouse_emulation = true;
config->rotate = 0;
config->codec = CODEC_UNSPECIFIED;
config->pin = 0;
config->inputsCount = 0;
config->mapping = get_path("gamecontrollerdb.txt", getenv("XDG_DATA_DIRS"));
@ -381,7 +386,7 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
} else {
int option_index = 0;
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);
}
}

View File

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

View File

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