/** * Get a long pretty path based on a DOS 8.3 path */ void CardReader::printLongPath(char *path) { lsAction = LS_GetFilename; int i, pathLen = strlen(path); // ECHO_M("Full Path: "); ECHO_EV(path); // Zero out slashes to make segments for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0'; SdFile diveDir = root; // start from the root for segment 1 for (i = 0; i < pathLen;) { if (path[i] == '\0') i++; // move past a single nul char *segment = &path[i]; // The segment after most slashes // If a segment is empty (extra-slash) then exit if (!*segment) break; // Go to the next segment while (path[++i]) { } // ECHO_M("Looking for segment: "); ECHO_EV(segment); // Find the item, setting the long filename diveDir.rewind(); lsDive("", diveDir, segment); // Print /LongNamePart to serial output ECHO_C('/'); ECHO_V(longFilename[0] ? longFilename : "???"); // If the filename was printed then that's it if (!filenameIsDir) break; // ECHO_M("Opening dir: "); ECHO_EV(segment); // Open the sub-item as the new dive parent SdFile dir; if (!dir.open(diveDir, segment, O_READ)) { ECHO_E; ECHO_SMV(DB, MSG_SD_CANT_OPEN_SUBDIR, segment); break; } diveDir.close(); diveDir = dir; } // while i<pathLen ECHO_E; }
void CardReader::removeFile(char* name) { if (!cardOK) return; file.close(); sdprinting = false; SdFile myDir; curDir = &root; char* fname = name; char* dirname_start, *dirname_end; if (name[0] == '/') { dirname_start = strchr(name, '/') + 1; while (dirname_start > 0) { dirname_end = strchr(dirname_start, '/'); if (dirname_end > 0 && dirname_end > dirname_start) { char subdirname[FILENAME_LENGTH]; strncpy(subdirname, dirname_start, dirname_end - dirname_start); subdirname[dirname_end - dirname_start] = 0; ECHO_EV(subdirname); if (!myDir.open(curDir, subdirname, O_READ)) { ECHO_SMV(DB, SERIAL_SD_OPEN_FILE_FAIL, subdirname); ECHO_EM("."); return; } curDir = &myDir; dirname_start = dirname_end + 1; } else { // the remainder after all /fsa/fdsa/ is the filename fname = dirname_start; break; } } } else // relative path curDir = &workDir; if (file.remove(curDir, fname)) { ECHO_EMV(SERIAL_SD_FILE_DELETED, fname); sdpos = 0; } else { ECHO_MV(SERIAL_SD_FILE_DELETION_ERR, fname); ECHO_C('.'); } }
void CardReader::openFile(char* name, bool read, bool replace_current/*=true*/, bool lcd_status/*=true*/) { if (!cardOK) return; if (file.isOpen()) { //replacing current file by new file, or subfile call if (!replace_current) { if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) { ECHO_LMV(ER, MSG_SD_MAX_DEPTH, SD_PROCEDURE_DEPTH); kill(PSTR(MSG_KILLED)); return; } ECHO_SMV(DB, "SUBROUTINE CALL target:\"", name); ECHO_M("\" parent:\""); //store current filename and position getAbsFilename(filenames[file_subcall_ctr]); ECHO_V(filenames[file_subcall_ctr]); ECHO_EMV("\" pos", sdpos); filespos[file_subcall_ctr] = sdpos; file_subcall_ctr++; } else { ECHO_LMV(DB, "Now doing file: ", name); } file.close(); } else { // opening fresh file file_subcall_ctr = 0; // resetting procedure depth in case user cancels print while in procedure ECHO_LMV(DB, "Now fresh file: ", name); } sdprinting = false; SdFile myDir; curDir = &root; char *fname = name; char *dirname_start, *dirname_end; if (name[0] == '/') { dirname_start = &name[1]; while (dirname_start > 0) { dirname_end = strchr(dirname_start, '/'); if (dirname_end > 0 && dirname_end > dirname_start) { char subdirname[FILENAME_LENGTH]; strncpy(subdirname, dirname_start, dirname_end - dirname_start); subdirname[dirname_end - dirname_start] = 0; ECHO_EV(subdirname); if (!myDir.open(curDir, subdirname, O_READ)) { ECHO_MV(MSG_SD_OPEN_FILE_FAIL, subdirname); ECHO_C('.'); return; } else { //ECHO_EM("dive ok"); } curDir = &myDir; dirname_start = dirname_end + 1; } else { // the remainder after all /fsa/fdsa/ is the filename fname = dirname_start; //ECHO_EM("remainder"); //ECHO_EV(fname); break; } } } else { //relative path curDir = &workDir; } if (read) { if (file.open(curDir, fname, O_READ)) { filesize = file.fileSize(); ECHO_MV(MSG_SD_FILE_OPENED, fname); ECHO_EMV(MSG_SD_SIZE, filesize); sdpos = 0; ECHO_EM(MSG_SD_FILE_SELECTED); getfilename(0, fname); if(lcd_status) lcd_setstatus(longFilename[0] ? longFilename : fname); } else { ECHO_MV(MSG_SD_OPEN_FILE_FAIL, fname); ECHO_PGM(".\n"); } } else { //write if (!file.open(curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) { ECHO_MV(MSG_SD_OPEN_FILE_FAIL, fname); ECHO_PGM(".\n"); } else { saving = true; ECHO_EMV(MSG_SD_WRITE_TO_FILE, name); if(lcd_status) lcd_setstatus(fname); } } }
/** * M503 - Print Configuration */ void Config_PrintSettings(bool forReplay) { // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown CONFIG_ECHO_START("Steps per unit:"); ECHO_SMV(CFG, " M92 X", planner.axis_steps_per_mm[X_AXIS]); ECHO_MV(" Y", planner.axis_steps_per_mm[Y_AXIS]); ECHO_MV(" Z", planner.axis_steps_per_mm[Z_AXIS]); ECHO_EMV(" E", planner.axis_steps_per_mm[E_AXIS]); #if EXTRUDERS > 1 for (short i = 1; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M92 T", i); ECHO_EMV(" E", planner.axis_steps_per_mm[E_AXIS + i]); } #endif //EXTRUDERS > 1 #if MECH(SCARA) CONFIG_ECHO_START("Scaling factors:"); ECHO_SMV(CFG, " M365 X", axis_scaling[X_AXIS]); ECHO_MV(" Y", axis_scaling[Y_AXIS]); ECHO_EMV(" Z", axis_scaling[Z_AXIS]); #endif // SCARA CONFIG_ECHO_START("Maximum feedrates (mm/s):"); ECHO_SMV(CFG, " M203 X", planner.max_feedrate[X_AXIS]); ECHO_MV(" Y", planner.max_feedrate[Y_AXIS] ); ECHO_MV(" Z", planner.max_feedrate[Z_AXIS] ); ECHO_EMV(" E", planner.max_feedrate[E_AXIS]); #if EXTRUDERS > 1 for (short i = 1; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M203 T", i); ECHO_EMV(" E", planner.max_acceleration_mm_per_s2[E_AXIS + i]); } #endif //EXTRUDERS > 1 CONFIG_ECHO_START("Maximum Acceleration (mm/s2):"); ECHO_SMV(CFG, " M201 X", planner.max_acceleration_mm_per_s2[X_AXIS] ); ECHO_MV(" Y", planner.max_acceleration_mm_per_s2[Y_AXIS] ); ECHO_MV(" Z", planner.max_acceleration_mm_per_s2[Z_AXIS] ); ECHO_EMV(" E", planner.max_acceleration_mm_per_s2[E_AXIS]); #if EXTRUDERS > 1 for (int8_t i = 1; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M201 T", i); ECHO_EMV(" E", planner.max_acceleration_mm_per_s2[E_AXIS + i]); } #endif //EXTRUDERS > 1 CONFIG_ECHO_START("Accelerations: P=printing, V=travel and T* R=retract"); ECHO_SMV(CFG," M204 P", planner.acceleration); ECHO_EMV(" V", planner.travel_acceleration); #if EXTRUDERS > 0 for (int8_t i = 0; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M204 T", i); ECHO_EMV(" R", planner.retract_acceleration[i]); } #endif CONFIG_ECHO_START("Advanced variables: S=Min feedrate (mm/s), V=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s)"); ECHO_SMV(CFG, " M205 S", planner.min_feedrate ); ECHO_MV(" V", planner.min_travel_feedrate ); ECHO_MV(" B", planner.min_segment_time ); ECHO_MV(" X", planner.max_xy_jerk ); ECHO_MV(" Z", planner.max_z_jerk); ECHO_EMV(" E", planner.max_e_jerk[0]); #if (EXTRUDERS > 1) for(int8_t i = 1; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M205 T", i); ECHO_EMV(" E" , planner.max_e_jerk[i]); } #endif CONFIG_ECHO_START("Home offset (mm):"); ECHO_SMV(CFG, " M206 X", home_offset[X_AXIS] ); ECHO_MV(" Y", home_offset[Y_AXIS] ); ECHO_EMV(" Z", home_offset[Z_AXIS] ); CONFIG_ECHO_START("Hotend offset (mm):"); for (int8_t h = 0; h < HOTENDS; h++) { ECHO_SMV(CFG, " M218 T", h); ECHO_MV(" X", hotend_offset[X_AXIS][h]); ECHO_MV(" Y", hotend_offset[Y_AXIS][h]); ECHO_EMV(" Z", hotend_offset[Z_AXIS][h]); } #if HAS(LCD_CONTRAST) CONFIG_ECHO_START("LCD Contrast:"); ECHO_LMV(CFG, " M250 C", lcd_contrast); #endif #if ENABLED(MESH_BED_LEVELING) CONFIG_ECHO_START("Mesh bed leveling:"); ECHO_SMV(CFG, " M420 S", mbl.has_mesh() ? 1 : 0); ECHO_MV(" X", MESH_NUM_X_POINTS); ECHO_MV(" Y", MESH_NUM_Y_POINTS); ECHO_E; for (uint8_t py = 1; py <= MESH_NUM_Y_POINTS; py++) { for (uint8_t px = 1; px <= MESH_NUM_X_POINTS; px++) { ECHO_SMV(CFG, " G29 S3 X", px); ECHO_MV(" Y", py); ECHO_EMV(" Z", mbl.z_values[py-1][px-1], 5); } } #endif #if HEATER_USES_AD595 CONFIG_ECHO_START("AD595 Offset and Gain:"); for (int8_t h = 0; h < HOTENDS; h++) { ECHO_SMV(CFG, " M595 T", h); ECHO_MV(" O", ad595_offset[h]); ECHO_EMV(", S", ad595_gain[h]); } #endif // HEATER_USES_AD595 #if MECH(DELTA) CONFIG_ECHO_START("Delta Geometry adjustment:"); ECHO_SMV(CFG, " M666 A", tower_adj[0], 3); ECHO_MV(" B", tower_adj[1], 3); ECHO_MV(" C", tower_adj[2], 3); ECHO_MV(" I", tower_adj[3], 3); ECHO_MV(" J", tower_adj[4], 3); ECHO_MV(" K", tower_adj[5], 3); ECHO_MV(" U", diagrod_adj[0], 3); ECHO_MV(" V", diagrod_adj[1], 3); ECHO_MV(" W", diagrod_adj[2], 3); ECHO_MV(" R", delta_radius); ECHO_MV(" D", delta_diagonal_rod); ECHO_EMV(" H", sw_endstop_max[2]); CONFIG_ECHO_START("Endstop Offsets:"); ECHO_SMV(CFG, " M666 X", endstop_adj[X_AXIS]); ECHO_MV(" Y", endstop_adj[Y_AXIS]); ECHO_EMV(" Z", endstop_adj[Z_AXIS]); #elif ENABLED(Z_DUAL_ENDSTOPS) CONFIG_ECHO_START("Z2 Endstop adjustement (mm):"); ECHO_LMV(CFG, " M666 Z", z_endstop_adj ); #endif // DELTA /** * Auto Bed Leveling */ #if HAS(BED_PROBE) CONFIG_ECHO_START("Z Probe offset (mm):"); ECHO_LMV(CFG, " M666 P", zprobe_zoffset); #endif #if ENABLED(ULTIPANEL) CONFIG_ECHO_START("Material heatup parameters:"); ECHO_SMV(CFG, " M145 S0 H", plaPreheatHotendTemp); ECHO_MV(" B", plaPreheatHPBTemp); ECHO_MV(" F", plaPreheatFanSpeed); ECHO_EM(" (Material PLA)"); ECHO_SMV(CFG, " M145 S1 H", absPreheatHotendTemp); ECHO_MV(" B", absPreheatHPBTemp); ECHO_MV(" F", absPreheatFanSpeed); ECHO_EM(" (Material ABS)"); ECHO_SMV(CFG, " M145 S2 H", gumPreheatHotendTemp); ECHO_MV(" B", gumPreheatHPBTemp); ECHO_MV(" F", gumPreheatFanSpeed); ECHO_EM(" (Material GUM)"); #endif // ULTIPANEL #if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED) || ENABLED(PIDTEMPCHAMBER) || ENABLED(PIDTEMPCOOLER) CONFIG_ECHO_START("PID settings:"); #if ENABLED(PIDTEMP) for (int8_t h = 0; h < HOTENDS; h++) { ECHO_SMV(CFG, " M301 H", h); ECHO_MV(" P", PID_PARAM(Kp, h)); ECHO_MV(" I", unscalePID_i(PID_PARAM(Ki, h))); ECHO_MV(" D", unscalePID_d(PID_PARAM(Kd, h))); #if ENABLED(PID_ADD_EXTRUSION_RATE) ECHO_MV(" C", PID_PARAM(Kc, h)); #endif ECHO_E; } #if ENABLED(PID_ADD_EXTRUSION_RATE) ECHO_SMV(CFG, " M301 L", lpq_len); #endif #endif #if ENABLED(PIDTEMPBED) ECHO_SMV(CFG, " M304 P", bedKp); ECHO_MV(" I", unscalePID_i(bedKi)); ECHO_EMV(" D", unscalePID_d(bedKd)); #endif #if ENABLED(PIDTEMPCHAMBER) ECHO_SMV(CFG, " M305 P", chamberKp); ECHO_MV(" I", unscalePID_i(chamberKi)); ECHO_EMV(" D", unscalePID_d(chamberKd)); #endif #if ENABLED(PIDTEMPCOOLER) ECHO_SMV(CFG, " M306 P", coolerKp); ECHO_MV(" I", unscalePID_i(coolerKi)); ECHO_EMV(" D", unscalePID_d(coolerKd)); #endif #endif #if ENABLED(FWRETRACT) CONFIG_ECHO_START("Retract: S=Length (mm) F:Speed (mm/m) Z: ZLift (mm)"); ECHO_SMV(CFG, " M207 S", retract_length); #if EXTRUDERS > 1 ECHO_MV(" W", retract_length_swap); #endif ECHO_MV(" F", retract_feedrate * 60); ECHO_EMV(" Z", retract_zlift); CONFIG_ECHO_START("Recover: S=Extra length (mm) F:Speed (mm/m)"); ECHO_SMV(CFG, " M208 S", retract_recover_length); #if EXTRUDERS > 1 ECHO_MV(" W", retract_recover_length_swap); #endif ECHO_MV(" F", retract_recover_feedrate * 60); CONFIG_ECHO_START("Auto-Retract: S=0 to disable, 1 to interpret extrude-only moves as retracts or recoveries"); ECHO_LMV(CFG, " M209 S", autoretract_enabled ? 1 : 0); #endif // FWRETRACT if (volumetric_enabled) { CONFIG_ECHO_START("Filament settings:"); ECHO_LMV(CFG, " M200 D", filament_size[0]); #if EXTRUDERS > 1 ECHO_LMV(CFG, " M200 T1 D", filament_size[1]); #if EXTRUDERS > 2 ECHO_LMV(CFG, " M200 T2 D", filament_size[2]); #if EXTRUDERS > 3 ECHO_LMV(CFG, " M200 T3 D", filament_size[3]); #endif #endif #endif } else CONFIG_ECHO_START(" M200 D0"); #if MB(ALLIGATOR) CONFIG_ECHO_START("Motor current:"); ECHO_SMV(CFG, " M906 X", motor_current[X_AXIS]); ECHO_MV(" Y", motor_current[Y_AXIS]); ECHO_MV(" Z", motor_current[Z_AXIS]); ECHO_EMV(" E", motor_current[E_AXIS]); #if DRIVER_EXTRUDERS > 1 for (uint8_t i = 1; i < DRIVER_EXTRUDERS; i++) { ECHO_SMV(CFG, " M906 T", i); ECHO_EMV(" E", motor_current[E_AXIS + i]); } #endif // DRIVER_EXTRUDERS > 1 #endif // ALLIGATOR ConfigSD_PrintSettings(forReplay); }
/** * M501 - Retrieve Configuration */ void Config_RetrieveSettings() { int i = EEPROM_OFFSET; char stored_ver[6]; uint16_t stored_checksum; EEPROM_READ_VAR(i, stored_ver); EEPROM_READ_VAR(i, stored_checksum); if (DEBUGGING(INFO)) { ECHO_SMV(INFO, "Version: [", version); ECHO_MV("] Stored version: [", stored_ver); ECHO_EM("]"); } if (strncmp(version, stored_ver, 5) != 0) { Config_ResetDefault(); } else { float dummy = 0; eeprom_checksum = 0; // clear before reading first "real data" // version number match EEPROM_READ_VAR(i, planner.axis_steps_per_mm); EEPROM_READ_VAR(i, planner.max_feedrate); EEPROM_READ_VAR(i, planner.max_acceleration_mm_per_s2); EEPROM_READ_VAR(i, planner.acceleration); EEPROM_READ_VAR(i, planner.retract_acceleration); EEPROM_READ_VAR(i, planner.travel_acceleration); EEPROM_READ_VAR(i, planner.min_feedrate); EEPROM_READ_VAR(i, planner.min_travel_feedrate); EEPROM_READ_VAR(i, planner.min_segment_time); EEPROM_READ_VAR(i, planner.max_xy_jerk); EEPROM_READ_VAR(i, planner.max_z_jerk); EEPROM_READ_VAR(i, planner.max_e_jerk); EEPROM_READ_VAR(i, home_offset); EEPROM_READ_VAR(i, hotend_offset); #if ENABLED(MESH_BED_LEVELING) uint8_t mesh_num_x = 0, mesh_num_y = 0; EEPROM_READ_VAR(i, mbl.status); EEPROM_READ_VAR(i, mbl.z_offset); EEPROM_READ_VAR(i, mesh_num_x); EEPROM_READ_VAR(i, mesh_num_y); EEPROM_READ_VAR(i, mbl.z_values); #endif #if HEATER_USES_AD595 EEPROM_READ_VAR(i, ad595_offset); EEPROM_READ_VAR(i, ad595_gain); for (int8_t h = 0; h < HOTENDS; h++) if (ad595_gain[h] == 0) ad595_gain[h] == TEMP_SENSOR_AD595_GAIN; #endif #if MECH(DELTA) EEPROM_READ_VAR(i, endstop_adj); EEPROM_READ_VAR(i, delta_radius); EEPROM_READ_VAR(i, delta_diagonal_rod); EEPROM_READ_VAR(i, sw_endstop_max); EEPROM_READ_VAR(i, tower_adj); EEPROM_READ_VAR(i, diagrod_adj); #endif //DELTA #if HASNT(BED_PROBE) float zprobe_zoffset = 0; #endif EEPROM_READ_VAR(i, zprobe_zoffset); #if DISABLED(ULTIPANEL) int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed, gumPreheatHotendTemp, gumPreheatHPBTemp, gumPreheatFanSpeed; #endif EEPROM_READ_VAR(i, plaPreheatHotendTemp); EEPROM_READ_VAR(i, plaPreheatHPBTemp); EEPROM_READ_VAR(i, plaPreheatFanSpeed); EEPROM_READ_VAR(i, absPreheatHotendTemp); EEPROM_READ_VAR(i, absPreheatHPBTemp); EEPROM_READ_VAR(i, absPreheatFanSpeed); EEPROM_READ_VAR(i, gumPreheatHotendTemp); EEPROM_READ_VAR(i, gumPreheatHPBTemp); EEPROM_READ_VAR(i, gumPreheatFanSpeed); #if ENABLED(PIDTEMP) for (int8_t h = 0; h < HOTENDS; h++) { EEPROM_READ_VAR(i, PID_PARAM(Kp, h)); EEPROM_READ_VAR(i, PID_PARAM(Ki, h)); EEPROM_READ_VAR(i, PID_PARAM(Kd, h)); EEPROM_READ_VAR(i, PID_PARAM(Kc, h)); } #endif // PIDTEMP #if DISABLED(PID_ADD_EXTRUSION_RATE) int lpq_len; #endif EEPROM_READ_VAR(i, lpq_len); #if ENABLED(PIDTEMPBED) EEPROM_READ_VAR(i, bedKp); EEPROM_READ_VAR(i, bedKi); EEPROM_READ_VAR(i, bedKd); #endif #if ENABLED(PIDTEMPCHAMBER) EEPROM_READ_VAR(i, chamberKp); EEPROM_READ_VAR(i, chamberKi); EEPROM_READ_VAR(i, chamberKd); #endif #if ENABLED(PIDTEMPCOOLER) EEPROM_READ_VAR(i, coolerKp); EEPROM_READ_VAR(i, coolerKi); EEPROM_READ_VAR(i, coolerKd); #endif #if HASNT(LCD_CONTRAST) int lcd_contrast; #endif EEPROM_READ_VAR(i, lcd_contrast); #if MECH(SCARA) EEPROM_READ_VAR(i, axis_scaling); // 3 floats #endif #if ENABLED(FWRETRACT) EEPROM_READ_VAR(i, autoretract_enabled); EEPROM_READ_VAR(i, retract_length); #if EXTRUDERS > 1 EEPROM_READ_VAR(i, retract_length_swap); #else EEPROM_READ_VAR(i, dummy); #endif EEPROM_READ_VAR(i, retract_feedrate); EEPROM_READ_VAR(i, retract_zlift); EEPROM_READ_VAR(i, retract_recover_length); #if EXTRUDERS > 1 EEPROM_READ_VAR(i, retract_recover_length_swap); #else EEPROM_READ_VAR(i, dummy); #endif EEPROM_READ_VAR(i, retract_recover_feedrate); #endif // FWRETRACT EEPROM_READ_VAR(i, volumetric_enabled); for (int8_t e = 0; e < EXTRUDERS; e++) EEPROM_READ_VAR(i, filament_size[e]); #if ENABLED(IDLE_OOZING_PREVENT) EEPROM_READ_VAR(i, IDLE_OOZING_enabled); #endif #if MB(ALLIGATOR) EEPROM_READ_VAR(i, motor_current); #endif if (eeprom_checksum == stored_checksum) { Config_Postprocess(); ECHO_SV(DB, version); ECHO_MV(" stored settings retrieved (", i); ECHO_EM(" bytes)"); } else { ECHO_LM(ER, "EEPROM checksum mismatch"); Config_ResetDefault(); } } #if ENABLED(EEPROM_CHITCHAT) Config_PrintSettings(); #endif }
/** * M500 - Store Configuration */ void Config_StoreSettings() { float dummy = 0.0f; char ver[6] = "00000"; int i = EEPROM_OFFSET; EEPROM_WRITE_VAR(i, ver); // invalidate data first i += sizeof(eeprom_checksum); // Skip the checksum slot eeprom_checksum = 0; // clear before first "real data" EEPROM_WRITE_VAR(i, planner.axis_steps_per_mm); EEPROM_WRITE_VAR(i, planner.max_feedrate); EEPROM_WRITE_VAR(i, planner.max_acceleration_mm_per_s2); EEPROM_WRITE_VAR(i, planner.acceleration); EEPROM_WRITE_VAR(i, planner.retract_acceleration); EEPROM_WRITE_VAR(i, planner.travel_acceleration); EEPROM_WRITE_VAR(i, planner.min_feedrate); EEPROM_WRITE_VAR(i, planner.min_travel_feedrate); EEPROM_WRITE_VAR(i, planner.min_segment_time); EEPROM_WRITE_VAR(i, planner.max_xy_jerk); EEPROM_WRITE_VAR(i, planner.max_z_jerk); EEPROM_WRITE_VAR(i, planner.max_e_jerk); EEPROM_WRITE_VAR(i, home_offset); EEPROM_WRITE_VAR(i, hotend_offset); #if ENABLED(MESH_BED_LEVELING) // Compile time test that sizeof(mbl.z_values) is as expected typedef char c_assert[(sizeof(mbl.z_values) == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS) * sizeof(dummy)) ? 1 : -1]; uint8_t mesh_num_x = MESH_NUM_X_POINTS, mesh_num_y = MESH_NUM_Y_POINTS, dummy_uint8 = mbl.status & _BV(MBL_STATUS_HAS_MESH_BIT); EEPROM_WRITE_VAR(i, dummy_uint8); EEPROM_WRITE_VAR(i, mbl.z_offset); EEPROM_WRITE_VAR(i, mesh_num_x); EEPROM_WRITE_VAR(i, mesh_num_y); EEPROM_WRITE_VAR(i, mbl.z_values); #endif #if HEATER_USES_AD595 EEPROM_WRITE_VAR(i, ad595_offset); EEPROM_WRITE_VAR(i, ad595_gain); #endif #if MECH(DELTA) EEPROM_WRITE_VAR(i, endstop_adj); EEPROM_WRITE_VAR(i, delta_radius); EEPROM_WRITE_VAR(i, delta_diagonal_rod); EEPROM_WRITE_VAR(i, sw_endstop_max); EEPROM_WRITE_VAR(i, tower_adj); EEPROM_WRITE_VAR(i, diagrod_adj); #elif ENABLED(Z_DUAL_ENDSTOPS) EEPROM_WRITE_VAR(i, z_endstop_adj); #endif #if HASNT(BED_PROBE) float zprobe_zoffset = 0; #endif EEPROM_WRITE_VAR(i, zprobe_zoffset); #if DISABLED(ULTIPANEL) int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED, absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED, gumPreheatHotendTemp = GUM_PREHEAT_HOTEND_TEMP, gumPreheatHPBTemp = GUM_PREHEAT_HPB_TEMP, gumPreheatFanSpeed = GUM_PREHEAT_FAN_SPEED; #endif EEPROM_WRITE_VAR(i, plaPreheatHotendTemp); EEPROM_WRITE_VAR(i, plaPreheatHPBTemp); EEPROM_WRITE_VAR(i, plaPreheatFanSpeed); EEPROM_WRITE_VAR(i, absPreheatHotendTemp); EEPROM_WRITE_VAR(i, absPreheatHPBTemp); EEPROM_WRITE_VAR(i, absPreheatFanSpeed); EEPROM_WRITE_VAR(i, gumPreheatHotendTemp); EEPROM_WRITE_VAR(i, gumPreheatHPBTemp); EEPROM_WRITE_VAR(i, gumPreheatFanSpeed); #if ENABLED(PIDTEMP) for (int h = 0; h < HOTENDS; h++) { EEPROM_WRITE_VAR(i, PID_PARAM(Kp, h)); EEPROM_WRITE_VAR(i, PID_PARAM(Ki, h)); EEPROM_WRITE_VAR(i, PID_PARAM(Kd, h)); EEPROM_WRITE_VAR(i, PID_PARAM(Kc, h)); } #endif #if DISABLED(PID_ADD_EXTRUSION_RATE) int lpq_len = 20; #endif EEPROM_WRITE_VAR(i, lpq_len); #if ENABLED(PIDTEMPBED) EEPROM_WRITE_VAR(i, bedKp); EEPROM_WRITE_VAR(i, bedKi); EEPROM_WRITE_VAR(i, bedKd); #endif #if ENABLED(PIDTEMPCHAMBER) EEPROM_WRITE_VAR(i, chamberKp); EEPROM_WRITE_VAR(i, chamberKi); EEPROM_WRITE_VAR(i, chamberKd); #endif #if ENABLED(PIDTEMPCOOLER) EEPROM_WRITE_VAR(i, coolerKp); EEPROM_WRITE_VAR(i, coolerKi); EEPROM_WRITE_VAR(i, coolerKd); #endif #if HASNT(LCD_CONTRAST) const int lcd_contrast = 32; #endif EEPROM_WRITE_VAR(i, lcd_contrast); #if MECH(SCARA) EEPROM_WRITE_VAR(i, axis_scaling); // 3 floats #endif #if ENABLED(FWRETRACT) EEPROM_WRITE_VAR(i, autoretract_enabled); EEPROM_WRITE_VAR(i, retract_length); #if EXTRUDERS > 1 EEPROM_WRITE_VAR(i, retract_length_swap); #else dummy = 0.0f; EEPROM_WRITE_VAR(i, dummy); #endif EEPROM_WRITE_VAR(i, retract_feedrate); EEPROM_WRITE_VAR(i, retract_zlift); EEPROM_WRITE_VAR(i, retract_recover_length); #if EXTRUDERS > 1 EEPROM_WRITE_VAR(i, retract_recover_length_swap); #else dummy = 0.0f; EEPROM_WRITE_VAR(i, dummy); #endif EEPROM_WRITE_VAR(i, retract_recover_feedrate); #endif // FWRETRACT EEPROM_WRITE_VAR(i, volumetric_enabled); // Save filament sizes for (int e = 0; e < EXTRUDERS; e++) EEPROM_WRITE_VAR(i, filament_size[e]); #if ENABLED(IDLE_OOZING_PREVENT) EEPROM_WRITE_VAR(i, IDLE_OOZING_enabled); #endif #if MB(ALLIGATOR) EEPROM_WRITE_VAR(i, motor_current); #endif uint16_t final_checksum = eeprom_checksum; int j = EEPROM_OFFSET; EEPROM_WRITE_VAR(j, version); EEPROM_WRITE_VAR(j, final_checksum); // Report storage size ECHO_SMV(DB, "Settings Stored (", i); ECHO_EM(" bytes)"); }
/** * Print Configuration Settings - M503 */ void Config_PrintSettings(bool forReplay) { // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown if (!forReplay) { ECHO_LM(CFG, "Steps per unit:"); } ECHO_SMV(CFG, " M92 X", axis_steps_per_unit[X_AXIS]); ECHO_MV(" Y", axis_steps_per_unit[Y_AXIS]); ECHO_MV(" Z", axis_steps_per_unit[Z_AXIS]); ECHO_EMV(" E", axis_steps_per_unit[E_AXIS]); #if EXTRUDERS > 1 for (short i = 1; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M92 T", i); ECHO_EMV(" E", axis_steps_per_unit[E_AXIS + i]); } #endif //EXTRUDERS > 1 #if MECH(SCARA) if (!forReplay) { ECHO_LM(CFG, "Scaling factors:"); } ECHO_SMV(CFG, " M365 X", axis_scaling[X_AXIS]); ECHO_MV(" Y", axis_scaling[Y_AXIS]); ECHO_EMV(" Z", axis_scaling[Z_AXIS]); #endif // SCARA if (!forReplay) { ECHO_LM(CFG, "Maximum feedrates (mm/s):"); } ECHO_SMV(CFG, " M203 X", max_feedrate[X_AXIS]); ECHO_MV(" Y", max_feedrate[Y_AXIS] ); ECHO_MV(" Z", max_feedrate[Z_AXIS] ); ECHO_EMV(" E", max_feedrate[E_AXIS]); #if EXTRUDERS > 1 for (short i = 1; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M203 T", i); ECHO_EMV(" E", max_feedrate[E_AXIS + i]); } #endif //EXTRUDERS > 1 if (!forReplay) { ECHO_LM(CFG, "Maximum Acceleration (mm/s2):"); } ECHO_SMV(CFG, " M201 X", max_acceleration_units_per_sq_second[X_AXIS] ); ECHO_MV(" Y", max_acceleration_units_per_sq_second[Y_AXIS] ); ECHO_MV(" Z", max_acceleration_units_per_sq_second[Z_AXIS] ); ECHO_EMV(" E", max_acceleration_units_per_sq_second[E_AXIS]); #if EXTRUDERS > 1 for (int8_t i = 1; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M201 T", i); ECHO_EMV(" E", max_acceleration_units_per_sq_second[E_AXIS + i]); } #endif //EXTRUDERS > 1 ECHO_E; if (!forReplay) { ECHO_LM(CFG, "Accelerations: P=printing, V=travel and T* R=retract"); } ECHO_SMV(CFG," M204 P", acceleration); ECHO_EMV(" V", travel_acceleration); #if EXTRUDERS > 0 for (int8_t i = 0; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M204 T", i); ECHO_EMV(" R", retract_acceleration[i]); } #endif if (!forReplay) { ECHO_LM(CFG, "Advanced variables: S=Min feedrate (mm/s), V=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s)"); } ECHO_SMV(CFG, " M205 S", minimumfeedrate ); ECHO_MV(" V", mintravelfeedrate ); ECHO_MV(" B", minsegmenttime ); ECHO_MV(" X", max_xy_jerk ); ECHO_MV(" Z", max_z_jerk); ECHO_EMV(" E", max_e_jerk[0]); #if (EXTRUDERS > 1) for(int8_t i = 1; i < EXTRUDERS; i++) { ECHO_SMV(CFG, " M205 T", i); ECHO_EMV(" E" , max_e_jerk[i]); } #endif if (!forReplay) { ECHO_LM(CFG, "Home offset (mm):"); } ECHO_SMV(CFG, " M206 X", home_offset[X_AXIS] ); ECHO_MV(" Y", home_offset[Y_AXIS] ); ECHO_EMV(" Z", home_offset[Z_AXIS] ); if (!forReplay) { ECHO_LM(CFG, "Hotend offset (mm):"); } for (int8_t h = 0; h < HOTENDS; h++) { ECHO_SMV(CFG, " M218 T", h); ECHO_MV(" X", hotend_offset[X_AXIS][h]); ECHO_MV(" Y", hotend_offset[Y_AXIS][h]); ECHO_EMV(" Z", hotend_offset[Z_AXIS][h]); } #if HEATER_USES_AD595 if (!forReplay) { ECHO_LM(CFG, "AD595 Offset and Gain:"); } for (int8_t h = 0; h < HOTENDS; h++) { ECHO_SMV(CFG, " M595 T", h); ECHO_MV(" O", ad595_offset[h]); ECHO_EMV(", S", ad595_gain[h]); } #endif // HEATER_USES_AD595 #if MECH(DELTA) if (!forReplay) { ECHO_LM(CFG, "Delta Geometry adjustment:"); } ECHO_SMV(CFG, " M666 A", tower_adj[0], 3); ECHO_MV(" B", tower_adj[1], 3); ECHO_MV(" C", tower_adj[2], 3); ECHO_MV(" I", tower_adj[3], 3); ECHO_MV(" J", tower_adj[4], 3); ECHO_MV(" K", tower_adj[5], 3); ECHO_MV(" U", diagrod_adj[0], 3); ECHO_MV(" V", diagrod_adj[1], 3); ECHO_MV(" W", diagrod_adj[2], 3); ECHO_MV(" R", delta_radius); ECHO_MV(" D", delta_diagonal_rod); ECHO_EMV(" H", sw_endstop_max[2]); if (!forReplay) { ECHO_LM(CFG, "Endstop Offsets:"); } ECHO_SMV(CFG, " M666 X", endstop_adj[X_AXIS]); ECHO_MV(" Y", endstop_adj[Y_AXIS]); ECHO_EMV(" Z", endstop_adj[Z_AXIS]); if (!forReplay) { ECHO_LM(CFG, "Z-Probe Offset:"); } ECHO_SMV(CFG, " M666 P X", z_probe_offset[0]); ECHO_MV(" Y", z_probe_offset[1]); ECHO_EMV(" Z", z_probe_offset[2]); #elif ENABLED(Z_DUAL_ENDSTOPS) if (!forReplay) { ECHO_LM(CFG, "Z2 Endstop adjustement (mm):"); } ECHO_LMV(CFG, " M666 Z", z_endstop_adj ); #elif ENABLED(AUTO_BED_LEVELING_FEATURE) if (!forReplay) { ECHO_LM(CFG, "Z Probe offset (mm)"); } ECHO_LMV(CFG, " M666 P", zprobe_zoffset); #endif #if ENABLED(ULTIPANEL) if (!forReplay) { ECHO_LM(CFG, "Material heatup parameters:"); } ECHO_SMV(CFG, " M145 S0 H", plaPreheatHotendTemp); ECHO_MV(" B", plaPreheatHPBTemp); ECHO_MV(" F", plaPreheatFanSpeed); ECHO_EM(" (Material PLA)"); ECHO_SMV(CFG, " M145 S1 H", absPreheatHotendTemp); ECHO_MV(" B", absPreheatHPBTemp); ECHO_MV(" F", absPreheatFanSpeed); ECHO_EM(" (Material ABS)"); ECHO_SMV(CFG, " M145 S2 H", gumPreheatHotendTemp); ECHO_MV(" B", gumPreheatHPBTemp); ECHO_MV(" F", gumPreheatFanSpeed); ECHO_EM(" (Material GUM)"); #endif // ULTIPANEL #if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED) if (!forReplay) { ECHO_LM(CFG, "PID settings:"); } #if ENABLED(PIDTEMP) for (uint8_t h = 0; h < HOTENDS; h++) { ECHO_SMV(CFG, " M301 H", h); ECHO_MV(" P", PID_PARAM(Kp, h)); ECHO_MV(" I", unscalePID_i(PID_PARAM(Ki, h))); ECHO_MV(" D", unscalePID_d(PID_PARAM(Kd, h))); #if ENABLED(PID_ADD_EXTRUSION_RATE) ECHO_MV(" C", PID_PARAM(Kc, h)); #endif ECHO_E; } #if ENABLED(PID_ADD_EXTRUSION_RATE) ECHO_SMV(CFG, " M301 L", lpq_len); #endif #endif #if ENABLED(PIDTEMPBED) ECHO_SMV(CFG, " M304 P", bedKp); // for compatibility with hosts, only echos values for E0 ECHO_MV(" I", unscalePID_i(bedKi)); ECHO_EMV(" D", unscalePID_d(bedKd)); #endif #endif #if ENABLED(FWRETRACT) if (!forReplay) { ECHO_LM(CFG, "Retract: S=Length (mm) F:Speed (mm/m) Z: ZLift (mm)"); } ECHO_SMV(CFG, " M207 S", retract_length); ECHO_MV(" F", retract_feedrate*60); ECHO_EMV(" Z", retract_zlift); if (!forReplay) { ECHO_LM(CFG, "Recover: S=Extra length (mm) F:Speed (mm/m)"); } ECHO_SMV(CFG, " M208 S", retract_recover_length); ECHO_MV(" F", retract_recover_feedrate*60); if (!forReplay) { ECHO_LM(CFG, "Auto-Retract: S=0 to disable, 1 to interpret extrude-only moves as retracts or recoveries"); } ECHO_LMV(CFG, " M209 S", autoretract_enabled); #if EXTRUDERS > 1 if (!forReplay) { ECHO_LM(CFG, "Multi-extruder settings:"); ECHO_LMV(CFG, " Swap retract length (mm): ", retract_length_swap); ECHO_LMV(CFG, " Swap rec. addl. length (mm): ", retract_recover_length_swap); } #endif // EXTRUDERS > 1 #endif // FWRETRACT if (volumetric_enabled) { if (!forReplay) { ECHO_LM(CFG, "Filament settings:"); } ECHO_LMV(CFG, " M200 D", filament_size[0]); #if EXTRUDERS > 1 ECHO_LMV(CFG, " M200 T1 D", filament_size[1]); #if EXTRUDERS > 2 ECHO_LMV(CFG, " M200 T2 D", filament_size[2]); #if EXTRUDERS > 3 ECHO_LMV(CFG, " M200 T3 D", filament_size[3]); #endif #endif #endif } else { if (!forReplay) { ECHO_LM(CFG, "Filament settings: Disabled"); } } #if MB(ALLIGATOR) if (!forReplay) { ECHO_LM(CFG, "Current:"); } ECHO_SMV(CFG, " M906 X", motor_current[X_AXIS]); ECHO_MV(" Y", motor_current[Y_AXIS]); ECHO_MV(" Z", motor_current[Z_AXIS]); ECHO_EMV(" E", motor_current[E_AXIS]); #if DRIVER_EXTRUDERS > 1 for (uint8_t i = 1; i < DRIVER_EXTRUDERS; i++) { ECHO_SMV(CFG, " M906 T", i); ECHO_EMV(" E", motor_current[E_AXIS + i]); } #endif // DRIVER_EXTRUDERS > 1 #endif // ALLIGATOR ConfigSD_PrintSettings(forReplay); }
void Config_StoreSettings() { float dummy = 0.0f; char ver[7] = "000000"; int i = EEPROM_OFFSET; EEPROM_WRITE_VAR(i, ver); // invalidate data first EEPROM_WRITE_VAR(i, axis_steps_per_unit); EEPROM_WRITE_VAR(i, max_feedrate); EEPROM_WRITE_VAR(i, max_acceleration_units_per_sq_second); EEPROM_WRITE_VAR(i, acceleration); EEPROM_WRITE_VAR(i, retract_acceleration); EEPROM_WRITE_VAR(i, travel_acceleration); EEPROM_WRITE_VAR(i, minimumfeedrate); EEPROM_WRITE_VAR(i, mintravelfeedrate); EEPROM_WRITE_VAR(i, minsegmenttime); EEPROM_WRITE_VAR(i, max_xy_jerk); EEPROM_WRITE_VAR(i, max_z_jerk); EEPROM_WRITE_VAR(i, max_e_jerk); EEPROM_WRITE_VAR(i, home_offset); EEPROM_WRITE_VAR(i, hotend_offset); #if !MECH(DELTA) EEPROM_WRITE_VAR(i, zprobe_zoffset); #endif #if HEATER_USES_AD595 EEPROM_WRITE_VAR(i, ad595_offset); EEPROM_WRITE_VAR(i, ad595_gain); #endif #if MECH(DELTA) EEPROM_WRITE_VAR(i, endstop_adj); EEPROM_WRITE_VAR(i, delta_radius); EEPROM_WRITE_VAR(i, delta_diagonal_rod); EEPROM_WRITE_VAR(i, sw_endstop_max); EEPROM_WRITE_VAR(i, tower_adj); EEPROM_WRITE_VAR(i, diagrod_adj); EEPROM_WRITE_VAR(i, z_probe_offset); #elif ENABLED(Z_DUAL_ENDSTOPS) EEPROM_WRITE_VAR(i, z_endstop_adj); // 1 floats #endif #if DISABLED(ULTIPANEL) int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED, absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED, gumPreheatHotendTemp = GUM_PREHEAT_HOTEND_TEMP, gumPreheatHPBTemp = GUM_PREHEAT_HPB_TEMP, gumPreheatFanSpeed = GUM_PREHEAT_FAN_SPEED; #endif EEPROM_WRITE_VAR(i, plaPreheatHotendTemp); EEPROM_WRITE_VAR(i, plaPreheatHPBTemp); EEPROM_WRITE_VAR(i, plaPreheatFanSpeed); EEPROM_WRITE_VAR(i, absPreheatHotendTemp); EEPROM_WRITE_VAR(i, absPreheatHPBTemp); EEPROM_WRITE_VAR(i, absPreheatFanSpeed); EEPROM_WRITE_VAR(i, gumPreheatHotendTemp); EEPROM_WRITE_VAR(i, gumPreheatHPBTemp); EEPROM_WRITE_VAR(i, gumPreheatFanSpeed); #if ENABLED(PIDTEMP) for (int h = 0; h < HOTENDS; h++) { EEPROM_WRITE_VAR(i, PID_PARAM(Kp, h)); EEPROM_WRITE_VAR(i, PID_PARAM(Ki, h)); EEPROM_WRITE_VAR(i, PID_PARAM(Kd, h)); EEPROM_WRITE_VAR(i, PID_PARAM(Kc, h)); } #endif #if DISABLED(PID_ADD_EXTRUSION_RATE) int lpq_len = 20; #endif EEPROM_WRITE_VAR(i, lpq_len); #if ENABLED(PIDTEMPBED) EEPROM_WRITE_VAR(i, bedKp); EEPROM_WRITE_VAR(i, bedKi); EEPROM_WRITE_VAR(i, bedKd); #endif #if HASNT(LCD_CONTRAST) const int lcd_contrast = 32; #endif EEPROM_WRITE_VAR(i, lcd_contrast); #if MECH(SCARA) EEPROM_WRITE_VAR(i, axis_scaling); // 3 floats #endif #if ENABLED(FWRETRACT) EEPROM_WRITE_VAR(i, autoretract_enabled); EEPROM_WRITE_VAR(i, retract_length); #if EXTRUDERS > 1 EEPROM_WRITE_VAR(i, retract_length_swap); #else dummy = 0.0f; EEPROM_WRITE_VAR(i, dummy); #endif EEPROM_WRITE_VAR(i, retract_feedrate); EEPROM_WRITE_VAR(i, retract_zlift); EEPROM_WRITE_VAR(i, retract_recover_length); #if EXTRUDERS > 1 EEPROM_WRITE_VAR(i, retract_recover_length_swap); #else dummy = 0.0f; EEPROM_WRITE_VAR(i, dummy); #endif EEPROM_WRITE_VAR(i, retract_recover_feedrate); #endif // FWRETRACT EEPROM_WRITE_VAR(i, volumetric_enabled); // Save filament sizes for (int e = 0; e < EXTRUDERS; e++) EEPROM_WRITE_VAR(i, filament_size[e]); #if ENABLED(IDLE_OOZING_PREVENT) EEPROM_WRITE_VAR(i, IDLE_OOZING_enabled); #endif #if MB(ALLIGATOR) EEPROM_WRITE_VAR(i, motor_current); #endif char ver2[7] = EEPROM_VERSION; int j = EEPROM_OFFSET; EEPROM_WRITE_VAR(j, ver2); // validate data // Report storage size ECHO_SMV(DB, "Settings Stored (", (unsigned long)i); ECHO_EM(" bytes)"); }
void PID_autotune(float temp, int hotend, int ncycles) { float input = 0.0; int cycles = 0; bool heating = true; millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms; long t_high = 0, t_low = 0; long bias, d; float Ku, Tu; float Kp_temp, Ki_temp, Kd_temp; float max = 0, min = 10000; #if HAS_AUTO_FAN millis_t next_auto_fan_check_ms = temp_ms + 2500; #endif if (hotend >= HOTENDS #if !HAS_TEMP_BED || hotend < 0 #endif ) { ECHO_LM(ER, MSG_PID_BAD_EXTRUDER_NUM); return; } ECHO_LM(DB, MSG_PID_AUTOTUNE_START); if (hotend < 0) { ECHO_SM(DB, "BED"); } else { ECHO_SMV(DB, "Hotend: ", hotend); } ECHO_MV(" Temp: ", temp); ECHO_EMV(" Cycles: ", ncycles); disable_all_heaters(); // switch off all heaters. if (hotend < 0) soft_pwm_bed = bias = d = MAX_BED_POWER / 2; else soft_pwm[hotend] = bias = d = PID_MAX / 2; // PID Tuning loop for (;;) { millis_t ms = millis(); if (temp_meas_ready) { // temp sample ready updateTemperaturesFromRawValues(); input = (hotend<0)?current_temperature_bed:current_temperature[hotend]; max = max(max, input); min = min(min, input); #if HAS_AUTO_FAN if (ms > next_auto_fan_check_ms) { checkExtruderAutoFans(); next_auto_fan_check_ms = ms + 2500; } #endif if (heating && input > temp) { if (ms > t2 + 5000) { heating = false; if (hotend < 0) soft_pwm_bed = (bias - d) >> 1; else soft_pwm[hotend] = (bias - d) >> 1; t1 = ms; t_high = t1 - t2; max = temp; } } if (!heating && input < temp) { if (ms > t1 + 5000) { heating = true; t2 = ms; t_low = t2 - t1; if (cycles > 0) { long max_pow = hotend < 0 ? MAX_BED_POWER : PID_MAX; bias += (d*(t_high - t_low))/(t_low + t_high); bias = constrain(bias, 20, max_pow - 20); d = (bias > max_pow / 2) ? max_pow - 1 - bias : bias; ECHO_MV(MSG_BIAS, bias); ECHO_MV(MSG_D, d); ECHO_MV(MSG_T_MIN, min); ECHO_MV(MSG_T_MAX, max); if (cycles > 2) { Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0); Tu = ((float)(t_low + t_high) / 1000.0); ECHO_MV(MSG_KU, Ku); ECHO_EMV(MSG_TU, Tu); Kp_temp = 0.6 * Ku; Ki_temp = 2 * Kp_temp / Tu; Kd_temp = Kp_temp * Tu / 8; ECHO_EM(MSG_CLASSIC_PID); ECHO_MV(MSG_KP, Kp_temp); ECHO_MV(MSG_KI, Ki_temp); ECHO_EMV(MSG_KD, Kd_temp); } else { ECHO_E; } } if (hotend < 0) soft_pwm_bed = (bias + d) >> 1; else soft_pwm[hotend] = (bias + d) >> 1; cycles++; min = temp; }