Page 1 of 1

Uploading a bitmap file programmatically (again)

Posted: Fri Oct 12, 2007 7:31 am
by oneelkruns
About a month and a half ago I asked about how to upload a bitmap file to a GLK240128-25 since I couldn't get it to work as in the manual. Clark kindly posted a reply saying the manual was wrong and I should try this approach:

---------------------------------------------------------------
Host: Transmit(0xFE); //Command Prefix
Transmit(0x5E); //Bitmap file upload command
Transmit(0x05); //Reference ID for bitmap file
Transmit(0x19); //Transmit bitmap file size LSB
Transmit(0x00); //Transmit bitmap file size MSB

Module: FileFits(0x01); //Send confirmation that file fits

Host: Receive(); //Receive confirmation that file fits
Transmit(0x05); //Transmit first byte of file data

Module: Echo(0x05); //Echo first byte of file

Host: Receive(); //Receive echo
Confirm(0x05); //Confirm echo
Transmit(0x07); //Transmit second byte of file data

etc...

If any byte other than 0x01 is seen for confirmation by host or module (usually 0x08) the upload it aborted.
------------------------------------------------------------

well, life being what it is, I am now getting around to trying this approach. First, the line that says Confirm(0x05) should be Confirm(0x01), ie, send 0x01 as a confirmation. Second, while the above does indeed upload a file the file appears as garbage when the display shows it. The same bitmap (ie, Windows bitmap) file when uploaded through MOGD# looks just fine.

So, there is a step missing somewhere. Any ideas as to what it is?

Thanks!
Ron

Posted: Fri Oct 12, 2007 8:16 am
by Ray
here's the relevant part out of mogd#

Code: Select all

// Write command
Write(254);
Write((byte)uploadType);
Write((byte)reference);

//In unit does not echo back the id, bail out.
if (revision == PcbRev.rev1X)
{
	Echo = Read();  
	if (Echo ==reference)
		Write(1);
	else
		return false;
}

//Write FileSize to unit and wait for echo's
byte SizeLo = (byte) (data.Length  & 0xff);
byte SizeHi = (byte) (data.Length >> 8);
Write(SizeLo);
if (revision == PcbRev.rev1X)
{
	Echo = Read();
	if (Echo == SizeLo)
		Write(1);
	else
		return false;
}
Write(SizeHi);
if (revision == PcbRev.rev1X)
{
	Echo = Read();
	if (Echo != SizeHi)  
		return false;
}

Echo = Read();

if (Echo == 0x01)  //If it stil fits go on
{
	for (int i=0; i < data.Length; i++) //Write the whole stream and check for echo's
	{
		Write(data[i]);	
		Echo = Read();
		if (Echo != data[i])
		{
			return false;
		}
		else
		Write(1);
	}
}   
else //Font or bitmap to big for unit / unit rejects font/bitmap
	return false;

return true; //Got all the way to the end? success!

The reason your bitmap maybe garbled is that between rev 1.x and 2.x the way the bitmap is stored has been changed, V1 scanned the bitmap vertically while V2 scans it horizontally.

Uploading a bitmap file programmatically (again)

Posted: Wed Oct 17, 2007 7:26 am
by oneelkruns
>The reason your bitmap maybe garbled is that between rev 1.x and 2.x the way the bitmap is
>stored has been changed, V1 scanned the bitmap vertically while V2 scans it horizontally.

So, the actual bitmap file is not uploaded but rather the pixel data only? If so, what specifies the dimensions of the image?

Ron

Posted: Wed Oct 17, 2007 8:32 am
by Ray
There was a section on this in the manual but it seems to have gone missing, I'll inform the manual team on this.

Bitmaps are stored almost the same as a font but with a simpler header
[Width (1 byte)] [Height ( 1 byte )] [Data (as much as needed)]

The data is enocded the same way as the individual characters in a font file, see section 5.2.1 Creating a font in your manual to see how its done.

Posted: Thu Oct 18, 2007 6:37 am
by oneelkruns
I see now. So, what gets sent to the display is this:

<width><height><data>...

where <data> represents the pixels of the bitmap packed as bytes + any padding zeros necessary to fill out the last byte.

Is this correct? It seems sensible to me, I'll give it a go.

Thanks!

Ron

Posted: Thu Oct 18, 2007 7:44 am
by Ray
That is correct, let me know if you have any more problems!