mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-01 12:02:02 +08:00
Apply CLANG style
This commit is contained in:
parent
606cc3f0ff
commit
3bc8c874ae
@ -20,20 +20,24 @@
|
|||||||
// #define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
// #define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
|
||||||
#include "../../include/esp3d_config.h"
|
#include "../../include/esp3d_config.h"
|
||||||
#ifdef SD_DEVICE
|
#ifdef SD_DEVICE
|
||||||
#include "esp_sd.h"
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "esp_sd.h"
|
||||||
|
|
||||||
|
|
||||||
#define ESP_MAX_SD_OPENHANDLE 4
|
#define ESP_MAX_SD_OPENHANDLE 4
|
||||||
#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266)
|
#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266)
|
||||||
#define FS_NO_GLOBALS
|
#define FS_NO_GLOBALS
|
||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||||
#elif ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined (ARDUINO_ARCH_ESP8266)
|
#elif ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && \
|
||||||
|
defined(ARDUINO_ARCH_ESP8266)
|
||||||
#define FS_NO_GLOBALS
|
#define FS_NO_GLOBALS
|
||||||
#define NO_GLOBAL_SD
|
#define NO_GLOBAL_SD
|
||||||
#include <SdFat.h>
|
#include <SdFat.h>
|
||||||
sdfat::File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
sdfat::File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||||
#elif ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined (ARDUINO_ARCH_ESP32)
|
#elif ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && \
|
||||||
|
defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <SdFat.h>
|
#include <SdFat.h>
|
||||||
#if (SD_DEVICE == ESP_SDFAT2)
|
#if (SD_DEVICE == ESP_SDFAT2)
|
||||||
#if SDFAT_FILE_TYPE == 1
|
#if SDFAT_FILE_TYPE == 1
|
||||||
@ -59,8 +63,7 @@ File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
|||||||
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||||
bool ESP_SD::_enabled = false;
|
bool ESP_SD::_enabled = false;
|
||||||
|
|
||||||
bool ESP_SD::enableSharedSD()
|
bool ESP_SD::enableSharedSD() {
|
||||||
{
|
|
||||||
if (_enabled) {
|
if (_enabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -70,12 +73,14 @@ bool ESP_SD::enableSharedSD()
|
|||||||
// Method : TBD
|
// Method : TBD
|
||||||
// 1 - check sd cs state ? what about SDIO then ?
|
// 1 - check sd cs state ? what about SDIO then ?
|
||||||
// 2 - check M27 status ?
|
// 2 - check M27 status ?
|
||||||
log_esp3d("SD shared enabled PIN %d with %d", ESP_FLAG_SHARED_SD_PIN, ESP_FLAG_SHARED_SD_VALUE);
|
log_esp3d("SD shared enabled PIN %d with %d", ESP_FLAG_SHARED_SD_PIN,
|
||||||
|
ESP_FLAG_SHARED_SD_VALUE);
|
||||||
digitalWrite(ESP_FLAG_SHARED_SD_PIN, ESP_FLAG_SHARED_SD_VALUE);
|
digitalWrite(ESP_FLAG_SHARED_SD_PIN, ESP_FLAG_SHARED_SD_VALUE);
|
||||||
#endif // ESP_FLAG_SHARED_SD_PIN
|
#endif // ESP_FLAG_SHARED_SD_PIN
|
||||||
#if defined(ESP3DLIB_ENV)
|
#if defined(ESP3DLIB_ENV)
|
||||||
// check if card is not currently in use
|
// check if card is not currently in use
|
||||||
if (card.isMounted() && (IS_SD_PRINTING() ||IS_SD_FETCHING() ||IS_SD_PAUSED() || IS_SD_FILE_OPEN())) {
|
if (card.isMounted() && (IS_SD_PRINTING() || IS_SD_FETCHING() ||
|
||||||
|
IS_SD_PAUSED() || IS_SD_FILE_OPEN())) {
|
||||||
_enabled = false;
|
_enabled = false;
|
||||||
} else {
|
} else {
|
||||||
card.release();
|
card.release();
|
||||||
@ -89,20 +94,17 @@ bool ESP_SD::_started = false;
|
|||||||
uint8_t ESP_SD::_state = ESP_SDCARD_NOT_PRESENT;
|
uint8_t ESP_SD::_state = ESP_SDCARD_NOT_PRESENT;
|
||||||
uint8_t ESP_SD::_spi_speed_divider = 1;
|
uint8_t ESP_SD::_spi_speed_divider = 1;
|
||||||
bool ESP_SD::_sizechanged = true;
|
bool ESP_SD::_sizechanged = true;
|
||||||
uint8_t ESP_SD::setState(uint8_t flag)
|
uint8_t ESP_SD::setState(uint8_t flag) {
|
||||||
{
|
|
||||||
_state = flag;
|
_state = flag;
|
||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ESP_SD::getFSType(const char * path)
|
uint8_t ESP_SD::getFSType(const char* path) {
|
||||||
{
|
|
||||||
(void)path;
|
(void)path;
|
||||||
return FS_SD;
|
return FS_SD;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP_SD::accessFS(uint8_t FS)
|
bool ESP_SD::accessFS(uint8_t FS) {
|
||||||
{
|
|
||||||
(void)FS;
|
(void)FS;
|
||||||
// if card is busy do not let another task access SD and so prevent a release
|
// if card is busy do not let another task access SD and so prevent a release
|
||||||
if (_state == ESP_SDCARD_BUSY) {
|
if (_state == ESP_SDCARD_BUSY) {
|
||||||
@ -122,15 +124,15 @@ bool ESP_SD::accessFS(uint8_t FS)
|
|||||||
return true;
|
return true;
|
||||||
#endif // SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
#endif // SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||||
}
|
}
|
||||||
void ESP_SD::releaseFS(uint8_t FS)
|
void ESP_SD::releaseFS(uint8_t FS) {
|
||||||
{
|
|
||||||
(void)FS;
|
(void)FS;
|
||||||
log_esp3d("Release SD");
|
log_esp3d("Release SD");
|
||||||
setState(ESP_SDCARD_IDLE);
|
setState(ESP_SDCARD_IDLE);
|
||||||
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
#if SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||||
_enabled = false;
|
_enabled = false;
|
||||||
#if defined(ESP_FLAG_SHARED_SD_PIN) && ESP_FLAG_SHARED_SD_PIN != -1
|
#if defined(ESP_FLAG_SHARED_SD_PIN) && ESP_FLAG_SHARED_SD_PIN != -1
|
||||||
log_esp3d("SD shared disabled PIN %d with %d", ESP_FLAG_SHARED_SD_PIN, ESP_FLAG_SHARED_SD_VALUE);
|
log_esp3d("SD shared disabled PIN %d with %d", ESP_FLAG_SHARED_SD_PIN,
|
||||||
|
ESP_FLAG_SHARED_SD_VALUE);
|
||||||
digitalWrite(ESP_FLAG_SHARED_SD_PIN, !ESP_FLAG_SHARED_SD_VALUE);
|
digitalWrite(ESP_FLAG_SHARED_SD_PIN, !ESP_FLAG_SHARED_SD_VALUE);
|
||||||
#endif // ESP_FLAG_SHARED_SD_PIN
|
#endif // ESP_FLAG_SHARED_SD_PIN
|
||||||
#if defined(ESP3DLIB_ENV)
|
#if defined(ESP3DLIB_ENV)
|
||||||
@ -138,18 +140,12 @@ void ESP_SD::releaseFS(uint8_t FS)
|
|||||||
card.mount();
|
card.mount();
|
||||||
#endif // ESP3DLIB_ENV
|
#endif // ESP3DLIB_ENV
|
||||||
#endif // SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
#endif // SD_DEVICE_CONNECTION == ESP_SHARED_SD
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESP_SD::handle() {}
|
||||||
void ESP_SD::handle()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// helper to format size to readable string
|
// helper to format size to readable string
|
||||||
String & ESP_SD::formatBytes (uint64_t bytes)
|
String& ESP_SD::formatBytes(uint64_t bytes) {
|
||||||
{
|
|
||||||
static String res;
|
static String res;
|
||||||
if (bytes < 1024) {
|
if (bytes < 1024) {
|
||||||
res = String((uint16_t)bytes) + " B";
|
res = String((uint16_t)bytes) + " B";
|
||||||
@ -163,8 +159,8 @@ String & ESP_SD::formatBytes (uint64_t bytes)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_SDFile::ESP_SDFile(const char * name, const char * filename, bool isdir, size_t size)
|
ESP_SDFile::ESP_SDFile(const char* name, const char* filename, bool isdir,
|
||||||
{
|
size_t size) {
|
||||||
_isdir = isdir;
|
_isdir = isdir;
|
||||||
_dirlist = "";
|
_dirlist = "";
|
||||||
_index = -1;
|
_index = -1;
|
||||||
@ -175,13 +171,11 @@ ESP_SDFile::ESP_SDFile(const char * name, const char * filename, bool isdir, siz
|
|||||||
_size = size;
|
_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_SDFile::~ESP_SDFile()
|
ESP_SDFile::~ESP_SDFile() {
|
||||||
{
|
|
||||||
// log_esp3d("Destructor %s index %d",(_isdir)?"Dir":"File", _index);
|
// log_esp3d("Destructor %s index %d",(_isdir)?"Dir":"File", _index);
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_SDFile::operator bool() const
|
ESP_SDFile::operator bool() const {
|
||||||
{
|
|
||||||
if ((_index != -1) || (_filename.length() > 0)) {
|
if ((_index != -1) || (_filename.length() > 0)) {
|
||||||
// log_esp3d("Bool yes %d %d",_index, _filename.length());
|
// log_esp3d("Bool yes %d %d",_index, _filename.length());
|
||||||
return true;
|
return true;
|
||||||
@ -190,86 +184,61 @@ ESP_SDFile::operator bool() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP_SDFile::isOpen()
|
bool ESP_SDFile::isOpen() { return !(_index == -1); }
|
||||||
{
|
|
||||||
return !(_index == -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* ESP_SDFile::name() const
|
const char* ESP_SDFile::name() const { return _name.c_str(); }
|
||||||
{
|
|
||||||
return _name.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* ESP_SDFile::filename() const
|
const char* ESP_SDFile::filename() const { return _filename.c_str(); }
|
||||||
{
|
|
||||||
return _filename.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ESP_SDFile::isDirectory()
|
bool ESP_SDFile::isDirectory() { return _isdir; }
|
||||||
{
|
|
||||||
return _isdir;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t ESP_SDFile::size()
|
size_t ESP_SDFile::size() { return _size; }
|
||||||
{
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
|
|
||||||
time_t ESP_SDFile::getLastWrite()
|
time_t ESP_SDFile::getLastWrite() { return _lastwrite; }
|
||||||
{
|
|
||||||
return _lastwrite;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ESP_SDFile::available()
|
int ESP_SDFile::available() {
|
||||||
{
|
|
||||||
if (_index == -1 || _isdir) {
|
if (_index == -1 || _isdir) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return tSDFile_handle[_index].available();
|
return tSDFile_handle[_index].available();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ESP_SDFile::write(uint8_t i)
|
size_t ESP_SDFile::write(uint8_t i) {
|
||||||
{
|
|
||||||
if ((_index == -1) || _isdir) {
|
if ((_index == -1) || _isdir) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return tSDFile_handle[_index].write(i);
|
return tSDFile_handle[_index].write(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ESP_SDFile::write(const uint8_t *buf, size_t size)
|
size_t ESP_SDFile::write(const uint8_t* buf, size_t size) {
|
||||||
{
|
|
||||||
if ((_index == -1) || _isdir) {
|
if ((_index == -1) || _isdir) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return tSDFile_handle[_index].write(buf, size);
|
return tSDFile_handle[_index].write(buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESP_SDFile::read()
|
int ESP_SDFile::read() {
|
||||||
{
|
|
||||||
if ((_index == -1) || _isdir) {
|
if ((_index == -1) || _isdir) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return tSDFile_handle[_index].read();
|
return tSDFile_handle[_index].read();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ESP_SDFile::read(uint8_t* buf, size_t size)
|
size_t ESP_SDFile::read(uint8_t* buf, size_t size) {
|
||||||
{
|
|
||||||
if ((_index == -1) || _isdir) {
|
if ((_index == -1) || _isdir) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return tSDFile_handle[_index].read(buf, size);
|
return tSDFile_handle[_index].read(buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP_SDFile::flush()
|
void ESP_SDFile::flush() {
|
||||||
{
|
|
||||||
if ((_index == -1) || _isdir) {
|
if ((_index == -1) || _isdir) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tSDFile_handle[_index].flush();
|
tSDFile_handle[_index].flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_SDFile& ESP_SDFile::operator=(const ESP_SDFile & other)
|
ESP_SDFile& ESP_SDFile::operator=(const ESP_SDFile& other) {
|
||||||
{
|
|
||||||
// log_esp3d("Copy %s", other._filename.c_str());
|
// log_esp3d("Copy %s", other._filename.c_str());
|
||||||
_isdir = other._isdir;
|
_isdir = other._isdir;
|
||||||
_index = other._index;
|
_index = other._index;
|
||||||
@ -282,8 +251,7 @@ ESP_SDFile& ESP_SDFile::operator=(const ESP_SDFile & other)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP_SD::setSPISpeedDivider(uint8_t speeddivider)
|
bool ESP_SD::setSPISpeedDivider(uint8_t speeddivider) {
|
||||||
{
|
|
||||||
if (speeddivider > 0) {
|
if (speeddivider > 0) {
|
||||||
_spi_speed_divider = speeddivider;
|
_spi_speed_divider = speeddivider;
|
||||||
return true;
|
return true;
|
||||||
|
@ -20,23 +20,25 @@ sd_native_esp32.cpp - ESP3D sd support class
|
|||||||
#include "../../../include/esp3d_config.h"
|
#include "../../../include/esp3d_config.h"
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && defined(SD_DEVICE)
|
#if defined(ARDUINO_ARCH_ESP32) && defined(SD_DEVICE)
|
||||||
#if (SD_DEVICE == ESP_SD_NATIVE)
|
#if (SD_DEVICE == ESP_SD_NATIVE)
|
||||||
#include "../esp_sd.h"
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
#include "../../../core/settings_esp3d.h"
|
#include "../../../core/settings_esp3d.h"
|
||||||
|
#include "../esp_sd.h"
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
#include "SD.h"
|
#include "SD.h"
|
||||||
|
|
||||||
//base frequency
|
|
||||||
//or use (1000000 * ESP.getCpuFreqMHz()) TBC
|
// TBC: base frequency
|
||||||
|
// or use (1000000 * ESP.getCpuFreqMHz())
|
||||||
#define ESP_SPI_FREQ 4000000
|
#define ESP_SPI_FREQ 4000000
|
||||||
|
|
||||||
extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||||
|
|
||||||
uint8_t ESP_SD::getState(bool refresh)
|
uint8_t ESP_SD::getState(bool refresh) {
|
||||||
{
|
|
||||||
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
|
||||||
// no need to go further if SD detect is not correct
|
// no need to go further if SD detect is not correct
|
||||||
if (!((digitalRead (ESP_SD_DETECT_PIN) == ESP_SD_DETECT_VALUE) ? true : false)) {
|
if (!((digitalRead(ESP_SD_DETECT_PIN) == ESP_SD_DETECT_VALUE) ? true
|
||||||
|
: false)) {
|
||||||
_state = ESP_SDCARD_NOT_PRESENT;
|
_state = ESP_SDCARD_NOT_PRESENT;
|
||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
@ -56,8 +58,13 @@ uint8_t ESP_SD::getState(bool refresh)
|
|||||||
_state = ESP_SDCARD_NOT_PRESENT;
|
_state = ESP_SDCARD_NOT_PRESENT;
|
||||||
// using default value for speed ? should be parameter
|
// using default value for speed ? should be parameter
|
||||||
// refresh content if card was removed
|
// refresh content if card was removed
|
||||||
log_esp3d("Spi : CS: %d, Miso: %d, Mosi: %d, SCK: %d",ESP_SD_CS_PIN!=-1?ESP_SD_CS_PIN:SS, ESP_SD_MISO_PIN!=-1?ESP_SD_MISO_PIN:MISO, ESP_SD_MOSI_PIN!=-1?ESP_SD_MOSI_PIN:MOSI, ESP_SD_SCK_PIN!=-1?ESP_SD_SCK_PIN:SCK);
|
log_esp3d("Spi : CS: %d, Miso: %d, Mosi: %d, SCK: %d",
|
||||||
if (SD.begin((ESP_SD_CS_PIN == -1)?SS:ESP_SD_CS_PIN, SPI, ESP_SPI_FREQ / _spi_speed_divider)) {
|
ESP_SD_CS_PIN != -1 ? ESP_SD_CS_PIN : SS,
|
||||||
|
ESP_SD_MISO_PIN != -1 ? ESP_SD_MISO_PIN : MISO,
|
||||||
|
ESP_SD_MOSI_PIN != -1 ? ESP_SD_MOSI_PIN : MOSI,
|
||||||
|
ESP_SD_SCK_PIN != -1 ? ESP_SD_SCK_PIN : SCK);
|
||||||
|
if (SD.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SPI,
|
||||||
|
ESP_SPI_FREQ / _spi_speed_divider)) {
|
||||||
if (SD.cardSize() > 0) {
|
if (SD.cardSize() > 0) {
|
||||||
_state = ESP_SDCARD_IDLE;
|
_state = ESP_SDCARD_IDLE;
|
||||||
}
|
}
|
||||||
@ -65,10 +72,11 @@ uint8_t ESP_SD::getState(bool refresh)
|
|||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP_SD::begin()
|
bool ESP_SD::begin() {
|
||||||
{
|
#if (ESP_SD_CS_PIN != -1) || (ESP_SD_MISO_PIN != -1) || \
|
||||||
#if (ESP_SD_CS_PIN != -1) || (ESP_SD_MISO_PIN != -1) || (ESP_SD_MOSI_PIN != -1) || (ESP_SD_SCK_PIN != -1)
|
(ESP_SD_MOSI_PIN != -1) || (ESP_SD_SCK_PIN != -1)
|
||||||
log_esp3d("Custom spi : CS: %d, Miso: %d, Mosi: %d, SCK: %d",ESP_SD_CS_PIN, ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_SCK_PIN);
|
log_esp3d("Custom spi : CS: %d, Miso: %d, Mosi: %d, SCK: %d", ESP_SD_CS_PIN,
|
||||||
|
ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_SCK_PIN);
|
||||||
SPI.begin(ESP_SD_SCK_PIN, ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_CS_PIN);
|
SPI.begin(ESP_SD_SCK_PIN, ESP_SD_MISO_PIN, ESP_SD_MOSI_PIN, ESP_SD_CS_PIN);
|
||||||
#endif
|
#endif
|
||||||
_started = true;
|
_started = true;
|
||||||
@ -91,32 +99,29 @@ bool ESP_SD::begin()
|
|||||||
return _started;
|
return _started;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP_SD::end()
|
void ESP_SD::end() {
|
||||||
{
|
|
||||||
SD.end();
|
SD.end();
|
||||||
_state = ESP_SDCARD_NOT_PRESENT;
|
_state = ESP_SDCARD_NOT_PRESENT;
|
||||||
_started = false;
|
_started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP_SD::refreshStats(bool force)
|
void ESP_SD::refreshStats(bool force) {
|
||||||
{
|
|
||||||
if (force || _sizechanged) {
|
if (force || _sizechanged) {
|
||||||
freeBytes(true);
|
freeBytes(true);
|
||||||
}
|
}
|
||||||
_sizechanged = false;
|
_sizechanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ESP_SD::totalBytes(bool refresh)
|
uint64_t ESP_SD::totalBytes(bool refresh) {
|
||||||
{
|
|
||||||
static uint64_t _totalBytes = 0;
|
static uint64_t _totalBytes = 0;
|
||||||
if (refresh || _totalBytes == 0) {
|
if (refresh || _totalBytes == 0) {
|
||||||
_totalBytes = SD.totalBytes();;
|
_totalBytes = SD.totalBytes();
|
||||||
|
;
|
||||||
}
|
}
|
||||||
return _totalBytes;
|
return _totalBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ESP_SD::usedBytes(bool refresh)
|
uint64_t ESP_SD::usedBytes(bool refresh) {
|
||||||
{
|
|
||||||
static uint64_t _usedBytes = 0;
|
static uint64_t _usedBytes = 0;
|
||||||
if (refresh || _usedBytes == 0) {
|
if (refresh || _usedBytes == 0) {
|
||||||
_usedBytes = SD.usedBytes();
|
_usedBytes = SD.usedBytes();
|
||||||
@ -124,23 +129,17 @@ uint64_t ESP_SD::usedBytes(bool refresh)
|
|||||||
return _usedBytes;
|
return _usedBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ESP_SD::freeBytes(bool refresh)
|
uint64_t ESP_SD::freeBytes(bool refresh) {
|
||||||
{
|
|
||||||
return (totalBytes(refresh) - usedBytes(refresh));
|
return (totalBytes(refresh) - usedBytes(refresh));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint ESP_SD::maxPathLength()
|
uint ESP_SD::maxPathLength() { return 255; }
|
||||||
{
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ESP_SD::rename(const char *oldpath, const char *newpath)
|
bool ESP_SD::rename(const char *oldpath, const char *newpath) {
|
||||||
{
|
|
||||||
return SD.rename(oldpath, newpath);
|
return SD.rename(oldpath, newpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP_SD::format(ESP3DOutput * output)
|
bool ESP_SD::format(ESP3DOutput *output) {
|
||||||
{
|
|
||||||
// not available yet
|
// not available yet
|
||||||
if (output) {
|
if (output) {
|
||||||
output->printERROR("Not implemented!");
|
output->printERROR("Not implemented!");
|
||||||
@ -148,10 +147,11 @@ bool ESP_SD::format(ESP3DOutput * output)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
ESP_SDFile ESP_SD::open(const char *path, uint8_t mode) {
|
||||||
{
|
|
||||||
// do some check
|
// do some check
|
||||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
if (((strcmp(path, "/") == 0) &&
|
||||||
|
((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) ||
|
||||||
|
(strlen(path) == 0)) {
|
||||||
return ESP_SDFile();
|
return ESP_SDFile();
|
||||||
}
|
}
|
||||||
// path must start by '/'
|
// path must start by '/'
|
||||||
@ -167,13 +167,15 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
|||||||
return ESP_SDFile();
|
return ESP_SDFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File tmp = SD.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
|
File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ
|
||||||
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
|
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
|
||||||
|
: FILE_APPEND);
|
||||||
|
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),
|
||||||
|
(mode == ESP_FILE_READ) ? false : true, path);
|
||||||
return esptmp;
|
return esptmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP_SD::exists(const char* path)
|
bool ESP_SD::exists(const char *path) {
|
||||||
{
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
String p = path;
|
String p = path;
|
||||||
// root should always be there if started
|
// root should always be there if started
|
||||||
@ -193,13 +195,9 @@ bool ESP_SD::exists(const char* path)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP_SD::remove(const char *path)
|
bool ESP_SD::remove(const char *path) { return SD.remove(path); }
|
||||||
{
|
|
||||||
return SD.remove(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ESP_SD::mkdir(const char *path)
|
bool ESP_SD::mkdir(const char *path) {
|
||||||
{
|
|
||||||
String p = path;
|
String p = path;
|
||||||
if (p.endsWith("/")) {
|
if (p.endsWith("/")) {
|
||||||
p.remove(p.length() - 1, 1);
|
p.remove(p.length() - 1, 1);
|
||||||
@ -207,9 +205,7 @@ bool ESP_SD::mkdir(const char *path)
|
|||||||
return SD.mkdir(p.c_str());
|
return SD.mkdir(p.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP_SD::rmdir(const char *path)
|
bool ESP_SD::rmdir(const char *path) {
|
||||||
{
|
|
||||||
|
|
||||||
String p = path;
|
String p = path;
|
||||||
if (!p.startsWith("/")) {
|
if (!p.startsWith("/")) {
|
||||||
p = '/' + p;
|
p = '/' + p;
|
||||||
@ -238,7 +234,6 @@ bool ESP_SD::rmdir(const char *path)
|
|||||||
f.close();
|
f.close();
|
||||||
f = File();
|
f = File();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
String filepath = pathlist.top() + '/';
|
String filepath = pathlist.top() + '/';
|
||||||
filepath += f.name();
|
filepath += f.name();
|
||||||
f.close();
|
f.close();
|
||||||
@ -261,16 +256,15 @@ bool ESP_SD::rmdir(const char *path)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP_SD::closeAll()
|
void ESP_SD::closeAll() {
|
||||||
{
|
|
||||||
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
|
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
|
||||||
tSDFile_handle[i].close();
|
tSDFile_handle[i].close();
|
||||||
tSDFile_handle[i] = File();
|
tSDFile_handle[i] = File();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * path)
|
ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode,
|
||||||
{
|
const char *path) {
|
||||||
_isdir = isdir;
|
_isdir = isdir;
|
||||||
_dirlist = "";
|
_dirlist = "";
|
||||||
_index = -1;
|
_index = -1;
|
||||||
@ -314,13 +308,11 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode)
|
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode) {
|
||||||
{
|
|
||||||
return tSDFile_handle[_index].seek(pos, (SeekMode)mode);
|
return tSDFile_handle[_index].seek(pos, (SeekMode)mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP_SDFile::close()
|
void ESP_SDFile::close() {
|
||||||
{
|
|
||||||
if (_index != -1) {
|
if (_index != -1) {
|
||||||
// log_esp3d("Closing File at index %d", _index);
|
// log_esp3d("Closing File at index %d", _index);
|
||||||
tSDFile_handle[_index].close();
|
tSDFile_handle[_index].close();
|
||||||
@ -340,15 +332,15 @@ void ESP_SDFile::close()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_SDFile ESP_SDFile::openNextFile()
|
ESP_SDFile ESP_SDFile::openNextFile() {
|
||||||
{
|
|
||||||
if ((_index == -1) || !_isdir) {
|
if ((_index == -1) || !_isdir) {
|
||||||
log_esp3d("openNextFile failed");
|
log_esp3d("openNextFile failed");
|
||||||
return ESP_SDFile();
|
return ESP_SDFile();
|
||||||
}
|
}
|
||||||
File tmp = tSDFile_handle[_index].openNextFile();
|
File tmp = tSDFile_handle[_index].openNextFile();
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
log_esp3d("tmp name :%s %s %s", tmp.name(), (tmp.isDirectory())?"isDir":"isFile", _filename.c_str());
|
log_esp3d("tmp name :%s %s %s", tmp.name(),
|
||||||
|
(tmp.isDirectory()) ? "isDir" : "isFile", _filename.c_str());
|
||||||
String s = tmp.name();
|
String s = tmp.name();
|
||||||
// if (s!="/")s+="/";
|
// if (s!="/")s+="/";
|
||||||
// s += tmp.name();
|
// s += tmp.name();
|
||||||
@ -360,15 +352,9 @@ ESP_SDFile ESP_SDFile::openNextFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO need to find reliable way
|
// TODO need to find reliable way
|
||||||
const char* ESP_SDFile::shortname() const
|
const char *ESP_SDFile::shortname() const { return _name.c_str(); }
|
||||||
{
|
|
||||||
return _name.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * ESP_SD::FilesystemName()
|
const char *ESP_SD::FilesystemName() { return "SD native"; }
|
||||||
{
|
|
||||||
return "SD native";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // SD_DEVICE == ESP_SD_NATIVE
|
#endif // SD_DEVICE == ESP_SD_NATIVE
|
||||||
#endif // ARCH_ESP32 && SD_DEVICE
|
#endif // ARCH_ESP32 && SD_DEVICE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user