FutabaGP1212A01.cpp
author sl
Thu, 21 Aug 2014 21:53:35 +0200
changeset 9 6b08e3e81cf3
child 10 1c3a4964a5bd
permissions -rw-r--r--
Still working on our architecture to support GP1212A02
sl@8
     1
//
sl@8
     2
//
sl@8
     3
//
sl@8
     4
sl@8
     5
#include "FutabaGP1212A01.h"
sl@8
     6
sl@8
     7
const int KNumberOfFrameBeforeDiffAlgo = 3;
sl@8
     8
sl@8
     9
//
sl@8
    10
// class GP1212A01A
sl@8
    11
//
sl@8
    12
sl@8
    13
GP1212A01A::GP1212A01A():
sl@8
    14
	iDisplayPositionX(0),iDisplayPositionY(0),
sl@8
    15
    iOffScreenMode(true),
sl@8
    16
    iUseFrameDifferencing(true),
sl@8
    17
    iFrameNext(NULL),
sl@8
    18
    iFrameCurrent(NULL),
sl@8
    19
    iFramePrevious(NULL),
sl@8
    20
    iFrameAlpha(NULL),
sl@8
    21
    iFrameBeta(NULL),
sl@8
    22
    iFrameGamma(NULL),
sl@8
    23
    iNeedFullFrameUpdate(0),
sl@8
    24
    iRequest(EMiniDisplayRequestNone),iPowerOn(false)
sl@8
    25
	{
sl@8
    26
	iDeviceId[0]=0;
sl@8
    27
	iFirmwareRevision[0]=0;
sl@8
    28
	//ResetBuffers();
sl@8
    29
	}
sl@8
    30
sl@8
    31
/**
sl@8
    32
*/
sl@8
    33
GP1212A01A::~GP1212A01A()
sl@8
    34
	{
sl@8
    35
    delete iFrameAlpha;
sl@8
    36
    iFrameAlpha=NULL;
sl@8
    37
    //
sl@8
    38
    delete iFrameBeta;
sl@8
    39
    iFrameBeta=NULL;
sl@8
    40
    //
sl@8
    41
    delete iFrameGamma;
sl@8
    42
    iFrameGamma=NULL;
sl@8
    43
    //
sl@8
    44
    iFrameNext=NULL;
sl@8
    45
    iFrameCurrent=NULL;
sl@8
    46
    iFramePrevious=NULL;
sl@8
    47
    //
sl@8
    48
    iNeedFullFrameUpdate=0;
sl@8
    49
	}
sl@8
    50
sl@8
    51
/**
sl@8
    52
*/
sl@8
    53
int GP1212A01A::Open()
sl@8
    54
	{
sl@8
    55
	int success = HidDevice::Open(KFutabaVendorId,KFutabaProductIdGP1212A01A,NULL);
sl@8
    56
	if (success)
sl@8
    57
		{
sl@8
    58
        //Allocate both frames
sl@8
    59
        delete iFrameAlpha;
sl@8
    60
        iFrameAlpha=NULL;
sl@8
    61
        iFrameAlpha=new BitArray(KGP12xFrameBufferPixelCount);
sl@8
    62
        //
sl@8
    63
        delete iFrameBeta;
sl@8
    64
        iFrameBeta=NULL;
sl@8
    65
        iFrameBeta=new BitArray(KGP12xFrameBufferPixelCount);
sl@8
    66
        //
sl@8
    67
        delete iFrameGamma;
sl@8
    68
        iFrameGamma=NULL;
sl@8
    69
        iFrameGamma=new BitArray(KGP12xFrameBufferPixelCount);
sl@8
    70
        //
sl@8
    71
        iFrameNext=iFrameAlpha;
sl@8
    72
        iFrameCurrent=iFrameBeta;
sl@8
    73
        iFramePrevious=iFrameGamma;
sl@8
    74
sl@8
    75
sl@8
    76
        //To make sure it is synced properly
sl@8
    77
        iNeedFullFrameUpdate=0;
sl@8
    78
        //
sl@8
    79
		SetNonBlocking(1);
sl@8
    80
        //Since we can't get our display position we force it to our default
sl@8
    81
		//This makes sure frames are in sync from the start
sl@8
    82
        //Clever clients will have taken care of putting back frame (0,0) before closing
sl@8
    83
		SetDisplayPosition(iDisplayPositionX,iDisplayPositionY);
sl@8
    84
		}
sl@8
    85
	return success;
sl@8
    86
	}
