本文整理汇总了C++中SdFile::println方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFile::println方法的具体用法?C++ SdFile::println怎么用?C++ SdFile::println使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SdFile
的用法示例。
在下文中一共展示了SdFile::println方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loop
void loop(void) {
// clear print error
file.writeError = 0;
delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
// log time
uint32_t m = millis();
file.print(m);
#if ECHO_TO_SERIAL
Serial.print(m);
#endif //ECHO_TO_SERIAL
// add sensor data
for (uint8_t ia = 0; ia < SENSOR_COUNT; ia++) {
uint16_t data = analogRead(ia);
file.print(',');
file.print(data);
#if ECHO_TO_SERIAL
Serial.print(',');
Serial.print(data);
#endif //ECHO_TO_SERIAL
}
file.println();
#if ECHO_TO_SERIAL
Serial.println();
#endif //ECHO_TO_SERIAL
if (file.writeError) error("write data failed");
//don't sync too often - requires 2048 bytes of I/O to SD card
if ((millis() - syncTime) < SYNC_INTERVAL) return;
syncTime = millis();
if (!file.sync()) error("sync failed");
}
示例2: setup
void setup(void) {
Serial.begin(BPS_115200);
Serial.println();
#if WAIT_TO_START
Serial.println("Type any character to start");
while (!Serial.available());
#endif //WAIT_TO_START
// initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
if (!card.init(SPI_HALF_SPEED)) error("card.init failed");
// initialize a FAT volume
if (!volume.init(&card)) error("volume.init failed");
// open root directory
if (!root.openRoot(&volume)) error("openRoot failed");
// create a new file
char name[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
name[6] = i/10 + '0';
name[7] = i%10 + '0';
if (file.open(&root, name, O_CREAT | O_EXCL | O_WRITE)) break;
}
if (!file.isOpen()) error ("file.create");
Serial.print("Logging to: ");
Serial.println(name);
// write header
file.writeError = 0;
file.print("millis");
#if ECHO_TO_SERIAL
Serial.print("millis");
#endif //ECHO_TO_SERIAL
#if SENSOR_COUNT > 6
#error SENSOR_COUNT too large
#endif //SENSOR_COUNT
for (uint8_t i = 0; i < SENSOR_COUNT; i++) {
file.print(",sens");file.print(i, DEC);
#if ECHO_TO_SERIAL
Serial.print(",sens");Serial.print(i, DEC);
#endif //ECHO_TO_SERIAL
}
file.println();
#if ECHO_TO_SERIAL
Serial.println();
#endif //ECHO_TO_SERIAL
if (file.writeError || !file.sync()) {
error("write header failed");
}
}
示例3: log
bool log(char* message) {
// TODO: Test if file is open first
// log time to file
#ifdef SDCARD
file.println(message);
#endif
sync(false);
#ifdef SDCARD
return (file.getWriteError() == false);
#else
return true;
#endif
}
示例4: main
int main()
{
// initialize the SD card at SPI_FULL_SPEED for best performance.
// try SPI_HALF_SPEED if bus errors occur.
if (!sd.begin(SD_ENABLE_PIN, SPI_FULL_SPEED)) sd.initErrorHalt();
if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening test.txt for write failed");
}
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
while (1);
return 0;
}
示例5: ScriviSd
void ScriviSd(void)
{
int n;
n = 0;
if (!sd.init(SPI_HALF_SPEED, 10))
{
sd.initErrorHalt();
return;
}
if (!myFile.open("test-1.txt", O_WRITE | O_CREAT | O_APPEND))
{
delay(800);
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(800);
sd.errorHalt("opening test.txt for write failed");
return;
}
// Serial.println(nMin);
// for(n = 0; n < nCount; n++)
// {
// myFile.print("TIME: ");
// myFile.print(nMin);
// myFile.print(" min. - VALUE : ");
// myFile.print(nValue[n]);
myFile.println(" mTesla");
// }
// Serial.println("ScriviSd5");
// nCount = 0;
// nMin++;
myFile.close();
}
示例6: open
bool open(char* fileName) {
// Create LDxxxx.CSV for the lowest value of x.
#ifdef SDCARD
uint16_t i = 0;
do {
fileName[2] = (i/1000) % 10 + '0';
fileName[3] = (i/100) % 10 + '0';
fileName[4] = (i/10) % 10 + '0';
fileName[5] = i % 10 + '0';
i++;
}
while(sd.exists(fileName));
if(!file.open(fileName, O_CREAT | O_WRITE | O_EXCL)) {
// error_P("file open");
return false;
}
file.clearWriteError();
// write data header
file.print("time (s)");
#endif
Serial.print("v");
Serial.println(FIRMWARE_VERSION);
Serial.print("File: ");
Serial.println(fileName);
// write data header
Serial.print("time (s)");
/* We are no longer using the junction temperature in our data output.
// write data header
file.print("time (s), ambient");
Serial.print("time (s), ambient");
switch(temperatureUnit) {
case TEMPERATURE_UNITS_C:
file.print(" (C)");
Serial.print(" (C)");
break;
case TEMPERATURE_UNITS_F:
file.print(" (F)");
Serial.print(" (F)");
break;
case TEMPERATURE_UNITS_K:
file.print(" (K)");
Serial.print(" (K)");
break;
}*/
for (uint8_t i = 0; i < SENSOR_COUNT; i++) {
#ifdef SDCARD
file.print(", temp_");
file.print(i, DEC);
#endif
Serial.print(", temp_");
Serial.print(i, DEC);
switch(temperatureUnit) {
case TEMPERATURE_UNITS_C:
#ifdef SDCARD
file.print(" (C)");
#endif
Serial.print(" (C)");
break;
case TEMPERATURE_UNITS_F:
#ifdef SDCARD
file.print(" (F)");
#endif
Serial.print(" (F)");
break;
case TEMPERATURE_UNITS_K:
#ifdef SDCARD
file.print(" (K)");
#endif
Serial.print(" (K)");
break;
}
}
#ifdef SDCARD
file.println();
file.flush();
#endif
Serial.println();
#ifdef SDCARD
return (file.getWriteError() == false);
#else
return true;
#endif
}
示例7: writeLog
void writeLog() {
if (disableLogging) {
return;
}
if (!dataFile.isOpen()) {
if (!dataFile.open(root, logFilename, O_WRITE | O_APPEND)) {
#ifdef DEBUG
Serial.println(F("Could not open file for writing"));
#endif
disableLogging = true;
return;
}
}
// Local sensor readings
logFileSize += dataFile.print(lastUpdate);
logFileSize += dataFile.print(F("\t"));
logFileSize += dataFile.print(sinceLastAck);
logFileSize += dataFile.print(F("\t"));
logFileSize += dataFile.print(lastVcc);
logFileSize += dataFile.print(F("\t"));
if (validReadingi(lastRoundtrip)) {
logFileSize += dataFile.print(lastRoundtrip);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingi(lastRssi)) {
logFileSize += dataFile.print(lastRssi);
}
logFileSize += dataFile.print(F("\t"));
// Remote sensor readings
if (validReadingi(m.vcc)) {
logFileSize += dataFile.print(m.vcc);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingi(m.rssi)) {
logFileSize += dataFile.print(m.rssi);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingi(m.vibration)) {
logFileSize += dataFile.print(m.vibration);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.altitudeGps)) {
logFileSize += dataFile.print(m.altitudeGps);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.altitude)) {
logFileSize += dataFile.print(m.altitude);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.temp)) {
logFileSize += dataFile.print(m.temp);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.temp2)) {
logFileSize += dataFile.print(m.temp2);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.latitude)) {
logFileSize += dataFile.print(m.latitude, 6);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.longitude)) {
logFileSize += dataFile.print(m.longitude, 6);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.accelX)) {
logFileSize += dataFile.print(m.accelX);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.accelY)) {
logFileSize += dataFile.print(m.accelY);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.accelZ)) {
logFileSize += dataFile.print(m.accelZ);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.magX)) {
logFileSize += dataFile.print(m.magX);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.magY)) {
logFileSize += dataFile.print(m.magY);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.magZ)) {
logFileSize += dataFile.print(m.magZ);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.gyroX)) {
logFileSize += dataFile.print(m.gyroX);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.gyroY)) {
logFileSize += dataFile.print(m.gyroY);
}
logFileSize += dataFile.print(F("\t"));
//.........这里部分代码省略.........
示例8: writeGPSLog
void writeGPSLog(uint32_t gpstime, int32_t latitude, int32_t longitude, int32_t altitude) {
#else
void writeGPSLog(int32_t latitude, int32_t longitude, int32_t altitude) {
#endif
if (f.SDCARD == 0) return;
if (gps_data.open(GPS_LOG_FILENAME, O_WRITE | O_CREAT | O_APPEND)) {
#ifdef UBLOX
gps_data.print(gpstime); gps_data.write(',');
#endif
gps_data.print(latitude); gps_data.write(',');
gps_data.print(longitude); gps_data.write(',');
gps_data.print(altitude); gps_data.println();
gps_data.close();
} else {
return;
}
}
void writePLogToSD() {
if (f.SDCARD == 0) return;
plog.checksum = calculate_sum((uint8_t*)&plog, sizeof(plog));
if (permanent.open(PERMANENT_LOG_FILENAME, O_WRITE | O_CREAT | O_TRUNC)) {
permanent.print(F("arm=")); permanent.println(plog.arm);
permanent.print(F("disarm=")); permanent.println(plog.disarm);
permanent.print(F("start=")); permanent.println(plog.start);
permanent.print(F("armed_time=")); permanent.println(plog.armed_time);
permanent.print(F("lifetime=")); permanent.println(plog.lifetime, DEC);
permanent.print(F("failsafe=")); permanent.println(plog.failsafe);
permanent.print(F("i2c=")); permanent.println(plog.i2c);
permanent.print(F("running=")); permanent.println(plog.running, DEC);
permanent.print(F("checksum=")); permanent.println(plog.checksum, DEC);
permanent.print(F("debug=")); permanent.print(debug[0]);
permanent.print(F(",")); permanent.print(debug[1]);
permanent.print(F(",")); permanent.print(debug[2]);
permanent.print(F(",")); permanent.println(debug[3]);
permanent.println();
permanent.close();
} else {
return;
}
}
void fillPlogStruct(char* key, char* value) {
if (strcmp(key, "arm") == 0) sscanf(value, "%u", &plog.arm);
if (strcmp(key, "disarm") == 0) sscanf(value, "%u", &plog.disarm);
if (strcmp(key, "start") == 0) sscanf(value, "%u", &plog.start);
if (strcmp(key, "armed_time") == 0) sscanf(value, "%lu", &plog.armed_time);
if (strcmp(key, "lifetime") == 0) sscanf(value, "%lu", &plog.lifetime);
if (strcmp(key, "failsafe") == 0) sscanf(value, "%u", &plog.failsafe);
if (strcmp(key, "i2c") == 0) sscanf(value, "%u", &plog.i2c);
if (strcmp(key, "running") == 0) sscanf(value, "%hhu", &plog.running);
if (strcmp(key, "checksum") == 0) sscanf(value, "%hhu", &plog.checksum);
}
void readPLogFromSD() {
if (f.SDCARD == 0) return;
SdFile myfile;
char key[12];
char value[32];
char* tabPtr = key;
int c;
uint8_t i = 0;
if (myfile.open(PERMANENT_LOG_FILENAME, O_READ)) {
while (myfile.available()) {
c = myfile.read();
switch ((char)c) {
case ' ':
break;
case '=':
*tabPtr = '\0';
tabPtr = value;
break;
case '\n':
*tabPtr = '\0';
tabPtr = key;
i = 0;
fillPlogStruct(key, value);
memset(key, '\0', sizeof(key));
memset(value, '\0', sizeof(value));
break;
default:
i++;
if (i <= 12) {
*tabPtr = (char)c;
tabPtr++;
}
break;
}
}
} else return;
if (calculate_sum((uint8_t*)&plog, sizeof(plog)) != plog.checksum) {
#if defined(BUZZER)
alarmArray[7] = 3;
blinkLED(9, 100, 3);
#endif
// force load defaults
plog.arm = plog.disarm = plog.start = plog.failsafe = plog.i2c = 11;
plog.running = 1;
plog.lifetime = plog.armed_time = 3;
//.........这里部分代码省略.........