diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d6da806d2..f1755f874 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2820,15 +2820,13 @@ static void gcode_G80() run = false; #endif //PINDA_THERMISTOR - uint8_t nMeasPoints = code_seen('N') ? code_value_uint8() : eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR); - if (nMeasPoints != 7) { - nMeasPoints = 3; - } + uint8_t nMeasPoints = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR); + if (uint8_t codeSeen = code_seen('N'), value = code_value_uint8(); codeSeen && (value == 7 || value == 3)) + nMeasPoints = value; - uint8_t nProbeRetryCount = code_seen('C') ? code_value_uint8() : eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR); - if (nProbeRetryCount > 10) { - nProbeRetryCount = 10; - } + uint8_t nProbeRetryCount = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR); + if (uint8_t codeSeen = code_seen('C'), value = code_value_uint8(); codeSeen && value >= 1 && value <= 10) + nProbeRetryCount = value; const float area_min_x = code_seen('X') ? code_value() - x_mesh_density - X_PROBE_OFFSET_FROM_EXTRUDER : -INFINITY; const float area_min_y = code_seen('Y') ? code_value() - y_mesh_density - Y_PROBE_OFFSET_FROM_EXTRUDER : -INFINITY; @@ -2973,7 +2971,7 @@ static void gcode_G80() static uint8_t g80_fail_cnt = 0; if (mesh_point != MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS) { if (g80_fail_cnt++ >= 2) { - kill(PSTR("Mesh bed leveling failed. Please run Z calibration.")); + kill(_i("Mesh bed leveling failed. Please run Z calibration.")); ////MSG_MBL_FAILED_Z_CAL c=20 r=4 } Sound_MakeSound(e_SOUND_TYPE_StandardAlert); bool bState; @@ -3328,10 +3326,10 @@ static void mmu_M600_filament_change_screen(uint8_t eject_slot) { manage_heater(); manage_inactivity(true); - btn = MMU2::mmu2.getPrinterButtonOperation(); + btn = MMU2::mmu2.GetPrinterButtonOperation(); if (btn != MMU2::Buttons::NoButton) { - MMU2::mmu2.clearPrinterButtonOperation(); + MMU2::mmu2.ClearPrinterButtonOperation(); if (btn == MMU2::Buttons::Eject) { if (eject_slot != (uint8_t)MMU2::FILAMENT_UNKNOWN) { @@ -4886,9 +4884,9 @@ void process_commands() G80 [ N | C | O | M | L | R | F | B | X | Y | W | H ] #### Parameters - - `N` - Number of mesh points on x axis. Default is 3. Valid values are 3 and 7. - - `C` - Probe retry counts. Default 3 max. 10 - - `O` - Return to origin. Default 1 (true) + - `N` - Number of mesh points on x axis. Default is value stored in EEPROM. Valid values are 3 and 7. + - `C` - Probe retry counts. Default is value stored in EEPROM. Valid values are 1 to 10. + - `O` - Return to origin. Default is 1. Valid values are 0 (false) and 1 (true). - `M` - Use magnet compensation. Will only be used if number of mesh points is set to 7. Default is value stored in EEPROM. Valid values are 0 (false) and 1 (true). Using the following parameters enables additional "manual" bed leveling correction. Valid values are -100 microns to 100 microns. diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index dcc070ce0..333a9d0e1 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -81,8 +81,7 @@ void MMU2::StopKeepPowered() { void MMU2::Tune() { switch (lastErrorCode) { case ErrorCode::HOMING_SELECTOR_FAILED: - case ErrorCode::HOMING_IDLER_FAILED: - { + case ErrorCode::HOMING_IDLER_FAILED: { // Prompt a menu for different values tuneIdlerStallguardThreshold(); break; @@ -115,7 +114,7 @@ void MMU2::ResetX0() { logic.ResetMMU(); // Send soft reset } -void MMU2::ResetX42(){ +void MMU2::ResetX42() { logic.ResetMMU(42); } @@ -196,7 +195,7 @@ void __attribute__((noinline)) MMU2::mmu_loop_inner(bool reportErrors) { if (isErrorScreenRunning()) { // Call this every iteration to keep the knob rotation responsive // This includes when mmu_loop is called within manage_response - ReportErrorHook((CommandInProgress)logic.CommandInProgress(), (uint16_t)lastErrorCode, uint8_t(lastErrorSource)); + ReportErrorHook((CommandInProgress)logic.CommandInProgress(), lastErrorCode, uint8_t(lastErrorSource)); } } @@ -204,7 +203,7 @@ void MMU2::CheckFINDARunout() { // Check for FINDA filament runout if (!FindaDetectsFilament() && check_fsensor()) { SERIAL_ECHOLNPGM("FINDA filament runout!"); - stop_and_save_print_to_ram(0, 0); + marlin_stop_and_save_print_to_ram(); restore_print_from_ram_and_continue(0); if (SpoolJoin::spooljoin.isSpoolJoinEnabled() && get_current_tool() != (uint8_t)FILAMENT_UNKNOWN){ // Can't auto if F=? enquecommand_front_P(PSTR("M600 AUTO")); // save print and run M600 command @@ -218,10 +217,10 @@ struct ReportingRAII { CommandInProgress cip; explicit inline __attribute__((always_inline)) ReportingRAII(CommandInProgress cip) : cip(cip) { - BeginReport(cip, (uint16_t)ProgressCode::EngagingIdler); + BeginReport(cip, ProgressCode::EngagingIdler); } inline __attribute__((always_inline)) ~ReportingRAII() { - EndReport(cip, (uint16_t)ProgressCode::OK); + EndReport(cip, ProgressCode::OK); } }; @@ -237,7 +236,7 @@ bool MMU2::WaitForMMUReady() { } } -bool MMU2::RetryIfPossible(uint16_t ec) { +bool MMU2::RetryIfPossible(ErrorCode ec) { if (logic.RetryAttempts()) { SetButtonResponse(ButtonOperations::Retry); // check, that Retry is actually allowed on that operation @@ -256,23 +255,13 @@ bool MMU2::RetryIfPossible(uint16_t ec) { bool MMU2::VerifyFilamentEnteredPTFE() { planner_synchronize(); - if (WhereIsFilament() == FilamentState::NOT_PRESENT) + if (WhereIsFilament() != FilamentState::AT_FSENSOR) return false; - uint8_t fsensorState = 0; - uint8_t fsensorStateLCD = 0; - uint8_t lcd_cursor_col = 0; // MMU has finished its load, push the filament further by some defined constant length // If the filament sensor reads 0 at any moment, then report FAILURE - - const float delta_mm = MMU2_CHECK_FILAMENT_PRESENCE_EXTRUSION_LENGTH - logic.ExtraLoadDistance(); - - // The total length is twice delta_mm. Divide that length by number of pixels - // available to get length per pixel. - // Note: Below is the reciprocal of (2 * delta_mm) / LCD_WIDTH [mm/pixel] - const float pixel_per_mm = 0.5f * float(LCD_WIDTH) / (delta_mm); - - TryLoadUnloadProgressbarInit(); + const float tryload_length = MMU2_CHECK_FILAMENT_PRESENCE_EXTRUSION_LENGTH - logic.ExtraLoadDistance(); + TryLoadUnloadReporter tlur(tryload_length); /* The position is a triangle wave // current position is not zero, it is an offset @@ -284,7 +273,7 @@ bool MMU2::VerifyFilamentEnteredPTFE() { // in the slope's sign or check the last machine position. // y(x) // ▲ - // │ ^◄────────── delta_mm + current_position + // │ ^◄────────── tryload_length + current_position // machine │ / \ // position │ / \◄────────── stepper_position_mm + current_position // (mm) │ / \ @@ -295,42 +284,24 @@ bool MMU2::VerifyFilamentEnteredPTFE() { // pixel # */ + bool filament_inserted = true; // expect success // Pixel index will go from 0 to 10, then back from 10 to 0 // The change in this number is used to indicate a new pixel // should be drawn on the display - uint8_t dpixel1 = 0; - uint8_t dpixel0 = 0; for (uint8_t move = 0; move < 2; move++) { - MoveE(move == 0 ? delta_mm : -delta_mm, MMU2_VERIFY_LOAD_TO_NOZZLE_FEED_RATE); + extruder_move(move == 0 ? tryload_length : -tryload_length, MMU2_VERIFY_LOAD_TO_NOZZLE_FEED_RATE); while (planner_any_moves()) { - // Wait for move to finish and monitor the fsensor the entire time - // A single 0 reading will set the bit. - fsensorStateLCD |= (WhereIsFilament() == FilamentState::NOT_PRESENT); - fsensorState |= fsensorStateLCD; // No need to do the above comparison twice, just bitwise OR - - // Always round up, you can only have 'whole' pixels. (floor is also an option) - dpixel1 = ceil((stepper_get_machine_position_E_mm() - planner_get_current_position_E()) * pixel_per_mm); - if (dpixel1 - dpixel0) { - dpixel0 = dpixel1; - if (lcd_cursor_col > (LCD_WIDTH - 1)) lcd_cursor_col = LCD_WIDTH - 1; - TryLoadUnloadProgressbar(lcd_cursor_col++, fsensorStateLCD); - fsensorStateLCD = 0; // Clear temporary bit - } + filament_inserted = filament_inserted && (WhereIsFilament() == FilamentState::AT_FSENSOR); + tlur.Progress(filament_inserted); safe_delay_keep_alive(0); } } - Disable_E0(); - TryLoadUnloadProgressbarEcho(); - TryLoadUnloadProgressbarDeinit(); - - if (fsensorState) { + if (!filament_inserted) { IncrementLoadFails(); - return false; - } else { - // else, happy printing! :) - return true; } + tlur.DumpToSerial(); + return filament_inserted; } bool MMU2::ToolChangeCommonOnce(uint8_t slot) { @@ -355,8 +326,6 @@ bool MMU2::ToolChangeCommonOnce(uint8_t slot) { // but honestly - if the MMU restarts during every toolchange, // something else is seriously broken and stopping a print is probably our best option. } - // reset current position to whatever the planner thinks it is - planner_set_current_position_E(planner_get_current_position_E()); if (VerifyFilamentEnteredPTFE()) { return true; // success } else { // Prepare a retry attempt @@ -455,7 +424,7 @@ uint8_t MMU2::get_tool_change_tool() const { bool MMU2::set_filament_type(uint8_t /*slot*/, uint8_t /*type*/) { if (!WaitForMMUReady()) return false; - + // @@TODO - this is not supported in the new MMU yet // slot = slot; // @@TODO // type = type; // @@TODO @@ -496,9 +465,11 @@ bool MMU2::unload() { WaitForHotendTargetTempBeep(); - ReportingRAII rep(CommandInProgress::UnloadFilament); - UnloadInner(); - + { + ReportingRAII rep(CommandInProgress::UnloadFilament); + UnloadInner(); + } + ScreenUpdateEnable(); return true; } @@ -526,10 +497,10 @@ bool MMU2::cut_filament(uint8_t slot, bool enableFullScreenMsg /*= true*/) { ReportingRAII rep(CommandInProgress::CutFilament); CutFilamentInner(slot); + extruder = MMU2_NO_TOOL; + tool_change_extruder = MMU2_NO_TOOL; + MakeSound(SoundType::Confirm); } - extruder = MMU2_NO_TOOL; - tool_change_extruder = MMU2_NO_TOOL; - MakeSound(SoundType::Confirm); ScreenUpdateEnable(); return true; } @@ -548,20 +519,18 @@ bool MMU2::load_filament(uint8_t slot) { return false; FullScreenMsgLoad(slot); - - ReportingRAII rep(CommandInProgress::LoadFilament); - for (;;) { - Disable_E0(); - logic.LoadFilament(slot); - if (manage_response(false, false)) - break; - IncrementMMUFails(); + { + ReportingRAII rep(CommandInProgress::LoadFilament); + for (;;) { + Disable_E0(); + logic.LoadFilament(slot); + if (manage_response(false, false)) + break; + IncrementMMUFails(); + } + MakeSound(SoundType::Confirm); } - - MakeSound(SoundType::Confirm); - ScreenUpdateEnable(); - return true; } @@ -611,10 +580,11 @@ bool MMU2::eject_filament(uint8_t slot, bool enableFullScreenMsg /* = true */) { break; IncrementMMUFails(); } + extruder = MMU2_NO_TOOL; + tool_change_extruder = MMU2_NO_TOOL; + MakeSound(Confirm); } - extruder = MMU2_NO_TOOL; - tool_change_extruder = MMU2_NO_TOOL; - MakeSound(Confirm); + ScreenUpdateEnable(); return true; } @@ -647,14 +617,14 @@ void MMU2::SaveAndPark(bool move_axes) { // In case a power panic happens while waiting for the user // take a partial back up of print state into RAM (current position, etc.) - refresh_print_state_in_ram(); + marlin_refresh_print_state_in_ram(); if (move_axes) { mmu_print_saved |= SavedState::ParkExtruder; resume_position = planner_current_position(); // save current pos // lift Z - MoveRaiseZ(MMU_ERR_Z_PAUSE_LIFT); + move_raise_z(MMU_ERR_Z_PAUSE_LIFT); // move XY aside if (all_axes_homed()) { @@ -706,14 +676,14 @@ void MMU2::ResumeUnpark() { // From this point forward, power panic should not use // the partial backup in RAM since the extruder is no // longer in parking position - clear_print_state_in_ram(); + marlin_clear_print_state_in_ram(); mmu_print_saved &= ~(SavedState::ParkExtruder); } } void MMU2::CheckUserInput() { - auto btn = ButtonPressed((uint16_t)lastErrorCode); + auto btn = ButtonPressed(lastErrorCode); // Was a button pressed on the MMU itself instead of the LCD? if (btn == Buttons::NoButton && lastButton != Buttons::NoButton) { @@ -737,12 +707,12 @@ void MMU2::CheckUserInput() { case Buttons::Middle: case Buttons::Right: SERIAL_ECHOPGM("CheckUserInput-btnLMR "); - SERIAL_ECHOLN(btn); + SERIAL_ECHOLN(buttons_to_uint8t(btn)); ResumeHotendTemp(); // Recover the hotend temp before we attempt to do anything else... if (mmu2.MMULastErrorSource() == MMU2::ErrorSourceMMU) { // Do not send a button to the MMU unless the MMU is in error state - Button(btn); + Button(buttons_to_uint8t(btn)); } // A quick hack: for specific error codes move the E-motor every time. @@ -763,7 +733,7 @@ void MMU2::CheckUserInput() { case Buttons::Load: case Buttons::Eject: // High level operation - setPrinterButtonOperation(btn); + SetPrinterButtonOperation(btn); break; case Buttons::ResetMMU: Reset(ResetPin); // we cannot do power cycle on the MK3 @@ -929,8 +899,8 @@ void MMU2::execute_extruder_sequence(const E_Step *sequence, uint8_t steps) { planner_synchronize(); const E_Step *step = sequence; - for (uint8_t i = steps; i ; --i) { - MoveE(pgm_read_float(&(step->extrude)), pgm_read_float(&(step->feedRate))); + for (uint8_t i = steps; i > 0; --i) { + extruder_move(pgm_read_float(&(step->extrude)), pgm_read_float(&(step->feedRate))); step++; } planner_synchronize(); // it looks like it's better to sync the moves at the end - smoother move (if the sequence is not too long). @@ -976,12 +946,13 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { if (ec != lastErrorCode) { // deduplicate: only report changes in error codes into the log lastErrorCode = ec; lastErrorSource = res; - LogErrorEvent_P(_O(PrusaErrorTitle(PrusaErrorCodeIndex((uint16_t)ec)))); + LogErrorEvent_P(_O(PrusaErrorTitle(PrusaErrorCodeIndex(ec)))); if (ec != ErrorCode::OK && ec != ErrorCode::FILAMENT_EJECTED && ec != ErrorCode::FILAMENT_CHANGE) { IncrementMMUFails(); // check if it is a "power" failure - we consider TMC-related errors as power failures + // clang-format off static constexpr uint16_t tmcMask = ( (uint16_t)ErrorCode::TMC_IOIN_MISMATCH | (uint16_t)ErrorCode::TMC_RESET @@ -990,6 +961,7 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { | (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_WARN | (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_ERROR | (uint16_t)ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION ) & 0x7fffU; // skip the top bit + // clang-format on static_assert(tmcMask == 0x7e00); // just make sure we fail compilation if any of the TMC error codes change if ((uint16_t)ec & tmcMask) { // @@TODO can be optimized to uint8_t operation @@ -999,11 +971,11 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { } } - if (!mmu2.RetryIfPossible((uint16_t)ec)) { + if (!mmu2.RetryIfPossible(ec)) { // If retry attempts are all used up // or if 'Retry' operation is not available - // raise the MMU error sceen and wait for user input - ReportErrorHook((CommandInProgress)logic.CommandInProgress(), (uint16_t)ec, uint8_t(lastErrorSource)); + // raise the MMU error screen and wait for user input + ReportErrorHook((CommandInProgress)logic.CommandInProgress(), ec, uint8_t(lastErrorSource)); } static_assert(mmu2Magic[0] == 'M' @@ -1016,8 +988,8 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { } void MMU2::ReportProgress(ProgressCode pc) { - ReportProgressHook((CommandInProgress)logic.CommandInProgress(), (uint16_t)pc); - LogEchoEvent_P(_O(ProgressCodeToText((uint16_t)pc))); + ReportProgressHook((CommandInProgress)logic.CommandInProgress(), pc); + LogEchoEvent_P(_O(ProgressCodeToText(pc))); } void MMU2::OnMMUProgressMsg(ProgressCode pc) { @@ -1058,7 +1030,7 @@ void MMU2::OnMMUProgressMsgChanged(ProgressCode pc) { } void __attribute__((noinline)) MMU2::HelpUnloadToFinda() { - MoveE(-MMU2_RETRY_UNLOAD_TO_FINDA_LENGTH, MMU2_RETRY_UNLOAD_TO_FINDA_FEED_RATE); + extruder_move(-MMU2_RETRY_UNLOAD_TO_FINDA_LENGTH, MMU2_RETRY_UNLOAD_TO_FINDA_FEED_RATE); } void MMU2::OnMMUProgressMsgSame(ProgressCode pc) { @@ -1089,7 +1061,7 @@ void MMU2::OnMMUProgressMsgSame(ProgressCode pc) { // After the MMU knows the FSENSOR is triggered it will: // 1. Push the filament by additional 30mm (see fsensorToNozzle) // 2. Disengage the idler and push another 2mm. - MoveE(logic.ExtraLoadDistance() + 2, logic.PulleySlowFeedRate()); + extruder_move(logic.ExtraLoadDistance() + 2, logic.PulleySlowFeedRate()); break; case FilamentState::NOT_PRESENT: // fsensor not triggered, continue moving extruder @@ -1099,7 +1071,7 @@ void MMU2::OnMMUProgressMsgSame(ProgressCode pc) { // than 450mm because the firmware will ignore too long extrusions // for safety reasons. See PREVENT_LENGTHY_EXTRUDE. // Use 350mm to be safely away from the prevention threshold - MoveE(350.0f, logic.PulleySlowFeedRate()); + extruder_move(350.0f, logic.PulleySlowFeedRate()); } break; default: diff --git a/Firmware/mmu2.h b/Firmware/mmu2.h index 0c4df18e1..750154ce0 100644 --- a/Firmware/mmu2.h +++ b/Firmware/mmu2.h @@ -5,14 +5,11 @@ #include "mmu2_marlin.h" #ifdef __AVR__ -#include "mmu2_protocol_logic.h" + #include "mmu2_protocol_logic.h" typedef float feedRate_t; #else - #include "protocol_logic.h" - #include "../../Marlin/src/core/macros.h" - #include "../../Marlin/src/core/types.h" #include #endif @@ -48,9 +45,9 @@ public: /// Different levels of resetting the MMU enum ResetForm : uint8_t { - Software = 0, ///< sends a X0 command into the MMU, the MMU will watchdog-reset itself - ResetPin = 1, ///< trigger the reset pin of the MMU - CutThePower = 2, ///< power off and power on (that includes +5V and +24V power lines) + Software = 0, ///< sends a X0 command into the MMU, the MMU will watchdog-reset itself + ResetPin = 1, ///< trigger the reset pin of the MMU + CutThePower = 2, ///< power off and power on (that includes +5V and +24V power lines) EraseEEPROM = 42, ///< erase MMU EEPROM and then perform a software reset }; @@ -182,7 +179,7 @@ public: /// Automagically "press" a Retry button if we have any retry attempts left /// @param ec ErrorCode enum value /// @returns true if auto-retry is ongoing, false when retry is unavailable or retry attempts are all used up - bool RetryIfPossible(uint16_t ec); + bool RetryIfPossible(ErrorCode ec); /// @return count for toolchange in current print inline uint16_t ToolChangeCounter() const { return toolchange_counter; }; @@ -201,9 +198,9 @@ public: }; inline void InvokeErrorScreen(ErrorCode ec) { // The printer may not raise an error when the MMU is busy - if ( !logic.CommandInProgress() // MMU must not be busy + if (!logic.CommandInProgress() // MMU must not be busy && MMUCurrentErrorCode() == ErrorCode::OK // The protocol must not be in error state - && lastErrorCode != ec) // The error code is not a duplicate + && lastErrorCode != ec) // The error code is not a duplicate { ReportError(ec, ErrorSource::ErrorSourcePrinter); } @@ -217,21 +214,23 @@ public: /// @brief Queue a button operation which the printer can act upon /// @param btn Button operation - inline void setPrinterButtonOperation(Buttons btn) { + inline void SetPrinterButtonOperation(Buttons btn) { printerButtonOperation = btn; } /// @brief Get the printer button operation /// @return currently set printer button operation, it can be NoButton if nothing is queued - inline Buttons getPrinterButtonOperation() { + inline Buttons GetPrinterButtonOperation() { return printerButtonOperation; } - inline void clearPrinterButtonOperation() { + inline void ClearPrinterButtonOperation() { printerButtonOperation = Buttons::NoButton; } +#ifndef UNITTEST private: +#endif /// Perform software self-reset of the MMU (sends an X0 command) void ResetX0(); @@ -279,6 +278,11 @@ private: /// Responds to a change of MMU's progress /// - plans additional steps, e.g. starts the E-motor after fsensor trigger + /// The function is quite complex, because it needs to handle asynchronnous + /// progress and error reports coming from the MMU without an explicit command + /// - typically after MMU's start or after some HW issue on the MMU. + /// It must ensure, that calls to @ref ReportProgress and/or @ref ReportError are + /// only executed after @ref BeginReport has been called first. void OnMMUProgressMsg(ProgressCode pc); /// Progress code changed - act accordingly void OnMMUProgressMsgChanged(ProgressCode pc); diff --git a/Firmware/mmu2/buttons.h b/Firmware/mmu2/buttons.h index 4941513a0..2d7b3128f 100644 --- a/Firmware/mmu2/buttons.h +++ b/Firmware/mmu2/buttons.h @@ -2,8 +2,8 @@ #include // Helper macros to parse the operations from Btns() -#define BUTTON_OP_RIGHT(X) ( ( X & 0xF0 ) >> 4 ) -#define BUTTON_OP_MIDDLE(X) ( X & 0x0F ) +#define BUTTON_OP_RIGHT(X) ((X & 0xF0) >> 4) +#define BUTTON_OP_MIDDLE(X) (X & 0x0F) namespace MMU2 { @@ -23,11 +23,11 @@ enum class ButtonOperations : uint8_t { }; /// Button codes + extended actions performed on the printer's side -enum Buttons : uint8_t { +enum class Buttons : uint_least8_t { Right = 0, Middle, Left, - + // performed on the printer's side ResetMMU, Load, @@ -35,9 +35,12 @@ enum Buttons : uint8_t { StopPrint, DisableMMU, TuneMMU, // Printer changes MMU register value - + NoButton = 0xff // shall be kept last }; +constexpr uint_least8_t buttons_to_uint8t(Buttons b) { + return static_cast(b); +} } // namespace MMU2 diff --git a/Firmware/mmu2/registers.h b/Firmware/mmu2/registers.h index 489facc39..29d4da9c5 100644 --- a/Firmware/mmu2/registers.h +++ b/Firmware/mmu2/registers.h @@ -1,8 +1,10 @@ #pragma once + +namespace MMU2 { + // Register map for MMU -enum class Register : uint8_t -{ +enum class Register : uint8_t { Project_Major = 0x00, Project_Minor = 0x01, Project_Revision = 0x02, @@ -38,3 +40,5 @@ enum class Register : uint8_t Set_Get_Idler_iRun = 0x20, Reserved = 0x21, }; + +} // namespace MMU2 diff --git a/Firmware/mmu2_crc.cpp b/Firmware/mmu2_crc.cpp index 20c68f7c5..994518911 100644 --- a/Firmware/mmu2_crc.cpp +++ b/Firmware/mmu2_crc.cpp @@ -2,12 +2,12 @@ #include "mmu2_crc.h" #ifdef __AVR__ -#include + #include #endif namespace modules { +// clang-format off namespace crc { - #ifdef __AVR__ uint8_t CRC8::CCITT_update(uint8_t crc, uint8_t b) { return _crc8_ccitt_update(crc, b); @@ -17,6 +17,6 @@ uint8_t CRC8::CCITT_update(uint8_t crc, uint8_t b) { return CCITT_updateCX(crc, b); } #endif - } // namespace crc +// clang-format on } // namespace modules diff --git a/Firmware/mmu2_crc.h b/Firmware/mmu2_crc.h index cc8f06dab..9fefbd319 100644 --- a/Firmware/mmu2_crc.h +++ b/Firmware/mmu2_crc.h @@ -4,6 +4,9 @@ namespace modules { +// clang-format off +// prevent silly indenting of the whole file + /// Contains all the necessary functions for computation of CRC namespace crc { @@ -40,4 +43,6 @@ public: } // namespace crc +// clang-format on + } // namespace modules diff --git a/Firmware/mmu2_error_converter.cpp b/Firmware/mmu2_error_converter.cpp index 20edb0336..1c760b94b 100644 --- a/Firmware/mmu2_error_converter.cpp +++ b/Firmware/mmu2_error_converter.cpp @@ -35,116 +35,125 @@ static_assert( FindErrorIndex(ERR_MECHANICAL_FINDA_FILAMENT_STUCK) == 1); static_assert( FindErrorIndex(ERR_MECHANICAL_FSENSOR_DIDNT_TRIGGER) == 2); static_assert( FindErrorIndex(ERR_MECHANICAL_FSENSOR_FILAMENT_STUCK) == 3); -uint8_t PrusaErrorCodeIndex(uint16_t ec) { +constexpr ErrorCode operator&(ErrorCode a, ErrorCode b){ + return (ErrorCode)((uint16_t)a & (uint16_t)b); +} + +constexpr bool ContainsBit(ErrorCode ec, ErrorCode mask){ + return (uint16_t)ec & (uint16_t)mask; +} + +uint8_t PrusaErrorCodeIndex(ErrorCode ec) { switch (ec) { - case (uint16_t)ErrorCode::FINDA_DIDNT_SWITCH_ON: + case ErrorCode::FINDA_DIDNT_SWITCH_ON: return FindErrorIndex(ERR_MECHANICAL_FINDA_DIDNT_TRIGGER); - case (uint16_t)ErrorCode::FINDA_DIDNT_SWITCH_OFF: + case ErrorCode::FINDA_DIDNT_SWITCH_OFF: return FindErrorIndex(ERR_MECHANICAL_FINDA_FILAMENT_STUCK); - case (uint16_t)ErrorCode::FSENSOR_DIDNT_SWITCH_ON: + case ErrorCode::FSENSOR_DIDNT_SWITCH_ON: return FindErrorIndex(ERR_MECHANICAL_FSENSOR_DIDNT_TRIGGER); - case (uint16_t)ErrorCode::FSENSOR_DIDNT_SWITCH_OFF: + case ErrorCode::FSENSOR_DIDNT_SWITCH_OFF: return FindErrorIndex(ERR_MECHANICAL_FSENSOR_FILAMENT_STUCK); - case (uint16_t)ErrorCode::FSENSOR_TOO_EARLY: + case ErrorCode::FSENSOR_TOO_EARLY: return FindErrorIndex(ERR_MECHANICAL_FSENSOR_TOO_EARLY); - case (uint16_t)ErrorCode::FINDA_FLICKERS: + case ErrorCode::FINDA_FLICKERS: return FindErrorIndex(ERR_MECHANICAL_INSPECT_FINDA); - case (uint16_t)ErrorCode::LOAD_TO_EXTRUDER_FAILED: + case ErrorCode::LOAD_TO_EXTRUDER_FAILED: return FindErrorIndex(ERR_MECHANICAL_LOAD_TO_EXTRUDER_FAILED); - case (uint16_t)ErrorCode::FILAMENT_EJECTED: + case ErrorCode::FILAMENT_EJECTED: return FindErrorIndex(ERR_SYSTEM_FILAMENT_EJECTED); - case (uint16_t)ErrorCode::FILAMENT_CHANGE: + case ErrorCode::FILAMENT_CHANGE: return FindErrorIndex(ERR_SYSTEM_FILAMENT_CHANGE); - case (uint16_t)ErrorCode::STALLED_PULLEY: - case (uint16_t)ErrorCode::MOVE_PULLEY_FAILED: + case ErrorCode::STALLED_PULLEY: + case ErrorCode::MOVE_PULLEY_FAILED: return FindErrorIndex(ERR_MECHANICAL_PULLEY_CANNOT_MOVE); - case (uint16_t)ErrorCode::HOMING_SELECTOR_FAILED: + case ErrorCode::HOMING_SELECTOR_FAILED: return FindErrorIndex(ERR_MECHANICAL_SELECTOR_CANNOT_HOME); - case (uint16_t)ErrorCode::MOVE_SELECTOR_FAILED: + case ErrorCode::MOVE_SELECTOR_FAILED: return FindErrorIndex(ERR_MECHANICAL_SELECTOR_CANNOT_MOVE); - case (uint16_t)ErrorCode::HOMING_IDLER_FAILED: + case ErrorCode::HOMING_IDLER_FAILED: return FindErrorIndex(ERR_MECHANICAL_IDLER_CANNOT_HOME); - case (uint16_t)ErrorCode::MOVE_IDLER_FAILED: + case ErrorCode::MOVE_IDLER_FAILED: return FindErrorIndex(ERR_MECHANICAL_IDLER_CANNOT_MOVE); - case (uint16_t)ErrorCode::MMU_NOT_RESPONDING: + case ErrorCode::MMU_NOT_RESPONDING: return FindErrorIndex(ERR_CONNECT_MMU_NOT_RESPONDING); - case (uint16_t)ErrorCode::PROTOCOL_ERROR: + case ErrorCode::PROTOCOL_ERROR: return FindErrorIndex(ERR_CONNECT_COMMUNICATION_ERROR); - case (uint16_t)ErrorCode::FILAMENT_ALREADY_LOADED: + case ErrorCode::FILAMENT_ALREADY_LOADED: return FindErrorIndex(ERR_SYSTEM_FILAMENT_ALREADY_LOADED); - case (uint16_t)ErrorCode::INVALID_TOOL: + case ErrorCode::INVALID_TOOL: return FindErrorIndex(ERR_SYSTEM_INVALID_TOOL); - case (uint16_t)ErrorCode::QUEUE_FULL: + case ErrorCode::QUEUE_FULL: return FindErrorIndex(ERR_SYSTEM_QUEUE_FULL); - case (uint16_t)ErrorCode::VERSION_MISMATCH: + case ErrorCode::VERSION_MISMATCH: return FindErrorIndex(ERR_SYSTEM_FW_UPDATE_NEEDED); - case (uint16_t)ErrorCode::INTERNAL: + case ErrorCode::INTERNAL: return FindErrorIndex(ERR_SYSTEM_FW_RUNTIME_ERROR); - case (uint16_t)ErrorCode::FINDA_VS_EEPROM_DISREPANCY: + case ErrorCode::FINDA_VS_EEPROM_DISREPANCY: return FindErrorIndex(ERR_SYSTEM_UNLOAD_MANUALLY); - case (uint16_t)ErrorCode::MCU_UNDERVOLTAGE_VCC: + case ErrorCode::MCU_UNDERVOLTAGE_VCC: return FindErrorIndex(ERR_ELECTRICAL_MMU_MCU_ERROR); + default: break; } // Electrical issues which can be detected somehow. // Need to be placed before TMC-related errors in order to process couples of error bits between single ones // and to keep the code size down. - if (ec & (uint16_t)ErrorCode::TMC_PULLEY_BIT) { - if ((ec & (uint16_t)ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) == (uint16_t)ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) + if (ContainsBit(ec, ErrorCode::TMC_PULLEY_BIT)) { + if ((ec & ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) == ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) return FindErrorIndex(ERR_ELECTRICAL_MMU_PULLEY_SELFTEST_FAILED); - } else if (ec & (uint16_t)ErrorCode::TMC_SELECTOR_BIT) { - if ((ec & (uint16_t)ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) == (uint16_t)ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) + } else if (ContainsBit(ec, ErrorCode::TMC_SELECTOR_BIT)) { + if ((ec & ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) == ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) return FindErrorIndex(ERR_ELECTRICAL_MMU_SELECTOR_SELFTEST_FAILED); - } else if (ec & (uint16_t)ErrorCode::TMC_IDLER_BIT) { - if ((ec & (uint16_t)ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) == (uint16_t)ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) + } else if (ContainsBit(ec, ErrorCode::TMC_IDLER_BIT)) { + if ((ec & ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) == ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION) return FindErrorIndex(ERR_ELECTRICAL_MMU_IDLER_SELFTEST_FAILED); } // TMC-related errors - multiple of these can occur at once // - in such a case we report the first which gets found/converted into Prusa-Error-Codes (usually the fact, that one TMC has an issue is serious enough) // By carefully ordering the checks here we can prioritize the errors being reported to the user. - if (ec & (uint16_t)ErrorCode::TMC_PULLEY_BIT) { - if (ec & (uint16_t)ErrorCode::TMC_IOIN_MISMATCH) + if (ContainsBit(ec, ErrorCode::TMC_PULLEY_BIT)) { + if (ContainsBit(ec, ErrorCode::TMC_IOIN_MISMATCH)) return FindErrorIndex(ERR_ELECTRICAL_TMC_PULLEY_DRIVER_ERROR); - if (ec & (uint16_t)ErrorCode::TMC_RESET) + if (ContainsBit(ec, ErrorCode::TMC_RESET)) return FindErrorIndex(ERR_ELECTRICAL_TMC_PULLEY_DRIVER_RESET); - if (ec & (uint16_t)ErrorCode::TMC_UNDERVOLTAGE_ON_CHARGE_PUMP) + if (ContainsBit(ec, ErrorCode::TMC_UNDERVOLTAGE_ON_CHARGE_PUMP)) return FindErrorIndex(ERR_ELECTRICAL_TMC_PULLEY_UNDERVOLTAGE_ERROR); - if (ec & (uint16_t)ErrorCode::TMC_SHORT_TO_GROUND) + if (ContainsBit(ec, ErrorCode::TMC_SHORT_TO_GROUND)) return FindErrorIndex(ERR_ELECTRICAL_TMC_PULLEY_DRIVER_SHORTED); - if (ec & (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_WARN) + if (ContainsBit(ec, ErrorCode::TMC_OVER_TEMPERATURE_WARN)) return FindErrorIndex(ERR_TEMPERATURE_WARNING_TMC_PULLEY_TOO_HOT); - if (ec & (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_ERROR) + if (ContainsBit(ec, ErrorCode::TMC_OVER_TEMPERATURE_ERROR)) return FindErrorIndex(ERR_TEMPERATURE_TMC_PULLEY_OVERHEAT_ERROR); - } else if (ec & (uint16_t)ErrorCode::TMC_SELECTOR_BIT) { - if (ec & (uint16_t)ErrorCode::TMC_IOIN_MISMATCH) + } else if (ContainsBit(ec, ErrorCode::TMC_SELECTOR_BIT)) { + if (ContainsBit(ec, ErrorCode::TMC_IOIN_MISMATCH)) return FindErrorIndex(ERR_ELECTRICAL_TMC_SELECTOR_DRIVER_ERROR); - if (ec & (uint16_t)ErrorCode::TMC_RESET) + if (ContainsBit(ec, ErrorCode::TMC_RESET)) return FindErrorIndex(ERR_ELECTRICAL_TMC_SELECTOR_DRIVER_RESET); - if (ec & (uint16_t)ErrorCode::TMC_UNDERVOLTAGE_ON_CHARGE_PUMP) + if (ContainsBit(ec, ErrorCode::TMC_UNDERVOLTAGE_ON_CHARGE_PUMP)) return FindErrorIndex(ERR_ELECTRICAL_TMC_SELECTOR_UNDERVOLTAGE_ERROR); - if (ec & (uint16_t)ErrorCode::TMC_SHORT_TO_GROUND) + if (ContainsBit(ec, ErrorCode::TMC_SHORT_TO_GROUND)) return FindErrorIndex(ERR_ELECTRICAL_TMC_SELECTOR_DRIVER_SHORTED); - if (ec & (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_WARN) + if (ContainsBit(ec, ErrorCode::TMC_OVER_TEMPERATURE_WARN)) return FindErrorIndex(ERR_TEMPERATURE_WARNING_TMC_SELECTOR_TOO_HOT); - if (ec & (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_ERROR) + if (ContainsBit(ec, ErrorCode::TMC_OVER_TEMPERATURE_ERROR)) return FindErrorIndex(ERR_TEMPERATURE_TMC_SELECTOR_OVERHEAT_ERROR); - } else if (ec & (uint16_t)ErrorCode::TMC_IDLER_BIT) { - if (ec & (uint16_t)ErrorCode::TMC_IOIN_MISMATCH) + } else if (ContainsBit(ec, ErrorCode::TMC_IDLER_BIT)) { + if (ContainsBit(ec, ErrorCode::TMC_IOIN_MISMATCH)) return FindErrorIndex(ERR_ELECTRICAL_TMC_IDLER_DRIVER_ERROR); - if (ec & (uint16_t)ErrorCode::TMC_RESET) + if (ContainsBit(ec, ErrorCode::TMC_RESET)) return FindErrorIndex(ERR_ELECTRICAL_TMC_IDLER_DRIVER_RESET); - if (ec & (uint16_t)ErrorCode::TMC_UNDERVOLTAGE_ON_CHARGE_PUMP) + if (ContainsBit(ec, ErrorCode::TMC_UNDERVOLTAGE_ON_CHARGE_PUMP)) return FindErrorIndex(ERR_ELECTRICAL_TMC_IDLER_UNDERVOLTAGE_ERROR); - if (ec & (uint16_t)ErrorCode::TMC_SHORT_TO_GROUND) + if (ContainsBit(ec, ErrorCode::TMC_SHORT_TO_GROUND)) return FindErrorIndex(ERR_ELECTRICAL_TMC_IDLER_DRIVER_SHORTED); - if (ec & (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_WARN) + if (ContainsBit(ec, ErrorCode::TMC_OVER_TEMPERATURE_WARN)) return FindErrorIndex(ERR_TEMPERATURE_WARNING_TMC_IDLER_TOO_HOT); - if (ec & (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_ERROR) + if (ContainsBit(ec, ErrorCode::TMC_OVER_TEMPERATURE_ERROR)) return FindErrorIndex(ERR_TEMPERATURE_TMC_IDLER_OVERHEAT_ERROR); } @@ -184,7 +193,7 @@ struct ResetOnExit { } }; -Buttons ButtonPressed(uint16_t ec) { +Buttons ButtonPressed(ErrorCode ec) { if (buttonSelectedOperation == ButtonOperations::NoOperation) { return Buttons::NoButton; // no button } @@ -193,7 +202,7 @@ Buttons ButtonPressed(uint16_t ec) { return ButtonAvailable(ec); } -Buttons ButtonAvailable(uint16_t ec) { +Buttons ButtonAvailable(ErrorCode ec) { uint8_t ei = PrusaErrorCodeIndex(ec); // The list of responses which occur in mmu error dialogs diff --git a/Firmware/mmu2_error_converter.h b/Firmware/mmu2_error_converter.h index 5f24bcb5c..fea2ba2a1 100644 --- a/Firmware/mmu2_error_converter.h +++ b/Firmware/mmu2_error_converter.h @@ -1,13 +1,20 @@ #pragma once #include #include -#include "mmu2/buttons.h" +#ifdef __AVR__ + #include "mmu2/buttons.h" + #include "mmu2/error_codes.h" +#else + #include "buttons.h" + #include "../../../../../../Prusa-Error-Codes/04_MMU/button_operations.h" + #include "../../../../../../Prusa-Firmware-MMU/src/logic/error_codes.h" +#endif namespace MMU2 { /// Translates MMU2::ErrorCode into an index of Prusa-Error-Codes /// Basically this is the way to obtain an index into all other functions in this API -uint8_t PrusaErrorCodeIndex(uint16_t ec); +uint8_t PrusaErrorCodeIndex(ErrorCode ec); /// @returns pointer to a PROGMEM string representing the Title of the Prusa-Error-Codes error /// @param i index of the error - obtained by calling ErrorCodeIndex @@ -38,11 +45,11 @@ void SetButtonResponse(ButtonOperations rsp); /// @returns button index/code based on currently processed error/screen /// Clears the "pressed" button upon exit -Buttons ButtonPressed(uint16_t ec); +Buttons ButtonPressed(ErrorCode ec); /// @returns button index/code based on currently processed error/screen /// Used as a subfunction of ButtonPressed. /// Does not clear the "pressed" button upon exit -Buttons ButtonAvailable(uint16_t ec); +Buttons ButtonAvailable(ErrorCode ec); } // namespace MMU2 diff --git a/Firmware/mmu2_log.h b/Firmware/mmu2_log.h index bc4313294..1d18a2b6d 100644 --- a/Firmware/mmu2_log.h +++ b/Firmware/mmu2_log.h @@ -1,7 +1,7 @@ #pragma once - -#ifndef UNITTEST -#include "Marlin.h" +#ifdef __AVR__ + #include +#endif // Beware - before changing this prefix, think twice // you'd need to change appmain.cpp app_marlin_serial_output_write_hook @@ -14,16 +14,22 @@ namespace MMU2 { /// @param msg pointer to a string in PROGMEM /// On the AVR platform this variant reads the input string from PROGMEM. /// On the ARM platform it calls LogErrorEvent directly (silently expecting the compiler to optimize it away) -void LogErrorEvent_P(const char *msg); +void LogErrorEvent_P(const char *msg_P); /// Report the msg into the general logging subsystem (through Marlin's SERIAL_ECHO stuff) /// @param msg pointer to a string in PROGMEM /// On the AVR platform this variant reads the input string from PROGMEM. /// On the ARM platform it calls LogErrorEvent directly (silently expecting the compiler to optimize it away) -void LogEchoEvent_P(const char *msg); +void LogEchoEvent_P(const char *msg_P); -} // namespace +} // namespace MMU2 +#ifndef UNITTEST + #ifdef __AVR__ + #include "Marlin.h" + #else + #include "../../core/serial.h" + #endif #define SERIAL_MMU2() \ { serialprintPGM(mmu2Magic); } @@ -49,11 +55,14 @@ void LogEchoEvent_P(const char *msg); } while (0) #define MMU2_ERROR_MSG(S) MMU2_ECHO_MSG(S) //!@todo Decide MMU errors on serial line -#else // #ifndef UNITTEST +#else // #ifndef UNITTEST + #include "stubs/stub_interfaces.h" + #define MMU2_ECHO_MSGLN(S) marlinLogSim.AppendLine(S) + #define MMU2_ERROR_MSGLN(S) marlinLogSim.AppendLine(S) + #define MMU2_ECHO_MSGRPGM(S) /*marlinLogSim.AppendLine(S)*/ + #define MMU2_ERROR_MSGRPGM(S) /*marlinLogSim.AppendLine(S)*/ + #define SERIAL_ECHOLNPGM(S) /*marlinLogSim.AppendLine(S)*/ + #define SERIAL_ECHOPGM(S) /* */ + #define SERIAL_ECHOLN(S) /*marlinLogSim.AppendLine(S)*/ - #define MMU2_ECHO_MSGLN(S) /* */ - #define MMU2_ERROR_MSGLN(S) /* */ - #define MMU2_ECHO_MSGRPGM(S) /* */ - #define MMU2_ERROR_MSGRPGM(S) /* */ - -#endif // #ifndef UNITTEST +#endif // #ifndef UNITTEST diff --git a/Firmware/mmu2_marlin.h b/Firmware/mmu2_marlin.h index 0877a60f8..40aeee0f2 100644 --- a/Firmware/mmu2_marlin.h +++ b/Firmware/mmu2_marlin.h @@ -14,27 +14,25 @@ struct pos3d { pos3d() = default; inline constexpr pos3d(float x, float y, float z) : xyz { x, y, z } {} - pos3d operator=(const float *newP){ - for(uint8_t i = 0; i < 3; ++i){ + pos3d operator=(const float *newP) { + for (uint8_t i = 0; i < 3; ++i) { xyz[i] = newP[i]; } return *this; } }; -void MoveE(float delta, float feedRate); +void extruder_move(float distance, float feed_rate); +void extruder_schedule_turning(float feed_rate); -float MoveRaiseZ(float delta); +float move_raise_z(float delta); void planner_abort_queued_moves(); void planner_synchronize(); bool planner_any_moves(); -float planner_get_machine_position_E_mm(); float stepper_get_machine_position_E_mm(); float planner_get_current_position_E(); void planner_set_current_position_E(float e); -void planner_line_to_current_position(float feedRate_mm_s); -void planner_line_to_current_position_sync(float feedRate_mm_s); pos3d planner_current_position(); void motion_do_blocking_move_to_xy(float rx, float ry, float feedRate_mm_s); @@ -46,6 +44,9 @@ bool marlin_printingIsActive(); void marlin_manage_heater(); void marlin_manage_inactivity(bool b); void marlin_idle(bool b); +void marlin_refresh_print_state_in_ram(); +void marlin_clear_print_state_in_ram(); +void marlin_stop_and_save_print_to_ram(); int16_t thermal_degTargetHotend(); int16_t thermal_degHotend(); @@ -61,6 +62,4 @@ bool all_axes_homed(); void gcode_reset_stepper_timeout(); -bool cutter_enabled(); - } // namespace MMU2 diff --git a/Firmware/mmu2_marlin1.cpp b/Firmware/mmu2_marlin1.cpp index 58ce99171..3a7dfa837 100644 --- a/Firmware/mmu2_marlin1.cpp +++ b/Firmware/mmu2_marlin1.cpp @@ -9,12 +9,21 @@ namespace MMU2 { -void MoveE(float delta, float feedRate) { +static void planner_line_to_current_position(float feedRate_mm_s){ + plan_buffer_line_curposXYZE(feedRate_mm_s); +} + +static void planner_line_to_current_position_sync(float feedRate_mm_s){ + planner_line_to_current_position(feedRate_mm_s); + planner_synchronize(); +} + +void extruder_move(float delta, float feedRate) { current_position[E_AXIS] += delta; planner_line_to_current_position(feedRate); } -float MoveRaiseZ(float delta) { +float move_raise_z(float delta) { return raise_z(delta); } @@ -53,15 +62,6 @@ void planner_set_current_position_E(float e){ current_position[E_AXIS] = e; } -void planner_line_to_current_position(float feedRate_mm_s){ - plan_buffer_line_curposXYZE(feedRate_mm_s); -} - -void planner_line_to_current_position_sync(float feedRate_mm_s){ - planner_line_to_current_position(feedRate_mm_s); - planner_synchronize(); -} - pos3d planner_current_position(){ return pos3d(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]); } @@ -101,6 +101,18 @@ void marlin_idle(bool b){ manage_inactivity(b); } +void marlin_refresh_print_state_in_ram(){ + refresh_print_state_in_ram(); +} + +void marlin_clear_print_state_in_ram(){ + clear_print_state_in_ram(); +} + +void marlin_stop_and_save_print_to_ram(){ + stop_and_save_print_to_ram(0,0); +} + int16_t thermal_degTargetHotend() { return degTargetHotend(0); } @@ -132,8 +144,4 @@ bool all_axes_homed(){ return axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]; } -bool cutter_enabled(){ - return eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED) == EEPROM_MMU_CUTTER_ENABLED_enabled; -} - } // namespace MMU2 diff --git a/Firmware/mmu2_marlin_macros.h b/Firmware/mmu2_marlin_macros.h index af2f79504..38f515e66 100644 --- a/Firmware/mmu2_marlin_macros.h +++ b/Firmware/mmu2_marlin_macros.h @@ -8,6 +8,10 @@ // brings _O and _T macros into MMU #include "language.h" #define MARLIN_KEEPALIVE_STATE_IN_PROCESS KEEPALIVE_STATE(IN_PROCESS) +#elif defined(UNITTEST) + #define _O(x) x + #define _T(x) x + #define MARLIN_KEEPALIVE_STATE_IN_PROCESS /*KEEPALIVE_STATE(IN_PROCESS) TODO*/ #else #include "../../gcode/gcode.h" #define _O(x) x diff --git a/Firmware/mmu2_progress_converter.cpp b/Firmware/mmu2_progress_converter.cpp index b44951385..29fd0d250 100644 --- a/Firmware/mmu2_progress_converter.cpp +++ b/Firmware/mmu2_progress_converter.cpp @@ -62,10 +62,10 @@ static const char * const progressTexts[] PROGMEM = { _R(MSG_PROGRESS_FEED_FSENSOR) }; -const char * ProgressCodeToText(uint16_t pc){ +const char * ProgressCodeToText(ProgressCode pc){ // @@TODO ?? a better fallback option? - return ( pc <= (sizeof(progressTexts) / sizeof(progressTexts[0])) ) - ? static_cast(pgm_read_ptr(&progressTexts[pc])) + return ( (uint16_t)pc <= (sizeof(progressTexts) / sizeof(progressTexts[0])) ) + ? static_cast(pgm_read_ptr(&progressTexts[(uint16_t)pc])) : static_cast(pgm_read_ptr(&progressTexts[0])); } diff --git a/Firmware/mmu2_progress_converter.h b/Firmware/mmu2_progress_converter.h index 19cb1e3fc..560cc5f7d 100644 --- a/Firmware/mmu2_progress_converter.h +++ b/Firmware/mmu2_progress_converter.h @@ -1,9 +1,14 @@ #pragma once #include #include +#ifdef __AVR__ + #include "mmu2/progress_codes.h" +#else + #include "../../../../../../Prusa-Firmware-MMU/src/logic/progress_codes.h" +#endif namespace MMU2 { -const char * ProgressCodeToText(uint16_t pc); +const char *ProgressCodeToText(ProgressCode pc); } diff --git a/Firmware/mmu2_protocol_logic.cpp b/Firmware/mmu2_protocol_logic.cpp index d01510c8c..77a0da950 100644 --- a/Firmware/mmu2_protocol_logic.cpp +++ b/Firmware/mmu2_protocol_logic.cpp @@ -9,6 +9,11 @@ // irrelevant on Buddy FW, just keep "_millis" as "millis" #include #define _millis millis + #ifdef UNITTEST + #define strncmp_P strncmp + #else + #include + #endif #endif #include @@ -16,7 +21,7 @@ namespace MMU2 { -/// Beware: +/// Beware - on AVR/MK3S: /// Changing the supportedMmuVersion numbers requires patching MSG_DESC_FW_UPDATE_NEEDED and all its related translations by hand. /// /// The message reads: @@ -27,18 +32,18 @@ namespace MMU2 { static constexpr uint8_t supportedMmuFWVersion[3] PROGMEM = { mmuVersionMajor, mmuVersionMinor, mmuVersionPatch }; const Register ProtocolLogic::regs8Addrs[ProtocolLogic::regs8Count] PROGMEM = { - Register::FINDA_State, // FINDA state + Register::FINDA_State, // FINDA state Register::Set_Get_Selector_Slot, // Selector slot - Register::Set_Get_Idler_Slot, // Idler slot + Register::Set_Get_Idler_Slot, // Idler slot }; const Register ProtocolLogic::regs16Addrs[ProtocolLogic::regs16Count] PROGMEM = { - Register::MMU_Errors, // MMU errors - aka statistics + Register::MMU_Errors, // MMU errors - aka statistics Register::Get_Pulley_Position, // Pulley position [mm] }; const Register ProtocolLogic::initRegs8Addrs[ProtocolLogic::initRegs8Count] PROGMEM = { - Register::Extra_Load_Distance, // extra load distance [mm] + Register::Extra_Load_Distance, // extra load distance [mm] Register::Pulley_Slow_Feedrate, // pulley slow feedrate [mm/s] }; @@ -181,7 +186,7 @@ StepStatus ProtocolLogic::ExpectingMessage() { break; } } - [[fallthrough]]; // otherwise + [[fallthrough]]; // otherwise default: RecordUARTActivity(); // something has happened on the UART, update the timeout record return ProtocolError; @@ -197,7 +202,11 @@ StepStatus ProtocolLogic::ExpectingMessage() { } void ProtocolLogic::SendMsg(RequestMsg rq) { +#ifdef __AVR__ + // Buddy FW cannot use stack-allocated txbuff - DMA doesn't work with CCMRAM + // No restrictions on MK3/S/+ though uint8_t txbuff[Protocol::MaxRequestSize()]; +#endif uint8_t len = Protocol::EncodeRequest(rq, txbuff); uart->write(txbuff, len); LogRequestMsg(txbuff, len); @@ -205,7 +214,11 @@ void ProtocolLogic::SendMsg(RequestMsg rq) { } void ProtocolLogic::SendWriteMsg(RequestMsg rq) { +#ifdef __AVR__ + // Buddy FW cannot use stack-allocated txbuff - DMA doesn't work with CCMRAM + // No restrictions on MK3/S/+ though uint8_t txbuff[Protocol::MaxRequestSize()]; +#endif uint8_t len = Protocol::EncodeWriteRequest(rq.value, rq.value2, txbuff); uart->write(txbuff, len); LogRequestMsg(txbuff, len); @@ -275,9 +288,9 @@ StepStatus ProtocolLogic::ScopeStep() { case Scope::StartSeq: return StartSeqStep(); // ~270B case Scope::Idle: - return IdleStep(); // ~300B + return IdleStep(); // ~300B case Scope::Command: - return CommandStep(); // ~430B + return CommandStep(); // ~430B case Scope::Stopped: return StoppedStep(); default: @@ -322,7 +335,7 @@ StepStatus ProtocolLogic::StartSeqStep() { StepStatus ProtocolLogic::DelayedRestartWait() { if (Elapsed(heartBeatPeriod)) { // this basically means, that we are waiting until there is some traffic on while (uart->read() != -1) - ; // clear the input buffer + ; // clear the input buffer // switch to StartSeq Start(); } @@ -349,6 +362,7 @@ StepStatus ProtocolLogic::ProcessCommandQueryResponse() { return Processing; case ResponseMsgParamCodes::Error: // in case of an error the progress code remains as it has been before + progressCode = ProgressCode::ERRWaitingForUser; errorCode = static_cast(rsp.paramValue); // keep on reporting the state of fsensor regularly even in command error state // - the MMU checks FINDA and fsensor even while recovering from errors @@ -469,9 +483,11 @@ StepStatus ProtocolLogic::IdleStep() { case ResponseMsgParamCodes::Processing: // @@TODO we may actually use this branch to report progress of manual operation on the MMU // The MMU sends e.g. X0 P27 after its restart when the user presses an MMU button to move the Selector + progressCode = static_cast(rsp.paramValue); errorCode = ErrorCode::OK; break; default: + progressCode = ProgressCode::ERRWaitingForUser; errorCode = static_cast(rsp.paramValue); StartReading8bitRegisters(); // continue Idle state without restarting the communication return CommandError; @@ -758,6 +774,7 @@ void ProtocolLogic::LogResponse() { StepStatus ProtocolLogic::SuppressShortDropOuts(const char *msg_P, StepStatus ss) { if (dataTO.Record(ss)) { LogError(msg_P); + dataTO.Reset(); // prepare for another run of consecutive retries before firing an error return dataTO.InitialCause(); } else { return Processing; // suppress short drop outs of communication diff --git a/Firmware/mmu2_protocol_logic.h b/Firmware/mmu2_protocol_logic.h index 251674ce8..bf884106b 100644 --- a/Firmware/mmu2_protocol_logic.h +++ b/Firmware/mmu2_protocol_logic.h @@ -3,37 +3,39 @@ #include #ifdef __AVR__ -#include "mmu2/error_codes.h" -#include "mmu2/progress_codes.h" -#include "mmu2/buttons.h" -#include "mmu2/registers.h" -#include "mmu2_protocol.h" + #include "mmu2/error_codes.h" + #include "mmu2/progress_codes.h" + #include "mmu2/buttons.h" + #include "mmu2/registers.h" + #include "mmu2_protocol.h" // #include std array is not available on AVR ... we need to "fake" it namespace std { -template +template class array { T data[N]; + public: array() = default; - inline constexpr T* begin()const { return data; } - inline constexpr T* end()const { return data + N; } + 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){ + inline T &operator[](uint8_t i) { return data[i]; } }; -} +} // namespace std #else -#include -#include "../../../../../../Prusa-Firmware-MMU/src/logic/error_codes.h" -#include "../../../../../../Prusa-Firmware-MMU/src/logic/progress_codes.h" + #include + #include "../../../../../../Prusa-Firmware-MMU/src/logic/error_codes.h" + #include "../../../../../../Prusa-Firmware-MMU/src/logic/progress_codes.h" -// prevent ARM HAL macros from breaking our code -#undef CRC -#include "../../../../../../Prusa-Firmware-MMU/src/modules/protocol.h" -#include "buttons.h" + // prevent ARM HAL macros from breaking our code + #undef CRC + #include "../../../../../../Prusa-Firmware-MMU/src/modules/protocol.h" + #include "buttons.h" + #include "registers.h" #endif #include "mmu2_serial.h" @@ -50,9 +52,9 @@ class ProtocolLogic; /// ProtocolLogic stepping statuses enum StepStatus : uint_fast8_t { Processing = 0, - MessageReady, ///< a message has been successfully decoded from the received bytes - Finished, ///< Scope finished successfully - Interrupted, ///< received "Finished" message related to a different command than originally issued (most likely the MMU restarted while doing something) + MessageReady, ///< a message has been successfully decoded from the received bytes + Finished, ///< Scope finished successfully + Interrupted, ///< received "Finished" message related to a different command than originally issued (most likely the MMU restarted while doing something) CommunicationTimeout, ///< the MMU failed to respond to a request within a specified time frame ProtocolError, ///< bytes read from the MMU didn't form a valid response CommandRejected, ///< the MMU rejected the command due to some other command in progress, may be the user is operating the MMU locally (button commands) @@ -60,19 +62,17 @@ enum StepStatus : uint_fast8_t { VersionMismatch, ///< the MMU reports its firmware version incompatible with our implementation PrinterError, ///< printer's explicit error - MMU is fine, but the printer was unable to complete the requested operation CommunicationRecovered, - ButtonPushed, ///< The MMU reported the user pushed one of its three buttons. + ButtonPushed, ///< The MMU reported the user pushed one of its three buttons. }; -static constexpr uint32_t linkLayerTimeout = 2000; ///< default link layer communication timeout -static constexpr uint32_t dataLayerTimeout = linkLayerTimeout * 3; ///< data layer communication timeout -static constexpr uint32_t heartBeatPeriod = linkLayerTimeout / 2; ///< period of heart beat messages (Q0) +inline constexpr uint32_t linkLayerTimeout = 2000; ///< default link layer communication timeout +inline constexpr uint32_t dataLayerTimeout = linkLayerTimeout * 3; ///< data layer communication timeout +inline constexpr uint32_t heartBeatPeriod = linkLayerTimeout / 2; ///< period of heart beat messages (Q0) static_assert(heartBeatPeriod < linkLayerTimeout && linkLayerTimeout < dataLayerTimeout, "Incorrect ordering of timeouts"); ///< Filter of short consecutive drop outs which are recovered instantly class DropOutFilter { - StepStatus cause; - uint8_t occurrences; public: static constexpr uint8_t maxOccurrences = 10; // ideally set this to >8 seconds -> 12x heartBeatPeriod static_assert(maxOccurrences > 1, "we should really silently ignore at least 1 comm drop out if recovered immediately afterwards"); @@ -86,6 +86,10 @@ public: /// Rearms the object for further processing - basically call this once the MMU responds with something meaningful (e.g. S0 A2) inline void Reset() { occurrences = maxOccurrences; } + +private: + StepStatus cause; + uint8_t occurrences = maxOccurrences; }; /// Logic layer of the MMU vs. printer communication protocol @@ -115,11 +119,11 @@ public: /// Sets the extra load distance to be reported to the MMU. /// Beware - this call doesn't send anything to the MMU. /// The MMU gets the newly set value either by a communication restart or via an explicit WriteRegister call - inline void PlanExtraLoadDistance(uint8_t eld_mm){ + inline void PlanExtraLoadDistance(uint8_t eld_mm) { initRegs8[0] = eld_mm; } /// @returns the currently preset extra load distance - inline uint8_t ExtraLoadDistance()const { + inline uint8_t ExtraLoadDistance() const { return initRegs8[0]; } @@ -187,13 +191,13 @@ public: inAutoRetry = iar; } - inline void SetPrinterError(ErrorCode ec){ + inline void SetPrinterError(ErrorCode ec) { explicitPrinterError = ec; } - inline void ClearPrinterError(){ + inline void ClearPrinterError() { explicitPrinterError = ErrorCode::OK; } - inline bool IsPrinterError()const { + inline bool IsPrinterError() const { return explicitPrinterError != ErrorCode::OK; } inline ErrorCode PrinterError() const { @@ -228,15 +232,6 @@ private: Running ///< normal operation - Idle + Command processing }; - // individual sub-state machines - may be they can be combined into a union since only one is active at once - // or we can blend them into ProtocolLogic at the cost of a less nice code (but hopefully shorter) -// Stopped stopped; -// StartSeq startSeq; -// DelayedRestart delayedRestart; -// Idle idle; -// Command command; -// ProtocolLogicPartBase *currentState; ///< command currently being processed - enum class Scope : uint_fast8_t { Stopped, StartSeq, @@ -350,25 +345,30 @@ private: /// Activate the planned state once the immediate response to a sent request arrived bool ActivatePlannedRequest(); - uint32_t lastUARTActivityMs; ///< timestamp - last ms when something occurred on the UART - DropOutFilter dataTO; ///< Filter of short consecutive drop outs which are recovered instantly + uint32_t lastUARTActivityMs; ///< timestamp - last ms when something occurred on the UART + DropOutFilter dataTO; ///< Filter of short consecutive drop outs which are recovered instantly - ResponseMsg rsp; ///< decoded response message from the MMU protocol + ResponseMsg rsp; ///< decoded response message from the MMU protocol - State state; ///< internal state of ProtocolLogic + State state; ///< internal state of ProtocolLogic - Protocol protocol; ///< protocol codec + Protocol protocol; ///< protocol codec std::array lastReceivedBytes; ///< remembers the last few bytes of incoming communication for diagnostic purposes uint8_t lrb; - MMU2Serial *uart; ///< UART interface + MMU2Serial *uart; ///< UART interface ErrorCode errorCode; ///< last received error code from the MMU ProgressCode progressCode; ///< last received progress code from the MMU Buttons buttonCode; ///< Last received button from the MMU. - uint8_t lastFSensor; ///< last state of filament sensor + uint8_t lastFSensor; ///< last state of filament sensor + +#ifndef __AVR__ + uint8_t txbuff[Protocol::MaxRequestSize()]; ///< In Buddy FW - a static transmit buffer needs to exist as DMA cannot be used from CCMRAM. + ///< On MK3/S/+ the transmit buffer is allocated on the stack without restrictions +#endif // 8bit registers static constexpr uint8_t regs8Count = 3; diff --git a/Firmware/mmu2_reporting.cpp b/Firmware/mmu2_reporting.cpp index d86f5abb1..0efe3341f 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -3,6 +3,7 @@ #include "mmu2_log.h" #include "mmu2_reporting.h" #include "mmu2_error_converter.h" +#include "mmu2_progress_converter.h" #include "mmu2/error_codes.h" #include "mmu2/buttons.h" #include "menu.h" @@ -14,14 +15,12 @@ namespace MMU2 { -const char * ProgressCodeToText(uint16_t pc); // we may join progress convertor and reporter together - -void BeginReport(CommandInProgress /*cip*/, uint16_t ec) { +void BeginReport(CommandInProgress /*cip*/, ProgressCode ec) { custom_message_type = CustomMsg::MMUProgress; lcd_setstatuspgm( _T(ProgressCodeToText(ec)) ); } -void EndReport(CommandInProgress /*cip*/, uint16_t /*ec*/) { +void EndReport(CommandInProgress /*cip*/, ProgressCode /*ec*/) { // clear the status msg line - let the printed filename get visible again if (!printJobOngoing()) { lcd_setstatuspgm(MSG_WELCOME); @@ -231,7 +230,7 @@ bool TuneMenuEntered() { return putErrorScreenToSleep; } -void ReportErrorHook(CommandInProgress /*cip*/, uint16_t ec, uint8_t /*es*/) { +void ReportErrorHook(CommandInProgress /*cip*/, ErrorCode ec, uint8_t /*es*/) { if (putErrorScreenToSleep) return; if (mmu2.MMUCurrentErrorCode() == ErrorCode::OK && mmu2.MMULastErrorSource() == MMU2::ErrorSourceMMU) { @@ -241,7 +240,7 @@ void ReportErrorHook(CommandInProgress /*cip*/, uint16_t ec, uint8_t /*es*/) { ReportErrorHookState = ReportErrorHookStates::DISMISS_ERROR_SCREEN; } - const uint8_t ei = PrusaErrorCodeIndex(ec); + const uint8_t ei = PrusaErrorCodeIndex((ErrorCode)ec); switch ((uint8_t)ReportErrorHookState) { case (uint8_t)ReportErrorHookStates::RENDER_ERROR_SCREEN: @@ -289,39 +288,57 @@ void ReportErrorHook(CommandInProgress /*cip*/, uint16_t ec, uint8_t /*es*/) { } } -void ReportProgressHook(CommandInProgress cip, uint16_t ec) { +void ReportProgressHook(CommandInProgress cip, ProgressCode ec) { if (cip != CommandInProgress::NoCommand) { custom_message_type = CustomMsg::MMUProgress; lcd_setstatuspgm( _T(ProgressCodeToText(ec)) ); } } -void TryLoadUnloadProgressbarInit() { +TryLoadUnloadReporter::TryLoadUnloadReporter(float delta_mm) +: dpixel0(0) +, dpixel1(0) +, lcd_cursor_col(0) +, pixel_per_mm(0.5F * float(LCD_WIDTH) / (delta_mm)) +{ lcd_clearstatus(); } -void TryLoadUnloadProgressbarDeinit() { +TryLoadUnloadReporter::~TryLoadUnloadReporter() { // Delay the next status message just so // the user can see the results clearly lcd_reset_status_message_timeout(); } -void TryLoadUnloadProgressbarEcho() { - char buf[LCD_WIDTH]; +void TryLoadUnloadReporter::Render(uint8_t col, bool sensorState) { + // Set the cursor position each time in case some other + // part of the firmware changes the cursor position + lcd_insert_char_into_status(col, sensorState ? LCD_STR_SOLID_BLOCK[0] : '-'); + if (!lcd_update_enabled) lcdui_print_status_line(); +} + +void TryLoadUnloadReporter::Progress(bool sensorState){ + // Always round up, you can only have 'whole' pixels. (floor is also an option) + dpixel1 = ceil((stepper_get_machine_position_E_mm() - planner_get_current_position_E()) * pixel_per_mm); + if (dpixel1 - dpixel0) { + dpixel0 = dpixel1; + if (lcd_cursor_col > (LCD_WIDTH - 1)) lcd_cursor_col = LCD_WIDTH - 1; + Render(lcd_cursor_col++, sensorState); + } +} + +void TryLoadUnloadReporter::DumpToSerial(){ + char buf[LCD_WIDTH + 1]; lcd_getstatus(buf); for (uint8_t i = 0; i < sizeof(buf); i++) { // 0xFF is -1 when converting from unsigned to signed char // If the number is negative, that means filament is present buf[i] = (buf[i] < 0) ? '1' : '0'; } + buf[LCD_WIDTH] = 0; MMU2_ECHO_MSGLN(buf); } -void TryLoadUnloadProgressbar(uint8_t col, bool sensorState) { - lcd_insert_char_into_status(col, sensorState ? '-' : LCD_STR_SOLID_BLOCK[0]); - if (!lcd_update_enabled) lcdui_print_status_line(); -} - void IncrementLoadFails(){ eeprom_increment_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL); eeprom_increment_word((uint16_t *)EEPROM_MMU_LOAD_FAIL_TOT); @@ -332,6 +349,10 @@ void IncrementMMUFails(){ eeprom_increment_word((uint16_t *)EEPROM_MMU_FAIL_TOT); } +bool cutter_enabled(){ + return eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED) == EEPROM_MMU_CUTTER_ENABLED_enabled; +} + void MakeSound(SoundType s){ Sound_MakeSound( (eSOUND_TYPE)s); } diff --git a/Firmware/mmu2_reporting.h b/Firmware/mmu2_reporting.h index 89a2765bd..2a01afa0c 100644 --- a/Firmware/mmu2_reporting.h +++ b/Firmware/mmu2_reporting.h @@ -2,12 +2,19 @@ #pragma once #include +#ifdef __AVR__ + #include "mmu2/error_codes.h" + #include "mmu2/progress_codes.h" +#else + #include "../../../../../../Prusa-Firmware-MMU/src/logic/error_codes.h" + #include "../../../../../../Prusa-Firmware-MMU/src/logic/progress_codes.h" +#endif namespace MMU2 { enum CommandInProgress : uint8_t { NoCommand = 0, - CutFilament = 'C', + CutFilament = 'K', EjectFilament = 'E', Homing = 'H', LoadFilament = 'L', @@ -17,10 +24,10 @@ enum CommandInProgress : uint8_t { }; /// Called at the begin of every MMU operation -void BeginReport(CommandInProgress cip, uint16_t ec); +void BeginReport(CommandInProgress cip, ProgressCode ec); /// Called at the end of every MMU operation -void EndReport(CommandInProgress cip, uint16_t ec); +void EndReport(CommandInProgress cip, ProgressCode ec); /// Return true if the printer's LCD is drawing the error screen bool isErrorScreenRunning(); @@ -35,24 +42,31 @@ bool TuneMenuEntered(); /// and allow the MMU and printer to communicate with each other. /// @param[in] ec error code /// @param[in] es error source -void ReportErrorHook(CommandInProgress cip, uint16_t ec, uint8_t es); +void ReportErrorHook(CommandInProgress cip, ErrorCode ec, uint8_t es); /// Called when the MMU sends operation progress update -void ReportProgressHook(CommandInProgress cip, uint16_t ec); +void ReportProgressHook(CommandInProgress cip, ProgressCode ec); -/// @brief Clear the status line and setup the LCD cursor -void TryLoadUnloadProgressbarInit(); +struct TryLoadUnloadReporter { + TryLoadUnloadReporter(float delta_mm); + ~TryLoadUnloadReporter(); + void Progress(bool sensorState); + void DumpToSerial(); -/// @brief Clear the status line and setup the LCD cursor -void TryLoadUnloadProgressbarDeinit(); +private: + /// @brief Add one block to the progress bar + /// @param col pixel position on the LCD status line, should range from 0 to (LCD_WIDTH - 1) + /// @param sensorState if true, filament is not present, else filament is present. This controls which character to render + void Render(uint8_t col, bool sensorState); -/// @brief Report the results to serial -void TryLoadUnloadProgressbarEcho(); - -/// @brief Add one block to the progress bar -/// @param col pixel position on the LCD status line, should range from 0 to (LCD_WIDTH - 1) -/// @param sensorState if true, filament is not present, else filament is present. This controls which character to render -void TryLoadUnloadProgressbar(uint8_t col, bool sensorState); + uint8_t dpixel0; + uint8_t dpixel1; + uint8_t lcd_cursor_col; + // The total length is twice delta_mm. Divide that length by number of pixels + // available to get length per pixel. + // Note: Below is the reciprocal of (2 * delta_mm) / LCD_WIDTH [mm/pixel] + float pixel_per_mm; +}; /// Remders the sensor status line. Also used by the "resume temperature" screen. void ReportErrorHookDynamicRender(); @@ -74,6 +88,9 @@ void IncrementLoadFails(); /// Increments EEPROM cell - number of MMU errors void IncrementMMUFails(); +/// @returns true when Cutter is enabled in the menus +bool cutter_enabled(); + // Beware: enum values intentionally chosen to match the 8bit FW to save code size enum SoundType { Prompt = 2, @@ -93,4 +110,4 @@ void ScreenClear(); void tuneIdlerStallguardThreshold(); -} // namespace +} // namespace MMU2 diff --git a/lang/po/Firmware.pot b/lang/po/Firmware.pot index 27b43fbaa..5470a549f 100644 --- a/lang/po/Firmware.pot +++ b/lang/po/Firmware.pot @@ -1209,6 +1209,11 @@ msgstr "" msgid "Mesh Bed Leveling" msgstr "" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "" + #. MSG_MODE c=6 #: ../../Firmware/messages.cpp:107 ../../Firmware/ultralcd.cpp:4122 #: ../../Firmware/ultralcd.cpp:4126 ../../Firmware/ultralcd.cpp:4134 diff --git a/lang/po/Firmware_cs.po b/lang/po/Firmware_cs.po index 49098bcd8..cbabfc95d 100644 --- a/lang/po/Firmware_cs.po +++ b/lang/po/Firmware_cs.po @@ -2550,6 +2550,11 @@ msgstr "Výměna filamentu M600. Vložte nový filament nebo vysuňte starý." msgid "Sensitivity" msgstr "Citlivost" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Mesh Bed Leveling selhal. Spusťte kalibraci osy Z." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Vyjmete stary filament a stisknete tlacitko pro zavedeni noveho." diff --git a/lang/po/Firmware_de.po b/lang/po/Firmware_de.po index 094cfb8f4..7967cc104 100644 --- a/lang/po/Firmware_de.po +++ b/lang/po/Firmware_de.po @@ -2578,6 +2578,11 @@ msgstr "" msgid "Sensitivity" msgstr "Sensitivität" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "MeshBett Ausgleich fehlgeschlagen. Z Kalibrierung ausführen." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Entferne das alte Fil. und drücke den Knopf, um das neue zu laden." diff --git a/lang/po/Firmware_es.po b/lang/po/Firmware_es.po index dd1c19daa..a98b34175 100644 --- a/lang/po/Firmware_es.po +++ b/lang/po/Firmware_es.po @@ -2574,6 +2574,11 @@ msgstr "" msgid "Sensitivity" msgstr "Sensibilidad" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Nivelacion fallada. Ejecute la calibración Z." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "" #~ "Retira el fil. viejo y presione el dial para comenzar a cargar el nuevo." diff --git a/lang/po/Firmware_fr.po b/lang/po/Firmware_fr.po index c4520e162..c142a85ed 100644 --- a/lang/po/Firmware_fr.po +++ b/lang/po/Firmware_fr.po @@ -2589,6 +2589,11 @@ msgstr "" msgid "Sensitivity" msgstr "Sensibilité" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "" + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "" #~ "Retirez l'ancien fil. puis appuyez sur le bouton pour charger le nouveau." diff --git a/lang/po/Firmware_hr.po b/lang/po/Firmware_hr.po index 31557cc05..a3a37dc21 100644 --- a/lang/po/Firmware_hr.po +++ b/lang/po/Firmware_hr.po @@ -2567,6 +2567,11 @@ msgstr "Promjena filamenta M600. Stavite novu nit ili izbacite staru." msgid "Sensitivity" msgstr "Osjetljivost" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Niveliranje podloge nije uspijelo. Pokrenite Z kalibraciju." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Uklonite stari fil. i pritisnite gumb za pocetak stavljanja novog." diff --git a/lang/po/Firmware_hu.po b/lang/po/Firmware_hu.po index e68c4e49a..8f6cb8614 100644 --- a/lang/po/Firmware_hu.po +++ b/lang/po/Firmware_hu.po @@ -2572,6 +2572,11 @@ msgstr "" msgid "Sensitivity" msgstr "Érzékenység" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Sikertelen asztal szintezés. Kérjük, futtasd a Z kalibrálást." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Vedd ki a regi fil., majd nyomd meg a gombot az uj fil. betoltesehez." diff --git a/lang/po/Firmware_it.po b/lang/po/Firmware_it.po index 999d5b98b..19c0a5780 100644 --- a/lang/po/Firmware_it.po +++ b/lang/po/Firmware_it.po @@ -2573,6 +2573,11 @@ msgstr "" msgid "Sensitivity" msgstr "Sensibilità" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Livellamento piano fallito. Si prega di eseguire la calibrazione Z." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Rimuovi il fil. precedente e premi la manopola per caricare il nuovo." diff --git a/lang/po/Firmware_nl.po b/lang/po/Firmware_nl.po index f4f8547f3..fb2454076 100644 --- a/lang/po/Firmware_nl.po +++ b/lang/po/Firmware_nl.po @@ -2575,6 +2575,11 @@ msgstr "M600-filamentwissel. Laad een nieuw filament of werp het oude uit." msgid "Sensitivity" msgstr "Sensitiviteit" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Bed leveling mislukt. Voer de Z-kalibratie uit." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "" #~ "Verwijder de oude filament en druk op de knop om nieuwe filament te laden." diff --git a/lang/po/Firmware_no.po b/lang/po/Firmware_no.po index fab3dcc41..731f05efb 100644 --- a/lang/po/Firmware_no.po +++ b/lang/po/Firmware_no.po @@ -2549,6 +2549,11 @@ msgstr "M600 filamentskifte. Sett inn en ny filament eller løs ut den gamle." msgid "Sensitivity" msgstr "Sensitivitet" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Sengeplanering feilet. Kjør Z-kalibrering." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Ta bort det gamle filamentet og trykk valghjulet for å laste et nytt." diff --git a/lang/po/Firmware_pl.po b/lang/po/Firmware_pl.po index b0abab91e..d7d2ad8d2 100644 --- a/lang/po/Firmware_pl.po +++ b/lang/po/Firmware_pl.po @@ -2568,6 +2568,11 @@ msgstr "Załaduj nowy filament lub wyładuj poprzedni." msgid "Sensitivity" msgstr "Wrażliwość" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Poziomowanie stołu nieudane. Proszę uruchomić kalibrację Z." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Wyciagnij poprzedni filament i nacisnij pokretlo aby zaladowac nowy." diff --git a/lang/po/Firmware_ro.po b/lang/po/Firmware_ro.po index f21be410b..0aeae1ecb 100644 --- a/lang/po/Firmware_ro.po +++ b/lang/po/Firmware_ro.po @@ -2573,6 +2573,11 @@ msgstr "" msgid "Sensitivity" msgstr "Sensibilitate" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Nivelarea patului a eșuat. Rulează Calibrare Z." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Scoateti fil. vechi si apasati butonul pentru a incarca nou." diff --git a/lang/po/Firmware_sk.po b/lang/po/Firmware_sk.po index 04219d0a9..98ec21c57 100644 --- a/lang/po/Firmware_sk.po +++ b/lang/po/Firmware_sk.po @@ -2555,6 +2555,11 @@ msgstr "Výmena filamentu M600. Vložte nový filament alebo vysuňte starý." msgid "Sensitivity" msgstr "Citlivosť" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Vyrovnanie platne zlyhalo. Spustite kalibráciu Z." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Vyberte stary filament a stlacte tlacidlo pre zavedenie noveho." diff --git a/lang/po/Firmware_sv.po b/lang/po/Firmware_sv.po index df05c1e81..b5e333df7 100644 --- a/lang/po/Firmware_sv.po +++ b/lang/po/Firmware_sv.po @@ -2562,6 +2562,11 @@ msgstr "M600 filamentbyte. Ladda en ny filament eller mata ut den gamla." msgid "Sensitivity" msgstr "Känslighet" +#. MSG_MBL_FAILED_Z_CAL c=20 r=4 +#: ../../Firmware/Marlin_main.cpp:2976 +msgid "Mesh bed leveling failed. Please run Z calibration." +msgstr "Bäddnivelleringen felade. Kör Z-kalibrering." + #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "Ta bort det gamla fil. och tryck på knappen för att börja ladda nytt."