how do you use the backwards compatible parts of sdfat??

sdfat says its compatible with the standard sd.h implementations

but i tried to just change the include and it messes up (not my idea of backwards compatible but ok)

my project is huge and i only need one function from sdfat which is cwd(), kinda lame i have to comprimise so much space for one function but ok, now i need some help getting it to work... i can post the code in a dowload if need be but its a major mess.

The File class has all the SdBaseFile functions plus the functions in
the Arduino SD.h File class. This provides compatibility with the
Arduino SD.h library.
Arduino: 1.8.1 (Linux), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

WARNING: Category 'Language' in library ArduinoStreaming is not valid. Setting to 'Uncategorized'
WARNING: Category '' in library UIPEthernet is not valid. Setting to 'Uncategorized'
Analog_320x240_2:13: error: 'SdVolume' does not name a type
 SdVolume volume;
 ^
/home/tjohnson/sketchbook/Analog_320x240_2/InitCore.ino: In function 'void InitializeCore()':
InitCore:68: error: 'volume' was not declared in this scope
    if (!volume.init(card)) {
         ^
InitCore:82: error: 'volume' was not declared in this scope
   pVar(volume.fatType(), TFT_GREEN, 80, Line, 1);
        ^
/home/tjohnson/sketchbook/Analog_320x240_2/SD_Functions.ino: In function 'double SDFreeSpace(double)':
SD_Functions:132: error: 'volume' was not declared in this scope
   volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
                ^
exit status 1
'SdVolume' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Arduino: 1.8.1 (Linux), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

WARNING: Category 'Language' in library ArduinoStreaming is not valid. Setting to 'Uncategorized'
WARNING: Category '' in library UIPEthernet is not valid. Setting to 'Uncategorized'
/home/tjohnson/sketchbook/Analog_320x240_2/InitCore.ino: In function 'void InitializeCore()':
InitCore:68: error: 'volume' was not declared in this scope
    if (!volume.init(card)) {
         ^
InitCore:82: error: 'volume' was not declared in this scope
   pVar(volume.fatType(), TFT_GREEN, 80, Line, 1);
        ^
/home/tjohnson/sketchbook/Analog_320x240_2/SD_Functions.ino: In function 'double SDFreeSpace(double)':
SD_Functions:132: error: 'volume' was not declared in this scope
   volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
                ^
exit status 1
'volume' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

boom what to do about the volume class which i been through the source and didnt see... this is error 1

possible solution:

1) On replacing SD.h, I got a series of "volume" errors

WebServer.ino:150:1: error: 'SdVolume' does not name a type:
WebServer.ino:244:26: error: 'volume' was not declared in this scope

So I deleted the volume code completely -it seems unneeded in the SdFat code

2a) The next errors were related to the change from 'SdFile::readDir(dir_t&)' to 'FatFile::readDir(dir_t*)'
2b) and 'SdFile::open(SdFile&, const char*&, int)' to 'open(FatFileSystem* fs, const char* path, uint8_t oflag)'

another thing how do you shut this stupid streaming off? another thing i always hated about C++ streaming... eeew

it continues; try to get the BMP to display and poof broken.. infact it says my image is 2GB... its maybe 238kb

Loading image '/img/I-7.bmp'
File size: 
2223656258
Image Offset: 2223656258
Header size: 2223656258
BMP format not recognized.

even further looking into this shows its just a problem with my code that used sd.h because when i run the example Quickstart i get

Card size: 1990 MB (MB = 1,000,000 bytes)

Volume is FAT16, Cluster size (bytes): 32768

Files found (date time size name):
2017-01-26 09:06:26          0 IMG/
  2017-01-26 08:25:44     230454 I-0.BMP
  2017-01-26 08:32:00     230538 I-1.BMP
  2017-01-26 08:32:10     230538 I-2.BMP
  2017-01-26 08:32:28     230538 I-3.BMP
  2017-01-26 08:32:46     230538 I-4.BMP
  2017-01-26 08:33:04     230538 I-5.BMP
  2017-01-26 08:33:18     230538 I-6.BMP
  2017-01-26 08:33:30     230538 I-7.BMP

