Skip to content

Commit

Permalink
Handle expander errors during pin initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley committed Mar 10, 2025
1 parent 18aff2e commit b585b4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
23 changes: 16 additions & 7 deletions FluidNC/src/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,11 @@ void Channel::handleRealtimeCharacter(uint8_t ch) {

_active = true;
if (cmd == PinACK) {
// log_debug("ACK");
_ackwait = false;
_ackwait = 0;
return;
}
if (cmd == PinNAK) {
log_error("Channel device rejected config");
// log_debug("NAK");
_ackwait = false;
_ackwait = -1;
return;
}

Expand Down Expand Up @@ -247,11 +244,23 @@ Error Channel::pollLine(char* line) {
return Error::NoData;
}

void Channel::setAttr(int index, bool* value, const std::string& attrString, const char* tag) {
bool Channel::setAttr(int index, bool* value, const std::string& attrString, const char* tag) {
if (value) {
_pin_values[index] = value;
}
out_acked(attrString, tag);
// out_acked(attrString, tag);
out(attrString, tag);
_ackwait = 1;
for (int i = 0; i < 20; i++) {
pollLine(nullptr);
if (_ackwait < 1) {
return _ackwait == 0;
}
delay_us(100);
}
_ackwait = 0;
log_error("IO Expander is unresponsive");
return false;
}

void Channel::out(const char* s, const char* tag) {
Expand Down
4 changes: 2 additions & 2 deletions FluidNC/src/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Channel : public Stream {
Channel(const char* name, int num, bool addCR = false);
virtual ~Channel() = default;

bool _ackwait = false;
int _ackwait = 0; // 1 - waiting, 0 - ACKed, -1 - NAKed

virtual void handle() {};
virtual Error pollLine(char* line);
Expand Down Expand Up @@ -191,7 +191,7 @@ class Channel : public Stream {
virtual void out(const std::string& s, const char* tag);
virtual void out_acked(const std::string& s, const char* tag);

void setAttr(int index, bool* valuep, const std::string& s, const char* tag);
bool setAttr(int index, bool* valuep, const std::string& s, const char* tag);

void ready();
void registerEvent(uint8_t code, EventPin* obj);
Expand Down
5 changes: 4 additions & 1 deletion FluidNC/src/Pins/ChannelPinDetail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ namespace Pins {
}

// The second parameter is used to maintain a list of pin values in the Channel
_channel->setAttr(_index, _attributes.has(Pins::PinAttributes::Input) ? &this->_value : nullptr, s, "INI:");
Assert(_channel->setAttr(_index, _attributes.has(Pins::PinAttributes::Input) ? &this->_value : nullptr, s, "INI:"),
"Expander pin configuration failed: %s %s",
_channel->name().c_str(),
s.c_str());
}
PinAttributes ChannelPinDetail::getAttr() const {
return _attributes;
Expand Down

0 comments on commit b585b4d

Please sign in to comment.