Skip to content

Commit

Permalink
Merge pull request #73 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored Oct 23, 2021
2 parents 29314f2 + be2207d commit c09b1a4
Show file tree
Hide file tree
Showing 16 changed files with 307 additions and 100 deletions.
Binary file modified FluidNC/data/index.html.gz
Binary file not shown.
22 changes: 12 additions & 10 deletions FluidNC/src/Configuration/JsonGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ namespace Configuration {

void JsonGenerator::item(const char* name, bool& value) {
enter(name);
const char* val = value ? "Yes" : "No";
const char* val = value ? "1" : "0";
_encoder.begin_webui(_currentPath, _currentPath, "B", val);
_encoder.begin_array("O");
{
_encoder.begin_object();
_encoder.member("No", 0);
_encoder.member("Yes", 1);
_encoder.member("False", 0);
_encoder.member("True", 1);
_encoder.end_object();
}
_encoder.end_array();
Expand Down Expand Up @@ -114,19 +114,21 @@ namespace Configuration {

void JsonGenerator::item(const char* name, int& value, EnumItem* e) {
enter(name);
const char* str = "unknown";
for (; e->name; ++e) {
if (value == e->value) {
str = e->name;
int selected_val = 0;
//const char* str = "unknown";
for (auto e2 = e; e2->name; ++e2) {
if (value == e2->value) {
//str = e2->name;
selected_val = e2->value;
break;
}
}

_encoder.begin_webui(_currentPath, _currentPath, "B", str);
_encoder.begin_webui(_currentPath, _currentPath, "B", selected_val);
_encoder.begin_array("O");
for (; e->name; ++e) {
for (auto e2 = e; e2->name; ++e2) {
_encoder.begin_object();
_encoder.member(e->name, e->value);
_encoder.member(e2->name, e2->value);
_encoder.end_object();
}
_encoder.end_array();
Expand Down
49 changes: 31 additions & 18 deletions FluidNC/src/Configuration/RuntimeSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace Configuration {
RuntimeSetting::RuntimeSetting(const char* key, const char* value, Print& out) : newValue_(value), out_(out) {
// Remove leading '/' if it is present
setting_ = (*key == '/') ? key + 1 : key;
start_ = setting_;
// Also remove trailing '/' if it is present

start_ = setting_;
// Read fence for config. Shouldn't be necessary, but better safe than sorry.
std::atomic_thread_fence(std::memory_order::memory_order_seq_cst);
}
Expand All @@ -26,19 +28,17 @@ namespace Configuration {
for (; *next && *next != '/'; ++next) {}

// Do we have a child?
if (*next == '/') {
if (*next == '/' && next[1] != '\0') {
++next;
start_ = next;

// Handle child:
value->group(*this);
} else {
if (newValue_ == nullptr) {
allClients << dataBeginMarker;
allClients << setting_ << ":\n";
allClients << "/" << setting_ << ":\n";
Configuration::Generator generator(allClients, 1);
value->group(generator);
allClients << dataEndMarker;
isHandled_ = true;
} else {
log_error("Can't set a value on a section");
Expand All @@ -54,9 +54,10 @@ namespace Configuration {
if (is(name)) {
isHandled_ = true;
if (newValue_ == nullptr) {
out_ << "$" << setting_ << "=" << (value ? "true" : "false") << '\n';
out_ << "$/" << setting_ << "=" << (value ? "true" : "false") << '\n';
} else {
value = (!strcasecmp(newValue_, "true"));
value = (!strcasecmp(newValue_, "true") || !strcasecmp(newValue_, "yes") || !strcasecmp(newValue_, "1"));
log_info("Bool value:" << value);
}
}
}
Expand All @@ -65,7 +66,7 @@ namespace Configuration {
if (is(name)) {
isHandled_ = true;
if (newValue_ == nullptr) {
out_ << "$" << setting_ << "=" << value << '\n';
out_ << "$/" << setting_ << "=" << value << '\n';
} else {
value = atoi(newValue_);
}
Expand All @@ -76,7 +77,7 @@ namespace Configuration {
if (is(name)) {
isHandled_ = true;
if (newValue_ == nullptr) {
out_ << "$" << setting_ << "=" << value << '\n';
out_ << "$/" << setting_ << "=" << value << '\n';
} else {
char* floatEnd;
value = strtof(newValue_, &floatEnd);
Expand All @@ -88,7 +89,7 @@ namespace Configuration {
if (is(name)) {
isHandled_ = true;
if (newValue_ == nullptr) {
out_ << "$" << setting_ << "=" << value << '\n';
out_ << "$/" << setting_ << "=" << value << '\n';
} else {
value = String(newValue_);
}
Expand All @@ -99,16 +100,28 @@ namespace Configuration {
if (is(name)) {
isHandled_ = true;
if (newValue_ == nullptr) {
for (; e->name; ++e) {
if (e->value == value) {
out_ << "$" << setting_ << "=" << e->name << '\n';
for (auto e2 = e; e2->name; ++e2) {
if (e2->value == value) {
out_ << "$/" << setting_ << "=" << e2->name << '\n';
return;
}
}

} else {
for (; e->name; ++e) {
if (!strcasecmp(newValue_, e->name)) {
value = e->value;
if (isdigit(newValue_[0])) { // if the first char is a number. assume it is an index of a webui enum list
int indexVal = 0;
indexVal = atoi(newValue_);
for (auto e2 = e; e2->name; ++e2) {
if (e2->value == indexVal) {
value = e2->value;
newValue_ = e2->name;
return;
}
}
}
for (auto e2 = e; e2->name; ++e2) {
if (!strcasecmp(newValue_, e2->name)) {
value = e2->value;
return;
}
}
Expand Down Expand Up @@ -169,7 +182,7 @@ namespace Configuration {
if (is(name)) {
isHandled_ = true;
if (newValue_ == nullptr) {
out_ << "$" << setting_ << "=" << value.toString() << '\n';
out_ << "$/" << setting_ << "=" << value.toString() << '\n';
} else {
IPAddress ip;
if (!ip.fromString(newValue_)) {
Expand All @@ -184,7 +197,7 @@ namespace Configuration {
if (is(name)) {
isHandled_ = true;
if (newValue_ == nullptr) {
out_ << "$" << setting_ << "=" << value.name() << '\n';
out_ << "$/" << setting_ << "=" << value.name() << '\n';
} else {
out_ << "Runtime setting of Pin objects is not supported\n";
// auto parsed = Pin::create(newValue);
Expand Down
18 changes: 8 additions & 10 deletions FluidNC/src/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,31 @@ size_t FileStream::write(const uint8_t* buffer, size_t length) {
}

FileStream::FileStream(const char* filename, const char* mode, const char* defaultFs) {
String path;

if (!filename || !*filename) {
throw Error::FsFailedCreateFile;
}

// Insert the default file system prefix if a file system name is not present
if (*filename != '/') {
path = "/";
path += defaultFs;
path += "/";
_path = "/";
_path += defaultFs;
_path += "/";
}

path += filename;
_path += filename;

// Map /localfs/ to the actual name of the local file system
if (path.startsWith("/localfs/")) {
path.replace("/localfs/", "/spiffs/");
if (_path.startsWith("/localfs/")) {
_path.replace("/localfs/", "/spiffs/");
}
if (path.startsWith("/sd/")) {
if (_path.startsWith("/sd/")) {
if (config->_sdCard->begin(SDCard::State::BusyWriting) != SDCard::State::Idle) {
throw Error::FsFailedMount;
}
_isSD = true;
}

_fd = fopen(path.c_str(), mode);
_fd = fopen(_path.c_str(), mode);
if (!_fd) {
throw strcmp(mode, "w") ? Error::FsFailedOpenFile : Error::FsFailedCreateFile;
}
Expand Down
10 changes: 8 additions & 2 deletions FluidNC/src/FileStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ extern "C" {
}

class FileStream : public Stream {
bool _isSD;
FILE* _fd;
bool _isSD;
FILE* _fd;
String _path;

public:
FileStream(const char* filename, const char* mode, const char* defaultFs = "localfs");

String path() {
String retval = _path;
retval.replace("/spiffs/", "/localfs/");
return retval;
}
int available() override;
int read() override;
int peek() override;
Expand Down
8 changes: 4 additions & 4 deletions FluidNC/src/Motors/TrinamicBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ namespace MotorDrivers {

bool TrinamicBase::report_open_load(bool ola, bool olb) {
if (ola || olb) {
log_info(" Driver Open Load a:" << yn(ola) << " b:" << yn(olb));
log_warn(" Driver Open Load a:" << yn(ola) << " b:" << yn(olb));
return true;
}
return false; // no error
}

bool TrinamicBase::report_short_to_ground(bool s2ga, bool s2gb) {
if (s2ga || s2gb) {
log_info(" Driver Short Coil a:" << yn(s2ga) << " b:" << yn(s2gb));
log_warn(" Driver Short Coil a:" << yn(s2ga) << " b:" << yn(s2gb));
}
return false; // no error
}

bool TrinamicBase::report_over_temp(bool ot, bool otpw) {
if (ot || otpw) {
log_info(" Driver Temp Warning:" << yn(otpw) << " Fault:" << yn(ot));
log_warn(" Driver Temp Warning:" << yn(otpw) << " Fault:" << yn(ot));
return true;
}
return false; // no error
Expand All @@ -83,7 +83,7 @@ namespace MotorDrivers {
bool TrinamicBase::report_short_to_ps(bool vsa, bool vsb) {
// check for short to power supply
if (vsa || vsb) {
log_info(" Driver Short vsa:" << yn(vsa) << " vsb:" << yn(vsb));
log_warn(" Driver Short vsa:" << yn(vsa) << " vsb:" << yn(vsb));
return true;
}
return false; // no error
Expand Down
6 changes: 3 additions & 3 deletions FluidNC/src/Motors/TrinamicSpiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace MotorDrivers {
} else if (_driver_part_number == 5160) {
tmc5160 = new TMC5160Stepper(cs_id, _r_sense, _spi_index);
} else {
log_info(" Unsupported Trinamic part number TMC" << _driver_part_number);
log_error(" Unsupported Trinamic part number TMC" << _driver_part_number);
_has_errors = true; // This motor cannot be used
return;
}
Expand Down Expand Up @@ -109,10 +109,10 @@ namespace MotorDrivers {
uint8_t result = tmc2130 ? tmc2130->test_connection() : tmc5160->test_connection();
switch (result) {
case 1:
log_info(axisName() << " driver test failed. Check connection");
log_error(axisName() << " driver test failed. Check connection");
return false;
case 2:
log_info(axisName() << " driver test failed. Check motor power");
log_error(axisName() << " driver test failed. Check motor power");
return false;
default:
// driver responded, so check for other errors from the DRV_STATUS register
Expand Down
8 changes: 4 additions & 4 deletions FluidNC/src/Motors/TrinamicUartDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace MotorDrivers {
tmc2209 = new TMC2209Stepper(_uart, _r_sense, _addr);
return false;
}
log_info("Unsupported Trinamic motor p/n:" << _driver_part_number);
log_error("Unsupported Trinamic motor p/n:" << _driver_part_number);
return true;
}

Expand All @@ -103,10 +103,10 @@ namespace MotorDrivers {
uint8_t result = tmc2208 ? tmc2208->test_connection() : tmc2209->test_connection();
switch (result) {
case 1:
log_info(" " << axisName() << " Trinamic driver test failed. Check connection");
log_error(" " << axisName() << " Trinamic driver test failed. Check connection");
return false;
case 2:
log_info(" " << axisName() << " Trinamic driver test failed. Check motor power");
log_error(" " << axisName() << " Trinamic driver test failed. Check motor power");
return false;
default:
// driver responded, so check for other errors from the DRV_STATUS register
Expand Down Expand Up @@ -191,7 +191,7 @@ namespace MotorDrivers {
tmc2208->pwm_autoscale(true);
break;
default:
log_info("Unsupported TMC2208 mode:" << _mode);
log_error("Unsupported TMC2208 mode:" << _mode);
}
} else {
switch (_mode) {
Expand Down
7 changes: 3 additions & 4 deletions FluidNC/src/ProcessSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,21 +467,20 @@ static Error xmodem_receive(const char* value, WebUI::AuthenticationLevel auth_l
if (!value || !*value) {
value = "uploaded";
}
Print* outfile;
FileStream* outfile;
try {
outfile = new FileStream(value, "w");
} catch (...) {
log_info("Cannot open " << value);
return Error::UploadFailed;
}
log_info("Receiving " << value << " via XModem");
int size = xmodemReceive(&Uart0, outfile);
delete outfile;
if (size >= 0) {
log_info("Received " << size << " bytes");
log_info("Received " << size << " bytes to file " << outfile->path());
} else {
log_info("Reception failed or was canceled");
}
delete outfile;
return size < 0 ? Error::UploadFailed : Error::Ok;
}

Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/SettingsDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ void make_settings() {
config_filename = new StringSetting("Name of Configuration File", EXTENDED, WG, NULL, "Config/Filename", "config.yaml", 1, 50, NULL);

// GRBL Numbered Settings
status_mask = new IntSetting(NULL, GRBL, WG, "10", "Report/Status", 1, 0, 3, NULL);
status_mask = new IntSetting("What to include in status report", GRBL, WG, "10", "Report/Status", 1, 0, 3, NULL);
}
Loading

0 comments on commit c09b1a4

Please sign in to comment.