From 1bcc5c98a9ebe3c83f0344321e4c4e7b144ddcde Mon Sep 17 00:00:00 2001 From: "J.C. Nelson" <32139633+xC0000005@users.noreply.github.com> Date: Fri, 16 Aug 2019 18:02:35 -0700 Subject: [PATCH] MalyanLCD: Pause, resume, more ExtUI (#14852) --- Marlin/src/lcd/extui_malyan_lcd.cpp | 131 +++++++------------- config/examples/Malyan/M200/Configuration.h | 11 +- config/examples/Malyan/M200/README.md | 33 +++++ 3 files changed, 82 insertions(+), 93 deletions(-) create mode 100644 config/examples/Malyan/M200/README.md diff --git a/Marlin/src/lcd/extui_malyan_lcd.cpp b/Marlin/src/lcd/extui_malyan_lcd.cpp index 979e159598..f03d667af6 100644 --- a/Marlin/src/lcd/extui_malyan_lcd.cpp +++ b/Marlin/src/lcd/extui_malyan_lcd.cpp @@ -45,6 +45,8 @@ #if ENABLED(MALYAN_LCD) +#define DEBUG_MALYAN_LCD + #include "extensible_ui/ui_api.h" #include "ultralcd.h" @@ -62,6 +64,9 @@ #define LONG_FILENAME_LENGTH 0 #endif +#define DEBUG_OUT ENABLED(DEBUG_MALYAN_LCD) +#include "../core/debug_out.h" + // On the Malyan M200, this will be Serial1. On a RAMPS board, // it might not be. #define LCD_SERIAL Serial1 @@ -119,13 +124,13 @@ void process_lcd_c_command(const char* command) { LIMIT(feedrate_percentage, 10, 999); break; - case 'T': thermalManager.setTargetHotend(atoi(command + 1), 0); break; + case 'T': ExtUI::setTargetTemp_celsius(atoi(command + 1), ExtUI::extruder_t::E0); break; #if HAS_HEATED_BED - case 'P': thermalManager.setTargetBed(atoi(command + 1)); break; + case 'P': ExtUI::setTargetTemp_celsius(atoi(command + 1), ExtUI::heater_t::BED); break; #endif - default: SERIAL_ECHOLNPAIR("UNKNOWN C COMMAND", command); + default: DEBUG_ECHOLNPAIR("UNKNOWN C COMMAND ", command); } } @@ -163,9 +168,7 @@ void process_lcd_eb_command(const char* command) { write_to_lcd(message_buffer); } break; - default: - SERIAL_ECHOLNPAIR("UNKNOWN E/B COMMAND", command); - return; + default: DEBUG_ECHOLNPAIR("UNKNOWN E/B COMMAND ", command); } } @@ -180,32 +183,18 @@ void process_lcd_eb_command(const char* command) { * X, Y, Z, A (extruder) */ void process_lcd_j_command(const char* command) { - static bool steppers_enabled = false; - char axis = command[0]; + auto move_axis = [](const auto axis) { + const float dist = atof(command + 1) / 10.0; + ExtUI::setAxisPosition_mm(ExtUI::getAxisPosition_mm(axis) + dist, axis); + } - switch (axis) { - case 'E': - // enable or disable steppers - // switch to relative - queue.enqueue_now_P(PSTR("G91")); - queue.enqueue_now_P(steppers_enabled ? PSTR("M18") : PSTR("M17")); - steppers_enabled = !steppers_enabled; - break; - case 'A': - axis = 'E'; - // fallthru - case 'Y': - case 'Z': - case 'X': { - // G0 - // The M200 class UI seems to send movement in .1mm values. - char cmd[20], pos[6]; - sprintf_P(cmd, PSTR("G1 %c%s"), axis, dtostrf(atof(command + 1) / 10.0, -5, 3, pos)); - queue.enqueue_one_now(cmd); - } break; - default: - SERIAL_ECHOLNPAIR("UNKNOWN J COMMAND", command); - return; + switch (command[0]) { + case 'E': break; + case 'A': move_axis(ExtUI::extruder_t::E0); break; + case 'Y': move_axis(ExtUI::axis_t::Y); break; + case 'Z': move_axis(ExtUI::axis_t::Z); break; + case 'X': move_axis(ExtUI::axis_t::X); break; + default: DEBUG_ECHOLNPAIR("UNKNOWN J COMMAND ", command); } } @@ -234,29 +223,20 @@ void process_lcd_j_command(const char* command) { void process_lcd_p_command(const char* command) { switch (command[0]) { + case 'P': + ExtUI::pausePrint(); + write_to_lcd_P(PSTR("{SYS:PAUSED}")); + break; + case 'R': + ExtUI::resumePrint(); + write_to_lcd_P(PSTR("{SYS:RESUMED}")); + break; case 'X': - #if ENABLED(SDSUPPORT) - // cancel print write_to_lcd_P(PSTR("{SYS:CANCELING}")); - last_printing_status = false; - card.stopSDPrint( - #if SD_RESORT - true - #endif - ); - queue.clear(); - quickstop_stepper(); - print_job_timer.stop(); - thermalManager.disable_all_heaters(); - thermalManager.zero_fan_speeds(); - wait_for_heatup = false; + ExtUI::stopPrint(); write_to_lcd_P(PSTR("{SYS:STARTED}")); - #endif - break; - case 'H': - // Home all axis - queue.enqueue_now_P(PSTR("G28")); - break; + break; + case 'H': queue.enqueue_now_P(PSTR("G28")); break; // Home all axes default: { #if ENABLED(SDSUPPORT) // Print file 000 - a three digit number indicating which @@ -338,9 +318,7 @@ void process_lcd_s_command(const char* command) { #endif } break; - default: - SERIAL_ECHOLNPAIR("UNKNOWN S COMMAND", command); - return; + default: DEBUG_ECHOLNPAIR("UNKNOWN S COMMAND ", command); } } @@ -354,34 +332,22 @@ void process_lcd_command(const char* command) { current++; // skip the leading {. The trailing one is already gone. byte command_code = *current++; - if (*current != ':') { - SERIAL_ECHOLNPAIR("UNKNOWN COMMAND FORMAT", command); - return; - } + if (*current == ':') { - current++; // skip the : + current++; // skip the : - switch (command_code) { - case 'S': - process_lcd_s_command(current); - break; - case 'J': - process_lcd_j_command(current); - break; - case 'P': - process_lcd_p_command(current); - break; - case 'C': - process_lcd_c_command(current); - break; - case 'B': - case 'E': - process_lcd_eb_command(current); - break; - default: - SERIAL_ECHOLNPAIR("UNKNOWN COMMAND", command); - return; + switch (command_code) { + case 'S': process_lcd_s_command(current); break; + case 'J': process_lcd_j_command(current); break; + case 'P': process_lcd_p_command(current); break; + case 'C': process_lcd_c_command(current); break; + case 'B': + case 'E': process_lcd_eb_command(current); break; + default: DEBUG_ECHOLNPAIR("UNKNOWN COMMAND ", command); + } } + else + DEBUG_ECHOLNPAIR("UNKNOWN COMMAND FORMAT ", command); } /** @@ -405,8 +371,7 @@ namespace ExtUI { /** * The Malyan LCD actually runs as a separate MCU on Serial 1. * This code's job is to siphon the weird curly-brace commands from - * it and translate into gcode, which then gets injected into - * the command queue where possible. + * it and translate into ExtUI operations where possible. */ inbound_count = 0; LCD_SERIAL.begin(500000); @@ -455,13 +420,13 @@ namespace ExtUI { // If there was a print in progress, we need to emit the final // print status as {TQ:100}. Reset last percent done so a new print will // issue a percent of 0. - const uint8_t percent_done = IS_SD_PRINTING() ? card.percentDone() : last_printing_status ? 100 : 0; + const uint8_t percent_done = (ExtUI::isPrinting() || ExtUI::isPrintingFromMediaPaused()) ? ExtUI::getProgress_percent() : last_printing_status ? 100 : 0; if (percent_done != last_percent_done) { char message_buffer[16]; sprintf_P(message_buffer, PSTR("{TQ:%03i}"), percent_done); write_to_lcd(message_buffer); last_percent_done = percent_done; - last_printing_status = IS_SD_PRINTING(); + last_printing_status = ExtUI::isPrinting(); } #endif } diff --git a/config/examples/Malyan/M200/Configuration.h b/config/examples/Malyan/M200/Configuration.h index b1259de5b5..87c368906e 100644 --- a/config/examples/Malyan/M200/Configuration.h +++ b/config/examples/Malyan/M200/Configuration.h @@ -2030,7 +2030,7 @@ // // Touch-screen LCD for Malyan M200 printers // -//#define MALYAN_LCD +#define MALYAN_LCD // // LulzBot Color Touch UI for FTDI EVE (FT800/FT810) displays @@ -2057,15 +2057,6 @@ //============================ Other Controllers ============================ //============================================================================= -// -// CONTROLLER TYPE: Standalone / Serial -// - -// -// LCD for Malyan M200 printers. -// -#define MALYAN_LCD - // // ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8 // diff --git a/config/examples/Malyan/M200/README.md b/config/examples/Malyan/M200/README.md new file mode 100644 index 0000000000..84490786e1 --- /dev/null +++ b/config/examples/Malyan/M200/README.md @@ -0,0 +1,33 @@ +### Malyan M200 Build Instructions + +Malyan M200 series firmware currently builds using the Arduino IDE. These instructions should +guide you through the configuration and compilation. + +1. Install the Arduino IDE from your favorite source (arduino.cc, windows store, app store) +2. Launch the IDE to add the ST boards manager: + - Open the **Preferences** dialog. + - Add this link in the "*Additional Boards Managers URLs*" field: + https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json + - Select "**Show verbose ouptut during: compilation**." +3. Select **Tools** > **Board** > **Boards Manager**. +4. Type "Malyan" into the Search field. +5. The only board listed will be "**STM32 Cores by STMicroelectronics**." Any version from 1.6.0 up is fine. Choose install. This will download many tools and packages, be patient. +6. Open the **Tools** > **Board** submenu, scroll all the way down, and select **3D Printer Boards**. +7. From the **Tools** menu, select a board part number: + - If you own a M200 V1 or early run (black V2), choose **Malyan M200 V1**. + - If you own a M200 V2 later run (white/black) or V3 (Pro), choose **Malyan M200 V2** (The V2 and V3 both share an STM32F070 MCU). Note that the V3 pinout is not complete (autolevel doesn't work as of this writing). +8. From the **Tools** menu, choose **USB Support** > **CDC No Generic Serial**. +9. Download the latest Marlin source (from the [bugfix-2.0.x](https://github.com/MarlinFirmware/Marlin/tree/bugfix-2.0.x) branch) and unzip it. +10. Look in the `Marlin` subdirectory for the `Configuration.h` and `Configuration_adv.h` files. Replace these files with the configurations in the `config\examples\Malyan\M200` folder. +11. If you have an early-run V2, the steps-per-mm are roughly half. Consult the [mpminipro.com wiki](https://mpminipro.com/) for the steps that apply to your unit. Modify `Configuration.h`. +12. Inverting Axis. There's no pattern to axes will need to be inverted. The only way to know is to test your particular printer. If you *do* know, go ahead and invert the correct axes. +13. Open the `Marlin/Marlin.ino` file in Arduino IDE. +14. From the **Sketch** menu, select **File** > **Export Compiled Binary**. +15. When compilation is done you've built the firmware. The next stage is to flash it to the board. To do this look for a line like this: `"path/to/bin/arm-none-eabi-objcopy" -O binary "/path/to/Marlin.ino.elf" "/path/to/Marlin.ino.bin"` + The file `Marlin.ino.bin` is your firmware binary. M200 (v1-3) and M300 printers require flashing via SD card. Use the SD card that came with the printer if possible. The bootloader is very picky about SD cards. Copy `Marlin.ino.bin` to your SD card under three names: `firmware.bin`, `update.bin`, and `fcupdate.flg`. +16. Insert the SD card into your printer. Make sure the X and Y axes are centered in the middle of the bed. (When X and Y endstops are closed this signals a UI upgrade to the bootloader.) +17. Power-cycle the printer. The first flash may take longer. Don't be surprised if the .99 version number doesn't show up until after the UI has launched the default screen. +18. Remove the SD card and delete the `fcupdate.flg` file from the card to prevent an accidental re-flash. +19. Test the endstops and homing directions, run M303 PID autotune, and verify all features are working correctly. + +Welcome to Marlin 2.x...