Skip to content

Commit 37115d0

Browse files
committed
Backported SD library from 1.5.x
1 parent b9b0fcd commit 37115d0

File tree

15 files changed

+212
-107
lines changed

15 files changed

+212
-107
lines changed

libraries/SD/SD.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,9 @@ boolean SDClass::mkdir(char *filepath) {
550550
boolean SDClass::rmdir(char *filepath) {
551551
/*
552552
553-
Makes a single directory or a heirarchy of directories.
553+
Remove a single directory or a heirarchy of directories.
554554
555-
A rough equivalent to `mkdir -p`.
555+
A rough equivalent to `rm -rf`.
556556
557557
*/
558558
return walkPath(filepath, root, callback_rmdir);

libraries/SD/examples/CardInfo/CardInfo.ino

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
/*
2-
SD card test
3-
2+
SD card test
3+
44
This example shows how use the utility libraries on which the'
55
SD library is based in order to get info about your SD card.
66
Very useful for testing a card when you're not sure whether its working or not.
7-
7+
88
The circuit:
99
* SD card attached to SPI bus as follows:
1010
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
1111
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
1212
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
13-
** CS - depends on your SD card shield or module.
13+
** CS - depends on your SD card shield or module.
1414
Pin 4 used here for consistency with other Arduino examples
1515
16-
16+
1717
created 28 Mar 2011
18-
by Limor Fried
18+
by Limor Fried
1919
modified 9 Apr 2012
2020
by Tom Igoe
2121
*/
22-
// include the SD library:
22+
// include the SD library:
23+
#include <SPI.h>
2324
#include <SD.h>
2425

2526
// set up variables using the SD utility library functions:
@@ -31,22 +32,22 @@ SdFile root;
3132
// Arduino Ethernet shield: pin 4
3233
// Adafruit SD shields and modules: pin 10
3334
// Sparkfun SD shield: pin 8
34-
const int chipSelect = 4;
35+
const int chipSelect = 4;
3536

3637
void setup()
3738
{
38-
// Open serial communications and wait for port to open:
39+
// Open serial communications and wait for port to open:
3940
Serial.begin(9600);
40-
while (!Serial) {
41+
while (!Serial) {
4142
; // wait for serial port to connect. Needed for Leonardo only
4243
}
4344

4445

4546
Serial.print("\nInitializing SD card...");
4647
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
47-
// Note that even if it's not used as the CS pin, the hardware SS pin
48-
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
49-
// or the SD library functions will not work.
48+
// Note that even if it's not used as the CS pin, the hardware SS pin
49+
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
50+
// or the SD library functions will not work.
5051
pinMode(10, OUTPUT); // change this to 53 on a mega
5152

5253

@@ -59,12 +60,12 @@ void setup()
5960
Serial.println("* did you change the chipSelect pin to match your shield or module?");
6061
return;
6162
} else {
62-
Serial.println("Wiring is correct and a card is present.");
63+
Serial.println("Wiring is correct and a card is present.");
6364
}
6465

6566
// print the type of card
6667
Serial.print("\nCard type: ");
67-
switch(card.type()) {
68+
switch (card.type()) {
6869
case SD_CARD_TYPE_SD1:
6970
Serial.println("SD1");
7071
break;
@@ -90,7 +91,7 @@ void setup()
9091
Serial.print("\nVolume type is FAT");
9192
Serial.println(volume.fatType(), DEC);
9293
Serial.println();
93-
94+
9495
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
9596
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
9697
volumesize *= 512; // SD card blocks are always 512 bytes
@@ -103,15 +104,15 @@ void setup()
103104
volumesize /= 1024;
104105
Serial.println(volumesize);
105106

106-
107+
107108
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
108109
root.openRoot(volume);
109-
110+
110111
// list all files in the card with date and size
111112
root.ls(LS_R | LS_DATE | LS_SIZE);
112113
}
113114

114115

115116
void loop(void) {
116-
117+
117118
}

libraries/SD/examples/Datalogger/Datalogger.ino

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
/*
22
SD card datalogger
3-
4-
This example shows how to log data from three analog sensors
3+
4+
This example shows how to log data from three analog sensors
55
to an SD card using the SD library.
6-
6+
77
The circuit:
88
* analog sensors on analog ins 0, 1, and 2
99
* SD card attached to SPI bus as follows:
1010
** MOSI - pin 11
1111
** MISO - pin 12
1212
** CLK - pin 13
1313
** CS - pin 4
14-
14+
1515
created 24 Nov 2010
1616
modified 9 Apr 2012
1717
by Tom Igoe
18-
18+
1919
This example code is in the public domain.
20-
20+
2121
*/
2222

23+
#include <SPI.h>
2324
#include <SD.h>
2425

2526
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
@@ -30,9 +31,9 @@ const int chipSelect = 4;
3031

3132
void setup()
3233
{
33-
// Open serial communications and wait for port to open:
34+
// Open serial communications and wait for port to open:
3435
Serial.begin(9600);
35-
while (!Serial) {
36+
while (!Serial) {
3637
; // wait for serial port to connect. Needed for Leonardo only
3738
}
3839

@@ -41,7 +42,7 @@ void setup()
4142
// make sure that the default chip select pin is set to
4243
// output, even if you don't use it:
4344
pinMode(10, OUTPUT);
44-
45+
4546
// see if the card is present and can be initialized:
4647
if (!SD.begin(chipSelect)) {
4748
Serial.println("Card failed, or not present");
@@ -61,7 +62,7 @@ void loop()
6162
int sensor = analogRead(analogPin);
6263
dataString += String(sensor);
6364
if (analogPin < 2) {
64-
dataString += ",";
65+
dataString += ",";
6566
}
6667
}
6768

@@ -75,11 +76,11 @@ void loop()
7576
dataFile.close();
7677
// print to the serial port too:
7778
Serial.println(dataString);
78-
}
79+
}
7980
// if the file isn't open, pop up an error:
8081
else {
8182
Serial.println("error opening datalog.txt");
82-
}
83+
}
8384
}
8485

8586

libraries/SD/examples/DumpFile/DumpFile.ino

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
/*
22
SD card file dump
3-
3+
44
This example shows how to read a file from the SD card using the
55
SD library and send it over the serial port.
6-
6+
77
The circuit:
88
* SD card attached to SPI bus as follows:
99
** MOSI - pin 11
1010
** MISO - pin 12
1111
** CLK - pin 13
1212
** CS - pin 4
13-
13+
1414
created 22 December 2010
1515
by Limor Fried
1616
modified 9 Apr 2012
1717
by Tom Igoe
18-
18+
1919
This example code is in the public domain.
20-
20+
2121
*/
2222

23+
#include <SPI.h>
2324
#include <SD.h>
2425

2526
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
@@ -30,9 +31,9 @@ const int chipSelect = 4;
3031

3132
void setup()
3233
{
33-
// Open serial communications and wait for port to open:
34+
// Open serial communications and wait for port to open:
3435
Serial.begin(9600);
35-
while (!Serial) {
36+
while (!Serial) {
3637
; // wait for serial port to connect. Needed for Leonardo only
3738
}
3839

@@ -41,15 +42,15 @@ void setup()
4142
// make sure that the default chip select pin is set to
4243
// output, even if you don't use it:
4344
pinMode(10, OUTPUT);
44-
45+
4546
// see if the card is present and can be initialized:
4647
if (!SD.begin(chipSelect)) {
4748
Serial.println("Card failed, or not present");
4849
// don't do anything more:
4950
return;
5051
}
5152
Serial.println("card initialized.");
52-
53+
5354
// open the file. note that only one file can be open at a time,
5455
// so you have to close this one before opening another.
5556
File dataFile = SD.open("datalog.txt");
@@ -60,11 +61,11 @@ void setup()
6061
Serial.write(dataFile.read());
6162
}
6263
dataFile.close();
63-
}
64+
}
6465
// if the file isn't open, pop up an error:
6566
else {
6667
Serial.println("error opening datalog.txt");
67-
}
68+
}
6869
}
6970

