🧑💻 Misc. MMU3 tweaks, less STL
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -36,24 +36,8 @@
|
||||
#include "mmu_hw/buttons.h"
|
||||
#include "mmu_hw/registers.h"
|
||||
#include "mmu3_protocol.h"
|
||||
|
||||
// #include <array> std array is not available on AVR ... we need to "fake" it
|
||||
namespace std {
|
||||
template <typename T, uint8_t N>
|
||||
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 <array>
|
||||
#include "mmu_hw/error_codes.h"
|
||||
#include "mmu_hw/progress_codes.h"
|
||||
|
||||
@@ -351,8 +335,7 @@ namespace MMU3 {
|
||||
|
||||
Protocol protocol; //!< protocol codec
|
||||
|
||||
std::array<uint8_t, 16> 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
|
||||
|
||||
Reference in New Issue
Block a user