# HG changeset patch # User sl # Date 1400598290 -7200 # Node ID d57fa1211bb054a5ec412c5ec4977b64108fb5f9 # Parent 2dbfd75c2bbee7943289a5fc9b776d447ac82e53 Add buttons and text field to set pixels. diff -r 2dbfd75c2bbe -r d57fa1211bb0 test.cpp --- a/test.cpp Mon May 19 22:33:38 2014 +0200 +++ b/test.cpp Tue May 20 17:04:50 2014 +0200 @@ -1,13 +1,13 @@ /******************************************************* Demo Program for HIDAPI - + Alan Ott Signal 11 Software 2010-07-20 Copyright 2010, All Rights Reserved - + This contents of this file may be used by anyone for any reason without any conditions and may be used as a starting point for your own applications @@ -32,7 +32,7 @@ class MainWindow : public FXMainWindow { FXDECLARE(MainWindow) - + public: enum { ID_FIRST = FXMainWindow::ID_LAST, @@ -51,9 +51,11 @@ ID_FUTABA_READ_ID, ID_FUTABA_READ_FIRMWARE_REVISION, ID_FUTABA_POWER_SUPPLY_MONITOR, + ID_FUTABA_SET_PIXEL, + ID_FUTABA_SET_ALL_PIXELS, ID_LAST, }; - + private: FXList *device_list; FXButton *connect_button; @@ -77,6 +79,11 @@ FXButton *iButtonReadId; FXButton *iButtonReadFirmwareRevision; FXButton *iButtonPowerSupplyMonitor; + FXTextField *iTextFieldX; + FXTextField *iTextFieldY; + FXButton *iButtonSetPixel; + FXButton *iButtonSetAllPixels; + unsigned char* iOutputReportBuffer; unsigned char iDimming; @@ -85,7 +92,7 @@ //FXTextField *iTextY; - + struct hid_device_info *devices; hid_device *connected_device; size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len); @@ -98,7 +105,7 @@ 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); @@ -113,6 +120,8 @@ long onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr); long onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr); long onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr); + long onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr); + long onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr); // long onTimeout(FXObject *sender, FXSelector sel, void *ptr); @@ -144,6 +153,8 @@ FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_ID, MainWindow::onFutabaReadId ), FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ), FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ), FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ), FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ), }; @@ -151,7 +162,7 @@ FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap)); MainWindow::MainWindow(FXApp *app) - : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 425,700) + : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900) { iDimming=0x35; devices = NULL; @@ -162,7 +173,7 @@ FXLabel *label = new FXLabel(vf, "HIDAPI Test Tool"); title_font = new FXFont(getApp(), "Arial", 14, FXFont::Bold); label->setFont(title_font); - + new FXLabel(vf, "Select a device and press Connect.", NULL, JUSTIFY_LEFT); new FXLabel(vf, @@ -192,7 +203,7 @@ new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0); connected_label = new FXLabel(vf, "Disconnected"); - + //Futaba VFD commands new FXHorizontalFrame(vf); FXGroupBox *gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X); @@ -203,6 +214,14 @@ iButtonReadId = new FXButton(matrix, "Read Id", NULL, this, ID_FUTABA_READ_ID, BUTTON_NORMAL|LAYOUT_FILL_X); iButtonReadFirmwareRevision = new FXButton(matrix, "Read Firmware Revision", NULL, this, ID_FUTABA_READ_FIRMWARE_REVISION, BUTTON_NORMAL|LAYOUT_FILL_X); iButtonPowerSupplyMonitor = new FXButton(matrix, "Power Supply Monitor", NULL, this, ID_FUTABA_POWER_SUPPLY_MONITOR, BUTTON_NORMAL|LAYOUT_FILL_X); + new FXLabel(matrix, "X",NULL,LABEL_NORMAL|LAYOUT_FILL_X); + new FXLabel(matrix, "Y",NULL,LABEL_NORMAL|LAYOUT_FILL_X); + new FXLabel(matrix, "",NULL,LABEL_NORMAL|LAYOUT_FILL_X); + iTextFieldX = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X); + iTextFieldY = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X); + iButtonSetPixel = new FXButton(matrix, "SetPixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X); + // + iButtonSetAllPixels = new FXButton(matrix, "Set All Pixels", NULL, this, ID_FUTABA_SET_ALL_PIXELS, BUTTON_NORMAL|LAYOUT_FILL_X); // iButtonClearDisplay->disable(); iButtonDimming->disable(); @@ -210,10 +229,14 @@ iButtonReadId->disable(); iButtonReadFirmwareRevision->disable(); iButtonPowerSupplyMonitor->disable(); + iTextFieldX->disable(); + iTextFieldY->disable(); + iButtonSetPixel->disable(); + iButtonSetAllPixels->disable(); // // Output Group Box - new FXHorizontalFrame(vf); + new FXHorizontalFrame(vf); gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X); matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X); new FXLabel(matrix, "Data"); @@ -246,7 +269,7 @@ 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); input_text->setEditable(false); new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT); - + } @@ -265,12 +288,12 @@ show(); onRescan(NULL, 0, NULL); - + #ifdef __APPLE__ init_apple_message_system(); #endif - + getApp()->addTimeout(this, ID_MAC_TIMER, 50 * timeout_scalar /*50ms*/); } @@ -280,7 +303,7 @@ { if (connected_device != NULL) return 1; - + FXint cur_item = device_list->getCurrentItem(); if (cur_item < 0) return -1; @@ -290,19 +313,19 @@ struct hid_device_info *device_info = (struct hid_device_info*) item->getData(); if (!device_info) return -1; - + connected_device = hid_open_path(device_info->path); - + if (!connected_device) { FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device"); return -1; } - + hid_set_nonblocking(connected_device, 1); getApp()->addTimeout(this, ID_TIMER, 5 * timeout_scalar /*5ms*/); - + FXString s; s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id); s += FXString(" ") + device_info->manufacturer_string; @@ -321,6 +344,11 @@ iButtonReadId->enable(); iButtonReadFirmwareRevision->enable(); iButtonPowerSupplyMonitor->enable(); + iTextFieldX->enable(); + iTextFieldY->enable(); + iButtonSetPixel->enable(); + iButtonSetAllPixels->enable(); + // iOutputReportBuffer=new unsigned char[KFutabaOutputReportLength]; //TODO: use connected_device->output_report_length @@ -348,12 +376,16 @@ iButtonReadId->disable(); iButtonReadFirmwareRevision->disable(); iButtonPowerSupplyMonitor->disable(); + iTextFieldX->disable(); + iTextFieldY->disable(); + iButtonSetPixel->disable(); + iButtonSetAllPixels->disable(); // delete iOutputReportBuffer; iOutputReportBuffer=NULL; - + return 1; } @@ -363,17 +395,17 @@ struct hid_device_info *cur_dev; device_list->clearItems(); - + //Define Futaba vendor ID to filter our list of device const unsigned short KFutabaVendorId = 0x1008; // List the Devices hid_free_enumeration(devices); devices = hid_enumerate(0x0, 0x0); - cur_dev = devices; + cur_dev = devices; while (cur_dev) { // Add it to the List Box only if it is a Futaba device - if (cur_dev->vendor_id == KFutabaVendorId) + if (cur_dev->vendor_id == KFutabaVendorId) { FXString s; FXString usage_str; @@ -385,7 +417,7 @@ FXListItem *li = new FXListItem(s, NULL, cur_dev); device_list->appendItem(li); } - + cur_dev = cur_dev->next; } @@ -405,12 +437,12 @@ FXString data = tf->getText(); const FXchar *d = data.text(); size_t i = 0; - + // Copy the string from the GUI. size_t sz = strlen(d); char *str = (char*) malloc(sz+1); strcpy(str, d); - + // For each token in the string, parse and store in buf[]. char *token = strtok(str, delim); while (token) { @@ -419,7 +451,7 @@ buf[i++] = val; token = strtok(NULL, delim); } - + free(str); return i; } @@ -480,7 +512,7 @@ if (res < 0) { FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device)); } - + return 1; } @@ -507,7 +539,7 @@ len = (textfield_len)? textfield_len: data_len; - int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len); + int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len); if (res < 0) { FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device)); } @@ -549,7 +581,7 @@ input_text->appendText(s); input_text->setBottomLine(INT_MAX); } - + return 1; } @@ -613,7 +645,7 @@ iOutputReportBuffer[10]=0xFF; // int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength); - + return 1; } @@ -668,6 +700,17 @@ return 1; } +long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr) +{ + return 1; + +} + + +long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr) +{ + return 1; +} long @@ -675,7 +718,7 @@ { unsigned char buf[256]; int res = hid_read(connected_device, buf, sizeof(buf)); - + if (res > 0) { FXString s; s.format("Received %d bytes:\n", res); @@ -707,7 +750,7 @@ { #ifdef __APPLE__ check_apple_events(); - + getApp()->addTimeout(this, ID_MAC_TIMER, 50 * timeout_scalar /*50ms*/); #endif