Table of Contents

Esp32SDCardDemo

Open Hard- & Software DokuWiki Module MicroController

Überblick

* Permanentes Schreiben von Daten auf SDCard (/YY/MM/DD/HHMMSS.txt)

* Esp32SDCardDemo zeigt folgende in der Klasse CSDCard gekapselten File- und Directory-Funktionen:

//
#ifndef SDCard_h
#define SDCard_h
//
//----------------------
//  Include
//----------------------
#include "Define.h"
//
#include <Arduino.h>
#include "FS.h"
#include "SD.h"
#include "SPI.h"
//
enum ECardType
{
    ctNone = 0,
    ctMMC = 1,
    ctSD = 2,
    ctSDHC = 3,
    ctUnknown = 4
};
//
const char* CardTypeText(ECardType cardtype);
//
class CSDCard
{
    private:
    int FPinSS;
    File FFile;
    TMessage FPMessage;
    TError FPError;
    //
    public:
    // Instance
    CSDCard(int pinss, TMessage pmessage, TError perror);    
    bool Initialise(void);
    // Property
    bool IsEndOfFile(void);
    ECardType GetCardType(void);
    uint64_t GetCardSizeMB(void);
    // WriteFile
    bool OpenWrite(const char* fileentry);
    bool OpenAppend(const char* fileentry);
    bool WriteCharacter(const char character);
    bool WriteText(const char* text);
    bool WriteLine(const char* line);
    bool CloseWrite(void);
    // ReadFile
    bool OpenRead(const char* fileentry);
    bool ReadCharacter(char &character);
    bool ReadText(char* text, unsigned &size);
    bool ReadLine(char* line);
    bool CloseRead(void);
    // File
    bool RenameFile(const char* entrysource, const char* entrytarget);
    bool RemoveFile(const char * entry);
    // Directory
    bool ListDirectory(const char* entry);
    bool CreateDirectory(const char* entry);
    bool RemoveDirectory(const char* entry);
};
//
#endif // SDCard_h
  const char* DIRECTORY_MAIN    = "/";
  const char* DIRECTORY_SUBYY   = "/22";
  const char* DIRECTORY_SUBMM   = "/22/11";
  const char* DIRECTORY_SUBDD   = "/22/11/04";
  _Message(LINE_SEPARATOR);
  sprintf(Line, "Create Directory[%s]:", DIRECTORY_SUBYY);
  _Message(Line);
  SDCard.CreateDirectory(DIRECTORY_SUBYY);
  //
  _Message(LINE_SEPARATOR);
  sprintf(Line, "Create Directory[%s]:", DIRECTORY_SUBMM);
  _Message(Line);
  SDCard.CreateDirectory(DIRECTORY_SUBMM);
  //
  _Message(LINE_SEPARATOR);
  sprintf(Line, "Create Directory[%s]:", DIRECTORY_SUBDD);
  _Message(Line);
  SDCard.CreateDirectory(DIRECTORY_SUBDD);
  _Message(LINE_SEPARATOR);
  sprintf(Line, "List Directory[%s]:", DIRECTORY_MAIN);
  _Message(Line);
  SDCard.ListDirectory(DIRECTORY_MAIN);
  //
  _Message(LINE_SEPARATOR);
  sprintf(Line, "List Directory[%s]:", DIRECTORY_SUBYY);
  _Message(Line);
  SDCard.ListDirectory(DIRECTORY_SUBYY);
  //
  _Message(LINE_SEPARATOR);
  sprintf(Line, "List Directory[%s]:", DIRECTORY_SUBMM);
  _Message(Line);
  SDCard.ListDirectory(DIRECTORY_SUBMM);
  //
  _Message(LINE_SEPARATOR);
  sprintf(Line, "List Directory[%s]:", DIRECTORY_SUBDD);
  _Message(Line);
  SDCard.ListDirectory(DIRECTORY_SUBDD);

ToDo

Done

221104

221104

221103


Open Hard- & Software DokuWiki Module MicroController