当前位置: 首页>>代码示例>>C++>>正文


C++ SdFile::print方法代码示例

本文整理汇总了C++中SdFile::print方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFile::print方法的具体用法?C++ SdFile::print怎么用?C++ SdFile::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SdFile的用法示例。


在下文中一共展示了SdFile::print方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LogTemps

void LogTemps(){
   if (!file.open(root, filename, O_CREAT | O_APPEND | O_WRITE)) {
     //error(“open”);
   }
   
// write values to the file

          sensorsa.requestTemperatures(); 
          sensorsb.requestTemperatures(); 
          sensorsc.requestTemperatures(); 
          sensorsd.requestTemperatures(); 
          

file.print(now() );
file.print("|");
file.print(sensorsa.getTempCByIndex(0));
file.print("|");
file.print(sensorsb.getTempCByIndex(0));
file.print("|");
file.print(sensorsc.getTempCByIndex(0));
file.print("|");
file.print(sensorsd.getTempCByIndex(0));
file.print("\n");

if (!file.close() || file.writeError){
 // error(“close/write”);
}
  
}
开发者ID:edboel,项目名称:projects,代码行数:29,代码来源:logtemps.c

示例2: 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");
}
开发者ID:cohabo,项目名称:my_src,代码行数:34,代码来源:main.cpp

示例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");
  }
}
开发者ID:cohabo,项目名称:my_src,代码行数:56,代码来源:main.cpp

示例4: dirAllocTest

/*
 * create enough files to force a cluster to be allocated to dir.
 */
void dirAllocTest(SdFile &dir) {
  char buf[13], name[13];
  SdFile file;
  uint16_t n; 
  uint32_t size = dir.fileSize();
 
  // create files and write name to file
  for (n = 0; ; n++){
    // make file name
    sprintf(name, "%u.TXT", n);
   
    // open start time
    uint32_t t0 = millis();
    if (!file.open(&dir, name, O_WRITE | O_CREAT | O_EXCL)) {
      error("open for write failed");
    }
   
    // open end time and write start time
    uint32_t t1 = millis();
    // write file name to file
    file.print(name);
    if (!file.close()) error("close write");
   
    // write end time
    uint32_t t2 = millis();
    PgmPrint("WR ");
    Serial.print(n);
    Serial.print(' ');
   
    // print time to create file
    Serial.print(t1 - t0);
    Serial.print(' ');
   
    // print time to write file
    Serial.println(t2 - t1);
   
    // directory size will change when a cluster is added
    if (dir.fileSize() != size) break;
  }

  // read files and check content
  for (uint16_t i = 0; i <= n; i++) {
    sprintf(name, "%u.TXT", i);
   
    // open start time
    uint32_t t0 = millis();
    if (!file.open(&dir, name, O_READ)) {
      error("open for read failed");
    }
    
    // open end time and read start time
    uint32_t t1 = millis();
    int16_t nr = file.read(buf, 13);
    if (nr < 5) error("file.read failed");
    
    // read end time
    uint32_t t2 = millis();
    
    // check file content
    if (strlen(name) != (uint16_t)nr || strncmp(name, buf, nr)) {
      error("content compare failed");
    }
    if (!file.close()) error("close read failed");
    
    PgmPrint("RD ");
    Serial.print(i);
    Serial.print(' ');
    
    // print open time
    Serial.print(t1 - t0);
    Serial.print(' ');
    
    // print read time
    Serial.println(t2 - t1);
  }
}
开发者ID:cohabo,项目名称:my_src,代码行数:79,代码来源:main.cpp

示例5: 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
}
开发者ID:davidbuzz,项目名称:t400-firmware,代码行数:98,代码来源:sd_log.cpp

示例6: 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"));
//.........这里部分代码省略.........
开发者ID:veonik,项目名称:transpond,代码行数:101,代码来源:handset.cpp

示例7: 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;
//.........这里部分代码省略.........
开发者ID:drinkypoo,项目名称:multiwii-2.4-fixedwing,代码行数:101,代码来源:SDcard.cpp


注:本文中的SdFile::print方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。