1.1 --- a/test.cpp Wed May 21 22:55:14 2014 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,826 +0,0 @@
1.4 -/*******************************************************
1.5 - Demo Program for HIDAPI
1.6 -
1.7 - Alan Ott
1.8 - Signal 11 Software
1.9 -
1.10 - 2010-07-20
1.11 -
1.12 - Copyright 2010, All Rights Reserved
1.13 -
1.14 - This contents of this file may be used by anyone
1.15 - for any reason without any conditions and may be
1.16 - used as a starting point for your own applications
1.17 - which use HIDAPI.
1.18 -********************************************************/
1.19 -
1.20 -#include "MainWindow.h"
1.21 -
1.22 -
1.23 -// FOX 1.7 changes the timeouts to all be nanoseconds.
1.24 -// Fox 1.6 had all timeouts as milliseconds.
1.25 -#if (FOX_MINOR >= 7)
1.26 - const int timeout_scalar = 1000*1000;
1.27 -#else
1.28 - const int timeout_scalar = 1;
1.29 -#endif
1.30 -
1.31 -
1.32 -FXDEFMAP(MainWindow) MainWindowMap [] = {
1.33 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CONNECT, MainWindow::onConnect ),
1.34 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_DISCONNECT, MainWindow::onDisconnect ),
1.35 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_RESCAN, MainWindow::onRescan ),
1.36 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_OUTPUT_REPORT, MainWindow::onSendOutputReport ),
1.37 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_FEATURE_REPORT, MainWindow::onSendFeatureReport ),
1.38 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_GET_FEATURE_REPORT, MainWindow::onGetFeatureReport ),
1.39 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CLEAR, MainWindow::onClear ),
1.40 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_CLEAR_DISPLAY, MainWindow::onFutabaClearDisplay ),
1.41 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DIMMING, MainWindow::onFutabaDimming ),
1.42 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DISPLAY_DATA_INPUT, MainWindow::onFutabaDisplayDataInput ),
1.43 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_ID, MainWindow::onFutabaReadId ),
1.44 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ),
1.45 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ),
1.46 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ),
1.47 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_RESET_PIXEL, MainWindow::onFutabaResetPixel ),
1.48 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ),
1.49 - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SELECT_FONT, MainWindow::onSelectFont ),
1.50 - FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ),
1.51 - FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ),
1.52 -};
1.53 -
1.54 -FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap));
1.55 -
1.56 -MainWindow::MainWindow(FXApp *app)
1.57 - : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900),
1.58 - iCurrentFont(NULL),
1.59 - iFontImage(NULL)
1.60 -{
1.61 - iDimming=0x35;
1.62 - devices = NULL;
1.63 - connected_device = NULL;
1.64 -
1.65 - FXVerticalFrame *vf = new FXVerticalFrame(this, LAYOUT_FILL_Y|LAYOUT_FILL_X);
1.66 -
1.67 - FXLabel *label = new FXLabel(vf, "HIDAPI Test Tool");
1.68 - title_font = new FXFont(getApp(), "Arial", 14, FXFont::Bold);
1.69 - label->setFont(title_font);
1.70 -
1.71 - new FXLabel(vf,
1.72 - "Select a device and press Connect.", NULL, JUSTIFY_LEFT);
1.73 - new FXLabel(vf,
1.74 - "Output data bytes can be entered in the Output section, \n"
1.75 - "separated by space, comma or brackets. Data starting with 0x\n"
1.76 - "is treated as hex. Data beginning with a 0 is treated as \n"
1.77 - "octal. All other data is treated as decimal.", NULL, JUSTIFY_LEFT);
1.78 - new FXLabel(vf,
1.79 - "Data received from the device appears in the Input section.",
1.80 - NULL, JUSTIFY_LEFT);
1.81 - new FXLabel(vf,
1.82 - "Optionally, a report length may be specified. Extra bytes are\n"
1.83 - "padded with zeros. If no length is specified, the length is \n"
1.84 - "inferred from the data.",
1.85 - NULL, JUSTIFY_LEFT);
1.86 - new FXLabel(vf, "");
1.87 -
1.88 - // Device List and Connect/Disconnect buttons
1.89 - FXHorizontalFrame *hf = new FXHorizontalFrame(vf, LAYOUT_FILL_X);
1.90 - //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);
1.91 - 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);
1.92 - FXVerticalFrame *buttonVF = new FXVerticalFrame(hf);
1.93 - connect_button = new FXButton(buttonVF, "Connect", NULL, this, ID_CONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
1.94 - disconnect_button = new FXButton(buttonVF, "Disconnect", NULL, this, ID_DISCONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
1.95 - disconnect_button->disable();
1.96 - rescan_button = new FXButton(buttonVF, "Re-Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X);
1.97 - new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0);
1.98 -
1.99 - connected_label = new FXLabel(vf, "Disconnected");
1.100 -
1.101 - //Font group
1.102 - new FXHorizontalFrame(vf);
1.103 - FXGroupBox *gb = new FXGroupBox(vf, "Fonts", FRAME_GROOVE|LAYOUT_FILL_X);
1.104 - FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
1.105 - iButtonSelectFont = new FXButton(matrix, "Select Font", NULL, this, ID_SELECT_FONT, BUTTON_NORMAL|LAYOUT_FILL_X);
1.106 -
1.107 - //Futaba VFD commands
1.108 - new FXHorizontalFrame(vf);
1.109 - gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X);
1.110 - matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
1.111 - iButtonClearDisplay = new FXButton(matrix, "Clear Display", NULL, this, ID_FUTABA_CLEAR_DISPLAY, BUTTON_NORMAL|LAYOUT_FILL_X);
1.112 - iButtonDimming = new FXButton(matrix, "Dimming", NULL, this, ID_FUTABA_DIMMING, BUTTON_NORMAL|LAYOUT_FILL_X);
1.113 - iButtonDisplayDataInput = new FXButton(matrix, "Display Data Input", NULL, this, ID_FUTABA_DISPLAY_DATA_INPUT, BUTTON_NORMAL|LAYOUT_FILL_X);
1.114 - iButtonReadId = new FXButton(matrix, "Read Id", NULL, this, ID_FUTABA_READ_ID, BUTTON_NORMAL|LAYOUT_FILL_X);
1.115 - iButtonReadFirmwareRevision = new FXButton(matrix, "Read Firmware Revision", NULL, this, ID_FUTABA_READ_FIRMWARE_REVISION, BUTTON_NORMAL|LAYOUT_FILL_X);
1.116 - iButtonPowerSupplyMonitor = new FXButton(matrix, "Power Supply Monitor", NULL, this, ID_FUTABA_POWER_SUPPLY_MONITOR, BUTTON_NORMAL|LAYOUT_FILL_X);
1.117 - new FXLabel(matrix, "X",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
1.118 - new FXLabel(matrix, "Y",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
1.119 - new FXLabel(matrix, "",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
1.120 - iTextFieldX = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
1.121 - iTextFieldY = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
1.122 - iButtonSetPixel = new FXButton(matrix, "Set Pixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
1.123 - iButtonResetPixel = new FXButton(matrix, "Reset Pixel", NULL, this, ID_FUTABA_RESET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
1.124 - //
1.125 - iButtonSetAllPixels = new FXButton(matrix, "Set All Pixels", NULL, this, ID_FUTABA_SET_ALL_PIXELS, BUTTON_NORMAL|LAYOUT_FILL_X);
1.126 - //
1.127 -
1.128 - //
1.129 - iButtonClearDisplay->disable();
1.130 - iButtonDimming->disable();
1.131 - iButtonDisplayDataInput->disable();
1.132 - iButtonReadId->disable();
1.133 - iButtonReadFirmwareRevision->disable();
1.134 - iButtonPowerSupplyMonitor->disable();
1.135 - iTextFieldX->disable();
1.136 - iTextFieldY->disable();
1.137 - iButtonSetPixel->disable();
1.138 - iButtonResetPixel->disable();
1.139 - iButtonSetAllPixels->disable();
1.140 - //
1.141 -
1.142 - // Output Group Box
1.143 - new FXHorizontalFrame(vf);
1.144 - gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X);
1.145 - matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
1.146 - new FXLabel(matrix, "Data");
1.147 - new FXLabel(matrix, "Length");
1.148 - new FXLabel(matrix, "");
1.149 -
1.150 - //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
1.151 - output_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
1.152 - output_text->setText("1 0x81 0");
1.153 - output_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
1.154 - output_button = new FXButton(matrix, "Send Output Report", NULL, this, ID_SEND_OUTPUT_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
1.155 - output_button->disable();
1.156 - //new FXHorizontalFrame(matrix, LAYOUT_FILL_X);
1.157 -
1.158 - //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
1.159 - feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
1.160 - feature_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
1.161 - feature_button = new FXButton(matrix, "Send Feature Report", NULL, this, ID_SEND_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
1.162 - feature_button->disable();
1.163 -
1.164 - get_feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
1.165 - new FXWindow(matrix);
1.166 - get_feature_button = new FXButton(matrix, "Get Feature Report", NULL, this, ID_GET_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
1.167 - get_feature_button->disable();
1.168 -
1.169 -
1.170 - // Input Group Box
1.171 - gb = new FXGroupBox(vf, "Input", FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y);
1.172 - FXVerticalFrame *innerVF = new FXVerticalFrame(gb, LAYOUT_FILL_X|LAYOUT_FILL_Y);
1.173 - 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);
1.174 - input_text->setEditable(false);
1.175 - new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT);
1.176 -
1.177 -
1.178 -}
1.179 -
1.180 -MainWindow::~MainWindow()
1.181 -{
1.182 - delete iCurrentFont;
1.183 - iCurrentFont = NULL;
1.184 -
1.185 - delete iFontImage;
1.186 - iFontImage = NULL;
1.187 -
1.188 - if (connected_device)
1.189 - hid_close(connected_device);
1.190 - hid_exit();
1.191 - delete title_font;
1.192 -}
1.193 -
1.194 -void
1.195 -MainWindow::create()
1.196 -{
1.197 - FXMainWindow::create();
1.198 - show();
1.199 -
1.200 - onRescan(NULL, 0, NULL);
1.201 -
1.202 - //Just testing our new VFD class
1.203 - iVfd01.Open();
1.204 - iVfd01.SetAllPixels(true);
1.205 - iVfd01.Close();
1.206 -
1.207 -
1.208 -#ifdef __APPLE__
1.209 - init_apple_message_system();
1.210 -#endif
1.211 -
1.212 - getApp()->addTimeout(this, ID_MAC_TIMER,
1.213 - 50 * timeout_scalar /*50ms*/);
1.214 -}
1.215 -
1.216 -long
1.217 -MainWindow::onConnect(FXObject *sender, FXSelector sel, void *ptr)
1.218 -{
1.219 - if (connected_device != NULL)
1.220 - return 1;
1.221 -
1.222 - FXint cur_item = device_list->getCurrentItem();
1.223 - if (cur_item < 0)
1.224 - return -1;
1.225 - FXListItem *item = device_list->getItem(cur_item);
1.226 - if (!item)
1.227 - return -1;
1.228 - struct hid_device_info *device_info = (struct hid_device_info*) item->getData();
1.229 - if (!device_info)
1.230 - return -1;
1.231 -
1.232 - connected_device = hid_open_path(device_info->path);
1.233 -
1.234 - if (!connected_device) {
1.235 - FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device");
1.236 - return -1;
1.237 - }
1.238 -
1.239 - hid_set_nonblocking(connected_device, 1);
1.240 -
1.241 - getApp()->addTimeout(this, ID_TIMER,
1.242 - 5 * timeout_scalar /*5ms*/);
1.243 -
1.244 - FXString s;
1.245 - s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id);
1.246 - s += FXString(" ") + device_info->manufacturer_string;
1.247 - s += FXString(" ") + device_info->product_string;
1.248 - connected_label->setText(s);
1.249 - output_button->enable();
1.250 - feature_button->enable();
1.251 - get_feature_button->enable();
1.252 - connect_button->disable();
1.253 - disconnect_button->enable();
1.254 - input_text->setText("");
1.255 - //
1.256 - iButtonClearDisplay->enable();
1.257 - iButtonDimming->enable();
1.258 - iButtonDisplayDataInput->enable();
1.259 - iButtonReadId->enable();
1.260 - iButtonReadFirmwareRevision->enable();
1.261 - iButtonPowerSupplyMonitor->enable();
1.262 - iTextFieldX->enable();
1.263 - iTextFieldY->enable();
1.264 - iButtonSetPixel->enable();
1.265 - iButtonResetPixel->enable();
1.266 - iButtonSetAllPixels->enable();
1.267 -
1.268 - //
1.269 - iOutputReportBuffer=new unsigned char[KFutabaMaxHidReportSize]; //TODO: use connected_device->output_report_length
1.270 -
1.271 - return 1;
1.272 -}
1.273 -
1.274 -long
1.275 -MainWindow::onDisconnect(FXObject *sender, FXSelector sel, void *ptr)
1.276 -{
1.277 - hid_close(connected_device);
1.278 - connected_device = NULL;
1.279 - connected_label->setText("Disconnected");
1.280 - output_button->disable();
1.281 - feature_button->disable();
1.282 - get_feature_button->disable();
1.283 - connect_button->enable();
1.284 - disconnect_button->disable();
1.285 -
1.286 - getApp()->removeTimeout(this, ID_TIMER);
1.287 -
1.288 - //
1.289 - iButtonClearDisplay->disable();
1.290 - iButtonDimming->disable();
1.291 - iButtonDisplayDataInput->disable();
1.292 - iButtonReadId->disable();
1.293 - iButtonReadFirmwareRevision->disable();
1.294 - iButtonPowerSupplyMonitor->disable();
1.295 - iTextFieldX->disable();
1.296 - iTextFieldY->disable();
1.297 - iButtonSetPixel->disable();
1.298 - iButtonResetPixel->disable();
1.299 - iButtonSetAllPixels->disable();
1.300 - //
1.301 -
1.302 -
1.303 - delete iOutputReportBuffer;
1.304 - iOutputReportBuffer=NULL;
1.305 -
1.306 - return 1;
1.307 -}
1.308 -
1.309 -long
1.310 -MainWindow::onRescan(FXObject *sender, FXSelector sel, void *ptr)
1.311 -{
1.312 - struct hid_device_info *cur_dev;
1.313 -
1.314 - device_list->clearItems();
1.315 -
1.316 - // List the Devices
1.317 - hid_free_enumeration(devices);
1.318 - devices = hid_enumerate(0x0, 0x0);
1.319 - cur_dev = devices;
1.320 - while (cur_dev) {
1.321 - // Add it to the List Box only if it is a Futaba device
1.322 - if (cur_dev->vendor_id == KFutabaVendorId)
1.323 - {
1.324 - FXString s;
1.325 - FXString usage_str;
1.326 - s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id);
1.327 - s += FXString(" ") + cur_dev->manufacturer_string;
1.328 - s += FXString(" ") + cur_dev->product_string;
1.329 - usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage);
1.330 - s += usage_str;
1.331 - FXListItem *li = new FXListItem(s, NULL, cur_dev);
1.332 - device_list->appendItem(li);
1.333 - }
1.334 -
1.335 - cur_dev = cur_dev->next;
1.336 - }
1.337 -
1.338 - if (device_list->getNumItems() == 0)
1.339 - device_list->appendItem("*** No Devices Connected ***");
1.340 - else {
1.341 - device_list->selectItem(0);
1.342 - }
1.343 -
1.344 - return 1;
1.345 -}
1.346 -
1.347 -size_t
1.348 -MainWindow::getDataFromTextField(FXTextField *tf, char *buf, size_t len)
1.349 -{
1.350 - const char *delim = " ,{}\t\r\n";
1.351 - FXString data = tf->getText();
1.352 - const FXchar *d = data.text();
1.353 - size_t i = 0;
1.354 -
1.355 - // Copy the string from the GUI.
1.356 - size_t sz = strlen(d);
1.357 - char *str = (char*) malloc(sz+1);
1.358 - strcpy(str, d);
1.359 -
1.360 - // For each token in the string, parse and store in buf[].
1.361 - char *token = strtok(str, delim);
1.362 - while (token) {
1.363 - char *endptr;
1.364 - long int val = strtol(token, &endptr, 0);
1.365 - buf[i++] = val;
1.366 - token = strtok(NULL, delim);
1.367 - }
1.368 -
1.369 - free(str);
1.370 - return i;
1.371 -}
1.372 -
1.373 -/* getLengthFromTextField()
1.374 - Returns length:
1.375 - 0: empty text field
1.376 - >0: valid length
1.377 - -1: invalid length */
1.378 -int
1.379 -MainWindow::getLengthFromTextField(FXTextField *tf)
1.380 -{
1.381 - long int len;
1.382 - FXString str = tf->getText();
1.383 - size_t sz = str.length();
1.384 -
1.385 - if (sz > 0) {
1.386 - char *endptr;
1.387 - len = strtol(str.text(), &endptr, 0);
1.388 - if (endptr != str.text() && *endptr == '\0') {
1.389 - if (len <= 0) {
1.390 - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Enter a length greater than zero.");
1.391 - return -1;
1.392 - }
1.393 - return len;
1.394 - }
1.395 - else
1.396 - return -1;
1.397 - }
1.398 -
1.399 - return 0;
1.400 -}
1.401 -
1.402 -long
1.403 -MainWindow::onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr)
1.404 -{
1.405 - char buf[256];
1.406 - size_t data_len, len;
1.407 - int textfield_len;
1.408 -
1.409 - memset(buf, 0x0, sizeof(buf));
1.410 - textfield_len = getLengthFromTextField(output_len);
1.411 - data_len = getDataFromTextField(output_text, buf, sizeof(buf));
1.412 -
1.413 - if (textfield_len < 0) {
1.414 - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal.");
1.415 - return 1;
1.416 - }
1.417 -
1.418 - if (textfield_len > sizeof(buf)) {
1.419 - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
1.420 - return 1;
1.421 - }
1.422 -
1.423 - len = (textfield_len)? textfield_len: data_len;
1.424 -
1.425 - int res = hid_write(connected_device, (const unsigned char*)buf, len);
1.426 - if (res < 0) {
1.427 - FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device));
1.428 - }
1.429 -
1.430 - return 1;
1.431 -}
1.432 -
1.433 -long
1.434 -MainWindow::onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
1.435 -{
1.436 - char buf[256];
1.437 - size_t data_len, len;
1.438 - int textfield_len;
1.439 -
1.440 - memset(buf, 0x0, sizeof(buf));
1.441 - textfield_len = getLengthFromTextField(feature_len);
1.442 - data_len = getDataFromTextField(feature_text, buf, sizeof(buf));
1.443 -
1.444 - if (textfield_len < 0) {
1.445 - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal.");
1.446 - return 1;
1.447 - }
1.448 -
1.449 - if (textfield_len > sizeof(buf)) {
1.450 - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
1.451 - return 1;
1.452 - }
1.453 -
1.454 - len = (textfield_len)? textfield_len: data_len;
1.455 -
1.456 - int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len);
1.457 - if (res < 0) {
1.458 - FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device));
1.459 - }
1.460 -
1.461 - return 1;
1.462 -}
1.463 -
1.464 -long
1.465 -MainWindow::onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
1.466 -{
1.467 - char buf[256];
1.468 - size_t len;
1.469 -
1.470 - memset(buf, 0x0, sizeof(buf));
1.471 - len = getDataFromTextField(get_feature_text, buf, sizeof(buf));
1.472 -
1.473 - if (len != 1) {
1.474 - FXMessageBox::error(this, MBOX_OK, "Too many numbers", "Enter only a single report number in the text field");
1.475 - }
1.476 -
1.477 - int res = hid_get_feature_report(connected_device, (unsigned char*)buf, sizeof(buf));
1.478 - if (res < 0) {
1.479 - FXMessageBox::error(this, MBOX_OK, "Error Getting Report", "Could not get feature report from device. Error reported was: %ls", hid_error(connected_device));
1.480 - }
1.481 -
1.482 - if (res > 0) {
1.483 - FXString s;
1.484 - s.format("Returned Feature Report. %d bytes:\n", res);
1.485 - for (int i = 0; i < res; i++) {
1.486 - FXString t;
1.487 - t.format("%02hhx ", buf[i]);
1.488 - s += t;
1.489 - if ((i+1) % 4 == 0)
1.490 - s += " ";
1.491 - if ((i+1) % 16 == 0)
1.492 - s += "\n";
1.493 - }
1.494 - s += "\n";
1.495 - input_text->appendText(s);
1.496 - input_text->setBottomLine(INT_MAX);
1.497 - }
1.498 -
1.499 - return 1;
1.500 -}
1.501 -
1.502 -long
1.503 -MainWindow::onClear(FXObject *sender, FXSelector sel, void *ptr)
1.504 -{
1.505 - input_text->setText("");
1.506 - return 1;
1.507 -}
1.508 -
1.509 -
1.510 -long
1.511 -MainWindow::onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr)
1.512 -{
1.513 - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
1.514 - iOutputReportBuffer[0]=0x00; //Report ID
1.515 - iOutputReportBuffer[1]=0x04; //Report length
1.516 - iOutputReportBuffer[2]=0x1B; //
1.517 - iOutputReportBuffer[3]=0x5B; //
1.518 - iOutputReportBuffer[4]=0x32; //
1.519 - iOutputReportBuffer[5]=0x4A; //
1.520 - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
1.521 -
1.522 - return 1;
1.523 -}
1.524 -
1.525 -long
1.526 -MainWindow::onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr)
1.527 -{
1.528 - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
1.529 - iOutputReportBuffer[0]=0x00; //Report ID
1.530 - iOutputReportBuffer[1]=0x06; //Report length
1.531 - iOutputReportBuffer[2]=0x1B; //
1.532 - iOutputReportBuffer[3]=0x5C; //
1.533 - iOutputReportBuffer[4]=0x3F; //
1.534 - iOutputReportBuffer[5]=0x4C; //
1.535 - iOutputReportBuffer[6]=0x44; //
1.536 - iDimming = (iDimming==0x35?0x30:++iDimming);
1.537 - iOutputReportBuffer[7]=iDimming;
1.538 - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
1.539 -
1.540 - return 1;
1.541 -}
1.542 -
1.543 -long
1.544 -MainWindow::onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr)
1.545 -{
1.546 - //@1B 5B F0 00 00 07 00 01 FF
1.547 -
1.548 - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
1.549 - iOutputReportBuffer[0]=0x00; //Report ID
1.550 - iOutputReportBuffer[1]=0x09; //Report length
1.551 - iOutputReportBuffer[2]=0x1B; //
1.552 - iOutputReportBuffer[3]=0x5B; //
1.553 - iOutputReportBuffer[4]=0xF0; //
1.554 - iOutputReportBuffer[5]=0x00; //X
1.555 - iOutputReportBuffer[6]=0x00; //Y
1.556 - iOutputReportBuffer[7]=0x07; //
1.557 - iOutputReportBuffer[8]=0x00; //
1.558 - iOutputReportBuffer[9]=0x01; //
1.559 - iOutputReportBuffer[10]=0xFF; //
1.560 - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
1.561 -
1.562 -
1.563 - return 1;
1.564 -}
1.565 -
1.566 -
1.567 -
1.568 -
1.569 -/**
1.570 -Set a single pixel to the specified value.
1.571 -@param X coordinate of our pixel.
1.572 -@param Y coordinate of our pixel.
1.573 -@param The LSB defines our pixel value.
1.574 -*/
1.575 -void MainWindow::SetPixel(int aX, int aY, unsigned char aValue)
1.576 - {
1.577 - //Just specify a one pixel block
1.578 - SetPixelBlock(aX,aY,0x00,0x01,aValue);
1.579 - }
1.580 -
1.581 -/**
1.582 -Set the defined pixel block to the given value.
1.583 -@param X coordinate of our pixel block starting point.
1.584 -@param Y coordinate of our pixel block starting point.
1.585 -@param The height of our pixel block.
1.586 -@param The size of our pixel data. Number of pixels divided by 8.
1.587 -@param The value set to 8 pixels.
1.588 -*/
1.589 -void MainWindow::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue)
1.590 - {
1.591 - //Size must be 63 or below
1.592 - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
1.593 - iOutputReportBuffer[0]=0x00; //Report ID
1.594 - iOutputReportBuffer[1]=0x08+aSize; //Report length
1.595 - iOutputReportBuffer[2]=0x1B; //
1.596 - iOutputReportBuffer[3]=0x5B; //
1.597 - iOutputReportBuffer[4]=0xF0; //
1.598 - iOutputReportBuffer[5]=aX; //X
1.599 - iOutputReportBuffer[6]=aY; //Y
1.600 - 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.
1.601 - iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
1.602 - iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
1.603 - memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize);
1.604 - //iOutputReportBuffer[10]=aValue; //Pixel data
1.605 - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
1.606 - }
1.607 -
1.608 -/**
1.609 -Send an output report to a Futaba VFD device.
1.610 -*/
1.611 -/*
1.612 -void MainWindow::SendFutabaOutputReport(unsigned char* aReportData, unsigned char aSize)
1.613 - {
1.614 - //
1.615 - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
1.616 - iOutputReportBuffer[0]=0x00; //Report ID is always null
1.617 - iOutputReportBuffer[1]=0x08+aSize; //Report length
1.618 - iOutputReportBuffer[2]=0x1B; //
1.619 - iOutputReportBuffer[3]=0x5B; //
1.620 - iOutputReportBuffer[4]=0xF0; //
1.621 - iOutputReportBuffer[5]=aX; //X
1.622 - iOutputReportBuffer[6]=aY; //Y
1.623 - 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.
1.624 - iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
1.625 - iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
1.626 - memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize);
1.627 - //iOutputReportBuffer[10]=aValue; //Pixel data
1.628 - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
1.629 - }
1.630 -*/
1.631 -
1.632 -
1.633 -/**
1.634 -*/
1.635 -long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr)
1.636 -{
1.637 - int x=0;
1.638 - int y=0;
1.639 - iTextFieldX->getText().scan("%d",&x);
1.640 - iTextFieldY->getText().scan("%d",&y);
1.641 - SetPixel(x,y,0x01);
1.642 - return 1;
1.643 -}
1.644 -
1.645 -/**
1.646 -*/
1.647 -long MainWindow::onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr)
1.648 -{
1.649 - int x=0;
1.650 - int y=0;
1.651 - iTextFieldX->getText().scan("%d",&x);
1.652 - iTextFieldY->getText().scan("%d",&y);
1.653 - SetPixel(x,y,0x00);
1.654 - return 1;
1.655 -}
1.656 -
1.657 -long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr)
1.658 - {
1.659 - //One pixel at a time
1.660 - /*
1.661 - for (int i=0;i<256;i++)
1.662 - {
1.663 - for (int j=0;j<64;j++)
1.664 - {
1.665 - SetPixel(i,j,0x01);
1.666 - }
1.667 - }
1.668 - */
1.669 - //16x16=256 pixels at a time goes much faster
1.670 - for (int i=0;i<256;i+=16)
1.671 - {
1.672 - for (int j=0;j<64;j+=16)
1.673 - {
1.674 - SetPixelBlock(i,j,15,32,0xFF);
1.675 - //FXThread::sleep(1000000000);
1.676 - }
1.677 - }
1.678 -
1.679 - return 1;
1.680 - }
1.681 -
1.682 -long
1.683 -MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr)
1.684 -{
1.685 - //1BH,5BH,63H,49H,44H
1.686 - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
1.687 - iOutputReportBuffer[0]=0x00; //Report ID
1.688 - iOutputReportBuffer[1]=0x05; //Report length
1.689 - iOutputReportBuffer[2]=0x1B; //
1.690 - iOutputReportBuffer[3]=0x5B; //
1.691 - iOutputReportBuffer[4]=0x63; //
1.692 - iOutputReportBuffer[5]=0x49; //
1.693 - iOutputReportBuffer[6]=0x44; //
1.694 - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
1.695 -
1.696 - return 1;
1.697 -}
1.698 -
1.699 -long
1.700 -MainWindow::onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr)
1.701 -{
1.702 - //1BH,5BH,63H,46H,52H
1.703 - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
1.704 - iOutputReportBuffer[0]=0x00; //Report ID
1.705 - iOutputReportBuffer[1]=0x05; //Report length
1.706 - iOutputReportBuffer[2]=0x1B; //
1.707 - iOutputReportBuffer[3]=0x5B; //
1.708 - iOutputReportBuffer[4]=0x63; //
1.709 - iOutputReportBuffer[5]=0x46; //
1.710 - iOutputReportBuffer[6]=0x52; //
1.711 - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
1.712 -
1.713 - return 1;
1.714 -}
1.715 -
1.716 -long
1.717 -MainWindow::onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr)
1.718 -{
1.719 - //1BH,5BH,63H,50H,4DH
1.720 - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
1.721 - iOutputReportBuffer[0]=0x00; //Report ID
1.722 - iOutputReportBuffer[1]=0x05; //Report length
1.723 - iOutputReportBuffer[2]=0x1B; //
1.724 - iOutputReportBuffer[3]=0x5B; //
1.725 - iOutputReportBuffer[4]=0x63; //
1.726 - iOutputReportBuffer[5]=0x50; //
1.727 - iOutputReportBuffer[6]=0x4D; //
1.728 - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
1.729 -
1.730 - return 1;
1.731 -}
1.732 -
1.733 -
1.734 -
1.735 -long
1.736 -MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr)
1.737 -{
1.738 - unsigned char buf[256];
1.739 - int res = hid_read(connected_device, buf, sizeof(buf));
1.740 -
1.741 - if (res > 0) {
1.742 - FXString s;
1.743 - s.format("Received %d bytes:\n", res);
1.744 - for (int i = 0; i < res; i++) {
1.745 - FXString t;
1.746 - t.format("%02hhx ", buf[i]);
1.747 - s += t;
1.748 - if ((i+1) % 4 == 0)
1.749 - s += " ";
1.750 - if ((i+1) % 16 == 0)
1.751 - s += "\n";
1.752 - }
1.753 - s += "\n";
1.754 - input_text->appendText(s);
1.755 - input_text->setBottomLine(INT_MAX);
1.756 - }
1.757 - if (res < 0) {
1.758 - input_text->appendText("hid_read() returned error\n");
1.759 - input_text->setBottomLine(INT_MAX);
1.760 - }
1.761 -
1.762 - getApp()->addTimeout(this, ID_TIMER,
1.763 - 5 * timeout_scalar /*5ms*/);
1.764 - return 1;
1.765 -}
1.766 -
1.767 -long
1.768 -MainWindow::onMacTimeout(FXObject *sender, FXSelector sel, void *ptr)
1.769 -{
1.770 -#ifdef __APPLE__
1.771 - check_apple_events();
1.772 -
1.773 - getApp()->addTimeout(this, ID_MAC_TIMER,
1.774 - 50 * timeout_scalar /*50ms*/);
1.775 -#endif
1.776 -
1.777 - return 1;
1.778 -}
1.779 -
1.780 -/**
1.781 -
1.782 -*/
1.783 -long MainWindow::onSelectFont(FXObject *sender, FXSelector sel, void *ptr)
1.784 - {
1.785 - FXFontDialog* dlg=new FXFontDialog(this,"Pick a font");
1.786 - if (dlg->execute())
1.787 - {
1.788 - dlg->getFontSelection(iCurrentFontDesc);
1.789 - delete iCurrentFont;
1.790 - iCurrentFont = NULL;
1.791 - iCurrentFont = new FXFont(getApp(),iCurrentFontDesc);
1.792 - iCurrentFont->create();
1.793 - //
1.794 - delete iFontImage;
1.795 - iFontImage = NULL;
1.796 - //
1.797 - FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_";
1.798 - //Create an image the proper size for our text
1.799 - iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_SHMI|IMAGE_SHMP,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight());
1.800 - iFontImage->create();
1.801 - //Perform our drawing
1.802 - {
1.803 - FXDCWindow dc(iFontImage);
1.804 - //dc.begin(iFontImage);
1.805 - dc.setFont(iCurrentFont);
1.806 - dc.setForeground(0xFFFFFFFF);
1.807 - //dc.setBackground(0xFF000000);
1.808 - //dc.setFillStyle(FILL_SOLID);
1.809 - dc.fillRectangle(0,0,iFontImage->getWidth(),iFontImage->getHeight());
1.810 - dc.setForeground(0xFF000000);
1.811 - dc.drawText(0,iCurrentFont->getFontAscent(),text);
1.812 - //dc.end();
1.813 - }
1.814 - FXFileStream file;
1.815 - file.open("fonttest.tga",FXStreamSave);
1.816 - iFontImage->restore();
1.817 - iFontImage->savePixels(file);
1.818 - file.close();
1.819 -
1.820 - //
1.821 -
1.822 - }
1.823 -
1.824 - delete dlg;
1.825 - return 1;
1.826 - }
1.827 -
1.828 -
1.829 -