examples: allow to select multiple devices

Since there might be external USB readers and embedded ones, better to allow
easily to select them all in examples.
This commit is contained in:
Marco Trevisan (Treviño) 2019-11-20 14:53:36 +01:00 committed by Benjamin Berg
parent 39e3e2b794
commit 1319daba54

View file

@ -27,14 +27,40 @@ FpDevice *
discover_device (GPtrArray * devices) discover_device (GPtrArray * devices)
{ {
FpDevice *dev; FpDevice *dev;
int i;
if (!devices->len) if (!devices->len)
return NULL; return NULL;
dev = g_ptr_array_index (devices, 0); if (devices->len == 1)
g_print ("Found device %s (%s) claimed by %s driver\n", {
i = 0;
}
else
{
g_print ("Multiple devices found, choose one\n");
for (i = 0; i < devices->len; ++i)
{
dev = g_ptr_array_index (devices, i);
g_print ("[%d] %s (%s) - driver %s\n", i,
fp_device_get_device_id (dev), fp_device_get_name (dev),
fp_device_get_driver (dev));
}
g_print ("> ");
if (!scanf ("%d%*c", &i))
return NULL;
if (i < 0 || i >= devices->len)
return NULL;
}
dev = g_ptr_array_index (devices, i);
g_print ("Selected device %s (%s) claimed by %s driver\n",
fp_device_get_device_id (dev), fp_device_get_name (dev), fp_device_get_device_id (dev), fp_device_get_name (dev),
fp_device_get_driver (dev)); fp_device_get_driver (dev));
return dev; return dev;
} }