-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support HID++ error data and non-long errors #24
Conversation
Some HID++ 2.0 features return error data as part of an error report. Make this available to applications.
--offset; | ||
*error_data = { _data.data() + 6, _data.data() + offset + 1 }; // Copy the error data | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like this should be a standard algorithm. But I don't know which one. The best I can come up with is:
auto begin = _data.begin() + 6;
auto end = std::find_if(std::make_reverse_iterator(_data.end()), std::make_reverse_iterator(begin), [](int v){return v != 0;}).base(); // Look for the last non-zero byte
error_data->assign(begin, end);
But it is not really readable. I guess your version is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember starting off searching for a standard algorithm solution and ended up deciding that the loop was a lot more readable. 😄
OK, this looks good but I have one question. On what does the presence and the format of the extra data depends? Is it the protocol version? Or the function being called? (the underlying question being: who should be responsible for parsing the data?) |
Sorry for the delay! The extra data depends purely on the function. Most functions don't give any extra data but some might, in which case the feature code needs to decode it. I can't share the full spec for that feature just yet but here's an excerpt from an upcoming feature that should help illustrate how functions might specify the error behavior:
In this case the extra error data not only shows up nicely in the USB analyzer but the client code can turn it into a more meaningful message. |
This fixes a bug that we previously talked about in #12 (comment) and adds a small feature to allow client applications to read the error bytes that HID++ errors can contain (quite helpful to retrieve details about the errors for certain HID++ functions).
The two commits are unrelated, so they could be separated if desired.