Fixing qml warnings.
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():
75 iDisplayPositionX(0),iDisplayPositionY(0),
76 iOffScreenMode(true),iFrameBuffer(NULL),iRequest(ERequestNone),iPowerOn(false)
83 GP1212A01A::~GP1212A01A()
91 int GP1212A01A::Open()
93 int success = HidDevice::Open(KFutabaVendorId,KFutabaProductIdGP1212A01A,NULL);
98 iFrameBuffer=new BitArray(KGP12xFrameBufferPixelCount);
100 //Since we can't get our display position we force it to our default
101 //This makes sure frames are in sync from the start
102 //Clever clients will have taken care of putting back frame (0,0) before closing
103 SetDisplayPosition(iDisplayPositionX,iDisplayPositionY);
110 void GP1212A01A::SetPixel(unsigned char aX, unsigned char aY, bool aOn)
112 //Just specify a one pixel block
113 //SetPixelBlock(aX,aY,0x00,0x01,aOn);
115 //int byteOffset=(aX*HeightInPixels()+aY)/8;
116 //int bitOffset=(aX*HeightInPixels()+aY)%8;
117 //iFrameBuffer[byteOffset] |= ( (aOn?0x01:0x00) << bitOffset );
120 iFrameBuffer->SetBit(aX*HeightInPixels()+aY);
124 iFrameBuffer->ClearBit(aX*HeightInPixels()+aY);
130 void GP1212A01A::BitBlit(const BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const
132 //TODO: amend loop values so that we don't keep on looping past our frame buffer dimensions.
133 for (int i=0;i<aSrcWidth;i++)
135 for (int j=0;j<aSrcHeight;j++)
137 iFrameBuffer->SetBitValue((aTargetX+i)*HeightInPixels()+aTargetY+j,aBitmap[+i*aSrcHeight+j]);
143 Set all pixels on our screen to the desired value.
144 This operation is performed off screen to avoid tearing.
145 @param 8 pixels pattern
147 void GP1212A01A::SetAllPixels(unsigned char aPattern)
149 //With a single buffer
150 //unsigned char screen[2048]; //One screen worth of pixels
151 //memset(screen,0xFF,sizeof(screen));
152 //SetPixelBlock(0,0,63,sizeof(screen),screen);
154 //Using pattern SetPixelBlock variant.
155 memset(iFrameBuffer->Ptr(),aPattern,FrameBufferSizeInBytes());
162 Set our screen brightness.
163 @param The desired brightness level. Must be between MinBrightness and MaxBrightness.
165 void GP1212A01A::SetBrightness(int aBrightness)
167 if (aBrightness<MinBrightness()||aBrightness>MaxBrightness())
169 //Brightness out of range.
170 //Just ignore that request.
174 FutabaVfdReport report;
175 report[0]=0x00; //Report ID
176 report[1]=0x06; //Report size
177 report[2]=0x1B; //Command ID
178 report[3]=0x5C; //Command ID
179 report[4]=0x3F; //Command ID
180 report[5]=0x4C; //Command ID
181 report[6]=0x44; //Command ID
182 report[7]=0x30+aBrightness; //Brightness level
188 Set the defined pixel block to the given value.
189 @param X coordinate of our pixel block starting point.
190 @param Y coordinate of our pixel block starting point.
191 @param The height of our pixel block.
192 @param The size of our pixel data. Number of pixels divided by 8.
193 @param The value set to 8 pixels used as a pattern.
195 void GP1212A01A::SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue)
197 OffScreenTranslation(aX,aY);
198 FutabaVfdReport report;
199 report[0]=0x00; //Report ID
200 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
201 report[2]=0x1B; //Command ID
202 report[3]=0x5B; //Command ID
203 report[4]=0xF0; //Command ID
206 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.
207 report[8]=aSize>>8; //Size of pixel data in bytes (MSB)
208 report[9]=aSize; //Size of pixel data in bytes (LSB)
209 int sizeWritten=MIN(aSize,report.Size()-10);
210 memset(report.Buffer()+10, aValue, sizeWritten);
213 int remainingSize=aSize;
214 //We need to keep on sending our pixel data until we are done
215 while (report[1]==64)
218 remainingSize-=sizeWritten;
219 report[0]=0x00; //Report ID
220 report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
221 sizeWritten=(report[1]==64?63:report[1]);
222 memset(report.Buffer()+2, aValue, sizeWritten);
228 Set the defined pixel block to the given value.
229 @param X coordinate of our pixel block starting point.
230 @param Y coordinate of our pixel block starting point.
231 @param The height of our pixel block.
232 @param The size of our pixel data. Number of pixels divided by 8.
233 @param Pointer to our pixel data.
235 void GP1212A01A::SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels)
237 OffScreenTranslation(aX,aY);
238 FutabaVfdReport report;
239 report[0]=0x00; //Report ID
240 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
241 report[2]=0x1B; //Command ID
242 report[3]=0x5B; //Command ID
243 report[4]=0xF0; //Command ID
246 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.
247 report[8]=aSize>>8; //Size of pixel data in bytes (MSB)
248 report[9]=aSize; //Size of pixel data in bytes (LSB)
249 int sizeWritten=MIN(aSize,report.Size()-10);
250 memcpy(report.Buffer()+10, aPixels, sizeWritten);
253 int remainingSize=aSize;
254 //We need to keep on sending our pixel data until we are done
255 while (report[1]==64)
258 remainingSize-=sizeWritten;
259 report[0]=0x00; //Report ID
260 report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
261 sizeWritten=(report[1]==64?63:report[1]);
262 memcpy(report.Buffer()+2, aPixels+(aSize-remainingSize), sizeWritten);
269 Clear our client side back buffer.
270 Call to SwapBuffers must follow to actually clear the display.
272 void GP1212A01A::Clear()
274 //memset(iFrameBuffer->Ptr(),0x00,FrameBufferSizeInBytes());
275 iFrameBuffer->ClearAll();
279 Using this function is advised against as is causes tearing.
282 void GP1212A01A::SendClearCommand()
285 //Send Clear Display Command
286 FutabaVfdReport report;
287 report[0]=0x00; //Report ID
288 report[1]=0x04; //Report length
289 report[2]=0x1B; //Command ID
290 report[3]=0x5B; //Command ID
291 report[4]=0x32; //Command ID
292 report[5]=0x4A; //Command ID
297 Change our display position within our buffer.
299 void GP1212A01A::SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY)
302 //Send Display Position Settings Command
303 FutabaVfdReport report;
304 report[0]=0x00; //Report ID
305 report[1]=0x05; //Report length
306 report[2]=0x1B; //Command ID
307 report[3]=0x5B; //Command ID
308 report[4]=aDw; //Specify our DW
309 report[5]=aX; //X coordinate of our DW top-left corner
310 report[6]=aY; //Y coordinate of our DW top-left corner
315 Change our display position within our buffer.
317 void GP1212A01A::SetDisplayPosition(unsigned char aX, unsigned char aY)
319 //Specs apparently says both DW should remain the same
321 SetDisplayPosition(GP1212A01A::DW1,aX,aY);
322 SetDisplayPosition(GP1212A01A::DW2,aX,aY);
323 iDisplayPositionX=aX;
324 iDisplayPositionY=aY;
328 Provide Y coordinate of our off screen buffer.
330 unsigned char GP1212A01A::OffScreenY() const
332 //Overflowing is fine this is just what we want
333 return iDisplayPositionY+HeightInPixels();
337 Put our off screen buffer on screen.
338 On screen buffer goes off screen.
340 void GP1212A01A::SwapBuffers()
342 //Only perform buffer swapping if off screen mode is enabled
345 //Send host back buffer to device back buffer
346 SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),iFrameBuffer->Ptr());
347 //Swap device front and back buffer
348 SetDisplayPosition(iDisplayPositionX,OffScreenY());
350 //unsigned char* backBuffer=iBackBuffer;
351 //iBackBuffer = iFrontBuffer;
352 //iFrontBuffer = backBuffer;
357 Translate the given pixel coordinate according to our off screen mode.
359 void GP1212A01A::OffScreenTranslation(unsigned char& aX, unsigned char& aY)
363 aX+=WidthInPixels()-iDisplayPositionX;
364 aY+=HeightInPixels()-iDisplayPositionY;
371 void GP1212A01A::ResetBuffers()
373 //iFrameBuffer->ClearAll();
374 //memset(iFrameBuffer,0x00,sizeof(iFrameBuffer));
375 //memset(iFrameBeta,0x00,sizeof(iFrameBeta));
380 void GP1212A01A::RequestDeviceId()
382 if (RequestPending())
384 //Abort silently for now
388 //1BH,5BH,63H,49H,44H
389 //Send Read ID command
390 FutabaVfdReport report;
391 report[0]=0x00; //Report ID
392 report[1]=0x05; //Report length
393 report[2]=0x1B; //Command ID
394 report[3]=0x5B; //Command ID
395 report[4]=0x63; //Command ID
396 report[5]=0x49; //Command ID
397 report[6]=0x44; //Command ID
398 if (Write(report)==report.Size())
400 iRequest=ERequestDeviceId;
406 void GP1212A01A::RequestFirmwareRevision()
408 if (RequestPending())
410 //Abort silently for now
414 //1BH,5BH,63H,46H,52H
415 //Send Software Revision Read Command
416 FutabaVfdReport report;
417 report[0]=0x00; //Report ID
418 report[1]=0x05; //Report length
419 report[2]=0x1B; //Command ID
420 report[3]=0x5B; //Command ID
421 report[4]=0x63; //Command ID
422 report[5]=0x46; //Command ID
423 report[6]=0x52; //Command ID
424 if (Write(report)==report.Size())
426 iRequest=ERequestFirmwareRevision;
432 void GP1212A01A::RequestPowerSupplyStatus()
434 if (RequestPending())
436 //Abort silently for now
439 //1BH,5BH,63H,50H,4DH
440 //Send Power Suppply Monitor Command
441 FutabaVfdReport report;
442 report[0]=0x00; //Report ID
443 report[1]=0x05; //Report length
444 report[2]=0x1B; //Command ID
445 report[3]=0x5B; //Command ID
446 report[4]=0x63; //Command ID
447 report[5]=0x50; //Command ID
448 report[6]=0x4D; //Command ID
449 if (Write(report)==report.Size())
451 iRequest=ERequestPowerSupplyStatus;
457 This is for development purposes only.
458 Production application should stick to off-screen mode to avoid tearing.
460 void GP1212A01A::ToggleOffScreenMode()
462 iOffScreenMode=!iOffScreenMode;
463 //Clean up our buffers upon switching modes
464 SetDisplayPosition(0,0);
472 GP1212A01A::Request GP1212A01A::AttemptRequestCompletion()
474 if (!RequestPending())
479 int res=Read(iInputReport);
486 //Process our request
487 if (CurrentRequest()==GP1212A01A::ERequestPowerSupplyStatus)
489 if (iInputReport[1]==0x4F && iInputReport[2]==0x4E)
493 else if (iInputReport[1]==0x4F && iInputReport[2]==0x46 && iInputReport[3]==0x46)
499 Request completed=iRequest;
500 //Our request was completed
501 iRequest=ERequestNone;