1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-01 02:21:46 +02:00

Fixed crashes caused by recent work

This commit is contained in:
Mitch Bradley
2021-05-27 09:28:47 -10:00
parent 97fd1e3a32
commit 6da2c699ff
13 changed files with 49 additions and 42 deletions

View File

@@ -482,7 +482,7 @@ Error gc_execute_line(char* line, uint8_t client) {
gc_block.modal.spindle = SpindleState::Cw;
break;
case 4: // Supported if the spindle can be reversed or laser mode is on.
if (spindle->is_reversable || config->_laserMode) {
if (config->_spindle->is_reversable || config->_laserMode) {
gc_block.modal.spindle = SpindleState::Ccw;
} else {
FAIL(Error::GcodeUnsupportedCommand);
@@ -1347,9 +1347,9 @@ Error gc_execute_line(char* line, uint8_t client) {
if (gc_state.modal.spindle != SpindleState::Disable) {
if (bit_isfalse(gc_parser_flags, GCParserLaserIsMotion)) {
if (bit_istrue(gc_parser_flags, GCParserLaserDisable)) {
spindle->sync(gc_state.modal.spindle, 0);
config->_spindle->sync(gc_state.modal.spindle, 0);
} else {
spindle->sync(gc_state.modal.spindle, (uint32_t)gc_block.values.s);
config->_spindle->sync(gc_state.modal.spindle, (uint32_t)gc_block.values.s);
}
}
}
@@ -1370,7 +1370,7 @@ Error gc_execute_line(char* line, uint8_t client) {
// Update spindle control and apply spindle speed when enabling it in this block.
// NOTE: All spindle state changes are synced, even in laser mode. Also, pl_data,
// rather than gc_state, is used to manage laser state for non-laser motions.
spindle->sync(gc_block.modal.spindle, (uint32_t)pl_data->spindle_speed);
config->_spindle->sync(gc_block.modal.spindle, (uint32_t)pl_data->spindle_speed);
gc_state.modal.spindle = gc_block.modal.spindle;
}
pl_data->spindle = gc_state.modal.spindle;
@@ -1598,7 +1598,7 @@ Error gc_execute_line(char* line, uint8_t client) {
if (sys.state != State::CheckMode) {
coords[gc_state.modal.coord_select]->get(gc_state.coord_system);
system_flag_wco_change(); // Set to refresh immediately just in case something altered.
spindle->set_state(SpindleState::Disable, 0);
config->_spindle->set_state(SpindleState::Disable, 0);
config->_coolant->off();
}

View File

@@ -96,7 +96,7 @@ void grbl_init() {
WebUI::wifi_config.begin();
#endif
if (config->_comms->_bluetoothConfig != nullptr) {
if (hasBluetooth()) {
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Initializing Bluetooth...");
config->_comms->_bluetoothConfig->begin();
@@ -140,8 +140,7 @@ static void reset_variables() {
// Reset Grbl primary systems.
client_reset_read_buffer(CLIENT_ALL); // Clear serial read buffer
gc_init(); // Set g-code parser to default state
spindle->stop();
config->_spindle->stop();
config->_coolant->init();
limits_init();
config->_probe->init();

View File

@@ -21,6 +21,8 @@
#include "Motors/Motor.h"
#include "Motors/NullMotor.h"
#include "Spindles/NullSpindle.h"
#include "Grbl.h"
#include "Logging.h"
@@ -411,6 +413,11 @@ void MachineConfig::afterParse() {
log_info("Control config missing; building default");
_control = new Control();
}
if (_spindle == nullptr) {
log_info("Using null spindle");
_spindle = new Spindles::Null();
}
}
size_t MachineConfig::readFile(const char* filename, char*& buffer) {
@@ -476,15 +483,15 @@ bool MachineConfig::load(const char* filename) {
// If the system crashes we skip the config file and use the default
// builtin config. This helps prevent reset loops on bad config files.
size_t filesize = 0;
char* buffer;
esp_reset_reason_t reason = esp_reset_reason();
char* buffer = nullptr;
esp_reset_reason_t reason = esp_reset_reason();
if (reason == ESP_RST_PANIC) {
log_debug("Skipping configuration file due to panic");
} else {
filesize = readFile(filename, buffer);
}
StringRange* input;
StringRange* input = nullptr;
if (filesize > 0) {
input = new StringRange(buffer, buffer + filesize);
@@ -544,7 +551,6 @@ bool MachineConfig::load(const char* filename) {
log_error("Unknown error while processing config file");
}
// Get rid of buffer and return
if (buffer) {
delete[] buffer;
}

View File

@@ -408,3 +408,7 @@ public:
};
extern MachineConfig* config;
inline bool hasBluetooth() {
return config && config->_comms && config->_comms->_bluetoothConfig != nullptr;
}

View File

@@ -537,8 +537,7 @@ void mc_reset() {
if (!rtReset) {
rtReset = true;
// Kill spindle and coolant.
spindle->stop();
config->_spindle->stop();
config->_coolant->stop();
// turn off all User I/O immediately

View File

@@ -579,7 +579,7 @@ static void protocol_execute_overrides() {
sys.report_ovr_counter = 0; // Set to report change immediately
// If spindle is on, tell it the RPM has been overridden
if (gc_state.modal.spindle != SpindleState::Disable) {
spindle->set_rpm(gc_state.spindle_speed);
config->_spindle->set_rpm(gc_state.spindle_speed);
}
}
@@ -901,7 +901,7 @@ void protocol_exec_rt_system() {
// sys.report_ovr_counter = 0; // Set to report change immediately
// // If spinlde is on, tell it the rpm has been overridden
// if (gc_state.modal.spindle != SpindleState::Disable) {
// spindle->set_rpm(gc_state.spindle_speed);
// config->_spindle->set_rpm(gc_state.spindle_speed);
// }
// }
//
@@ -1022,7 +1022,7 @@ static void protocol_exec_rt_suspend() {
// Ensure any prior spindle stop override is disabled at start of safety door routine.
sys.spindle_stop_ovr.value = 0; // Disable override
#ifndef PARKING_ENABLE
spindle->set_state(SpindleState::Disable, 0); // De-energize
config->_spindle->set_state(SpindleState::Disable, 0); // De-energize
config->_coolant->off();
#else
// Get current position and store restore location and spindle retract waypoint.
@@ -1052,7 +1052,7 @@ static void protocol_exec_rt_suspend() {
pl_data->motion.systemMotion = 1;
pl_data->motion.noFeedOverride = 1;
pl_data->spindle_speed = 0.0;
spindle->set_state(pl_data->spindle, 0); // De-energize
config->_spindle->set_state(pl_data->spindle, 0); // De-energize
config->_coolant->set_state(pl_data->coolant);
// Execute fast parking retract motion to parking target location.
if (parking_target[PARKING_AXIS] < PARKING_TARGET) {
@@ -1063,7 +1063,7 @@ static void protocol_exec_rt_suspend() {
} else {
// Parking motion not possible. Just disable the spindle and coolant.
// NOTE: Laser mode does not start a parking motion to ensure the laser stops immediately.
spindle->set_state(SpindleState::Disable, 0); // De-energize
config->_spindle->set_state(SpindleState::Disable, 0); // De-energize
config->_coolant->off();
}
#endif
@@ -1073,7 +1073,7 @@ static void protocol_exec_rt_suspend() {
if (sys.state == State::Sleep) {
report_feedback_message(Message::SleepMode);
// Spindle and coolant should already be stopped, but do it again just to be sure.
spindle->set_state(SpindleState::Disable, 0); // De-energize
config->_spindle->set_state(SpindleState::Disable, 0); // De-energize
config->_coolant->off();
st_go_idle(); // Disable steppers
while (!(sys.abort)) {
@@ -1109,7 +1109,7 @@ static void protocol_exec_rt_suspend() {
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts.
sys.step_control.updateSpindleRpm = true;
} else {
spindle->set_state(restore_spindle, (uint32_t)restore_spindle_speed);
config->_spindle->set_state(restore_spindle, (uint32_t)restore_spindle_speed);
// restore delay is done in the spindle class
}
}
@@ -1149,7 +1149,7 @@ static void protocol_exec_rt_suspend() {
// Handles beginning of spindle stop
if (sys.spindle_stop_ovr.bit.initiate) {
if (gc_state.modal.spindle != SpindleState::Disable) {
spindle->set_state(SpindleState::Disable, 0); // De-energize
config->_spindle->set_state(SpindleState::Disable, 0); // De-energize
sys.spindle_stop_ovr.value = 0;
sys.spindle_stop_ovr.bit.enabled = true; // Set stop override state to enabled, if de-energized.
} else {
@@ -1163,7 +1163,7 @@ static void protocol_exec_rt_suspend() {
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts.
sys.step_control.updateSpindleRpm = true;
} else {
spindle->set_state(restore_spindle, (uint32_t)restore_spindle_speed);
config->_spindle->set_state(restore_spindle, (uint32_t)restore_spindle_speed);
}
}
if (sys.spindle_stop_ovr.bit.restoreCycle) {
@@ -1175,7 +1175,7 @@ static void protocol_exec_rt_suspend() {
// Handles spindle state during hold. NOTE: Spindle speed overrides may be altered during hold state.
// NOTE: sys.step_control.updateSpindleRpm is automatically reset upon resume in step generator.
if (sys.step_control.updateSpindleRpm) {
spindle->set_state(restore_spindle, (uint32_t)restore_spindle_speed);
config->_spindle->set_state(restore_spindle, (uint32_t)restore_spindle_speed);
sys.step_control.updateSpindleRpm = false;
}
}

View File

@@ -529,7 +529,7 @@ void report_build_info(const char* line, uint8_t client) {
#ifdef ALLOW_FEED_OVERRIDE_DURING_PROBE_CYCLES
grbl_send(client, "A");
#endif
if (config->_comms->_bluetoothConfig != nullptr) {
if (hasBluetooth()) {
grbl_send(client, "B");
}
#ifdef ENABLE_SD_CARD
@@ -563,7 +563,7 @@ void report_build_info(const char* line, uint8_t client) {
#if defined(ENABLE_WIFI)
grbl_send(client, (char*)WebUI::wifi_config.info());
#endif
if (config->_comms->_bluetoothConfig != nullptr) {
if (hasBluetooth()) {
grbl_send(client, config->_comms->_bluetoothConfig->info().c_str());
}
}
@@ -616,7 +616,7 @@ void report_realtime_status(uint8_t client) {
bufsize = WebUI::telnet_server.get_rx_buffer_available();
}
#endif //ENABLE_WIFI && ENABLE_TELNET
if (config->_comms->_bluetoothConfig != nullptr && client == CLIENT_BT) {
if (hasBluetooth() && client == CLIENT_BT) {
//TODO FIXME
bufsize = 512 - WebUI::SerialBT.available();
}
@@ -712,7 +712,7 @@ void report_realtime_status(uint8_t client) {
sprintf(temp, "|Ov:%d,%d,%d", sys.f_override, sys.r_override, sys.spindle_speed_ovr);
strcat(status, temp);
SpindleState sp_state = spindle->get_state();
SpindleState sp_state = config->_spindle->get_state();
CoolantState coolant_state = config->_coolant->get_state();
if (sp_state != SpindleState::Disable || coolant_state.Mist || coolant_state.Flood) {
strcat(status, "|A:");

View File

@@ -57,7 +57,7 @@ public:
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 = false; // Grbl has processed a line and is waiting for another
//bool mount();
SDCard::State get_state(bool refresh);

View File

@@ -125,7 +125,7 @@ static uint8_t getClientChar(uint8_t* data) {
return CLIENT_INPUT;
}
//currently is wifi or BT but better to prepare both can be live
if (config->_comms->_bluetoothConfig != nullptr) {
if (hasBluetooth()) {
if (WebUI::SerialBT.hasClient()) {
if ((res = WebUI::SerialBT.read()) != -1) {
*data = res;
@@ -181,7 +181,7 @@ void clientCheckTask(void* pvParameters) {
#ifdef ENABLE_WIFI
WebUI::wifi_config.handle();
#endif
if (config->_comms->_bluetoothConfig != nullptr) {
if (hasBluetooth()) {
config->_comms->_bluetoothConfig->handle();
}
#if defined(ENABLE_WIFI) && defined(ENABLE_HTTP) && defined(ENABLE_SERIAL2SOCKET_IN)
@@ -332,8 +332,11 @@ void client_write(uint8_t client, const char* text) {
if (client == CLIENT_INPUT) {
return;
}
if (config->_comms->_bluetoothConfig != nullptr) {
if (hasBluetooth()) {
if (WebUI::SerialBT.hasClient() && (client == CLIENT_BT || client == CLIENT_ALL)) {
// TODO: This can be .print() for consistency with other clients,
// and it is not necessary to call .hasClient() because .write()
// checks for a client and does nothing if one is not present.
WebUI::SerialBT.print(text);
//delay(10); // possible fix for dropped characters
}

View File

@@ -39,5 +39,3 @@ namespace Spindles {
set_state(state, rpm);
}
}
Spindles::Spindle* spindle;

View File

@@ -83,5 +83,3 @@ namespace Spindles {
};
using SpindleFactory = Configuration::GenericFactory<Spindle>;
}
extern Spindles::Spindle* spindle;

View File

@@ -285,14 +285,14 @@ static void stepper_pulse_func() {
st.steps[axis] = st.exec_block->steps[axis] >> st.exec_segment->amass_level;
}
// Set real-time spindle output as segment is loaded, just prior to the first step.
spindle->set_rpm(st.exec_segment->spindle_rpm);
config->_spindle->set_rpm(st.exec_segment->spindle_rpm);
} else {
// Segment buffer empty. Shutdown.
st_go_idle();
if (sys.state != State::Jog) { // added to prevent ... jog after probing crash
// Ensure pwm is set properly upon completion of rate-controlled motion.
if (st.exec_block != NULL && st.exec_block->is_pwm_rate_adjusted) {
spindle->set_rpm(0);
config->_spindle->set_rpm(0);
}
}
rtCycleStop = true;

View File

@@ -557,7 +557,7 @@ namespace WebUI {
break;
}
#endif // ENABLE_WIFI
if (config->_comms->_bluetoothConfig != nullptr) {
if (hasBluetooth()) {
auto bt_config = config->_comms->_bluetoothConfig;
webPrint("Current BT Mode: ");
if (bt_config->Is_BT_on()) {
@@ -909,7 +909,7 @@ namespace WebUI {
}
#endif
if (config->_comms->_bluetoothConfig != nullptr && config->_comms->_bluetoothConfig->Is_BT_on()) {
if (hasBluetooth() && config->_comms->_bluetoothConfig->Is_BT_on()) {
on = true;
}
@@ -933,7 +933,7 @@ namespace WebUI {
wifi_config.StopWiFi();
}
#endif
if (config->_comms->_bluetoothConfig != nullptr) {
if (hasBluetooth()) {
if (config->_comms->_bluetoothConfig->Is_BT_on()) {
config->_comms->_bluetoothConfig->end();
}
@@ -958,7 +958,7 @@ namespace WebUI {
return Error::Ok;
# endif
case ESP_BT:
if (config->_comms->_bluetoothConfig == nullptr) {
if (hasBluetooth()) {
webPrintln("Bluetooth is not enabled!");
return Error::BtFailBegin;
} else {