====== Esp32SDCardDemo ====== [[http://www.openhardsoftware.de/ | Open Hard- & Software]] [[http://www.openhardsoftware.de/dokuwiki | DokuWiki]] [[http://www.openhardsoftware.de/dokuwiki/doku.php?id=module:module | Module]] [[http://www.openhardsoftware.de/dokuwiki/doku.php?id=module:microcontroller:microcontroller | MicroController]] ===== Überblick ===== * Permanentes Schreiben von Daten auf SDCard (/YY/MM/DD/HHMMSS.txt) * SubDirectories müssen Ebene für Ebene einzeln angelegt werden * SubDirectories/Files müssen mit vollem Pfadnamen angesprochen werden * Esp32SDCardDemo zeigt folgende in der Klasse CSDCard gekapselten File- und Directory-Funktionen: * || 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); // #ifndef SDCard_h #define SDCard_h // //---------------------- // Include //---------------------- #include "Define.h" // #include #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 * Geschachteltes Anlegen von geschachtelten Verzeichnissen: * (SubDirectories müssen Ebene für Ebene einzeln angelegt werden) * (SubDirectories/Files müssen mit vollem Pfadnamen angesprochen werden) 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); * Geschachteltes Listing der SubDirectories: _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 ==== * X Anlegen von geschachtelten SubDirectories * X Listing von geschachtelten SubDirectories * Download: {{:module:microcontroller:esp32sdcarddemo:2211041559_esp32sdcarddemo_02v03_chdir.zip | 2211041559_Esp32SDCardDemo_02V03_chdir}} ==== 221104 ==== * Download (VSCode): {{:module:microcontroller:esp32sdcarddemo:2211041209_esp32sdcarddemo_02v02.zip | 2211041209_Esp32SDCardDemo_02V02.zip}} ==== 221103 ==== * Neuauflage von {{:module:microcontroller:esp32sdcarddemo:2208211552_esp32sdcardinfo_01v03.zip | 2208211552_Esp32SDCardInfo_01V03.zip}} * zu 2211031450_Esp32SDCardDemo_02V01.zip ----- [[http://www.openhardsoftware.de/ | Open Hard- & Software]] [[http://www.openhardsoftware.de/dokuwiki | DokuWiki]] [[http://www.openhardsoftware.de/dokuwiki/doku.php?id=module:module | Module]] [[http://www.openhardsoftware.de/dokuwiki/doku.php?id=module:microcontroller:microcontroller | MicroController]]