mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-01 06:22:01 +08:00

* Update WebSocket library * Update SSDP library * Update TFT_eSPI library * Update EspLuaEngine library * Update SDFat library * Change to pioarduino * Make ESP3DMessageFIFO and ESP3DMessage more thread safe * Fix sanity checks for BT * Add some C6 support * Refactor ethernet code * Split Ethernet Sta / WiFi sta ESP Commands and settings * Simplify wait and wdtFeed code * Set C3 with 4MB by default in platformio.ini * Apply Disable brown out only on ESP32 to avoid crash e.g:ESP32S3 * Add missing entries in platformio.ini
78 lines
1.8 KiB
C++
78 lines
1.8 KiB
C++
/*
|
|
* Append Example
|
|
*
|
|
* This program shows how to use open for append.
|
|
* The program will append 100 line each time it opens the file.
|
|
* The program will open and close the file 100 times.
|
|
*/
|
|
#include <SPI.h>
|
|
#include "SdFat.h"
|
|
#include "sdios.h"
|
|
|
|
// SD chip select pin
|
|
const uint8_t chipSelect = SS;
|
|
|
|
// file system object
|
|
SdFat sd;
|
|
|
|
// create Serial stream
|
|
ArduinoOutStream cout(Serial);
|
|
|
|
// store error strings in flash to save RAM
|
|
#define error(s) sd.errorHalt(F(s))
|
|
//------------------------------------------------------------------------------
|
|
void setup() {
|
|
// filename for this example
|
|
char name[] = "append.txt";
|
|
|
|
Serial.begin(9600);
|
|
|
|
// Wait for USB Serial
|
|
while (!Serial) {
|
|
yield();
|
|
}
|
|
// F() stores strings in flash to save RAM
|
|
cout << endl << F("Type any character to start\n");
|
|
while (!Serial.available()) {
|
|
yield();
|
|
}
|
|
|
|
// Initialize at the highest speed supported by the board that is
|
|
// not over 50 MHz. Try a lower speed if SPI errors occur.
|
|
if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
|
|
sd.initErrorHalt();
|
|
}
|
|
|
|
cout << F("Appending to: ") << name;
|
|
|
|
for (uint8_t i = 0; i < 100; i++) {
|
|
// open stream for append
|
|
ofstream sdout(name, ios::out | ios::app);
|
|
if (!sdout) {
|
|
error("open failed");
|
|
}
|
|
|
|
// append 100 lines to the file
|
|
for (uint8_t j = 0; j < 100; j++) {
|
|
// use int() so byte will print as decimal number
|
|
sdout << "line " << int(j) << " of pass " << int(i);
|
|
sdout << " millis = " << millis() << endl;
|
|
}
|
|
// close the stream
|
|
sdout.close();
|
|
|
|
if (!sdout) {
|
|
error("append data failed");
|
|
}
|
|
|
|
// output progress indicator
|
|
if (i % 25 == 0) {
|
|
cout << endl;
|
|
}
|
|
cout << '.';
|
|
}
|
|
cout << endl << "Done" << endl;
|
|
}
|
|
//------------------------------------------------------------------------------
|
|
void loop() {}
|