SDL  2.0
MainWindow Class Reference
+ Inheritance diagram for MainWindow:
+ Collaboration diagram for MainWindow:

Public Types

enum  {
  ID_FIRST = FXMainWindow::ID_LAST,
  ID_CONNECT,
  ID_DISCONNECT,
  ID_RESCAN,
  ID_SEND_OUTPUT_REPORT,
  ID_SEND_FEATURE_REPORT,
  ID_GET_FEATURE_REPORT,
  ID_CLEAR,
  ID_TIMER,
  ID_MAC_TIMER,
  ID_LAST
}
 

Public Member Functions

 MainWindow (FXApp *a)
 
 ~MainWindow ()
 
virtual void create ()
 
long onConnect (FXObject *sender, FXSelector sel, void *ptr)
 
long onDisconnect (FXObject *sender, FXSelector sel, void *ptr)
 
long onRescan (FXObject *sender, FXSelector sel, void *ptr)
 
long onSendOutputReport (FXObject *sender, FXSelector sel, void *ptr)
 
long onSendFeatureReport (FXObject *sender, FXSelector sel, void *ptr)
 
long onGetFeatureReport (FXObject *sender, FXSelector sel, void *ptr)
 
long onClear (FXObject *sender, FXSelector sel, void *ptr)
 
long onTimeout (FXObject *sender, FXSelector sel, void *ptr)
 
long onMacTimeout (FXObject *sender, FXSelector sel, void *ptr)
 

Protected Member Functions

 MainWindow ()
 

Private Member Functions

size_t getDataFromTextField (FXTextField *tf, char *buf, size_t len)
 
int getLengthFromTextField (FXTextField *tf)
 

Private Attributes

FXList * device_list
 
FXButton * connect_button
 
FXButton * disconnect_button
 
FXButton * rescan_button
 
FXButton * output_button
 
FXLabel * connected_label
 
FXTextField * output_text
 
FXTextField * output_len
 
FXButton * feature_button
 
FXButton * get_feature_button
 
FXTextField * feature_text
 
FXTextField * feature_len
 
FXTextField * get_feature_text
 
FXText * input_text
 
FXFont * title_font
 
struct hid_device_infodevices
 
hid_device * connected_device
 

Detailed Description

Definition at line 31 of file test.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
ID_FIRST 
ID_CONNECT 
ID_DISCONNECT 
ID_RESCAN 
ID_SEND_OUTPUT_REPORT 
ID_SEND_FEATURE_REPORT 
ID_GET_FEATURE_REPORT 
ID_CLEAR 
ID_TIMER 
ID_MAC_TIMER 
ID_LAST 

Definition at line 35 of file test.cpp.

Constructor & Destructor Documentation

◆ MainWindow() [1/2]

MainWindow::MainWindow ( )
inlineprotected

◆ MainWindow() [2/2]

MainWindow::MainWindow ( FXApp *  a)

Definition at line 115 of file test.cpp.

References connect_button, connected_device, connected_label, device_list, disconnect_button, feature_button, feature_len, feature_text, get_feature_button, get_feature_text, ID_CLEAR, ID_CONNECT, ID_DISCONNECT, ID_GET_FEATURE_REPORT, ID_RESCAN, ID_SEND_FEATURE_REPORT, ID_SEND_OUTPUT_REPORT, input_text, NULL, output_button, output_len, output_text, rescan_button, and title_font.

