mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-22 14:12:59 +02:00
Avoid reiterationIteration in spindle names (#530)
This commit is contained in:
@@ -51,7 +51,7 @@ have a single class.
|
||||
- Class names and namespace names are named `CamelCase`. Note that
|
||||
class and namespace names should only start with an `_` if they are
|
||||
(A) not in the global namespace and (b) should otherwise start with a digit.
|
||||
For example `_10VSpindle`.
|
||||
For example `_10V`.
|
||||
- Class member functions should be `snake_case`
|
||||
- Class member variables should be `_snake_case` with a leading `_`.
|
||||
|
||||
|
@@ -87,7 +87,7 @@ void setup() {
|
||||
if (homing_enable->get())
|
||||
sys.state = STATE_ALARM;
|
||||
#endif
|
||||
Spindles::Spindle::spindle_select();
|
||||
Spindles::Spindle::select();
|
||||
#ifdef ENABLE_WIFI
|
||||
wifi_config.begin();
|
||||
#endif
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "10vSpindle.h"
|
||||
|
||||
namespace Spindles {
|
||||
void _10vSpindle::init() {
|
||||
void _10v::init() {
|
||||
get_pins_and_settings(); // these gets the standard PWM settings, but many need to be changed for BESC
|
||||
|
||||
// a couple more pins not inherited from PWM Spindle
|
||||
@@ -48,8 +48,8 @@ namespace Spindles {
|
||||
return; // We cannot continue without the output pin
|
||||
}
|
||||
|
||||
ledcSetup(_spindle_pwm_chan_num, (double)_pwm_freq, _pwm_precision); // setup the channel
|
||||
ledcAttachPin(_output_pin, _spindle_pwm_chan_num); // attach the PWM to the pin
|
||||
ledcSetup(_pwm_chan_num, (double)_pwm_freq, _pwm_precision); // setup the channel
|
||||
ledcAttachPin(_output_pin, _pwm_chan_num); // attach the PWM to the pin
|
||||
|
||||
pinMode(_enable_pin, OUTPUT);
|
||||
pinMode(_direction_pin, OUTPUT);
|
||||
@@ -65,7 +65,7 @@ namespace Spindles {
|
||||
}
|
||||
|
||||
// prints the startup message of the spindle config
|
||||
void _10vSpindle::config_message() {
|
||||
void _10v::config_message() {
|
||||
grbl_msg_sendf(CLIENT_SERIAL,
|
||||
MSG_LEVEL_INFO,
|
||||
"0-10V spindle Out:%s Enbl:%s, Dir:%s, Fwd:%s, Rev:%s, Freq:%dHz Res:%dbits",
|
||||
@@ -78,7 +78,7 @@ namespace Spindles {
|
||||
_pwm_precision);
|
||||
}
|
||||
|
||||
uint32_t _10vSpindle::set_rpm(uint32_t rpm) {
|
||||
uint32_t _10v::set_rpm(uint32_t rpm) {
|
||||
uint32_t pwm_value;
|
||||
|
||||
if (_output_pin == UNDEFINED_PIN)
|
||||
@@ -104,7 +104,7 @@ namespace Spindles {
|
||||
return rpm;
|
||||
}
|
||||
/*
|
||||
void _10vSpindle::set_state(uint8_t state, uint32_t rpm) {
|
||||
void _10v::set_state(uint8_t state, uint32_t rpm) {
|
||||
if (sys.abort)
|
||||
return; // Block during abort.
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace Spindles {
|
||||
sys.spindle_speed = 0;
|
||||
stop();
|
||||
} else {
|
||||
set_spindle_dir_pin(state == SPINDLE_ENABLE_CW);
|
||||
set_dir_pin(state == SPINDLE_ENABLE_CW);
|
||||
set_rpm(rpm);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Spindles {
|
||||
|
||||
*/
|
||||
|
||||
uint8_t _10vSpindle::get_state() {
|
||||
uint8_t _10v::get_state() {
|
||||
if (_current_pwm_duty == 0 || _output_pin == UNDEFINED_PIN)
|
||||
return (SPINDLE_STATE_DISABLE);
|
||||
if (_direction_pin != UNDEFINED_PIN)
|
||||
@@ -131,14 +131,14 @@ namespace Spindles {
|
||||
return (SPINDLE_STATE_CW);
|
||||
}
|
||||
|
||||
void _10vSpindle::stop() {
|
||||
void _10v::stop() {
|
||||
// inverts are delt with in methods
|
||||
set_enable_pin(false);
|
||||
set_output(_pwm_off_value);
|
||||
}
|
||||
|
||||
void _10vSpindle::set_enable_pin(bool enable) {
|
||||
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "_10vSpindle::set_enable_pin");
|
||||
void _10v::set_enable_pin(bool enable) {
|
||||
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Spindle::_10v::set_enable_pin");
|
||||
if (_off_with_zero_speed && sys.spindle_speed == 0)
|
||||
enable = false;
|
||||
|
||||
@@ -155,8 +155,8 @@ namespace Spindles {
|
||||
}
|
||||
}
|
||||
|
||||
void _10vSpindle::set_spindle_dir_pin(bool Clockwise) {
|
||||
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "_10vSpindle::set_spindle_dir_pin");
|
||||
void _10v::set_dir_pin(bool Clockwise) {
|
||||
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Spindle::_10v::set_dir_pin");
|
||||
digitalWrite(_direction_pin, Clockwise);
|
||||
digitalWrite(_forward_pin, Clockwise);
|
||||
digitalWrite(_reverse_pin, !Clockwise);
|
||||
|
@@ -29,14 +29,14 @@
|
||||
#include "PWMSpindle.h"
|
||||
|
||||
namespace Spindles {
|
||||
class _10vSpindle : public PWMSpindle {
|
||||
class _10v : public PWM {
|
||||
public:
|
||||
_10vSpindle() = default;
|
||||
_10v() = default;
|
||||
|
||||
_10vSpindle(const _10vSpindle&) = delete;
|
||||
_10vSpindle(_10vSpindle&&) = delete;
|
||||
_10vSpindle& operator=(const _10vSpindle&) = delete;
|
||||
_10vSpindle& operator=(_10vSpindle&&) = delete;
|
||||
_10v(const _10v&) = delete;
|
||||
_10v(_10v&&) = delete;
|
||||
_10v& operator=(const _10v&) = delete;
|
||||
_10v& operator=(_10v&&) = delete;
|
||||
|
||||
void init() override;
|
||||
void config_message() override;
|
||||
@@ -46,13 +46,13 @@ namespace Spindles {
|
||||
uint8_t get_state() override;
|
||||
void stop() override;
|
||||
|
||||
virtual ~_10vSpindle() {}
|
||||
virtual ~_10v() {}
|
||||
|
||||
uint8_t _forward_pin;
|
||||
uint8_t _reverse_pin;
|
||||
|
||||
protected:
|
||||
void set_enable_pin(bool enable_pin) override;
|
||||
void set_spindle_dir_pin(bool Clockwise) override;
|
||||
void set_dir_pin(bool Clockwise) override;
|
||||
};
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@
|
||||
#define BESC_MAX_PULSE_CNT (uint16_t)(BESC_MAX_PULSE_SECS / BESC_PULSE_PERIOD * 65535.0)
|
||||
|
||||
namespace Spindles {
|
||||
void BESCSpindle::init() {
|
||||
void BESC::init() {
|
||||
get_pins_and_settings(); // these gets the standard PWM settings, but many need to be changed for BESC
|
||||
|
||||
if (_output_pin == UNDEFINED_PIN) {
|
||||
@@ -69,8 +69,8 @@ namespace Spindles {
|
||||
_pwm_min_value = _pwm_off_value;
|
||||
_pwm_max_value = BESC_MAX_PULSE_CNT;
|
||||
|
||||
ledcSetup(_spindle_pwm_chan_num, (double)_pwm_freq, _pwm_precision); // setup the channel
|
||||
ledcAttachPin(_output_pin, _spindle_pwm_chan_num); // attach the PWM to the pin
|
||||
ledcSetup(_pwm_chan_num, (double)_pwm_freq, _pwm_precision); // setup the channel
|
||||
ledcAttachPin(_output_pin, _pwm_chan_num); // attach the PWM to the pin
|
||||
|
||||
pinMode(_enable_pin, OUTPUT);
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Spindles {
|
||||
}
|
||||
|
||||
// prints the startup message of the spindle config
|
||||
void BESCSpindle::config_message() {
|
||||
void BESC::config_message() {
|
||||
grbl_msg_sendf(CLIENT_SERIAL,
|
||||
MSG_LEVEL_INFO,
|
||||
"BESC spindle on Pin:%s Min:%0.2fms Max:%0.2fms Freq:%dHz Res:%dbits",
|
||||
@@ -93,7 +93,7 @@ namespace Spindles {
|
||||
_pwm_precision);
|
||||
}
|
||||
|
||||
uint32_t BESCSpindle::set_rpm(uint32_t rpm) {
|
||||
uint32_t BESC::set_rpm(uint32_t rpm) {
|
||||
uint32_t pwm_value;
|
||||
|
||||
if (_output_pin == UNDEFINED_PIN)
|
||||
|
@@ -36,19 +36,19 @@
|
||||
#include "PWMSpindle.h"
|
||||
|
||||
namespace Spindles {
|
||||
class BESCSpindle : public PWMSpindle {
|
||||
class BESC : public PWM {
|
||||
public:
|
||||
BESCSpindle() = default;
|
||||
BESC() = default;
|
||||
|
||||
BESCSpindle(const BESCSpindle&) = delete;
|
||||
BESCSpindle(BESCSpindle&&) = delete;
|
||||
BESCSpindle& operator=(const BESCSpindle&) = delete;
|
||||
BESCSpindle& operator=(BESCSpindle&&) = delete;
|
||||
BESC(const BESC&) = delete;
|
||||
BESC(BESC&&) = delete;
|
||||
BESC& operator=(const BESC&) = delete;
|
||||
BESC& operator=(BESC&&) = delete;
|
||||
|
||||
void init() override;
|
||||
void config_message() override;
|
||||
uint32_t set_rpm(uint32_t rpm) override;
|
||||
|
||||
virtual ~BESCSpindle() {}
|
||||
virtual ~BESC() {}
|
||||
};
|
||||
}
|
||||
|
@@ -24,8 +24,8 @@
|
||||
#include "DacSpindle.h"
|
||||
|
||||
namespace Spindles {
|
||||
// ======================================== DacSpindle ======================================
|
||||
void DacSpindle::init() {
|
||||
// ======================================== Dac ======================================
|
||||
void Dac::init() {
|
||||
get_pins_and_settings();
|
||||
|
||||
if (_output_pin == UNDEFINED_PIN)
|
||||
@@ -52,7 +52,7 @@ namespace Spindles {
|
||||
config_message();
|
||||
}
|
||||
|
||||
void DacSpindle::config_message() {
|
||||
void Dac::config_message() {
|
||||
grbl_msg_sendf(CLIENT_SERIAL,
|
||||
MSG_LEVEL_INFO,
|
||||
"DAC spindle Output:%s, Enbl:%s, Dir:%s, Res:8bits",
|
||||
@@ -61,7 +61,7 @@ namespace Spindles {
|
||||
pinName(_direction_pin).c_str());
|
||||
}
|
||||
|
||||
uint32_t DacSpindle::set_rpm(uint32_t rpm) {
|
||||
uint32_t Dac::set_rpm(uint32_t rpm) {
|
||||
if (_output_pin == UNDEFINED_PIN)
|
||||
return rpm;
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace Spindles {
|
||||
return rpm;
|
||||
}
|
||||
|
||||
void DacSpindle::set_output(uint32_t duty) {
|
||||
void Dac::set_output(uint32_t duty) {
|
||||
if (_gpio_ok) {
|
||||
dacWrite(_output_pin, (uint8_t)duty);
|
||||
}
|
||||
|
@@ -28,20 +28,20 @@
|
||||
|
||||
namespace Spindles {
|
||||
// This uses one of the (2) DAC pins on ESP32 to output a voltage
|
||||
class DacSpindle : public PWMSpindle {
|
||||
class Dac : public PWM {
|
||||
public:
|
||||
DacSpindle() = default;
|
||||
Dac() = default;
|
||||
|
||||
DacSpindle(const DacSpindle&) = delete;
|
||||
DacSpindle(DacSpindle&&) = delete;
|
||||
DacSpindle& operator=(const DacSpindle&) = delete;
|
||||
DacSpindle& operator=(DacSpindle&&) = delete;
|
||||
Dac(const Dac&) = delete;
|
||||
Dac(Dac&&) = delete;
|
||||
Dac& operator=(const Dac&) = delete;
|
||||
Dac& operator=(Dac&&) = delete;
|
||||
|
||||
void init() override;
|
||||
void config_message() override;
|
||||
uint32_t set_rpm(uint32_t rpm) override;
|
||||
|
||||
virtual ~DacSpindle() {}
|
||||
virtual ~Dac() {}
|
||||
|
||||
private:
|
||||
bool _gpio_ok; // DAC is on a valid pin
|
||||
|
@@ -155,7 +155,7 @@ namespace Spindles {
|
||||
|
||||
static TaskHandle_t vfd_cmdTaskHandle = 0;
|
||||
|
||||
bool hy_spindle_ok = true;
|
||||
bool hy_ok = true;
|
||||
|
||||
// The communications task
|
||||
void vfd_cmd_task(void* pvParameters) {
|
||||
@@ -190,7 +190,7 @@ namespace Spindles {
|
||||
}
|
||||
|
||||
} else {
|
||||
HuanyangSpindle::read_value(reg_item); // only this appears to work all the time. Other registers are flakey.
|
||||
Huanyang::read_value(reg_item); // only this appears to work all the time. Other registers are flakey.
|
||||
if (reg_item < 0x03)
|
||||
reg_item++;
|
||||
else {
|
||||
@@ -203,8 +203,8 @@ namespace Spindles {
|
||||
|
||||
// ================== Class methods ==================================
|
||||
|
||||
void HuanyangSpindle::init() {
|
||||
hy_spindle_ok = true; // initialize
|
||||
void Huanyang::init() {
|
||||
hy_ok = true; // initialize
|
||||
|
||||
// fail if required items are not defined
|
||||
if (!get_pins_and_settings()) {
|
||||
@@ -259,49 +259,49 @@ namespace Spindles {
|
||||
// Checks for all the required pin definitions
|
||||
// It returns a message for each missing pin
|
||||
// Returns true if all pins are defined.
|
||||
bool HuanyangSpindle::get_pins_and_settings() {
|
||||
bool Huanyang::get_pins_and_settings() {
|
||||
#ifdef HUANYANG_TXD_PIN
|
||||
_txd_pin = HUANYANG_TXD_PIN;
|
||||
#else
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Undefined HUANYANG_TXD_PIN");
|
||||
hy_spindle_ok = false;
|
||||
hy_ok = false;
|
||||
#endif
|
||||
|
||||
#ifdef HUANYANG_RXD_PIN
|
||||
_rxd_pin = HUANYANG_RXD_PIN;
|
||||
#else
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Undefined HUANYANG_RXD_PIN");
|
||||
hy_spindle_ok = false;
|
||||
hy_ok = false;
|
||||
#endif
|
||||
|
||||
#ifdef HUANYANG_RTS_PIN
|
||||
_rts_pin = HUANYANG_RTS_PIN;
|
||||
#else
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Undefined HUANYANG_RTS_PIN");
|
||||
hy_spindle_ok = false;
|
||||
hy_ok = false;
|
||||
#endif
|
||||
|
||||
if (laser_mode->get()) {
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Huanyang spindle disabled in laser mode. Set $GCode/LaserMode=Off and restart");
|
||||
hy_spindle_ok = false;
|
||||
hy_ok = false;
|
||||
}
|
||||
|
||||
_min_rpm = rpm_min->get();
|
||||
_max_rpm = rpm_max->get();
|
||||
|
||||
return hy_spindle_ok;
|
||||
return hy_ok;
|
||||
}
|
||||
|
||||
void HuanyangSpindle::config_message() {
|
||||
void Huanyang::config_message() {
|
||||
grbl_msg_sendf(CLIENT_SERIAL,
|
||||
MSG_LEVEL_INFO,
|
||||
"Huanyang Spindle Tx:%s Rx:%s RTS:%s",
|
||||
"Huanyang Tx:%s Rx:%s RTS:%s",
|
||||
pinName(_txd_pin).c_str(),
|
||||
pinName(_rxd_pin).c_str(),
|
||||
pinName(_rts_pin).c_str());
|
||||
}
|
||||
|
||||
void HuanyangSpindle::set_state(uint8_t state, uint32_t rpm) {
|
||||
void Huanyang::set_state(uint8_t state, uint32_t rpm) {
|
||||
if (sys.abort)
|
||||
return; // Block during abort.
|
||||
|
||||
@@ -330,8 +330,8 @@ namespace Spindles {
|
||||
return;
|
||||
}
|
||||
|
||||
bool HuanyangSpindle::set_mode(uint8_t mode, bool critical) {
|
||||
if (!hy_spindle_ok)
|
||||
bool Huanyang::set_mode(uint8_t mode, bool critical) {
|
||||
if (!hy_ok)
|
||||
return false;
|
||||
|
||||
hy_command_t mode_cmd;
|
||||
@@ -365,8 +365,8 @@ namespace Spindles {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t HuanyangSpindle::set_rpm(uint32_t rpm) {
|
||||
if (!hy_spindle_ok)
|
||||
uint32_t Huanyang::set_rpm(uint32_t rpm) {
|
||||
if (!hy_ok)
|
||||
return 0;
|
||||
|
||||
hy_command_t rpm_cmd;
|
||||
@@ -412,7 +412,7 @@ namespace Spindles {
|
||||
}
|
||||
|
||||
// This appears to read the control register and will return an RPM running or not.
|
||||
void HuanyangSpindle::read_value(uint8_t reg) {
|
||||
void Huanyang::read_value(uint8_t reg) {
|
||||
uint16_t ret_value = 0;
|
||||
hy_command_t read_cmd;
|
||||
uint8_t rx_message[HUANYANG_MAX_MSG_SIZE];
|
||||
@@ -437,16 +437,16 @@ namespace Spindles {
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "VFD Queue Full");
|
||||
}
|
||||
|
||||
void HuanyangSpindle::stop() { set_mode(SPINDLE_DISABLE, false); }
|
||||
void Huanyang::stop() { set_mode(SPINDLE_DISABLE, false); }
|
||||
|
||||
// state is cached rather than read right now to prevent delays
|
||||
uint8_t HuanyangSpindle::get_state() { return _state; }
|
||||
uint8_t Huanyang::get_state() { return _state; }
|
||||
|
||||
// Calculate the CRC on all of the byte except the last 2
|
||||
// It then added the CRC to those last 2 bytes
|
||||
// full_msg_len This is the length of the message including the 2 crc bytes
|
||||
// Source: https://ctlsys.com/support/how_to_compute_the_modbus_rtu_message_crc/
|
||||
void HuanyangSpindle::add_ModRTU_CRC(char* buf, int full_msg_len) {
|
||||
void Huanyang::add_ModRTU_CRC(char* buf, int full_msg_len) {
|
||||
uint16_t crc = 0xFFFF;
|
||||
for (int pos = 0; pos < full_msg_len - 2; pos++) {
|
||||
crc ^= (uint16_t)buf[pos]; // XOR byte into least sig. byte of crc
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#include "Spindle.h"
|
||||
|
||||
namespace Spindles {
|
||||
class HuanyangSpindle : public Spindle {
|
||||
class Huanyang : public Spindle {
|
||||
private:
|
||||
uint16_t ModRTU_CRC(char* buf, int len);
|
||||
|
||||
@@ -37,12 +37,12 @@ namespace Spindles {
|
||||
bool _task_running;
|
||||
|
||||
public:
|
||||
HuanyangSpindle() : _task_running(false) {}
|
||||
Huanyang() : _task_running(false) {}
|
||||
|
||||
HuanyangSpindle(const HuanyangSpindle&) = delete;
|
||||
HuanyangSpindle(HuanyangSpindle&&) = delete;
|
||||
HuanyangSpindle& operator=(const HuanyangSpindle&) = delete;
|
||||
HuanyangSpindle& operator=(HuanyangSpindle&&) = delete;
|
||||
Huanyang(const Huanyang&) = delete;
|
||||
Huanyang(Huanyang&&) = delete;
|
||||
Huanyang& operator=(const Huanyang&) = delete;
|
||||
Huanyang& operator=(Huanyang&&) = delete;
|
||||
|
||||
void init();
|
||||
void config_message();
|
||||
@@ -53,7 +53,7 @@ namespace Spindles {
|
||||
static void read_value(uint8_t reg);
|
||||
static void add_ModRTU_CRC(char* buf, int full_msg_len);
|
||||
|
||||
virtual ~HuanyangSpindle() {}
|
||||
virtual ~Huanyang() {}
|
||||
|
||||
protected:
|
||||
uint32_t _min_rpm;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Laser.cpp
|
||||
|
||||
This is similar the the PWM Spindle except that it allows the
|
||||
This is similar to the PWM Spindle except that it allows the
|
||||
M4 speed vs. power copensation.
|
||||
|
||||
Part of Grbl_ESP32
|
||||
@@ -37,6 +37,6 @@ namespace Spindles {
|
||||
_pwm_precision,
|
||||
isRateAdjusted()); // the current mode
|
||||
|
||||
use_delays = false; // this will override the value set in PWMSpindle intit()
|
||||
use_delays = false; // this will override the value set in Spindle::PWM::init()
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
Laser.h
|
||||
|
||||
This is similar the the PWM Spindle except that it allows the
|
||||
This is similar to the PWM Spindle except that it allows the
|
||||
M4 speed vs. power copensation.
|
||||
|
||||
Part of Grbl_ESP32
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
namespace Spindles {
|
||||
// this is the same as a PWM spindle but the M4 compensation is supported.
|
||||
class Laser : public PWMSpindle {
|
||||
class Laser : public PWM {
|
||||
public:
|
||||
Laser() = default;
|
||||
|
||||
|
@@ -22,17 +22,17 @@
|
||||
#include "NullSpindle.h"
|
||||
|
||||
namespace Spindles {
|
||||
// ======================= NullSpindle ==============================
|
||||
// NullSpindle is just bunch of do nothing (ignore) methods to be used when you don't want a spindle
|
||||
// ======================= Null ==============================
|
||||
// Null is just bunch of do nothing (ignore) methods to be used when you don't want a spindle
|
||||
|
||||
void NullSpindle::init() {
|
||||
void Null::init() {
|
||||
is_reversable = false;
|
||||
use_delays = false;
|
||||
config_message();
|
||||
}
|
||||
uint32_t NullSpindle::set_rpm(uint32_t rpm) { return rpm; }
|
||||
void NullSpindle::set_state(uint8_t state, uint32_t rpm) {}
|
||||
uint8_t NullSpindle::get_state() { return (SPINDLE_STATE_DISABLE); }
|
||||
void NullSpindle::stop() {}
|
||||
void NullSpindle::config_message() { grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "No spindle"); }
|
||||
uint32_t Null::set_rpm(uint32_t rpm) { return rpm; }
|
||||
void Null::set_state(uint8_t state, uint32_t rpm) {}
|
||||
uint8_t Null::get_state() { return (SPINDLE_STATE_DISABLE); }
|
||||
void Null::stop() {}
|
||||
void Null::config_message() { grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "No spindle"); }
|
||||
}
|
||||
|
@@ -26,14 +26,14 @@
|
||||
namespace Spindles {
|
||||
// This is a dummy spindle that has no I/O.
|
||||
// It is used to ignore spindle commands when no spinde is desired
|
||||
class NullSpindle : public Spindle {
|
||||
class Null : public Spindle {
|
||||
public:
|
||||
NullSpindle() = default;
|
||||
Null() = default;
|
||||
|
||||
NullSpindle(const NullSpindle&) = delete;
|
||||
NullSpindle(NullSpindle&&) = delete;
|
||||
NullSpindle& operator=(const NullSpindle&) = delete;
|
||||
NullSpindle& operator=(NullSpindle&&) = delete;
|
||||
Null(const Null&) = delete;
|
||||
Null(Null&&) = delete;
|
||||
Null& operator=(const Null&) = delete;
|
||||
Null& operator=(Null&&) = delete;
|
||||
|
||||
void init() override;
|
||||
uint32_t set_rpm(uint32_t rpm) override;
|
||||
@@ -42,6 +42,6 @@ namespace Spindles {
|
||||
void stop() override;
|
||||
void config_message() override;
|
||||
|
||||
virtual ~NullSpindle() {}
|
||||
virtual ~Null() {}
|
||||
};
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
#include "PWMSpindle.h"
|
||||
|
||||
// ======================= PWMSpindle ==============================
|
||||
// ======================= PWM ==============================
|
||||
/*
|
||||
This gets called at startup or whenever a spindle setting changes
|
||||
If the spindle is running it will stop and need to be restarted with M3Snnnn
|
||||
@@ -30,7 +30,7 @@
|
||||
//#include "grbl.h"
|
||||
|
||||
namespace Spindles {
|
||||
void PWMSpindle::init() {
|
||||
void PWM::init() {
|
||||
get_pins_and_settings();
|
||||
|
||||
if (_output_pin == UNDEFINED_PIN) {
|
||||
@@ -43,8 +43,8 @@ namespace Spindles {
|
||||
return;
|
||||
}
|
||||
|
||||
ledcSetup(_spindle_pwm_chan_num, (double)_pwm_freq, _pwm_precision); // setup the channel
|
||||
ledcAttachPin(_output_pin, _spindle_pwm_chan_num); // attach the PWM to the pin
|
||||
ledcSetup(_pwm_chan_num, (double)_pwm_freq, _pwm_precision); // setup the channel
|
||||
ledcAttachPin(_output_pin, _pwm_chan_num); // attach the PWM to the pin
|
||||
|
||||
pinMode(_enable_pin, OUTPUT);
|
||||
pinMode(_direction_pin, OUTPUT);
|
||||
@@ -55,7 +55,7 @@ namespace Spindles {
|
||||
}
|
||||
|
||||
// Get the GPIO from the machine definition
|
||||
void PWMSpindle::get_pins_and_settings() {
|
||||
void PWM::get_pins_and_settings() {
|
||||
// setup all the pins
|
||||
|
||||
#ifdef SPINDLE_OUTPUT_PIN
|
||||
@@ -112,10 +112,10 @@ namespace Spindles {
|
||||
// The pwm_gradient is the pwm duty cycle units per rpm
|
||||
// _pwm_gradient = (_pwm_max_value - _pwm_min_value) / (_max_rpm - _min_rpm);
|
||||
|
||||
_spindle_pwm_chan_num = 0; // Channel 0 is reserved for spindle use
|
||||
_pwm_chan_num = 0; // Channel 0 is reserved for spindle use
|
||||
}
|
||||
|
||||
uint32_t PWMSpindle::set_rpm(uint32_t rpm) {
|
||||
uint32_t PWM::set_rpm(uint32_t rpm) {
|
||||
uint32_t pwm_value;
|
||||
|
||||
if (_output_pin == UNDEFINED_PIN)
|
||||
@@ -151,7 +151,7 @@ namespace Spindles {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PWMSpindle::set_state(uint8_t state, uint32_t rpm) {
|
||||
void PWM::set_state(uint8_t state, uint32_t rpm) {
|
||||
if (sys.abort)
|
||||
return; // Block during abort.
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace Spindles {
|
||||
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "SpinDown Done");
|
||||
}
|
||||
} else {
|
||||
set_spindle_dir_pin(state == SPINDLE_ENABLE_CW);
|
||||
set_dir_pin(state == SPINDLE_ENABLE_CW);
|
||||
set_rpm(rpm);
|
||||
set_enable_pin(state != SPINDLE_DISABLE); // must be done after setting rpm for enable features to work
|
||||
if (use_delays && (_current_state != state)) {
|
||||
@@ -179,7 +179,7 @@ namespace Spindles {
|
||||
sys.report_ovr_counter = 0; // Set to report change immediately
|
||||
}
|
||||
|
||||
uint8_t PWMSpindle::get_state() {
|
||||
uint8_t PWM::get_state() {
|
||||
if (_current_pwm_duty == 0 || _output_pin == UNDEFINED_PIN)
|
||||
return (SPINDLE_STATE_DISABLE);
|
||||
if (_direction_pin != UNDEFINED_PIN)
|
||||
@@ -187,14 +187,14 @@ namespace Spindles {
|
||||
return (SPINDLE_STATE_CW);
|
||||
}
|
||||
|
||||
void PWMSpindle::stop() {
|
||||
void PWM::stop() {
|
||||
// inverts are delt with in methods
|
||||
set_enable_pin(false);
|
||||
set_output(_pwm_off_value);
|
||||
}
|
||||
|
||||
// prints the startup message of the spindle config
|
||||
void PWMSpindle::config_message() {
|
||||
void PWM::config_message() {
|
||||
grbl_msg_sendf(CLIENT_SERIAL,
|
||||
MSG_LEVEL_INFO,
|
||||
"PWM spindle Output:%s, Enbl:%s, Dir:%s, Freq:%dHz, Res:%dbits",
|
||||
@@ -205,7 +205,7 @@ namespace Spindles {
|
||||
_pwm_precision);
|
||||
}
|
||||
|
||||
void PWMSpindle::set_output(uint32_t duty) {
|
||||
void PWM::set_output(uint32_t duty) {
|
||||
if (_output_pin == UNDEFINED_PIN)
|
||||
return;
|
||||
|
||||
@@ -220,10 +220,10 @@ namespace Spindles {
|
||||
|
||||
//grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "set_output(%d)", duty);
|
||||
|
||||
ledcWrite(_spindle_pwm_chan_num, duty);
|
||||
ledcWrite(_pwm_chan_num, duty);
|
||||
}
|
||||
|
||||
void PWMSpindle::set_enable_pin(bool enable) {
|
||||
void PWM::set_enable_pin(bool enable) {
|
||||
if (_enable_pin == UNDEFINED_PIN)
|
||||
return;
|
||||
|
||||
@@ -238,7 +238,7 @@ namespace Spindles {
|
||||
digitalWrite(_enable_pin, enable);
|
||||
}
|
||||
|
||||
void PWMSpindle::set_spindle_dir_pin(bool Clockwise) { digitalWrite(_direction_pin, Clockwise); }
|
||||
void PWM::set_dir_pin(bool Clockwise) { digitalWrite(_direction_pin, Clockwise); }
|
||||
|
||||
/*
|
||||
Calculate the highest precision of a PWM based on the frequency in bits
|
||||
@@ -246,7 +246,7 @@ namespace Spindles {
|
||||
80,000,000 / freq = period
|
||||
determine the highest precision where (1 << precision) < period
|
||||
*/
|
||||
uint8_t PWMSpindle::calc_pwm_precision(uint32_t freq) {
|
||||
uint8_t PWM::calc_pwm_precision(uint32_t freq) {
|
||||
uint8_t precision = 0;
|
||||
|
||||
// increase the precision (bits) until it exceeds allow by frequency the max or is 16
|
||||
|
@@ -25,14 +25,14 @@
|
||||
|
||||
namespace Spindles {
|
||||
// This adds support for PWM
|
||||
class PWMSpindle : public Spindle {
|
||||
class PWM : public Spindle {
|
||||
public:
|
||||
PWMSpindle() = default;
|
||||
PWM() = default;
|
||||
|
||||
PWMSpindle(const PWMSpindle&) = delete;
|
||||
PWMSpindle(PWMSpindle&&) = delete;
|
||||
PWMSpindle& operator=(const PWMSpindle&) = delete;
|
||||
PWMSpindle& operator=(PWMSpindle&&) = delete;
|
||||
PWM(const PWM&) = delete;
|
||||
PWM(PWM&&) = delete;
|
||||
PWM& operator=(const PWM&) = delete;
|
||||
PWM& operator=(PWM&&) = delete;
|
||||
|
||||
void init() override;
|
||||
virtual uint32_t set_rpm(uint32_t rpm) override;
|
||||
@@ -41,7 +41,7 @@ namespace Spindles {
|
||||
void stop() override;
|
||||
void config_message() override;
|
||||
|
||||
virtual ~PWMSpindle() {}
|
||||
virtual ~PWM() {}
|
||||
|
||||
protected:
|
||||
int32_t _current_pwm_duty;
|
||||
@@ -53,7 +53,7 @@ namespace Spindles {
|
||||
uint8_t _output_pin;
|
||||
uint8_t _enable_pin;
|
||||
uint8_t _direction_pin;
|
||||
uint8_t _spindle_pwm_chan_num;
|
||||
uint8_t _pwm_chan_num;
|
||||
uint32_t _pwm_freq;
|
||||
uint32_t _pwm_period; // how many counts in 1 period
|
||||
uint8_t _pwm_precision;
|
||||
@@ -62,7 +62,7 @@ namespace Spindles {
|
||||
bool _invert_pwm;
|
||||
//uint32_t _pwm_gradient; // Precalulated value to speed up rpm to PWM conversions.
|
||||
|
||||
virtual void set_spindle_dir_pin(bool Clockwise);
|
||||
virtual void set_dir_pin(bool Clockwise);
|
||||
virtual void set_output(uint32_t duty);
|
||||
virtual void set_enable_pin(bool enable_pin);
|
||||
|
||||
|
@@ -21,13 +21,13 @@
|
||||
*/
|
||||
#include "RelaySpindle.h"
|
||||
|
||||
// ========================= RelaySpindle ==================================
|
||||
// ========================= Relay ==================================
|
||||
|
||||
namespace Spindles {
|
||||
/*
|
||||
This is a sub class of PWMSpindle but is a digital rather than PWM output
|
||||
This is a sub class of PWM but is a digital rather than PWM output
|
||||
*/
|
||||
void RelaySpindle::init() {
|
||||
void Relay::init() {
|
||||
get_pins_and_settings();
|
||||
|
||||
if (_output_pin == UNDEFINED_PIN)
|
||||
@@ -44,7 +44,7 @@ namespace Spindles {
|
||||
}
|
||||
|
||||
// prints the startup message of the spindle config
|
||||
void RelaySpindle ::config_message() {
|
||||
void Relay ::config_message() {
|
||||
grbl_msg_sendf(CLIENT_SERIAL,
|
||||
MSG_LEVEL_INFO,
|
||||
"Relay spindle Output:%s, Enbl:%s, Dir:%s",
|
||||
@@ -53,7 +53,7 @@ namespace Spindles {
|
||||
pinName(_direction_pin).c_str());
|
||||
}
|
||||
|
||||
uint32_t RelaySpindle::set_rpm(uint32_t rpm) {
|
||||
uint32_t Relay::set_rpm(uint32_t rpm) {
|
||||
if (_output_pin == UNDEFINED_PIN)
|
||||
return rpm;
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Spindles {
|
||||
return rpm;
|
||||
}
|
||||
|
||||
void RelaySpindle::set_output(uint32_t duty) {
|
||||
void Relay::set_output(uint32_t duty) {
|
||||
#ifdef INVERT_SPINDLE_PWM
|
||||
duty = (duty == 0); // flip duty
|
||||
#endif
|
||||
|
@@ -25,20 +25,20 @@
|
||||
|
||||
namespace Spindles {
|
||||
// This is for an on/off spindle all RPMs above 0 are on
|
||||
class RelaySpindle : public PWMSpindle {
|
||||
class Relay : public PWM {
|
||||
public:
|
||||
RelaySpindle() = default;
|
||||
Relay() = default;
|
||||
|
||||
RelaySpindle(const RelaySpindle&) = delete;
|
||||
RelaySpindle(RelaySpindle&&) = delete;
|
||||
RelaySpindle& operator=(const RelaySpindle&) = delete;
|
||||
RelaySpindle& operator=(RelaySpindle&&) = delete;
|
||||
Relay(const Relay&) = delete;
|
||||
Relay(Relay&&) = delete;
|
||||
Relay& operator=(const Relay&) = delete;
|
||||
Relay& operator=(Relay&&) = delete;
|
||||
|
||||
void init() override;
|
||||
void config_message() override;
|
||||
uint32_t set_rpm(uint32_t rpm) override;
|
||||
|
||||
virtual ~RelaySpindle() {}
|
||||
virtual ~Relay() {}
|
||||
|
||||
protected:
|
||||
void set_output(uint32_t duty);
|
||||
|
@@ -41,26 +41,26 @@
|
||||
namespace Spindles {
|
||||
// An instance of each type of spindle is created here.
|
||||
// This allows the spindle to be dynamicly switched
|
||||
NullSpindle null_spindle;
|
||||
PWMSpindle pwm_spindle;
|
||||
RelaySpindle relay_spindle;
|
||||
Null null;
|
||||
PWM pwm;
|
||||
Relay relay;
|
||||
Laser laser;
|
||||
DacSpindle dac_spindle;
|
||||
HuanyangSpindle huanyang_spindle;
|
||||
BESCSpindle besc_spindle;
|
||||
_10vSpindle _10v_spindle;
|
||||
Dac dac;
|
||||
Huanyang huanyang;
|
||||
BESC besc;
|
||||
_10v _10v;
|
||||
|
||||
void Spindle::spindle_select() {
|
||||
void Spindle::select() {
|
||||
switch (spindle_type->get()) {
|
||||
case SPINDLE_TYPE_PWM: spindle = &pwm_spindle; break;
|
||||
case SPINDLE_TYPE_RELAY: spindle = &relay_spindle; break;
|
||||
case SPINDLE_TYPE_PWM: spindle = &pwm; break;
|
||||
case SPINDLE_TYPE_RELAY: spindle = &relay; break;
|
||||
case SPINDLE_TYPE_LASER: spindle = &laser; break;
|
||||
case SPINDLE_TYPE_DAC: spindle = &dac_spindle; break;
|
||||
case SPINDLE_TYPE_HUANYANG: spindle = &huanyang_spindle; break;
|
||||
case SPINDLE_TYPE_BESC: spindle = &besc_spindle; break;
|
||||
case SPINDLE_TYPE_10V: spindle = &_10v_spindle; break;
|
||||
case SPINDLE_TYPE_DAC: spindle = &dac; break;
|
||||
case SPINDLE_TYPE_HUANYANG: spindle = &huanyang; break;
|
||||
case SPINDLE_TYPE_BESC: spindle = &besc; break;
|
||||
case SPINDLE_TYPE_10V: spindle = &_10v; break;
|
||||
case SPINDLE_TYPE_NONE:
|
||||
default: spindle = &null_spindle; break;
|
||||
default: spindle = &null; break;
|
||||
}
|
||||
|
||||
spindle->init();
|
||||
@@ -72,7 +72,7 @@ namespace Spindles {
|
||||
return false; // default for basic spindle is false
|
||||
}
|
||||
|
||||
void Spindle::spindle_sync(uint8_t state, uint32_t rpm) {
|
||||
void Spindle::sync(uint8_t state, uint32_t rpm) {
|
||||
if (sys.state == STATE_CHECK_MODE)
|
||||
return;
|
||||
protocol_buffer_synchronize(); // Empty planner buffer to ensure spindle is set when programmed.
|
||||
|
@@ -64,7 +64,7 @@ namespace Spindles {
|
||||
virtual void stop() = 0;
|
||||
virtual void config_message() = 0;
|
||||
virtual bool isRateAdjusted();
|
||||
virtual void spindle_sync(uint8_t state, uint32_t rpm);
|
||||
virtual void sync(uint8_t state, uint32_t rpm);
|
||||
|
||||
virtual ~Spindle() {}
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Spindles {
|
||||
bool use_delays; // will SpinUp and SpinDown delays be used.
|
||||
uint8_t _current_state;
|
||||
|
||||
static void spindle_select();
|
||||
static void select();
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -1122,9 +1122,9 @@ uint8_t gc_execute_line(char* line, uint8_t client) {
|
||||
if (gc_state.modal.spindle != SPINDLE_DISABLE) {
|
||||
if (bit_isfalse(gc_parser_flags, GC_PARSER_LASER_ISMOTION)) {
|
||||
if (bit_istrue(gc_parser_flags, GC_PARSER_LASER_DISABLE))
|
||||
spindle->spindle_sync(gc_state.modal.spindle, 0);
|
||||
spindle->sync(gc_state.modal.spindle, 0);
|
||||
else
|
||||
spindle->spindle_sync(gc_state.modal.spindle, (uint32_t)gc_block.values.s);
|
||||
spindle->sync(gc_state.modal.spindle, (uint32_t)gc_block.values.s);
|
||||
}
|
||||
}
|
||||
gc_state.spindle_speed = gc_block.values.s; // Update spindle speed state.
|
||||
@@ -1146,7 +1146,7 @@ uint8_t 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->spindle_sync(gc_block.modal.spindle, (uint32_t)pl_data->spindle_speed);
|
||||
spindle->sync(gc_block.modal.spindle, (uint32_t)pl_data->spindle_speed);
|
||||
gc_state.modal.spindle = gc_block.modal.spindle;
|
||||
}
|
||||
pl_data->condition |= gc_state.modal.spindle; // Set condition flag for planner use.
|
||||
|
Reference in New Issue
Block a user