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