116  : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 425,700)
117 {
118  devices = NULL;
120 
121  FXVerticalFrame *vf = new FXVerticalFrame(this, LAYOUT_FILL_Y|LAYOUT_FILL_X);
122 
123  FXLabel *label = new FXLabel(vf, "HIDAPI Test Tool");
124  title_font = new FXFont(getApp(), "Arial", 14, FXFont::Bold);
125  label->setFont(title_font);
126 
127  new FXLabel(vf,
128  "Select a device and press Connect.", NULL, JUSTIFY_LEFT);
129  new FXLabel(vf,
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);
134  new FXLabel(vf,
135  "Data received from the device appears in the Input section.",
136  NULL, JUSTIFY_LEFT);
137  new FXLabel(vf,
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.",
141  NULL, JUSTIFY_LEFT);
142  new FXLabel(vf, "");
143 
144  // Device List and Connect/Disconnect buttons
145  FXHorizontalFrame *hf = new FXHorizontalFrame(vf, LAYOUT_FILL_X);
146  //device_list = new FXList(new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK, 0,0,0,0, 0,0,0,0), NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT, 0,0,300,200);
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);
149  connect_button = new FXButton(buttonVF, "Connect", NULL, this, ID_CONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
150  disconnect_button = new FXButton(buttonVF, "Disconnect", NULL, this, ID_DISCONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
151  disconnect_button->disable();
152  rescan_button = new FXButton(buttonVF, "Re-Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X);
153  new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0);
154 
155  connected_label = new FXLabel(vf, "Disconnected");
156 
157  new FXHorizontalFrame(vf);
158 
159  // Output Group Box
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, "");
165 
166  //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
167  output_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
168  output_text->setText("1 0x81 0");
169  output_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
170  output_button = new FXButton(matrix, "Send Output Report", NULL, this, ID_SEND_OUTPUT_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
171  output_button->disable();
172  //new FXHorizontalFrame(matrix, LAYOUT_FILL_X);
173 
174  //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
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);
177  feature_button = new FXButton(matrix, "Send Feature Report", NULL, this, ID_SEND_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
178  feature_button->disable();
179 
180  get_feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
181  new FXWindow(matrix);
182  get_feature_button = new FXButton(matrix, "Get Feature Report", NULL, this, ID_GET_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
183  get_feature_button->disable();
184 
185 
186  // Input Group Box
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);
190  input_text->setEditable(false);
191  new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT);
192 
193 
194 }
GLuint GLenum matrix
FXTextField * feature_len
Definition: test.cpp:61
FXList * device_list
Definition: test.cpp:50
FXTextField * output_text
Definition: test.cpp:56
FXButton * output_button
Definition: test.cpp:54
FXButton * connect_button
Definition: test.cpp:51
FXTextField * feature_text
Definition: test.cpp:60
hid_device * connected_device
Definition: test.cpp:67
GLuint GLsizei const GLchar * label
FXButton * get_feature_button
Definition: test.cpp:59
FXButton * rescan_button
Definition: test.cpp:53
FXLabel * connected_label
Definition: test.cpp:55
#define NULL
Definition: begin_code.h:164
FXFont * title_font
Definition: test.cpp:64
FXButton * feature_button
Definition: test.cpp:58
FXTextField * get_feature_text
Definition: test.cpp:62
FXButton * disconnect_button
Definition: test.cpp:52
FXText * input_text
Definition: test.cpp:63
FXTextField * output_len
Definition: test.cpp:57
EGLDeviceEXT * devices
Definition: eglext.h:621

◆ ~MainWindow()

MainWindow::~MainWindow ( )

Definition at line 196 of file test.cpp.

References connected_device, hid_close(), hid_exit(), and title_font.

Referenced by MainWindow().

197 {
198  if (connected_device)
200  hid_exit();
201  delete title_font;
202 }
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device)
Close a HID device.
Definition: hid.cpp:1090
hid_device * connected_device
Definition: test.cpp:67
int hid_exit(void)
Finalize the HIDAPI library.
Definition: hid.cpp:1154
FXFont * title_font
Definition: test.cpp:64

Member Function Documentation

◆ create()

void MainWindow::create ( )
virtual

Definition at line 205 of file test.cpp.

References ID_MAC_TIMER, init_apple_message_system(), NULL, onRescan(), and timeout_scalar.

Referenced by MainWindow().

