FutabaVfd.h
author sl
Sat, 12 Jul 2014 13:15:31 +0200
changeset 7 8bac7aac665c
parent 5 33e930b11152
child 8 5a9dbbc40c6b
permissions -rw-r--r--
Display can now be opened, closed and reopened thanks to the following fixes.
Fixing issue with non-virtual destructor.
Fixing issue with deletion of void pointer.
     1 //
     2 //
     3 //
     4 
     5 #ifndef FUTABA_VFD_H
     6 #define FUTABA_VFD_H
     7 
     8 #include "hidapi.h"
     9 #include "HidDevice.h"
    10 #include "BitArray.h"
    11 #include "MiniDisplay.h"
    12 
    13 #ifndef MIN
    14 #define MIN(a,b) (((a)<(b))?(a):(b))
    15 #endif
    16 
    17 #ifndef MAX
    18 #define MAX(a,b) (((a)>(b))?(a):(b))
    19 #endif
    20 
    21 
    22 //This was computed from our number of pixels as follow 256x64/8/64 = 32 + 1 = 33
    23 //+1 was added for our header
    24 const int KFutabaMaxCommandOutputReport = 33;
    25 //TODO: Get ride of that constant once we figure out a way to get it from hidapi
    26 const int KFutabaMaxHidReportSize = 65;
    27 
    28 const int KHidReportIdIndex=0;
    29 const int KFutabaHidReportSizeIndex=1;
    30 //Define Futaba vendor ID to filter our list of device
    31 const unsigned short KFutabaVendorId = 0x1008;
    32 const unsigned short KFutabaProductIdGP1212A01A = 0x100C;
    33 const unsigned short KFutabaProductIdGP1212A02A = 0x1013; //Or is it 0x1015
    34 const int KGP12xWidthInPixels = 256;
    35 const int KGP12xHeightInPixels = 64;
    36 const int KGP12xPixelsPerByte = 8;
    37 const int KGP12xFrameBufferSizeInBytes = KGP12xWidthInPixels*KGP12xHeightInPixels/KGP12xPixelsPerByte; //256*64/8=2048
    38 const int KGP12xFrameBufferPixelCount = KGP12xWidthInPixels*KGP12xHeightInPixels;
    39 
    40 //typedef struct hid_device_info HidDeviceInfo;
    41 
    42 /**
    43 Define a Futaba HID report.
    44 */
    45 class FutabaVfdReport: public HidReport<KFutabaMaxHidReportSize>
    46 	{
    47 
    48 private:
    49 
    50 	};
    51 
    52 
    53 /**
    54 Define a generic Futaba VFD command.
    55 */
    56 class FutabaVfdCommand
    57     {
    58 public:
    59     FutabaVfdCommand();
    60     ~FutabaVfdCommand();
    61     //
    62     //void Create(int aMaxSize);
    63     //void Delete();
    64 
    65     //inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];}
    66 
    67     void Reset();
    68 
    69 private:
    70     //unsigned char* iBuffer;
    71     FutabaVfdReport iReports[KFutabaMaxCommandOutputReport];
    72     int iSize;
    73     int iMaxSize;
    74     };
    75 
    76 /**
    77 */
    78 class FutabaVfd : public HidDevice
    79 	{
    80 public:
    81 	virtual int MinBrightness() const=0;
    82 	virtual int MaxBrightness() const=0;
    83 	virtual void SetBrightness(int aBrightness)=0;
    84 	virtual void Clear()=0;
    85 	};
    86 
    87 
    88 /**
    89 */
    90 class FutabaGraphicVfd : public FutabaVfd
    91 	{
    92 public:
    93 	virtual int WidthInPixels() const=0;
    94 	virtual int HeightInPixels() const=0;
    95 	virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn)=0;
    96 	virtual void SetAllPixels(unsigned char aOn)=0;
    97 	virtual int FrameBufferSizeInBytes() const=0;
    98 	//virtual int BitBlit(unsigned char* aSrc, unsigned char aSrcWidth, unsigned char aSrcHeight, unsigned char aTargetX, unsigned char aTargetY) const=0;
    99 
   100 	};
   101 
   102 /**
   103 Common functionality between GP1212A01A and GP1212A02A
   104 */
   105 class GP1212XXXX : public FutabaGraphicVfd
   106 	{
   107 public:
   108 	//From FutabaVfd
   109     virtual int MinBrightness() const {return 0;}
   110     virtual int MaxBrightness() const {return 5;}
   111 	};
   112 
   113 /**
   114 GP1212A01A is a graphic display module using a FUTABA 256x64dots VFD.
   115 The module do not include character ROM, the customer will compile the character
   116 by themselves (from main system).
   117 */
   118 class GP1212A01A : public GP1212XXXX
   119 	{
   120 public:
   121 
   122 
   123 public:
   124     GP1212A01A();
   125     ~GP1212A01A();
   126 
   127 	//
   128 	int Open();
   129 	//From FutabaGraphicVfd
   130     virtual int WidthInPixels() const {return KGP12xWidthInPixels;}
   131     virtual int HeightInPixels() const {return KGP12xHeightInPixels;}
   132 	virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn);
   133 	virtual void SetAllPixels(unsigned char aPattern);
   134     virtual int FrameBufferSizeInBytes() const {return KGP12xFrameBufferSizeInBytes;}
   135     virtual void BitBlit(const BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const;
   136 	//From FutabaVfd
   137 	virtual void SetBrightness(int aBrightness);
   138 	virtual void Clear();
   139 
   140 	//Specific to GP1212A01A
   141 	void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue);
   142     void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels);
   143     //Define display position within our display RAM
   144 	void SetDisplayPosition(unsigned char aX, unsigned char aY);
   145     unsigned char DisplayPositionX() const {return iDisplayPositionX;}
   146     unsigned char DisplayPositionY() const {return iDisplayPositionY;}
   147     //
   148 	void SwapBuffers();
   149     //
   150     void RequestDeviceId();
   151     void RequestFirmwareRevision();
   152     void RequestPowerSupplyStatus();
   153 	//
   154 	void ToggleOffScreenMode();
   155     void SetOffScreenMode(bool aOn);
   156     bool OffScreenMode() const {return iOffScreenMode;}
   157     //
   158     void SetFrameDifferencing(bool aOn){iUseFrameDifferencing=aOn;}
   159     bool FrameDifferencing() const {return iUseFrameDifferencing;}
   160     //
   161     bool RequestPending(){return iRequest!=EMiniDisplayRequestNone;}
   162     TMiniDisplayRequest CurrentRequest(){return iRequest;}
   163     void CancelRequest(){iRequest=EMiniDisplayRequestNone;}
   164     TMiniDisplayRequest AttemptRequestCompletion();
   165     FutabaVfdReport& InputReport() {return iInputReport;}
   166     bool PowerOn();
   167 	char* DeviceId();
   168 	char* FirmwareRevision();
   169 
   170 private:
   171 	enum DW
   172 		{
   173         DW1=0xC0,
   174         DW2=0xD0
   175 		};
   176 
   177 	void SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY);
   178 	unsigned char OffScreenY() const;
   179 	void SendClearCommand();
   180 	void OffScreenTranslation(unsigned char& aX, unsigned char& aY);
   181 	void ResetBuffers();
   182     void SendModifiedPixelBlocks();
   183 
   184 private:
   185 	unsigned char iDisplayPositionX;
   186 	unsigned char iDisplayPositionY;
   187 	///Off screen mode is the recommended default settings to avoid tearing.
   188 	///Though turning it off can be useful for debugging
   189 	bool iOffScreenMode;
   190     ///Frame differences algo is used to reduce USB bus traffic and improve frame rate in typical use case
   191     bool iUseFrameDifferencing;
   192 	///
   193 	//FutabaVfdReport iReport;
   194 	///
   195 	//unsigned char iFrameBuffer[256*64];
   196     BitArray* iFrameNext;
   197     BitArray* iFrameCurrent;
   198     BitArray* iFramePrevious;
   199     //
   200     BitArray* iFrameAlpha;
   201     BitArray* iFrameBeta;
   202     BitArray* iFrameGamma;
   203     //
   204     int iNeedFullFrameUpdate;
   205 	//unsigned char iFrameBeta[256*64];
   206 	//unsigned char *iFrontBuffer;
   207 	//unsigned char *iBackBuffer;
   208     TMiniDisplayRequest iRequest;
   209     FutabaVfdReport iInputReport;
   210 	//
   211 	char iDeviceId[KFutabaMaxHidReportSize];
   212 	char iFirmwareRevision[KFutabaMaxHidReportSize];
   213     bool iPowerOn;
   214 	};
   215 
   216 
   217 #endif