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