From f3876e81a74b8ffebdef7776e721f7c25e0ce770 Mon Sep 17 00:00:00 2001 From: Sebastiaan Dammann Date: Sun, 20 Sep 2020 15:49:45 +0200 Subject: [PATCH] Creality CR-6 source code dump from CR-6 SE -source code V1.0.3.6.rar As downloadable currently from Creality.com. It appears the source code has been based on 25a7cea. Using a cycle of 'git reset', 'git clean', copying over the files, doing a normalize (because the line endings were messed up), then checking for the origin of the changes, I could not trace it back much farther than this commit. This commit is like e95395ffe03c05e9c7b60233ea67e6ba819d1a3e but with the odd files like the .github files excluded. It is almost like Creality took the latest 1.x source codes files and half plastered their changes over it - or they might have backported specific changes from the latest Marlin sources back to this code? --- Marlin/Configuration.h | 165 +- Marlin/Configuration_adv.h | 35 +- Marlin/Version.h | 16 +- Marlin/src/HAL/HAL_STM32F1/sdio.h | 2 +- Marlin/src/HAL/HAL_STM32F1/timers.h | 2 +- Marlin/src/HAL/HAL_STM32F1/watchdog.cpp | 2 +- Marlin/src/HAL/HAL_STM32F1/watchdog.h | 2 +- Marlin/src/Marlin.cpp | 103 +- Marlin/src/core/boards.h | 1 + Marlin/src/core/serial.h | 2 +- Marlin/src/feature/bedlevel/abl/abl.h | 1 + Marlin/src/feature/leds/neopixel.h | 2 + Marlin/src/feature/power_loss_recovery.cpp | 90 +- Marlin/src/feature/power_loss_recovery.h | 7 + Marlin/src/gcode/bedlevel/abl/G29.cpp | 57 +- Marlin/src/gcode/calibrate/G28.cpp | 121 +- Marlin/src/gcode/eeprom/M500-M504.cpp | 1 + Marlin/src/gcode/gcode.cpp | 8 +- Marlin/src/gcode/queue.cpp | 21 + Marlin/src/gcode/sdcard/M24_M25.cpp | 3 +- Marlin/src/inc/Conditionals_post.h | 2 +- Marlin/src/inc/Version.h | 4 +- Marlin/src/lcd/dwin/LCD_RTS.cpp | 1992 +++++++++++++++++ Marlin/src/lcd/dwin/LCD_RTS.h | 253 +++ Marlin/src/lcd/dwin/i2c_eeprom.cpp | 271 +++ Marlin/src/lcd/dwin/i2c_eeprom.h | 60 + Marlin/src/lcd/menu/menu_configuration.cpp | 2 +- Marlin/src/module/configuration_store.cpp | 28 +- Marlin/src/module/endstops.cpp | 16 +- Marlin/src/module/motion.cpp | 15 + Marlin/src/module/motion.h | 2 +- Marlin/src/module/probe.cpp | 34 + Marlin/src/module/temperature.cpp | 95 +- Marlin/src/pins/pins.h | 2 + Marlin/src/pins/stm32/pins_CREALITY.h | 191 ++ Marlin/src/sd/cardreader.cpp | 29 +- Marlin/src/sd/cardreader.h | 5 +- .../share/PlatformIO/ldscripts/creality.ld | 14 + .../share/PlatformIO/scripts/creality.py | 16 + platformio.ini | 14 +- 40 files changed, 3510 insertions(+), 176 deletions(-) create mode 100644 Marlin/src/lcd/dwin/LCD_RTS.cpp create mode 100644 Marlin/src/lcd/dwin/LCD_RTS.h create mode 100644 Marlin/src/lcd/dwin/i2c_eeprom.cpp create mode 100644 Marlin/src/lcd/dwin/i2c_eeprom.h create mode 100644 Marlin/src/pins/stm32/pins_CREALITY.h create mode 100644 buildroot/share/PlatformIO/ldscripts/creality.ld create mode 100644 buildroot/share/PlatformIO/scripts/creality.py diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c2bf6340dcb2..ea442424fe2c 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -71,8 +71,13 @@ // @section info // Author info of this build printed to the host during boot and M115 -#define STRING_CONFIG_H_AUTHOR "(none, default config)" // Who made the changes. -//#define CUSTOM_VERSION_FILE Version.h // Path from the root directory (no quotes) +#define STRING_CONFIG_H_AUTHOR "CR-6 SE" // Who made the changes. +#define CUSTOM_VERSION_FILE Version.h // Path from the root directory (no quotes) +#define MACVERSION STRING_CONFIG_H_AUTHOR +#define SOFTVERSION SHORT_BUILD_VERSION +#define MAC_LENGTH 235 +#define MAC_WIDTH 235 +#define MAC_HEIGHT 250 /** * *** VENDORS PLEASE READ *** @@ -103,7 +108,7 @@ * * :[-1, 0, 1, 2, 3, 4, 5, 6, 7] */ -#define SERIAL_PORT 0 +#define SERIAL_PORT 1 /** * Select a secondary serial port on the board to use for communication with the host. @@ -112,7 +117,7 @@ * * :[-1, 0, 1, 2, 3, 4, 5, 6, 7] */ -//#define SERIAL_PORT_2 -1 +#define SERIAL_PORT_2 3 /** * This setting determines the communication speed of the printer. @@ -123,14 +128,14 @@ * * :[2400, 9600, 19200, 38400, 57600, 115200, 250000, 500000, 1000000] */ -#define BAUDRATE 250000 +#define BAUDRATE 115200 // Enable the Bluetooth serial interface on AT90USB devices //#define BLUETOOTH // Choose the name from boards.h that matches your setup #ifndef MOTHERBOARD - #define MOTHERBOARD BOARD_RAMPS_14_EFB + #define MOTHERBOARD BOARD_CREALITY #endif // Name displayed in the LCD "Ready" message and Info menu @@ -147,7 +152,7 @@ #define EXTRUDERS 1 // Generally expected filament diameter (1.75, 2.85, 3.0, ...). Used for Volumetric, Filament Width Sensor, etc. -#define DEFAULT_NOMINAL_FILAMENT_DIA 3.0 +#define DEFAULT_NOMINAL_FILAMENT_DIA 1.75 // For Cyclops or any "multi-extruder" that shares a single nozzle. //#define SINGLENOZZLE @@ -411,7 +416,7 @@ #define TEMP_SENSOR_3 0 #define TEMP_SENSOR_4 0 #define TEMP_SENSOR_5 0 -#define TEMP_SENSOR_BED 0 +#define TEMP_SENSOR_BED 1 #define TEMP_SENSOR_CHAMBER 0 // Dummy thermistor constant temperature readings, for use with 998 and 999 @@ -433,13 +438,13 @@ // Below this temperature the heater will be switched off // because it probably indicates a broken thermistor wire. -#define HEATER_0_MINTEMP 5 +#define HEATER_0_MINTEMP 0 #define HEATER_1_MINTEMP 5 #define HEATER_2_MINTEMP 5 #define HEATER_3_MINTEMP 5 #define HEATER_4_MINTEMP 5 #define HEATER_5_MINTEMP 5 -#define BED_MINTEMP 5 +#define BED_MINTEMP 0 // Above this temperature the heater will be switched off. // This can protect components from overheating, but NOT from shorts and failures. @@ -450,7 +455,7 @@ #define HEATER_3_MAXTEMP 275 #define HEATER_4_MAXTEMP 275 #define HEATER_5_MAXTEMP 275 -#define BED_MAXTEMP 150 +#define BED_MAXTEMP 120 //=========================================================================== //============================= PID Settings ================================ @@ -476,9 +481,14 @@ // If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it // Ultimaker + /* #define DEFAULT_Kp 22.2 #define DEFAULT_Ki 1.08 #define DEFAULT_Kd 114 + */ + #define DEFAULT_Kp 14.32 + #define DEFAULT_Ki 0.81 + #define DEFAULT_Kd 63.12 // MakerGear //#define DEFAULT_Kp 7.0 @@ -509,7 +519,7 @@ * heater. If your configuration is significantly different than this and you don't understand * the issues involved, don't use bed PID until someone else verifies that your hardware works. */ -//#define PIDTEMPBED +#define PIDTEMPBED //#define BED_LIMIT_SWITCHING @@ -527,9 +537,14 @@ //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) //from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10) + /* #define DEFAULT_bedKp 10.00 #define DEFAULT_bedKi .023 #define DEFAULT_bedKd 305.4 + */ + #define DEFAULT_bedKp 79.49 + #define DEFAULT_bedKi 1.17 + #define DEFAULT_bedKd 1349.52 //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) //from pidautotune @@ -550,14 +565,14 @@ * *** IT IS HIGHLY RECOMMENDED TO LEAVE THIS OPTION ENABLED! *** */ #define PREVENT_COLD_EXTRUSION -#define EXTRUDE_MINTEMP 170 +#define EXTRUDE_MINTEMP 180 /** * Prevent a single extrusion longer than EXTRUDE_MAXLENGTH. * Note: For Bowden Extruders make this large enough to allow load/unload. */ #define PREVENT_LENGTHY_EXTRUDE -#define EXTRUDE_MAXLENGTH 200 +#define EXTRUDE_MAXLENGTH 1000 //=========================================================================== //======================== Thermal Runaway Protection ======================= @@ -578,7 +593,7 @@ #define THERMAL_PROTECTION_HOTENDS // Enable thermal protection for all extruders #define THERMAL_PROTECTION_BED // Enable thermal protection for the heated bed -#define THERMAL_PROTECTION_CHAMBER // Enable thermal protection for the heated chamber +// #define THERMAL_PROTECTION_CHAMBER // Enable thermal protection for the heated chamber //=========================================================================== //============================= Mechanical Settings ========================= @@ -677,7 +692,7 @@ // Enable this feature if all enabled endstop pins are interrupt-capable. // This will remove the need to poll the interrupt pins, saving many CPU cycles. -//#define ENDSTOP_INTERRUPTS_FEATURE +// #define ENDSTOP_INTERRUPTS_FEATURE /** * Endstop Noise Threshold @@ -718,14 +733,14 @@ * Override with M92 * X, Y, Z, E0 [, E1[, E2...]] */ -#define DEFAULT_AXIS_STEPS_PER_UNIT { 80, 80, 4000, 500 } +#define DEFAULT_AXIS_STEPS_PER_UNIT { 80, 80, 400, 93 } /** * Default Max Feed Rate (mm/s) * Override with M203 * X, Y, Z, E0 [, E1[, E2...]] */ -#define DEFAULT_MAX_FEEDRATE { 300, 300, 5, 25 } +#define DEFAULT_MAX_FEEDRATE { 500, 500, 5, 25 } //#define LIMITED_MAX_FR_EDITING // Limit edit via M203 or LCD to DEFAULT_MAX_FEEDRATE * 2 #if ENABLED(LIMITED_MAX_FR_EDITING) @@ -738,7 +753,7 @@ * Override with M201 * X, Y, Z, E0 [, E1[, E2...]] */ -#define DEFAULT_MAX_ACCELERATION { 3000, 3000, 100, 10000 } +#define DEFAULT_MAX_ACCELERATION { 500, 500, 100, 1000 } //#define LIMITED_MAX_ACCEL_EDITING // Limit edit via M201 or LCD to DEFAULT_MAX_ACCELERATION * 2 #if ENABLED(LIMITED_MAX_ACCEL_EDITING) @@ -753,9 +768,9 @@ * M204 R Retract Acceleration * M204 T Travel Acceleration */ -#define DEFAULT_ACCELERATION 3000 // X, Y, Z and E acceleration for printing moves -#define DEFAULT_RETRACT_ACCELERATION 3000 // E acceleration for retracts -#define DEFAULT_TRAVEL_ACCELERATION 3000 // X, Y, Z acceleration for travel (non printing) moves +#define DEFAULT_ACCELERATION 500 // X, Y, Z and E acceleration for printing moves +#define DEFAULT_RETRACT_ACCELERATION 1000 // E acceleration for retracts +#define DEFAULT_TRAVEL_ACCELERATION 1000 // X, Y, Z acceleration for travel (non printing) moves /** * Default Jerk limits (mm/s) @@ -765,7 +780,7 @@ * When changing speed and direction, if the difference is less than the * value set here, it may happen instantaneously. */ -//#define CLASSIC_JERK +#define CLASSIC_JERK #if ENABLED(CLASSIC_JERK) #define DEFAULT_XJERK 10.0 #define DEFAULT_YJERK 10.0 @@ -853,7 +868,7 @@ * A Fix-Mounted Probe either doesn't deploy or needs manual deployment. * (e.g., an inductive probe or a nozzle-based probe-switch.) */ -//#define FIX_MOUNTED_PROBE +#define FIX_MOUNTED_PROBE /** * Z Servo Probe, such as an endstop switch on a rotating arm. @@ -864,7 +879,7 @@ /** * The BLTouch probe uses a Hall effect sensor and emulates a servo. */ -//#define BLTOUCH +// #define BLTOUCH /** * Touch-MI Probe by hotends.fr @@ -921,10 +936,10 @@ * * Specify a Probe position as { X, Y, Z } */ -#define NOZZLE_TO_PROBE_OFFSET { 10, 10, 0 } +#define NOZZLE_TO_PROBE_OFFSET { 0, 0, 0.2 } // Certain types of probes need to stay away from edges -#define MIN_PROBE_EDGE 10 +#define MIN_PROBE_EDGE 30 // X and Y axis travel speed (mm/m) between probes #define XY_PROBE_SPEED 8000 @@ -944,7 +959,7 @@ * A total of 2 does fast/slow probes with a weighted average. * A total of 3 or more adds more slow probes, taking the average. */ -//#define MULTIPLE_PROBING 2 +#define MULTIPLE_PROBING 2 //#define EXTRA_PROBING 1 /** @@ -962,15 +977,15 @@ * But: `M851 Z+1` with a CLEARANCE of 2 => 2mm from bed to nozzle. */ #define Z_CLEARANCE_DEPLOY_PROBE 10 // Z Clearance for Deploy/Stow -#define Z_CLEARANCE_BETWEEN_PROBES 5 // Z Clearance between probe points -#define Z_CLEARANCE_MULTI_PROBE 5 // Z Clearance between multiple probes +#define Z_CLEARANCE_BETWEEN_PROBES 3 // Z Clearance between probe points +#define Z_CLEARANCE_MULTI_PROBE 2 // Z Clearance between multiple probes //#define Z_AFTER_PROBING 5 // Z position after probing is done #define Z_PROBE_LOW_POINT -2 // Farthest distance below the trigger-point to go before stopping // For M851 give a range for adjusting the Z probe offset -#define Z_PROBE_OFFSET_RANGE_MIN -20 -#define Z_PROBE_OFFSET_RANGE_MAX 20 +#define Z_PROBE_OFFSET_RANGE_MIN -10 +#define Z_PROBE_OFFSET_RANGE_MAX 10 // Enable the M48 repeatability test to test probe accuracy //#define Z_MIN_PROBE_REPEATABILITY_TEST @@ -1020,14 +1035,14 @@ // @section machine // Invert the stepper direction. Change (or reverse the motor connector) if an axis goes the wrong way. -#define INVERT_X_DIR false -#define INVERT_Y_DIR true -#define INVERT_Z_DIR false +#define INVERT_X_DIR true +#define INVERT_Y_DIR false +#define INVERT_Z_DIR true // @section extruder // For direct drive extruder v9 set to true, for geared extruder set to false. -#define INVERT_E0_DIR false +#define INVERT_E0_DIR true #define INVERT_E1_DIR false #define INVERT_E2_DIR false #define INVERT_E3_DIR false @@ -1040,8 +1055,8 @@ //#define UNKNOWN_Z_NO_RAISE // Don't raise Z (lower the bed) if Z is "unknown." For beds that fall when Z is powered off. -//#define Z_HOMING_HEIGHT 4 // (mm) Minimal Z height before homing (G28) for Z clearance above the bed, clamps, ... - // Be sure you have this distance over your Z_MAX_POS in case. +#define Z_HOMING_HEIGHT 5 // (mm) Minimal Z height before homing (G28) for Z clearance above the bed, clamps, ... + // Be sure you have this distance over your Z_MAX_POS in case. // Direction of endstops when homing; 1=MAX, -1=MIN // :[-1,1] @@ -1052,16 +1067,16 @@ // @section machine // The size of the print bed -#define X_BED_SIZE 200 -#define Y_BED_SIZE 200 +#define X_BED_SIZE 235 +#define Y_BED_SIZE 235 // Travel limits (mm) after homing, corresponding to endstop positions. -#define X_MIN_POS 0 -#define Y_MIN_POS 0 +#define X_MIN_POS -5 +#define Y_MIN_POS -2 #define Z_MIN_POS 0 #define X_MAX_POS X_BED_SIZE #define Y_MAX_POS Y_BED_SIZE -#define Z_MAX_POS 200 +#define Z_MAX_POS 250 /** * Software Endstops @@ -1073,7 +1088,7 @@ */ // Min software endstops constrain movement within minimum coordinate bounds -#define MIN_SOFTWARE_ENDSTOPS +// #define MIN_SOFTWARE_ENDSTOPS #if ENABLED(MIN_SOFTWARE_ENDSTOPS) #define MIN_SOFTWARE_ENDSTOP_X #define MIN_SOFTWARE_ENDSTOP_Y @@ -1164,7 +1179,7 @@ */ //#define AUTO_BED_LEVELING_3POINT //#define AUTO_BED_LEVELING_LINEAR -//#define AUTO_BED_LEVELING_BILINEAR +#define AUTO_BED_LEVELING_BILINEAR //#define AUTO_BED_LEVELING_UBL //#define MESH_BED_LEVELING @@ -1179,7 +1194,7 @@ * Turn on with the command 'M111 S32'. * NOTE: Requires a lot of PROGMEM! */ -//#define DEBUG_LEVELING_FEATURE +// #define DEBUG_LEVELING_FEATURE #if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL) // Gradually reduce leveling correction until a set height is reached, @@ -1210,17 +1225,17 @@ #if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR) // Set the number of grid points per dimension. - #define GRID_MAX_POINTS_X 3 + #define GRID_MAX_POINTS_X 4 #define GRID_MAX_POINTS_Y GRID_MAX_POINTS_X // Probe along the Y axis, advancing X after each column - //#define PROBE_Y_FIRST + #define PROBE_Y_FIRST #if ENABLED(AUTO_BED_LEVELING_BILINEAR) // Beyond the probed grid, continue the implied tilt? // Default is to maintain the height of the nearest edge. - //#define EXTRAPOLATE_BEYOND_GRID + #define EXTRAPOLATE_BEYOND_GRID // // Experimental Subdivision of the grid by Catmull-Rom method. @@ -1315,11 +1330,11 @@ // - Move the Z probe (or nozzle) to a defined XY point before Z Homing when homing all axes (G28). // - Prevent Z homing when the Z probe is outside bed area. // -//#define Z_SAFE_HOMING +#define Z_SAFE_HOMING #if ENABLED(Z_SAFE_HOMING) - #define Z_SAFE_HOMING_X_POINT ((X_BED_SIZE) / 2) // X point for Z homing when homing all axes (G28). - #define Z_SAFE_HOMING_Y_POINT ((Y_BED_SIZE) / 2) // Y point for Z homing when homing all axes (G28). + #define Z_SAFE_HOMING_X_POINT (X_BED_SIZE / 2) // X point for Z homing when homing all axes (G28). + #define Z_SAFE_HOMING_Y_POINT (Y_BED_SIZE / 2) // Y point for Z homing when homing all axes (G28). #endif // Homing speeds (mm/m) @@ -1401,9 +1416,9 @@ * M501 - Read settings from EEPROM. (i.e., Throw away unsaved changes) * M502 - Revert settings to "factory" defaults. (Follow with M500 to init the EEPROM.) */ -//#define EEPROM_SETTINGS // Persistent storage with M500 and M501 +#define EEPROM_SETTINGS // Persistent storage with M500 and M501 //#define DISABLE_M503 // Saves ~2700 bytes of PROGMEM. Disable for release! -#define EEPROM_CHITCHAT // Give feedback on EEPROM commands. Disable to save PROGMEM. +// #define EEPROM_CHITCHAT // Give feedback on EEPROM commands. Disable to save PROGMEM. #if ENABLED(EEPROM_SETTINGS) //#define EEPROM_AUTO_INIT // Init EEPROM automatically on any errors. #endif @@ -1437,14 +1452,14 @@ // Preheat Constants #define PREHEAT_1_LABEL "PLA" -#define PREHEAT_1_TEMP_HOTEND 180 -#define PREHEAT_1_TEMP_BED 70 -#define PREHEAT_1_FAN_SPEED 0 // Value from 0 to 255 +#define PREHEAT_1_TEMP_HOTEND 200 +#define PREHEAT_1_TEMP_BED 60 +#define PREHEAT_1_FAN_SPEED 255 // Value from 0 to 255 #define PREHEAT_2_LABEL "ABS" #define PREHEAT_2_TEMP_HOTEND 240 -#define PREHEAT_2_TEMP_BED 110 -#define PREHEAT_2_FAN_SPEED 0 // Value from 0 to 255 +#define PREHEAT_2_TEMP_BED 70 +#define PREHEAT_2_FAN_SPEED 255 // Value from 0 to 255 /** * Nozzle Park @@ -1457,7 +1472,7 @@ * P1 Raise the nozzle always to Z-park height. * P2 Raise the nozzle by Z-park amount, limited to Z_MAX_POS. */ -//#define NOZZLE_PARK_FEATURE +#define NOZZLE_PARK_FEATURE #if ENABLED(NOZZLE_PARK_FEATURE) // Specify a park position as { X, Y, Z_raise } @@ -1618,7 +1633,8 @@ * you must uncomment the following option or it won't work. * */ -//#define SDSUPPORT +#define SDSUPPORT +#define SDIO_SUPPORT /** * SD CARD: SPI SPEED @@ -1652,13 +1668,13 @@ // This option overrides the default number of encoder pulses needed to // produce one step. Should be increased for high-resolution encoders. // -//#define ENCODER_PULSES_PER_STEP 4 +#define ENCODER_PULSES_PER_STEP 4 // // Use this option to override the number of step signals required to // move between next/prev menu items. // -//#define ENCODER_STEPS_PER_MENU_ITEM 1 +#define ENCODER_STEPS_PER_MENU_ITEM 1 /** * Encoder Direction Options @@ -1715,8 +1731,8 @@ // Note: Test audio output with the G-Code: // M300 S P // -//#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2 -//#define LCD_FEEDBACK_FREQUENCY_HZ 5000 +#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2 +#define LCD_FEEDBACK_FREQUENCY_HZ 5000 //============================================================================= //======================== LCD / Controller Selection ========================= @@ -1950,6 +1966,17 @@ // //#define CR10_STOCKDISPLAY +/* DWIN Rotary LCD */ +// #define DWIN_LCDDISPLAY + +/* DWIN Touch LCD */ +#define RTS_AVAILABLE + +#define EEPROM_PLR +#if ENABLED(EEPROM_PLR) + #define PLR_ADDR 100 +#endif + // // ANET and Tronxy Graphical Controller // @@ -2154,13 +2181,13 @@ #endif // Support for Adafruit Neopixel LED driver -//#define NEOPIXEL_LED +// #define NEOPIXEL_LED #if ENABLED(NEOPIXEL_LED) - #define NEOPIXEL_TYPE NEO_GRBW // NEO_GRBW / NEO_GRB - four/three channel driver type (defined in Adafruit_NeoPixel.h) - #define NEOPIXEL_PIN 4 // LED driving pin + #define NEOPIXEL_TYPE NEO_GRB // NEO_GRBW / NEO_GRB - four/three channel driver type (defined in Adafruit_NeoPixel.h) + #define NEOPIXEL_PIN PB2 // LED driving pin //#define NEOPIXEL2_TYPE NEOPIXEL_TYPE //#define NEOPIXEL2_PIN 5 - #define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip, larger of 2 strips if 2 neopixel strips are used + #define NEOPIXEL_PIXELS 4 // Number of LEDs in the strip, larger of 2 strips if 2 neopixel strips are used #define NEOPIXEL_IS_SEQUENTIAL // Sequential display for temperature change - LED by LED. Disable to change all LEDs at once. #define NEOPIXEL_BRIGHTNESS 127 // Initial brightness (0-255) //#define NEOPIXEL_STARTUP_TEST // Cycle through colors at startup diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 0717a3ac5489..70a9608e2cbd 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -137,7 +137,7 @@ * THERMAL_PROTECTION_HYSTERESIS and/or THERMAL_PROTECTION_PERIOD */ #if ENABLED(THERMAL_PROTECTION_HOTENDS) - #define THERMAL_PROTECTION_PERIOD 40 // Seconds + #define THERMAL_PROTECTION_PERIOD 60 // Seconds #define THERMAL_PROTECTION_HYSTERESIS 4 // Degrees Celsius //#define ADAPTIVE_FAN_SLOWING // Slow part cooling fan if temperature drops @@ -157,7 +157,7 @@ * and/or decrease WATCH_TEMP_INCREASE. WATCH_TEMP_INCREASE should not be set * below 2. */ - #define WATCH_TEMP_PERIOD 20 // Seconds + #define WATCH_TEMP_PERIOD 60 // Seconds #define WATCH_TEMP_INCREASE 2 // Degrees Celsius #endif @@ -165,13 +165,13 @@ * Thermal Protection parameters for the bed are just as above for hotends. */ #if ENABLED(THERMAL_PROTECTION_BED) - #define THERMAL_PROTECTION_BED_PERIOD 20 // Seconds + #define THERMAL_PROTECTION_BED_PERIOD 180 // Seconds #define THERMAL_PROTECTION_BED_HYSTERESIS 2 // Degrees Celsius /** * As described above, except for the bed (M140/M190/M303). */ - #define WATCH_BED_TEMP_PERIOD 60 // Seconds + #define WATCH_BED_TEMP_PERIOD 180 // Seconds #define WATCH_BED_TEMP_INCREASE 2 // Degrees Celsius #endif @@ -355,7 +355,7 @@ * * Define one or both of these to override the default 0-255 range. */ -//#define FAN_MIN_PWM 50 +#define FAN_MIN_PWM 50 //#define FAN_MAX_PWM 128 /** @@ -608,7 +608,7 @@ // Feature: Switch into SW mode after a deploy. It makes the output pulse longer. Can be useful // in special cases, like noisy or filtered input configurations. - //#define BLTOUCH_FORCE_SW_MODE + // #define BLTOUCH_FORCE_SW_MODE /** * Settings for BLTouch Smart 3.0 and 3.1 @@ -902,8 +902,9 @@ // Change values more rapidly when the encoder is rotated faster #define ENCODER_RATE_MULTIPLIER #if ENABLED(ENCODER_RATE_MULTIPLIER) - #define ENCODER_10X_STEPS_PER_SEC 30 // (steps/s) Encoder rate for 10x speed - #define ENCODER_100X_STEPS_PER_SEC 80 // (steps/s) Encoder rate for 100x speed + #define ENCODER_5X_STEPS_PER_SEC 30 + #define ENCODER_10X_STEPS_PER_SEC 80 // (steps/s) Encoder rate for 10x speed + #define ENCODER_100X_STEPS_PER_SEC 130 // (steps/s) Encoder rate for 100x speed #endif // Play a beep when the feedrate is changed from the Status Screen @@ -998,7 +999,7 @@ //#define MENU_ADDAUTOSTART // Add a menu option to run auto#.g files - #define EVENT_GCODE_SD_STOP "G28XY" // G-code to run on Stop Print (e.g., "G28XY" or "G27") + #define EVENT_GCODE_SD_STOP "G28XY\nM84" // G-code to run on Stop Print (e.g., "G28XY" or "G27") /** * Continue after Power-Loss (Creality3D) @@ -1008,7 +1009,7 @@ * an option on the LCD screen to continue the print from the last-known * point in the file. */ - //#define POWER_LOSS_RECOVERY + #define POWER_LOSS_RECOVERY #if ENABLED(POWER_LOSS_RECOVERY) //#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power loss //#define POWER_LOSS_ZRAISE 2 // (mm) Z axis raise on resume (on power loss with UPS) @@ -1366,12 +1367,12 @@ * * Warning: Does not respect endstops! */ -//#define BABYSTEPPING +#define BABYSTEPPING #if ENABLED(BABYSTEPPING) //#define BABYSTEP_WITHOUT_HOMING //#define BABYSTEP_XY // Also enable X/Y Babystepping. Not supported on DELTA! #define BABYSTEP_INVERT_Z false // Change if Z babysteps should go the other way - #define BABYSTEP_MULTIPLICATOR_Z 1 // Babysteps are very small. Increase for faster motion. + #define BABYSTEP_MULTIPLICATOR_Z 40 // Babysteps are very small. Increase for faster motion. #define BABYSTEP_MULTIPLICATOR_XY 1 //#define DOUBLECLICK_FOR_Z_BABYSTEPPING // Double-click on the Status Screen for Z Babystepping. @@ -1387,7 +1388,9 @@ //#define BABYSTEP_DISPLAY_TOTAL // Display total babysteps since last G28 - //#define BABYSTEP_ZPROBE_OFFSET // Combine M851 Z and Babystepping + #if HAS_BED_PROBE + #define BABYSTEP_ZPROBE_OFFSET // Combine M851 Z and Babystepping + #endif #if ENABLED(BABYSTEP_ZPROBE_OFFSET) //#define BABYSTEP_HOTEND_Z_OFFSET // For multiple hotends, babystep relative Z offsets //#define BABYSTEP_ZPROBE_GFX_OVERLAY // Enable graphical overlay on Z-offset editor @@ -1488,7 +1491,7 @@ // // G2/G3 Arc Support // -#define ARC_SUPPORT // Disable this feature to save ~3226 bytes +// #define ARC_SUPPORT // Disable this feature to save ~3226 bytes #if ENABLED(ARC_SUPPORT) #define MM_PER_ARC_SEGMENT 1 // Length of each arc segment #define MIN_ARC_SEGMENTS 24 // Minimum number of segments in a complete circle @@ -1529,8 +1532,8 @@ * * Override the default value based on the driver type set in Configuration.h. */ -//#define MINIMUM_STEPPER_POST_DIR_DELAY 650 -//#define MINIMUM_STEPPER_PRE_DIR_DELAY 650 +// #define MINIMUM_STEPPER_POST_DIR_DELAY 30 +// #define MINIMUM_STEPPER_PRE_DIR_DELAY 30 /** * Minimum stepper driver pulse width (in µs) diff --git a/Marlin/Version.h b/Marlin/Version.h index d18176f27f74..a53ad9d42cc3 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -25,16 +25,20 @@ // VENDOR VERSION EXAMPLE // //////////////////////////// +#define MACHINE_SIZE "235x235x250" +#define CORP_WEBSITE_C "www.cxsw3d.com" +#define CORP_WEBSITE_E "www.creality.com" + /** * Marlin release version identifier */ -//#define SHORT_BUILD_VERSION "bugfix-2.0.x" +#define SHORT_BUILD_VERSION "Ver 1.0.3.6" /** * Verbose version identifier which should contain a reference to the location * from where the binary was downloaded or the source code was compiled. */ -//#define DETAILED_BUILD_VERSION SHORT_BUILD_VERSION " (Github)" +#define DETAILED_BUILD_VERSION "Creality 3D" /** * The STRING_DISTRIBUTION_DATE represents when the binary file was built, @@ -46,7 +50,7 @@ /** * Defines a generic printer name to be output to the LCD after booting Marlin. */ -//#define MACHINE_NAME "3D Printer" +#define MACHINE_NAME "CR-6 SE" /** * The SOURCE_CODE_URL is the location where users will find the Marlin Source @@ -54,18 +58,18 @@ * has a distinct Github fork— the Source Code URL should just be the main * Marlin repository. */ -//#define SOURCE_CODE_URL "https://github.com/MarlinFirmware/Marlin" +#define SOURCE_CODE_URL "https://github.com/MarlinFirmware/Marlin" /** * Default generic printer UUID. */ -//#define DEFAULT_MACHINE_UUID "cede2a2f-41a2-4748-9b12-c55c62f367ff" +#define DEFAULT_MACHINE_UUID "cede2a2f-41a2-4748-9b12-c55c62f367ff" /** * The WEBSITE_URL is the location where users can get more information such as * documentation about a specific Marlin release. */ -//#define WEBSITE_URL "http://marlinfw.org" +#define WEBSITE_URL "www.creality.com" /** * Set the vendor info the serial USB interface, if changable diff --git a/Marlin/src/HAL/HAL_STM32F1/sdio.h b/Marlin/src/HAL/HAL_STM32F1/sdio.h index ca0aced69581..886cbfa94b79 100644 --- a/Marlin/src/HAL/HAL_STM32F1/sdio.h +++ b/Marlin/src/HAL/HAL_STM32F1/sdio.h @@ -100,7 +100,7 @@ #define SDIO_DATA_TIMEOUT 100U /* Read data transfer timeout */ #define SDIO_WRITE_TIMEOUT 200U /* Write data transfer timeout */ -#define SDIO_CLOCK 18000000 /* 18 MHz */ +#define SDIO_CLOCK 6000000 /* 18 MHz */ // ------------------------ // Types diff --git a/Marlin/src/HAL/HAL_STM32F1/timers.h b/Marlin/src/HAL/HAL_STM32F1/timers.h index d5d02a3dc65c..eaac343265b4 100644 --- a/Marlin/src/HAL/HAL_STM32F1/timers.h +++ b/Marlin/src/HAL/HAL_STM32F1/timers.h @@ -45,7 +45,7 @@ typedef uint16_t hal_timer_t; #define HAL_TIMER_RATE uint32_t(F_CPU) // frequency of timers peripherals #define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts -#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts +#define TEMP_TIMER_CHAN 4 // Channel of the timer to use for compare and interrupts /** * Note: Timers may be used by platforms and libraries diff --git a/Marlin/src/HAL/HAL_STM32F1/watchdog.cpp b/Marlin/src/HAL/HAL_STM32F1/watchdog.cpp index 17f5aa9725b7..e2435d2ec3c0 100644 --- a/Marlin/src/HAL/HAL_STM32F1/watchdog.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/watchdog.cpp @@ -52,7 +52,7 @@ void watchdogSetup() { * @details The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and 625 reload value (counts down to 0) */ void watchdog_init() { - //iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD); + iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD); } #endif // USE_WATCHDOG diff --git a/Marlin/src/HAL/HAL_STM32F1/watchdog.h b/Marlin/src/HAL/HAL_STM32F1/watchdog.h index 21f97dd7a159..2ffeab5b6ad1 100644 --- a/Marlin/src/HAL/HAL_STM32F1/watchdog.h +++ b/Marlin/src/HAL/HAL_STM32F1/watchdog.h @@ -32,7 +32,7 @@ * 625 reload value (counts down to 0) * use 1250 for 8 seconds */ -#define STM32F1_WD_RELOAD 625 +#define STM32F1_WD_RELOAD 1250 // Arduino STM32F1 core now has watchdog support diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 2198672ff875..d18059228cdc 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -30,6 +30,17 @@ #include "Marlin.h" +#ifdef DWIN_LCDDISPLAY + // DWIN file + #include "lcd/dwin/dwin.h" + #include "lcd/dwin/dwin_lcd.h" + #include "lcd/dwin/rotary_encoder.h" + #include "lcd/dwin/i2c_eeprom.h" +#elif ENABLED(RTS_AVAILABLE) + #include "lcd/dwin/LCD_RTS.h" + #include "lcd/dwin/i2c_eeprom.h" +#endif + #include "core/utility.h" #include "lcd/ultralcd.h" #include "module/motion.h" @@ -442,7 +453,15 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) { if (max_inactive_time && ELAPSED(ms, gcode.previous_move_ms + max_inactive_time)) { SERIAL_ERROR_START(); SERIAL_ECHOLNPAIR(MSG_KILL_INACTIVE_TIME, parser.command_ptr); - kill(); + #ifdef RTS_AVAILABLE + waitway = 0; + rtscheck.RTS_SndData(ExchangePageBase + 62, ExchangepageAddr); + change_page_font = 62; + rtscheck.RTS_SndData(Error_201, ABNORMAL_TEXT_VP); + errorway = 1; + #else + kill(); + #endif } // Prevent steppers timing-out in the middle of M600 @@ -455,7 +474,9 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) { if (stepper_inactive_time) { static bool already_shutdown_steppers; // = false if (planner.has_blocks_queued()) + { gcode.reset_stepper_timeout(); + } else if (MOVE_AWAY_TEST && !ignore_stepper_queue && ELAPSED(ms, gcode.previous_move_ms + stepper_inactive_time)) { if (!already_shutdown_steppers) { already_shutdown_steppers = true; // L6470 SPI will consume 99% of free time without this @@ -653,7 +674,30 @@ void idle( max7219.idle_tasks(); #endif - ui.update(); + #ifdef DWIN_LCDDISPLAY + DWIN_Update(); + #elif ENABLED(RTS_AVAILABLE) + RTSUpdate(); + #else + ui.update(); + #endif + #if ENABLED(FIX_MOUNTED_PROBE) + if((IS_SD_PRINTING() == true) && home_flag == false) // printing and no homing + { + endstops.enable_z_probe(false); + } + #endif + + #if ENABLED(FIX_MOUNTED_PROBE) + if((0 == READ(OPTO_SWITCH_PIN)) && (home_flag == true)) + { + endstops.enable_z_probe(true); + delay(100); + WRITE(COM_PIN, 0); + delay(200); + WRITE(COM_PIN, 1); + } + #endif #if ENABLED(HOST_KEEPALIVE_FEATURE) gcode.host_keepalive(); @@ -932,9 +976,17 @@ void setup() { leds.setup(); #endif - ui.init(); - #if HAS_SPI_LCD && ENABLED(SHOW_BOOTSCREEN) - ui.show_bootscreen(); + #ifdef DWIN_LCDDISPLAY + delay(800); // wait stabillze dalay + if(DWIN_ShakeHand()) SERIAL_ECHOLN("\r\nDwin shake hand ok."); + else SERIAL_ECHOLN("\r\nDwin shake hand error."); + DWIN_Frame_SetDir(1); + DWIN_UpdateLCD(); // show bootscreen ( first picture ) + #else + ui.init(); + #if HAS_SPI_LCD && ENABLED(SHOW_BOOTSCREEN) + ui.show_bootscreen(); + #endif #endif #if ENABLED(SDSUPPORT) @@ -961,7 +1013,7 @@ void setup() { print_job_timer.init(); // Initial setup of print job timer - ui.reset_status(); // Print startup message after print statistics are loaded + // ui.reset_status(); // Print startup message after print statistics are loaded endstops.init(); // Init endstops and pullups @@ -1086,10 +1138,6 @@ void setup() { est_init(); #endif - #if ENABLED(POWER_LOSS_RECOVERY) - recovery.check(); - #endif - #if ENABLED(USE_WATCHDOG) watchdog_init(); // Reinit watchdog after HAL_get_reset_source call #endif @@ -1117,6 +1165,41 @@ void setup() { #if ENABLED(PRUSA_MMU2) mmu2.init(); #endif + + #if HAS_COLOR_LEDS + leds.set_color(LEDColorWhite()); + #endif + + #ifdef MYI2C_EEPROM + BL24CXX_Init(); + if(BL24CXX_Check()) // no found I2C_EEPROM + SERIAL_ECHOLN("I2C_EEPROM Check Failed!"); + else + SERIAL_ECHOLN("I2C_EEPROM Check Successed!"); + #endif + + #if ENABLED(POWER_LOSS_RECOVERY) + recovery.check(); + #endif + + #ifdef DWIN_LCDDISPLAY + + // dwin init + Encoder_Configuration(); + HMI_Init(); + HMI_StartFrame(); + + #elif ENABLED(RTS_AVAILABLE) + + rtscheck.RTS_Init(); + #ifdef FIX_MOUNTED_PROBE + OUT_WRITE(COM_PIN, 1); + SET_INPUT(CHECK_MATWEIAL); + SET_INPUT(OPTO_SWITCH_PIN); + OUT_WRITE(LED_CONTROL_PIN, 0); + #endif + + #endif } /** diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h index 1b29c001e299..a921859e7910 100644 --- a/Marlin/src/core/boards.h +++ b/Marlin/src/core/boards.h @@ -278,6 +278,7 @@ #define BOARD_FYSETC_CHEETAH 4016 // FYSETC Cheetah #define BOARD_FYSETC_CHEETAH_V12 4017 // FYSETC Cheetah V1.2 #define BOARD_LONGER3D_LK 4018 // Alfawise U20/U20+/U30 (Longer3D LK1/2) / STM32F103VET6 +#define BOARD_CREALITY 4019 // Creality (STM32F103RE) // // ARM Cortex-M4F diff --git a/Marlin/src/core/serial.h b/Marlin/src/core/serial.h index 0db7bb9e4e38..b57a187b076a 100644 --- a/Marlin/src/core/serial.h +++ b/Marlin/src/core/serial.h @@ -53,7 +53,7 @@ extern uint8_t marlin_debug_flags; #define _PORT_RESTORE(n) RESTORE(n) #define SERIAL_OUT(WHAT, V...) do{ \ if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(V); \ - if ( serial_port_index) (void)MYSERIAL1.WHAT(V); \ + if ( serial_port_index) (void)MYSERIAL0.WHAT(V); \ }while(0) #define SERIAL_ASSERT(P) if(serial_port_index!=(P)){ debugger(); } #else diff --git a/Marlin/src/feature/bedlevel/abl/abl.h b/Marlin/src/feature/bedlevel/abl/abl.h index 15e988fe0a76..bac1fbae9069 100644 --- a/Marlin/src/feature/bedlevel/abl/abl.h +++ b/Marlin/src/feature/bedlevel/abl/abl.h @@ -22,6 +22,7 @@ #pragma once #include "../../../inc/MarlinConfigPre.h" +#include "../../../feature/bedlevel/bedlevel.h" extern xy_pos_t bilinear_grid_spacing, bilinear_start; extern xy_float_t bilinear_grid_factor; diff --git a/Marlin/src/feature/leds/neopixel.h b/Marlin/src/feature/leds/neopixel.h index e0a3d7c389d7..554a43515451 100644 --- a/Marlin/src/feature/leds/neopixel.h +++ b/Marlin/src/feature/leds/neopixel.h @@ -31,7 +31,9 @@ #include "../../inc/MarlinConfig.h" +// #include "../../libs/Adafruit_NeoPixel.h" #include + #include // ------------------------ diff --git a/Marlin/src/feature/power_loss_recovery.cpp b/Marlin/src/feature/power_loss_recovery.cpp index 0cf0fc5885f4..6200c4fc3628 100644 --- a/Marlin/src/feature/power_loss_recovery.cpp +++ b/Marlin/src/feature/power_loss_recovery.cpp @@ -50,6 +50,9 @@ uint32_t PrintJobRecovery::cmd_sdpos, // = 0 #include "../module/temperature.h" #include "../core/serial.h" +#include "../lcd/dwin/LCD_RTS.h" +#include "../lcd/dwin/i2c_eeprom.h" + #if ENABLED(FWRETRACT) #include "fwretract.h" #endif @@ -103,9 +106,14 @@ void PrintJobRecovery::check() { if (enabled) { if (!card.isMounted()) card.mount(); if (card.isMounted()) { - load(); - if (!valid()) return purge(); - queue.inject_P(PSTR("M1000 S")); + #ifdef EEPROM_PLR + delay(20); + BL24CXX_Read(PLR_ADDR, (uint8_t*)&info, sizeof(info)); + #else + load(); + if (!valid()) return purge(); + queue.inject_P(PSTR("M1000 S")); + #endif } } } @@ -233,7 +241,13 @@ void PrintJobRecovery::save(const bool force/*=false*/, const bool save_queue/*= // Elapsed print job time info.print_job_elapsed = print_job_timer.duration(); - write(); + info.recovery_flag = true; + + #ifdef EEPROM_PLR + BL24CXX_Write(PLR_ADDR, (uint8_t*)&info, sizeof(info)); + #else + write(); + #endif } } @@ -294,38 +308,6 @@ void PrintJobRecovery::resume() { gcode.process_subcommands_now_P(PSTR("M420 S0 Z0")); #endif - // Reset E, raise Z, home XY... - gcode.process_subcommands_now_P(PSTR("G92.9 E0" - #if Z_HOME_DIR > 0 - - // If Z homing goes to max, just reset E and home all - "\n" - "G28R0" - #if ENABLED(MARLIN_DEV_MODE) - "S" - #endif - - #else // "G92.9 E0 ..." - - // Set Z to 0, raise Z by RECOVERY_ZRAISE, and Home (XY only for Cartesian) - // with no raise. (Only do simulated homing in Marlin Dev Mode.) - #if ENABLED(BACKUP_POWER_SUPPLY) - "Z" STRINGIFY(POWER_LOSS_ZRAISE) // Z-axis was already raised at outage - #else - "Z0\n" // Set Z=0 - "G1Z" STRINGIFY(POWER_LOSS_ZRAISE) // Raise Z - #endif - "\n" - - "G28R0" - #if ENABLED(MARLIN_DEV_MODE) - "S" - #elif !IS_KINEMATIC - "XY" - #endif - #endif - )); - // Pretend that all axes are homed axis_homed = axis_known_position = xyz_bits; @@ -391,6 +373,41 @@ void PrintJobRecovery::resume() { } } + gcode.process_subcommands_now_P(PSTR("G92.9 E0 Z0")); + gcode.process_subcommands_now_P(PSTR("G28 XY")); + + // Reset E, raise Z, home XY... + // gcode.process_subcommands_now_P(PSTR("G92.9 E0" + // #if Z_HOME_DIR > 0 + + // // If Z homing goes to max, just reset E and home all + // "\n" + // "G28R0" + // #if ENABLED(MARLIN_DEV_MODE) + // "S" + // #endif + + // #else // "G92.9 E0 ..." + + // // Set Z to 0, raise Z by RECOVERY_ZRAISE, and Home (XY only for Cartesian) + // // with no raise. (Only do simulated homing in Marlin Dev Mode.) + // #if ENABLED(BACKUP_POWER_SUPPLY) + // "Z" STRINGIFY(POWER_LOSS_ZRAISE) // Z-axis was already raised at outage + // #else + // "Z0\n" // Set Z=0 + // "G1Z" STRINGIFY(POWER_LOSS_ZRAISE) // Raise Z + // #endif + // "\n" + + // "G28R0" + // #if ENABLED(MARLIN_DEV_MODE) + // "S" + // #elif !IS_KINEMATIC + // "XY" + // #endif + // #endif + // )); + // Restore retract and hop state #if ENABLED(FWRETRACT) for (uint8_t e = 0; e < EXTRUDERS; e++) { @@ -444,6 +461,7 @@ void PrintJobRecovery::resume() { #endif gcode.process_subcommands_now(cmd); + // Un-retract #if POWER_LOSS_PURGE_LEN //sprintf_P(cmd, PSTR("G1 E%d F3000"), POWER_LOSS_PURGE_LEN); diff --git a/Marlin/src/feature/power_loss_recovery.h b/Marlin/src/feature/power_loss_recovery.h index 771fce44dfd9..a83cf6294e13 100644 --- a/Marlin/src/feature/power_loss_recovery.h +++ b/Marlin/src/feature/power_loss_recovery.h @@ -28,6 +28,8 @@ #include "../sd/cardreader.h" #include "../inc/MarlinConfig.h" +#if ENABLED(POWER_LOSS_RECOVERY) + #if ENABLED(MIXING_EXTRUDER) #include "../feature/mixing.h" #endif @@ -101,6 +103,9 @@ typedef struct { // Relative axis modes uint8_t axis_relative; + // recovery flag + uint8_t recovery_flag; + // SD Filename and position char sd_filename[MAXPATHNAMELENGTH]; volatile uint32_t sdpos; @@ -194,3 +199,5 @@ class PrintJobRecovery { }; extern PrintJobRecovery recovery; + +#endif diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 41e5fce4d29d..7427a8278df7 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -34,10 +34,16 @@ #include "../../../module/planner.h" #include "../../../module/stepper.h" #include "../../../module/probe.h" +#include "../../../module/configuration_store.h" +#include "../../../module/temperature.h" #include "../../queue.h" -#if HAS_DISPLAY - #include "../../../lcd/ultralcd.h" +#include "../../../lcd/ultralcd.h" +#ifdef DWIN_LCDDISPLAY + #include "../../../lcd/dwin/dwin.h" +#endif +#ifdef RTS_AVAILABLE + #include "../../../lcd/dwin/LCD_RTS.h" #endif #if ENABLED(AUTO_BED_LEVELING_LINEAR) @@ -453,6 +459,8 @@ G29_TYPE GcodeSuite::G29() { } #endif + do_blocking_move_to_z(_MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE)); + if (!faux) remember_feedrate_scaling_off(); #if ENABLED(AUTO_BED_LEVELING_BILINEAR) @@ -659,7 +667,10 @@ G29_TYPE GcodeSuite::G29() { #if ABL_GRID - bool zig = PR_OUTER_END & 1; // Always end at RIGHT and BACK_PROBE_BED_POSITION + // bool zig = PR_OUTER_END & 1; // Always end at RIGHT and BACK_PROBE_BED_POSITION + bool zig = 1; + + uint8_t showcount = 0; measured_z = 0; @@ -731,6 +742,30 @@ G29_TYPE GcodeSuite::G29() { ExtUI::onMeshUpdate(meshCount, z_values[meshCount.x][meshCount.y]); #endif + #ifdef RTS_AVAILABLE + if((showcount++) < GRID_MAX_POINTS) + { + rtscheck.RTS_SndData(showcount, AUTO_BED_LEVEL_TITLE_VP); + if(language_change_font != 0) + { + rtscheck.RTS_SndData(ExchangePageBase + 26, ExchangepageAddr); + change_page_font = 26; + } + else + { + rtscheck.RTS_SndData(ExchangePageBase + 53, ExchangepageAddr); + change_page_font = 53; + } + rtscheck.RTS_SndData(AUTO_BED_LEVEL_PREHEAT, AUTO_BED_PREHEAT_HEAD_DATA_VP); + rtscheck.RTS_SndData(AUTO_BED_LEVEL_PREHEAT, HEAD_SET_TEMP_VP); + rtscheck.RTS_SndData(probe_offset.z * 100, AUTO_BED_LEVEL_ZOFFSET_VP); + + rtscheck.RTS_SndData(feedrate_percentage, PRINT_SPEED_RATE_VP); + rtscheck.RTS_SndData(thermalManager.temp_hotend[0].target, HEAD_SET_TEMP_VP); + rtscheck.RTS_SndData(thermalManager.temp_bed.target, BED_SET_TEMP_VP); + } + #endif + #endif abl_should_enable = false; @@ -808,6 +843,14 @@ G29_TYPE GcodeSuite::G29() { if (!dryrun) extrapolate_unprobed_bed_level(); print_bilinear_leveling_grid(); + #ifdef RTS_AVAILABLE + if(3 == waitway) + { + waitway = 0; + } + #endif + + settings.save(); refresh_bed_level(); #if ENABLED(ABL_BILINEAR_SUBDIVISION) @@ -960,8 +1003,16 @@ G29_TYPE GcodeSuite::G29() { process_subcommands_now_P(PSTR(Z_PROBE_END_SCRIPT)); #endif + #ifdef DWIN_LCDDISPLAY + + if(checkkey == Leveing) Goto_ProcessFrame(); + + #endif + report_current_position(); + do_blocking_move_to_xy(safe_homing_xy); + G29_RETURN(isnan(measured_z)); } diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index b7af871b11a6..fce48f4060ad 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -26,6 +26,9 @@ #include "../../module/stepper.h" #include "../../module/endstops.h" +#include "../../module/printcounter.h" +#include "../../sd/cardreader.h" +#include "../../feature/power_loss_recovery.h" #if HOTENDS > 1 #include "../../module/tool_change.h" @@ -46,6 +49,11 @@ #endif #include "../../lcd/ultralcd.h" +#ifdef DWIN_LCDDISPLAY + #include "../../lcd/dwin/dwin.h" +#elif ENABLED(RTS_AVAILABLE) + #include "../../lcd/dwin/LCD_RTS.h" +#endif #if HAS_DRIVER(L6470) // set L6470 absolute position registers to counts #include "../../libs/L6470/L6470_Marlin.h" @@ -214,6 +222,24 @@ void GcodeSuite::G28(const bool always_home_all) { log_machine_info(); } + home_flag = true; + + if(waitway == 4 || waitway == 6 || waitway == 7) + { + if(language_change_font != 0) + { + // exchange to 60 page + rtscheck.RTS_SndData(ExchangePageBase + 60, ExchangepageAddr); + change_page_font = 60; + } + else + { + // exchange to 61 page + rtscheck.RTS_SndData(ExchangePageBase + 61, ExchangepageAddr); + change_page_font = 61; + } + } + #if ENABLED(DUAL_X_CARRIAGE) bool IDEX_saved_duplication_state = extruder_duplication_enabled; DualXMode IDEX_saved_mode = dual_x_carriage_mode; @@ -338,15 +364,17 @@ void GcodeSuite::G28(const bool always_home_all) { #if ENABLED(UNKNOWN_Z_NO_RAISE) !TEST(axis_known_position, Z_AXIS) ? 0 : #endif - (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT) + (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT) ); - if (z_homing_height && (doX || doY)) { - // Raise Z before homing any other axes and z is not already high enough (never lower z) - destination.z = z_homing_height + (TEST(axis_known_position, Z_AXIS) ? 0.0f : current_position.z); - if (destination.z > current_position.z) { - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Raise Z (before homing) to ", destination.z); - do_blocking_move_to_z(destination.z); + if(finish_home == false && waitway != 7) + { + if (z_homing_height && (doX || doY)) { + destination.z = z_homing_height + (TEST(axis_known_position, Z_AXIS) ? 0.0f : current_position.z); + if (destination.z > current_position.z) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Raise Z (before homing) to ", destination.z); + do_blocking_move_to_z(destination.z); + } } } @@ -522,6 +550,84 @@ void GcodeSuite::G28(const bool always_home_all) { ui.refresh(); + #ifdef RTS_AVAILABLE + if(change_page_font != 62) + { + if(waitway == 6) + { + if(language_change_font != 0) + { + do_blocking_move_to_z(0); + rtscheck.RTS_SndData(ExchangePageBase + 25, ExchangepageAddr); + change_page_font = 25; + } + else + { + do_blocking_move_to_z(0); + rtscheck.RTS_SndData(ExchangePageBase + 52, ExchangepageAddr); + change_page_font = 52; + } + waitway = 0; + } + else if(waitway == 4) + { + if(language_change_font != 0) + { + do_blocking_move_to_z(0); + rtscheck.RTS_SndData(ExchangePageBase + 15 + AxisUnitMode, ExchangepageAddr); + change_page_font = 15; + } + else + { + do_blocking_move_to_z(0); + rtscheck.RTS_SndData(ExchangePageBase + 42 + AxisUnitMode, ExchangepageAddr); + change_page_font = 42; + } + waitway = 0; + } + else if(waitway == 7) + { + if(language_change_font != 0) + { + // exchange to 1 page + rtscheck.RTS_SndData(ExchangePageBase + 1, ExchangepageAddr); + change_page_font = 1; + } + else + { + // exchange to 24 page + rtscheck.RTS_SndData(ExchangePageBase + 28, ExchangepageAddr); + change_page_font = 28; + } + rtscheck.RTS_SndData(2, MOTOR_FREE_ICON_VP); + rtscheck.RTS_SndData(0, PRINT_PROCESS_TITLE_VP); + rtscheck.RTS_SndData(0, PRINT_PROCESS_VP); + delay(2); + for(int j = 0;j < 10;j ++) + { + // clean screen. + rtscheck.RTS_SndData(0, CONTINUE_PRINT_FILE_TEXT_VP + j); + } + waitway = 0; + } + rtscheck.RTS_SndData(10*current_position[X_AXIS], AXIS_X_COORD_VP); + rtscheck.RTS_SndData(10*current_position[Y_AXIS], AXIS_Y_COORD_VP); + rtscheck.RTS_SndData(10*current_position[Z_AXIS], AXIS_Z_COORD_VP); + + if(finish_home) finish_home = false; + + if(StartPrint_flag) + { + StartPrint_flag = 0; + recovery.info.current_position.z = 0; + } + errorway = errornum = 0; + } + #endif + + home_flag = false; + endstops.enable_z_probe(false); + report_current_position(); #if ENABLED(NANODLP_Z_SYNC) @@ -543,4 +649,5 @@ void GcodeSuite::G28(const bool always_home_all) { L6470.set_param(cv, L6470_ABS_POS, stepper.position((AxisEnum)L6470.axis_xref[cv])); } #endif + } diff --git a/Marlin/src/gcode/eeprom/M500-M504.cpp b/Marlin/src/gcode/eeprom/M500-M504.cpp index 79bacf06623d..bdfdeb778888 100644 --- a/Marlin/src/gcode/eeprom/M500-M504.cpp +++ b/Marlin/src/gcode/eeprom/M500-M504.cpp @@ -24,6 +24,7 @@ #include "../../module/configuration_store.h" #include "../../core/serial.h" #include "../../inc/MarlinConfig.h" +#include "../../lcd/dwin/LCD_RTS.h" /** * M500: Store settings in EEPROM diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 92928cf8b335..84ddedd56cc9 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -31,6 +31,7 @@ GcodeSuite gcode; #include "parser.h" #include "queue.h" #include "../module/motion.h" +#include "../feature/bedlevel/bedlevel.h" #if ENABLED(PRINTCOUNTER) #include "../module/printcounter.h" @@ -269,7 +270,12 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 27: G27(); break; // G27: Nozzle Park #endif - case 28: G28(false); break; // G28: Home all axes, one at a time + case 28: + G28(false); + #if HAS_LEVELING + set_bed_leveling_enabled(true); + #endif + break; // G28: Home all axes, one at a time #if HAS_LEVELING case 29: // G29: Bed leveling calibration diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index a9bd714c1e38..83958142314e 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -29,6 +29,9 @@ GCodeQueue queue; #include "gcode.h" +#ifdef RTS_AVAILABLE + #include "../lcd/dwin/LCD_RTS.h" +#endif #include "../lcd/ultralcd.h" #include "../sd/cardreader.h" #include "../module/planner.h" @@ -528,6 +531,8 @@ void GCodeQueue::get_serial_commands() { card.printingHasFinished(); + print_finish = 1; + if (IS_SD_PRINTING()) sd_count = 0; // If a sub-file was printing, continue from call point else { @@ -545,6 +550,22 @@ void GCodeQueue::get_serial_commands() { #endif #endif // PRINTER_EVENT_LEDS } + + #ifdef RTS_AVAILABLE + rtscheck.RTS_SndData(100, PRINT_PROCESS_VP); + delay(1); + rtscheck.RTS_SndData(100 ,PRINT_PROCESS_TITLE_VP); + if(language_change_font != 0) + { + rtscheck.RTS_SndData(ExchangePageBase + 9, ExchangepageAddr); + change_page_font = 9; + } + else + { + rtscheck.RTS_SndData(ExchangePageBase + 36, ExchangepageAddr); + change_page_font = 36; + } + #endif } else if (n == -1) SERIAL_ERROR_MSG(MSG_SD_ERR_READ); diff --git a/Marlin/src/gcode/sdcard/M24_M25.cpp b/Marlin/src/gcode/sdcard/M24_M25.cpp index d1a9c2f23f29..e26c223abf49 100644 --- a/Marlin/src/gcode/sdcard/M24_M25.cpp +++ b/Marlin/src/gcode/sdcard/M24_M25.cpp @@ -27,6 +27,7 @@ #include "../gcode.h" #include "../../sd/cardreader.h" #include "../../module/printcounter.h" +#include "../../gcode/queue.h" #include "../../lcd/ultralcd.h" #if ENABLED(PARK_HEAD_ON_PAUSE) @@ -98,7 +99,6 @@ void GcodeSuite::M25() { #else print_job_timer.pause(); - ui.reset_status(); #if ENABLED(HOST_ACTION_COMMANDS) #if ENABLED(HOST_PROMPT_SUPPORT) @@ -110,6 +110,7 @@ void GcodeSuite::M25() { #endif #endif + } #endif // SDSUPPORT diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 13ae3511cd7a..0bd083be545b 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1667,7 +1667,7 @@ #if ENABLED(SCROLL_LONG_FILENAMES) #define MAX_VFAT_ENTRIES (5) #else - #define MAX_VFAT_ENTRIES (2) + #define MAX_VFAT_ENTRIES (5) #endif // Set defaults for unspecified LED user colors diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index f94fbffc421d..ad3115ad60a2 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -25,7 +25,7 @@ * Release version. Leave the Marlin version or apply a custom scheme. */ #ifndef SHORT_BUILD_VERSION - #define SHORT_BUILD_VERSION "bugfix-2.0.x" + #define SHORT_BUILD_VERSION "2.0.x" #endif /** @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2019-11-30" + #define STRING_DISTRIBUTION_DATE "2019-12-01" #endif /** diff --git a/Marlin/src/lcd/dwin/LCD_RTS.cpp b/Marlin/src/lcd/dwin/LCD_RTS.cpp new file mode 100644 index 000000000000..a03b6947919b --- /dev/null +++ b/Marlin/src/lcd/dwin/LCD_RTS.cpp @@ -0,0 +1,1992 @@ +#include "LCD_RTS.h" +#include +#include +#include +#include +#include "../../inc/MarlinConfig.h" +#include "../../../Version.h" + +#include "../../Marlin.h" +#include "../../sd/cardreader.h" +#include "../../module/temperature.h" +#include "../../module/planner.h" +#include "../../module/stepper.h" +#include "../../module/configuration_store.h" +#include "../../module/printcounter.h" +#include "../../feature/babystep.h" +#include "../../feature/power_loss_recovery.h" +#include "../../gcode/gcode.h" + +#include "../../feature/bedlevel/abl/abl.h" + +#include "../../libs/duration_t.h" + +#if ENABLED(BLTOUCH) + #include "endstops.h" +#endif + +#define CHECKFILEMENT true + +char errorway = 0; +char errornum = 0; + +bool StartPrint_flag = 0; + +float last_zoffset = 0.0; + +int power_off_type_yes = 0; + +const float manual_feedrate_mm_m[] = { 50*60, 50*60, 4*60, 60 }; + +HMI_ValueTypeDef HMI_ValueStruct; + +bool heat_flag = 0; + +int startprogress = 0; +CRec CardRecbuf; +int temphot = 0; +int tempbed = 0; +int PLAhead = 0; +int PLAbed = 0; +int PLAfan = 0; +int ABShead = 0; +int ABSbed = 0; +int ABSfan = 0; +float pause_z = 0; +float pause_e = 0; +bool sdcard_pause_check = true; +bool pause_action_flag = false; +bool probe_offset_flag = false; + +millis_t next_rts_update_ms = 0; +int last_target_temperature[4] = {0}; +int last_target_temperature_bed; +char waitway = 0; +int change_page_font = 0; +int recnum = 0; +unsigned char Percentrecord = 0; +float FilamentLOAD = 0; + +// 1 represent 10mm, 2 represent 1mm, 3 represent 0.1mm +unsigned char AxisUnitMode; +float axis_unit = 10.0; + +// represents to update file list +bool CardUpdate = false; +extern CardReader card; +unsigned int language_change_font = 0; +// represents SD-card status, true means SD is available, false means opposite. +bool lcd_sd_status; + +char Checkfilenum = 0; +char checkpause = 0; +char FilenamesCount = 0; + +bool LEDStatus = true; +RTSSHOW rtscheck; +int Update_Time_Value = 0; +unsigned long VolumeSet = 0x80; + +bool print_finish = false; +bool finish_home = false; + +bool home_flag = false; +bool AutohomeZflag = false; +char cmdbuf[20] = {0}; + +unsigned short int checktime = 0; + +inline void RTS_line_to_current(AxisEnum axis) +{ + if (!planner.is_full()) + { + planner.buffer_line(current_position, MMM_TO_MMS(manual_feedrate_mm_m[(int8_t)axis]), active_extruder); + } +} + +RTSSHOW::RTSSHOW() +{ + recdat.head[0] = snddat.head[0] = FHONE; + recdat.head[1] = snddat.head[1] = FHTWO; + memset(databuf, 0, sizeof(databuf)); +} + +void RTSSHOW::RTS_SDCardInit(void) +{ + if(!IS_SD_INSERTED()) + { + card.mount(); + } + delay(2); + if(IS_SD_INSERTED()) + { + uint16_t fileCnt = card.get_num_Files(); + card.getWorkDirName(); + if (card.filename[0] == '/') + { + card.mount(); + } + else + { + card.cdup(); + } + + int addrnum = 0; + int num = 0; + for(uint16_t i = 0;(i < fileCnt) && (i < MaxFileNumber + addrnum);i ++) + { + card.selectFileByIndex(fileCnt - 1 - i); + char *pointFilename = card.longFilename; + int filenamelen = strlen(card.longFilename); + int j = 1; + while((strncmp(&pointFilename[j],".gcode",6) && strncmp(&pointFilename[j],".GCODE",6)) && ((j++) < filenamelen)); + if(j >= filenamelen) + { + addrnum++; + continue; + } + + if(j >= TEXTBYTELEN) + { + strncpy(&card.longFilename[TEXTBYTELEN -3], "~~", 2); + card.longFilename[TEXTBYTELEN-1] = '\0'; + j = TEXTBYTELEN-1; + } + + delay(3); + strncpy(CardRecbuf.Cardshowfilename[num], card.longFilename, j); + + strcpy(CardRecbuf.Cardfilename[num], card.filename); + CardRecbuf.addr[num] = FILE1_TEXT_VP + num * 10; + RTS_SndData(CardRecbuf.Cardshowfilename[num],CardRecbuf.addr[num]); + CardRecbuf.Filesum = (++num); + } + lcd_sd_status = IS_SD_INSERTED(); + SERIAL_ECHOLN("***Initing card is OK***"); + } + else + { + SERIAL_ECHOLN("***Initing card fail***"); + } +} + +void RTSSHOW::RTS_SDCardUpate(void) +{ + const bool sd_status = IS_SD_INSERTED(); + if (sd_status != lcd_sd_status) + { + if(sd_status) + { + card.mount(); + RTS_SDCardInit(); + } + else + { + card.release(); + for(int i = 0;i < CardRecbuf.Filesum;i ++) + { + for(int j = 0;j < 10;j++) + RTS_SndData(0, CardRecbuf.addr[i] + j); + // white + RTS_SndData((unsigned long)0xFFFF, FilenameNature + (i + 1) * 16); + } + + for(int j = 0;j < 10;j ++) + { + // clean screen. + RTS_SndData(0, CONTINUE_PRINT_FILE_TEXT_VP + j); + } + // clean filename Icon + for(int j = 1;j <= 20;j ++) + { + RTS_SndData(10, FILE1_SELECT_ICON_VP - 1 + j); + } + memset(&CardRecbuf, 0, sizeof(CardRecbuf)); + } + lcd_sd_status = sd_status; + } + + // represents to update file list + if(CardUpdate && lcd_sd_status && IS_SD_INSERTED()) + { + for(uint16_t i = 0;i < CardRecbuf.Filesum;i ++) + { + delay(3); + RTS_SndData(CardRecbuf.Cardshowfilename[i], CardRecbuf.addr[i]); + RTS_SndData((unsigned long)0xFFFF,FilenameNature + (i+1)*16); + RTS_SndData(10, FILE1_SELECT_ICON_VP + i); + } + CardUpdate = false; + } +} + +#define DEFAULT_LANGUAGE 0 // 0: EN, 1: CN +bool first_load_language = 0; +void lcd_select_language(void) +{ + BL24CXX_Read(FONT_EEPROM+2, (uint8_t*)&first_load_language, sizeof(first_load_language)); + delay(10); + if(first_load_language == 0) + { + BL24CXX_Read(FONT_EEPROM, (uint8_t*)&language_change_font, 1); + } + else + { + first_load_language = 0; + BL24CXX_Write(FONT_EEPROM+2, (uint8_t*)&first_load_language, sizeof(first_load_language)); + #if ENABLED(DEFAULT_LANGUAGE) + language_change_font = 1; + #else + language_change_font = 0; + #endif + BL24CXX_Write(FONT_EEPROM, (uint8_t*)&language_change_font, 1); + } +} + +void RTSSHOW::RTS_Init() +{ + lcd_select_language(); + AxisUnitMode = 1; + last_zoffset = probe_offset.z; + RTS_SndData(probe_offset.z * 100, AUTO_BED_LEVEL_ZOFFSET_VP); + last_target_temperature[0] = thermalManager.temp_hotend[0].target; + last_target_temperature_bed = thermalManager.temp_bed.target; + feedrate_percentage = 100; + RTS_SndData(feedrate_percentage, PRINT_SPEED_RATE_VP); + + /***************turn off motor*****************/ + RTS_SndData(2, MOTOR_FREE_ICON_VP); + + /***************transmit temperature to screen*****************/ + RTS_SndData(0, HEAD_SET_TEMP_VP); + RTS_SndData(0, BED_SET_TEMP_VP); + RTS_SndData(thermalManager.temp_hotend[0].celsius, HEAD_CURRENT_TEMP_VP); + RTS_SndData(thermalManager.temp_bed.celsius, BED_CURRENT_TEMP_VP); + /***************transmit Fan speed to screen*****************/ + #if FAN_COUNT > 0 + // turn off fans + for (uint8_t i = 0; i < FAN_COUNT; i++) thermalManager.fan_speed[i] = 255; + #endif + // turn on fans + RTS_SndData(1, PRINTER_FANOPEN_TITLE_VP); + RTS_SndData(2, PRINTER_LEDOPEN_TITLE_VP); + LEDStatus = true; + + /*********transmit SD card filename to screen***************/ + RTS_SDCardInit(); + /***************transmit Printer information to screen*****************/ + // clean filename + for(int j = 0;j < 20;j ++) + { + RTS_SndData(0, PRINTER_MACHINE_TEXT_VP + j); + } + char PRINTSIZE[20] = {0}; + sprintf(PRINTSIZE,"%d X %d X %d",MAC_LENGTH, MAC_WIDTH, MAC_HEIGHT); + RTS_SndData(SOFTVERSION, PRINTER_VERSION_TEXT_VP); + RTS_SndData(PRINTSIZE, PRINTER_PRINTSIZE_TEXT_VP); + if(language_change_font != 0) + { + RTS_SndData(CORP_WEBSITE_C, PRINTER_WEBSITE_TEXT_VP); + } + else + { + RTS_SndData(CORP_WEBSITE_E, PRINTER_WEBSITE_TEXT_VP); + } + RTS_SndData(language_change_font + 7, SYSTEM_LANGUAGE_TEXT_VP); + + /**************************some info init*******************************/ + RTS_SndData(0, PRINT_PROCESS_TITLE_VP); + + /************************clean screen*******************************/ + for(int i = 0;i < MaxFileNumber;i ++) + { + for(int j = 0;j < 10;j ++) + { + RTS_SndData(0, FILE1_TEXT_VP + i * 10 + j); + } + } + + for(int j = 0;j < 10;j ++) + { + // clean screen. + RTS_SndData(0, CONTINUE_PRINT_FILE_TEXT_VP + j); + } + for(int j = 1;j <= MaxFileNumber;j ++) + { + RTS_SndData(10, FILE1_SELECT_ICON_VP - 1 + j); + } + + rtscheck.RTS_SndData(ExchangePageBase, ExchangepageAddr); + change_page_font = 0; + for(startprogress = 0; startprogress <= 100; startprogress++) + { + rtscheck.RTS_SndData(startprogress, START_PROCESS_ICON_VP); + delay(30); + } + + rtscheck.RTS_SndData(StartSoundSet, SoundAddr); + Update_Time_Value = RTS_UPDATE_VALUE; + if(language_change_font != 0) + { + rtscheck.RTS_SndData(ExchangePageBase + 1, ExchangepageAddr); + change_page_font = 1; + } + else + { + rtscheck.RTS_SndData(ExchangePageBase + 28, ExchangepageAddr); + change_page_font = 28; + } + + SERIAL_ECHOLN("===Initing RTS has finished==="); +} + +int RTSSHOW::RTS_RecData() +{ + while(MYSERIAL1.available() > 0 && (recnum < SizeofDatabuf)) + { + delay(1); + databuf[recnum] = MYSERIAL1.read(); + if(databuf[0] == FHONE) + { + recnum++; + } + else if(databuf[0] == FHTWO) + { + databuf[0] = FHONE; + databuf[1] = FHTWO; + recnum += 2; + } + else if(databuf[0] == FHLENG) + { + databuf[0] = FHONE; + databuf[1] = FHTWO; + databuf[2] = FHLENG; + recnum += 3; + } + else if(databuf[0] == VarAddr_R) + { + databuf[0] = FHONE; + databuf[1] = FHTWO; + databuf[2] = FHLENG; + databuf[3] = VarAddr_R; + recnum += 4; + } + else + { + recnum = 0; + } + } + + // receive nothing + if(recnum < 1) + { + return -1; + } + else if((recdat.head[0] == databuf[0]) && (recdat.head[1] == databuf[1]) && recnum > 2) + { + recdat.len = databuf[2]; + recdat.command = databuf[3]; + if(recdat.len == 0x03 && (recdat.command == 0x82 || recdat.command == 0x80) && (databuf[4] == 0x4F) && (databuf[5] == 0x4B)) //response for writing byte + { + memset(databuf,0, sizeof(databuf)); + recnum = 0; + return -1; + } + else if(recdat.command == 0x83) + { + // response for reading the data from the variate + recdat.addr = databuf[4]; + recdat.addr = (recdat.addr << 8 ) | databuf[5]; + recdat.bytelen = databuf[6]; + for(unsigned int i = 0;i < recdat.bytelen;i+=2) + { + recdat.data[i/2]= databuf[7+i]; + recdat.data[i/2]= (recdat.data[i/2] << 8 )| databuf[8+i]; + } + } + else if(recdat.command == 0x81) + { + // response for reading the page from the register + recdat.addr = databuf[4]; + recdat.bytelen = databuf[5]; + for(unsigned int i = 0;i < recdat.bytelen;i++) + { + recdat.data[i]= databuf[6+i]; + // recdat.data[i]= (recdat.data[i] << 8 )| databuf[7+i]; + } + } + } + else + { + memset(databuf,0, sizeof(databuf)); + recnum = 0; + // receive the wrong data + return -1; + } + memset(databuf,0, sizeof(databuf)); + recnum = 0; + return 2; +} + +void RTSSHOW::RTS_SndData(void) +{ + if((snddat.head[0] == FHONE) && (snddat.head[1] == FHTWO) && (snddat.len >= 3)) + { + databuf[0] = snddat.head[0]; + databuf[1] = snddat.head[1]; + databuf[2] = snddat.len; + databuf[3] = snddat.command; + // to write data to the register + if(snddat.command == 0x80) + { + databuf[4] = snddat.addr; + for(int i =0;i <(snddat.len - 2);i++) + { + databuf[5 + i] = snddat.data[i]; + } + } + else if((snddat.len == 3) && (snddat.command == 0x81)) + { + // to read data from the register + databuf[4] = snddat.addr; + databuf[5] = snddat.bytelen; + } + else if(snddat.command == 0x82) + { + // to write data to the variate + databuf[4] = snddat.addr >> 8; + databuf[5] = snddat.addr & 0xFF; + for(int i =0;i <(snddat.len - 3);i += 2) + { + databuf[6 + i] = snddat.data[i/2] >> 8; + databuf[7 + i] = snddat.data[i/2] & 0xFF; + } + } + else if((snddat.len == 4) && (snddat.command == 0x83)) + { + // to read data from the variate + databuf[4] = snddat.addr >> 8; + databuf[5] = snddat.addr & 0xFF; + databuf[6] = snddat.bytelen; + } + // for(int i = 0;i < (snddat.len + 3);i ++) + // { + // MYSERIAL1.write(databuf[i]); + // delayMicroseconds(1); + // } + usart_tx(MYSERIAL1.c_dev(), databuf, snddat.len + 3); + MYSERIAL1.flush(); + + memset(&snddat, 0, sizeof(snddat)); + memset(databuf, 0, sizeof(databuf)); + snddat.head[0] = FHONE; + snddat.head[1] = FHTWO; + } +} + +void RTSSHOW::RTS_SndData(const String &s, unsigned long addr, unsigned char cmd /*= VarAddr_W*/) +{ + if(s.length() < 1) + { + return; + } + RTS_SndData(s.c_str(), addr, cmd); +} + +void RTSSHOW::RTS_SndData(const char *str, unsigned long addr, unsigned char cmd/*= VarAddr_W*/) +{ + int len = strlen(str); + if(len > 0) + { + databuf[0] = FHONE; + databuf[1] = FHTWO; + databuf[2] = 3+len; + databuf[3] = cmd; + databuf[4] = addr >> 8; + databuf[5] = addr & 0x00FF; + for(int i = 0;i < len;i ++) + { + databuf[6 + i] = str[i]; + } + + for(int i = 0;i < (len + 6);i ++) + { + MYSERIAL1.write(databuf[i]); + delayMicroseconds(1); + } + memset(databuf, 0, sizeof(databuf)); + } +} + +void RTSSHOW::RTS_SndData(char c, unsigned long addr, unsigned char cmd/*= VarAddr_W*/) +{ + snddat.command = cmd; + snddat.addr = addr; + snddat.data[0] = (unsigned long)c; + snddat.data[0] = snddat.data[0] << 8; + snddat.len = 5; + RTS_SndData(); +} + +void RTSSHOW::RTS_SndData(unsigned char* str, unsigned long addr, unsigned char cmd){RTS_SndData((char *)str, addr, cmd);} + +void RTSSHOW::RTS_SndData(int n, unsigned long addr, unsigned char cmd/*= VarAddr_W*/) +{ + if(cmd == VarAddr_W ) + { + if(n > 0xFFFF) + { + snddat.data[0] = n >> 16; + snddat.data[1] = n & 0xFFFF; + snddat.len = 7; + } + else + { + snddat.data[0] = n; + snddat.len = 5; + } + } + else if(cmd == RegAddr_W) + { + snddat.data[0] = n; + snddat.len = 3; + } + else if(cmd == VarAddr_R) + { + snddat.bytelen = n; + snddat.len = 4; + } + snddat.command = cmd; + snddat.addr = addr; + RTS_SndData(); +} + +void RTSSHOW::RTS_SndData(unsigned int n, unsigned long addr, unsigned char cmd){ RTS_SndData((int)n, addr, cmd); } + +void RTSSHOW::RTS_SndData(float n, unsigned long addr, unsigned char cmd){ RTS_SndData((int)n, addr, cmd); } + +void RTSSHOW::RTS_SndData(long n, unsigned long addr, unsigned char cmd){ RTS_SndData((unsigned long)n, addr, cmd); } + +void RTSSHOW::RTS_SndData(unsigned long n, unsigned long addr, unsigned char cmd/*= VarAddr_W*/) +{ + if(cmd == VarAddr_W ) + { + if(n > 0xFFFF) + { + snddat.data[0] = n >> 16; + snddat.data[1] = n & 0xFFFF; + snddat.len = 7; + } + else + { + snddat.data[0] = n; + snddat.len = 5; + } + } + else if(cmd == VarAddr_R) + { + snddat.bytelen = n; + snddat.len = 4; + } + snddat.command = cmd; + snddat.addr = addr; + RTS_SndData(); +} + +void RTSSHOW::RTS_SDcard_Stop() +{ + if(heat_flag) + { + if(home_flag) planner.synchronize(); + card.stopSDPrint(); + queue.clear(); + quickstop_stepper(); + print_job_timer.stop(); + thermalManager.disable_all_heaters(); + thermalManager.zero_fan_speeds(); + wait_for_heatup = false; + #if ENABLED(SDSUPPORT) && ENABLED(POWER_LOSS_RECOVERY) + card.removeJobRecoveryFile(); + #endif + #ifdef EVENT_GCODE_SD_STOP + queue.inject_P(PSTR(EVENT_GCODE_SD_STOP)); + #endif + } + else + { + if(home_flag) planner.synchronize(); + card.flag.abort_sd_printing = true; + } + + wait_for_heatup = false; + sdcard_pause_check = true; + + waitway = 7; +} + +void RTSSHOW::RTS_HandleData() +{ + int Checkkey = -1; + // for waiting + if(waitway > 0) + { + memset(&recdat, 0, sizeof(recdat)); + recdat.head[0] = FHONE; + recdat.head[1] = FHTWO; + return; + } + for(int i = 0;Addrbuf[i] != 0;i ++) + { + if(recdat.addr == Addrbuf[i]) + { + Checkkey = i; + } + } + + if(Checkkey < 0) + { + memset(&recdat, 0, sizeof(recdat)); + recdat.head[0] = FHONE; + recdat.head[1] = FHTWO; + return; + } + + switch(Checkkey) + { + case MainEnterKey: + if(recdat.data[0] == 1) + { + CardUpdate = true; + RTS_SDCardUpate(); + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 2, ExchangepageAddr); + change_page_font = 2; + } + else + { + RTS_SndData(ExchangePageBase + 29, ExchangepageAddr); + change_page_font = 29; + } + } + else if(recdat.data[0] == 2) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 15, ExchangepageAddr); + change_page_font = 15; + } + else + { + RTS_SndData(ExchangePageBase + 42, ExchangepageAddr); + change_page_font = 42; + } + } + else if(recdat.data[0] == 3) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 20, ExchangepageAddr); + change_page_font = 20; + } + else + { + RTS_SndData(ExchangePageBase + 47, ExchangepageAddr); + change_page_font = 47; + } + RTS_SndData(language_change_font + 7, SYSTEM_LANGUAGE_TEXT_VP); + } + else if(recdat.data[0] == 4) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 25, ExchangepageAddr); + change_page_font = 25; + } + else + { + RTS_SndData(ExchangePageBase + 52, ExchangepageAddr); + change_page_font = 52; + } + } + else if(recdat.data[0] == 5) + { + RTS_SndData(1, MOTOR_FREE_ICON_VP); + RTS_SndData(0, PRINT_PROCESS_TITLE_VP); + RTS_SndData(0, PRINT_PROCESS_VP); + delay(2); + RTS_SndData(0, PRINT_TIME_HOUR_VP); + RTS_SndData(0, PRINT_TIME_MIN_VP); + print_job_timer.reset(); + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 1, ExchangepageAddr); + change_page_font = 1; + } + else + { + RTS_SndData(ExchangePageBase + 28, ExchangepageAddr); + change_page_font = 28; + } + } + else if(recdat.data[0] == 6) + { + waitway = 3; + RTS_SndData(1, AUTO_BED_LEVEL_TITLE_VP); + RTS_SndData(AUTO_BED_LEVEL_PREHEAT, AUTO_BED_PREHEAT_HEAD_DATA_VP); + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 26, ExchangepageAddr); + change_page_font = 26; + } + else + { + RTS_SndData(ExchangePageBase + 53, ExchangepageAddr); + change_page_font = 53; + } + thermalManager.setTargetHotend(AUTO_BED_LEVEL_PREHEAT, 0); + RTS_SndData(AUTO_BED_LEVEL_PREHEAT, HEAD_SET_TEMP_VP); + if(thermalManager.temp_hotend[0].celsius < (AUTO_BED_LEVEL_PREHEAT - 5)) + { + queue.enqueue_now_P(PSTR("G4 S40")); + } + queue.enqueue_now_P(PSTR("G28""\n""G29")); + RTS_SndData(1, MOTOR_FREE_ICON_VP); + } + break; + case AdjustEnterKey: + if(recdat.data[0] == 1) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 14, ExchangepageAddr); + change_page_font = 14; + } + else + { + RTS_SndData(ExchangePageBase + 41, ExchangepageAddr); + change_page_font = 41; + } + } + else if(recdat.data[0] == 2) + { + Update_Time_Value = RTS_UPDATE_VALUE; + + if(last_zoffset != probe_offset.z) + { + last_zoffset = probe_offset.z; + RTS_SndData(probe_offset.z * 100, AUTO_BED_LEVEL_ZOFFSET_VP); + settings.save(); + } + if(card.isPrinting()) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 10, ExchangepageAddr); + change_page_font = 10; + } + else + { + RTS_SndData(ExchangePageBase + 37, ExchangepageAddr); + change_page_font = 37; + } + } + else + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 12, ExchangepageAddr); + change_page_font = 12; + } + else + { + RTS_SndData(ExchangePageBase + 39, ExchangepageAddr); + change_page_font = 39; + } + } + } + else if(recdat.data[0] == 3) + { + // turn on the fan + if(thermalManager.fan_speed[0] == 0) + { + RTS_SndData(1, PRINTER_FANOPEN_TITLE_VP); + thermalManager.fan_speed[0] = 255; + } + else + { + // turn off the fan + RTS_SndData(2, PRINTER_FANOPEN_TITLE_VP); + thermalManager.fan_speed[0] = 0; + } + } + else if(recdat.data[0] == 4) + { + // turn on the LED + if(LEDStatus) + { + RTS_SndData(1, PRINTER_LEDOPEN_TITLE_VP); + digitalWrite(LED_CONTROL_PIN, HIGH); + LEDStatus = false; + } + else + { + // turn off the LED + RTS_SndData(2, PRINTER_LEDOPEN_TITLE_VP); + digitalWrite(LED_CONTROL_PIN, LOW); + LEDStatus = true; + } + } + break; + case PrintSpeedEnterKey: + feedrate_percentage = recdat.data[0]; + break; + case StopPrintKey: + if(recdat.data[0] == 1) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 13, ExchangepageAddr); + change_page_font = 13; + } + else + { + RTS_SndData(ExchangePageBase + 40, ExchangepageAddr); + change_page_font = 40; + } + } + else if(recdat.data[0] == 2) + { + RTS_SndData(0, PRINT_TIME_HOUR_VP); + RTS_SndData(0, PRINT_TIME_MIN_VP); + Update_Time_Value = 0; + tempbed = 0; + temphot = 0; + RTS_SDcard_Stop(); + } + else if(recdat.data[0] == 3) + { + if(card.isPrinting()) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 10, ExchangepageAddr); + change_page_font = 10; + } + else + { + RTS_SndData(ExchangePageBase + 37, ExchangepageAddr); + change_page_font = 37; + } + } + else + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 12, ExchangepageAddr); + change_page_font = 12; + } + else + { + RTS_SndData(ExchangePageBase + 39, ExchangepageAddr); + change_page_font = 39; + } + } + } + break; + case PausePrintKey: + if(recdat.data[0] == 1) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 11, ExchangepageAddr); + change_page_font = 11; + } + else + { + RTS_SndData(ExchangePageBase + 38, ExchangepageAddr); + change_page_font = 38; + } + } + else if(recdat.data[0] == 2) + { + pause_z = current_position[Z_AXIS]; + pause_e = current_position[E_AXIS] - 5; + + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 12, ExchangepageAddr); + change_page_font = 12; + } + else + { + RTS_SndData(ExchangePageBase + 39, ExchangepageAddr); + change_page_font = 39; + } + + if(!temphot) + temphot = thermalManager.degTargetHotend(0); + if(!tempbed) + tempbed = thermalManager.degTargetBed(); + + queue.inject_P(PSTR("M25")); + + Update_Time_Value = 0; + pause_action_flag = true; + } + else if(recdat.data[0] == 3) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 10, ExchangepageAddr); + change_page_font = 10; + } + else + { + RTS_SndData(ExchangePageBase + 37, ExchangepageAddr); + change_page_font = 37; + } + } + break; + case ResumePrintKey: + if(recdat.data[0] == 1) + { + char commandbuf[20]; + char pause_str_Z[16]; + char pause_str_E[16]; + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 10, ExchangepageAddr); + change_page_font = 10; + } + else + { + RTS_SndData(ExchangePageBase + 37, ExchangepageAddr); + change_page_font = 37; + } + memset(pause_str_Z, 0, sizeof(pause_str_Z)); + dtostrf(pause_z, 3, 2, pause_str_Z); + memset(pause_str_E, 0, sizeof(pause_str_E)); + dtostrf(pause_e, 3, 2, pause_str_E); + + memset(commandbuf, 0, sizeof(commandbuf)); + sprintf_P(commandbuf, PSTR("G0 Z%s"), pause_str_Z); + gcode.process_subcommands_now_P(commandbuf); + sprintf_P(commandbuf, PSTR("G92 E%s"), pause_str_E); + gcode.process_subcommands_now_P(commandbuf); + + gcode.process_subcommands_now_P(PSTR("M24")); + sdcard_pause_check = true; + } + else if(recdat.data[0] == 2) + { + thermalManager.setTargetHotend(temphot, 0); + } + break; + case ZoffsetEnterKey: + last_zoffset = probe_offset.z; + if(recdat.data[0] >= 32768) + { + probe_offset.z = ((float)recdat.data[0] - 65536)/100; + } + else + { + probe_offset.z = ((float)recdat.data[0])/100; + } + if(WITHIN((probe_offset.z), Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) + { + babystep.add_mm(Z_AXIS, probe_offset.z - last_zoffset); + } + break; + case TempControlKey: + if(recdat.data[0] == 2) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 21, ExchangepageAddr); + change_page_font = 21; + } + else + { + RTS_SndData(ExchangePageBase + 48, ExchangepageAddr); + change_page_font = 48; + } + } + else if(recdat.data[0] == 3) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 22, ExchangepageAddr); + change_page_font = 22; + } + else + { + RTS_SndData(ExchangePageBase + 49, ExchangepageAddr); + change_page_font = 49; + } + } + else if(recdat.data[0] == 4) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 23, ExchangepageAddr); + change_page_font = 23; + } + else + { + RTS_SndData(ExchangePageBase + 50, ExchangepageAddr); + change_page_font = 50; + } + } + else if(recdat.data[0] == 5) + { + thermalManager.setTargetHotend(HMI_ValueStruct.preheat_hotend_temp[0], 0); + thermalManager.setTargetBed(HMI_ValueStruct.preheat_bed_temp[0]); + + RTS_SndData(HMI_ValueStruct.preheat_hotend_temp[0], HEAD_SET_TEMP_VP); + RTS_SndData(HMI_ValueStruct.preheat_bed_temp[0], BED_SET_TEMP_VP); + } + else if(recdat.data[0] == 6) + { + thermalManager.setTargetHotend(HMI_ValueStruct.preheat_hotend_temp[1], 0); + thermalManager.setTargetBed(HMI_ValueStruct.preheat_bed_temp[1]); + + RTS_SndData(HMI_ValueStruct.preheat_hotend_temp[1], HEAD_SET_TEMP_VP); + RTS_SndData(HMI_ValueStruct.preheat_bed_temp[1], BED_SET_TEMP_VP); + } + else if(recdat.data[0] == 7) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 20, ExchangepageAddr); + change_page_font = 20; + } + else + { + RTS_SndData(ExchangePageBase + 47, ExchangepageAddr); + change_page_font = 47; + } + } + break; + case CoolDownKey: + if(recdat.data[0] == 1) + { + thermalManager.setTargetHotend(0, 0); + thermalManager.setTargetBed(0); + + RTS_SndData(0, HEAD_SET_TEMP_VP); + RTS_SndData(0, BED_SET_TEMP_VP); + } + else if(recdat.data[0] == 2) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 21, ExchangepageAddr); + change_page_font = 21; + } + else + { + RTS_SndData(ExchangePageBase + 48, ExchangepageAddr); + change_page_font = 48; + } + } + break; + case HeaterTempEnterKey: + thermalManager.temp_hotend[0].target = recdat.data[0]; + thermalManager.setTargetHotend(thermalManager.temp_hotend[0].target, 0); + RTS_SndData(thermalManager.temp_hotend[0].target, HEAD_SET_TEMP_VP); + break; + case HotBedTempEnterKey: + thermalManager.temp_bed.target = recdat.data[0]; + thermalManager.setTargetBed(thermalManager.temp_bed.target); + RTS_SndData(thermalManager.temp_bed.target, BED_SET_TEMP_VP); + break; + case PrepareEnterKey: + if(recdat.data[0] == 3) + { + rtscheck.RTS_SndData(10*current_position[X_AXIS], AXIS_X_COORD_VP); + rtscheck.RTS_SndData(10*current_position[Y_AXIS], AXIS_Y_COORD_VP); + rtscheck.RTS_SndData(10*current_position[Z_AXIS], AXIS_Z_COORD_VP); + delay(2); + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 16, ExchangepageAddr); + change_page_font = 16; + } + else + { + RTS_SndData(ExchangePageBase + 43, ExchangepageAddr); + change_page_font = 43; + } + } + else if(recdat.data[0] == 5) + { + if(language_change_font != 0) + { + RTS_SndData(CORP_WEBSITE_C, PRINTER_WEBSITE_TEXT_VP); + RTS_SndData(ExchangePageBase + 24, ExchangepageAddr); + change_page_font = 24; + } + else + { + RTS_SndData(CORP_WEBSITE_E, PRINTER_WEBSITE_TEXT_VP); + RTS_SndData(ExchangePageBase + 51, ExchangepageAddr); + change_page_font = 51; + } + } + else if(recdat.data[0] == 6) + { + queue.enqueue_now_P(PSTR("M84")); + RTS_SndData(2, MOTOR_FREE_ICON_VP); + } + else if(recdat.data[0] == 7) + { + settings.reset(); + settings.save(); + } + else if(recdat.data[0] == 8) + { + settings.save(); + } + else if(recdat.data[0] == 9) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 1, ExchangepageAddr); + change_page_font = 1; + } + else + { + RTS_SndData(ExchangePageBase + 28, ExchangepageAddr); + change_page_font = 28; + } + } + break; + case BedLevelKey: + if(recdat.data[0] == 1) + { + waitway = 6; + if (!TEST(axis_known_position, X_AXIS) || !TEST(axis_known_position, Y_AXIS)) + { + queue.enqueue_now_P(PSTR("G28")); + } + else + { + queue.enqueue_now_P(PSTR("G28 Z")); + } + RTS_SndData(1, MOTOR_FREE_ICON_VP); + Update_Time_Value = 0; + } + else if(recdat.data[0] == 2) + { + if (WITHIN((probe_offset.z + 0.05), -0.52, 0.52)) + { + babystep.add_mm(Z_AXIS, 0.05); + probe_offset.z = (probe_offset.z + 0.05); + } + RTS_SndData(probe_offset.z * 100, AUTO_BED_LEVEL_ZOFFSET_VP); + } + else if(recdat.data[0] == 3) + { + if (WITHIN((probe_offset.z - 0.05), -0.52, 0.52)) + { + babystep.add_mm(Z_AXIS, -0.05); + probe_offset.z = (probe_offset.z - 0.05); + } + RTS_SndData(probe_offset.z * 100, AUTO_BED_LEVEL_ZOFFSET_VP); + } + else if(recdat.data[0] == 4) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 25, ExchangepageAddr); + change_page_font = 25; + } + else + { + RTS_SndData(ExchangePageBase + 52, ExchangepageAddr); + change_page_font = 52; + } + } + break; + case AutoHomeKey: + if(recdat.data[0] == 1) + { + AxisUnitMode = 1; + axis_unit = 10.0; + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 16, ExchangepageAddr); + change_page_font = 16; + } + else + { + RTS_SndData(ExchangePageBase + 43, ExchangepageAddr); + change_page_font = 43; + } + } + else if(recdat.data[0] == 2) + { + AxisUnitMode = 2; + axis_unit = 1.0; + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 17, ExchangepageAddr); + change_page_font = 17; + } + else + { + RTS_SndData(ExchangePageBase + 44, ExchangepageAddr); + change_page_font = 44; + } + } + else if(recdat.data[0] == 3) + { + AxisUnitMode = 3; + axis_unit = 0.1; + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 18, ExchangepageAddr); + change_page_font = 18; + } + else + { + RTS_SndData(ExchangePageBase + 45, ExchangepageAddr); + change_page_font = 45; + } + } + else if(recdat.data[0] == 4) + { + waitway = 4; + queue.enqueue_now_P(PSTR("G28")); + RTS_SndData(1, MOTOR_FREE_ICON_VP); + Update_Time_Value = 0; + } + break; + case XaxismoveKey: + float x_min, x_max; + waitway = 4; + x_min = 0; + x_max = X_MAX_POS; + current_position[X_AXIS] = ((float)recdat.data[0])/10; + if(current_position[X_AXIS] < x_min) + { + current_position[X_AXIS] = x_min; + } + else if(current_position[X_AXIS] > x_max) + { + current_position[X_AXIS] = x_max; + } + RTS_line_to_current(X_AXIS); + RTS_SndData(10 * current_position[X_AXIS], AXIS_X_COORD_VP); + delay(1); + RTS_SndData(1, MOTOR_FREE_ICON_VP); + waitway = 0; + break; + case YaxismoveKey: + float y_min, y_max; + waitway = 4; + y_min = 0; + y_max = Y_MAX_POS; + current_position[Y_AXIS] = ((float)recdat.data[0])/10; + if (current_position[Y_AXIS] < y_min) + { + current_position[Y_AXIS] = y_min; + } + else if (current_position[Y_AXIS] > y_max) + { + current_position[Y_AXIS] = y_max; + } + RTS_line_to_current(Y_AXIS); + RTS_SndData(10 * current_position[Y_AXIS], AXIS_Y_COORD_VP); + delay(1); + RTS_SndData(1, MOTOR_FREE_ICON_VP); + waitway = 0; + break; + case ZaxismoveKey: + float z_min, z_max; + waitway = 4; + z_min = Z_MIN_POS; + z_max = Z_MAX_POS; + current_position[Z_AXIS] = ((float)recdat.data[0])/10; + if (current_position[Z_AXIS] < z_min) + { + current_position[Z_AXIS] = z_min; + } + else if (current_position[Z_AXIS] > z_max) + { + current_position[Z_AXIS] = z_max; + } + RTS_line_to_current(Z_AXIS); + RTS_SndData(10 * current_position[Z_AXIS], AXIS_Z_COORD_VP); + delay(1); + RTS_SndData(1, MOTOR_FREE_ICON_VP); + waitway = 0; + break; + case HeaterLoadEnterKey: + FilamentLOAD = ((float)recdat.data[0])/10; + break; + case HeaterLoadStartKey: + if(recdat.data[0] == 1) + { + current_position[E_AXIS] += FilamentLOAD; + + if(thermalManager.temp_hotend[0].celsius < PREHEAT_1_TEMP_HOTEND) + { + thermalManager.temp_hotend[0].target = PREHEAT_1_TEMP_HOTEND; + thermalManager.setTargetHotend(thermalManager.temp_hotend[0].target, 0); + RTS_SndData(thermalManager.temp_hotend[0].target, HEAD_SET_TEMP_VP); + } + } + else if(recdat.data[0] == 2) + { + current_position[E_AXIS] -= FilamentLOAD; + + if(thermalManager.temp_hotend[0].celsius < PREHEAT_1_TEMP_HOTEND) + { + thermalManager.temp_hotend[0].target = PREHEAT_1_TEMP_HOTEND; + thermalManager.setTargetHotend(thermalManager.temp_hotend[0].target, 0); + RTS_SndData(thermalManager.temp_hotend[0].target, HEAD_SET_TEMP_VP); + } + } + else if(recdat.data[0] == 3) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 15, ExchangepageAddr); + change_page_font = 15; + } + else + { + RTS_SndData(ExchangePageBase + 42, ExchangepageAddr); + change_page_font = 42; + } + } + else if(recdat.data[0] == 4) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 19, ExchangepageAddr); + change_page_font = 19; + } + else + { + RTS_SndData(ExchangePageBase + 46, ExchangepageAddr); + change_page_font = 46; + } + } + RTS_line_to_current(E_AXIS); + RTS_SndData(10 * FilamentLOAD, HEAD_FILAMENT_LOAD_DATA_VP); + break; + case SelectLanguageKey: + if(recdat.data[0] != 0) + { + language_change_font = recdat.data[0] - 1; + } + if(recdat.data[0] == 2) + { + RTS_SndData(ExchangePageBase + 20, ExchangepageAddr); + change_page_font = 20; + } + else if(recdat.data[0] == 1) + { + RTS_SndData(ExchangePageBase + 47, ExchangepageAddr); + change_page_font = 47; + } + RTS_SndData(language_change_font + 7, SYSTEM_LANGUAGE_TEXT_VP); + BL24CXX_Write(FONT_EEPROM, (uint8_t*)&language_change_font, 1); + break; + case PowerContinuePrintKey: + if(recdat.data[0] == 1) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 10, ExchangepageAddr); + change_page_font = 10; + } + else + { + RTS_SndData(ExchangePageBase + 37, ExchangepageAddr); + change_page_font = 37; + } + if(recovery.info.recovery_flag) + { + power_off_type_yes = 1; + + RTS_SndData(1, PRINTER_FANOPEN_TITLE_VP); + + Update_Time_Value = 0; + + heat_flag = 1; + + recovery.resume(); + } + } + else if(recdat.data[0] == 2) + { + waitway = 3; + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 1, ExchangepageAddr); + change_page_font = 1; + } + else + { + RTS_SndData(ExchangePageBase + 28, ExchangepageAddr); + change_page_font = 28; + } + Update_Time_Value = RTS_UPDATE_VALUE; + card.stopSDPrint(); + queue.clear(); + quickstop_stepper(); + print_job_timer.stop(); + thermalManager.disable_all_heaters(); + print_job_timer.reset(); + + #if ENABLED(SDSUPPORT) && ENABLED(POWER_LOSS_RECOVERY) + card.removeJobRecoveryFile(); + #endif + wait_for_heatup = false; + sdcard_pause_check = true; + RTS_SndData(1, MOTOR_FREE_ICON_VP); + delay(500); + waitway = 0; + } + break; + case FanSpeedEnterKey: + #if FAN_COUNT > 0 + for (uint8_t i = 0; i < FAN_COUNT; i++) + { + thermalManager.fan_speed[i] = recdat.data[0]; + RTS_SndData(thermalManager.fan_speed[i], FAN_SPEED_CONTROL_DATA_VP); + } + #endif + break; + case PLAHeadSetEnterKey: + HMI_ValueStruct.preheat_hotend_temp[0] = recdat.data[0]; + RTS_SndData(HMI_ValueStruct.preheat_hotend_temp[0], PLA_HEAD_SET_DATA_VP); + break; + case PLABedSetEnterKey: + HMI_ValueStruct.preheat_bed_temp[0] = recdat.data[0]; + RTS_SndData(HMI_ValueStruct.preheat_bed_temp[0], PLA_BED_SET_DATA_VP); + break; + case PLAFanSetEnterKey: + HMI_ValueStruct.preheat_fan_speed[0] = recdat.data[0]; + RTS_SndData(HMI_ValueStruct.preheat_fan_speed[0], PLA_FAN_SET_DATA_VP); + break; + case ABSHeadSetEnterKey: + HMI_ValueStruct.preheat_hotend_temp[1] = recdat.data[0]; + RTS_SndData(HMI_ValueStruct.preheat_hotend_temp[1], ABS_HEAD_SET_DATA_VP); + break; + case ABSBedSetEnterKey: + HMI_ValueStruct.preheat_bed_temp[1] = recdat.data[0]; + RTS_SndData(HMI_ValueStruct.preheat_bed_temp[1], ABS_BED_SET_DATA_VP); + break; + case ABSFanSetEnterKey: + HMI_ValueStruct.preheat_fan_speed[1] = recdat.data[0]; + RTS_SndData(HMI_ValueStruct.preheat_fan_speed[1], ABS_FAN_SET_DATA_VP); + break; + case SelectFileKey: + if(card.flag.mounted) + { + if(recdat.data[0] > CardRecbuf.Filesum) break; + + CardRecbuf.recordcount = recdat.data[0] - 1; + delay(2); + for(int j = 1;j <= CardRecbuf.Filesum;j ++) + { + RTS_SndData((unsigned long)0xFFFF, FilenameNature + j * 16); + RTS_SndData(10, FILE1_SELECT_ICON_VP - 1 + j); + } + RTS_SndData((unsigned long)0x87F0, FilenameNature + recdat.data[0] * 16); + RTS_SndData(6, FILE1_SELECT_ICON_VP - 1 + recdat.data[0]); + } + break; + case StartFileKey: + if((recdat.data[0] == 1) && card.flag.mounted) + { + if(CardRecbuf.recordcount < 0) + { + break; + } + + char cmd[30]; + char* c; + sprintf_P(cmd, PSTR("M23 %s"), CardRecbuf.Cardfilename[CardRecbuf.recordcount]); + for (c = &cmd[4]; *c; c++) *c = tolower(*c); + + FilenamesCount = CardRecbuf.recordcount; + memset(cmdbuf, 0, sizeof(cmdbuf)); + strcpy(cmdbuf, cmd); + + queue.enqueue_one_now(cmd); + queue.enqueue_now_P(PSTR("M24")); + + card.removeJobRecoveryFile(); + StartPrint_flag = 1; + + heat_flag = 1; + + // clean screen. + for(int j = 0;j < 10;j ++) + { + RTS_SndData(0, CONTINUE_PRINT_FILE_TEXT_VP + j); + } + + int filelen = strlen(CardRecbuf.Cardshowfilename[CardRecbuf.recordcount]); + filelen = (TEXTBYTELEN - filelen)/2; + if(filelen > 0) + { + char buf[20]; + memset(buf, 0, sizeof(buf)); + strncpy(buf," ",filelen); + strcpy(&buf[filelen], CardRecbuf.Cardshowfilename[CardRecbuf.recordcount]); + RTS_SndData(buf, CONTINUE_PRINT_FILE_TEXT_VP); + } + else + { + RTS_SndData(CardRecbuf.Cardshowfilename[CardRecbuf.recordcount], CONTINUE_PRINT_FILE_TEXT_VP); + } + delay(2); + #if FAN_COUNT > 0 + for (uint8_t i = 0; i < FAN_COUNT; i++) thermalManager.fan_speed[i] = 255; + #endif + RTS_SndData(1, PRINTER_FANOPEN_TITLE_VP); + + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 10, ExchangepageAddr); + change_page_font = 10; + } + else + { + RTS_SndData(ExchangePageBase + 37, ExchangepageAddr); + change_page_font = 37; + } + Update_Time_Value = 0; + } + else if(recdat.data[0] == 4) + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 1, ExchangepageAddr); + change_page_font = 1; + } + else + { + RTS_SndData(ExchangePageBase + 28, ExchangepageAddr); + change_page_font = 28; + } + } + break; + case ChangePageKey: + { + // clean screen. + for(int j = 0;j < 10;j ++) + { + RTS_SndData(0, CONTINUE_PRINT_FILE_TEXT_VP + j); + } + + int filelen = strlen(CardRecbuf.Cardshowfilename[CardRecbuf.recordcount]); + filelen = (TEXTBYTELEN - filelen)/2; + if(filelen > 0) + { + char buf[20]; + memset(buf, 0, sizeof(buf)); + strncpy(buf, " ", filelen); + strcpy(&buf[filelen], CardRecbuf.Cardshowfilename[CardRecbuf.recordcount]); + RTS_SndData(buf, CONTINUE_PRINT_FILE_TEXT_VP); + } + else + { + RTS_SndData(CardRecbuf.Cardshowfilename[CardRecbuf.recordcount], CONTINUE_PRINT_FILE_TEXT_VP); + } + + // represents to update file list + if(IS_SD_INSERTED()) + { + for(uint16_t i = 0;i < CardRecbuf.Filesum;i ++) + { + delay(3); + RTS_SndData(CardRecbuf.Cardshowfilename[i], CardRecbuf.addr[i]); + RTS_SndData((unsigned long)0xFFFF,FilenameNature + (i+1)*16); + RTS_SndData(10, FILE1_SELECT_ICON_VP + i); + } + } + + char PRINTSIZE[20] = {0}; + sprintf(PRINTSIZE,"%d X %d X %d",MAC_LENGTH, MAC_WIDTH, MAC_HEIGHT); + RTS_SndData(SOFTVERSION, PRINTER_VERSION_TEXT_VP); + RTS_SndData(PRINTSIZE, PRINTER_PRINTSIZE_TEXT_VP); + if(language_change_font != 0) + { + RTS_SndData(CORP_WEBSITE_C, PRINTER_WEBSITE_TEXT_VP); + } + else + { + RTS_SndData(CORP_WEBSITE_E, PRINTER_WEBSITE_TEXT_VP); + } + RTS_SndData(language_change_font + 7, SYSTEM_LANGUAGE_TEXT_VP); + + if(thermalManager.fan_speed[0]) + { + RTS_SndData(1, PRINTER_FANOPEN_TITLE_VP); + } + else + { + RTS_SndData(2, PRINTER_FANOPEN_TITLE_VP); + } + + if(LEDStatus) + { + RTS_SndData(1, PRINTER_LEDOPEN_TITLE_VP); + } + else + { + RTS_SndData(2, PRINTER_LEDOPEN_TITLE_VP); + } + + Percentrecord = card.percentDone() + 1; + if(Percentrecord <= 100) + { + rtscheck.RTS_SndData((unsigned int)Percentrecord, PRINT_PROCESS_TITLE_VP); + } + + RTS_SndData(probe_offset.z * 100, AUTO_BED_LEVEL_ZOFFSET_VP); + + RTS_SndData(feedrate_percentage, PRINT_SPEED_RATE_VP); + RTS_SndData(thermalManager.temp_hotend[0].target, HEAD_SET_TEMP_VP); + RTS_SndData(thermalManager.temp_bed.target, BED_SET_TEMP_VP); + + RTS_SndData(ExchangePageBase + change_page_font, ExchangepageAddr); + break; + } + case ErrorKey: + { + if(recdat.data[0] == 1) + { + if(printingIsActive()) // printing + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 10, ExchangepageAddr); + change_page_font = 10; + } + else + { + RTS_SndData(ExchangePageBase + 37, ExchangepageAddr); + change_page_font = 37; + } + } + else if(printingIsPaused()) // pause + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 12, ExchangepageAddr); + change_page_font = 12; + } + else + { + RTS_SndData(ExchangePageBase + 39, ExchangepageAddr); + change_page_font = 39; + } + } + else // other + { + if(language_change_font != 0) + { + RTS_SndData(ExchangePageBase + 1, ExchangepageAddr); + change_page_font = 1; + } + else + { + RTS_SndData(ExchangePageBase + 28, ExchangepageAddr); + change_page_font = 28; + } + } + } + break; + } + default: + break; + } + memset(&recdat, 0, sizeof(recdat)); + recdat.head[0] = FHONE; + recdat.head[1] = FHTWO; +} + +void EachMomentUpdate() +{ + millis_t ms = millis(); + if(ms > next_rts_update_ms) + { + // print the file before the power is off. + if((power_off_type_yes == 0) && lcd_sd_status && recovery.info.recovery_flag) + { + power_off_type_yes = 1; + for(uint16_t i = 0;i < CardRecbuf.Filesum;i ++) + { + if(!strcmp(CardRecbuf.Cardfilename[i], &recovery.info.sd_filename[1])) + { + int filelen = strlen(CardRecbuf.Cardshowfilename[i]); + filelen = (TEXTBYTELEN - filelen)/2; + if(filelen > 0) + { + char buf[20]; + memset(buf, 0, sizeof(buf)); + strncpy(buf, " ", filelen); + strcpy(&buf[filelen],CardRecbuf.Cardshowfilename[i]); + rtscheck.RTS_SndData(buf, CONTINUE_PRINT_FILE_TEXT_VP); + } + else + { + rtscheck.RTS_SndData(CardRecbuf.Cardshowfilename[i], CONTINUE_PRINT_FILE_TEXT_VP); + } + if(language_change_font != 0) + { + rtscheck.RTS_SndData(ExchangePageBase + 27, ExchangepageAddr); + change_page_font = 27; + } + else + { + rtscheck.RTS_SndData(ExchangePageBase + 54, ExchangepageAddr); + change_page_font = 54; + } + break; + } + } + return; + } + else if((power_off_type_yes == 0) && !recovery.info.recovery_flag) + { + power_off_type_yes = 1; + Update_Time_Value = RTS_UPDATE_VALUE; + if(language_change_font != 0) + { + rtscheck.RTS_SndData(ExchangePageBase + 1, ExchangepageAddr); + change_page_font = 1; + } + else + { + rtscheck.RTS_SndData(ExchangePageBase + 28, ExchangepageAddr); + change_page_font = 28; + } + return; + } + else + { + // need to optimize + if(gcode.previous_move_ms != 0) + { + duration_t elapsed = print_job_timer.duration(); + static unsigned int last_cardpercentValue = 101; + rtscheck.RTS_SndData(elapsed.value/3600, PRINT_TIME_HOUR_VP); + rtscheck.RTS_SndData((elapsed.value%3600)/60, PRINT_TIME_MIN_VP); + + if(card.isPrinting() && last_cardpercentValue != card.percentDone()) + { + if((unsigned int) card.percentDone() > 0) + { + Percentrecord = card.percentDone() + 1; + if(Percentrecord <= 100) + { + rtscheck.RTS_SndData((unsigned int)Percentrecord, PRINT_PROCESS_TITLE_VP); + } + } + else + { + rtscheck.RTS_SndData(0, PRINT_PROCESS_TITLE_VP); + } + rtscheck.RTS_SndData((unsigned int) card.percentDone(), PRINT_PROCESS_VP); + last_cardpercentValue = card.percentDone(); + } + } + + // save z offset + if(probe_offset.z != last_zoffset) + { + settings.save(); + last_zoffset = probe_offset.z; + } + + if(print_finish && !planner.has_blocks_queued()) + { + print_finish = false; + finish_home = true; + queue.inject_P(PSTR(EVENT_GCODE_SD_STOP)); + } + + // float temp_buf = thermalManager.temp_hotend[0].celsius; + rtscheck.RTS_SndData(thermalManager.temp_hotend[0].celsius, HEAD_CURRENT_TEMP_VP); + rtscheck.RTS_SndData(thermalManager.temp_bed.celsius, BED_CURRENT_TEMP_VP); + if((false == card.isPrinting()) && (false == sdcard_pause_check)) + { + if(0 == READ(CHECK_MATWEIAL)) + { + if(language_change_font != 0) + { + rtscheck.RTS_SndData(ExchangePageBase + 8, ExchangepageAddr); + change_page_font = 8; + } + else + { + rtscheck.RTS_SndData(ExchangePageBase + 35, ExchangepageAddr); + change_page_font = 35; + } + sdcard_pause_check = true; + } + } + + if(1 == READ(CHECK_MATWEIAL)) + { + if(language_change_font != 0) + { + rtscheck.RTS_SndData(11, FILAMENT_LOAD_ICON_VP); + } + else + { + rtscheck.RTS_SndData(9, FILAMENT_LOAD_ICON_VP); + } + } + else if(0 == READ(CHECK_MATWEIAL)) + { + if(language_change_font != 0) + { + rtscheck.RTS_SndData(12, FILAMENT_LOAD_ICON_VP); + } + else + { + rtscheck.RTS_SndData(10, FILAMENT_LOAD_ICON_VP); + } + } + + if(pause_action_flag && printingIsPaused() && !planner.has_blocks_queued()) + { + pause_action_flag = false; + queue.enqueue_now_P(PSTR("G1 X0 Y0 F3000 ")); + } + + if(last_target_temperature_bed != thermalManager.temp_bed.target || (last_target_temperature[0] != thermalManager.temp_hotend[0].target)) + { + thermalManager.setTargetHotend(thermalManager.temp_hotend[0].target, 0); + thermalManager.setTargetBed(thermalManager.temp_bed.target); + rtscheck.RTS_SndData(thermalManager.temp_hotend[0].target, HEAD_SET_TEMP_VP); + rtscheck.RTS_SndData(thermalManager.temp_bed.target, BED_SET_TEMP_VP); + + if(card.isPrinting()) + { + // keep the icon + } + else if(last_target_temperature_bed < thermalManager.temp_bed.target || (last_target_temperature[0] < thermalManager.temp_hotend[0].target)) + { + Update_Time_Value = 0; + } + else if((last_target_temperature_bed > thermalManager.temp_bed.target) || (last_target_temperature[0] > thermalManager.temp_hotend[0].target)) + { + Update_Time_Value = 0; + } + last_target_temperature_bed = thermalManager.temp_bed.target; + last_target_temperature[0] = thermalManager.temp_hotend[0].target; + } + } + ErrorHanding(); + next_rts_update_ms = ms + RTS_UPDATE_INTERVAL + Update_Time_Value; + } +} + +// looping at the loop function +void RTSUpdate() +{ + /* Check the status of card */ + rtscheck.RTS_SDCardUpate(); + + #if CHECKFILEMENT + if((true == card.isPrinting()) && (true == sdcard_pause_check)) + { + if(1 == READ(CHECK_MATWEIAL)) + { + checktime++; + delay(10); + } + else if(0 == READ(CHECK_MATWEIAL)) + { + checktime = 0; + } + + if(checktime > 200) + { + checktime = 0; + pause_z = current_position[Z_AXIS]; + pause_e = current_position[E_AXIS] - 5; + #if ENABLED(POWER_LOSS_RECOVERY) + if (recovery.enabled) recovery.save(true, false); + #endif + if(!temphot) + temphot = thermalManager.degTargetHotend(0); + if(!tempbed) + tempbed = thermalManager.degTargetBed(); + + queue.inject_P(PSTR("M25")); + + Update_Time_Value = 0; + if(language_change_font != 0) + { + rtscheck.RTS_SndData(ExchangePageBase + 7, ExchangepageAddr); + change_page_font = 7; + } + else + { + rtscheck.RTS_SndData(ExchangePageBase + 34, ExchangepageAddr); + change_page_font = 34; + } + sdcard_pause_check = false; + pause_action_flag = true; + } + } + #endif + + EachMomentUpdate(); + + // wait to receive massage and response + if(rtscheck.RTS_RecData() > 0) + { + rtscheck.RTS_HandleData(); + } +} + +void ErrorHanding() +{ + if(errorway) + { + if(errornum < Retry_num) // try again 3 times + { + errornum++; + if(errorway == 1) + { + errorway = errornum = 0; // don't try again + + } + else if(errorway == 2) + { + // No processing is done in printing + if(!printingIsActive() && !printingIsPaused()) + { + errorway = 0; + waitway = 4; + queue.enqueue_now_P(PSTR("G28")); + rtscheck.RTS_SndData(1, MOTOR_FREE_ICON_VP); + Update_Time_Value = 0; + } + } + else if(errorway == 3) + { + reset_bed_level(); + errorway = errornum = 0; // don't try again + } + } + else + { + errorway = errornum = 0; + } + } +} \ No newline at end of file diff --git a/Marlin/src/lcd/dwin/LCD_RTS.h b/Marlin/src/lcd/dwin/LCD_RTS.h new file mode 100644 index 000000000000..387df15d2d28 --- /dev/null +++ b/Marlin/src/lcd/dwin/LCD_RTS.h @@ -0,0 +1,253 @@ +#ifndef RTS_H +#define RTS_H + +#include "string.h" +#include + +#include "i2c_eeprom.h" + +/*********************************/ +#define FHONE (0x5A) +#define FHTWO (0xA5) +#define FHLENG (0x06) +#define TEXTBYTELEN 18 +#define MaxFileNumber 20 + +#define AUTO_BED_LEVEL_PREHEAT 120 + +#define FileNum MaxFileNumber +#define FileNameLen TEXTBYTELEN +#define RTS_UPDATE_INTERVAL 2000 +#define RTS_UPDATE_VALUE RTS_UPDATE_INTERVAL + +#define SizeofDatabuf 26 + +#define FONT_EEPROM 0 +#define Z_VALUE_EEPROM 500 + +#define Retry_num 2 + +/*************Register and Variable addr*****************/ +#define RegAddr_W 0x80 +#define RegAddr_R 0x81 +#define VarAddr_W 0x82 +#define VarAddr_R 0x83 +#define ExchangePageBase ((unsigned long)0x5A010000) // the first page ID. other page = first page ID + relevant num; +#define StartSoundSet ((unsigned long)0x060480A0) // 06,start-music; 04, 4 musics; 80, the volume value; 04, return value about music number. + +/*Error value*/ +#define Error_201 "201 (Command Timeout)" // The command too much inactive time +#define Error_202 "202 (Homing Failed)" // Homing Failed +#define Error_203 "203 (Probing Failed)" // Probing Failed + +/*variable addr*/ +#define ExchangepageAddr 0x0084 +#define SoundAddr 0x00A0 +#define START_PROCESS_ICON_VP 0x1000 +#define PRINT_SPEED_RATE_VP 0x1006 +#define PRINT_PROCESS_TITLE_VP 0x100E +#define PRINT_TIME_HOUR_VP 0x1010 +#define PRINT_TIME_MIN_VP 0x1012 +#define PRINT_PROCESS_VP 0x1016 +#define SYSTEM_LANGUAGE_TEXT_VP 0x101D +#define PRINTER_FANOPEN_TITLE_VP 0x101E +#define PRINTER_LEDOPEN_TITLE_VP 0x101F +#define AUTO_BED_LEVEL_ZOFFSET_VP 0x1026 +#define HEAD_SET_TEMP_VP 0x1034 +#define HEAD_CURRENT_TEMP_VP 0x1036 +#define BED_SET_TEMP_VP 0x103A +#define BED_CURRENT_TEMP_VP 0x103C +#define AXIS_X_COORD_VP 0x1048 +#define AXIS_Y_COORD_VP 0x104A +#define AXIS_Z_COORD_VP 0x104C +#define HEAD_FILAMENT_LOAD_DATA_VP 0x1054 +#define PRINTER_MACHINE_TEXT_VP 0x1060 +#define PRINTER_VERSION_TEXT_VP 0x106A +#define PRINTER_PRINTSIZE_TEXT_VP 0x1074 +#define PRINTER_WEBSITE_TEXT_VP 0x107E +#define AUTO_BED_PREHEAT_HEAD_DATA_VP 0x108A +#define AUTO_BED_LEVEL_TITLE_VP 0x108D +#define FILAMENT_LOAD_ICON_VP 0x108E +#define FAN_SPEED_CONTROL_DATA_VP 0x1100 +#define PLA_HEAD_SET_DATA_VP 0x1102 +#define PLA_BED_SET_DATA_VP 0x1104 +#define PLA_FAN_SET_DATA_VP 0x1106 +#define ABS_HEAD_SET_DATA_VP 0x1108 +#define ABS_BED_SET_DATA_VP 0x110A +#define ABS_FAN_SET_DATA_VP 0x110C +#define ABNORMAL_TEXT_VP 0X1110 +#define MOTOR_FREE_ICON_VP 0x1200 +#define CONTINUE_PRINT_FILE_TEXT_VP 0x2000 + +#define FILE1_SELECT_ICON_VP 0x1221 +#define FILE2_SELECT_ICON_VP 0x1222 +#define FILE3_SELECT_ICON_VP 0x1223 +#define FILE4_SELECT_ICON_VP 0x1224 +#define FILE5_SELECT_ICON_VP 0x1225 +#define FILE6_SELECT_ICON_VP 0x1226 +#define FILE7_SELECT_ICON_VP 0x1227 +#define FILE8_SELECT_ICON_VP 0x1228 +#define FILE9_SELECT_ICON_VP 0x1229 +#define FILE10_SELECT_ICON_VP 0x122A +#define FILE11_SELECT_ICON_VP 0x122B +#define FILE12_SELECT_ICON_VP 0x122C +#define FILE13_SELECT_ICON_VP 0x122D +#define FILE14_SELECT_ICON_VP 0x122E +#define FILE15_SELECT_ICON_VP 0x122F +#define FILE16_SELECT_ICON_VP 0x1230 +#define FILE17_SELECT_ICON_VP 0x1231 +#define FILE18_SELECT_ICON_VP 0x1232 +#define FILE19_SELECT_ICON_VP 0x1233 +#define FILE20_SELECT_ICON_VP 0x1234 +#define FILE1_TEXT_VP 0x200A +#define FILE2_TEXT_VP 0x2014 +#define FILE3_TEXT_VP 0x201E +#define FILE4_TEXT_VP 0x2028 +#define FILE5_TEXT_VP 0x2032 +#define FILE6_TEXT_VP 0x203C +#define FILE7_TEXT_VP 0x2046 +#define FILE8_TEXT_VP 0x2050 +#define FILE9_TEXT_VP 0x205A +#define FILE10_TEXT_VP 0x2064 +#define FILE11_TEXT_VP 0x206E +#define FILE12_TEXT_VP 0x2078 +#define FILE13_TEXT_VP 0x2082 +#define FILE14_TEXT_VP 0x208C +#define FILE15_TEXT_VP 0x2096 +#define FILE16_TEXT_VP 0x20A0 +#define FILE17_TEXT_VP 0x20AA +#define FILE18_TEXT_VP 0x20B4 +#define FILE19_TEXT_VP 0x20BE +#define FILE20_TEXT_VP 0x20C8 +#define FilenameNature 0x6003 + +/************struct**************/ +typedef struct DataBuf +{ + unsigned char len; + unsigned char head[2]; + unsigned char command; + unsigned long addr; + unsigned long bytelen; + unsigned short data[32]; + unsigned char reserv[4]; +} DB; + +typedef struct CardRecord +{ + int recordcount; + int Filesum; + unsigned long addr[FileNum]; + char Cardshowfilename[FileNum][FileNameLen]; + char Cardfilename[FileNum][FileNameLen]; +}CRec; + +extern CRec CardRecbuf; + +class RTSSHOW { + public: + RTSSHOW(); + int RTS_RecData(); + void RTS_SDCardInit(void); + void RTS_SDCardUpate(void); + void RTS_SndData(void); + void RTS_SndData(const String &, unsigned long, unsigned char = VarAddr_W); + void RTS_SndData(const char[], unsigned long, unsigned char = VarAddr_W); + void RTS_SndData(char, unsigned long, unsigned char = VarAddr_W); + void RTS_SndData(unsigned char*, unsigned long, unsigned char = VarAddr_W); + void RTS_SndData(int, unsigned long, unsigned char = VarAddr_W); + void RTS_SndData(float, unsigned long, unsigned char = VarAddr_W); + void RTS_SndData(unsigned int,unsigned long, unsigned char = VarAddr_W); + void RTS_SndData(long,unsigned long, unsigned char = VarAddr_W); + void RTS_SndData(unsigned long,unsigned long, unsigned char = VarAddr_W); + void RTS_SDcard_Stop(); + void RTS_HandleData(); + void RTS_Init(); + + DB recdat; + DB snddat; + private: + unsigned char databuf[SizeofDatabuf]; + }; + +extern RTSSHOW rtscheck; + +enum PROC_COM +{ + MainEnterKey = 0, + AdjustEnterKey = 1, + PrintSpeedEnterKey = 2, + StopPrintKey = 3, + PausePrintKey = 4, + ResumePrintKey = 5, + ZoffsetEnterKey = 6, + TempControlKey = 7, + CoolDownKey = 8, + HeaterTempEnterKey = 9, + HotBedTempEnterKey = 10, + PrepareEnterKey = 11, + BedLevelKey = 12, + AutoHomeKey = 13, + XaxismoveKey = 14, + YaxismoveKey = 15, + ZaxismoveKey = 16, + HeaterLoadEnterKey = 17, + HeaterLoadStartKey = 18, + SelectLanguageKey = 19, + PowerContinuePrintKey = 20, + FanSpeedEnterKey = 21, + PLAHeadSetEnterKey = 22, + PLABedSetEnterKey = 23, + PLAFanSetEnterKey = 24, + ABSHeadSetEnterKey = 25, + ABSBedSetEnterKey = 26, + ABSFanSetEnterKey = 27, + ChangePageKey = 28, + StartFileKey = 29, + SelectFileKey = 30, + ErrorKey = 31, +}; + +const unsigned long Addrbuf[] = +{ + 0x1002, 0x1004, 0x1006, 0x1008, 0x100A, + 0x100C, 0x1026, 0x1030, 0x1032, 0x1034, + 0x103A, 0x103E, 0x1044, 0x1046, 0x1048, + 0x104A, 0x104C, 0x1054, 0x1056, 0x105C, + 0x105F, 0x1100, 0x1102, 0x1104, 0x1106, + 0x1108, 0x110A, 0x110C, 0x110E, 0x20D2, + 0x20D3, 0x111A +}; + +typedef struct +{ + int16_t preheat_hotend_temp[2]; + int16_t preheat_bed_temp[2]; + uint8_t preheat_fan_speed[2]; +}HMI_ValueTypeDef; + +extern HMI_ValueTypeDef HMI_ValueStruct; + +void ErrorHanding(); + +extern void RTSUpdate(); + +extern unsigned int language_change_font; + +extern char waitway; +extern int change_page_font; +extern int Update_Time_Value; +extern unsigned char AxisUnitMode; +extern bool home_flag; +extern bool heat_flag; +extern bool print_finish; +extern bool finish_home; +extern bool AutohomeZflag; +extern char commandbuf[30]; + +extern bool StartPrint_flag; + +extern char errorway; +extern char errornum; + +#endif// RTS_H diff --git a/Marlin/src/lcd/dwin/i2c_eeprom.cpp b/Marlin/src/lcd/dwin/i2c_eeprom.cpp new file mode 100644 index 000000000000..e6a52f97acb1 --- /dev/null +++ b/Marlin/src/lcd/dwin/i2c_eeprom.cpp @@ -0,0 +1,271 @@ +#include "i2c_eeprom.h" +#include + +#include "../../inc/MarlinConfigPre.h" +#include "../../Marlin.h" + + +/******************** IIC ********************/ + +//初始化IIC +void IIC_Init(void) +{ + SET_OUTPUT(IIC_EEPROM_SDA); + SET_OUTPUT(IIC_EEPROM_SCL); + + IIC_SCL_1(); + IIC_SDA_1(); +} + +//产生IIC起始信号 +void IIC_Start(void) +{ + SDA_OUT(); //sda线输出 + IIC_SDA_1(); + IIC_SCL_1(); + delay_us(4); + IIC_SDA_0();//START:when CLK is high,DATA change form high to low + delay_us(4); + IIC_SCL_0();//钳住I2C总线,准备发送或接收数据 +} + +//产生IIC停止信号 +void IIC_Stop(void) +{ + SDA_OUT();//sda线输出 + IIC_SCL_0(); + IIC_SDA_0();//STOP:when CLK is high DATA change form low to high + delay_us(4); + IIC_SCL_1(); + IIC_SDA_1();//发送I2C总线结束信号 + delay_us(4); +} + +//等待应答信号到来 +//返回值:1,接收应答失败 +// 0,接收应答成功 +uint8_t IIC_Wait_Ack(void) +{ + uint8_t ucErrTime=0; + SDA_IN(); //SDA设置为输入 + IIC_SDA_1();delay_us(1); + IIC_SCL_1();delay_us(1); + while(READ_SDA()) + { + ucErrTime++; + if(ucErrTime>250) + { + IIC_Stop(); + return 1; + } + } + IIC_SCL_0();//时钟输出0 + return 0; +} + +//产生ACK应答 +void IIC_Ack(void) +{ + IIC_SCL_0(); + SDA_OUT(); + IIC_SDA_0(); + delay_us(2); + IIC_SCL_1(); + delay_us(2); + IIC_SCL_0(); +} + +//不产生ACK应答 +void IIC_NAck(void) +{ + IIC_SCL_0(); + SDA_OUT(); + IIC_SDA_1(); + delay_us(2); + IIC_SCL_1(); + delay_us(2); + IIC_SCL_0(); +} + +//IIC发送一个字节 +//返回从机有无应答 +//1,有应答 +//0,无应答 +void IIC_Send_Byte(uint8_t txd) +{ + uint8_t t; + SDA_OUT(); + IIC_SCL_0();//拉低时钟开始数据传输 + for(t=0; t<8; t++) + { + // IIC_SDA=(txd&0x80)>>7; + if(txd & 0x80) {IIC_SDA_1();} + else IIC_SDA_0(); + txd <<= 1; + delay_us(2); //对TEA5767这三个延时都是必须的 + IIC_SCL_1(); + delay_us(2); + IIC_SCL_0(); + delay_us(2); + } +} + +//读1个字节,ack=1时,发送ACK,ack=0,发送nACK +uint8_t IIC_Read_Byte(unsigned char ack) +{ + unsigned char i, receive = 0; + SDA_IN();//SDA设置为输入 + for(i=0; i<8; i++) + { + IIC_SCL_0(); + delay_us(2); + IIC_SCL_1(); + receive <<= 1; + if(READ_SDA()) receive++; + delay_us(1); + } + if (!ack) + IIC_NAck();//发送nACK + else + IIC_Ack(); //发送ACK + return receive; +} + + +/******************** EEPROM ********************/ + +//初始化IIC接口 +void BL24CXX_Init(void) +{ + IIC_Init(); +} + +//在BL24CXX指定地址读出一个数据 +//ReadAddr:开始读数的地址 +//返回值 :读到的数据 +uint8_t BL24CXX_ReadOneByte(uint16_t ReadAddr) +{ + uint8_t temp = 0; + IIC_Start(); + if(EE_TYPE>BL24C16) + { + IIC_Send_Byte(0XA0); //发送写命令 + IIC_Wait_Ack(); + IIC_Send_Byte(ReadAddr >> 8);//发送高地址 + IIC_Wait_Ack(); + }else IIC_Send_Byte(0XA0+((ReadAddr/256) << 1)); //发送器件地址0XA0,写数据 + + IIC_Wait_Ack(); + IIC_Send_Byte(ReadAddr%256); //发送低地址 + IIC_Wait_Ack(); + IIC_Start(); + IIC_Send_Byte(0XA1); //进入接收模式 + IIC_Wait_Ack(); + temp = IIC_Read_Byte(0); + IIC_Stop();//产生一个停止条件 + return temp; +} + +//在BL24CXX指定地址写入一个数据 +//WriteAddr :写入数据的目的地址 +//DataToWrite:要写入的数据 +void BL24CXX_WriteOneByte(uint16_t WriteAddr,uint8_t DataToWrite) +{ + IIC_Start(); + if(EE_TYPE>BL24C16) + { + IIC_Send_Byte(0XA0); //发送写命令 + IIC_Wait_Ack(); + IIC_Send_Byte(WriteAddr>>8);//发送高地址 + }else + { + IIC_Send_Byte(0XA0+((WriteAddr/256)<<1)); //发送器件地址0XA0,写数据 + } + IIC_Wait_Ack(); + IIC_Send_Byte(WriteAddr%256); //发送低地址 + IIC_Wait_Ack(); + IIC_Send_Byte(DataToWrite); //发送字节 + IIC_Wait_Ack(); + IIC_Stop();//产生一个停止条件 + delay(2); +} + +//在BL24CXX里面的指定地址开始写入长度为Len的数据 +//该函数用于写入16bit或者32bit的数据. +//WriteAddr :开始写入的地址 +//DataToWrite:数据数组首地址 +//Len :要写入数据的长度2,4 +void BL24CXX_WriteLenByte(uint16_t WriteAddr,uint32_t DataToWrite,uint8_t Len) +{ + uint8_t t; + for(t=0;t>(8*t))&0xff); + } + delay(10); +} + +//在BL24CXX里面的指定地址开始读出长度为Len的数据 +//该函数用于读出16bit或者32bit的数据. +//ReadAddr :开始读出的地址 +//返回值 :数据 +//Len :要读出数据的长度2,4 +uint32_t BL24CXX_ReadLenByte(uint16_t ReadAddr,uint8_t Len) +{ + uint8_t t; + uint32_t temp=0; + for(t=0;t + + +/******************** IIC ********************/ +//IO方向设置 +#define SDA_IN() {PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH&=0XFFFF0FFF;PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH|=8<<12;} +#define SDA_OUT() {PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH&=0XFFFF0FFF;PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH|=3<<12;} + +//IO操作函数 +#define IIC_SCL_0() digitalWrite(IIC_EEPROM_SCL,LOW) +#define IIC_SCL_1() digitalWrite(IIC_EEPROM_SCL,HIGH) +#define IIC_SDA_0() digitalWrite(IIC_EEPROM_SDA,LOW) +#define IIC_SDA_1() digitalWrite(IIC_EEPROM_SDA,HIGH) +#define READ_SDA() READ(IIC_EEPROM_SDA) + +//IIC所有操作函数 +void IIC_Init(void); //初始化IIC的IO口 +void IIC_Start(void); //发送IIC开始信号 +void IIC_Stop(void); //发送IIC停止信号 +void IIC_Send_Byte(uint8_t txd); //IIC发送一个字节 +uint8_t IIC_Read_Byte(unsigned char ack);//IIC读取一个字节 +uint8_t IIC_Wait_Ack(void); //IIC等待ACK信号 +void IIC_Ack(void); //IIC发送ACK信号 +void IIC_NAck(void); //IIC不发送ACK信号 + +void IIC_Write_One_Byte(uint8_t daddr,uint8_t addr,uint8_t data); +uint8_t IIC_Read_One_Byte(uint8_t daddr,uint8_t addr); + + +/******************** EEPROM ********************/ +#define BL24C01 127 +#define BL24C02 255 +#define BL24C04 511 +#define BL24C08 1023 +#define BL24C16 2047 +#define BL24C32 4095 +#define BL24C64 8191 +#define BL24C128 16383 +#define BL24C256 32767 +#define EE_TYPE BL24C16 + +uint8_t BL24CXX_ReadOneByte(uint16_t ReadAddr); //指定地址读取一个字节 +void BL24CXX_WriteOneByte(uint16_t WriteAddr,uint8_t DataToWrite); //指定地址写入一个字节 +void BL24CXX_WriteLenByte(uint16_t WriteAddr,uint32_t DataToWrite,uint8_t Len);//指定地址开始写入指定长度的数据 +uint32_t BL24CXX_ReadLenByte(uint16_t ReadAddr,uint8_t Len); //指定地址开始读取指定长度数据 +void BL24CXX_Write(uint16_t WriteAddr,uint8_t *pBuffer,uint16_t NumToWrite); //从指定地址开始写入指定长度的数据 +void BL24CXX_Read(uint16_t ReadAddr,uint8_t *pBuffer,uint16_t NumToRead); //从指定地址开始读出指定长度的数据 + +uint8_t BL24CXX_Check(void); //检查器件 +void BL24CXX_Init(void); //初始化IIC + + +#endif + diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 5199f90ea01a..992cf93ec9a1 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -145,7 +145,7 @@ void menu_advanced_settings(); EDIT_ITEM_FAST(float41sign, MSG_HOTEND_OFFSET_Y, &hotend_offset[1].y, -99.0, 99.0, _recalc_offsets); EDIT_ITEM_FAST(float41sign, MSG_HOTEND_OFFSET_Z, &hotend_offset[1].z, Z_PROBE_LOW_POINT, 10.0, _recalc_offsets); #if ENABLED(EEPROM_SETTINGS) - ACTION_ITEM(MSG_STORE_EEPROM, lcd_store_settings); + ACTION_ITEM(, lcd_store_settings); #endif END_MENU(); } diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index fdd851c170b3..96f6f4ba2286 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -50,7 +50,13 @@ #include "planner.h" #include "stepper.h" #include "temperature.h" -#include "../lcd/ultralcd.h" +#ifdef DWIN_LCDDISPLAY + #include "../lcd/dwin/dwin.h" +#elif ENABLED(RTS_AVAILABLE) + #include "../lcd/dwin/LCD_RTS.h" +#else + #include "../lcd/ultralcd.h" +#endif #include "../core/language.h" #include "../libs/vector_3.h" // for matrix_3x3 #include "../gcode/gcode.h" @@ -770,6 +776,10 @@ void MarlinSettings::postprocess() { const int16_t (&ui_preheat_hotend_temp)[2] = ui.preheat_hotend_temp, (&ui_preheat_bed_temp)[2] = ui.preheat_bed_temp; const uint8_t (&ui_preheat_fan_speed)[2] = ui.preheat_fan_speed; + #elif ENABLED(DWIN_LCDDISPLAY) || ENABLED(RTS_AVAILABLE) + const int16_t (&ui_preheat_hotend_temp)[2] = HMI_ValueStruct.preheat_hotend_temp, + (&ui_preheat_bed_temp)[2] = HMI_ValueStruct.preheat_bed_temp; + const uint8_t (&ui_preheat_fan_speed)[2] = HMI_ValueStruct.preheat_fan_speed; #else constexpr int16_t ui_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND }, ui_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED }; @@ -1575,7 +1585,11 @@ void MarlinSettings::postprocess() { int16_t (&ui_preheat_hotend_temp)[2] = ui.preheat_hotend_temp, (&ui_preheat_bed_temp)[2] = ui.preheat_bed_temp; uint8_t (&ui_preheat_fan_speed)[2] = ui.preheat_fan_speed; - #else + #elif ENABLED(DWIN_LCDDISPLAY) || ENABLED(RTS_AVAILABLE) + int16_t (&ui_preheat_hotend_temp)[2] = HMI_ValueStruct.preheat_hotend_temp, + (&ui_preheat_bed_temp)[2] = HMI_ValueStruct.preheat_bed_temp; + uint8_t (&ui_preheat_fan_speed)[2] = HMI_ValueStruct.preheat_fan_speed; + #else int16_t ui_preheat_hotend_temp[2], ui_preheat_bed_temp[2]; uint8_t ui_preheat_fan_speed[2]; #endif @@ -2430,8 +2444,14 @@ void MarlinSettings::reset() { // // Preheat parameters // - - #if HOTENDS && HAS_LCD_MENU + #if ENABLED(DWIN_LCDDISPLAY) || ENABLED(RTS_AVAILABLE) + HMI_ValueStruct.preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND; + HMI_ValueStruct.preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND; + HMI_ValueStruct.preheat_bed_temp[0] = PREHEAT_1_TEMP_BED; + HMI_ValueStruct.preheat_bed_temp[1] = PREHEAT_2_TEMP_BED; + HMI_ValueStruct.preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED; + HMI_ValueStruct.preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED; + #elif HOTENDS && HAS_LCD_MENU ui.preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND; ui.preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND; ui.preheat_bed_temp[0] = PREHEAT_1_TEMP_BED; diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index cbe274a6921a..91f409c15897 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -31,6 +31,9 @@ #include "../sd/cardreader.h" #include "temperature.h" #include "../lcd/ultralcd.h" +#ifdef RTS_AVAILABLE + #include "../lcd/dwin/LCD_RTS.h" +#endif #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) #include HAL_PATH(../HAL, endstop_interrupts.h) @@ -302,7 +305,18 @@ void Endstops::not_homing() { // If the last move failed to trigger an endstop, call kill void Endstops::validate_homing_move() { if (trigger_state()) hit_on_purpose(); - else kill(GET_TEXT(MSG_LCD_HOMING_FAILED)); + else + { + #ifdef RTS_AVAILABLE + waitway = 0; + rtscheck.RTS_SndData(ExchangePageBase + 62, ExchangepageAddr); + change_page_font = 62; + rtscheck.RTS_SndData(Error_202, ABNORMAL_TEXT_VP); + errorway = 2; + #else + kill(GET_TEXT(MSG_LCD_HOMING_FAILED)); + #endif + } } #endif diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 484d6a077a1d..7bc3835fdfa6 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -38,6 +38,7 @@ #include "../libs/buzzer.h" #include "../lcd/ultralcd.h" #endif +#include "../lcd/dwin/LCD_RTS.h" #if HAS_BED_PROBE #include "probe.h" @@ -1249,6 +1250,13 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t DEBUG_ECHOLNPGM(")"); } + #if ENABLED(FIX_MOUNTED_PROBE) + if((axis == Z_AXIS) && (1 == READ(OPTO_SWITCH_PIN))) + { + set_probe_deployed(false); + } + #endif + #if HOMING_Z_WITH_PROBE && HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER) // Wait for bed to heat back up between probing points if (axis == Z_AXIS && distance < 0 && thermalManager.isHeatingBed()) { @@ -1496,6 +1504,13 @@ void homeaxis(const AxisEnum axis) { } #endif + #if ENABLED(FIX_MOUNTED_PROBE) + if(axis == Z_AXIS) + { + AutohomeZflag = true; + } + #endif + // Fast move towards endstop until triggered if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Home 1 Fast:"); diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 2e8ff64f52ec..6394ab28537d 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -135,7 +135,7 @@ XYZ_DEFS(signed char, home_dir, HOME_DIR); extern xyz_pos_t hotend_offset[HOTENDS]; void reset_hotend_offsets(); #elif HOTENDS - constexpr xyz_pos_t hotend_offset[HOTENDS] = { { 0 } }; + constexpr xyz_pos_t hotend_offset[HOTENDS] = { { 0 } }; // BLtouch offset --2019-12-19 #else constexpr xyz_pos_t hotend_offset[1] = { { 0 } }; #endif diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index eaabd687f6a8..1017cc78cd15 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -37,6 +37,9 @@ #include "../gcode/gcode.h" #include "../lcd/ultralcd.h" +#ifdef RTS_AVAILABLE + #include "../lcd/dwin/LCD_RTS.h" +#endif #include "../Marlin.h" // for stop(), disable_e_steppers, wait_for_user @@ -578,6 +581,17 @@ static float run_z_probe() { float probes[TOTAL_PROBING]; #endif + #if ENABLED(FIX_MOUNTED_PROBE) + if((0 == READ(OPTO_SWITCH_PIN)) && (AutohomeZflag == true)) + { + digitalWrite(COM_PIN, HIGH); + delay(200); + digitalWrite(COM_PIN, LOW); + delay(200); + AutohomeZflag = false; + } + #endif + #if TOTAL_PROBING > 2 float probes_total = 0; for ( @@ -715,6 +729,15 @@ float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_ // Move the probe to the starting XYZ do_blocking_move_to(npos); + #ifdef FIX_MOUNTED_PROBE + if(0 == READ(OPTO_SWITCH_PIN)) + { + delay(100); + WRITE(COM_PIN, 0); + delay(200); + } + #endif + float measured_z = NAN; if (!DEPLOY_PROBE()) { measured_z = run_z_probe() + probe_offset.z; @@ -726,6 +749,10 @@ float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_ if (STOW_PROBE()) measured_z = NAN; } + #ifdef FIX_MOUNTED_PROBE + WRITE(COM_PIN, 1); + #endif + if (verbose_level > 2) { SERIAL_ECHOPAIR_F("Bed X: ", LOGICAL_X_POSITION(rx), 3); SERIAL_ECHOPAIR_F(" Y: ", LOGICAL_Y_POSITION(ry), 3); @@ -735,6 +762,13 @@ float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_ feedrate_mm_s = old_feedrate_mm_s; if (isnan(measured_z)) { + #if ENABLED(RTS_AVAILABLE) + waitway = 0; + rtscheck.RTS_SndData(ExchangePageBase + 62, ExchangepageAddr); + change_page_font = 62; + rtscheck.RTS_SndData(Error_203, ABNORMAL_TEXT_VP); + errorway = 3; + #endif STOW_PROBE(); LCD_MESSAGEPGM(MSG_LCD_PROBING_FAILED); SERIAL_ERROR_MSG(MSG_ERR_PROBING_FAILED); diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index daaa008bf926..a386b38a552b 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -29,6 +29,11 @@ #include "../Marlin.h" #include "../lcd/ultralcd.h" +#ifdef DWIN_LCDDISPLAY + #include "../lcd/dwin/dwin.h" +#elif ENABLED(RTS_AVAILABLE) + #include "../lcd/dwin/LCD_RTS.h" +#endif #include "planner.h" #include "../core/language.h" #include "../HAL/shared/Delay.h" @@ -541,10 +546,20 @@ volatile bool Temperature::temp_meas_ready = false; if (current_temp > watch_temp_target) heated = true; // - Flag if target temperature reached } else if (ELAPSED(ms, temp_change_ms)) // Watch timer expired + { + #ifdef DWIN_LCDDISPLAY + Popup_Window_Temperation(2); + #endif _temp_error(heater, PSTR(MSG_T_HEATING_FAILED), GET_TEXT(MSG_HEATING_FAILED_LCD)); + } } else if (current_temp < target - (MAX_OVERSHOOT_PID_AUTOTUNE)) // Heated, then temperature fell too far? + { + #ifdef DWIN_LCDDISPLAY + Popup_Window_Temperation(2); + #endif _temp_error(heater, PSTR(MSG_T_THERMAL_RUNAWAY), GET_TEXT(MSG_THERMAL_RUNAWAY)); + } } #endif } // every 2 seconds @@ -554,6 +569,10 @@ volatile bool Temperature::temp_meas_ready = false; #define MAX_CYCLE_TIME_PID_AUTOTUNE 20L #endif if (((ms - t1) + (ms - t2)) > (MAX_CYCLE_TIME_PID_AUTOTUNE * 60L * 1000L)) { + #ifdef RTS_AVAILABLE + rtscheck.RTS_SndData(ExchangePageBase + 58, ExchangepageAddr); + change_page_font = 58; + #endif SERIAL_ECHOLNPGM(MSG_PID_TIMEOUT); break; } @@ -605,7 +624,13 @@ volatile bool Temperature::temp_meas_ready = false; goto EXIT_M303; } - ui.update(); + #ifdef DWIN_LCDDISPLAY + DWIN_Update(); + #elif ENABLED(RTS_AVAILABLE) + RTSUpdate(); + #else + ui.update(); + #endif } disable_all_heaters(); @@ -801,10 +826,22 @@ void Temperature::_temp_error(const heater_ind_t heater, PGM_P const serial_msg, } void Temperature::max_temp_error(const heater_ind_t heater) { + #ifdef DWIN_LCDDISPLAY + Popup_Window_Temperation(1); + #elif ENABLED(RTS_AVAILABLE) + rtscheck.RTS_SndData(ExchangePageBase + 59, ExchangepageAddr); + change_page_font = 59; + #endif _temp_error(heater, PSTR(MSG_T_MAXTEMP), GET_TEXT(MSG_ERR_MAXTEMP)); } void Temperature::min_temp_error(const heater_ind_t heater) { + #ifdef DWIN_LCDDISPLAY + Popup_Window_Temperation(0); + #elif ENABLED(RTS_AVAILABLE) + rtscheck.RTS_SndData(ExchangePageBase + 59, ExchangepageAddr); + change_page_font = 59; + #endif _temp_error(heater, PSTR(MSG_T_MINTEMP), GET_TEXT(MSG_ERR_MINTEMP)); } @@ -1040,7 +1077,12 @@ void Temperature::manage_heater() { HOTEND_LOOP() { #if ENABLED(THERMAL_PROTECTION_HOTENDS) if (degHotend(e) > temp_range[e].maxtemp) + { + #ifdef DWIN_LCDDISPLAY + Popup_Window_Temperation(1); + #endif _temp_error((heater_ind_t)e, PSTR(MSG_T_THERMAL_RUNAWAY), GET_TEXT(MSG_THERMAL_RUNAWAY)); + } #endif #if HEATER_IDLE_HANDLER @@ -1058,7 +1100,15 @@ void Temperature::manage_heater() { // Make sure temperature is increasing if (watch_hotend[e].next_ms && ELAPSED(ms, watch_hotend[e].next_ms)) { // Time to check this extruder? if (degHotend(e) < watch_hotend[e].target) // Failed to increase enough? + { + #ifdef DWIN_LCDDISPLAY + Popup_Window_Temperation(0); + #elif ENABLED(RTS_AVAILABLE) + rtscheck.RTS_SndData(ExchangePageBase + 58, ExchangepageAddr); + change_page_font = 58; + #endif _temp_error((heater_ind_t)e, PSTR(MSG_T_HEATING_FAILED), GET_TEXT(MSG_HEATING_FAILED_LCD)); + } else // Start again if the target is still far off start_watching_hotend(e); } @@ -1093,14 +1143,27 @@ void Temperature::manage_heater() { #if ENABLED(THERMAL_PROTECTION_BED) if (degBed() > BED_MAXTEMP) + { + #ifdef DWIN_LCDDISPLAY + Popup_Window_Temperation(1); + #endif _temp_error(H_BED, PSTR(MSG_T_THERMAL_RUNAWAY), GET_TEXT(MSG_THERMAL_RUNAWAY)); + } #endif #if WATCH_BED // Make sure temperature is increasing if (watch_bed.elapsed(ms)) { // Time to check the bed? if (degBed() < watch_bed.target) // Failed to increase enough? + { + #ifdef DWIN_LCDDISPLAY + Popup_Window_Temperation(0); + #elif ENABLED(RTS_AVAILABLE) + rtscheck.RTS_SndData(ExchangePageBase + 58, ExchangepageAddr); + change_page_font = 58; + #endif _temp_error(H_BED, PSTR(MSG_T_HEATING_FAILED), GET_TEXT(MSG_HEATING_FAILED_LCD)); + } else // Start again if the target is still far off start_watching_bed(); } @@ -1959,6 +2022,12 @@ void Temperature::init() { sm.state = TRRunaway; case TRRunaway: + #ifdef DWIN_LCDDISPLAY + Popup_Window_Temperation(2); + #elif ENABLED(RTS_AVAILABLE) + rtscheck.RTS_SndData(ExchangePageBase + 57, ExchangepageAddr); + change_page_font = 57; + #endif _temp_error(heater_id, PSTR(MSG_T_THERMAL_RUNAWAY), GET_TEXT(MSG_THERMAL_RUNAWAY)); } } @@ -2338,6 +2407,8 @@ HAL_TEMP_TIMER_ISR() { Temperature::tick(); + HAL_watchdog_refresh(); + HAL_timer_isr_epilogue(TEMP_TIMER_NUM); } @@ -2986,7 +3057,27 @@ void Temperature::tick() { } while (wait_for_heatup && TEMP_CONDITIONS); if (wait_for_heatup) { - ui.reset_status(); + if(heat_flag && printingIsActive()) + { + if(language_change_font != 0) + { + rtscheck.RTS_SndData(ExchangePageBase + 10, ExchangepageAddr); + change_page_font = 10; + } + else + { + rtscheck.RTS_SndData(ExchangePageBase + 37, ExchangepageAddr); + change_page_font = 37; + } + } + heat_flag = 0; + #ifdef DWIN_LCDDISPLAY + HMI_flag.heat_flag = 0; + duration_t elapsed = print_job_timer.duration(); // print timer + heat_time = elapsed.value; + #else + ui.reset_status(); + #endif #if ENABLED(PRINTER_EVENT_LEDS) printerEventLEDs.onHeatingDone(); #endif diff --git a/Marlin/src/pins/pins.h b/Marlin/src/pins/pins.h index e917c09c9395..0a7658e5d21d 100644 --- a/Marlin/src/pins/pins.h +++ b/Marlin/src/pins/pins.h @@ -487,6 +487,8 @@ #include "stm32/pins_FYSETC_CHEETAH_V12.h" // STM32F1 env:STM32F103RC_fysetc #elif MB(LONGER3D_LK) #include "stm32/pins_LONGER3D_LK.h" // STM32F1 env:STM32F103VE_longer +#elif MB(CREALITY) + #include "stm32/pins_CREALITY.h" // STM32F1 env:creality // // ARM Cortex-M4F diff --git a/Marlin/src/pins/stm32/pins_CREALITY.h b/Marlin/src/pins/stm32/pins_CREALITY.h new file mode 100644 index 000000000000..012508a1a088 --- /dev/null +++ b/Marlin/src/pins/stm32/pins_CREALITY.h @@ -0,0 +1,191 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2016 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 . + * + */ + +/** + * CREALITY (STM32F103) board pin assignments + */ + +#ifndef __STM32F1__ + #error "Oops! Select an STM32F1 board in 'Tools > Board.'" +#endif + +#if HOTENDS > 1 || E_STEPPERS > 1 + #error "CREALITY supports up to 1 hotends / E-steppers. Comment out this line to continue." +#endif + +#define BOARD_NAME "CREALITY" + +// +// EEPROM +// +/* I2C */ +// #define I2C_EEPROM +// #define E2END 0x3FFF // 16Kb (24c16) +#define MYI2C_EEPROM // EEPROM on I2C-0 +#define IIC_EEPROM_SDA PA11 +#define IIC_EEPROM_SCL PA12 + +/* SPI */ +//#define SPI_EEPROM // EEPROM on SPI-0 +//#define SPI_CHAN_EEPROM1 ? +//#define SPI_EEPROM1_CS ? +// 2K EEPROM +//#define SPI_EEPROM2_CS ? +// 32Mb FLASH +//#define SPI_FLASH_CS ? + +/* FLASH */ +// Enable EEPROM Emulation for this board +// This setting should probably be in configuration.h +// but it is literally the only board which uses it. +//#define FLASH_EEPROM_EMULATION + + +// +// Limit Switches +// +#define X_MIN_PIN PC4 +// #define X_MAX_PIN PA7 +#define Y_MIN_PIN PC5 +#ifdef BLTOUCH + #define Z_MIN_PIN PB1 // BLTouch IN PIN + #define SERVO0_PIN PB0 // BLTouch OUT PIN +#elif ENABLED(FIX_MOUNTED_PROBE) + #define Z_MIN_PIN PA4 + #define COM_PIN PA5 +#else + #define Z_MIN_PIN PA7 +#endif + +// +// Steppers +// +#define X_ENABLE_PIN PC3 +#define X_STEP_PIN PB8 +#define X_DIR_PIN PB7 + +#define Y_ENABLE_PIN PC3 +#define Y_STEP_PIN PB6 +#define Y_DIR_PIN PB5 + +#define Z_ENABLE_PIN PC3 +#define Z_STEP_PIN PB4 +#define Z_DIR_PIN PB3 + +#define E0_ENABLE_PIN PC3 +#define E0_STEP_PIN PC2 +#define E0_DIR_PIN PB9 + +#if HAS_TMC220x + + // + // TMC2208 mode + // + // #define TMC2208_STANDALONE + + #define X_HARDWARE_SERIAL MSerial2 + #define Y_HARDWARE_SERIAL MSerial2 + #define Z_HARDWARE_SERIAL MSerial2 + #define E0_HARDWARE_SERIAL MSerial2 + + // + // TMC2208 Software serial + // + // #define HAVE_SW_SERIAL + + // Reduce baud rate to improve software serial reliability + // #define TMC_BAUD_RATE 19200 + +#endif + +// +// Release PB4 (Z_STEP_PIN) from JTAG NRST role +// +#define DISABLE_DEBUG + +// +// Temperature Sensors +// +#define TEMP_0_PIN PB1 // TH1 +#define TEMP_BED_PIN PB0 // TB1 + +// +// Heaters / Fans +/*certification*/ +// #define HEATER_0_PIN PB14 // HEATER1 +// #define HEATER_BED_PIN PB13 // HOT BED + +// #define FAN_PIN PB15 // FAN +// #define FAN_SOFT_PWM + +#define HEATER_0_PIN PA1 // HEATER1 +#define HEATER_BED_PIN PA2 // HOT BED + +#define FAN_PIN PA0 // FAN +#define FAN_SOFT_PWM + + +/* RET6 12864 LCD */ +// #define LCD_PINS_RS PB12 +// #define LCD_PINS_ENABLE PB15 +// #define LCD_PINS_D4 PB13 + +// #define BTN_ENC PB2 +// #define BTN_EN1 PB10 +// #define BTN_EN2 PB14 + +// #define BEEPER_PIN PC6 + + +/* VET6 12864 LCD */ +// #define LCD_PINS_RS PA4 +// #define LCD_PINS_ENABLE PA7 +// #define LCD_PINS_D4 PA5 + +// #define BTN_ENC PC5 +// #define BTN_EN1 PB10 +// #define BTN_EN2 PA6 + + +/* RET6 DWIN ENCODER LCD */ +// #define BTN_ENC PB14 +// #define BTN_EN1 PB15 +// #define BTN_EN2 PB12 + +// #define BEEPER_PIN PB13 + + +/* VET6 DWIN ENCODER LCD */ +// #define BTN_ENC PA6 +// #define BTN_EN1 PA7 +// #define BTN_EN2 PA4 + +// #define BEEPER_PIN PA5 + + +/* SD card detect */ +#define SD_DETECT_PIN PC7 + +#define LED_CONTROL_PIN PA6 +#define CHECK_MATWEIAL PA7 +// #define OPTO_SWITCH_PIN PB2 // certification +#define OPTO_SWITCH_PIN PC6 diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index a0cb19b95d8a..327a0348a620 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -28,6 +28,11 @@ #include "../Marlin.h" #include "../lcd/ultralcd.h" +#ifdef DWIN_LCDDISPLAY + #include "../lcd/dwin/dwin.h" +#endif +#include "../lcd/dwin/i2c_eeprom.h" + #include "../module/planner.h" #include "../module/printcounter.h" #include "../core/language.h" @@ -354,6 +359,7 @@ void CardReader::printFilename() { } void CardReader::mount() { + delay(200); // Power on flag.mounted = false; if (root.isOpen()) root.close(); @@ -1044,6 +1050,10 @@ void CardReader::printingHasFinished() { else { stopSDPrint(); + #ifdef DWIN_LCDDISPLAY + HMI_flag.print_finish = 1; + #endif + #if ENABLED(POWER_LOSS_RECOVERY) removeJobRecoveryFile(); #endif @@ -1107,14 +1117,19 @@ void CardReader::printingHasFinished() { // the file being printed, so during SD printing the file should // be zeroed and written instead of deleted. void CardReader::removeJobRecoveryFile() { - if (jobRecoverFileExists()) { + #ifdef EEPROM_PLR recovery.init(); - removeFile(recovery.filename); - #if ENABLED(DEBUG_POWER_LOSS_RECOVERY) - SERIAL_ECHOPGM("Power-loss file delete"); - serialprintPGM(jobRecoverFileExists() ? PSTR(" failed.\n") : PSTR("d.\n")); - #endif - } + BL24CXX_Write(PLR_ADDR, (uint8_t*)&recovery.info, sizeof(recovery.info)); + #else + if (jobRecoverFileExists()) { + recovery.init(); + removeFile(recovery.filename); + #if ENABLED(DEBUG_POWER_LOSS_RECOVERY) + SERIAL_ECHOPGM("Power-loss file delete"); + serialprintPGM(jobRecoverFileExists() ? PSTR(" failed.\n") : PSTR("d.\n")); + #endif + } + #endif } #endif // POWER_LOSS_RECOVERY diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index 8ef8dbeae31a..521b9d9155f9 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -146,6 +146,7 @@ class CardReader { static inline bool isFileOpen() { return isMounted() && file.isOpen(); } static inline uint32_t getIndex() { return sdpos; } + static inline uint32_t getfilesize() { return filesize; } static inline bool eof() { return sdpos >= filesize; } static inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); } static inline char* getWorkDirName() { workDir.getDosName(filename); return filename; } @@ -275,9 +276,9 @@ class CardReader { #define IS_SD_INSERTED() Sd2Card::isInserted() #elif PIN_EXISTS(SD_DETECT) #if ENABLED(SD_DETECT_INVERTED) - #define IS_SD_INSERTED() READ(SD_DETECT_PIN) - #else #define IS_SD_INSERTED() !READ(SD_DETECT_PIN) + #else + #define IS_SD_INSERTED() READ(SD_DETECT_PIN) #endif #else // No card detect line? Assume the card is inserted. diff --git a/buildroot/share/PlatformIO/ldscripts/creality.ld b/buildroot/share/PlatformIO/ldscripts/creality.ld new file mode 100644 index 000000000000..785345543c0c --- /dev/null +++ b/buildroot/share/PlatformIO/ldscripts/creality.ld @@ -0,0 +1,14 @@ +MEMORY +{ + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K - 40 + rom (rx) : ORIGIN = 0x08007000, LENGTH = 512K - 28K +} + +/* Provide memory region aliases for common.inc */ +REGION_ALIAS("REGION_TEXT", rom); +REGION_ALIAS("REGION_DATA", ram); +REGION_ALIAS("REGION_BSS", ram); +REGION_ALIAS("REGION_RODATA", rom); + +/* Let common.inc handle the real work. */ +INCLUDE common.inc diff --git a/buildroot/share/PlatformIO/scripts/creality.py b/buildroot/share/PlatformIO/scripts/creality.py new file mode 100644 index 000000000000..d7b7823356a7 --- /dev/null +++ b/buildroot/share/PlatformIO/scripts/creality.py @@ -0,0 +1,16 @@ +import os +Import("env") + +# Relocate firmware from 0x08000000 to 0x08007000 +for define in env['CPPDEFINES']: + if define[0] == "VECT_TAB_ADDR": + env['CPPDEFINES'].remove(define) +env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08007000")) + +custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/creality.ld") +for i, flag in enumerate(env["LINKFLAGS"]): + if "-Wl,-T" in flag: + env["LINKFLAGS"][i] = "-Wl,-T" + custom_ld_script + elif flag == "-T": + env["LINKFLAGS"][i + 1] = custom_ld_script + diff --git a/platformio.ini b/platformio.ini index 57d72e6bd483..1bae5b0bc3b3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,7 +18,7 @@ [platformio] src_dir = Marlin boards_dir = buildroot/share/PlatformIO/boards -default_envs = megaatmega2560 +default_envs = creality [common] default_src_filter = + - - + @@ -412,6 +412,18 @@ build_flags = !python Marlin/src/HAL/HAL_STM32F1/build_flags.py build_unflags = -std=gnu++11 -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG= -DERROR_LED_PORT=GPIOE -DERROR_LED_PIN=6 lib_ignore = Adafruit NeoPixel +# +# Creality (STM32F103RET6) +# +[env:creality] +extends = env:STM32F1_base +board = genericSTM32F103RE +extra_scripts = buildroot/share/PlatformIO/scripts/creality.py +build_flags = !python Marlin/src/HAL/HAL_STM32F1/build_flags.py + ${common.build_flags} -std=gnu++14 -DSTM32_XL_DENSITY +debug_tool = jlink +upload_protocol = jlink + # # STM32 HAL environments #