Repository navigation
Conversation
|
I have attached two commits to not crash on Windows as you mentioned (unfortunately I cannot test this) and to update the docs. In the docs of It might be nicer to write and implement this instead: In this case, all What do you think about this?
No problem. |
|
Any update on this? |
|
Hi Alan, would you mind to change the API little bit? So there's some shared context amongst all API functions calls and there's no global variable used (there's currently libusb_context shared). This would make better error handling easier and library thread safe. As nh2 already suggests, there's currently no way of knowing where did for example hid_enumerate() failed as there's no context and so hid_error() couldn't be used properly. I'm working on Lua bindings and I think, that it might be a support nightmare if I don't know where did hid_enumerate() failed and why. The changes would mean something along this lines: struct hid_device dev;
uint16_t vendor = 0x1234;
uint16_t product = 0x5678;
if (hid_enumerate(&dev, vendor, product) == NULL)
wprintf(L"%s() error: %ls\n", hid_error(dev));
...
int hid_init(struct hid_device *dev);
int hid_open(struct hid_device *dev, uint16_t vendor, ...);
...Thanks. |
|
That seems a very awkward design choice, to pass in a device just to use the error string/code. Also, hid_device is opaque (you can use a pointer only), because it's different between platforms. I welcome a solution to the design issue you state, but let's come up with a better way. Alan. |
|
Well, it was just an example :) The context concept is simply needed for other useful stuff like logging for example, here struct hidapi is of course opaque also. typedef void (*hid_log_fn)(struct hid_api *ctx, int priority, const char *file, int line, const char *fn, const char *format, va_list args); struct hidapi {
int last_error;
char *last_error_str;
hid_log_fn log_fn;
int log_priority;
struct libusb_context *usb_ctx;
};
int hid_init(struct hidapi **ctx);
int hid_open(struct hidapi *ctx, struct hid_device *dev, uint16_t vendor, uint16_t product);
const char* hid_strerror(struct hidapi *ctx);
void hid_set_log_priority(struct hidapi *ctx, int priority);
void hid_set_log_fn(struct hidapi *ctx, void (*log_fn)(struct hidapi *ctx, int priority, const char *file, int line, const char *fn, const char *format, va_list args));
int hid_finish(struct hidapi *ctx);
void main()
{
struct hidapi context;
if (hid_init(&context) < 0)
return -1;
...
hid_finish(context);
} |
|
The patch attached to this pull request makes some assertions in the documentation but doesn't actually implement any functionality. To answer your last post, I'd like users to not have to deal with contexts if they don't need to. What you propose addresses a few different issues at once. Maybe if we take one at a time. API changes are tricky and you want to get them right the first time. Also, I'd like it if we could just add to the API rather than change. What about the possibility of adding an error parameter to hid_open() and hid_enumerate() the way winpcap does (pcap_open_live())? Maybe we could have a struct that has an error code and a string in it? |
Not sure what you meant - it does implement |
|
ok, there are three patches and I only saw the one. Nevermind. I'll look closer. |
|
Has this been abandoned? |
* macOS support for multiple usage/usage-pages Update of @fengji2006 PR#65, second try * apply requested changes and test * handle possible nullptr
NOTE: This commit does not handle composite HID descriptors I am interested in adding support for composite descriptors though I still need to find a device with a composite descriptor to test it correctly. The implementation idea is similar, as in signal11#125 for macOS.
Here is my first try at implementing error messages for the Linux/hidraw implementation.
NULLintohid_erroras I suggested in What is hid_error good for? #123.A few extra questions:
utf8_to_wchar_tthe input is calledutf8. As far as I know, the encoding used inmbstowcsdepends on the current locale, if if I haven't set my locale to use UTF8, then the input is not UTF8.register_errorequivalent inwindows/hid.cdoesn't use its argumentconst char *op. Is that intended?HidD_GetPreparsedDataactually set the error code forGetLastError()?