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