11/* *
22 * Marlin 3D Printer Firmware
3- * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
3+ * Copyright (c) 2024 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
44 *
55 * Based on Sprinter and grbl.
66 * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
@@ -47,7 +47,7 @@ static void gcodes_M704_M705_M706(uint16_t gcode) {
4747}
4848
4949/* *
50- * ### M704 - Preload to MMU <a href="https://reprap.org/wiki/G-code#M704:_Preload_to_MMU">M704: Preload to MMU</a>
50+ * ### M704 - Preload to MMU
5151 * #### Usage
5252 *
5353 * M704 [ P ]
@@ -60,7 +60,7 @@ void GcodeSuite::M704() {
6060}
6161
6262/* *
63- * ### M705 - Eject filament <a href="https://reprap.org/wiki/G-code#M705:_Eject_filament">M705: Eject filament</a>
63+ * ### M705 - Eject filament
6464 * #### Usage
6565 *
6666 * M705 [ P ]
@@ -73,7 +73,7 @@ void GcodeSuite::M705() {
7373}
7474
7575/* !
76- * ### M706 - Cut filament <a href="https://reprap.org/wiki/G-code#M706:_Cut_filament">M706: Cut filament</a>
76+ * ### M706 - Cut filament
7777 * #### Usage
7878 *
7979 * M706 [ P ]
@@ -86,7 +86,7 @@ void GcodeSuite::M706() {
8686}
8787
8888/* *
89- * ### M707 - Read from MMU register <a href="https://reprap.org/wiki/G-code#M707:_Read_from_MMU_register">M707: Read from MMU register</a>
89+ * ### M707 - Read from MMU register
9090 * #### Usage
9191 *
9292 * M707 [ A ]
@@ -102,16 +102,14 @@ void GcodeSuite::M706() {
102102 *
103103 */
104104void GcodeSuite::M707 () {
105- if (mmu3.enabled () ) {
106- if (parser.seenval (' A' ) ) {
107- char *address = parser.stringval (' A' );
108- mmu3.readRegister (uint8_t (strtol (address, NULL , 16 )));
109- }
105+ if (mmu3.enabled () && parser.seenval (' A' )) {
106+ char *address = parser.value_string ();
107+ mmu3.readRegister (uint8_t (strtol (address, NULL , 16 )));
110108 }
111109}
112110
113111/* *
114- * ### M708 - Write to MMU register <a href="https://reprap.org/wiki/G-code#M708:_Write_to_MMU_register">M707: Write to MMU register</a>
112+ * ### M708 - Write to MMU register
115113 * #### Usage
116114 *
117115 * M708 [ A | X ]
@@ -126,24 +124,18 @@ void GcodeSuite::M707() {
126124 * Does nothing if A parameter is missing or if MMU is not enabled.
127125 */
128126void GcodeSuite::M708 () {
129- if (mmu3.enabled () ) {
130- uint8_t addr = 0 ;
131- if (parser.seenval (' A' ) ) {
132- char *address = parser.stringval (' A' );
133- addr = uint8_t (strtol (address, NULL , 16 ));
134- }
135- uint16_t data = 0 ;
136- if (parser.seenval (' X' ) ) {
137- data = parser.ushortval (' X' , 0 );
138- }
127+ if (mmu3.enabled () && parser.seenval (' A' )) {
128+ char *address = parser.value_string ();
129+ const uint8_t addr = uint8_t (strtol (address, NULL , 16 ));
139130 if (addr) {
131+ const uint16_t data = parser.ushortval (' X' , 0 );
140132 mmu3.writeRegister (addr, data);
141133 }
142134 }
143135}
144136
145137/* *
146- * ### M709 - MMU power & reset <a href="https://reprap.org/wiki/G-code#M709:_MMU_power_&_reset">M709: MMU power & reset</a>
138+ * ### M709 - MMU power & reset
147139 * The MK3S cannot not power off the MMU, but we can en- and disable the MMU.
148140 *
149141 * The new state of the MMU is stored in printer's EEPROM.
@@ -167,14 +159,14 @@ void GcodeSuite::M708() {
167159 */
168160void GcodeSuite::M709 () {
169161 if (parser.seenval (' S' )) {
170- switch (parser.byteval (' S' , -1 )) {
171- case 0 : mmu3.stop (); break ;
172- case 1 : mmu3.start (); break ;
173- default : break ;
174- }
162+ if (parser.value_bool ())
163+ mmu3.start ();
164+ else
165+ mmu3.stop ();
175166 }
167+
176168 if (mmu3.enabled () && parser.seenval (' X' )) {
177- switch (parser.byteval ( ' X ' , - 1 )) {
169+ switch (parser.value_byte ( )) {
178170 case 0 : mmu3.reset (MMU3::MMU3::Software); break ;
179171 case 1 : mmu3.reset (MMU3::MMU3::ResetPin); break ;
180172 case 42 : mmu3.reset (MMU3::MMU3::EraseEEPROM); break ;
@@ -184,4 +176,26 @@ void GcodeSuite::M709() {
184176 mmu3.status ();
185177}
186178
179+ /* *
180+ * Report for M503.
181+ * TODO: Report MMU3 G-code settings here, status via a different G-code.
182+ */
183+ void GcodeSuite::MMU3_report () {
184+ report_heading (forReplay, F (" MMU3 Operational Stats" ));
185+ SERIAL_ECHOPGM (" MMU " ); serialprintln_onoff (mmu3.mmu_hw_enabled );
186+ SERIAL_ECHOPGM (" Stealth Mode " ); serialprintln_onoff (mmu3.stealth_mode );
187+ #if ENABLED(MMU_HAS_CUTTER)
188+ SERIAL_ECHOPGM (" Cutter " );
189+ serialprintln_onoff (mmu3.cutter_mode != 0 );
190+ #endif
191+ SERIAL_ECHOPGM (" SpoolJoin " ); serialprintln_onoff (spooljoin.enabled );
192+ SERIAL_ECHOLNPGM (" Tool Changes " , MMU3::operation_statistics.tool_change_counter );
193+ SERIAL_ECHOLNPGM (" Total Tool Changes " , MMU3::operation_statistics.tool_change_total_counter );
194+ SERIAL_ECHOLNPGM (" Fails " , MMU3::operation_statistics.fail_num );
195+ SERIAL_ECHOLNPGM (" Total Fails " , MMU3::operation_statistics.fail_total_num );
196+ SERIAL_ECHOLNPGM (" Load Fails " , MMU3::operation_statistics.load_fail_num );
197+ SERIAL_ECHOLNPGM (" Total Load Fails " , MMU3::operation_statistics.load_fail_total_num );
198+ SERIAL_ECHOLNPGM (" Power Fails " , mmu3.tmcFailures ());
199+ }
200+
187201#endif // HAS_PRUSA_MMU3
0 commit comments