本文整理汇总了C++中SdFile::sync方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFile::sync方法的具体用法?C++ SdFile::sync怎么用?C++ SdFile::sync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SdFile
的用法示例。
在下文中一共展示了SdFile::sync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: writeSDData
void writeSDData() {
char SDString[200] = "";
int tmp_year = mD.vals.year + 2000;
sprintf(SDString, "%ld,%d,%04d-%02d-%02d,%02d:%02d:%02d.%02d,%ld,%ld,%ld,%ld,%ld,%d,%d,%d,%d,%d,%d,%d,%d,%d,%ld,%ld,%d,%ld,%d,%ld,%ld,%d,%d,%d,%d,%d,%d,%d\n",
mD.vals.uslCount,mD.vals.tCount,
tmp_year, mD.vals.month, mD.vals.day,
mD.vals.hour, mD.vals.minute, mD.vals.second, mD.vals.hundredths,
mD.vals.iLat,mD.vals.iLong,mD.vals.iAlt,mD.vals.iAngle,mD.vals.iHspeed,
mD.vals.AcXPayload,mD.vals.AcYPayload,mD.vals.AcZPayload,
mD.vals.GyXPayload,mD.vals.GyYPayload,mD.vals.GyZPayload,
mD.vals.MgXPayload,mD.vals.MgYPayload,mD.vals.MgZPayload,
mD.vals.AcXCamera,mD.vals.AcYCamera,mD.vals.AcZCamera,
mD.vals.GyXCamera,mD.vals.GyYCamera,mD.vals.GyZCamera,
mD.vals.MgXCamera,mD.vals.MgYCamera,mD.vals.MgZCamera,
mD.vals.PressurePayload,mD.vals.TmpExternal,mD.vals.TmpCamera,
mD.vals.CmpssPayload,mD.vals.CmpssCamera,
mD.vals.bSats,mD.vals.age,mD.vals.ihdop);
#ifdef DEBUG_ON
Serial.println(SDString);
#endif
if (sizeof(SDBuffer)-strlen(SDBuffer) < strlen(SDString)) {
dataFile.write(SDBuffer,strlen(SDBuffer));
dataFile.sync();
memset(SDBuffer, 0, sizeof(SDBuffer));
}
strcat(SDBuffer,SDString);
}
示例3: 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");
}
}
示例4: loop
void loop() {
uint32_t t;
double r;
Serial.println("Type any character to start");
while (!Serial.available()) SPARK_WLAN_Loop();
while (Serial.available()) Serial.read();
// open or create file - truncate existing file.
if (!file.open(&root, "BENCH.DAT", O_CREAT | O_TRUNC | O_RDWR)) {
error("open failed");
}
// fill buf with known data
for (uint16_t i = 0; i < (BUF_SIZE-2); i++) {
buf[i] = 'A' + (i % 26);
}
buf[BUF_SIZE-2] = '\r';
buf[BUF_SIZE-1] = '\n';
Serial.print("File size ");
Serial.print(FILE_SIZE_MB);
Serial.println(" MB");
uint32_t n = FILE_SIZE/sizeof(buf);
Serial.println("Starting write test. Please wait up to a minute");
// do write test
t = millis();
for (uint32_t i = 0; i < n; i++) {
if (file.write(buf, sizeof(buf)) != sizeof(buf)) {
error("write failed");
}
}
t = millis() - t;
file.sync();
r = (double)file.fileSize()/t;
Serial.print("Write ");
Serial.print(r);
Serial.println(" kB/sec");
Serial.println();
Serial.println("Starting read test. Please wait up to a minute");
// do read test
file.rewind();
t = millis();
for (uint32_t i = 0; i < n; i++) {
if (file.read(buf, sizeof(buf)) != sizeof(buf)) {
error("read failed");
}
}
t = millis() - t;
r = (double)file.fileSize()/t;
Serial.print("Read ");
Serial.print(r);
Serial.println(" kB/sec");
Serial.println("Done");
file.close();
}
示例5: writeLog
//.........这里部分代码省略.........
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"));
if (validReadingf(m.gyroZ)) {
logFileSize += dataFile.print(m.gyroZ);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.accel2X)) {
logFileSize += dataFile.print(m.accel2X);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.accel2Y)) {
logFileSize += dataFile.print(m.accel2Y);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.accel2Z)) {
logFileSize += dataFile.print(m.accel2Z);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.mag2X)) {
logFileSize += dataFile.print(m.mag2X);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.mag2Y)) {
logFileSize += dataFile.print(m.mag2Y);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.mag2Z)) {
logFileSize += dataFile.print(m.mag2Z);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.gyro2X)) {
logFileSize += dataFile.print(m.gyro2X);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.gyro2Y)) {
logFileSize += dataFile.print(m.gyro2Y);
}
logFileSize += dataFile.print(F("\t"));
if (validReadingf(m.gyro2Z)) {
logFileSize += dataFile.print(m.gyro2Z);
}
logFileSize += dataFile.println(F("\t"));
dataFile.sync();
if (logFileSize >= logFileMax) {
dataFile.close();
rotateLog();
openLog();
}
}
示例6: setup
void setup() {
int logNo;
char configLineBuffer[LINE_BUFFER_MAX];
spi.begin(SPI_281_250KHZ, MSBFIRST, 0);
pinMode(GRN_LED,OUTPUT);
pinMode(ORN_LED,OUTPUT);
pinMode(RED_LED,OUTPUT);
digitalWrite(GRN_LED,HIGH);
digitalWrite(ORN_LED,LOW);
digitalWrite(RED_LED,LOW);
iwdg_init(IWDG_PRE_256, WATCHDOG_TIMEOUT);
Watchdog_Reset();
if (!card.init(&spi)) {
//if (!card.init()) {
console.printf("FTL: card.init failed");
}
delay(100);
// initialize a FAT volume
if (!volume.init(&card)) {
console.printf("FTL: volume.init failed");
}
// open the root directory
if (!root.openRoot(&volume))
;//SerialUSB.println("FTL: openRoot failed");
for (logNo=0; (!logOpened) && logNo<512; logNo++) {
Watchdog_Reset();
//int snprintf(char *str, size_t size, const char *format, ...);
snprintf(logFileName,15,"LOG%03d.TXT",logNo);
if (file.open(&root, logFileName, O_READ)) {
//SerialUSB.print("DBG: Exists :"); SerialUSB.println(logFileName);
file.close();
} else if (file.open(&root, logFileName, O_CREAT|O_READ|O_WRITE)) {
//SerialUSB.print("DBG: New File:"); SerialUSB.println(logFileName);
logOpened=true;
file.sync();
file.close();
file.open(&root,logFileName,O_WRITE|O_READ);
while (file.read(configLineBuffer,LINE_BUFFER_MAX)) {
}
file.sync();
}
}
//if (!logOpened) SerialUSB.println("FTL: openRoot failed");
digitalWrite(GRN_LED,LOW);
digitalWrite(RED_LED,HIGH);
readSettings();
console.printf("LSV:" BOM_VERSION "\r\n");
console.printf("NST: %s\r\n",networkStatus()?"CONNECTED":"NOT CONNECTED");
digitalWrite(ORN_LED,HIGH);
digitalWrite(RED_LED,networkStatus()?HIGH:LOW);
}
示例7: logData
void logData(char *data) {
int n;
n=file.write(data,strlen(data));
console.printf("DBG: Logging (%d)'%s'",n,data);
file.sync();
}