Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Firmware/Marlin_main.cpp')
-rw-r--r--Firmware/Marlin_main.cpp498
1 files changed, 403 insertions, 95 deletions
diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp
index 61d5caa96..41328c2e1 100644
--- a/Firmware/Marlin_main.cpp
+++ b/Firmware/Marlin_main.cpp
@@ -1155,7 +1155,9 @@ void setup()
if (lang_selected >= LANG_NUM){
lcd_mylang();
}
-
+
+ check_babystep(); //checking if Z babystep is in allowed range
+
if (calibration_status() == CALIBRATION_STATUS_ASSEMBLED ||
calibration_status() == CALIBRATION_STATUS_UNKNOWN) {
// Reset the babystepping values, so the printer will not move the Z axis up when the babystepping is enabled.
@@ -1553,7 +1555,7 @@ void get_command()
// Return True if a character was found
static inline bool code_seen(char code) { return (strchr_pointer = strchr(CMDBUFFER_CURRENT_STRING, code)) != NULL; }
static inline bool code_seen(const char *code) { return (strchr_pointer = strstr(CMDBUFFER_CURRENT_STRING, code)) != NULL; }
-static inline float code_value() { return strtod(strchr_pointer+1, NULL); }
+static inline float code_value() { return strtod(strchr_pointer+1, NULL);}
static inline long code_value_long() { return strtol(strchr_pointer+1, NULL, 10); }
static inline int16_t code_value_short() { return int16_t(strtol(strchr_pointer+1, NULL, 10)); };
static inline uint8_t code_value_uint8() { return uint8_t(strtol(strchr_pointer+1, NULL, 10)); };
@@ -1956,7 +1958,15 @@ void process_commands()
int8_t SilentMode;
#endif
if(code_seen("PRUSA")){
- if (code_seen("fv")) {
+ if (code_seen("fn")) {
+ if (farm_mode) {
+ MYSERIAL.println(farm_no);
+ }
+ else {
+ MYSERIAL.println("Not in farm mode.");
+ }
+
+ }else if (code_seen("fv")) {
// get file version
#ifdef SDSUPPORT
card.openFile(strchr_pointer + 3,true);
@@ -2756,8 +2766,37 @@ void process_commands()
* v Y-axis
*
*/
+
+#ifdef DIS
+ case 77:
+ {
+ //G77 X200 Y150 XP100 YP15 XO10 Y015
+
+ //for 9 point mesh bed leveling G77 X203 Y196 XP3 YP3 XO0 YO0
+
+
+ //G77 X232 Y218 XP116 YP109 XO-11 YO0
+
+ float dimension_x = 40;
+ float dimension_y = 40;
+ int points_x = 40;
+ int points_y = 40;
+ float offset_x = 74;
+ float offset_y = 33;
+
+ if (code_seen('X')) dimension_x = code_value();
+ if (code_seen('Y')) dimension_y = code_value();
+ if (code_seen('XP')) points_x = code_value();
+ if (code_seen('YP')) points_y = code_value();
+ if (code_seen('XO')) offset_x = code_value();
+ if (code_seen('YO')) offset_y = code_value();
+
+ bed_analysis(dimension_x,dimension_y,points_x,points_y,offset_x,offset_y);
+
+ } break;
-
+#endif
+
case 80:
case_G80:
{
@@ -3087,9 +3126,17 @@ void process_commands()
else if(code_seen('M'))
{
- switch( (int)code_value() )
+ int index;
+ for (index = 1; *(strchr_pointer + index) == ' ' || *(strchr_pointer + index) == '\t'; index++);
+
+ /*for (++strchr_pointer; *strchr_pointer == ' ' || *strchr_pointer == '\t'; ++strchr_pointer);*/
+ if (*(strchr_pointer+index) < '0' || *(strchr_pointer+index) > '9') {
+ SERIAL_ECHOLNPGM("Invalid M code");
+ } else
+ switch((int)code_value())
{
#ifdef ULTIPANEL
+
case 0: // M0 - Unconditional stop - Wait for user button press on LCD
case 1: // M1 - Conditional stop - Wait for user button press on LCD
{
@@ -5104,7 +5151,7 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
{
custom_message = true;
custom_message_type = 2;
- lcd_setstatuspgm(MSG_UNLOADING_FILAMENT); //need to be tranlated to spanish language
+ lcd_setstatuspgm(MSG_UNLOADING_FILAMENT);
current_position[E_AXIS] -= 80;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 7000 / 60, active_extruder);
@@ -5122,98 +5169,109 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
gcode_LastN = Stopped_gcode_LastN;
FlushSerialRequestResend();
break;
+ default: SERIAL_ECHOLNPGM("Invalid M code.");
}
+
} // end if(code_seen('M')) (end of M codes)
else if(code_seen('T'))
{
- tmp_extruder = code_value();
+ int index;
+ for (index = 1; *(strchr_pointer + index) == ' ' || *(strchr_pointer + index) == '\t'; index++);
+
+ if (*(strchr_pointer + index) < '0' || *(strchr_pointer + index) > '9') {
+ SERIAL_ECHOLNPGM("Invalid T code.");
+ }
+ else {
+ tmp_extruder = code_value();
#ifdef SNMM
-
- st_synchronize();
- delay(100);
-
- disable_e0();
- disable_e1();
- disable_e2();
-
- pinMode(E_MUX0_PIN,OUTPUT);
- pinMode(E_MUX1_PIN,OUTPUT);
- pinMode(E_MUX2_PIN,OUTPUT);
-
- delay(100);
- SERIAL_ECHO_START;
- SERIAL_ECHO("T:");
- SERIAL_ECHOLN((int)tmp_extruder);
- switch (tmp_extruder) {
- case 1:
- WRITE(E_MUX0_PIN, HIGH);
- WRITE(E_MUX1_PIN, LOW);
- WRITE(E_MUX2_PIN, LOW);
-
- break;
- case 2:
- WRITE(E_MUX0_PIN, LOW);
- WRITE(E_MUX1_PIN, HIGH);
- WRITE(E_MUX2_PIN, LOW);
-
- break;
- case 3:
- WRITE(E_MUX0_PIN, HIGH);
- WRITE(E_MUX1_PIN, HIGH);
- WRITE(E_MUX2_PIN, LOW);
-
- break;
- default:
- WRITE(E_MUX0_PIN, LOW);
- WRITE(E_MUX1_PIN, LOW);
- WRITE(E_MUX2_PIN, LOW);
-
- break;
- }
- delay(100);
-
+
+ st_synchronize();
+ delay(100);
+
+ disable_e0();
+ disable_e1();
+ disable_e2();
+
+ pinMode(E_MUX0_PIN, OUTPUT);
+ pinMode(E_MUX1_PIN, OUTPUT);
+ pinMode(E_MUX2_PIN, OUTPUT);
+
+ delay(100);
+ SERIAL_ECHO_START;
+ SERIAL_ECHO("T:");
+ SERIAL_ECHOLN((int)tmp_extruder);
+ switch (tmp_extruder) {
+ case 1:
+ WRITE(E_MUX0_PIN, HIGH);
+ WRITE(E_MUX1_PIN, LOW);
+ WRITE(E_MUX2_PIN, LOW);
+
+ break;
+ case 2:
+ WRITE(E_MUX0_PIN, LOW);
+ WRITE(E_MUX1_PIN, HIGH);
+ WRITE(E_MUX2_PIN, LOW);
+
+ break;
+ case 3:
+ WRITE(E_MUX0_PIN, HIGH);
+ WRITE(E_MUX1_PIN, HIGH);
+ WRITE(E_MUX2_PIN, LOW);
+
+ break;
+ default:
+ WRITE(E_MUX0_PIN, LOW);
+ WRITE(E_MUX1_PIN, LOW);
+ WRITE(E_MUX2_PIN, LOW);
+
+ break;
+ }
+ delay(100);
+
#else
- if(tmp_extruder >= EXTRUDERS) {
- SERIAL_ECHO_START;
- SERIAL_ECHO("T");
- SERIAL_ECHO(tmp_extruder);
- SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
- }
- else {
- boolean make_move = false;
- if(code_seen('F')) {
- make_move = true;
- next_feedrate = code_value();
- if(next_feedrate > 0.0) {
- feedrate = next_feedrate;
- }
- }
- #if EXTRUDERS > 1
- if(tmp_extruder != active_extruder) {
- // Save current position to return to after applying extruder offset
- memcpy(destination, current_position, sizeof(destination));
- // Offset extruder (only by XY)
- int i;
- for(i = 0; i < 2; i++) {
- current_position[i] = current_position[i] -
- extruder_offset[i][active_extruder] +
- extruder_offset[i][tmp_extruder];
- }
- // Set the new active extruder and position
- active_extruder = tmp_extruder;
- plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
- // Move to the old position if 'F' was in the parameters
- if(make_move && Stopped == false) {
- prepare_move();
- }
- }
- #endif
- SERIAL_ECHO_START;
- SERIAL_ECHO(MSG_ACTIVE_EXTRUDER);
- SERIAL_PROTOCOLLN((int)active_extruder);
- }
+ if (tmp_extruder >= EXTRUDERS) {
+ SERIAL_ECHO_START;
+ SERIAL_ECHOPGM("T");
+ SERIAL_PROTOCOLLN((int)tmp_extruder);
+ SERIAL_ECHOLNRPGM(MSG_INVALID_EXTRUDER);
+ }
+ else {
+ boolean make_move = false;
+ if (code_seen('F')) {
+ make_move = true;
+ next_feedrate = code_value();
+ if (next_feedrate > 0.0) {
+ feedrate = next_feedrate;
+ }
+ }
+#if EXTRUDERS > 1
+ if (tmp_extruder != active_extruder) {
+ // Save current position to return to after applying extruder offset
+ memcpy(destination, current_position, sizeof(destination));
+ // Offset extruder (only by XY)
+ int i;
+ for (i = 0; i < 2; i++) {
+ current_position[i] = current_position[i] -
+ extruder_offset[i][active_extruder] +
+ extruder_offset[i][tmp_extruder];
+ }
+ // Set the new active extruder and position
+ active_extruder = tmp_extruder;
+ plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
+ // Move to the old position if 'F' was in the parameters
+ if (make_move && Stopped == false) {
+ prepare_move();
+ }
+ }
#endif
+ SERIAL_ECHO_START;
+ SERIAL_ECHORPGM(MSG_ACTIVE_EXTRUDER);
+ SERIAL_PROTOCOLLN((int)active_extruder);
+ }
+
+#endif
+ }
} // end if(code_seen('T')) (end of T codes)
else
@@ -5673,7 +5731,7 @@ bool setTargetedHotend(int code){
SERIAL_ECHO_START;
switch(code){
case 104:
- SERIAL_ECHO(MSG_M104_INVALID_EXTRUDER);
+ SERIAL_ECHORPGM(MSG_M104_INVALID_EXTRUDER);
break;
case 105:
SERIAL_ECHO(MSG_M105_INVALID_EXTRUDER);
@@ -5688,14 +5746,14 @@ bool setTargetedHotend(int code){
SERIAL_ECHO(MSG_M221_INVALID_EXTRUDER);
break;
}
- SERIAL_ECHOLN(tmp_extruder);
+ SERIAL_PROTOCOLLN((int)tmp_extruder);
return true;
}
}
return false;
}
-void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time) //_total_filament_used unit: mm/100
+void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time) //_total_filament_used unit: mm/100; print time in s
{
if (eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 1) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 2) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 3) == 255)
{
@@ -5704,9 +5762,9 @@ void save_statistics(unsigned long _total_filament_used, unsigned long _total_pr
}
unsigned long _previous_filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED); //_previous_filament unit: cm
- unsigned long _previous_time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME);
+ unsigned long _previous_time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //_previous_time unit: min
- eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, _previous_time + (_total_print_time/60));
+ eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, _previous_time + (_total_print_time/60)); //EEPROM_TOTALTIME unit: min
eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, _previous_filament + (_total_filament_used / 1000));
total_filament_used = 0;
@@ -5756,3 +5814,253 @@ void delay_keep_alive(int ms)
}
}
}
+
+void check_babystep() {
+ int babystep_z;
+ EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystep_z);
+ if ((babystep_z < Z_BABYSTEP_MIN) || (babystep_z > Z_BABYSTEP_MAX)) {
+ babystep_z = 0; //if babystep value is out of min max range, set it to 0
+ SERIAL_ECHOLNPGM("Z live adjust out of range. Setting to 0");
+ EEPROM_save_B(EEPROM_BABYSTEP_Z, &babystep_z);
+ lcd_show_fullscreen_message_and_wait_P(PSTR("Z live adjust out of range. Setting to 0. Click to continue."));
+ lcd_update_enable(true);
+ }
+}
+#ifdef DIS
+void d_setup()
+{
+ pinMode(D_DATACLOCK, INPUT_PULLUP);
+ pinMode(D_DATA, INPUT_PULLUP);
+ pinMode(D_REQUIRE, OUTPUT);
+ digitalWrite(D_REQUIRE, HIGH);
+}
+
+
+float d_ReadData()
+{
+ int digit[13];
+ String mergeOutput;
+ float output;
+
+ digitalWrite(D_REQUIRE, HIGH);
+ for (int i = 0; i<13; i++)
+ {
+ for (int j = 0; j < 4; j++)
+ {
+ while (digitalRead(D_DATACLOCK) == LOW) {}
+ while (digitalRead(D_DATACLOCK) == HIGH) {}
+ bitWrite(digit[i], j, digitalRead(D_DATA));
+ }
+ }
+
+ digitalWrite(D_REQUIRE, LOW);
+ mergeOutput = "";
+ output = 0;
+ for (int r = 5; r <= 10; r++) //Merge digits
+ {
+ mergeOutput += digit[r];
+ }
+ output = mergeOutput.toFloat();
+
+ if (digit[4] == 8) //Handle sign
+ {
+ output *= -1;
+ }
+
+ for (int i = digit[11]; i > 0; i--) //Handle floating point
+ {
+ output /= 10;
+ }
+
+ return output;
+
+}
+
+void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_points_num, float shift_x, float shift_y) {
+ int t1 = 0;
+ int t_delay = 0;
+ int digit[13];
+ int m;
+ char str[3];
+ //String mergeOutput;
+ char mergeOutput[15];
+ float output;
+
+ int mesh_point = 0; //index number of calibration point
+ float bed_zero_ref_x = (-22.f + X_PROBE_OFFSET_FROM_EXTRUDER); //shift between zero point on bed and target and between probe and nozzle
+ float bed_zero_ref_y = (-0.6f + Y_PROBE_OFFSET_FROM_EXTRUDER);
+
+ float mesh_home_z_search = 4;
+ float row[x_points_num];
+ int ix = 0;
+ int iy = 0;
+
+ char* filename_wldsd = "wldsd.txt";
+ char data_wldsd[70];
+ char numb_wldsd[10];
+
+ d_setup();
+
+ if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])) {
+ // We don't know where we are! HOME!
+ // Push the commands to the front of the message queue in the reverse order!
+ // There shall be always enough space reserved for these commands.
+ repeatcommand_front(); // repeat G80 with all its parameters
+
+ enquecommand_front_P((PSTR("G28 W0")));
+ enquecommand_front_P((PSTR("G1 Z5")));
+ return;
+ }
+ bool custom_message_old = custom_message;
+ unsigned int custom_message_type_old = custom_message_type;
+ unsigned int custom_message_state_old = custom_message_state;
+ custom_message = true;
+ custom_message_type = 1;
+ custom_message_state = (x_points_num * y_points_num) + 10;
+ lcd_update(1);
+
+ mbl.reset();
+ babystep_undo();
+
+ card.openFile(filename_wldsd, false);
+
+ current_position[Z_AXIS] = mesh_home_z_search;
+ plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 60, active_extruder);
+
+ int XY_AXIS_FEEDRATE = homing_feedrate[X_AXIS] / 20;
+ int Z_PROBE_FEEDRATE = homing_feedrate[Z_AXIS] / 60;
+ int Z_LIFT_FEEDRATE = homing_feedrate[Z_AXIS] / 40;
+
+ setup_for_endstop_move(false);
+
+ SERIAL_PROTOCOLPGM("Num X,Y: ");
+ SERIAL_PROTOCOL(x_points_num);
+ SERIAL_PROTOCOLPGM(",");
+ SERIAL_PROTOCOL(y_points_num);
+ SERIAL_PROTOCOLPGM("\nZ search height: ");
+ SERIAL_PROTOCOL(mesh_home_z_search);
+ SERIAL_PROTOCOLPGM("\nDimension X,Y: ");
+ SERIAL_PROTOCOL(x_dimension);
+ SERIAL_PROTOCOLPGM(",");
+ SERIAL_PROTOCOL(y_dimension);
+ SERIAL_PROTOCOLLNPGM("\nMeasured points:");
+
+ while (mesh_point != x_points_num * y_points_num) {
+ ix = mesh_point % x_points_num; // from 0 to MESH_NUM_X_POINTS - 1
+ iy = mesh_point / x_points_num;
+ if (iy & 1) ix = (x_points_num - 1) - ix; // Zig zag
+ float z0 = 0.f;
+ current_position[Z_AXIS] = mesh_home_z_search;
+ plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], Z_LIFT_FEEDRATE, active_extruder);
+ st_synchronize();
+
+
+ current_position[X_AXIS] = 13.f + ix * (x_dimension / (x_points_num - 1)) - bed_zero_ref_x + shift_x;
+ current_position[Y_AXIS] = 6.4f + iy * (y_dimension / (y_points_num - 1)) - bed_zero_ref_y + shift_y;
+
+ plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], XY_AXIS_FEEDRATE, active_extruder);
+ st_synchronize();
+
+ if (!find_bed_induction_sensor_point_z(-10.f)) { //if we have data from z calibration max allowed difference is 1mm for each point, if we dont have data max difference is 10mm from initial point
+ break;
+ card.closefile();
+ }
+
+
+ //memset(numb_wldsd, 0, sizeof(numb_wldsd));
+ //dtostrf(d_ReadData(), 8, 5, numb_wldsd);
+ //strcat(data_wldsd, numb_wldsd);
+
+
+
+ //MYSERIAL.println(data_wldsd);
+ //delay(1000);
+ //delay(3000);
+ //t1 = millis();
+
+ //while (digitalRead(D_DATACLOCK) == LOW) {}
+ //while (digitalRead(D_DATACLOCK) == HIGH) {}
+ memset(digit, 0, sizeof(digit));
+ //cli();
+ digitalWrite(D_REQUIRE, LOW);
+
+ for (int i = 0; i<13; i++)
+ {
+ //t1 = millis();
+ for (int j = 0; j < 4; j++)
+ {
+ while (digitalRead(D_DATACLOCK) == LOW) {}
+ while (digitalRead(D_DATACLOCK) == HIGH) {}
+ bitWrite(digit[i], j, digitalRead(D_DATA));
+ }
+ //t_delay = (millis() - t1);
+ //SERIAL_PROTOCOLPGM(" ");
+ //SERIAL_PROTOCOL_F(t_delay, 5);
+ //SERIAL_PROTOCOLPGM(" ");
+ }
+ //sei();
+ digitalWrite(D_REQUIRE, HIGH);
+ mergeOutput[0] = '\0';
+ output = 0;
+ for (int r = 5; r <= 10; r++) //Merge digits
+ {
+ sprintf(str, "%d", digit[r]);
+ strcat(mergeOutput, str);
+ }
+
+ output = atof(mergeOutput);
+
+ if (digit[4] == 8) //Handle sign
+ {
+ output *= -1;
+ }
+
+ for (int i = digit[11]; i > 0; i--) //Handle floating point
+ {
+ output *= 0.1;
+ }
+
+
+ //output = d_ReadData();
+
+ //row[ix] = current_position[Z_AXIS];
+
+ memset(data_wldsd, 0, sizeof(data_wldsd));
+
+ for (int i = 0; i <3; i++) {
+ memset(numb_wldsd, 0, sizeof(numb_wldsd));
+ dtostrf(current_position[i], 8, 5, numb_wldsd);
+ strcat(data_wldsd, numb_wldsd);
+ strcat(data_wldsd, ";");
+
+ }
+ memset(numb_wldsd, 0, sizeof(numb_wldsd));
+ dtostrf(output, 8, 5, numb_wldsd);
+ strcat(data_wldsd, numb_wldsd);
+ //strcat(data_wldsd, ";");
+ card.write_command(data_wldsd);
+
+
+ //row[ix] = d_ReadData();
+
+ row[ix] = output; // current_position[Z_AXIS];
+
+ if (iy % 2 == 1 ? ix == 0 : ix == x_points_num - 1) {
+ for (int i = 0; i < x_points_num; i++) {
+ SERIAL_PROTOCOLPGM(" ");
+ SERIAL_PROTOCOL_F(row[i], 5);
+
+
+ }
+ SERIAL_PROTOCOLPGM("\n");
+ }
+ custom_message_state--;
+ mesh_point++;
+ lcd_update(1);
+
+ }
+ card.closefile();
+
+}
+
+#endif \ No newline at end of file