diff --git a/RabbitGRBL/src/Backlash/BacklashManager.cpp b/RabbitGRBL/src/Backlash/BacklashManager.cpp index 06bd2dd..590d544 100644 --- a/RabbitGRBL/src/Backlash/BacklashManager.cpp +++ b/RabbitGRBL/src/Backlash/BacklashManager.cpp @@ -20,6 +20,7 @@ along with Rabbit GRBL. If not, see . */ +#include "../Grbl.h" #include "BacklashManager.h" #define DIR_POSITIVE 0 @@ -27,9 +28,6 @@ #define DIR_NEUTRAL 2 // Private (Statics) -float BacklashManager::fPreviousTargets[MAX_N_AXIS] = {0.0}; -uint8_t BacklashManager::fAxisDirections[MAX_N_AXIS] = {DIR_NEUTRAL}; - /** * Initialize the Backlash Manager * This method is called from grbl_init (Grbl.cpp) diff --git a/RabbitGRBL/src/Backlash/BacklashManager.h b/RabbitGRBL/src/Backlash/BacklashManager.h index 8f7bcdf..2410ca7 100644 --- a/RabbitGRBL/src/Backlash/BacklashManager.h +++ b/RabbitGRBL/src/Backlash/BacklashManager.h @@ -27,13 +27,13 @@ class BacklashManager { public: - static void Initialize(); - static void CompensateBacklash(float *target, plan_line_data_t *pl_data); + void Initialize(); + void CompensateBacklash(float *target, plan_line_data_t *pl_data); - static void ResetTargets(); - static void SynchPositionWhileUsingProbe(); + void ResetTargets(); + void SynchPositionWhileUsingProbe(); private: - static float fPreviousTargets[]; - static uint8_t fAxisDirections[]; + float fPreviousTargets[MAX_N_AXIS]; + uint8_t fAxisDirections[MAX_N_AXIS]; }; diff --git a/RabbitGRBL/src/CNCMachine.cpp b/RabbitGRBL/src/CNCMachine.cpp new file mode 100644 index 0000000..ac5a2e1 --- /dev/null +++ b/RabbitGRBL/src/CNCMachine.cpp @@ -0,0 +1,51 @@ +/* + CNCMachine.cpp + + Copyright (c) 2026 Nikolaos Siatras + Twitter: nsiatras + Github: https://github.com/nsiatras + Website: https://www.sourcerabbit.com + + Rabbit GRBL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Rabbit GRBL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Rabbit GRBL. If not, see . +*/ + +#include "Grbl.h" +#include "CNCMachine.h" + +BacklashManager CNCMachine::fBacklashManager; +MotorsManager CNCMachine::fMotorsManager; +CoolantManager CNCMachine::fCoolantManager; +Probe CNCMachine::fProbe; + +/** + * Initialize the CNC Machine + */ +void CNCMachine::Initialize() +{ + CNCMachine::fBacklashManager.Initialize(); + CNCMachine::fMotorsManager.Initialize(); + CNCMachine::fCoolantManager.Initialize(); + CNCMachine::fProbe.Initialize(); +} + +/** + * Reset the CNC Machine. + * (Re-Initialize managers etc.) + */ +void CNCMachine::Reset() +{ + CNCMachine::fBacklashManager.ResetTargets(); + CNCMachine::fCoolantManager.Initialize(); + CNCMachine::fProbe.Initialize(); +} diff --git a/RabbitGRBL/src/CNCMachine.h b/RabbitGRBL/src/CNCMachine.h new file mode 100644 index 0000000..8577fd6 --- /dev/null +++ b/RabbitGRBL/src/CNCMachine.h @@ -0,0 +1,41 @@ +/* + CNCMachine.h + + Copyright (c) 2026 Nikolaos Siatras + Twitter: nsiatras + Github: https://github.com/nsiatras + Website: https://www.sourcerabbit.com + + Rabbit GRBL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Rabbit GRBL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Rabbit GRBL. If not, see . +*/ + +#pragma once + +#include "Grbl.h" +#include "Backlash/BacklashManager.h" +#include "Motors/MotorsManager.h" +#include "Coolant/CoolantManager.h" +#include "Probe/Probe.h" + +class CNCMachine +{ +public: + static BacklashManager fBacklashManager; + static MotorsManager fMotorsManager; + static CoolantManager fCoolantManager; + static Probe fProbe; + + static void Initialize(); + static void Reset(); +}; diff --git a/RabbitGRBL/src/Coolant/CoolantManager.cpp b/RabbitGRBL/src/Coolant/CoolantManager.cpp index 530cfaa..da4ee27 100644 --- a/RabbitGRBL/src/Coolant/CoolantManager.cpp +++ b/RabbitGRBL/src/Coolant/CoolantManager.cpp @@ -20,24 +20,17 @@ You should have received a copy of the GNU General Public License along with Rabbit GRBL. If not, see . */ +#include "../Grbl.h" #include "CoolantManager.h" #define COOLANTS_COUNT 2 -// Public (Statics) -Coolant CoolantManager::Mist_Coolant; -Coolant CoolantManager::Flood_Coolant; - -// Private (Statics) -Coolant *CoolantManager::fCoolants[COOLANTS_COUNT]; -bool CoolantManager::fInitialized = false; - /** * Initialize the Coolant Manager */ void CoolantManager::Initialize() { - if (CoolantManager::fInitialized) + if (fInitialized) { // If the CoolantManager has already been initialized then just turn all coolants off. // This case might happened after the user send a reset command to the controller. @@ -49,28 +42,28 @@ void CoolantManager::Initialize() // Initialize Mist (M7) ///////////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef COOLANT_MIST_PIN - CoolantManager::Mist_Coolant.Initialize(COOLANT_MIST_PIN, INVERT_COOLANT_MIST_PIN, settings_coolant_mist_start_delay); + Mist_Coolant.Initialize(COOLANT_MIST_PIN, INVERT_COOLANT_MIST_PIN, settings_coolant_mist_start_delay); // MessageSender::SendMessage(EMessageLevel::Info, "Mist coolant on pin %s", pinName(COOLANT_MIST_PIN).c_str()); #else - CoolantManager::Mist_Coolant.Initialize(0, true); + Mist_Coolant.Initialize(0, true); #endif - CoolantManager::fCoolants[0] = &CoolantManager::Mist_Coolant; + fCoolants[0] = &Mist_Coolant; ///////////////////////////////////////////////////////////////////////////////////////////////////////// // Initialize Flood (M8) ///////////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef COOLANT_FLOOD_PIN - CoolantManager::Flood_Coolant.Initialize(COOLANT_FLOOD_PIN, INVERT_COOLANT_FLOOD_PIN, settings_coolant_flood_start_delay); + Flood_Coolant.Initialize(COOLANT_FLOOD_PIN, INVERT_COOLANT_FLOOD_PIN, settings_coolant_flood_start_delay); // MessageSender::SendMessage(EMessageLevel::Info, "Flood coolant on pin %s", pinName(COOLANT_FLOOD_PIN).c_str()); #else - CoolantManager::Flood_Coolant.Initialize(0, true); + Flood_Coolant.Initialize(0, true); #endif - CoolantManager::fCoolants[1] = &CoolantManager::Flood_Coolant; + fCoolants[1] = &Flood_Coolant; /////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Finally mark the CoolantManager as Initialized ! - CoolantManager::fInitialized = true; + fInitialized = true; } /** @@ -80,7 +73,7 @@ void CoolantManager::TurnAllCoolantsOff() { for (int i = 0; i < COOLANTS_COUNT; i++) { - CoolantManager::fCoolants[i]->TurnOff(); + fCoolants[i]->TurnOff(); } sys.report_ovr_counter = 0; // Set to report change immediately @@ -91,8 +84,8 @@ void CoolantManager::TurnAllCoolantsOff() */ void CoolantManager::setCoolantState(CoolantState state) { - CoolantManager::Mist_Coolant.setState(state.Mist == 1); - CoolantManager::Flood_Coolant.setState(state.Flood == 1); + Mist_Coolant.setState(state.Mist == 1); + Flood_Coolant.setState(state.Flood == 1); sys.report_ovr_counter = 0; // Set to report change immediately } @@ -103,7 +96,7 @@ bool CoolantManager::AreAllCoolantsOff() { for (int i = 0; i < COOLANTS_COUNT; i++) { - if (CoolantManager::fCoolants[i]->isOn()) + if (fCoolants[i]->isOn()) { return false; } diff --git a/RabbitGRBL/src/Coolant/CoolantManager.h b/RabbitGRBL/src/Coolant/CoolantManager.h index aa80d3d..818c2d6 100644 --- a/RabbitGRBL/src/Coolant/CoolantManager.h +++ b/RabbitGRBL/src/Coolant/CoolantManager.h @@ -29,16 +29,16 @@ class CoolantManager { public: - static Coolant Mist_Coolant; - static Coolant Flood_Coolant; + Coolant Mist_Coolant; + Coolant Flood_Coolant; - static void Initialize(); - static void TurnAllCoolantsOff(); - static void setCoolantState(CoolantState state); + void Initialize(); + void TurnAllCoolantsOff(); + void setCoolantState(CoolantState state); - static bool AreAllCoolantsOff(); + bool AreAllCoolantsOff(); private: - static bool fInitialized; - static Coolant *fCoolants[]; + bool fInitialized; + Coolant *fCoolants[2]; }; diff --git a/RabbitGRBL/src/GCode.cpp b/RabbitGRBL/src/GCode.cpp index 2279767..c69b2b8 100644 --- a/RabbitGRBL/src/GCode.cpp +++ b/RabbitGRBL/src/GCode.cpp @@ -2212,20 +2212,20 @@ EError gc_execute_line(char *line) gc_state.modal.coolant.Mist = 1; protocol_buffer_synchronize(); // Ask Mist Coolant to TurnOn - CoolantManager::Mist_Coolant.TurnOn(); + CNCMachine::fCoolantManager.Mist_Coolant.TurnOn(); break; case GCodeCoolant::M8: gc_state.modal.coolant.Flood = 1; protocol_buffer_synchronize(); // Ask Flood Coolant to TurnOn - CoolantManager::Flood_Coolant.TurnOn(); + CNCMachine::fCoolantManager.Flood_Coolant.TurnOn(); break; case GCodeCoolant::M9: gc_state.modal.coolant = {}; // Turn all Collants off - CoolantManager::TurnAllCoolantsOff(); + CNCMachine::fCoolantManager.TurnAllCoolantsOff(); break; } pl_data->coolant = gc_state.modal.coolant; // Set state for planner use. @@ -2510,7 +2510,7 @@ EError gc_execute_line(char *line) coords[gc_state.modal.coord_select]->get(gc_state.coord_system); system_flag_wco_change(); // Set to refresh immediately just in case something altered. fSpindle->setState(SpindleState::Disable, 0); - CoolantManager::TurnAllCoolantsOff(); + CNCMachine::fCoolantManager.TurnAllCoolantsOff(); } MessageSender::SendFeedbackMessage(EFeedbackMessage::ProgramEnd); #ifdef USE_M30 diff --git a/RabbitGRBL/src/Grbl.cpp b/RabbitGRBL/src/Grbl.cpp index 5a93073..4f098af 100644 --- a/RabbitGRBL/src/Grbl.cpp +++ b/RabbitGRBL/src/Grbl.cpp @@ -22,13 +22,12 @@ void grbl_init() { - client_init(); // Setup serial baud rate and interrupts + client_init(); // Setup serial baud rate and interrupts settings_init(); // Load Grbl settings from non-volatile storage stepper_init(); // Configure stepper pins and interrupt timers system_ini(); // Configure pinout pins and pin-change interrupt (Renamed due to conflict with esp32 files) - BacklashManager::Initialize(); - MotorsManager::Initialize(); + CNCMachine::Initialize(); memset(sys_position, 0, sizeof(sys_position)); // Clear machine position. machine_init(); // weak definition in Grbl.cpp does nothing @@ -69,7 +68,7 @@ static void reset_variables() sys.spindle_speed_ovr = SpindleSpeedOverride::Default; // Set to 100% memset(sys_probe_position, 0, sizeof(sys_probe_position)); // Clear probe position. - Probe::setSystemProbeState(false); + CNCMachine::fProbe.setSystemProbeState(false); sys_rt_exec_state.value = 0; sys_rt_exec_accessory_override.value = 0; @@ -85,15 +84,13 @@ static void reset_variables() client_reset_read_buffer(); gc_init(); // Set g-code parser to default state fSpindle->Stop(); - CoolantManager::Initialize(); limits_init(); - Probe::Initialize(); plan_reset(); // Clear block buffer and planner variables st_reset(); // Clear stepper subsystem variables // Sync cleared gcode and planner positions to current system position. plan_sync_position(); - BacklashManager::ResetTargets(); + CNCMachine::fBacklashManager.ResetTargets(); gc_sync_position(); report_init_message(); } @@ -108,5 +105,3 @@ void run_once() } void __attribute__((weak)) machine_init() {} - - diff --git a/RabbitGRBL/src/Grbl.h b/RabbitGRBL/src/Grbl.h index eed3e87..da2947a 100644 --- a/RabbitGRBL/src/Grbl.h +++ b/RabbitGRBL/src/Grbl.h @@ -39,12 +39,12 @@ const char *const GRBL_VERSION = "1.1h"; #include "Diagnostics/Errors/ErrorsManager.h" #include "Diagnostics/Alarms/AlarmsManager.h" -#include "Probe/Probe.h" + #include "System.h" #include "GCode.h" #include "Planner.h" #include "Limits.h" -#include "Backlash/BacklashManager.h" + #include "MotionControl.h" #include "Protocol.h" #include "Serial.h" @@ -52,13 +52,14 @@ const char *const GRBL_VERSION = "1.1h"; #include "Report.h" #include "Pins.h" #include "Spindles/Spindle.h" -#include "Motors/MotorsManager.h" + #include "Stepper.h" #include "Jog.h" #include "InputBuffer/InputBuffer.h" #include "Settings.h" #include "SettingsDefinitions.h" -#include "Coolant/CoolantManager.h" + +#include "CNCMachine.h" #include "UserOutputs/UserOutputs.h" #include diff --git a/RabbitGRBL/src/Limits.cpp b/RabbitGRBL/src/Limits.cpp index 72c9304..396f57b 100644 --- a/RabbitGRBL/src/Limits.cpp +++ b/RabbitGRBL/src/Limits.cpp @@ -93,7 +93,7 @@ void limits_go_home(uint8_t cycle_mask) // Put motors on axes listed in cycle_mask in homing mode and // replace cycle_mask with the list of motors that are ready for homing. // Motors with non standard homing can home during motors_set_homing_mode(...) - cycle_mask = MotorsManager::SetHomingMode(cycle_mask, true); // tell motors homing is about to start + cycle_mask = CNCMachine::fMotorsManager.SetHomingMode(cycle_mask, true); // tell motors homing is about to start // see if any motors are left if (cycle_mask == 0) @@ -240,7 +240,7 @@ void limits_go_home(uint8_t cycle_mask) if (sys_rt_exec_alarm != EAlarm::None) { - MotorsManager::SetHomingMode(cycle_mask, false); // tell motors homing is done...failed + CNCMachine::fMotorsManager.SetHomingMode(cycle_mask, false); // tell motors homing is done...failed MessageSender::SendMessage(EMessageLevel::Debug, "Homing fail"); mc_reset(); // Stop motors, if they are running. protocol_execute_realtime(); @@ -300,7 +300,7 @@ void limits_go_home(uint8_t cycle_mask) } } sys.step_control = {}; // Return step control to normal operation. - MotorsManager::SetHomingMode(cycle_mask, false); // tell motors homing is done + CNCMachine::fMotorsManager.SetHomingMode(cycle_mask, false); // tell motors homing is done } uint8_t limit_pins[MAX_N_AXIS][2] = {{X_LIMIT_PIN, X2_LIMIT_PIN}, {Y_LIMIT_PIN, Y2_LIMIT_PIN}, {Z_LIMIT_PIN, Z2_LIMIT_PIN}, {A_LIMIT_PIN, A2_LIMIT_PIN}, {B_LIMIT_PIN, B2_LIMIT_PIN}, {C_LIMIT_PIN, C2_LIMIT_PIN}}; diff --git a/RabbitGRBL/src/MotionControl.cpp b/RabbitGRBL/src/MotionControl.cpp index aa1140d..26c19c6 100644 --- a/RabbitGRBL/src/MotionControl.cpp +++ b/RabbitGRBL/src/MotionControl.cpp @@ -61,7 +61,7 @@ void mc_line(float *target, plan_line_data_t *pl_data) //////////////////////////////////////////////////////////////////// // Backlash Compensation - BacklashManager::CompensateBacklash(target, pl_data); + CNCMachine::fBacklashManager.CompensateBacklash(target, pl_data); //////////////////////////////////////////////////////////////////// do @@ -358,7 +358,7 @@ void mc_homing_cycle(uint8_t cycle_mask) // Sync gcode parser and planner positions to homed position. gc_sync_position(); plan_sync_position(); - BacklashManager::ResetTargets(); + CNCMachine::fBacklashManager.ResetTargets(); // If hard limits feature enabled, re-enable hard limits pin change register after homing cycle. limits_init(); @@ -391,11 +391,11 @@ GCUpdatePos mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t par uint8_t is_probe_away = bit_istrue(parser_flags, GCParserProbeIsAway); uint8_t is_no_error = bit_istrue(parser_flags, GCParserProbeIsNoError); sys.probe_succeeded = false; // Re-initialize probe history before beginning cycle. - Probe::setDirection(is_probe_away == 1); + CNCMachine::fProbe.setDirection(is_probe_away == 1); // After syncing, check if probe is already triggered. If so, halt and issue alarm. // NOTE: This probe initialization error applies to all probing cycles. - if (Probe::isTriggered() ^ is_probe_away) + if (CNCMachine::fProbe.isTriggered() ^ is_probe_away) { // Check probe pin state. sys_rt_exec_alarm = EAlarm::ProbeFailInitial; @@ -409,7 +409,7 @@ GCUpdatePos mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t par mc_line(target, pl_data); // Activate the probing state monitor in the stepper module. - Probe::setSystemProbeState(true); + CNCMachine::fProbe.setSystemProbeState(true); // Perform probing cycle. Wait here until probe is triggered or motion completes. sys_rt_exec_state.bit.cycleStart = true; @@ -428,7 +428,7 @@ GCUpdatePos mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t par // Probing cycle complete! // Set state variables and error out, if the probe failed and cycle with error is enabled. - if (Probe::isSystemUsingProbe()) + if (CNCMachine::fProbe.isSystemUsingProbe()) { if (is_no_error) { @@ -444,18 +444,18 @@ GCUpdatePos mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t par sys.probe_succeeded = true; // Indicate to system the probing cycle completed successfully. } - Probe::setSystemProbeState(false); // Ensure probe state monitor is disabled. + CNCMachine::fProbe.setSystemProbeState(false); // Ensure probe state monitor is disabled. protocol_execute_realtime(); // Check and execute run-time commands // Reset the stepper and planner buffers to remove the remainder of the probe motion. st_reset(); // Reset step segment buffer. plan_reset(); // Reset planner buffer. Zero planner positions. Ensure probing motion is cleared. plan_sync_position(); // Sync planner position to current machine position. - BacklashManager::SynchPositionWhileUsingProbe(); + CNCMachine::fBacklashManager.SynchPositionWhileUsingProbe(); #ifdef MESSAGE_PROBE_COORDINATES // All done! Output the probe position as message. - Probe::ReportProbeParameters(); + CNCMachine::fProbe.ReportProbeParameters(); #endif if (sys.probe_succeeded) @@ -529,7 +529,7 @@ void mc_reset() // Kill spindle and coolant. fSpindle->Stop(); - CoolantManager::TurnAllCoolantsOff(); + CNCMachine::fCoolantManager.TurnAllCoolantsOff(); // Turn off all User I/O immediately sys_digital_all_off(); diff --git a/RabbitGRBL/src/Motors/MotorsManager.cpp b/RabbitGRBL/src/Motors/MotorsManager.cpp index 2dd4f91..6c5a154 100644 --- a/RabbitGRBL/src/Motors/MotorsManager.cpp +++ b/RabbitGRBL/src/Motors/MotorsManager.cpp @@ -30,9 +30,6 @@ using StepperImpl = Stepper_RMT; using StepperImpl = Stepper_Software; #endif -// Static member definition -Motor *MotorsManager::fMotors[MAX_AXES][MAX_GANGED]; - void MotorsManager::Initialize() { // MessageSender::SendMessage(EMessageLevel::Info, "Init Motors"); diff --git a/RabbitGRBL/src/Motors/MotorsManager.h b/RabbitGRBL/src/Motors/MotorsManager.h index 8d76393..c634d04 100644 --- a/RabbitGRBL/src/Motors/MotorsManager.h +++ b/RabbitGRBL/src/Motors/MotorsManager.h @@ -32,15 +32,15 @@ class MotorsManager { public: - static void Initialize(); + void Initialize(); // The return value is a bitmask of axes that can home - static uint8_t SetHomingMode(uint8_t homing_mask, bool isHoming); - static void SetDisable(bool disable, uint8_t mask = B11111111); // default is all axes - static bool Direction(uint8_t dir_mask); - static void Step(uint8_t step_mask); - static void Unstep(); + uint8_t SetHomingMode(uint8_t homing_mask, bool isHoming); + void SetDisable(bool disable, uint8_t mask = B11111111); // default is all axes + bool Direction(uint8_t dir_mask); + void Step(uint8_t step_mask); + void Unstep(); private: - static Motor *fMotors[MAX_AXES][MAX_GANGED]; + Motor *fMotors[MAX_AXES][MAX_GANGED]; }; diff --git a/RabbitGRBL/src/Probe/Probe.cpp b/RabbitGRBL/src/Probe/Probe.cpp index 6b2092f..d5f1e65 100644 --- a/RabbitGRBL/src/Probe/Probe.cpp +++ b/RabbitGRBL/src/Probe/Probe.cpp @@ -23,9 +23,6 @@ #include "Probe.h" // Private (Statics) -bool Probe::fIsProbeAway = false; -volatile bool Probe::fSystemIsUsingProbe = false; - /** * Initializes the machine's probe */ @@ -47,7 +44,7 @@ void Probe::Initialize() */ void Probe::setDirection(bool isAway) { - Probe::fIsProbeAway = isAway; + fIsProbeAway = isAway; } /** @@ -65,9 +62,9 @@ bool Probe::isTriggered() // NOTE: This function must be extremely efficient as to not bog down the stepper ISR. void Probe::StateMonitor() { - if (Probe::isTriggered() ^ Probe::fIsProbeAway) + if (isTriggered() ^ fIsProbeAway) { - Probe::fSystemIsUsingProbe = false; + fSystemIsUsingProbe = false; memcpy(sys_probe_position, sys_position, sizeof(sys_position)); sys_rt_exec_state.bit.motionCancel = true; } @@ -100,7 +97,7 @@ void Probe::ReportProbeParameters() */ bool Probe::isSystemUsingProbe() { - return Probe::fSystemIsUsingProbe; + return fSystemIsUsingProbe; } /** @@ -109,5 +106,5 @@ bool Probe::isSystemUsingProbe() */ void Probe::setSystemProbeState(bool state) { - Probe::fSystemIsUsingProbe = state; + fSystemIsUsingProbe = state; } diff --git a/RabbitGRBL/src/Probe/Probe.h b/RabbitGRBL/src/Probe/Probe.h index a87d80e..981f4a1 100644 --- a/RabbitGRBL/src/Probe/Probe.h +++ b/RabbitGRBL/src/Probe/Probe.h @@ -24,17 +24,17 @@ class Probe { public: - static void Initialize(); - static void setDirection(bool isAway); - static bool isTriggered(); - static void StateMonitor(); + void Initialize(); + void setDirection(bool isAway); + bool isTriggered(); + void StateMonitor(); - static void ReportProbeParameters(); + void ReportProbeParameters(); - static bool isSystemUsingProbe(); - static void setSystemProbeState(bool state); + bool isSystemUsingProbe(); + void setSystemProbeState(bool state); private: - static bool fIsProbeAway; - static volatile bool fSystemIsUsingProbe; + bool fIsProbeAway; + volatile bool fSystemIsUsingProbe; }; diff --git a/RabbitGRBL/src/ProcessSettings.cpp b/RabbitGRBL/src/ProcessSettings.cpp index b97fc32..0324a5f 100644 --- a/RabbitGRBL/src/ProcessSettings.cpp +++ b/RabbitGRBL/src/ProcessSettings.cpp @@ -389,7 +389,7 @@ EError motor_disable(const char *value) } } } - MotorsManager::SetDisable(true, convertedValue); + CNCMachine::fMotorsManager.SetDisable(true, convertedValue); return EError::Ok; } diff --git a/RabbitGRBL/src/Protocol.cpp b/RabbitGRBL/src/Protocol.cpp index 559eb44..9e9df08 100644 --- a/RabbitGRBL/src/Protocol.cpp +++ b/RabbitGRBL/src/Protocol.cpp @@ -210,7 +210,7 @@ void protocol_main_loop() { if (esp_timer_get_time() > stepper_idle_counter) { - MotorsManager::SetDisable(true); + CNCMachine::fMotorsManager.SetDisable(true); } } } @@ -577,7 +577,7 @@ void protocol_exec_rt_system() if (sys.state == State::Idle || sys.state == State::Cycle || sys.state == State::Hold) { gc_state.modal.coolant.Flood = !gc_state.modal.coolant.Flood; - CoolantManager::Flood_Coolant.Toggle(); // Report counter set in Toggle(). + CNCMachine::fCoolantManager.Flood_Coolant.Toggle(); // Report counter set in Toggle(). } #endif } @@ -591,7 +591,7 @@ void protocol_exec_rt_system() if (sys.state == State::Idle || sys.state == State::Cycle || sys.state == State::Hold) { gc_state.modal.coolant.Mist = !gc_state.modal.coolant.Mist; - CoolantManager::Mist_Coolant.Toggle(); // Report counter set in Toggle(). + CNCMachine::fCoolantManager.Mist_Coolant.Toggle(); // Report counter set in Toggle(). } #endif } @@ -677,7 +677,7 @@ static void protocol_exec_rt_suspend() sys.spindle_stop_ovr.value = 0; // Disable override #ifndef PARKING_ENABLE fSpindle->set_state(SpindleState::Disable, 0); // De-energize - CoolantManager::TurnAllCoolantsOff(); + CNCMachine::fCoolantManager.TurnAllCoolantsOff(); #else // Get current position and store restore location and spindle retract waypoint. system_convert_array_steps_to_mpos(parking_target, sys_position); @@ -713,7 +713,7 @@ static void protocol_exec_rt_suspend() pl_data->motion.noFeedOverride = 1; pl_data->spindle_speed = 0.0; fSpindle->setState(pl_data->spindle, 0); // De-energize - CoolantManager::TurnAllCoolantsOff(); + CNCMachine::fCoolantManager.TurnAllCoolantsOff(); // Execute fast parking retract motion to parking target location. if (parking_target[PARKING_AXIS] < PARKING_TARGET) @@ -728,7 +728,7 @@ static void protocol_exec_rt_suspend() // 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. fSpindle->setState(SpindleState::Disable, 0); // De-energize - CoolantManager::TurnAllCoolantsOff(); + CNCMachine::fCoolantManager.TurnAllCoolantsOff(); } #endif sys.suspend.bit.restartRetract = false; @@ -741,7 +741,7 @@ static void protocol_exec_rt_suspend() MessageSender::SendFeedbackMessage(EFeedbackMessage::SleepMode); // Spindle and coolant should already be stopped, but do it again just to be sure. fSpindle->setState(SpindleState::Disable, 0); // De-energize - CoolantManager::TurnAllCoolantsOff(); + CNCMachine::fCoolantManager.TurnAllCoolantsOff(); st_go_idle(); // Disable steppers while (!(sys.abort)) { @@ -799,7 +799,7 @@ static void protocol_exec_rt_suspend() // Block if safety door re-opened during prior restore actions. if (!sys.suspend.bit.restartRetract) { - CoolantManager::setCoolantState(restore_coolant); + CNCMachine::fCoolantManager.setCoolantState(restore_coolant); } } #ifdef PARKING_ENABLE diff --git a/RabbitGRBL/src/Report.cpp b/RabbitGRBL/src/Report.cpp index 54714d9..baf32e9 100644 --- a/RabbitGRBL/src/Report.cpp +++ b/RabbitGRBL/src/Report.cpp @@ -205,7 +205,7 @@ void report_ngc_parameters() ; ngc_rpt += "]\r\n"; Serial.write(ngc_rpt.c_str()); - Probe::ReportProbeParameters(); + CNCMachine::fProbe.ReportProbeParameters(); } // Print current gcode parser mode state @@ -353,7 +353,7 @@ void report_gcode_modes() strcat(modes_rpt, mode); // report_util_gcode_modes_M(); // optional M7 and M8 should have been dealt with by here - if (CoolantManager::AreAllCoolantsOff()) + if (CNCMachine::fCoolantManager.AreAllCoolantsOff()) { // All coolants are off. Report with M9 strcat(modes_rpt, " M9"); @@ -361,12 +361,12 @@ void report_gcode_modes() else { // Note: Multiple coolant states may be active at the same time. - if (CoolantManager::Mist_Coolant.isOn()) + if (CNCMachine::fCoolantManager.Mist_Coolant.isOn()) { strcat(modes_rpt, " M7"); } - if (CoolantManager::Flood_Coolant.isOn()) + if (CNCMachine::fCoolantManager.Flood_Coolant.isOn()) { strcat(modes_rpt, " M8"); } @@ -554,7 +554,7 @@ void report_realtime_status() AxisMask lim_pin_state = limits_get_state(); ControlPins ctrl_pin_state = system_control_get_state(); - bool isProbeTriggered = Probe::isTriggered(); + bool isProbeTriggered = CNCMachine::fProbe.isTriggered(); if (lim_pin_state || ctrl_pin_state.value || isProbeTriggered) { @@ -682,7 +682,7 @@ void report_realtime_status() strcat(status, temp); SpindleState sp_state = fSpindle->getState(); - if (sp_state != SpindleState::Disable || CoolantManager::Flood_Coolant.isOn() || CoolantManager::Mist_Coolant.isOn()) + if (sp_state != SpindleState::Disable || CNCMachine::fCoolantManager.Flood_Coolant.isOn() || CNCMachine::fCoolantManager.Mist_Coolant.isOn()) { strcat(status, "|A:"); switch (sp_state) @@ -697,12 +697,12 @@ void report_realtime_status() break; } - if (CoolantManager::Flood_Coolant.isOn()) + if (CNCMachine::fCoolantManager.Flood_Coolant.isOn()) { strcat(status, "F"); } - if (CoolantManager::Mist_Coolant.isOn()) + if (CNCMachine::fCoolantManager.Mist_Coolant.isOn()) { strcat(status, "M"); } diff --git a/RabbitGRBL/src/Stepper.cpp b/RabbitGRBL/src/Stepper.cpp index e106a7e..c3c2dee 100644 --- a/RabbitGRBL/src/Stepper.cpp +++ b/RabbitGRBL/src/Stepper.cpp @@ -224,7 +224,7 @@ static void stepper_pulse_func() { auto n_axis = number_axis->get(); - if (MotorsManager::Direction(st.dir_outbits)) + if (CNCMachine::fMotorsManager.Direction(st.dir_outbits)) { auto wait_direction = direction_delay_microseconds->get(); if (wait_direction > 0) @@ -260,7 +260,7 @@ static void stepper_pulse_func() // // NOTE: We could use direction_pulse_start_time + wait_direction, but let's play it safe uint64_t step_pulse_start_time = esp_timer_get_time(); - MotorsManager::Step(st.step_outbits); + CNCMachine::fMotorsManager.Step(st.step_outbits); // If there is no step segment, attempt to pop one from the stepper buffer if (st.exec_segment == NULL) @@ -311,9 +311,9 @@ static void stepper_pulse_func() } } // Check probing state. - if (Probe::isSystemUsingProbe()) + if (CNCMachine::fProbe.isSystemUsingProbe()) { - Probe::StateMonitor(); + CNCMachine::fProbe.StateMonitor(); } // Reset step out bits. st.step_outbits = 0; @@ -365,7 +365,7 @@ static void stepper_pulse_func() { NOP(); // spin here until time to turn off step } - MotorsManager::Unstep(); + CNCMachine::fMotorsManager.Unstep(); break; case ST_RMT: break; @@ -398,7 +398,7 @@ void st_wake_up() { // MessageSender::SendMessage(EMessageLevel::Info, "st_wake_up"); // Enable stepper drivers. - MotorsManager::SetDisable(false); + CNCMachine::fMotorsManager.SetDisable(false); stepper_idle = false; // Initialize step pulse timing from settings. Here to ensure updating after re-writing. @@ -454,7 +454,7 @@ void st_go_idle() if (sys.state == State::Sleep || sys_rt_exec_alarm != EAlarm::None) { - MotorsManager::SetDisable(true); + CNCMachine::fMotorsManager.SetDisable(true); } else { @@ -465,10 +465,10 @@ void st_go_idle() } else { - MotorsManager::SetDisable(false); + CNCMachine::fMotorsManager.SetDisable(false); } - MotorsManager::Unstep(); + CNCMachine::fMotorsManager.Unstep(); st.step_outbits = 0; }