sl@8
    87
sl@8
    88
/**
sl@8
    89
*/
sl@8
    90
void GP1212A01A::SetPixel(unsigned char aX, unsigned char aY, bool aOn)
sl@8
    91
	{
sl@8
    92
	//
sl@8
    93
	//int byteOffset=(aX*HeightInPixels()+aY)/8;
sl@8
    94
	//int bitOffset=(aX*HeightInPixels()+aY)%8;
sl@8
    95
    //iNextFrame[byteOffset] |= ( (aOn?0x01:0x00) << bitOffset );
sl@8
    96
sl@8
    97
    if (iOffScreenMode)
sl@8
    98
        {
sl@8
    99
        if (aOn)
sl@8
   100
            {
sl@8
   101
            iFrameNext->SetBit(aX*HeightInPixels()+aY);
sl@8
   102
            }
sl@8
   103
        else
sl@8
   104
            {
sl@8
   105
            iFrameNext->ClearBit(aX*HeightInPixels()+aY);
sl@8
   106
            }
sl@8
   107
        }
sl@8
   108
    else
sl@8
   109
        {
sl@8
   110
        //Just specify a one pixel block
sl@8
   111
        SetPixelBlock(aX,aY,0x00,0x01,aOn);
sl@8
   112
        }
sl@8
   113
	}
sl@8
   114
sl@8
   115
/**
sl@8
   116
*/
sl@8
   117
void GP1212A01A::BitBlit(const BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const
sl@8
   118
	{
sl@8
   119
	//TODO: amend loop values so that we don't keep on looping past our frame buffer dimensions.
sl@8
   120
	for (int i=0;i<aSrcWidth;i++)
sl@8
   121
		{
sl@8
   122
		for (int j=0;j<aSrcHeight;j++)
sl@8
   123
			{
sl@8
   124
            iFrameNext->SetBitValue((aTargetX+i)*HeightInPixels()+aTargetY+j,aBitmap[+i*aSrcHeight+j]);
sl@8
   125
			}
sl@8
   126
		}
sl@8
   127
	}
sl@8
   128
sl@8
   129
/**
sl@8
   130
Clear our client side back buffer.
sl@8
   131
Call to SwapBuffers must follow to actually clear the display.
sl@8
   132
*/
sl@8
   133
void GP1212A01A::Clear()
sl@8
   134
    {
sl@8
   135
    //memset(iNextFrame->Ptr(),0x00,FrameBufferSizeInBytes());
sl@8
   136
    if (iOffScreenMode)
sl@8
   137
        {
sl@8
   138
        iFrameNext->ClearAll();
sl@8
   139
        }
sl@8
   140
    else
sl@8
   141
        {
sl@8
   142
        SendClearCommand();
sl@8
   143
        }
sl@8
   144
    }
sl@8
   145
sl@8
   146
/**
sl@8
   147
Set all pixels on our screen to the desired value.
sl@8
   148
This operation is performed off screen to avoid tearing.
sl@8
   149
@param 8 pixels pattern
sl@8
   150
*/
sl@8
   151
void GP1212A01A::SetAllPixels(unsigned char aPattern)
sl@8
   152
	{
sl@8
   153
	//With a single buffer
sl@8
   154
	//unsigned char screen[2048]; //One screen worth of pixels
sl@8
   155
	//memset(screen,0xFF,sizeof(screen));
sl@8
   156
	//SetPixelBlock(0,0,63,sizeof(screen),screen);
sl@8
   157
sl@8
   158
sl@8
   159
    if (iOffScreenMode)
sl@8
   160
        {
sl@8
   161
        memset(iFrameNext->Ptr(),aPattern,FrameBufferSizeInBytes());
sl@8
   162
        }
sl@8
   163
    else
sl@8
   164
        {
sl@8
   165
        //Using pattern SetPixelBlock variant.
sl@8
   166
        SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),aPattern);
sl@8
   167
        }
sl@8
   168
	//
sl@8
   169
	}
sl@8
   170
sl@8
   171
sl@8
   172
