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


C++ SdFat类代码示例

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


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

示例1: SDBeaconSetup

void TicketflySDBeacon::SDBeaconSetup (SdFat& SD) {
	Serial.begin (9600);
  Serial.print(F("Initializing SD card..."));
	pinMode(10, OUTPUT);
	
  if (!SD.begin(4)) {
    Serial.println(F("initialization failed!"));
    return;
  }
  Serial.println(F("initialization done."));

}
开发者ID:mikealbinson,项目名称:CustomLibraries,代码行数:12,代码来源:SDBeacon.cpp

示例2: writeToSD

void TicketflySDBeacon::writeToSD (String writeThisString, String fileName, SdFat& SD) { 
	File myFile;
	const char* conversion = fileName.c_str();
	Serial.println (conversion);
	myFile = SD.open(conversion);
  if (myFile) {
    myFile.println(writeThisString);
    myFile.close();
  } 
	else {
    Serial.println(F("error opening example.txt"));
  }
}
开发者ID:mikealbinson,项目名称:CustomLibraries,代码行数:13,代码来源:SDBeacon.cpp

示例3: begin

bool Tune::begin()
{
	// Pin configuration
	pinMode(DREQ, INPUT_PULLUP);
	pinMode(XDCS, OUTPUT);
	pinMode(XCS, OUTPUT);
	pinMode(SDCS, OUTPUT);
	
	// Deselect control & data ctrl
	digitalWrite(XCS, HIGH);
	digitalWrite(XDCS, HIGH);
	// Deselect SD's chip select
	digitalWrite(SDCS, HIGH);
	
	// SD card initialization
	if (!sd.begin(SDCS, SPI_HALF_SPEED))
	{
		sd.initErrorHalt(); // describe problem if there's one
		return 0; 
	}
	
	// Tracklisting also return the number of playable files
	Serial.print(listFiles());
	Serial.print(" tracks found, ");
	
	// SPI bus initialization
	SPI.begin();
	SPI.setDataMode(SPI_MODE0);
	// Both SCI and SDI read data MSB first
	SPI.setBitOrder(MSBFIRST);
	// From the datasheet, max SPI reads are CLKI/6. Here CLKI = 26MHz -> SPI max speed is 4.33MHz.
	// We'll take 16MHz/4 = 4MHz to be safe.
	// Plus it's the max recommended speed when using a resistor-based lvl converter with an SD card.
	SPI.setClockDivider(SPI_CLOCK_DIV4);
	SPI.transfer(0xFF);
	delay(10);
	
	// Codec initialization
	// Software reset
	setBit(SCI_MODE, SM_RESET);
	delay(5);
	// VS1022 "New mode" activation
	setBit(SCI_MODE, SM_SDINEW);
	// Clock setting (default is 24.576MHz)
	writeSCI(SCI_CLOCKF, 0x32, 0xC8);
	delay(5);
	
	// Wait until the chip is ready
	while (!digitalRead(DREQ));
	delay(100);
	
	// Set playState flag
	playState = idle;
	
	// Set volume to avoid hurt ears ;)
	setVolume(150);
	
	Serial.println("Tune ready !");
	return 1;
}
开发者ID:Snootlab,项目名称:Tune,代码行数:60,代码来源:Tune.cpp

示例4: beginDataLog

/**
 * Function starts the SD card service and makes sure that the appropriate directory
 * structure exists, then creates the file to use for logging data. Data will be logged
 * to a file called fileNamePrefix_0.csv or fileNamePrefix_0.bin (number will be incremented
 * for each new log file)
 *
 * @param chipSelectPin Arduino pin SD card reader CS pin is attached to
 * @param fileNamePrefix string to prefix at beginning of data file
 * @param csvData boolean flag whether we are writing csv data or binary data (used for filename)
 *
 * @return true if successful, false if failed
 */
