mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-01 02:21:46 +02:00
Assert improvements
This commit is contained in:
@@ -64,13 +64,14 @@ void grbl_init() {
|
||||
// Load Grbl settings from non-volatile storage
|
||||
debug_serial("Initializing settings...");
|
||||
settings_init(); // requires config
|
||||
config->load(config_filename->get());
|
||||
bool configOkay = config->load(config_filename->get());
|
||||
make_grbl_commands();
|
||||
|
||||
// Setup input polling loop after loading the configuration,
|
||||
// because the polling may depend on the config
|
||||
client_init();
|
||||
|
||||
if (configOkay) {
|
||||
report_machine_type(CLIENT_SERIAL);
|
||||
info_serial("Board: %s", config->_board.c_str());
|
||||
|
||||
@@ -102,6 +103,7 @@ void grbl_init() {
|
||||
memset(sys_position, 0, sizeof(sys_position)); // Clear machine position.
|
||||
|
||||
machine_init(); // user supplied function for special initialization
|
||||
}
|
||||
|
||||
// Initialize system state.
|
||||
if (sys.state != State::ConfigAlarm) {
|
||||
@@ -166,6 +168,7 @@ static void reset_variables() {
|
||||
}
|
||||
|
||||
void run_once() {
|
||||
static int tries = 0;
|
||||
try {
|
||||
reset_variables();
|
||||
// Start Grbl main loop. Processes program inputs and executes them.
|
||||
@@ -188,6 +191,9 @@ void run_once() {
|
||||
error_all("Critical error in run_once: %s", ex.msg.c_str());
|
||||
sys.state = State::ConfigAlarm;
|
||||
}
|
||||
if (++tries > 1) {
|
||||
while (1) {}
|
||||
}
|
||||
// This is inside a loop in Grbl_Esp32.ino
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Machine/MachineConfig.h" // config->_stepType
|
||||
#include "../Stepper.h" // ST_I2S_*
|
||||
#include "Motor.h"
|
||||
|
||||
#include <driver/rmt.h>
|
||||
@@ -33,8 +35,11 @@ namespace Motors {
|
||||
|
||||
// Configuration handlers:
|
||||
void validate() const override {
|
||||
Assert(!_step_pin.undefined(), "Step pin should be configured.");
|
||||
Assert(!_dir_pin.undefined(), "Direction pin should be configured.");
|
||||
Assert(_step_pin.defined(), "Step pin should be configured.");
|
||||
Assert(_dir_pin.defined(), "Direction pin should be configured.");
|
||||
bool isI2SO = config->_stepType == ST_I2S_STREAM || config->_stepType == ST_I2S_STATIC;
|
||||
Assert(!isI2SO || _step_pin.name().startsWith("I2SO"), "Step pin must be an I2SO pin");
|
||||
Assert(!isI2SO || _dir_pin.name().startsWith("I2SO"), "Direction pin must be an I2SO pin");
|
||||
}
|
||||
|
||||
void group(Configuration::HandlerBase& handler) override {
|
||||
|
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "GPIOPinDetail.h"
|
||||
#include "../Assert.h"
|
||||
#include "../Logging.h"
|
||||
|
||||
extern "C" void __pinMode(uint8_t pin, uint8_t mode);
|
||||
extern "C" int __digitalRead(uint8_t pin);
|
||||
@@ -133,7 +134,10 @@ namespace Pins {
|
||||
PinCapabilities GPIOPinDetail::capabilities() const { return _capabilities; }
|
||||
|
||||
void GPIOPinDetail::write(int high) {
|
||||
Assert(_attributes.has(PinAttributes::Output), "Pin has no output attribute defined. Cannot write to it.");
|
||||
if (!_attributes.has(PinAttributes::Output)) {
|
||||
log_error(toString());
|
||||
}
|
||||
Assert(_attributes.has(PinAttributes::Output), "Pin %s cannot be written", toString());
|
||||
int value = _readWriteMask ^ high;
|
||||
__digitalWrite(_index, value);
|
||||
}
|
||||
@@ -149,9 +153,11 @@ namespace Pins {
|
||||
|
||||
// Check the attributes first:
|
||||
Assert(value.validateWith(this->_capabilities) || _index == 1 || _index == 3,
|
||||
"The requested attributes don't match the pin capabilities");
|
||||
"The requested attributes don't match the capabilities for %s",
|
||||
toString());
|
||||
Assert(!_attributes.conflictsWith(value) || _index == 1 || _index == 3,
|
||||
"Attributes on this pin have been set before, and there's a conflict.");
|
||||
"The requested attributes on %s conflict with previous settings",
|
||||
toString());
|
||||
|
||||
_attributes = _attributes | value;
|
||||
|
||||
@@ -180,14 +186,12 @@ namespace Pins {
|
||||
}
|
||||
|
||||
void GPIOPinDetail::attachInterrupt(void (*callback)(void*), void* arg, int mode) {
|
||||
Assert(_attributes.has(PinAttributes::ISR),
|
||||
"Pin has no ISR attribute, which means 'setAttr' was not set, or the pin doesn't support ISR's. Cannot bind ISR.");
|
||||
Assert(_attributes.has(PinAttributes::ISR), "Pin %s does not support interrupts", toString());
|
||||
::attachInterruptArg(_index, callback, arg, mode);
|
||||
}
|
||||
|
||||
void GPIOPinDetail::detachInterrupt() {
|
||||
Assert(_attributes.has(PinAttributes::ISR),
|
||||
"Pin has no ISR attribute, which means 'setAttr' was not set, or the pin doesn't support ISR's. Cannot unbind ISR.");
|
||||
Assert(_attributes.has(PinAttributes::ISR), "Pin %s does not support interrupts");
|
||||
::detachInterrupt(_index);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user