# HG changeset patch # User sl # Date 1400655275 -7200 # Node ID 7d41682fce1aec70b31c27872c3a67b15dd904d6 # Parent 4cb67272815c87045a696081440a88ef00ca96b8 Adding font selection dialog. Did a bit of cleaning too. diff -r 4cb67272815c -r 7d41682fce1a FutabaVfd.vcxproj --- a/FutabaVfd.vcxproj Tue May 20 22:31:46 2014 +0200 +++ b/FutabaVfd.vcxproj Wed May 21 08:54:35 2014 +0200 @@ -104,10 +104,12 @@ + + diff -r 4cb67272815c -r 7d41682fce1a Main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Main.cpp Wed May 21 08:54:35 2014 +0200 @@ -0,0 +1,15 @@ + + +#include "MainWindow.h" + +FXMainWindow *g_main_window; + +int main(int argc, char **argv) +{ + FXApp app("Futaba VFD", "Slions Software"); + app.init(argc, argv); + g_main_window = new MainWindow(&app); + app.create(); + app.run(); + return 0; +} \ No newline at end of file diff -r 4cb67272815c -r 7d41682fce1a MainWindow.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MainWindow.h Wed May 21 08:54:35 2014 +0200 @@ -0,0 +1,125 @@ + + +#ifndef MAIN_WINDOW_H +#define MAIN_WINDOW_H + +#include +#include "hidapi.h" +#include "mac_support.h" +#include +#include +#include + + +//TODO: Get ride of that constant once we figure out a way to get it from hidapi +const int KFutabaOutputReportLength = 65; + +#ifdef _WIN32 +// Thanks Microsoft, but I know how to use strncpy(). +#pragma warning(disable:4996) +#endif + +class MainWindow : public FXMainWindow { + FXDECLARE(MainWindow) + +public: + enum { + ID_FIRST = FXMainWindow::ID_LAST, + ID_CONNECT, + ID_DISCONNECT, + ID_RESCAN, + ID_SEND_OUTPUT_REPORT, + ID_SEND_FEATURE_REPORT, + ID_GET_FEATURE_REPORT, + ID_CLEAR, + ID_TIMER, + ID_MAC_TIMER, + ID_FUTABA_CLEAR_DISPLAY, + ID_FUTABA_DIMMING, + ID_FUTABA_DISPLAY_DATA_INPUT, + ID_FUTABA_READ_ID, + ID_FUTABA_READ_FIRMWARE_REVISION, + ID_FUTABA_POWER_SUPPLY_MONITOR, + ID_FUTABA_SET_PIXEL, + ID_FUTABA_RESET_PIXEL, + ID_FUTABA_SET_ALL_PIXELS, + ID_SELECT_FONT, + ID_LAST + }; + + size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len); + int getLengthFromTextField(FXTextField *tf); + +protected: + MainWindow() {}; +public: + 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); + long onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr); + long onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr); + long onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr); + long onClear(FXObject *sender, FXSelector sel, void *ptr); + // + long onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr); + long onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr); + long onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr); + 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 onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr); + // + long onSelectFont(FXObject *sender, FXSelector sel, void *ptr); + // + long onTimeout(FXObject *sender, FXSelector sel, void *ptr); + long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr); + // + void SetPixel(int aX, int aY, unsigned char aValue); + void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue); + +private: + FXList *device_list; + FXButton *connect_button; + FXButton *disconnect_button; + FXButton *rescan_button; + FXButton *output_button; + FXLabel *connected_label; + FXTextField *output_text; + FXTextField *output_len; + FXButton *feature_button; + FXButton *get_feature_button; + FXTextField *feature_text; + FXTextField *feature_len; + FXTextField *get_feature_text; + FXText *input_text; + FXFont *title_font; + //Futaba VFD control + FXButton *iButtonClearDisplay; + FXButton *iButtonDimming; + FXButton *iButtonDisplayDataInput; + FXButton *iButtonReadId; + FXButton *iButtonReadFirmwareRevision; + FXButton *iButtonPowerSupplyMonitor; + FXTextField *iTextFieldX; + FXTextField *iTextFieldY; + FXButton *iButtonSetPixel; + FXButton *iButtonResetPixel; + FXButton *iButtonSetAllPixels; + //Font + FXButton *iButtonSelectFont; + + unsigned char* iOutputReportBuffer; + unsigned char iDimming; //Current VFD dimming + FXFontDesc iCurrentFontDesc; + + struct hid_device_info *devices; + hid_device *connected_device; +}; + +#endif // \ No newline at end of file diff -r 4cb67272815c -r 7d41682fce1a test.cpp --- a/test.cpp Tue May 20 22:31:46 2014 +0200 +++ b/test.cpp Wed May 21 08:54:35 2014 +0200 @@ -14,126 +14,8 @@ which use HIDAPI. ********************************************************/ +#include "MainWindow.h" -#include - -#include "hidapi.h" -#include "mac_support.h" -#include -#include -#include - -const int KFutabaOutputReportLength = 65; - -#ifdef _WIN32 - // Thanks Microsoft, but I know how to use strncpy(). - #pragma warning(disable:4996) -#endif - -class MainWindow : public FXMainWindow { - FXDECLARE(MainWindow) - -public: - enum { - ID_FIRST = FXMainWindow::ID_LAST, - ID_CONNECT, - ID_DISCONNECT, - ID_RESCAN, - ID_SEND_OUTPUT_REPORT, - ID_SEND_FEATURE_REPORT, - ID_GET_FEATURE_REPORT, - ID_CLEAR, - ID_TIMER, - ID_MAC_TIMER, - ID_FUTABA_CLEAR_DISPLAY, - ID_FUTABA_DIMMING, - ID_FUTABA_DISPLAY_DATA_INPUT, - ID_FUTABA_READ_ID, - ID_FUTABA_READ_FIRMWARE_REVISION, - ID_FUTABA_POWER_SUPPLY_MONITOR, - ID_FUTABA_SET_PIXEL, - ID_FUTABA_RESET_PIXEL, - ID_FUTABA_SET_ALL_PIXELS, - ID_LAST, - }; - -private: - FXList *device_list; - FXButton *connect_button; - FXButton *disconnect_button; - FXButton *rescan_button; - FXButton *output_button; - FXLabel *connected_label; - FXTextField *output_text; - FXTextField *output_len; - FXButton *feature_button; - FXButton *get_feature_button; - FXTextField *feature_text; - FXTextField *feature_len; - FXTextField *get_feature_text; - FXText *input_text; - FXFont *title_font; - //Futaba VFD control - FXButton *iButtonClearDisplay; - FXButton *iButtonDimming; - FXButton *iButtonDisplayDataInput; - FXButton *iButtonReadId; - FXButton *iButtonReadFirmwareRevision; - FXButton *iButtonPowerSupplyMonitor; - FXTextField *iTextFieldX; - FXTextField *iTextFieldY; - FXButton *iButtonSetPixel; - FXButton *iButtonResetPixel; - FXButton *iButtonSetAllPixels; - - - unsigned char* iOutputReportBuffer; - unsigned char iDimming; - - //FXTextField *iTextX; - //FXTextField *iTextY; - - - - struct hid_device_info *devices; - hid_device *connected_device; - size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len); - int getLengthFromTextField(FXTextField *tf); - - -protected: - MainWindow() {}; -public: - 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); - long onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr); - long onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr); - long onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr); - long onClear(FXObject *sender, FXSelector sel, void *ptr); - // - long onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr); - long onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr); - long onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr); - 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 onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr); - // - // - long onTimeout(FXObject *sender, FXSelector sel, void *ptr); - long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr); - // - void SetPixel(int aX, int aY, unsigned char aValue); - void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue); - -}; // FOX 1.7 changes the timeouts to all be nanoseconds. // Fox 1.6 had all timeouts as milliseconds. @@ -143,8 +25,6 @@ const int timeout_scalar = 1; #endif -FXMainWindow *g_main_window; - FXDEFMAP(MainWindow) MainWindowMap [] = { FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CONNECT, MainWindow::onConnect ), @@ -163,6 +43,7 @@ FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ), FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_RESET_PIXEL, MainWindow::onFutabaResetPixel ), FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SELECT_FONT, MainWindow::onSelectFont ), FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ), FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ), }; @@ -212,10 +93,16 @@ connected_label = new FXLabel(vf, "Disconnected"); + //Font group + new FXHorizontalFrame(vf); + FXGroupBox *gb = new FXGroupBox(vf, "Fonts", FRAME_GROOVE|LAYOUT_FILL_X); + FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X); + iButtonSelectFont = new FXButton(matrix, "Select Font", NULL, this, ID_SELECT_FONT, BUTTON_NORMAL|LAYOUT_FILL_X); + //Futaba VFD commands new FXHorizontalFrame(vf); - FXGroupBox *gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X); - FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X); + gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X); + matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X); iButtonClearDisplay = new FXButton(matrix, "Clear Display", NULL, this, ID_FUTABA_CLEAR_DISPLAY, BUTTON_NORMAL|LAYOUT_FILL_X); iButtonDimming = new FXButton(matrix, "Dimming", NULL, this, ID_FUTABA_DIMMING, BUTTON_NORMAL|LAYOUT_FILL_X); iButtonDisplayDataInput = new FXButton(matrix, "Display Data Input", NULL, this, ID_FUTABA_DISPLAY_DATA_INPUT, BUTTON_NORMAL|LAYOUT_FILL_X); @@ -231,6 +118,8 @@ iButtonResetPixel = new FXButton(matrix, "Reset Pixel", NULL, this, ID_FUTABA_RESET_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(); @@ -689,7 +578,7 @@ iOutputReportBuffer[4]=0xF0; // iOutputReportBuffer[5]=aX; //X iOutputReportBuffer[6]=aY; //Y - 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. + 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. iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB) iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB) memset(iOutputReportBuffer+10, aValue, KFutabaOutputReportLength); @@ -845,12 +734,17 @@ return 1; } -int main(int argc, char **argv) +/** + +*/ +long MainWindow::onSelectFont(FXObject *sender, FXSelector sel, void *ptr) { - FXApp app("Futaba VFD", "Slions Software"); - app.init(argc, argv); - g_main_window = new MainWindow(&app); - app.create(); - app.run(); - return 0; + FXFontDialog* dlg=new FXFontDialog(this,"Pick a font"); + dlg->execute(); + dlg->getFontSelection(iCurrentFontDesc); + delete dlg; + return 1; } + + +