Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add end() method #79

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions examples/CardInfo/CardInfo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
Sd2Card card;
SdFatFs fatFs;

void setup()
{
void setup() {
bool disp = false;
// Open serial communications and wait for port to open:
Serial.begin(9600);

while (!Serial);
while (!Serial)
;
Serial.print("\nInitializing SD card...");
while(!card.init(SD_DETECT_PIN)) {
while (!card.init(SD_DETECT_PIN)) {
if (!disp) {
Serial.println("initialization failed. Is a card inserted?");
disp = true;
Expand Down Expand Up @@ -66,9 +66,9 @@ void setup()
Serial.println(fatFs.fatType(), DEC);
Serial.println();

volumesize = fatFs.blocksPerCluster(); // clusters are collections of blocks
volumesize *= fatFs.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
volumesize = fatFs.blocksPerCluster(); // clusters are collections of blocks
volumesize *= fatFs.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
Expand All @@ -85,6 +85,13 @@ void setup()
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
root.close();
if (!fatFs.deinit()) {
Serial.println("Failed to deinit card");
}
if (!card.deinit()) {
Serial.println("Failed to deinit card");
}

Serial.println("###### End of the SD tests ######");
}

Expand Down
15 changes: 6 additions & 9 deletions examples/Datalogger/Datalogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@
#define SD_DETECT_PIN SD_DETECT_NONE
#endif

uint32_t A[] = { A0, A1, A2};
uint32_t A[] = { A0, A1, A2 };

File dataFile;

void setup()
{
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
while (!SD.begin(SD_DETECT_PIN))
{
while (!SD.begin(SD_DETECT_PIN)) {
delay(10);
}
delay(100);
Expand All @@ -52,8 +50,7 @@ void setup()
}
}

void loop()
{
void loop() {
// make a string for assembling the data to log:
String dataString = "";

Expand All @@ -70,7 +67,7 @@ void loop()
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.flush(); // use flush to ensure the data written
dataFile.flush(); // use flush to ensure the data written
// print to the serial port too:
Serial.println(dataString);
}
Expand Down
14 changes: 7 additions & 7 deletions examples/DumpFile/DumpFile.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@
#define SD_DETECT_PIN SD_DETECT_NONE
#endif

void setup()
{
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
; // wait for serial port to connect. Needed for Leonardo only
}


Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
while (!SD.begin(SD_DETECT_PIN))
{
while (!SD.begin(SD_DETECT_PIN)) {
delay(10);
}
delay(100);
Expand All @@ -52,9 +50,11 @@ void setup()
else {
Serial.println("error opening datalog.txt");
}
if (!SD.end()) {
Serial.println("Failed to properly end the SD.");
}
Serial.println("###### End of the SD tests ######");
}

void loop()
{
void loop() {
}
24 changes: 11 additions & 13 deletions examples/Files/Files.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,37 @@

File myFile;

void setup()
{
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
; // wait for serial port to connect. Needed for Leonardo only
}


Serial.print("Initializing SD card...");

while (!SD.begin(SD_DETECT_PIN))
{
while (!SD.begin(SD_DETECT_PIN)) {
delay(10);
}
Serial.println("initialization done.");

if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
}
else {
} else {
Serial.println("example.txt doesn't exist.");
}

// open a new file and immediately close it:
Serial.println("Creating example.txt...");
Serial.flush();
myFile = SD.open("example.txt", FILE_WRITE);
myFile.close();

// Check to see if the file exists:
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
}
else {
} else {
Serial.println("example.txt doesn't exist.");
}

Expand All @@ -61,14 +58,15 @@ void setup()

if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
}
else {
} else {
Serial.println("example.txt doesn't exist.");
}
if (!SD.end()) {
Serial.println("Failed to properly end the SD.");
}
Serial.println("###### End of the SD tests ######");
}

void loop()
{
void loop() {
// nothing happens after setup finishes.
}
Loading