Draft implementation of our bitmap to display format.
19 FutabaVfdCommand::FutabaVfdCommand():/*iBuffer(NULL),*/iSize(0),iMaxSize(0)
23 FutabaVfdCommand::~FutabaVfdCommand()
32 void FutabaVfdCommand::Reset()
34 memset(iReports,0,sizeof(iReports));
43 void FutabaVfdCommand::Create(int aMaxSize)
45 iBuffer=new unsigned char[aMaxSize];
58 void FutabaVfdCommand::Delete()
74 GP1212A01A::GP1212A01A():iDisplayPositionX(0),iDisplayPositionY(0),iOffScreenMode(true)
78 int GP1212A01A::Open()
80 int success = HidDevice::Open(KFutabaVendorId,KFutabaProductIdGP1212A01A,NULL);
84 //Since we can't get our display position we for it to our default
85 //This makes sure frames are in sync from the start
86 SetDisplayPosition(iDisplayPositionX,iDisplayPositionY);
93 void GP1212A01A::SetPixel(unsigned char aX, unsigned char aY, bool aOn)
95 //Just specify a one pixel block
96 SetPixelBlock(aX,aY,0x00,0x01,aOn);
100 Set all pixels on our screen to the desired value.
101 This operation is performed off screen to avoid tearing.
102 @param 8 pixels pattern
104 void GP1212A01A::SetAllPixels(unsigned char aPattern)
106 //With a single buffer
107 //unsigned char screen[2048]; //One screen worth of pixels
108 //memset(screen,0xFF,sizeof(screen));
109 //SetPixelBlock(0,0,63,sizeof(screen),screen);
111 //Using pattern SetPixelBlock variant.
112 SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),aPattern);
116 Set our screen brightness.
117 @param The desired brightness level. Must be between MinBrightness and MaxBrightness.
119 void GP1212A01A::SetBrightness(int aBrightness)
121 if (aBrightness<MinBrightness()||aBrightness>MaxBrightness())
123 //Brightness out of range.
124 //Just ignore that request.
128 FutabaVfdReport report;
129 report[0]=0x00; //Report ID
130 report[1]=0x06; //Report size
131 report[2]=0x1B; //Command ID
132 report[3]=0x5C; //Command ID
133 report[4]=0x3F; //Command ID
134 report[5]=0x4C; //Command ID
135 report[6]=0x44; //Command ID
136 report[7]=0x30+aBrightness; //Brightness level
142 Set the defined pixel block to the given value.
143 @param X coordinate of our pixel block starting point.
144 @param Y coordinate of our pixel block starting point.
145 @param The height of our pixel block.
146 @param The size of our pixel data. Number of pixels divided by 8.
147 @param The value set to 8 pixels used as a pattern.
149 void GP1212A01A::SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue)
151 OffScreenTranslation(aX,aY);
152 FutabaVfdReport report;
153 report[0]=0x00; //Report ID
154 report[1]=(aSize<=report.Size()-10?aSize+0x08:64); //Report length. -10 is for our header first 10 bytes. +8 is for our Futaba header size
155 report[2]=0x1B; //Command ID
156 report[3]=0x5B; //Command ID
157 report[4]=0xF0; //Command ID
160 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.
161 report[8]=aSize>>8; //Size of pixel data in bytes (MSB)
162 report[9]=aSize; //Size of pixel data in bytes (LSB)
163 int sizeWritten=MIN(aSize,report.Size()-10);
164 memset(report.Buffer()+10, aValue, sizeWritten);
167 int remainingSize=aSize;
168 //We need to keep on sending our pixel data until we are done
169 while (report[1]==64)
172 remainingSize-=sizeWritten;
173 report[0]=0x00; //Report ID
174 report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
175 sizeWritten=(report[1]==64?63:report[1]);
176 memset(report.Buffer()+2, aValue, sizeWritten);
182 Set the defined pixel block to the given value.
183 @param X coordinate of our pixel block starting point.
184 @param Y coordinate of our pixel block starting point.
185 @param The height of our pixel block.
186 @param The size of our pixel data. Number of pixels divided by 8.
187 @param Pointer to our pixel data.
189 void GP1212A01A::SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels)
191 OffScreenTranslation(aX,aY);
192 FutabaVfdReport report;
193 report[0]=0x00; //Report ID
194 report[1]=(aSize<=report.Size()-10?aSize+0x08:64); //Report length. -10 is for our header first 10 bytes. +8 is for our Futaba header size
195 report[2]=0x1B; //Command ID
196 report[3]=0x5B; //Command ID
197 report[4]=0xF0; //Command ID
200 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.
201 report[8]=aSize>>8; //Size of pixel data in bytes (MSB)
202 report[9]=aSize; //Size of pixel data in bytes (LSB)
203 int sizeWritten=MIN(aSize,report.Size()-10);
204 memcpy(report.Buffer()+10, aPixels, sizeWritten);
207 int remainingSize=aSize;
208 //We need to keep on sending our pixel data until we are done
209 while (report[1]==64)
212 remainingSize-=sizeWritten;
213 report[0]=0x00; //Report ID
214 report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
215 sizeWritten=(report[1]==64?63:report[1]);
216 memcpy(report.Buffer()+2, aPixels+(aSize-remainingSize), sizeWritten);
223 Clear our display's screen.
224 This operation is performed off screen to avoid tearing.
226 void GP1212A01A::Clear()
228 //Using pattern SetPixelBlock variant.
229 //First fill our off screen buffer with the desired values
230 SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),(unsigned char)0x00);
234 Using this function is advised against as is causes tearing.
237 void GP1212A01A::SendClearCommand()
240 //Send Clear Display Command
241 FutabaVfdReport report;
242 report[0]=0x00; //Report ID
243 report[1]=0x04; //Report length
244 report[2]=0x1B; //Command ID
245 report[3]=0x5B; //Command ID
246 report[4]=0x32; //Command ID
247 report[5]=0x4A; //Command ID
252 Change our display position within our buffer.
254 void GP1212A01A::SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY)
257 //Send Display Position Settings Command
258 FutabaVfdReport report;
259 report[0]=0x00; //Report ID
260 report[1]=0x05; //Report length
261 report[2]=0x1B; //Command ID
262 report[3]=0x5B; //Command ID
263 report[4]=aDw; //Specify our DW
264 report[5]=aX; //X coordinate of our DW top-left corner
265 report[6]=aY; //Y coordinate of our DW top-left corner
270 Change our display position within our buffer.
272 void GP1212A01A::SetDisplayPosition(unsigned char aX, unsigned char aY)
274 //Specs apparently says both DW should remain the same
276 SetDisplayPosition(GP1212A01A::DW1,aX,aY);
277 SetDisplayPosition(GP1212A01A::DW2,aX,aY);
278 iDisplayPositionX=aX;
279 iDisplayPositionY=aY;
283 Provide Y coordinate of our off screen buffer.
285 unsigned char GP1212A01A::OffScreenY() const
287 //Overflowing is fine this is just what we want
288 return iDisplayPositionY+HeightInPixels();
292 Put our off screen buffer on screen.
293 On screen buffer goes off screen.
295 void GP1212A01A::SwapBuffers()
297 //Only perform buffer swapping if off screen mode is enabled
300 SetDisplayPosition(iDisplayPositionX,OffScreenY());
305 Translate the given pixel coordinate according to our off screen mode.
307 void GP1212A01A::OffScreenTranslation(unsigned char& aX, unsigned char& aY)
311 aX+=WidthInPixels()-iDisplayPositionX;
312 aY+=HeightInPixels()-iDisplayPositionY;
317 void GP1212A01A::RequestId()
319 //1BH,5BH,63H,49H,44H
320 //Send Read ID command
321 FutabaVfdReport report;
322 report[0]=0x00; //Report ID
323 report[1]=0x05; //Report length
324 report[2]=0x1B; //Command ID
325 report[3]=0x5B; //Command ID
326 report[4]=0x63; //Command ID
327 report[5]=0x49; //Command ID
328 report[6]=0x44; //Command ID
334 void GP1212A01A::RequestFirmwareRevision()
336 //1BH,5BH,63H,46H,52H
337 //Send Software Revision Read Command
338 FutabaVfdReport report;
339 report[0]=0x00; //Report ID
340 report[1]=0x05; //Report length
341 report[2]=0x1B; //Command ID
342 report[3]=0x5B; //Command ID
343 report[4]=0x63; //Command ID
344 report[5]=0x46; //Command ID
345 report[6]=0x52; //Command ID
351 void GP1212A01A::RequestPowerSupplyStatus()
353 //1BH,5BH,63H,50H,4DH
354 //Send Power Suppply Monitor Command
355 FutabaVfdReport report;
356 report[0]=0x00; //Report ID
357 report[1]=0x05; //Report length
358 report[2]=0x1B; //Command ID
359 report[3]=0x5B; //Command ID
360 report[4]=0x63; //Command ID
361 report[5]=0x50; //Command ID
362 report[6]=0x4D; //Command ID
368 This is for development purposes only.
369 Production application should stick to off-screen mode to avoid tearing.
371 void GP1212A01A::ToggleOffScreenMode()
373 iOffScreenMode=!iOffScreenMode;
374 //Clean up our buffers upon switching modes
375 SetDisplayPosition(0,0);