Skip to content

Commit

Permalink
Check for config
Browse files Browse the repository at this point in the history
  • Loading branch information
bdring committed Feb 20, 2024
1 parent 09fd572 commit fd74676
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
11 changes: 10 additions & 1 deletion FluidNC/src/SDCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ void SDCard::init() {
init_message = false;
}
_cs.setAttr(Pin::Attr::Output);
csPin = _cs.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
csPin = _cs.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
config_ok = true;
} else if ((csFallback = sd_fallback_cs->get()) != -1) {
csPin = static_cast<pinnum_t>(csFallback);
log_info("Using fallback CS pin " << int(csPin));
config_ok = true;
} else {
log_debug("See http://wiki.fluidnc.com/en/config/sd_card#sdfallbackcs-access-sd-without-a-config-file");
return;
Expand All @@ -51,4 +53,11 @@ void SDCard::afterParse() {
// }
}

bool SDCard::is_configured(Channel& out) {
if (!config_ok) {
log_warn_to(out, "SD card not configured");
}
return config_ok;
}

SDCard::~SDCard() {}
4 changes: 3 additions & 1 deletion FluidNC/src/SDCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ class SDCard : public Configuration::Configurable {

public:
SDCard();
SDCard(const SDCard&) = delete;
SDCard(const SDCard&) = delete;
SDCard& operator=(const SDCard&) = delete;

void afterParse() override;
bool is_configured(Channel& out);

const char* filename();
bool config_ok = false;

// Initializes pins.
void init();
Expand Down
30 changes: 30 additions & 0 deletions FluidNC/src/WebUI/WebSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ namespace WebUI {
}

static Error showFile(const char* fs, char* parameter, AuthenticationLevel auth_level, Channel& out) { // ESP221

if (fs == sdName && !config->_sdCard->is_configured(out)) {
return Error::InvalidStatement;
}

if (notIdleOrAlarm()) {
return Error::IdleError;
}
Expand Down Expand Up @@ -400,6 +405,11 @@ namespace WebUI {

static Error runFile(const char* fs, char* parameter, AuthenticationLevel auth_level, Channel& out) {
Error err;

if (fs == sdName && !config->_sdCard->is_configured(out)) {
return Error::InvalidStatement;
}

if (sys.state == State::Alarm || sys.state == State::ConfigAlarm) {
log_string(out, "Alarm");
return Error::IdleError;
Expand Down Expand Up @@ -430,6 +440,10 @@ namespace WebUI {
static Error deleteObject(const char* fs, char* name, Channel& out) {
std::error_code ec;

if (fs == sdName && !config->_sdCard->is_configured(out)) {
return Error::InvalidStatement;
}

if (!name || !*name || (strcmp(name, "/") == 0)) {
// Disallow deleting everything
log_error_to(out, "Will not delete everything");
Expand Down Expand Up @@ -474,6 +488,10 @@ namespace WebUI {
static Error listFilesystem(const char* fs, const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) {
std::error_code ec;

if (fs == sdName && !config->_sdCard->is_configured(out)) {
return Error::InvalidStatement;
}

FluidPath fpath { value, fs, ec };
if (ec) {
log_string(out, "No SD card");
Expand Down Expand Up @@ -520,6 +538,10 @@ namespace WebUI {
static Error listFilesystemJSON(const char* fs, const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) {
std::error_code ec;

if (fs == sdName && !config->_sdCard->is_configured(out)) {
return Error::InvalidStatement;
}

FluidPath fpath { value, fs, ec };
if (ec) {
log_string(out, "No SD card");
Expand Down Expand Up @@ -633,6 +655,10 @@ namespace WebUI {
}

static Error renameObject(const char* fs, char* parameter, AuthenticationLevel auth_level, Channel& out) {
if (fs == sdName && !config->_sdCard->is_configured(out)) {
return Error::InvalidStatement;
}

if (!parameter || *parameter == '\0') {
return Error::InvalidValue;
}
Expand Down Expand Up @@ -765,6 +791,10 @@ namespace WebUI {
static Error showSDStatus(char* parameter, AuthenticationLevel auth_level, Channel& out) { // ESP200
std::error_code ec;

if (!config->_sdCard->is_configured(out)) {
return Error::InvalidStatement;
}

FluidPath path { "", "/sd", ec };
if (ec) {
log_string(out, "No SD card");
Expand Down

0 comments on commit fd74676

Please sign in to comment.