FutabaMDM166AA.h
author StephaneLenclud
Wed, 04 Feb 2015 21:47:17 +0100
changeset 25 3fa4007c0b19
child 27 949be5444c57
permissions -rw-r--r--
First draft implementation of Futaba MDM166AA.
Only clock and brightness working for now.
     1 //
     2 //
     3 //
     4 
     5 #ifndef FUTABA_MDM166AA_H
     6 #define FUTABA_MDM166AA_H
     7 
     8 #include "FutabaVfd.h"
     9 
    10 
    11 const int KMDM166AAWidthInPixels = 96;
    12 const int KMDM166AAHeightInPixels = 16;
    13 const int KMDM166AAPixelsPerByte = 8;
    14 const int KMDM166AAFrameBufferSizeInBytes = KMDM166AAWidthInPixels*KMDM166AAHeightInPixels/KMDM166AAPixelsPerByte; //96*16/8=192
    15 const int KMDM166AAFrameBufferPixelCount = KMDM166AAWidthInPixels*KMDM166AAHeightInPixels;
    16 
    17 
    18 /**
    19 MDM166AA is a graphic display module using a FUTABA 96x16dots VFD.
    20 */
    21 class MDM166AA : public FutabaGraphicDisplay
    22 	{
    23 public:
    24 
    25     MDM166AA();
    26     ~MDM166AA();
    27 
    28 	//From DisplayBase
    29 	virtual int Open();
    30 	virtual void SwapBuffers();
    31 		//Brightness support
    32     virtual int MinBrightness() const {return 0;}
    33     virtual int MaxBrightness() const {return 2;}
    34 	virtual void SetBrightness(int aBrightness);
    35 		//Clock support
    36 	virtual void ShowClock();
    37 	virtual void HideClock();
    38 	virtual bool SupportClock(){return true;}
    39 
    40 	//From GraphicDisplay
    41     virtual int WidthInPixels() const {return KMDM166AAWidthInPixels;}
    42     virtual int HeightInPixels() const {return KMDM166AAHeightInPixels;}
    43 
    44 	virtual void SetPixel(unsigned char aX, unsigned char aY, unsigned int aPixel);
    45 	virtual void SetAllPixels(unsigned char aPattern);
    46     virtual int FrameBufferSizeInBytes() const {return KMDM166AAFrameBufferSizeInBytes;}	
    47 	virtual void Clear();
    48 	virtual void Fill();
    49 	virtual void Request(TMiniDisplayRequest aRequest);
    50 		
    51 	//
    52 	void ToggleOffScreenMode();
    53     void SetOffScreenMode(bool aOn);
    54     bool OffScreenMode() const {return iOffScreenMode;}
    55     //
    56     void SetFrameDifferencing(bool aOn){iUseFrameDifferencing=aOn;}
    57     bool FrameDifferencing() const {return iUseFrameDifferencing;}
    58     //    
    59     TMiniDisplayRequest AttemptRequestCompletion();
    60     FutabaVfdReport& InputReport() {return iInputReport;}
    61     bool IsPowerOn();
    62 	char* DeviceId();
    63 	char* FirmwareRevision();
    64 
    65 private:
    66 
    67 	enum TClockFormat
    68 	{
    69 		EClock12	=	0x00,
    70 		EClock24	=	0x01,
    71 	};
    72 
    73 	enum TClockSize
    74 	{
    75 		EClockSmall		=	0x01,
    76 		EClockLarge		=	0x02
    77 	};
    78 	
    79 
    80 private:
    81 	//Specific to MDM166AA
    82 	//General setting command
    83 	void SendCommandClear();
    84 	void SendCommandReset();
    85 	void SendCommandSetAddressCounter(unsigned char aAddressCounter);
    86 	//void SendCommandWriteGraphicData();
    87 	//
    88 	//Clock commands
    89 	void SendCommandClockSetting(unsigned char aHour, unsigned char aMinute);
    90 	void SendCommandClockDisplay(TClockSize aClockSize, TClockFormat aClockFormat);	
    91 
    92 	void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels);
    93 
    94 private:
    95     void RequestDeviceId();
    96     void RequestFirmwareRevision();
    97     void RequestPowerSupplyStatus();
    98 	//
    99 	void SetClockSetting();
   100 
   101 
   102 private:
   103 	unsigned char OffScreenY() const;	
   104 	void OffScreenTranslation(unsigned char& aX, unsigned char& aY);
   105 	void ResetBuffers();
   106 
   107 private:
   108 	unsigned char iDisplayPositionX;
   109 	unsigned char iDisplayPositionY;
   110 	///Off screen mode is the recommended default settings to avoid tearing.
   111 	///Though turning it off can be useful for debugging
   112 	bool iOffScreenMode;
   113     ///Frame differences algo is used to reduce USB bus traffic and improve frame rate in typical use case
   114     bool iUseFrameDifferencing;
   115 	///
   116 	//FutabaVfdReport iReport;
   117 	///
   118 	//unsigned char iFrameBuffer[256*64];
   119     BitArrayLow* iFrameNext;
   120     BitArrayLow* iFrameCurrent;
   121     BitArrayLow* iFramePrevious;
   122     //
   123     BitArrayLow* iFrameAlpha;
   124     BitArrayLow* iFrameBeta;
   125     BitArrayLow* iFrameGamma;
   126     //
   127     int iNeedFullFrameUpdate;
   128 	//unsigned char iFrameBeta[256*64];
   129 	//unsigned char *iFrontBuffer;
   130 	//unsigned char *iBackBuffer;
   131     FutabaVfdReport iInputReport;
   132 	//
   133 	char iDeviceId[KFutabaMaxHidReportSize];
   134 	char iFirmwareRevision[KFutabaMaxHidReportSize];
   135     bool iPowerOn;
   136 	};
   137 
   138 
   139 
   140 #endif