Adding font selection dialog. Did a bit of cleaning too.
1 /*******************************************************
2 Demo Program for HIDAPI
9 Copyright 2010, All Rights Reserved
11 This contents of this file may be used by anyone
12 for any reason without any conditions and may be
13 used as a starting point for your own applications
15 ********************************************************/
17 #include "MainWindow.h"
20 // FOX 1.7 changes the timeouts to all be nanoseconds.
21 // Fox 1.6 had all timeouts as milliseconds.
23 const int timeout_scalar = 1000*1000;
25 const int timeout_scalar = 1;
29 FXDEFMAP(MainWindow) MainWindowMap [] = {
30 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CONNECT, MainWindow::onConnect ),
31 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_DISCONNECT, MainWindow::onDisconnect ),
32 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_RESCAN, MainWindow::onRescan ),
33 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_OUTPUT_REPORT, MainWindow::onSendOutputReport ),
34 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_FEATURE_REPORT, MainWindow::onSendFeatureReport ),
35 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_GET_FEATURE_REPORT, MainWindow::onGetFeatureReport ),
36 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CLEAR, MainWindow::onClear ),
37 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_CLEAR_DISPLAY, MainWindow::onFutabaClearDisplay ),
38 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DIMMING, MainWindow::onFutabaDimming ),
39 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DISPLAY_DATA_INPUT, MainWindow::onFutabaDisplayDataInput ),
40 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_ID, MainWindow::onFutabaReadId ),
41 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ),
42 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ),
43 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ),
44 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_RESET_PIXEL, MainWindow::onFutabaResetPixel ),
45 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ),
46 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SELECT_FONT, MainWindow::onSelectFont ),
47 FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ),
48 FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ),
51 FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap));
53 MainWindow::MainWindow(FXApp *app)
54 : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900)
58 connected_device = NULL;
60 FXVerticalFrame *vf = new FXVerticalFrame(this, LAYOUT_FILL_Y|LAYOUT_FILL_X);
62 FXLabel *label = new FXLabel(vf, "HIDAPI Test Tool");
63 title_font = new FXFont(getApp(), "Arial", 14, FXFont::Bold);
64 label->setFont(title_font);
67 "Select a device and press Connect.", NULL, JUSTIFY_LEFT);
69 "Output data bytes can be entered in the Output section, \n"
70 "separated by space, comma or brackets. Data starting with 0x\n"
71 "is treated as hex. Data beginning with a 0 is treated as \n"
72 "octal. All other data is treated as decimal.", NULL, JUSTIFY_LEFT);
74 "Data received from the device appears in the Input section.",
77 "Optionally, a report length may be specified. Extra bytes are\n"
78 "padded with zeros. If no length is specified, the length is \n"
79 "inferred from the data.",
83 // Device List and Connect/Disconnect buttons
84 FXHorizontalFrame *hf = new FXHorizontalFrame(vf, LAYOUT_FILL_X);
85 //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);
86 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);
87 FXVerticalFrame *buttonVF = new FXVerticalFrame(hf);
88 connect_button = new FXButton(buttonVF, "Connect", NULL, this, ID_CONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
89 disconnect_button = new FXButton(buttonVF, "Disconnect", NULL, this, ID_DISCONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
90 disconnect_button->disable();
91 rescan_button = new FXButton(buttonVF, "Re-Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X);
92 new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0);
94 connected_label = new FXLabel(vf, "Disconnected");
97 new FXHorizontalFrame(vf);
98 FXGroupBox *gb = new FXGroupBox(vf, "Fonts", FRAME_GROOVE|LAYOUT_FILL_X);
99 FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
100 iButtonSelectFont = new FXButton(matrix, "Select Font", NULL, this, ID_SELECT_FONT, BUTTON_NORMAL|LAYOUT_FILL_X);
102 //Futaba VFD commands
103 new FXHorizontalFrame(vf);
104 gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X);
105 matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
106 iButtonClearDisplay = new FXButton(matrix, "Clear Display", NULL, this, ID_FUTABA_CLEAR_DISPLAY, BUTTON_NORMAL|LAYOUT_FILL_X);
107 iButtonDimming = new FXButton(matrix, "Dimming", NULL, this, ID_FUTABA_DIMMING, BUTTON_NORMAL|LAYOUT_FILL_X);
108 iButtonDisplayDataInput = new FXButton(matrix, "Display Data Input", NULL, this, ID_FUTABA_DISPLAY_DATA_INPUT, BUTTON_NORMAL|LAYOUT_FILL_X);
109 iButtonReadId = new FXButton(matrix, "Read Id", NULL, this, ID_FUTABA_READ_ID, BUTTON_NORMAL|LAYOUT_FILL_X);
110 iButtonReadFirmwareRevision = new FXButton(matrix, "Read Firmware Revision", NULL, this, ID_FUTABA_READ_FIRMWARE_REVISION, BUTTON_NORMAL|LAYOUT_FILL_X);
111 iButtonPowerSupplyMonitor = new FXButton(matrix, "Power Supply Monitor", NULL, this, ID_FUTABA_POWER_SUPPLY_MONITOR, BUTTON_NORMAL|LAYOUT_FILL_X);
112 new FXLabel(matrix, "X",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
113 new FXLabel(matrix, "Y",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
114 new FXLabel(matrix, "",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
115 iTextFieldX = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
116 iTextFieldY = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
117 iButtonSetPixel = new FXButton(matrix, "Set Pixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
118 iButtonResetPixel = new FXButton(matrix, "Reset Pixel", NULL, this, ID_FUTABA_RESET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
120 iButtonSetAllPixels = new FXButton(matrix, "Set All Pixels", NULL, this, ID_FUTABA_SET_ALL_PIXELS, BUTTON_NORMAL|LAYOUT_FILL_X);
124 iButtonClearDisplay->disable();
125 iButtonDimming->disable();
126 iButtonDisplayDataInput->disable();
127 iButtonReadId->disable();
128 iButtonReadFirmwareRevision->disable();
129 iButtonPowerSupplyMonitor->disable();
130 iTextFieldX->disable();
131 iTextFieldY->disable();
132 iButtonSetPixel->disable();
133 iButtonResetPixel->disable();
134 iButtonSetAllPixels->disable();
138 new FXHorizontalFrame(vf);
139 gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X);
140 matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
141 new FXLabel(matrix, "Data");
142 new FXLabel(matrix, "Length");
143 new FXLabel(matrix, "");
145 //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
146 output_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
147 output_text->setText("1 0x81 0");
148 output_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
149 output_button = new FXButton(matrix, "Send Output Report", NULL, this, ID_SEND_OUTPUT_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
150 output_button->disable();
151 //new FXHorizontalFrame(matrix, LAYOUT_FILL_X);
153 //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
154 feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
155 feature_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
156 feature_button = new FXButton(matrix, "Send Feature Report", NULL, this, ID_SEND_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
157 feature_button->disable();
159 get_feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
160 new FXWindow(matrix);
161 get_feature_button = new FXButton(matrix, "Get Feature Report", NULL, this, ID_GET_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
162 get_feature_button->disable();
166 gb = new FXGroupBox(vf, "Input", FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y);
167 FXVerticalFrame *innerVF = new FXVerticalFrame(gb, LAYOUT_FILL_X|LAYOUT_FILL_Y);
168 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);
169 input_text->setEditable(false);
170 new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT);
175 MainWindow::~MainWindow()
177 if (connected_device)
178 hid_close(connected_device);
186 FXMainWindow::create();
189 onRescan(NULL, 0, NULL);
193 init_apple_message_system();
196 getApp()->addTimeout(this, ID_MAC_TIMER,
197 50 * timeout_scalar /*50ms*/);
201 MainWindow::onConnect(FXObject *sender, FXSelector sel, void *ptr)
203 if (connected_device != NULL)
206 FXint cur_item = device_list->getCurrentItem();
209 FXListItem *item = device_list->getItem(cur_item);
212 struct hid_device_info *device_info = (struct hid_device_info*) item->getData();
216 connected_device = hid_open_path(device_info->path);
218 if (!connected_device) {
219 FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device");
223 hid_set_nonblocking(connected_device, 1);
225 getApp()->addTimeout(this, ID_TIMER,
226 5 * timeout_scalar /*5ms*/);
229 s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id);
230 s += FXString(" ") + device_info->manufacturer_string;
231 s += FXString(" ") + device_info->product_string;
232 connected_label->setText(s);
233 output_button->enable();
234 feature_button->enable();
235 get_feature_button->enable();
236 connect_button->disable();
237 disconnect_button->enable();
238 input_text->setText("");
240 iButtonClearDisplay->enable();
241 iButtonDimming->enable();
242 iButtonDisplayDataInput->enable();
243 iButtonReadId->enable();
244 iButtonReadFirmwareRevision->enable();
245 iButtonPowerSupplyMonitor->enable();
246 iTextFieldX->enable();
247 iTextFieldY->enable();
248 iButtonSetPixel->enable();
249 iButtonResetPixel->enable();
250 iButtonSetAllPixels->enable();
253 iOutputReportBuffer=new unsigned char[KFutabaOutputReportLength]; //TODO: use connected_device->output_report_length
259 MainWindow::onDisconnect(FXObject *sender, FXSelector sel, void *ptr)
261 hid_close(connected_device);
262 connected_device = NULL;
263 connected_label->setText("Disconnected");
264 output_button->disable();
265 feature_button->disable();
266 get_feature_button->disable();
267 connect_button->enable();
268 disconnect_button->disable();
270 getApp()->removeTimeout(this, ID_TIMER);
273 iButtonClearDisplay->disable();
274 iButtonDimming->disable();
275 iButtonDisplayDataInput->disable();
276 iButtonReadId->disable();
277 iButtonReadFirmwareRevision->disable();
278 iButtonPowerSupplyMonitor->disable();
279 iTextFieldX->disable();
280 iTextFieldY->disable();
281 iButtonSetPixel->disable();
282 iButtonResetPixel->disable();
283 iButtonSetAllPixels->disable();
287 delete iOutputReportBuffer;
288 iOutputReportBuffer=NULL;
294 MainWindow::onRescan(FXObject *sender, FXSelector sel, void *ptr)
296 struct hid_device_info *cur_dev;
298 device_list->clearItems();
300 //Define Futaba vendor ID to filter our list of device
301 const unsigned short KFutabaVendorId = 0x1008;
304 hid_free_enumeration(devices);
305 devices = hid_enumerate(0x0, 0x0);
308 // Add it to the List Box only if it is a Futaba device
309 if (cur_dev->vendor_id == KFutabaVendorId)
313 s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id);
314 s += FXString(" ") + cur_dev->manufacturer_string;
315 s += FXString(" ") + cur_dev->product_string;
316 usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage);
318 FXListItem *li = new FXListItem(s, NULL, cur_dev);
319 device_list->appendItem(li);
322 cur_dev = cur_dev->next;
325 if (device_list->getNumItems() == 0)
326 device_list->appendItem("*** No Devices Connected ***");
328 device_list->selectItem(0);
335 MainWindow::getDataFromTextField(FXTextField *tf, char *buf, size_t len)
337 const char *delim = " ,{}\t\r\n";
338 FXString data = tf->getText();
339 const FXchar *d = data.text();
342 // Copy the string from the GUI.
343 size_t sz = strlen(d);
344 char *str = (char*) malloc(sz+1);
347 // For each token in the string, parse and store in buf[].
348 char *token = strtok(str, delim);
351 long int val = strtol(token, &endptr, 0);
353 token = strtok(NULL, delim);
360 /* getLengthFromTextField()
364 -1: invalid length */
366 MainWindow::getLengthFromTextField(FXTextField *tf)
369 FXString str = tf->getText();
370 size_t sz = str.length();
374 len = strtol(str.text(), &endptr, 0);
375 if (endptr != str.text() && *endptr == '\0') {
377 FXMessageBox::error(this, MBOX_OK, "Invalid length", "Enter a length greater than zero.");
390 MainWindow::onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr)
393 size_t data_len, len;
396 memset(buf, 0x0, sizeof(buf));
397 textfield_len = getLengthFromTextField(output_len);
398 data_len = getDataFromTextField(output_text, buf, sizeof(buf));
400 if (textfield_len < 0) {
401 FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal.");
405 if (textfield_len > sizeof(buf)) {
406 FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
410 len = (textfield_len)? textfield_len: data_len;
412 int res = hid_write(connected_device, (const unsigned char*)buf, len);
414 FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device));
421 MainWindow::onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
424 size_t data_len, len;
427 memset(buf, 0x0, sizeof(buf));
428 textfield_len = getLengthFromTextField(feature_len);
429 data_len = getDataFromTextField(feature_text, buf, sizeof(buf));
431 if (textfield_len < 0) {
432 FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal.");
436 if (textfield_len > sizeof(buf)) {
437 FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
441 len = (textfield_len)? textfield_len: data_len;
443 int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len);
445 FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device));
452 MainWindow::onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
457 memset(buf, 0x0, sizeof(buf));
458 len = getDataFromTextField(get_feature_text, buf, sizeof(buf));
461 FXMessageBox::error(this, MBOX_OK, "Too many numbers", "Enter only a single report number in the text field");
464 int res = hid_get_feature_report(connected_device, (unsigned char*)buf, sizeof(buf));
466 FXMessageBox::error(this, MBOX_OK, "Error Getting Report", "Could not get feature report from device. Error reported was: %ls", hid_error(connected_device));
471 s.format("Returned Feature Report. %d bytes:\n", res);
472 for (int i = 0; i < res; i++) {
474 t.format("%02hhx ", buf[i]);
482 input_text->appendText(s);
483 input_text->setBottomLine(INT_MAX);
490 MainWindow::onClear(FXObject *sender, FXSelector sel, void *ptr)
492 input_text->setText("");
498 MainWindow::onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr)
500 memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
501 iOutputReportBuffer[0]=0x00; //Report ID
502 iOutputReportBuffer[1]=0x04; //Report length
503 iOutputReportBuffer[2]=0x1B; //
504 iOutputReportBuffer[3]=0x5B; //
505 iOutputReportBuffer[4]=0x32; //
506 iOutputReportBuffer[5]=0x4A; //
507 int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
513 MainWindow::onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr)
515 memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
516 iOutputReportBuffer[0]=0x00; //Report ID
517 iOutputReportBuffer[1]=0x06; //Report length
518 iOutputReportBuffer[2]=0x1B; //
519 iOutputReportBuffer[3]=0x5C; //
520 iOutputReportBuffer[4]=0x3F; //
521 iOutputReportBuffer[5]=0x4C; //
522 iOutputReportBuffer[6]=0x44; //
523 iDimming = (iDimming==0x35?0x30:++iDimming);
524 iOutputReportBuffer[7]=iDimming;
525 int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
531 MainWindow::onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr)
533 //@1B 5B F0 00 00 07 00 01 FF
535 memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
536 iOutputReportBuffer[0]=0x00; //Report ID
537 iOutputReportBuffer[1]=0x09; //Report length
538 iOutputReportBuffer[2]=0x1B; //
539 iOutputReportBuffer[3]=0x5B; //
540 iOutputReportBuffer[4]=0xF0; //
541 iOutputReportBuffer[5]=0x00; //X
542 iOutputReportBuffer[6]=0x00; //Y
543 iOutputReportBuffer[7]=0x07; //
544 iOutputReportBuffer[8]=0x00; //
545 iOutputReportBuffer[9]=0x01; //
546 iOutputReportBuffer[10]=0xFF; //
547 int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
557 Set a single pixel to the specified value.
558 @param X coordinate of our pixel.
559 @param Y coordinate of our pixel.
560 @param The LSB defines our pixel value.
562 void MainWindow::SetPixel(int aX, int aY, unsigned char aValue)
564 //Just specify a one pixel block
565 SetPixelBlock(aX,aY,0x00,0x01,aValue);
570 void MainWindow::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue)
572 //Size must be 63 or below
573 memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
574 iOutputReportBuffer[0]=0x00; //Report ID
575 iOutputReportBuffer[1]=0x08+aSize; //Report length
576 iOutputReportBuffer[2]=0x1B; //
577 iOutputReportBuffer[3]=0x5B; //
578 iOutputReportBuffer[4]=0xF0; //
579 iOutputReportBuffer[5]=aX; //X
580 iOutputReportBuffer[6]=aY; //Y
581 iOutputReportBuffer[7]=aHeight; //Y length before return. Though outside the specs, setting this to zero apparently allows us to modify a single pixel without touching any other.
582 iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
583 iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
584 memset(iOutputReportBuffer+10, aValue, KFutabaOutputReportLength);
585 //iOutputReportBuffer[10]=aValue; //Pixel data
586 int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
592 long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr)
596 iTextFieldX->getText().scan("%d",&x);
597 iTextFieldY->getText().scan("%d",&y);
604 long MainWindow::onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr)
608 iTextFieldX->getText().scan("%d",&x);
609 iTextFieldY->getText().scan("%d",&y);
614 long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr)
616 //One pixel at a time
618 for (int i=0;i<256;i++)
620 for (int j=0;j<64;j++)
626 //16x16=256 pixels at a time goes much faster
627 for (int i=0;i<256;i+=16)
629 for (int j=0;j<64;j+=16)
631 SetPixelBlock(i,j,15,32,0xFF);
632 //FXThread::sleep(1000000000);
640 MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr)
642 //1BH,5BH,63H,49H,44H
643 memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
644 iOutputReportBuffer[0]=0x00; //Report ID
645 iOutputReportBuffer[1]=0x05; //Report length
646 iOutputReportBuffer[2]=0x1B; //
647 iOutputReportBuffer[3]=0x5B; //
648 iOutputReportBuffer[4]=0x63; //
649 iOutputReportBuffer[5]=0x49; //
650 iOutputReportBuffer[6]=0x44; //
651 int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
657 MainWindow::onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr)
659 //1BH,5BH,63H,46H,52H
660 memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
661 iOutputReportBuffer[0]=0x00; //Report ID
662 iOutputReportBuffer[1]=0x05; //Report length
663 iOutputReportBuffer[2]=0x1B; //
664 iOutputReportBuffer[3]=0x5B; //
665 iOutputReportBuffer[4]=0x63; //
666 iOutputReportBuffer[5]=0x46; //
667 iOutputReportBuffer[6]=0x52; //
668 int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
674 MainWindow::onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr)
676 //1BH,5BH,63H,50H,4DH
677 memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
678 iOutputReportBuffer[0]=0x00; //Report ID
679 iOutputReportBuffer[1]=0x05; //Report length
680 iOutputReportBuffer[2]=0x1B; //
681 iOutputReportBuffer[3]=0x5B; //
682 iOutputReportBuffer[4]=0x63; //
683 iOutputReportBuffer[5]=0x50; //
684 iOutputReportBuffer[6]=0x4D; //
685 int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
693 MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr)
695 unsigned char buf[256];
696 int res = hid_read(connected_device, buf, sizeof(buf));
700 s.format("Received %d bytes:\n", res);
701 for (int i = 0; i < res; i++) {
703 t.format("%02hhx ", buf[i]);
711 input_text->appendText(s);
712 input_text->setBottomLine(INT_MAX);
715 input_text->appendText("hid_read() returned error\n");
716 input_text->setBottomLine(INT_MAX);
719 getApp()->addTimeout(this, ID_TIMER,
720 5 * timeout_scalar /*5ms*/);
725 MainWindow::onMacTimeout(FXObject *sender, FXSelector sel, void *ptr)
728 check_apple_events();
730 getApp()->addTimeout(this, ID_MAC_TIMER,
731 50 * timeout_scalar /*50ms*/);
740 long MainWindow::onSelectFont(FXObject *sender, FXSelector sel, void *ptr)
742 FXFontDialog* dlg=new FXFontDialog(this,"Pick a font");
744 dlg->getFontSelection(iCurrentFontDesc);