/**
sl@8
   173
Set the defined pixel block to the given value.
sl@8
   174
@param X coordinate of our pixel block starting point.
sl@8
   175
@param Y coordinate of our pixel block starting point.
sl@8
   176
@param The height of our pixel block.
sl@8
   177
@param The size of our pixel data. Number of pixels divided by 8.
sl@8
   178
@param The value set to 8 pixels used as a pattern.
sl@8
   179
*/
sl@8
   180
void GP1212A01A::SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue)
sl@8
   181
	{
sl@8
   182
	OffScreenTranslation(aX,aY);
sl@8
   183
    FutabaVfdReport report;
sl@8
   184
    report[0]=0x00; //Report ID
sl@8
   185
    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
sl@8
   186
    report[2]=0x1B; //Command ID
sl@8
   187
    report[3]=0x5B; //Command ID
sl@8
   188
    report[4]=0xF0; //Command ID
sl@8
   189
    report[5]=aX;   //X
sl@8
   190
    report[6]=aY;   //Y
sl@8
   191
    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@8
   192
	report[8]=aSize>>8; //Size of pixel data in bytes (MSB)
sl@8
   193
	report[9]=aSize;	//Size of pixel data in bytes (LSB)
sl@8
   194
    int sizeWritten=MIN(aSize,report.Size()-10);
sl@8
   195
    memset(report.Buffer()+10, aValue, sizeWritten);
sl@8
   196
    Write(report);
sl@8
   197
sl@8
   198
    int remainingSize=aSize;
sl@8
   199
    //We need to keep on sending our pixel data until we are done
sl@8
   200
    while (report[1]==64)
sl@8
   201
        {
sl@8
   202
        report.Reset();
sl@8
   203
        remainingSize-=sizeWritten;
sl@8
   204
        report[0]=0x00; //Report ID
sl@8
   205
        report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
sl@8
   206
        sizeWritten=(report[1]==64?63:report[1]);
sl@8
   207
        memset(report.Buffer()+2, aValue, sizeWritten);
sl@8
   208
        Write(report);
sl@8
   209
        }
sl@8
   210
	}
sl@8
   211
sl@8
   212
/**
sl@8
   213
Set the defined pixel block to the given value.
sl@8
   214
@param X coordinate of our pixel block starting point.
sl@8
   215
@param Y coordinate of our pixel block starting point.
sl@8
   216
@param The height of our pixel block.
sl@8
   217
@param The size of our pixel data. Number of pixels divided by 8.
sl@8
   218
@param Pointer to our pixel data.
sl@8
   219
*/
sl@8
   220
void GP1212A01A::SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels)
sl@8
   221
    {
sl@8
   222
	OffScreenTranslation(aX,aY);
sl@8
   223
    FutabaVfdReport report;
sl@8
   224
    report[0]=0x00; //Report ID
sl@8
   225
    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
sl@8
   226
    report[2]=0x1B; //Command ID
sl@8
   227
    report[3]=0x5B; //Command ID
sl@8
   228
    report[4]=0xF0; //Command ID
sl@8
   229
    report[5]=aX;   //X
sl@8
   230
    report[6]=aY;   //Y
sl@8
   231
    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@8
   232
	report[8]=aSize>>8; //Size of pixel data in bytes (MSB)
sl@8
   233
	report[9]=aSize;	//Size of pixel data in bytes (LSB)
sl@8
   234
    int sizeWritten=MIN(aSize,report.Size()-10);
sl@8
   235
    memcpy(report.Buffer()+10, aPixels, sizeWritten);
sl@8
   236
    Write(report);
sl@8
   237
sl@8
   238
    int remainingSize=aSize;
sl@8
   239
    //We need to keep on sending our pixel data until we are done
sl@8
   240
    while (report[1]==64)
sl@8
   241
        {
sl@8
   242
        report.Reset();
sl@8
   243
        remainingSize-=sizeWritten;
sl@8
   244
        report[0]=0x00; //Report ID
sl@8
   245
        report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
sl@8
   246
        sizeWritten=(report[1]==64?63:report[1]);
sl@8
   247
        memcpy(report.Buffer()+2, aPixels+(aSize-remainingSize), sizeWritten);
sl@8
   248
        Write(report);
sl@8
   249
        }
sl@8
   250
    }
sl@8
   251
sl@8
   252
