Add buttons and text field to set pixels.
1.1 --- a/test.cpp Mon May 19 22:33:38 2014 +0200
1.2 +++ b/test.cpp Tue May 20 17:04:50 2014 +0200
1.3 @@ -1,13 +1,13 @@
1.4 /*******************************************************
1.5 Demo Program for HIDAPI
1.6 -
1.7 +
1.8 Alan Ott
1.9 Signal 11 Software
1.10
1.11 2010-07-20
1.12
1.13 Copyright 2010, All Rights Reserved
1.14 -
1.15 +
1.16 This contents of this file may be used by anyone
1.17 for any reason without any conditions and may be
1.18 used as a starting point for your own applications
1.19 @@ -32,7 +32,7 @@
1.20
1.21 class MainWindow : public FXMainWindow {
1.22 FXDECLARE(MainWindow)
1.23 -
1.24 +
1.25 public:
1.26 enum {
1.27 ID_FIRST = FXMainWindow::ID_LAST,
1.28 @@ -51,9 +51,11 @@
1.29 ID_FUTABA_READ_ID,
1.30 ID_FUTABA_READ_FIRMWARE_REVISION,
1.31 ID_FUTABA_POWER_SUPPLY_MONITOR,
1.32 + ID_FUTABA_SET_PIXEL,
1.33 + ID_FUTABA_SET_ALL_PIXELS,
1.34 ID_LAST,
1.35 };
1.36 -
1.37 +
1.38 private:
1.39 FXList *device_list;
1.40 FXButton *connect_button;
1.41 @@ -77,6 +79,11 @@
1.42 FXButton *iButtonReadId;
1.43 FXButton *iButtonReadFirmwareRevision;
1.44 FXButton *iButtonPowerSupplyMonitor;
1.45 + FXTextField *iTextFieldX;
1.46 + FXTextField *iTextFieldY;
1.47 + FXButton *iButtonSetPixel;
1.48 + FXButton *iButtonSetAllPixels;
1.49 +
1.50
1.51 unsigned char* iOutputReportBuffer;
1.52 unsigned char iDimming;
1.53 @@ -85,7 +92,7 @@
1.54 //FXTextField *iTextY;
1.55
1.56
1.57 -
1.58 +
1.59 struct hid_device_info *devices;
1.60 hid_device *connected_device;
1.61 size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len);
1.62 @@ -98,7 +105,7 @@
1.63 MainWindow(FXApp *a);
1.64 ~MainWindow();
1.65 virtual void create();
1.66 -
1.67 +
1.68 long onConnect(FXObject *sender, FXSelector sel, void *ptr);
1.69 long onDisconnect(FXObject *sender, FXSelector sel, void *ptr);
1.70 long onRescan(FXObject *sender, FXSelector sel, void *ptr);
1.71 @@ -113,6 +120,8 @@
1.72 long onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr);
1.73 long onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr);
1.74 long onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr);
1.75 + long onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr);
1.76 + long onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr);
1.77 //
1.78
1.79 long onTimeout(FXObject *sender, FXSelector sel, void *ptr);
1.80 @@ -144,6 +153,8 @@
1.81 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_ID, MainWindow::onFutabaReadId ),
1.82 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ),
1.83 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ),
1.84 + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ),
1.85 + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ),
1.86 FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ),
1.87 FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ),
1.88 };
1.89 @@ -151,7 +162,7 @@
1.90 FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap));
1.91
1.92 MainWindow::MainWindow(FXApp *app)
1.93 - : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 425,700)
1.94 + : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900)
1.95 {
1.96 iDimming=0x35;
1.97 devices = NULL;
1.98 @@ -162,7 +173,7 @@
1.99 FXLabel *label = new FXLabel(vf, "HIDAPI Test Tool");
1.100 title_font = new FXFont(getApp(), "Arial", 14, FXFont::Bold);
1.101 label->setFont(title_font);
1.102 -
1.103 +
1.104 new FXLabel(vf,
1.105 "Select a device and press Connect.", NULL, JUSTIFY_LEFT);
1.106 new FXLabel(vf,
1.107 @@ -192,7 +203,7 @@
1.108 new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0);
1.109
1.110 connected_label = new FXLabel(vf, "Disconnected");
1.111 -
1.112 +
1.113 //Futaba VFD commands
1.114 new FXHorizontalFrame(vf);
1.115 FXGroupBox *gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X);
1.116 @@ -203,6 +214,14 @@
1.117 iButtonReadId = new FXButton(matrix, "Read Id", NULL, this, ID_FUTABA_READ_ID, BUTTON_NORMAL|LAYOUT_FILL_X);
1.118 iButtonReadFirmwareRevision = new FXButton(matrix, "Read Firmware Revision", NULL, this, ID_FUTABA_READ_FIRMWARE_REVISION, BUTTON_NORMAL|LAYOUT_FILL_X);
1.119 iButtonPowerSupplyMonitor = new FXButton(matrix, "Power Supply Monitor", NULL, this, ID_FUTABA_POWER_SUPPLY_MONITOR, BUTTON_NORMAL|LAYOUT_FILL_X);
1.120 + new FXLabel(matrix, "X",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
1.121 + new FXLabel(matrix, "Y",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
1.122 + new FXLabel(matrix, "",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
1.123 + iTextFieldX = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
1.124 + iTextFieldY = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
1.125 + iButtonSetPixel = new FXButton(matrix, "SetPixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
1.126 + //
1.127 + iButtonSetAllPixels = new FXButton(matrix, "Set All Pixels", NULL, this, ID_FUTABA_SET_ALL_PIXELS, BUTTON_NORMAL|LAYOUT_FILL_X);
1.128 //
1.129 iButtonClearDisplay->disable();
1.130 iButtonDimming->disable();
1.131 @@ -210,10 +229,14 @@
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 + iButtonSetAllPixels->disable();
1.139 //
1.140
1.141 // Output Group Box
1.142 - new FXHorizontalFrame(vf);
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 @@ -246,7 +269,7 @@
1.148 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.149 input_text->setEditable(false);
1.150 new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT);
1.151 -
1.152 +
1.153
1.154 }
1.155
1.156 @@ -265,12 +288,12 @@
1.157 show();
1.158
1.159 onRescan(NULL, 0, NULL);
1.160 -
1.161 +
1.162
1.163 #ifdef __APPLE__
1.164 init_apple_message_system();
1.165 #endif
1.166 -
1.167 +
1.168 getApp()->addTimeout(this, ID_MAC_TIMER,
1.169 50 * timeout_scalar /*50ms*/);
1.170 }
1.171 @@ -280,7 +303,7 @@
1.172 {
1.173 if (connected_device != NULL)
1.174 return 1;
1.175 -
1.176 +
1.177 FXint cur_item = device_list->getCurrentItem();
1.178 if (cur_item < 0)
1.179 return -1;
1.180 @@ -290,19 +313,19 @@
1.181 struct hid_device_info *device_info = (struct hid_device_info*) item->getData();
1.182 if (!device_info)
1.183 return -1;
1.184 -
1.185 +
1.186 connected_device = hid_open_path(device_info->path);
1.187 -
1.188 +
1.189 if (!connected_device) {
1.190 FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device");
1.191 return -1;
1.192 }
1.193 -
1.194 +
1.195 hid_set_nonblocking(connected_device, 1);
1.196
1.197 getApp()->addTimeout(this, ID_TIMER,
1.198 5 * timeout_scalar /*5ms*/);
1.199 -
1.200 +
1.201 FXString s;
1.202 s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id);
1.203 s += FXString(" ") + device_info->manufacturer_string;
1.204 @@ -321,6 +344,11 @@
1.205 iButtonReadId->enable();
1.206 iButtonReadFirmwareRevision->enable();
1.207 iButtonPowerSupplyMonitor->enable();
1.208 + iTextFieldX->enable();
1.209 + iTextFieldY->enable();
1.210 + iButtonSetPixel->enable();
1.211 + iButtonSetAllPixels->enable();
1.212 +
1.213 //
1.214 iOutputReportBuffer=new unsigned char[KFutabaOutputReportLength]; //TODO: use connected_device->output_report_length
1.215
1.216 @@ -348,12 +376,16 @@
1.217 iButtonReadId->disable();
1.218 iButtonReadFirmwareRevision->disable();
1.219 iButtonPowerSupplyMonitor->disable();
1.220 + iTextFieldX->disable();
1.221 + iTextFieldY->disable();
1.222 + iButtonSetPixel->disable();
1.223 + iButtonSetAllPixels->disable();
1.224 //
1.225
1.226
1.227 delete iOutputReportBuffer;
1.228 iOutputReportBuffer=NULL;
1.229 -
1.230 +
1.231 return 1;
1.232 }
1.233
1.234 @@ -363,17 +395,17 @@
1.235 struct hid_device_info *cur_dev;
1.236
1.237 device_list->clearItems();
1.238 -
1.239 +
1.240 //Define Futaba vendor ID to filter our list of device
1.241 const unsigned short KFutabaVendorId = 0x1008;
1.242
1.243 // List the Devices
1.244 hid_free_enumeration(devices);
1.245 devices = hid_enumerate(0x0, 0x0);
1.246 - cur_dev = devices;
1.247 + cur_dev = devices;
1.248 while (cur_dev) {
1.249 // Add it to the List Box only if it is a Futaba device
1.250 - if (cur_dev->vendor_id == KFutabaVendorId)
1.251 + if (cur_dev->vendor_id == KFutabaVendorId)
1.252 {
1.253 FXString s;
1.254 FXString usage_str;
1.255 @@ -385,7 +417,7 @@
1.256 FXListItem *li = new FXListItem(s, NULL, cur_dev);
1.257 device_list->appendItem(li);
1.258 }
1.259 -
1.260 +
1.261 cur_dev = cur_dev->next;
1.262 }
1.263
1.264 @@ -405,12 +437,12 @@
1.265 FXString data = tf->getText();
1.266 const FXchar *d = data.text();
1.267 size_t i = 0;
1.268 -
1.269 +
1.270 // Copy the string from the GUI.
1.271 size_t sz = strlen(d);
1.272 char *str = (char*) malloc(sz+1);
1.273 strcpy(str, d);
1.274 -
1.275 +
1.276 // For each token in the string, parse and store in buf[].
1.277 char *token = strtok(str, delim);
1.278 while (token) {
1.279 @@ -419,7 +451,7 @@
1.280 buf[i++] = val;
1.281 token = strtok(NULL, delim);
1.282 }
1.283 -
1.284 +
1.285 free(str);
1.286 return i;
1.287 }
1.288 @@ -480,7 +512,7 @@
1.289 if (res < 0) {
1.290 FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device));
1.291 }
1.292 -
1.293 +
1.294 return 1;
1.295 }
1.296
1.297 @@ -507,7 +539,7 @@
1.298
1.299 len = (textfield_len)? textfield_len: data_len;
1.300
1.301 - int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len);
1.302 + int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len);
1.303 if (res < 0) {
1.304 FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device));
1.305 }
1.306 @@ -549,7 +581,7 @@
1.307 input_text->appendText(s);
1.308 input_text->setBottomLine(INT_MAX);
1.309 }
1.310 -
1.311 +
1.312 return 1;
1.313 }
1.314
1.315 @@ -613,7 +645,7 @@
1.316 iOutputReportBuffer[10]=0xFF; //
1.317 int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
1.318
1.319 -
1.320 +
1.321 return 1;
1.322 }
1.323
1.324 @@ -668,6 +700,17 @@
1.325 return 1;
1.326 }
1.327
1.328 +long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr)
1.329 +{
1.330 + return 1;
1.331 +
1.332 +}
1.333 +
1.334 +
1.335 +long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr)
1.336 +{
1.337 + return 1;
1.338 +}
1.339
1.340
1.341 long
1.342 @@ -675,7 +718,7 @@
1.343 {
1.344 unsigned char buf[256];
1.345 int res = hid_read(connected_device, buf, sizeof(buf));
1.346 -
1.347 +
1.348 if (res > 0) {
1.349 FXString s;
1.350 s.format("Received %d bytes:\n", res);
1.351 @@ -707,7 +750,7 @@
1.352 {
1.353 #ifdef __APPLE__
1.354 check_apple_events();
1.355 -
1.356 +
1.357 getApp()->addTimeout(this, ID_MAC_TIMER,
1.358 50 * timeout_scalar /*50ms*/);
1.359 #endif