Adding font selection dialog. Did a bit of cleaning too.
1.1 --- a/FutabaVfd.vcxproj Tue May 20 22:31:46 2014 +0200
1.2 +++ b/FutabaVfd.vcxproj Wed May 21 08:54:35 2014 +0200
1.3 @@ -104,10 +104,12 @@
1.4 </ItemDefinitionGroup>
1.5 <ItemGroup>
1.6 <ClCompile Include="..\hidapi\windows\hid.c" />
1.7 + <ClCompile Include="Main.cpp" />
1.8 <ClCompile Include="test.cpp" />
1.9 </ItemGroup>
1.10 <ItemGroup>
1.11 <ClInclude Include="..\hidapi\hidapi.h" />
1.12 + <ClInclude Include="MainWindow.h" />
1.13 </ItemGroup>
1.14 <ItemGroup>
1.15 <Text Include="ReadMe.txt" />
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/Main.cpp Wed May 21 08:54:35 2014 +0200
2.3 @@ -0,0 +1,15 @@
2.4 +
2.5 +
2.6 +#include "MainWindow.h"
2.7 +
2.8 +FXMainWindow *g_main_window;
2.9 +
2.10 +int main(int argc, char **argv)
2.11 +{
2.12 + FXApp app("Futaba VFD", "Slions Software");
2.13 + app.init(argc, argv);
2.14 + g_main_window = new MainWindow(&app);
2.15 + app.create();
2.16 + app.run();
2.17 + return 0;
2.18 +}
2.19 \ No newline at end of file
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/MainWindow.h Wed May 21 08:54:35 2014 +0200
3.3 @@ -0,0 +1,125 @@
3.4 +
3.5 +
3.6 +#ifndef MAIN_WINDOW_H
3.7 +#define MAIN_WINDOW_H
3.8 +
3.9 +#include <fx.h>
3.10 +#include "hidapi.h"
3.11 +#include "mac_support.h"
3.12 +#include <string.h>
3.13 +#include <stdlib.h>
3.14 +#include <limits.h>
3.15 +
3.16 +
3.17 +//TODO: Get ride of that constant once we figure out a way to get it from hidapi
3.18 +const int KFutabaOutputReportLength = 65;
3.19 +
3.20 +#ifdef _WIN32
3.21 +// Thanks Microsoft, but I know how to use strncpy().
3.22 +#pragma warning(disable:4996)
3.23 +#endif
3.24 +
3.25 +class MainWindow : public FXMainWindow {
3.26 + FXDECLARE(MainWindow)
3.27 +
3.28 +public:
3.29 + enum {
3.30 + ID_FIRST = FXMainWindow::ID_LAST,
3.31 + ID_CONNECT,
3.32 + ID_DISCONNECT,
3.33 + ID_RESCAN,
3.34 + ID_SEND_OUTPUT_REPORT,
3.35 + ID_SEND_FEATURE_REPORT,
3.36 + ID_GET_FEATURE_REPORT,
3.37 + ID_CLEAR,
3.38 + ID_TIMER,
3.39 + ID_MAC_TIMER,
3.40 + ID_FUTABA_CLEAR_DISPLAY,
3.41 + ID_FUTABA_DIMMING,
3.42 + ID_FUTABA_DISPLAY_DATA_INPUT,
3.43 + ID_FUTABA_READ_ID,
3.44 + ID_FUTABA_READ_FIRMWARE_REVISION,
3.45 + ID_FUTABA_POWER_SUPPLY_MONITOR,
3.46 + ID_FUTABA_SET_PIXEL,
3.47 + ID_FUTABA_RESET_PIXEL,
3.48 + ID_FUTABA_SET_ALL_PIXELS,
3.49 + ID_SELECT_FONT,
3.50 + ID_LAST
3.51 + };
3.52 +
3.53 + size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len);
3.54 + int getLengthFromTextField(FXTextField *tf);
3.55 +
3.56 +protected:
3.57 + MainWindow() {};
3.58 +public:
3.59 + MainWindow(FXApp *a);
3.60 + ~MainWindow();
3.61 + virtual void create();
3.62 +
3.63 + long onConnect(FXObject *sender, FXSelector sel, void *ptr);
3.64 + long onDisconnect(FXObject *sender, FXSelector sel, void *ptr);
3.65 + long onRescan(FXObject *sender, FXSelector sel, void *ptr);
3.66 + long onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr);
3.67 + long onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr);
3.68 + long onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr);
3.69 + long onClear(FXObject *sender, FXSelector sel, void *ptr);
3.70 + //
3.71 + long onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr);
3.72 + long onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr);
3.73 + long onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr);
3.74 + long onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr);
3.75 + long onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr);
3.76 + long onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr);
3.77 + long onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr);
3.78 + long onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr);
3.79 + long onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr);
3.80 + //
3.81 + long onSelectFont(FXObject *sender, FXSelector sel, void *ptr);
3.82 + //
3.83 + long onTimeout(FXObject *sender, FXSelector sel, void *ptr);
3.84 + long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr);
3.85 + //
3.86 + void SetPixel(int aX, int aY, unsigned char aValue);
3.87 + void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue);
3.88 +
3.89 +private:
3.90 + FXList *device_list;
3.91 + FXButton *connect_button;
3.92 + FXButton *disconnect_button;
3.93 + FXButton *rescan_button;
3.94 + FXButton *output_button;
3.95 + FXLabel *connected_label;
3.96 + FXTextField *output_text;
3.97 + FXTextField *output_len;
3.98 + FXButton *feature_button;
3.99 + FXButton *get_feature_button;
3.100 + FXTextField *feature_text;
3.101 + FXTextField *feature_len;
3.102 + FXTextField *get_feature_text;
3.103 + FXText *input_text;
3.104 + FXFont *title_font;
3.105 + //Futaba VFD control
3.106 + FXButton *iButtonClearDisplay;
3.107 + FXButton *iButtonDimming;
3.108 + FXButton *iButtonDisplayDataInput;
3.109 + FXButton *iButtonReadId;
3.110 + FXButton *iButtonReadFirmwareRevision;
3.111 + FXButton *iButtonPowerSupplyMonitor;
3.112 + FXTextField *iTextFieldX;
3.113 + FXTextField *iTextFieldY;
3.114 + FXButton *iButtonSetPixel;
3.115 + FXButton *iButtonResetPixel;
3.116 + FXButton *iButtonSetAllPixels;
3.117 + //Font
3.118 + FXButton *iButtonSelectFont;
3.119 +
3.120 + unsigned char* iOutputReportBuffer;
3.121 + unsigned char iDimming; //Current VFD dimming
3.122 + FXFontDesc iCurrentFontDesc;
3.123 +
3.124 + struct hid_device_info *devices;
3.125 + hid_device *connected_device;
3.126 +};
3.127 +
3.128 +#endif //
3.129 \ No newline at end of file
4.1 --- a/test.cpp Tue May 20 22:31:46 2014 +0200
4.2 +++ b/test.cpp Wed May 21 08:54:35 2014 +0200
4.3 @@ -14,126 +14,8 @@
4.4 which use HIDAPI.
4.5 ********************************************************/
4.6
4.7 +#include "MainWindow.h"
4.8
4.9 -#include <fx.h>
4.10 -
4.11 -#include "hidapi.h"
4.12 -#include "mac_support.h"
4.13 -#include <string.h>
4.14 -#include <stdlib.h>
4.15 -#include <limits.h>
4.16 -
4.17 -const int KFutabaOutputReportLength = 65;
4.18 -
4.19 -#ifdef _WIN32
4.20 - // Thanks Microsoft, but I know how to use strncpy().
4.21 - #pragma warning(disable:4996)
4.22 -#endif
4.23 -
4.24 -class MainWindow : public FXMainWindow {
4.25 - FXDECLARE(MainWindow)
4.26 -
4.27 -public:
4.28 - enum {
4.29 - ID_FIRST = FXMainWindow::ID_LAST,
4.30 - ID_CONNECT,
4.31 - ID_DISCONNECT,
4.32 - ID_RESCAN,
4.33 - ID_SEND_OUTPUT_REPORT,
4.34 - ID_SEND_FEATURE_REPORT,
4.35 - ID_GET_FEATURE_REPORT,
4.36 - ID_CLEAR,
4.37 - ID_TIMER,
4.38 - ID_MAC_TIMER,
4.39 - ID_FUTABA_CLEAR_DISPLAY,
4.40 - ID_FUTABA_DIMMING,
4.41 - ID_FUTABA_DISPLAY_DATA_INPUT,
4.42 - ID_FUTABA_READ_ID,
4.43 - ID_FUTABA_READ_FIRMWARE_REVISION,
4.44 - ID_FUTABA_POWER_SUPPLY_MONITOR,
4.45 - ID_FUTABA_SET_PIXEL,
4.46 - ID_FUTABA_RESET_PIXEL,
4.47 - ID_FUTABA_SET_ALL_PIXELS,
4.48 - ID_LAST,
4.49 - };
4.50 -
4.51 -private:
4.52 - FXList *device_list;
4.53 - FXButton *connect_button;
4.54 - FXButton *disconnect_button;
4.55 - FXButton *rescan_button;
4.56 - FXButton *output_button;
4.57 - FXLabel *connected_label;
4.58 - FXTextField *output_text;
4.59 - FXTextField *output_len;
4.60 - FXButton *feature_button;
4.61 - FXButton *get_feature_button;
4.62 - FXTextField *feature_text;
4.63 - FXTextField *feature_len;
4.64 - FXTextField *get_feature_text;
4.65 - FXText *input_text;
4.66 - FXFont *title_font;
4.67 - //Futaba VFD control
4.68 - FXButton *iButtonClearDisplay;
4.69 - FXButton *iButtonDimming;
4.70 - FXButton *iButtonDisplayDataInput;
4.71 - FXButton *iButtonReadId;
4.72 - FXButton *iButtonReadFirmwareRevision;
4.73 - FXButton *iButtonPowerSupplyMonitor;
4.74 - FXTextField *iTextFieldX;
4.75 - FXTextField *iTextFieldY;
4.76 - FXButton *iButtonSetPixel;
4.77 - FXButton *iButtonResetPixel;
4.78 - FXButton *iButtonSetAllPixels;
4.79 -
4.80 -
4.81 - unsigned char* iOutputReportBuffer;
4.82 - unsigned char iDimming;
4.83 -
4.84 - //FXTextField *iTextX;
4.85 - //FXTextField *iTextY;
4.86 -
4.87 -
4.88 -
4.89 - struct hid_device_info *devices;
4.90 - hid_device *connected_device;
4.91 - size_t getDataFromTextField(FXTextField *tf, char *buf, size_t len);
4.92 - int getLengthFromTextField(FXTextField *tf);
4.93 -
4.94 -
4.95 -protected:
4.96 - MainWindow() {};
4.97 -public:
4.98 - MainWindow(FXApp *a);
4.99 - ~MainWindow();
4.100 - virtual void create();
4.101 -
4.102 - long onConnect(FXObject *sender, FXSelector sel, void *ptr);
4.103 - long onDisconnect(FXObject *sender, FXSelector sel, void *ptr);
4.104 - long onRescan(FXObject *sender, FXSelector sel, void *ptr);
4.105 - long onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr);
4.106 - long onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr);
4.107 - long onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr);
4.108 - long onClear(FXObject *sender, FXSelector sel, void *ptr);
4.109 - //
4.110 - long onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr);
4.111 - long onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr);
4.112 - long onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr);
4.113 - long onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr);
4.114 - long onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr);
4.115 - long onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr);
4.116 - long onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr);
4.117 - long onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr);
4.118 - long onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr);
4.119 - //
4.120 - //
4.121 - long onTimeout(FXObject *sender, FXSelector sel, void *ptr);
4.122 - long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr);
4.123 - //
4.124 - void SetPixel(int aX, int aY, unsigned char aValue);
4.125 - void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue);
4.126 -
4.127 -};
4.128
4.129 // FOX 1.7 changes the timeouts to all be nanoseconds.
4.130 // Fox 1.6 had all timeouts as milliseconds.
4.131 @@ -143,8 +25,6 @@
4.132 const int timeout_scalar = 1;
4.133 #endif
4.134
4.135 -FXMainWindow *g_main_window;
4.136 -
4.137
4.138 FXDEFMAP(MainWindow) MainWindowMap [] = {
4.139 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CONNECT, MainWindow::onConnect ),
4.140 @@ -163,6 +43,7 @@
4.141 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ),
4.142 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_RESET_PIXEL, MainWindow::onFutabaResetPixel ),
4.143 FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ),
4.144 + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SELECT_FONT, MainWindow::onSelectFont ),
4.145 FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ),
4.146 FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ),
4.147 };
4.148 @@ -212,10 +93,16 @@
4.149
4.150 connected_label = new FXLabel(vf, "Disconnected");
4.151
4.152 + //Font group
4.153 + new FXHorizontalFrame(vf);
4.154 + FXGroupBox *gb = new FXGroupBox(vf, "Fonts", FRAME_GROOVE|LAYOUT_FILL_X);
4.155 + FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
4.156 + iButtonSelectFont = new FXButton(matrix, "Select Font", NULL, this, ID_SELECT_FONT, BUTTON_NORMAL|LAYOUT_FILL_X);
4.157 +
4.158 //Futaba VFD commands
4.159 new FXHorizontalFrame(vf);
4.160 - FXGroupBox *gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X);
4.161 - FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
4.162 + gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X);
4.163 + matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
4.164 iButtonClearDisplay = new FXButton(matrix, "Clear Display", NULL, this, ID_FUTABA_CLEAR_DISPLAY, BUTTON_NORMAL|LAYOUT_FILL_X);
4.165 iButtonDimming = new FXButton(matrix, "Dimming", NULL, this, ID_FUTABA_DIMMING, BUTTON_NORMAL|LAYOUT_FILL_X);
4.166 iButtonDisplayDataInput = new FXButton(matrix, "Display Data Input", NULL, this, ID_FUTABA_DISPLAY_DATA_INPUT, BUTTON_NORMAL|LAYOUT_FILL_X);
4.167 @@ -231,6 +118,8 @@
4.168 iButtonResetPixel = new FXButton(matrix, "Reset Pixel", NULL, this, ID_FUTABA_RESET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
4.169 //
4.170 iButtonSetAllPixels = new FXButton(matrix, "Set All Pixels", NULL, this, ID_FUTABA_SET_ALL_PIXELS, BUTTON_NORMAL|LAYOUT_FILL_X);
4.171 + //
4.172 +
4.173 //
4.174 iButtonClearDisplay->disable();
4.175 iButtonDimming->disable();
4.176 @@ -689,7 +578,7 @@
4.177 iOutputReportBuffer[4]=0xF0; //
4.178 iOutputReportBuffer[5]=aX; //X
4.179 iOutputReportBuffer[6]=aY; //Y
4.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.
4.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.
4.182 iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
4.183 iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
4.184 memset(iOutputReportBuffer+10, aValue, KFutabaOutputReportLength);
4.185 @@ -845,12 +734,17 @@
4.186 return 1;
4.187 }
4.188
4.189 -int main(int argc, char **argv)
4.190 +/**
4.191 +
4.192 +*/
4.193 +long MainWindow::onSelectFont(FXObject *sender, FXSelector sel, void *ptr)
4.194 {
4.195 - FXApp app("Futaba VFD", "Slions Software");
4.196 - app.init(argc, argv);
4.197 - g_main_window = new MainWindow(&app);
4.198 - app.create();
4.199 - app.run();
4.200 - return 0;
4.201 + FXFontDialog* dlg=new FXFontDialog(this,"Pick a font");
4.202 + dlg->execute();
4.203 + dlg->getFontSelection(iCurrentFontDesc);
4.204 + delete dlg;
4.205 + return 1;
4.206 }
4.207 +
4.208 +
4.209 +