206 {
207  FXMainWindow::create();
208  show();
209 
210  onRescan(NULL, 0, NULL);
211 
212 
213 #ifdef __APPLE__
215 #endif
216 
217  getApp()->addTimeout(this, ID_MAC_TIMER,
218  50 * timeout_scalar /*50ms*/);
219 }
const int timeout_scalar
Definition: test.cpp:95
long onRescan(FXObject *sender, FXSelector sel, void *ptr)
Definition: test.cpp:283
void init_apple_message_system()
Definition: mac_support.cpp:96
#define NULL
Definition: begin_code.h:164

◆ getDataFromTextField()

size_t MainWindow::getDataFromTextField ( FXTextField *  tf,
char *  buf,
size_t  len 
)
private

Definition at line 318 of file test.cpp.

References d, free, i, malloc, and NULL.

Referenced by onGetFeatureReport(), onSendFeatureReport(), and onSendOutputReport().

319 {
320  const char *delim = " ,{}\t\r\n";
321  FXString data = tf->getText();
322  const FXchar *d = data.text();
323  size_t i = 0;
324 
325  // Copy the string from the GUI.
326  size_t sz = strlen(d);
327  char *str = (char*) malloc(sz+1);
328  strcpy(str, d);
329 
330  // For each token in the string, parse and store in buf[].
331  char *token = strtok(str, delim);
332  while (token) {
333  char *endptr;
334  long int val = strtol(token, &endptr, 0);
335  buf[i++] = val;
336  token = strtok(NULL, delim);
337  }
338 
339  free(str);
340  return i;
341 }
SDL_EventEntry * free
Definition: SDL_events.c:84
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
static char * tf(SDL_bool tf)
Definition: testatomic.c:23
GLuint GLfloat * val
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
GLenum GLuint GLenum GLsizei const GLchar * buf
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)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:164
#define malloc
Definition: SDL_qsort.c:47

◆ getLengthFromTextField()

int MainWindow::getLengthFromTextField ( FXTextField *  tf)
private

Definition at line 349 of file test.cpp.

Referenced by onSendFeatureReport(), and onSendOutputReport().

350 {
351  long int len;
352  FXString str = tf->getText();
353  size_t sz = str.length();
354 
355  if (sz > 0) {
356  char *endptr;
357  len = strtol(str.text(), &endptr, 0);
358  if (endptr != str.text() && *endptr == '\0') {
359  if (len <= 0) {
360  FXMessageBox::error(this, MBOX_OK, "Invalid length", "Enter a length greater than zero.");
361  return -1;
362  }
363  return len;
364  }
365  else
366  return -1;
367  }
368 
369  return 0;
370 }
static char * tf(SDL_bool tf)
Definition: testatomic.c:23
GLenum GLsizei len

◆ onClear()

long MainWindow::onClear ( FXObject *  sender,
FXSelector  sel,
void ptr 
)

Definition at line 473 of file test.cpp.

References input_text.

Referenced by MainWindow().

474 {
475  input_text->setText("");
476  return 1;
477 }
FXText * input_text
Definition: test.cpp:63

◆ onConnect()

long MainWindow::onConnect ( FXObject *  sender,
FXSelector  sel,
void ptr 
)

Definition at line 222 of file test.cpp.

References connect_button, connected_device, connected_label, device_list, disconnect_button, feature_button, get_feature_button, hid_open_path(), hid_set_nonblocking(), ID_TIMER, input_text, hid_device_info::manufacturer_string, NULL, output_button, hid_device_info::path, hid_device_info::product_id, hid_device_info::product_string, timeout_scalar, and hid_device_info::vendor_id.

Referenced by MainWindow().