/**
sl@8
   253
Using this function is advised against as is causes tearing.
sl@8
   254
Use Clear instead.
sl@8
   255
*/
sl@8
   256
void GP1212A01A::SendClearCommand()
sl@8
   257
	{
sl@8
   258
    //1BH,5BH,32H,4AH
sl@8
   259
    //Send Clear Display Command
sl@8
   260
	FutabaVfdReport report;
sl@8
   261
	report[0]=0x00; //Report ID
sl@8
   262
	report[1]=0x04; //Report length
sl@8
   263
	report[2]=0x1B; //Command ID
sl@8
   264
	report[3]=0x5B; //Command ID
sl@8
   265
	report[4]=0x32; //Command ID
sl@8
   266
	report[5]=0x4A; //Command ID
sl@8
   267
	Write(report);
sl@8
   268
	}
sl@8
   269
sl@8
   270
/**
sl@8
   271
Change our display position within our buffer.
sl@8
   272
*/
sl@8
   273
void GP1212A01A::SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY)
sl@8
   274
    {
sl@8
   275
    //1BH,5BH,Dw,Px,Py
sl@8
   276
    //Send Display Position Settings Command
sl@8
   277
    FutabaVfdReport report;
sl@8
   278
    report[0]=0x00; //Report ID
sl@8
   279
    report[1]=0x05; //Report length
sl@8
   280
    report[2]=0x1B; //Command ID
sl@8
   281
    report[3]=0x5B; //Command ID
sl@8
   282
    report[4]=aDw;  //Specify our DW
sl@8
   283
    report[5]=aX;   //X coordinate of our DW top-left corner
sl@8
   284
    report[6]=aY;   //Y coordinate of our DW top-left corner
sl@8
   285
    Write(report);
sl@8
   286
    }
sl@8
   287
sl@8
   288
/**
sl@8
   289
Change our display position within our buffer.
sl@8
   290
*/
sl@8
   291
void GP1212A01A::SetDisplayPosition(unsigned char aX, unsigned char aY)
sl@8
   292
	{
sl@8
   293
	//Specs apparently says both DW should remain the same
sl@8
   294
	//Just don't ask
sl@8
   295
    SetDisplayPosition(GP1212A01A::DW1,aX,aY);
sl@8
   296
    SetDisplayPosition(GP1212A01A::DW2,aX,aY);
sl@8
   297
	iDisplayPositionX=aX;
sl@8
   298
	iDisplayPositionY=aY;
sl@8
   299
	}
sl@8
   300
sl@8
   301
/**
sl@8
   302
Provide Y coordinate of our off screen buffer.
sl@8
   303
*/
sl@8
   304
unsigned char GP1212A01A::OffScreenY() const
sl@8
   305
	{
sl@8
   306
	//Overflowing is fine this is just what we want
sl@8
   307
	return iDisplayPositionY+HeightInPixels();
sl@8
   308
	}
sl@8
   309
sl@8
   310
/**
sl@8
   311
Put our off screen buffer on screen.
sl@8
   312
On screen buffer goes off screen.
sl@8
   313
*/
sl@8
   314
void GP1212A01A::SwapBuffers()
sl@8
   315
	{
sl@8
   316
	//Only perform buffer swapping if off screen mode is enabled
sl@8
   317
	if (OffScreenMode())
sl@8
   318
		{
sl@8
   319
		//Send host back buffer to device back buffer
sl@8
   320
        if (!iUseFrameDifferencing || iNeedFullFrameUpdate<KNumberOfFrameBeforeDiffAlgo)
sl@8
   321
            {
sl@8
   322
            iNeedFullFrameUpdate++;
sl@8
   323
            SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),iFrameNext->Ptr());
sl@8
   324
            }
sl@8
   325
        else
sl@8
   326
            {
sl@8
   327
            //Frame diff algo is enabled
sl@8
   328
            //We are going to send to our device only the differences between next frame and previous frame
sl@8
   329
            SendModifiedPixelBlocks();
sl@8
   330
            }
sl@8
   331
		//Swap device front and back buffer
sl@8
   332
		SetDisplayPosition(iDisplayPositionX,OffScreenY());
sl@8
   333
sl@8
   334
        //Cycle through our frame buffers
sl@8
   335
        //We keep track of previous frame which is in fact our device back buffer.
