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