223 {
224  if (connected_device != NULL)
225  return 1;
226 
227  FXint cur_item = device_list->getCurrentItem();
228  if (cur_item < 0)
229  return -1;
230  FXListItem *item = device_list->getItem(cur_item);
231  if (!item)
232  return -1;
233  struct hid_device_info *device_info = (struct hid_device_info*) item->getData();
234  if (!device_info)
235  return -1;
236 
237  connected_device = hid_open_path(device_info->path);
238 
239  if (!connected_device) {
240  FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device");
241  return -1;
242  }
243 
245 
246  getApp()->addTimeout(this, ID_TIMER,
247  5 * timeout_scalar /*5ms*/);
248 
249  FXString s;
250  s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id);
251  s += FXString(" ") + device_info->manufacturer_string;
252  s += FXString(" ") + device_info->product_string;
253  connected_label->setText(s);
254  output_button->enable();
255  feature_button->enable();
256  get_feature_button->enable();
257  connect_button->disable();
258  disconnect_button->enable();
259  input_text->setText("");
260 
261 
262  return 1;
263 }
FXList * device_list
Definition: test.cpp:50
GLdouble s
Definition: SDL_opengl.h:2063
const int timeout_scalar
Definition: test.cpp:95
FXButton * output_button
Definition: test.cpp:54
wchar_t * manufacturer_string
Definition: hidapi.h:66
char * path
Definition: hidapi.h:55
FXButton * connect_button
Definition: test.cpp:51
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock)
Set the device handle to be non-blocking.
Definition: hid.cpp:1060
unsigned short product_id
Definition: hidapi.h:59
hid_device * connected_device
Definition: test.cpp:67
FXButton * get_feature_button
Definition: test.cpp:59
unsigned short vendor_id
Definition: hidapi.h:57
wchar_t * product_string
Definition: hidapi.h:68
FXLabel * connected_label
Definition: test.cpp:55
#define NULL
Definition: begin_code.h:164
FXButton * feature_button
Definition: test.cpp:58
HID_API_EXPORT hid_device *HID_API_CALL hid_open_path(const char *path, int bExclusive)
Open a HID device by its path name.
Definition: hid.cpp:995
FXButton * disconnect_button
Definition: test.cpp:52
FXText * input_text
Definition: test.cpp:63

◆ onDisconnect()

long MainWindow::onDisconnect ( FXObject *  sender,
FXSelector  sel,
void ptr 
)

Definition at line 266 of file test.cpp.

References connect_button, connected_device, connected_label, disconnect_button, feature_button, get_feature_button, hid_close(), ID_TIMER, NULL, and output_button.

Referenced by MainWindow().

267 {
270  connected_label->setText("Disconnected");
271  output_button->disable();
272  feature_button->disable();
273  get_feature_button->disable();
274  connect_button->enable();
275  disconnect_button->disable();
276 
277  getApp()->removeTimeout(this, ID_TIMER);
278 
279  return 1;
280 }
FXButton * output_button
Definition: test.cpp:54
FXButton * connect_button
Definition: test.cpp:51
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device)
Close a HID device.
Definition: hid.cpp:1090
hid_device * connected_device
Definition: test.cpp:67
FXButton * get_feature_button
Definition: test.cpp:59
FXLabel * connected_label
Definition: test.cpp:55
#define NULL
Definition: begin_code.h:164
FXButton * feature_button
Definition: test.cpp:58
FXButton * disconnect_button
Definition: test.cpp:52

◆ onGetFeatureReport()

long MainWindow::onGetFeatureReport ( FXObject *  sender,
FXSelector  sel,
void ptr 
)

Definition at line 435 of file test.cpp.

References connected_device, get_feature_text, getDataFromTextField(), hid_error(), hid_get_feature_report(), i, input_text, and memset.

Referenced by MainWindow().

