# HG changeset patch # User sl # Date 1400759197 -7200 # Node ID 23cacc1d17a3d410ab3046cd916aa62e8caaa1c9 # Parent 0d9d062609eb181801b59e1b194fc15f46f04c45 Draft implementation of multiple report pixel command. diff -r 0d9d062609eb -r 23cacc1d17a3 inc/FutabaVfd.h --- a/inc/FutabaVfd.h Thu May 22 11:29:23 2014 +0200 +++ b/inc/FutabaVfd.h Thu May 22 13:46:37 2014 +0200 @@ -1,4 +1,6 @@ - +// +// +// #ifndef FUTABA_VFD_H #define FUTABA_VFD_H @@ -6,6 +8,15 @@ #include "hidapi.h" #include "HidDevice.h" +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + + //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; @@ -22,9 +33,8 @@ //typedef struct hid_device_info HidDeviceInfo; - - /** +Define a Futaba HID report. */ class FutabaVfdReport: public HidReport { @@ -112,6 +122,7 @@ //Specific to GP1212A01A void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue); + void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char* aPixels); // void RequestId(); void RequestFirmwareRevision(); diff -r 0d9d062609eb -r 23cacc1d17a3 src/FutabaVfd.cpp --- a/src/FutabaVfd.cpp Thu May 22 11:29:23 2014 +0200 +++ b/src/FutabaVfd.cpp Thu May 22 13:46:37 2014 +0200 @@ -147,7 +147,7 @@ @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. +@param The value set to 8 pixels used as a pattern. */ void GP1212A01A::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue) { @@ -168,6 +168,45 @@ Write(report); } +/** +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 Pointer to our pixel data. +*/ +void GP1212A01A::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char* aPixels) + { + FutabaVfdReport report; + report[0]=0x00; //Report ID + report[1]=0x08+(aSize<=report.Size()-10?aSize:64); //Report length. -10 is for our header first 10 bytes + report[2]=0x1B; //Command ID + report[3]=0x5B; //Command ID + report[4]=0xF0; //Command ID + 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. + unsigned short* sizePtr=(unsigned short*)report.Buffer()+8; //Size of pixel data in bytes (MSB) + *sizePtr=aSize; //Put our size over 2 bytes + int sizeWritten=MIN(aSize,report.Size()-10); + memcpy(report.Buffer()+10, aPixels, sizeWritten); + Write(report); + + int remainingSize=aSize; + //We need to keep on sending our pixel data until we are done + while (report[1]==64) + { + report.Reset(); + remainingSize-=sizeWritten; + report[0]=0x00; //Report ID + report[1]=(remainingSize<=report.Size()-2?aSize:64); //Report length, should be 64 or the remaining size + sizeWritten=(report[1]==64?63:report[1]); + memcpy(report.Buffer()+2, aPixels+(aSize-remainingSize), sizeWritten); + Write(report); + } + } + /** Clear our display's screen.