Skip to content

Commit 39881ec

Browse files
committed
ATLEDGE-393 Update SD library
Rebase library from version 1.05 to 1.06 Fixes issue with passing String class object to SD.exists()
1 parent bca4512 commit 39881ec

File tree

10 files changed

+84
-77
lines changed

10 files changed

+84
-77
lines changed

libraries/SD/examples/CardInfo/CardInfo.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ SdFile root;
3434
// Sparkfun SD shield: pin 8
3535
const int chipSelect = 4;
3636

37-
void setup()
38-
{
37+
void setup() {
3938
// Open serial communications and wait for port to open:
4039
Serial.begin(9600);
4140
while (!Serial) {
42-
; // wait for serial port to connect. Needed for Leonardo only
41+
; // wait for serial port to connect. Needed for native USB port only
4342
}
4443

4544

libraries/SD/examples/Datalogger/Datalogger.ino

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525

2626
const int chipSelect = 4;
2727

28-
void setup()
29-
{
28+
void setup() {
3029
// Open serial communications and wait for port to open:
3130
Serial.begin(9600);
3231
while (!Serial) {
33-
; // wait for serial port to connect. Needed for Leonardo only
32+
; // wait for serial port to connect. Needed for native USB port only
3433
}
3534

3635

@@ -45,8 +44,7 @@ void setup()
4544
Serial.println("card initialized.");
4645
}
4746

48-
void loop()
49-
{
47+
void loop() {
5048
// make a string for assembling the data to log:
5149
String dataString = "";
5250

libraries/SD/examples/DumpFile/DumpFile.ino

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525

2626
const int chipSelect = 4;
2727

28-
void setup()
29-
{
28+
void setup() {
3029
// Open serial communications and wait for port to open:
3130
Serial.begin(9600);
3231
while (!Serial) {
33-
; // wait for serial port to connect. Needed for Leonardo only
32+
; // wait for serial port to connect. Needed for native USB port only
3433
}
3534

3635

@@ -61,7 +60,6 @@ void setup()
6160
}
6261
}
6362

64-
void loop()
65-
{
63+
void loop() {
6664
}
6765

libraries/SD/examples/Files/Files.ino

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222

2323
File myFile;
2424

25-
void setup()
26-
{
25+
void setup() {
2726
// Open serial communications and wait for port to open:
2827
Serial.begin(9600);
2928
while (!Serial) {
30-
; // wait for serial port to connect. Needed for Leonardo only
29+
; // wait for serial port to connect. Needed for native USB port only
3130
}
3231

3332

@@ -41,8 +40,7 @@ void setup()
4140

4241
if (SD.exists("example.txt")) {
4342
Serial.println("example.txt exists.");
44-
}
45-
else {
43+
} else {
4644
Serial.println("example.txt doesn't exist.");
4745
}
4846

@@ -54,8 +52,7 @@ void setup()
5452
// Check to see if the file exists:
5553
if (SD.exists("example.txt")) {
5654
Serial.println("example.txt exists.");
57-
}
58-
else {
55+
} else {
5956
Serial.println("example.txt doesn't exist.");
6057
}
6158

@@ -65,14 +62,12 @@ void setup()
6562

6663
if (SD.exists("example.txt")) {
6764
Serial.println("example.txt exists.");
68-
}
69-
else {
65+
} else {
7066
Serial.println("example.txt doesn't exist.");
7167
}
7268
}
7369

74-
void loop()
75-
{
70+
void loop() {
7671
// nothing happens after setup finishes.
7772
}
7873

libraries/SD/examples/ReadWrite/ReadWrite.ino

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323

2424
File myFile;
2525

26-
void setup()
27-
{
26+
void setup() {
2827
// Open serial communications and wait for port to open:
2928
Serial.begin(9600);
3029
while (!Serial) {
31-
; // wait for serial port to connect. Needed for Leonardo only
30+
; // wait for serial port to connect. Needed for native USB port only
3231
}
3332

3433

@@ -73,8 +72,7 @@ void setup()
7372
}
7473
}
7574

76-
void loop()
77-
{
75+
void loop() {
7876
// nothing happens after setup
7977
}
8078

libraries/SD/examples/listfiles/listfiles.ino

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
Listfiles
3-
4-
This example shows how print out the files in a
5-
directory on a SD card
6-
3+
4+
This example shows how print out the files in a
5+
directory on a SD card
6+
77
The circuit:
88
* SD card attached to SPI bus as follows:
99
** MOSI - pin 11
@@ -17,7 +17,7 @@
1717
by Tom Igoe
1818
modified 2 Feb 2014
1919
by Scott Fitzgerald
20-
20+
2121
This example code is in the public domain.
2222
2323
*/
@@ -26,12 +26,11 @@
2626

2727
File root;
2828

29-
void setup()
30-
{
29+
void setup() {
3130
// Open serial communications and wait for port to open:
3231
Serial.begin(9600);
3332
while (!Serial) {
34-
; // wait for serial port to connect. Needed for Leonardo only
33+
; // wait for serial port to connect. Needed for native USB port only
3534
}
3635

3736
Serial.print("Initializing SD card...");
@@ -49,33 +48,32 @@ void setup()
4948
Serial.println("done!");
5049
}
5150

52-
void loop()
53-
{
51+
void loop() {
5452
// nothing happens after setup finishes.
5553
}
5654

5755
void printDirectory(File dir, int numTabs) {
58-
while(true) {
59-
60-
File entry = dir.openNextFile();
61-
if (! entry) {
62-
// no more files
63-
break;
64-
}
65-
for (uint8_t i=0; i<numTabs; i++) {
66-
Serial.print('\t');
67-
}
68-
Serial.print(entry.name());
69-
if (entry.isDirectory()) {
70-
Serial.println("/");
71-
printDirectory(entry, numTabs+1);
72-
} else {
73-
// files have sizes, directories do not
74-
Serial.print("\t\t");
75-
Serial.println(entry.size(), DEC);
76-
}
77-
entry.close();
78-
}
56+
while (true) {
57+
58+
File entry = dir.openNextFile();
59+
if (! entry) {
60+
// no more files
61+
break;
62+
}
63+
for (uint8_t i = 0; i < numTabs; i++) {
64+
Serial.print('\t');
65+
}
66+
Serial.print(entry.name());
67+
if (entry.isDirectory()) {
68+
Serial.println("/");
69+
printDirectory(entry, numTabs + 1);
70+
} else {
71+
// files have sizes, directories do not
72+
Serial.print("\t\t");
73+
Serial.println(entry.size(), DEC);
74+
}
75+
entry.close();
76+
}
7977
}
8078

8179

libraries/SD/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
SD KEYWORD1 SD
1010
File KEYWORD1 SD
11+
SDFile KEYWORD1 SD
1112

1213
#######################################
1314
# Methods and Functions (KEYWORD2)

libraries/SD/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SD
2-
version=1.0.5
2+
version=1.0.6
33
author=Arduino, SparkFun
44
maintainer=Arduino <info@arduino.cc>
55
sentence=Enables reading and writing on SD cards. For all Arduino boards.

libraries/SD/src/SD.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@
5252

5353
#include "SD.h"
5454

55+
namespace SDLib {
56+
5557
// Used by `getNextPathComponent`
5658
#define MAX_COMPONENT_LEN 12 // What is max length?
5759
#define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1
5860

59-
bool getNextPathComponent(char *path, unsigned int *p_offset,
61+
bool getNextPathComponent(const char *path, unsigned int *p_offset,
6062
char *buffer) {
6163
/*
6264
@@ -115,9 +117,9 @@ bool getNextPathComponent(char *path, unsigned int *p_offset,
115117

116118

117119

118-
boolean walkPath(char *filepath, SdFile& parentDir,
120+
boolean walkPath(const char *filepath, SdFile& parentDir,
119121
boolean (*callback)(SdFile& parentDir,
120-
char *filePathComponent,
122+
const char *filePathComponent,
121123
boolean isLastComponent,
122124
void *object),
123125
void *object = NULL) {
@@ -230,7 +232,7 @@ boolean walkPath(char *filepath, SdFile& parentDir,
230232
231233
*/
232234

233-
boolean callback_pathExists(SdFile& parentDir, char *filePathComponent,
235+
boolean callback_pathExists(SdFile& parentDir, const char *filePathComponent,
234236
boolean isLastComponent, void *object) {
235237
/*
236238
@@ -253,7 +255,7 @@ boolean callback_pathExists(SdFile& parentDir, char *filePathComponent,
253255

254256

255257

256-
boolean callback_makeDirPath(SdFile& parentDir, char *filePathComponent,
258+
boolean callback_makeDirPath(SdFile& parentDir, const char *filePathComponent,
257259
boolean isLastComponent, void *object) {
258260
/*
259261
@@ -308,15 +310,15 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,
308310

309311

310312

311-
boolean callback_remove(SdFile& parentDir, char *filePathComponent,
313+
boolean callback_remove(SdFile& parentDir, const char *filePathComponent,
312314
boolean isLastComponent, void *object) {
313315
if (isLastComponent) {
314316
return SdFile::remove(parentDir, filePathComponent);
315317
}
316318
return true;
317319
}
318320

319-
boolean callback_rmdir(SdFile& parentDir, char *filePathComponent,
321+
boolean callback_rmdir(SdFile& parentDir, const char *filePathComponent,
320322
boolean isLastComponent, void *object) {
321323
if (isLastComponent) {
322324
SdFile f;
@@ -515,7 +517,7 @@ File SDClass::open(char *filepath, uint8_t mode) {
515517
//}
516518

517519

518-
boolean SDClass::exists(char *filepath) {
520+
boolean SDClass::exists(const char *filepath) {
519521
/*
520522
521523
Returns true if the supplied file path exists.
@@ -536,7 +538,7 @@ boolean SDClass::exists(char *filepath) {
536538
//}
537539

538540

539-
boolean SDClass::mkdir(char *filepath) {
541+
boolean SDClass::mkdir(const char *filepath) {
540542
/*
541543
542544
Makes a single directory or a heirarchy of directories.
@@ -547,7 +549,7 @@ boolean SDClass::mkdir(char *filepath) {
547549
return walkPath(filepath, root, callback_makeDirPath);
548550
}
549551

550-
boolean SDClass::rmdir(char *filepath) {
552+
boolean SDClass::rmdir(const char *filepath) {
551553
/*
552554
553555
Remove a single directory or a heirarchy of directories.
@@ -558,7 +560,7 @@ boolean SDClass::rmdir(char *filepath) {
558560
return walkPath(filepath, root, callback_rmdir);
559561
}
560562

561-
boolean SDClass::remove(char *filepath) {
563+
boolean SDClass::remove(const char *filepath) {
562564
return walkPath(filepath, root, callback_remove);
563565
}
564566

@@ -614,3 +616,5 @@ void File::rewindDirectory(void) {
614616
}
615617

616618
SDClass SD;
619+
620+
};

0 commit comments

Comments
 (0)