436 {
437  char buf[256];
438  size_t len;
439 
440  memset(buf, 0x0, sizeof(buf));
441  len = getDataFromTextField(get_feature_text, buf, sizeof(buf));
442 
443  if (len != 1) {
444  FXMessageBox::error(this, MBOX_OK, "Too many numbers", "Enter only a single report number in the text field");
445  }
446 
447  int res = hid_get_feature_report(connected_device, (unsigned char*)buf, sizeof(buf));
448  if (res < 0) {
449  FXMessageBox::error(this, MBOX_OK, "Error Getting Report", "Could not get feature report from device. Error reported was: %ls", hid_error(connected_device));
450  }
451 
452  if (res > 0) {
453  FXString s;
454  s.format("Returned Feature Report. %d bytes:\n", res);
455  for (int i = 0; i < res; i++) {
456  FXString t;
457  t.format("%02hhx ", buf[i]);
458  s += t;
459  if ((i+1) % 4 == 0)
460  s += " ";
461  if ((i+1) % 16 == 0)
462  s += "\n";
463  }
464  s += "\n";
465  input_text->appendText(s);
466  input_text->setBottomLine(INT_MAX);
467  }
468 
469  return 1;
470 }
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error(hid_device *device)
Get a string describing the last error which occurred.
Definition: hid.cpp:1149
GLdouble s
Definition: SDL_opengl.h:2063
#define memset
Definition: SDL_malloc.c:619
GLenum GLsizei len
GLuint res
hid_device * connected_device
Definition: test.cpp:67
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.
Definition: hid.cpp:1078
GLenum GLuint GLenum GLsizei const GLchar * buf
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)
Definition: SDL_x11sym.h:50
GLuint GLfloat x0
FXTextField * get_feature_text
Definition: test.cpp:62
size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len)
Definition: test.cpp:318
FXText * input_text
Definition: test.cpp:63
GLdouble GLdouble t
Definition: SDL_opengl.h:2071

◆ onMacTimeout()

long MainWindow::onMacTimeout ( FXObject *  sender,
FXSelector  sel,
void ptr 
)

Definition at line 512 of file test.cpp.

References check_apple_events(), ID_MAC_TIMER, and timeout_scalar.

Referenced by MainWindow().

513 {
514 #ifdef __APPLE__
516 
517  getApp()->addTimeout(this, ID_MAC_TIMER,
518  50 * timeout_scalar /*50ms*/);
519 #endif
520 
521  return 1;
522 }
const int timeout_scalar
Definition: test.cpp:95
void check_apple_events()

◆ onRescan()

long MainWindow::onRescan ( FXObject *  sender,
FXSelector  sel,
void ptr 
)

Definition at line 283 of file test.cpp.

References device_list, devices, hid_enumerate(), hid_free_enumeration(), hid_device_info::manufacturer_string, hid_device_info::next, NULL, hid_device_info::product_id, hid_device_info::product_string, hid_device_info::usage, hid_device_info::usage_page, and hid_device_info::vendor_id.

Referenced by create(), and MainWindow().

284 {
285  struct hid_device_info *cur_dev;
286 
287  device_list->clearItems();
288 
289  // List the Devices
291  devices = hid_enumerate(0x0, 0x0);
292  cur_dev = devices;
293  while (cur_dev) {
294  // Add it to the List Box.
295  FXString s;
296  FXString usage_str;
297  s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id);
298  s += FXString(" ") + cur_dev->manufacturer_string;
299  s += FXString(" ") + cur_dev->product_string;
300  usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage);
301  s += usage_str;
302  FXListItem *li = new FXListItem(s, NULL, cur_dev);
303  device_list->appendItem(li);
304 
305  cur_dev = cur_dev->next;
306  }
307 
308  if (device_list->getNumItems() == 0)
309  device_list->appendItem("*** No Devices Connected ***");
310  else {
311  device_list->selectItem(0);
312  }
313 
314  return 1;
315 }
FXList * device_list
Definition: test.cpp:50
GLdouble s
Definition: SDL_opengl.h:2063
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs)
Free an enumeration Linked List.
Definition: hid.cpp:979
struct hid_device_info * devices
Definition: test.cpp:66
wchar_t * manufacturer_string
Definition: hidapi.h:66
struct hid_device_info * next
Definition: hidapi.h:82
unsigned short product_id
Definition: hidapi.h:59
unsigned short vendor_id
Definition: hidapi.h:57
wchar_t * product_string
Definition: hidapi.h:68
unsigned short usage
Definition: hidapi.h:74
#define NULL
Definition: begin_code.h:164
unsigned short usage_page
Definition: hidapi.h:71
GLuint GLfloat x0
EGLDeviceEXT * devices
Definition: eglext.h:621
struct hid_device_info HID_API_EXPORT *HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
Enumerate the HID Devices.
Definition: hid.cpp:961

