mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-06 05:36:11 +08:00
Goodbye genLinkedList - welcome std::stack
it decrease ESP32 binary size of few bytes (-256) - when it increase esp8266 binary of few bytes (+56) , but make code more standard so it is fine IMHO
This commit is contained in:
parent
6a82412878
commit
159b9e6f47
@ -1,223 +0,0 @@
|
||||
/*
|
||||
genlinkedlist.h - ESP3D simple generic linked list class
|
||||
* inspired by great https://github.com/ivanseidel/LinkedList
|
||||
|
||||
Copyright (c) 2018 Luc Lebosse. All rights reserved.
|
||||
|
||||
This code is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with This code; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef _GENLINKEDLIST_H
|
||||
#define _GENLINKEDLIST_H
|
||||
|
||||
template<class T> struct GenNode {
|
||||
T data;
|
||||
GenNode<T> *next;
|
||||
GenNode<T> *prev;
|
||||
};
|
||||
|
||||
template <typename T> class GenLinkedList
|
||||
{
|
||||
public:
|
||||
GenLinkedList();
|
||||
~GenLinkedList();
|
||||
//Clear list
|
||||
void clear();
|
||||
//number of GenNodes
|
||||
size_t count();
|
||||
//add data at the end of list
|
||||
bool push(T data);
|
||||
//get data at end of list and remove from list
|
||||
T pop();
|
||||
//add data at the begining of list
|
||||
bool shift(T data);
|
||||
//get data from begining of list and remove from list
|
||||
T unshift();
|
||||
//get data from index position
|
||||
T get(size_t index);
|
||||
//get head data
|
||||
T getFirst();
|
||||
//get tail data
|
||||
T getLast();
|
||||
|
||||
private:
|
||||
//number of GenNode
|
||||
size_t _nb;
|
||||
//First GenNode
|
||||
GenNode<T> *_head;
|
||||
//Last GenNode
|
||||
GenNode<T> *_tail;
|
||||
};
|
||||
|
||||
//Constructor
|
||||
template <typename T>GenLinkedList<T>::GenLinkedList()
|
||||
{
|
||||
_nb = 0;
|
||||
_head = nullptr;
|
||||
_tail = nullptr;
|
||||
}
|
||||
|
||||
//Destructor
|
||||
template <typename T>GenLinkedList<T>::~GenLinkedList()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
//clear list of all GenNodes
|
||||
template<typename T>void GenLinkedList<T>::clear()
|
||||
{
|
||||
GenNode<T> *current;
|
||||
//delete from first to last
|
||||
while (_head != nullptr) {
|
||||
current = _head;
|
||||
_head = _head->next;
|
||||
current->data = T();
|
||||
delete current;
|
||||
}
|
||||
_tail = _head;
|
||||
_nb = 0;
|
||||
}
|
||||
|
||||
//Number of GenNodes
|
||||
template<typename T>size_t GenLinkedList<T>::count()
|
||||
{
|
||||
return _nb;
|
||||
}
|
||||
|
||||
//add to end of list
|
||||
template<typename T> bool GenLinkedList<T>::push (T data)
|
||||
{
|
||||
GenNode<T> *ptr = new GenNode<T>();
|
||||
if (!ptr) {
|
||||
return false;
|
||||
}
|
||||
ptr->data = data;
|
||||
ptr->next = nullptr;
|
||||
ptr->prev = nullptr;
|
||||
_nb++;
|
||||
//Check if already have element in list
|
||||
if (_head) {
|
||||
_tail->next = ptr;
|
||||
ptr->prev = _tail;
|
||||
_tail = ptr;
|
||||
} else { // no element _head = _tail
|
||||
_head = ptr;
|
||||
_tail = _head;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//take out from end of list
|
||||
template<typename T>T GenLinkedList<T>::pop()
|
||||
{
|
||||
if (_head == nullptr) {
|
||||
return T();
|
||||
}
|
||||
T data = _tail->data;
|
||||
|
||||
_nb--;
|
||||
if (_head == _tail) {
|
||||
_head->data = T();
|
||||
delete (_head);
|
||||
_head = nullptr;
|
||||
_tail = _head;
|
||||
} else {
|
||||
GenNode<T> *ptr = _tail;
|
||||
_tail = _tail->prev;
|
||||
_tail->next = nullptr;
|
||||
ptr->data = T();
|
||||
delete (ptr);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
//add to head of list
|
||||
template<typename T> bool GenLinkedList<T>::shift (T data)
|
||||
{
|
||||
|
||||
GenNode<T> *ptr = new GenNode<T>();
|
||||
if (!ptr) {
|
||||
return false;
|
||||
}
|
||||
ptr->data = data;
|
||||
ptr->next = nullptr;
|
||||
ptr->prev = nullptr;
|
||||
_nb++;
|
||||
//Check if already have element in list
|
||||
if (_head) {
|
||||
ptr->next = _head;
|
||||
_head->prev = ptr;
|
||||
_head = ptr;
|
||||
} else { // no element _head = _tail
|
||||
_head = ptr;
|
||||
_tail = _head;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//take out from Head
|
||||
template<typename T>T GenLinkedList<T>::unshift()
|
||||
{
|
||||
if (_head == nullptr) {
|
||||
return T();
|
||||
}
|
||||
T data = _head->data;
|
||||
_nb--;
|
||||
if (_head == _tail) {
|
||||
_head->data = T();
|
||||
delete (_head);
|
||||
_head = nullptr;
|
||||
_tail = _head;
|
||||
} else {
|
||||
GenNode<T> *ptr = _head;
|
||||
_head = _head->next;
|
||||
_head->prev = nullptr;
|
||||
ptr->data = T();
|
||||
delete (ptr);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
//get data from position (do not remove from list)
|
||||
template<typename T>T GenLinkedList<T>::get(size_t index)
|
||||
{
|
||||
if ((_head == nullptr) || (index > _nb)) {
|
||||
return T();
|
||||
}
|
||||
GenNode<T> *ptr = _head;
|
||||
for (size_t pos = 0; pos < index; pos++) {
|
||||
ptr = ptr->next;
|
||||
}
|
||||
return ptr->data;
|
||||
}
|
||||
|
||||
|
||||
//get head data (do not remove from list)
|
||||
template<typename T>T GenLinkedList<T>::getFirst()
|
||||
{
|
||||
if (_head == nullptr) {
|
||||
return T();
|
||||
}
|
||||
return _head->data;
|
||||
}
|
||||
|
||||
//get tail data (do not remove from list)
|
||||
template<typename T>T GenLinkedList<T>::getLast()
|
||||
{
|
||||
if (_head == nullptr) {
|
||||
return T();
|
||||
}
|
||||
return _tail->data;
|
||||
}
|
||||
|
||||
#endif //_GENLINKEDLIST_H
|
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a207"
|
||||
#define FW_VERSION "3.0.0.a208"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "../../include/esp3d_config.h"
|
||||
#if defined(GLOBAL_FILESYSTEM_FEATURE)
|
||||
#include "esp_globalFS.h"
|
||||
//#include "../../core/genLinkedList.h"
|
||||
|
||||
//to verify FS is accessible
|
||||
bool ESP_GBFS::isavailable(uint8_t FS)
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "../../include/esp3d_config.h"
|
||||
#ifdef SD_DEVICE
|
||||
#include "esp_sd.h"
|
||||
#include "../../core/genLinkedList.h"
|
||||
#include <time.h>
|
||||
|
||||
#define ESP_MAX_SD_OPENHANDLE 4
|
||||
|
@ -21,7 +21,7 @@ fat_esp32_filesystem.cpp - ESP3D fat filesystem configuration class
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if (FILESYSTEM_FEATURE == ESP_FAT_FILESYSTEM)
|
||||
#include "../esp_filesystem.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include <FS.h>
|
||||
#include "FFat.h"
|
||||
|
||||
@ -156,10 +156,10 @@ bool ESP_FileSystem::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String > pathlist;
|
||||
pathlist.push(p);
|
||||
while (pathlist.count() > 0) {
|
||||
File dir = FFat.open(pathlist.getLast().c_str());
|
||||
while (pathlist.size() > 0) {
|
||||
File dir = FFat.open(pathlist.top().c_str());
|
||||
File f = dir.openNextFile();
|
||||
bool candelete = true;
|
||||
while (f) {
|
||||
@ -176,15 +176,15 @@ bool ESP_FileSystem::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
if (candelete) {
|
||||
if (pathlist.getLast() !="/") {
|
||||
res = FFat.rmdir(pathlist.getLast().c_str());
|
||||
if (pathlist.top() !="/") {
|
||||
res = FFat.rmdir(pathlist.top().c_str());
|
||||
}
|
||||
pathlist.pop();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
p = String();
|
||||
log_esp3d("count %d", pathlist.count());
|
||||
log_esp3d("count %d", pathlist.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ littlefs_esp32_filesystem.cpp - ESP3D littlefs filesystem configuration class
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if (FILESYSTEM_FEATURE == ESP_LITTLEFS_FILESYSTEM) && defined(ARDUINO_ARCH_ESP32)
|
||||
#include "../esp_filesystem.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
@ -163,10 +163,10 @@ bool ESP_FileSystem::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String> pathlist;
|
||||
pathlist.push(p);
|
||||
while (pathlist.count() > 0) {
|
||||
File dir = LittleFS.open(pathlist.getLast().c_str());
|
||||
while (pathlist.size() > 0) {
|
||||
File dir = LittleFS.open(pathlist.top().c_str());
|
||||
File f = dir.openNextFile();
|
||||
bool candelete = true;
|
||||
while (f) {
|
||||
@ -183,15 +183,15 @@ bool ESP_FileSystem::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
if (candelete) {
|
||||
if (pathlist.getLast() !="/") {
|
||||
res = LittleFS.rmdir(pathlist.getLast().c_str());
|
||||
if (pathlist.top() !="/") {
|
||||
res = LittleFS.rmdir(pathlist.top().c_str());
|
||||
}
|
||||
pathlist.pop();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
p = String();
|
||||
log_esp3d("count %d", pathlist.count());
|
||||
log_esp3d("count %d", pathlist.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ littlefs_esp8266_filesystem.cpp - ESP3D littlefs filesystem configuration class
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if (FILESYSTEM_FEATURE == ESP_LITTLEFS_FILESYSTEM) && defined(ARDUINO_ARCH_ESP8266)
|
||||
#include "../esp_filesystem.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include <FS.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
@ -157,7 +157,7 @@ bool ESP_FileSystem::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String> pathlist;
|
||||
String spath = path;
|
||||
spath.trim();
|
||||
if (spath[spath.length()-1] != '/') {
|
||||
@ -167,15 +167,15 @@ bool ESP_FileSystem::rmdir(const char *path)
|
||||
spath ="/" + spath;
|
||||
}
|
||||
pathlist.push(spath);
|
||||
while (pathlist.count() > 0) {
|
||||
spath=pathlist.getLast();
|
||||
while (pathlist.size() > 0) {
|
||||
spath=pathlist.top();
|
||||
bool candelete = true;
|
||||
if (LittleFS.exists(spath.c_str())) {
|
||||
Dir dir = LittleFS.openDir(pathlist.getLast().c_str());
|
||||
Dir dir = LittleFS.openDir(pathlist.top().c_str());
|
||||
while (dir.next()) {
|
||||
if (dir.isDirectory()) {
|
||||
candelete = false;
|
||||
String newdir = pathlist.getLast() + dir.fileName() + "/";
|
||||
String newdir = pathlist.top() + dir.fileName() + "/";
|
||||
pathlist.push(newdir);
|
||||
} else {
|
||||
log_esp3d("remove %s", dir.fileName().c_str());
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if (FILESYSTEM_FEATURE == ESP_SPIFFS_FILESYSTEM) && defined(ARDUINO_ARCH_ESP32)
|
||||
#include "../esp_filesystem.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include <FS.h>
|
||||
#include <SPIFFS.h>
|
||||
extern File tFile_handle[ESP_MAX_OPENHANDLE];
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "../../../include/esp3d_config.h"
|
||||
#if (FILESYSTEM_FEATURE == ESP_SPIFFS_FILESYSTEM) && defined (ARDUINO_ARCH_ESP8266)
|
||||
#include "../esp_filesystem.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <FS.h>
|
||||
Dir tDir_handle[ESP_MAX_OPENHANDLE];
|
||||
extern File tFile_handle[ESP_MAX_OPENHANDLE];
|
||||
|
@ -21,7 +21,7 @@ sd_native_esp32.cpp - ESP3D sd support class
|
||||
#if defined (ARDUINO_ARCH_ESP32) && defined(SD_DEVICE)
|
||||
#if (SD_DEVICE == ESP_SD_NATIVE)
|
||||
#include "../esp_sd.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include "FS.h"
|
||||
#include "SD.h"
|
||||
@ -213,14 +213,14 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String > pathlist;
|
||||
String p = path;
|
||||
if (p.endsWith("/")) {
|
||||
p.remove( p.length() - 1,1);
|
||||
}
|
||||
pathlist.push(p);
|
||||
while (pathlist.count() > 0) {
|
||||
File dir = SD.open(pathlist.getLast().c_str());
|
||||
while (pathlist.size() > 0) {
|
||||
File dir = SD.open(pathlist.top().c_str());
|
||||
File f = dir.openNextFile();
|
||||
bool candelete = true;
|
||||
while (f) {
|
||||
@ -237,15 +237,15 @@ bool ESP_SD::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
if (candelete) {
|
||||
if (pathlist.getLast() !="/") {
|
||||
res = SD.rmdir(pathlist.getLast().c_str());
|
||||
if (pathlist.top() !="/") {
|
||||
res = SD.rmdir(pathlist.top().c_str());
|
||||
}
|
||||
pathlist.pop();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
p = String();
|
||||
log_esp3d("count %d", pathlist.count());
|
||||
log_esp3d("count %d", pathlist.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ sd_native_esp8266.cpp - ESP3D sd support class
|
||||
#if (SD_DEVICE == ESP_SD_NATIVE)
|
||||
#define FS_NO_GLOBALS
|
||||
#include "../esp_sd.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include <SD.h>
|
||||
#include <SDFS.h>
|
||||
@ -256,11 +256,11 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String > pathlist;
|
||||
String p = path;
|
||||
pathlist.push(p);
|
||||
while (pathlist.count() > 0) {
|
||||
File dir = SD.open(pathlist.getLast().c_str());
|
||||
while (pathlist.size() > 0) {
|
||||
File dir = SD.open(pathlist.top().c_str());
|
||||
dir.rewindDirectory();
|
||||
File f = dir.openNextFile();
|
||||
bool candelete = true;
|
||||
@ -279,15 +279,15 @@ bool ESP_SD::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
if (candelete) {
|
||||
if (pathlist.getLast() !="/") {
|
||||
res = SD.rmdir(pathlist.getLast().c_str());
|
||||
if (pathlist.top() !="/") {
|
||||
res = SD.rmdir(pathlist.top().c_str());
|
||||
}
|
||||
pathlist.pop();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
p = String();
|
||||
log_esp3d("count %d", pathlist.count());
|
||||
log_esp3d("count %d", pathlist.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ sd_sdfat2_esp32.cpp - ESP3D sd support class
|
||||
#if defined (ARDUINO_ARCH_ESP32) && defined(SD_DEVICE)
|
||||
#if (SD_DEVICE == ESP_SDFAT2)
|
||||
#include "../esp_sd.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include <SdFat.h>
|
||||
#include <sdios.h>
|
||||
@ -366,11 +366,11 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String > pathlist;
|
||||
String p = path;
|
||||
pathlist.push(p);
|
||||
while (pathlist.count() > 0) {
|
||||
File dir = SD.open(pathlist.getLast().c_str());
|
||||
while (pathlist.size() > 0) {
|
||||
File dir = SD.open(pathlist.top().c_str());
|
||||
dir.rewindDirectory();
|
||||
File f = dir.openNextFile();
|
||||
bool candelete = true;
|
||||
@ -394,15 +394,15 @@ bool ESP_SD::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
if (candelete) {
|
||||
if (pathlist.getLast() !="/") {
|
||||
res = SD.rmdir(pathlist.getLast().c_str());
|
||||
if (pathlist.top() !="/") {
|
||||
res = SD.rmdir(pathlist.top().c_str());
|
||||
}
|
||||
pathlist.pop();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
p = String();
|
||||
log_esp3d("count %d", pathlist.count());
|
||||
log_esp3d("count %d", pathlist.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ sd_sdfat2_esp8266.cpp - ESP3D sd support class
|
||||
#if (SD_DEVICE == ESP_SDFAT2)
|
||||
#define FS_NO_GLOBALS
|
||||
#include "../esp_sd.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#define NO_GLOBAL_SD
|
||||
#include <SdFat.h>
|
||||
@ -351,11 +351,11 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String > pathlist;
|
||||
String p = path;
|
||||
pathlist.push(p);
|
||||
while (pathlist.count() > 0) {
|
||||
sdfat::File dir = SD.open(pathlist.getLast().c_str());
|
||||
while (pathlist.size() > 0) {
|
||||
sdfat::File dir = SD.open(pathlist.top().c_str());
|
||||
dir.rewindDirectory();
|
||||
sdfat::File f = dir.openNextFile();
|
||||
bool candelete = true;
|
||||
@ -379,15 +379,15 @@ bool ESP_SD::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
if (candelete) {
|
||||
if (pathlist.getLast() !="/") {
|
||||
res = SD.rmdir(pathlist.getLast().c_str());
|
||||
if (pathlist.top() !="/") {
|
||||
res = SD.rmdir(pathlist.top().c_str());
|
||||
}
|
||||
pathlist.pop();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
p = String();
|
||||
log_esp3d("count %d", pathlist.count());
|
||||
log_esp3d("count %d", pathlist.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ sd_sdfat_esp32.cpp - ESP3D sd support class
|
||||
#if defined (ARDUINO_ARCH_ESP32) && defined(SD_DEVICE)
|
||||
#if (SD_DEVICE == ESP_SDFAT)
|
||||
#include "../esp_sd.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include <SdFat.h>
|
||||
extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||
@ -677,11 +677,11 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String > pathlist;
|
||||
String p = path;
|
||||
pathlist.push(p);
|
||||
while (pathlist.count() > 0) {
|
||||
File dir = SD.open(pathlist.getLast().c_str());
|
||||
while (pathlist.size() > 0) {
|
||||
File dir = SD.open(pathlist.top().c_str());
|
||||
dir.rewindDirectory();
|
||||
File f = dir.openNextFile();
|
||||
bool candelete = true;
|
||||
@ -705,15 +705,15 @@ bool ESP_SD::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
if (candelete) {
|
||||
if (pathlist.getLast() !="/") {
|
||||
res = SD.rmdir(pathlist.getLast().c_str());
|
||||
if (pathlist.top() !="/") {
|
||||
res = SD.rmdir(pathlist.top().c_str());
|
||||
}
|
||||
pathlist.pop();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
p = String();
|
||||
log_esp3d("count %d", pathlist.count());
|
||||
log_esp3d("count %d", pathlist.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ sd_sdfat_esp8266.cpp - ESP3D sd support class
|
||||
#if (SD_DEVICE == ESP_SDFAT)
|
||||
#define FS_NO_GLOBALS
|
||||
#include "../esp_sd.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#define NO_GLOBAL_SD
|
||||
#include <SdFat.h>
|
||||
@ -684,11 +684,11 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String > pathlist;
|
||||
String p = path;
|
||||
pathlist.push(p);
|
||||
while (pathlist.count() > 0) {
|
||||
sdfat::File dir = SD.open(pathlist.getLast().c_str());
|
||||
while (pathlist.size() > 0) {
|
||||
sdfat::File dir = SD.open(pathlist.top().c_str());
|
||||
dir.rewindDirectory();
|
||||
sdfat::File f = dir.openNextFile();
|
||||
bool candelete = true;
|
||||
@ -712,15 +712,15 @@ bool ESP_SD::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
if (candelete) {
|
||||
if (pathlist.getLast() !="/") {
|
||||
res = SD.rmdir(pathlist.getLast().c_str());
|
||||
if (pathlist.top() !="/") {
|
||||
res = SD.rmdir(pathlist.top().c_str());
|
||||
}
|
||||
pathlist.pop();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
p = String();
|
||||
log_esp3d("count %d", pathlist.count());
|
||||
log_esp3d("count %d", pathlist.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ sdio_esp32.cpp - ESP3D sd support class
|
||||
#if defined (ARDUINO_ARCH_ESP32) && defined(SD_DEVICE)
|
||||
#if (SD_DEVICE == ESP_SDIO)
|
||||
#include "../esp_sd.h"
|
||||
#include "../../../core/genLinkedList.h"
|
||||
#include <stack>
|
||||
#include "../../../core/settings_esp3d.h"
|
||||
#include "FS.h"
|
||||
#include "SD_MMC.h"
|
||||
@ -237,14 +237,14 @@ bool ESP_SD::rmdir(const char *path)
|
||||
return false;
|
||||
}
|
||||
bool res = true;
|
||||
GenLinkedList<String > pathlist;
|
||||
std::stack <String > pathlist;
|
||||
String p = path;
|
||||
if (p.endsWith("/")) {
|
||||
p.remove( p.length() - 1,1);
|
||||
}
|
||||
pathlist.push(p);
|
||||
while (pathlist.count() > 0) {
|
||||
File dir = SD_MMC.open(pathlist.getLast().c_str());
|
||||
while (pathlist.size() > 0) {
|
||||
File dir = SD_MMC.open(pathlist.top().c_str());
|
||||
File f = dir.openNextFile();
|
||||
bool candelete = true;
|
||||
while (f) {
|
||||
@ -261,15 +261,15 @@ bool ESP_SD::rmdir(const char *path)
|
||||
}
|
||||
}
|
||||
if (candelete) {
|
||||
if (pathlist.getLast() !="/") {
|
||||
res = SD_MMC.rmdir(pathlist.getLast().c_str());
|
||||
if (pathlist.top() !="/") {
|
||||
res = SD_MMC.rmdir(pathlist.top().c_str());
|
||||
}
|
||||
pathlist.pop();
|
||||
}
|
||||
dir.close();
|
||||
}
|
||||
p = String();
|
||||
log_esp3d("count %d", pathlist.count());
|
||||
log_esp3d("count %d", pathlist.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user