Skip to content

Commit

Permalink
Fixed some config errors that used to panic
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley committed Sep 12, 2023
1 parent 3ee2c61 commit 608e614
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
5 changes: 1 addition & 4 deletions FluidNC/src/Motors/TrinamicUartDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ namespace MotorDrivers {

void TrinamicUartDriver::init() {
_uart = config->_uarts[_uart_num];
if (!_uart) {
log_error("TMC Driver missing uart" << _uart_num << " section");
return;
}
Assert(_uart, "TMC Driver missing uart%d section", _uart_num);

_cs_pin.setAttr(Pin::Attr::Output);
}
Expand Down
5 changes: 1 addition & 4 deletions FluidNC/src/Pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "Pins/I2SOPinDetail.h"
#include "Pins/ErrorPinDetail.h"
#include "string_util.h"
#include <stdio.h> // snprintf()

Pins::PinDetail* Pin::undefinedPin = new Pins::VoidPinDetail();
Pins::PinDetail* Pin::errorPin = new Pins::ErrorPinDetail("unknown");
Expand Down Expand Up @@ -113,9 +112,7 @@ Pin Pin::create(std::string_view str) {
}
} catch (const AssertionFailed& ex) { // We shouldn't get here under normal circumstances.
log_error("ERR: " << str << " - " << ex.what());
char buf[255];
snprintf(buf, 255, "ERR: %s - %s", str, ex.what());
Assert(false, buf);
Assert(false, "");
// return Pin(new Pins::ErrorPinDetail(str.str()));
}
}
Expand Down
27 changes: 7 additions & 20 deletions FluidNC/src/Pins/DebugPinDetail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,15 @@

#include "../UartChannel.h"
#include <esp32-hal.h> // millis()
#include <cstdio> // vsnprintf
#include <cstdarg>

namespace Pins {
inline void WriteSerial(const char* format, ...) {
char buf[50];
va_list arg;
va_list copy;
va_start(arg, format);
va_copy(copy, arg);
size_t len = vsnprintf(buf, 50, format, arg);
va_end(copy);
log_msg_to(Uart0, buf);
va_end(arg);
}

// I/O:
void DebugPinDetail::write(int high) {
if (high != int(_isHigh)) {
_isHigh = bool(high);
if (shouldEvent()) {
WriteSerial("Write %s < %d", toString(), high);
log_msg_to(Uart0, "Write " << toString() << " < " << high);
}
}
_implementation->write(high);
Expand All @@ -35,7 +22,7 @@ namespace Pins {
int DebugPinDetail::read() {
auto result = _implementation->read();
if (shouldEvent()) {
WriteSerial("Read %s > %d", toString(), result);
log_msg_to(Uart0, "Read " << toString() << " > " << result);
}
return result;
}
Expand Down Expand Up @@ -63,10 +50,10 @@ namespace Pins {
if (value.has(PinAttributes::InitialOn)) {
buf[n++] = '+';
}
buf[n++] = 0;
buf[n++] = '\0';

if (shouldEvent()) {
WriteSerial("Set pin attr %s = %s", toString(), buf);
log_msg_to(Uart0, "Set pin attr " << toString() << " = " << buf);
}
_implementation->setAttr(value);
}
Expand All @@ -76,7 +63,7 @@ namespace Pins {
void DebugPinDetail::CallbackHandler::handle(void* arg) {
auto handler = static_cast<CallbackHandler*>(arg);
if (handler->_myPin->shouldEvent()) {
WriteSerial("Received ISR on %s", handler->_myPin->toString());
log_msg_to(Uart0, "Received ISR on " << handler->_myPin->toString());
}
handler->callback(handler->argument);
}
Expand All @@ -88,7 +75,7 @@ namespace Pins {
_isrHandler.callback = callback;

if (shouldEvent()) {
WriteSerial("Attaching interrupt to pin %s, mode %d", toString(), mode);
log_msg_to(Uart0, "Attaching interrupt to pin " << toString() << ", mode " << mode);
}
_implementation->attachInterrupt(_isrHandler.handle, &_isrHandler, mode);
}
Expand All @@ -109,7 +96,7 @@ namespace Pins {
} else if (_eventCount == 10) {
_lastEvent = time;
++_eventCount;
WriteSerial("Suppressing events...");
log_msg_to(Uart0, "Suppressing events...");
return false;
} else {
_lastEvent = time;
Expand Down

0 comments on commit 608e614

Please sign in to comment.