sl@9
|
1 |
|
sl@9
|
2 |
#include "FutabaVfd.h"
|
sl@9
|
3 |
//#include <stdlib.h>
|
sl@9
|
4 |
#include <string.h>
|
sl@9
|
5 |
|
sl@10
|
6 |
|
sl@10
|
7 |
//
|
sl@10
|
8 |
//
|
sl@10
|
9 |
//
|
sl@10
|
10 |
|
sl@10
|
11 |
|
sl@10
|
12 |
|
sl@10
|
13 |
|
sl@10
|
14 |
|
sl@10
|
15 |
//
|
sl@10
|
16 |
//
|
sl@10
|
17 |
//
|
sl@10
|
18 |
|
sl@9
|
19 |
FutabaVfdCommand::FutabaVfdCommand():/*iBuffer(NULL),*/iSize(0),iMaxSize(0)
|
sl@9
|
20 |
{
|
sl@9
|
21 |
}
|
sl@9
|
22 |
|
sl@9
|
23 |
FutabaVfdCommand::~FutabaVfdCommand()
|
sl@9
|
24 |
{
|
sl@9
|
25 |
//Delete();
|
sl@9
|
26 |
}
|
sl@9
|
27 |
|
sl@9
|
28 |
|
sl@9
|
29 |
/**
|
sl@9
|
30 |
|
sl@9
|
31 |
*/
|
sl@9
|
32 |
void FutabaVfdCommand::Reset()
|
sl@9
|
33 |
{
|
sl@9
|
34 |
memset(iReports,0,sizeof(iReports));
|
sl@9
|
35 |
}
|
sl@9
|
36 |
|
sl@9
|
37 |
|
sl@9
|
38 |
|
sl@9
|
39 |
/**
|
sl@9
|
40 |
|
sl@9
|
41 |
*/
|
sl@9
|
42 |
/*
|
sl@9
|
43 |
void FutabaVfdCommand::Create(int aMaxSize)
|
sl@9
|
44 |
{
|
sl@9
|
45 |
iBuffer=new unsigned char[aMaxSize];
|
sl@9
|
46 |
if (iBuffer)
|
sl@9
|
47 |
{
|
sl@9
|
48 |
iMaxSize = aMaxSize;
|
sl@9
|
49 |
iSize = 0;
|
sl@9
|
50 |
}
|
sl@9
|
51 |
}
|
sl@9
|
52 |
*/
|
sl@9
|
53 |
|
sl@9
|
54 |
/**
|
sl@9
|
55 |
|
sl@9
|
56 |
*/
|
sl@9
|
57 |
/*
|
sl@9
|
58 |
void FutabaVfdCommand::Delete()
|
sl@9
|
59 |
{
|
sl@9
|
60 |
delete[] iBuffer;
|
sl@9
|
61 |
iBuffer = NULL;
|
sl@9
|
62 |
iMaxSize = 0;
|
sl@9
|
63 |
iSize = 0;
|
sl@9
|
64 |
}
|
sl@9
|
65 |
*/
|
sl@9
|
66 |
|
sl@9
|
67 |
|
sl@10
|
68 |
//
|
sl@10
|
69 |
// class HidDevice
|
sl@10
|
70 |
//
|
sl@10
|
71 |
|
sl@10
|
72 |
/**
|
sl@10
|
73 |
*/
|
sl@10
|
74 |
int HidDevice::Open(const char* aPath)
|
sl@10
|
75 |
{
|
sl@10
|
76 |
Close();
|
sl@10
|
77 |
|
sl@10
|
78 |
iHidDevice = hid_open_path(aPath);
|
sl@10
|
79 |
|
sl@10
|
80 |
if (!iHidDevice)
|
sl@10
|
81 |
{
|
sl@10
|
82 |
//Fail to connect our device
|
sl@10
|
83 |
return 0;
|
sl@10
|
84 |
}
|
sl@10
|
85 |
|
sl@10
|
86 |
return 1;
|
sl@10
|
87 |
}
|
sl@10
|
88 |
|
sl@10
|
89 |
/**
|
sl@10
|
90 |
See hidapi documentation.
|
sl@10
|
91 |
*/
|
sl@10
|
92 |
int HidDevice::Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber)
|
sl@10
|
93 |
{
|
sl@10
|
94 |
iHidDevice = hid_open(aVendorId, aProductId, aSerialNumber);
|
sl@10
|
95 |
|
sl@10
|
96 |
if (!iHidDevice)
|
sl@10
|
97 |
{
|
sl@10
|
98 |
//Fail to connect our device
|
sl@10
|
99 |
return 0;
|
sl@10
|
100 |
}
|
sl@10
|
101 |
|
sl@10
|
102 |
return 1;
|
sl@10
|
103 |
}
|
sl@10
|
104 |
|
sl@10
|
105 |
/**
|
sl@10
|
106 |
*/
|
sl@10
|
107 |
void HidDevice::Close()
|
sl@10
|
108 |
{
|
sl@10
|
109 |
hid_close(iHidDevice);
|
sl@10
|
110 |
iHidDevice=NULL;
|
sl@10
|
111 |
}
|
sl@10
|
112 |
|
sl@13
|
113 |
/**
|
sl@13
|
114 |
*/
|
sl@13
|
115 |
bool HidDevice::IsOpen()
|
sl@13
|
116 |
{
|
sl@13
|
117 |
return iHidDevice!=NULL;
|
sl@13
|
118 |
}
|
sl@13
|
119 |
|
sl@10
|
120 |
|
sl@10
|
121 |
/**
|
sl@10
|
122 |
*/
|
sl@10
|
123 |
const wchar_t* HidDevice::Error()
|
sl@10
|
124 |
{
|
sl@10
|
125 |
return hid_error(iHidDevice);
|
sl@10
|
126 |
}
|
sl@10
|
127 |
|
sl@10
|
128 |
/**
|
sl@10
|
129 |
*/
|
sl@10
|
130 |
int HidDevice::SetNonBlocking(int aNonBlocking)
|
sl@10
|
131 |
{
|
sl@13
|
132 |
//Success we are now connected to our HID device
|
sl@10
|
133 |
//Set read operation as non blocking
|
sl@10
|
134 |
return hid_set_nonblocking(iHidDevice, aNonBlocking);
|
sl@10
|
135 |
}
|
sl@10
|
136 |
|
sl@10
|
137 |
|
sl@10
|
138 |
//
|
sl@10
|
139 |
// class GP1212A01A
|
sl@10
|
140 |
//
|
sl@10
|
141 |
|
sl@10
|
142 |
int GP1212A01A::Open()
|
sl@10
|
143 |
{
|
sl@10
|
144 |
int success = HidDevice::Open(KFutabaVendorId,KFutabaProductIdGP1212A01A,NULL);
|
sl@10
|
145 |
if (success)
|
sl@10
|
146 |
{
|
sl@10
|
147 |
SetNonBlocking(1);
|
sl@10
|
148 |
}
|
sl@10
|
149 |
return success;
|
sl@10
|
150 |
}
|
sl@10
|
151 |
|
sl@10
|
152 |
/**
|
sl@10
|
153 |
*/
|
sl@10
|
154 |
void GP1212A01A::SetPixel(int aX, int aY, bool aOn)
|
sl@10
|
155 |
{
|
sl@10
|
156 |
//Just specify a one pixel block
|
sl@10
|
157 |
SetPixelBlock(aX,aY,0x00,0x01,aOn);
|
sl@10
|
158 |
}
|
sl@10
|
159 |
|
sl@10
|
160 |
/**
|
sl@10
|
161 |
*/
|
sl@10
|
162 |
void GP1212A01A::SetAllPixels(bool aOn)
|
sl@10
|
163 |
{
|
sl@10
|
164 |
//One pixel at a time
|
sl@10
|
165 |
/*
|
sl@10
|
166 |
for (int i=0;i<256;i++)
|
sl@10
|
167 |
{
|
sl@10
|
168 |
for (int j=0;j<64;j++)
|
sl@10
|
169 |
{
|
sl@10
|
170 |
SetPixel(i,j,0x01);
|
sl@10
|
171 |
}
|
sl@10
|
172 |
}
|
sl@10
|
173 |
*/
|
sl@10
|
174 |
|
sl@10
|
175 |
//16x16=256 pixels at a time goes much faster
|
sl@10
|
176 |
//TODO: use even larger blocks
|
sl@10
|
177 |
for (int i=0;i<256;i+=16)
|
sl@10
|
178 |
{
|
sl@10
|
179 |
for (int j=0;j<64;j+=16)
|
sl@10
|
180 |
{
|
sl@10
|
181 |
SetPixelBlock(i,j,15,32,(aOn?0xFF:0x00));
|
sl@10
|
182 |
//FXThread::sleep(1000000000);
|
sl@10
|
183 |
}
|
sl@10
|
184 |
}
|
sl@10
|
185 |
|
sl@10
|
186 |
}
|
sl@10
|
187 |
|
sl@10
|
188 |
/**
|
sl@10
|
189 |
*/
|
sl@10
|
190 |
void GP1212A01A::SetBrightness(int aBrightness)
|
sl@10
|
191 |
{
|
sl@10
|
192 |
}
|
sl@10
|
193 |
|
sl@10
|
194 |
/**
|
sl@10
|
195 |
Set the defined pixel block to the given value.
|
sl@10
|
196 |
@param X coordinate of our pixel block starting point.
|
sl@10
|
197 |
@param Y coordinate of our pixel block starting point.
|
sl@10
|
198 |
@param The height of our pixel block.
|
sl@10
|
199 |
@param The size of our pixel data. Number of pixels divided by 8.
|
sl@10
|
200 |
@param The value set to 8 pixels.
|
sl@10
|
201 |
*/
|
sl@10
|
202 |
void GP1212A01A::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue)
|
sl@10
|
203 |
{
|
sl@10
|
204 |
//Size must be 63 or below
|
sl@10
|
205 |
FutabaVfdReport report;
|
sl@10
|
206 |
report[0]=0x00; //Report ID
|
sl@10
|
207 |
report[1]=0x08+aSize; //Report length
|
sl@10
|
208 |
report[2]=0x1B; //
|
sl@10
|
209 |
report[3]=0x5B; //
|
sl@10
|
210 |
report[4]=0xF0; //
|
sl@10
|
211 |
report[5]=aX; //X
|
sl@10
|
212 |
report[6]=aY; //Y
|
sl@10
|
213 |
report[7]=aHeight; //Y length before return. Though outside the specs, setting this to zero apparently allows us to modify a single pixel without touching any other.
|
sl@10
|
214 |
report[8]=0x00; //Size of pixel data in bytes (MSB)
|
sl@10
|
215 |
report[9]=aSize; //Size of pixel data in bytes (LSB)
|
sl@11
|
216 |
memset(report.Buffer()+10, aValue, aSize);
|
sl@10
|
217 |
//iOutputReportBuffer[10]=aValue; //Pixel data
|
sl@10
|
218 |
Write(report);
|
sl@10
|
219 |
}
|
sl@10
|
220 |
|
sl@10
|
221 |
|
sl@10
|
222 |
/**
|
sl@10
|
223 |
*/
|
sl@10
|
224 |
void GP1212A01A::Clear()
|
sl@10
|
225 |
{
|
sl@10
|
226 |
FutabaVfdReport report;
|
sl@10
|
227 |
report[0]=0x00; //Report ID
|
sl@10
|
228 |
report[1]=0x04; //Report length
|
sl@10
|
229 |
report[2]=0x1B; //
|
sl@10
|
230 |
report[3]=0x5B; //
|
sl@10
|
231 |
report[4]=0x32; //
|
sl@10
|
232 |
report[5]=0x4A; //
|
sl@10
|
233 |
Write(report);
|
sl@10
|
234 |
} |