bool beginDataLog(int chipSelectPin, const char *fileNamePrefix, bool csvData)
{
  bool ret;
  int i = 0;
  int max_len;
  char fileName[19];
  char prefix[8];
  char rootPath[] = "/data";


  if (_output_buffer != NULL) {
    delete []_output_buffer;
  }
  OUTPUT_BUF_SIZE = 512;
  _output_buffer = vol.cacheAddress()->output_buf;

  if (freeMemory() < 400) {
    strcpy_P(_getOutBuf(), sd_card_error);
    Serial.print(_getOutBuf());
    Serial.print(freeMemory());
    Serial.println(", need 400)");
    ret = false;
  } else {
    ret = sd.begin(chipSelectPin, SPI_FULL_SPEED);
  }

  //Filenames need to fit the 8.3 filename convention, so truncate down the
  //given filename if it is too long.
  memcpy(prefix, fileNamePrefix, 7);
  prefix[7] = '\0';

  if (ret) {
    if (!sd.exists(rootPath))
      ret = sd.mkdir(rootPath);
    if (ret) {
      while (true) {
	if (i < 10) {
	  max_len = 7;
	} else if (i < 100) {
	  max_len = 6;
	} else if (i < 1000) {
	  max_len = 5;
	} else {
	  break;
	}

	prefix[max_len - 1] = '\0';
	sprintf(fileName, "%s/%s%d.%s", rootPath, prefix, i,
		csvData ? "csv" : "bin");
	if (!sd.exists(fileName)) {
	  file = sd.open(fileName, FILE_WRITE);
	  break;
	}
	i++;
      }
    }
  }
  return file.isOpen();
}
开发者ID:ArduSat,项目名称:ArdusatSDK-Logging,代码行数:71,代码来源:ArdusatLogging.cpp

示例5: error

void error(String message) {
  if(self.isInState(Start)) {
    sd.initErrorPrint(&terminal);
  } else {
    sd.errorPrint(&terminal);
  }
  terminal.flush();

  errorMessage = message;
  self.transitionTo(Error);
}
开发者ID:tjpeden,项目名称:mane-avis,代码行数:11,代码来源:ManeAvis.cpp

示例6: fastLog

void fastLog(){
    if (blockNum == DATA_DIM-1){
        if (!sd.card()->isBusy()){
            if (!sd.card()->writeData((uint8_t*)&block)){
                error("fast write failed");
            }
            blockNum = 0;
        }
        else
            Serial.println("Card BUSY!");
    }
    else
        blockNum++;
}
开发者ID:Wetmelon,项目名称:Salus,代码行数:14,代码来源:Salus_Logging.cpp

示例7: renderError

void renderError() {
  Display.setTextColor(RED, BLACK);

  /***** Error Message *****/
  Display.setTextSize(1);
  Display.setCursor(1, 55);

  Display.println(errorMessage);

  if(self.isInState(Start)) {
    sd.initErrorPrint(&Display);
  } else {
    sd.errorPrint(&Display);
  }
}
开发者ID:tjpeden,项目名称:mane-avis,代码行数:15,代码来源:ManeAvis.cpp

示例8: enterStart

void enterStart() {
  // Read configuration from Flash
  Time.zone(-6); // TODO: store in Flash and add configuration

  // Display splash screen
  Display.print("Mane Avis v");
  Display.println(MANE_AVIS_VERSION);
  Display.print("Firmware: ");
  Display.println(System.version());
  // TODO: display a real splash screen

  // Read alarms from SD card
  if(sd.exists(STORE)) {
    digitalWrite(D7, HIGH);
    if(!store.open(STORE, O_READ)) {
      error("Failed to open store");
      return;
    }

    String line;
    while((line = store.readStringUntil('\r')) != NULL) {
      alarms.add(line);
      store.read(); // clear '\n'
    }
  }

  store.close();
  digitalWrite(D7, LOW);
}
开发者ID:tjpeden,项目名称:mane-avis,代码行数:29,代码来源:ManeAvis.cpp

示例9: getGIFFilenameByIndex

// Get the full path/filename of the GIF file with specified index
void getGIFFilenameByIndex(const char *directoryName, int index, char *pnBuffer) {

	char fname[30];

    // Make sure index is in range
    if ((index < 0) || (index >= numberOfFiles))
        return;

    File directory = sd.open(directoryName);
    if (!directory)
        return;

    File file = directory.openNextFile();
    while (file && (index >= 0)) {
        file.getName(fname, sizeof(fname));

        if (isAnimationFile(fname)) {
            index--;

            // Copy the directory name into the pathname buffer
            strcpy(pnBuffer, directoryName);

            // Append the filename to the pathname
            strcat(pnBuffer, fname);
        }

        file.close();
        file = directory.openNextFile();
    }

    file.close();
    directory.close();
}
开发者ID:monkbroc,项目名称:RGBMatrixPanel-Shield-V4-Test-app,代码行数:34,代码来源:FilenameFunctions.cpp

示例10: enumerateGIFFiles