◆ onSendFeatureReport()

long MainWindow::onSendFeatureReport ( FXObject *  sender,
FXSelector  sel,
void ptr 
)

Definition at line 404 of file test.cpp.

References connected_device, feature_len, feature_text, getDataFromTextField(), getLengthFromTextField(), hid_error(), hid_send_feature_report(), and memset.

Referenced by MainWindow().

405 {
406  char buf[256];
407  size_t data_len, len;
408  int textfield_len;
409 
410  memset(buf, 0x0, sizeof(buf));
411  textfield_len = getLengthFromTextField(feature_len);
412  data_len = getDataFromTextField(feature_text, buf, sizeof(buf));
413 
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.");
416  return 1;
417  }
418 
419  if (textfield_len > sizeof(buf)) {
420  FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
421  return 1;
422  }
423 
424  len = (textfield_len)? textfield_len: data_len;
425 
426  int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len);
427  if (res < 0) {
428  FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device));
429  }
430 
431  return 1;
432 }
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error(hid_device *device)
Get a string describing the last error which occurred.
Definition: hid.cpp:1149
int getLengthFromTextField(FXTextField *tf)
Definition: test.cpp:349
FXTextField * feature_len
Definition: test.cpp:61
#define memset
Definition: SDL_malloc.c:619
GLenum GLsizei len
GLuint res
FXTextField * feature_text
Definition: test.cpp:60
hid_device * connected_device
Definition: test.cpp:67
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLfloat x0
size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len)
Definition: test.cpp:318
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.
Definition: hid.cpp:1065

◆ onSendOutputReport()

long MainWindow::onSendOutputReport ( FXObject *  sender,
FXSelector  sel,
void ptr 
)

Definition at line 373 of file test.cpp.

References connected_device, getDataFromTextField(), getLengthFromTextField(), hid_error(), hid_write(), memset, output_len, and output_text.

Referenced by MainWindow().

374 {
375  char buf[256];
376  size_t data_len, len;
377  int textfield_len;
378 
379  memset(buf, 0x0, sizeof(buf));
380  textfield_len = getLengthFromTextField(output_len);
381  data_len = getDataFromTextField(output_text, buf, sizeof(buf));
382 
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.");
385  return 1;
386  }
387 
388  if (textfield_len > sizeof(buf)) {
389  FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
390  return 1;
391  }
392 
393  len = (textfield_len)? textfield_len: data_len;
394 
395  int res = hid_write(connected_device, (const unsigned char*)buf, len);
396  if (res < 0) {
397  FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device));
398  }
399 
400  return 1;
401 }
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error(hid_device *device)
Get a string describing the last error which occurred.
Definition: hid.cpp:1149
int getLengthFromTextField(FXTextField *tf)
Definition: test.cpp:349
FXTextField * output_text
Definition: test.cpp:56
#define memset
Definition: SDL_malloc.c:619
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.
Definition: hid.cpp:1028
GLenum GLsizei len
GLuint res
hid_device * connected_device
Definition: test.cpp:67
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLfloat x0
size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len)
Definition: test.cpp:318
FXTextField * output_len
Definition: test.cpp:57

◆ onTimeout()

long MainWindow::onTimeout ( FXObject *  sender,
FXSelector  sel,
void ptr 
)

Definition at line 480 of file test.cpp.

References connected_device, hid_read(), i, ID_TIMER, input_text, and timeout_scalar.

Referenced by MainWindow().

