Adding buttons to test basic functionality of Futaba VFD GP1212A01A.
authorsl
Mon, 19 May 2014 22:33:38 +0200
changeset 22dbfd75c2bbe
parent 1 5c2c48109457
child 3 d57fa1211bb0
Adding buttons to test basic functionality of Futaba VFD GP1212A01A.
test.cpp
     1.1 --- a/test.cpp	Mon May 19 21:11:52 2014 +0200
     1.2 +++ b/test.cpp	Mon May 19 22:33:38 2014 +0200
     1.3 @@ -23,6 +23,8 @@
     1.4  #include <stdlib.h>
     1.5  #include <limits.h>
     1.6  
     1.7 +const int KFutabaOutputReportLength = 65;
     1.8 +
     1.9  #ifdef _WIN32
    1.10  	// Thanks Microsoft, but I know how to use strncpy().
    1.11  	#pragma warning(disable:4996)
    1.12 @@ -43,6 +45,12 @@
    1.13  		ID_CLEAR,
    1.14  		ID_TIMER,
    1.15  		ID_MAC_TIMER,
    1.16 +		ID_FUTABA_CLEAR_DISPLAY,
    1.17 +		ID_FUTABA_DIMMING,
    1.18 +		ID_FUTABA_DISPLAY_DATA_INPUT,
    1.19 +		ID_FUTABA_READ_ID,
    1.20 +		ID_FUTABA_READ_FIRMWARE_REVISION,
    1.21 +		ID_FUTABA_POWER_SUPPLY_MONITOR,
    1.22  		ID_LAST,
    1.23  	};
    1.24  	
    1.25 @@ -62,6 +70,21 @@
    1.26  	FXTextField *get_feature_text;
    1.27  	FXText *input_text;
    1.28  	FXFont *title_font;
    1.29 +	//Futaba VFD control
    1.30 +	FXButton *iButtonClearDisplay;
    1.31 +	FXButton *iButtonDimming;
    1.32 +	FXButton *iButtonDisplayDataInput;
    1.33 +	FXButton *iButtonReadId;
    1.34 +	FXButton *iButtonReadFirmwareRevision;
    1.35 +	FXButton *iButtonPowerSupplyMonitor;
    1.36 +
    1.37 +	unsigned char* iOutputReportBuffer;
    1.38 +	unsigned char iDimming;
    1.39 +
    1.40 +	//FXTextField *iTextX;
    1.41 +	//FXTextField *iTextY;
    1.42 +
    1.43 +
    1.44  	
    1.45  	struct hid_device_info *devices;
    1.46  	hid_device *connected_device;
    1.47 @@ -83,6 +106,15 @@
    1.48  	long onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr);
    1.49  	long onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr);
    1.50  	long onClear(FXObject *sender, FXSelector sel, void *ptr);
    1.51 +	//
    1.52 +	long onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr);
    1.53 +	long onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr);
    1.54 +	long onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr);
    1.55 +	long onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr);
    1.56 +	long onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr);
    1.57 +	long onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr);
    1.58 +	//
    1.59 +
    1.60  	long onTimeout(FXObject *sender, FXSelector sel, void *ptr);
    1.61  	long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr);
    1.62  };
    1.63 @@ -106,6 +138,12 @@
    1.64  	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_FEATURE_REPORT, MainWindow::onSendFeatureReport ),
    1.65  	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_GET_FEATURE_REPORT, MainWindow::onGetFeatureReport ),
    1.66  	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CLEAR, MainWindow::onClear ),
    1.67 +	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_CLEAR_DISPLAY, MainWindow::onFutabaClearDisplay ),
    1.68 +	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DIMMING, MainWindow::onFutabaDimming ),
    1.69 +	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DISPLAY_DATA_INPUT, MainWindow::onFutabaDisplayDataInput ),
    1.70 +	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_ID, MainWindow::onFutabaReadId ),
    1.71 +	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ),
    1.72 +	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ),
    1.73  	FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ),
    1.74  	FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ),
    1.75  };
    1.76 @@ -115,6 +153,7 @@
    1.77  MainWindow::MainWindow(FXApp *app)
    1.78  	: FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 425,700)
    1.79  {
    1.80 +	iDimming=0x35;
    1.81  	devices = NULL;
    1.82  	connected_device = NULL;
    1.83  
    1.84 @@ -154,11 +193,29 @@
    1.85  
    1.86  	connected_label = new FXLabel(vf, "Disconnected");
    1.87  	
    1.88 +	//Futaba VFD commands
    1.89  	new FXHorizontalFrame(vf);
    1.90 -	
    1.91 +	FXGroupBox *gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X);
    1.92 +	FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
    1.93 +	iButtonClearDisplay = new FXButton(matrix, "Clear Display", NULL, this, ID_FUTABA_CLEAR_DISPLAY, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.94 +	iButtonDimming = new FXButton(matrix, "Dimming", NULL, this, ID_FUTABA_DIMMING, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.95 +	iButtonDisplayDataInput = new FXButton(matrix, "Display Data Input", NULL, this, ID_FUTABA_DISPLAY_DATA_INPUT, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.96 +	iButtonReadId = new FXButton(matrix, "Read Id", NULL, this, ID_FUTABA_READ_ID, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.97 +	iButtonReadFirmwareRevision =  new FXButton(matrix, "Read Firmware Revision", NULL, this, ID_FUTABA_READ_FIRMWARE_REVISION, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.98 +	iButtonPowerSupplyMonitor = new FXButton(matrix, "Power Supply Monitor", NULL, this, ID_FUTABA_POWER_SUPPLY_MONITOR, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.99 +	//
   1.100 +	iButtonClearDisplay->disable();
   1.101 +	iButtonDimming->disable();
   1.102 +	iButtonDisplayDataInput->disable();
   1.103 +	iButtonReadId->disable();
   1.104 +	iButtonReadFirmwareRevision->disable();
   1.105 +	iButtonPowerSupplyMonitor->disable();
   1.106 +	//
   1.107 +
   1.108  	// Output Group Box
   1.109 -	FXGroupBox *gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X);
   1.110 -	FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
   1.111 +	new FXHorizontalFrame(vf);		
   1.112 +	gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X);
   1.113 +	matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
   1.114  	new FXLabel(matrix, "Data");
   1.115  	new FXLabel(matrix, "Length");
   1.116  	new FXLabel(matrix, "");
   1.117 @@ -257,7 +314,15 @@
   1.118  	connect_button->disable();
   1.119  	disconnect_button->enable();
   1.120  	input_text->setText("");
   1.121 -
   1.122 +	//
   1.123 +	iButtonClearDisplay->enable();
   1.124 +	iButtonDimming->enable();
   1.125 +	iButtonDisplayDataInput->enable();
   1.126 +	iButtonReadId->enable();
   1.127 +	iButtonReadFirmwareRevision->enable();
   1.128 +	iButtonPowerSupplyMonitor->enable();
   1.129 +	//
   1.130 +	iOutputReportBuffer=new unsigned char[KFutabaOutputReportLength]; //TODO: use connected_device->output_report_length
   1.131  
   1.132  	return 1;
   1.133  }
   1.134 @@ -275,6 +340,19 @@
   1.135  	disconnect_button->disable();
   1.136  
   1.137  	getApp()->removeTimeout(this, ID_TIMER);
   1.138 +
   1.139 +	//
   1.140 +	iButtonClearDisplay->disable();
   1.141 +	iButtonDimming->disable();
   1.142 +	iButtonDisplayDataInput->disable();
   1.143 +	iButtonReadId->disable();
   1.144 +	iButtonReadFirmwareRevision->disable();
   1.145 +	iButtonPowerSupplyMonitor->disable();
   1.146 +	//
   1.147 +
   1.148 +
   1.149 +	delete iOutputReportBuffer;
   1.150 +	iOutputReportBuffer=NULL;
   1.151  	
   1.152  	return 1;
   1.153  }
   1.154 @@ -286,21 +364,27 @@
   1.155  
   1.156  	device_list->clearItems();
   1.157  	
   1.158 +	//Define Futaba vendor ID to filter our list of device
   1.159 +	const unsigned short KFutabaVendorId = 0x1008;
   1.160 +
   1.161  	// List the Devices
   1.162  	hid_free_enumeration(devices);
   1.163  	devices = hid_enumerate(0x0, 0x0);
   1.164  	cur_dev = devices;	
   1.165  	while (cur_dev) {
   1.166 -		// Add it to the List Box.
   1.167 -		FXString s;
   1.168 -		FXString usage_str;
   1.169 -		s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id);
   1.170 -		s += FXString(" ") + cur_dev->manufacturer_string;
   1.171 -		s += FXString(" ") + cur_dev->product_string;
   1.172 -		usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage);
   1.173 -		s += usage_str;
   1.174 -		FXListItem *li = new FXListItem(s, NULL, cur_dev);
   1.175 -		device_list->appendItem(li);
   1.176 +		// Add it to the List Box only if it is a Futaba device
   1.177 +		if (cur_dev->vendor_id == KFutabaVendorId) 
   1.178 +			{
   1.179 +			FXString s;
   1.180 +			FXString usage_str;
   1.181 +			s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id);
   1.182 +			s += FXString(" ") + cur_dev->manufacturer_string;
   1.183 +			s += FXString(" ") + cur_dev->product_string;
   1.184 +			usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage);
   1.185 +			s += usage_str;
   1.186 +			FXListItem *li = new FXListItem(s, NULL, cur_dev);
   1.187 +			device_list->appendItem(li);
   1.188 +			}
   1.189  		
   1.190  		cur_dev = cur_dev->next;
   1.191  	}
   1.192 @@ -476,6 +560,116 @@
   1.193  	return 1;
   1.194  }
   1.195  
   1.196 +
   1.197 +long
   1.198 +MainWindow::onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr)
   1.199 +{
   1.200 +	memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
   1.201 +	iOutputReportBuffer[0]=0x00; //Report ID
   1.202 +	iOutputReportBuffer[1]=0x04; //Report length
   1.203 +	iOutputReportBuffer[2]=0x1B; //
   1.204 +	iOutputReportBuffer[3]=0x5B; //
   1.205 +	iOutputReportBuffer[4]=0x32; //
   1.206 +	iOutputReportBuffer[5]=0x4A; //
   1.207 +	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
   1.208 +
   1.209 +	return 1;
   1.210 +}
   1.211 +
   1.212 +long
   1.213 +MainWindow::onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr)
   1.214 +{
   1.215 +	memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
   1.216 +	iOutputReportBuffer[0]=0x00; //Report ID
   1.217 +	iOutputReportBuffer[1]=0x06; //Report length
   1.218 +	iOutputReportBuffer[2]=0x1B; //
   1.219 +	iOutputReportBuffer[3]=0x5C; //
   1.220 +	iOutputReportBuffer[4]=0x3F; //
   1.221 +	iOutputReportBuffer[5]=0x4C; //
   1.222 +	iOutputReportBuffer[6]=0x44; //
   1.223 +	iDimming = (iDimming==0x35?0x30:++iDimming);
   1.224 +	iOutputReportBuffer[7]=iDimming;
   1.225 +	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
   1.226 +
   1.227 +	return 1;
   1.228 +}
   1.229 +
   1.230 +long
   1.231 +MainWindow::onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr)
   1.232 +{
   1.233 +	//@1B 5B F0 00 00 07 00 01 FF
   1.234 +
   1.235 +	memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
   1.236 +	iOutputReportBuffer[0]=0x00; //Report ID
   1.237 +	iOutputReportBuffer[1]=0x09; //Report length
   1.238 +	iOutputReportBuffer[2]=0x1B; //
   1.239 +	iOutputReportBuffer[3]=0x5B; //
   1.240 +	iOutputReportBuffer[4]=0xF0; //
   1.241 +	iOutputReportBuffer[5]=0x00; //
   1.242 +	iOutputReportBuffer[6]=0x00; //
   1.243 +	iOutputReportBuffer[7]=0x07; //
   1.244 +	iOutputReportBuffer[8]=0x00; //
   1.245 +	iOutputReportBuffer[9]=0x01; //
   1.246 +	iOutputReportBuffer[10]=0xFF; //
   1.247 +	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
   1.248 +
   1.249 +	
   1.250 +	return 1;
   1.251 +}
   1.252 +
   1.253 +long
   1.254 +MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr)
   1.255 +{
   1.256 +	//1BH,5BH,63H,49H,44H
   1.257 +	memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
   1.258 +	iOutputReportBuffer[0]=0x00; //Report ID
   1.259 +	iOutputReportBuffer[1]=0x05; //Report length
   1.260 +	iOutputReportBuffer[2]=0x1B; //
   1.261 +	iOutputReportBuffer[3]=0x5B; //
   1.262 +	iOutputReportBuffer[4]=0x63; //
   1.263 +	iOutputReportBuffer[5]=0x49; //
   1.264 +	iOutputReportBuffer[6]=0x44; //
   1.265 +	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
   1.266 +
   1.267 +	return 1;
   1.268 +}
   1.269 +
   1.270 +long
   1.271 +MainWindow::onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr)
   1.272 +{
   1.273 +	//1BH,5BH,63H,46H,52H
   1.274 +	memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
   1.275 +	iOutputReportBuffer[0]=0x00; //Report ID
   1.276 +	iOutputReportBuffer[1]=0x05; //Report length
   1.277 +	iOutputReportBuffer[2]=0x1B; //
   1.278 +	iOutputReportBuffer[3]=0x5B; //
   1.279 +	iOutputReportBuffer[4]=0x63; //
   1.280 +	iOutputReportBuffer[5]=0x46; //
   1.281 +	iOutputReportBuffer[6]=0x52; //
   1.282 +	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
   1.283 +
   1.284 +	return 1;
   1.285 +}
   1.286 +
   1.287 +long
   1.288 +MainWindow::onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr)
   1.289 +{
   1.290 +	//1BH,5BH,63H,50H,4DH
   1.291 +	memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
   1.292 +	iOutputReportBuffer[0]=0x00; //Report ID
   1.293 +	iOutputReportBuffer[1]=0x05; //Report length
   1.294 +	iOutputReportBuffer[2]=0x1B; //
   1.295 +	iOutputReportBuffer[3]=0x5B; //
   1.296 +	iOutputReportBuffer[4]=0x63; //
   1.297 +	iOutputReportBuffer[5]=0x50; //
   1.298 +	iOutputReportBuffer[6]=0x4D; //
   1.299 +	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
   1.300 +
   1.301 +	return 1;
   1.302 +}
   1.303 +
   1.304 +
   1.305 +
   1.306  long
   1.307  MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr)
   1.308  {
   1.309 @@ -523,7 +717,7 @@
   1.310  
   1.311  int main(int argc, char **argv)
   1.312  {
   1.313 -	FXApp app("HIDAPI Test Application", "Signal 11 Software");
   1.314 +	FXApp app("Futaba VFD", "Slions Software");
   1.315  	app.init(argc, argv);
   1.316  	g_main_window = new MainWindow(&app);
   1.317  	app.create();