From 36c8aee75b3f500c42228fbbfc37c996512787d0 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Fri, 23 Dec 2022 16:01:45 +0100 Subject: [PATCH 1/2] make custom Anycubic touchscreen implementation an ExtUI module Start migration to ExtUI module. We do not yet change much of the custom logic, but this brings us closer to upstream and allows use of some integration hooks with less patching required. --- Marlin/src/MarlinCore.cpp | 27 +--- Marlin/src/gcode/anycubic_tft_debug/M9999.cpp | 4 +- Marlin/src/gcode/control/M80_M81.cpp | 2 +- Marlin/src/gcode/feature/pause/M600.cpp | 2 +- Marlin/src/gcode/temp/M104_M109.cpp | 2 +- Marlin/src/inc/Conditionals_LCD.h | 2 +- .../knutwurst}/anycubic_touchscreen.cpp | 47 ++++--- .../knutwurst}/anycubic_touchscreen.h | 8 +- .../lcd/extui/knutwurst/knutwurst_extui.cpp | 122 ++++++++++++++++++ 9 files changed, 167 insertions(+), 49 deletions(-) rename Marlin/src/lcd/{ => extui/knutwurst}/anycubic_touchscreen.cpp (98%) rename Marlin/src/lcd/{ => extui/knutwurst}/anycubic_touchscreen.h (98%) create mode 100644 Marlin/src/lcd/extui/knutwurst/knutwurst_extui.cpp diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 1bb1c8eb..34d8ff39 100755 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -254,7 +254,7 @@ // PATCH START: Knutwurst #if ENABLED(ANYCUBIC_TOUCHSCREEN) - #include "lcd/anycubic_touchscreen.h" + #include "lcd/extui/knutwurst/anycubic_touchscreen.h" #endif // PATCH END: Knutwurst @@ -353,7 +353,7 @@ void startOrResumeJob() { TERN_(GCODE_REPEAT_MARKERS, repeat.reset()); TERN_(CANCEL_OBJECTS, cancelable.reset()); TERN_(LCD_SHOW_E_TOTAL, e_move_accumulator = 0); - #if ENABLED(SET_REMAINING_TIME) + #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME) ui.reset_remaining_time(); #endif } @@ -890,10 +890,6 @@ void idle(bool no_stepper_sleep/*=false*/) { TERN_(MAX7219_DEBUG, max7219.idle_tasks()); // PATCH START: Knutwurst - #ifdef ANYCUBIC_TOUCHSCREEN - AnycubicTouchscreen.CommandScan(); - #endif - #ifdef ENDSTOP_BEEP EndstopBeep(); #endif @@ -1011,12 +1007,6 @@ void kill(FSTR_P const lcd_error/*=nullptr*/, FSTR_P const lcd_component/*=nullp // "Error:Printer halted. kill() called!" SERIAL_ERROR_MSG(STR_ERR_KILLED); - // PATCH START: Knutwurst - #ifdef ANYCUBIC_TOUCHSCREEN - AnycubicTouchscreen.KillTFT(); - #endif - // PATCH END: Knutwurst - #ifdef ACTION_ON_KILL hostui.kill(); #endif @@ -1292,12 +1282,6 @@ void setup() { #endif SERIAL_ECHOLNPGM("start"); - // PATCH START: Knutwurst - #ifdef ANYCUBIC_TOUCHSCREEN - AnycubicTouchscreen.Setup(); - #endif - // PATCH END: Knutwurst - // Set up these pins early to prevent suicide #if HAS_KILL SETUP_LOG("KILL_PIN"); @@ -1796,13 +1780,6 @@ void loop() { endstops.event_handler(); - // PATCH START: Knutwurst - idle(); - #ifdef ANYCUBIC_TOUCHSCREEN - AnycubicTouchscreen.CommandScan(); - #endif - // PATCH END: Knutwurst - TERN_(HAS_TFT_LVGL_UI, printer_state_polling()); TERN_(MARLIN_TEST_BUILD, runPeriodicTests()); diff --git a/Marlin/src/gcode/anycubic_tft_debug/M9999.cpp b/Marlin/src/gcode/anycubic_tft_debug/M9999.cpp index 354c746f..7b3628f6 100644 --- a/Marlin/src/gcode/anycubic_tft_debug/M9999.cpp +++ b/Marlin/src/gcode/anycubic_tft_debug/M9999.cpp @@ -24,7 +24,7 @@ #if BOTH(ANYCUBIC_TFT_DEBUG, KNUTWURST_DGUS2_TFT) -#include "../../lcd/anycubic_touchscreen.h" +#include "../../lcd/extui/knutwurst/anycubic_touchscreen.h" #include "../gcode.h" void GcodeSuite::M9999() { @@ -38,4 +38,4 @@ void GcodeSuite::M9999() { } #endif -// PATCH END: KNUTWURST \ No newline at end of file +// PATCH END: KNUTWURST diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index a1658eb2..6bfe92a8 100755 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -31,7 +31,7 @@ // PATCH START: Knutwurst #if ENABLED(ANYCUBIC_TOUCHSCREEN) - #include "../../lcd/anycubic_touchscreen.h" + #include "../../lcd/extui/knutwurst/anycubic_touchscreen.h" #endif // PATCH END: Knutwurst diff --git a/Marlin/src/gcode/feature/pause/M600.cpp b/Marlin/src/gcode/feature/pause/M600.cpp index fc8c8ab9..912be2fb 100755 --- a/Marlin/src/gcode/feature/pause/M600.cpp +++ b/Marlin/src/gcode/feature/pause/M600.cpp @@ -32,7 +32,7 @@ // PATCH START: Knutwurst #ifdef ANYCUBIC_TOUCHSCREEN - #include "../../../lcd/anycubic_touchscreen.h" + #include "../../../lcd/extui/knutwurst/anycubic_touchscreen.h" #include "../../../sd/cardreader.h" #endif // PATCH END: Knutwurst diff --git a/Marlin/src/gcode/temp/M104_M109.cpp b/Marlin/src/gcode/temp/M104_M109.cpp index 707f8c60..68bfefe0 100644 --- a/Marlin/src/gcode/temp/M104_M109.cpp +++ b/Marlin/src/gcode/temp/M104_M109.cpp @@ -39,7 +39,7 @@ #include "../../MarlinCore.h" // for startOrResumeJob, etc. #ifdef ANYCUBIC_TOUCHSCREEN - #include "../../lcd/anycubic_touchscreen.h" + #include "../../lcd/extui/knutwurst/anycubic_touchscreen.h" #endif #if ENABLED(PRINTJOB_TIMER_AUTOSTART) diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 545d5534..46b6ec65 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -471,7 +471,7 @@ #endif // Extensible UI serial touch screens. (See src/lcd/extui) -#if ANY(HAS_DGUS_LCD, MALYAN_LCD, TOUCH_UI_FTDI_EVE, ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON, NEXTION_TFT) +#if ANY(HAS_DGUS_LCD, MALYAN_LCD, TOUCH_UI_FTDI_EVE, ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON, ANYCUBIC_TOUCHSCREEN, NEXTION_TFT) // PATCH: knutwurst #define IS_EXTUI 1 #define EXTENSIBLE_UI #endif diff --git a/Marlin/src/lcd/anycubic_touchscreen.cpp b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp similarity index 98% rename from Marlin/src/lcd/anycubic_touchscreen.cpp rename to Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp index 60529165..08298ba5 100755 --- a/Marlin/src/lcd/anycubic_touchscreen.cpp +++ b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp @@ -24,21 +24,21 @@ #include #include -#include "../gcode/queue.h" -#include "../gcode/parser.h" -#include "../feature/e_parser.h" -#include "../feature/pause.h" -#include "../feature/bedlevel/bedlevel.h" -#include "../libs/buzzer.h" -#include "../libs/numtostr.h" -#include "../module/planner.h" -#include "../module/printcounter.h" -#include "../module/temperature.h" -#include "../module/motion.h" -#include "../module/probe.h" -#include "../module/settings.h" -#include "../module/stepper.h" -#include "../sd/cardreader.h" +#include "../../../gcode/queue.h" +#include "../../../gcode/parser.h" +#include "../../../feature/e_parser.h" +#include "../../../feature/pause.h" +#include "../../../feature/bedlevel/bedlevel.h" +#include "../../../libs/buzzer.h" +#include "../../../libs/numtostr.h" +#include "../../../module/planner.h" +#include "../../../module/printcounter.h" +#include "../../../module/temperature.h" +#include "../../../module/motion.h" +#include "../../../module/probe.h" +#include "../../../module/settings.h" +#include "../../../module/stepper.h" +#include "../../../sd/cardreader.h" #ifdef ANYCUBIC_TOUCHSCREEN #include "./anycubic_touchscreen.h" @@ -1267,6 +1267,20 @@ #endif } + void AnycubicTouchscreenClass::SDCardStateChange(bool isInserted) { + #if ENABLED(ANYCUBIC_TFT_DEBUG) + SERIAL_ECHOLNPGM("TFT Serial Debug: SDCardStateChange event triggered...", isInserted); + #endif + CheckSDCardChange(); + } + + void AnycubicTouchscreenClass::SDCardError() { + #if ENABLED(ANYCUBIC_TFT_DEBUG) + SERIAL_ECHOLNPGM("TFT Serial Debug: SDCardError event triggered..."); + #endif + SENDLINE_DBG_PGM("J21", "TFT Serial Debug: SD Card Error ... J21"); + } + void AnycubicTouchscreenClass::CheckHeaterError() { if ((thermalManager.degHotend(0) < 5) || (thermalManager.degHotend(0) > 300)) { if (HeaterCheckCount > 600000) { @@ -1443,6 +1457,9 @@ } } + void AnycubicTouchscreenClass::UserConfirmRequired(const char * const msg) { + // TODO: implement to make advanced pause, filament change, etc. work again + } static boolean TFTcomment_mode = false; diff --git a/Marlin/src/lcd/anycubic_touchscreen.h b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h similarity index 98% rename from Marlin/src/lcd/anycubic_touchscreen.h rename to Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h index dc08110c..c0c9d29e 100755 --- a/Marlin/src/lcd/anycubic_touchscreen.h +++ b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h @@ -25,9 +25,8 @@ // #include "../inc/MarlinConfig.h" // #include "../module/configuration_store.h" -#include "./src/inc/MarlinConfigPre.h" -#include "./src/feature/bedlevel/bedlevel.h" -#include "src/module/probe.h" +#include "../../../inc/MarlinConfigPre.h" +#include "../../../module/probe.h" enum axis_t : uint8_t { X, Y, Z, X2, Y2, Z2, Z3, Z4 }; @@ -253,6 +252,9 @@ void BedHeatingDone(); void HeatingDone(); void HeatingStart(); void FilamentRunout(); +void UserConfirmRequired(const char *); +void SDCardStateChange(bool); +void SDCardError(); void KillTFT(); #if BOTH(ANYCUBIC_TFT_DEBUG, KNUTWURST_DGUS2_TFT) void Command(const char * const command); diff --git a/Marlin/src/lcd/extui/knutwurst/knutwurst_extui.cpp b/Marlin/src/lcd/extui/knutwurst/knutwurst_extui.cpp new file mode 100644 index 00000000..a4bd2113 --- /dev/null +++ b/Marlin/src/lcd/extui/knutwurst/knutwurst_extui.cpp @@ -0,0 +1,122 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * lcd/extui/knutwurst/knutwurst_extui.cpp + */ + +#include "../../../inc/MarlinConfigPre.h" + +#if ENABLED(ANYCUBIC_TOUCHSCREEN) + +#include "anycubic_touchscreen.h" +#include "../ui_api.h" + +#include // for the ::tone() call + +namespace ExtUI { + void onStartup() { AnycubicTouchscreen.Setup(); } + void onIdle() { AnycubicTouchscreen.CommandScan(); } + void onPrinterKilled(FSTR_P const error, FSTR_P const component) { AnycubicTouchscreen.KillTFT(); } + void onMediaInserted() { AnycubicTouchscreen.SDCardStateChange(true); } + void onMediaError() { AnycubicTouchscreen.SDCardError(); } + void onMediaRemoved() { AnycubicTouchscreen.SDCardStateChange(false); } + void onPlayTone(const uint16_t frequency, const uint16_t duration) { + TERN_(SPEAKER, ::tone(BEEPER_PIN, frequency, duration)); + } + void onPrintTimerStarted() { } + void onPrintTimerPaused() { } + void onPrintTimerStopped() { } + void onFilamentRunout(const extruder_t extruder) { AnycubicTouchscreen.FilamentRunout(); } + void onUserConfirmRequired(const char * const msg) { AnycubicTouchscreen.UserConfirmRequired(msg); } + void onStatusChanged(const char * const msg) {} + + void onHomingStart() {} + void onHomingDone() {} + void onPrintDone() {} + + void onFactoryReset() {} + + void onStoreSettings(char *buff) { + // Called when saving to EEPROM (i.e. M500). If the ExtUI needs + // permanent data to be stored, it can write up to eeprom_data_size bytes + // into buff. + + // Example: + // static_assert(sizeof(myDataStruct) <= eeprom_data_size); + // memcpy(buff, &myDataStruct, sizeof(myDataStruct)); + } + + void onLoadSettings(const char *buff) { + // Called while loading settings from EEPROM. If the ExtUI + // needs to retrieve data, it should copy up to eeprom_data_size bytes + // from buff + + // Example: + // static_assert(sizeof(myDataStruct) <= eeprom_data_size); + // memcpy(&myDataStruct, buff, sizeof(myDataStruct)); + } + + void onPostprocessSettings() { + // Called after loading or resetting stored settings + } + + void onSettingsStored(bool success) { + // Called after the entire EEPROM has been written, + // whether successful or not. + } + + void onSettingsLoaded(bool success) { + // Called after the entire EEPROM has been read, + // whether successful or not. + } + + #if HAS_MESH + void onLevelingStart() {} + void onLevelingDone() {} + + void onMeshUpdate(const int8_t xpos, const int8_t ypos, const_float_t zval) { + // Called when any mesh points are updated + } + + void onMeshUpdate(const int8_t xpos, const int8_t ypos, probe_state_t state) { + // Called when any mesh points are updated + } + #endif + + #if ENABLED(POWER_LOSS_RECOVERY) + void onPowerLossResume() { + // Called on resume from power-loss + } + #endif + + #if HAS_PID_HEATING + void onPidTuning(const result_t rst) { + // Called for temperature PID tuning result + } + #endif + + void onSteppersDisabled() {} + void onSteppersEnabled() {} +} + +#endif // ANYCUBIC_TOUCHSCREEN From b115276feeee2e294423cc70703ae2876abcbdd0 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Fri, 23 Dec 2022 17:49:15 +0100 Subject: [PATCH 2/2] move display notification after leveling for Chiron into ExtUI hook --- Marlin/src/gcode/bedlevel/abl/G29.cpp | 5 ----- Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp | 6 ++++++ Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h | 3 +++ Marlin/src/lcd/extui/knutwurst/knutwurst_extui.cpp | 7 ++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 3a3201b9..0fef5ad6 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -806,11 +806,6 @@ G29_TYPE GcodeSuite::G29() { bedlevel.set_grid(abl.gridSpacing, abl.probe_position_lf); COPY(bedlevel.z_values, abl.z_values); TERN_(IS_KINEMATIC, bedlevel.extrapolate_unprobed_bed_level()); - - #if ENABLED(KNUTWURST_TFT_LEVELING) - LCD_SERIAL.print("J25\r\n"); // Autoleveling done! - #endif - bedlevel.refresh_bed_level(); bedlevel.print_leveling_grid(); diff --git a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp index 08298ba5..547ef15b 100755 --- a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp +++ b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp @@ -2333,5 +2333,11 @@ #endif } + #if ENABLED(KNUTWURST_TFT_LEVELING) + void AnycubicTouchscreenClass::LevelingDone() { + SENDLINE_DBG_PGM("J25", "TFT Serial Debug: Auto leveling done... J25"); + } + #endif + AnycubicTouchscreenClass AnycubicTouchscreen; #endif // ifdef ANYCUBIC_TOUCHSCREEN diff --git a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h index c0c9d29e..8c66ce25 100755 --- a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h +++ b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.h @@ -259,6 +259,9 @@ void KillTFT(); #if BOTH(ANYCUBIC_TFT_DEBUG, KNUTWURST_DGUS2_TFT) void Command(const char * const command); #endif +#if ENABLED(KNUTWURST_TFT_LEVELING) + void LevelingDone(); +#endif char TFTstate = ANYCUBIC_TFT_STATE_IDLE; /** diff --git a/Marlin/src/lcd/extui/knutwurst/knutwurst_extui.cpp b/Marlin/src/lcd/extui/knutwurst/knutwurst_extui.cpp index a4bd2113..68132055 100644 --- a/Marlin/src/lcd/extui/knutwurst/knutwurst_extui.cpp +++ b/Marlin/src/lcd/extui/knutwurst/knutwurst_extui.cpp @@ -92,7 +92,12 @@ namespace ExtUI { #if HAS_MESH void onLevelingStart() {} - void onLevelingDone() {} + + void onLevelingDone() { + #if ENABLED(KNUTWURST_TFT_LEVELING) + AnycubicTouchscreen.LevelingDone(); + #endif + } void onMeshUpdate(const int8_t xpos, const int8_t ypos, const_float_t zval) { // Called when any mesh points are updated