diff --git a/src/main.cpp b/src/main.cpp index 1f01c52..38ff65f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -190,6 +190,11 @@ void ReportVersion(const mp::RequestMsg &rq) { case 2: v = project_version_revision; break; + case 3: + // @@TODO may be allow reporting uint16_t number of errors, + // but anything beyond 255 errors means there is something seriously wrong with the MMU + v = mg::globals.DriveErrors(); + break; default: v = 0; break; diff --git a/src/modules/buttons.cpp b/src/modules/buttons.cpp index 5c3b6a1..cd3f855 100644 --- a/src/modules/buttons.cpp +++ b/src/modules/buttons.cpp @@ -10,8 +10,8 @@ Buttons buttons; int8_t Buttons::DecodeADC(uint16_t rawADC) { // decode 3 buttons' levels from one ADC // Button 1 - 0 - // Button 2 - 344 - // Button 3 - 516 + // Button 2 - 90 + // Button 3 - 170 // Doesn't handle multiple pressed buttons at once for (int8_t buttonIndex = 0; buttonIndex < config::buttonCount; ++buttonIndex) { diff --git a/src/modules/globals.cpp b/src/modules/globals.cpp index ac9649c..eaf86b7 100644 --- a/src/modules/globals.cpp +++ b/src/modules/globals.cpp @@ -28,5 +28,13 @@ void Globals::SetFilamentLoaded(bool newFilamentLoaded) { filamentLoaded = newFilamentLoaded; } +uint16_t Globals::DriveErrors() const { + return modules::permanent_storage::DriveError::get(); +} + +void Globals::IncDriveErrors() { + modules::permanent_storage::DriveError::increment(); +} + } // namespace globals } // namespace modules diff --git a/src/modules/globals.h b/src/modules/globals.h index f164c04..d64176c 100644 --- a/src/modules/globals.h +++ b/src/modules/globals.h @@ -33,6 +33,13 @@ public: /// @param newFilamentLoaded new state void SetFilamentLoaded(bool newFilamentLoaded); + /// @returns the total number of MMU errors so far + /// Errors are stored in the EEPROM + uint16_t DriveErrors() const; + + /// Increment MMU errors by 1 + void IncDriveErrors(); + private: uint8_t activeSlot; bool filamentLoaded; diff --git a/src/modules/motion.cpp b/src/modules/motion.cpp index b358149..8500b06 100644 --- a/src/modules/motion.cpp +++ b/src/modules/motion.cpp @@ -100,7 +100,7 @@ st_timer_t Motion::Step() { return next; } -void ISR() {} +void Isr() {} } // namespace motion } // namespace modules diff --git a/src/modules/motion.h b/src/modules/motion.h index c8c377e..e3a88b5 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -248,7 +248,7 @@ private: }; /// ISR stepping routine -//extern void ISR(); +//extern void Isr(); extern Motion motion; diff --git a/src/modules/protocol.cpp b/src/modules/protocol.cpp index a230fd3..2b60404 100644 --- a/src/modules/protocol.cpp +++ b/src/modules/protocol.cpp @@ -51,11 +51,11 @@ DecodeStatus Protocol::DecodeRequest(uint8_t c) { return DecodeStatus::Error; } case RequestStates::Value: - if (c >= '0' && c <= '9') { + if (IsDigit(c)) { requestMsg.value *= 10; requestMsg.value += c - '0'; return DecodeStatus::NeedMoreData; - } else if (c == '\n') { + } else if (IsNewLine(c)) { rqState = RequestStates::Code; return DecodeStatus::MessageCompleted; } else { @@ -64,7 +64,7 @@ DecodeStatus Protocol::DecodeRequest(uint8_t c) { return DecodeStatus::Error; } default: //case error: - if (c == '\n') { + if (IsNewLine(c)) { rqState = RequestStates::Code; return DecodeStatus::MessageCompleted; } else { @@ -107,7 +107,7 @@ DecodeStatus Protocol::DecodeResponse(uint8_t c) { return DecodeStatus::Error; } case ResponseStates::RequestValue: - if (c >= '0' && c <= '9') { + if (IsDigit(c)) { responseMsg.request.value *= 10; responseMsg.request.value += c - '0'; return DecodeStatus::NeedMoreData; @@ -135,11 +135,11 @@ DecodeStatus Protocol::DecodeResponse(uint8_t c) { return DecodeStatus::Error; } case ResponseStates::ParamValue: - if (c >= '0' && c <= '9') { + if (IsDigit(c)) { responseMsg.paramValue *= 10; responseMsg.paramValue += c - '0'; return DecodeStatus::NeedMoreData; - } else if (c == '\n') { + } else if (IsNewLine(c)) { rspState = ResponseStates::RequestCode; return DecodeStatus::MessageCompleted; } else { @@ -148,7 +148,7 @@ DecodeStatus Protocol::DecodeResponse(uint8_t c) { return DecodeStatus::Error; } default: //case error: - if (c == '\n') { + if (IsNewLine(c)) { rspState = ResponseStates::RequestCode; return DecodeStatus::MessageCompleted; } else { diff --git a/src/modules/protocol.h b/src/modules/protocol.h index d55e655..dea8ea1 100644 --- a/src/modules/protocol.h +++ b/src/modules/protocol.h @@ -151,6 +151,13 @@ private: ResponseStates rspState; ResponseMsg responseMsg; + + static bool IsNewLine(uint8_t c) { + return c == '\n' || c == '\r'; + } + static bool IsDigit(uint8_t c) { + return c >= '0' && c <= '9'; + } }; } // namespace protocol diff --git a/src/modules/timebase.cpp b/src/modules/timebase.cpp index a55ebbe..3db6852 100644 --- a/src/modules/timebase.cpp +++ b/src/modules/timebase.cpp @@ -9,7 +9,7 @@ Timebase timebase; void Timebase::Init() { } -void Timebase::ISR() { +void Timebase::Isr() { } uint16_t Timebase::Millis() const { diff --git a/src/modules/timebase.h b/src/modules/timebase.h index 8c29c0b..0241e42 100644 --- a/src/modules/timebase.h +++ b/src/modules/timebase.h @@ -23,7 +23,7 @@ public: private: uint16_t ms; - static void ISR(); + static void Isr(); }; /// The one and only instance of Selector in the FW diff --git a/tests/unit/modules/stubs/stub_timebase.cpp b/tests/unit/modules/stubs/stub_timebase.cpp index 04267fe..d4e57f9 100644 --- a/tests/unit/modules/stubs/stub_timebase.cpp +++ b/tests/unit/modules/stubs/stub_timebase.cpp @@ -10,7 +10,7 @@ uint16_t millis = 0; void Timebase::Init() {} -void Timebase::ISR() {} +void Timebase::Isr() {} uint16_t Timebase::Millis() const { return millis;