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