mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-02 10:53:01 +02:00
Fixed SDCard config
This commit is contained in:
@@ -403,7 +403,7 @@ void MachineConfig::afterParse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_sdCard == nullptr) {
|
if (_sdCard == nullptr) {
|
||||||
_sdCard = new SDCardPin();
|
_sdCard = new SDCard();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_control == nullptr) {
|
if (_control == nullptr) {
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
#include "WebUI/BTConfig.h"
|
#include "WebUI/BTConfig.h"
|
||||||
#include "Control.h"
|
#include "Control.h"
|
||||||
#include "Probe.h"
|
#include "Probe.h"
|
||||||
#include "SDCardPin.h"
|
#include "SDCard.h"
|
||||||
#include "Spindles/Spindle.h"
|
#include "Spindles/Spindle.h"
|
||||||
|
|
||||||
// TODO FIXME: Split this file up into several files, perhaps put it in some folder and namespace Machine?
|
// TODO FIXME: Split this file up into several files, perhaps put it in some folder and namespace Machine?
|
||||||
@@ -374,7 +374,7 @@ public:
|
|||||||
Communications* _comms = nullptr;
|
Communications* _comms = nullptr;
|
||||||
Control* _control = nullptr;
|
Control* _control = nullptr;
|
||||||
UserOutputs* _userOutputs = nullptr;
|
UserOutputs* _userOutputs = nullptr;
|
||||||
SDCardPin* _sdCard = nullptr;
|
SDCard* _sdCard = nullptr;
|
||||||
Spindles::Spindle* _spindle = nullptr;
|
Spindles::Spindle* _spindle = nullptr;
|
||||||
|
|
||||||
int _pulseMicroSeconds = 3;
|
int _pulseMicroSeconds = 3;
|
||||||
|
@@ -546,10 +546,10 @@ void mc_reset() {
|
|||||||
sys_analog_all_off();
|
sys_analog_all_off();
|
||||||
#ifdef ENABLE_SD_CARD
|
#ifdef ENABLE_SD_CARD
|
||||||
// do we need to stop a running SD job?
|
// do we need to stop a running SD job?
|
||||||
if (sdCard.get_state(false) == SDCard::State::BusyPrinting) {
|
if (config->_sdCard->get_state(false) == SDCard::State::BusyPrinting) {
|
||||||
//Report print stopped
|
//Report print stopped
|
||||||
report_feedback_message(Message::SdFileQuit);
|
report_feedback_message(Message::SdFileQuit);
|
||||||
sdCard.closeFile();
|
config->_sdCard->closeFile();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Kill steppers only if in any motion state, i.e. cycle, actively holding, or homing.
|
// Kill steppers only if in any motion state, i.e. cycle, actively holding, or homing.
|
||||||
|
@@ -140,16 +140,17 @@ void protocol_main_loop() {
|
|||||||
int c;
|
int c;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
#ifdef ENABLE_SD_CARD
|
#ifdef ENABLE_SD_CARD
|
||||||
if (sdCard._ready_next) {
|
auto sdcard = config->_sdCard;
|
||||||
|
if (sdcard->_ready_next) {
|
||||||
char fileLine[255];
|
char fileLine[255];
|
||||||
if (sdCard.readFileLine(fileLine, 255)) {
|
if (sdcard->readFileLine(fileLine, 255)) {
|
||||||
sdCard._ready_next = false;
|
sdcard->_ready_next = false;
|
||||||
report_status_message(execute_line(fileLine, sdCard._client, sdCard._auth_level), sdCard._client);
|
report_status_message(execute_line(fileLine, sdcard->_client, sdcard->_auth_level), sdcard->_client);
|
||||||
} else {
|
} else {
|
||||||
char temp[50];
|
char temp[50];
|
||||||
sdCard.get_current_filename(temp);
|
sdcard->get_current_filename(temp);
|
||||||
grbl_notifyf("SD print done", "%s print is successful", temp);
|
grbl_notifyf("SD print done", "%s print is successful", temp);
|
||||||
sdCard.closeFile(); // close file and clear SD ready/running flags
|
sdcard->closeFile(); // close file and clear SD ready/running flags
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -204,11 +204,12 @@ static String report_util_axis_values(const float* axis_value) {
|
|||||||
// from a critical error, such as a triggered hard limit. Interface should always monitor for these
|
// from a critical error, such as a triggered hard limit. Interface should always monitor for these
|
||||||
// responses.
|
// responses.
|
||||||
void report_status_message(Error status_code, uint8_t client) {
|
void report_status_message(Error status_code, uint8_t client) {
|
||||||
|
auto sdCard = config->_sdCard;
|
||||||
switch (status_code) {
|
switch (status_code) {
|
||||||
case Error::Ok: // Error::Ok
|
case Error::Ok: // Error::Ok
|
||||||
#ifdef ENABLE_SD_CARD
|
#ifdef ENABLE_SD_CARD
|
||||||
if (sdCard.get_state(false) == SDCard::State::BusyPrinting) {
|
if (sdCard->get_state(false) == SDCard::State::BusyPrinting) {
|
||||||
sdCard._ready_next = true; // flag so system_execute_line() will send the next line
|
sdCard->_ready_next = true; // flag so system_execute_line() will send the next line
|
||||||
} else {
|
} else {
|
||||||
grbl_send(client, "ok\r\n");
|
grbl_send(client, "ok\r\n");
|
||||||
}
|
}
|
||||||
@@ -219,16 +220,16 @@ void report_status_message(Error status_code, uint8_t client) {
|
|||||||
default:
|
default:
|
||||||
#ifdef ENABLE_SD_CARD
|
#ifdef ENABLE_SD_CARD
|
||||||
// do we need to stop a running SD job?
|
// do we need to stop a running SD job?
|
||||||
if (sdCard.get_state(false) == SDCard::State::BusyPrinting) {
|
if (sdCard->get_state(false) == SDCard::State::BusyPrinting) {
|
||||||
if (status_code == Error::GcodeUnsupportedCommand) {
|
if (status_code == Error::GcodeUnsupportedCommand) {
|
||||||
grbl_sendf(client, "error:%d\r\n", status_code); // most senders seem to tolerate this error and keep on going
|
grbl_sendf(client, "error:%d\r\n", status_code); // most senders seem to tolerate this error and keep on going
|
||||||
grbl_sendf(CLIENT_ALL, "error:%d in SD file at line %d\r\n", status_code, sdCard.get_current_line_number());
|
grbl_sendf(CLIENT_ALL, "error:%d in SD file at line %d\r\n", status_code, sdCard->get_current_line_number());
|
||||||
// don't close file
|
// don't close file
|
||||||
sdCard._ready_next = true; // flag so system_execute_line() will send the next line
|
sdCard->_ready_next = true; // flag so system_execute_line() will send the next line
|
||||||
} else {
|
} else {
|
||||||
grbl_notifyf("SD print error", "Error:%d during SD file at line: %d", status_code, sdCard.get_current_line_number());
|
grbl_notifyf("SD print error", "Error:%d during SD file at line: %d", status_code, sdCard->get_current_line_number());
|
||||||
grbl_sendf(CLIENT_ALL, "error:%d in SD file at line %d\r\n", status_code, sdCard.get_current_line_number());
|
grbl_sendf(CLIENT_ALL, "error:%d in SD file at line %d\r\n", status_code, sdCard->get_current_line_number());
|
||||||
sdCard.closeFile();
|
sdCard->closeFile();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -274,8 +275,8 @@ std::map<Message, const char*> MessageText = {
|
|||||||
void report_feedback_message(Message message) { // ok to send to all clients
|
void report_feedback_message(Message message) { // ok to send to all clients
|
||||||
#if defined(ENABLE_SD_CARD)
|
#if defined(ENABLE_SD_CARD)
|
||||||
if (message == Message::SdFileQuit) {
|
if (message == Message::SdFileQuit) {
|
||||||
grbl_notifyf("SD print canceled", "Reset during SD file at line: %d", sdCard.get_current_line_number());
|
grbl_notifyf("SD print canceled", "Reset during SD file at line: %d", config->_sdCard->get_current_line_number());
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Reset during SD file at line: %d", sdCard.get_current_line_number());
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Reset during SD file at line: %d", config->_sdCard->get_current_line_number());
|
||||||
|
|
||||||
} else
|
} else
|
||||||
#endif //ENABLE_SD_CARD
|
#endif //ENABLE_SD_CARD
|
||||||
@@ -740,10 +741,10 @@ void report_realtime_status(uint8_t client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_SD_CARD
|
#ifdef ENABLE_SD_CARD
|
||||||
if (sdCard.get_state(false) == SDCard::State::BusyPrinting) {
|
if (config->_sdCard->get_state(false) == SDCard::State::BusyPrinting) {
|
||||||
sprintf(temp, "|SD:%4.2f,", sdCard.report_perc_complete());
|
sprintf(temp, "|SD:%4.2f,", config->_sdCard->report_perc_complete());
|
||||||
strcat(status, temp);
|
strcat(status, temp);
|
||||||
sdCard.get_current_filename(temp);
|
config->_sdCard->get_current_filename(temp);
|
||||||
strcat(status, temp);
|
strcat(status, temp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -19,14 +19,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#ifdef ENABLE_SD_CARD
|
|
||||||
#include "SDCard.h"
|
#include "SDCard.h"
|
||||||
#include "MachineConfig.h"
|
#include "MachineConfig.h"
|
||||||
|
|
||||||
SDCard sdCard;
|
#include <FS.h>
|
||||||
|
#include <SD.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
struct SDCard::FileWrap {
|
||||||
|
FileWrap() : _file(nullptr) {}
|
||||||
|
File _file;
|
||||||
|
};
|
||||||
|
|
||||||
SDCard::SDCard() :
|
SDCard::SDCard() :
|
||||||
_file(nullptr), _current_line_number(0), _state(State::Idle), _readyNext(false), _client(CLIENT_SERIAL),
|
_pImpl(new FileWrap()), _current_line_number(0), _state(State::Idle), _readyNext(false), _client(CLIENT_SERIAL),
|
||||||
_auth_level(WebUI::AuthenticationLevel::LEVEL_GUEST) {}
|
_auth_level(WebUI::AuthenticationLevel::LEVEL_GUEST) {}
|
||||||
|
|
||||||
// attempt to mount the SD card
|
// attempt to mount the SD card
|
||||||
@@ -64,8 +71,8 @@ void SDCard::listDir(fs::FS& fs, const char* dirname, uint8_t levels, uint8_t cl
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SDCard::openFile(fs::FS& fs, const char* path) {
|
bool SDCard::openFile(fs::FS& fs, const char* path) {
|
||||||
_file = fs.open(path);
|
_pImpl->_file = fs.open(path);
|
||||||
if (!_file) {
|
if (!_pImpl->_file) {
|
||||||
//report_status_message(Error::FsFailedRead, CLIENT_SERIAL);
|
//report_status_message(Error::FsFailedRead, CLIENT_SERIAL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -76,13 +83,13 @@ bool SDCard::openFile(fs::FS& fs, const char* path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SDCard::closeFile() {
|
bool SDCard::closeFile() {
|
||||||
if (!_file) {
|
if (!_pImpl->_file) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
set_state(State::Idle);
|
set_state(State::Idle);
|
||||||
_readyNext = false;
|
_readyNext = false;
|
||||||
_current_line_number = 0;
|
_current_line_number = 0;
|
||||||
_file.close();
|
_pImpl->_file.close();
|
||||||
SD.end();
|
SD.end();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -95,32 +102,33 @@ bool SDCard::closeFile() {
|
|||||||
return true if a line is
|
return true if a line is
|
||||||
*/
|
*/
|
||||||
bool SDCard::readFileLine(char* line, int maxlen) {
|
bool SDCard::readFileLine(char* line, int maxlen) {
|
||||||
if (!_file) {
|
if (!_pImpl->_file) {
|
||||||
report_status_message(Error::FsFailedRead, _client);
|
report_status_message(Error::FsFailedRead, _client);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_current_line_number += 1;
|
_current_line_number += 1;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while (_file.available()) {
|
while (_pImpl->_file.available()) {
|
||||||
if (len >= maxlen) {
|
if (len >= maxlen) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
char c = _file.read();
|
char c = _pImpl->_file.read();
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
line[len++] = c;
|
line[len++] = c;
|
||||||
}
|
}
|
||||||
line[len] = '\0';
|
line[len] = '\0';
|
||||||
return len || _file.available();
|
return len || _pImpl->_file.available();
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a percentage complete 50.5 = 50.5%
|
// return a percentage complete 50.5 = 50.5%
|
||||||
float SDCard::report_perc_complete() {
|
float SDCard::report_perc_complete() {
|
||||||
if (!_file) {
|
if (!_pImpl->_file) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
return (float)_file.position() / (float)_file.size() * 100.0f;
|
return (float)_pImpl->_file.position() / (float)_pImpl->_file.size() * 100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SDCard::get_current_line_number() {
|
uint32_t SDCard::get_current_line_number() {
|
||||||
@@ -176,10 +184,32 @@ SDCard::State SDCard::set_state(SDCard::State state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SDCard::get_current_filename(char* name) {
|
void SDCard::get_current_filename(char* name) {
|
||||||
if (_file) {
|
if (_pImpl->_file) {
|
||||||
strcpy(name, _file.name());
|
strcpy(name, _pImpl->_file.name());
|
||||||
} else {
|
} else {
|
||||||
name[0] = 0;
|
name[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif //ENABLE_SD_CARD
|
|
||||||
|
void SDCard::init() {
|
||||||
|
static bool init_message = true; // used to show messages only once.
|
||||||
|
|
||||||
|
if (init_message) {
|
||||||
|
if (_cardDetect.defined()) {
|
||||||
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "SD Card Detect on pin %s", _cardDetect.name().c_str());
|
||||||
|
}
|
||||||
|
init_message = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_cardDetect.setAttr(Pin::Attr::Output);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDCard::validate() const {}
|
||||||
|
|
||||||
|
void SDCard::handle(Configuration::HandlerBase& handler) {
|
||||||
|
handler.handle("card_detect", _cardDetect);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDCard::~SDCard() {
|
||||||
|
delete _pImpl;
|
||||||
|
}
|
||||||
|
@@ -15,12 +15,17 @@
|
|||||||
* D1 -
|
* D1 -
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Grbl.h"
|
#include <cstdint>
|
||||||
#include <FS.h>
|
#include "Configuration/Configurable.h"
|
||||||
#include <SD.h>
|
#include "WebUI/Authentication.h"
|
||||||
#include <SPI.h>
|
#include "Pin.h"
|
||||||
|
|
||||||
class SDCard {
|
// Forward declaration:
|
||||||
|
namespace fs {
|
||||||
|
class FS;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SDCard : public Configuration::Configurable {
|
||||||
public:
|
public:
|
||||||
enum class State : uint8_t {
|
enum class State : uint8_t {
|
||||||
Idle = 0,
|
Idle = 0,
|
||||||
@@ -31,12 +36,17 @@ public:
|
|||||||
BusyParsing = 4,
|
BusyParsing = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class FileWrap; // holds a single 'File'; we don't want to include <FS.h> here
|
||||||
|
|
||||||
private:
|
private:
|
||||||
File _file;
|
static const int COMMENT_SIZE = 256;
|
||||||
|
|
||||||
|
FileWrap* _pImpl; // this is actually a 'File'; we don't want to include <FS.h>
|
||||||
uint32_t _current_line_number; // the most recent line number read
|
uint32_t _current_line_number; // the most recent line number read
|
||||||
char comment[LINE_BUFFER_SIZE]; // Line to be executed. Zero-terminated.
|
char comment[COMMENT_SIZE]; // Line to be executed. Zero-terminated.
|
||||||
|
|
||||||
State _state;
|
State _state;
|
||||||
|
Pin _cardDetect;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool _readyNext;
|
bool _readyNext;
|
||||||
@@ -44,20 +54,29 @@ public:
|
|||||||
WebUI::AuthenticationLevel _auth_level;
|
WebUI::AuthenticationLevel _auth_level;
|
||||||
|
|
||||||
SDCard();
|
SDCard();
|
||||||
|
SDCard(const SDCard&) = delete;
|
||||||
|
SDCard& operator=(const SDCard&) = delete;
|
||||||
|
|
||||||
bool _ready_next; // Grbl has processed a line and is waiting for another
|
bool _ready_next; // Grbl has processed a line and is waiting for another
|
||||||
|
|
||||||
//bool mount();
|
//bool mount();
|
||||||
SDCard::State get_state(bool refresh);
|
SDCard::State get_state(bool refresh);
|
||||||
SDCard::State set_state(SDCard::State state);
|
SDCard::State set_state(SDCard::State state);
|
||||||
|
|
||||||
void listDir(fs::FS& fs, const char* dirname, uint8_t levels, uint8_t client);
|
void listDir(fs::FS& fs, const char* dirname, uint8_t levels, uint8_t client);
|
||||||
bool openFile(fs::FS& fs, const char* path);
|
bool openFile(fs::FS& fs, const char* path);
|
||||||
bool closeFile();
|
bool closeFile();
|
||||||
bool readFileLine(char* line, int len);
|
bool readFileLine(char* line, int len);
|
||||||
void readFile(fs::FS& fs, const char* path);
|
|
||||||
float report_perc_complete();
|
float report_perc_complete();
|
||||||
uint32_t get_current_line_number();
|
uint32_t get_current_line_number();
|
||||||
void get_current_filename(char* name);
|
void get_current_filename(char* name);
|
||||||
~SDCard() = default;
|
|
||||||
|
// Initializes pins.
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// Configuration handlers.
|
||||||
|
void validate() const override;
|
||||||
|
void handle(Configuration::HandlerBase& handler) override;
|
||||||
|
|
||||||
|
~SDCard();
|
||||||
};
|
};
|
||||||
extern SDCard sdCard;
|
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
#include "Grbl.h"
|
|
||||||
#include "SDCardPin.h"
|
|
||||||
|
|
||||||
void SDCardPin::init() {
|
|
||||||
static bool init_message = true; // used to show messages only once.
|
|
||||||
|
|
||||||
if (init_message) {
|
|
||||||
if (_cardDetect.defined()) {
|
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "SD Card Detect on pin %s", _cardDetect.name().c_str());
|
|
||||||
}
|
|
||||||
init_message = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_cardDetect.setAttr(Pin::Attr::Output);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDCardPin::validate() const {}
|
|
||||||
|
|
||||||
void SDCardPin::handle(Configuration::HandlerBase& handler) {
|
|
||||||
handler.handle("card_detect", _cardDetect);
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
// TODO: This should be merged with SDCard.h but for now doing so
|
|
||||||
// causes strange include conflicts.
|
|
||||||
|
|
||||||
class SDCardPin : public Configuration::Configurable {
|
|
||||||
public:
|
|
||||||
Pin _cardDetect;
|
|
||||||
|
|
||||||
SDCardPin() = default;
|
|
||||||
|
|
||||||
// Initializes pins.
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// Configuration handlers.
|
|
||||||
void validate() const override;
|
|
||||||
void handle(Configuration::HandlerBase& handler) override;
|
|
||||||
|
|
||||||
~SDCardPin() = default;
|
|
||||||
};
|
|
@@ -162,7 +162,7 @@ void clientCheckTask(void* pvParameters) {
|
|||||||
execute_realtime_command(static_cast<Cmd>(data), client);
|
execute_realtime_command(static_cast<Cmd>(data), client);
|
||||||
} else {
|
} else {
|
||||||
#if defined(ENABLE_SD_CARD)
|
#if defined(ENABLE_SD_CARD)
|
||||||
if (sdCard.get_state(false) < SDCard::State::Busy) {
|
if (config->_sdCard->get_state(false) < SDCard::State::Busy) {
|
||||||
#endif //ENABLE_SD_CARD
|
#endif //ENABLE_SD_CARD
|
||||||
vTaskEnterCritical(&myMutex);
|
vTaskEnterCritical(&myMutex);
|
||||||
client_buffer[client].write(data);
|
client_buffer[client].write(data);
|
||||||
|
@@ -279,16 +279,17 @@ namespace WebUI {
|
|||||||
|
|
||||||
# ifdef ENABLE_SD_CARD
|
# ifdef ENABLE_SD_CARD
|
||||||
if ((path.substring(0, 4) == "/SD/")) {
|
if ((path.substring(0, 4) == "/SD/")) {
|
||||||
|
auto sdCard = config->_sdCard;
|
||||||
//remove /SD
|
//remove /SD
|
||||||
path = path.substring(3);
|
path = path.substring(3);
|
||||||
if (SDCard::State::Idle != sdCard.get_state(true)) {
|
if (SDCard::State::Idle != sdCard->get_state(true)) {
|
||||||
String content = "cannot open: ";
|
String content = "cannot open: ";
|
||||||
content += path + ", SD is not available.";
|
content += path + ", SD is not available.";
|
||||||
|
|
||||||
_webserver->send(500, "text/plain", content);
|
_webserver->send(500, "text/plain", content);
|
||||||
}
|
}
|
||||||
if (SD.exists(pathWithGz) || SD.exists(path)) {
|
if (SD.exists(pathWithGz) || SD.exists(path)) {
|
||||||
sdCard.set_state(SDCard::State::BusyUploading);
|
sdCard->set_state(SDCard::State::BusyUploading);
|
||||||
if (SD.exists(pathWithGz)) {
|
if (SD.exists(pathWithGz)) {
|
||||||
path = pathWithGz;
|
path = pathWithGz;
|
||||||
}
|
}
|
||||||
@@ -319,10 +320,10 @@ namespace WebUI {
|
|||||||
if (i != totalFileSize) {
|
if (i != totalFileSize) {
|
||||||
//error: TBD
|
//error: TBD
|
||||||
}
|
}
|
||||||
sdCard.set_state(SDCard::State::Idle);
|
sdCard->set_state(SDCard::State::Idle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sdCard.set_state(SDCard::State::Idle);
|
sdCard->set_state(SDCard::State::Idle);
|
||||||
}
|
}
|
||||||
String content = "cannot find ";
|
String content = "cannot find ";
|
||||||
content += path;
|
content += path;
|
||||||
@@ -1232,7 +1233,7 @@ namespace WebUI {
|
|||||||
bool list_files = true;
|
bool list_files = true;
|
||||||
uint64_t totalspace = 0;
|
uint64_t totalspace = 0;
|
||||||
uint64_t usedspace = 0;
|
uint64_t usedspace = 0;
|
||||||
SDCard::State state = sdCard.get_state(true);
|
SDCard::State state = config->_sdCard->get_state(true);
|
||||||
if (state != SDCard::State::Idle) {
|
if (state != SDCard::State::Idle) {
|
||||||
String status = "{\"status\":\"";
|
String status = "{\"status\":\"";
|
||||||
status += state == SDCard::State::NotPresent ? "No SD Card\"}" : "Busy\"}";
|
status += state == SDCard::State::NotPresent ? "No SD Card\"}" : "Busy\"}";
|
||||||
@@ -1240,7 +1241,7 @@ namespace WebUI {
|
|||||||
_webserver->send(200, "application/json", status);
|
_webserver->send(200, "application/json", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sdCard.set_state(SDCard::State::BusyParsing);
|
config->_sdCard->set_state(SDCard::State::BusyParsing);
|
||||||
|
|
||||||
//get current path
|
//get current path
|
||||||
if (_webserver->hasArg("path")) {
|
if (_webserver->hasArg("path")) {
|
||||||
@@ -1333,7 +1334,7 @@ namespace WebUI {
|
|||||||
s += " does not exist on SD Card\"}";
|
s += " does not exist on SD Card\"}";
|
||||||
_webserver->send(200, "application/json", s);
|
_webserver->send(200, "application/json", s);
|
||||||
SD.end();
|
SD.end();
|
||||||
sdCard.set_state(SDCard::State::Idle);
|
config->_sdCard->set_state(SDCard::State::Idle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (list_files) {
|
if (list_files) {
|
||||||
@@ -1410,7 +1411,7 @@ namespace WebUI {
|
|||||||
jsonfile += "}";
|
jsonfile += "}";
|
||||||
_webserver->sendHeader("Cache-Control", "no-cache");
|
_webserver->sendHeader("Cache-Control", "no-cache");
|
||||||
_webserver->send(200, "application/json", jsonfile);
|
_webserver->send(200, "application/json", jsonfile);
|
||||||
sdCard.set_state(SDCard::State::Idle);
|
config->_sdCard->set_state(SDCard::State::Idle);
|
||||||
SD.end();
|
SD.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1437,13 +1438,13 @@ namespace WebUI {
|
|||||||
filename = "/" + upload.filename;
|
filename = "/" + upload.filename;
|
||||||
}
|
}
|
||||||
//check if SD Card is available
|
//check if SD Card is available
|
||||||
if (sdCard.get_state(true) != SDCard::State::Idle) {
|
if (config->_sdCard->get_state(true) != SDCard::State::Idle) {
|
||||||
_upload_status = UploadStatusType::FAILED;
|
_upload_status = UploadStatusType::FAILED;
|
||||||
grbl_send(CLIENT_ALL, "[MSG:Upload cancelled]\r\n");
|
grbl_send(CLIENT_ALL, "[MSG:Upload cancelled]\r\n");
|
||||||
pushError(ESP_ERROR_UPLOAD_CANCELLED, "Upload cancelled");
|
pushError(ESP_ERROR_UPLOAD_CANCELLED, "Upload cancelled");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sdCard.set_state(SDCard::State::BusyUploading);
|
config->_sdCard->set_state(SDCard::State::BusyUploading);
|
||||||
//delete file on SD Card if already present
|
//delete file on SD Card if already present
|
||||||
if (SD.exists(filename)) {
|
if (SD.exists(filename)) {
|
||||||
SD.remove(filename);
|
SD.remove(filename);
|
||||||
@@ -1477,9 +1478,10 @@ namespace WebUI {
|
|||||||
//Upload write
|
//Upload write
|
||||||
//**************
|
//**************
|
||||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||||
|
auto sdCard = config->_sdCard;
|
||||||
vTaskDelay(1 / portTICK_RATE_MS);
|
vTaskDelay(1 / portTICK_RATE_MS);
|
||||||
if (sdUploadFile && (_upload_status == UploadStatusType::ONGOING) &&
|
if (sdUploadFile && (_upload_status == UploadStatusType::ONGOING) &&
|
||||||
(sdCard.get_state(false) == SDCard::State::BusyUploading)) {
|
(sdCard->get_state(false) == SDCard::State::BusyUploading)) {
|
||||||
//no error write post data
|
//no error write post data
|
||||||
if (upload.currentSize != sdUploadFile.write(upload.buf, upload.currentSize)) {
|
if (upload.currentSize != sdUploadFile.write(upload.buf, upload.currentSize)) {
|
||||||
_upload_status = UploadStatusType::FAILED;
|
_upload_status = UploadStatusType::FAILED;
|
||||||
@@ -1517,7 +1519,7 @@ namespace WebUI {
|
|||||||
}
|
}
|
||||||
if (_upload_status == UploadStatusType::ONGOING) {
|
if (_upload_status == UploadStatusType::ONGOING) {
|
||||||
_upload_status = UploadStatusType::SUCCESSFUL;
|
_upload_status = UploadStatusType::SUCCESSFUL;
|
||||||
sdCard.set_state(SDCard::State::Idle);
|
config->_sdCard->set_state(SDCard::State::Idle);
|
||||||
} else {
|
} else {
|
||||||
_upload_status = UploadStatusType::FAILED;
|
_upload_status = UploadStatusType::FAILED;
|
||||||
pushError(ESP_ERROR_UPLOAD, "Upload error");
|
pushError(ESP_ERROR_UPLOAD, "Upload error");
|
||||||
@@ -1525,7 +1527,7 @@ namespace WebUI {
|
|||||||
|
|
||||||
} else { //Upload cancelled
|
} else { //Upload cancelled
|
||||||
_upload_status = UploadStatusType::FAILED;
|
_upload_status = UploadStatusType::FAILED;
|
||||||
sdCard.set_state(SDCard::State::Idle);
|
config->_sdCard->set_state(SDCard::State::Idle);
|
||||||
grbl_send(CLIENT_ALL, "[MSG:Upload failed]\r\n");
|
grbl_send(CLIENT_ALL, "[MSG:Upload failed]\r\n");
|
||||||
if (sdUploadFile) {
|
if (sdUploadFile) {
|
||||||
sdUploadFile.close();
|
sdUploadFile.close();
|
||||||
@@ -1543,7 +1545,7 @@ namespace WebUI {
|
|||||||
if (SD.exists(filename)) {
|
if (SD.exists(filename)) {
|
||||||
SD.remove(filename);
|
SD.remove(filename);
|
||||||
}
|
}
|
||||||
sdCard.set_state(SDCard::State::Idle);
|
config->_sdCard->set_state(SDCard::State::Idle);
|
||||||
}
|
}
|
||||||
COMMANDS::wait(0);
|
COMMANDS::wait(0);
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
#include <esp_wifi.h>
|
#include <esp_wifi.h>
|
||||||
#include <esp_ota_ops.h>
|
#include <esp_ota_ops.h>
|
||||||
|
#include <SD.h>
|
||||||
|
|
||||||
#include "ESPResponse.h"
|
#include "ESPResponse.h"
|
||||||
#include "WebServer.h"
|
#include "WebServer.h"
|
||||||
@@ -678,7 +679,7 @@ namespace WebUI {
|
|||||||
if (path[0] != '/') {
|
if (path[0] != '/') {
|
||||||
path = "/" + path;
|
path = "/" + path;
|
||||||
}
|
}
|
||||||
SDCard::State state = sdCard.get_state(true);
|
SDCard::State state = config->_sdCard->get_state(true);
|
||||||
if (state != SDCard::State::Idle) {
|
if (state != SDCard::State::Idle) {
|
||||||
if (state == SDCard::State::NotPresent) {
|
if (state == SDCard::State::NotPresent) {
|
||||||
webPrintln("No SD Card");
|
webPrintln("No SD Card");
|
||||||
@@ -688,7 +689,7 @@ namespace WebUI {
|
|||||||
return Error::FsFailedBusy;
|
return Error::FsFailedBusy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sdCard.openFile(SD, path.c_str())) {
|
if (!config->_sdCard->openFile(SD, path.c_str())) {
|
||||||
report_status_message(Error::FsFailedRead, (espresponse) ? espresponse->client() : CLIENT_ALL);
|
report_status_message(Error::FsFailedRead, (espresponse) ? espresponse->client() : CLIENT_ALL);
|
||||||
webPrintln("");
|
webPrintln("");
|
||||||
return Error::FsFailedOpenFile;
|
return Error::FsFailedOpenFile;
|
||||||
@@ -703,13 +704,13 @@ namespace WebUI {
|
|||||||
if ((err = openSDFile(parameter)) != Error::Ok) {
|
if ((err = openSDFile(parameter)) != Error::Ok) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
sdCard._client = (espresponse) ? espresponse->client() : CLIENT_ALL;
|
config->_sdCard->_client = (espresponse) ? espresponse->client() : CLIENT_ALL;
|
||||||
char fileLine[255];
|
char fileLine[255];
|
||||||
while (sdCard.readFileLine(fileLine, 255)) {
|
while (config->_sdCard->readFileLine(fileLine, 255)) {
|
||||||
webPrintln(fileLine);
|
webPrintln(fileLine);
|
||||||
}
|
}
|
||||||
webPrintln("");
|
webPrintln("");
|
||||||
sdCard.closeFile();
|
config->_sdCard->closeFile();
|
||||||
return Error::Ok;
|
return Error::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,18 +727,20 @@ namespace WebUI {
|
|||||||
if ((err = openSDFile(parameter)) != Error::Ok) {
|
if ((err = openSDFile(parameter)) != Error::Ok) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
auto sdCard = config->_sdCard;
|
||||||
|
|
||||||
char fileLine[255];
|
char fileLine[255];
|
||||||
if (!sdCard.readFileLine(fileLine, 255)) {
|
if (!sdCard->readFileLine(fileLine, 255)) {
|
||||||
//No need notification here it is just a macro
|
//No need notification here it is just a macro
|
||||||
sdCard.closeFile();
|
sdCard->closeFile();
|
||||||
webPrintln("");
|
webPrintln("");
|
||||||
return Error::Ok;
|
return Error::Ok;
|
||||||
}
|
}
|
||||||
sdCard._client = (espresponse) ? espresponse->client() : CLIENT_ALL;
|
sdCard->_client = (espresponse) ? espresponse->client() : CLIENT_ALL;
|
||||||
sdCard._auth_level = auth_level;
|
sdCard->_auth_level = auth_level;
|
||||||
// execute the first line now; Protocol.cpp handles later ones when sdCard._ready_next
|
// execute the first line now; Protocol.cpp handles later ones when sdCard._ready_next
|
||||||
report_status_message(execute_line(fileLine, sdCard._client, sdCard._auth_level), sdCard._client);
|
report_status_message(execute_line(fileLine, sdCard->_client, sdCard->_auth_level), sdCard->_client);
|
||||||
report_realtime_status(sdCard._client);
|
report_realtime_status(sdCard->_client);
|
||||||
webPrintln("");
|
webPrintln("");
|
||||||
return Error::Ok;
|
return Error::Ok;
|
||||||
}
|
}
|
||||||
@@ -748,7 +751,7 @@ namespace WebUI {
|
|||||||
webPrintln("Missing file name!");
|
webPrintln("Missing file name!");
|
||||||
return Error::InvalidValue;
|
return Error::InvalidValue;
|
||||||
}
|
}
|
||||||
SDCard::State state = sdCard.get_state(true);
|
SDCard::State state = config->_sdCard->get_state(true);
|
||||||
if (state != SDCard::State::Idle) {
|
if (state != SDCard::State::Idle) {
|
||||||
webPrintln((state == SDCard::State::NotPresent) ? "No SD card" : "Busy");
|
webPrintln((state == SDCard::State::NotPresent) ? "No SD card" : "Busy");
|
||||||
return Error::Ok;
|
return Error::Ok;
|
||||||
@@ -780,7 +783,7 @@ namespace WebUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Error listSDFiles(char* parameter, AuthenticationLevel auth_level) { // ESP210
|
static Error listSDFiles(char* parameter, AuthenticationLevel auth_level) { // ESP210
|
||||||
SDCard::State state = sdCard.get_state(true);
|
SDCard::State state = config->_sdCard->get_state(true);
|
||||||
if (state != SDCard::State::Idle) {
|
if (state != SDCard::State::Idle) {
|
||||||
if (state == SDCard::State::NotPresent) {
|
if (state == SDCard::State::NotPresent) {
|
||||||
webPrintln("No SD Card");
|
webPrintln("No SD Card");
|
||||||
@@ -791,7 +794,7 @@ namespace WebUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
webPrintln("");
|
webPrintln("");
|
||||||
sdCard.listDir(SD, "/", 10, espresponse->client());
|
config->_sdCard->listDir(SD, "/", 10, espresponse->client());
|
||||||
String ssd = "[SD Free:" + ESPResponseStream::formatBytes(SD.totalBytes() - SD.usedBytes());
|
String ssd = "[SD Free:" + ESPResponseStream::formatBytes(SD.totalBytes() - SD.usedBytes());
|
||||||
ssd += " Used:" + ESPResponseStream::formatBytes(SD.usedBytes());
|
ssd += " Used:" + ESPResponseStream::formatBytes(SD.usedBytes());
|
||||||
ssd += " Total:" + ESPResponseStream::formatBytes(SD.totalBytes());
|
ssd += " Total:" + ESPResponseStream::formatBytes(SD.totalBytes());
|
||||||
@@ -878,7 +881,7 @@ namespace WebUI {
|
|||||||
static Error showSDStatus(char* parameter, AuthenticationLevel auth_level) { // ESP200
|
static Error showSDStatus(char* parameter, AuthenticationLevel auth_level) { // ESP200
|
||||||
const char* resp = "No SD card";
|
const char* resp = "No SD card";
|
||||||
#ifdef ENABLE_SD_CARD
|
#ifdef ENABLE_SD_CARD
|
||||||
switch (sdCard.get_state(true)) {
|
switch (config->_sdCard->get_state(true)) {
|
||||||
case SDCard::State::Idle:
|
case SDCard::State::Idle:
|
||||||
resp = "SD card detected";
|
resp = "SD card detected";
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user