// Enumerate and possibly display the animated GIF filenames in GIFS directory
int enumerateGIFFiles(const char *directoryName, boolean displayFilenames) {

	char fname[30];
	numberOfFiles = 0;

    File directory = sd.open(directoryName);
    if (!directory) {
        return -1;
    }

    File file = directory.openNextFile();
    while (file) {
		file.getName(fname, sizeof(fname));
  		Serial.println(fname);
        if (isAnimationFile(fname)) {
            numberOfFiles++;
            if (displayFilenames) {
                Serial.println(fname);
            }
        }
        file.close();
        file = directory.openNextFile();
    }

    file.close();
    directory.close();

    return numberOfFiles;
}
开发者ID:monkbroc,项目名称:RGBMatrixPanel-Shield-V4-Test-app,代码行数:30,代码来源:FilenameFunctions.cpp

示例11: writefile

void SDcard::writefile(uint64_t timestamp_sd, int eeprom){
  
    myfile = SD.open("data.txt", FILE_WRITE);
    
    if (myfile) {
      myfile.print("G|");
      uint64_t xx = timestamp_sd/1000000000ULL;
      if (xx >0) myfile.print((long)xx);
      myfile.print((long)(timestamp_sd-xx*1000000000));
      myfile.print("|");
      myfile.print(eeprom);
      myfile.print("|");
      for(int i = 0; i<3;i++){ // nombre de capteurs = 3
        String data = this->mem->getNext();
        myfile.print(data);
        if (i!=2)
        myfile.print("|");
      }
      myfile.write('\n');
      //myfile.print("|H,");
      //myfile.println(value);
      myfile.close();
    }
    else {
      Serial.println("error opening data.txt");
    }
  }
开发者ID:eHealth2015,项目名称:arduino,代码行数:27,代码来源:SDcard.cpp

示例12: init

void init() {
  close();
  #ifdef SDCARD
  if (!sd.begin(SD_CS, SPI_FULL_SPEED)) {
//    error_P("card.init");
    return;
  }
  #endif
}
开发者ID:davidbuzz,项目名称:t400-firmware,代码行数:9,代码来源:sd_log.cpp

示例13: SD_GetFileSize

uint32_t SD_GetFileSize(void)
{
    uint32_t retVal = 0;
    //TEST.TXT
    sdf.chdir();	// Change directory to root
    // OPEN the file for reading:
    if (!file.open("TEST.TXT", O_READ)) {
        sdf.errorHalt("opening FILE for read failed");
    }
    else
    {
        retVal = file.fileSize();
        file.close();

    }

    return retVal;
}
开发者ID:ro0lz,项目名称:_CANcrusher_ARM,代码行数:18,代码来源:sdfi.cpp

示例14: init_SD

void init_SD(){
  if (!sd.begin(SDCARD_CSPIN, SPI_HALF_SPEED)) {
    f.SDCARD = 0; // If init fails, tell the code not to try to write on it
    debug[1] = 999;
  }
  else {
    f.SDCARD = 1;
    debug[1] = 000;
  }
}
开发者ID:drinkypoo,项目名称:multiwii-2.4-fixedwing,代码行数:10,代码来源:SDcard.cpp

示例15: put_handler

  boolean put_handler(AtMegaWebServer& web_server) {
	const char* length_str = web_server.get_header_value("Content-Length");
	long length = atol(length_str);
	const char *path = web_server.get_path();

	SdFile file;
	if(!file.open(path, O_CREAT | O_WRITE | O_TRUNC)){
		 // maybe the folder must be created
		char *c = strrchr(path, '/');
		if(c){
			*c = 0;
			if(sdfat.mkdir(path)){
#if DEBUG
				Serial << "put_handler make DIR: ok " << path <<'\n';
#endif
				*c = '/';
				if(!file.open(path, O_CREAT | O_WRITE | O_TRUNC)){
#if DEBUG
					Serial << "put_handler open FILE: failed " << path <<'\n';
#endif
				}
			}
			*c = '/';
		}
	}
	if(file.isOpen()){

		EthernetClient client = web_server.get_client();
		long size = 0;
		int read = 0;
		while(size < length && web_server.waitClientAvailable()){
			read = client.read((uint8_t*)buffer, sizeof(buffer));
			file.write(buffer, read);
			size += read;
		}
		file.close();
#if DEBUG
		Serial << "file written: " << size << " of: " << length << '\n';
#endif
		if(size < length){
			web_server.sendHttpResult(404);
		}else{
			web_server.sendHttpResult(200);
			web_server << path;
		}

	}else{
		web_server.sendHttpResult(422); // assuming it's a bad filename (non 8.3 name)
#if DEBUG
		Serial << F("put_handler open file failed: send 422 ") << path <<'\n';
#endif
	}
	return true;
  }
开发者ID:gonboy,项目名称:AtMegaWebServer,代码行数:54,代码来源:AtMegaWebServer.cpp


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