Commit 89caa423 authored by MagoKimbra's avatar MagoKimbra

Same fix

parent 29907c62
...@@ -139,7 +139,7 @@ void manage_inactivity(bool ignore_stepper_queue=false); ...@@ -139,7 +139,7 @@ void manage_inactivity(bool ignore_stepper_queue=false);
*/ */
enum AxisEnum {X_AXIS=0, Y_AXIS=1, A_AXIS=0, B_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5}; enum AxisEnum {X_AXIS=0, Y_AXIS=1, A_AXIS=0, B_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5};
enum EndstopEnum {X_MIN=0, Y_MIN=1, Z_MIN=2, Z_PROBE=3, X_MAX=4, Y_MAX=5, Z_MAX=6}; enum EndstopEnum {X_MIN=0, Y_MIN=1, Z_MIN=2, Z_PROBE=3, X_MAX=4, Y_MAX=5, Z_MAX=6, Z2_MIN=7, Z2_MAX=8};
void enable_all_steppers(); void enable_all_steppers();
void disable_all_steppers(); void disable_all_steppers();
......
...@@ -240,6 +240,7 @@ bool axis_known_position[3] = { false }; ...@@ -240,6 +240,7 @@ bool axis_known_position[3] = { false };
static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0; static long gcode_N, gcode_LastN, Stopped_gcode_LastN = 0;
static char *current_command, *current_command_args;
static int cmd_queue_index_r = 0; static int cmd_queue_index_r = 0;
static int cmd_queue_index_w = 0; static int cmd_queue_index_w = 0;
static int commands_in_queue = 0; static int commands_in_queue = 0;
...@@ -269,8 +270,8 @@ static bool relative_mode = false; //Determines Absolute or Relative Coordinate ...@@ -269,8 +270,8 @@ static bool relative_mode = false; //Determines Absolute or Relative Coordinate
static char serial_char; static char serial_char;
static int serial_count = 0; static int serial_count = 0;
static boolean comment_mode = false; static boolean comment_mode = false;
static char *strchr_pointer; ///< A pointer to find chars in the command string (X, Y, Z, E, etc.) static char *seen_pointer; // < A pointer to find chars in the command string (X, Y, Z, E, etc.)
const char* queued_commands_P= NULL; /* pointer to the current line in the active sequence of commands, or NULL when none */ const char* queued_commands_P = NULL; /* pointer to the current line in the active sequence of commands, or NULL when none */
const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42 const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
// Inactivity shutdown // Inactivity shutdown
millis_t previous_cmd_ms = 0; millis_t previous_cmd_ms = 0;
...@@ -872,8 +873,8 @@ void get_command() { ...@@ -872,8 +873,8 @@ void get_command() {
#endif #endif
if (strchr(command, 'N') != NULL) { if (strchr(command, 'N') != NULL) {
strchr_pointer = strchr(command, 'N'); seen_pointer = strchr(command, 'N');
gcode_N = (strtol(strchr_pointer + 1, NULL, 10)); gcode_N = (strtol(seen_pointer + 1, NULL, 10));
if (gcode_N != gcode_LastN + 1 && strstr_P(command, PSTR("M110")) == NULL) { if (gcode_N != gcode_LastN + 1 && strstr_P(command, PSTR("M110")) == NULL) {
gcode_line_error(PSTR(MSG_ERR_LINE_NO)); gcode_line_error(PSTR(MSG_ERR_LINE_NO));
return; return;
...@@ -883,9 +884,9 @@ void get_command() { ...@@ -883,9 +884,9 @@ void get_command() {
byte checksum = 0; byte checksum = 0;
byte count = 0; byte count = 0;
while (command[count] != '*') checksum ^= command[count++]; while (command[count] != '*') checksum ^= command[count++];
strchr_pointer = strchr(command, '*'); seen_pointer = strchr(command, '*');
if (strtol(strchr_pointer + 1, NULL, 10) != checksum) { if (strtol(seen_pointer + 1, NULL, 10) != checksum) {
gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH)); gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH));
return; return;
} }
...@@ -907,8 +908,8 @@ void get_command() { ...@@ -907,8 +908,8 @@ void get_command() {
} }
if (strchr(command, 'G') != NULL) { if (strchr(command, 'G') != NULL) {
strchr_pointer = strchr(command, 'G'); seen_pointer = strchr(command, 'G');
switch (strtol(strchr_pointer + 1, NULL, 10)) { switch (strtol(seen_pointer + 1, NULL, 10)) {
case 0: case 0:
case 1: case 1:
case 2: case 2:
...@@ -1001,32 +1002,32 @@ void get_command() { ...@@ -1001,32 +1002,32 @@ void get_command() {
bool code_has_value() { bool code_has_value() {
int i = 1; int i = 1;
char c = strchr_pointer[i]; char c = seen_pointer[i];
if (c == '-' || c == '+') c = strchr_pointer[++i]; if (c == '-' || c == '+') c = seen_pointer[++i];
if (c == '.') c = strchr_pointer[++i]; if (c == '.') c = seen_pointer[++i];
return (c >= '0' && c <= '9'); return (c >= '0' && c <= '9');
} }
float code_value() { float code_value() {
float ret; float ret;
char *e = strchr(strchr_pointer, 'E'); char *e = strchr(seen_pointer, 'E');
if (e) { if (e) {
*e = 0; *e = 0;
ret = strtod(strchr_pointer+1, NULL); ret = strtod(seen_pointer + 1, NULL);
*e = 'E'; *e = 'E';
} }
else else
ret = strtod(strchr_pointer+1, NULL); ret = strtod(seen_pointer + 1, NULL);
return ret; return ret;
} }
long code_value_long() { return strtol(strchr_pointer + 1, NULL, 10); } long code_value_long() { return strtol(seen_pointer + 1, NULL, 10); }
int16_t code_value_short() { return (int16_t)strtol(strchr_pointer + 1, NULL, 10); } int16_t code_value_short() { return (int16_t)strtol(seen_pointer + 1, NULL, 10); }
bool code_seen(char code) { bool code_seen(char code) {
strchr_pointer = strchr(command_queue[cmd_queue_index_r], code); seen_pointer = strchr(command_queue[cmd_queue_index_r], code);
return (strchr_pointer != NULL); //Return True if a character was found return (seen_pointer != NULL); //Return True if a character was found
} }
#define DEFINE_PGM_READ_ANY(type, reader) \ #define DEFINE_PGM_READ_ANY(type, reader) \
...@@ -2609,6 +2610,11 @@ void gcode_get_destination() { ...@@ -2609,6 +2610,11 @@ void gcode_get_destination() {
} }
} }
void unknown_command_error() {
ECHO_SMV(DB, MSG_UNKNOWN_COMMAND, current_command);
ECHO_M("\"\n");
}
/** /**
* G0, G1: Coordinated movement of X Y Z E axes * G0, G1: Coordinated movement of X Y Z E axes
*/ */
...@@ -3692,7 +3698,7 @@ inline void gcode_G92() { ...@@ -3692,7 +3698,7 @@ inline void gcode_G92() {
* M1: // M1 - Conditional stop - Wait for user button press on LCD * M1: // M1 - Conditional stop - Wait for user button press on LCD
*/ */
inline void gcode_M0_M1() { inline void gcode_M0_M1() {
char *src = strchr_pointer + 2; char *src = seen_pointer + 2;
millis_t codenum = 0; millis_t codenum = 0;
bool hasP = false, hasS = false; bool hasP = false, hasS = false;
...@@ -3826,7 +3832,7 @@ inline void gcode_M17() { ...@@ -3826,7 +3832,7 @@ inline void gcode_M17() {
* M23: Select a file * M23: Select a file
*/ */
inline void gcode_M23() { inline void gcode_M23() {
char* codepos = strchr_pointer + 4; char* codepos = seen_pointer + 4;
char* starpos = strchr(codepos, '*'); char* starpos = strchr(codepos, '*');
if (starpos) *starpos = '\0'; if (starpos) *starpos = '\0';
card.openFile(codepos, true); card.openFile(codepos, true);
...@@ -3869,11 +3875,11 @@ inline void gcode_M17() { ...@@ -3869,11 +3875,11 @@ inline void gcode_M17() {
* M28: Start SD Write * M28: Start SD Write
*/ */
inline void gcode_M28() { inline void gcode_M28() {
char* codepos = strchr_pointer + 4; char* codepos = seen_pointer + 4;
char* starpos = strchr(codepos, '*'); char* starpos = strchr(codepos, '*');
if (starpos) { if (starpos) {
char* npos = strchr(command_queue[cmd_queue_index_r], 'N'); char* npos = strchr(command_queue[cmd_queue_index_r], 'N');
strchr_pointer = strchr(npos, ' ') + 1; seen_pointer = strchr(npos, ' ') + 1;
*(starpos) = '\0'; *(starpos) = '\0';
} }
card.openFile(codepos, false); card.openFile(codepos, false);
...@@ -3893,13 +3899,13 @@ inline void gcode_M17() { ...@@ -3893,13 +3899,13 @@ inline void gcode_M17() {
inline void gcode_M30() { inline void gcode_M30() {
if (card.cardOK) { if (card.cardOK) {
card.closeFile(); card.closeFile();
char* starpos = strchr(strchr_pointer + 4, '*'); char* starpos = strchr(seen_pointer + 4, '*');
if (starpos) { if (starpos) {
char* npos = strchr(command_queue[cmd_queue_index_r], 'N'); char* npos = strchr(command_queue[cmd_queue_index_r], 'N');
strchr_pointer = strchr(npos, ' ') + 1; seen_pointer = strchr(npos, ' ') + 1;
*(starpos) = '\0'; *(starpos) = '\0';
} }
card.removeFile(strchr_pointer + 4); card.removeFile(seen_pointer + 4);
} }
} }
#endif #endif
...@@ -3927,46 +3933,60 @@ inline void gcode_M31() { ...@@ -3927,46 +3933,60 @@ inline void gcode_M31() {
if (card.sdprinting) if (card.sdprinting)
st_synchronize(); st_synchronize();
char* codepos = strchr_pointer + 4; char* namestartpos = strchr(current_command_args, '!'); // Find ! to indicate filename string start.
if (!namestartpos)
char* namestartpos = strchr(codepos, '!'); //find ! to indicate filename string start. namestartpos = current_command_args; // Default name position, 4 letters after the M
if (! namestartpos)
namestartpos = codepos; //default name position, 4 letters after the M
else else
namestartpos++; //to skip the '!' namestartpos++; // to skip the '!'
char* starpos = strchr(codepos, '*');
if (starpos) *(starpos) = '\0';
bool call_procedure = code_seen('P') && (strchr_pointer < namestartpos); bool call_procedure = code_seen('P') && (seen_pointer < namestartpos);
if (card.cardOK) { if (card.cardOK) {
card.openFile(namestartpos, true, !call_procedure); card.openFile(namestartpos, true, !call_procedure);
if (code_seen('S') && strchr_pointer < namestartpos) // "S" (must occur _before_ the filename!) if (code_seen('S') && seen_pointer < namestartpos) // "S" (must occur _before_ the filename!)
card.setIndex(code_value_short()); card.setIndex(code_value_short());
card.startFileprint(); card.startFileprint();
if (!call_procedure) { if (!call_procedure)
print_job_start_ms = millis(); //procedure calls count as normal print time. print_job_start_ms = millis(); // procedure calls count as normal print time.
#if HAS_POWER_CONSUMPTION_SENSOR
startpower = power_consumption_hour;
#endif
} }
} }
#ifdef LONG_FILENAME_HOST_SUPPORT
/**
* M33: Get the long full path of a file or folder
*
* Parameters:
* <dospath> Case-insensitive DOS-style path to a file or folder
*
* Example:
* M33 miscel~1/armchair/armcha~1.gco
*
* Output:
* /Miscellaneous/Armchair/Armchair.gcode
*/
inline void gcode_M33() {
char *args = seen_pointer + 4;
while (*args == ' ') ++args;
clear_asterisk(args);
card.printLongPath(args);
} }
#endif
/** /**
* M928: Start SD Write * M928: Start SD Write
*/ */
inline void gcode_M928() { inline void gcode_M928() {
char* starpos = strchr(strchr_pointer + 5, '*'); char* starpos = strchr(seen_pointer + 5, '*');
if (starpos) { if (starpos) {
char* npos = strchr(command_queue[cmd_queue_index_r], 'N'); char* npos = strchr(command_queue[cmd_queue_index_r], 'N');
strchr_pointer = strchr(npos, ' ') + 1; seen_pointer = strchr(npos, ' ') + 1;
*(starpos) = '\0'; *(starpos) = '\0';
} }
card.openLogFile(strchr_pointer + 5); card.openLogFile(seen_pointer + 5);
} }
#endif // SDSUPPORT #endif // SDSUPPORT
...@@ -4554,7 +4574,7 @@ inline void gcode_M115() { ...@@ -4554,7 +4574,7 @@ inline void gcode_M115() {
* M117: Set LCD Status Message * M117: Set LCD Status Message
*/ */
inline void gcode_M117() { inline void gcode_M117() {
lcd_setstatus(strchr_pointer + 5); lcd_setstatus(seen_pointer + 5);
} }
#endif #endif
...@@ -5889,8 +5909,7 @@ inline void gcode_M999() { ...@@ -5889,8 +5909,7 @@ inline void gcode_M999() {
* *
* F[mm/min] Set the movement feedrate * F[mm/min] Set the movement feedrate
*/ */
inline void gcode_T() { inline void gcode_T(uint8_t tmp_extruder) {
uint16_t tmp_extruder = code_value_short();
long csteps; long csteps;
if (tmp_extruder >= EXTRUDERS) { if (tmp_extruder >= EXTRUDERS) {
ECHO_SMV(DB, "T", tmp_extruder); ECHO_SMV(DB, "T", tmp_extruder);
...@@ -6128,22 +6147,53 @@ inline void gcode_T() { ...@@ -6128,22 +6147,53 @@ inline void gcode_T() {
* This is called from the main loop() * This is called from the main loop()
*/ */
void process_next_command() { void process_next_command() {
current_command = command_queue[cmd_queue_index_r];
if ((debugLevel & DEBUG_ECHO)) { if ((debugLevel & DEBUG_ECHO)) {
ECHO_LV(DB, command_queue[cmd_queue_index_r]); ECHO_LV(DB, current_command);
}
// Sanitize the current command:
// - Skip leading spaces
// - Bypass N...
// - Overwrite * with nul to mark the end
while (*current_command == ' ') ++current_command;
if (*current_command == 'N' && current_command[1] >= '0' && current_command[1] <= '9') {
while (*current_command != ' ') ++current_command;
while (*current_command == ' ') ++current_command;
} }
char *starpos = strchr(current_command, '*'); // * should always be the last parameter
if (starpos) *starpos = '\0';
// Get the command code, which must be G, M, or T
char command_code = *current_command;
// The code must have a numeric value
bool code_is_good = (current_command[1] >= '0' && current_command[1] <= '9');
int codenum; // define ahead of goto
if(code_seen('G')) { // Bail early if there's no code
if (!code_is_good) goto ExitUnknownCommand;
int codenum = code_value_short(); // Args pointer optimizes code_seen, especially those taking XYZEF
// This wastes a little cpu on commands that expect no arguments.
current_command_args = current_command;
while (*current_command_args != ' ') ++current_command_args;
while (*current_command_args == ' ') ++current_command_args;
switch (codenum) { // Interpret the code int
seen_pointer = current_command;
codenum = code_value_short();
// Handle a known G, M, or T
switch(command_code) {
case 'G': switch (codenum) {
//G0 -> G1 //G0 -> G1
case 0: case 0:
case 1: case 1:
gcode_G0_G1(); gcode_G0_G1(); break;
break;
// G2, G3 // G2, G3
#ifndef SCARA #ifndef SCARA
...@@ -6195,11 +6245,12 @@ void process_next_command() { ...@@ -6195,11 +6245,12 @@ void process_next_command() {
relative_mode = true; break; relative_mode = true; break;
case 92: // G92 case 92: // G92
gcode_G92(); break; gcode_G92(); break;
default: code_is_good = false;
} }
} break;
else if (code_seen('M')) { case 'M': switch (codenum) {
switch(code_value_short()) {
#ifdef ULTIPANEL #ifdef ULTIPANEL
case 0: // M0 - Unconditional stop - Wait for user button press on LCD case 0: // M0 - Unconditional stop - Wait for user button press on LCD
case 1: // M1 - Conditional stop - Wait for user button press on LCD case 1: // M1 - Conditional stop - Wait for user button press on LCD
...@@ -6529,17 +6580,19 @@ void process_next_command() { ...@@ -6529,17 +6580,19 @@ void process_next_command() {
gcode_SET_Z_PROBE_OFFSET(); break; gcode_SET_Z_PROBE_OFFSET(); break;
#endif // CUSTOM_M_CODE_SET_Z_PROBE_OFFSET #endif // CUSTOM_M_CODE_SET_Z_PROBE_OFFSET
default: code_is_good = false;
} }
} break;
else if (code_seen('T')) { case 'T':
gcode_T(); gcode_T(codenum);
break;
} }
else { ExitUnknownCommand:
ECHO_SM(ER, MSG_UNKNOWN_COMMAND);
ECHO_EVM(command_queue[cmd_queue_index_r], "\""); // Still unknown command? Throw an error
} if (!code_is_good) unknown_command_error();
ok_to_send(); ok_to_send();
} }
......
...@@ -226,6 +226,23 @@ ...@@ -226,6 +226,23 @@
#define CONDITIONALS_H #define CONDITIONALS_H
/**
* SINGLENOZZLE
*/
#ifdef SINGLENOZZLE
#define HOTENDS 1
#undef TEMP_SENSOR_1_AS_REDUNDANT
#else
#define HOTENDS EXTRUDERS
#endif
/**
* DRIVER_EXTRUDERS
*/
#if !defined(MKR4) && !defined(NPR2)
#define DRIVER_EXTRUDERS EXTRUDERS // This defines the number of Driver extruder
#endif
#ifndef __SAM3X8E__ #ifndef __SAM3X8E__
#ifndef AT90USB #ifndef AT90USB
#define HardwareSerial_h // trick to disable the standard HWserial #define HardwareSerial_h // trick to disable the standard HWserial
...@@ -289,23 +306,6 @@ ...@@ -289,23 +306,6 @@
#define BAUDRATE 115200 // Baudrate setting to 115200 because serial monitor arduino function at max 115200 baudrate. #define BAUDRATE 115200 // Baudrate setting to 115200 because serial monitor arduino function at max 115200 baudrate.
#endif #endif
/**
* SINGLENOZZLE
*/
#ifdef SINGLENOZZLE
#define HOTENDS 1
#undef TEMP_SENSOR_1_AS_REDUNDANT
#else
#define HOTENDS EXTRUDERS
#endif
/**
* DRIVER_EXTRUDERS
*/
#if !defined(MKR4) && !defined(NPR2)
#define DRIVER_EXTRUDERS EXTRUDERS // This defines the number of Driver extruder
#endif
/** /**
* Axis lengths * Axis lengths
*/ */
......
...@@ -76,9 +76,10 @@ volatile long endstops_trigsteps[3] = { 0 }; ...@@ -76,9 +76,10 @@ volatile long endstops_trigsteps[3] = { 0 };
volatile long endstops_stepsTotal, endstops_stepsDone; volatile long endstops_stepsTotal, endstops_stepsDone;
static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_PROBE as BIT value static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_PROBE as BIT value
static char old_endstop_bits = 0; // use X_MIN, X_MAX... Z_MAX, Z_PROBE #ifndef Z_DUAL_ENDSTOPS
#ifdef Z_DUAL_ENDSTOPS static byte old_endstop_bits = 0; // use X_MIN, X_MAX... Z_MAX, Z_PROBE, Z2_MIN, Z2_MAX
static char old_dual_endstop_bits = 0; // actually only implemented for Z #else
static uint16_t old_endstop_bits = 0; // use X_MIN, X_MAX... Z_MAX, Z_PROBE, Z2_MIN, Z2_MAX
#endif #endif
#ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
...@@ -136,10 +137,10 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 }; ...@@ -136,10 +137,10 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
if (performing_homing) { \ if (performing_homing) { \
if (Z_HOME_DIR > 0) {\ if (Z_HOME_DIR > 0) {\
if (!(TEST(old_endstop_bits, Z_MAX) && (count_direction[Z_AXIS] > 0)) && !locked_z_motor) Z_STEP_WRITE(v); \ if (!(TEST(old_endstop_bits, Z_MAX) && (count_direction[Z_AXIS] > 0)) && !locked_z_motor) Z_STEP_WRITE(v); \
if (!(TEST(old_dual_endstop_bits, Z_MAX) && (count_direction[Z_AXIS] > 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \ if (!(TEST(old_endstop_bits, Z2_MAX) && (count_direction[Z_AXIS] > 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \
} else {\ } else {\
if (!(TEST(old_endstop_bits, Z_MIN) && (count_direction[Z_AXIS] < 0)) && !locked_z_motor) Z_STEP_WRITE(v); \ if (!(TEST(old_endstop_bits, Z_MIN) && (count_direction[Z_AXIS] < 0)) && !locked_z_motor) Z_STEP_WRITE(v); \
if (!(TEST(old_dual_endstop_bits, Z_MIN) && (count_direction[Z_AXIS] < 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \ if (!(TEST(old_endstop_bits, Z2_MIN) && (count_direction[Z_AXIS] < 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \
} \ } \
} else { \ } else { \
Z_STEP_WRITE(v); \ Z_STEP_WRITE(v); \
...@@ -466,9 +467,10 @@ ISR(TIMER1_COMPA_vect) { ...@@ -466,9 +467,10 @@ ISR(TIMER1_COMPA_vect) {
// Check endstops // Check endstops
if (check_endstops) { if (check_endstops) {
char current_endstop_bits;
#ifdef Z_DUAL_ENDSTOPS #ifdef Z_DUAL_ENDSTOPS
char current_dual_endstop_bits; uint16_t current_endstop_bits;
#else
byte current_endstop_bits;
#endif #endif
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
...@@ -477,16 +479,16 @@ ISR(TIMER1_COMPA_vect) { ...@@ -477,16 +479,16 @@ ISR(TIMER1_COMPA_vect) {
#define _ENDSTOP_HIT(AXIS) endstop_hit_bits |= BIT(_ENDSTOP(AXIS, MIN)) #define _ENDSTOP_HIT(AXIS) endstop_hit_bits |= BIT(_ENDSTOP(AXIS, MIN))
#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX #define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
// GET_ENDSTOP_STATUS: set the current endstop bits for an endstop to its status // SET_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
#define GET_ENDSTOP_STATUS(endstop, AXIS, MINMAX) SET_BIT(endstop, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX))) #define SET_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT(current_endstop_bits, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
// COPY_BIT: copy the value of COPY_BIT to BIT in bits
#define COPY_BIT(bits, COPY_BIT, BIT) SET_BIT(bits, BIT, TEST(bits, COPY_BIT))
// TEST_ENDSTOP: test the old and the current status of an endstop // TEST_ENDSTOP: test the old and the current status of an endstop
#define TEST_ENDSTOPS(AXIS, MINMAX) (TEST(current_endstop_bits, _ENDSTOP(AXIS, MINMAX)) && TEST(old_endstop_bits, _ENDSTOP(AXIS, MINMAX))) #define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits, ENDSTOP) && TEST(old_endstop_bits, ENDSTOP))
// TEST_DUAL_ENDSTOP: same like TEST_ENDSTOP for dual endstops
#define TEST_DUAL_ENDSTOPS(AXIS, MINMAX) (TEST(current_dual_endstop_bits, _ENDSTOP(AXIS, MINMAX)) && TEST(old_dual_endstop_bits, _ENDSTOP(AXIS, MINMAX)))
#define UPDATE_ENDSTOP(AXIS,MINMAX) \ #define UPDATE_ENDSTOP(AXIS,MINMAX) \
GET_ENDSTOP_STATUS(current_endstop_bits, AXIS, MINMAX); \ SET_ENDSTOP_BIT(AXIS, MINMAX); \
if (TEST_ENDSTOPS(AXIS, MINMAX) && (current_block->steps[_AXIS(AXIS)] > 0)) { \ if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \ endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
_ENDSTOP_HIT(AXIS); \ _ENDSTOP_HIT(AXIS); \
step_events_completed = current_block->step_event_count; \ step_events_completed = current_block->step_event_count; \
...@@ -548,22 +550,20 @@ ISR(TIMER1_COMPA_vect) { ...@@ -548,22 +550,20 @@ ISR(TIMER1_COMPA_vect) {
#if HAS_Z_MIN #if HAS_Z_MIN
#ifdef Z_DUAL_ENDSTOPS #ifdef Z_DUAL_ENDSTOPS
GET_ENDSTOP_STATUS(current_endstop_bits, Z, MIN); SET_ENDSTOP_BIT(Z, MIN);
#if HAS_Z2_MIN #if HAS_Z2_MIN
GET_ENDSTOP_STATUS(current_dual_endstop_bits, Z, MIN); SET_ENDSTOP_BIT(Z2, MIN);
#else
COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN)
#endif #endif
bool z_test = TEST_ENDSTOPS(Z, MIN) byte z_test = TEST_ENDSTOP(Z_MIN) << 0 + TEST_ENDSTOP(Z2_MIN) << 1; // bit 0 for Z, bit 1 for Z2
#if HAS_Z2_MIN
&& TEST_DUAL_ENDSTOPS(Z, MIN)
#endif
;
if (z_test && current_block->steps[Z_AXIS] > 0) { if (z_test && current_block->steps[Z_AXIS] > 0) { // z_test = Z_MIN || Z2_MIN
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
endstop_hit_bits |= BIT(Z_MIN); endstop_hit_bits |= BIT(Z_MIN);
if (!performing_homing || (performing_homing && !z_test)) //if not performing home or if both endstops were trigged during homing... if (!performing_homing || (performing_homing && !((~z_test) & 0x3))) //if not performing home or if both endstops were trigged during homing...
step_events_completed = current_block->step_event_count; step_events_completed = current_block->step_event_count; //!((~z_test) & 0x3) = Z_MIN && Z2_MIN
} }
#else // !Z_DUAL_ENDSTOPS #else // !Z_DUAL_ENDSTOPS
...@@ -573,10 +573,9 @@ ISR(TIMER1_COMPA_vect) { ...@@ -573,10 +573,9 @@ ISR(TIMER1_COMPA_vect) {
#ifdef Z_PROBE_ENDSTOP #ifdef Z_PROBE_ENDSTOP
UPDATE_ENDSTOP(Z, PROBE); UPDATE_ENDSTOP(Z, PROBE);
GET_ENDSTOP_STATUS(current_endstop_bits, Z, PROBE); SET_ENDSTOP_BIT(Z, PROBE);
if(TEST_ENDSTOPS(Z, PROBE)) if (TEST_ENDSTOP(Z_PROBE)) {
{
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
endstop_hit_bits |= BIT(Z_PROBE); endstop_hit_bits |= BIT(Z_PROBE);
} }
...@@ -587,22 +586,20 @@ ISR(TIMER1_COMPA_vect) { ...@@ -587,22 +586,20 @@ ISR(TIMER1_COMPA_vect) {
#ifdef Z_DUAL_ENDSTOPS #ifdef Z_DUAL_ENDSTOPS
GET_ENDSTOP_STATUS(current_endstop_bits, Z, MAX); SET_ENDSTOP_BIT(Z, MAX);
#if HAS_Z2_MAX #if HAS_Z2_MAX
GET_ENDSTOP_STATUS(current_dual_endstop_bits, Z, MAX); SET_ENDSTOP_BIT(Z2, MAX);
#else
COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX)
#endif #endif
bool z_test = TEST_ENDSTOPS(Z, MAX) byte z_test = TEST_ENDSTOP(Z_MAX) << 0 + TEST_ENDSTOP(Z2_MAX) << 1; // bit 0 for Z, bit 1 for Z2
#if HAS_Z2_MAX
&& TEST_DUAL_ENDSTOPS(Z, MAX)
#endif
;
if (z_test && current_block->steps[Z_AXIS] > 0) { if (z_test && current_block->steps[Z_AXIS] > 0) { // t_test = Z_MAX || Z2_MAX
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
endstop_hit_bits |= BIT(Z_MIN); endstop_hit_bits |= BIT(Z_MIN);
if (!performing_homing || (performing_homing && !z_test)) //if not performing home or if both endstops were trigged during homing... if (!performing_homing || (performing_homing && !((~z_test) & 0x3))) //if not performing home or if both endstops were trigged during homing...
step_events_completed = current_block->step_event_count; step_events_completed = current_block->step_event_count; //!((~z_test) & 0x3) = Z_MAX && Z2_MAX
} }
#else // !Z_DUAL_ENDSTOPS #else // !Z_DUAL_ENDSTOPS
...@@ -614,9 +611,6 @@ ISR(TIMER1_COMPA_vect) { ...@@ -614,9 +611,6 @@ ISR(TIMER1_COMPA_vect) {
} }
old_endstop_bits = current_endstop_bits; old_endstop_bits = current_endstop_bits;
#ifdef Z_DUAL_ENDSTOPS
old_dual_endstop_bits = current_dual_endstop_bits;
#endif
} }
...@@ -921,21 +915,21 @@ void st_init() { ...@@ -921,21 +915,21 @@ void st_init() {
#if HAS_X_MIN #if HAS_X_MIN
SET_INPUT(X_MIN_PIN); SET_INPUT(X_MIN_PIN);
#ifdef ENDSTOPPULLUP_XMIN #ifdef ENDSTOPPULLUP_XMIN
WRITE(X_MIN_PIN, HIGH); WRITE(X_MIN_PIN,HIGH);
#endif #endif
#endif #endif
#if HAS_Y_MIN #if HAS_Y_MIN
SET_INPUT(Y_MIN_PIN); SET_INPUT(Y_MIN_PIN);
#ifdef ENDSTOPPULLUP_YMIN #ifdef ENDSTOPPULLUP_YMIN
WRITE(Y_MIN_PIN, HIGH); WRITE(Y_MIN_PIN,HIGH);
#endif #endif
#endif #endif
#if HAS_Z_MIN #if HAS_Z_MIN
SET_INPUT(Z_MIN_PIN); SET_INPUT(Z_MIN_PIN);
#ifdef ENDSTOPPULLUP_ZMIN #ifdef ENDSTOPPULLUP_ZMIN
WRITE(Z_MIN_PIN, HIGH); WRITE(Z_MIN_PIN,HIGH);
#endif #endif
#endif #endif
...@@ -949,35 +943,35 @@ void st_init() { ...@@ -949,35 +943,35 @@ void st_init() {
#if HAS_X_MAX #if HAS_X_MAX
SET_INPUT(X_MAX_PIN); SET_INPUT(X_MAX_PIN);
#ifdef ENDSTOPPULLUP_XMAX #ifdef ENDSTOPPULLUP_XMAX
WRITE(X_MAX_PIN, HIGH); WRITE(X_MAX_PIN,HIGH);
#endif #endif
#endif #endif
#if HAS_Y_MAX #if HAS_Y_MAX
SET_INPUT(Y_MAX_PIN); SET_INPUT(Y_MAX_PIN);
#ifdef ENDSTOPPULLUP_YMAX #ifdef ENDSTOPPULLUP_YMAX
WRITE(Y_MAX_PIN, HIGH); WRITE(Y_MAX_PIN,HIGH);
#endif #endif
#endif #endif
#if HAS_Z_MAX #if HAS_Z_MAX
SET_INPUT(Z_MAX_PIN); SET_INPUT(Z_MAX_PIN);
#ifdef ENDSTOPPULLUP_ZMAX #ifdef ENDSTOPPULLUP_ZMAX
WRITE(Z_MAX_PIN, HIGH); WRITE(Z_MAX_PIN,HIGH);
#endif #endif
#endif #endif
#if HAS_Z2_MAX #if HAS_Z2_MAX
SET_INPUT(Z2_MAX_PIN); SET_INPUT(Z2_MAX_PIN);
#ifdef ENDSTOPPULLUP_ZMAX #ifdef ENDSTOPPULLUP_ZMAX
WRITE(Z2_MAX_PIN, HIGH); WRITE(Z2_MAX_PIN,HIGH);
#endif #endif
#endif #endif
#if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used. #if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
SET_INPUT(Z_PROBE_PIN); SET_INPUT(Z_PROBE_PIN);
#ifdef ENDSTOPPULLUP_ZPROBE #ifdef ENDSTOPPULLUP_ZPROBE
WRITE(Z_PROBE_PIN, HIGH); WRITE(Z_PROBE_PIN,HIGH);
#endif #endif
#endif #endif
......
...@@ -53,9 +53,9 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo ...@@ -53,9 +53,9 @@ uint8_t u8g_dev_rrd_st7920_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, vo
{ {
case U8G_DEV_MSG_INIT: case U8G_DEV_MSG_INIT:
{ {
OUT_WRITE(ST7920_CS_PIN, LOW); OUT_WRITE(ST7920_CS_PIN,LOW);
OUT_WRITE(ST7920_DAT_PIN, LOW); OUT_WRITE(ST7920_DAT_PIN,LOW);
OUT_WRITE(ST7920_CLK_PIN, HIGH); OUT_WRITE(ST7920_CLK_PIN,HIGH);
ST7920_CS(); ST7920_CS();
u8g_Delay(120); //initial delay for boot up u8g_Delay(120); //initial delay for boot up
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment