eizoctl: add an option to filter by serial number
Some checks failed
Alpine 3.21 Scripts failed

It turns out that this is actually critical when switching inputs
in certain wild setups.
This commit is contained in:
Přemysl Eric Janouch 2025-07-31 21:11:45 +02:00
parent 135f336a7c
commit d8b01cdaee
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -1039,6 +1039,8 @@ eizo_watch(struct eizo_monitor *m, print_fn output, print_fn error)
static const char *usage = "Usage: %s OPTION...\n\n" static const char *usage = "Usage: %s OPTION...\n\n"
" -l, --list\n" " -l, --list\n"
" List all connected EIZO monitors, with their serial number.\n" " List all connected EIZO monitors, with their serial number.\n"
" -s, --serial SERIAL\n"
" Only act on the monitor matching the specified serial number.\n"
" -b, --brightness [+-]BRIGHTNESS\n" " -b, --brightness [+-]BRIGHTNESS\n"
" Change monitor brightness; values go from 0 to 1 and may be relative.\n" " Change monitor brightness; values go from 0 to 1 and may be relative.\n"
" -i, --input NAME\n" " -i, --input NAME\n"
@ -1060,6 +1062,7 @@ run(int argc, char *argv[], print_fn output, print_fn error)
const char *name = argv[0]; const char *name = argv[0];
static struct option opts[] = { static struct option opts[] = {
{"list", no_argument, NULL, 'l'}, {"list", no_argument, NULL, 'l'},
{"serial", required_argument, NULL, 's'},
{"brightness", required_argument, NULL, 'b'}, {"brightness", required_argument, NULL, 'b'},
{"input", required_argument, NULL, 'i'}, {"input", required_argument, NULL, 'i'},
{"restart", no_argument, NULL, 'r'}, {"restart", no_argument, NULL, 'r'},
@ -1073,13 +1076,16 @@ run(int argc, char *argv[], print_fn output, print_fn error)
int quiet = 0; int quiet = 0;
double brightness = NAN; double brightness = NAN;
bool list = false, relative = false, restart = false, events = false; bool list = false, relative = false, restart = false, events = false;
const char *port = NULL; const char *serial = NULL, *port = NULL;
int c = 0; int c = 0;
while ((c = getopt_long(argc, argv, "lb:i:reqhV", opts, NULL)) != -1) while ((c = getopt_long(argc, argv, "ls:b:i:reqhV", opts, NULL)) != -1)
switch (c) { switch (c) {
case 'l': case 'l':
list = true; list = true;
break; break;
case 's':
serial = optarg;
break;
case 'b': case 'b':
relative = *optarg == '+' || *optarg == '-'; relative = *optarg == '+' || *optarg == '-';
if (sscanf(optarg, "%lf", &brightness) && isfinite(brightness)) if (sscanf(optarg, "%lf", &brightness) && isfinite(brightness))
@ -1129,8 +1135,6 @@ run(int argc, char *argv[], print_fn output, print_fn error)
if (quiet > 1) if (quiet > 1)
error = print_dummy; error = print_dummy;
// It should be possible to choose a particular monitor,
// but it is generally more useful to operate on all of them.
struct hid_device_info *devs = hid_enumerate(USB_VID_EIZO, 0), *p = devs; struct hid_device_info *devs = hid_enumerate(USB_VID_EIZO, 0), *p = devs;
for (; p; p = p->next) { for (; p; p = p->next) {
struct eizo_monitor m = {}; struct eizo_monitor m = {};
@ -1142,6 +1146,12 @@ run(int argc, char *argv[], print_fn output, print_fn error)
if (list) if (list)
output("%s %s\n", m.product, m.serial); output("%s %s\n", m.product, m.serial);
// Generously assuming that different products/models
// don't share serial numbers,
// which would otherwise deserve another filtering option.
if (serial && strcmp(serial, m.serial))
goto next;
if (isfinite(brightness)) { if (isfinite(brightness)) {
double prev = 0.; double prev = 0.;
if (!eizo_get_brightness(&m, &prev)) { if (!eizo_get_brightness(&m, &prev)) {
@ -1186,6 +1196,7 @@ run(int argc, char *argv[], print_fn output, print_fn error)
error("%s\n", m.error); error("%s\n", m.error);
} }
next:
eizo_monitor_close(&m); eizo_monitor_close(&m);
} }
hid_free_enumeration(devs); hid_free_enumeration(devs);