28 #pragma warning(disable:4996) 79 long onConnect(FXObject *sender, FXSelector sel,
void *ptr);
80 long onDisconnect(FXObject *sender, FXSelector sel,
void *ptr);
81 long onRescan(FXObject *sender, FXSelector sel,
void *ptr);
85 long onClear(FXObject *sender, FXSelector sel,
void *ptr);
86 long onTimeout(FXObject *sender, FXSelector sel,
void *ptr);
87 long onMacTimeout(FXObject *sender, FXSelector sel,
void *ptr);
116 : FXMainWindow(app,
"HIDAPI Test Application",
NULL,
NULL, DECOR_ALL, 200,100, 425,700)
121 FXVerticalFrame *vf =
new FXVerticalFrame(
this, LAYOUT_FILL_Y|LAYOUT_FILL_X);
123 FXLabel *
label =
new FXLabel(vf,
"HIDAPI Test Tool");
124 title_font =
new FXFont(getApp(),
"Arial", 14, FXFont::Bold);
128 "Select a device and press Connect.",
NULL, JUSTIFY_LEFT);
130 "Output data bytes can be entered in the Output section, \n" 131 "separated by space, comma or brackets. Data starting with 0x\n" 132 "is treated as hex. Data beginning with a 0 is treated as \n" 133 "octal. All other data is treated as decimal.",
NULL, JUSTIFY_LEFT);
135 "Data received from the device appears in the Input section.",
138 "Optionally, a report length may be specified. Extra bytes are\n" 139 "padded with zeros. If no length is specified, the length is \n" 140 "inferred from the data.",
145 FXHorizontalFrame *hf =
new FXHorizontalFrame(vf, LAYOUT_FILL_X);
147 device_list =
new FXList(
new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0),
NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,300,200);
148 FXVerticalFrame *buttonVF =
new FXVerticalFrame(hf);
153 new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0);
157 new FXHorizontalFrame(vf);
160 FXGroupBox *gb =
new FXGroupBox(vf,
"Output", FRAME_GROOVE|LAYOUT_FILL_X);
161 FXMatrix *
matrix =
new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
162 new FXLabel(matrix,
"Data");
163 new FXLabel(matrix,
"Length");
164 new FXLabel(matrix,
"");
167 output_text =
new FXTextField(matrix, 30,
NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
169 output_len =
new FXTextField(matrix, 5,
NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
175 feature_text =
new FXTextField(matrix, 30,
NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
176 feature_len =
new FXTextField(matrix, 5,
NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
180 get_feature_text =
new FXTextField(matrix, 30,
NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
181 new FXWindow(matrix);
187 gb =
new FXGroupBox(vf,
"Input", FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y);
188 FXVerticalFrame *innerVF =
new FXVerticalFrame(gb, LAYOUT_FILL_X|LAYOUT_FILL_Y);
189 input_text =
new FXText(
new FXHorizontalFrame(innerVF,LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, 0,0,0,0, 0,0,0,0),
NULL, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y);
191 new FXButton(innerVF,
"Clear",
NULL,
this,
ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT);
207 FXMainWindow::create();
240 FXMessageBox::error(
this, MBOX_OK,
"Device Error",
"Unable To Connect to Device");
246 getApp()->addTimeout(
this,
ID_TIMER,
277 getApp()->removeTimeout(
this,
ID_TIMER);
300 usage_str.format(
" (usage: %04hx:%04hx) ", cur_dev->
usage_page, cur_dev->
usage);
302 FXListItem *li =
new FXListItem(s,
NULL, cur_dev);
305 cur_dev = cur_dev->
next;
309 device_list->appendItem(
"*** No Devices Connected ***");
320 const char *delim =
" ,{}\t\r\n";
321 FXString
data = tf->getText();
322 const FXchar *
d = data.text();
326 size_t sz = strlen(d);
327 char *str = (
char*)
malloc(sz+1);
331 char *token = strtok(str, delim);
334 long int val = strtol(token, &endptr, 0);
336 token = strtok(
NULL, delim);
352 FXString str = tf->getText();
353 size_t sz = str.length();
357 len = strtol(str.text(), &endptr, 0);
358 if (endptr != str.text() && *endptr ==
'\0') {
360 FXMessageBox::error(
this, MBOX_OK,
"Invalid length",
"Enter a length greater than zero.");
376 size_t data_len,
len;
383 if (textfield_len < 0) {
384 FXMessageBox::error(
this, MBOX_OK,
"Invalid length",
"Length field is invalid. Please enter a number in hex, octal, or decimal.");
388 if (textfield_len >
sizeof(buf)) {
389 FXMessageBox::error(
this, MBOX_OK,
"Invalid length",
"Length field is too long.");
393 len = (textfield_len)? textfield_len: data_len;
397 FXMessageBox::error(
this, MBOX_OK,
"Error Writing",
"Could not write to device. Error reported was: %ls",
hid_error(
connected_device));
407 size_t data_len,
len;
414 if (textfield_len < 0) {
415 FXMessageBox::error(
this, MBOX_OK,
"Invalid length",
"Length field is invalid. Please enter a number in hex, octal, or decimal.");
419 if (textfield_len >
sizeof(buf)) {
420 FXMessageBox::error(
this, MBOX_OK,
"Invalid length",
"Length field is too long.");
424 len = (textfield_len)? textfield_len: data_len;
428 FXMessageBox::error(
this, MBOX_OK,
"Error Writing",
"Could not send feature report to device. Error reported was: %ls",
hid_error(
connected_device));
444 FXMessageBox::error(
this, MBOX_OK,
"Too many numbers",
"Enter only a single report number in the text field");
449 FXMessageBox::error(
this, MBOX_OK,
"Error Getting Report",
"Could not get feature report from device. Error reported was: %ls",
hid_error(
connected_device));
454 s.format(
"Returned Feature Report. %d bytes:\n", res);
455 for (
int i = 0;
i <
res;
i++) {
457 t.format(
"%02hhx ", buf[
i]);
482 unsigned char buf[256];
487 s.format(
"Received %d bytes:\n", res);
488 for (
int i = 0;
i <
res;
i++) {
490 t.format(
"%02hhx ", buf[
i]);
502 input_text->appendText(
"hid_read() returned error\n");
506 getApp()->addTimeout(
this,
ID_TIMER,
524 int main(
int argc,
char **argv)
526 FXApp app(
"HIDAPI Test Application",
"Signal 11 Software");
527 app.init(argc, argv);
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error(hid_device *device)
Get a string describing the last error which occurred.
int getLengthFromTextField(FXTextField *tf)
FXTextField * feature_len
FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap))
long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr)
long onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr)
long onConnect(FXObject *sender, FXSelector sel, void *ptr)
FXDEFMAP(MainWindow) MainWindowMap []
FXTextField * output_text
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs)
Free an enumeration Linked List.
long onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
struct hid_device_info * devices
FXMainWindow * g_main_window
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
static char * tf(SDL_bool tf)
long onTimeout(FXObject *sender, FXSelector sel, void *ptr)
long onRescan(FXObject *sender, FXSelector sel, void *ptr)
wchar_t * manufacturer_string
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length)
Write an Output report to a HID device.
FXButton * connect_button
struct hid_device_info * next
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock)
Set the device handle to be non-blocking.
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device)
Close a HID device.
FXTextField * feature_text
unsigned short product_id
hid_device * connected_device
GLuint GLsizei const GLchar * label
void init_apple_message_system()
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
FXButton * get_feature_button
int hid_exit(void)
Finalize the HIDAPI library.
long onDisconnect(FXObject *sender, FXSelector sel, void *ptr)
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length)
Get a feature report from a HID device.
GLenum GLuint GLenum GLsizei const GLchar * buf
int main(int argc, char **argv)
FXLabel * connected_label
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
unsigned short usage_page
FXButton * feature_button
long onClear(FXObject *sender, FXSelector sel, void *ptr)
FXTextField * get_feature_text
HID_API_EXPORT hid_device *HID_API_CALL hid_open_path(const char *path, int bExclusive)
Open a HID device by its path name.
FXButton * disconnect_button
size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len)
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length)
Send a Feature report to the device.
void check_apple_events()
GLboolean GLboolean GLboolean GLboolean a
long onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
struct hid_device_info HID_API_EXPORT *HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length)
Read an Input report from a HID device.