MiniDisplay/FutabaVfd.h
author sl
Thu, 29 May 2014 19:46:57 +0200
changeset 18 79801cc3bc94
parent 11 b935de604982
child 19 be04ffbb561c
permissions -rw-r--r--
Restoring some of our on-screen functionality for debug purposes.
We could prove that updating a single pixel is much faster than updating our
whole screen. Single pixel updates runs at full 24 FPS.
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@9
   120
    enum Request
sl@9
   121
        {
sl@9
   122
        ERequestNone,
sl@9
   123
        ERequestDeviceId,
sl@9
   124
        ERequestFirmwareRevision,
sl@9
   125
        ERequestPowerSupplyStatus
sl@9
   126
        };
sl@9
   127
sl@9
   128
public:
sl@9
   129
    GP1212A01A();
sl@9
   130
    ~GP1212A01A();
sl@9
   131
sl@4
   132
	//
sl@4
   133
	int Open();
sl@4
   134
	//From FutabaGraphicVfd
sl@4
   135
    virtual int WidthInPixels() const {return KGP12xWidthInPixels;}
sl@4
   136
    virtual int HeightInPixels() const {return KGP12xHeightInPixels;}
sl@4
   137
	virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn);
sl@4
   138
	virtual void SetAllPixels(unsigned char aPattern);
sl@4
   139
    virtual int FrameBufferSizeInBytes() const {return KGP12xFrameBufferSizeInBytes;}
sl@6
   140
    virtual void BitBlit(const BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const;
sl@4
   141
	//From FutabaVfd
sl@4
   142
	virtual void SetBrightness(int aBrightness);
sl@4
   143
	virtual void Clear();
sl@4
   144
sl@4
   145
	//Specific to GP1212A01A
sl@4
   146
	void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue);
sl@4
   147
    void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels);
sl@11
   148
    //Define display position within our display RAM
sl@11
   149
	void SetDisplayPosition(unsigned char aX, unsigned char aY);
sl@11
   150
    unsigned char DisplayPositionX() const {return iDisplayPositionX;}
sl@11
   151
    unsigned char DisplayPositionY() const {return iDisplayPositionY;}
sl@4
   152
    //
sl@4
   153
	void SwapBuffers();
sl@4
   154
    //
sl@9
   155
    void RequestDeviceId();
sl@4
   156
    void RequestFirmwareRevision();
sl@4
   157
    void RequestPowerSupplyStatus();
sl@4
   158
	//
sl@4
   159
	void ToggleOffScreenMode();
sl@18
   160
    void SetOffScreenMode(bool aOn);
sl@4
   161
    bool OffScreenMode() const {return iOffScreenMode;}
sl@4
   162
	//
sl@9
   163
    bool RequestPending(){return iRequest!=ERequestNone;}
sl@9
   164
    Request CurrentRequest(){return iRequest;}
sl@9
   165
    void CancelRequest(){iRequest=ERequestNone;}
sl@9
   166
    Request AttemptRequestCompletion();
sl@9
   167
    FutabaVfdReport& InputReport() {return iInputReport;}
sl@9
   168
    bool PowerOn(){return iPowerOn;}
sl@4
   169
	
sl@4
   170
private:
sl@4
   171
	enum DW
sl@4
   172
		{
sl@4
   173
        DW1=0xC0,
sl@4
   174
        DW2=0xD0
sl@4
   175
		};
sl@4
   176
sl@4
   177
	void SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY);
sl@4
   178
	unsigned char OffScreenY() const;
sl@4
   179
	void SendClearCommand();
sl@4
   180
	void OffScreenTranslation(unsigned char& aX, unsigned char& aY);
sl@4
   181
	void ResetBuffers();
sl@4
   182
sl@4
   183
private:
sl@4
   184
	unsigned char iDisplayPositionX;
sl@4
   185
	unsigned char iDisplayPositionY;
sl@4
   186
	///Off screen mode is the recommended default settings to avoid tearing.
sl@4
   187
	///Though turning it off can be useful for debugging
sl@4
   188
	bool iOffScreenMode;
sl@4
   189
	///
sl@4
   190
	//FutabaVfdReport iReport;
sl@4
   191
	///
sl@4
   192
	//unsigned char iFrameBuffer[256*64];
sl@4
   193
	BitArray* iFrameBuffer;
sl@4
   194
	//unsigned char iFrameBeta[256*64];
sl@4
   195
	//unsigned char *iFrontBuffer;
sl@4
   196
	//unsigned char *iBackBuffer;
sl@9
   197
    Request iRequest;
sl@9
   198
    FutabaVfdReport iInputReport;
sl@9
   199
    bool iPowerOn;
sl@4
   200
	};
sl@4
   201
sl@4
   202
sl@4
   203
#endif