<p>Hey there, I just got the MicroSD module for Arduino and
used the SDuFAT
library on it. I think I found and fixed one bug, made one change
that
probably makes it better and have a couple of requests so here
goes:</p><p> </p><p>1 - File SDuFAT.cpp in
function append(const char*
filename), the original code exits the function with
statement:</p><p>return print("hola.txt",
data);</p><p> </p><p>I think you meant to
write:</p><p>return
print(filename, data);</p><p> </p><p>I
changed it and now your example
code works (for cases W and A) even with files which are not named
"hola.txt".</p><p> </p><p>2 - File
SDuFAT.cpp in function
del(const char* filename), the code just reads all of a file's
sectors and
dumps a zero at the start of each. This is OK for small files.
However, I
am using a whole 2 Gb SD card containing one big file with 0x03 at
the end
for generic logging data storage. Deleting the whole thing is
probably
going to take a couple of centuries and is unnecessary 99% of the
time
since the card will practically never fill up. So, I changed the
line where
the zero gets written to the start of the sector
from:</p><p>buffer[0] =
EOF;</p><p> </p><p>to</p><p>if
(buffer[0] == EOF) {</p><p>
return 0;</p><p>} else {</p><p> buffer[0] =
EOF;</p><p>}</p><p> </p><p>in
order to only delete the written part of
the file.</p><p> </p><p>I could have made
some grave error (I 'm a
Java programmer so C++ is totally new to me) but if I got things
right, I
think both these changes are in line with the spirit of the library
which
should be updated for useability asap. Change 2 might perhaps need a
separate function or whatever.</p><p>
</p><p>Now, the feature
requests. Could you please add a couple of functions for
repositioning the
file counter? Right now, if we have a file and want to overwrite its
data
we have to delete it using "del" (might be time consuming
and
unnecessary). Could you please add a couple of functions for dumping
the
counter at an arbitrary position in the file (or at the very least,
something like rewind() for going to the first byte and starting to
write
from there onwards)? I looked at function print(const char*
filename, char*
data) which looks like a good candidate for that sort of thing and
it looks
like the lines:</p><p>// check where to start writing in
the file<br />//
these calls will init sector and length<br />int offset1 =
0;<br />long
file1Length = usedBytes(filename);<br />offset1 = (int)
(file1Length %
BYTESPERSECTOR);<br />sectors = file1Length /
BYTESPERSECTOR;</p><p> </p><p>are what I
should be playing with but I
'm not confident with C++ and I 'm afraid of breaking
things.</p><p> </p><p>Thanks.</p>
Reported by David Cuartielles, Feb 17, 2010
<p>Hey there, I just got the MicroSD module for Arduino and used the SDuFAT library on it. I think I found and fixed one bug, made one change that probably makes it better and have a couple of requests so here goes:</p><p> </p><p>1 - File SDuFAT.cpp in function append(const char* filename), the original code exits the function with statement:</p><p>return print("hola.txt", data);</p><p> </p><p>I think you meant to write:</p><p>return print(filename, data);</p><p> </p><p>I changed it and now your example code works (for cases W and A) even with files which are not named "hola.txt".</p><p> </p><p>2 - File SDuFAT.cpp in function del(const char* filename), the code just reads all of a file's sectors and dumps a zero at the start of each. This is OK for small files. However, I am using a whole 2 Gb SD card containing one big file with 0x03 at the end for generic logging data storage. Deleting the whole thing is probably going to take a couple of centuries and is unnecessary 99% of the time since the card will practically never fill up. So, I changed the line where the zero gets written to the start of the sector from:</p><p>buffer[0] = EOF;</p><p> </p><p>to</p><p>if (buffer[0] == EOF) {</p><p> return 0;</p><p>} else {</p><p> buffer[0] = EOF;</p><p>}</p><p> </p><p>in order to only delete the written part of the file.</p><p> </p><p>I could have made some grave error (I 'm a Java programmer so C++ is totally new to me) but if I got things right, I think both these changes are in line with the spirit of the library which should be updated for useability asap. Change 2 might perhaps need a separate function or whatever.</p><p> </p><p>Now, the feature requests. Could you please add a couple of functions for repositioning the file counter? Right now, if we have a file and want to overwrite its data we have to delete it using "del" (might be time consuming and unnecessary). Could you please add a couple of functions for dumping the counter at an arbitrary position in the file (or at the very least, something like rewind() for going to the first byte and starting to write from there onwards)? I looked at function print(const char* filename, char* data) which looks like a good candidate for that sort of thing and it looks like the lines:</p><p>// check where to start writing in the file<br />// these calls will init sector and length<br />int offset1 = 0;<br />long file1Length = usedBytes(filename);<br />offset1 = (int) (file1Length % BYTESPERSECTOR);<br />sectors = file1Length / BYTESPERSECTOR;</p><p> </p><p>are what I should be playing with but I 'm not confident with C++ and I 'm afraid of breaking things.</p><p> </p><p>Thanks.</p>