sl@8
   336
        //We can then compare previous and next frame and send only the differences to our device.
sl@8
   337
        //This mechanism allows us to reduce traffic over our USB bus thus improving our frame rate from 14 FPS to 30 FPS.
sl@8
   338
        //Keep our previous frame pointer
sl@8
   339
        BitArray* previousFrame=iFramePrevious;
sl@8
   340
        //Current frame becomes the previous one
sl@8
   341
        iFramePrevious = iFrameCurrent;
sl@8
   342
        //Next frame becomes the current one
sl@8
   343
        iFrameCurrent = iFrameNext;
sl@8
   344
        //Next frame is now our former previous
sl@8
   345
        iFrameNext = previousFrame;
sl@8
   346
		}
sl@8
   347
	}
sl@8
   348
sl@8
   349
sl@8
   350
//Define the edge of our pixel block
sl@8
   351
//Pixel blocks of 32x32 seems to run almost as fast as full screen update in worse case scenarii.
sl@8
   352
//Though I wonder if in some situations 16 could be better. Make this an attribute at some point if need be.
sl@8
   353
const int KPixelBlockEdge = 32;
sl@8
   354
const int KPixelBlockSizeInBits = KPixelBlockEdge*KPixelBlockEdge;
sl@8
   355
const int KPixelBlockSizeInBytes = KPixelBlockSizeInBits/8;
sl@8
   356
sl@8
   357
sl@8
   358
/**
sl@8
   359
 * @brief GP1212A01A::SendModifiedPixelBlocks
sl@8
   360
 * Compare our back and front buffer and send to the device only the modified pixels.
sl@8
   361
 */
sl@8
   362
void GP1212A01A::SendModifiedPixelBlocks()
sl@8
   363
    {
sl@8
   364
    int w=WidthInPixels();
sl@8
   365
    int h=HeightInPixels();
sl@8
   366
sl@8
   367
sl@8
   368
    //TODO: optimize with memcmp and 16 inc
sl@8
   369
    /*
sl@8
   370
sl@8
   371
    for (int i=0;i<w;i++)
sl@8
   372
        {
sl@8
   373
        for (int j=0;j<h;j++)
sl@8
   374
            {
sl@8
   375
            //aX*HeightInPixels()+aY
sl@8
   376
            if ((*iFrameNext)[i*h+j]!=(*iFramePrevious)[i*h+j])
sl@8
   377
                {
sl@8
   378
                //We need to update that pixel
sl@8
   379
                SetPixelBlock(i,j,0,1,((*iFrameNext)[i*h+j]?0x01:0x00));
sl@8
   380
                //SetDisplayPosition(iDisplayPositionX,OffScreenY());
sl@8
   381
                //SetDisplayPosition(iDisplayPositionX,OffScreenY());
sl@8
   382
sl@8
   383
                //SetPixelBlock(i,j,15,32,iNextFrame->Ptr()+offset);
sl@8
   384
                }
sl@8
   385
            }
sl@8
   386
        }
sl@8
   387
    */
sl@8
   388
sl@8
   389
    BitArray nextBlock(KPixelBlockSizeInBits);
sl@8
   390
    BitArray previousBlock(KPixelBlockSizeInBits);
sl@8
   391
sl@8
   392
    for (int i=0;i<w;i+=KPixelBlockEdge)
sl@8
   393
        {
sl@8
   394
        for (int j=0;j<h;j+=KPixelBlockEdge)
sl@8
   395
            {
sl@8
   396
            //aX*HeightInPixels()+aY
sl@8
   397
            //int offset=(i*w/8)+(j/8);
sl@8
   398
sl@8
   399
#ifdef DEBUG_FRAME_DIFF
sl@8
   400
            QImage imagePrevious(KPixelBlockEdge,KPixelBlockEdge,QImage::Format_RGB32);
sl@8
   401
            QImage imageNext(KPixelBlockEdge,KPixelBlockEdge,QImage::Format_RGB32);
sl@8
   402
#endif
sl@8
   403
sl@8
   404
            //Get both our blocks from our buffers
sl@8
   405
            for (int x=i;x<i+KPixelBlockEdge;x++)
sl@8
   406
                {
sl@8
   407
                for (int y=j;y<j+KPixelBlockEdge;y++)
sl@8
   408
                    {
sl@8
   409
                    int blockOffset=(x-i)*KPixelBlockEdge+(y-j);
sl@8
   410
                    int frameOffset=x*h+y;
sl@8
   411
                    nextBlock.SetBitValue(blockOffset,(*iFrameNext)[frameOffset]);
sl@8
   412
                    previousBlock.SetBitValue(blockOffset,(*iFramePrevious)[frameOffset]);
sl@8
   413
sl@8
   414
#ifdef DEBUG_FRAME_DIFF
sl@8
   415
                    imageNext.setPixel(x-i,y-j,(nextBlock[blockOffset]?0xFFFFFFFF:0x00000000));
sl@8
   416
                    imagePrevious.setPixel(x-i,y-j,(previousBlock[blockOffset]?0xFFFFFFFF:0x00000000));
sl@8
   417
#endif
sl@8
   418
                    }
sl@8
   419
                }
sl@8
   420
sl@8
   421
#ifdef DEBUG_FRAME_DIFF
sl@8
   422
            QString previousName;
sl@8
   423
            QString nextName;
sl@8
   424
            QTextStream(&previousName) << "p" << i << "x" << j << ".png";
sl@8
   425
            QTextStream(&nextName) << "n" << i << "x" << j << ".png";
sl@8
   426
            imagePrevious.save(previousName);
sl@8
   427
            imageNext.save(nextName);
sl@8
   428
#endif
sl@8
   429
sl@8
   430
sl@8
   431
            //if (memcmp(iFrameNext->Ptr()+offset,iFramePrevious->Ptr()+offset,32 )) //32=(16*16/8)
sl@8
   432
            if (memcmp(nextBlock.Ptr(),previousBlock.Ptr(),KPixelBlockSizeInBytes)!=0)
sl@8
   433
                {
sl@8
   434
                //We need to update that block
sl@8
   435
                SetPixelBlock(i,j,KPixelBlockEdge-1,KPixelBlockSizeInBytes,nextBlock.Ptr());
sl@8
   436
                //SetPixelBlock(i,j,15,32,0xFF/*nextBlock.Ptr()*/);
sl@8
   437
                //SetDisplayPosition(iDisplayPositionX,OffScreenY());
sl@8
   438
                //SetDisplayPosition(iDisplayPositionX,OffScreenY());
sl@8
   439
sl@8
   440
                //SetPixelBlock(i,j,15,32,iFrameNext->Ptr()+offset);
sl@8
   441
                }
sl@8
   442
            }
sl@8
   443
        }
sl@8
   444
sl@8
   445
    }