481 {
482  unsigned char buf[256];
483  int res = hid_read(connected_device, buf, sizeof(buf));
484 
485  if (res > 0) {
486  FXString s;
487  s.format("Received %d bytes:\n", res);
488  for (int i = 0; i < res; i++) {
489  FXString t;
490  t.format("%02hhx ", buf[i]);
491  s += t;
492  if ((i+1) % 4 == 0)
493  s += " ";
494  if ((i+1) % 16 == 0)
495  s += "\n";
496  }
497  s += "\n";
498  input_text->appendText(s);
499  input_text->setBottomLine(INT_MAX);
500  }
501  if (res < 0) {
502  input_text->appendText("hid_read() returned error\n");
503  input_text->setBottomLine(INT_MAX);
504  }
505 
506  getApp()->addTimeout(this, ID_TIMER,
507  5 * timeout_scalar /*5ms*/);
508  return 1;
509 }
GLdouble s
Definition: SDL_opengl.h:2063
const int timeout_scalar
Definition: test.cpp:95
GLuint res
hid_device * connected_device
Definition: test.cpp:67
GLenum GLuint GLenum GLsizei const GLchar * buf
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)
Definition: SDL_x11sym.h:50
FXText * input_text
Definition: test.cpp:63
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
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.
Definition: hid.cpp:1053

Field Documentation

◆ connect_button

FXButton* MainWindow::connect_button
private

Definition at line 51 of file test.cpp.

Referenced by MainWindow(), onConnect(), and onDisconnect().

◆ connected_device

hid_device* MainWindow::connected_device
private

◆ connected_label

FXLabel* MainWindow::connected_label
private

Definition at line 55 of file test.cpp.

Referenced by MainWindow(), onConnect(), and onDisconnect().

◆ device_list

FXList* MainWindow::device_list
private

Definition at line 50 of file test.cpp.

Referenced by MainWindow(), onConnect(), and onRescan().

◆ devices

struct hid_device_info* MainWindow::devices
private

Definition at line 66 of file test.cpp.

Referenced by onRescan().

◆ disconnect_button

FXButton* MainWindow::disconnect_button
private

Definition at line 52 of file test.cpp.

Referenced by MainWindow(), onConnect(), and onDisconnect().

◆ feature_button

FXButton* MainWindow::feature_button
private

Definition at line 58 of file test.cpp.

Referenced by MainWindow(), onConnect(), and onDisconnect().

◆ feature_len

FXTextField* MainWindow::feature_len
private

Definition at line 61 of file test.cpp.

Referenced by MainWindow(), and onSendFeatureReport().

◆ feature_text

FXTextField* MainWindow::feature_text
private

Definition at line 60 of file test.cpp.

Referenced by MainWindow(), and onSendFeatureReport().

◆ get_feature_button

FXButton* MainWindow::get_feature_button
private

Definition at line 59 of file test.cpp.

Referenced by MainWindow(), onConnect(), and onDisconnect().

◆ get_feature_text

FXTextField* MainWindow::get_feature_text
private

Definition at line 62 of file test.cpp.

Referenced by MainWindow(), and onGetFeatureReport().

◆ input_text

FXText* MainWindow::input_text
private

Definition at line 63 of file test.cpp.

Referenced by MainWindow(), onClear(), onConnect(), onGetFeatureReport(), and onTimeout().

◆ output_button

FXButton* MainWindow::output_button
private

Definition at line 54 of file test.cpp.

Referenced by MainWindow(), onConnect(), and onDisconnect().

◆ output_len

FXTextField* MainWindow::output_len
private

Definition at line 57 of file test.cpp.

Referenced by MainWindow(), and onSendOutputReport().

◆ output_text

FXTextField* MainWindow::output_text
private

Definition at line 56 of file test.cpp.

Referenced by MainWindow(), and onSendOutputReport().

◆ rescan_button

FXButton* MainWindow::rescan_button
private

Definition at line 53 of file test.cpp.

Referenced by MainWindow().

◆ title_font

FXFont* MainWindow::title_font
private

Definition at line 64 of file test.cpp.

Referenced by MainWindow(), and ~MainWindow().


The documentation for this class was generated from the following file: