test.cpp
changeset 6 7d41682fce1a
parent 5 4cb67272815c
child 7 e8c05ae7f418
     1.1 --- a/test.cpp	Tue May 20 22:31:46 2014 +0200
     1.2 +++ b/test.cpp	Wed May 21 08:54:35 2014 +0200
     1.3 @@ -14,126 +14,8 @@
     1.4   which use HIDAPI.
     1.5  ********************************************************/
     1.6  
     1.7 +#include "MainWindow.h"
     1.8  
     1.9 -#include <fx.h>
    1.10 -
    1.11 -#include "hidapi.h"
    1.12 -#include "mac_support.h"
    1.13 -#include <string.h>
    1.14 -#include <stdlib.h>
    1.15 -#include <limits.h>
    1.16 -
    1.17 -const int KFutabaOutputReportLength = 65;
    1.18 -
    1.19 -#ifdef _WIN32
    1.20 -	// Thanks Microsoft, but I know how to use strncpy().
    1.21 -	#pragma warning(disable:4996)
    1.22 -#endif
    1.23 -
    1.24 -class MainWindow : public FXMainWindow {
    1.25 -	FXDECLARE(MainWindow)
    1.26 -
    1.27 -public:
    1.28 -	enum {
    1.29 -		ID_FIRST = FXMainWindow::ID_LAST,
    1.30 -		ID_CONNECT,
    1.31 -		ID_DISCONNECT,
    1.32 -		ID_RESCAN,
    1.33 -		ID_SEND_OUTPUT_REPORT,
    1.34 -		ID_SEND_FEATURE_REPORT,
    1.35 -		ID_GET_FEATURE_REPORT,
    1.36 -		ID_CLEAR,
    1.37 -		ID_TIMER,
    1.38 -		ID_MAC_TIMER,
    1.39 -		ID_FUTABA_CLEAR_DISPLAY,
    1.40 -		ID_FUTABA_DIMMING,
    1.41 -		ID_FUTABA_DISPLAY_DATA_INPUT,
    1.42 -		ID_FUTABA_READ_ID,
    1.43 -		ID_FUTABA_READ_FIRMWARE_REVISION,
    1.44 -		ID_FUTABA_POWER_SUPPLY_MONITOR,
    1.45 -        ID_FUTABA_SET_PIXEL,
    1.46 -		ID_FUTABA_RESET_PIXEL,
    1.47 -        ID_FUTABA_SET_ALL_PIXELS,
    1.48 -		ID_LAST,
    1.49 -	};
    1.50 -
    1.51 -private:
    1.52 -	FXList *device_list;
    1.53 -	FXButton *connect_button;
    1.54 -	FXButton *disconnect_button;
    1.55 -	FXButton *rescan_button;
    1.56 -	FXButton *output_button;
    1.57 -	FXLabel *connected_label;
    1.58 -	FXTextField *output_text;
    1.59 -	FXTextField *output_len;
    1.60 -	FXButton *feature_button;
    1.61 -	FXButton *get_feature_button;
    1.62 -	FXTextField *feature_text;
    1.63 -	FXTextField *feature_len;
    1.64 -	FXTextField *get_feature_text;
    1.65 -	FXText *input_text;
    1.66 -	FXFont *title_font;
    1.67 -	//Futaba VFD control
    1.68 -	FXButton *iButtonClearDisplay;
    1.69 -	FXButton *iButtonDimming;
    1.70 -	FXButton *iButtonDisplayDataInput;
    1.71 -	FXButton *iButtonReadId;
    1.72 -	FXButton *iButtonReadFirmwareRevision;
    1.73 -	FXButton *iButtonPowerSupplyMonitor;
    1.74 -    FXTextField *iTextFieldX;
    1.75 -    FXTextField *iTextFieldY;
    1.76 -    FXButton *iButtonSetPixel;
    1.77 -	FXButton *iButtonResetPixel;
    1.78 -    FXButton *iButtonSetAllPixels;
    1.79 -
    1.80 -
    1.81 -	unsigned char* iOutputReportBuffer;
    1.82 -	unsigned char iDimming;
    1.83 -
    1.84 -	//FXTextField *iTextX;
    1.85 -	//FXTextField *iTextY;
    1.86 -
    1.87 -
    1.88 -
    1.89 -	struct hid_device_info *devices;
    1.90 -	hid_device *connected_device;
    1.91 -	size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len);
    1.92 -	int getLengthFromTextField(FXTextField *tf);
    1.93 -
    1.94 -
    1.95 -protected:
    1.96 -	MainWindow() {};
    1.97 -public:
    1.98 -	MainWindow(FXApp *a);
    1.99 -	~MainWindow();
   1.100 -	virtual void create();
   1.101 -
   1.102 -	long onConnect(FXObject *sender, FXSelector sel, void *ptr);
   1.103 -	long onDisconnect(FXObject *sender, FXSelector sel, void *ptr);
   1.104 -	long onRescan(FXObject *sender, FXSelector sel, void *ptr);
   1.105 -	long onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr);
   1.106 -	long onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr);
   1.107 -	long onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr);
   1.108 -	long onClear(FXObject *sender, FXSelector sel, void *ptr);
   1.109 -	//
   1.110 -	long onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr);
   1.111 -	long onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr);
   1.112 -	long onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr);
   1.113 -	long onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr);
   1.114 -	long onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr);
   1.115 -	long onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr);
   1.116 -    long onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr);
   1.117 -    long onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr);
   1.118 -	long onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr);
   1.119 -	//
   1.120 -	//
   1.121 -	long onTimeout(FXObject *sender, FXSelector sel, void *ptr);
   1.122 -	long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr);
   1.123 -	//
   1.124 -	void SetPixel(int aX, int aY, unsigned char aValue);
   1.125 -	void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue);
   1.126 -
   1.127 -};
   1.128  
   1.129  // FOX 1.7 changes the timeouts to all be nanoseconds.
   1.130  // Fox 1.6 had all timeouts as milliseconds.
   1.131 @@ -143,8 +25,6 @@
   1.132  	const int timeout_scalar = 1;
   1.133  #endif
   1.134  
   1.135 -FXMainWindow *g_main_window;
   1.136 -
   1.137  
   1.138  FXDEFMAP(MainWindow) MainWindowMap [] = {
   1.139  	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CONNECT, MainWindow::onConnect ),
   1.140 @@ -163,6 +43,7 @@
   1.141      FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ),
   1.142  	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_RESET_PIXEL, MainWindow::onFutabaResetPixel ),
   1.143      FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ),
   1.144 +    FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SELECT_FONT, MainWindow::onSelectFont ),
   1.145  	FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ),
   1.146  	FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ),
   1.147  };
   1.148 @@ -212,10 +93,16 @@
   1.149  
   1.150  	connected_label = new FXLabel(vf, "Disconnected");
   1.151  
   1.152 +    //Font group
   1.153 +    new FXHorizontalFrame(vf);
   1.154 +    FXGroupBox *gb = new FXGroupBox(vf, "Fonts", FRAME_GROOVE|LAYOUT_FILL_X);
   1.155 +    FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
   1.156 +    iButtonSelectFont = new FXButton(matrix, "Select Font", NULL, this, ID_SELECT_FONT, BUTTON_NORMAL|LAYOUT_FILL_X);
   1.157 +
   1.158  	//Futaba VFD commands
   1.159  	new FXHorizontalFrame(vf);
   1.160 -	FXGroupBox *gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X);
   1.161 -	FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
   1.162 +	gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X);
   1.163 +	matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
   1.164  	iButtonClearDisplay = new FXButton(matrix, "Clear Display", NULL, this, ID_FUTABA_CLEAR_DISPLAY, BUTTON_NORMAL|LAYOUT_FILL_X);
   1.165  	iButtonDimming = new FXButton(matrix, "Dimming", NULL, this, ID_FUTABA_DIMMING, BUTTON_NORMAL|LAYOUT_FILL_X);
   1.166  	iButtonDisplayDataInput = new FXButton(matrix, "Display Data Input", NULL, this, ID_FUTABA_DISPLAY_DATA_INPUT, BUTTON_NORMAL|LAYOUT_FILL_X);
   1.167 @@ -231,6 +118,8 @@
   1.168  	iButtonResetPixel = new FXButton(matrix, "Reset Pixel", NULL, this, ID_FUTABA_RESET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
   1.169      //
   1.170      iButtonSetAllPixels = new FXButton(matrix, "Set All Pixels", NULL, this, ID_FUTABA_SET_ALL_PIXELS, BUTTON_NORMAL|LAYOUT_FILL_X);
   1.171 +    //
   1.172 +
   1.173  	//
   1.174  	iButtonClearDisplay->disable();
   1.175  	iButtonDimming->disable();
   1.176 @@ -689,7 +578,7 @@
   1.177  	iOutputReportBuffer[4]=0xF0; //
   1.178  	iOutputReportBuffer[5]=aX; //X
   1.179  	iOutputReportBuffer[6]=aY; //Y
   1.180 -	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.181 +	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.182  	iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
   1.183  	iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
   1.184  	memset(iOutputReportBuffer+10, aValue, KFutabaOutputReportLength);
   1.185 @@ -845,12 +734,17 @@
   1.186  	return 1;
   1.187  }
   1.188  
   1.189 -int main(int argc, char **argv)
   1.190 +/**
   1.191 +
   1.192 +*/
   1.193 +long MainWindow::onSelectFont(FXObject *sender, FXSelector sel, void *ptr)
   1.194  {
   1.195 -	FXApp app("Futaba VFD", "Slions Software");
   1.196 -	app.init(argc, argv);
   1.197 -	g_main_window = new MainWindow(&app);
   1.198 -	app.create();
   1.199 -	app.run();
   1.200 -	return 0;
   1.201 +    FXFontDialog* dlg=new FXFontDialog(this,"Pick a font");
   1.202 +    dlg->execute();
   1.203 +    dlg->getFontSelection(iCurrentFontDesc);
   1.204 +    delete dlg;
   1.205 +    return 1;
   1.206  }
   1.207 +
   1.208 +
   1.209 +