sl@8
   446
sl@8
   447
/**
sl@8
   448
Translate the given pixel coordinate according to our off screen mode.
sl@8
   449
*/
sl@8
   450
void GP1212A01A::OffScreenTranslation(unsigned char& aX, unsigned char& aY)
sl@8
   451
	{
sl@8
   452
	if (OffScreenMode())
sl@8
   453
		{
sl@8
   454
		aX+=WidthInPixels()-iDisplayPositionX;
sl@8
   455
		aY+=HeightInPixels()-iDisplayPositionY;
sl@8
   456
		}
sl@8
   457
	}
sl@8
   458
sl@8
   459
sl@8
   460
/**
sl@8
   461
*/
sl@8
   462
void GP1212A01A::ResetBuffers()
sl@8
   463
	{
sl@8
   464
    //iNextFrame->ClearAll();
sl@8
   465
    //memset(iFrameAlpha,0x00,sizeof(iFrameAlpha));
sl@8
   466
	//memset(iFrameBeta,0x00,sizeof(iFrameBeta));
sl@8
   467
	}
sl@8
   468
sl@8
   469
/**
sl@8
   470
*/
sl@8
   471
void GP1212A01A::RequestDeviceId()
sl@8
   472
    {
sl@8
   473
    if (RequestPending())
sl@8
   474
        {
sl@8
   475
        //Abort silently for now
sl@8
   476
        return;
sl@8
   477
        }
sl@8
   478
sl@8
   479
    //1BH,5BH,63H,49H,44H
sl@8
   480
    //Send Read ID command
sl@8
   481
    FutabaVfdReport report;
sl@8
   482
    report[0]=0x00; //Report ID
sl@8
   483
    report[1]=0x05; //Report length
sl@8
   484
    report[2]=0x1B; //Command ID
sl@8
   485
    report[3]=0x5B; //Command ID
sl@8
   486
    report[4]=0x63; //Command ID
sl@8
   487
    report[5]=0x49; //Command ID
sl@8
   488
    report[6]=0x44; //Command ID
sl@8
   489
    if (Write(report)==report.Size())
sl@8
   490
        {
sl@8
   491
        iRequest=EMiniDisplayRequestDeviceId;
sl@8
   492
        }
sl@8
   493
    }
