diff --git a/Marlin/src/feature/mmu3/mmu3_protocol_logic.cpp b/Marlin/src/feature/mmu3/mmu3_protocol_logic.cpp index cf74e669b8..4323925b6b 100644 --- a/Marlin/src/feature/mmu3/mmu3_protocol_logic.cpp +++ b/Marlin/src/feature/mmu3/mmu3_protocol_logic.cpp @@ -707,7 +707,7 @@ namespace MMU3 { } bool ProtocolLogic::Elapsed(uint32_t timeout) const { - return _millis() >= (lastUARTActivityMs + timeout); + return ELAPSED(_millis(), lastUARTActivityMs + timeout); } void ProtocolLogic::RecordUARTActivity() { @@ -716,7 +716,7 @@ namespace MMU3 { void ProtocolLogic::RecordReceivedByte(uint8_t c) { lastReceivedBytes[lrb] = c; - lrb = (lrb + 1) % lastReceivedBytes.size(); + lrb = (lrb + 1) % COUNT(lastReceivedBytes); } constexpr char NibbleToChar(uint8_t c) { @@ -728,13 +728,13 @@ namespace MMU3 { } void ProtocolLogic::FormatLastReceivedBytes(char *dst) { - for (uint8_t i = 0; i < lastReceivedBytes.size(); ++i) { - uint8_t b = lastReceivedBytes[(lrb - i - 1) % lastReceivedBytes.size()]; + for (uint8_t i = 0; i < COUNT(lastReceivedBytes); ++i) { + uint8_t b = lastReceivedBytes[(COUNT(lastReceivedBytes) - 1 + (lrb - i)) % COUNT(lastReceivedBytes)]; dst[i * 3] = NibbleToChar(b >> 4); dst[i * 3 + 1] = NibbleToChar(b & 0xf); dst[i * 3 + 2] = ' '; } - dst[(lastReceivedBytes.size() - 1) * 3 + 2] = 0; // terminate properly + dst[(COUNT(lastReceivedBytes) - 1) * 3 + 2] = 0; // terminate properly } void ProtocolLogic::FormatLastResponseMsgAndClearLRB(char *dst) { @@ -777,18 +777,18 @@ namespace MMU3 { } void ProtocolLogic::LogError(const char *reason_P) { - char lrb[lastReceivedBytes.size() * 3]; - FormatLastReceivedBytes(lrb); + char _lrb[COUNT(lastReceivedBytes) * 3]; + FormatLastReceivedBytes(_lrb); MMU2_ERROR_MSGRPGM(reason_P); SERIAL_ECHOPGM(", last bytes: "); - SERIAL_ECHOLN(lrb); + SERIAL_ECHOLN(_lrb); } void ProtocolLogic::LogResponse() { - char lrb[lastReceivedBytes.size()]; - FormatLastResponseMsgAndClearLRB(lrb); - MMU2_ECHO_MSGLN(lrb); + char _lrb[COUNT(lastReceivedBytes)]; + FormatLastResponseMsgAndClearLRB(_lrb); + MMU2_ECHO_MSGLN(_lrb); } StepStatus ProtocolLogic::SuppressShortDropOuts(const char *msg_P, StepStatus ss) { diff --git a/Marlin/src/feature/mmu3/mmu3_protocol_logic.h b/Marlin/src/feature/mmu3/mmu3_protocol_logic.h index 2fef77c276..30f9c5d0d5 100644 --- a/Marlin/src/feature/mmu3/mmu3_protocol_logic.h +++ b/Marlin/src/feature/mmu3/mmu3_protocol_logic.h @@ -36,24 +36,8 @@ #include "mmu_hw/buttons.h" #include "mmu_hw/registers.h" #include "mmu3_protocol.h" - - // #include std array is not available on AVR ... we need to "fake" it - namespace std { - template - class array { - T data[N]; - public: - array() = default; - inline constexpr T *begin() const { return data; } - inline constexpr T *end() const { return data + N; } - static constexpr uint8_t size() { return N; } - inline T &operator[](uint8_t i) { return data[i]; } - }; - } // std - #else // !__AVR__ - #include #include "mmu_hw/error_codes.h" #include "mmu_hw/progress_codes.h" @@ -351,8 +335,7 @@ namespace MMU3 { Protocol protocol; //!< protocol codec - std::array lastReceivedBytes; //!< remembers the last few bytes of incoming communication for diagnostic purposes - uint8_t lrb; + uint8_t lrb, lastReceivedBytes[16]; //!< keep the last few bytes of incoming communication for diagnostic purposes ErrorCode errorCode; //!< last received error code from the MMU ProgressCode progressCode; //!< last received progress code from the MMU