WootingKb / wooting-analog-sdk

Native support for Analog Keyboards #WootDev
Mozilla Public License 2.0
153 stars 20 forks source link

Device Enumerating is Done Odd #69

Open Karutoh opened 1 year ago

Karutoh commented 1 year ago

So this is an odd way to enumerate devices at runtime as shown below.

WootingAnalog_DeviceInfo_FFI* buffer = nullptr;

int len = wooting_analog_get_connected_devices_info(nullptr, 0xFFFFFFFF);

buffer = new WootingAnalog_DeviceInfo_FFI[len];

wooting_analog_get_connected_devices_info(&buffer, len);

It should be done this way so there's no mistake on how it's done. As this method is typically common.

WootingAnalog_DeviceInfo_FFI* buffer = nullptr;
unsigned int size = 0;

wooting_analog_get_connected_devices_info(nullptr, &size); // Given buffer is a "nullptr" which will set the "size" variable.

buffer = new WootingAnalog_DeviceInfo_FFI[size];

wooting_analog_get_connected_devices_info(&buffer, &size); // Here the array is actually set.
Sainan commented 1 year ago

This would be a breaking change. Instead, maybe something like wooting_analog_get_num_connected_devices so you can do your dynamic allocation.

Karutoh commented 1 year ago

This would be a breaking change. Instead, maybe something like wooting_analog_get_num_connected_devices so you can do your dynamic allocation.

I think that would be a good compromise.

Sainan commented 2 months ago

One thing to note is that wooting_analog_initialise actually already returns the number of devices (at init time), which may be useful for whatever your use-case is/was.