From ca27841d6778771c6a746b3c2bd2fa1880665950 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 13 Sep 2023 11:14:16 +0200 Subject: [PATCH 01/22] Add new MBL message for #4183 and translate these messages --- Firmware/Marlin_main.cpp | 2 +- lang/po/Firmware.pot | 5 +++++ lang/po/Firmware_cs.po | 5 +++++ lang/po/Firmware_de.po | 5 +++++ lang/po/Firmware_es.po | 5 +++++ lang/po/Firmware_fr.po | 5 +++++ lang/po/Firmware_hr.po | 5 +++++ lang/po/Firmware_hu.po | 5 +++++ lang/po/Firmware_it.po | 5 +++++ lang/po/Firmware_nl.po | 5 +++++ lang/po/Firmware_no.po | 5 +++++ lang/po/Firmware_pl.po | 5 +++++ lang/po/Firmware_ro.po | 5 +++++ lang/po/Firmware_sk.po | 5 +++++ lang/po/Firmware_sv.po | 5 +++++ 15 files changed, 71 insertions(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 7c362a3d1..4ea846fdc 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2973,7 +2973,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; 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..489518109 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 "Vyrovnání síťového lože se nezdařilo. Spusťte prosím Z kalibraci." + #~ 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..778c13485 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. Führe Z Kalibrierung aus." + #~ 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..668eccab5 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 "Capt. non declenche pendant que je nivele le plateau. Veuillez exécuter l'étalonnage Z." + #~ 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..8f8b234e4 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 szintezes. Kérjük, futtassa 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..430fe3a17 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 stolu. 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..304427162 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 esuat. Nivelarea patului a esuat." + #~ 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..1c18defe0 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 lôžka 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." From 4c930594fcd2ed6e67024f38a0d416302dcdbc44 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Wed, 13 Sep 2023 14:39:56 +0200 Subject: [PATCH 02/22] Update CZ translation --- lang/po/Firmware_cs.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/po/Firmware_cs.po b/lang/po/Firmware_cs.po index 489518109..cbabfc95d 100644 --- a/lang/po/Firmware_cs.po +++ b/lang/po/Firmware_cs.po @@ -2553,7 +2553,7 @@ 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 "Vyrovnání síťového lože se nezdařilo. Spusťte prosím Z kalibraci." +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." From adf2cd6afc91358f0a0fa44e644232a6b3243d55 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Fri, 15 Sep 2023 08:40:45 +0200 Subject: [PATCH 03/22] Thanks to everyone for the translation updates. @ingbrzy @leptun @petrubecheru @Hauzman @AttilaSVK @sarusani @Painkiller56 @vintagepc @stelgenhof @wavexx @OS-kar @trondkla @arekm I had to remove the French translation as it exceeds the limt. Only 53 bytes are free. --- lang/po/Firmware_de.po | 2 +- lang/po/Firmware_fr.po | 2 +- lang/po/Firmware_hu.po | 2 +- lang/po/Firmware_pl.po | 2 +- lang/po/Firmware_ro.po | 2 +- lang/po/Firmware_sk.po | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lang/po/Firmware_de.po b/lang/po/Firmware_de.po index 778c13485..7967cc104 100644 --- a/lang/po/Firmware_de.po +++ b/lang/po/Firmware_de.po @@ -2581,7 +2581,7 @@ 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. Führe Z Kalibrierung aus." +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_fr.po b/lang/po/Firmware_fr.po index 668eccab5..c142a85ed 100644 --- a/lang/po/Firmware_fr.po +++ b/lang/po/Firmware_fr.po @@ -2592,7 +2592,7 @@ 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 "Capt. non declenche pendant que je nivele le plateau. Veuillez exécuter l'étalonnage Z." +msgstr "" #~ msgid "Remove old filament and press the knob to start loading new filament." #~ msgstr "" diff --git a/lang/po/Firmware_hu.po b/lang/po/Firmware_hu.po index 8f8b234e4..8f6cb8614 100644 --- a/lang/po/Firmware_hu.po +++ b/lang/po/Firmware_hu.po @@ -2575,7 +2575,7 @@ 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 szintezes. Kérjük, futtassa a Z kalibrálást." +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_pl.po b/lang/po/Firmware_pl.po index 430fe3a17..d7d2ad8d2 100644 --- a/lang/po/Firmware_pl.po +++ b/lang/po/Firmware_pl.po @@ -2571,7 +2571,7 @@ 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 stolu. Proszę uruchomić kalibrację Z." +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 304427162..0aeae1ecb 100644 --- a/lang/po/Firmware_ro.po +++ b/lang/po/Firmware_ro.po @@ -2576,7 +2576,7 @@ 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 esuat. Nivelarea patului a esuat." +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 1c18defe0..98ec21c57 100644 --- a/lang/po/Firmware_sk.po +++ b/lang/po/Firmware_sk.po @@ -2558,7 +2558,7 @@ 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 lôžka zlyhalo. Spustite kalibráciu Z." +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." From 2951bc8af0ec296c382ed01a55f1280ddfd0041c Mon Sep 17 00:00:00 2001 From: sarusani <62053849+sarusani@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:05:59 +0200 Subject: [PATCH 04/22] Default to eeprom values Use eeprom values if provided parameters are out of bounds. --- Firmware/Marlin_main.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 7c06981f7..ebf35e6bd 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 nProbeRetryCount = code_seen('C') ? code_value_uint8() : eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR); - if (nProbeRetryCount > 10) { - nProbeRetryCount = 10; - } + uint8_t nMeasPoints = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR); + if (code_seen('N') && (code_value_uint8() == 7 || code_value_uint8() == 3)) + nMeasPoints = code_value_uint8(); + + uint8_t nProbeRetryCount = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR); + if (code_seen('C') && code_value_uint8() >= 1 && code_value_uint8() <= 10) + nProbeRetryCount = code_value_uint8(); 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; @@ -4885,9 +4883,9 @@ void process_commands() G80 [ N | C | O | 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). Using the following parameters enables additional "manual" bed leveling correction. Valid values are -100 microns to 100 microns. #### Additional Parameters From 56a79f88ef34a10aebb6315413c2047add8e290d Mon Sep 17 00:00:00 2001 From: sarusani <62053849+sarusani@users.noreply.github.com> Date: Fri, 15 Sep 2023 00:05:21 +0200 Subject: [PATCH 05/22] Optimise memory usage --- Firmware/Marlin_main.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index ebf35e6bd..4ecd17f35 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2821,12 +2821,14 @@ static void gcode_G80() #endif //PINDA_THERMISTOR uint8_t nMeasPoints = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR); - if (code_seen('N') && (code_value_uint8() == 7 || code_value_uint8() == 3)) - nMeasPoints = code_value_uint8(); - + bool bCodeSeen = code_seen('N'); + if (uint8_t value = code_value_uint8(); bCodeSeen && (value == 7 || value == 3)) + nMeasPoints = value; + uint8_t nProbeRetryCount = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR); - if (code_seen('C') && code_value_uint8() >= 1 && code_value_uint8() <= 10) - nProbeRetryCount = code_value_uint8(); + bCodeSeen = code_seen('C'); + if (uint8_t value = code_value_uint8(); bCodeSeen && 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; From e4a10e5fab497004cf2ff28a6d7ee191243db887 Mon Sep 17 00:00:00 2001 From: sarusani <62053849+sarusani@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:04:32 +0200 Subject: [PATCH 06/22] Move code_seen back into if statement Same memory usage, but prettier to look at. :) --- Firmware/Marlin_main.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4ecd17f35..3b3b361ba 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2821,13 +2821,11 @@ static void gcode_G80() #endif //PINDA_THERMISTOR uint8_t nMeasPoints = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR); - bool bCodeSeen = code_seen('N'); - if (uint8_t value = code_value_uint8(); bCodeSeen && (value == 7 || value == 3)) + if (uint8_t codeSeen = code_seen('N'), value = code_value_uint8(); codeSeen && (value == 7 || value == 3)) nMeasPoints = value; uint8_t nProbeRetryCount = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR); - bCodeSeen = code_seen('C'); - if (uint8_t value = code_value_uint8(); bCodeSeen && value >= 1 && value <= 10) + 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; From f235976f2698a8837a02448f1bc8180c1d36e8a0 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 09:07:53 +0200 Subject: [PATCH 07/22] Sync MK3<->MK4 MMU2 protocol logic --- Firmware/mmu2/registers.h | 8 ++- Firmware/mmu2_protocol_logic.cpp | 37 ++++++++++--- Firmware/mmu2_protocol_logic.h | 94 ++++++++++++++++---------------- 3 files changed, 81 insertions(+), 58 deletions(-) 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_protocol_logic.cpp b/Firmware/mmu2_protocol_logic.cpp index d01510c8c..bad34310c 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: @@ -24,21 +29,23 @@ namespace MMU2 { /// /// Currently, this is not possible to perform automatically at compile time with the existing languages/translations infrastructure. /// To save space a "dumb" solution was chosen + a few static_assert checks in errors_list.h preventing the code from compiling when the string doesn't match. +/// ----- +/// On Buddy FW we should improve the error screen to be able to print formatted strings 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 +188,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 +204,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 +216,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 +290,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 +337,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 +364,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 +485,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 +776,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; From 717281cd8733069b3f22eca536bdb73665c8c550 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 09:17:29 +0200 Subject: [PATCH 08/22] Sync MK3<->MK4 MMU2 crc --- Firmware/mmu2_crc.cpp | 6 +++--- Firmware/mmu2_crc.h | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) 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 From ec4740fe53fcf71dabe15aafe31180a5e65c32a1 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 10:05:14 +0200 Subject: [PATCH 09/22] Clean-up ProgressCodes and ErrorCodes parameters throughout the code --- Firmware/mmu2.cpp | 8 +- Firmware/mmu2.h | 2 +- Firmware/mmu2_error_converter.cpp | 117 ++++++++++++++++-------------- Firmware/mmu2_error_converter.h | 15 +++- Firmware/mmu2_reporting.cpp | 2 +- 5 files changed, 80 insertions(+), 64 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index dcc070ce0..045d9deff 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -237,7 +237,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 @@ -713,7 +713,7 @@ void MMU2::ResumeUnpark() { } 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) { @@ -976,7 +976,7 @@ 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(); @@ -999,7 +999,7 @@ 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 diff --git a/Firmware/mmu2.h b/Firmware/mmu2.h index 0c4df18e1..6040eebb9 100644 --- a/Firmware/mmu2.h +++ b/Firmware/mmu2.h @@ -182,7 +182,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; }; 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_reporting.cpp b/Firmware/mmu2_reporting.cpp index d86f5abb1..f2b0fab45 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -241,7 +241,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: From fd9f4ffb9ed56d1af22823f7b435889afd57868a Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 10:11:08 +0200 Subject: [PATCH 10/22] Sync MK3<->MK4 MMU2 progress converter --- Firmware/mmu2_progress_converter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/mmu2_progress_converter.h b/Firmware/mmu2_progress_converter.h index 19cb1e3fc..b8cd8611b 100644 --- a/Firmware/mmu2_progress_converter.h +++ b/Firmware/mmu2_progress_converter.h @@ -4,6 +4,6 @@ namespace MMU2 { -const char * ProgressCodeToText(uint16_t pc); +const char *ProgressCodeToText(uint16_t pc); } From eb7a73e7487add440acc246a73a6ec4c8e81b162 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 10:58:42 +0200 Subject: [PATCH 11/22] Sync MK3<->MK4 MMU2 log --- Firmware/mmu2_log.h | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) 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 From b4b0bba11ce0143d3f3c3e9e0fd14adae7eb4968 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 11:12:11 +0200 Subject: [PATCH 12/22] Sync MK3<->MK4 MMU2 marlin interface --- Firmware/mmu2.cpp | 14 ++++++-------- Firmware/mmu2_marlin.h | 14 +++++--------- Firmware/mmu2_marlin1.cpp | 26 +++++++++++--------------- Firmware/mmu2_reporting.cpp | 4 ++++ Firmware/mmu2_reporting.h | 3 +++ 5 files changed, 29 insertions(+), 32 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 045d9deff..972fc5cd1 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -301,7 +301,7 @@ bool MMU2::VerifyFilamentEnteredPTFE() { 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 ? delta_mm : -delta_mm, 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. @@ -355,8 +355,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 @@ -654,7 +652,7 @@ void MMU2::SaveAndPark(bool move_axes) { 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()) { @@ -930,7 +928,7 @@ void MMU2::execute_extruder_sequence(const E_Step *sequence, uint8_t steps) { const E_Step *step = sequence; for (uint8_t i = steps; i ; --i) { - MoveE(pgm_read_float(&(step->extrude)), pgm_read_float(&(step->feedRate))); + 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). @@ -1058,7 +1056,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 +1087,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 +1097,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_marlin.h b/Firmware/mmu2_marlin.h index 0877a60f8..0990fdbc2 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); @@ -61,6 +59,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..05a9bf05e 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]); } @@ -132,8 +132,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_reporting.cpp b/Firmware/mmu2_reporting.cpp index f2b0fab45..ddef50c61 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -332,6 +332,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..e26a11ea0 100644 --- a/Firmware/mmu2_reporting.h +++ b/Firmware/mmu2_reporting.h @@ -74,6 +74,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, From 5235fe2480e423fed574dcb0a6d1b753c6772073 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 11:13:41 +0200 Subject: [PATCH 13/22] Sync MK3<->MK4 MMU2 marlin macros --- Firmware/mmu2_marlin_macros.h | 4 ++++ 1 file changed, 4 insertions(+) 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 From 075858c9fae3da055aeedcfeedcc3ace3cd5c187 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 11:33:31 +0200 Subject: [PATCH 14/22] Sync MK3<->MK4 MMU2 reporting --- Firmware/mmu2.cpp | 12 ++++++------ Firmware/mmu2_progress_converter.cpp | 6 +++--- Firmware/mmu2_progress_converter.h | 7 ++++++- Firmware/mmu2_reporting.cpp | 11 +++++------ Firmware/mmu2_reporting.h | 19 +++++++++++++------ 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 972fc5cd1..15c42915b 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -196,7 +196,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)); } } @@ -218,10 +218,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); } }; @@ -1001,7 +1001,7 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { // 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)); + ReportErrorHook((CommandInProgress)logic.CommandInProgress(), ec, uint8_t(lastErrorSource)); } static_assert(mmu2Magic[0] == 'M' @@ -1014,8 +1014,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) { 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 b8cd8611b..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_reporting.cpp b/Firmware/mmu2_reporting.cpp index ddef50c61..844fe5fe5 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) { @@ -289,7 +288,7 @@ 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)) ); diff --git a/Firmware/mmu2_reporting.h b/Firmware/mmu2_reporting.h index e26a11ea0..0549db2d6 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,10 +42,10 @@ 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(); @@ -96,4 +103,4 @@ void ScreenClear(); void tuneIdlerStallguardThreshold(); -} // namespace +} // namespace MMU2 From be5523187bcf14e90c7f6b03469a9002d3b22310 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 11:53:13 +0200 Subject: [PATCH 15/22] Sync MK3<->MK4 MMU2 mmu2_mk4.h --- Firmware/Marlin_main.cpp | 4 ++-- Firmware/mmu2.cpp | 2 +- Firmware/mmu2.h | 28 ++++++++++++++++------------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 7c06981f7..dc2a58818 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3327,10 +3327,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) { diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 15c42915b..1ec53e6e4 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -761,7 +761,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 diff --git a/Firmware/mmu2.h b/Firmware/mmu2.h index 6040eebb9..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 }; @@ -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); From 7db725077388358dae92e7522257708496a9f8d2 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 12:49:30 +0200 Subject: [PATCH 16/22] Sync MK3<->MK4 MMU2 mmu2_mk4.cpp formatting --- Firmware/mmu2.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 1ec53e6e4..be8843a1a 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -115,7 +115,7 @@ void MMU2::ResetX0() { logic.ResetMMU(); // Send soft reset } -void MMU2::ResetX42(){ +void MMU2::ResetX42() { logic.ResetMMU(42); } @@ -453,7 +453,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 @@ -927,7 +927,7 @@ 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) { + for (uint8_t i = steps; i > 0; --i) { extruder_move(pgm_read_float(&(step->extrude)), pgm_read_float(&(step->feedRate))); step++; } @@ -980,6 +980,7 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { 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 @@ -988,6 +989,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 @@ -1000,7 +1002,7 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { 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 + // raise the MMU error screen and wait for user input ReportErrorHook((CommandInProgress)logic.CommandInProgress(), ec, uint8_t(lastErrorSource)); } From 9b48ab729afee7443b192c6a55756d1b277b5aca Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 12:50:44 +0200 Subject: [PATCH 17/22] Sync MK3<->MK4 MMU2 TryLoadUnloadReporter --- Firmware/mmu2.cpp | 50 ++++++++----------------------------- Firmware/mmu2_reporting.cpp | 38 +++++++++++++++------------- Firmware/mmu2_reporting.h | 27 ++++++++++++-------- 3 files changed, 47 insertions(+), 68 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index be8843a1a..7b6304d03 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -256,23 +256,14 @@ bool MMU2::RetryIfPossible(ErrorCode 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 +275,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 +286,23 @@ 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++) { - extruder_move(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; } + + return filament_inserted; } bool MMU2::ToolChangeCommonOnce(uint8_t slot) { diff --git a/Firmware/mmu2_reporting.cpp b/Firmware/mmu2_reporting.cpp index 844fe5fe5..ac037aeb9 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -295,30 +295,32 @@ void ReportProgressHook(CommandInProgress cip, ProgressCode ec) { } } -void TryLoadUnloadProgressbarInit() { - lcd_clearstatus(); +TryLoadUnloadReporter::TryLoadUnloadReporter(float delta_mm) +: dpixel0(0) +, dpixel1(0) +, lcd_cursor_col(0) +, pixel_per_mm(0.5F * float(LCD_WIDTH) / (delta_mm)) +{ + // Clear the status line + lcd_set_cursor(0, 3); + lcd_space(LCD_WIDTH); } -void TryLoadUnloadProgressbarDeinit() { - // Delay the next status message just so - // the user can see the results clearly +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_putc_at(col, 3, sensorState ? '-' : LCD_STR_SOLID_BLOCK[0]); lcd_reset_status_message_timeout(); } -void TryLoadUnloadProgressbarEcho() { - char buf[LCD_WIDTH]; - 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'; +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); } - 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(){ diff --git a/Firmware/mmu2_reporting.h b/Firmware/mmu2_reporting.h index 0549db2d6..5705efc47 100644 --- a/Firmware/mmu2_reporting.h +++ b/Firmware/mmu2_reporting.h @@ -47,19 +47,24 @@ void ReportErrorHook(CommandInProgress cip, ErrorCode ec, uint8_t es); /// Called when the MMU sends operation progress update void ReportProgressHook(CommandInProgress cip, ProgressCode ec); -/// @brief Clear the status line and setup the LCD cursor -void TryLoadUnloadProgressbarInit(); +struct TryLoadUnloadReporter { + TryLoadUnloadReporter(float delta_mm); + void Progress(bool sensorState); -/// @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 dpixel1; + uint8_t dpixel0; + // 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; + uint8_t lcd_cursor_col; +}; /// Remders the sensor status line. Also used by the "resume temperature" screen. void ReportErrorHookDynamicRender(); From 59e49c80f94d9a0599e45724a016b6edb6e8ddeb Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 11 Sep 2023 13:41:40 +0200 Subject: [PATCH 18/22] Sync MK3<->MK4 MMU2 Tune, Buttons, PowerPanic hooks refactoring --- Firmware/mmu2.cpp | 11 +++++------ Firmware/mmu2/buttons.h | 13 ++++++++----- Firmware/mmu2_marlin.h | 3 +++ Firmware/mmu2_marlin1.cpp | 12 ++++++++++++ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 7b6304d03..b46b51c3a 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -204,7 +204,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 @@ -261,7 +261,6 @@ bool MMU2::VerifyFilamentEnteredPTFE() { // 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 tryload_length = MMU2_CHECK_FILAMENT_PRESENCE_EXTRUSION_LENGTH - logic.ExtraLoadDistance(); TryLoadUnloadReporter tlur(tryload_length); @@ -617,7 +616,7 @@ 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; @@ -676,7 +675,7 @@ 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); } @@ -707,12 +706,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. 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_marlin.h b/Firmware/mmu2_marlin.h index 0990fdbc2..40aeee0f2 100644 --- a/Firmware/mmu2_marlin.h +++ b/Firmware/mmu2_marlin.h @@ -44,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(); diff --git a/Firmware/mmu2_marlin1.cpp b/Firmware/mmu2_marlin1.cpp index 05a9bf05e..3a7dfa837 100644 --- a/Firmware/mmu2_marlin1.cpp +++ b/Firmware/mmu2_marlin1.cpp @@ -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); } From a02ff0651c7b8044af9733358c0936abe639db8a Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Wed, 13 Sep 2023 07:45:11 +0200 Subject: [PATCH 19/22] Return try-load reporting to serial --- Firmware/mmu2.cpp | 2 +- Firmware/mmu2_reporting.cpp | 19 +++++++++++++++++++ Firmware/mmu2_reporting.h | 12 ++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index b46b51c3a..4d9c89063 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -300,7 +300,7 @@ bool MMU2::VerifyFilamentEnteredPTFE() { if (!filament_inserted) { IncrementLoadFails(); } - + tlur.DumpToSerial(); return filament_inserted; } diff --git a/Firmware/mmu2_reporting.cpp b/Firmware/mmu2_reporting.cpp index ac037aeb9..fd6a66b63 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -304,6 +304,7 @@ TryLoadUnloadReporter::TryLoadUnloadReporter(float delta_mm) // Clear the status line lcd_set_cursor(0, 3); lcd_space(LCD_WIDTH); + static_assert(LCD_WIDTH < 32); // for progress bits } void TryLoadUnloadReporter::Render(uint8_t col, bool sensorState) { @@ -320,9 +321,27 @@ void TryLoadUnloadReporter::Progress(bool sensorState){ dpixel0 = dpixel1; if (lcd_cursor_col > (LCD_WIDTH - 1)) lcd_cursor_col = LCD_WIDTH - 1; Render(lcd_cursor_col++, sensorState); + progress.dw <<= 1; + if(sensorState){ + progress.bytes[0] |= 1; + } } } +void TryLoadUnloadReporter::DumpToSerial(){ + char buf[LCD_WIDTH + 1]; + PU tmpProgress { progress.dw }; // avoid storing the shifted progress back into the memory - saves 4 instructions ;) + + // fill the buffer from the back - the last recorded fs state shall be printed as the last character + // i < 0xff means we go from LCD_WIDTH-1 down to zero included (LCD_WIDTH-1 is less than 0xff) + for (uint8_t i = LCD_WIDTH - 1; i < 0xff; --i) { + buf[i] = (tmpProgress.bytes[0] & 1) + '0'; + tmpProgress.dw >>= 1; + } + buf[LCD_WIDTH] = 0; + MMU2_ECHO_MSGLN(buf); +} + void IncrementLoadFails(){ eeprom_increment_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL); eeprom_increment_word((uint16_t *)EEPROM_MMU_LOAD_FAIL_TOT); diff --git a/Firmware/mmu2_reporting.h b/Firmware/mmu2_reporting.h index 5705efc47..a5c3b6583 100644 --- a/Firmware/mmu2_reporting.h +++ b/Firmware/mmu2_reporting.h @@ -50,6 +50,7 @@ void ReportProgressHook(CommandInProgress cip, ProgressCode ec); struct TryLoadUnloadReporter { TryLoadUnloadReporter(float delta_mm); void Progress(bool sensorState); + void DumpToSerial(); private: /// @brief Add one block to the progress bar @@ -64,6 +65,17 @@ private: // Note: Below is the reciprocal of (2 * delta_mm) / LCD_WIDTH [mm/pixel] float pixel_per_mm; uint8_t lcd_cursor_col; + + // Beware: needs to be a union to optimize for the 8bit better + union __attribute__((packed)) PU { + uint32_t dw; + uint8_t bytes[4]; + constexpr PU() + : dw(0) {} + constexpr PU(uint32_t dw) + : dw(dw) {} + } progress; + static_assert(sizeof(PU) == 4); }; /// Remders the sensor status line. Also used by the "resume temperature" screen. From ea010120264aa1abe0ca71b6171827754bf0212f Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Wed, 13 Sep 2023 12:43:44 +0200 Subject: [PATCH 20/22] Unify MMU operations' workflow --- Firmware/mmu2.cpp | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 4d9c89063..40387cdd5 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; @@ -465,9 +464,11 @@ bool MMU2::unload() { WaitForHotendTargetTempBeep(); - ReportingRAII rep(CommandInProgress::UnloadFilament); - UnloadInner(); - + { + ReportingRAII rep(CommandInProgress::UnloadFilament); + UnloadInner(); + } + ScreenUpdateEnable(); return true; } @@ -495,10 +496,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; } @@ -517,20 +518,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; } @@ -580,10 +579,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; } From 4134bf4f4006b9bfc55a28d0009bad2aaf56cffe Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sat, 16 Sep 2023 13:30:56 +0000 Subject: [PATCH 21/22] 8-bit proposed changes The status line code is not nice, but we need to work around it so the status line rendering works correctly This commit mostly reapplies the code from 3.13.2 Also fixes compiler warnings --- Firmware/mmu2_reporting.cpp | 31 ++++++++++++++----------------- Firmware/mmu2_reporting.h | 16 +++------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/Firmware/mmu2_reporting.cpp b/Firmware/mmu2_reporting.cpp index fd6a66b63..0efe3341f 100644 --- a/Firmware/mmu2_reporting.cpp +++ b/Firmware/mmu2_reporting.cpp @@ -301,17 +301,20 @@ TryLoadUnloadReporter::TryLoadUnloadReporter(float delta_mm) , lcd_cursor_col(0) , pixel_per_mm(0.5F * float(LCD_WIDTH) / (delta_mm)) { - // Clear the status line - lcd_set_cursor(0, 3); - lcd_space(LCD_WIDTH); - static_assert(LCD_WIDTH < 32); // for progress bits + lcd_clearstatus(); +} + +TryLoadUnloadReporter::~TryLoadUnloadReporter() { + // Delay the next status message just so + // the user can see the results clearly + lcd_reset_status_message_timeout(); } 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_putc_at(col, 3, sensorState ? '-' : LCD_STR_SOLID_BLOCK[0]); - lcd_reset_status_message_timeout(); + 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){ @@ -321,22 +324,16 @@ void TryLoadUnloadReporter::Progress(bool sensorState){ dpixel0 = dpixel1; if (lcd_cursor_col > (LCD_WIDTH - 1)) lcd_cursor_col = LCD_WIDTH - 1; Render(lcd_cursor_col++, sensorState); - progress.dw <<= 1; - if(sensorState){ - progress.bytes[0] |= 1; - } } } void TryLoadUnloadReporter::DumpToSerial(){ char buf[LCD_WIDTH + 1]; - PU tmpProgress { progress.dw }; // avoid storing the shifted progress back into the memory - saves 4 instructions ;) - - // fill the buffer from the back - the last recorded fs state shall be printed as the last character - // i < 0xff means we go from LCD_WIDTH-1 down to zero included (LCD_WIDTH-1 is less than 0xff) - for (uint8_t i = LCD_WIDTH - 1; i < 0xff; --i) { - buf[i] = (tmpProgress.bytes[0] & 1) + '0'; - tmpProgress.dw >>= 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); diff --git a/Firmware/mmu2_reporting.h b/Firmware/mmu2_reporting.h index a5c3b6583..2a01afa0c 100644 --- a/Firmware/mmu2_reporting.h +++ b/Firmware/mmu2_reporting.h @@ -49,6 +49,7 @@ void ReportProgressHook(CommandInProgress cip, ProgressCode ec); struct TryLoadUnloadReporter { TryLoadUnloadReporter(float delta_mm); + ~TryLoadUnloadReporter(); void Progress(bool sensorState); void DumpToSerial(); @@ -58,24 +59,13 @@ private: /// @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); - uint8_t dpixel1; 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; - uint8_t lcd_cursor_col; - - // Beware: needs to be a union to optimize for the 8bit better - union __attribute__((packed)) PU { - uint32_t dw; - uint8_t bytes[4]; - constexpr PU() - : dw(0) {} - constexpr PU(uint32_t dw) - : dw(dw) {} - } progress; - static_assert(sizeof(PU) == 4); }; /// Remders the sensor status line. Also used by the "resume temperature" screen. From 0f1cb4f407adbac43718c058b9e84ac11ab5163f Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 18 Sep 2023 07:39:45 +0200 Subject: [PATCH 22/22] Fixup from review --- Firmware/mmu2.cpp | 1 + Firmware/mmu2_protocol_logic.cpp | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 40387cdd5..333a9d0e1 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -296,6 +296,7 @@ bool MMU2::VerifyFilamentEnteredPTFE() { safe_delay_keep_alive(0); } } + Disable_E0(); if (!filament_inserted) { IncrementLoadFails(); } diff --git a/Firmware/mmu2_protocol_logic.cpp b/Firmware/mmu2_protocol_logic.cpp index bad34310c..77a0da950 100644 --- a/Firmware/mmu2_protocol_logic.cpp +++ b/Firmware/mmu2_protocol_logic.cpp @@ -29,8 +29,6 @@ namespace MMU2 { /// /// Currently, this is not possible to perform automatically at compile time with the existing languages/translations infrastructure. /// To save space a "dumb" solution was chosen + a few static_assert checks in errors_list.h preventing the code from compiling when the string doesn't match. -/// ----- -/// On Buddy FW we should improve the error screen to be able to print formatted strings static constexpr uint8_t supportedMmuFWVersion[3] PROGMEM = { mmuVersionMajor, mmuVersionMinor, mmuVersionPatch }; const Register ProtocolLogic::regs8Addrs[ProtocolLogic::regs8Count] PROGMEM = {