-TB

i can post the code in a dowload if need be but its a major mess.

Well, lets see. Do you want help, or not? If so, we (obviously, to me) need to see the code you need help with.

another thing how do you shut this stupid streaming off?

Don't use it.

another thing i always hated about C++ streaming

Are you kidding? If you want to print 3 values on one line, it is simple:

cout << value1 << ", " << value2 << ", " << value3 << endl;

Compare that with using Serial.print() or printf().

Now, suppose that you want to stop printing value2. How much effort is it to change that line above? How much effort is it to change using Serial.print()s? Using printf()?

try to get the BMP to display and poof broken

It's your code that is broken.

even further looking into this shows its just a problem with my code

Color me surprised. 8)

lol. your funny paul, i love where you chose to truncate my comment. funny none the less. heres the code.

streaming is a waste in my personal OPINION of space and time and seeing as i dont use the terminal as a primary information output in my program only diagnostic stuff that will eventually be removed streaming makes not much difference and if the project doesnt work at all well then streaming is really useless. seems to me that sd would be a pretty wanted feature in Arduino, kinda crazy that the suppoer foir it when you want todo something outside the box with it is kinda weak.

i mean look at what we have here, we have something that works SD.h and another thing that works SDFAT (by itself using examples) SD.h is aimed at beginners, and SDFat at people who know what they are doing but for the rest of us who have a complicated idea of what we are doing but only trial and error to learn it and get frustrated and quit (ps im not quitting but i know the feeling) there is no solution, I dont know enough about arduino to help myself, not the coding platform or the hardware really, ive only been with the arduino stuff a year, and my results for the most part have been very pleasing, and then i run into this which to me is a simple thing, just wanna really know how to get cwd functionality in sd.h or if i really must i would like to know the steps i would have to take pretty exactly to get my 2000 lines of code to work with a bloated supersized library (seriously not disrepectful but the current sdfat is full of things that i just dont need.) the 6 year old version was working great for me in its wrapper, so if your a beginner its the 6 year old version in a nice wrapper and if your an expert hands down its sdfat, but for the mid level guys, well nothing, maybe we should get a wrapper for the new version of sd fat? that would be like the perfect middle of the road in my opinion. i mean the questions on sdfat are numerous, when people ask questions that normally means something isnt easy so yeah, and i have read the dox and well if you dont know what your doing (which i will be the first to admit when it comes to sd fat you could tell me red was an sd volume and i would probably believe you) you really cant search for the right answer, js.

anywho, if you can help it is a hundred percent appreciated, if not thats cool too either way i do appreciate all the hard work that has been done for me with any library but i think in the end the quality comes down to useability, if i at 30 cant understand it a 10 year old sure cant. and the next gen makers are 10, and mentally im about 5.

why it does this at this point would be most helpful

Loading image '/img/I-7.bmp'
File size: 
2223656258
Image Offset: 2223656258
Header size: 2223656258
BMP format not recognized.

the code that is reading the file is this:

#define BUFFPIXEL 20
void bmpDraw(char *filename, int x, int y) {

  File     bmpFile;
  int      bmpWidth, bmpHeight;   // W+H in pixels
  uint8_t  bmpDepth;              // Bit depth (currently must be 24)
  uint32_t bmpImageoffset;        // Start of image data in file
  uint32_t rowSize;               // Not always = bmpWidth; may have padding
  uint8_t  sdbuffer[3 * BUFFPIXEL]; // pixel in buffer (R+G+B per pixel)
  uint16_t lcdbuffer[BUFFPIXEL];  // pixel out buffer (16-bit per pixel)
  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer
  boolean  goodBmp = false;       // Set to true on valid header parse
  boolean  flip    = true;        // BMP is stored bottom-to-top
  int      w, h, row, col;
  uint8_t  r, g, b;
  uint32_t pos = 0, startTime = millis();
  uint8_t  lcdidx = 0;
  boolean  first = true;

  if ((x >= tft.width()) || (y >= tft.height())) return;

  Serial.println();
  Serial.print(F("Loading image '"));
  Serial.print(filename);
  Serial.println('\'');
  // Open requested file on SD card
  if ((bmpFile = SD.open(filename)) == NULL) {
    Serial.println(F("File not found"));
    return;
  }

  // Parse BMP header
  if (read16(bmpFile) == 0x4D42) { // BMP signature
    Serial.println(F("File size: ")); Serial.println(read32(bmpFile));
    (void)read32(bmpFile); // Read & ignore creator bytes
    bmpImageoffset = read32(bmpFile); // Start of image data
    Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
    // Read DIB header
    Serial.print(F("Header size: ")); Serial.println(read32(bmpFile));
    bmpWidth  = read32(bmpFile);
    bmpHeight = read32(bmpFile);
    if (read16(bmpFile) == 1) { // # planes -- must be '1'
      bmpDepth = read16(bmpFile); // bits per pixel
      Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
      if ((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed

        goodBmp = true; // Supported BMP format -- proceed!
        Serial.print(F("Image size: "));
        Serial.print(bmpWidth);
        Serial.print('x');
        Serial.println(bmpHeight);

        // BMP rows are padded (if needed) to 4-byte boundary
        rowSize = (bmpWidth * 3 + 3) & ~3;

        // If bmpHeight is negative, image is in top-down order.
        // This is not canon but has been observed in the wild.
        if (bmpHeight < 0) {
          bmpHeight = -bmpHeight;
          flip      = false;
        }

        // Crop area to be loaded
        w = bmpWidth;
        h = bmpHeight;
        if ((x + w - 1) >= tft.width())  w = tft.width()  - x;
        if ((y + h - 1) >= tft.height()) h = tft.height() - y;

        // Set TFT address window to clipped image bounds
        tft.setAddrWindow(x, y, x + w - 1, y + h - 1);

        for (row = 0; row < h; row++) { // For each scanline...
          // Seek to start of scan line.  It might seem labor-
          // intensive to be doing this on every line, but this
          // method covers a lot of gritty details like cropping
          // and scanline padding.  Also, the seek only takes
          // place if the file position actually needs to change
          // (avoids a lot of cluster math in SD library).
          if (flip) // Bitmap is stored bottom-to-top order (normal BMP)
            pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
          else     // Bitmap is stored top-to-bottom
            pos = bmpImageoffset + row * rowSize;
          if (bmpFile.position() != pos) { // Need seek?
            bmpFile.seek(pos);
            buffidx = sizeof(sdbuffer); // Force buffer reload
          }

          for (col = 0; col < w; col++) { // For each column...
            // Time to read more pixel data?
            if (buffidx >= sizeof(sdbuffer)) { // Indeed
              // Push LCD buffer to the display first
              if (lcdidx > 0) {
                tft.pushColors(lcdbuffer, lcdidx, first);
                lcdidx = 0;
                first  = false;
              }
              bmpFile.read(sdbuffer, sizeof(sdbuffer));
              buffidx = 0; // Set index to beginning
            }

            // Convert pixel from BMP to TFT format
            b = sdbuffer[buffidx++];
            g = sdbuffer[buffidx++];
            r = sdbuffer[buffidx++];
            lcdbuffer[lcdidx++] = tft.color565(r, g, b);
          } // end pixel
        } // end scanline
        // Write any remaining data to LCD
        if (lcdidx > 0) {
          tft.pushColors(lcdbuffer, lcdidx, first);
        }
        Serial.print(F("Loaded in "));
        Serial.print(millis() - startTime);
        Serial.println(" ms");
      } // end goodBmp
    }
  }

  bmpFile.close();
  if (!goodBmp) Serial.println(F("BMP format not recognized."));
}

// These read 16- and 32-bit types from the SD card file.
// BMP data is stored little-endian, Arduino is little-endian too.
// May need to reverse subscript order if porting elsewhere.

uint16_t read16(File f) {
  uint16_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read(); // MSB
  return result;
}

uint32_t read32(File 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;
}

which is Bodmers code and is meant to be used with sdfat... worked in sd.h just not here

Tbcode.zip (64.1 KB)

seriously not disrepectful but the current sdfat is full of things that i just dont need.

So? If you don't use some functionality, the linker won't link it in. If you do, the linker will. Having 300 extra functions that you never call (directly or indirectly) will NOT result in your sketch getting larger.

  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer

Why do you start by pointing beyond the end of the array?

What I would do to debug the issue is to have two copies of the code - one using SD and one using SdFat. Read the file, byte by byte (or just the first 100 bytes) and print the value that you read.d

Compare the two outputs. If the read() function in each library is returning the same value (and I can't imagine that they aren't), then the problem is with how you use the data in one or the other sketches.

Combine the bytes as you do in read16() and read32(), and print those values, instead of the individual bytes. Are you getting the same results?

PaulS:

  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer

Why do you start by pointing beyond the end of the array?

What I would do to debug the issue is to have two copies of the code - one using SD and one using SdFat. Read the file, byte by byte (or just the first 100 bytes) and print the value that you read.d

Compare the two outputs. If the read() function in each library is returning the same value (and I can't imagine that they aren't), then the problem is with how you use the data in one or the other sketches.

Combine the bytes as you do in read16() and read32(), and print those values, instead of the individual bytes. Are you getting the same results?

the code like i say is Bodmers, i dont know what its looking at it used to work and now it doesnt. i will go check on they byte thing. i cant see how good code goes bad changing one library that is supposd to essentially do the same thing brb ill let you know...

with SD.h

done!

Loading image '/img/I-7.bmp'
19778
File size: 
230538
Image Offset: 138
Header size: 124
1
24
Bit Depth: 24
Image size: 320x240
Loaded in 3432 ms

with sdfat

Card successfully initialized.

Card size: 1990 MB (MB = 1,000,000 bytes)

Volume is FAT16, Cluster size (bytes): 32768


Loading image '/img/I-7.bmp'
19778
File size: 
2223656258
Image Offset: 2223656258
Header size: 2223656258
19778
BMP format not recognized.

either one gives me the 19778, only one loads the image.

I hate anonymous printing. I'm looking at that output (with no code to back it up) and seeing 19778. I'm going to guess that you printed your shoe size.

Am I right? You must have big feet.

tbillion:

Card successfully initialized.

Card size: 1990 MB (MB = 1,000,000 bytes)

Volume is FAT16, Cluster size (bytes): 32768

Loading image '/img/I-7.bmp'
19778
File size:
2223656258
Image Offset: 2223656258
Header size: 2223656258
19778
BMP format not recognized.

The clue to what is happening is in the printed result, reading the file keeps returning the same value. If you convert 2223656258 to hexadecimal you get 8364D42, note that the LS 2 bytes is the BMP start of file signature bytes 0x4D42. The conclusion therefore is that the file pointer is not incrementing.

Now looking at the read16() and read32() functions we can see the bug, there is a "&" missing after the "File" it should read File& f so the local copy of the incremented file pointer gets passed back. Correct you code to:

uint16_t read16(File& f) {
  uint16_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read(); // MSB
  return result;
}

uint32_t read32(File& 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;
}

Bodmer, man you are my hero and truly a god member, A million thanks. seriously!

PaulS:
I hate anonymous printing. I'm looking at that output (with no code to back it up) and seeing 19778. I'm going to guess that you printed your shoe size.

Am I right? You must have big feet.

Yup enormous feet, Thank you too paul for both the help and the entertainment :slight_smile: Karma for all :wink: