Draft implementation of multiple report pixel command.
1.1 --- a/inc/FutabaVfd.h Thu May 22 11:29:23 2014 +0200
1.2 +++ b/inc/FutabaVfd.h Thu May 22 13:46:37 2014 +0200
1.3 @@ -1,4 +1,6 @@
1.4 -
1.5 +//
1.6 +//
1.7 +//
1.8
1.9 #ifndef FUTABA_VFD_H
1.10 #define FUTABA_VFD_H
1.11 @@ -6,6 +8,15 @@
1.12 #include "hidapi.h"
1.13 #include "HidDevice.h"
1.14
1.15 +#ifndef MIN
1.16 +#define MIN(a,b) (((a)<(b))?(a):(b))
1.17 +#endif
1.18 +
1.19 +#ifndef MAX
1.20 +#define MAX(a,b) (((a)>(b))?(a):(b))
1.21 +#endif
1.22 +
1.23 +
1.24 //This was computed from our number of pixels as follow 256x64/8/64 = 32 + 1 = 33
1.25 //+1 was added for our header
1.26 const int KFutabaMaxCommandOutputReport = 33;
1.27 @@ -22,9 +33,8 @@
1.28
1.29 //typedef struct hid_device_info HidDeviceInfo;
1.30
1.31 -
1.32 -
1.33 /**
1.34 +Define a Futaba HID report.
1.35 */
1.36 class FutabaVfdReport: public HidReport<KFutabaMaxHidReportSize>
1.37 {
1.38 @@ -112,6 +122,7 @@
1.39
1.40 //Specific to GP1212A01A
1.41 void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue);
1.42 + void SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char* aPixels);
1.43 //
1.44 void RequestId();
1.45 void RequestFirmwareRevision();
2.1 --- a/src/FutabaVfd.cpp Thu May 22 11:29:23 2014 +0200
2.2 +++ b/src/FutabaVfd.cpp Thu May 22 13:46:37 2014 +0200
2.3 @@ -147,7 +147,7 @@
2.4 @param Y coordinate of our pixel block starting point.
2.5 @param The height of our pixel block.
2.6 @param The size of our pixel data. Number of pixels divided by 8.
2.7 -@param The value set to 8 pixels.
2.8 +@param The value set to 8 pixels used as a pattern.
2.9 */
2.10 void GP1212A01A::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue)
2.11 {
2.12 @@ -168,6 +168,45 @@
2.13 Write(report);
2.14 }
2.15
2.16 +/**
2.17 +Set the defined pixel block to the given value.
2.18 +@param X coordinate of our pixel block starting point.
2.19 +@param Y coordinate of our pixel block starting point.
2.20 +@param The height of our pixel block.
2.21 +@param The size of our pixel data. Number of pixels divided by 8.
2.22 +@param Pointer to our pixel data.
2.23 +*/
2.24 +void GP1212A01A::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char* aPixels)
2.25 + {
2.26 + FutabaVfdReport report;
2.27 + report[0]=0x00; //Report ID
2.28 + report[1]=0x08+(aSize<=report.Size()-10?aSize:64); //Report length. -10 is for our header first 10 bytes
2.29 + report[2]=0x1B; //Command ID
2.30 + report[3]=0x5B; //Command ID
2.31 + report[4]=0xF0; //Command ID
2.32 + report[5]=aX; //X
2.33 + report[6]=aY; //Y
2.34 + 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.
2.35 + unsigned short* sizePtr=(unsigned short*)report.Buffer()+8; //Size of pixel data in bytes (MSB)
2.36 + *sizePtr=aSize; //Put our size over 2 bytes
2.37 + int sizeWritten=MIN(aSize,report.Size()-10);
2.38 + memcpy(report.Buffer()+10, aPixels, sizeWritten);
2.39 + Write(report);
2.40 +
2.41 + int remainingSize=aSize;
2.42 + //We need to keep on sending our pixel data until we are done
2.43 + while (report[1]==64)
2.44 + {
2.45 + report.Reset();
2.46 + remainingSize-=sizeWritten;
2.47 + report[0]=0x00; //Report ID
2.48 + report[1]=(remainingSize<=report.Size()-2?aSize:64); //Report length, should be 64 or the remaining size
2.49 + sizeWritten=(report[1]==64?63:report[1]);
2.50 + memcpy(report.Buffer()+2, aPixels+(aSize-remainingSize), sizeWritten);
2.51 + Write(report);
2.52 + }
2.53 + }
2.54 +
2.55
2.56 /**
2.57 Clear our display's screen.