sl@8
   494
sl@8
   495
/**
sl@8
   496
*/
sl@8
   497
void GP1212A01A::RequestFirmwareRevision()
sl@8
   498
    {
sl@8
   499
    if (RequestPending())
sl@8
   500
        {
sl@8
   501
        //Abort silently for now
sl@8
   502
        return;
sl@8
   503
        }
sl@8
   504
sl@8
   505
    //1BH,5BH,63H,46H,52H
sl@8
   506
    //Send Software Revision Read Command
sl@8
   507
    FutabaVfdReport report;
sl@8
   508
    report[0]=0x00; //Report ID
sl@8
   509
    report[1]=0x05; //Report length
sl@8
   510
    report[2]=0x1B; //Command ID
sl@8
   511
    report[3]=0x5B; //Command ID
sl@8
   512
    report[4]=0x63; //Command ID
sl@8
   513
    report[5]=0x46; //Command ID
sl@8
   514
    report[6]=0x52; //Command ID
sl@8
   515
    if (Write(report)==report.Size())
sl@8
   516
        {
sl@8
   517
        iRequest=EMiniDisplayRequestFirmwareRevision;
sl@8
   518
        }
sl@8
   519
    }
sl@8
   520
sl@8
   521
/**
sl@8
   522
*/
sl@8
   523
void GP1212A01A::RequestPowerSupplyStatus()
sl@8
   524
    {
sl@8
   525
    if (RequestPending())
sl@8
   526
        {
sl@8
   527
        //Abort silently for now
sl@8
   528
        return;
sl@8
   529
        }
sl@8
   530
    //1BH,5BH,63H,50H,4DH
sl@8
   531
    //Send Power Suppply Monitor Command
sl@8
   532
    FutabaVfdReport report;
sl@8
   533
    report[0]=0x00; //Report ID
sl@8
   534
    report[1]=0x05; //Report length
sl@8
   535
    report[2]=0x1B; //Command ID
sl@8
   536
    report[3]=0x5B; //Command ID
sl@8
   537
    report[4]=0x63; //Command ID
sl@8
   538
    report[5]=0x50; //Command ID
sl@8
   539
    report[6]=0x4D; //Command ID
sl@8
   540
    if (Write(report)==report.Size())
sl@8
   541
        {
sl@8
   542
        iRequest=EMiniDisplayRequestPowerSupplyStatus;
sl@8
   543
        }
sl@8
   544
    }
sl@8
   545
sl@8
   546
sl@8
   547
/**
sl@8
   548
This is for development purposes only.
sl@8
   549
Production application should stick to off-screen mode to avoid tearing.
sl@8
   550
*/
sl@8
   551
void GP1212A01A::ToggleOffScreenMode()
sl@8
   552
	{
sl@8
   553
    SetOffScreenMode(!iOffScreenMode);
sl@8
   554
	}
sl@8
   555
sl@8
   556
/**
sl@8
   557
 * @brief GP1212A01A::SetOffScreenMode
sl@8
   558
 * @param aOn
sl@8
   559
 * @return
sl@8
   560
 */
sl@8
   561
void GP1212A01A::SetOffScreenMode(bool aOn)
sl@8
   562
    {
sl@8
   563
    if (aOn==iOffScreenMode)
sl@8
   564
    {
sl@8
   565
        //Nothing to do here
sl@8
   566
        return;
sl@8
   567
    }
sl@8
   568
sl@8
   569
    iOffScreenMode=aOn;
sl@8
   570
sl@8
   571
    //Clean up our buffers upon switching modes
sl@8
   572
    SetDisplayPosition(0,0);
sl@8
   573
    Clear();
sl@8
   574
    SwapBuffers();
sl@8
   575
    Clear();
sl@8
   576
    }