7071
void loop()

libraries/SD/examples/Files/Files.ino

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
/*
22
SD card basic file example
3-
4-
This example shows how to create and destroy an SD card file
3+
4+
This example shows how to create and destroy an SD card file
55
The circuit:
66
* SD card attached to SPI bus as follows:
77
** MOSI - pin 11
88
** MISO - pin 12
99
** CLK - pin 13
1010
** CS - pin 4
11-
11+
1212
created Nov 2010
1313
by David A. Mellis
1414
modified 9 Apr 2012
1515
by Tom Igoe
16-
16+
1717
This example code is in the public domain.
18-
18+
1919
*/
20+
#include <SPI.h>
2021
#include <SD.h>
2122

2223
File myFile;
2324

2425
void setup()
2526
{
26-
// Open serial communications and wait for port to open:
27+
// Open serial communications and wait for port to open:
2728
Serial.begin(9600);
28-
while (!Serial) {
29+
while (!Serial) {
2930
; // wait for serial port to connect. Needed for Leonardo only
3031
}
3132

3233

3334
Serial.print("Initializing SD card...");
3435
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
35-
// Note that even if it's not used as the CS pin, the hardware SS pin
36-
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
37-
// or the SD library functions will not work.
36+
// Note that even if it's not used as the CS pin, the hardware SS pin
37+
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
38+
// or the SD library functions will not work.
3839
pinMode(10, OUTPUT);
3940

4041
if (!SD.begin(4)) {
@@ -55,23 +56,23 @@ void setup()
5556
myFile = SD.open("example.txt", FILE_WRITE);
5657
myFile.close();
5758

58-
// Check to see if the file exists:
59+
// Check to see if the file exists:
5960
if (SD.exists("example.txt")) {
6061
Serial.println("example.txt exists.");
6162
}
6263
else {
63-
Serial.println("example.txt doesn't exist.");
64+
Serial.println("example.txt doesn't exist.");
6465
}
6566

6667
// delete the file:
6768
Serial.println("Removing example.txt...");
6869
SD.remove("example.txt");
6970

70-
if (SD.exists("example.txt")){
71+
if (SD.exists("example.txt")) {
7172
Serial.println("example.txt exists.");
7273
}
7374
else {
74-
Serial.println("example.txt doesn't exist.");
75+
Serial.println("example.txt doesn't exist.");
7576
}
7677
}
7778

0 commit comments

Comments
 (0)