# HG changeset patch # User sl # Date 1400735815 -7200 # Node ID 7268128148b8b2967cac7aeca2ae3b392c9010c2 # Parent 11a0e8a2346e19ec65c477ce2f1369e930e635b0 Files reorganisation. diff -r 11a0e8a2346e -r 7268128148b8 FutabaVfd.cpp --- a/FutabaVfd.cpp Wed May 21 22:55:14 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,227 +0,0 @@ - -#include "FutabaVfd.h" -//#include -#include - - -// -// -// - - - - - -// -// -// - -FutabaVfdCommand::FutabaVfdCommand():/*iBuffer(NULL),*/iSize(0),iMaxSize(0) - { - } - -FutabaVfdCommand::~FutabaVfdCommand() - { - //Delete(); - } - - -/** - -*/ -void FutabaVfdCommand::Reset() - { - memset(iReports,0,sizeof(iReports)); - } - - - -/** - -*/ -/* -void FutabaVfdCommand::Create(int aMaxSize) - { - iBuffer=new unsigned char[aMaxSize]; - if (iBuffer) - { - iMaxSize = aMaxSize; - iSize = 0; - } - } -*/ - -/** - -*/ -/* -void FutabaVfdCommand::Delete() -{ - delete[] iBuffer; - iBuffer = NULL; - iMaxSize = 0; - iSize = 0; -} -*/ - - -// -// class HidDevice -// - -/** -*/ -int HidDevice::Open(const char* aPath) - { - Close(); - - iHidDevice = hid_open_path(aPath); - - if (!iHidDevice) - { - //Fail to connect our device - return 0; - } - - return 1; - } - -/** -See hidapi documentation. -*/ -int HidDevice::Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber) - { - iHidDevice = hid_open(aVendorId, aProductId, aSerialNumber); - - if (!iHidDevice) - { - //Fail to connect our device - return 0; - } - - return 1; - } - -/** -*/ -void HidDevice::Close() - { - hid_close(iHidDevice); - iHidDevice=NULL; - } - - -/** -*/ -const wchar_t* HidDevice::Error() - { - return hid_error(iHidDevice); - } - -/** -*/ -int HidDevice::SetNonBlocking(int aNonBlocking) - { - //Success we are now connected to our HID device - //Set read operation as non blocking - return hid_set_nonblocking(iHidDevice, aNonBlocking); - } - - -// -// class GP1212A01A -// - -int GP1212A01A::Open() - { - int success = HidDevice::Open(KFutabaVendorId,KFutabaProductIdGP1212A01A,NULL); - if (success) - { - SetNonBlocking(1); - } - return success; - } - -/** -*/ -void GP1212A01A::SetPixel(int aX, int aY, bool aOn) - { - //Just specify a one pixel block - SetPixelBlock(aX,aY,0x00,0x01,aOn); - } - -/** -*/ -void GP1212A01A::SetAllPixels(bool aOn) - { - //One pixel at a time - /* - for (int i=0;i<256;i++) - { - for (int j=0;j<64;j++) - { - SetPixel(i,j,0x01); - } - } - */ - - //16x16=256 pixels at a time goes much faster - //TODO: use even larger blocks - for (int i=0;i<256;i+=16) - { - for (int j=0;j<64;j+=16) - { - SetPixelBlock(i,j,15,32,(aOn?0xFF:0x00)); - //FXThread::sleep(1000000000); - } - } - - } - -/** -*/ -void GP1212A01A::SetBrightness(int aBrightness) - { - } - -/** -Set the defined pixel block to the given value. -@param X coordinate of our pixel block starting point. -@param Y coordinate of our pixel block starting point. -@param The height of our pixel block. -@param The size of our pixel data. Number of pixels divided by 8. -@param The value set to 8 pixels. -*/ -void GP1212A01A::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue) - { - //Size must be 63 or below - FutabaVfdReport report; - report[0]=0x00; //Report ID - report[1]=0x08+aSize; //Report length - report[2]=0x1B; // - report[3]=0x5B; // - report[4]=0xF0; // - report[5]=aX; //X - report[6]=aY; //Y - report[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. - report[8]=0x00; //Size of pixel data in bytes (MSB) - report[9]=aSize; //Size of pixel data in bytes (LSB) - memset(report.Buffer()+10, aValue, aSize); - //iOutputReportBuffer[10]=aValue; //Pixel data - Write(report); - } - - -/** -*/ -void GP1212A01A::Clear() - { - FutabaVfdReport report; - report[0]=0x00; //Report ID - report[1]=0x04; //Report length - report[2]=0x1B; // - report[3]=0x5B; // - report[4]=0x32; // - report[5]=0x4A; // - Write(report); - } \ No newline at end of file diff -r 11a0e8a2346e -r 7268128148b8 FutabaVfd.h --- a/FutabaVfd.h Wed May 21 22:55:14 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,177 +0,0 @@ - - -#ifndef FUTABA_VFD_H -#define FUTABA_VFD_H - -#include "hidapi.h" - -//This was computed from our number of pixels as follow 256x64/8/64 = 32 + 1 = 33 -//+1 was added for our header -const int KFutabaMaxCommandOutputReport = 33; -//TODO: Get ride of that constant once we figure out a way to get it from hidapi -const int KFutabaMaxHidReportSize = 65; - -const int KHidReportIdIndex=0; -const int KFutabaHidReportSizeIndex=1; -//Define Futaba vendor ID to filter our list of device -const unsigned short KFutabaVendorId = 0x1008; -const unsigned short KFutabaProductIdGP1212A01A = 0x100C; -const unsigned short KFutabaProductIdGP1212A02A = 0x1013; //Or is it 0x1015 - - -//typedef struct hid_device_info HidDeviceInfo; - -/** -TODO: move to another header -*/ -template -class HidReport - { -public: - HidReport(){Reset();}; - void Reset(); - inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];} - const unsigned char* Buffer() const {return iBuffer;}; - unsigned char* Buffer() {return iBuffer;}; -protected: - unsigned char iBuffer[S]; - }; - -template -void HidReport::Reset() - { - memset(iBuffer,0,sizeof(iBuffer)); - } - -/** -TODO: move to another header -*/ -class HidDevice - { -public: - int Open(const char* aPath); - int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber); - void Close(); - // - int SetNonBlocking(int aNonBlocking); - // - template - int Write(const HidReport& aOutputReport); - // - const wchar_t* Error(); - - - -private: - ///Our USB HID device - hid_device* iHidDevice; - }; - - -/** -*/ -template -int HidDevice::Write(const HidReport& aOutputReport) - { - return hid_write(iHidDevice,aOutputReport.Buffer(),S); - } - - -/** -*/ -class FutabaVfdReport: public HidReport - { - -private: - - }; - - - -/** -Define a generic Futaba VFD command. -*/ -class FutabaVfdCommand - { -public: - FutabaVfdCommand(); - ~FutabaVfdCommand(); - // - //void Create(int aMaxSize); - //void Delete(); - - //inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];} - - void Reset(); - -private: - //unsigned char* iBuffer; - FutabaVfdReport iReports[KFutabaMaxCommandOutputReport]; - int iSize; - int iMaxSize; - }; - -/** -*/ -class FutabaVfd : public HidDevice - { -public: - virtual int MinBrightness()=0; - virtual int MaxBrightness()=0; - virtual void SetBrightness(int aBrightness)=0; - virtual void Clear()=0; - }; - - -/** -*/ -class FutabaGraphicVfd : public FutabaVfd - { -public: - virtual int WidthInPixels()=0; - virtual int HeightInPixels()=0; - virtual void SetPixel(int aX, int aY, bool aOn)=0; - virtual void SetAllPixels(bool aOn)=0; - - }; - -/** -Common functionality between GP1212A01A and GP1212A02A -*/ -class GP1212XXXX : public FutabaGraphicVfd - { -public: - //From FutabaVfd - virtual int MinBrightness(){return 0;}; - virtual int MaxBrightness(){return 5;}; - }; - -/** -GP1212A01A is a graphic display module using a FUTABA 256x64dots VFD. -The module do not include character ROM, the customer will compile the character -by themselves (from main system). -*/ -class GP1212A01A : public GP1212XXXX - { -public: - int Open(); - //From FutabaGraphicVfd - virtual int WidthInPixels(){return 256;}; - virtual int HeightInPixels(){return 64;}; - virtual void SetPixel(int aX, int aY, bool aOn); - virtual void SetAllPixels(bool aOn); - //From FutabaVfd - virtual void SetBrightness(int aBrightness); - virtual void Clear(); - // - void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue); - -private: - /// - //FutabaVfdReport iReport; - /// - unsigned char iPixelBuffer[256][128]; - }; - - -#endif \ No newline at end of file diff -r 11a0e8a2346e -r 7268128148b8 FutabaVfd.vcxproj --- a/FutabaVfd.vcxproj Wed May 21 22:55:14 2014 +0200 +++ b/FutabaVfd.vcxproj Thu May 22 07:16:55 2014 +0200 @@ -53,7 +53,7 @@ Disabled - ..\hidapi-externals\fox\include;..\hidapi\hidapi;%(AdditionalIncludeDirectories) + .\inc;..\hidapi-externals\fox\include;..\hidapi\hidapi;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true EnableFastChecks @@ -104,16 +104,14 @@ - - - + + + - - - - - + + + diff -r 11a0e8a2346e -r 7268128148b8 Main.cpp --- a/Main.cpp Wed May 21 22:55:14 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ - - -#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 11a0e8a2346e -r 7268128148b8 MainWindow.h --- a/MainWindow.h Wed May 21 22:55:14 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ - - -#ifndef MAIN_WINDOW_H -#define MAIN_WINDOW_H - -#include -#include "hidapi.h" -#include "mac_support.h" -#include -#include -#include -#include "FutabaVfd.h" - -#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; - FXFont* iCurrentFont; - FXTGAImage* iFontImage; - - struct hid_device_info *devices; - hid_device *connected_device; - - //Futaba - GP1212A01A iVfd01; - -}; - -#endif // \ No newline at end of file diff -r 11a0e8a2346e -r 7268128148b8 inc/FutabaVfd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inc/FutabaVfd.h Thu May 22 07:16:55 2014 +0200 @@ -0,0 +1,177 @@ + + +#ifndef FUTABA_VFD_H +#define FUTABA_VFD_H + +#include "hidapi.h" + +//This was computed from our number of pixels as follow 256x64/8/64 = 32 + 1 = 33 +//+1 was added for our header +const int KFutabaMaxCommandOutputReport = 33; +//TODO: Get ride of that constant once we figure out a way to get it from hidapi +const int KFutabaMaxHidReportSize = 65; + +const int KHidReportIdIndex=0; +const int KFutabaHidReportSizeIndex=1; +//Define Futaba vendor ID to filter our list of device +const unsigned short KFutabaVendorId = 0x1008; +const unsigned short KFutabaProductIdGP1212A01A = 0x100C; +const unsigned short KFutabaProductIdGP1212A02A = 0x1013; //Or is it 0x1015 + + +//typedef struct hid_device_info HidDeviceInfo; + +/** +TODO: move to another header +*/ +template +class HidReport + { +public: + HidReport(){Reset();}; + void Reset(); + inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];} + const unsigned char* Buffer() const {return iBuffer;}; + unsigned char* Buffer() {return iBuffer;}; +protected: + unsigned char iBuffer[S]; + }; + +template +void HidReport::Reset() + { + memset(iBuffer,0,sizeof(iBuffer)); + } + +/** +TODO: move to another header +*/ +class HidDevice + { +public: + int Open(const char* aPath); + int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber); + void Close(); + // + int SetNonBlocking(int aNonBlocking); + // + template + int Write(const HidReport& aOutputReport); + // + const wchar_t* Error(); + + + +private: + ///Our USB HID device + hid_device* iHidDevice; + }; + + +/** +*/ +template +int HidDevice::Write(const HidReport& aOutputReport) + { + return hid_write(iHidDevice,aOutputReport.Buffer(),S); + } + + +/** +*/ +class FutabaVfdReport: public HidReport + { + +private: + + }; + + + +/** +Define a generic Futaba VFD command. +*/ +class FutabaVfdCommand + { +public: + FutabaVfdCommand(); + ~FutabaVfdCommand(); + // + //void Create(int aMaxSize); + //void Delete(); + + //inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];} + + void Reset(); + +private: + //unsigned char* iBuffer; + FutabaVfdReport iReports[KFutabaMaxCommandOutputReport]; + int iSize; + int iMaxSize; + }; + +/** +*/ +class FutabaVfd : public HidDevice + { +public: + virtual int MinBrightness()=0; + virtual int MaxBrightness()=0; + virtual void SetBrightness(int aBrightness)=0; + virtual void Clear()=0; + }; + + +/** +*/ +class FutabaGraphicVfd : public FutabaVfd + { +public: + virtual int WidthInPixels()=0; + virtual int HeightInPixels()=0; + virtual void SetPixel(int aX, int aY, bool aOn)=0; + virtual void SetAllPixels(bool aOn)=0; + + }; + +/** +Common functionality between GP1212A01A and GP1212A02A +*/ +class GP1212XXXX : public FutabaGraphicVfd + { +public: + //From FutabaVfd + virtual int MinBrightness(){return 0;}; + virtual int MaxBrightness(){return 5;}; + }; + +/** +GP1212A01A is a graphic display module using a FUTABA 256x64dots VFD. +The module do not include character ROM, the customer will compile the character +by themselves (from main system). +*/ +class GP1212A01A : public GP1212XXXX + { +public: + int Open(); + //From FutabaGraphicVfd + virtual int WidthInPixels(){return 256;}; + virtual int HeightInPixels(){return 64;}; + virtual void SetPixel(int aX, int aY, bool aOn); + virtual void SetAllPixels(bool aOn); + //From FutabaVfd + virtual void SetBrightness(int aBrightness); + virtual void Clear(); + // + void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue); + +private: + /// + //FutabaVfdReport iReport; + /// + unsigned char iPixelBuffer[256][128]; + }; + + +#endif \ No newline at end of file diff -r 11a0e8a2346e -r 7268128148b8 inc/MainWindow.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inc/MainWindow.h Thu May 22 07:16:55 2014 +0200 @@ -0,0 +1,128 @@ + + +#ifndef MAIN_WINDOW_H +#define MAIN_WINDOW_H + +#include +#include "hidapi.h" +#include "mac_support.h" +#include +#include +#include +#include "FutabaVfd.h" + +#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; + FXFont* iCurrentFont; + FXTGAImage* iFontImage; + + struct hid_device_info *devices; + hid_device *connected_device; + + //Futaba + GP1212A01A iVfd01; + +}; + +#endif // \ No newline at end of file diff -r 11a0e8a2346e -r 7268128148b8 inc/mac_support.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inc/mac_support.h Thu May 22 07:16:55 2014 +0200 @@ -0,0 +1,17 @@ +/******************************* + Mac support for HID Test GUI + + Alan Ott + Signal 11 Software + +*******************************/ + +#ifndef MAC_SUPPORT_H__ +#define MAC_SUPPORT_H__ + +extern "C" { + void init_apple_message_system(); + void check_apple_events(); +} + +#endif diff -r 11a0e8a2346e -r 7268128148b8 mac_support.cpp --- a/mac_support.cpp Wed May 21 22:55:14 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -/******************************* - Mac support for HID Test GUI - - Alan Ott - Signal 11 Software - - Some of this code is from Apple Documentation, most notably - http://developer.apple.com/legacy/mac/library/documentation/AppleScript/Conceptual/AppleEvents/AppleEvents.pdf -*******************************/ - -#include -#include - - -extern FXMainWindow *g_main_window; - -static pascal OSErr HandleQuitMessage(const AppleEvent *theAppleEvent, AppleEvent - *reply, long handlerRefcon) -{ - puts("Quitting\n"); - FXApp::instance()->exit(); - return 0; -} - -static pascal OSErr HandleReopenMessage(const AppleEvent *theAppleEvent, AppleEvent - *reply, long handlerRefcon) -{ - puts("Showing"); - g_main_window->show(); - return 0; -} - -static pascal OSErr HandleWildCardMessage(const AppleEvent *theAppleEvent, AppleEvent - *reply, long handlerRefcon) -{ - puts("WildCard\n"); - return 0; -} - -OSStatus AEHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon) -{ - Boolean release = false; - EventRecord eventRecord; - OSErr ignoreErrForThisSample; - - // Events of type kEventAppleEvent must be removed from the queue - // before being passed to AEProcessAppleEvent. - if (IsEventInQueue(GetMainEventQueue(), inEvent)) - { - // RemoveEventFromQueue will release the event, which will - // destroy it if we don't retain it first. - RetainEvent(inEvent); - release = true; - RemoveEventFromQueue(GetMainEventQueue(), inEvent); - } - // Convert the event ref to the type AEProcessAppleEvent expects. - ConvertEventRefToEventRecord(inEvent, &eventRecord); - ignoreErrForThisSample = AEProcessAppleEvent(&eventRecord); - if (release) - ReleaseEvent(inEvent); - // This Carbon event has been handled, even if no AppleEvent handlers - // were installed for the Apple event. - return noErr; -} - -static void HandleEvent(EventRecord *event) -{ - //printf("What: %d message %x\n", event->what, event->message); - if (event->what == osEvt) { - if (((event->message >> 24) & 0xff) == suspendResumeMessage) { - if (event->message & resumeFlag) { - g_main_window->show(); - } - } - } - -#if 0 - switch (event->what) - { - case mouseDown: - //HandleMouseDown(event); - break; - case keyDown: - case autoKey: - //HandleKeyPress(event); - break; - case kHighLevelEvent: - puts("Calling ProcessAppleEvent\n"); - AEProcessAppleEvent(event); - break; - } -#endif -} - -void -init_apple_message_system() -{ - OSErr err; - static const EventTypeSpec appleEvents[] = - { - { kEventClassAppleEvent, kEventAppleEvent } - }; - - /* Install the handler for Apple Events */ - InstallApplicationEventHandler(NewEventHandlerUPP(AEHandler), - GetEventTypeCount(appleEvents), appleEvents, 0, NULL); - - /* Install handlers for the individual Apple Events that come - from the Dock icon: the Reopen (click), and the Quit messages. */ - err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, - NewAEEventHandlerUPP(HandleQuitMessage), 0, false); - err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, - NewAEEventHandlerUPP(HandleReopenMessage), 0, false); -#if 0 - // Left as an example of a wild card match. - err = AEInstallEventHandler(kCoreEventClass, typeWildCard, - NewAEEventHandlerUPP(HandleWildMessage), 0, false); -#endif -} - -void -check_apple_events() -{ - RgnHandle cursorRgn = NULL; - Boolean gotEvent=TRUE; - EventRecord event; - - while (gotEvent) { - gotEvent = WaitNextEvent(everyEvent, &event, 0L/*timeout*/, cursorRgn); - if (gotEvent) { - HandleEvent(&event); - } - } -} diff -r 11a0e8a2346e -r 7268128148b8 mac_support.h --- a/mac_support.h Wed May 21 22:55:14 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -/******************************* - Mac support for HID Test GUI - - Alan Ott - Signal 11 Software - -*******************************/ - -#ifndef MAC_SUPPORT_H__ -#define MAC_SUPPORT_H__ - -extern "C" { - void init_apple_message_system(); - void check_apple_events(); -} - -#endif diff -r 11a0e8a2346e -r 7268128148b8 src/FutabaVfd.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/FutabaVfd.cpp Thu May 22 07:16:55 2014 +0200 @@ -0,0 +1,227 @@ + +#include "FutabaVfd.h" +//#include +#include + + +// +// +// + + + + + +// +// +// + +FutabaVfdCommand::FutabaVfdCommand():/*iBuffer(NULL),*/iSize(0),iMaxSize(0) + { + } + +FutabaVfdCommand::~FutabaVfdCommand() + { + //Delete(); + } + + +/** + +*/ +void FutabaVfdCommand::Reset() + { + memset(iReports,0,sizeof(iReports)); + } + + + +/** + +*/ +/* +void FutabaVfdCommand::Create(int aMaxSize) + { + iBuffer=new unsigned char[aMaxSize]; + if (iBuffer) + { + iMaxSize = aMaxSize; + iSize = 0; + } + } +*/ + +/** + +*/ +/* +void FutabaVfdCommand::Delete() +{ + delete[] iBuffer; + iBuffer = NULL; + iMaxSize = 0; + iSize = 0; +} +*/ + + +// +// class HidDevice +// + +/** +*/ +int HidDevice::Open(const char* aPath) + { + Close(); + + iHidDevice = hid_open_path(aPath); + + if (!iHidDevice) + { + //Fail to connect our device + return 0; + } + + return 1; + } + +/** +See hidapi documentation. +*/ +int HidDevice::Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber) + { + iHidDevice = hid_open(aVendorId, aProductId, aSerialNumber); + + if (!iHidDevice) + { + //Fail to connect our device + return 0; + } + + return 1; + } + +/** +*/ +void HidDevice::Close() + { + hid_close(iHidDevice); + iHidDevice=NULL; + } + + +/** +*/ +const wchar_t* HidDevice::Error() + { + return hid_error(iHidDevice); + } + +/** +*/ +int HidDevice::SetNonBlocking(int aNonBlocking) + { + //Success we are now connected to our HID device + //Set read operation as non blocking + return hid_set_nonblocking(iHidDevice, aNonBlocking); + } + + +// +// class GP1212A01A +// + +int GP1212A01A::Open() + { + int success = HidDevice::Open(KFutabaVendorId,KFutabaProductIdGP1212A01A,NULL); + if (success) + { + SetNonBlocking(1); + } + return success; + } + +/** +*/ +void GP1212A01A::SetPixel(int aX, int aY, bool aOn) + { + //Just specify a one pixel block + SetPixelBlock(aX,aY,0x00,0x01,aOn); + } + +/** +*/ +void GP1212A01A::SetAllPixels(bool aOn) + { + //One pixel at a time + /* + for (int i=0;i<256;i++) + { + for (int j=0;j<64;j++) + { + SetPixel(i,j,0x01); + } + } + */ + + //16x16=256 pixels at a time goes much faster + //TODO: use even larger blocks + for (int i=0;i<256;i+=16) + { + for (int j=0;j<64;j+=16) + { + SetPixelBlock(i,j,15,32,(aOn?0xFF:0x00)); + //FXThread::sleep(1000000000); + } + } + + } + +/** +*/ +void GP1212A01A::SetBrightness(int aBrightness) + { + } + +/** +Set the defined pixel block to the given value. +@param X coordinate of our pixel block starting point. +@param Y coordinate of our pixel block starting point. +@param The height of our pixel block. +@param The size of our pixel data. Number of pixels divided by 8. +@param The value set to 8 pixels. +*/ +void GP1212A01A::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue) + { + //Size must be 63 or below + FutabaVfdReport report; + report[0]=0x00; //Report ID + report[1]=0x08+aSize; //Report length + report[2]=0x1B; // + report[3]=0x5B; // + report[4]=0xF0; // + report[5]=aX; //X + report[6]=aY; //Y + report[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. + report[8]=0x00; //Size of pixel data in bytes (MSB) + report[9]=aSize; //Size of pixel data in bytes (LSB) + memset(report.Buffer()+10, aValue, aSize); + //iOutputReportBuffer[10]=aValue; //Pixel data + Write(report); + } + + +/** +*/ +void GP1212A01A::Clear() + { + FutabaVfdReport report; + report[0]=0x00; //Report ID + report[1]=0x04; //Report length + report[2]=0x1B; // + report[3]=0x5B; // + report[4]=0x32; // + report[5]=0x4A; // + Write(report); + } \ No newline at end of file diff -r 11a0e8a2346e -r 7268128148b8 src/Main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Main.cpp Thu May 22 07:16:55 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 11a0e8a2346e -r 7268128148b8 src/mac_support.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mac_support.cpp Thu May 22 07:16:55 2014 +0200 @@ -0,0 +1,134 @@ +/******************************* + Mac support for HID Test GUI + + Alan Ott + Signal 11 Software + + Some of this code is from Apple Documentation, most notably + http://developer.apple.com/legacy/mac/library/documentation/AppleScript/Conceptual/AppleEvents/AppleEvents.pdf +*******************************/ + +#include +#include + + +extern FXMainWindow *g_main_window; + +static pascal OSErr HandleQuitMessage(const AppleEvent *theAppleEvent, AppleEvent + *reply, long handlerRefcon) +{ + puts("Quitting\n"); + FXApp::instance()->exit(); + return 0; +} + +static pascal OSErr HandleReopenMessage(const AppleEvent *theAppleEvent, AppleEvent + *reply, long handlerRefcon) +{ + puts("Showing"); + g_main_window->show(); + return 0; +} + +static pascal OSErr HandleWildCardMessage(const AppleEvent *theAppleEvent, AppleEvent + *reply, long handlerRefcon) +{ + puts("WildCard\n"); + return 0; +} + +OSStatus AEHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon) +{ + Boolean release = false; + EventRecord eventRecord; + OSErr ignoreErrForThisSample; + + // Events of type kEventAppleEvent must be removed from the queue + // before being passed to AEProcessAppleEvent. + if (IsEventInQueue(GetMainEventQueue(), inEvent)) + { + // RemoveEventFromQueue will release the event, which will + // destroy it if we don't retain it first. + RetainEvent(inEvent); + release = true; + RemoveEventFromQueue(GetMainEventQueue(), inEvent); + } + // Convert the event ref to the type AEProcessAppleEvent expects. + ConvertEventRefToEventRecord(inEvent, &eventRecord); + ignoreErrForThisSample = AEProcessAppleEvent(&eventRecord); + if (release) + ReleaseEvent(inEvent); + // This Carbon event has been handled, even if no AppleEvent handlers + // were installed for the Apple event. + return noErr; +} + +static void HandleEvent(EventRecord *event) +{ + //printf("What: %d message %x\n", event->what, event->message); + if (event->what == osEvt) { + if (((event->message >> 24) & 0xff) == suspendResumeMessage) { + if (event->message & resumeFlag) { + g_main_window->show(); + } + } + } + +#if 0 + switch (event->what) + { + case mouseDown: + //HandleMouseDown(event); + break; + case keyDown: + case autoKey: + //HandleKeyPress(event); + break; + case kHighLevelEvent: + puts("Calling ProcessAppleEvent\n"); + AEProcessAppleEvent(event); + break; + } +#endif +} + +void +init_apple_message_system() +{ + OSErr err; + static const EventTypeSpec appleEvents[] = + { + { kEventClassAppleEvent, kEventAppleEvent } + }; + + /* Install the handler for Apple Events */ + InstallApplicationEventHandler(NewEventHandlerUPP(AEHandler), + GetEventTypeCount(appleEvents), appleEvents, 0, NULL); + + /* Install handlers for the individual Apple Events that come + from the Dock icon: the Reopen (click), and the Quit messages. */ + err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, + NewAEEventHandlerUPP(HandleQuitMessage), 0, false); + err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, + NewAEEventHandlerUPP(HandleReopenMessage), 0, false); +#if 0 + // Left as an example of a wild card match. + err = AEInstallEventHandler(kCoreEventClass, typeWildCard, + NewAEEventHandlerUPP(HandleWildMessage), 0, false); +#endif +} + +void +check_apple_events() +{ + RgnHandle cursorRgn = NULL; + Boolean gotEvent=TRUE; + EventRecord event; + + while (gotEvent) { + gotEvent = WaitNextEvent(everyEvent, &event, 0L/*timeout*/, cursorRgn); + if (gotEvent) { + HandleEvent(&event); + } + } +} diff -r 11a0e8a2346e -r 7268128148b8 src/test.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test.cpp Thu May 22 07:16:55 2014 +0200 @@ -0,0 +1,826 @@ +/******************************************************* + Demo Program for HIDAPI + + Alan Ott + Signal 11 Software + + 2010-07-20 + + Copyright 2010, All Rights Reserved + + This contents of this file may be used by anyone + for any reason without any conditions and may be + used as a starting point for your own applications + which use HIDAPI. +********************************************************/ + +#include "MainWindow.h" + + +// FOX 1.7 changes the timeouts to all be nanoseconds. +// Fox 1.6 had all timeouts as milliseconds. +#if (FOX_MINOR >= 7) + const int timeout_scalar = 1000*1000; +#else + const int timeout_scalar = 1; +#endif + + +FXDEFMAP(MainWindow) MainWindowMap [] = { + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CONNECT, MainWindow::onConnect ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_DISCONNECT, MainWindow::onDisconnect ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_RESCAN, MainWindow::onRescan ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_OUTPUT_REPORT, MainWindow::onSendOutputReport ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_FEATURE_REPORT, MainWindow::onSendFeatureReport ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_GET_FEATURE_REPORT, MainWindow::onGetFeatureReport ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CLEAR, MainWindow::onClear ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_CLEAR_DISPLAY, MainWindow::onFutabaClearDisplay ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DIMMING, MainWindow::onFutabaDimming ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DISPLAY_DATA_INPUT, MainWindow::onFutabaDisplayDataInput ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_ID, MainWindow::onFutabaReadId ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ), + 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 ), +}; + +FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap)); + +MainWindow::MainWindow(FXApp *app) + : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900), + iCurrentFont(NULL), + iFontImage(NULL) +{ + iDimming=0x35; + devices = NULL; + connected_device = NULL; + + FXVerticalFrame *vf = new FXVerticalFrame(this, LAYOUT_FILL_Y|LAYOUT_FILL_X); + + FXLabel *label = new FXLabel(vf, "HIDAPI Test Tool"); + title_font = new FXFont(getApp(), "Arial", 14, FXFont::Bold); + label->setFont(title_font); + + new FXLabel(vf, + "Select a device and press Connect.", NULL, JUSTIFY_LEFT); + new FXLabel(vf, + "Output data bytes can be entered in the Output section, \n" + "separated by space, comma or brackets. Data starting with 0x\n" + "is treated as hex. Data beginning with a 0 is treated as \n" + "octal. All other data is treated as decimal.", NULL, JUSTIFY_LEFT); + new FXLabel(vf, + "Data received from the device appears in the Input section.", + NULL, JUSTIFY_LEFT); + new FXLabel(vf, + "Optionally, a report length may be specified. Extra bytes are\n" + "padded with zeros. If no length is specified, the length is \n" + "inferred from the data.", + NULL, JUSTIFY_LEFT); + new FXLabel(vf, ""); + + // Device List and Connect/Disconnect buttons + FXHorizontalFrame *hf = new FXHorizontalFrame(vf, LAYOUT_FILL_X); + //device_list = new FXList(new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK, 0,0,0,0, 0,0,0,0), NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT, 0,0,300,200); + device_list = new FXList(new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0), NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,300,200); + FXVerticalFrame *buttonVF = new FXVerticalFrame(hf); + connect_button = new FXButton(buttonVF, "Connect", NULL, this, ID_CONNECT, BUTTON_NORMAL|LAYOUT_FILL_X); + disconnect_button = new FXButton(buttonVF, "Disconnect", NULL, this, ID_DISCONNECT, BUTTON_NORMAL|LAYOUT_FILL_X); + disconnect_button->disable(); + rescan_button = new FXButton(buttonVF, "Re-Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X); + new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0); + + 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); + 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); + iButtonReadId = new FXButton(matrix, "Read Id", NULL, this, ID_FUTABA_READ_ID, BUTTON_NORMAL|LAYOUT_FILL_X); + iButtonReadFirmwareRevision = new FXButton(matrix, "Read Firmware Revision", NULL, this, ID_FUTABA_READ_FIRMWARE_REVISION, BUTTON_NORMAL|LAYOUT_FILL_X); + iButtonPowerSupplyMonitor = new FXButton(matrix, "Power Supply Monitor", NULL, this, ID_FUTABA_POWER_SUPPLY_MONITOR, BUTTON_NORMAL|LAYOUT_FILL_X); + new FXLabel(matrix, "X",NULL,LABEL_NORMAL|LAYOUT_FILL_X); + new FXLabel(matrix, "Y",NULL,LABEL_NORMAL|LAYOUT_FILL_X); + new FXLabel(matrix, "",NULL,LABEL_NORMAL|LAYOUT_FILL_X); + iTextFieldX = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X); + iTextFieldY = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X); + iButtonSetPixel = new FXButton(matrix, "Set Pixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X); + 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(); + iButtonDisplayDataInput->disable(); + iButtonReadId->disable(); + iButtonReadFirmwareRevision->disable(); + iButtonPowerSupplyMonitor->disable(); + iTextFieldX->disable(); + iTextFieldY->disable(); + iButtonSetPixel->disable(); + iButtonResetPixel->disable(); + iButtonSetAllPixels->disable(); + // + + // Output Group Box + new FXHorizontalFrame(vf); + gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X); + matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X); + new FXLabel(matrix, "Data"); + new FXLabel(matrix, "Length"); + new FXLabel(matrix, ""); + + //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X); + output_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); + output_text->setText("1 0x81 0"); + output_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); + output_button = new FXButton(matrix, "Send Output Report", NULL, this, ID_SEND_OUTPUT_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X); + output_button->disable(); + //new FXHorizontalFrame(matrix, LAYOUT_FILL_X); + + //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X); + feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); + feature_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); + feature_button = new FXButton(matrix, "Send Feature Report", NULL, this, ID_SEND_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X); + feature_button->disable(); + + get_feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); + new FXWindow(matrix); + get_feature_button = new FXButton(matrix, "Get Feature Report", NULL, this, ID_GET_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X); + get_feature_button->disable(); + + + // Input Group Box + gb = new FXGroupBox(vf, "Input", FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y); + FXVerticalFrame *innerVF = new FXVerticalFrame(gb, LAYOUT_FILL_X|LAYOUT_FILL_Y); + 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); + input_text->setEditable(false); + new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT); + + +} + +MainWindow::~MainWindow() +{ + delete iCurrentFont; + iCurrentFont = NULL; + + delete iFontImage; + iFontImage = NULL; + + if (connected_device) + hid_close(connected_device); + hid_exit(); + delete title_font; +} + +void +MainWindow::create() +{ + FXMainWindow::create(); + show(); + + onRescan(NULL, 0, NULL); + + //Just testing our new VFD class + iVfd01.Open(); + iVfd01.SetAllPixels(true); + iVfd01.Close(); + + +#ifdef __APPLE__ + init_apple_message_system(); +#endif + + getApp()->addTimeout(this, ID_MAC_TIMER, + 50 * timeout_scalar /*50ms*/); +} + +long +MainWindow::onConnect(FXObject *sender, FXSelector sel, void *ptr) +{ + if (connected_device != NULL) + return 1; + + FXint cur_item = device_list->getCurrentItem(); + if (cur_item < 0) + return -1; + FXListItem *item = device_list->getItem(cur_item); + if (!item) + return -1; + struct hid_device_info *device_info = (struct hid_device_info*) item->getData(); + if (!device_info) + return -1; + + connected_device = hid_open_path(device_info->path); + + if (!connected_device) { + FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device"); + return -1; + } + + hid_set_nonblocking(connected_device, 1); + + getApp()->addTimeout(this, ID_TIMER, + 5 * timeout_scalar /*5ms*/); + + FXString s; + s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id); + s += FXString(" ") + device_info->manufacturer_string; + s += FXString(" ") + device_info->product_string; + connected_label->setText(s); + output_button->enable(); + feature_button->enable(); + get_feature_button->enable(); + connect_button->disable(); + disconnect_button->enable(); + input_text->setText(""); + // + iButtonClearDisplay->enable(); + iButtonDimming->enable(); + iButtonDisplayDataInput->enable(); + iButtonReadId->enable(); + iButtonReadFirmwareRevision->enable(); + iButtonPowerSupplyMonitor->enable(); + iTextFieldX->enable(); + iTextFieldY->enable(); + iButtonSetPixel->enable(); + iButtonResetPixel->enable(); + iButtonSetAllPixels->enable(); + + // + iOutputReportBuffer=new unsigned char[KFutabaMaxHidReportSize]; //TODO: use connected_device->output_report_length + + return 1; +} + +long +MainWindow::onDisconnect(FXObject *sender, FXSelector sel, void *ptr) +{ + hid_close(connected_device); + connected_device = NULL; + connected_label->setText("Disconnected"); + output_button->disable(); + feature_button->disable(); + get_feature_button->disable(); + connect_button->enable(); + disconnect_button->disable(); + + getApp()->removeTimeout(this, ID_TIMER); + + // + iButtonClearDisplay->disable(); + iButtonDimming->disable(); + iButtonDisplayDataInput->disable(); + iButtonReadId->disable(); + iButtonReadFirmwareRevision->disable(); + iButtonPowerSupplyMonitor->disable(); + iTextFieldX->disable(); + iTextFieldY->disable(); + iButtonSetPixel->disable(); + iButtonResetPixel->disable(); + iButtonSetAllPixels->disable(); + // + + + delete iOutputReportBuffer; + iOutputReportBuffer=NULL; + + return 1; +} + +long +MainWindow::onRescan(FXObject *sender, FXSelector sel, void *ptr) +{ + struct hid_device_info *cur_dev; + + device_list->clearItems(); + + // List the Devices + hid_free_enumeration(devices); + devices = hid_enumerate(0x0, 0x0); + cur_dev = devices; + while (cur_dev) { + // Add it to the List Box only if it is a Futaba device + if (cur_dev->vendor_id == KFutabaVendorId) + { + FXString s; + FXString usage_str; + s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id); + s += FXString(" ") + cur_dev->manufacturer_string; + s += FXString(" ") + cur_dev->product_string; + usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage); + s += usage_str; + FXListItem *li = new FXListItem(s, NULL, cur_dev); + device_list->appendItem(li); + } + + cur_dev = cur_dev->next; + } + + if (device_list->getNumItems() == 0) + device_list->appendItem("*** No Devices Connected ***"); + else { + device_list->selectItem(0); + } + + return 1; +} + +size_t +MainWindow::getDataFromTextField(FXTextField *tf, char *buf, size_t len) +{ + const char *delim = " ,{}\t\r\n"; + FXString data = tf->getText(); + const FXchar *d = data.text(); + size_t i = 0; + + // Copy the string from the GUI. + size_t sz = strlen(d); + char *str = (char*) malloc(sz+1); + strcpy(str, d); + + // For each token in the string, parse and store in buf[]. + char *token = strtok(str, delim); + while (token) { + char *endptr; + long int val = strtol(token, &endptr, 0); + buf[i++] = val; + token = strtok(NULL, delim); + } + + free(str); + return i; +} + +/* getLengthFromTextField() + Returns length: + 0: empty text field + >0: valid length + -1: invalid length */ +int +MainWindow::getLengthFromTextField(FXTextField *tf) +{ + long int len; + FXString str = tf->getText(); + size_t sz = str.length(); + + if (sz > 0) { + char *endptr; + len = strtol(str.text(), &endptr, 0); + if (endptr != str.text() && *endptr == '\0') { + if (len <= 0) { + FXMessageBox::error(this, MBOX_OK, "Invalid length", "Enter a length greater than zero."); + return -1; + } + return len; + } + else + return -1; + } + + return 0; +} + +long +MainWindow::onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr) +{ + char buf[256]; + size_t data_len, len; + int textfield_len; + + memset(buf, 0x0, sizeof(buf)); + textfield_len = getLengthFromTextField(output_len); + data_len = getDataFromTextField(output_text, buf, sizeof(buf)); + + if (textfield_len < 0) { + FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal."); + return 1; + } + + if (textfield_len > sizeof(buf)) { + FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long."); + return 1; + } + + len = (textfield_len)? textfield_len: data_len; + + int res = hid_write(connected_device, (const unsigned char*)buf, len); + if (res < 0) { + FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device)); + } + + return 1; +} + +long +MainWindow::onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr) +{ + char buf[256]; + size_t data_len, len; + int textfield_len; + + memset(buf, 0x0, sizeof(buf)); + textfield_len = getLengthFromTextField(feature_len); + data_len = getDataFromTextField(feature_text, buf, sizeof(buf)); + + if (textfield_len < 0) { + FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal."); + return 1; + } + + if (textfield_len > sizeof(buf)) { + FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long."); + return 1; + } + + len = (textfield_len)? textfield_len: data_len; + + int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len); + if (res < 0) { + FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device)); + } + + return 1; +} + +long +MainWindow::onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr) +{ + char buf[256]; + size_t len; + + memset(buf, 0x0, sizeof(buf)); + len = getDataFromTextField(get_feature_text, buf, sizeof(buf)); + + if (len != 1) { + FXMessageBox::error(this, MBOX_OK, "Too many numbers", "Enter only a single report number in the text field"); + } + + int res = hid_get_feature_report(connected_device, (unsigned char*)buf, sizeof(buf)); + if (res < 0) { + FXMessageBox::error(this, MBOX_OK, "Error Getting Report", "Could not get feature report from device. Error reported was: %ls", hid_error(connected_device)); + } + + if (res > 0) { + FXString s; + s.format("Returned Feature Report. %d bytes:\n", res); + for (int i = 0; i < res; i++) { + FXString t; + t.format("%02hhx ", buf[i]); + s += t; + if ((i+1) % 4 == 0) + s += " "; + if ((i+1) % 16 == 0) + s += "\n"; + } + s += "\n"; + input_text->appendText(s); + input_text->setBottomLine(INT_MAX); + } + + return 1; +} + +long +MainWindow::onClear(FXObject *sender, FXSelector sel, void *ptr) +{ + input_text->setText(""); + return 1; +} + + +long +MainWindow::onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr) +{ + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); + iOutputReportBuffer[0]=0x00; //Report ID + iOutputReportBuffer[1]=0x04; //Report length + iOutputReportBuffer[2]=0x1B; // + iOutputReportBuffer[3]=0x5B; // + iOutputReportBuffer[4]=0x32; // + iOutputReportBuffer[5]=0x4A; // + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); + + return 1; +} + +long +MainWindow::onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr) +{ + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); + iOutputReportBuffer[0]=0x00; //Report ID + iOutputReportBuffer[1]=0x06; //Report length + iOutputReportBuffer[2]=0x1B; // + iOutputReportBuffer[3]=0x5C; // + iOutputReportBuffer[4]=0x3F; // + iOutputReportBuffer[5]=0x4C; // + iOutputReportBuffer[6]=0x44; // + iDimming = (iDimming==0x35?0x30:++iDimming); + iOutputReportBuffer[7]=iDimming; + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); + + return 1; +} + +long +MainWindow::onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr) +{ + //@1B 5B F0 00 00 07 00 01 FF + + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); + iOutputReportBuffer[0]=0x00; //Report ID + iOutputReportBuffer[1]=0x09; //Report length + iOutputReportBuffer[2]=0x1B; // + iOutputReportBuffer[3]=0x5B; // + iOutputReportBuffer[4]=0xF0; // + iOutputReportBuffer[5]=0x00; //X + iOutputReportBuffer[6]=0x00; //Y + iOutputReportBuffer[7]=0x07; // + iOutputReportBuffer[8]=0x00; // + iOutputReportBuffer[9]=0x01; // + iOutputReportBuffer[10]=0xFF; // + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); + + + return 1; +} + + + + +/** +Set a single pixel to the specified value. +@param X coordinate of our pixel. +@param Y coordinate of our pixel. +@param The LSB defines our pixel value. +*/ +void MainWindow::SetPixel(int aX, int aY, unsigned char aValue) + { + //Just specify a one pixel block + SetPixelBlock(aX,aY,0x00,0x01,aValue); + } + +/** +Set the defined pixel block to the given value. +@param X coordinate of our pixel block starting point. +@param Y coordinate of our pixel block starting point. +@param The height of our pixel block. +@param The size of our pixel data. Number of pixels divided by 8. +@param The value set to 8 pixels. +*/ +void MainWindow::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue) + { + //Size must be 63 or below + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); + iOutputReportBuffer[0]=0x00; //Report ID + iOutputReportBuffer[1]=0x08+aSize; //Report length + iOutputReportBuffer[2]=0x1B; // + iOutputReportBuffer[3]=0x5B; // + 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[8]=0x00; //Size of pixel data in bytes (MSB) + iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB) + memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize); + //iOutputReportBuffer[10]=aValue; //Pixel data + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); + } + +/** +Send an output report to a Futaba VFD device. +*/ +/* +void MainWindow::SendFutabaOutputReport(unsigned char* aReportData, unsigned char aSize) + { + // + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); + iOutputReportBuffer[0]=0x00; //Report ID is always null + iOutputReportBuffer[1]=0x08+aSize; //Report length + iOutputReportBuffer[2]=0x1B; // + iOutputReportBuffer[3]=0x5B; // + 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[8]=0x00; //Size of pixel data in bytes (MSB) + iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB) + memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize); + //iOutputReportBuffer[10]=aValue; //Pixel data + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); + } +*/ + + +/** +*/ +long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr) +{ + int x=0; + int y=0; + iTextFieldX->getText().scan("%d",&x); + iTextFieldY->getText().scan("%d",&y); + SetPixel(x,y,0x01); + return 1; +} + +/** +*/ +long MainWindow::onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr) +{ + int x=0; + int y=0; + iTextFieldX->getText().scan("%d",&x); + iTextFieldY->getText().scan("%d",&y); + SetPixel(x,y,0x00); + return 1; +} + +long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr) + { + //One pixel at a time + /* + for (int i=0;i<256;i++) + { + for (int j=0;j<64;j++) + { + SetPixel(i,j,0x01); + } + } + */ + //16x16=256 pixels at a time goes much faster + for (int i=0;i<256;i+=16) + { + for (int j=0;j<64;j+=16) + { + SetPixelBlock(i,j,15,32,0xFF); + //FXThread::sleep(1000000000); + } + } + + return 1; + } + +long +MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr) +{ + //1BH,5BH,63H,49H,44H + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); + iOutputReportBuffer[0]=0x00; //Report ID + iOutputReportBuffer[1]=0x05; //Report length + iOutputReportBuffer[2]=0x1B; // + iOutputReportBuffer[3]=0x5B; // + iOutputReportBuffer[4]=0x63; // + iOutputReportBuffer[5]=0x49; // + iOutputReportBuffer[6]=0x44; // + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); + + return 1; +} + +long +MainWindow::onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr) +{ + //1BH,5BH,63H,46H,52H + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); + iOutputReportBuffer[0]=0x00; //Report ID + iOutputReportBuffer[1]=0x05; //Report length + iOutputReportBuffer[2]=0x1B; // + iOutputReportBuffer[3]=0x5B; // + iOutputReportBuffer[4]=0x63; // + iOutputReportBuffer[5]=0x46; // + iOutputReportBuffer[6]=0x52; // + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); + + return 1; +} + +long +MainWindow::onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr) +{ + //1BH,5BH,63H,50H,4DH + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); + iOutputReportBuffer[0]=0x00; //Report ID + iOutputReportBuffer[1]=0x05; //Report length + iOutputReportBuffer[2]=0x1B; // + iOutputReportBuffer[3]=0x5B; // + iOutputReportBuffer[4]=0x63; // + iOutputReportBuffer[5]=0x50; // + iOutputReportBuffer[6]=0x4D; // + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); + + return 1; +} + + + +long +MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr) +{ + unsigned char buf[256]; + int res = hid_read(connected_device, buf, sizeof(buf)); + + if (res > 0) { + FXString s; + s.format("Received %d bytes:\n", res); + for (int i = 0; i < res; i++) { + FXString t; + t.format("%02hhx ", buf[i]); + s += t; + if ((i+1) % 4 == 0) + s += " "; + if ((i+1) % 16 == 0) + s += "\n"; + } + s += "\n"; + input_text->appendText(s); + input_text->setBottomLine(INT_MAX); + } + if (res < 0) { + input_text->appendText("hid_read() returned error\n"); + input_text->setBottomLine(INT_MAX); + } + + getApp()->addTimeout(this, ID_TIMER, + 5 * timeout_scalar /*5ms*/); + return 1; +} + +long +MainWindow::onMacTimeout(FXObject *sender, FXSelector sel, void *ptr) +{ +#ifdef __APPLE__ + check_apple_events(); + + getApp()->addTimeout(this, ID_MAC_TIMER, + 50 * timeout_scalar /*50ms*/); +#endif + + return 1; +} + +/** + +*/ +long MainWindow::onSelectFont(FXObject *sender, FXSelector sel, void *ptr) + { + FXFontDialog* dlg=new FXFontDialog(this,"Pick a font"); + if (dlg->execute()) + { + dlg->getFontSelection(iCurrentFontDesc); + delete iCurrentFont; + iCurrentFont = NULL; + iCurrentFont = new FXFont(getApp(),iCurrentFontDesc); + iCurrentFont->create(); + // + delete iFontImage; + iFontImage = NULL; + // + FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_"; + //Create an image the proper size for our text + iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_SHMI|IMAGE_SHMP,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight()); + iFontImage->create(); + //Perform our drawing + { + FXDCWindow dc(iFontImage); + //dc.begin(iFontImage); + dc.setFont(iCurrentFont); + dc.setForeground(0xFFFFFFFF); + //dc.setBackground(0xFF000000); + //dc.setFillStyle(FILL_SOLID); + dc.fillRectangle(0,0,iFontImage->getWidth(),iFontImage->getHeight()); + dc.setForeground(0xFF000000); + dc.drawText(0,iCurrentFont->getFontAscent(),text); + //dc.end(); + } + FXFileStream file; + file.open("fonttest.tga",FXStreamSave); + iFontImage->restore(); + iFontImage->savePixels(file); + file.close(); + + // + + } + + delete dlg; + return 1; + } + + + diff -r 11a0e8a2346e -r 7268128148b8 test.cpp --- a/test.cpp Wed May 21 22:55:14 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,826 +0,0 @@ -/******************************************************* - Demo Program for HIDAPI - - Alan Ott - Signal 11 Software - - 2010-07-20 - - Copyright 2010, All Rights Reserved - - This contents of this file may be used by anyone - for any reason without any conditions and may be - used as a starting point for your own applications - which use HIDAPI. -********************************************************/ - -#include "MainWindow.h" - - -// FOX 1.7 changes the timeouts to all be nanoseconds. -// Fox 1.6 had all timeouts as milliseconds. -#if (FOX_MINOR >= 7) - const int timeout_scalar = 1000*1000; -#else - const int timeout_scalar = 1; -#endif - - -FXDEFMAP(MainWindow) MainWindowMap [] = { - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CONNECT, MainWindow::onConnect ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_DISCONNECT, MainWindow::onDisconnect ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_RESCAN, MainWindow::onRescan ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_OUTPUT_REPORT, MainWindow::onSendOutputReport ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_FEATURE_REPORT, MainWindow::onSendFeatureReport ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_GET_FEATURE_REPORT, MainWindow::onGetFeatureReport ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CLEAR, MainWindow::onClear ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_CLEAR_DISPLAY, MainWindow::onFutabaClearDisplay ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DIMMING, MainWindow::onFutabaDimming ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DISPLAY_DATA_INPUT, MainWindow::onFutabaDisplayDataInput ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_ID, MainWindow::onFutabaReadId ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ), - FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ), - 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 ), -}; - -FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap)); - -MainWindow::MainWindow(FXApp *app) - : FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900), - iCurrentFont(NULL), - iFontImage(NULL) -{ - iDimming=0x35; - devices = NULL; - connected_device = NULL; - - FXVerticalFrame *vf = new FXVerticalFrame(this, LAYOUT_FILL_Y|LAYOUT_FILL_X); - - FXLabel *label = new FXLabel(vf, "HIDAPI Test Tool"); - title_font = new FXFont(getApp(), "Arial", 14, FXFont::Bold); - label->setFont(title_font); - - new FXLabel(vf, - "Select a device and press Connect.", NULL, JUSTIFY_LEFT); - new FXLabel(vf, - "Output data bytes can be entered in the Output section, \n" - "separated by space, comma or brackets. Data starting with 0x\n" - "is treated as hex. Data beginning with a 0 is treated as \n" - "octal. All other data is treated as decimal.", NULL, JUSTIFY_LEFT); - new FXLabel(vf, - "Data received from the device appears in the Input section.", - NULL, JUSTIFY_LEFT); - new FXLabel(vf, - "Optionally, a report length may be specified. Extra bytes are\n" - "padded with zeros. If no length is specified, the length is \n" - "inferred from the data.", - NULL, JUSTIFY_LEFT); - new FXLabel(vf, ""); - - // Device List and Connect/Disconnect buttons - FXHorizontalFrame *hf = new FXHorizontalFrame(vf, LAYOUT_FILL_X); - //device_list = new FXList(new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK, 0,0,0,0, 0,0,0,0), NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT, 0,0,300,200); - device_list = new FXList(new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0), NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,300,200); - FXVerticalFrame *buttonVF = new FXVerticalFrame(hf); - connect_button = new FXButton(buttonVF, "Connect", NULL, this, ID_CONNECT, BUTTON_NORMAL|LAYOUT_FILL_X); - disconnect_button = new FXButton(buttonVF, "Disconnect", NULL, this, ID_DISCONNECT, BUTTON_NORMAL|LAYOUT_FILL_X); - disconnect_button->disable(); - rescan_button = new FXButton(buttonVF, "Re-Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X); - new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0); - - 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); - 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); - iButtonReadId = new FXButton(matrix, "Read Id", NULL, this, ID_FUTABA_READ_ID, BUTTON_NORMAL|LAYOUT_FILL_X); - iButtonReadFirmwareRevision = new FXButton(matrix, "Read Firmware Revision", NULL, this, ID_FUTABA_READ_FIRMWARE_REVISION, BUTTON_NORMAL|LAYOUT_FILL_X); - iButtonPowerSupplyMonitor = new FXButton(matrix, "Power Supply Monitor", NULL, this, ID_FUTABA_POWER_SUPPLY_MONITOR, BUTTON_NORMAL|LAYOUT_FILL_X); - new FXLabel(matrix, "X",NULL,LABEL_NORMAL|LAYOUT_FILL_X); - new FXLabel(matrix, "Y",NULL,LABEL_NORMAL|LAYOUT_FILL_X); - new FXLabel(matrix, "",NULL,LABEL_NORMAL|LAYOUT_FILL_X); - iTextFieldX = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X); - iTextFieldY = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X); - iButtonSetPixel = new FXButton(matrix, "Set Pixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X); - 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(); - iButtonDisplayDataInput->disable(); - iButtonReadId->disable(); - iButtonReadFirmwareRevision->disable(); - iButtonPowerSupplyMonitor->disable(); - iTextFieldX->disable(); - iTextFieldY->disable(); - iButtonSetPixel->disable(); - iButtonResetPixel->disable(); - iButtonSetAllPixels->disable(); - // - - // Output Group Box - new FXHorizontalFrame(vf); - gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X); - matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X); - new FXLabel(matrix, "Data"); - new FXLabel(matrix, "Length"); - new FXLabel(matrix, ""); - - //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X); - output_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); - output_text->setText("1 0x81 0"); - output_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); - output_button = new FXButton(matrix, "Send Output Report", NULL, this, ID_SEND_OUTPUT_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X); - output_button->disable(); - //new FXHorizontalFrame(matrix, LAYOUT_FILL_X); - - //hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X); - feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); - feature_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); - feature_button = new FXButton(matrix, "Send Feature Report", NULL, this, ID_SEND_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X); - feature_button->disable(); - - get_feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN); - new FXWindow(matrix); - get_feature_button = new FXButton(matrix, "Get Feature Report", NULL, this, ID_GET_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X); - get_feature_button->disable(); - - - // Input Group Box - gb = new FXGroupBox(vf, "Input", FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y); - FXVerticalFrame *innerVF = new FXVerticalFrame(gb, LAYOUT_FILL_X|LAYOUT_FILL_Y); - 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); - input_text->setEditable(false); - new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT); - - -} - -MainWindow::~MainWindow() -{ - delete iCurrentFont; - iCurrentFont = NULL; - - delete iFontImage; - iFontImage = NULL; - - if (connected_device) - hid_close(connected_device); - hid_exit(); - delete title_font; -} - -void -MainWindow::create() -{ - FXMainWindow::create(); - show(); - - onRescan(NULL, 0, NULL); - - //Just testing our new VFD class - iVfd01.Open(); - iVfd01.SetAllPixels(true); - iVfd01.Close(); - - -#ifdef __APPLE__ - init_apple_message_system(); -#endif - - getApp()->addTimeout(this, ID_MAC_TIMER, - 50 * timeout_scalar /*50ms*/); -} - -long -MainWindow::onConnect(FXObject *sender, FXSelector sel, void *ptr) -{ - if (connected_device != NULL) - return 1; - - FXint cur_item = device_list->getCurrentItem(); - if (cur_item < 0) - return -1; - FXListItem *item = device_list->getItem(cur_item); - if (!item) - return -1; - struct hid_device_info *device_info = (struct hid_device_info*) item->getData(); - if (!device_info) - return -1; - - connected_device = hid_open_path(device_info->path); - - if (!connected_device) { - FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device"); - return -1; - } - - hid_set_nonblocking(connected_device, 1); - - getApp()->addTimeout(this, ID_TIMER, - 5 * timeout_scalar /*5ms*/); - - FXString s; - s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id); - s += FXString(" ") + device_info->manufacturer_string; - s += FXString(" ") + device_info->product_string; - connected_label->setText(s); - output_button->enable(); - feature_button->enable(); - get_feature_button->enable(); - connect_button->disable(); - disconnect_button->enable(); - input_text->setText(""); - // - iButtonClearDisplay->enable(); - iButtonDimming->enable(); - iButtonDisplayDataInput->enable(); - iButtonReadId->enable(); - iButtonReadFirmwareRevision->enable(); - iButtonPowerSupplyMonitor->enable(); - iTextFieldX->enable(); - iTextFieldY->enable(); - iButtonSetPixel->enable(); - iButtonResetPixel->enable(); - iButtonSetAllPixels->enable(); - - // - iOutputReportBuffer=new unsigned char[KFutabaMaxHidReportSize]; //TODO: use connected_device->output_report_length - - return 1; -} - -long -MainWindow::onDisconnect(FXObject *sender, FXSelector sel, void *ptr) -{ - hid_close(connected_device); - connected_device = NULL; - connected_label->setText("Disconnected"); - output_button->disable(); - feature_button->disable(); - get_feature_button->disable(); - connect_button->enable(); - disconnect_button->disable(); - - getApp()->removeTimeout(this, ID_TIMER); - - // - iButtonClearDisplay->disable(); - iButtonDimming->disable(); - iButtonDisplayDataInput->disable(); - iButtonReadId->disable(); - iButtonReadFirmwareRevision->disable(); - iButtonPowerSupplyMonitor->disable(); - iTextFieldX->disable(); - iTextFieldY->disable(); - iButtonSetPixel->disable(); - iButtonResetPixel->disable(); - iButtonSetAllPixels->disable(); - // - - - delete iOutputReportBuffer; - iOutputReportBuffer=NULL; - - return 1; -} - -long -MainWindow::onRescan(FXObject *sender, FXSelector sel, void *ptr) -{ - struct hid_device_info *cur_dev; - - device_list->clearItems(); - - // List the Devices - hid_free_enumeration(devices); - devices = hid_enumerate(0x0, 0x0); - cur_dev = devices; - while (cur_dev) { - // Add it to the List Box only if it is a Futaba device - if (cur_dev->vendor_id == KFutabaVendorId) - { - FXString s; - FXString usage_str; - s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id); - s += FXString(" ") + cur_dev->manufacturer_string; - s += FXString(" ") + cur_dev->product_string; - usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage); - s += usage_str; - FXListItem *li = new FXListItem(s, NULL, cur_dev); - device_list->appendItem(li); - } - - cur_dev = cur_dev->next; - } - - if (device_list->getNumItems() == 0) - device_list->appendItem("*** No Devices Connected ***"); - else { - device_list->selectItem(0); - } - - return 1; -} - -size_t -MainWindow::getDataFromTextField(FXTextField *tf, char *buf, size_t len) -{ - const char *delim = " ,{}\t\r\n"; - FXString data = tf->getText(); - const FXchar *d = data.text(); - size_t i = 0; - - // Copy the string from the GUI. - size_t sz = strlen(d); - char *str = (char*) malloc(sz+1); - strcpy(str, d); - - // For each token in the string, parse and store in buf[]. - char *token = strtok(str, delim); - while (token) { - char *endptr; - long int val = strtol(token, &endptr, 0); - buf[i++] = val; - token = strtok(NULL, delim); - } - - free(str); - return i; -} - -/* getLengthFromTextField() - Returns length: - 0: empty text field - >0: valid length - -1: invalid length */ -int -MainWindow::getLengthFromTextField(FXTextField *tf) -{ - long int len; - FXString str = tf->getText(); - size_t sz = str.length(); - - if (sz > 0) { - char *endptr; - len = strtol(str.text(), &endptr, 0); - if (endptr != str.text() && *endptr == '\0') { - if (len <= 0) { - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Enter a length greater than zero."); - return -1; - } - return len; - } - else - return -1; - } - - return 0; -} - -long -MainWindow::onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr) -{ - char buf[256]; - size_t data_len, len; - int textfield_len; - - memset(buf, 0x0, sizeof(buf)); - textfield_len = getLengthFromTextField(output_len); - data_len = getDataFromTextField(output_text, buf, sizeof(buf)); - - if (textfield_len < 0) { - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal."); - return 1; - } - - if (textfield_len > sizeof(buf)) { - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long."); - return 1; - } - - len = (textfield_len)? textfield_len: data_len; - - int res = hid_write(connected_device, (const unsigned char*)buf, len); - if (res < 0) { - FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device)); - } - - return 1; -} - -long -MainWindow::onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr) -{ - char buf[256]; - size_t data_len, len; - int textfield_len; - - memset(buf, 0x0, sizeof(buf)); - textfield_len = getLengthFromTextField(feature_len); - data_len = getDataFromTextField(feature_text, buf, sizeof(buf)); - - if (textfield_len < 0) { - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal."); - return 1; - } - - if (textfield_len > sizeof(buf)) { - FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long."); - return 1; - } - - len = (textfield_len)? textfield_len: data_len; - - int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len); - if (res < 0) { - FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device)); - } - - return 1; -} - -long -MainWindow::onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr) -{ - char buf[256]; - size_t len; - - memset(buf, 0x0, sizeof(buf)); - len = getDataFromTextField(get_feature_text, buf, sizeof(buf)); - - if (len != 1) { - FXMessageBox::error(this, MBOX_OK, "Too many numbers", "Enter only a single report number in the text field"); - } - - int res = hid_get_feature_report(connected_device, (unsigned char*)buf, sizeof(buf)); - if (res < 0) { - FXMessageBox::error(this, MBOX_OK, "Error Getting Report", "Could not get feature report from device. Error reported was: %ls", hid_error(connected_device)); - } - - if (res > 0) { - FXString s; - s.format("Returned Feature Report. %d bytes:\n", res); - for (int i = 0; i < res; i++) { - FXString t; - t.format("%02hhx ", buf[i]); - s += t; - if ((i+1) % 4 == 0) - s += " "; - if ((i+1) % 16 == 0) - s += "\n"; - } - s += "\n"; - input_text->appendText(s); - input_text->setBottomLine(INT_MAX); - } - - return 1; -} - -long -MainWindow::onClear(FXObject *sender, FXSelector sel, void *ptr) -{ - input_text->setText(""); - return 1; -} - - -long -MainWindow::onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr) -{ - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); - iOutputReportBuffer[0]=0x00; //Report ID - iOutputReportBuffer[1]=0x04; //Report length - iOutputReportBuffer[2]=0x1B; // - iOutputReportBuffer[3]=0x5B; // - iOutputReportBuffer[4]=0x32; // - iOutputReportBuffer[5]=0x4A; // - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); - - return 1; -} - -long -MainWindow::onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr) -{ - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); - iOutputReportBuffer[0]=0x00; //Report ID - iOutputReportBuffer[1]=0x06; //Report length - iOutputReportBuffer[2]=0x1B; // - iOutputReportBuffer[3]=0x5C; // - iOutputReportBuffer[4]=0x3F; // - iOutputReportBuffer[5]=0x4C; // - iOutputReportBuffer[6]=0x44; // - iDimming = (iDimming==0x35?0x30:++iDimming); - iOutputReportBuffer[7]=iDimming; - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); - - return 1; -} - -long -MainWindow::onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr) -{ - //@1B 5B F0 00 00 07 00 01 FF - - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); - iOutputReportBuffer[0]=0x00; //Report ID - iOutputReportBuffer[1]=0x09; //Report length - iOutputReportBuffer[2]=0x1B; // - iOutputReportBuffer[3]=0x5B; // - iOutputReportBuffer[4]=0xF0; // - iOutputReportBuffer[5]=0x00; //X - iOutputReportBuffer[6]=0x00; //Y - iOutputReportBuffer[7]=0x07; // - iOutputReportBuffer[8]=0x00; // - iOutputReportBuffer[9]=0x01; // - iOutputReportBuffer[10]=0xFF; // - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); - - - return 1; -} - - - - -/** -Set a single pixel to the specified value. -@param X coordinate of our pixel. -@param Y coordinate of our pixel. -@param The LSB defines our pixel value. -*/ -void MainWindow::SetPixel(int aX, int aY, unsigned char aValue) - { - //Just specify a one pixel block - SetPixelBlock(aX,aY,0x00,0x01,aValue); - } - -/** -Set the defined pixel block to the given value. -@param X coordinate of our pixel block starting point. -@param Y coordinate of our pixel block starting point. -@param The height of our pixel block. -@param The size of our pixel data. Number of pixels divided by 8. -@param The value set to 8 pixels. -*/ -void MainWindow::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue) - { - //Size must be 63 or below - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); - iOutputReportBuffer[0]=0x00; //Report ID - iOutputReportBuffer[1]=0x08+aSize; //Report length - iOutputReportBuffer[2]=0x1B; // - iOutputReportBuffer[3]=0x5B; // - 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[8]=0x00; //Size of pixel data in bytes (MSB) - iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB) - memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize); - //iOutputReportBuffer[10]=aValue; //Pixel data - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); - } - -/** -Send an output report to a Futaba VFD device. -*/ -/* -void MainWindow::SendFutabaOutputReport(unsigned char* aReportData, unsigned char aSize) - { - // - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); - iOutputReportBuffer[0]=0x00; //Report ID is always null - iOutputReportBuffer[1]=0x08+aSize; //Report length - iOutputReportBuffer[2]=0x1B; // - iOutputReportBuffer[3]=0x5B; // - 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[8]=0x00; //Size of pixel data in bytes (MSB) - iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB) - memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize); - //iOutputReportBuffer[10]=aValue; //Pixel data - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); - } -*/ - - -/** -*/ -long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr) -{ - int x=0; - int y=0; - iTextFieldX->getText().scan("%d",&x); - iTextFieldY->getText().scan("%d",&y); - SetPixel(x,y,0x01); - return 1; -} - -/** -*/ -long MainWindow::onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr) -{ - int x=0; - int y=0; - iTextFieldX->getText().scan("%d",&x); - iTextFieldY->getText().scan("%d",&y); - SetPixel(x,y,0x00); - return 1; -} - -long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr) - { - //One pixel at a time - /* - for (int i=0;i<256;i++) - { - for (int j=0;j<64;j++) - { - SetPixel(i,j,0x01); - } - } - */ - //16x16=256 pixels at a time goes much faster - for (int i=0;i<256;i+=16) - { - for (int j=0;j<64;j+=16) - { - SetPixelBlock(i,j,15,32,0xFF); - //FXThread::sleep(1000000000); - } - } - - return 1; - } - -long -MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr) -{ - //1BH,5BH,63H,49H,44H - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); - iOutputReportBuffer[0]=0x00; //Report ID - iOutputReportBuffer[1]=0x05; //Report length - iOutputReportBuffer[2]=0x1B; // - iOutputReportBuffer[3]=0x5B; // - iOutputReportBuffer[4]=0x63; // - iOutputReportBuffer[5]=0x49; // - iOutputReportBuffer[6]=0x44; // - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); - - return 1; -} - -long -MainWindow::onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr) -{ - //1BH,5BH,63H,46H,52H - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); - iOutputReportBuffer[0]=0x00; //Report ID - iOutputReportBuffer[1]=0x05; //Report length - iOutputReportBuffer[2]=0x1B; // - iOutputReportBuffer[3]=0x5B; // - iOutputReportBuffer[4]=0x63; // - iOutputReportBuffer[5]=0x46; // - iOutputReportBuffer[6]=0x52; // - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); - - return 1; -} - -long -MainWindow::onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr) -{ - //1BH,5BH,63H,50H,4DH - memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); - iOutputReportBuffer[0]=0x00; //Report ID - iOutputReportBuffer[1]=0x05; //Report length - iOutputReportBuffer[2]=0x1B; // - iOutputReportBuffer[3]=0x5B; // - iOutputReportBuffer[4]=0x63; // - iOutputReportBuffer[5]=0x50; // - iOutputReportBuffer[6]=0x4D; // - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); - - return 1; -} - - - -long -MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr) -{ - unsigned char buf[256]; - int res = hid_read(connected_device, buf, sizeof(buf)); - - if (res > 0) { - FXString s; - s.format("Received %d bytes:\n", res); - for (int i = 0; i < res; i++) { - FXString t; - t.format("%02hhx ", buf[i]); - s += t; - if ((i+1) % 4 == 0) - s += " "; - if ((i+1) % 16 == 0) - s += "\n"; - } - s += "\n"; - input_text->appendText(s); - input_text->setBottomLine(INT_MAX); - } - if (res < 0) { - input_text->appendText("hid_read() returned error\n"); - input_text->setBottomLine(INT_MAX); - } - - getApp()->addTimeout(this, ID_TIMER, - 5 * timeout_scalar /*5ms*/); - return 1; -} - -long -MainWindow::onMacTimeout(FXObject *sender, FXSelector sel, void *ptr) -{ -#ifdef __APPLE__ - check_apple_events(); - - getApp()->addTimeout(this, ID_MAC_TIMER, - 50 * timeout_scalar /*50ms*/); -#endif - - return 1; -} - -/** - -*/ -long MainWindow::onSelectFont(FXObject *sender, FXSelector sel, void *ptr) - { - FXFontDialog* dlg=new FXFontDialog(this,"Pick a font"); - if (dlg->execute()) - { - dlg->getFontSelection(iCurrentFontDesc); - delete iCurrentFont; - iCurrentFont = NULL; - iCurrentFont = new FXFont(getApp(),iCurrentFontDesc); - iCurrentFont->create(); - // - delete iFontImage; - iFontImage = NULL; - // - FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_"; - //Create an image the proper size for our text - iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_SHMI|IMAGE_SHMP,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight()); - iFontImage->create(); - //Perform our drawing - { - FXDCWindow dc(iFontImage); - //dc.begin(iFontImage); - dc.setFont(iCurrentFont); - dc.setForeground(0xFFFFFFFF); - //dc.setBackground(0xFF000000); - //dc.setFillStyle(FILL_SOLID); - dc.fillRectangle(0,0,iFontImage->getWidth(),iFontImage->getHeight()); - dc.setForeground(0xFF000000); - dc.drawText(0,iCurrentFont->getFontAscent(),text); - //dc.end(); - } - FXFileStream file; - file.open("fonttest.tga",FXStreamSave); - iFontImage->restore(); - iFontImage->savePixels(file); - file.close(); - - // - - } - - delete dlg; - return 1; - } - - -