Skip to content

Commit

Permalink
Anycubic Mega Zero custom changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kad committed May 17, 2020
1 parent f75a823 commit 65cc110
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 65 deletions.
4 changes: 4 additions & 0 deletions Marlin/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include "utility.h"
#include "serial.h"

extern char TFTpausingFlag ;



void idle(
#if ENABLED(ADVANCED_PAUSE_FEATURE)
bool no_stepper_sleep = false // pass true to keep steppers from disabling on timeout
Expand Down
70 changes: 64 additions & 6 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,15 @@ uint8_t axis_homed, axis_known_position; // = 0
*/
static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0;

bool is_resume = false ;
char flag_adjusted_level = 0 ;


char TFTpausingFlag=0;//for return a flag that buffer carry out




/**
* GCode Command Queue
* A simple ring buffer of BUFSIZE command strings.
Expand Down Expand Up @@ -3235,8 +3244,11 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa
planner.buffer_line(line_lengths[A_AXIS], line_lengths[B_AXIS], line_lengths[C_AXIS], line_lengths[D_AXIS], current_position[E_CART], fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
#else
sync_plan_position();
if(axis != Z_AXIS ||(axis == Z_AXIS && is_resume==false )) //daxiong dnot go z_home
{
current_position[axis] = distance; // Set delta/cartesian axes directly
planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_CART], fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
}
#endif

planner.synchronize();
Expand All @@ -3247,7 +3259,10 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa
if (axis == Z_AXIS) probing_pause(false);
#endif

endstops.validate_homing_move();
if(axis != Z_AXIS ||(axis == Z_AXIS && is_resume==false )) //daxiong dnot go z_home
{
endstops.validate_homing_move();
}

// Re-enable stealthChop if used. Disable diag1 pin on driver.
#if ENABLED(SENSORLESS_HOMING)
Expand Down Expand Up @@ -3614,6 +3629,8 @@ inline void gcode_G0_G1(
bool fast_move=false
#endif
) {
flag_adjusted_level = 1 ;

if (IsRunning() && G0_G1_CONDITION) {
gcode_get_destination(); // For X Y Z E F

Expand Down Expand Up @@ -4510,7 +4527,7 @@ inline void gcode_G28(const bool always_home_all) {
(parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT)
);

if (z_homing_height && (home_all || homeX || homeY)) {
if (is_resume==false&&z_homing_height && (home_all || homeX || homeY)) {
// Raise Z before homing any other axes and z is not already high enough (never lower z)
destination[Z_AXIS] = z_homing_height;
if (destination[Z_AXIS] > current_position[Z_AXIS]) {
Expand All @@ -4520,7 +4537,7 @@ inline void gcode_G28(const bool always_home_all) {
SERIAL_ECHOLNPAIR("Raise Z (before homing) to ", destination[Z_AXIS]);
#endif

do_blocking_move_to_z(destination[Z_AXIS]);
do_blocking_move_to_z(destination[Z_AXIS]);
}
}

Expand Down Expand Up @@ -4638,6 +4655,13 @@ inline void gcode_G28(const bool always_home_all) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< G28");
#endif

if(is_resume==true)
{
homeaxis(Z_AXIS);
is_resume=false ;
}
flag_adjusted_level = 0 ;
} // G28

void home_all_axes() { gcode_G28(true); }
Expand Down Expand Up @@ -8435,7 +8459,8 @@ inline void gcode_M104() {
#endif

if (parser.seenval('S')) {
const int16_t temp = parser.value_celsius();
int16_t temp = parser.value_celsius();
if(temp>HEATER_0_MAXTEMP)temp = HEATER_0_MAXTEMP;
thermalManager.setTargetHotend(temp, target_extruder);

#if ENABLED(DUAL_X_CARRIAGE)
Expand Down Expand Up @@ -15444,7 +15469,7 @@ void setup() {
#endif

#if ENABLED(POWER_LOSS_RECOVERY)
check_print_job_recovery();
check_print_job_recovery(); //查看是否有断电续打的文件
#endif

#if ENABLED(USE_WATCHDOG)
Expand All @@ -15463,6 +15488,20 @@ void setup() {
#endif
}


void pauseCMDsend()
{
static char temp=0;
if(commands_in_queue < BUFSIZE)
{
temp++;
if(temp==1)enqueue_and_echo_commands_P(PSTR("G91"));
if(temp==2){enqueue_and_echo_commands_P(PSTR("G1 Z+20")); TFTpausingFlag = 3 ;temp=0;}
}
}



/**
* The main Marlin program loop
*
Expand All @@ -15476,6 +15515,12 @@ void setup() {
*/
void loop() {


//暂停 抬高的步�?//1,首先停止SD卡,不允许读新的指令
//2,等待缓存区的指令执行结�?,然后嵌入G91 Z20.0 两个指令
if(TFTpausingFlag==2)pauseCMDsend();//when pause,i need rase z axis,but if i use enquecommand_P,it maybe lose cmd,very dangerous,so i need sent cmd one by one


#if ENABLED(SDSUPPORT)

card.checkautostart();
Expand All @@ -15494,6 +15539,12 @@ void loop() {
for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
#endif
wait_for_heatup = false;

enqueue_and_echo_commands_P(PSTR("G91"));
enqueue_and_echo_commands_P(PSTR("G1 E-5 F1000")); //缩一下料
enqueue_and_echo_commands_P(PSTR("G1 Z20 F6000")); //抬高20mm
enqueue_and_echo_commands_P(PSTR("M84")); //关闭步进电机

#if ENABLED(POWER_LOSS_RECOVERY)
card.removeJobRecoveryFile();
#endif
Expand Down Expand Up @@ -15537,7 +15588,7 @@ void loop() {
else {
process_next_command();
#if ENABLED(POWER_LOSS_RECOVERY)
if (card.cardOK && card.sdprinting) save_job_recovery_info();
if (card.cardOK && card.sdprinting) save_job_recovery_info(current_position[2]);
#endif
}

Expand All @@ -15555,4 +15606,11 @@ void loop() {
}
endstops.event_handler();
idle();


if(TFTpausingFlag==1) //when pause sd printing,send "ok"to tft as read buffer carry out
{
planner.synchronize();
TFTpausingFlag=2;
}
}
2 changes: 2 additions & 0 deletions Marlin/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
#define BOARD_STB_11 64 // STB V1.1
#define BOARD_AZTEEG_X1 65 // Azteeg X1
#define BOARD_ANET_10 69 // Anet 1.0 (Melzi clone)
#define BOARD_ANYCUBIC_Mega_Zero 61 // MELZI_ANYCUBIC_M7


//
// Other ATmega644P, ATmega644, ATmega1284P
Expand Down
3 changes: 2 additions & 1 deletion Marlin/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@
#include "pins_STB_11.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(AZTEEG_X1)
#include "pins_AZTEEG_X1.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(ANYCUBIC_Mega_Zero)
#include "pins_ANYCUBIC_M7.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p

//
// Other ATmega644P, ATmega644, ATmega1284P
//

Expand Down
117 changes: 117 additions & 0 deletions Marlin/pins_ANYCUBIC_M7.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*
*/

/**
* Melzi (Anycubic) pin assignments
*
* The Anycubic board needs a bootloader installed before Marlin can be uploaded.
* If you don't have a chip programmer you can use a spare Arduino plus a few
* electronic components to write the bootloader.
*
* See http://www.instructables.com/id/Burn-Arduino-Bootloader-with-Arduino-MEGA/
*/

#define BOARD_NAME "Melzi (Anycubic)"

#include "pins_MELZI.h"

// For the stock CR-10 use the REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
// option for the display in Configuration.h

#undef LCD_SDSS
#undef LED_PIN
#undef LCD_PINS_RS
#undef LCD_PINS_ENABLE
#undef LCD_PINS_D4
#undef LCD_PINS_D5
#undef LCD_PINS_D6
#undef LCD_PINS_D7
#undef FIL_RUNOUT_PIN

#define LCD_SDSS 31 // Smart Controller SD card reader (rather than the Melzi)
#define LCD_PINS_RS 28 // ST9720 CS
#define LCD_PINS_ENABLE 17 // ST9720 DAT
#define LCD_PINS_D4 30 // ST9720 CLK
#define FIL_RUNOUT_PIN -1 // Uses Beeper/LED Pin Pulled to GND

// Alter timing for graphical display
#ifndef ST7920_DELAY_1
#define ST7920_DELAY_1 DELAY_NS(125)
#endif
#ifndef ST7920_DELAY_2
#define ST7920_DELAY_2 DELAY_NS(125)
#endif
#ifndef ST7920_DELAY_3
#define ST7920_DELAY_3 DELAY_NS(125)
#endif

#if ENABLED(MINIPANEL)
#undef DOGLCD_CS
#define DOGLCD_CS LCD_PINS_RS
#endif

/**
PIN: 0 Port: B0 E0_DIR_PIN protected
PIN: 1 Port: B1 E0_STEP_PIN protected
PIN: 2 Port: B2 Z_DIR_PIN protected
PIN: 3 Port: B3 Z_STEP_PIN protected
PIN: 4 Port: B4 AVR_SS_PIN protected
. FAN_PIN protected
. SS_PIN protected
PIN: 5 Port: B5 AVR_MOSI_PIN Output = 1
. MOSI_PIN Output = 1
PIN: 6 Port: B6 AVR_MISO_PIN Input = 0 TIMER3A PWM: 0 WGM: 1 COM3A: 0 CS: 3 TCCR3A: 1 TCCR3B: 3 TIMSK3: 0
. MISO_PIN Input = 0
PIN: 7 Port: B7 AVR_SCK_PIN Output = 0 TIMER3B PWM: 0 WGM: 1 COM3B: 0 CS: 3 TCCR3A: 1 TCCR3B: 3 TIMSK3: 0
. SCK_PIN Output = 0
PIN: 8 Port: D0 RXD Input = 1
PIN: 9 Port: D1 TXD Input = 0
PIN: 10 Port: D2 BTN_EN2 Input = 1
PIN: 11 Port: D3 BTN_EN1 Input = 1
PIN: 12 Port: D4 HEATER_BED_PIN protected
PIN: 13 Port: D5 HEATER_0_PIN protected
PIN: 14 Port: D6 E0_ENABLE_PIN protected
. X_ENABLE_PIN protected
. Y_ENABLE_PIN protected
PIN: 15 Port: D7 X_STEP_PIN protected
PIN: 16 Port: C0 BTN_ENC Input = 1
. SCL Input = 1
PIN: 17 Port: C1 LCD_PINS_ENABLE Output = 0
. SDA Output = 0
PIN: 18 Port: C2 X_MIN_PIN protected
. X_STOP_PIN protected
PIN: 19 Port: C3 Y_MIN_PIN protected
. Y_STOP_PIN protected
PIN: 20 Port: C4 Z_MIN_PIN protected
. Z_STOP_PIN protected
PIN: 21 Port: C5 X_DIR_PIN protected
PIN: 22 Port: C6 Y_STEP_PIN protected
PIN: 23 Port: C7 Y_DIR_PIN protected
PIN: 24 Port: A7 TEMP_0_PIN protected
PIN: 25 Port: A6 TEMP_BED_PIN protected
PIN: 26 Port: A5 Z_ENABLE_PIN protected
PIN: 27 Port: A4 BEEPER_PIN Output = 0
PIN: 28 Port: A3 LCD_PINS_RS Output = 0
PIN: 29 Port: A2 <unused/unknown> Input = 0
PIN: 30 Port: A1 LCD_PINS_D4 Output = 1
PIN: 31 Port: A0 SDSS Output = 1
*/
1 change: 1 addition & 0 deletions Marlin/pins_SANGUINOLOLU_12.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* MELZI_MAKR3D
* SANGUINOLOLU_12
* STB_11
* ANYCUBIC_M7
*/

#ifndef BOARD_NAME
Expand Down
Loading

0 comments on commit 65cc110

Please sign in to comment.