Commit fff64606 authored by MagoKimbra's avatar MagoKimbra

Adjust only tab

parent 24eb4064
...@@ -377,19 +377,19 @@ float axis_scaling[3]={1,1,1}; // Build size scaling, default to 1 ...@@ -377,19 +377,19 @@ float axis_scaling[3]={1,1,1}; // Build size scaling, default to 1
bool cancel_heatup = false ; bool cancel_heatup = false ;
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
//Variables for Filament Sensor input //Variables for Filament Sensor input
float filament_width_nominal=DEFAULT_NOMINAL_FILAMENT_DIA; //Set nominal filament width, can be changed with M404 float filament_width_nominal=DEFAULT_NOMINAL_FILAMENT_DIA; //Set nominal filament width, can be changed with M404
bool filament_sensor=false; //M405 turns on filament_sensor control, M406 turns it off bool filament_sensor=false; //M405 turns on filament_sensor control, M406 turns it off
float filament_width_meas=DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter float filament_width_meas=DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter
signed char measurement_delay[MAX_MEASUREMENT_DELAY+1]; //ring buffer to delay measurement store extruder factor after subtracting 100 signed char measurement_delay[MAX_MEASUREMENT_DELAY+1]; //ring buffer to delay measurement store extruder factor after subtracting 100
int delay_index1=0; //index into ring buffer int delay_index1=0; //index into ring buffer
int delay_index2=-1; //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized int delay_index2=-1; //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized
float delay_dist=0; //delay distance counter float delay_dist=0; //delay distance counter
int meas_delay_cm = MEASUREMENT_DELAY_CM; //distance delay setting int meas_delay_cm = MEASUREMENT_DELAY_CM; //distance delay setting
#endif #endif
#ifdef LASERBEAM #ifdef LASERBEAM
int laser_ttl_modulation = 0; int laser_ttl_modulation = 0;
#endif #endif
//=========================================================================== //===========================================================================
...@@ -507,8 +507,7 @@ extern "C"{ ...@@ -507,8 +507,7 @@ extern "C"{
//needs overworking someday //needs overworking someday
void enquecommand(const char *cmd) void enquecommand(const char *cmd)
{ {
if(buflen < BUFSIZE) if(buflen < BUFSIZE) {
{
//this is dangerous if a mixing of serial and this happens //this is dangerous if a mixing of serial and this happens
strcpy(&(cmdbuffer[bufindw][0]),cmd); strcpy(&(cmdbuffer[bufindw][0]),cmd);
SERIAL_ECHO_START; SERIAL_ECHO_START;
...@@ -522,8 +521,7 @@ void enquecommand(const char *cmd) ...@@ -522,8 +521,7 @@ void enquecommand(const char *cmd)
void enquecommand_P(const char *cmd) void enquecommand_P(const char *cmd)
{ {
if(buflen < BUFSIZE) if(buflen < BUFSIZE) {
{
//this is dangerous if a mixing of serial and this happens //this is dangerous if a mixing of serial and this happens
strcpy_P(&(cmdbuffer[bufindw][0]),cmd); strcpy_P(&(cmdbuffer[bufindw][0]),cmd);
SERIAL_ECHO_START; SERIAL_ECHO_START;
...@@ -759,7 +757,7 @@ void get_command() ...@@ -759,7 +757,7 @@ void get_command()
if(serial_char == '\n' || if(serial_char == '\n' ||
serial_char == '\r' || serial_char == '\r' ||
(serial_char == ':' && comment_mode == false) || (serial_char == ':' && comment_mode == false) ||
serial_count >= (MAX_CMD_SIZE - 1) ) serial_count >= (MAX_CMD_SIZE - 1))
{ {
if(!serial_count) { //if empty line if(!serial_count) { //if empty line
comment_mode = false; //for new command comment_mode = false; //for new command
...@@ -773,7 +771,7 @@ void get_command() ...@@ -773,7 +771,7 @@ void get_command()
{ {
strchr_pointer = strchr(cmdbuffer[bufindw], 'N'); strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10)); gcode_N = (strtol(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL, 10));
if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) { if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL)) {
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_LINE_NO); SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
SERIAL_ERRORLN(gcode_LastN); SERIAL_ERRORLN(gcode_LastN);
...@@ -783,8 +781,7 @@ void get_command() ...@@ -783,8 +781,7 @@ void get_command()
return; return;
} }
if(strchr(cmdbuffer[bufindw], '*') != NULL) if(strchr(cmdbuffer[bufindw], '*') != NULL) {
{
byte checksum = 0; byte checksum = 0;
byte count = 0; byte count = 0;
while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++]; while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
...@@ -799,9 +796,7 @@ void get_command() ...@@ -799,9 +796,7 @@ void get_command()
return; return;
} }
//if no errors, continue parsing //if no errors, continue parsing
} } else {
else
{
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM); SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
SERIAL_ERRORLN(gcode_LastN); SERIAL_ERRORLN(gcode_LastN);
...@@ -812,11 +807,8 @@ void get_command() ...@@ -812,11 +807,8 @@ void get_command()
gcode_LastN = gcode_N; gcode_LastN = gcode_N;
//if no errors, continue parsing //if no errors, continue parsing
} } else { // if we don't receive 'N' but still see '*'
else // if we don't receive 'N' but still see '*' if((strchr(cmdbuffer[bufindw], '*') != NULL)) {
{
if((strchr(cmdbuffer[bufindw], '*') != NULL))
{
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM); SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
SERIAL_ERRORLN(gcode_LastN); SERIAL_ERRORLN(gcode_LastN);
...@@ -824,18 +816,17 @@ void get_command() ...@@ -824,18 +816,17 @@ void get_command()
return; return;
} }
} }
if((strchr(cmdbuffer[bufindw], 'G') != NULL)){ if((strchr(cmdbuffer[bufindw], 'G') != NULL)) {
strchr_pointer = strchr(cmdbuffer[bufindw], 'G'); strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))){ switch((int)((strtod(&cmdbuffer[bufindw][strchr_pointer - cmdbuffer[bufindw] + 1], NULL)))) {
case 0: case 0:
case 1: case 1:
case 2: case 2:
case 3: case 3:
if(Stopped == false) { // If printer is stopped by an error the G[0-3] codes are ignored. if(Stopped == false) { // If printer is stopped by an error the G[0-3] codes are ignored.
#ifdef SDSUPPORT #ifdef SDSUPPORT
if(card.saving) if(card.saving) break;
break; #endif //SDSUPPORT
#endif //SDSUPPORT
SERIAL_PROTOCOLLNPGM(MSG_OK); SERIAL_PROTOCOLLNPGM(MSG_OK);
} }
else { else {
...@@ -864,7 +855,7 @@ void get_command() ...@@ -864,7 +855,7 @@ void get_command()
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char; if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
} }
} }
#ifdef SDSUPPORT #ifdef SDSUPPORT
if(!card.sdprinting || serial_count!=0){ if(!card.sdprinting || serial_count!=0){
return; return;
} }
...@@ -910,11 +901,11 @@ void get_command() ...@@ -910,11 +901,11 @@ void get_command()
return; //if empty line return; //if empty line
} }
cmdbuffer[bufindw][serial_count] = 0; //terminate string cmdbuffer[bufindw][serial_count] = 0; //terminate string
// if(!comment_mode){ // if(!comment_mode){
fromsd[bufindw] = true; fromsd[bufindw] = true;
buflen += 1; buflen += 1;
bufindw = (bufindw + 1)%BUFSIZE; bufindw = (bufindw + 1)%BUFSIZE;
// } // }
comment_mode = false; //for new command comment_mode = false; //for new command
serial_count = 0; //clear buffer serial_count = 0; //clear buffer
} }
...@@ -924,9 +915,7 @@ void get_command() ...@@ -924,9 +915,7 @@ void get_command()
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char; if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
} }
} }
#endif //SDSUPPORT
#endif //SDSUPPORT
} }
...@@ -1504,7 +1493,8 @@ float z_probe() { ...@@ -1504,7 +1493,8 @@ float z_probe() {
return mm; return mm;
} }
void calibrate_print_surface(float z_offset) { void calibrate_print_surface(float z_offset)
{
float probe_bed_z, probe_z, probe_h, probe_l; float probe_bed_z, probe_z, probe_h, probe_l;
int probe_count; int probe_count;
...@@ -1553,7 +1543,8 @@ void calibrate_print_surface(float z_offset) { ...@@ -1553,7 +1543,8 @@ void calibrate_print_surface(float z_offset) {
} }
} }
float probe_bed(float x, float y) { float probe_bed(float x, float y)
{
//Probe bed at specified location and return z height of bed //Probe bed at specified location and return z height of bed
float probe_bed_z, probe_z, probe_h, probe_l; float probe_bed_z, probe_z, probe_h, probe_l;
int probe_count; int probe_count;
...@@ -1609,7 +1600,8 @@ float probe_bed(float x, float y) { ...@@ -1609,7 +1600,8 @@ float probe_bed(float x, float y) {
return probe_bed_z; return probe_bed_z;
} }
float z_probe_accuracy(){ float z_probe_accuracy()
{
//Perform z-probe accuracy test //Perform z-probe accuracy test
float probe_h[7]; float probe_h[7];
float probe_l[7]; float probe_l[7];
...@@ -1649,7 +1641,8 @@ float z_probe_accuracy(){ ...@@ -1649,7 +1641,8 @@ float z_probe_accuracy(){
return range_h - range_l; return range_h - range_l;
} }
void bed_probe_all(){ void bed_probe_all()
{
//Probe all bed positions & store carriage positions //Probe all bed positions & store carriage positions
bed_level_c = probe_bed(0.0, 0.0); bed_level_c = probe_bed(0.0, 0.0);
save_carriage_positions(0); save_carriage_positions(0);
...@@ -1665,9 +1658,10 @@ void bed_probe_all(){ ...@@ -1665,9 +1658,10 @@ void bed_probe_all(){
save_carriage_positions(5); save_carriage_positions(5);
bed_level_ox = probe_bed(SIN_60 * bed_radius, COS_60 * bed_radius); bed_level_ox = probe_bed(SIN_60 * bed_radius, COS_60 * bed_radius);
save_carriage_positions(6); save_carriage_positions(6);
} }
void calibration_report(){ void calibration_report()
{
//Display Report //Display Report
SERIAL_ECHOLN("\tZ-Tower\t\t\tEndstop Offsets"); SERIAL_ECHOLN("\tZ-Tower\t\t\tEndstop Offsets");
...@@ -1709,13 +1703,15 @@ void calibration_report(){ ...@@ -1709,13 +1703,15 @@ void calibration_report(){
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
} }
void save_carriage_positions(int position_num) { void save_carriage_positions(int position_num)
{
for(int8_t i=0; i < NUM_AXIS; i++) { for(int8_t i=0; i < NUM_AXIS; i++) {
saved_positions[position_num][i] = saved_position[i]; saved_positions[position_num][i] = saved_position[i];
} }
} }
void home_delta_axis(){ void home_delta_axis()
{
saved_feedrate = feedrate; saved_feedrate = feedrate;
saved_feedmultiply = feedmultiply; saved_feedmultiply = feedmultiply;
feedmultiply = 100; feedmultiply = 100;
...@@ -1763,7 +1759,8 @@ void home_delta_axis(){ ...@@ -1763,7 +1759,8 @@ void home_delta_axis(){
endstops_hit_on_purpose(); endstops_hit_on_purpose();
} }
void prepare_move_raw(){ void prepare_move_raw()
{
previous_millis_cmd = millis(); previous_millis_cmd = millis();
calculate_delta(destination); calculate_delta(destination);
plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS],
...@@ -1782,7 +1779,8 @@ void refresh_cmd_timeout(void) ...@@ -1782,7 +1779,8 @@ void refresh_cmd_timeout(void)
} }
#ifdef FWRETRACT #ifdef FWRETRACT
void retract(bool retracting, bool swapretract = false) { void retract(bool retracting, bool swapretract = false)
{
if(retracting && !retracted[active_extruder]) { if(retracting && !retracted[active_extruder]) {
destination[X_AXIS]=current_position[X_AXIS]; destination[X_AXIS]=current_position[X_AXIS];
destination[Y_AXIS]=current_position[Y_AXIS]; destination[Y_AXIS]=current_position[Y_AXIS];
...@@ -1832,7 +1830,7 @@ void refresh_cmd_timeout(void) ...@@ -1832,7 +1830,7 @@ void refresh_cmd_timeout(void)
prepare_move(); prepare_move();
feedrate = oldFeedrate; feedrate = oldFeedrate;
} }
} //retract }
#endif //FWRETRACT #endif //FWRETRACT
#ifdef Z_PROBE_SLED #ifdef Z_PROBE_SLED
...@@ -1842,7 +1840,8 @@ void refresh_cmd_timeout(void) ...@@ -1842,7 +1840,8 @@ void refresh_cmd_timeout(void)
// dock[in] If true, move to MAX_X and engage the electromagnet // dock[in] If true, move to MAX_X and engage the electromagnet
// offset[in] The additional distance to move to adjust docking location // offset[in] The additional distance to move to adjust docking location
// //
static void dock_sled(bool dock, int offset=0) { static void dock_sled(bool dock, int offset=0)
{
int z_loc; int z_loc;
if (!((axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]))) { if (!((axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]))) {
...@@ -1878,15 +1877,13 @@ void process_commands() ...@@ -1878,15 +1877,13 @@ void process_commands()
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
float x_tmp, y_tmp, z_tmp, real_z; float x_tmp, y_tmp, z_tmp, real_z;
#endif #endif
if(code_seen('G')) if(code_seen('G')) {
{ switch((int)code_value()) {
switch((int)code_value())
{
case 0: // G0 -> G1 case 0: // G0 -> G1
case 1: // G1 case 1: // G1
if(Stopped == false) { if(Stopped == false) {
get_coordinates(); // For X Y Z E F get_coordinates(); // For X Y Z E F
#ifdef FWRETRACT #ifdef FWRETRACT
if(autoretract_enabled) if(autoretract_enabled)
if( !(code_seen('X') || code_seen('Y') || code_seen('Z')) && code_seen('E')) { if( !(code_seen('X') || code_seen('Y') || code_seen('Z')) && code_seen('E')) {
float echange=destination[E_AXIS]-current_position[E_AXIS]; float echange=destination[E_AXIS]-current_position[E_AXIS];
...@@ -1897,12 +1894,13 @@ void process_commands() ...@@ -1897,12 +1894,13 @@ void process_commands()
return; return;
} }
} }
#endif //FWRETRACT #endif //FWRETRACT
prepare_move(); prepare_move();
//ClearToSend(); //ClearToSend();
return; return;
} }
break; break;
#ifndef SCARA //disable arc support #ifndef SCARA //disable arc support
case 2: // G2 - CW ARC case 2: // G2 - CW ARC
if(Stopped == false) { if(Stopped == false) {
...@@ -1919,6 +1917,7 @@ void process_commands() ...@@ -1919,6 +1917,7 @@ void process_commands()
} }
break; break;
#endif // no SCARA #endif // no SCARA
case 4: // G4 dwell case 4: // G4 dwell
LCD_MESSAGEPGM(MSG_DWELL); LCD_MESSAGEPGM(MSG_DWELL);
codenum = 0; codenum = 0;
...@@ -1934,28 +1933,29 @@ void process_commands() ...@@ -1934,28 +1933,29 @@ void process_commands()
lcd_update(); lcd_update();
} }
break; break;
#ifdef FWRETRACT
#ifdef FWRETRACT
case 10: // G10 retract case 10: // G10 retract
#if EXTRUDERS > 1 #if EXTRUDERS > 1
retracted_swap[active_extruder]=(code_seen('S') && code_value_long() == 1); // checks for swap retract argument retracted_swap[active_extruder]=(code_seen('S') && code_value_long() == 1); // checks for swap retract argument
retract(true,retracted_swap[active_extruder]); retract(true,retracted_swap[active_extruder]);
#else #else
retract(true); retract(true);
#endif #endif
break; break;
case 11: // G11 retract_recover case 11: // G11 retract_recover
#if EXTRUDERS > 1 #if EXTRUDERS > 1
retract(false,retracted_swap[active_extruder]); retract(false,retracted_swap[active_extruder]);
#else #else
retract(false); retract(false);
#endif #endif
break; break;
#endif //FWRETRACT #endif //FWRETRACT
case 28: //G28 Home all Axis one at a time case 28: //G28 Home all Axis one at a time
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
plan_bed_level_matrix.set_to_identity(); //Reset the plane ("erase" all leveling data) plan_bed_level_matrix.set_to_identity(); //Reset the plane ("erase" all leveling data)
#endif //ENABLE_AUTO_BED_LEVELING #endif //ENABLE_AUTO_BED_LEVELING
saved_feedrate = feedrate; saved_feedrate = feedrate;
saved_feedmultiply = feedmultiply; saved_feedmultiply = feedmultiply;
...@@ -1971,7 +1971,7 @@ void process_commands() ...@@ -1971,7 +1971,7 @@ void process_commands()
home_all_axis = !((code_seen(axis_codes[X_AXIS])) || (code_seen(axis_codes[Y_AXIS])) || (code_seen(axis_codes[Z_AXIS])) || (code_seen(axis_codes[E_AXIS]))); home_all_axis = !((code_seen(axis_codes[X_AXIS])) || (code_seen(axis_codes[Y_AXIS])) || (code_seen(axis_codes[Z_AXIS])) || (code_seen(axis_codes[E_AXIS])));
#ifdef NPR2 #ifdef NPR2
if((home_all_axis) || (code_seen(axis_codes[E_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[E_AXIS]))) {
active_driver = active_extruder = 1; active_driver = active_extruder = 1;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], -200, COLOR_HOMERATE, active_extruder, active_driver); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], -200, COLOR_HOMERATE, active_extruder, active_driver);
...@@ -1979,9 +1979,9 @@ void process_commands() ...@@ -1979,9 +1979,9 @@ void process_commands()
old_color = 99; old_color = 99;
active_driver = active_extruder = 0; active_driver = active_extruder = 0;
} }
#endif #endif
#ifdef DELTA #ifdef DELTA
// A delta can only safely home all axis at the same time // A delta can only safely home all axis at the same time
// all axis have to home at the same time // all axis have to home at the same time
// Move all carriages up together until the first endstop is hit. // Move all carriages up together until the first endstop is hit.
...@@ -2011,33 +2011,36 @@ void process_commands() ...@@ -2011,33 +2011,36 @@ void process_commands()
calculate_delta(current_position); calculate_delta(current_position);
plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]); plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
#else // NOT DELTA #else // NOT DELTA
#if Z_HOME_DIR > 0 // If homing away from BED do Z first #if Z_HOME_DIR > 0 // If homing away from BED do Z first
if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
HOMEAXIS(Z); HOMEAXIS(Z);
} }
#endif #endif
#ifdef QUICK_HOME #ifdef QUICK_HOME
if((home_all_axis)||( code_seen(axis_codes[X_AXIS]) && code_seen(axis_codes[Y_AXIS]))) { //first diagonal move if((home_all_axis)||( code_seen(axis_codes[X_AXIS]) && code_seen(axis_codes[Y_AXIS]))) { //first diagonal move
current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0; current_position[X_AXIS] = 0;
current_position[Y_AXIS] = 0;
#ifndef DUAL_X_CARRIAGE #ifndef DUAL_X_CARRIAGE
int x_axis_home_dir = home_dir(X_AXIS); int x_axis_home_dir = home_dir(X_AXIS);
#else #else
int x_axis_home_dir = x_home_dir(active_extruder); int x_axis_home_dir = x_home_dir(active_extruder);
extruder_duplication_enabled = false; extruder_duplication_enabled = false;
#endif #endif
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
destination[X_AXIS] = 1.5 * max_length(X_AXIS) * x_axis_home_dir;destination[Y_AXIS] = 1.5 * max_length(Y_AXIS) * home_dir(Y_AXIS); destination[X_AXIS] = 1.5 * max_length(X_AXIS) * x_axis_home_dir;
destination[Y_AXIS] = 1.5 * max_length(Y_AXIS) * home_dir(Y_AXIS);
feedrate = homing_feedrate[X_AXIS]; feedrate = homing_feedrate[X_AXIS];
if(homing_feedrate[Y_AXIS]<feedrate) if(homing_feedrate[Y_AXIS]<feedrate)
feedrate = homing_feedrate[Y_AXIS]; feedrate = homing_feedrate[Y_AXIS];
if (max_length(X_AXIS) > max_length(Y_AXIS)) { if (max_length(X_AXIS) > max_length(Y_AXIS)) {
feedrate *= sqrt(pow(max_length(Y_AXIS) / max_length(X_AXIS), 2) + 1); feedrate *= sqrt(pow(max_length(Y_AXIS) / max_length(X_AXIS), 2) + 1);
} else { }
else {
feedrate *= sqrt(pow(max_length(X_AXIS) / max_length(Y_AXIS), 2) + 1); feedrate *= sqrt(pow(max_length(X_AXIS) / max_length(Y_AXIS), 2) + 1);
} }
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder, active_driver); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder, active_driver);
...@@ -2055,14 +2058,14 @@ void process_commands() ...@@ -2055,14 +2058,14 @@ void process_commands()
current_position[X_AXIS] = destination[X_AXIS]; current_position[X_AXIS] = destination[X_AXIS];
current_position[Y_AXIS] = destination[Y_AXIS]; current_position[Y_AXIS] = destination[Y_AXIS];
#ifndef SCARA #ifndef SCARA
current_position[Z_AXIS] = destination[Z_AXIS]; current_position[Z_AXIS] = destination[Z_AXIS];
#endif #endif
} }
#endif // QUICK_HOME #endif // QUICK_HOME
if((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) {
#ifdef DUAL_X_CARRIAGE #ifdef DUAL_X_CARRIAGE
int tmp_extruder = active_extruder; int tmp_extruder = active_extruder;
extruder_duplication_enabled = false; extruder_duplication_enabled = false;
active_extruder = !active_extruder; active_extruder = !active_extruder;
...@@ -2074,9 +2077,9 @@ void process_commands() ...@@ -2074,9 +2077,9 @@ void process_commands()
memcpy(raised_parked_position, current_position, sizeof(raised_parked_position)); memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
delayed_move_time = 0; delayed_move_time = 0;
active_extruder_parked = true; active_extruder_parked = true;
#else #else
HOMEAXIS(X); HOMEAXIS(X);
#endif // DUAL_X_CARRIAGE #endif // DUAL_X_CARRIAGE
} }
if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) {
...@@ -2085,28 +2088,28 @@ void process_commands() ...@@ -2085,28 +2088,28 @@ void process_commands()
if(code_seen(axis_codes[X_AXIS])) { if(code_seen(axis_codes[X_AXIS])) {
if(code_value_long() != 0) { if(code_value_long() != 0) {
#ifdef SCARA #ifdef SCARA
current_position[X_AXIS]=code_value(); current_position[X_AXIS]=code_value();
#else #else
current_position[X_AXIS]=code_value()+add_homing[0]; current_position[X_AXIS]=code_value()+add_homing[0];
#endif #endif
} }
} }
if(code_seen(axis_codes[Y_AXIS])) { if(code_seen(axis_codes[Y_AXIS])) {
if(code_value_long() != 0) { if(code_value_long() != 0) {
#ifdef SCARA #ifdef SCARA
current_position[Y_AXIS]=code_value(); current_position[Y_AXIS]=code_value();
#else #else
current_position[Y_AXIS]=code_value()+add_homing[1]; current_position[Y_AXIS]=code_value()+add_homing[1];
#endif #endif
} }
} }
#if Z_HOME_DIR < 0 // If homing towards BED do Z last #if Z_HOME_DIR < 0 // If homing towards BED do Z last
#ifndef Z_SAFE_HOMING #ifndef Z_SAFE_HOMING
if (code_seen('M')) { // Manual G28 if (code_seen('M')) { // Manual G28
#ifdef ULTIPANEL #ifdef ULTIPANEL
if(home_all_axis) { if(home_all_axis) {
boolean zig = true; boolean zig = true;
int xGridSpacing = (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION); int xGridSpacing = (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION);
...@@ -2117,7 +2120,8 @@ void process_commands() ...@@ -2117,7 +2120,8 @@ void process_commands()
xProbe = LEFT_PROBE_BED_POSITION; xProbe = LEFT_PROBE_BED_POSITION;
xInc = xGridSpacing; xInc = xGridSpacing;
zig = false; zig = false;
} else { // zag }
else { // zag
xProbe = RIGHT_PROBE_BED_POSITION; xProbe = RIGHT_PROBE_BED_POSITION;
xInc = -xGridSpacing; xInc = -xGridSpacing;
zig = true; zig = true;
...@@ -2141,19 +2145,19 @@ void process_commands() ...@@ -2141,19 +2145,19 @@ void process_commands()
manage_inactivity(); manage_inactivity();
lcd_update(); lcd_update();
if(beepbutton) { if(beepbutton) {
#if BEEPER > 0 #if BEEPER > 0
SET_OUTPUT(BEEPER); SET_OUTPUT(BEEPER);
WRITE(BEEPER,HIGH); WRITE(BEEPER,HIGH);
delay(100); delay(100);
WRITE(BEEPER,LOW); WRITE(BEEPER,LOW);
delay(3); delay(3);
#else #else
#if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS) #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
lcd_buzz(1000/6,100); lcd_buzz(1000/6,100);
#else #else
lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ); lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
#endif #endif
#endif #endif
beepbutton=false; beepbutton=false;
} }
} }
...@@ -2166,18 +2170,18 @@ void process_commands() ...@@ -2166,18 +2170,18 @@ void process_commands()
enquecommand("G4 P0"); enquecommand("G4 P0");
enquecommand("G4 P0"); enquecommand("G4 P0");
} }
#endif // ULTIPANEL #endif // ULTIPANEL
} }
else if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { else if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
#if defined (Z_RAISE_BEFORE_HOMING) && (Z_RAISE_BEFORE_HOMING > 0) #if defined (Z_RAISE_BEFORE_HOMING) && (Z_RAISE_BEFORE_HOMING > 0)
destination[Z_AXIS] = Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS) * (-1); // Set destination away from bed destination[Z_AXIS] = Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS) * (-1); // Set destination away from bed
feedrate = max_feedrate[Z_AXIS]; feedrate = max_feedrate[Z_AXIS];
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder, active_driver); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate, active_extruder, active_driver);
st_synchronize(); st_synchronize();
#endif #endif
HOMEAXIS(Z); HOMEAXIS(Z);
} }
#else // Z Safe mode activated. #else // Z Safe mode activated.
if(home_all_axis) { if(home_all_axis) {
destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT - X_PROBE_OFFSET_FROM_EXTRUDER); destination[X_AXIS] = round(Z_SAFE_HOMING_X_POINT - X_PROBE_OFFSET_FROM_EXTRUDER);
destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER); destination[Y_AXIS] = round(Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER);
...@@ -2209,18 +2213,20 @@ void process_commands() ...@@ -2209,18 +2213,20 @@ void process_commands()
st_synchronize(); st_synchronize();
HOMEAXIS(Z); HOMEAXIS(Z);
} else if (!((axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]))) { }
else if (!((axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]))) {
LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN); LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN); SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
} else { }
else {
LCD_MESSAGEPGM(MSG_ZPROBE_OUT); LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT); SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT);
} }
} }
#endif // Z_SAFE_HOMING #endif // Z_SAFE_HOMING
#endif // Z_HOME_DIR < 0 #endif // Z_HOME_DIR < 0
if(code_seen(axis_codes[Z_AXIS])) { if(code_seen(axis_codes[Z_AXIS])) {
if(code_value_long() != 0) { if(code_value_long() != 0) {
...@@ -2228,23 +2234,23 @@ void process_commands() ...@@ -2228,23 +2234,23 @@ void process_commands()
} }
} }
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
current_position[Z_AXIS] += zprobe_zoffset; //Add Z_Probe offset (the distance is negative) current_position[Z_AXIS] += zprobe_zoffset; //Add Z_Probe offset (the distance is negative)
} }
#endif #endif
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
#endif // else DELTA #endif // else DELTA
#ifdef SCARA #ifdef SCARA
calculate_delta(current_position); calculate_delta(current_position);
plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]); plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
#endif SCARA #endif SCARA
#ifdef ENDSTOPS_ONLY_FOR_HOMING #ifdef ENDSTOPS_ONLY_FOR_HOMING
enable_endstops(false); enable_endstops(false);
#endif #endif
feedrate = saved_feedrate; feedrate = saved_feedrate;
feedmultiply = saved_feedmultiply; feedmultiply = saved_feedmultiply;
...@@ -2252,12 +2258,12 @@ void process_commands() ...@@ -2252,12 +2258,12 @@ void process_commands()
endstops_hit_on_purpose(); endstops_hit_on_purpose();
break; break;
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points. case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points.
{ {
#if Z_MIN_PIN == -1 #if Z_MIN_PIN == -1
#error "You must have a Z_MIN endstop in order to enable Auto Bed Leveling feature!!! Z_MIN_PIN must point to a valid hardware pin." #error "You must have a Z_MIN endstop in order to enable Auto Bed Leveling feature!!! Z_MIN_PIN must point to a valid hardware pin."
#endif #endif
// Prevent user from running a G29 without first homing in X and Y // Prevent user from running a G29 without first homing in X and Y
if (! (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) ) { if (! (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) ) {
...@@ -2267,9 +2273,9 @@ void process_commands() ...@@ -2267,9 +2273,9 @@ void process_commands()
break; // abort G29, since we don't know where we are break; // abort G29, since we don't know where we are
} }
#ifdef Z_PROBE_SLED #ifdef Z_PROBE_SLED
dock_sled(false); dock_sled(false);
#endif // Z_PROBE_SLED #endif // Z_PROBE_SLED
st_synchronize(); st_synchronize();
// make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly // make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly
...@@ -2285,7 +2291,7 @@ void process_commands() ...@@ -2285,7 +2291,7 @@ void process_commands()
setup_for_endstop_move(); setup_for_endstop_move();
feedrate = homing_feedrate[Z_AXIS]; feedrate = homing_feedrate[Z_AXIS];
#ifdef AUTO_BED_LEVELING_GRID #ifdef AUTO_BED_LEVELING_GRID
int r_probe_bed_position = RIGHT_PROBE_BED_POSITION; int r_probe_bed_position = RIGHT_PROBE_BED_POSITION;
int l_probe_bed_position = LEFT_PROBE_BED_POSITION; int l_probe_bed_position = LEFT_PROBE_BED_POSITION;
int f_probe_bed_position = FRONT_PROBE_BED_POSITION; int f_probe_bed_position = FRONT_PROBE_BED_POSITION;
...@@ -2353,7 +2359,8 @@ void process_commands() ...@@ -2353,7 +2359,8 @@ void process_commands()
//xEnd = RIGHT_PROBE_BED_POSITION; //xEnd = RIGHT_PROBE_BED_POSITION;
xInc = xGridSpacing; xInc = xGridSpacing;
zig = false; zig = false;
} else // zag }
else // zag
{ {
xProbe = r_probe_bed_position; xProbe = r_probe_bed_position;
//xEnd = LEFT_PROBE_BED_POSITION; //xEnd = LEFT_PROBE_BED_POSITION;
...@@ -2368,7 +2375,8 @@ void process_commands() ...@@ -2368,7 +2375,8 @@ void process_commands()
{ {
// raise before probing // raise before probing
z_before = Z_RAISE_BEFORE_PROBING; z_before = Z_RAISE_BEFORE_PROBING;
} else }
else
{ {
// raise extruder // raise extruder
z_before = current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS; z_before = current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS;
...@@ -2402,7 +2410,7 @@ void process_commands() ...@@ -2402,7 +2410,7 @@ void process_commands()
free(plane_equation_coefficients); free(plane_equation_coefficients);
#else // AUTO_BED_LEVELING_GRID not defined #else // AUTO_BED_LEVELING_GRID not defined
// Probe at 3 arbitrary points // Probe at 3 arbitrary points
// probe 1 // probe 1
...@@ -2418,7 +2426,7 @@ void process_commands() ...@@ -2418,7 +2426,7 @@ void process_commands()
set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3); set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3);
#endif // AUTO_BED_LEVELING_GRID #endif // AUTO_BED_LEVELING_GRID
st_synchronize(); st_synchronize();
// The following code correct the Z height difference from z-probe position and hotend tip position. // The following code correct the Z height difference from z-probe position and hotend tip position.
...@@ -2432,13 +2440,13 @@ void process_commands() ...@@ -2432,13 +2440,13 @@ void process_commands()
apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp); //Apply the correction sending the probe offset apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp); //Apply the correction sending the probe offset
current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS]; //The difference is added to current position and sent to planner. current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS]; //The difference is added to current position and sent to planner.
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
#ifdef Z_PROBE_SLED #ifdef Z_PROBE_SLED
dock_sled(true, -SLED_DOCKING_OFFSET); // correct for over travel. dock_sled(true, -SLED_DOCKING_OFFSET); // correct for over travel.
#endif // Z_PROBE_SLED #endif // Z_PROBE_SLED
} }
break; break;
#ifndef Z_PROBE_SLED #ifndef Z_PROBE_SLED
case 30: // G30 Single Z Probe case 30: // G30 Single Z Probe
{ {
engage_z_probe(); // Engage Z Servo endstop if available engage_z_probe(); // Engage Z Servo endstop if available
...@@ -2462,7 +2470,7 @@ void process_commands() ...@@ -2462,7 +2470,7 @@ void process_commands()
retract_z_probe(); // Retract Z Servo endstop if available retract_z_probe(); // Retract Z Servo endstop if available
} }
break; break;
#else #else
case 31: // G31 - dock the sled case 31: // G31 - dock the sled
dock_sled(true); dock_sled(true);
break; break;
...@@ -2527,7 +2535,9 @@ void process_commands() ...@@ -2527,7 +2535,9 @@ void process_commands()
} }
break; break;
} }
if (code_seen('F')) {probing_feedrate=code_value();} if (code_seen('F')) {
probing_feedrate=code_value();
}
if (code_seen('X') and code_seen('Y')) { if (code_seen('X') and code_seen('Y')) {
//Probe specified X,Y point //Probe specified X,Y point
float x = code_seen('X') ? code_value():0.00; float x = code_seen('X') ? code_value():0.00;
...@@ -2643,7 +2653,8 @@ void process_commands() ...@@ -2643,7 +2653,8 @@ void process_commands()
set_delta_constants(); set_delta_constants();
SERIAL_ECHOPAIR("Adjusting Z-Height to: ", max_pos[Z_AXIS]); SERIAL_ECHOPAIR("Adjusting Z-Height to: ", max_pos[Z_AXIS]);
SERIAL_ECHOLN(" mm.."); SERIAL_ECHOLN(" mm..");
} else { }
else {
if ((bed_level_x < -ac_prec) or (bed_level_x > ac_prec) or (bed_level_y < -ac_prec) or (bed_level_y > ac_prec) or (bed_level_z < -ac_prec) or (bed_level_z > ac_prec)) { if ((bed_level_x < -ac_prec) or (bed_level_x > ac_prec) or (bed_level_y < -ac_prec) or (bed_level_y > ac_prec) or (bed_level_z < -ac_prec) or (bed_level_z > ac_prec)) {
//Endstops req adjustment //Endstops req adjustment
SERIAL_ECHOLN("Adjusting Endstops.."); SERIAL_ECHOLN("Adjusting Endstops..");
...@@ -2666,27 +2677,33 @@ void process_commands() ...@@ -2666,27 +2677,33 @@ void process_commands()
SERIAL_ECHOPAIR("Adjusting Z-Height to: ", max_pos[Z_AXIS]); SERIAL_ECHOPAIR("Adjusting Z-Height to: ", max_pos[Z_AXIS]);
SERIAL_ECHOLN(" mm.."); SERIAL_ECHOLN(" mm..");
} }
} else { }
else {
SERIAL_ECHOLN("Endstops: OK"); SERIAL_ECHOLN("Endstops: OK");
adj_r_target = (bed_level_x + bed_level_y + bed_level_z) / 3; adj_r_target = (bed_level_x + bed_level_y + bed_level_z) / 3;
adj_dr_target = (bed_level_ox + bed_level_oy + bed_level_oz) / 3; adj_dr_target = (bed_level_ox + bed_level_oy + bed_level_oz) / 3;
//Determine which parameters require adjustment //Determine which parameters require adjustment
if ((bed_level_c >= adj_r_target - ac_prec) and (bed_level_c <= adj_r_target + ac_prec)) adj_r_done = true; else adj_r_done = false; if ((bed_level_c >= adj_r_target - ac_prec) and (bed_level_c <= adj_r_target + ac_prec)) adj_r_done = true;
if ((adj_dr_target >= adj_r_target - ac_prec) and (adj_dr_target <= adj_r_target + ac_prec)) adj_dr_done = true; else adj_dr_done = false; else adj_r_done = false;
if ((bed_level_x != bed_level_ox) or (bed_level_y != bed_level_oy) or (bed_level_z != bed_level_oz)) adj_tower_done = false; else adj_tower_done = true; if ((adj_dr_target >= adj_r_target - ac_prec) and (adj_dr_target <= adj_r_target + ac_prec)) adj_dr_done = true;
else adj_dr_done = false;
if ((bed_level_x != bed_level_ox) or (bed_level_y != bed_level_oy) or (bed_level_z != bed_level_oz)) adj_tower_done = false;
else adj_tower_done = true;
if ((adj_r_done == false) or (adj_dr_done == false) or (adj_tower_done == false)) { if ((adj_r_done == false) or (adj_dr_done == false) or (adj_tower_done == false)) {
//delta geometry adjustment required //delta geometry adjustment required
SERIAL_ECHOLN("Adjusting Delta Geometry.."); SERIAL_ECHOLN("Adjusting Delta Geometry..");
//set inital direction and magnitude for delta radius & diagonal rod adjustment //set inital direction and magnitude for delta radius & diagonal rod adjustment
if (adj_r == 0) { if (adj_r == 0) {
if (adj_r_target > bed_level_c) adj_r = 1; else adj_r = -1; if (adj_r_target > bed_level_c) adj_r = 1;
else adj_r = -1;
} }
if (adj_dr == 0) { if (adj_dr == 0) {
if (adj_r_target > adj_dr_target) adj_dr = 1; else adj_dr = -1; if (adj_r_target > adj_dr_target) adj_dr = 1;
else adj_dr = -1;
} }
//Don't adjust tower positions on first iteration //Don't adjust tower positions on first iteration
...@@ -2731,7 +2748,8 @@ void process_commands() ...@@ -2731,7 +2748,8 @@ void process_commands()
and (bed_level_ox >= -ac_prec) and (bed_level_ox <= ac_prec) and (bed_level_ox >= -ac_prec) and (bed_level_ox <= ac_prec)
and (bed_level_oy >= -ac_prec) and (bed_level_oy <= ac_prec) and (bed_level_oy >= -ac_prec) and (bed_level_oy <= ac_prec)
and (bed_level_oz >= -ac_prec) and (bed_level_oz <= ac_prec)) loopcount = iterations; and (bed_level_oz >= -ac_prec) and (bed_level_oz <= ac_prec)) loopcount = iterations;
} else { }
else {
if ((bed_level_x >= -ac_prec) and (bed_level_x <= ac_prec) if ((bed_level_x >= -ac_prec) and (bed_level_x <= ac_prec)
and (bed_level_y >= -ac_prec) and (bed_level_y <= ac_prec) and (bed_level_y >= -ac_prec) and (bed_level_y <= ac_prec)
and (bed_level_z >= -ac_prec) and (bed_level_z <= ac_prec) and (bed_level_z >= -ac_prec) and (bed_level_z <= ac_prec)
...@@ -2752,35 +2770,41 @@ void process_commands() ...@@ -2752,35 +2770,41 @@ void process_commands()
radiusErrorB = bed_level_y - bed_level_oy; radiusErrorB = bed_level_y - bed_level_oy;
radiusErrorC = bed_level_z - bed_level_oz; radiusErrorC = bed_level_z - bed_level_oz;
if ((radiusErrorA >= (radiusErrorB - 0.02)) and (radiusErrorA <= (radiusErrorB + 0.02))) equalAB = true; else equalAB = false; if ((radiusErrorA >= (radiusErrorB - 0.02)) and (radiusErrorA <= (radiusErrorB + 0.02))) equalAB = true;
if ((radiusErrorB >= (radiusErrorC - 0.02)) and (radiusErrorB <= (radiusErrorC + 0.02))) equalBC = true; else equalBC = false; else equalAB = false;
if ((radiusErrorC >= (radiusErrorA - 0.02)) and (radiusErrorC <= (radiusErrorA + 0.02))) equalCA = true; else equalCA = false; if ((radiusErrorB >= (radiusErrorC - 0.02)) and (radiusErrorB <= (radiusErrorC + 0.02))) equalBC = true;
else equalBC = false;
if ((radiusErrorC >= (radiusErrorA - 0.02)) and (radiusErrorC <= (radiusErrorA + 0.02))) equalCA = true;
else equalCA = false;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
if (equalAB == true) { if (equalAB == true) {
SERIAL_ECHOPAIR("Tower AB Equal (A=",radiusErrorA); SERIAL_ECHOPAIR("Tower AB Equal (A=",radiusErrorA);
SERIAL_ECHOPAIR(" B=",radiusErrorB); SERIAL_ECHOPAIR(" B=",radiusErrorB);
SERIAL_ECHOLN(")"); SERIAL_ECHOLN(")");
} else SERIAL_ECHOLN("equalAB=false"); }
else SERIAL_ECHOLN("equalAB=false");
if (equalBC == true) { if (equalBC == true) {
SERIAL_ECHOPAIR("Tower BC Equal (B=",radiusErrorB); SERIAL_ECHOPAIR("Tower BC Equal (B=",radiusErrorB);
SERIAL_ECHOPAIR(" C=",radiusErrorC); SERIAL_ECHOPAIR(" C=",radiusErrorC);
SERIAL_ECHOLN(")"); SERIAL_ECHOLN(")");
} else SERIAL_ECHOLN("equalBC=false"); }
else SERIAL_ECHOLN("equalBC=false");
if (equalCA == true) { if (equalCA == true) {
SERIAL_ECHOPAIR("Tower CA Equal (C=",radiusErrorC); SERIAL_ECHOPAIR("Tower CA Equal (C=",radiusErrorC);
SERIAL_ECHOPAIR(" A=",radiusErrorA); SERIAL_ECHOPAIR(" A=",radiusErrorA);
SERIAL_ECHOLN(")"); SERIAL_ECHOLN(")");
} else SERIAL_ECHOLN("equalCA=false"); }
#endif // DEBUG_MESSAGES else SERIAL_ECHOLN("equalCA=false");
#endif // DEBUG_MESSAGES
if ((equalAB == true) and (equalBC == true) and (equalCA == true)) { if ((equalAB == true) and (equalBC == true) and (equalCA == true)) {
// all tower radius out by the same amount (within 0.02) - allow adjustment with delta rod length // all tower radius out by the same amount (within 0.02) - allow adjustment with delta rod length
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOLN("All tower radius errors equal"); SERIAL_ECHOLN("All tower radius errors equal");
#endif #endif
adj_RadiusA = adj_RadiusB = adj_RadiusC = 0; adj_RadiusA = adj_RadiusB = adj_RadiusC = 0;
} }
...@@ -2790,10 +2814,10 @@ void process_commands() ...@@ -2790,10 +2814,10 @@ void process_commands()
if (adj_RadiusC == 0) { if (adj_RadiusC == 0) {
if (bed_level_z < bed_level_oz) adj_RadiusC = 0.5; if (bed_level_z < bed_level_oz) adj_RadiusC = 0.5;
if (bed_level_z > bed_level_oz) adj_RadiusC = -0.5; if (bed_level_z > bed_level_oz) adj_RadiusC = -0.5;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("adj_RadiusC set to ",adj_RadiusC); SERIAL_ECHOPAIR("adj_RadiusC set to ",adj_RadiusC);
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
#endif #endif
} }
} }
if ((equalBC == true) and (equalAB == false) and (equalCA == false)) { if ((equalBC == true) and (equalAB == false) and (equalCA == false)) {
...@@ -2802,10 +2826,10 @@ void process_commands() ...@@ -2802,10 +2826,10 @@ void process_commands()
if (adj_RadiusA == 0) { if (adj_RadiusA == 0) {
if (bed_level_x < bed_level_ox) adj_RadiusA = 0.5; if (bed_level_x < bed_level_ox) adj_RadiusA = 0.5;
if (bed_level_x > bed_level_ox) adj_RadiusA = -0.5; if (bed_level_x > bed_level_ox) adj_RadiusA = -0.5;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("adj_RadiusA set to ",adj_RadiusA); SERIAL_ECHOPAIR("adj_RadiusA set to ",adj_RadiusA);
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
#endif #endif
} }
} }
if ((equalCA == true) and (equalAB == false) and (equalBC == false)) { if ((equalCA == true) and (equalAB == false) and (equalBC == false)) {
...@@ -2814,10 +2838,10 @@ void process_commands() ...@@ -2814,10 +2838,10 @@ void process_commands()
if (adj_RadiusB == 0) { if (adj_RadiusB == 0) {
if (bed_level_y < bed_level_oy) adj_RadiusB = 0.5; if (bed_level_y < bed_level_oy) adj_RadiusB = 0.5;
if (bed_level_y > bed_level_oy) adj_RadiusB = -0.5; if (bed_level_y > bed_level_oy) adj_RadiusB = -0.5;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("adj_RadiusB set to ",adj_RadiusB); SERIAL_ECHOPAIR("adj_RadiusB set to ",adj_RadiusB);
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
#endif #endif
} }
} }
...@@ -2837,12 +2861,14 @@ void process_commands() ...@@ -2837,12 +2861,14 @@ void process_commands()
if (((adj_RadiusC > 0) and (bed_level_z > bed_level_oz)) or ((adj_RadiusC < 0) and (bed_level_z < bed_level_oz))) adj_RadiusC = -(adj_RadiusC / 2); if (((adj_RadiusC > 0) and (bed_level_z > bed_level_oz)) or ((adj_RadiusC < 0) and (bed_level_z < bed_level_oz))) adj_RadiusC = -(adj_RadiusC / 2);
//Delta radius adjustment complete? //Delta radius adjustment complete?
if ((bed_level_c >= (adj_r_target - ac_prec)) and (bed_level_c <= (adj_r_target + ac_prec))) adj_r_done = true; else adj_r_done = false; if ((bed_level_c >= (adj_r_target - ac_prec)) and (bed_level_c <= (adj_r_target + ac_prec))) adj_r_done = true;
else adj_r_done = false;
//Diag Rod adjustment complete? //Diag Rod adjustment complete?
if ((adj_dr_target >= (adj_r_target - ac_prec)) and (adj_dr_target <= (adj_r_target + ac_prec))) adj_dr_done = true; else adj_dr_done = false; if ((adj_dr_target >= (adj_r_target - ac_prec)) and (adj_dr_target <= (adj_r_target + ac_prec))) adj_dr_done = true;
else adj_dr_done = false;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
SERIAL_ECHOPAIR("c: ", bed_level_c); SERIAL_ECHOPAIR("c: ", bed_level_c);
SERIAL_ECHOPAIR(" x: ", bed_level_x); SERIAL_ECHOPAIR(" x: ", bed_level_x);
SERIAL_ECHOPAIR(" y: ", bed_level_y); SERIAL_ECHOPAIR(" y: ", bed_level_y);
...@@ -2857,9 +2883,11 @@ void process_commands() ...@@ -2857,9 +2883,11 @@ void process_commands()
SERIAL_PROTOCOL_F(delta_diagonal_rod, 4); SERIAL_PROTOCOL_F(delta_diagonal_rod, 4);
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
SERIAL_ECHO("Radius Adj Complete: "); SERIAL_ECHO("Radius Adj Complete: ");
if (adj_r_done == true) SERIAL_ECHO("Yes"); else SERIAL_ECHO("No"); if (adj_r_done == true) SERIAL_ECHO("Yes");
else SERIAL_ECHO("No");
SERIAL_ECHO(" DiagRod Adj Complete: "); SERIAL_ECHO(" DiagRod Adj Complete: ");
if (adj_dr_done == true) SERIAL_ECHO("Yes"); else SERIAL_ECHO("No"); if (adj_dr_done == true) SERIAL_ECHO("Yes");
else SERIAL_ECHO("No");
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
SERIAL_ECHOPAIR("RadiusA Error: ",radiusErrorA); SERIAL_ECHOPAIR("RadiusA Error: ",radiusErrorA);
SERIAL_ECHOPAIR(" (adjust: ",adj_RadiusA); SERIAL_ECHOPAIR(" (adjust: ",adj_RadiusA);
...@@ -2876,10 +2904,12 @@ void process_commands() ...@@ -2876,10 +2904,12 @@ void process_commands()
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
SERIAL_ECHOPAIR("DeltaAlphaC: ",adj_AlphaC); SERIAL_ECHOPAIR("DeltaAlphaC: ",adj_AlphaC);
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
#endif #endif
} while (((adj_r_done == false) or (adj_dr_done = false)) and (loopcount < iterations)); }
} else { while (((adj_r_done == false) or (adj_dr_done = false)) and (loopcount < iterations));
}
else {
SERIAL_ECHOLN("Delta Geometry: OK"); SERIAL_ECHOLN("Delta Geometry: OK");
} }
} }
...@@ -2901,7 +2931,8 @@ void process_commands() ...@@ -2901,7 +2931,8 @@ void process_commands()
and (bed_level_ox >= -ac_prec) and (bed_level_ox <= ac_prec) and (bed_level_ox >= -ac_prec) and (bed_level_ox <= ac_prec)
and (bed_level_oy >= -ac_prec) and (bed_level_oy <= ac_prec) and (bed_level_oy >= -ac_prec) and (bed_level_oy <= ac_prec)
and (bed_level_oz >= -ac_prec) and (bed_level_oz <= ac_prec)) loopcount = iterations; and (bed_level_oz >= -ac_prec) and (bed_level_oz <= ac_prec)) loopcount = iterations;
} else { }
else {
if ((bed_level_x >= -ac_prec) and (bed_level_x <= ac_prec) if ((bed_level_x >= -ac_prec) and (bed_level_x <= ac_prec)
and (bed_level_y >= -ac_prec) and (bed_level_y <= ac_prec) and (bed_level_y >= -ac_prec) and (bed_level_y <= ac_prec)
and (bed_level_z >= -ac_prec) and (bed_level_z <= ac_prec) and (bed_level_z >= -ac_prec) and (bed_level_z <= ac_prec)
...@@ -2910,7 +2941,8 @@ void process_commands() ...@@ -2910,7 +2941,8 @@ void process_commands()
} }
loopcount ++; loopcount ++;
} while(loopcount < iterations); }
while(loopcount < iterations);
SERIAL_ECHOLN("Auto Calibration Complete"); SERIAL_ECHOLN("Auto Calibration Complete");
SERIAL_ECHOLN("Issue M500 Command to save calibration settings to EPROM (if enabled)"); SERIAL_ECHOLN("Issue M500 Command to save calibration settings to EPROM (if enabled)");
...@@ -2971,15 +3003,12 @@ void process_commands() ...@@ -2971,15 +3003,12 @@ void process_commands()
prepare_move(); prepare_move();
} }
break; break;
case 90: // G90 case 90: // G90
relative_mode = false; relative_mode = false;
break; break;
case 91: // G91 case 91: // G91
relative_mode = true; relative_mode = true;
break; break;
case 92: // G92 case 92: // G92
if(!code_seen(axis_codes[E_AXIS])) if(!code_seen(axis_codes[E_AXIS]))
st_synchronize(); st_synchronize();
...@@ -2988,16 +3017,18 @@ void process_commands() ...@@ -2988,16 +3017,18 @@ void process_commands()
if(i == E_AXIS) { if(i == E_AXIS) {
current_position[i] = code_value(); current_position[i] = code_value();
plan_set_e_position(current_position[E_AXIS]); plan_set_e_position(current_position[E_AXIS]);
} else { }
#ifdef SCARA else {
#ifdef SCARA
if (i == X_AXIS || i == Y_AXIS) { if (i == X_AXIS || i == Y_AXIS) {
current_position[i] = code_value(); current_position[i] = code_value();
} else { }
else {
current_position[i] = code_value()+add_homing[i]; current_position[i] = code_value()+add_homing[i];
} }
#else #else
current_position[i] = code_value()+add_homing[i]; current_position[i] = code_value()+add_homing[i];
#endif #endif
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
} }
} }
...@@ -3005,11 +3036,9 @@ void process_commands() ...@@ -3005,11 +3036,9 @@ void process_commands()
break; break;
} }
} }
else if(code_seen('M')){
switch((int)code_value()){
else if(code_seen('M'))
{
switch( (int)code_value() )
{
#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
...@@ -3028,7 +3057,8 @@ void process_commands() ...@@ -3028,7 +3057,8 @@ void process_commands()
manage_inactivity(); manage_inactivity();
lcd_update(); lcd_update();
} }
}else{ }
else {
while(!lcd_clicked()){ while(!lcd_clicked()){
manage_heater(); manage_heater();
manage_inactivity(); manage_inactivity();
...@@ -3041,7 +3071,7 @@ void process_commands() ...@@ -3041,7 +3071,7 @@ void process_commands()
#endif #endif
#ifdef LASERBEAM #ifdef LASERBEAM
case 03: // M03 S - Setting laser beam case 3: // M03 S - Setting laser beam
{ {
if(code_seen('S')) { if(code_seen('S')) {
laser_ttl_modulation=constrain(code_value(),0,255); laser_ttl_modulation=constrain(code_value(),0,255);
...@@ -3051,11 +3081,11 @@ void process_commands() ...@@ -3051,11 +3081,11 @@ void process_commands()
} }
} }
break; break;
case 04: // M04 - Turn on laser beam case 4: // M04 - Turn on laser beam
digitalWrite(LASER_PWR_PIN, HIGH); digitalWrite(LASER_PWR_PIN, HIGH);
laser_ttl_modulation = 0; laser_ttl_modulation = 0;
break; break;
case 05: // M05 - Turn off laser beam case 5: // M05 - Turn off laser beam
digitalWrite(LASER_PWR_PIN, LOW); digitalWrite(LASER_PWR_PIN, LOW);
laser_ttl_modulation=0; laser_ttl_modulation=0;
break; break;
...@@ -3078,13 +3108,10 @@ void process_commands() ...@@ -3078,13 +3108,10 @@ void process_commands()
SERIAL_PROTOCOLLNPGM(MSG_END_FILE_LIST); SERIAL_PROTOCOLLNPGM(MSG_END_FILE_LIST);
break; break;
case 21: // M21 - init SD card case 21: // M21 - init SD card
card.initsd(); card.initsd();
break; break;
case 22: //M22 - release SD card case 22: //M22 - release SD card
card.release(); card.release();
break; break;
case 23: //M23 - Select file case 23: //M23 - Select file
starpos = (strchr(strchr_pointer + 4,'*')); starpos = (strchr(strchr_pointer + 4,'*'));
...@@ -3136,28 +3163,24 @@ void process_commands() ...@@ -3136,28 +3163,24 @@ void process_commands()
{ {
if(card.sdprinting) { if(card.sdprinting) {
st_synchronize(); st_synchronize();
} }
starpos = (strchr(strchr_pointer + 4,'*')); starpos = (strchr(strchr_pointer + 4,'*'));
char* namestartpos = (strchr(strchr_pointer + 4,'!')); //find ! to indicate filename string start. char* namestartpos = (strchr(strchr_pointer + 4,'!')); //find ! to indicate filename string start.
if(namestartpos==NULL) if(namestartpos==NULL) {
{
namestartpos=strchr_pointer + 4; //default name position, 4 letters after the M namestartpos=strchr_pointer + 4; //default name position, 4 letters after the M
} }
else else {
namestartpos++; //to skip the '!' namestartpos++; //to skip the '!'
}
if(starpos!=NULL) if(starpos!=NULL) *(starpos)='\0';
*(starpos)='\0';
bool call_procedure=(code_seen('P')); bool call_procedure=(code_seen('P'));
if(strchr_pointer>namestartpos) if(strchr_pointer>namestartpos) call_procedure=false; //false alert, 'P' found within filename
call_procedure=false; //false alert, 'P' found within filename
if( card.cardOK ) if(card.cardOK) {
{
card.openFile(namestartpos,true,!call_procedure); card.openFile(namestartpos,true,!call_procedure);
if(code_seen('S')) if(code_seen('S'))
if(strchr_pointer<namestartpos) //only if "S" is occuring _before_ the filename if(strchr_pointer<namestartpos) //only if "S" is occuring _before_ the filename
...@@ -3166,8 +3189,10 @@ void process_commands() ...@@ -3166,8 +3189,10 @@ void process_commands()
if(!call_procedure) if(!call_procedure)
starttime=millis(); //procedure calls count as normal print time. starttime=millis(); //procedure calls count as normal print time.
} }
} break; }
break;
case 928: //M928 - Start SD write case 928: //M928 - Start SD write
{
starpos = (strchr(strchr_pointer + 5,'*')); starpos = (strchr(strchr_pointer + 5,'*'));
if(starpos != NULL){ if(starpos != NULL){
char* npos = strchr(cmdbuffer[bufindr], 'N'); char* npos = strchr(cmdbuffer[bufindr], 'N');
...@@ -3175,8 +3200,8 @@ void process_commands() ...@@ -3175,8 +3200,8 @@ void process_commands()
*(starpos) = '\0'; *(starpos) = '\0';
} }
card.openLogFile(strchr_pointer+5); card.openLogFile(strchr_pointer+5);
}
break; break;
#endif //SDSUPPORT #endif //SDSUPPORT
case 31: //M31 take time since the start of the SD print or an M109 command case 31: //M31 take time since the start of the SD print or an M109 command
...@@ -3195,8 +3220,8 @@ void process_commands() ...@@ -3195,8 +3220,8 @@ void process_commands()
} }
break; break;
case 42: //M42 -Change pin status via gcode case 42: //M42 -Change pin status via gcode
if (code_seen('S'))
{ {
if (code_seen('S')) {
int pin_status = code_value(); int pin_status = code_value();
int pin_number = LED_PIN; int pin_number = LED_PIN;
if (code_seen('P') && pin_status >= 0 && pin_status <= 255) if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
...@@ -3209,45 +3234,25 @@ void process_commands() ...@@ -3209,45 +3234,25 @@ void process_commands()
break; break;
} }
} }
#if defined(FAN_PIN) && FAN_PIN > -1 #if defined(FAN_PIN) && FAN_PIN > -1
if (pin_number == FAN_PIN) if (pin_number == FAN_PIN) fanSpeed = pin_status;
fanSpeed = pin_status; #endif
#endif if (pin_number > -1) {
if (pin_number > -1)
{
pinMode(pin_number, OUTPUT); pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, pin_status); digitalWrite(pin_number, pin_status);
analogWrite(pin_number, pin_status); analogWrite(pin_number, pin_status);
} }
} }
}
break; break;
/**********************************************************************\
****************** Firmware Marlin by MagoKimbra **********************\
***********************************************************************\
* M49 Z-Probe repeatability measurement function.
*
* Usage: M49 <n #_samples> <X X_position_for_samples> <Y Y_position_for_samples> <V Verbose_Level> <Engage_probe_for_each_reading> <L legs_of_movement_prior_to_doing_probe>
*
* This function assumes the bed has been homed. Specificaly, that a G28 command
* as been issued prior to invoking the M49 Z-Probe repeatability measurement function.
* Any information generated by a prior G29 Bed leveling command will be lost and need to be
* regenerated.
*
* The number of samples will default to 10 if not specified. You can use upper or lower case
* letters for any of the options EXCEPT n. n must be in lower case because Marlin uses a capital
* N for its communication protocol and will get horribly confused if you send it a capital N.
*
***********************************************************************/
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
#ifdef Z_PROBE_REPEATABILITY_TEST #ifdef Z_PROBE_REPEATABILITY_TEST
case 49: // M49 Z-Probe repeatability case 49: // M49 Z-Probe repeatability
{ {
#if Z_MIN_PIN == -1 #if Z_MIN_PIN == -1
#error "You must have a Z_MIN endstop in order to enable calculation of Z-Probe repeatability." #error "You must have a Z_MIN endstop in order to enable calculation of Z-Probe repeatability."
#endif #endif
double sum=0.0; double sum=0.0;
double mean=0.0; double mean=0.0;
...@@ -3284,12 +3289,11 @@ void process_commands() ...@@ -3284,12 +3289,11 @@ void process_commands()
Z_start_location = st_get_position_mm(Z_AXIS) + Z_RAISE_BEFORE_PROBING; Z_start_location = st_get_position_mm(Z_AXIS) + Z_RAISE_BEFORE_PROBING;
ext_position = st_get_position_mm(E_AXIS); ext_position = st_get_position_mm(E_AXIS);
if (code_seen('E') || code_seen('e') ) if (code_seen('E') || code_seen('e')) engage_probe_for_each_reading++;
engage_probe_for_each_reading++;
if (code_seen('X') || code_seen('x') ) { if (code_seen('X') || code_seen('x')) {
X_probe_location = code_value() - X_PROBE_OFFSET_FROM_EXTRUDER; X_probe_location = code_value() - X_PROBE_OFFSET_FROM_EXTRUDER;
if (X_probe_location<X_MIN_POS || X_probe_location>X_MAX_POS ) { if (X_probe_location<X_MIN_POS || X_probe_location>X_MAX_POS) {
SERIAL_PROTOCOLPGM("?Specified X position out of range.\n"); SERIAL_PROTOCOLPGM("?Specified X position out of range.\n");
goto Sigma_Exit; goto Sigma_Exit;
} }
...@@ -3313,9 +3317,9 @@ void process_commands() ...@@ -3313,9 +3317,9 @@ void process_commands()
} }
} }
// //
// Do all the preliminary setup work. First raise the probe. // Do all the preliminary setup work. First raise the probe.
// //
st_synchronize(); st_synchronize();
plan_bed_level_matrix.set_to_identity(); plan_bed_level_matrix.set_to_identity();
...@@ -3325,11 +3329,11 @@ void process_commands() ...@@ -3325,11 +3329,11 @@ void process_commands()
active_extruder, active_driver); active_extruder, active_driver);
st_synchronize(); st_synchronize();
// //
// Now get everything to the specified probe point So we can safely do a probe to // Now get everything to the specified probe point So we can safely do a probe to
// get us close to the bed. If the Z-Axis is far from the bed, we don't want to // get us close to the bed. If the Z-Axis is far from the bed, we don't want to
// use that as a starting point for each probe. // use that as a starting point for each probe.
// //
if (verbose_level > 2) if (verbose_level > 2)
SERIAL_PROTOCOL("Positioning probe for the test.\n"); SERIAL_PROTOCOL("Positioning probe for the test.\n");
...@@ -3344,10 +3348,10 @@ void process_commands() ...@@ -3344,10 +3348,10 @@ void process_commands()
current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS); current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS);
current_position[E_AXIS] = ext_position = st_get_position_mm(E_AXIS); current_position[E_AXIS] = ext_position = st_get_position_mm(E_AXIS);
// //
// OK, do the inital probe to get us close to the bed. // OK, do the inital probe to get us close to the bed.
// Then retrace the right amount and use that in subsequent probes // Then retrace the right amount and use that in subsequent probes
// //
engage_z_probe(); engage_z_probe();
...@@ -3364,8 +3368,7 @@ void process_commands() ...@@ -3364,8 +3368,7 @@ void process_commands()
st_synchronize(); st_synchronize();
current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS); current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS);
if (engage_probe_for_each_reading) if (engage_probe_for_each_reading) retract_z_probe();
retract_z_probe();
for( n=0; n<n_samples; n++) { for( n=0; n<n_samples; n++) {
...@@ -3379,10 +3382,10 @@ void process_commands() ...@@ -3379,10 +3382,10 @@ void process_commands()
radius = (unsigned long) millis() % (long) (X_MAX_LENGTH/4); // limit how far out to go radius = (unsigned long) millis() % (long) (X_MAX_LENGTH/4); // limit how far out to go
theta = (float) ((unsigned long) millis() % (long) 360) / (360./(2*3.1415926)); // turn into radians theta = (float) ((unsigned long) millis() % (long) 360) / (360./(2*3.1415926)); // turn into radians
//SERIAL_ECHOPAIR("starting radius: ",radius); //SERIAL_ECHOPAIR("starting radius: ",radius);
//SERIAL_ECHOPAIR(" theta: ",theta); //SERIAL_ECHOPAIR(" theta: ",theta);
//SERIAL_ECHOPAIR(" direction: ",rotational_direction); //SERIAL_ECHOPAIR(" direction: ",rotational_direction);
//SERIAL_PROTOCOLLNPGM(""); //SERIAL_PROTOCOLLNPGM("");
for( l=0; l<n_legs-1; l++) { for( l=0; l<n_legs-1; l++) {
if (rotational_direction==1) if (rotational_direction==1)
...@@ -3428,18 +3431,18 @@ void process_commands() ...@@ -3428,18 +3431,18 @@ void process_commands()
sample_set[n] = current_position[Z_AXIS]; sample_set[n] = current_position[Z_AXIS];
// //
// Get the current mean for the data points we have so far // Get the current mean for the data points we have so far
// //
sum=0.0; sum=0.0;
for( j=0; j<=n; j++) { for( j=0; j<=n; j++) {
sum = sum + sample_set[j]; sum = sum + sample_set[j];
} }
mean = sum / (double (n+1)); mean = sum / (double (n+1));
// //
// Now, use that mean to calculate the standard deviation for the // Now, use that mean to calculate the standard deviation for the
// data points we have so far // data points we have so far
// //
sum=0.0; sum=0.0;
for( j=0; j<=n; j++) { for( j=0; j<=n; j++) {
...@@ -3481,7 +3484,7 @@ void process_commands() ...@@ -3481,7 +3484,7 @@ void process_commands()
clean_up_after_endstop_move(); clean_up_after_endstop_move();
// enable_endstops(true); // enable_endstops(true);
if (verbose_level > 0) { if (verbose_level > 0) {
SERIAL_PROTOCOLPGM("Mean: "); SERIAL_PROTOCOLPGM("Mean: ");
...@@ -3489,9 +3492,9 @@ void process_commands() ...@@ -3489,9 +3492,9 @@ void process_commands()
SERIAL_PROTOCOLPGM("\n"); SERIAL_PROTOCOLPGM("\n");
} }
SERIAL_PROTOCOLPGM("Standard Deviation: "); SERIAL_PROTOCOLPGM("Standard Deviation: ");
SERIAL_PROTOCOL_F(sigma, 6); SERIAL_PROTOCOL_F(sigma, 6);
SERIAL_PROTOCOLPGM("\n\n"); SERIAL_PROTOCOLPGM("\n\n");
Sigma_Exit: Sigma_Exit:
break; break;
...@@ -3531,17 +3534,17 @@ Sigma_Exit: ...@@ -3531,17 +3534,17 @@ Sigma_Exit:
case 105 : // M105 case 105 : // M105
if(setTargetedHotend(105)) break; if(setTargetedHotend(105)) break;
if(debugDryrun()) break; if(debugDryrun()) break;
#if defined(TEMP_0_PIN) && TEMP_0_PIN > -1 #if defined(TEMP_0_PIN) && TEMP_0_PIN > -1
SERIAL_PROTOCOLPGM("ok T:"); SERIAL_PROTOCOLPGM("ok T:");
SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1); SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1);
SERIAL_PROTOCOLPGM(" /"); SERIAL_PROTOCOLPGM(" /");
SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder),1); SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder),1);
#if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
SERIAL_PROTOCOLPGM(" B:"); SERIAL_PROTOCOLPGM(" B:");
SERIAL_PROTOCOL_F(degBed(),1); SERIAL_PROTOCOL_F(degBed(),1);
SERIAL_PROTOCOLPGM(" /"); SERIAL_PROTOCOLPGM(" /");
SERIAL_PROTOCOL_F(degTargetBed(),1); SERIAL_PROTOCOL_F(degTargetBed(),1);
#endif //TEMP_BED_PIN #endif //TEMP_BED_PIN
for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) { for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
SERIAL_PROTOCOLPGM(" T"); SERIAL_PROTOCOLPGM(" T");
SERIAL_PROTOCOL(cur_extruder); SERIAL_PROTOCOL(cur_extruder);
...@@ -3550,34 +3553,34 @@ Sigma_Exit: ...@@ -3550,34 +3553,34 @@ Sigma_Exit:
SERIAL_PROTOCOLPGM(" /"); SERIAL_PROTOCOLPGM(" /");
SERIAL_PROTOCOL_F(degTargetHotend(cur_extruder),1); SERIAL_PROTOCOL_F(degTargetHotend(cur_extruder),1);
} }
#else // no TEMP_0_PIN #else // no TEMP_0_PIN
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORLNPGM(MSG_ERR_NO_THERMISTORS); SERIAL_ERRORLNPGM(MSG_ERR_NO_THERMISTORS);
#endif //end TEMP_0_PIN #endif //end TEMP_0_PIN
SERIAL_PROTOCOLPGM(" @:"); SERIAL_PROTOCOLPGM(" @:");
#ifdef HOTEND_WATTS #ifdef HOTEND_WATTS
SERIAL_PROTOCOL((HOTEND_WATTS * getHeaterPower(tmp_hotend))/127); SERIAL_PROTOCOL((HOTEND_WATTS * getHeaterPower(tmp_hotend))/127);
SERIAL_PROTOCOLPGM("W"); SERIAL_PROTOCOLPGM("W");
#else #else
SERIAL_PROTOCOL(getHeaterPower(tmp_extruder)); SERIAL_PROTOCOL(getHeaterPower(tmp_extruder));
#endif #endif
SERIAL_PROTOCOLPGM(" B@:"); SERIAL_PROTOCOLPGM(" B@:");
#ifdef BED_WATTS #ifdef BED_WATTS
SERIAL_PROTOCOL((BED_WATTS * getHeaterPower(-1))/127); SERIAL_PROTOCOL((BED_WATTS * getHeaterPower(-1))/127);
SERIAL_PROTOCOLPGM("W"); SERIAL_PROTOCOLPGM("W");
#else #else
SERIAL_PROTOCOL(getHeaterPower(-1)); SERIAL_PROTOCOL(getHeaterPower(-1));
#endif #endif
#ifdef SHOW_TEMP_ADC_VALUES #ifdef SHOW_TEMP_ADC_VALUES
#if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
SERIAL_PROTOCOLPGM(" ADC B:"); SERIAL_PROTOCOLPGM(" ADC B:");
SERIAL_PROTOCOL_F(degBed(),1); SERIAL_PROTOCOL_F(degBed(),1);
SERIAL_PROTOCOLPGM("C->"); SERIAL_PROTOCOLPGM("C->");
SERIAL_PROTOCOL_F(rawBedTemp()/OVERSAMPLENR,0); SERIAL_PROTOCOL_F(rawBedTemp()/OVERSAMPLENR,0);
#endif #endif
for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) { for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
SERIAL_PROTOCOLPGM(" T"); SERIAL_PROTOCOLPGM(" T");
SERIAL_PROTOCOL(cur_extruder); SERIAL_PROTOCOL(cur_extruder);
...@@ -3586,7 +3589,7 @@ Sigma_Exit: ...@@ -3586,7 +3589,7 @@ Sigma_Exit:
SERIAL_PROTOCOLPGM("C->"); SERIAL_PROTOCOLPGM("C->");
SERIAL_PROTOCOL_F(rawHotendTemp(cur_extruder)/OVERSAMPLENR,0); SERIAL_PROTOCOL_F(rawHotendTemp(cur_extruder)/OVERSAMPLENR,0);
} }
#endif #endif
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
return; return;
...@@ -3596,9 +3599,9 @@ Sigma_Exit: ...@@ -3596,9 +3599,9 @@ Sigma_Exit:
if(setTargetedHotend(109)) break; if(setTargetedHotend(109)) break;
if(debugDryrun()) break; if(debugDryrun()) break;
LCD_MESSAGEPGM(MSG_HEATING); LCD_MESSAGEPGM(MSG_HEATING);
#ifdef AUTOTEMP #ifdef AUTOTEMP
autotemp_enabled=false; autotemp_enabled=false;
#endif #endif
if (code_seen('S')) { if (code_seen('S')) {
setTargetHotend(code_value(), tmp_extruder); setTargetHotend(code_value(), tmp_extruder);
#ifdef DUAL_X_CARRIAGE #ifdef DUAL_X_CARRIAGE
...@@ -3606,7 +3609,8 @@ Sigma_Exit: ...@@ -3606,7 +3609,8 @@ Sigma_Exit:
setTargetHotend1(code_value() == 0.0 ? 0.0 : code_value() + duplicate_extruder_temp_offset); setTargetHotend1(code_value() == 0.0 ? 0.0 : code_value() + duplicate_extruder_temp_offset);
#endif #endif
CooldownNoWait = true; CooldownNoWait = true;
} else if (code_seen('R')) { }
else if (code_seen('R')) {
setTargetHotend(code_value(), tmp_extruder); setTargetHotend(code_value(), tmp_extruder);
#ifdef DUAL_X_CARRIAGE #ifdef DUAL_X_CARRIAGE
if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && tmp_extruder == 0) if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && tmp_extruder == 0)
...@@ -3614,7 +3618,7 @@ Sigma_Exit: ...@@ -3614,7 +3618,7 @@ Sigma_Exit:
#endif #endif
CooldownNoWait = false; CooldownNoWait = false;
} }
#ifdef AUTOTEMP #ifdef AUTOTEMP
if (code_seen('S')) autotemp_min=code_value(); if (code_seen('S')) autotemp_min=code_value();
if (code_seen('B')) autotemp_max=code_value(); if (code_seen('B')) autotemp_max=code_value();
if (code_seen('F')) if (code_seen('F'))
...@@ -3622,7 +3626,7 @@ Sigma_Exit: ...@@ -3622,7 +3626,7 @@ Sigma_Exit:
autotemp_factor=code_value(); autotemp_factor=code_value();
autotemp_enabled=true; autotemp_enabled=true;
} }
#endif #endif
setWatch(); setWatch();
codenum = millis(); codenum = millis();
...@@ -3632,23 +3636,23 @@ Sigma_Exit: ...@@ -3632,23 +3636,23 @@ Sigma_Exit:
cancel_heatup = false; cancel_heatup = false;
#ifdef TEMP_RESIDENCY_TIME #ifdef TEMP_RESIDENCY_TIME
long residencyStart; long residencyStart;
residencyStart = -1; residencyStart = -1;
/* continue to loop until we have reached the target temp /* continue to loop until we have reached the target temp
_and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
while((!cancel_heatup)&&((residencyStart == -1) || while((!cancel_heatup)&&((residencyStart == -1) ||
(residencyStart >= 0 && (((unsigned int) (millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL)))) ) { (residencyStart >= 0 && (((unsigned int) (millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL)))) ) {
#else #else
while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) { while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
#endif //TEMP_RESIDENCY_TIME #endif //TEMP_RESIDENCY_TIME
if( (millis() - codenum) > 1000UL ) if( (millis() - codenum) > 1000UL )
{ //Print Temp Reading and remaining time every 1 second while heating up/cooling down { //Print Temp Reading and remaining time every 1 second while heating up/cooling down
SERIAL_PROTOCOLPGM("T:"); SERIAL_PROTOCOLPGM("T:");
SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1); SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1);
SERIAL_PROTOCOLPGM(" E:"); SERIAL_PROTOCOLPGM(" E:");
SERIAL_PROTOCOL((int)tmp_extruder); SERIAL_PROTOCOL((int)tmp_extruder);
#ifdef TEMP_RESIDENCY_TIME #ifdef TEMP_RESIDENCY_TIME
SERIAL_PROTOCOLPGM(" W:"); SERIAL_PROTOCOLPGM(" W:");
if(residencyStart > -1) if(residencyStart > -1)
{ {
...@@ -3659,15 +3663,15 @@ Sigma_Exit: ...@@ -3659,15 +3663,15 @@ Sigma_Exit:
{ {
SERIAL_PROTOCOLLN( "?" ); SERIAL_PROTOCOLLN( "?" );
} }
#else #else
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
#endif #endif
codenum = millis(); codenum = millis();
} }
manage_heater(); manage_heater();
manage_inactivity(); manage_inactivity();
lcd_update(); lcd_update();
#ifdef TEMP_RESIDENCY_TIME #ifdef TEMP_RESIDENCY_TIME
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
or when current temp falls outside the hysteresis after target temp was reached */ or when current temp falls outside the hysteresis after target temp was reached */
if ((residencyStart == -1 && target_direction && (degHotend(tmp_extruder) >= (degTargetHotend(tmp_extruder)-TEMP_WINDOW))) || if ((residencyStart == -1 && target_direction && (degHotend(tmp_extruder) >= (degTargetHotend(tmp_extruder)-TEMP_WINDOW))) ||
...@@ -3676,7 +3680,7 @@ Sigma_Exit: ...@@ -3676,7 +3680,7 @@ Sigma_Exit:
{ {
residencyStart = millis(); residencyStart = millis();
} }
#endif //TEMP_RESIDENCY_TIME #endif //TEMP_RESIDENCY_TIME
} }
LCD_MESSAGEPGM(MSG_HEATING_COMPLETE); LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
starttime=millis(); starttime=millis();
...@@ -3684,13 +3688,14 @@ Sigma_Exit: ...@@ -3684,13 +3688,14 @@ Sigma_Exit:
} }
break; break;
case 190: // M190 - Wait for bed heater to reach target. case 190: // M190 - Wait for bed heater to reach target.
#if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
if(debugDryrun()) break; if(debugDryrun()) break;
LCD_MESSAGEPGM(MSG_BED_HEATING); LCD_MESSAGEPGM(MSG_BED_HEATING);
if (code_seen('S')) { if (code_seen('S')) {
setTargetBed(code_value()); setTargetBed(code_value());
CooldownNoWait = true; CooldownNoWait = true;
} else if (code_seen('R')) { }
else if (code_seen('R')) {
setTargetBed(code_value()); setTargetBed(code_value());
CooldownNoWait = false; CooldownNoWait = false;
} }
...@@ -3719,10 +3724,10 @@ Sigma_Exit: ...@@ -3719,10 +3724,10 @@ Sigma_Exit:
} }
LCD_MESSAGEPGM(MSG_BED_DONE); LCD_MESSAGEPGM(MSG_BED_DONE);
previous_millis_cmd = millis(); previous_millis_cmd = millis();
#endif #endif
break; break;
#if defined(FAN_PIN) && FAN_PIN > -1 #if defined(FAN_PIN) && FAN_PIN > -1
case 106: //M106 Fan On case 106: //M106 Fan On
if (code_seen('S')){ if (code_seen('S')){
fanSpeed=constrain(code_value(),0,255); fanSpeed=constrain(code_value(),0,255);
...@@ -3734,10 +3739,10 @@ Sigma_Exit: ...@@ -3734,10 +3739,10 @@ Sigma_Exit:
case 107: //M107 Fan Off case 107: //M107 Fan Off
fanSpeed = 0; fanSpeed = 0;
break; break;
#endif //FAN_PIN #endif //FAN_PIN
#ifdef BARICUDA #ifdef BARICUDA
// PWM for HEATER_1_PIN // PWM for HEATER_1_PIN
#if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 #if defined(HEATER_1_PIN) && HEATER_1_PIN > -1
case 126: //M126 valve open case 126: //M126 valve open
if (code_seen('S')){ if (code_seen('S')){
ValvePressure=constrain(code_value(),0,255); ValvePressure=constrain(code_value(),0,255);
...@@ -3749,10 +3754,10 @@ Sigma_Exit: ...@@ -3749,10 +3754,10 @@ Sigma_Exit:
case 127: //M127 valve closed case 127: //M127 valve closed
ValvePressure = 0; ValvePressure = 0;
break; break;
#endif //HEATER_1_PIN #endif //HEATER_1_PIN
// PWM for HEATER_2_PIN // PWM for HEATER_2_PIN
#if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 #if defined(HEATER_2_PIN) && HEATER_2_PIN > -1
case 128: //M128 valve open case 128: //M128 valve open
if (code_seen('S')){ if (code_seen('S')){
EtoPPressure=constrain(code_value(),0,255); EtoPPressure=constrain(code_value(),0,255);
...@@ -3764,10 +3769,10 @@ Sigma_Exit: ...@@ -3764,10 +3769,10 @@ Sigma_Exit:
case 129: //M129 valve closed case 129: //M129 valve closed
EtoPPressure = 0; EtoPPressure = 0;
break; break;
#endif //HEATER_2_PIN #endif //HEATER_2_PIN
#endif #endif
#if defined(PS_ON_PIN) && PS_ON_PIN > -1 #if defined(PS_ON_PIN) && PS_ON_PIN > -1
case 80: // M80 - Turn on Power Supply case 80: // M80 - Turn on Power Supply
SET_OUTPUT(PS_ON_PIN); //GND SET_OUTPUT(PS_ON_PIN); //GND
WRITE(PS_ON_PIN, PS_ON_AWAKE); WRITE(PS_ON_PIN, PS_ON_AWAKE);
...@@ -3775,18 +3780,18 @@ Sigma_Exit: ...@@ -3775,18 +3780,18 @@ Sigma_Exit:
// If you have a switch on suicide pin, this is useful // If you have a switch on suicide pin, this is useful
// if you want to start another print with suicide feature after // if you want to start another print with suicide feature after
// a print without suicide... // a print without suicide...
#if defined SUICIDE_PIN && SUICIDE_PIN > -1 #if defined SUICIDE_PIN && SUICIDE_PIN > -1
SET_OUTPUT(SUICIDE_PIN); SET_OUTPUT(SUICIDE_PIN);
WRITE(SUICIDE_PIN, HIGH); WRITE(SUICIDE_PIN, HIGH);
#endif #endif
#ifdef ULTIPANEL #ifdef ULTIPANEL
powersupply = true; powersupply = true;
LCD_MESSAGEPGM(WELCOME_MSG); LCD_MESSAGEPGM(WELCOME_MSG);
lcd_update(); lcd_update();
#endif #endif
break; break;
#endif #endif
case 81: // M81 - Turn off Power Supply case 81: // M81 - Turn off Power Supply
disable_heater(); disable_heater();
...@@ -3794,18 +3799,18 @@ Sigma_Exit: ...@@ -3794,18 +3799,18 @@ Sigma_Exit:
finishAndDisableSteppers(); finishAndDisableSteppers();
fanSpeed = 0; fanSpeed = 0;
delay(1000); // Wait a little before to switch off delay(1000); // Wait a little before to switch off
#if defined(SUICIDE_PIN) && SUICIDE_PIN > -1 #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
st_synchronize(); st_synchronize();
suicide(); suicide();
#elif defined(PS_ON_PIN) && PS_ON_PIN > -1 #elif defined(PS_ON_PIN) && PS_ON_PIN > -1
SET_OUTPUT(PS_ON_PIN); SET_OUTPUT(PS_ON_PIN);
WRITE(PS_ON_PIN, PS_ON_ASLEEP); WRITE(PS_ON_PIN, PS_ON_ASLEEP);
#endif #endif
#ifdef ULTIPANEL #ifdef ULTIPANEL
powersupply = false; powersupply = false;
LCD_MESSAGEPGM(MACHINE_NAME" "MSG_OFF"."); LCD_MESSAGEPGM(MACHINE_NAME" "MSG_OFF".");
lcd_update(); lcd_update();
#endif #endif
break; break;
case 82: case 82:
...@@ -3833,14 +3838,14 @@ Sigma_Exit: ...@@ -3833,14 +3838,14 @@ Sigma_Exit:
if(code_seen('X')) disable_x(); if(code_seen('X')) disable_x();
if(code_seen('Y')) disable_y(); if(code_seen('Y')) disable_y();
if(code_seen('Z')) disable_z(); if(code_seen('Z')) disable_z();
#if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS #if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
if(code_seen('E')) { if(code_seen('E')) {
disable_e0(); disable_e0();
disable_e1(); disable_e1();
disable_e2(); disable_e2();
disable_e3(); disable_e3();
} }
#endif #endif
} }
} }
break; break;
...@@ -3926,37 +3931,37 @@ Sigma_Exit: ...@@ -3926,37 +3931,37 @@ Sigma_Exit:
break; break;
case 119: // M119 case 119: // M119
SERIAL_PROTOCOLLN(MSG_M119_REPORT); SERIAL_PROTOCOLLN(MSG_M119_REPORT);
#if defined(X_MIN_PIN) && X_MIN_PIN > -1 #if defined(X_MIN_PIN) && X_MIN_PIN > -1
SERIAL_PROTOCOLPGM(MSG_X_MIN); SERIAL_PROTOCOLPGM(MSG_X_MIN);
SERIAL_PROTOCOLLN(((READ(X_MIN_PIN)^X_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); SERIAL_PROTOCOLLN(((READ(X_MIN_PIN)^X_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
#endif #endif
#if defined(X_MAX_PIN) && X_MAX_PIN > -1 #if defined(X_MAX_PIN) && X_MAX_PIN > -1
SERIAL_PROTOCOLPGM(MSG_X_MAX); SERIAL_PROTOCOLPGM(MSG_X_MAX);
SERIAL_PROTOCOLLN(((READ(X_MAX_PIN)^X_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); SERIAL_PROTOCOLLN(((READ(X_MAX_PIN)^X_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
#endif #endif
#if defined(Y_MIN_PIN) && Y_MIN_PIN > -1 #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
SERIAL_PROTOCOLPGM(MSG_Y_MIN); SERIAL_PROTOCOLPGM(MSG_Y_MIN);
SERIAL_PROTOCOLLN(((READ(Y_MIN_PIN)^Y_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); SERIAL_PROTOCOLLN(((READ(Y_MIN_PIN)^Y_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
#endif #endif
#if defined(Y_MAX_PIN) && Y_MAX_PIN > -1 #if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
SERIAL_PROTOCOLPGM(MSG_Y_MAX); SERIAL_PROTOCOLPGM(MSG_Y_MAX);
SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
#endif #endif
#if defined(Z_MIN_PIN) && Z_MIN_PIN > -1 #if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
SERIAL_PROTOCOLPGM(MSG_Z_MIN); SERIAL_PROTOCOLPGM(MSG_Z_MIN);
SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
#endif #endif
#if defined(Z_MAX_PIN) && Z_MAX_PIN > -1 #if defined(Z_MAX_PIN) && Z_MAX_PIN > -1
SERIAL_PROTOCOLPGM(MSG_Z_MAX); SERIAL_PROTOCOLPGM(MSG_Z_MAX);
SERIAL_PROTOCOLLN(((READ(Z_MAX_PIN)^Z_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); SERIAL_PROTOCOLLN(((READ(Z_MAX_PIN)^Z_MAX_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
#endif #endif
#if defined(E_MIN_PIN) && E_MIN_PIN > -1 #if defined(E_MIN_PIN) && E_MIN_PIN > -1
SERIAL_PROTOCOLPGM(MSG_E_MIN); SERIAL_PROTOCOLPGM(MSG_E_MIN);
SERIAL_PROTOCOLLN(((READ(E_MIN_PIN)^E_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN)); SERIAL_PROTOCOLLN(((READ(E_MIN_PIN)^E_MIN_ENDSTOP_INVERTING)?MSG_ENDSTOP_HIT:MSG_ENDSTOP_OPEN));
#endif #endif
break; break;
//TODO: update for all axis, use for loop //TODO: update for all axis, use for loop
#ifdef BLINKM #ifdef BLINKM
case 150: // M150 case 150: // M150
{ {
byte red; byte red;
...@@ -3970,7 +3975,7 @@ Sigma_Exit: ...@@ -3970,7 +3975,7 @@ Sigma_Exit:
SendColors(red,grn,blu); SendColors(red,grn,blu);
} }
break; break;
#endif //BLINKM #endif //BLINKM
case 200: // M200 D<millimeters> set filament diameter and set E axis units to cubic millimeters (use S0 to set back to millimeters). case 200: // M200 D<millimeters> set filament diameter and set E axis units to cubic millimeters (use S0 to set back to millimeters).
{ {
float area = .0; float area = .0;
...@@ -3979,10 +3984,12 @@ Sigma_Exit: ...@@ -3979,10 +3984,12 @@ Sigma_Exit:
radius = (float)code_value() * .5; radius = (float)code_value() * .5;
if(radius == 0) { if(radius == 0) {
area = 1; area = 1;
} else { }
else {
area = M_PI * pow(radius, 2); area = M_PI * pow(radius, 2);
} }
} else { }
else {
//reserved for setting filament diameter via UFID or filament measuring device //reserved for setting filament diameter via UFID or filament measuring device
break; break;
...@@ -4011,13 +4018,13 @@ Sigma_Exit: ...@@ -4011,13 +4018,13 @@ Sigma_Exit:
// steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner) // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
reset_acceleration_rates(); reset_acceleration_rates();
break; break;
#if 0 // Not used for Sprinter/grbl gen6 #if 0 // Not used for Sprinter/grbl gen6
case 202: // M202 case 202: // M202
for(int8_t i=0; i < NUM_AXIS; i++) { for(int8_t i=0; i < NUM_AXIS; i++) {
if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i]; if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
} }
break; break;
#endif #endif
case 203: // M203 max feedrate mm/sec case 203: // M203 max feedrate mm/sec
for(int8_t i=0; i < NUM_AXIS; i++) { for(int8_t i=0; i < NUM_AXIS; i++) {
if(code_seen(axis_codes[i])) max_feedrate[i] = code_value(); if(code_seen(axis_codes[i])) max_feedrate[i] = code_value();
...@@ -4044,7 +4051,7 @@ Sigma_Exit: ...@@ -4044,7 +4051,7 @@ Sigma_Exit:
{ {
if(code_seen(axis_codes[i])) add_homing[i] = code_value(); if(code_seen(axis_codes[i])) add_homing[i] = code_value();
} }
#ifdef SCARA #ifdef SCARA
if(code_seen('T')) // Theta if(code_seen('T')) // Theta
{ {
add_homing[0] = code_value() ; add_homing[0] = code_value() ;
...@@ -4053,7 +4060,7 @@ Sigma_Exit: ...@@ -4053,7 +4060,7 @@ Sigma_Exit:
{ {
add_homing[1] = code_value() ; add_homing[1] = code_value() ;
} }
#endif #endif
break; break;
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
...@@ -4115,7 +4122,8 @@ Sigma_Exit: ...@@ -4115,7 +4122,8 @@ Sigma_Exit:
float pz = code_value(); float pz = code_value();
if ( !(code_seen(axis_codes[0]) || code_seen(axis_codes[1]) || code_seen(axis_codes[2]) ) ) { // Allow direct set of Z offset without an axis code if ( !(code_seen(axis_codes[0]) || code_seen(axis_codes[1]) || code_seen(axis_codes[2]) ) ) { // Allow direct set of Z offset without an axis code
z_probe_offset[Z_AXIS]= pz; z_probe_offset[Z_AXIS]= pz;
} else { }
else {
for(int8_t i=0; i < 3; i++) { for(int8_t i=0; i < 3; i++) {
if (code_seen(axis_codes[i])) z_probe_offset[i] = code_value(); if (code_seen(axis_codes[i])) z_probe_offset[i] = code_value();
} }
...@@ -4154,7 +4162,7 @@ Sigma_Exit: ...@@ -4154,7 +4162,7 @@ Sigma_Exit:
} }
break; break;
#endif // Delta #endif // Delta
#ifdef FWRETRACT #ifdef FWRETRACT
case 207: //M207 - set retract length S[positive mm] F[feedrate mm/min] Z[additional zlift/hop] case 207: //M207 - set retract length S[positive mm] F[feedrate mm/min] Z[additional zlift/hop]
{ {
if(code_seen('S')) if(code_seen('S'))
...@@ -4169,7 +4177,8 @@ Sigma_Exit: ...@@ -4169,7 +4177,8 @@ Sigma_Exit:
{ {
retract_zlift = code_value() ; retract_zlift = code_value() ;
} }
}break; }
break;
case 208: // M208 - set retract recover length S[positive mm surplus to the M207 S*] F[feedrate mm/min] case 208: // M208 - set retract recover length S[positive mm surplus to the M207 S*] F[feedrate mm/min]
{ {
if(code_seen('S')) if(code_seen('S'))
...@@ -4180,7 +4189,8 @@ Sigma_Exit: ...@@ -4180,7 +4189,8 @@ Sigma_Exit:
{ {
retract_recover_feedrate = code_value()/60 ; retract_recover_feedrate = code_value()/60 ;
} }
}break; }
break;
case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction. case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction.
{ {
if(code_seen('S')) if(code_seen('S'))
...@@ -4192,30 +4202,32 @@ Sigma_Exit: ...@@ -4192,30 +4202,32 @@ Sigma_Exit:
{ {
autoretract_enabled=false; autoretract_enabled=false;
retracted[0]=false; retracted[0]=false;
#if EXTRUDERS > 1 #if EXTRUDERS > 1
retracted[1]=false; retracted[1]=false;
#endif #endif
#if EXTRUDERS > 2 #if EXTRUDERS > 2
retracted[2]=false; retracted[2]=false;
#endif #endif
#if EXTRUDERS > 3 #if EXTRUDERS > 3
retracted[3]=false; retracted[3]=false;
#endif #endif
}break; }
break;
case 1: case 1:
{ {
autoretract_enabled=true; autoretract_enabled=true;
retracted[0]=false; retracted[0]=false;
#if EXTRUDERS > 1 #if EXTRUDERS > 1
retracted[1]=false; retracted[1]=false;
#endif #endif
#if EXTRUDERS > 2 #if EXTRUDERS > 2
retracted[2]=false; retracted[2]=false;
#endif #endif
#if EXTRUDERS > 3 #if EXTRUDERS > 3
retracted[3]=false; retracted[3]=false;
#endif #endif
}break; }
break;
default: default:
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_UNKNOWN_COMMAND); SERIAL_ECHOPGM(MSG_UNKNOWN_COMMAND);
...@@ -4224,12 +4236,12 @@ Sigma_Exit: ...@@ -4224,12 +4236,12 @@ Sigma_Exit:
} }
} }
}break; }
#endif // FWRETRACT break;
#endif // FWRETRACT
#ifndef SINGLENOZZLE #ifndef SINGLENOZZLE
#if EXTRUDERS > 1
#if EXTRUDERS > 1
case 218: // M218 - set hotend offset (in mm), T<extruder_number> X<offset_on_X> Y<offset_on_Y> case 218: // M218 - set hotend offset (in mm), T<extruder_number> X<offset_on_X> Y<offset_on_Y>
{ {
if(setTargetedHotend(218)){ if(setTargetedHotend(218)){
...@@ -4243,12 +4255,12 @@ Sigma_Exit: ...@@ -4243,12 +4255,12 @@ Sigma_Exit:
{ {
extruder_offset[Y_AXIS][tmp_extruder] = code_value(); extruder_offset[Y_AXIS][tmp_extruder] = code_value();
} }
#ifdef DUAL_X_CARRIAGE #ifdef DUAL_X_CARRIAGE
if(code_seen('Z')) if(code_seen('Z'))
{ {
extruder_offset[Z_AXIS][tmp_extruder] = code_value(); extruder_offset[Z_AXIS][tmp_extruder] = code_value();
} }
#endif #endif
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_HOTEND_OFFSET); SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
for(tmp_extruder = 0; tmp_extruder < EXTRUDERS; tmp_extruder++) for(tmp_extruder = 0; tmp_extruder < EXTRUDERS; tmp_extruder++)
...@@ -4257,15 +4269,17 @@ Sigma_Exit: ...@@ -4257,15 +4269,17 @@ Sigma_Exit:
SERIAL_ECHO(extruder_offset[X_AXIS][tmp_extruder]); SERIAL_ECHO(extruder_offset[X_AXIS][tmp_extruder]);
SERIAL_ECHO(","); SERIAL_ECHO(",");
SERIAL_ECHO(extruder_offset[Y_AXIS][tmp_extruder]); SERIAL_ECHO(extruder_offset[Y_AXIS][tmp_extruder]);
#ifdef DUAL_X_CARRIAGE #ifdef DUAL_X_CARRIAGE
SERIAL_ECHO(","); SERIAL_ECHO(",");
SERIAL_ECHO(extruder_offset[Z_AXIS][tmp_extruder]); SERIAL_ECHO(extruder_offset[Z_AXIS][tmp_extruder]);
#endif #endif
} }
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
}break; }
#endif //EXTRUDERS break;
#endif //EXTRUDERS
#endif // SINGLENOZZLE #endif // SINGLENOZZLE
case 220: // M220 S<factor in percent>- set speed factor override percentage case 220: // M220 S<factor in percent>- set speed factor override percentage
{ {
if(code_seen('S')) if(code_seen('S'))
...@@ -4293,7 +4307,6 @@ Sigma_Exit: ...@@ -4293,7 +4307,6 @@ Sigma_Exit:
} }
} }
break; break;
case 226: // M226 P<pin number> S<pin state>- Wait until the specified pin reaches the state required case 226: // M226 P<pin number> S<pin state>- Wait until the specified pin reaches the state required
{ {
if(code_seen('P')){ if(code_seen('P')){
...@@ -4345,7 +4358,7 @@ Sigma_Exit: ...@@ -4345,7 +4358,7 @@ Sigma_Exit:
} }
break; break;
#if NUM_SERVOS > 0 #if NUM_SERVOS > 0
case 280: // M280 - set servo position absolute. P: servo index, S: angle or microseconds case 280: // M280 - set servo position absolute. P: servo index, S: angle or microseconds
{ {
int servo_index = -1; int servo_index = -1;
...@@ -4381,11 +4394,13 @@ Sigma_Exit: ...@@ -4381,11 +4394,13 @@ Sigma_Exit:
} }
} }
break; break;
#endif // NUM_SERVOS > 0 #endif // NUM_SERVOS > 0
#if (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))) #if (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)))
case 299: // M299 turn on/off beep sound temp case 299: // M299 turn on/off beep sound temp
{
beeptemponoff = !beeptemponoff; beeptemponoff = !beeptemponoff;
}
break; break;
case 300: // M300 case 300: // M300
{ {
...@@ -4393,15 +4408,15 @@ Sigma_Exit: ...@@ -4393,15 +4408,15 @@ Sigma_Exit:
int beepP = code_seen('P') ? code_value() : 1000; int beepP = code_seen('P') ? code_value() : 1000;
if (beepS > 0) if (beepS > 0)
{ {
#if BEEPER > 0 #if BEEPER > 0
tone(BEEPER, beepS); tone(BEEPER, beepS);
delay(beepP); delay(beepP);
noTone(BEEPER); noTone(BEEPER);
#elif defined(ULTRALCD) #elif defined(ULTRALCD)
lcd_buzz(beepS, beepP); lcd_buzz(beepS, beepP);
#elif defined(LCD_USE_I2C_BUZZER) #elif defined(LCD_USE_I2C_BUZZER)
lcd_buzz(beepP, beepS); lcd_buzz(beepP, beepS);
#endif #endif
} }
else else
{ {
...@@ -4409,18 +4424,18 @@ Sigma_Exit: ...@@ -4409,18 +4424,18 @@ Sigma_Exit:
} }
} }
break; break;
#endif // M299 - M300 #endif // M299 - M300
#ifdef PIDTEMP #ifdef PIDTEMP
case 301: // M301 case 301: // M301
{ {
if(code_seen('P')) Kp[active_extruder] = code_value(); if(code_seen('P')) Kp[active_extruder] = code_value();
if(code_seen('I')) Ki[active_extruder] = scalePID_i(code_value()); if(code_seen('I')) Ki[active_extruder] = scalePID_i(code_value());
if(code_seen('D')) Kd[active_extruder] = scalePID_d(code_value()); if(code_seen('D')) Kd[active_extruder] = scalePID_d(code_value());
#ifdef PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE
if(code_seen('C')) Kc = code_value(); if(code_seen('C')) Kc = code_value();
#endif #endif
updatePID(); updatePID();
SERIAL_PROTOCOL(MSG_OK); SERIAL_PROTOCOL(MSG_OK);
...@@ -4430,16 +4445,17 @@ Sigma_Exit: ...@@ -4430,16 +4445,17 @@ Sigma_Exit:
SERIAL_PROTOCOL(unscalePID_i(Ki[active_extruder])); SERIAL_PROTOCOL(unscalePID_i(Ki[active_extruder]));
SERIAL_PROTOCOL(" d:"); SERIAL_PROTOCOL(" d:");
SERIAL_PROTOCOL(unscalePID_d(Kd[active_extruder])); SERIAL_PROTOCOL(unscalePID_d(Kd[active_extruder]));
#ifdef PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE
SERIAL_PROTOCOL(" c:"); SERIAL_PROTOCOL(" c:");
//Kc does not have scaling applied above, or in resetting defaults //Kc does not have scaling applied above, or in resetting defaults
SERIAL_PROTOCOL(Kc); SERIAL_PROTOCOL(Kc);
#endif #endif
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
} }
break; break;
#endif //PIDTEMP #endif //PIDTEMP
#ifdef PIDTEMPBED
#ifdef PIDTEMPBED
case 304: // M304 case 304: // M304
{ {
if(code_seen('P')) bedKp = code_value(); if(code_seen('P')) bedKp = code_value();
...@@ -4457,19 +4473,19 @@ Sigma_Exit: ...@@ -4457,19 +4473,19 @@ Sigma_Exit:
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
} }
break; break;
#endif //PIDTEMP #endif //PIDTEMP
case 240: // M240 Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/ case 240: // M240 Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/
{ {
#ifdef CHDK #ifdef CHDK
SET_OUTPUT(CHDK); SET_OUTPUT(CHDK);
WRITE(CHDK, HIGH); WRITE(CHDK, HIGH);
chdkHigh = millis(); chdkHigh = millis();
chdkActive = true; chdkActive = true;
#else #else
#if defined(PHOTOGRAPH_PIN) && PHOTOGRAPH_PIN > -1 #if defined(PHOTOGRAPH_PIN) && PHOTOGRAPH_PIN > -1
const uint8_t NUM_PULSES=16; const uint8_t NUM_PULSES=16;
const float PULSE_LENGTH=0.01524; const float PULSE_LENGTH=0.01524;
for(int i=0; i < NUM_PULSES; i++) { for(int i=0; i < NUM_PULSES; i++) {
...@@ -4485,8 +4501,8 @@ Sigma_Exit: ...@@ -4485,8 +4501,8 @@ Sigma_Exit:
WRITE(PHOTOGRAPH_PIN, LOW); WRITE(PHOTOGRAPH_PIN, LOW);
_delay_ms(PULSE_LENGTH); _delay_ms(PULSE_LENGTH);
} }
#endif #endif
#endif //chdk end if #endif //chdk end if
} }
break; break;
#ifdef DOGLCD #ifdef DOGLCD
...@@ -4501,7 +4517,8 @@ Sigma_Exit: ...@@ -4501,7 +4517,8 @@ Sigma_Exit:
} }
break; break;
#endif #endif
#ifdef PREVENT_DANGEROUS_EXTRUDE
#ifdef PREVENT_DANGEROUS_EXTRUDE
case 302: // allow cold extrudes, or set the minimum extrude temperature case 302: // allow cold extrudes, or set the minimum extrude temperature
{ {
float temp = .0; float temp = .0;
...@@ -4509,15 +4526,15 @@ Sigma_Exit: ...@@ -4509,15 +4526,15 @@ Sigma_Exit:
set_extrude_min_temp(temp); set_extrude_min_temp(temp);
} }
break; break;
#endif #endif
case 303: // M303 PID autotune case 303: // M303 PID autotune
{ {
float temp = 150.0; float temp = 150.0;
int e=0; int e=0;
int c=5; int c=5;
if (code_seen('E')) e=code_value(); if (code_seen('E')) e=code_value();
if (e<0) if (e<0) temp=70;
temp=70;
if (code_seen('S')) temp=code_value(); if (code_seen('S')) temp=code_value();
if (code_seen('C')) c=code_value(); if (code_seen('C')) c=code_value();
PID_autotune(temp, e, c); PID_autotune(temp, e, c);
...@@ -4542,7 +4559,6 @@ Sigma_Exit: ...@@ -4542,7 +4559,6 @@ Sigma_Exit:
return; return;
} }
break; break;
case 361: // SCARA Theta pos2 case 361: // SCARA Theta pos2
SERIAL_ECHOLN(" Cal: Theta 90 "); SERIAL_ECHOLN(" Cal: Theta 90 ");
//SoftEndsEnabled = false; // Ignore soft endstops during calibration //SoftEndsEnabled = false; // Ignore soft endstops during calibration
...@@ -4629,13 +4645,13 @@ Sigma_Exit: ...@@ -4629,13 +4645,13 @@ Sigma_Exit:
st_synchronize(); st_synchronize();
} }
break; break;
#if defined(ENABLE_AUTO_BED_LEVELING) && defined(SERVO_ENDSTOPS) && not defined(Z_PROBE_SLED) #if defined(ENABLE_AUTO_BED_LEVELING) && defined(SERVO_ENDSTOPS) && not defined(Z_PROBE_SLED)
case 401: case 401:
{ {
engage_z_probe(); // Engage Z Servo endstop if available engage_z_probe(); // Engage Z Servo endstop if available
} }
break; break;
case 402: case 402:
{ {
retract_z_probe(); // Retract Z Servo endstop if enabled retract_z_probe(); // Retract Z Servo endstop if enabled
...@@ -4644,31 +4660,27 @@ Sigma_Exit: ...@@ -4644,31 +4660,27 @@ Sigma_Exit:
#endif // ENABLE_AUTO_BED_LEVELING #endif // ENABLE_AUTO_BED_LEVELING
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width
{ {
#if (FILWIDTH_PIN > -1) #if (FILWIDTH_PIN > -1)
if(code_seen('N')) filament_width_nominal=code_value(); if(code_seen('N')) filament_width_nominal=code_value();
else{ else{
SERIAL_PROTOCOLPGM("Filament dia (nominal mm):"); SERIAL_PROTOCOLPGM("Filament dia (nominal mm):");
SERIAL_PROTOCOLLN(filament_width_nominal); SERIAL_PROTOCOLLN(filament_width_nominal);
} }
#endif #endif
} }
break; break;
case 405: //M405 Turn on filament sensor for control case 405: //M405 Turn on filament sensor for control
{ {
if(code_seen('D')) meas_delay_cm=code_value(); if(code_seen('D')) meas_delay_cm=code_value();
if(meas_delay_cm> MAX_MEASUREMENT_DELAY) if(meas_delay_cm> MAX_MEASUREMENT_DELAY) meas_delay_cm = MAX_MEASUREMENT_DELAY;
meas_delay_cm = MAX_MEASUREMENT_DELAY;
if(delay_index2 == -1) //initialize the ring buffer if it has not been done since startup if(delay_index2 == -1) //initialize the ring buffer if it has not been done since startup
{ {
int temp_ratio = widthFil_to_size_ratio(); int temp_ratio = widthFil_to_size_ratio();
for (delay_index1=0; delay_index1<(MAX_MEASUREMENT_DELAY+1); ++delay_index1 ){ for (delay_index1=0; delay_index1<(MAX_MEASUREMENT_DELAY+1); ++delay_index1 ){
measurement_delay[delay_index1]=temp_ratio-100; //subtract 100 to scale within a signed byte measurement_delay[delay_index1]=temp_ratio-100; //subtract 100 to scale within a signed byte
} }
...@@ -4677,35 +4689,25 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4677,35 +4689,25 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
filament_sensor = true ; filament_sensor = true ;
//SERIAL_PROTOCOLPGM("Filament dia (measured mm):"); //SERIAL_PROTOCOLPGM("Filament dia (measured mm):");
//SERIAL_PROTOCOL(filament_width_meas); //SERIAL_PROTOCOL(filament_width_meas);
//SERIAL_PROTOCOLPGM("Extrusion ratio(%):"); //SERIAL_PROTOCOLPGM("Extrusion ratio(%):");
//SERIAL_PROTOCOL(extrudemultiply); //SERIAL_PROTOCOL(extrudemultiply);
} }
break; break;
case 406: //M406 Turn off filament sensor for control case 406: //M406 Turn off filament sensor for control
{ {
filament_sensor = false ; filament_sensor = false ;
} }
break; break;
case 407: //M407 Display measured filament diameter case 407: //M407 Display measured filament diameter
{ {
SERIAL_PROTOCOLPGM("Filament dia (measured mm):"); SERIAL_PROTOCOLPGM("Filament dia (measured mm):");
SERIAL_PROTOCOLLN(filament_width_meas); SERIAL_PROTOCOLLN(filament_width_meas);
} }
break; break;
#endif // FILAMENT_SENSOR #endif // FILAMENT_SENSOR
case 500: // M500 Store settings in EEPROM case 500: // M500 Store settings in EEPROM
{ {
Config_StoreSettings(); Config_StoreSettings();
...@@ -4726,15 +4728,15 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4726,15 +4728,15 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
Config_PrintSettings(); Config_PrintSettings();
} }
break; break;
#ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
case 540: case 540:
{ {
if(code_seen('S')) abort_on_endstop_hit = code_value() > 0; if(code_seen('S')) abort_on_endstop_hit = code_value() > 0;
} }
break; break;
#endif #endif
#ifdef CUSTOM_M_CODE_SET_Z_PROBE_OFFSET #ifdef CUSTOM_M_CODE_SET_Z_PROBE_OFFSET
case CUSTOM_M_CODE_SET_Z_PROBE_OFFSET: case CUSTOM_M_CODE_SET_Z_PROBE_OFFSET:
{ {
float value; float value;
...@@ -4768,9 +4770,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4768,9 +4770,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
break; break;
} }
#endif // CUSTOM_M_CODE_SET_Z_PROBE_OFFSET #endif // CUSTOM_M_CODE_SET_Z_PROBE_OFFSET
#ifdef FILAMENTCHANGEENABLE #ifdef FILAMENTCHANGEENABLE
case 600: //M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] case 600: //M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
{ {
float target[4]; float target[4];
...@@ -4789,9 +4791,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4789,9 +4791,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
else else
{ {
#ifdef FILAMENTCHANGE_FIRSTRETRACT #ifdef FILAMENTCHANGE_FIRSTRETRACT
target[E_AXIS]+= FILAMENTCHANGE_FIRSTRETRACT ; target[E_AXIS]+= FILAMENTCHANGE_FIRSTRETRACT ;
#endif #endif
} }
plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder, active_driver); plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder, active_driver);
...@@ -4802,9 +4804,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4802,9 +4804,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
else else
{ {
#ifdef FILAMENTCHANGE_ZADD #ifdef FILAMENTCHANGE_ZADD
target[Z_AXIS]+= FILAMENTCHANGE_ZADD ; target[Z_AXIS]+= FILAMENTCHANGE_ZADD ;
#endif #endif
} }
plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder, active_driver); plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder, active_driver);
...@@ -4815,9 +4817,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4815,9 +4817,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
else else
{ {
#ifdef FILAMENTCHANGE_XPOS #ifdef FILAMENTCHANGE_XPOS
target[X_AXIS]= FILAMENTCHANGE_XPOS ; target[X_AXIS]= FILAMENTCHANGE_XPOS ;
#endif #endif
} }
if(code_seen('Y')) if(code_seen('Y'))
{ {
...@@ -4825,9 +4827,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4825,9 +4827,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
else else
{ {
#ifdef FILAMENTCHANGE_YPOS #ifdef FILAMENTCHANGE_YPOS
target[Y_AXIS]= FILAMENTCHANGE_YPOS ; target[Y_AXIS]= FILAMENTCHANGE_YPOS ;
#endif #endif
} }
plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder, active_driver); plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder, active_driver);
...@@ -4838,9 +4840,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4838,9 +4840,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
else else
{ {
#ifdef FILAMENTCHANGE_FINALRETRACT #ifdef FILAMENTCHANGE_FINALRETRACT
target[E_AXIS]+= FILAMENTCHANGE_FINALRETRACT ; target[E_AXIS]+= FILAMENTCHANGE_FINALRETRACT ;
#endif #endif
} }
plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder, active_driver); plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder, active_driver);
...@@ -4862,20 +4864,20 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4862,20 +4864,20 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
lcd_update(); lcd_update();
if(cnt==0) if(cnt==0)
{ {
#if BEEPER > 0 #if BEEPER > 0
SET_OUTPUT(BEEPER); SET_OUTPUT(BEEPER);
WRITE(BEEPER,HIGH); WRITE(BEEPER,HIGH);
delay(3); delay(3);
WRITE(BEEPER,LOW); WRITE(BEEPER,LOW);
delay(3); delay(3);
#else #else
#if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS) #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
lcd_buzz(1000/6,100); lcd_buzz(1000/6,100);
#else #else
lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ); lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS,LCD_FEEDBACK_FREQUENCY_HZ);
#endif #endif
#endif #endif
} }
} }
...@@ -4886,9 +4888,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -4886,9 +4888,9 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
else else
{ {
#ifdef FILAMENTCHANGE_FINALRETRACT #ifdef FILAMENTCHANGE_FINALRETRACT
target[E_AXIS]+=(-1)*FILAMENTCHANGE_FINALRETRACT ; target[E_AXIS]+=(-1)*FILAMENTCHANGE_FINALRETRACT ;
#endif #endif
} }
current_position[E_AXIS]=target[E_AXIS]; //the long retract of L is compensated by manual filament feeding current_position[E_AXIS]=target[E_AXIS]; //the long retract of L is compensated by manual filament feeding
plan_set_e_position(current_position[E_AXIS]); plan_set_e_position(current_position[E_AXIS]);
...@@ -5023,6 +5025,7 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -5023,6 +5025,7 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
} }
break; break;
#endif // NPR2 #endif // NPR2
case 999: // M999: Restart after being stopped case 999: // M999: Restart after being stopped
Stopped = false; Stopped = false;
lcd_reset_alert_level(); lcd_reset_alert_level();
...@@ -5031,27 +5034,20 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -5031,27 +5034,20 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
break; break;
} }
} }
else if(code_seen('T')) {
else if(code_seen('T'))
{
tmp_extruder = code_value(); tmp_extruder = code_value();
long csteps; long csteps;
if(tmp_extruder >= EXTRUDERS) if(tmp_extruder >= EXTRUDERS) {
{
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHO("T"); SERIAL_ECHO("T");
SERIAL_ECHO(tmp_extruder); SERIAL_ECHO(tmp_extruder);
SERIAL_ECHOLN(MSG_INVALID_EXTRUDER); SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
} } else {
else
{
boolean make_move = false; boolean make_move = false;
if(code_seen('F')) if(code_seen('F')) {
{
make_move = true; make_move = true;
next_feedrate = code_value(); next_feedrate = code_value();
if(next_feedrate > 0.0) if(next_feedrate > 0.0) {
{
feedrate = next_feedrate; feedrate = next_feedrate;
} }
} }
...@@ -5134,11 +5130,27 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -5134,11 +5130,27 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
st_synchronize(); // Finish all movement st_synchronize(); // Finish all movement
disable_e0(); disable_e0();
disable_e1(); disable_e1();
switch(tmp_extruder){ switch(tmp_extruder) {
case 0: WRITE(E0E2_CHOICE_PIN,LOW); WRITE(E1E3_CHOICE_PIN,LOW); active_driver=0; break; case 0:
case 1: WRITE(E0E2_CHOICE_PIN,LOW); WRITE(E1E3_CHOICE_PIN,LOW); active_driver=1; break; WRITE(E0E2_CHOICE_PIN,LOW);
case 2: WRITE(E0E2_CHOICE_PIN,HIGH); WRITE(E1E3_CHOICE_PIN,LOW); active_driver=0; break; WRITE(E1E3_CHOICE_PIN,LOW);
case 3: WRITE(E0E2_CHOICE_PIN,LOW); WRITE(E1E3_CHOICE_PIN,HIGH); active_driver=1; break; active_driver=0;
break;
case 1:
WRITE(E0E2_CHOICE_PIN,LOW);
WRITE(E1E3_CHOICE_PIN,LOW);
active_driver=1;
break;
case 2:
WRITE(E0E2_CHOICE_PIN,HIGH);
WRITE(E1E3_CHOICE_PIN,LOW);
active_driver=0;
break;
case 3:
WRITE(E0E2_CHOICE_PIN,LOW);
WRITE(E1E3_CHOICE_PIN,HIGH);
active_driver=1;
break;
} }
delay(DELAY_R); // ritardo per commutazione rele delay(DELAY_R); // ritardo per commutazione rele
enable_e0(); enable_e0();
...@@ -5147,10 +5159,19 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -5147,10 +5159,19 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
#elif (EXTRUDERS == 3) && (E0E2_CHOICE_PIN >1) #elif (EXTRUDERS == 3) && (E0E2_CHOICE_PIN >1)
st_synchronize(); // Finish all movement st_synchronize(); // Finish all movement
disable_e0(); disable_e0();
switch(tmp_extruder){ switch(tmp_extruder) {
case 0: WRITE(E0E2_CHOICE_PIN,LOW); active_driver=0; break; case 0:
case 1: WRITE(E0E2_CHOICE_PIN,LOW); active_driver=1; break; WRITE(E0E2_CHOICE_PIN,LOW);
case 2: WRITE(E0E2_CHOICE_PIN,HIGH); active_driver=0; break; active_driver=0;
break;
case 1:
WRITE(E0E2_CHOICE_PIN,LOW);
active_driver=1;
break;
case 2:
WRITE(E0E2_CHOICE_PIN,HIGH);
active_driver=0;
break;
} }
delay(DELAY_R); // ritardo per commutazione rele delay(DELAY_R); // ritardo per commutazione rele
enable_e0(); enable_e0();
...@@ -5158,9 +5179,15 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -5158,9 +5179,15 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
#elif (EXTRUDERS == 2) && (E0E1_CHOICE_PIN >1) #elif (EXTRUDERS == 2) && (E0E1_CHOICE_PIN >1)
st_synchronize(); // Finish all movement st_synchronize(); // Finish all movement
disable_e0(); disable_e0();
switch(tmp_extruder){ switch(tmp_extruder) {
case 0: WRITE(E0E1_CHOICE_PIN,LOW); active_driver=0; break; case 0:
case 1: WRITE(E0E1_CHOICE_PIN,HIGH); active_driver=0; break; WRITE(E0E1_CHOICE_PIN,LOW);
active_driver=0;
break;
case 1:
WRITE(E0E1_CHOICE_PIN,HIGH);
active_driver=0;
break;
} }
delay(DELAY_R); // ritardo per commutazione rele delay(DELAY_R); // ritardo per commutazione rele
enable_e0(); enable_e0();
...@@ -5176,7 +5203,7 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp ...@@ -5176,7 +5203,7 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
#elif defined(NPR2) #elif defined(NPR2)
st_synchronize(); // Finish all movement st_synchronize(); // Finish all movement
if (old_color == 99){ if (old_color == 99) {
csteps = (color_position[tmp_extruder]) * color_step_moltiplicator; csteps = (color_position[tmp_extruder]) * color_step_moltiplicator;
} }
else{ else{
...@@ -5260,7 +5287,7 @@ void get_coordinates() ...@@ -5260,7 +5287,7 @@ void get_coordinates()
if(next_feedrate > 0.0) feedrate = next_feedrate; if(next_feedrate > 0.0) feedrate = next_feedrate;
} }
#ifdef LASERBEAM #ifdef LASERBEAM
if(code_seen('L')){ if(code_seen('L')) {
laser_ttl_modulation=constrain(code_value(),0,255); laser_ttl_modulation=constrain(code_value(),0,255);
} }
#endif // LASERBEAM #endif // LASERBEAM
...@@ -5387,24 +5414,27 @@ void prepare_move() ...@@ -5387,24 +5414,27 @@ void prepare_move()
clamp_to_software_endstops(destination); clamp_to_software_endstops(destination);
previous_millis_cmd = millis(); previous_millis_cmd = millis();
#ifdef SCARA //for now same as delta-code #ifdef SCARA //for now same as delta-code
float difference[NUM_AXIS];
float difference[NUM_AXIS]; for (int8_t i=0; i < NUM_AXIS; i++) {
for (int8_t i=0; i < NUM_AXIS; i++) {
difference[i] = destination[i] - current_position[i]; difference[i] = destination[i] - current_position[i];
} }
float cartesian_mm = sqrt( sq(difference[X_AXIS]) + float cartesian_mm = sqrt( sq(difference[X_AXIS]) +
sq(difference[Y_AXIS]) + sq(difference[Y_AXIS]) +
sq(difference[Z_AXIS])); sq(difference[Z_AXIS]));
if (cartesian_mm < 0.000001) { cartesian_mm = abs(difference[E_AXIS]); } if (cartesian_mm < 0.000001) {
if (cartesian_mm < 0.000001) { return; } cartesian_mm = abs(difference[E_AXIS]);
float seconds = 6000 * cartesian_mm / feedrate / feedmultiply; }
int steps = max(1, int(scara_segments_per_second * seconds)); if (cartesian_mm < 0.000001) {
return;
}
float seconds = 6000 * cartesian_mm / feedrate / feedmultiply;
int steps = max(1, int(scara_segments_per_second * seconds));
//SERIAL_ECHOPGM("mm="); SERIAL_ECHO(cartesian_mm); //SERIAL_ECHOPGM("mm="); SERIAL_ECHO(cartesian_mm);
//SERIAL_ECHOPGM(" seconds="); SERIAL_ECHO(seconds); //SERIAL_ECHOPGM(" seconds="); SERIAL_ECHO(seconds);
//SERIAL_ECHOPGM(" steps="); SERIAL_ECHOLN(steps); //SERIAL_ECHOPGM(" steps="); SERIAL_ECHOLN(steps);
for (int s = 1; s <= steps; s++) { for (int s = 1; s <= steps; s++) {
float fraction = float(s) / float(steps); float fraction = float(s) / float(steps);
for(int8_t i=0; i < NUM_AXIS; i++) { for(int8_t i=0; i < NUM_AXIS; i++) {
destination[i] = current_position[i] + difference[i] * fraction; destination[i] = current_position[i] + difference[i] * fraction;
...@@ -5422,7 +5452,7 @@ for (int s = 1; s <= steps; s++) { ...@@ -5422,7 +5452,7 @@ for (int s = 1; s <= steps; s++) {
plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS],
destination[E_AXIS], feedrate*feedmultiply/60/100.0, destination[E_AXIS], feedrate*feedmultiply/60/100.0,
active_extruder, active_driver); active_extruder, active_driver);
} }
#endif // SCARA #endif // SCARA
#ifdef DELTA #ifdef DELTA
...@@ -5433,8 +5463,12 @@ for (int s = 1; s <= steps; s++) { ...@@ -5433,8 +5463,12 @@ for (int s = 1; s <= steps; s++) {
float cartesian_mm = sqrt(sq(difference[X_AXIS]) + float cartesian_mm = sqrt(sq(difference[X_AXIS]) +
sq(difference[Y_AXIS]) + sq(difference[Y_AXIS]) +
sq(difference[Z_AXIS])); sq(difference[Z_AXIS]));
if (cartesian_mm < 0.000001) { cartesian_mm = abs(difference[E_AXIS]); } if (cartesian_mm < 0.000001) {
if (cartesian_mm < 0.000001) { return; } cartesian_mm = abs(difference[E_AXIS]);
}
if (cartesian_mm < 0.000001) {
return;
}
float seconds = 6000 * cartesian_mm / feedrate / feedmultiply; float seconds = 6000 * cartesian_mm / feedrate / feedmultiply;
int steps = max(1, int(DELTA_SEGMENTS_PER_SECOND * seconds)); int steps = max(1, int(DELTA_SEGMENTS_PER_SECOND * seconds));
// SERIAL_ECHOPGM("mm="); SERIAL_ECHO(cartesian_mm); // SERIAL_ECHOPGM("mm="); SERIAL_ECHO(cartesian_mm);
...@@ -5519,7 +5553,8 @@ for (int s = 1; s <= steps; s++) { ...@@ -5519,7 +5553,8 @@ for (int s = 1; s <= steps; s++) {
} }
} }
void prepare_arc_move(char isclockwise) { void prepare_arc_move(char isclockwise)
{
float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc
// Trace the arc // Trace the arc
...@@ -5535,13 +5570,11 @@ void prepare_arc_move(char isclockwise) { ...@@ -5535,13 +5570,11 @@ void prepare_arc_move(char isclockwise) {
} }
#if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1 #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
#if defined(FAN_PIN) #if defined(FAN_PIN)
#if CONTROLLERFAN_PIN == FAN_PIN #if CONTROLLERFAN_PIN == FAN_PIN
#error "You cannot set CONTROLLERFAN_PIN equal to FAN_PIN" #error "You cannot set CONTROLLERFAN_PIN equal to FAN_PIN"
#endif #endif // CONTROLLERFAN_PIN == FAN_PIN
#endif #endif // defined(FAN_PIN)
unsigned long lastMotor = 0; //Save the time for when a motor was turned on last unsigned long lastMotor = 0; //Save the time for when a motor was turned on last
unsigned long lastMotorCheck = 0; unsigned long lastMotorCheck = 0;
...@@ -5552,15 +5585,15 @@ void controllerFan() ...@@ -5552,15 +5585,15 @@ void controllerFan()
lastMotorCheck = millis(); lastMotorCheck = millis();
if(!READ(X_ENABLE_PIN) || !READ(Y_ENABLE_PIN) || !READ(Z_ENABLE_PIN) || (soft_pwm_bed > 0) if(!READ(X_ENABLE_PIN) || !READ(Y_ENABLE_PIN) || !READ(Z_ENABLE_PIN) || (soft_pwm_bed > 0)
#if DRIVER_EXTRUDERS > 2 #if DRIVER_EXTRUDERS > 2
|| !READ(E2_ENABLE_PIN) || !READ(E2_ENABLE_PIN)
#endif #endif
#if DRIVER_EXTRUDER > 1 #if DRIVER_EXTRUDER > 1
#if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1 #if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
|| !READ(X2_ENABLE_PIN) || !READ(X2_ENABLE_PIN)
#endif #endif
|| !READ(E1_ENABLE_PIN) || !READ(E1_ENABLE_PIN)
#endif #endif
|| !READ(E0_ENABLE_PIN)) //If any of the drivers are enabled... || !READ(E0_ENABLE_PIN)) //If any of the drivers are enabled...
{ {
lastMotor = millis(); //... set time to NOW so the fan will turn on lastMotor = millis(); //... set time to NOW so the fan will turn on
...@@ -5579,7 +5612,7 @@ void controllerFan() ...@@ -5579,7 +5612,7 @@ void controllerFan()
} }
} }
} }
#endif #endif // defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
#ifdef SCARA #ifdef SCARA
void calculate_SCARA_forward_Transform(float f_scara[3]) void calculate_SCARA_forward_Transform(float f_scara[3])
...@@ -5609,7 +5642,8 @@ void calculate_SCARA_forward_Transform(float f_scara[3]) ...@@ -5609,7 +5642,8 @@ void calculate_SCARA_forward_Transform(float f_scara[3])
//SERIAL_ECHOPGM(" delta[Y_AXIS]="); SERIAL_ECHOLN(delta[Y_AXIS]); //SERIAL_ECHOPGM(" delta[Y_AXIS]="); SERIAL_ECHOLN(delta[Y_AXIS]);
} }
void calculate_delta(float cartesian[3]){ void calculate_delta(float cartesian[3])
{
//reverse kinematics. //reverse kinematics.
// Perform reversed kinematics, and place results in delta[3] // Perform reversed kinematics, and place results in delta[3]
// The maths and first version has been done by QHARLEY . Integrated into masterbranch 06/2014 and slightly restructured by Joachim Cerny in June 2014 // The maths and first version has been done by QHARLEY . Integrated into masterbranch 06/2014 and slightly restructured by Joachim Cerny in June 2014
...@@ -5620,11 +5654,11 @@ void calculate_delta(float cartesian[3]){ ...@@ -5620,11 +5654,11 @@ void calculate_delta(float cartesian[3]){
SCARA_pos[X_AXIS] = cartesian[X_AXIS] * axis_scaling[X_AXIS] - SCARA_offset_x; //Translate SCARA to standard X Y SCARA_pos[X_AXIS] = cartesian[X_AXIS] * axis_scaling[X_AXIS] - SCARA_offset_x; //Translate SCARA to standard X Y
SCARA_pos[Y_AXIS] = cartesian[Y_AXIS] * axis_scaling[Y_AXIS] - SCARA_offset_y; // With scaling factor. SCARA_pos[Y_AXIS] = cartesian[Y_AXIS] * axis_scaling[Y_AXIS] - SCARA_offset_y; // With scaling factor.
#if (Linkage_1 == Linkage_2) #if (Linkage_1 == Linkage_2)
SCARA_C2 = ( ( sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS]) ) / (2 * (float)L1_2) ) - 1; SCARA_C2 = ( ( sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS]) ) / (2 * (float)L1_2) ) - 1;
#else #else
SCARA_C2 = ( sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS]) - (float)L1_2 - (float)L2_2 ) / 45000; SCARA_C2 = ( sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS]) - (float)L1_2 - (float)L2_2 ) / 45000;
#endif #endif
SCARA_S2 = sqrt( 1 - sq(SCARA_C2) ); SCARA_S2 = sqrt( 1 - sq(SCARA_C2) );
...@@ -5656,15 +5690,14 @@ void calculate_delta(float cartesian[3]){ ...@@ -5656,15 +5690,14 @@ void calculate_delta(float cartesian[3]){
SERIAL_ECHOPGM(" Psi="); SERIAL_ECHOLN(SCARA_psi); SERIAL_ECHOPGM(" Psi="); SERIAL_ECHOLN(SCARA_psi);
SERIAL_ECHOLN(" ");*/ SERIAL_ECHOLN(" ");*/
} }
#endif // SCARA
#endif
#ifdef TEMP_STAT_LEDS #ifdef TEMP_STAT_LEDS
static bool blue_led = false; static bool blue_led = false;
static bool red_led = false; static bool red_led = false;
static uint32_t stat_update = 0; static uint32_t stat_update = 0;
void handle_status_leds(void)
void handle_status_leds(void) { {
float max_temp = 0.0; float max_temp = 0.0;
if(millis() > stat_update) { if(millis() > stat_update) {
stat_update += 500; // Update every 0.5s stat_update += 500; // Update every 0.5s
...@@ -5672,10 +5705,10 @@ void handle_status_leds(void) { ...@@ -5672,10 +5705,10 @@ void handle_status_leds(void) {
max_temp = max(max_temp, degHotend(cur_extruder)); max_temp = max(max_temp, degHotend(cur_extruder));
max_temp = max(max_temp, degTargetHotend(cur_extruder)); max_temp = max(max_temp, degTargetHotend(cur_extruder));
} }
#if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
max_temp = max(max_temp, degTargetBed()); max_temp = max(max_temp, degTargetBed());
max_temp = max(max_temp, degBed()); max_temp = max(max_temp, degBed());
#endif #endif
if((max_temp > 55.0) && (red_led == false)) { if((max_temp > 55.0) && (red_led == false)) {
digitalWrite(STAT_LED_RED, 1); digitalWrite(STAT_LED_RED, 1);
digitalWrite(STAT_LED_BLUE, 0); digitalWrite(STAT_LED_BLUE, 0);
...@@ -5690,7 +5723,7 @@ void handle_status_leds(void) { ...@@ -5690,7 +5723,7 @@ void handle_status_leds(void) {
} }
} }
} }
#endif #endif // TEMP_STAT_LEDS
void manage_inactivity() void manage_inactivity()
{ {
...@@ -5715,32 +5748,30 @@ void manage_inactivity() ...@@ -5715,32 +5748,30 @@ void manage_inactivity()
} }
} }
#if (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))) #if (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)))
if (beeptemponoff) temptone(); if (beeptemponoff) temptone();
#endif #endif
#ifdef CHDK //Check if pin should be set to LOW after M240 set it to HIGH #ifdef CHDK //Check if pin should be set to LOW after M240 set it to HIGH
if (chdkActive && (millis() - chdkHigh > CHDK_DELAY)) if (chdkActive && (millis() - chdkHigh > CHDK_DELAY))
{ {
chdkActive = false; chdkActive = false;
WRITE(CHDK, LOW); WRITE(CHDK, LOW);
} }
#endif #endif
#if defined(KILL_PIN) && KILL_PIN > -1 #if defined(KILL_PIN) && KILL_PIN > -1
if( 0 == READ(KILL_PIN) ) if(0 == READ(KILL_PIN)) kill();
kill(); #endif
#endif
#if defined(PAUSE_PIN) && PAUSE_PIN > -1 #if defined(PAUSE_PIN) && PAUSE_PIN > -1
if( 0 == READ(PAUSE_PIN) ) if(0 == READ(PAUSE_PIN)) pause();
pause(); #endif
#endif
#if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1 #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
controllerFan(); //Check if fan should be turned on to cool stepper drivers down controllerFan(); //Check if fan should be turned on to cool stepper drivers down
#endif #endif
#ifdef EXTRUDER_RUNOUT_PREVENT #ifdef EXTRUDER_RUNOUT_PREVENT
if( (millis() - previous_millis_cmd) > EXTRUDER_RUNOUT_SECONDS*1000 ) if( (millis() - previous_millis_cmd) > EXTRUDER_RUNOUT_SECONDS*1000 )
if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP) if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP)
{ {
...@@ -5758,8 +5789,8 @@ void manage_inactivity() ...@@ -5758,8 +5789,8 @@ void manage_inactivity()
st_synchronize(); st_synchronize();
WRITE(E0_ENABLE_PIN,oldstatus); WRITE(E0_ENABLE_PIN,oldstatus);
} }
#endif #endif
#if defined(DUAL_X_CARRIAGE) #if defined(DUAL_X_CARRIAGE)
// handle delayed move timeout // handle delayed move timeout
if (delayed_move_time != 0 && (millis() - delayed_move_time) > 1000 && Stopped == false) if (delayed_move_time != 0 && (millis() - delayed_move_time) > 1000 && Stopped == false)
{ {
...@@ -5768,10 +5799,10 @@ void manage_inactivity() ...@@ -5768,10 +5799,10 @@ void manage_inactivity()
memcpy(destination,current_position,sizeof(destination)); memcpy(destination,current_position,sizeof(destination));
prepare_move(); prepare_move();
} }
#endif #endif
#ifdef TEMP_STAT_LEDS #ifdef TEMP_STAT_LEDS
handle_status_leds(); handle_status_leds();
#endif #endif
check_axes_activity(); check_axes_activity();
} }
...@@ -5802,48 +5833,45 @@ void kill() ...@@ -5802,48 +5833,45 @@ void kill()
#if (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))) #if (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)))
void temptone() void temptone()
{ {
if (!isHeatingHotend(active_extruder) && degTargetHotend(active_extruder)!=0 && beeptemphe) if (!isHeatingHotend(active_extruder) && degTargetHotend(active_extruder)!=0 && beeptemphe) {
{
int beepS = 200; int beepS = 200;
int beepP = 500; int beepP = 500;
int beepN = 3; int beepN = 3;
for (int i = 0; i < beepN; ++i) for (int i = 0; i < beepN; ++i)
{ {
#if BEEPER > 0 #if BEEPER > 0
tone(BEEPER, beepS); tone(BEEPER, beepS);
delay(beepP); delay(beepP);
noTone(BEEPER); noTone(BEEPER);
#elif defined(ULTRALCD) #elif defined(ULTRALCD)
lcd_buzz(beepS, beepP); lcd_buzz(beepS, beepP);
#elif defined(LCD_USE_I2C_BUZZER) #elif defined(LCD_USE_I2C_BUZZER)
lcd_buzz(beepP, beepS); lcd_buzz(beepP, beepS);
#endif #endif
delay(beepP); delay(beepP);
} }
beeptemphe=false; beeptemphe=false;
} }
else if (!isHeatingBed() && degTargetBed()!=0 && beeptemphb) else if (!isHeatingBed() && degTargetBed()!=0 && beeptemphb) {
{
int beepS = 100; int beepS = 100;
int beepP = 500; int beepP = 500;
int beepN = 2; int beepN = 2;
for (int i = 0; i < beepN; ++i) for (int i = 0; i < beepN; ++i) {
{ #if BEEPER > 0
#if BEEPER > 0
tone(BEEPER, beepS); tone(BEEPER, beepS);
delay(beepP); delay(beepP);
noTone(BEEPER); noTone(BEEPER);
#elif defined(ULTRALCD) #elif defined(ULTRALCD)
lcd_buzz(beepS, beepP); lcd_buzz(beepS, beepP);
#elif defined(LCD_USE_I2C_BUZZER) #elif defined(LCD_USE_I2C_BUZZER)
lcd_buzz(beepP, beepS); lcd_buzz(beepP, beepS);
#endif #endif
delay(beepP); delay(beepP);
} }
beeptemphb=false; beeptemphb=false;
} }
} }
#endif #endif // (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)))
#if defined(PAUSE_PIN) && PAUSE_PIN > -1 #if defined(PAUSE_PIN) && PAUSE_PIN > -1
void pause() void pause()
...@@ -5853,7 +5881,7 @@ void pause() ...@@ -5853,7 +5881,7 @@ void pause()
enquecommand("G4 P0"); enquecommand("G4 P0");
enquecommand("G4 P0"); enquecommand("G4 P0");
} }
#endif #endif // defined(PAUSE_PIN) && PAUSE_PIN > -1
void Stop() void Stop()
{ {
...@@ -5873,79 +5901,77 @@ bool IsStopped() { return Stopped; }; ...@@ -5873,79 +5901,77 @@ bool IsStopped() { return Stopped; };
void setPwmFrequency(uint8_t pin, int val) void setPwmFrequency(uint8_t pin, int val)
{ {
val &= 0x07; val &= 0x07;
switch(digitalPinToTimer(pin)) switch(digitalPinToTimer(pin)) {
{ #if defined(TCCR0A)
#if defined(TCCR0A)
case TIMER0A: case TIMER0A:
case TIMER0B: case TIMER0B:
// TCCR0B &= ~(_BV(CS00) | _BV(CS01) | _BV(CS02)); //TCCR0B &= ~(_BV(CS00) | _BV(CS01) | _BV(CS02));
// TCCR0B |= val; //TCCR0B |= val;
break; break;
#endif #endif
#if defined(TCCR1A) #if defined(TCCR1A)
case TIMER1A: case TIMER1A:
case TIMER1B: case TIMER1B:
// TCCR1B &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12)); //TCCR1B &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12));
// TCCR1B |= val; //TCCR1B |= val;
break; break;
#endif #endif
#if defined(TCCR2) #if defined(TCCR2)
case TIMER2: case TIMER2:
case TIMER2: case TIMER2:
TCCR2 &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12)); TCCR2 &= ~(_BV(CS10) | _BV(CS11) | _BV(CS12));
TCCR2 |= val; TCCR2 |= val;
break; break;
#endif #endif
#if defined(TCCR2A) #if defined(TCCR2A)
case TIMER2A: case TIMER2A:
case TIMER2B: case TIMER2B:
TCCR2B &= ~(_BV(CS20) | _BV(CS21) | _BV(CS22)); TCCR2B &= ~(_BV(CS20) | _BV(CS21) | _BV(CS22));
TCCR2B |= val; TCCR2B |= val;
break; break;
#endif #endif
#if defined(TCCR3A) #if defined(TCCR3A)
case TIMER3A: case TIMER3A:
case TIMER3B: case TIMER3B:
case TIMER3C: case TIMER3C:
TCCR3B &= ~(_BV(CS30) | _BV(CS31) | _BV(CS32)); TCCR3B &= ~(_BV(CS30) | _BV(CS31) | _BV(CS32));
TCCR3B |= val; TCCR3B |= val;
break; break;
#endif #endif
#if defined(TCCR4A) #if defined(TCCR4A)
case TIMER4A: case TIMER4A:
case TIMER4B: case TIMER4B:
case TIMER4C: case TIMER4C:
TCCR4B &= ~(_BV(CS40) | _BV(CS41) | _BV(CS42)); TCCR4B &= ~(_BV(CS40) | _BV(CS41) | _BV(CS42));
TCCR4B |= val; TCCR4B |= val;
break; break;
#endif #endif
#if defined(TCCR5A) #if defined(TCCR5A)
case TIMER5A: case TIMER5A:
case TIMER5B: case TIMER5B:
case TIMER5C: case TIMER5C:
TCCR5B &= ~(_BV(CS50) | _BV(CS51) | _BV(CS52)); TCCR5B &= ~(_BV(CS50) | _BV(CS51) | _BV(CS52));
TCCR5B |= val; TCCR5B |= val;
break; break;
#endif #endif
} }
} }
#endif //FAST_PWM_FAN #endif //FAST_PWM_FAN
bool setTargetedHotend(int code){ bool setTargetedHotend(int code) {
tmp_extruder = active_extruder; tmp_extruder = active_extruder;
if(code_seen('T')) { if(code_seen('T')) {
tmp_extruder = code_value(); tmp_extruder = code_value();
if(tmp_extruder >= EXTRUDERS) { if(tmp_extruder >= EXTRUDERS) {
SERIAL_ECHO_START; SERIAL_ECHO_START;
switch(code){ switch(code) {
case 104: case 104:
SERIAL_ECHO(MSG_M104_INVALID_EXTRUDER); SERIAL_ECHO(MSG_M104_INVALID_EXTRUDER);
break; break;
......
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