MDM166AA swap buffers now working.
authorStephaneLenclud
Thu, 05 Feb 2015 11:41:19 +0100
changeset 27949be5444c57
parent 26 f943cd500390
child 28 0d426caeaefe
MDM166AA swap buffers now working.
FutabaMDM166AA.cpp
FutabaMDM166AA.h
     1.1 --- a/FutabaMDM166AA.cpp	Wed Feb 04 21:53:06 2015 +0100
     1.2 +++ b/FutabaMDM166AA.cpp	Thu Feb 05 11:41:19 2015 +0100
     1.3 @@ -95,45 +95,6 @@
     1.4  	return success;
     1.5  	}
     1.6  
     1.7 -
     1.8 -/**
     1.9 -Display RAM filled with 00H.
    1.10 -Address Counter is set by 00H.
    1.11 -Dimming is set to 50%.
    1.12 -*/
    1.13 -void MDM166AA::SendCommandReset()
    1.14 -	{
    1.15 -	FutabaVfdReport report;
    1.16 -	report[0]=0x00; //Report ID
    1.17 -	report[1]=0x01; //Report length.
    1.18 -	report[2]=0x1F; //Command ID
    1.19 -	Write(report);
    1.20 -	//Wait until reset is done. Is that needed?
    1.21 -	//sleep(2000);
    1.22 -	}
    1.23 -
    1.24 -
    1.25 -/**
    1.26 -Set Address Counter (AC) values: 1BH + 60H + xxH
    1.27 -xxH: 00 ~ BFH
    1.28 -AC value represents the start address for graphic data.
    1.29 -There are 192 bytes as display RAM. It can be set on anywhere even if AC value is not visible area.
    1.30 -The default value is 00H.
    1.31 -Default: 00H
    1.32 -When clock is displayed, AC value is set 00H.
    1.33 -*/
    1.34 -void MDM166AA::SendCommandSetAddressCounter(unsigned char aAddressCounter)
    1.35 -	{
    1.36 -	FutabaVfdReport report;
    1.37 -	report[0]=0x00; //Report ID
    1.38 -	report[1]=0x03; //Report length.
    1.39 -	report[2]=0x1B; //Command ID
    1.40 -	report[3]=0x60; //Command ID
    1.41 -	report[4]=aAddressCounter;
    1.42 -	Write(report);
    1.43 -	}
    1.44 -
    1.45 -
    1.46  /**
    1.47  */
    1.48  void MDM166AA::SetPixel(unsigned char aX, unsigned char aY, unsigned int aPixel)
    1.49 @@ -266,16 +227,7 @@
    1.50  	if (OffScreenMode())
    1.51  		{
    1.52  		//Send pixel directly into BMP box
    1.53 -		//BmpBoxDataInput(FrameBufferSizeInBytes(),iFrameNext->Ptr());
    1.54 -		//Send pixel data directly into the display window
    1.55 -		//BmpDataInput(ETargetDisplayWindow,0x0000,EDirectionY, FrameBufferSizeInBytes(),iFrameNext->Ptr());
    1.56 -		//Send pixel data first to Data Memory then copy into the selected BMP box	
    1.57 -		//BmpDataInput(ETargetDataMemory,0x0000,EDirectionY, FrameBufferSizeInBytes(),iFrameNext->Ptr());
    1.58 -		//BmpBoxDataMemoryTransfer(0x0000);
    1.59 -		//Send pixel data first to Data Memory then copy into the selected BMP box, cycling through our Data Memory frmae
    1.60 -		//BmpDataInput(ETargetDataMemory,iNextFrameAddress,EDirectionY, FrameBufferSizeInBytes(),iFrameNext->Ptr());
    1.61 -		//BmpBoxDataMemoryTransfer(iNextFrameAddress);
    1.62 -
    1.63 +		SendCommandWriteGraphicData(FrameBufferSizeInBytes(),iFrameNext->Ptr());
    1.64  
    1.65          //Cycle through our frame buffers
    1.66          //We keep track of previous frame which is in fact our device back buffer.
    1.67 @@ -293,48 +245,6 @@
    1.68  	}
    1.69  
    1.70  
    1.71 -/**
    1.72 -Set the defined pixel block to the given value.
    1.73 -@param X coordinate of our pixel block starting point.
    1.74 -@param Y coordinate of our pixel block starting point.
    1.75 -@param The height of our pixel block.
    1.76 -@param The size of our pixel data. Number of pixels divided by 8.
    1.77 -@param Pointer to our pixel data.
    1.78 -*/
    1.79 -void MDM166AA::SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels)
    1.80 -    {
    1.81 -	//TODO: Assuming 0,0 for now, do the math later
    1.82 -	SendCommandSetAddressCounter(0);
    1.83 -
    1.84 -	const int KMaxPixelBytes=48;
    1.85 -
    1.86 -    FutabaVfdReport report;
    1.87 -    report[0]=0x00; //Report ID
    1.88 -    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
    1.89 -    report[2]=0x1B; //Command ID
    1.90 -    report[3]=0x70; //Command ID
    1.91 -	//TODO: All rubbish
    1.92 -	report[4]=MAX(KMaxPixelBytes,aSize); //Size of pixel data in bytes
    1.93 -    int sizeWritten=MIN(aSize,report.Size()-10);
    1.94 -    memcpy(report.Buffer()+10, aPixels, sizeWritten);
    1.95 -    Write(report);
    1.96 -
    1.97 -    int remainingSize=aSize;
    1.98 -    //We need to keep on sending our pixel data until we are done
    1.99 -    while (report[1]==64)
   1.100 -        {
   1.101 -        report.Reset();
   1.102 -        remainingSize-=sizeWritten;
   1.103 -        report[0]=0x00; //Report ID
   1.104 -        report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
   1.105 -        sizeWritten=(report[1]==64?63:report[1]);
   1.106 -        memcpy(report.Buffer()+2, aPixels+(aSize-remainingSize), sizeWritten);
   1.107 -        Write(report);
   1.108 -        }
   1.109 -    }
   1.110 -
   1.111 -
   1.112 -
   1.113  //Define the edge of our pixel block
   1.114  //Pixel blocks of 32x32 seems to run almost as fast as full screen update in worse case scenarii.
   1.115  //Though I wonder if in some situations 16 could be better. Make this an attribute at some point if need be.
   1.116 @@ -612,3 +522,77 @@
   1.117      Write(report);
   1.118  	}
   1.119  
   1.120 +
   1.121 +/**
   1.122 +Display RAM filled with 00H.
   1.123 +Address Counter is set by 00H.
   1.124 +Dimming is set to 50%.
   1.125 +*/
   1.126 +void MDM166AA::SendCommandReset()
   1.127 +	{
   1.128 +	FutabaVfdReport report;
   1.129 +	report[0]=0x00; //Report ID
   1.130 +	report[1]=0x01; //Report length.
   1.131 +	report[2]=0x1F; //Command ID
   1.132 +	Write(report);
   1.133 +	//Wait until reset is done. Is that needed?
   1.134 +	//sleep(2000);
   1.135 +	}
   1.136 +
   1.137 +
   1.138 +/**
   1.139 +Set Address Counter (AC) values: 1BH + 60H + xxH
   1.140 +xxH: 00 ~ BFH
   1.141 +AC value represents the start address for graphic data.
   1.142 +There are 192 bytes as display RAM. It can be set on anywhere even if AC value is not visible area.
   1.143 +The default value is 00H.
   1.144 +Default: 00H
   1.145 +When clock is displayed, AC value is set 00H.
   1.146 +*/
   1.147 +void MDM166AA::SendCommandSetAddressCounter(unsigned char aAddressCounter)
   1.148 +	{
   1.149 +	FutabaVfdReport report;
   1.150 +	report[0]=0x00; //Report ID
   1.151 +	report[1]=0x03; //Report length.
   1.152 +	report[2]=0x1B; //Command ID
   1.153 +	report[3]=0x60; //Command ID
   1.154 +	report[4]=aAddressCounter;
   1.155 +	Write(report);
   1.156 +	}
   1.157 +
   1.158 +
   1.159 +/**
   1.160 +Set the defined pixel block to the given value.
   1.161 +
   1.162 +@param The size of our pixel data. Number of pixels divided by 8.
   1.163 +@param Pointer to our pixel data.
   1.164 +*/
   1.165 +void MDM166AA::SendCommandWriteGraphicData(int aSize, unsigned char* aPixels)
   1.166 +    {
   1.167 +	//TODO: Remove that at some point
   1.168 +	SendCommandSetAddressCounter(0);
   1.169 +
   1.170 +	const int KMaxPixelBytes=48;
   1.171 +	const int KHeaderSize=3;
   1.172 +	
   1.173 +	int remainingSize=aSize;
   1.174 +	int sizeWritten=0;
   1.175 +
   1.176 +	while (remainingSize>0)
   1.177 +		{
   1.178 +		//Only send a maximum of 48 bytes worth of pixels per report
   1.179 +		const int KPixelDataSize=(remainingSize<=KMaxPixelBytes?remainingSize:KMaxPixelBytes);
   1.180 +
   1.181 +		FutabaVfdReport report;
   1.182 +		report[0]=0x00; //Report ID
   1.183 +		report[1]=KPixelDataSize+KHeaderSize; //Report length. +3 is for our header first 3 bytes.
   1.184 +		report[2]=0x1B; //Command ID
   1.185 +		report[3]=0x70; //Command ID
   1.186 +		report[4]=KPixelDataSize; //Size of pixel data in bytes		
   1.187 +		memcpy(report.Buffer()+5, aPixels+sizeWritten, KPixelDataSize);
   1.188 +		Write(report);
   1.189 +		//Advance
   1.190 +		sizeWritten+=KPixelDataSize;
   1.191 +		remainingSize-=KPixelDataSize;
   1.192 +		}
   1.193 +    }
     2.1 --- a/FutabaMDM166AA.h	Wed Feb 04 21:53:06 2015 +0100
     2.2 +++ b/FutabaMDM166AA.h	Thu Feb 05 11:41:19 2015 +0100
     2.3 @@ -82,14 +82,15 @@
     2.4  	//General setting command
     2.5  	void SendCommandClear();
     2.6  	void SendCommandReset();
     2.7 -	void SendCommandSetAddressCounter(unsigned char aAddressCounter);
     2.8 -	//void SendCommandWriteGraphicData();
     2.9  	//
    2.10  	//Clock commands
    2.11  	void SendCommandClockSetting(unsigned char aHour, unsigned char aMinute);
    2.12  	void SendCommandClockDisplay(TClockSize aClockSize, TClockFormat aClockFormat);	
    2.13  
    2.14 -	void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels);
    2.15 +	//Graphics commands
    2.16 +	void SendCommandSetAddressCounter(unsigned char aAddressCounter);
    2.17 +	void SendCommandWriteGraphicData(int aSize, unsigned char* aPixels);
    2.18 +
    2.19  
    2.20  private:
    2.21      void RequestDeviceId();