diff --git a/Grbl_Esp32/src/DumpConfig.cpp b/Grbl_Esp32/src/DumpConfig.cpp index f5493cdf..07a955be 100644 --- a/Grbl_Esp32/src/DumpConfig.cpp +++ b/Grbl_Esp32/src/DumpConfig.cpp @@ -1,282 +1,482 @@ +#include "Grbl.h" +#include "Motors/Motor.h" +#include "Motors/TrinamicDriver.h" +#include "Motors/TrinamicUartDriver.h" +#include "Motors/Dynamixel2.h" +#include "Motors/Servo.h" +#include "Motors/RcServo.h" +#include "Motors/StandardStepper.h" +#include "Motors/UnipolarMotor.h" +#include "Spindles/Spindle.h" +#include "Spindles/NullSpindle.h" +#include "Spindles/DacSpindle.h" +#include "Spindles/10vSpindle.h" +#include "Spindles/BESCSpindle.h" +#include "Spindles/H2ASpindle.h" +#include "Spindles/HuanyangSpindle.h" +#include "Spindles/PWMSpindle.h" +#include "Spindles/RelaySpindle.h" +#include "Spindles/VFDSpindle.h" +#include "Spindles/YL620Spindle.h" +#include "Spindles/Laser.h" + +using namespace Motors; +using namespace Spindles; + #define p(...) \ do { \ grbl_sendf(CLIENT_SERIAL, __VA_ARGS__); \ - grbl_sendf(CLIENT_SERIAL, "\n"); \ } while (0); -const char* tf(bool v) { return v ? "true" : "false" }; -void print_steps(int axis) { - p(" steps_per_mm: %f", axis_settings[axis]->steps_per_mm->get()); - p(" max_rate: %f", axis_settings[axis]->max_rate->get()); - p(" acceleration: %f", axis_settings[axis]->acceleration->get()); - p(" max_travel: %f", axis_settings[axis]->max_travel->get()); - p(" soft_limits: %s", tf(soft_limits->get())); +const char* tf(bool v) { + return v ? "true" : "false"; +}; +static int indent = 0; +void print_indent() { + for (int i = 0; i < indent; ++i) { + p(" "); + } +} +void section(const char* name) { + print_indent(); + p("%s:\n", name); + indent += 2; +} +void end_section() { + indent -= 2; +} +void item(const char* name, int value) { + print_indent(); + p("%s: %d\n", name, value); +} +void item(const char* name, unsigned int value) { + print_indent(); + p("%s: %u\n", name, value); +} +void item(const char* name, bool value) { + print_indent(); + p("%s: %s\n", name, value ? "true" : "false"); +} +void item(const char* name, const char* value) { + print_indent(); + p("%s: %s\n", name, value); +} +void item(const char* name, float value) { + print_indent(); + p("%s: %0.3f\n", name, value); +} + +const char* pinspec(int pin_number, bool active_low = false, bool pullup = false) { + if (pin_number == -1) { + return "UNSPECIFIED"; + } + if (pin_number == UNDEFINED_PIN) { + return "NO_PIN"; + } + static char temp[50]; + temp[0] = '\0'; + if (pin_number < I2S_OUT_PIN_BASE) { + sprintf(temp, "gpio.%d", pin_number); + } else { + sprintf(temp, "i2so.%d", pin_number - I2S_OUT_PIN_BASE); + } + if (active_low) { + strcat(temp, ":low"); + } + if (pullup) { + strcat(temp, ":pu"); + } + return temp; +} +void print_uart(int portnum, uint8_t txd, uint8_t rxd, uint8_t rts, uint32_t baudrate, const char* mode) { + section("uart"); + item("txd_pin", pinspec(txd)); + item("rxd_pin", pinspec(rxd)); + item("rts_pin", pinspec(rts)); + item("cts_pin", pinspec(UNDEFINED_PIN)); // Nothing in the old code uses CTS + item("baud", baudrate); + item("mode", mode); + end_section(); +} + +void print_steps(int axis) { + item("steps_per_mm", axis_settings[axis]->steps_per_mm->get()); + item("max_rate", axis_settings[axis]->max_rate->get()); + item("acceleration", axis_settings[axis]->acceleration->get()); + item("max_travel", axis_settings[axis]->max_travel->get()); + item("soft_limits", tf(soft_limits->get())); } void print_homing(int axis) { - for (int cycle; cycle < MAX_N_AXIS; cycle++) { - if (bitnum_istrue(homing_cycle[cycle], axis)) { + int cycle; + for (cycle = 0; cycle < MAX_N_AXIS; cycle++) { + if (bitnum_istrue(homing_cycle[cycle]->get(), axis)) { break; } } if (cycle == MAX_N_AXIS) { - // XXX alternative: set cycle to 0 return; } - p(" homing:") p(" cycle", cycle); - p(" positive_direction: %s", tf(bitnum_istrue(homing_dir_mask->get(), axis))); - p(" mpos: %f", axis_settings[axis]->home_mpos->get()); - p(" debounce: %f", homing_debounce->get()); - p(" pulloff: %f", homing_pulloff->get()); - p(" square: %s", tf(bitnum_istrue(homing_squared_axes->get, axis)); - p(" seek_rate: %f", homing_seek_rate->get()); - p(" feed_rate: %f", homing_feed_rate->get()); - p(" seek_scaler: %f", HOMING_AXIS_SEARCH_SCALAR); - p(" feed_scaler: %f", HOMING_AXIS_LOCATE_SCALAR); + section("homing"); + + item("cycle", cycle + 1); + item("positive_direction", bitnum_istrue(homing_dir_mask->get(), axis)); + item("mpos", axis_settings[axis]->home_mpos->get()); + item("debounce", homing_debounce->get()); + item("pulloff", homing_pulloff->get()); + item("square", bitnum_istrue(homing_squared_axes->get(), axis)); + item("seek_rate", homing_seek_rate->get()); + item("feed_rate", homing_feed_rate->get()); + + float hass = 1.1f; +#ifdef HOMING_AXIS_SEARCH_SCALAR + hass = HOMING_AXIS_SEARCH_SCALAR; +#endif + item("seek_scaler", hass); + + float hals = 5.0f; +#ifdef HOMING_AXIS_LOCATE_SCALAR + hals = HOMING_AXIS_LOCATE_SCALAR; +#endif + item("feed_scaler", hals); + end_section(); } void print_endstops(int axis, int gang) { if (limit_pins[axis][gang] != UNDEFINED_PIN) { - p(" endstops:"); - p(" dual: %s", print_pin(limit_pins[axis][gang], limit_invert->get(), DISABLE_LIMIT_PIN_PULL_UP)); - p(" hard_limits: %s", tf(DEFAULT_HARD_LIMIT_ENABLE)); + section("endstops"); + bool dlppu = false; +#ifdef DISABLE_LIMIT_PIN_PULL_UP + dlppu = true; +#endif + item("dual", pinspec(limit_pins[axis][gang], limit_invert->get(), dlppu)); + item("hard_limits", bool(DEFAULT_HARD_LIMIT_ENABLE)); + end_section(); } } -void print_motor(Motor* m, int axis, int gang) { - p(" %s:", m->name()); +void print_motor(Motor* m, int axis, int gang, const char* name) { + section(name); } -void print_servo(Motor* m, int axis, int gang) { - print_motor(m, axis, gang)); +void print_servo(Motor* m, int axis, int gang, const char* name = "servo") { + print_motor(m, axis, gang, name); } -void print_rc_servo(Motor* m, int axis, int gang) { - print_servo(m, axis, gang); - p(" cal_min: %f", m->_cal_min); - p(" cal_max: %f", m->_cal_max); - p(" pwm: %s" print_pin(m->_pwm_pin, false)) +void print_rc_servo(RcServo* m, int axis, int gang, const char* name = "rc_servo") { + print_servo(m, axis, gang, name); + item("cal_min", m->rc_servo_cal_min->get()); + item("cal_max", m->rc_servo_cal_max->get()); + item("pwm", pinspec(m->_pwm_pin, false)); + end_section(); } -void print_solenoid(Motor* m, int axis, int gang) { - print_rc_servo(m, axis, gang); - p(" transition_point: %f", 1.0f); // Placeholder +#if 0 +void print_solenoid(Solenoid* m, int axis, int gang, const char* name = "solenoid") { + print_rc_servo(m, axis, gang, name); + item("transition_point", 1.0f); // Placeholder + end_section(); } -void print_unipolar(Motor* m, int axis, int gang) { - print_motor(m, axis, gang)); - p(" phase0: %s", print_pin(m->_pin_phase0, false)); - p(" phase1: %s", print_pin(m->_pin_phase1, false)); - p(" phase2: %s", print_pin(m->_pin_phase2, false)); - p(" phase3: %s", print_pin(m->_pin_phase3, false)); - p(" half_step: %s", tf(m->_half_step))); +#endif +void print_unipolar(UnipolarMotor* m, int axis, int gang, const char* name = "unipolar") { + print_motor(m, axis, gang, name); + item("phase0", pinspec(m->_pin_phase0, false)); + item("phase1", pinspec(m->_pin_phase1, false)); + item("phase2", pinspec(m->_pin_phase2, false)); + item("phase3", pinspec(m->_pin_phase3, false)); + item("half_step", tf(m->_half_step)); + end_section(); } -void print_dynamixel(Motor* m, int axis, int gang) { - print_servo(m, axis, gang); - p(" invert_direction: %s", tf(bitnum_istrue(dir_invert_mask->get(), axis))); - p(" count_min: %d", int(m->dxl_count_min)); - p(" count_max: %d", int(m->dxl_count_max)); - p(" full_time_move: %d", DYNAMIXEL_FULL_MOVE_TIME); - p(" id: %d", m->ids[axis][gang]); - p(" uart:"); - print_uart(m->_uart_num, m->_tx_pin, m->_rx_pin, m->_rts_pin); +void print_dynamixel(Dynamixel2* m, int axis, int gang, const char* name = "dynamixel2") { + print_servo(m, axis, gang, name); + item("invert_direction", bitnum_istrue(dir_invert_mask->get(), axis)); + item("count_min", m->_dxl_count_min); + item("count_max", m->_dxl_count_max); + item("id", m->ids[axis][gang]); + print_uart(m->_uart_num, m->_tx_pin, m->_rx_pin, m->_rts_pin, DYNAMIXEL_BAUD_RATE, "8n1"); + end_section(); } -void print_stepstick(Motor* m, int axis, int gang) { - print_motor(m, axis, gang); - p(" direction: %s", print_pin(m->_dir_pin, m->_invert_dir_pin)); - p(" step: %s", print_pin(m->_step_pin, m->_invert_step_pin)); - p(" disable: %s", print_pin(m->_disable_pin, false)); +void print_stepper(StandardStepper* m, int axis, int gang, const char* name) { + print_motor(m, axis, gang, name); + item("direction", pinspec(m->_dir_pin, m->_invert_dir_pin)); + item("step", pinspec(m->_step_pin, m->_invert_step_pin)); + item("disable", pinspec(m->_disable_pin, false)); +} +void print_stepstick(StandardStepper* m, int axis, int gang, const char* name) { + print_stepper(m, axis, gang, name); + end_section(); } const char* trinamicModes(TrinamicMode mode) { + const char* ret; switch (mode) { + case TrinamicMode::None: + ret = "ERROR"; case TrinamicMode::CoolStep: - return "CoolStep"; + ret = "CoolStep"; case TrinamicMode::StealthChop: - return "StealthChop"; - case TrinamicMode::Stallguard: - return "Stallguard"; + ret = "StealthChop"; + case TrinamicMode::StallGuard: + ret = "Stallguard"; } + return ret; } -void print_trinamic_base(Motor* m, int axis, int gang) { - print_stepstick(m, axis, gang); - p(" r_sense: %f", m->_r_sense); - p(" run_current: %f", axis_settings[axis]->run_current->get()); - p(" hold_current: %f", axis_settings[axis]->hold_current->get()); - p(" microsteps: %d", axis_settings[axis]->microsteps->get()); - p(" stallguard: %d", axis_settings[axis]->stallguard->get()); - p(" stallguardDebugMode: %s", tf(false)); - p(" run_mode: %s", _run_mode, trinamicModes(TRINAMIC_RUN_MODE)); - p(" homing_mode: %s", _homing_mode, trinamicModes(TRINAMIC_HOMING_MODE)); +void print_trinamic_common(int axis, int gang, TrinamicMode run, TrinamicMode homing) { + item("run_current", axis_settings[axis]->run_current->get()); + item("hold_current", axis_settings[axis]->hold_current->get()); + item("microsteps", axis_settings[axis]->microsteps->get()); + item("stallguard", axis_settings[axis]->stallguard->get()); + item("stallguardDebugMode", false); + item("run_mode", trinamicModes(run)); + item("homing_mode", trinamicModes(homing)); #ifdef USE_TRINAMIC_ENABLE - p(" use_enable: %s", tf(true)); - p(" toff_disable: %d", TRINAMIC_TOFF_DISABLE); - p(" toff_stealthchop: %d", TRINAMIC_TOFF_STEALTHCHOP); - p(" toff_coolstep: %d", TRINAMIC_TOFF_COOLSTEP); + item("use_enable", tf(true)); + item("toff_disable", TRINAMIC_TOFF_DISABLE); + item("toff_stealthchop", TRINAMIC_TOFF_STEALTHCHOP); + item("toff_coolstep", TRINAMIC_TOFF_COOLSTEP); #else - p(" use_enable: %s", tf(false)); + item("use_enable", tf(false)); #endif } -void print_trinamic_spi(Motor* m, int axis, int gang) { - print_trinamic_base(m, axis, gang); - p(" cs: %s", print_pin(m->_cs_pin, true)); +void print_trinamic_spi(TrinamicDriver* m, int axis, int gang, const char* name = "trinamic_spi") { + print_stepper(m, axis, gang, name); + print_trinamic_common(axis, gang, TRINAMIC_RUN_MODE, TRINAMIC_HOMING_MODE); + item("r_sense", m->_r_sense); + item("cs", pinspec(m->_cs_pin, true)); + end_section(); } -void print_trinamic_uart(Motor* m, int axis, int gang) { - print_trinamic_base(m, axis, gang); - p(" uart:"); - print_uart(???); +void print_trinamic_uart(TrinamicUartDriver* m, int axis, int gang, const char* name = "trinamic_uart") { + print_stepper(m, axis, gang, name); + item("r_sense", m->_r_sense); + print_trinamic_common(axis, gang, TrinamicMode(TRINAMIC_UART_RUN_MODE), TrinamicMode(TRINAMIC_UART_HOMING_MODE)); + print_uart(TMC_UART, TMC_UART_TX, TMC_UART_RX, UNDEFINED_PIN, 115200, "8n1"); + end_section(); } -void print_motor_class(Motor* m, int axis, int gang) { +void print_null_motor(Motor* m, int axis, int gang, const char* name) { + print_motor(m, axis, gang, name); + end_section(); +} +void print_motor_class(int axis, int gang) { + Motor* m = myMotor[axis][gang]; const char* name = m->name(); - if (!strcmp(name, "null_motor")) { - print_motor_name(name); + if (!strcasecmp(name, "null_motor")) { + print_null_motor(m, axis, gang, name); return; } - if (!strcmp(name, "stepstick")) { - print_stepstick(m, axis, gang); + if (!strcasecmp(name, "stepstick")) { + print_stepstick((StandardStepper*)m, axis, gang, name); return; } - if (!strcmp(name, "solenoid")) { - print_solenoid(name); +#if 0 + if (!strcasecmp(name, "solenoid")) { + print_solenoid((Solenoid*)m, axis, gang, name); return; } - if (!strcmp(name, "rc_servo")) { - print_rc_servo(name); +#endif + if (!strcasecmp(name, "rc_servo")) { + print_rc_servo((RcServo*)m, axis, gang, name); return; } - if (!strcmp(name, "dynamixel2")) { - print_dynamixel(m, axis, gang); + if (!strcasecmp(name, "dynamixel2")) { + print_dynamixel((Dynamixel2*)m, axis, gang, name); return; } - if (!strcmp(name, "unipolar")) { - print_unipolar(name); + if (!strcasecmp(name, "unipolar")) { + print_unipolar((UnipolarMotor*)m, axis, gang, name); return; } - if (!strcmp(name, "tmc_2130" || !strcmp(name, "tmc_5160")) { - print_trinamic_spi(name); + if (!strcasecmp(name, "tmc_2130") || !strcasecmp(name, "tmc_5160")) { + print_trinamic_spi((TrinamicDriver*)m, axis, gang, name); return; } - if (!strcmp(name, "tmc_2208" || !strcmp(name, "tmc_2209")) { - print_trinamic_uart(name); + if (!strcasecmp(name, "tmc_2208") || !strcasecmp(name, "tmc_2209")) { + print_trinamic_uart((TrinamicUartDriver*)m, axis, gang, name); return; } } -void print_axes() { - p("axes:"); - for (int axis = 0; axis <= n_axis; axis++) { - p(" %c:", "xyzabc"[axis]); +const char* axis_names[] = { "x", "y", "z", "a", "b", "c" }; +void print_axes() { + section("axes"); + for (int axis = 0; axis < number_axis->get(); axis++) { + section(axis_names[axis]); print_steps(axis); print_homing(axis); for (int gang = 0; gang < 2; gang++) { - print_endstops(axis); - p(" gang%d:", gang); print_endstops(axis, gang); - print_motor_class(myMotor[axis][gang], axis, gang); + section(gang ? "gang1" : "gang0"); + print_endstops(axis, gang); + print_motor_class(axis, gang); + end_section(); } + end_section(); } + end_section(); } void print_stepping() { - p(" engine: %s", stepper_names[current_stepper]); - p(" idle_ms: %d", stepper_idle_lock_time); - p(" pulse_us: %d", pulse_microseconds); - p(" dir_delay_us: %d", direction_delay_microseconds); - p(" disable_delay_us: %d", enable_delay_microseconds); + section("stepping"); + item("engine", stepper_names[current_stepper]); + item("idle_ms", stepper_idle_lock_time->get()); + item("pulse_us", pulse_microseconds->get()); + item("dir_delay_us", direction_delay_microseconds->get()); + item("disable_delay_us", enable_delay_microseconds->get()); + end_section(); } void print_i2so() { - p("i2so:"); - p(" bck: %s", print_pin(_bck, ); - p(" data: %s", print_pin(_data, ); - p(" ws: %s", print_pin(_ws, ); + section("i2so"); + item("bck", pinspec(I2S_OUT_BCK)); + item("data", pinspec(I2S_OUT_DATA)); + item("ws", pinspec(I2S_OUT_WS)); + end_section(); } void print_spi() { - p("spi:"); - p(" cs: %s", print_pin(_cs, ); - p(" miso %s", print_pin(_miso, ); - p(" mosi %s", print_pin(_mosi, ); - p(" sck %s", print_pin(_sck, ); + section("spi"); + // -1 is not the same as UNDEFINED_PIN; -1 means use the hardware default + item("cs", pinspec(GRBL_SPI_SS == -1 ? GPIO_NUM_5 : GRBL_SPI_SS)); + item("miso", pinspec(GRBL_SPI_MISO == -1 ? GPIO_NUM_19 : GRBL_SPI_MISO)); + item("mosi", pinspec(GRBL_SPI_MOSI == -1 ? GPIO_NUM_23 : GRBL_SPI_MOSI)); + item("sck", pinspec(GRBL_SPI_SCK == -1 ? GPIO_NUM_18 : GRBL_SPI_SCK)); + end_section(); } +#ifndef CONTROL_SAFETY_DOOR_PIN +# define CONTROL_SAFETY_DOOR_PIN UNDEFINED_PIN +#endif +#ifndef CONTROL_RESET_PIN +# define CONTROL_RESET_PIN UNDEFINED_PIN +#endif +#ifndef CONTROL_FEED_HOLD_PIN +# define CONTROL_FEED_HOLD_PIN UNDEFINED_PIN +#endif +#ifndef CONTROL_CYCLE_START_PIN +# define CONTROL_CYCLE_START_PIN UNDEFINED_PIN +#endif +#ifndef MACRO_BUTTON_0_PIN +# define MACRO_BUTTON_0_PIN UNDEFINED_PIN +#endif +#ifndef MACRO_BUTTON_1_PIN +# define MACRO_BUTTON_1_PIN UNDEFINED_PIN +#endif +#ifndef MACRO_BUTTON_2_PIN +# define MACRO_BUTTON_2_PIN UNDEFINED_PIN +#endif +#ifndef MACRO_BUTTON_3_PIN +# define MACRO_BUTTON_3_PIN UNDEFINED_PIN +#endif + void print_control() { - p("control:"); - p(" safety_door: %s", print_pin(CONTROL_SAFETY_DOOR_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 0), DISABLE_CONTROL_PIN_PULL_UP); - p(" reset: %s", print_pin(CONTROL_RESET_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 1), DISABLE_CONTROL_PIN_PULL_UP); - p(" feed_hold: %s", print_pin(CONTROL_FEED_HOLD_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 2), DISABLE_CONTROL_PIN_PULL_UP); - p(" cycle_start: %s", print_pin(CONTROL_CYCLE_START_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 3), DISABLE_CONTROL_PIN_PULL_UP); - p(" macro0: %s", print_pin(MACRO_BUTTON_0_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 4), DISABLE_CONTROL_PIN_PULL_UP); - p(" macro1: %s", print_pin(MACRO_BUTTON_1_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 5), DISABLE_CONTROL_PIN_PULL_UP); - p(" macro2: %s", print_pin(MACRO_BUTTON_2_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 6), DISABLE_CONTROL_PIN_PULL_UP); - p(" macro3: %s", print_pin(MACRO_BUTTON_3_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 7), DISABLE_CONTROL_PIN_PULL_UP); + bool pu = true; +#ifdef DISABLE_CONTROL_PIN_PULL_UP + pu = false; +#endif + section("control"); + item("safety_door", pinspec(CONTROL_SAFETY_DOOR_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 0), pu)); + item("reset", pinspec(CONTROL_RESET_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 1), pu)); + item("cycle_start", pinspec(CONTROL_CYCLE_START_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 3), pu)); + item("macro0", pinspec(MACRO_BUTTON_0_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 4), pu)); + item("macro1", pinspec(MACRO_BUTTON_1_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 5), pu)); + item("macro2", pinspec(MACRO_BUTTON_2_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 6), pu)); + item("macro3", pinspec(MACRO_BUTTON_3_PIN, bitnum_istrue(INVERT_CONTROL_PIN_MASK, 7), pu)); + end_section(); } +#ifndef COOLANT_FLOOD_PIN +# define COOLANT_FLOOD_PIN UNDEFINED_PIN +#endif +#ifndef COOLANT_MIST_PIN +# define COOLANT_MIST_PIN UNDEFINED_PIN +#endif void print_coolant() { - p("coolant:"); - p(" flood: %s", print_pin(COOLANT_FLOOD_PIN, INVERT_COOLANT_FLOOD_PIN)); - p(" mist: %s", print_pin(COOLANT_MIST_PIN, INVERT_COOLANT_MIST_PIN)); - p(" delay: %f", coolant_start_delay->get()); // XXX should the be int as delay_ms? + section("coolant"); + bool floodlow = false; +#ifdef INVERT_COOLANT_FLOOD_PIN + floodlow = true; +#endif + item("flood", pinspec(COOLANT_FLOOD_PIN, floodlow, floodlow)); + bool mistlow = false; +#ifdef INVERT_COOLANT_MIST_PIN + mistlow = true; +#endif + item("mist", pinspec(COOLANT_MIST_PIN, mistlow, mistlow)); + item("delay_ms", coolant_start_delay->get() * 1000); + end_section(); } void print_probe() { - p("probe:"); - p(" pin: %s", print_pin(PROBE_PIN, probe_invert->get(), DISABLE_PROBE_PIN_INPUT_PULLUP); + section("probe"); + bool pu = true; +#ifdef DISABLE_PROBE_PIN_INPUT_PULLUP + pu = false; +#endif + item("pin", pinspec(PROBE_PIN, probe_invert->get(), pu)); bool cms = false; #ifdef SET_CHECK_MODE_PROBE_TO_START cms = true; #endif - p(" check_mode_start: %s", cms); + item("check_mode_start", cms); + end_section(); } void print_comms() { - p("comms:"); + section("comms"); // XXX + end_section(); } void print_macros() { - p("macros:"); - p(" n0: %s", startup_line0->get()); - p(" n1: %s", startup_line1->get()); - p(" macro0: %s", user_macro0->get()); - p(" macro1: %s", user_macro1->get()); - p(" macro2: %s", user_macro2->get()); - p(" macro3: %s", user_macro3->get()); + section("macros"); + item("n0", startup_line_0->get()); + item("n1", startup_line_1->get()); + item("macro0", user_macro0->get()); + item("macro1", user_macro1->get()); + item("macro2", user_macro2->get()); + item("macro3", user_macro3->get()); + end_section(); +} +const char* makeSpeedMap(PWM* s) { + return "0=0% 1000=100%"; } void print_spindle(const char* name, Spindle* s) { - p("%s:", name); - p(" spinup_ms: %d", s->_spinup_delay); - p(" spindown_ms: %d", s->_spindown_delay); - p(" tool: 0"); - p(" speeds: %s", makeSpeedMap(s)); + section(name); + item("spinup_ms", s->_spinup_delay); + item("spindown_ms", s->_spindown_delay); + item("tool", int(0)); + item("speeds", makeSpeedMap((PWM*)s)); + end_section(); } -void print_onoff_spindle(const char* name, Spindle* s) { +void print_onoff_spindle(const char* name, PWM* s) { print_spindle(name, s); - p(" output_pin: %s", print_pin(s->_output_pin)); - p(" enable_pin: %s", print_pin(s->_enable_pin)); - p(" direction_pin: %s", print_pin(s->_direction_pin)); - p(" disable_with_zero_speed: %s", tf(s->_off_with_zero_speed)); - p(" zero_speed_with_disable: %s", tf(false)); + item("output_pin", pinspec(s->_output_pin, s->_invert_pwm, false)); + item("enable_pin", pinspec(s->_enable_pin)); + item("direction_pin", pinspec(s->_direction_pin)); + item("disable_with_zero_speed", bool(s->_off_with_zero_speed)); + item("zero_speed_with_disable", false); + end_section(); } -void print_pwm_spindle(const char* name = "pwm", Spindle* s = &pwmb) { +void print_pwm_spindle(const char* name, PWM* s) { print_onoff_spindle(name, s); - p(" pwm_freq: %d", s-?_pwm_freq)'' + item("pwm_freq", s->_pwm_freq); + end_section(); } -void print_relay_spindle() { - Spindle* s = &relay; +void print_relay_spindle(Relay* s) { print_onoff_spindle("relay", s); + end_section(); } -void print_laser_spindle() { +void print_laser_spindle(Laser* s) { print_pwm_spindle("laser", s); - // XXX should this be just full_power ? - p(" laser_full_power: %u", laser_full_power->get()); + end_section(); } -void print_dac_spindle() { - print_onoff_spindle("dac", &dac); +void print_dac_spindle(Dac* s) { + print_onoff_spindle("dac", s); + end_section(); } - -void print_besc_spindle() { - Spindle* s = &besc; +void print_besc_spindle(BESC* s) { print_pwm_spindle("besc", s); // XXX override frequency to BEDC_PWM_FREQ and period to BESC_PULSE_PERIOD - p(" min_pulse_us: %d", int(BESC_MIN_PULSE_SECS * 1000000)); - p(" max_pulse_us: %d", int(BESC_MAX_PULSE_SECS * 1000000)) + item("min_pulse_us", int(BESC_MIN_PULSE_SECS * 1000000)); + item("max_pulse_us", int(BESC_MAX_PULSE_SECS * 1000000)); + + end_section(); } -void print_10v_spindle() { - Spindle* s = &_10v; +void print_10v_spindle(_10v* s) { print_pwm_spindle("10v", s); + end_section(); } -void print_vfd_spindle(const char* name, Spindle* s) { +void print_vfd_spindle(const char* name, VFD* s) { print_spindle(name, s); print_uart(VFD_RS485_UART_PORT, -#ifdef VFD_RS485_TXD_PIN VFD_RS485_TXD_PIN +#ifdef VFD_RS485_TXD_PIN VFD_RS485_TXD_PIN #else -1 @@ -304,65 +504,70 @@ void print_vfd_spindle(const char* name, Spindle* s) { #ifdef VFD_RS485_PARITY # if VFD_RS485_PARITY == Uart::Parity::None "8n1" -# else if VFD_RS485_PARITY == Uart::Parity::Even +# elseif VFD_RS485_PARITY == Uart::Parity::Even "8e1" -# else if VFD_RS485_PARITY == Uart::Parity::Odd +# else // VFD_RS485_PARITY == Uart::Parity::Odd "8o1" # endif #else "8n1" #endif ); + end_section(); } -void print_huanyang_spindle() { - print_vfd_spindle("huanyang", &huanyang); +void print_huanyang_spindle(Huanyang* s) { + print_vfd_spindle("huanyang", s); + end_section(); } -void print_h2a_spindle() { - print_vfd_spindle("h2a", &h2a); +void print_h2a_spindle(H2A* s) { + print_vfd_spindle("h2a", s); + end_section(); } -void print_yl620_spindle() { - print_vfd_spindle("yl620", &yl620); +void print_yl620_spindle(YL620* s) { + print_vfd_spindle("yl620", s); + end_section(); } void print_spindle_class() { + Spindle* s = spindle; switch (spindle_type->get()) { - case SpindleType::NONE: + case int8_t(SpindleType::NONE): break; - case SpindleType::PWM: - print_pwm_spindle(); + case int8_t(SpindleType::PWM): + print_pwm_spindle("pwm", (PWM*)s); break; - case SpindleType::RELAY: - print_relay_spindle(); + case int8_t(SpindleType::RELAY): + print_relay_spindle((Relay*)s); break; - case SpindleType::LASER: - print_laser_spindle(); + case int8_t(SpindleType::LASER): + print_laser_spindle((Laser*)s); break; - case SpindleType::DAC: - print_dac_spindle(); + case int8_t(SpindleType::DAC): + print_dac_spindle((Dac*)s); break; - case SpindleType::HUANYANG: - print_huanyang_spindle(); + case int8_t(SpindleType::HUANYANG): + print_huanyang_spindle((Huanyang*)s); break; - case SpindleType::BESC: - print_besc_spindle(); + case int8_t(SpindleType::BESC): + print_besc_spindle((BESC*)s); break; - case SpindleType::_10V: - print_10v_spindle(); + case int8_t(SpindleType::_10V): + print_10v_spindle((_10v*)s); break; - case SpindleType::H2A: - print_h2a_spindle(); + case int8_t(SpindleType::H2A): + print_h2a_spindle((H2A*)s); break; - case SpindleType::YL620: - print_yl620_spindle(); + case int8_t(SpindleType::YL620): + print_yl620_spindle((YL620*)s); break; } } -void print_machine() { - p("board", _board); - p("name", _name); +void dump_config() { + item("board", "unknown"); + item("name", MACHINE_NAME); print_stepping(); print_axes(); print_i2so(); @@ -377,59 +582,61 @@ void print_machine() { #ifdef ENABLE_SOFTWARE_DEBOUNCE db = DEBOUNCE_PERIOD; #endif - p("software_debounce_ms", db); + item("software_debounce_ms", db); // TODO: Consider putting these under a gcode: hierarchy level? Or motion control? - p("laser_mode: %", laser_mode->get()); - p("arc_tolerance: %", arc_tolerance->get()); - p("junction_deviation: %", junction_deviation->get()); - p("verbose_errors: %", verbose_errors->get()); + item("laser_mode", laser_mode->get()); + item("arc_tolerance", arc_tolerance->get()); + item("junction_deviation", junction_deviation->get()); + item("verbose_errors", verbose_errors->get()); bool hil = false; #ifdef HOMING_INIT_LOCK hil = true; #endif - p("homing_init_lock: %s", tf(hil)); + item("homing_init_lock", tf(hil)); - p("report_inches: %", report_inches->get()); + item("report_inches", report_inches->get()); bool epoc = false; #ifdef ENABLE_PARKING_OVERRIDE_CONTROL epoc = true; #endif - p("enable_parking_override_control: %", tf(epoc)); + item("enable_parking_override_control", tf(epoc)); bool dpoi = false; #ifdef DEACTIVATE_PARKING_UPON_INIT dpoi = true; #endif - p("deactivate_parking_upon_init: %", tf(dpoi)); + item("deactivate_parking_upon_init", tf(dpoi)); bool clai = false; #ifdef CHECK_LIMITS_AT_INIT clai = true; #endif - p("check_limits_at_init: %", tf(clai)); + item("check_limits_at_init", tf(clai)); bool l2soa = false; #ifdef LIMITS_TWO_SWITCHES_ON_AXES l2soa = true; #endif - p("limits_two_switches_on_axis: %", tf(l2soa)); + item("limits_two_switches_on_axis", tf(l2soa)); bool dldh = false; #ifdef DISABLE_LASER_DURING_HOLD dldh = true; #endif - p("disable_laser_during_hold: %", tf(dldh)); + item("disable_laser_during_hold", tf(dldh)); bool uln = false; #ifdef USE_LINE_NUMBERS uln = true; #endif - p("use_line_numbers: %", tf(uln); + item("use_line_numbers", uln); print_spindle_class(); } +#if 0 void machine_init() { print_machine(); } +#endif diff --git a/Grbl_Esp32/src/DumpConfig.h b/Grbl_Esp32/src/DumpConfig.h new file mode 100644 index 00000000..3613c695 --- /dev/null +++ b/Grbl_Esp32/src/DumpConfig.h @@ -0,0 +1,2 @@ +#pragma once +extern void dump_config(); diff --git a/Grbl_Esp32/src/I2SOut.cpp b/Grbl_Esp32/src/I2SOut.cpp index 463c7c65..077680ee 100644 --- a/Grbl_Esp32/src/I2SOut.cpp +++ b/Grbl_Esp32/src/I2SOut.cpp @@ -945,18 +945,6 @@ int IRAM_ATTR i2s_out_init(i2s_out_init_t& init_param) { return 0; } -#ifndef I2S_OUT_WS -# define I2S_OUT_WS GPIO_NUM_17 -#endif -#ifndef I2S_OUT_BCK -# define I2S_OUT_BCK GPIO_NUM_22 -#endif -#ifndef I2S_OUT_DATA -# define I2S_OUT_DATA GPIO_NUM_21 -#endif -#ifndef I2S_OUT_INIT_VAL -# define I2S_OUT_INIT_VAL 0 -#endif /* Initialize I2S out by default parameters. diff --git a/Grbl_Esp32/src/I2SOut.h b/Grbl_Esp32/src/I2SOut.h index 5ae31c16..2e8304ff 100644 --- a/Grbl_Esp32/src/I2SOut.h +++ b/Grbl_Esp32/src/I2SOut.h @@ -41,18 +41,18 @@ // It should be included at the outset to know the machine configuration. #include "Config.h" -# include +#include /* Assert */ -# if defined(I2S_OUT_NUM_BITS) -# if (I2S_OUT_NUM_BITS != 16) && (I2S_OUT_NUM_BITS != 32) -# error "I2S_OUT_NUM_BITS should be 16 or 32" -# endif -# else -# define I2S_OUT_NUM_BITS 32 +#if defined(I2S_OUT_NUM_BITS) +# if (I2S_OUT_NUM_BITS != 16) && (I2S_OUT_NUM_BITS != 32) +# error "I2S_OUT_NUM_BITS should be 16 or 32" # endif +#else +# define I2S_OUT_NUM_BITS 32 +#endif -# define I2SO(n) (I2S_OUT_PIN_BASE + n) +#define I2SO(n) (I2S_OUT_PIN_BASE + n) /* 16-bit mode: 1000000 usec / ((160000000 Hz) / 10 / 2) x 16 bit/pulse x 2(stereo) = 4 usec/pulse */ /* 32-bit mode: 1000000 usec / ((160000000 Hz) / 5 / 2) x 32 bit/pulse x 2(stereo) = 4 usec/pulse */ @@ -187,3 +187,15 @@ int i2s_out_reset(); Reference: "ESP32 Technical Reference Manual" by Espressif Systems https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf */ +#ifndef I2S_OUT_WS +# define I2S_OUT_WS GPIO_NUM_17 +#endif +#ifndef I2S_OUT_BCK +# define I2S_OUT_BCK GPIO_NUM_22 +#endif +#ifndef I2S_OUT_DATA +# define I2S_OUT_DATA GPIO_NUM_21 +#endif +#ifndef I2S_OUT_INIT_VAL +# define I2S_OUT_INIT_VAL 0 +#endif diff --git a/Grbl_Esp32/src/Limits.h b/Grbl_Esp32/src/Limits.h index 3697f8e0..ee4dda2d 100644 --- a/Grbl_Esp32/src/Limits.h +++ b/Grbl_Esp32/src/Limits.h @@ -57,3 +57,5 @@ bool limitsCheckTravel(float* target); // check if a switch has been defined bool limitsSwitchDefined(uint8_t axis, uint8_t gang_index); + +extern uint8_t limit_pins[MAX_N_AXIS][2]; diff --git a/Grbl_Esp32/src/Motors/Dynamixel2.h b/Grbl_Esp32/src/Motors/Dynamixel2.h index d4a482c3..27a0deed 100644 --- a/Grbl_Esp32/src/Motors/Dynamixel2.h +++ b/Grbl_Esp32/src/Motors/Dynamixel2.h @@ -84,16 +84,26 @@ namespace Motors { void set_disable(bool disable) override; void update() override; + const char* name() override { return "Dynamixel2"; } + static bool uart_ready; static uint8_t ids[MAX_N_AXIS][2]; + float _dxl_count_min; + float _dxl_count_max; + + uint8_t _id; + + uint8_t _tx_pin; + uint8_t _rx_pin; + uint8_t _rts_pin; + uart_port_t _uart_num; protected: void config_message() override; void set_location(); - uint8_t _id; char _dxl_tx_message[50]; // outgoing to dynamixel uint8_t _dxl_rx_message[50]; // received from dynamixel @@ -113,14 +123,6 @@ namespace Motors { float _homing_position; - float _dxl_count_min; - float _dxl_count_max; - - uint8_t _tx_pin; - uint8_t _rx_pin; - uint8_t _rts_pin; - uart_port_t _uart_num; - bool _disabled; bool _has_errors; }; diff --git a/Grbl_Esp32/src/Motors/Motor.h b/Grbl_Esp32/src/Motors/Motor.h index c9c0300b..c9ea484b 100644 --- a/Grbl_Esp32/src/Motors/Motor.h +++ b/Grbl_Esp32/src/Motors/Motor.h @@ -94,6 +94,8 @@ namespace Motors { // called from a periodic task. virtual void update() {} + virtual const char* name() = 0; + protected: // config_message(), called from init(), displays a message describing // the motor configuration - pins and other motor-specific items @@ -115,3 +117,4 @@ namespace Motors { uint8_t _dual_axis_index; // 0 = primary 1=ganged }; } +extern Motors::Motor* myMotor[MAX_AXES][MAX_GANGED]; diff --git a/Grbl_Esp32/src/Motors/NullMotor.h b/Grbl_Esp32/src/Motors/NullMotor.h index 6e859855..ac7175c5 100644 --- a/Grbl_Esp32/src/Motors/NullMotor.h +++ b/Grbl_Esp32/src/Motors/NullMotor.h @@ -7,5 +7,7 @@ namespace Motors { public: Nullmotor(uint8_t axis_index); bool set_homing_mode(bool isHoming) { return false; } + + const char* name() override { return "null_motor"; } }; } diff --git a/Grbl_Esp32/src/Motors/RcServo.h b/Grbl_Esp32/src/Motors/RcServo.h index 77540891..822d4348 100644 --- a/Grbl_Esp32/src/Motors/RcServo.h +++ b/Grbl_Esp32/src/Motors/RcServo.h @@ -36,15 +36,19 @@ namespace Motors { void set_disable(bool disable) override; void update() override; + const char* name() override { return "rc_servo"; } + void _write_pwm(uint32_t duty); - + + uint8_t _pwm_pin; + FloatSetting* rc_servo_cal_min; + FloatSetting* rc_servo_cal_max; protected: void config_message() override; void set_location(); - uint8_t _pwm_pin; uint8_t _channel_num; uint32_t _current_pwm_duty; @@ -54,8 +58,5 @@ namespace Motors { float _pwm_pulse_max; bool _disabled; - - FloatSetting* rc_servo_cal_min; - FloatSetting* rc_servo_cal_max; - }; + }; } diff --git a/Grbl_Esp32/src/Motors/Servo.h b/Grbl_Esp32/src/Motors/Servo.h index 09b6e35c..9d467b58 100644 --- a/Grbl_Esp32/src/Motors/Servo.h +++ b/Grbl_Esp32/src/Motors/Servo.h @@ -36,6 +36,8 @@ namespace Motors { bool set_homing_mode(bool isHoming) override; void set_disable(bool disable) override; #endif + const char* name() override { return "servo"; } + virtual void update() = 0; // This must be implemented by derived classes protected: diff --git a/Grbl_Esp32/src/Motors/Solenoid.h b/Grbl_Esp32/src/Motors/Solenoid.h index 60b62077..3f9e5029 100644 --- a/Grbl_Esp32/src/Motors/Solenoid.h +++ b/Grbl_Esp32/src/Motors/Solenoid.h @@ -11,9 +11,11 @@ namespace Motors { void update() override; void init() override; void set_disable(bool disable) override; + void name() override { return "unipolar"; } float _transition_poiont; - protected: + + protected: void config_message() override; }; } diff --git a/Grbl_Esp32/src/Motors/StandardStepper.h b/Grbl_Esp32/src/Motors/StandardStepper.h index 269e5b2f..5d20029d 100644 --- a/Grbl_Esp32/src/Motors/StandardStepper.h +++ b/Grbl_Esp32/src/Motors/StandardStepper.h @@ -17,6 +17,8 @@ namespace Motors { void unstep() override; void read_settings() override; + const char* name() override { return "stepstick"; } + void init_step_dir_pins(); protected: @@ -25,6 +27,7 @@ namespace Motors { #ifdef USE_RMT_STEPS rmt_channel_t _rmt_chan_num; #endif + public: bool _invert_step_pin; bool _invert_dir_pin; uint8_t _step_pin; diff --git a/Grbl_Esp32/src/Motors/TrinamicDriver.h b/Grbl_Esp32/src/Motors/TrinamicDriver.h index facedf0d..28897ab3 100644 --- a/Grbl_Esp32/src/Motors/TrinamicDriver.h +++ b/Grbl_Esp32/src/Motors/TrinamicDriver.h @@ -95,6 +95,8 @@ namespace Motors { bool set_homing_mode(bool ishoming) override; void set_disable(bool disable) override; + const char* name() override { return _driver_part_number == 2130 ? "tmc_2130" : "tmc_5160"; } + void debug_message(); private: @@ -102,12 +104,20 @@ namespace Motors { TMC2130Stepper* tmcstepper; // all other driver types are subclasses of this one TrinamicMode _homing_mode; - uint8_t _cs_pin = UNDEFINED_PIN; // The chip select pin (can be the same for daisy chain) - uint16_t _driver_part_number; // example: use 2130 for TMC2130 - float _r_sense; - int8_t _spi_index; - bool _has_errors; - bool _disabled; + + public: + uint8_t _cs_pin = UNDEFINED_PIN; // The chip select pin (can be the same for daisy chain) + + private: + uint16_t _driver_part_number; // example: use 2130 for TMC2130 + + public: + float _r_sense; + + private: + int8_t _spi_index; + bool _has_errors; + bool _disabled; TrinamicMode _mode = TrinamicMode::None; bool test(); diff --git a/Grbl_Esp32/src/Motors/TrinamicUartDriver.h b/Grbl_Esp32/src/Motors/TrinamicUartDriver.h index 440231a8..56e0a616 100644 --- a/Grbl_Esp32/src/Motors/TrinamicUartDriver.h +++ b/Grbl_Esp32/src/Motors/TrinamicUartDriver.h @@ -97,6 +97,8 @@ namespace Motors { bool set_homing_mode(bool is_homing) override; void set_disable(bool disable) override; + const char* name() override { return _driver_part_number == 2008 ? "tmc_2008" : "tmc_2009"; } + uint8_t addr; private: @@ -105,9 +107,13 @@ namespace Motors { TMC2209Stepper* tmcstepper; // all other driver types are subclasses of this one TrinamicUartMode _homing_mode; uint16_t _driver_part_number; // example: use 2209 for TMC2209 - float _r_sense; - bool _has_errors; - bool _disabled; + + public: + float _r_sense; + + private: + bool _has_errors; + bool _disabled; TrinamicUartMode _mode = TrinamicUartMode::None; bool test(); diff --git a/Grbl_Esp32/src/Motors/UnipolarMotor.h b/Grbl_Esp32/src/Motors/UnipolarMotor.h index ba554646..3f8cfd31 100644 --- a/Grbl_Esp32/src/Motors/UnipolarMotor.h +++ b/Grbl_Esp32/src/Motors/UnipolarMotor.h @@ -14,17 +14,18 @@ namespace Motors { void set_direction(bool) override; void step() override; - private: uint8_t _pin_phase0; uint8_t _pin_phase1; uint8_t _pin_phase2; uint8_t _pin_phase3; - uint8_t _current_phase; bool _half_step; + + private: + uint8_t _current_phase; bool _enabled; bool _dir; - protected: + protected: void config_message() override; }; } diff --git a/Grbl_Esp32/src/ProcessSettings.cpp b/Grbl_Esp32/src/ProcessSettings.cpp index 25041262..88fb9b0f 100644 --- a/Grbl_Esp32/src/ProcessSettings.cpp +++ b/Grbl_Esp32/src/ProcessSettings.cpp @@ -1,6 +1,7 @@ #include "Grbl.h" #include #include "Regex.h" +#include "DumpConfig.h" // WG Readable and writable as guest // WU Readable and writable as user and admin @@ -290,6 +291,11 @@ Error report_startup_lines(const char* value, WebUI::AuthenticationLevel auth_le return Error::Ok; } +Error dump_config_command(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { + dump_config(); + return Error::Ok; +} + std::map restoreCommands = { #ifdef ENABLE_RESTORE_DEFAULT_SETTINGS { "$", SettingsRestore::Defaults }, { "settings", SettingsRestore::Defaults }, @@ -461,6 +467,8 @@ void make_grbl_commands() { new GrblCommand("I", "Build/Info", get_report_build_info, idleOrAlarm); new GrblCommand("N", "GCode/StartupLines", report_startup_lines, idleOrAlarm); new GrblCommand("RST", "Settings/Restore", restore_settings, idleOrAlarm, WA); + + new GrblCommand("CD", "Config/Dump", dump_config_command, anyState); }; // normalize_key puts a key string into canonical form - diff --git a/Grbl_Esp32/src/Spindles/BESCSpindle.cpp b/Grbl_Esp32/src/Spindles/BESCSpindle.cpp index fceb8bc5..8d04edec 100644 --- a/Grbl_Esp32/src/Spindles/BESCSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/BESCSpindle.cpp @@ -36,16 +36,6 @@ const double BESC_PWM_FREQ = 50.0; // Hz const double BESC_PULSE_PERIOD = (1.0 / BESC_PWM_FREQ); -// Ok to tweak. These are the pulse lengths in seconds -// #define them in your machine definition file if you want different values -#ifndef BESC_MIN_PULSE_SECS -# define BESC_MIN_PULSE_SECS 0.0009f // in seconds -#endif - -#ifndef BESC_MAX_PULSE_SECS -# define BESC_MAX_PULSE_SECS 0.0022f // in seconds -#endif - //calculations...don't change const uint16_t BESC_MIN_PULSE_CNT = static_cast(BESC_MIN_PULSE_SECS / BESC_PULSE_PERIOD * 65535.0); const uint16_t BESC_MAX_PULSE_CNT = static_cast(BESC_MAX_PULSE_SECS / BESC_PULSE_PERIOD * 65535.0); diff --git a/Grbl_Esp32/src/Spindles/BESCSpindle.h b/Grbl_Esp32/src/Spindles/BESCSpindle.h index 50f51bde..4bc36531 100644 --- a/Grbl_Esp32/src/Spindles/BESCSpindle.h +++ b/Grbl_Esp32/src/Spindles/BESCSpindle.h @@ -52,3 +52,12 @@ namespace Spindles { virtual ~BESC() {} }; } +// Ok to tweak. These are the pulse lengths in seconds +// #define them in your machine definition file if you want different values +#ifndef BESC_MIN_PULSE_SECS +# define BESC_MIN_PULSE_SECS 0.0009f // in seconds +#endif + +#ifndef BESC_MAX_PULSE_SECS +# define BESC_MAX_PULSE_SECS 0.0022f // in seconds +#endif diff --git a/Grbl_Esp32/src/Spindles/PWMSpindle.h b/Grbl_Esp32/src/Spindles/PWMSpindle.h index 07ffdf25..adc18642 100644 --- a/Grbl_Esp32/src/Spindles/PWMSpindle.h +++ b/Grbl_Esp32/src/Spindles/PWMSpindle.h @@ -44,7 +44,9 @@ namespace Spindles { virtual ~PWM() {} protected: - int32_t _current_pwm_duty; + int32_t _current_pwm_duty; + + public: uint32_t _min_rpm; uint32_t _max_rpm; uint32_t _pwm_off_value; @@ -65,7 +67,7 @@ namespace Spindles { virtual void set_dir_pin(bool Clockwise); virtual void set_output(uint32_t duty); virtual void set_enable_pin(bool enable_pin); - virtual void deinit(); + void deinit() override; virtual void get_pins_and_settings(); uint8_t calc_pwm_precision(uint32_t freq); diff --git a/Grbl_Esp32/src/Spindles/VFDSpindle.cpp b/Grbl_Esp32/src/Spindles/VFDSpindle.cpp index 463a0933..48325fd9 100644 --- a/Grbl_Esp32/src/Spindles/VFDSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/VFDSpindle.cpp @@ -42,7 +42,6 @@ // be plenty: assuming 9600 8N1, that's roughly 250 chars. A message of 2x16 chars with 4x4 // chars buffering is just 40 chars. -const int VFD_RS485_UART_PORT = 2; // hard coded for this port right now const int VFD_RS485_BUF_SIZE = 127; const int VFD_RS485_QUEUE_SIZE = 10; // numv\ber of commands that can be queued up. const int RESPONSE_WAIT_MILLIS = 1000; // how long to wait for a response in milliseconds @@ -567,7 +566,7 @@ namespace Spindles { set_speed_command(rpm, rpm_cmd); - // Sometimes sync_rpm is retained between different set_speed_command's. We don't want that - we want + // Sometimes sync_rpm is retained between different set_speed_command's. We don't want that - we want // spindle sync to kick in after we set the speed. This forces that. _sync_rpm = UINT32_MAX; diff --git a/Grbl_Esp32/src/Spindles/VFDSpindle.h b/Grbl_Esp32/src/Spindles/VFDSpindle.h index 89035a79..6d871ca4 100644 --- a/Grbl_Esp32/src/Spindles/VFDSpindle.h +++ b/Grbl_Esp32/src/Spindles/VFDSpindle.h @@ -101,4 +101,5 @@ namespace Spindles { virtual ~VFD() {} }; + const int VFD_RS485_UART_PORT = 2; // hard coded for this port right now }