# HG changeset patch # User sl # Date 1400704999 -7200 # Node ID 4c3d32f38c091adf733595ef7fea28bd5bd5fed7 # Parent e6c42e1e2a967d3c7b8175cdec442f9a4de52f52 Working on our architecture. Adding a bunch of HID and Futaba classes. diff -r e6c42e1e2a96 -r 4c3d32f38c09 FutabaVfd.cpp --- a/FutabaVfd.cpp Wed May 21 16:11:09 2014 +0200 +++ b/FutabaVfd.cpp Wed May 21 22:43:19 2014 +0200 @@ -3,6 +3,19 @@ //#include #include + +// +// +// + + + + + +// +// +// + FutabaVfdCommand::FutabaVfdCommand():/*iBuffer(NULL),*/iSize(0),iMaxSize(0) { } @@ -52,3 +65,163 @@ */ +// +// 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, KFutabaMaxHidReportSize); + //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 e6c42e1e2a96 -r 4c3d32f38c09 FutabaVfd.h --- a/FutabaVfd.h Wed May 21 16:11:09 2014 +0200 +++ b/FutabaVfd.h Wed May 21 22:43:19 2014 +0200 @@ -9,7 +9,83 @@ //+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 KFutabaOutputReportLength = 65; +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: + + }; + /** @@ -30,10 +106,72 @@ private: //unsigned char* iBuffer; - unsigned char iReports[KFutabaMaxCommandOutputReport][KFutabaOutputReportLength]; + FutabaVfdReport iReports[KFutabaMaxCommandOutputReport]; int iSize; int iMaxSize; }; +/** +*/ +class FutabaVfd : protected 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 e6c42e1e2a96 -r 4c3d32f38c09 test.cpp --- a/test.cpp Wed May 21 16:11:09 2014 +0200 +++ b/test.cpp Wed May 21 22:43:19 2014 +0200 @@ -258,7 +258,7 @@ iButtonSetAllPixels->enable(); // - iOutputReportBuffer=new unsigned char[KFutabaOutputReportLength]; //TODO: use connected_device->output_report_length + iOutputReportBuffer=new unsigned char[KFutabaMaxHidReportSize]; //TODO: use connected_device->output_report_length return 1; } @@ -305,9 +305,6 @@ device_list->clearItems(); - //Define Futaba vendor ID to filter our list of device - const unsigned short KFutabaVendorId = 0x1008; - // List the Devices hid_free_enumeration(devices); devices = hid_enumerate(0x0, 0x0); @@ -505,14 +502,14 @@ long MainWindow::onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr) { - memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength); + 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, KFutabaOutputReportLength); + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); return 1; } @@ -520,7 +517,7 @@ long MainWindow::onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr) { - memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength); + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); iOutputReportBuffer[0]=0x00; //Report ID iOutputReportBuffer[1]=0x06; //Report length iOutputReportBuffer[2]=0x1B; // @@ -530,7 +527,7 @@ iOutputReportBuffer[6]=0x44; // iDimming = (iDimming==0x35?0x30:++iDimming); iOutputReportBuffer[7]=iDimming; - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength); + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); return 1; } @@ -540,7 +537,7 @@ { //@1B 5B F0 00 00 07 00 01 FF - memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength); + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); iOutputReportBuffer[0]=0x00; //Report ID iOutputReportBuffer[1]=0x09; //Report length iOutputReportBuffer[2]=0x1B; // @@ -552,7 +549,7 @@ iOutputReportBuffer[8]=0x00; // iOutputReportBuffer[9]=0x01; // iOutputReportBuffer[10]=0xFF; // - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength); + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); return 1; @@ -584,7 +581,7 @@ void MainWindow::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue) { //Size must be 63 or below - memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength); + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); iOutputReportBuffer[0]=0x00; //Report ID iOutputReportBuffer[1]=0x08+aSize; //Report length iOutputReportBuffer[2]=0x1B; // @@ -595,9 +592,9 @@ iOutputReportBuffer[7]=aHeight; //Y length before return. Though outside the specs, setting this to zero apparently allows us to modify a single pixel without touching any other. iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB) iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB) - memset(iOutputReportBuffer+10, aValue, KFutabaOutputReportLength); + memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize); //iOutputReportBuffer[10]=aValue; //Pixel data - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength); + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); } /** @@ -607,7 +604,7 @@ void MainWindow::SendFutabaOutputReport(unsigned char* aReportData, unsigned char aSize) { // - memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength); + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); iOutputReportBuffer[0]=0x00; //Report ID is always null iOutputReportBuffer[1]=0x08+aSize; //Report length iOutputReportBuffer[2]=0x1B; // @@ -618,9 +615,9 @@ iOutputReportBuffer[7]=aHeight; //Y length before return. Though outside the specs, setting this to zero apparently allows us to modify a single pixel without touching any other. iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB) iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB) - memset(iOutputReportBuffer+10, aValue, KFutabaOutputReportLength); + memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize); //iOutputReportBuffer[10]=aValue; //Pixel data - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength); + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); } */ @@ -678,7 +675,7 @@ MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr) { //1BH,5BH,63H,49H,44H - memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength); + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); iOutputReportBuffer[0]=0x00; //Report ID iOutputReportBuffer[1]=0x05; //Report length iOutputReportBuffer[2]=0x1B; // @@ -686,7 +683,7 @@ iOutputReportBuffer[4]=0x63; // iOutputReportBuffer[5]=0x49; // iOutputReportBuffer[6]=0x44; // - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength); + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); return 1; } @@ -695,7 +692,7 @@ MainWindow::onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr) { //1BH,5BH,63H,46H,52H - memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength); + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); iOutputReportBuffer[0]=0x00; //Report ID iOutputReportBuffer[1]=0x05; //Report length iOutputReportBuffer[2]=0x1B; // @@ -703,7 +700,7 @@ iOutputReportBuffer[4]=0x63; // iOutputReportBuffer[5]=0x46; // iOutputReportBuffer[6]=0x52; // - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength); + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); return 1; } @@ -712,7 +709,7 @@ MainWindow::onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr) { //1BH,5BH,63H,50H,4DH - memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength); + memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize); iOutputReportBuffer[0]=0x00; //Report ID iOutputReportBuffer[1]=0x05; //Report length iOutputReportBuffer[2]=0x1B; // @@ -720,7 +717,7 @@ iOutputReportBuffer[4]=0x63; // iOutputReportBuffer[5]=0x50; // iOutputReportBuffer[6]=0x4D; // - int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength); + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize); return 1; }