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