本文整理汇总了C++中SdFile::close方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFile::close方法的具体用法?C++ SdFile::close怎么用?C++ SdFile::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SdFile
的用法示例。
在下文中一共展示了SdFile::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mas_sdfat_get_nth_file
/*
Description:
Requrest for a specific file at a specified position within the directory
The path argument is identical to the path which was provided to last
call to "mas_sdfat_move_to_pwd"
*/
uint8_t mas_sdfat_get_nth_file(const char *path, uint16_t n, char *buf, uint8_t *is_dir)
{
uint16_t c = 0;
if ( mas_sdfat_move_to_pwd(path) == 0 )
return 0;
if ( mas_sdfat_file_is_open != 0 )
{
mas_sdfat_file.close();
mas_sdfat_file_is_open = 0;
}
mas_sdfat_sd->vwd()->rewind();
while (mas_sdfat_file.openNext(mas_sdfat_sd->vwd(), O_READ))
{
if ( n == c )
{
mas_sdfat_file.getFilename(buf);
buf[12] = '\0';
*is_dir = mas_sdfat_file.isDir();
mas_sdfat_file.close();
return 1;
}
c++;
mas_sdfat_file.close();
}
return 0;
}
示例2:
// grafix has to be stored at /gfx/
int speedo_disp::sd2ssd(char filename[10],int frame){
send_command(0x15);
send_command(0x00);
send_command(0x7F);
send_command(0x75);
send_command(0x00);
send_command(0x3F);
SdFile root;
SdFile file;
SdFile subdir;
root.openRoot(&pSD->volume);
if(!subdir.open(&root, "gfx", O_READ)) { return 1; };
if(!file.open(&subdir, filename, O_READ)) { return 2; };
unsigned long frame_seeker=(unsigned long)frame*64*64;
if(!file.seekSet(frame_seeker)) { return 3; }; // ein bild ist 64*64 Byte groß, da wir 64 lines zu je 64*2*4 Bit Breite haben
uint8_t buf[65];
//int n;
//while ((n = file.read(buf, sizeof(byte)*64)) > 0) {
for (int zeile=0; (file.read(buf, sizeof(byte)*64)>0) && zeile<64; zeile++ ) {
for(int j=0;j<64;j++){
send_char(buf[j]);
};
};
file.close();
subdir.close();
root.close();
return 0;
};
示例3: getParentDir
// this little helper is used to traverse paths
SdFile SDClass::getParentDir(const char *filepath, int *index)
{
// get parent directory
SdFile d1 = root; // start with the mostparent, root!
SdFile d2;
// we'll use the pointers to swap between the two objects
SdFile *parent = &d1;
SdFile *subdir = &d2;
const char *origpath = filepath;
while (strchr(filepath, '/'))
{
// get rid of leading /'s
if (filepath[0] == '/')
{
filepath++;
continue;
}
if (!strchr(filepath, '/'))
{
// it was in the root directory, so leave now
break;
}
// extract just the name of the next subdirectory
uint8_t idx = strchr(filepath, '/') - filepath;
if (idx > 12)
idx = 12; // dont let them specify long names
char subdirname[13];
strncpy(subdirname, filepath, idx);
subdirname[idx] = 0;
// close the subdir (we reuse them) if open
subdir->close();
if (!subdir->open(parent, subdirname, O_READ))
{
// failed to open one of the subdirectories
return SdFile();
}
// move forward to the next subdirectory
filepath += idx;
// we reuse the objects, close it.
parent->close();
// swap the pointers
SdFile *t = parent;
parent = subdir;
subdir = t;
}
*index = (int) (filepath - origpath);
// parent is now the parent diretory of the file!
return *parent;
}
示例4: app_process_file_stat
idigi_callback_status_t iDigiFileSystem::app_process_file_stat(idigi_file_stat_request_t * const request_data,
idigi_file_stat_response_t * const response_data)
{
idigi_file_stat_t *pstat = &response_data->statbuf;
idigi_callback_status_t status = idigi_callback_continue;
SdFile entry = DigiSD.open(request_data->path);
if (!entry.isOpen())
{
APP_DEBUG("stat cannot open: %s\n", request_data->path);
goto done;
}
pstat->last_modified = 0; // Last modified date unsupported:
pstat->hash_alg = idigi_file_hash_none; // File hash not supported
pstat->file_size = (size_t) entry.fileSize();
pstat->flags = 0;
if (entry.isDir())
pstat->flags |= IDIGI_FILE_IS_DIR;
else
pstat->flags |= IDIGI_FILE_IS_REG;
entry.close();
done:
return status;
}
示例5: syncEEPROM
void HAL::syncEEPROM() { // store to disk if changed
millis_t time = millis();
if (eprSyncTime && (time - eprSyncTime > 15000)) // Buffer writes only every 15 seconds to pool writes
{
eprSyncTime = 0;
bool failed = false;
if (!sd.sdactive) // not mounted
{
if (eepromFile.isOpen())
eepromFile.close();
Com::printErrorF("Could not write eeprom to sd card - no sd card mounted");
Com::println();
return;
}
if (!eepromFile.seekSet(0))
failed = true;
if(!failed && !eepromFile.write(virtualEeprom, EEPROM_BYTES) == EEPROM_BYTES)
failed = true;
if(failed) {
Com::printErrorF("Could not write eeprom to sd card");
Com::println();
}
}
}
示例6: 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”);
}
}
示例7: WiFiSendPicture
int WiFiCmdRobot::WiFiSendPicture (int16_t n)
{
int ret=SUCCESS;
int16_t nbytes;
uint8_t buf[PAYLOAD_SIZE];
char filename[12+1];
Serial.print("n: ");
Serial.println(n);
// Open the file
sprintf(filename, "PICT%02d.jpg", n);
if (!FilePicture.open(&root, filename, O_READ)) return FILE_OPEN_ERROR;
Serial.print("Open file: ");
Serial.println(filename);
// read from the file until there's nothing else in it:
while ((nbytes = FilePicture.read(buf, sizeof(buf))) > 0 && ret == SUCCESS) {
for (unsigned int idx = 0; idx<nbytes;idx++)
{
tcpClient.print(buf[idx]);
}
}// while
//Close file
if (!FilePicture.close()) return FILE_CLOSE_ERROR;
return SUCCESS;
}
示例8: enumerateGIFFiles
// Enumerate and possibly display the animated GIF filenames in GIFS directory
int enumerateGIFFiles(const char *directoryName, boolean displayFilenames) {
numberOfFiles = 0;
// Set the current working directory
if (! sd.chdir(directoryName, true)) {
sd.errorHalt("Could not change to gifs directory");
}
sd.vwd()->rewind();
char fn[13];
while (file.openNext(sd.vwd(), O_READ)) {
file.getName(fn, 13);
// If filename not deleted, count it
if (fn[0] != '_') {
numberOfFiles++;
if (displayFilenames) {
Serial.println(fn);
delay(20);
}
}
file.close();
}
// Set the current working directory
if (! sd.chdir("/", true)) {
sd.errorHalt("Could not change to root directory");
}
return numberOfFiles;
}
示例9: readSettings
void readSettings() {
int n,cc;
char ch, buff[24];
char buff2[80];
unsigned int ndx=0;
int read=0;
if (!settingsFile.open(&root, settingsFileName, O_READ)) {
console.printf("DBG: Creating New Settings File\r\n"); console.flush();
writeSettings();
return;
}
console.printf("DBG: Opened Settings File: %s\r\n",settingsFileName);
settingsFile.seekSet(0);
while ((read=settingsFile.read(buff, sizeof(buff))) > 0) {
//console.printf("DBG: READ %d\r\n",read); console.flush();
for (cc=0; cc < read ; cc++) {
ch=buff[cc];
//console.putChar(ch); console.flush();
buff2[ndx]=ch;
if (ndx<MAX_INPUT_LINE) {ndx++;}
if (ch=='\n'){//console.putChar('\r');
if(ndx) {
ndx--; // eat the newline.
}
buff2[ndx]='\0';
//console.puts(buff2);
if ((ndx>4) && buff2[3]=='!') {//fix this when the files are better
buff2[3]='\0';
n=lookupIndex(buff2);
switch (n) {
case _NPW_:
networkSetPassword(buff2+4);
break;
case _NJN_:
Watchdog_Reset();
networkJoin(buff2 +4);
break;
case _PKY_:
strncpy(pachubeKey, buff2+4, MAX_PATCHUBE_KEY_LENGHT-1);
break;
case _PFD_:
strncpy(pachubeFeed, buff2+4, MAX_PATCHUBE_FEED_LENGHT-1);
break;
default:
break;
}
}
ndx=0;
}
}
}
console.printf("DBG: Finished with Settings File: %s\r\n",settingsFileName);
settingsFile.close();
}
示例10: printLongPath
/**
* Get a long pretty path based on a DOS 8.3 path
*/
void CardReader::printLongPath(char *path) {
lsAction = LS_GetFilename;
int i, pathLen = strlen(path);
// SERIAL_ECHOPGM("Full Path: "); SERIAL_ECHOLN(path);
// Zero out slashes to make segments
for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';
SdFile diveDir = root; // start from the root for segment 1
for (i = 0; i < pathLen;) {
if (path[i] == '\0') i++; // move past a single nul
char *segment = &path[i]; // The segment after most slashes
// If a segment is empty (extra-slash) then exit
if (!*segment) break;
// Go to the next segment
while (path[++i]) { }
// SERIAL_ECHOPGM("Looking for segment: "); SERIAL_ECHOLN(segment);
// Find the item, setting the long filename
diveDir.rewind();
lsDive("", diveDir, segment);
// Print /LongNamePart to serial output
SERIAL_PROTOCOLCHAR('/');
SERIAL_PROTOCOL(longFilename[0] ? longFilename : "???");
// If the filename was printed then that's it
if (!filenameIsDir) break;
// SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment);
// Open the sub-item as the new dive parent
SdFile dir;
if (!dir.open(diveDir, segment, O_READ)) {
SERIAL_EOL;
SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
SERIAL_ECHO(segment);
break;
}
diveDir.close();
diveDir = dir;
} // while i<pathLen
SERIAL_EOL;
}
示例11: open
File SDClass::open(const char *filepath, uint8_t mode) {
/*
Open the supplied file path for reading or writing.
The file content can be accessed via the `file` property of
the `SDClass` object--this property is currently
a standard `SdFile` object from `sdfatlib`.
Defaults to read only.
If `write` is true, default action (when `append` is true) is to
append data to the end of the file.
If `append` is false then the file will be truncated first.
If the file does not exist and it is opened for writing the file
will be created.
An attempt to open a file for reading that does not exist is an
error.
*/
int pathidx;
// do the interative search
SdFile parentdir = getParentDir(filepath, &pathidx);
// no more subdirs!
filepath += pathidx;
if (! filepath[0]) {
// it was the directory itself!
return File(parentdir, "/");
}
// Open the file itself
SdFile file;
// failed to open a subdir!
if (!parentdir.isOpen())
return File();
if ( ! file.open(parentdir, filepath, mode)) {
return File();
}
// close the parent
parentdir.close();
if (mode & (O_APPEND | O_WRITE))
file.seekSet(file.fileSize());
return File(file, filepath);
}
示例12: 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;
}
示例13: 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();
}
示例14: importEEPROM
void HAL::importEEPROM() {
if (eepromFile.isOpen())
eepromFile.close();
if (!eepromFile.open("eeprom.bin", O_RDWR | O_CREAT | O_SYNC) ||
eepromFile.read(virtualEeprom, EEPROM_BYTES) != EEPROM_BYTES)
{
Com::printFLN(Com::tOpenFailedFile, "eeprom.bin");
} else {
Com::printFLN("EEPROM read from sd card.");
}
EEPROM::readDataFromEEPROM(true);
}
示例15: getGIFFilenameByIndex
// Get the full path/filename of the GIF file with specified index
void getGIFFilenameByIndex(const char *directoryName, int index, char *pnBuffer) {
char filename[13];
// Make sure index is in range
if ((index >= 0) && (index < numberOfFiles)) {
// Set the current working directory
if (! sd.chdir(directoryName, true)) {
sd.errorHalt("Could not change to gifs directory");
}
// Make sure file is closed before starting
file.close();
// Rewind the directory to the beginning
sd.vwd()->rewind();
while ((file.openNext(sd.vwd(), O_READ)) && (index >= 0)) {
file.getName(filename, 13);
// If filename is not marked as deleted, count it
if ((filename[0] != '_') && (filename[0] != '~')) {
index--;
}
file.close();
}
// Set the current working directory back to root
if (! sd.chdir("/", true)) {
sd.errorHalt("Could not change to root directory");
}
// Copy the directory name into the pathname buffer
strcpy(pnBuffer, directoryName);
// Append the filename to the pathname
strcat(pnBuffer, filename);
}
}