Combining tftbmp example with SdFat

Status
Not open for further replies.

ZTiK.nl

Well-known member
Hello everyone,

I am trying to combine 2 example .ino files to make one functioning script, but I have been stuck at the same point for a while now.

I am combining the tftbmp example that comes with Adafruits TFTLCD library for (including but not limited to) the 2.8" Touchscreen TFT with SdFat, so that I can load fullscreen bmp files at reasonable speed.
A few hours ago I noticed a new SdFat so I updated, and finally my code does compile, but results arent as they should.

The most important change I made to the original tftbmp example is a call to SdFile.position() and one to SdFile.seek(pos):
Code:
          if(bmpFile.position() != pos) { // Need seek?
            bmpFile.search(pos);
            buffidx = sizeof(sdbuffer); // Force buffer reload
          }
which I changed to:
Code:
          if(bmpFile.curPosition() != pos) { // Need seek?
            bmpFile.seekSet(pos);
            buffidx = sizeof(sdbuffer); // Force buffer reload
          }
position() and search() could not be found in SdFat libs, but I did find curPosition() and seekSet()
This code resulted in compile errors in the previous SdFat beta (dated 12/2012) but it does compile in the newer version.

However, I believe that the problem lies in two other functions which I only changed to point to SdFile instead of File:
Code:
uint16_t read16(SdFile f) {
  uint16_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read(); // MSB
  return result;
}
uint32_t read32(SdFile f) {
  uint32_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read();
  ((uint8_t *)&result)[2] = f.read();
  ((uint8_t *)&result)[3] = f.read(); // MSB
  return result;
}

The reason I think the problem lies here is because right after where the file is opened there is a check for the BMP signature, which doesnt validate.

I'm not too sure how to troubleshoot any further, so I'm kinda looking for any advice on where I'm going the wrong way.

(I included the original example .ino file and my 'updated' .ino file, SdFat can be downloaded here and the full TFTLCD lib is here)
 

Attachments

  • tftbmp.ino
    9 KB · Views: 141
  • tftbmp_SdFat.ino
    9.2 KB · Views: 151
When adding a Serial.print(read16(bmpFile)); at the end of the script (just before the file closes), but the BMP signature always seems to result in 65535 (hex 0xFFFF).

Also tried to reverse the order of the read16/read32 functions, but don't notice anything different so far.
 
Last edited:
Got a step further.
Finally gotten the code to compile, and something is actually drawn on the screen.

However...
I made an image with black background and green lines, it turned into black backgr. and blue lines.
SdFat bmpdisplay.jpg

Also, the image is broken up in two parts, a small section on the right side is supposed to be on the left side (it seems the start offset is incorrect)
You can see there is a part of the left hand being displayed right next to the end of the right hand :x

Still a major improvement, the image loads and displays in 0.119 sec, haven't tested fullscreen 320x240 images yet...
I will continue working on this to make it work 100%, but in the meantime I have added my modified example file to this post if anyone wants to use it/take a look at it ;)
 

Attachments

  • tftbmp_SdFat.ino
    9 KB · Views: 354
wow, fixed all problems now by changing:
Code:
bmpFile.seekEnd(pos);
to :
Code:
bmpFile.seekSet(pos);
 
Status
Not open for further replies.
Back
Top