ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
esp_globalFS.h
Go to the documentation of this file.
1 /*
2  esp_globalFS.h - ESP3D FS support class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef _ESP_GLOBAL_FS_H
22 #define _ESP_GLOBAL_FS_H
23 #include "../../include/esp3d_config.h"
24 #include "../../core/esp3doutput.h"
25 #include <time.h>
26 #ifdef FILESYSTEM_FEATURE
27 #include "esp_filesystem.h"
28 #endif //FILESYSTEM_FEATURE
29 #ifdef SD_DEVICE
30 #include "esp_sd.h"
31 #endif //SD_DEVICE
32 
33 
35 {
36 public:
37  ESP_GBFile();
38  ESP_GBFile(uint8_t FS);
39 #ifdef FILESYSTEM_FEATURE
40  ESP_GBFile(ESP_File & flashFile);
41 #endif //FILESYSTEM_FEATURE
42 #ifdef SD_DEVICE
43  ESP_GBFile(ESP_SDFile & sdFile);
44 #endif //SD_DEVICE
45  ~ESP_GBFile();
46  operator bool() const;
47  bool isDirectory();
48  const char* name() const;
49  const char* shortname() const;
50  const char* filename() const;
51  void close();
52  bool isOpen();
53  ESP_GBFile & operator=(const ESP_GBFile & other);
54 #ifdef FILESYSTEM_FEATURE
55  ESP_GBFile & operator=(const ESP_File & other);
56 #endif //FILESYSTEM_FEATURE
57 #ifdef SD_DEVICE
58  ESP_GBFile & operator=(const ESP_SDFile & other);
59 #endif //SD_DEVICE
60  size_t size();
61  time_t getLastWrite();
62  int available();
63  size_t write(uint8_t i);
64  size_t write(const uint8_t *buf, size_t size);
65  int read();
66  size_t read(uint8_t* buf, size_t size);
67  void flush();
69 private:
70 
71 #ifdef FILESYSTEM_FEATURE
72  ESP_File _flashFile;
73 #endif //FILESYSTEM_FEATURE
74 #ifdef SD_DEVICE
75  ESP_SDFile _sdFile;
76 #endif //SD_DEVICE
77  uint8_t _type;
78 };
79 
80 class ESP_GBFS
81 {
82 public:
83  ESP_GBFS();
84  ~ESP_GBFS();
85  static bool isavailable(uint8_t FS);
86  static uint64_t totalBytes(uint8_t FS);
87  static uint64_t usedBytes(uint8_t FS);
88  static uint64_t freeBytes(uint8_t FS);
89  static bool format(uint8_t FS, ESP3DOutput * output = nullptr);
90  static ESP_GBFile open(const char* path, uint8_t mode = ESP_FILE_READ);
91  static bool exists(const char* path);
92  static bool remove(const char *path);
93  static bool mkdir(const char *path);
94  static bool rmdir(const char *path);
95  static bool rename(const char *oldpath, const char *newpath);
96  static void closeAll();
97  static String & formatBytes (uint64_t bytes);
98  static const char * getNextFS(bool reset = false);
99  static uint8_t getFSType(const char * path);
100 private:
101  static const char * getRealPath(const char * path);
102  static uint8_t _nbFS;
103  static String _rootlist[MAX_FS];
104 };
105 
106 
107 #endif //_ESP_GLOBAL_FS_H
ESP_GBFile::filename
const char * filename() const
Definition: esp_globalFS.cpp:460
MAX_FS
#define MAX_FS
Definition: defines.h:129
ESP_GBFS::formatBytes
static String & formatBytes(uint64_t bytes)
Definition: esp_globalFS.cpp:57
ESP_GBFile::getLastWrite
time_t getLastWrite()
Definition: esp_globalFS.cpp:525
ESP_GBFile::available
int available()
Definition: esp_globalFS.cpp:536
ESP_GBFS::open
static ESP_GBFile open(const char *path, uint8_t mode=ESP_FILE_READ)
Definition: esp_globalFS.cpp:304
ESP_GBFile::isDirectory
bool isDirectory()
Definition: esp_globalFS.cpp:485
ESP_GBFile::~ESP_GBFile
~ESP_GBFile()
Definition: esp_globalFS.cpp:366
ESP_GBFS::mkdir
static bool mkdir(const char *path)
Definition: esp_globalFS.cpp:251
ESP_GBFile::openNextFile
ESP_GBFile openNextFile()
Definition: esp_globalFS.cpp:711
ESP_FILE_READ
#define ESP_FILE_READ
Definition: defines.h:120
ESP_SDFile
Definition: esp_sd.h:31
ESP_GBFile::close
void close()
Definition: esp_globalFS.cpp:390
ESP_GBFS::remove
static bool remove(const char *path)
Definition: esp_globalFS.cpp:209
ESP_GBFS::exists
static bool exists(const char *path)
Definition: esp_globalFS.cpp:187
ESP_GBFile::shortname
const char * shortname() const
ESP_GBFile::write
size_t write(uint8_t i)
Definition: esp_globalFS.cpp:556
ESP_GBFS::rmdir
static bool rmdir(const char *path)
Definition: esp_globalFS.cpp:272
ESP_GBFS::~ESP_GBFS
~ESP_GBFS()
Definition: esp_globalFS.cpp:52
ESP_GBFile::operator=
ESP_GBFile & operator=(const ESP_GBFile &other)
Definition: esp_globalFS.cpp:651
ESP_GBFile::name
const char * name() const
Definition: esp_globalFS.cpp:429
ESP_GBFile
Definition: esp_globalFS.h:34
ESP_GBFile::ESP_GBFile
ESP_GBFile()
Definition: esp_globalFS.cpp:330
ESP_GBFS::isavailable
static bool isavailable(uint8_t FS)
Definition: esp_globalFS.cpp:28
ESP_File
Definition: esp_filesystem.h:30
ESP_GBFS::getNextFS
static const char * getNextFS(bool reset=false)
Definition: esp_globalFS.cpp:686
ESP_GBFS::closeAll
static void closeAll()
Definition: esp_globalFS.cpp:293
ESP_GBFS::freeBytes
static uint64_t freeBytes(uint8_t FS)
Definition: esp_globalFS.cpp:103
ESP_GBFS::getFSType
static uint8_t getFSType(const char *path)
Definition: esp_globalFS.cpp:136
ESP_GBFile::flush
void flush()
Definition: esp_globalFS.cpp:636
ESP_GBFS::totalBytes
static uint64_t totalBytes(uint8_t FS)
Definition: esp_globalFS.cpp:73
ESP_GBFS::rename
static bool rename(const char *oldpath, const char *newpath)
Definition: esp_globalFS.cpp:230
ESP_GBFile::read
int read()
Definition: esp_globalFS.cpp:596
ESP_GBFile::isOpen
bool isOpen()
Definition: esp_globalFS.cpp:409
ESP_GBFS::ESP_GBFS
ESP_GBFS()
Definition: esp_globalFS.cpp:46
ESP_GBFile::size
size_t size()
Definition: esp_globalFS.cpp:505
ESP_GBFS::format
static bool format(uint8_t FS, ESP3DOutput *output=nullptr)
esp_filesystem.h
esp_sd.h
ESP3DOutput
Definition: esp3doutput.h:48
ESP_GBFS::usedBytes
static uint64_t usedBytes(uint8_t FS)
Definition: esp_globalFS.cpp:88
ESP_GBFS
Definition: esp_globalFS.h:80