Esempio n. 1
0
unsigned char newSD::openFile(unsigned int index)
{
  if (file.open(index, O_READ)) {
   // Serial.print(index);
  //  Serial.println(" opened");
    return 1;
  }
  else{
    error("open file failed");
    return 0;
  }
}
Esempio n. 2
0
unsigned char newSD::openFile(char *fileName)
{
  if (file.open(fileName, O_READ)) {
    Serial.write(fileName);
    Serial.println(" opened");
    return 1;
  }
  else{
    error("open file failed");
    return 0;
  }
}
Esempio n. 3
0
int openFile(uint16_t index)
{

  if (file.open(index, O_READ)) {
    Serial.print(index);
    Serial.println(" opened");
    return 1;
  }
  else{
    error("open file failed");
    return 0;
  }
}
Esempio n. 4
0
void logInit() {
    // initialize the SD card
    if (!card.init()) { 
        Serial.print("Error initializing card - ");
        Serial.println(card.errorCode, HEX);
        return;
    }
    
    // initialize a FAT16 volume
    if (!Fat16::init(&card)) {
        Serial.println("Can't initialize volume.");
        return;
    }
    
    // create a new file
    char name[] = "LOGGER00.TXT";
    for (uint8_t i = 0; i < 100; i++) {
        name[6] = i/10 + '0';
        name[7] = i%10 + '0';
        // O_CREAT - create the file if it does not exist
        // O_EXCL - fail if the file exists
        // O_WRITE - open for write only
        if (file.open(name, O_CREAT | O_EXCL | O_WRITE)) break;
    }

    if (!file.isOpen()) {
        Serial.println("Error creating log file.");
        return;
    }
    
    Serial.print("Logging to: ");
    Serial.println(name);

    // write data header
    
    // clear write error
    file.writeError = false;
    file.println("Started log.");
    file.sync();
    
    fileReady = 1;
}