napperley
08/26/2019, 2:54 AMudev_list_entry_foreach
which is used to access each entry in the list. Would manually iterating over the list (via udev_list_entry_get_next
) be the way to workaround the macro? I am using this C example as a reference: https://github.com/gavv/snippets/blob/master/udev/udev_monitor_usb.cnapperley
08/26/2019, 2:59 AMnapperley
08/26/2019, 3:01 AMnapperley
08/26/2019, 3:03 AM> Task :runSerial_reading_demoReleaseExecutableLinux
Starting USB monitor example...
Device Path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-0:1.0
* Device: Action - exists, Vendor - 0000, Product - 0000
Device Path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-0:1.0
* Device: Action - exists, Vendor - 0000, Product - 0000
napperley
08/26/2019, 3:04 AMlsusb
command:
Bus 002 Device 002: ID 0bda:0316 Realtek Semiconductor Corp.
Bus 002 Device 008: ID 2109:0813 VIA Labs, Inc.
Bus 002 Device 007: ID 2109:0813 VIA Labs, Inc.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 04f2:b604 Chicony Electronics Co., Ltd
Bus 001 Device 013: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 001 Device 012: ID 2109:2813 VIA Labs, Inc.
Bus 001 Device 011: ID 2109:2813 VIA Labs, Inc.
Bus 001 Device 002: ID 046d:c52f Logitech, Inc. Unifying Receiver
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
msink
08/26/2019, 6:02 AMstruct udev_list_entry {
struct udev_list *list;
char *name;
char *value;
LIST_FIELDS(struct udev_list_entry, entries);
};
napperley
08/26/2019, 6:44 AMudev_enumerate_get_list_entry
to a property 🤦♂️. Iterating through the registered devices now looks like this:
val devices = udev_enumerate_get_list_entry(enumerate)
val usbDevices = mutableListOf<UsbDevice>()
if (devices != null) {
val tmp = processListEntry(udev, devices)
if (tmp.vendor.isNotEmpty()) usbDevices += tmp
}
var entry = udev_list_entry_get_next(devices)
while (entry != null) {
val tmp = processListEntry(udev, entry)
if (tmp.vendor.isNotEmpty()) usbDevices += tmp
entry = udev_list_entry_get_next(entry)
}
usbDevices.forEach { println("* $it") }
println("Total USB Devices: ${usbDevices.size}")
Dominaezzz
08/26/2019, 10:43 AMgenerateSequence
, you might find it useful here.