sl@8
   577
sl@8
   578
/**
sl@8
   579
Tries to complete our current request if we have one pending.
sl@8
   580
 */
sl@8
   581
TMiniDisplayRequest GP1212A01A::AttemptRequestCompletion()
sl@8
   582
    {
sl@8
   583
    if (!RequestPending())
sl@8
   584
        {
sl@8
   585
        return EMiniDisplayRequestNone;
sl@8
   586
        }
sl@8
   587
sl@8
   588
    int res=Read(iInputReport);
sl@8
   589
sl@8
   590
    if (!res)
sl@8
   591
        {
sl@8
   592
        return EMiniDisplayRequestNone;
sl@8
   593
        }
sl@8
   594
sl@8
   595
    //Process our request
sl@8
   596
    if (CurrentRequest()==EMiniDisplayRequestPowerSupplyStatus)
sl@8
   597
        {
sl@8
   598
        if (iInputReport[1]==0x4F && iInputReport[2]==0x4E)
sl@8
   599
            {
sl@8
   600
            iPowerOn = true;
sl@8
   601
            }
sl@8
   602
        else if (iInputReport[1]==0x4F && iInputReport[2]==0x46 && iInputReport[3]==0x46)
sl@8
   603
            {
sl@8
   604
            iPowerOn = false;
sl@8
   605
            }
sl@8
   606
        }
sl@8
   607
	else if (CurrentRequest()==EMiniDisplayRequestDeviceId)
sl@8
   608
		{
sl@8
   609
			unsigned char* ptr=&iInputReport[1];
sl@8
   610
			strcpy(iDeviceId,(const char*)ptr);
sl@8
   611
		}
sl@8
   612
	else if (CurrentRequest()==EMiniDisplayRequestFirmwareRevision)
sl@8
   613
		{
sl@8
   614
			unsigned char* ptr=&iInputReport[1];
sl@8
   615
			strcpy(iFirmwareRevision,(const char*)ptr);
sl@8
   616
		}
sl@8
   617
sl@8
   618
    TMiniDisplayRequest completed=iRequest;
sl@8
   619
    //Our request was completed
sl@8
   620
    iRequest=EMiniDisplayRequestNone;
sl@8
   621
sl@8
   622
    return completed;
sl@8
   623
    }
sl@8
   624
sl@8
   625
sl@8
   626
/**
sl@8
   627
Set our screen brightness.
sl@8
   628
@param The desired brightness level. Must be between MinBrightness and MaxBrightness.
sl@8
   629
*/
sl@8
   630
void GP1212A01A::SetBrightness(int aBrightness)
sl@8
   631
    {
sl@8
   632
    if (aBrightness<MinBrightness()||aBrightness>MaxBrightness())
sl@8
   633
        {
sl@8
   634
        //Brightness out of range.
sl@8
   635
        //Just ignore that request.
sl@8
   636
        return;
sl@8
   637
        }
sl@8
   638
sl@8
   639
    FutabaVfdReport report;
sl@8
   640
    report[0]=0x00; //Report ID
sl@8
   641
    report[1]=0x06; //Report size
sl@8
   642
    report[2]=0x1B; //Command ID
sl@8
   643
    report[3]=0x5C; //Command ID
sl@8
   644
    report[4]=0x3F; //Command ID
sl@8
   645
    report[5]=0x4C; //Command ID
sl@8
   646
    report[6]=0x44; //Command ID
sl@8
   647
    report[7]=0x30+aBrightness; //Brightness level
sl@8
   648
    Write(report);
sl@8
   649
    }
sl@8
   650
sl@8
   651
/**
sl@8
   652
*/
sl@8
   653
bool GP1212A01A::PowerOn()
sl@8
   654
	{
sl@8
   655
	return iPowerOn;
sl@8
   656
	}
sl@8
   657
sl@8
   658
/**
sl@8
   659
*/
sl@8
   660
char* GP1212A01A::DeviceId()
sl@8
   661
	{
sl@8
   662
	return iDeviceId;
sl@8
   663
	}
sl@8
   664
sl@8
   665
/**
sl@8
   666
*/
sl@8
   667
char* GP1212A01A::FirmwareRevision()
sl@8
   668
	{
sl@8
   669
	return iFirmwareRevision;
sl@8
   670
	}