inc/FutabaVfd.h
author sl
Tue, 27 May 2014 17:49:33 +0200
changeset 27 ee1305f3a6bf
parent 25 233a997193b8
permissions -rw-r--r--
Experimenting with our bitmap to bitarray convertion.
     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 
    12 #ifndef MIN
    13 #define MIN(a,b) (((a)<(b))?(a):(b))
    14 #endif
    15 
    16 #ifndef MAX
    17 #define MAX(a,b) (((a)>(b))?(a):(b))
    18 #endif
    19 
    20 
    21 //This was computed from our number of pixels as follow 256x64/8/64 = 32 + 1 = 33
    22 //+1 was added for our header
    23 const int KFutabaMaxCommandOutputReport = 33;
    24 //TODO: Get ride of that constant once we figure out a way to get it from hidapi
    25 const int KFutabaMaxHidReportSize = 65;
    26 
    27 const int KHidReportIdIndex=0;
    28 const int KFutabaHidReportSizeIndex=1;
    29 //Define Futaba vendor ID to filter our list of device
    30 const unsigned short KFutabaVendorId = 0x1008;
    31 const unsigned short KFutabaProductIdGP1212A01A = 0x100C;
    32 const unsigned short KFutabaProductIdGP1212A02A = 0x1013; //Or is it 0x1015
    33 const int KGP12xWidthInPixels = 256;
    34 const int KGP12xHeightInPixels = 64;
    35 const int KGP12xPixelsPerByte = 8;
    36 const int KGP12xFrameBufferSizeInBytes = KGP12xWidthInPixels*KGP12xHeightInPixels/KGP12xPixelsPerByte; //256*64/8=2048
    37 const int KGP12xFrameBufferPixelCount = KGP12xWidthInPixels*KGP12xHeightInPixels;
    38 
    39 //typedef struct hid_device_info HidDeviceInfo;
    40 
    41 /**
    42 Define a Futaba HID report.
    43 */
    44 class FutabaVfdReport: public HidReport<KFutabaMaxHidReportSize>
    45 	{
    46 
    47 private:
    48 
    49 	};
    50 
    51 
    52 /**
    53 Define a generic Futaba VFD command.
    54 */
    55 class FutabaVfdCommand
    56     {
    57 public:
    58     FutabaVfdCommand();
    59     ~FutabaVfdCommand();
    60     //
    61     //void Create(int aMaxSize);
    62     //void Delete();
    63 
    64     //inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];}
    65 
    66     void Reset();
    67 
    68 private:
    69     //unsigned char* iBuffer;
    70     FutabaVfdReport iReports[KFutabaMaxCommandOutputReport];
    71     int iSize;
    72     int iMaxSize;
    73     };
    74 
    75 /**
    76 */
    77 class FutabaVfd : public HidDevice
    78 	{
    79 public:
    80 	virtual int MinBrightness() const=0;
    81 	virtual int MaxBrightness() const=0;
    82 	virtual void SetBrightness(int aBrightness)=0;
    83 	virtual void Clear()=0;
    84 	};
    85 
    86 
    87 /**
    88 */
    89 class FutabaGraphicVfd : public FutabaVfd
    90 	{
    91 public:
    92 	virtual int WidthInPixels() const=0;
    93 	virtual int HeightInPixels() const=0;
    94 	virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn)=0;
    95 	virtual void SetAllPixels(unsigned char aOn)=0;
    96 	virtual int FrameBufferSizeInBytes() const=0;
    97 	//virtual int BitBlit(unsigned char* aSrc, unsigned char aSrcWidth, unsigned char aSrcHeight, unsigned char aTargetX, unsigned char aTargetY) const=0;
    98 
    99 	};
   100 
   101 /**
   102 Common functionality between GP1212A01A and GP1212A02A
   103 */
   104 class GP1212XXXX : public FutabaGraphicVfd
   105 	{
   106 public:
   107 	//From FutabaVfd
   108 	virtual int MinBrightness() const {return 0;};
   109 	virtual int MaxBrightness() const {return 5;};
   110 	};
   111 
   112 /**
   113 GP1212A01A is a graphic display module using a FUTABA 256x64dots VFD.
   114 The module do not include character ROM, the customer will compile the character
   115 by themselves (from main system).
   116 */
   117 class GP1212A01A : public GP1212XXXX
   118 	{
   119 public:
   120 	GP1212A01A();
   121 	~GP1212A01A();
   122 	//
   123 	int Open();
   124 	//From FutabaGraphicVfd
   125 	virtual int WidthInPixels() const {return KGP12xWidthInPixels;};
   126 	virtual int HeightInPixels() const {return KGP12xHeightInPixels;};
   127 	virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn);
   128 	virtual void SetAllPixels(unsigned char aPattern);
   129 	virtual int FrameBufferSizeInBytes() const {return KGP12xFrameBufferSizeInBytes;};
   130 	virtual void BitBlit(BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const;
   131 	//From FutabaVfd
   132 	virtual void SetBrightness(int aBrightness);
   133 	virtual void Clear();
   134 
   135 	//Specific to GP1212A01A
   136 	void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue);
   137     void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels);
   138     //
   139 	void SetDisplayPosition(unsigned char aX, unsigned char aY);
   140 	void SwapBuffers();
   141     //
   142     void RequestId();
   143     void RequestFirmwareRevision();
   144     void RequestPowerSupplyStatus();
   145 	//
   146 	void ToggleOffScreenMode();
   147 	bool OffScreenMode() const {return iOffScreenMode;};
   148 	//
   149 
   150 	
   151 private:
   152 	enum DW
   153 		{
   154         DW1=0xC0,
   155         DW2=0xD0
   156 		};
   157 
   158 	void SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY);
   159 	unsigned char OffScreenY() const;
   160 	void SendClearCommand();
   161 	void OffScreenTranslation(unsigned char& aX, unsigned char& aY);
   162 	void ResetBuffers();
   163 
   164 private:
   165 	unsigned char iDisplayPositionX;
   166 	unsigned char iDisplayPositionY;
   167 	///Off screen mode is the recommended default settings to avoid tearing.
   168 	///Though turning it off can be useful for debugging
   169 	bool iOffScreenMode;
   170 	///
   171 	//FutabaVfdReport iReport;
   172 	///
   173 	//unsigned char iFrameBuffer[256*64];
   174 	BitArray* iFrameBuffer;
   175 	//unsigned char iFrameBeta[256*64];
   176 	//unsigned char *iFrontBuffer;
   177 	//unsigned char *iBackBuffer;
   178 	};
   179 
   180 
   181 #endif