Skip to content

Commit

Permalink
Merge pull request #23 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored Sep 24, 2021
2 parents 33bacf5 + c4be515 commit 254ee24
Show file tree
Hide file tree
Showing 40 changed files with 482 additions and 380 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ FluidNC.vcxproj.filters
packages/
pio_machine.h
project.checksum
version.cpp
17 changes: 8 additions & 9 deletions FluidNC/src/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ void Control::group(Configuration::HandlerBase& handler) {
handler.item("macro3", _macro3._pin);
}

void Control::report(char* status) {
_safetyDoor.report(status);
_reset.report(status);
_feedHold.report(status);
_cycleStart.report(status);
_macro0.report(status);
_macro1.report(status);
_macro2.report(status);
_macro3.report(status);
String Control::report() {
return _safetyDoor.report() + _safetyDoor.report() + _reset.report() + _feedHold.report() + _cycleStart.report() + _macro0.report() +
_macro1.report() + _macro2.report() + _macro3.report();
}

bool Control::stuck() {
return _safetyDoor.get() || _reset.get() || _feedHold.get() || _cycleStart.get() || _macro0.get() || _macro1.get() || _macro2.get() ||
_macro3.get();
}

// Returns if safety door is ajar(T) or closed(F), based on pin state.
Expand Down
5 changes: 3 additions & 2 deletions FluidNC/src/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class Control : public Configuration::Configurable {
// Configuration handlers.
void group(Configuration::HandlerBase& handler) override;

bool system_check_safety_door_ajar();
void report(char* status);
bool stuck();
bool system_check_safety_door_ajar();
String report();

~Control() = default;
};
17 changes: 12 additions & 5 deletions FluidNC/src/ControlPin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
void IRAM_ATTR ControlPin::handleISR() {
bool pinState = _pin.read();
_value = pinState;
_rtVariable = pinState;
if (pinState) {
_rtVariable = pinState;
}
}

void ControlPin::init() {
Expand All @@ -22,12 +24,17 @@ void ControlPin::init() {
}
_pin.setAttr(attr);
_pin.attachInterrupt<ControlPin, &ControlPin::handleISR>(this, CHANGE);
_rtVariable = false;
_value = _pin.read();
// Control pins must start in inactive state
if (_value) {
log_error(_legend << " pin is active at startup");
rtAlarm = ExecAlarm::ControlPin;
}
}

void ControlPin::report(char* status) {
if (get()) {
addPinReport(status, _letter);
}
String ControlPin::report() {
return get() ? String(_letter) : String("");
}

ControlPin::~ControlPin() {
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/ControlPin.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ControlPin {
void init();
bool get() { return _value; }

void report(char* status);
String report();

~ControlPin();
};
1 change: 1 addition & 0 deletions FluidNC/src/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ std::map<Error, const char*> ErrorNames = {
{ Error::GcodeG43DynamicAxisError, "Gcode G43 dynamic axis error" },
{ Error::GcodeMaxValueExceeded, "Gcode max value exceeded" },
{ Error::PParamMaxExceeded, "P param max exceeded" },
{ Error::CheckControlPins, "Check control pins" },
{ Error::FsFailedMount, "Failed to mount device" },
{ Error::FsFailedRead, "Read failed" },
{ Error::FsFailedOpenDir, "Failed to open directory" },
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum class Error : uint8_t {
GcodeG43DynamicAxisError = 37,
GcodeMaxValueExceeded = 38,
PParamMaxExceeded = 39,
CheckControlPins = 40,
FsFailedMount = 60, // SD Failed to mount
FsFailedRead = 61, // SD Failed to read file
FsFailedOpenDir = 62, // SD card failed to open directory
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Machine/Axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace Machine {

// returns the offset between the pulloffs
// value is positive when motor1 has a larger pulloff
float Axis::pulloffOffset() { return _motors[1]->_pulloff - _motors[0]->_pulloff; }
float Axis::pulloffOffset() { return hasDualMotor()? _motors[1]->_pulloff - _motors[0]->_pulloff : 0.0f; }

Axis::~Axis() {
for (size_t i = 0; i < MAX_MOTORS_PER_AXIS; i++) {
Expand Down
76 changes: 0 additions & 76 deletions FluidNC/src/Machine/Communications.h

This file was deleted.

12 changes: 7 additions & 5 deletions FluidNC/src/Machine/Homing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,13 @@ namespace Machine {
for (int axis = 0; axis < n_axis; axis++) {
if (bitnum_is_true(motors, axis)) {
auto axisConfig = config->_axes->_axis[axis];
pulloffOffset = axisConfig->pulloffOffset();
if (pulloffOffset != 0) {
//log_info("Pulloff offset needed on axis " << axis << " of " << pulloffOffset);
// TODO Do it
run(motors & MOTOR1, false, false, pulloffOffset);
if(axisConfig->hasDualMotor()){
pulloffOffset = axisConfig->pulloffOffset();
if (pulloffOffset != 0) {
//log_info("Pulloff offset needed on axis " << axis << " of " << pulloffOffset);
// TODO Do it
run(motors & MOTOR1, false, false, pulloffOffset);
}
}
}
}
Expand Down
19 changes: 0 additions & 19 deletions FluidNC/src/Machine/MachineConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namespace Machine {
handler.section("control", _control);
handler.section("coolant", _coolant);
handler.section("probe", _probe);
handler.section("comms", _comms);
handler.section("macros", _macros);

handler.section("user_outputs", _userOutputs);
Expand Down Expand Up @@ -118,23 +117,6 @@ namespace Machine {
}
}

if (_comms == nullptr) {
log_info("Comms: using defaults");
_comms = new Communications();
#ifdef ENABLE_WIFI
_comms->_apConfig = new WifiAPConfig();
#endif
}

#ifdef ENABLE_WIFI
// This is very helpful for testing YAML config files. If things
// screw up, you can still connect and upload a new config.yaml
// TODO - Consider whether we want this for the long term
if (!_comms->_apConfig) {
_comms->_apConfig = new WifiAPConfig();
}
#endif

if (_macros == nullptr) {
_macros = new Macros();
}
Expand Down Expand Up @@ -310,7 +292,6 @@ namespace Machine {
delete _sdCard;
delete _spi;
delete _control;
delete _comms;
delete _macros;
}
}
2 changes: 0 additions & 2 deletions FluidNC/src/Machine/MachineConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "Axes.h"
#include "SPIBus.h"
#include "I2SOBus.h"
#include "Communications.h"
#include "UserOutputs.h"
#include "Macros.h"

Expand All @@ -36,7 +35,6 @@ namespace Machine {
Stepping* _stepping = nullptr;
CoolantControl* _coolant = nullptr;
Probe* _probe = nullptr;
Communications* _comms = nullptr;
Control* _control = nullptr;
UserOutputs* _userOutputs = nullptr;
SDCard* _sdCard = nullptr;
Expand Down
8 changes: 3 additions & 5 deletions FluidNC/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void setup() {
// Load settings from non-volatile storage
settings_init(); // requires config

log_info("FluidNC " << GIT_TAG << GIT_REV);
log_info("FluidNC " << git_info);
log_info("Compiled with ESP32 SDK:" << ESP.getSdkVersion());

if (!SPIFFS.begin(true)) {
Expand Down Expand Up @@ -125,10 +125,8 @@ void setup() {
register_client(&WebUI::telnet_server);
#endif
#ifdef ENABLE_BLUETOOTH
if (config->_comms->_bluetoothConfig) {
config->_comms->_bluetoothConfig->begin();
register_client(&WebUI::SerialBT);
}
WebUI::bt_config.begin();
register_client(&WebUI::SerialBT);
#endif
WebUI::inputBuffer.begin();
} catch (const AssertionFailed& ex) {
Expand Down
28 changes: 21 additions & 7 deletions FluidNC/src/ProcessSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,27 @@ static Error toggle_check_mode(const char* value, WebUI::AuthenticationLevel aut
}
return Error::Ok;
}
static Error isStuck() {
// Block if a control pin is stuck on
if (config->_control->system_check_safety_door_ajar()) {
rtAlarm = ExecAlarm::ControlPin;
return Error::CheckDoor;
}
if (config->_control->stuck()) {
log_info("Control pins:" << config->_control->report());
rtAlarm = ExecAlarm::ControlPin;
return Error::CheckControlPins;
}
return Error::Ok;
}
static Error disable_alarm_lock(const char* value, WebUI::AuthenticationLevel auth_level, Print& out) {
if (sys.state == State::ConfigAlarm) {
return Error::ConfigurationInvalid;
} else if (sys.state == State::Alarm) {
// Block if safety door is ajar.
if (config->_control->system_check_safety_door_ajar()) {
return Error::CheckDoor;
}
if (sys.state == State::Alarm) {
Error err = isStuck();
if (err != Error::Ok) {
return err;
}
report_feedback_message(Message::AlarmUnlock);
sys.state = State::Idle;
Expand All @@ -214,12 +228,12 @@ static Error home(int cycle) {
if (sys.state == State::ConfigAlarm) {
return Error::ConfigurationInvalid;
}

if (!Machine::Axes::homingMask) {
return Error::SettingDisabled;
}
if (config->_control->system_check_safety_door_ajar()) {
return Error::CheckDoor; // Block if safety door is ajar.
Error err = isStuck();
if (err != Error::Ok) {
return err;
}
sys.state = State::Homing; // Set system state variable

Expand Down
7 changes: 5 additions & 2 deletions FluidNC/src/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ std::map<ExecAlarm, const char*> AlarmNames = {
{ ExecAlarm::HomingFailPulloff, "Homing Fail Pulloff" },
{ ExecAlarm::HomingFailApproach, "Homing Fail Approach" },
{ ExecAlarm::SpindleControl, "Spindle Control" },
{ ExecAlarm::ControlPin, "Control Pin Initially On" },
};

volatile Accessory rtAccessoryOverride; // Global realtime executor bitflag variable for spindle/coolant overrides.
Expand Down Expand Up @@ -95,11 +96,13 @@ void protocol_reset() {
rtSleep = false;
rtCycleStop = false;
rtAccessoryOverride.value = 0;
rtAlarm = ExecAlarm::None;
rtFOverride = FeedOverride::Default;
rtROverride = RapidOverride::Default;
rtSOverride = SpindleSpeedOverride::Default;
spindle_stop_ovr.value = 0;

// Do not clear rtAlarm because it might have been set during configuration
// rtAlarm = ExecAlarm::None;
}

static int32_t idleEndTime = 0;
Expand Down Expand Up @@ -699,7 +702,7 @@ void protocol_exec_rt_system() {
protocol_do_macro(1);
}
if (rtButtonMacro2) {
rtButtonMacro0 = false;
rtButtonMacro2 = false;
protocol_do_macro(2);
}
if (rtButtonMacro3) {
Expand Down
3 changes: 2 additions & 1 deletion FluidNC/src/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ enum class ExecAlarm : uint8_t {
HomingFailPulloff = 8,
HomingFailApproach = 9,
SpindleControl = 10,
ControlPin = 11,
};

extern volatile ExecAlarm rtAlarm; // Global realtime executor bitflag variable for setting various alarms.
extern volatile ExecAlarm rtAlarm; // Global realtime executor variable for setting various alarms.

#include <map>
extern std::map<ExecAlarm, const char*> AlarmNames;
Loading

0 comments on commit 254ee24

Please sign in to comment.