This commit is contained in:
Rob McKenzie 2018-11-21 17:21:27 +10:00
parent 27e860e945
commit 11f1a44d40
87 changed files with 27331 additions and 26605 deletions

View File

@ -6,9 +6,9 @@
#ifdef BLINKM #ifdef BLINKM
#if (ARDUINO >= 100) #if (ARDUINO >= 100)
# include "Arduino.h" # include "Arduino.h"
#else #else
# include "WProgram.h" # include "WProgram.h"
#endif #endif
#include "BlinkM.h" #include "BlinkM.h"

View File

@ -3,9 +3,9 @@
Library header file for BlinkM library Library header file for BlinkM library
*/ */
#if (ARDUINO >= 100) #if (ARDUINO >= 100)
# include "Arduino.h" # include "Arduino.h"
#else #else
# include "WProgram.h" # include "WProgram.h"
#endif #endif
#include "Wire.h" #include "Wire.h"

View File

@ -128,14 +128,14 @@
#define BANG_MAX 255 // limits current to nozzle while in bang-bang mode; 255=full current #define BANG_MAX 255 // limits current to nozzle while in bang-bang mode; 255=full current
#define PID_MAX BANG_MAX // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current #define PID_MAX BANG_MAX // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current
#ifdef PIDTEMP #ifdef PIDTEMP
//#define PID_DEBUG // Sends debug data to the serial port. //#define PID_DEBUG // Sends debug data to the serial port.
//#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX //#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
//#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay //#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay
#define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature #define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature
// is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max. // is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
#define PID_INTEGRAL_DRIVE_MAX PID_MAX //limit for the integral term #define PID_INTEGRAL_DRIVE_MAX PID_MAX //limit for the integral term
#define K1 0.95 //smoothing factor within the PID #define K1 0.95 //smoothing factor within the PID
#define PID_dT ((OVERSAMPLENR * 10.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the temperature routine #define PID_dT ((OVERSAMPLENR * 10.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the temperature routine
// If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it // If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it
// Ultimaker // Ultimaker
@ -215,22 +215,22 @@ your extruder heater takes 2 minutes to hit the target on heating.
#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
#ifndef ENDSTOPPULLUPS #ifndef ENDSTOPPULLUPS
// fine endstop settings: Individual pullups. will be ignored if ENDSTOPPULLUPS is defined // fine endstop settings: Individual pullups. will be ignored if ENDSTOPPULLUPS is defined
// #define ENDSTOPPULLUP_XMAX // #define ENDSTOPPULLUP_XMAX
// #define ENDSTOPPULLUP_YMAX // #define ENDSTOPPULLUP_YMAX
// #define ENDSTOPPULLUP_ZMAX // #define ENDSTOPPULLUP_ZMAX
// #define ENDSTOPPULLUP_XMIN // #define ENDSTOPPULLUP_XMIN
// #define ENDSTOPPULLUP_YMIN // #define ENDSTOPPULLUP_YMIN
// #define ENDSTOPPULLUP_ZMIN // #define ENDSTOPPULLUP_ZMIN
#endif #endif
#ifdef ENDSTOPPULLUPS #ifdef ENDSTOPPULLUPS
#define ENDSTOPPULLUP_XMAX #define ENDSTOPPULLUP_XMAX
#define ENDSTOPPULLUP_YMAX #define ENDSTOPPULLUP_YMAX
#define ENDSTOPPULLUP_ZMAX #define ENDSTOPPULLUP_ZMAX
#define ENDSTOPPULLUP_XMIN #define ENDSTOPPULLUP_XMIN
#define ENDSTOPPULLUP_YMIN #define ENDSTOPPULLUP_YMIN
#define ENDSTOPPULLUP_ZMIN #define ENDSTOPPULLUP_ZMIN
#endif #endif
// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
@ -243,7 +243,7 @@ your extruder heater takes 2 minutes to hit the target on heating.
// Disable max endstops for compatibility with endstop checking routine // Disable max endstops for compatibility with endstop checking routine
#if defined(COREXY) && !defined(DISABLE_MAX_ENDSTOPS) #if defined(COREXY) && !defined(DISABLE_MAX_ENDSTOPS)
#define DISABLE_MAX_ENDSTOPS #define DISABLE_MAX_ENDSTOPS
#endif #endif
// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
@ -300,58 +300,58 @@ your extruder heater takes 2 minutes to hit the target on heating.
// Probe 3 arbitrary points on the bed (that aren't colinear) // Probe 3 arbitrary points on the bed (that aren't colinear)
// You must specify the X & Y coordinates of all 3 points // You must specify the X & Y coordinates of all 3 points
#define AUTO_BED_LEVELING_GRID #define AUTO_BED_LEVELING_GRID
// with AUTO_BED_LEVELING_GRID, the bed is sampled in a // with AUTO_BED_LEVELING_GRID, the bed is sampled in a
// AUTO_BED_LEVELING_GRID_POINTSxAUTO_BED_LEVELING_GRID_POINTS grid // AUTO_BED_LEVELING_GRID_POINTSxAUTO_BED_LEVELING_GRID_POINTS grid
// and least squares solution is calculated // and least squares solution is calculated
// Note: this feature occupies 10'206 byte // Note: this feature occupies 10'206 byte
#ifdef AUTO_BED_LEVELING_GRID #ifdef AUTO_BED_LEVELING_GRID
// set the rectangle in which to probe // set the rectangle in which to probe
#define LEFT_PROBE_BED_POSITION 15 #define LEFT_PROBE_BED_POSITION 15
#define RIGHT_PROBE_BED_POSITION 170 #define RIGHT_PROBE_BED_POSITION 170
#define BACK_PROBE_BED_POSITION 180 #define BACK_PROBE_BED_POSITION 180
#define FRONT_PROBE_BED_POSITION 20 #define FRONT_PROBE_BED_POSITION 20
// set the number of grid points per dimension // set the number of grid points per dimension
// I wouldn't see a reason to go above 3 (=9 probing points on the bed) // I wouldn't see a reason to go above 3 (=9 probing points on the bed)
#define AUTO_BED_LEVELING_GRID_POINTS 2 #define AUTO_BED_LEVELING_GRID_POINTS 2
#else // not AUTO_BED_LEVELING_GRID #else // not AUTO_BED_LEVELING_GRID
// with no grid, just probe 3 arbitrary points. A simple cross-product // with no grid, just probe 3 arbitrary points. A simple cross-product
// is used to esimate the plane of the print bed // is used to esimate the plane of the print bed
#define ABL_PROBE_PT_1_X 15 #define ABL_PROBE_PT_1_X 15
#define ABL_PROBE_PT_1_Y 180 #define ABL_PROBE_PT_1_Y 180
#define ABL_PROBE_PT_2_X 15 #define ABL_PROBE_PT_2_X 15
#define ABL_PROBE_PT_2_Y 20 #define ABL_PROBE_PT_2_Y 20
#define ABL_PROBE_PT_3_X 170 #define ABL_PROBE_PT_3_X 170
#define ABL_PROBE_PT_3_Y 20 #define ABL_PROBE_PT_3_Y 20
#endif // AUTO_BED_LEVELING_GRID #endif // AUTO_BED_LEVELING_GRID
// these are the offsets to the probe relative to the extruder tip (Hotend - Probe) // these are the offsets to the probe relative to the extruder tip (Hotend - Probe)
// X and Y offsets must be integers // X and Y offsets must be integers
#define X_PROBE_OFFSET_FROM_EXTRUDER -25 #define X_PROBE_OFFSET_FROM_EXTRUDER -25
#define Y_PROBE_OFFSET_FROM_EXTRUDER -29 #define Y_PROBE_OFFSET_FROM_EXTRUDER -29
#define Z_PROBE_OFFSET_FROM_EXTRUDER -12.35 #define Z_PROBE_OFFSET_FROM_EXTRUDER -12.35
#define Z_RAISE_BEFORE_HOMING 4 // (in mm) Raise Z before homing (G28) for Probe Clearance. #define Z_RAISE_BEFORE_HOMING 4 // (in mm) Raise Z before homing (G28) for Probe Clearance.
// Be sure you have this distance over your Z_MAX_POS in case // Be sure you have this distance over your Z_MAX_POS in case
#define XY_TRAVEL_SPEED 8000 // X and Y axis travel speed between probes, in mm/min #define XY_TRAVEL_SPEED 8000 // X and Y axis travel speed between probes, in mm/min
#define Z_RAISE_BEFORE_PROBING 15 //How much the extruder will be raised before traveling to the first probing point. #define Z_RAISE_BEFORE_PROBING 15 //How much the extruder will be raised before traveling to the first probing point.
#define Z_RAISE_BETWEEN_PROBINGS 5 //How much the extruder will be raised when traveling from between next probing points #define Z_RAISE_BETWEEN_PROBINGS 5 //How much the extruder will be raised when traveling from between next probing points
//#define Z_PROBE_SLED // turn on if you have a z-probe mounted on a sled like those designed by Charles Bell //#define Z_PROBE_SLED // turn on if you have a z-probe mounted on a sled like those designed by Charles Bell
//#define SLED_DOCKING_OFFSET 5 // the extra distance the X axis must travel to pickup the sled. 0 should be fine but you can push it further if you'd like. //#define SLED_DOCKING_OFFSET 5 // the extra distance the X axis must travel to pickup the sled. 0 should be fine but you can push it further if you'd like.
//If defined, the Probe servo will be turned on only during movement and then turned off to avoid jerk //If defined, the Probe servo will be turned on only during movement and then turned off to avoid jerk
//The value is the delay to turn the servo off after powered on - depends on the servo speed; 300ms is good value, but you can try lower it. //The value is the delay to turn the servo off after powered on - depends on the servo speed; 300ms is good value, but you can try lower it.
// You MUST HAVE the SERVO_ENDSTOPS defined to use here a value higher than zero otherwise your code will not compile. // You MUST HAVE the SERVO_ENDSTOPS defined to use here a value higher than zero otherwise your code will not compile.
// #define PROBE_SERVO_DEACTIVATION_DELAY 300 // #define PROBE_SERVO_DEACTIVATION_DELAY 300
@ -359,42 +359,42 @@ your extruder heater takes 2 minutes to hit the target on heating.
//If you have enabled the Bed Auto Leveling and are using the same Z Probe for Z Homing, //If you have enabled the Bed Auto Leveling and are using the same Z Probe for Z Homing,
//it is highly recommended you let this Z_SAFE_HOMING enabled! //it is highly recommended you let this Z_SAFE_HOMING enabled!
//#define Z_SAFE_HOMING // This feature is meant to avoid Z homing with probe outside the bed area. //#define Z_SAFE_HOMING // This feature is meant to avoid Z homing with probe outside the bed area.
// When defined, it will: // When defined, it will:
// - Allow Z homing only after X and Y homing AND stepper drivers still enabled // - Allow Z homing only after X and Y homing AND stepper drivers still enabled
// - If stepper drivers timeout, it will need X and Y homing again before Z homing // - If stepper drivers timeout, it will need X and Y homing again before Z homing
// - Position the probe in a defined XY point before Z Homing when homing all axis (G28) // - Position the probe in a defined XY point before Z Homing when homing all axis (G28)
// - Block Z homing only when the probe is outside bed area. // - Block Z homing only when the probe is outside bed area.
#ifdef Z_SAFE_HOMING #ifdef Z_SAFE_HOMING
#define Z_SAFE_HOMING_X_POINT (X_MAX_LENGTH/2) // X point for Z homing when homing all axis (G28) #define Z_SAFE_HOMING_X_POINT (X_MAX_LENGTH/2) // X point for Z homing when homing all axis (G28)
#define Z_SAFE_HOMING_Y_POINT (Y_MAX_LENGTH/2) // Y point for Z homing when homing all axis (G28) #define Z_SAFE_HOMING_Y_POINT (Y_MAX_LENGTH/2) // Y point for Z homing when homing all axis (G28)
#endif #endif
#ifdef AUTO_BED_LEVELING_GRID // Check if Probe_Offset * Grid Points is greater than Probing Range #ifdef AUTO_BED_LEVELING_GRID // Check if Probe_Offset * Grid Points is greater than Probing Range
#if X_PROBE_OFFSET_FROM_EXTRUDER < 0 #if X_PROBE_OFFSET_FROM_EXTRUDER < 0
#if (-(X_PROBE_OFFSET_FROM_EXTRUDER * AUTO_BED_LEVELING_GRID_POINTS) >= (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION)) #if (-(X_PROBE_OFFSET_FROM_EXTRUDER * AUTO_BED_LEVELING_GRID_POINTS) >= (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION))
#error "The X axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" #error "The X axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS"
#endif #endif
#else #else
#if ((X_PROBE_OFFSET_FROM_EXTRUDER * AUTO_BED_LEVELING_GRID_POINTS) >= (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION)) #if ((X_PROBE_OFFSET_FROM_EXTRUDER * AUTO_BED_LEVELING_GRID_POINTS) >= (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION))
#error "The X axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" #error "The X axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS"
#endif #endif
#endif #endif
#if Y_PROBE_OFFSET_FROM_EXTRUDER < 0 #if Y_PROBE_OFFSET_FROM_EXTRUDER < 0
#if (-(Y_PROBE_OFFSET_FROM_EXTRUDER * AUTO_BED_LEVELING_GRID_POINTS) >= (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION)) #if (-(Y_PROBE_OFFSET_FROM_EXTRUDER * AUTO_BED_LEVELING_GRID_POINTS) >= (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION))
#error "The Y axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" #error "The Y axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS"
#endif #endif
#else #else
#if ((Y_PROBE_OFFSET_FROM_EXTRUDER * AUTO_BED_LEVELING_GRID_POINTS) >= (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION)) #if ((Y_PROBE_OFFSET_FROM_EXTRUDER * AUTO_BED_LEVELING_GRID_POINTS) >= (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION))
#error "The Y axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" #error "The Y axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS"
#endif #endif
#endif #endif
#endif #endif
#endif // ENABLE_AUTO_BED_LEVELING #endif // ENABLE_AUTO_BED_LEVELING
@ -426,9 +426,9 @@ your extruder heater takes 2 minutes to hit the target on heating.
// Custom M code points // Custom M code points
#define CUSTOM_M_CODES #define CUSTOM_M_CODES
#ifdef CUSTOM_M_CODES #ifdef CUSTOM_M_CODES
#define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851
#define Z_PROBE_OFFSET_RANGE_MIN -15 #define Z_PROBE_OFFSET_RANGE_MIN -15
#define Z_PROBE_OFFSET_RANGE_MAX -5 #define Z_PROBE_OFFSET_RANGE_MAX -5
#endif #endif

View File

@ -210,7 +210,7 @@ static const M500_conf default_conf PROGMEM =
RETRACT_RECOVER_LENGTH, RETRACT_RECOVER_LENGTH,
RETRACT_RECOVER_FEEDRATE, RETRACT_RECOVER_FEEDRATE,
false, false,
{DEFAULT_NOMINAL_FILAMENT_DIA, { DEFAULT_NOMINAL_FILAMENT_DIA,
#if EXTRUDERS > 1 #if EXTRUDERS > 1
DEFAULT_NOMINAL_FILAMENT_DIA, DEFAULT_NOMINAL_FILAMENT_DIA,
#if EXTRUDERS > 2 #if EXTRUDERS > 2
@ -295,9 +295,9 @@ bool Config_RetrieveSettings()
previous_settings_retrieved = false; previous_settings_retrieved = false;
} }
} }
#ifdef EEPROM_CHITCHAT #ifdef EEPROM_CHITCHAT
Config_PrintSettings(); Config_PrintSettings();
#endif #endif
return previous_settings_retrieved; return previous_settings_retrieved;
} }
#endif #endif
@ -318,7 +318,7 @@ void Config_ResetDefault()
calculate_extruder_multipliers(); calculate_extruder_multipliers();
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded"); SERIAL_ECHOLNPGM("Hardcoded Default Settings Loaded");
} }

View File

@ -54,11 +54,20 @@ void Config_StoreSettings();
bool Config_RetrieveSettings(); bool Config_RetrieveSettings();
#else #else
FORCE_INLINE void Config_StoreSettings() {} FORCE_INLINE void Config_StoreSettings() {}
FORCE_INLINE void Config_RetrieveSettings() { Config_ResetDefault(); Config_PrintSettings(); } FORCE_INLINE void Config_RetrieveSettings() {
Config_ResetDefault();
Config_PrintSettings();
}
#endif #endif
inline uint8_t calibration_status() { return eeprom_read_byte((uint8_t*)EEPROM_CALIBRATION_STATUS); } inline uint8_t calibration_status() {
inline void calibration_status_store(uint8_t status) { eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS, status); } return eeprom_read_byte((uint8_t*)EEPROM_CALIBRATION_STATUS);
inline bool calibration_status_pinda() { return eeprom_read_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA); } }
inline void calibration_status_store(uint8_t status) {
eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS, status);
}
inline bool calibration_status_pinda() {
return eeprom_read_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA);
}
#endif//CONFIG_STORE_H #endif//CONFIG_STORE_H

View File

@ -6,7 +6,7 @@
//=========================================================================== //===========================================================================
#ifdef BED_LIMIT_SWITCHING #ifdef BED_LIMIT_SWITCHING
#define BED_HYSTERESIS 2 //only disable heating if T>target+BED_HYSTERESIS and enable heating if T>target-BED_HYSTERESIS #define BED_HYSTERESIS 2 //only disable heating if T>target+BED_HYSTERESIS and enable heating if T>target-BED_HYSTERESIS
#endif #endif
#define BED_CHECK_INTERVAL 5000 //ms between checks in bang-bang control #define BED_CHECK_INTERVAL 5000 //ms between checks in bang-bang control
@ -19,12 +19,12 @@
//#define WATCH_TEMP_INCREASE 10 //Heat up at least 10 degree in 20 seconds //#define WATCH_TEMP_INCREASE 10 //Heat up at least 10 degree in 20 seconds
#ifdef PIDTEMP #ifdef PIDTEMP
// this adds an experimental additional term to the heating power, proportional to the extrusion speed. // this adds an experimental additional term to the heating power, proportional to the extrusion speed.
// if Kc is chosen well, the additional required power due to increased melting should be compensated. // if Kc is chosen well, the additional required power due to increased melting should be compensated.
#define PID_ADD_EXTRUSION_RATE #define PID_ADD_EXTRUSION_RATE
#ifdef PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE
#define DEFAULT_Kc (1) //heating power=Kc*(e_speed) #define DEFAULT_Kc (1) //heating power=Kc*(e_speed)
#endif #endif
#endif #endif
@ -37,7 +37,7 @@
// on an Ultimaker, some initial testing worked with M109 S215 B260 F1 in the start.gcode // on an Ultimaker, some initial testing worked with M109 S215 B260 F1 in the start.gcode
//#define AUTOTEMP //#define AUTOTEMP
#ifdef AUTOTEMP #ifdef AUTOTEMP
#define AUTOTEMP_OLDWEIGHT 0.98 #define AUTOTEMP_OLDWEIGHT 0.98
#endif #endif
//Show Temperature ADC value //Show Temperature ADC value
@ -83,46 +83,46 @@
//// AUTOSET LOCATIONS OF LIMIT SWITCHES //// AUTOSET LOCATIONS OF LIMIT SWITCHES
//// Added by ZetaPhoenix 09-15-2012 //// Added by ZetaPhoenix 09-15-2012
#ifdef MANUAL_HOME_POSITIONS // Use manual limit switch locations #ifdef MANUAL_HOME_POSITIONS // Use manual limit switch locations
#define X_HOME_POS MANUAL_X_HOME_POS #define X_HOME_POS MANUAL_X_HOME_POS
#define Y_HOME_POS MANUAL_Y_HOME_POS #define Y_HOME_POS MANUAL_Y_HOME_POS
#define Z_HOME_POS MANUAL_Z_HOME_POS #define Z_HOME_POS MANUAL_Z_HOME_POS
#else //Set min/max homing switch positions based upon homing direction and min/max travel limits #else //Set min/max homing switch positions based upon homing direction and min/max travel limits
//X axis //X axis
#if X_HOME_DIR == -1 #if X_HOME_DIR == -1
#ifdef BED_CENTER_AT_0_0 #ifdef BED_CENTER_AT_0_0
#define X_HOME_POS X_MAX_LENGTH * -0.5 #define X_HOME_POS X_MAX_LENGTH * -0.5
#else #else
#define X_HOME_POS X_MIN_POS #define X_HOME_POS X_MIN_POS
#endif //BED_CENTER_AT_0_0 #endif //BED_CENTER_AT_0_0
#else #else
#ifdef BED_CENTER_AT_0_0 #ifdef BED_CENTER_AT_0_0
#define X_HOME_POS X_MAX_LENGTH * 0.5 #define X_HOME_POS X_MAX_LENGTH * 0.5
#else #else
#define X_HOME_POS X_MAX_POS #define X_HOME_POS X_MAX_POS
#endif //BED_CENTER_AT_0_0 #endif //BED_CENTER_AT_0_0
#endif //X_HOME_DIR == -1 #endif //X_HOME_DIR == -1
//Y axis //Y axis
#if Y_HOME_DIR == -1 #if Y_HOME_DIR == -1
#ifdef BED_CENTER_AT_0_0 #ifdef BED_CENTER_AT_0_0
#define Y_HOME_POS Y_MAX_LENGTH * -0.5 #define Y_HOME_POS Y_MAX_LENGTH * -0.5
#else #else
#define Y_HOME_POS Y_MIN_POS #define Y_HOME_POS Y_MIN_POS
#endif //BED_CENTER_AT_0_0 #endif //BED_CENTER_AT_0_0
#else #else
#ifdef BED_CENTER_AT_0_0 #ifdef BED_CENTER_AT_0_0
#define Y_HOME_POS Y_MAX_LENGTH * 0.5 #define Y_HOME_POS Y_MAX_LENGTH * 0.5
#else #else
#define Y_HOME_POS Y_MAX_POS #define Y_HOME_POS Y_MAX_POS
#endif //BED_CENTER_AT_0_0 #endif //BED_CENTER_AT_0_0
#endif //Y_HOME_DIR == -1 #endif //Y_HOME_DIR == -1
// Z axis // Z axis
#if Z_HOME_DIR == -1 //BED_CENTER_AT_0_0 not used #if Z_HOME_DIR == -1 //BED_CENTER_AT_0_0 not used
#define Z_HOME_POS Z_MIN_POS #define Z_HOME_POS Z_MIN_POS
#else #else
#define Z_HOME_POS Z_MAX_POS #define Z_HOME_POS Z_MAX_POS
#endif //Z_HOME_DIR == -1 #endif //Z_HOME_DIR == -1
#endif //End auto min/max positions #endif //End auto min/max positions
//END AUTOSET LOCATIONS OF LIMIT SWITCHES -ZP //END AUTOSET LOCATIONS OF LIMIT SWITCHES -ZP
@ -135,8 +135,8 @@
//#define Z_DUAL_STEPPER_DRIVERS //#define Z_DUAL_STEPPER_DRIVERS
#ifdef Z_DUAL_STEPPER_DRIVERS #ifdef Z_DUAL_STEPPER_DRIVERS
#undef EXTRUDERS #undef EXTRUDERS
#define EXTRUDERS 1 #define EXTRUDERS 1
#endif #endif
// Same again but for Y Axis. // Same again but for Y Axis.
@ -146,12 +146,12 @@
#define INVERT_Y2_VS_Y_DIR 1 #define INVERT_Y2_VS_Y_DIR 1
#ifdef Y_DUAL_STEPPER_DRIVERS #ifdef Y_DUAL_STEPPER_DRIVERS
#undef EXTRUDERS #undef EXTRUDERS
#define EXTRUDERS 1 #define EXTRUDERS 1
#endif #endif
#if defined (Z_DUAL_STEPPER_DRIVERS) && defined (Y_DUAL_STEPPER_DRIVERS) #if defined (Z_DUAL_STEPPER_DRIVERS) && defined (Y_DUAL_STEPPER_DRIVERS)
#error "You cannot have dual drivers for both Y and Z" #error "You cannot have dual drivers for both Y and Z"
#endif #endif
//homing hits the endstop, then retracts by this distance, before it tries to slowly bump again: //homing hits the endstop, then retracts by this distance, before it tries to slowly bump again:
@ -235,28 +235,28 @@
* - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!) * - SDSORT_CACHE_NAMES will retain the sorted file listing in RAM. (Expensive!)
* - SDSORT_DYNAMIC_RAM only uses RAM when the SD menu is visible. (Use with caution!) * - SDSORT_DYNAMIC_RAM only uses RAM when the SD menu is visible. (Use with caution!)
*/ */
#define SDCARD_SORT_ALPHA //Alphabetical sorting of SD files menu #define SDCARD_SORT_ALPHA //Alphabetical sorting of SD files menu
// SD Card Sorting options // SD Card Sorting options
// In current firmware Prusa Firmware version, // In current firmware Prusa Firmware version,
// SDSORT_CACHE_NAMES and SDSORT_DYNAMIC_RAM is not supported and must be set to 0. // SDSORT_CACHE_NAMES and SDSORT_DYNAMIC_RAM is not supported and must be set to 0.
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
#define SD_SORT_TIME 0 #define SD_SORT_TIME 0
#define SD_SORT_ALPHA 1 #define SD_SORT_ALPHA 1
#define SD_SORT_NONE 2 #define SD_SORT_NONE 2
#define SDSORT_LIMIT 100 // Maximum number of sorted items (10-256). #define SDSORT_LIMIT 100 // Maximum number of sorted items (10-256).
#define FOLDER_SORTING -1 // -1=above 0=none 1=below #define FOLDER_SORTING -1 // -1=above 0=none 1=below
#define SDSORT_GCODE 0 // Allow turning sorting on/off with LCD and M34 g-code. #define SDSORT_GCODE 0 // Allow turning sorting on/off with LCD and M34 g-code.
#define SDSORT_USES_RAM 0 // Pre-allocate a static array for faster pre-sorting. #define SDSORT_USES_RAM 0 // Pre-allocate a static array for faster pre-sorting.
#define SDSORT_USES_STACK 0 // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.) #define SDSORT_USES_STACK 0 // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
#define SDSORT_CACHE_NAMES 0 // Keep sorted items in RAM longer for speedy performance. Most expensive option. #define SDSORT_CACHE_NAMES 0 // Keep sorted items in RAM longer for speedy performance. Most expensive option.
#define SDSORT_DYNAMIC_RAM 0 // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use! #define SDSORT_DYNAMIC_RAM 0 // Use dynamic allocation (within SD menus). Least expensive option. Set SDSORT_LIMIT before use!
#endif #endif
#if defined(SDCARD_SORT_ALPHA) #if defined(SDCARD_SORT_ALPHA)
#define HAS_FOLDER_SORTING (FOLDER_SORTING || SDSORT_GCODE) #define HAS_FOLDER_SORTING (FOLDER_SORTING || SDSORT_GCODE)
#endif #endif
// Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled. // Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled.
//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED //#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
@ -266,13 +266,13 @@
// does not respect endstops! // does not respect endstops!
#define BABYSTEPPING #define BABYSTEPPING
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
#define BABYSTEP_XY //not only z, but also XY in the menu. more clutter, more functions #define BABYSTEP_XY //not only z, but also XY in the menu. more clutter, more functions
#define BABYSTEP_INVERT_Z 0 //1 for inverse movements in Z #define BABYSTEP_INVERT_Z 0 //1 for inverse movements in Z
#define BABYSTEP_Z_MULTIPLICATOR 2 //faster z movements #define BABYSTEP_Z_MULTIPLICATOR 2 //faster z movements
#ifdef COREXY #ifdef COREXY
#error BABYSTEPPING not implemented for COREXY yet. #error BABYSTEPPING not implemented for COREXY yet.
#endif #endif
#endif #endif
/** /**
@ -285,9 +285,9 @@
#define LIN_ADVANCE #define LIN_ADVANCE
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
#define LIN_ADVANCE_K 0 //Try around 45 for PLA, around 25 for ABS. #define LIN_ADVANCE_K 0 //Try around 45 for PLA, around 25 for ABS.
/** /**
* Some Slicers produce Gcode with randomly jumping extrusion widths occasionally. * Some Slicers produce Gcode with randomly jumping extrusion widths occasionally.
* For example within a 0.4mm perimeter it may produce a single segment of 0.05mm width. * For example within a 0.4mm perimeter it may produce a single segment of 0.05mm width.
* While this is harmless for normal printing (the fluid nature of the filament will * While this is harmless for normal printing (the fluid nature of the filament will
@ -312,7 +312,7 @@
* Cura (as of this writing) may produce Gcode incompatible with the automatic mode. * Cura (as of this writing) may produce Gcode incompatible with the automatic mode.
*/ */
#define LIN_ADVANCE_E_D_RATIO 0 // The calculated ratio (or 0) according to the formula W * H / ((D / 2) ^ 2 * PI) #define LIN_ADVANCE_E_D_RATIO 0 // The calculated ratio (or 0) according to the formula W * H / ((D / 2) ^ 2 * PI)
// Example: 0.4 * 0.2 / ((1.75 / 2) ^ 2 * PI) = 0.033260135 // Example: 0.4 * 0.2 / ((1.75 / 2) ^ 2 * PI) = 0.033260135
#endif #endif
// Arc interpretation settings: // Arc interpretation settings:
@ -331,17 +331,17 @@ const unsigned int dropsegments=5; //everything with less than this number of st
// Power Signal Control Definitions // Power Signal Control Definitions
// By default use ATX definition // By default use ATX definition
#ifndef POWER_SUPPLY #ifndef POWER_SUPPLY
#define POWER_SUPPLY 1 #define POWER_SUPPLY 1
#endif #endif
// 1 = ATX // 1 = ATX
#if (POWER_SUPPLY == 1) #if (POWER_SUPPLY == 1)
#define PS_ON_AWAKE LOW #define PS_ON_AWAKE LOW
#define PS_ON_ASLEEP HIGH #define PS_ON_ASLEEP HIGH
#endif #endif
// 2 = X-Box 360 203W // 2 = X-Box 360 203W
#if (POWER_SUPPLY == 2) #if (POWER_SUPPLY == 2)
#define PS_ON_AWAKE HIGH #define PS_ON_AWAKE HIGH
#define PS_ON_ASLEEP LOW #define PS_ON_ASLEEP LOW
#endif #endif
// Control heater 0 and heater 1 in parallel. // Control heater 0 and heater 1 in parallel.
@ -354,9 +354,9 @@ const unsigned int dropsegments=5; //everything with less than this number of st
// The number of linear motions that can be in the plan at any give time. // The number of linear motions that can be in the plan at any give time.
// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, i.g. 8,16,32 because shifts and ors are used to do the ring-buffering. // THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, i.g. 8,16,32 because shifts and ors are used to do the ring-buffering.
#if defined SDSUPPORT #if defined SDSUPPORT
#define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller #define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller
#else #else
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer #define BLOCK_BUFFER_SIZE 16 // maximize block buffer
#endif #endif
@ -377,23 +377,23 @@ const unsigned int dropsegments=5; //everything with less than this number of st
#define FWRETRACT //ONLY PARTIALLY TESTED #define FWRETRACT //ONLY PARTIALLY TESTED
#ifdef FWRETRACT #ifdef FWRETRACT
#define MIN_RETRACT 0.1 //minimum extruded mm to accept a automatic gcode retraction attempt #define MIN_RETRACT 0.1 //minimum extruded mm to accept a automatic gcode retraction attempt
#define RETRACT_LENGTH 3 //default retract length (positive mm) #define RETRACT_LENGTH 3 //default retract length (positive mm)
#define RETRACT_LENGTH_SWAP 13 //default swap retract length (positive mm), for extruder change #define RETRACT_LENGTH_SWAP 13 //default swap retract length (positive mm), for extruder change
#define RETRACT_FEEDRATE 45 //default feedrate for retracting (mm/s) #define RETRACT_FEEDRATE 45 //default feedrate for retracting (mm/s)
#define RETRACT_ZLIFT 0 //default retract Z-lift #define RETRACT_ZLIFT 0 //default retract Z-lift
#define RETRACT_RECOVER_LENGTH 0 //default additional recover length (mm, added to retract length when recovering) #define RETRACT_RECOVER_LENGTH 0 //default additional recover length (mm, added to retract length when recovering)
#define RETRACT_RECOVER_LENGTH_SWAP 0 //default additional swap recover length (mm, added to retract length when recovering from extruder change) #define RETRACT_RECOVER_LENGTH_SWAP 0 //default additional swap recover length (mm, added to retract length when recovering from extruder change)
#define RETRACT_RECOVER_FEEDRATE 8 //default feedrate for recovering from retraction (mm/s) #define RETRACT_RECOVER_FEEDRATE 8 //default feedrate for recovering from retraction (mm/s)
#endif #endif
//adds support for experimental filament exchange support M600; requires display //adds support for experimental filament exchange support M600; requires display
#ifdef FILAMENTCHANGEENABLE #ifdef FILAMENTCHANGEENABLE
#ifdef EXTRUDER_RUNOUT_PREVENT #ifdef EXTRUDER_RUNOUT_PREVENT
#error EXTRUDER_RUNOUT_PREVENT currently incompatible with FILAMENTCHANGE #error EXTRUDER_RUNOUT_PREVENT currently incompatible with FILAMENTCHANGE
#endif #endif
#endif #endif
//=========================================================================== //===========================================================================
@ -401,65 +401,65 @@ const unsigned int dropsegments=5; //everything with less than this number of st
//=========================================================================== //===========================================================================
#if EXTRUDERS > 1 && defined TEMP_SENSOR_1_AS_REDUNDANT #if EXTRUDERS > 1 && defined TEMP_SENSOR_1_AS_REDUNDANT
#error "You cannot use TEMP_SENSOR_1_AS_REDUNDANT if EXTRUDERS > 1" #error "You cannot use TEMP_SENSOR_1_AS_REDUNDANT if EXTRUDERS > 1"
#endif #endif
#if EXTRUDERS > 1 && defined HEATERS_PARALLEL #if EXTRUDERS > 1 && defined HEATERS_PARALLEL
#error "You cannot use HEATERS_PARALLEL if EXTRUDERS > 1" #error "You cannot use HEATERS_PARALLEL if EXTRUDERS > 1"
#endif #endif
#if TEMP_SENSOR_0 > 0 #if TEMP_SENSOR_0 > 0
#define THERMISTORHEATER_0 TEMP_SENSOR_0 #define THERMISTORHEATER_0 TEMP_SENSOR_0
#define HEATER_0_USES_THERMISTOR #define HEATER_0_USES_THERMISTOR
#endif #endif
#if TEMP_SENSOR_1 > 0 #if TEMP_SENSOR_1 > 0
#define THERMISTORHEATER_1 TEMP_SENSOR_1 #define THERMISTORHEATER_1 TEMP_SENSOR_1
#define HEATER_1_USES_THERMISTOR #define HEATER_1_USES_THERMISTOR
#endif #endif
#if TEMP_SENSOR_2 > 0 #if TEMP_SENSOR_2 > 0
#define THERMISTORHEATER_2 TEMP_SENSOR_2 #define THERMISTORHEATER_2 TEMP_SENSOR_2
#define HEATER_2_USES_THERMISTOR #define HEATER_2_USES_THERMISTOR
#endif #endif
#if TEMP_SENSOR_BED > 0 #if TEMP_SENSOR_BED > 0
#define THERMISTORBED TEMP_SENSOR_BED #define THERMISTORBED TEMP_SENSOR_BED
#define BED_USES_THERMISTOR #define BED_USES_THERMISTOR
#endif #endif
#if TEMP_SENSOR_PINDA > 0 #if TEMP_SENSOR_PINDA > 0
#define THERMISTORPINDA TEMP_SENSOR_PINDA #define THERMISTORPINDA TEMP_SENSOR_PINDA
#endif #endif
#if TEMP_SENSOR_AMBIENT > 0 #if TEMP_SENSOR_AMBIENT > 0
#define THERMISTORAMBIENT TEMP_SENSOR_AMBIENT #define THERMISTORAMBIENT TEMP_SENSOR_AMBIENT
#endif #endif
#if TEMP_SENSOR_0 == -1 #if TEMP_SENSOR_0 == -1
#define HEATER_0_USES_AD595 #define HEATER_0_USES_AD595
#endif #endif
#if TEMP_SENSOR_1 == -1 #if TEMP_SENSOR_1 == -1
#define HEATER_1_USES_AD595 #define HEATER_1_USES_AD595
#endif #endif
#if TEMP_SENSOR_2 == -1 #if TEMP_SENSOR_2 == -1
#define HEATER_2_USES_AD595 #define HEATER_2_USES_AD595
#endif #endif
#if TEMP_SENSOR_BED == -1 #if TEMP_SENSOR_BED == -1
#define BED_USES_AD595 #define BED_USES_AD595
#endif #endif
#if TEMP_SENSOR_0 == -2 #if TEMP_SENSOR_0 == -2
#define HEATER_0_USES_MAX6675 #define HEATER_0_USES_MAX6675
#endif #endif
#if TEMP_SENSOR_0 == 0 #if TEMP_SENSOR_0 == 0
#undef HEATER_0_MINTEMP #undef HEATER_0_MINTEMP
#undef HEATER_0_MAXTEMP #undef HEATER_0_MAXTEMP
#endif #endif
#if TEMP_SENSOR_1 == 0 #if TEMP_SENSOR_1 == 0
#undef HEATER_1_MINTEMP #undef HEATER_1_MINTEMP
#undef HEATER_1_MAXTEMP #undef HEATER_1_MAXTEMP
#endif #endif
#if TEMP_SENSOR_2 == 0 #if TEMP_SENSOR_2 == 0
#undef HEATER_2_MINTEMP #undef HEATER_2_MINTEMP
#undef HEATER_2_MAXTEMP #undef HEATER_2_MAXTEMP
#endif #endif
#if TEMP_SENSOR_BED == 0 #if TEMP_SENSOR_BED == 0
#undef BED_MINTEMP #undef BED_MINTEMP
#undef BED_MAXTEMP #undef BED_MAXTEMP
#endif #endif

View File

@ -81,9 +81,15 @@ void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperl
uint8_t data = 0; uint8_t data = 0;
switch (type) switch (type)
{ {
case 0: data = *((uint8_t*)address++); break; case 0:
case 1: data = eeprom_read_byte((uint8_t*)address++); break; data = *((uint8_t*)address++);
case 2: data = pgm_read_byte_far((uint8_t*)address++); break; break;
case 1:
data = eeprom_read_byte((uint8_t*)address++);
break;
case 2:
data = pgm_read_byte_far((uint8_t*)address++);
break;
} }
putchar(' '); putchar(' ');
print_hex_byte(data); print_hex_byte(data);
@ -123,7 +129,7 @@ void dcode_3()
count = 0; count = 0;
} }
print_mem(address, count, 1); print_mem(address, count, 1);
/* while (count) /* while (count)
{ {
print_hex_word(address); print_hex_word(address);
putchar(' '); putchar(' ');
@ -235,7 +241,7 @@ void dcode_2()
count = 0; count = 0;
} }
print_mem(address, count, 0); print_mem(address, count, 0);
/* while (count) /* while (count)
{ {
print_hex_word(address); print_hex_word(address);
putchar(' '); putchar(' ');
@ -355,7 +361,7 @@ void dcode_6()
void dcode_7() void dcode_7()
{ {
LOG("D7 - Read/Write Bootloader\n"); LOG("D7 - Read/Write Bootloader\n");
/* /*
cli(); cli();
boot_app_magic = 0x55aa55aa; boot_app_magic = 0x55aa55aa;
boot_app_flags = BOOT_APP_FLG_ERASE | BOOT_APP_FLG_COPY | BOOT_APP_FLG_FLASH; boot_app_flags = BOOT_APP_FLG_ERASE | BOOT_APP_FLG_COPY | BOOT_APP_FLG_FLASH;
@ -364,7 +370,7 @@ void dcode_7()
boot_dst_addr = (uint32_t)0x0003f400; boot_dst_addr = (uint32_t)0x0003f400;
wdt_enable(WDTO_15MS); wdt_enable(WDTO_15MS);
while(1); while(1);
*/ */
} }
void dcode_8() void dcode_8()
@ -412,13 +418,20 @@ const char* dcode_9_ADC_name(uint8_t i)
{ {
switch (i) switch (i)
{ {
case 0: return PSTR("TEMP_HEATER0"); case 0:
case 1: return PSTR("TEMP_HEATER1"); return PSTR("TEMP_HEATER0");
case 2: return PSTR("TEMP_BED"); case 1:
case 3: return PSTR("TEMP_PINDA"); return PSTR("TEMP_HEATER1");
case 4: return PSTR("VOLT_PWR"); case 2:
case 5: return PSTR("TEMP_AMBIENT"); return PSTR("TEMP_BED");
case 6: return PSTR("VOLT_BED"); case 3:
return PSTR("TEMP_PINDA");
case 4:
return PSTR("VOLT_PWR");
case 5:
return PSTR("TEMP_AMBIENT");
case 6:
return PSTR("VOLT_BED");
} }
return 0; return 0;
} }
@ -443,18 +456,25 @@ uint16_t dcode_9_ADC_val(uint8_t i)
{ {
switch (i) switch (i)
{ {
case 0: return current_temperature_raw[0]; case 0:
case 1: return 0; return current_temperature_raw[0];
case 2: return current_temperature_bed_raw; case 1:
case 3: return current_temperature_raw_pinda; return 0;
case 2:
return current_temperature_bed_raw;
case 3:
return current_temperature_raw_pinda;
#ifdef VOLT_PWR_PIN #ifdef VOLT_PWR_PIN
case 4: return current_voltage_raw_pwr; case 4:
return current_voltage_raw_pwr;
#endif //VOLT_PWR_PIN #endif //VOLT_PWR_PIN
#ifdef AMBIENT_THERMISTOR #ifdef AMBIENT_THERMISTOR
case 5: return current_temperature_raw_ambient; case 5:
return current_temperature_raw_ambient;
#endif //AMBIENT_THERMISTOR #endif //AMBIENT_THERMISTOR
#ifdef VOLT_BED_PIN #ifdef VOLT_BED_PIN
case 6: return current_voltage_raw_bed; case 6:
return current_voltage_raw_bed;
#endif //VOLT_BED_PIN #endif //VOLT_BED_PIN
} }
return 0; return 0;
@ -486,13 +506,13 @@ void dcode_9()
} }
void dcode_10() void dcode_10()
{//Tell the printer that XYZ calibration went OK { //Tell the printer that XYZ calibration went OK
LOG("D10 - XYZ calibration = OK\n"); LOG("D10 - XYZ calibration = OK\n");
calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST); calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
} }
void dcode_12() void dcode_12()
{//Time { //Time
LOG("D12 - Time\n"); LOG("D12 - Time\n");
} }
@ -540,16 +560,28 @@ void dcode_2130()
uint8_t axis = 0xff; uint8_t axis = 0xff;
switch (strchr_pointer[1+4]) switch (strchr_pointer[1+4])
{ {
case 'X': axis = X_AXIS; break; case 'X':
case 'Y': axis = Y_AXIS; break; axis = X_AXIS;
case 'Z': axis = Z_AXIS; break; break;
case 'E': axis = E_AXIS; break; case 'Y':
axis = Y_AXIS;
break;
case 'Z':
axis = Z_AXIS;
break;
case 'E':
axis = E_AXIS;
break;
} }
if (axis != 0xff) if (axis != 0xff)
{ {
char ch_axis = strchr_pointer[1+4]; char ch_axis = strchr_pointer[1+4];
if (strchr_pointer[1+5] == '0') { tmc2130_set_pwr(axis, 0); } if (strchr_pointer[1+5] == '0') {
else if (strchr_pointer[1+5] == '1') { tmc2130_set_pwr(axis, 1); } tmc2130_set_pwr(axis, 0);
}
else if (strchr_pointer[1+5] == '1') {
tmc2130_set_pwr(axis, 1);
}
else if (strchr_pointer[1+5] == '+') else if (strchr_pointer[1+5] == '+')
{ {
if (strchr_pointer[1+6] == 0) if (strchr_pointer[1+6] == 0)
@ -651,13 +683,13 @@ void dcode_9125()
printf("x=%d y=%d b=%d s=%d\n", pat9125_x, pat9125_y, pat9125_b, pat9125_s); printf("x=%d y=%d b=%d s=%d\n", pat9125_x, pat9125_y, pat9125_b, pat9125_s);
return; return;
} }
/* /*
if (code_seen('R')) if (code_seen('R'))
{ {
unsigned char res = (int)code_value(); unsigned char res = (int)code_value();
LOG("pat9125_init(xres=yres=%d)=%d\n", res, pat9125_init(res, res)); LOG("pat9125_init(xres=yres=%d)=%d\n", res, pat9125_init(res, res));
} }
*/ */
if (code_seen('X')) if (code_seen('X'))
{ {
pat9125_x = (int)code_value(); pat9125_x = (int)code_value();

View File

@ -54,13 +54,13 @@
//#include "WString.h" //#include "WString.h"
#ifdef AT90USB #ifdef AT90USB
#ifdef BTENABLED #ifdef BTENABLED
#define MYSERIAL bt #define MYSERIAL bt
#else
#define MYSERIAL Serial
#endif // BTENABLED
#else #else
#define MYSERIAL MSerial #define MYSERIAL Serial
#endif // BTENABLED
#else
#define MYSERIAL MSerial
#endif #endif
#include "lcd.h" #include "lcd.h"
@ -129,47 +129,47 @@ void ramming();
void manage_inactivity(bool ignore_stepper_queue=false); void manage_inactivity(bool ignore_stepper_queue=false);
#if defined(X_ENABLE_PIN) && X_ENABLE_PIN > -1 #if defined(X_ENABLE_PIN) && X_ENABLE_PIN > -1
#define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON) #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
#define disable_x() { WRITE(X_ENABLE_PIN,!X_ENABLE_ON); axis_known_position[X_AXIS] = false; } #define disable_x() { WRITE(X_ENABLE_PIN,!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }
#else #else
#define enable_x() ; #define enable_x() ;
#define disable_x() ; #define disable_x() ;
#endif #endif
#if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1 #if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1
#ifdef Y_DUAL_STEPPER_DRIVERS #ifdef Y_DUAL_STEPPER_DRIVERS
#define enable_y() { WRITE(Y_ENABLE_PIN, Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, Y_ENABLE_ON); } #define enable_y() { WRITE(Y_ENABLE_PIN, Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, Y_ENABLE_ON); }
#define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, !Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; } #define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); WRITE(Y2_ENABLE_PIN, !Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
#else
#define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
#define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
#endif
#else #else
#define enable_y() ; #define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
#define disable_y() ; #define disable_y() { WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
#endif
#else
#define enable_y() ;
#define disable_y() ;
#endif #endif
#if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1 #if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
#if defined(Z_AXIS_ALWAYS_ON) #if defined(Z_AXIS_ALWAYS_ON)
#ifdef Z_DUAL_STEPPER_DRIVERS #ifdef Z_DUAL_STEPPER_DRIVERS
#define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); } #define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } #define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
#else
#define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
#define disable_z() {}
#endif
#else
#ifdef Z_DUAL_STEPPER_DRIVERS
#define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
#else
#define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
#endif
#endif
#else #else
#define enable_z() {} #define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
#define disable_z() {} #define disable_z() {}
#endif
#else
#ifdef Z_DUAL_STEPPER_DRIVERS
#define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); }
#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
#else
#define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
#define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
#endif
#endif
#else
#define enable_z() {}
#define disable_z() {}
#endif #endif
@ -190,27 +190,27 @@ void manage_inactivity(bool ignore_stepper_queue=false);
#if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1) #if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
#define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON) #define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON)
#define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON) #define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON)
#else #else
#define enable_e0() /* nothing */ #define enable_e0() /* nothing */
#define disable_e0() /* nothing */ #define disable_e0() /* nothing */
#endif #endif
#if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1) #if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
#define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON) #define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON)
#define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON) #define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON)
#else #else
#define enable_e1() /* nothing */ #define enable_e1() /* nothing */
#define disable_e1() /* nothing */ #define disable_e1() /* nothing */
#endif #endif
#if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1) #if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
#define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON) #define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON)
#define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON) #define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON)
#else #else
#define enable_e2() /* nothing */ #define enable_e2() /* nothing */
#define disable_e2() /* nothing */ #define disable_e2() /* nothing */
#endif #endif
@ -262,15 +262,17 @@ void refresh_cmd_timeout(void);
extern volatile unsigned long timer0_millis; extern volatile unsigned long timer0_millis;
// An unsynchronized equivalent to a standard Arduino millis() function. // An unsynchronized equivalent to a standard Arduino millis() function.
// To be used inside an interrupt routine. // To be used inside an interrupt routine.
FORCE_INLINE unsigned long millis_nc() { return timer0_millis; } FORCE_INLINE unsigned long millis_nc() {
return timer0_millis;
}
#ifdef FAST_PWM_FAN #ifdef FAST_PWM_FAN
void setPwmFrequency(uint8_t pin, int val); void setPwmFrequency(uint8_t pin, int val);
#endif #endif
#ifndef CRITICAL_SECTION_START #ifndef CRITICAL_SECTION_START
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli(); #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
#define CRITICAL_SECTION_END SREG = _sreg; #define CRITICAL_SECTION_END SREG = _sreg;
#endif //CRITICAL_SECTION_START #endif //CRITICAL_SECTION_START
extern float homing_feedrate[]; extern float homing_feedrate[];

View File

@ -31,7 +31,7 @@ uint8_t selectedSerialPort = 0;
#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H) #if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
#if UART_PRESENT(SERIAL_PORT) #if UART_PRESENT(SERIAL_PORT)
ring_buffer rx_buffer = { { 0 }, 0, 0 }; ring_buffer rx_buffer = { { 0 }, 0, 0 };
#endif #endif
FORCE_INLINE void store_char(unsigned char c) FORCE_INLINE void store_char(unsigned char c)
@ -380,6 +380,6 @@ MarlinSerial MSerial;
// For AT90USB targets use the UART for BT interfacing // For AT90USB targets use the UART for BT interfacing
#if defined(AT90USB) && defined (BTENABLED) #if defined(AT90USB) && defined (BTENABLED)
HardwareSerial bt; HardwareSerial bt;
#endif #endif

View File

@ -83,13 +83,13 @@ struct ring_buffer
}; };
#if UART_PRESENT(SERIAL_PORT) #if UART_PRESENT(SERIAL_PORT)
extern ring_buffer rx_buffer; extern ring_buffer rx_buffer;
#endif #endif
class MarlinSerial //: public Stream class MarlinSerial //: public Stream
{ {
public: public:
static void begin(long); static void begin(long);
static void end(); static void end();
static int peek(void); static int peek(void);
@ -177,12 +177,12 @@ class MarlinSerial //: public Stream
} }
private: private:
static void printNumber(unsigned long, uint8_t); static void printNumber(unsigned long, uint8_t);
static void printFloat(double, uint8_t); static void printFloat(double, uint8_t);
public: public:
static FORCE_INLINE void write(const char *str) static FORCE_INLINE void write(const char *str)
{ {
@ -197,7 +197,7 @@ class MarlinSerial //: public Stream
write(*buffer++); write(*buffer++);
} }
/* static FORCE_INLINE void print(const String &s) /* static FORCE_INLINE void print(const String &s)
{ {
for (int i = 0; i < (int)s.length(); i++) { for (int i = 0; i < (int)s.length(); i++) {
write(s[i]); write(s[i]);
@ -233,7 +233,7 @@ extern MarlinSerial MSerial;
// Use the UART for BT in AT90USB configurations // Use the UART for BT in AT90USB configurations
#if defined(AT90USB) && defined (BTENABLED) #if defined(AT90USB) && defined (BTENABLED)
extern HardwareSerial bt; extern HardwareSerial bt;
#endif #endif
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -68,7 +68,7 @@ static void spiSend(uint8_t b) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** SPI send block - only one call so force inline */ /** SPI send block - only one call so force inline */
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t* buf) {
SPDR = token; SPDR = token;
for (uint16_t i = 0; i < 512; i += 2) { for (uint16_t i = 0; i < 512; i += 2) {
while (!(SPSR & (1 << SPIF))) { /* Intentionally left empty */ } while (!(SPSR & (1 << SPIF))) { /* Intentionally left empty */ }
@ -142,7 +142,7 @@ static void spiSend(uint8_t data) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Soft SPI send block */ /** Soft SPI send block */
void spiSendBlock(uint8_t token, const uint8_t* buf) { void spiSendBlock(uint8_t token, const uint8_t* buf) {
spiSend(token); spiSend(token);
for (uint16_t i = 0; i < 512; i++) { for (uint16_t i = 0; i < 512; i++) {
spiSend(buf[i]); spiSend(buf[i]);
@ -258,7 +258,7 @@ bool Sd2Card::erase(uint32_t firstBlock, uint32_t lastBlock) {
chipSelectHigh(); chipSelectHigh();
return true; return true;
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -359,7 +359,7 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
return true; return true;
#endif // SOFTWARE_SPI #endif // SOFTWARE_SPI
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -377,7 +377,7 @@ bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) {
uint8_t retryCnt = 3; uint8_t retryCnt = 3;
// use address if not SDHC card // use address if not SDHC card
if (type()!= SD_CARD_TYPE_SDHC) blockNumber <<= 9; if (type()!= SD_CARD_TYPE_SDHC) blockNumber <<= 9;
retry2: retry2:
retryCnt --; retryCnt --;
if (cardCommand(CMD17, blockNumber)) { if (cardCommand(CMD17, blockNumber)) {
error(SD_CARD_ERROR_CMD17); error(SD_CARD_ERROR_CMD17);
@ -390,7 +390,7 @@ bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) {
goto fail; goto fail;
} }
return true; return true;
retry: retry:
chipSelectHigh(); chipSelectHigh();
cardCommand(CMD12, 0);//Try sending a stop command, but ignore the result. cardCommand(CMD12, 0);//Try sending a stop command, but ignore the result.
errorCode_ = 0; errorCode_ = 0;
@ -405,7 +405,7 @@ bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) {
return readData(dst, 512); return readData(dst, 512);
#endif #endif
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -505,7 +505,7 @@ bool Sd2Card::readData(uint8_t* dst, uint16_t count) {
spiSend(0XFF); spiSend(0XFF);
return true; return true;
fail: fail:
chipSelectHigh(); chipSelectHigh();
// Toshiba FlashAir Patch. Purge pending status byte. // Toshiba FlashAir Patch. Purge pending status byte.
if (flash_air_compatible_) if (flash_air_compatible_)
@ -522,7 +522,7 @@ bool Sd2Card::readRegister(uint8_t cmd, void* buf) {
} }
return readData(dst, 16); return readData(dst, 16);
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -546,7 +546,7 @@ bool Sd2Card::readStart(uint32_t blockNumber) {
chipSelectHigh(); chipSelectHigh();
return true; return true;
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -565,7 +565,7 @@ bool Sd2Card::readStop() {
chipSelectHigh(); chipSelectHigh();
return true; return true;
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -599,7 +599,7 @@ bool Sd2Card::waitNotBusy(uint16_t timeoutMillis) {
} }
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -633,7 +633,7 @@ bool Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
chipSelectHigh(); chipSelectHigh();
return true; return true;
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -651,7 +651,7 @@ bool Sd2Card::writeData(const uint8_t* src) {
chipSelectHigh(); chipSelectHigh();
return true; return true;
fail: fail:
error(SD_CARD_ERROR_WRITE_MULTIPLE); error(SD_CARD_ERROR_WRITE_MULTIPLE);
chipSelectHigh(); chipSelectHigh();
return false; return false;
@ -671,7 +671,7 @@ bool Sd2Card::writeData(uint8_t token, const uint8_t* src) {
} }
return true; return true;
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -702,7 +702,7 @@ bool Sd2Card::writeStart(uint32_t blockNumber, uint32_t eraseCount) {
chipSelectHigh(); chipSelectHigh();
return true; return true;
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -720,7 +720,7 @@ bool Sd2Card::writeStop() {
chipSelectHigh(); chipSelectHigh();
return true; return true;
fail: fail:
error(SD_CARD_ERROR_STOP_TRAN); error(SD_CARD_ERROR_STOP_TRAN);
chipSelectHigh(); chipSelectHigh();
return false; return false;
@ -744,7 +744,7 @@ uint8_t Sd2Card::waitStartBlock(void) {
} }
return true; return true;
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }
@ -782,7 +782,7 @@ uint8_t Sd2Card::readExt(uint32_t arg, uint8_t* dst, uint16_t count) {
spiSend(0xFF); // dummy clock to force FlashAir finish the command. spiSend(0xFF); // dummy clock to force FlashAir finish the command.
return true; return true;
fail: fail:
chipSelectHigh(); chipSelectHigh();
return false; return false;
} }

View File

@ -160,7 +160,7 @@ uint8_t const SPI_SCK_PIN = SOFT_SPI_SCK_PIN;
* \brief Raw access to SD and SDHC flash memory cards. * \brief Raw access to SD and SDHC flash memory cards.
*/ */
class Sd2Card { class Sd2Card {
public: public:
/** Construct an instance of Sd2Card. */ /** Construct an instance of Sd2Card. */
Sd2Card() : errorCode_(SD_CARD_ERROR_INIT_NOT_CALLED), type_(0), flash_air_compatible_(false) {} Sd2Card() : errorCode_(SD_CARD_ERROR_INIT_NOT_CALLED), type_(0), flash_air_compatible_(false) {}
uint32_t cardSize(); uint32_t cardSize();
@ -170,13 +170,19 @@ class Sd2Card {
* Set SD error code. * Set SD error code.
* \param[in] code value for error code. * \param[in] code value for error code.
*/ */
void error(uint8_t code) {errorCode_ = code;} void error(uint8_t code) {
errorCode_ = code;
}
/** /**
* \return error code for last error. See Sd2Card.h for a list of error codes. * \return error code for last error. See Sd2Card.h for a list of error codes.
*/ */
int errorCode() const {return errorCode_;} int errorCode() const {
return errorCode_;
}
/** \return error data for last error. */ /** \return error data for last error. */
int errorData() const {return status_;} int errorData() const {
return status_;
}
/** /**
* Initialize an SD flash memory card with default clock rate and chip * Initialize an SD flash memory card with default clock rate and chip
* select pin. See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin). * select pin. See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).
@ -216,7 +222,9 @@ class Sd2Card {
/** Return the card type: SD V1, SD V2 or SDHC /** Return the card type: SD V1, SD V2 or SDHC
* \return 0 - SD V1, 1 - SD V2, or 3 - SDHC. * \return 0 - SD V1, 1 - SD V2, or 3 - SDHC.
*/ */
int type() const {return type_;} int type() const {
return type_;
}
bool writeBlock(uint32_t blockNumber, const uint8_t* src); bool writeBlock(uint32_t blockNumber, const uint8_t* src);
bool writeData(const uint8_t* src); bool writeData(const uint8_t* src);
bool writeStart(uint32_t blockNumber, uint32_t eraseCount); bool writeStart(uint32_t blockNumber, uint32_t eraseCount);
@ -225,10 +233,14 @@ class Sd2Card {
// Toshiba FlashAir support // Toshiba FlashAir support
uint8_t readExtMemory(uint8_t mio, uint8_t func, uint32_t addr, uint16_t count, uint8_t* dst); uint8_t readExtMemory(uint8_t mio, uint8_t func, uint32_t addr, uint16_t count, uint8_t* dst);
void setFlashAirCompatible(bool flashAirCompatible) { flash_air_compatible_ = flashAirCompatible; } void setFlashAirCompatible(bool flashAirCompatible) {
bool getFlashAirCompatible() const { return flash_air_compatible_; } flash_air_compatible_ = flashAirCompatible;
}
bool getFlashAirCompatible() const {
return flash_air_compatible_;
}
private: private:
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
uint8_t chipSelectPin_; uint8_t chipSelectPin_;
uint8_t errorCode_; uint8_t errorCode_;
@ -247,7 +259,9 @@ class Sd2Card {
bool readRegister(uint8_t cmd, void* buf); bool readRegister(uint8_t cmd, void* buf);
void chipSelectHigh(); void chipSelectHigh();
void chipSelectLow(); void chipSelectLow();
void type(uint8_t value) {type_ = value;} void type(uint8_t value) {
type_ = value;
}
bool waitNotBusy(uint16_t timeoutMillis); bool waitNotBusy(uint16_t timeoutMillis);
bool writeData(uint8_t token, const uint8_t* src); bool writeData(uint8_t token, const uint8_t* src);

View File

@ -320,10 +320,10 @@ static const pin_map_t digitalPinMap[] = {
static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t); static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);
uint8_t badPinNumber(void) uint8_t badPinNumber(void)
__attribute__((error("Pin number is too large or not a constant"))); __attribute__((error("Pin number is too large or not a constant")));
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
bool getPinMode(uint8_t pin) { bool getPinMode(uint8_t pin) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) { if (__builtin_constant_p(pin) && pin < digitalPinCount) {
return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1; return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;
} else { } else {
@ -331,7 +331,7 @@ static inline __attribute__((always_inline))
} }
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void setPinMode(uint8_t pin, uint8_t mode) { void setPinMode(uint8_t pin, uint8_t mode) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) { if (__builtin_constant_p(pin) && pin < digitalPinCount) {
if (mode) { if (mode) {
*digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit; *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;
@ -343,7 +343,7 @@ static inline __attribute__((always_inline))
} }
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
bool fastDigitalRead(uint8_t pin) { bool fastDigitalRead(uint8_t pin) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) { if (__builtin_constant_p(pin) && pin < digitalPinCount) {
return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1; return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;
} else { } else {
@ -351,7 +351,7 @@ static inline __attribute__((always_inline))
} }
} }
static inline __attribute__((always_inline)) static inline __attribute__((always_inline))
void fastDigitalWrite(uint8_t pin, uint8_t value) { void fastDigitalWrite(uint8_t pin, uint8_t value) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) { if (__builtin_constant_p(pin) && pin < digitalPinCount) {
if (value) { if (value) {
*digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit; *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;

View File

@ -39,7 +39,7 @@ bool SdBaseFile::addCluster() {
} }
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -69,7 +69,7 @@ bool SdBaseFile::addDirCluster() {
fileSize_ += 512UL << vol_->clusterSizeShift_; fileSize_ += 512UL << vol_->clusterSizeShift_;
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -79,7 +79,7 @@ dir_t* SdBaseFile::cacheDirEntry(uint8_t action) {
if (!vol_->cacheRawBlock(dirBlock_, action)) goto fail; if (!vol_->cacheRawBlock(dirBlock_, action)) goto fail;
return vol_->cache()->dir + dirIndex_; return vol_->cache()->dir + dirIndex_;
fail: fail:
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -125,7 +125,7 @@ bool SdBaseFile::contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock) {
} }
} }
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -168,7 +168,7 @@ bool SdBaseFile::createContiguous(SdBaseFile* dirFile,
return sync(); return sync();
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -192,7 +192,7 @@ bool SdBaseFile::dirEntry(dir_t* dir) {
memcpy(dir, p, sizeof(dir_t)); memcpy(dir, p, sizeof(dir_t));
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -407,7 +407,7 @@ bool SdBaseFile::make83Name(const char* str, uint8_t* name, const char** ptr) {
// must have a file name, extension is optional // must have a file name, extension is optional
return name[0] != ' '; return name[0] != ' ';
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -455,7 +455,7 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const char* path, bool pFlag) {
} }
return mkdir(parent, dname); return mkdir(parent, dname);
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -513,11 +513,11 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
// write first block // write first block
return vol_->cacheFlush(); return vol_->cacheFlush();
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Open a file in the current working directory. /** Open a file in the current working directory.
* *
* \param[in] path A path with a valid 8.3 DOS name for a file to be opened. * \param[in] path A path with a valid 8.3 DOS name for a file to be opened.
* *
@ -527,9 +527,9 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
* \return The value one, true, is returned for success and * \return The value one, true, is returned for success and
* the value zero, false, is returned for failure. * the value zero, false, is returned for failure.
*/ */
bool SdBaseFile::open(const char* path, uint8_t oflag) { bool SdBaseFile::open(const char* path, uint8_t oflag) {
return open(cwd_, path, oflag); return open(cwd_, path, oflag);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** Open a file or directory by name. /** Open a file or directory by name.
* *
@ -610,7 +610,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, const char* path, uint8_t oflag) {
} }
return open(parent, dname, oflag); return open(parent, dname, oflag);
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -689,7 +689,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile,
// open entry in cache // open entry in cache
return openCachedEntry(index, oflag); return openCachedEntry(index, oflag);
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -732,7 +732,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag) {
// open cached entry // open cached entry
return openCachedEntry(index & 0XF, oflag); return openCachedEntry(index & 0XF, oflag);
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -772,7 +772,7 @@ bool SdBaseFile::openCachedEntry(uint8_t dirIndex, uint8_t oflag) {
if ((oflag & O_TRUNC) && !truncate(0)) return false; if ((oflag & O_TRUNC) && !truncate(0)) return false;
return oflag & O_AT_END ? seekEnd(0) : true; return oflag & O_AT_END ? seekEnd(0) : true;
fail: fail:
type_ = FAT_FILE_TYPE_CLOSED; type_ = FAT_FILE_TYPE_CLOSED;
return false; return false;
} }
@ -819,7 +819,7 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) {
} }
} }
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -874,7 +874,7 @@ bool SdBaseFile::openParent(SdBaseFile* dir) {
// open parent // open parent
return open(&file, file.curPosition()/32 - 1, O_READ); return open(&file, file.curPosition()/32 - 1, O_READ);
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -916,7 +916,7 @@ bool SdBaseFile::openRoot(SdVolume* vol) {
dirIndex_ = 0; dirIndex_ = 0;
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1094,7 +1094,7 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
} }
return nbyte; return nbyte;
fail: fail:
return -1; return -1;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1178,7 +1178,7 @@ dir_t* SdBaseFile::readDirCache() {
// return pointer to entry // return pointer to entry
return vol_->cache()->dir + i; return vol_->cache()->dir + i;
fail: fail:
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1214,7 +1214,7 @@ bool SdBaseFile::remove() {
return vol_->cacheFlush(); return vol_->cacheFlush();
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1240,7 +1240,7 @@ bool SdBaseFile::remove(SdBaseFile* dirFile, const char* path) {
if (!file.open(dirFile, path, O_WRITE)) goto fail; if (!file.open(dirFile, path, O_WRITE)) goto fail;
return file.remove(); return file.remove();
fail: fail:
// can't set iostate - static function // can't set iostate - static function
return false; return false;
} }
@ -1322,14 +1322,14 @@ bool SdBaseFile::rename(SdBaseFile* dirFile, const char* newPath) {
} }
return vol_->cacheFlush(); return vol_->cacheFlush();
restore: restore:
d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE); d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
if (!d) goto fail; if (!d) goto fail;
// restore entry // restore entry
d->name[0] = entry.name[0]; d->name[0] = entry.name[0];
vol_->cacheFlush(); vol_->cacheFlush();
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1370,7 +1370,7 @@ bool SdBaseFile::rmdir() {
flags_ |= O_WRITE; flags_ |= O_WRITE;
return remove(); return remove();
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1429,7 +1429,7 @@ bool SdBaseFile::rmRfStar() {
} }
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1485,10 +1485,10 @@ bool SdBaseFile::seekSet(uint32_t pos) {
} }
curPosition_ = pos; curPosition_ = pos;
done: done:
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1531,7 +1531,7 @@ bool SdBaseFile::sync() {
} }
return vol_->cacheFlush(); return vol_->cacheFlush();
fail: fail:
writeError = true; writeError = true;
return false; return false;
} }
@ -1571,7 +1571,7 @@ bool SdBaseFile::timestamp(SdBaseFile* file) {
// write back entry // write back entry
return vol_->cacheFlush(); return vol_->cacheFlush();
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1649,7 +1649,7 @@ bool SdBaseFile::timestamp(uint8_t flags, uint16_t year, uint8_t month,
} }
return vol_->cacheFlush(); return vol_->cacheFlush();
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1707,7 +1707,7 @@ bool SdBaseFile::truncate(uint32_t length) {
// set file to correct position // set file to correct position
return seekSet(newPos); return seekSet(newPos);
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -1810,7 +1810,7 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
} }
return nbyte; return nbyte;
fail: fail:
// return for write error // return for write error
writeError = true; writeError = true;
return -1; return -1;

View File

@ -180,11 +180,13 @@ uint16_t const FAT_DEFAULT_TIME = (1 << 11);
* \brief Base class for SdFile with Print and C++ streams. * \brief Base class for SdFile with Print and C++ streams.
*/ */
class SdBaseFile { class SdBaseFile {
public: public:
/** Create an instance. */ /** Create an instance. */
SdBaseFile() : writeError(false), type_(FAT_FILE_TYPE_CLOSED) {} SdBaseFile() : writeError(false), type_(FAT_FILE_TYPE_CLOSED) {}
SdBaseFile(const char* path, uint8_t oflag); SdBaseFile(const char* path, uint8_t oflag);
~SdBaseFile() {if(isOpen()) close();} ~SdBaseFile() {
if(isOpen()) close();
}
/** /**
* writeError is set to true if an error occurs during a write(). * writeError is set to true if an error occurs during a write().
* Set writeError to false before calling print() and/or write() and check * Set writeError to false before calling print() and/or write() and check
@ -207,11 +209,17 @@ class SdBaseFile {
bool createContiguous(SdBaseFile* dirFile, bool createContiguous(SdBaseFile* dirFile,
const char* path, uint32_t size); const char* path, uint32_t size);
/** \return The current cluster number for a file or directory. */ /** \return The current cluster number for a file or directory. */
uint32_t curCluster() const {return curCluster_;} uint32_t curCluster() const {
return curCluster_;
}
/** \return The current position for a file or directory. */ /** \return The current position for a file or directory. */
uint32_t curPosition() const {return curPosition_;} uint32_t curPosition() const {
return curPosition_;
}
/** \return Current working directory */ /** \return Current working directory */
static SdBaseFile* cwd() {return cwd_;} static SdBaseFile* cwd() {
return cwd_;
}
/** Set the date/time callback function /** Set the date/time callback function
* *
* \param[in] dateTime The user's call back function. The callback * \param[in] dateTime The user's call back function. The callback
@ -244,24 +252,38 @@ class SdBaseFile {
dateTime_ = dateTime; dateTime_ = dateTime;
} }
/** Cancel the date/time callback function. */ /** Cancel the date/time callback function. */
static void dateTimeCallbackCancel() {dateTime_ = 0;} static void dateTimeCallbackCancel() {
dateTime_ = 0;
}
bool dirEntry(dir_t* dir); bool dirEntry(dir_t* dir);
static void dirName(const dir_t& dir, char* name); static void dirName(const dir_t& dir, char* name);
bool exists(const char* name); bool exists(const char* name);
int16_t fgets(char* str, int16_t num, char* delim = 0); int16_t fgets(char* str, int16_t num, char* delim = 0);
/** \return The total number of bytes in a file or directory. */ /** \return The total number of bytes in a file or directory. */
uint32_t fileSize() const {return fileSize_;} uint32_t fileSize() const {
return fileSize_;
}
/** \return The first cluster number for a file or directory. */ /** \return The first cluster number for a file or directory. */
uint32_t firstCluster() const {return firstCluster_;} uint32_t firstCluster() const {
return firstCluster_;
}
bool getFilename(char* name); bool getFilename(char* name);
/** \return True if this is a directory else false. */ /** \return True if this is a directory else false. */
bool isDir() const {return type_ >= FAT_FILE_TYPE_MIN_DIR;} bool isDir() const {
return type_ >= FAT_FILE_TYPE_MIN_DIR;
}
/** \return True if this is a normal file else false. */ /** \return True if this is a normal file else false. */
bool isFile() const {return type_ == FAT_FILE_TYPE_NORMAL;} bool isFile() const {
return type_ == FAT_FILE_TYPE_NORMAL;
}
/** \return True if this is an open file/directory else false. */ /** \return True if this is an open file/directory else false. */
bool isOpen() const {return type_ != FAT_FILE_TYPE_CLOSED;} bool isOpen() const {
return type_ != FAT_FILE_TYPE_CLOSED;
}
/** \return True if this is a subdirectory else false. */ /** \return True if this is a subdirectory else false. */
bool isSubDir() const {return type_ == FAT_FILE_TYPE_SUBDIR;} bool isSubDir() const {
return type_ == FAT_FILE_TYPE_SUBDIR;
}
/** \return True if this is the root directory. */ /** \return True if this is the root directory. */
bool isRoot() const { bool isRoot() const {
return type_ == FAT_FILE_TYPE_ROOT_FIXED || type_ == FAT_FILE_TYPE_ROOT32; return type_ == FAT_FILE_TYPE_ROOT_FIXED || type_ == FAT_FILE_TYPE_ROOT32;
@ -287,11 +309,15 @@ class SdBaseFile {
static bool remove(SdBaseFile* dirFile, const char* path); static bool remove(SdBaseFile* dirFile, const char* path);
bool remove(); bool remove();
/** Set the file's current position to zero. */ /** Set the file's current position to zero. */
void rewind() {seekSet(0);} void rewind() {
seekSet(0);
}
bool rename(SdBaseFile* dirFile, const char* newPath); bool rename(SdBaseFile* dirFile, const char* newPath);
bool rmdir(); bool rmdir();
// for backward compatibility // for backward compatibility
bool rmDir() {return rmdir();} bool rmDir() {
return rmdir();
}
bool rmRfStar(); bool rmRfStar();
/** Set the files position to current position + \a pos. See seekSet(). /** Set the files position to current position + \a pos. See seekSet().
* \param[in] offset The new position in bytes from the current position. * \param[in] offset The new position in bytes from the current position.
@ -304,7 +330,9 @@ class SdBaseFile {
* \param[in] offset The new position in bytes from end-of-file. * \param[in] offset The new position in bytes from end-of-file.
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool seekEnd(int32_t offset = 0) {return seekSet(fileSize_ + offset);} bool seekEnd(int32_t offset = 0) {
return seekSet(fileSize_ + offset);
}
bool seekSet(uint32_t pos); bool seekSet(uint32_t pos);
bool sync(); bool sync();
bool timestamp(SdBaseFile* file); bool timestamp(SdBaseFile* file);
@ -315,13 +343,17 @@ class SdBaseFile {
* *
* \return The file or directory type. * \return The file or directory type.
*/ */
uint8_t type() const {return type_;} uint8_t type() const {
return type_;
}
bool truncate(uint32_t size); bool truncate(uint32_t size);
/** \return SdVolume that contains this file. */ /** \return SdVolume that contains this file. */
SdVolume* volume() const {return vol_;} SdVolume* volume() const {
return vol_;
}
int16_t write(const void* buf, uint16_t nbyte); int16_t write(const void* buf, uint16_t nbyte);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
private: private:
// allow SdFat to set cwd_ // allow SdFat to set cwd_
friend class SdFat; friend class SdFat;
// global pointer to cwd dir // global pointer to cwd dir
@ -365,7 +397,7 @@ class SdBaseFile {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Deprecated functions - suppress cpplint warnings with NOLINT comment // Deprecated functions - suppress cpplint warnings with NOLINT comment
#if ALLOW_DEPRECATED_FUNCTIONS && !defined(DOXYGEN) #if ALLOW_DEPRECATED_FUNCTIONS && !defined(DOXYGEN)
public: public:
/** \deprecated Use: /** \deprecated Use:
* bool contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock); * bool contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock);
* \param[out] bgnBlock the first block address for the file. * \param[out] bgnBlock the first block address for the file.
@ -401,7 +433,9 @@ class SdBaseFile {
* \param[out] dir Location for return of the file's directory entry. * \param[out] dir Location for return of the file's directory entry.
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool dirEntry(dir_t& dir) {return dirEntry(&dir);} // NOLINT bool dirEntry(dir_t& dir) {
return dirEntry(&dir); // NOLINT
}
/** \deprecated Use: /** \deprecated Use:
* bool mkdir(SdBaseFile* dir, const char* path); * bool mkdir(SdBaseFile* dir, const char* path);
* \param[in] dir An open SdFat instance for the directory that will contain * \param[in] dir An open SdFat instance for the directory that will contain
@ -450,12 +484,16 @@ class SdBaseFile {
* \param[in] vol The FAT volume containing the root directory to be opened. * \param[in] vol The FAT volume containing the root directory to be opened.
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool openRoot(SdVolume& vol) {return openRoot(&vol);} // NOLINT bool openRoot(SdVolume& vol) {
return openRoot(&vol); // NOLINT
}
/** \deprecated Use: int8_t readDir(dir_t* dir); /** \deprecated Use: int8_t readDir(dir_t* dir);
* \param[out] dir The dir_t struct that will receive the data. * \param[out] dir The dir_t struct that will receive the data.
* \return bytes read for success zero for eof or -1 for failure. * \return bytes read for success zero for eof or -1 for failure.
*/ */
int8_t readDir(dir_t& dir, char* longFilename) {return readDir(&dir, longFilename);} // NOLINT int8_t readDir(dir_t& dir, char* longFilename) {
return readDir(&dir, longFilename); // NOLINT
}
/** \deprecated Use: /** \deprecated Use:
* static uint8_t remove(SdBaseFile* dirFile, const char* path); * static uint8_t remove(SdBaseFile* dirFile, const char* path);
* \param[in] dirFile The directory that contains the file. * \param[in] dirFile The directory that contains the file.
@ -467,7 +505,7 @@ class SdBaseFile {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// rest are private // rest are private
private: private:
static void (*oldDateTime_)(uint16_t& date, uint16_t& time); // NOLINT static void (*oldDateTime_)(uint16_t& date, uint16_t& time); // NOLINT
static void oldToNew(uint16_t* date, uint16_t* time) { static void oldToNew(uint16_t* date, uint16_t* time) {
uint16_t d; uint16_t d;

View File

@ -34,14 +34,14 @@
#define PgmPrintln(x) SerialPrintln_P(PSTR(x)) #define PgmPrintln(x) SerialPrintln_P(PSTR(x))
namespace SdFatUtil { namespace SdFatUtil {
int FreeRam(); int FreeRam();
void print_P( PGM_P str); void print_P( PGM_P str);
void println_P( PGM_P str); void println_P( PGM_P str);
void SerialPrint_P(PGM_P str); void SerialPrint_P(PGM_P str);
void SerialPrintln_P(PGM_P str); void SerialPrintln_P(PGM_P str);
void set_stack_guard(); void set_stack_guard();
bool test_stack_integrity(); bool test_stack_integrity();
uint32_t get_stack_guard_test_value(); uint32_t get_stack_guard_test_value();
} }
using namespace SdFatUtil; // NOLINT using namespace SdFatUtil; // NOLINT

View File

@ -33,15 +33,15 @@
* \class SdFile * \class SdFile
* \brief SdBaseFile with Print. * \brief SdBaseFile with Print.
*/ */
class SdFile : public SdBaseFile/*, public Print*/ { class SdFile : public SdBaseFile { /*, public Print*/
public: public:
SdFile() {} SdFile() {}
SdFile(const char* name, uint8_t oflag); SdFile(const char* name, uint8_t oflag);
#if ARDUINO >= 100 #if ARDUINO >= 100
size_t write(uint8_t b); size_t write(uint8_t b);
#else #else
void write(uint8_t b); void write(uint8_t b);
#endif #endif
int16_t write(const void* buf, uint16_t nbyte); int16_t write(const void* buf, uint16_t nbyte);
void write(const char* str); void write(const char* str);

View File

@ -130,7 +130,7 @@ typedef struct CID {
unsigned char always1 : 1; unsigned char always1 : 1;
/** CRC7 checksum */ /** CRC7 checksum */
unsigned char crc : 7; unsigned char crc : 7;
}cid_t; } cid_t;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** CSD for version 1.00 cards */ /** CSD for version 1.00 cards */
typedef struct CSDV1 { typedef struct CSDV1 {
@ -192,7 +192,7 @@ typedef struct CSDV1 {
// byte 15 // byte 15
unsigned char always1 : 1; unsigned char always1 : 1;
unsigned char crc : 7; unsigned char crc : 7;
}csd1_t; } csd1_t;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** CSD for version 2.00 cards */ /** CSD for version 2.00 cards */
typedef struct CSDV2 { typedef struct CSDV2 {
@ -274,7 +274,7 @@ typedef struct CSDV2 {
unsigned char always1 : 1; unsigned char always1 : 1;
/** checksum */ /** checksum */
unsigned char crc : 7; unsigned char crc : 7;
}csd2_t; } csd2_t;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** union of old and new style CSD register */ /** union of old and new style CSD register */
union csd_t { union csd_t {

View File

@ -100,7 +100,7 @@ bool SdVolume::allocContiguous(uint32_t count, uint32_t* curCluster) {
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -120,7 +120,7 @@ bool SdVolume::cacheFlush() {
} }
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -133,7 +133,7 @@ bool SdVolume::cacheRawBlock(uint32_t blockNumber, bool dirty) {
if (dirty) cacheDirty_ = true; if (dirty) cacheDirty_ = true;
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -147,7 +147,7 @@ bool SdVolume::chainSize(uint32_t cluster, uint32_t* size) {
*size = s; *size = s;
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -188,7 +188,7 @@ bool SdVolume::fatGet(uint32_t cluster, uint32_t* value) {
} }
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -247,7 +247,7 @@ bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_; if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -269,7 +269,7 @@ bool SdVolume::freeChain(uint32_t cluster) {
return true; return true;
fail: fail:
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -399,7 +399,7 @@ bool SdVolume::init(Sd2Card* dev, uint8_t part) {
} }
return true; return true;
fail: fail:
return false; return false;
} }
#endif #endif

View File

@ -58,7 +58,7 @@ union cache_t {
* \brief Access FAT16 and FAT32 volumes on SD and SDHC cards. * \brief Access FAT16 and FAT32 volumes on SD and SDHC cards.
*/ */
class SdVolume { class SdVolume {
public: public:
/** Create an instance of SdVolume */ /** Create an instance of SdVolume */
SdVolume() : fatType_(0) {} SdVolume() : fatType_(0) {}
/** Clear the cache and returns a pointer to the cache. Used by the WaveRP /** Clear the cache and returns a pointer to the cache. Used by the WaveRP
@ -80,45 +80,71 @@ class SdVolume {
* failure include not finding a valid partition, not finding a valid * failure include not finding a valid partition, not finding a valid
* FAT file system or an I/O error. * FAT file system or an I/O error.
*/ */
bool init(Sd2Card* dev) { return init(dev, 1) ? true : init(dev, 0);} bool init(Sd2Card* dev) {
return init(dev, 1) ? true : init(dev, 0);
}
bool init(Sd2Card* dev, uint8_t part); bool init(Sd2Card* dev, uint8_t part);
// inline functions that return volume info // inline functions that return volume info
/** \return The volume's cluster size in blocks. */ /** \return The volume's cluster size in blocks. */
uint8_t blocksPerCluster() const {return blocksPerCluster_;} uint8_t blocksPerCluster() const {
return blocksPerCluster_;
}
/** \return The number of blocks in one FAT. */ /** \return The number of blocks in one FAT. */
uint32_t blocksPerFat() const {return blocksPerFat_;} uint32_t blocksPerFat() const {
return blocksPerFat_;
}
/** \return The total number of clusters in the volume. */ /** \return The total number of clusters in the volume. */
uint32_t clusterCount() const {return clusterCount_;} uint32_t clusterCount() const {
return clusterCount_;
}
/** \return The shift count required to multiply by blocksPerCluster. */ /** \return The shift count required to multiply by blocksPerCluster. */
uint8_t clusterSizeShift() const {return clusterSizeShift_;} uint8_t clusterSizeShift() const {
return clusterSizeShift_;
}
/** \return The logical block number for the start of file data. */ /** \return The logical block number for the start of file data. */
uint32_t dataStartBlock() const {return dataStartBlock_;} uint32_t dataStartBlock() const {
return dataStartBlock_;
}
/** \return The number of FAT structures on the volume. */ /** \return The number of FAT structures on the volume. */
uint8_t fatCount() const {return fatCount_;} uint8_t fatCount() const {
return fatCount_;
}
/** \return The logical block number for the start of the first FAT. */ /** \return The logical block number for the start of the first FAT. */
uint32_t fatStartBlock() const {return fatStartBlock_;} uint32_t fatStartBlock() const {
return fatStartBlock_;
}
/** \return The FAT type of the volume. Values are 12, 16 or 32. */ /** \return The FAT type of the volume. Values are 12, 16 or 32. */
uint8_t fatType() const {return fatType_;} uint8_t fatType() const {
return fatType_;
}
int32_t freeClusterCount(); int32_t freeClusterCount();
/** \return The number of entries in the root directory for FAT16 volumes. */ /** \return The number of entries in the root directory for FAT16 volumes. */
uint32_t rootDirEntryCount() const {return rootDirEntryCount_;} uint32_t rootDirEntryCount() const {
return rootDirEntryCount_;
}
/** \return The logical block number for the start of the root directory /** \return The logical block number for the start of the root directory
on FAT16 volumes or the first cluster number on FAT32 volumes. */ on FAT16 volumes or the first cluster number on FAT32 volumes. */
uint32_t rootDirStart() const {return rootDirStart_;} uint32_t rootDirStart() const {
return rootDirStart_;
}
/** Sd2Card object for this volume /** Sd2Card object for this volume
* \return pointer to Sd2Card object. * \return pointer to Sd2Card object.
*/ */
Sd2Card* sdCard() {return sdCard_;} Sd2Card* sdCard() {
return sdCard_;
}
/** Debug access to FAT table /** Debug access to FAT table
* *
* \param[in] n cluster number. * \param[in] n cluster number.
* \param[out] v value of entry * \param[out] v value of entry
* \return true for success or false for failure * \return true for success or false for failure
*/ */
bool dbgFat(uint32_t n, uint32_t* v) {return fatGet(n, v);} bool dbgFat(uint32_t n, uint32_t* v) {
return fatGet(n, v);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
private: private:
// Allow SdBaseFile access to SdVolume private data. // Allow SdBaseFile access to SdVolume private data.
friend class SdBaseFile; friend class SdBaseFile;
@ -154,13 +180,20 @@ class SdVolume {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool allocContiguous(uint32_t count, uint32_t* curCluster); bool allocContiguous(uint32_t count, uint32_t* curCluster);
uint8_t blockOfCluster(uint32_t position) const { uint8_t blockOfCluster(uint32_t position) const {
return (position >> 9) & (blocksPerCluster_ - 1);} return (position >> 9) & (blocksPerCluster_ - 1);
}
uint32_t clusterStartBlock(uint32_t cluster) const { uint32_t clusterStartBlock(uint32_t cluster) const {
return dataStartBlock_ + ((cluster - 2) << clusterSizeShift_);} return dataStartBlock_ + ((cluster - 2) << clusterSizeShift_);
}
uint32_t blockNumber(uint32_t cluster, uint32_t position) const { uint32_t blockNumber(uint32_t cluster, uint32_t position) const {
return clusterStartBlock(cluster) + blockOfCluster(position);} return clusterStartBlock(cluster) + blockOfCluster(position);
cache_t *cache() {return &cacheBuffer_;} }
uint32_t cacheBlockNumber() {return cacheBlockNumber_;} cache_t *cache() {
return &cacheBuffer_;
}
uint32_t cacheBlockNumber() {
return cacheBlockNumber_;
}
#if USE_MULTIPLE_CARDS #if USE_MULTIPLE_CARDS
bool cacheFlush(); bool cacheFlush();
bool cacheRawBlock(uint32_t blockNumber, bool dirty); bool cacheRawBlock(uint32_t blockNumber, bool dirty);
@ -173,7 +206,9 @@ class SdVolume {
cacheDirty_ = dirty; cacheDirty_ = dirty;
cacheBlockNumber_ = blockNumber; cacheBlockNumber_ = blockNumber;
} }
void cacheSetDirty() {cacheDirty_ |= CACHE_FOR_WRITE;} void cacheSetDirty() {
cacheDirty_ |= CACHE_FOR_WRITE;
}
bool chainSize(uint32_t beginCluster, uint32_t* size); bool chainSize(uint32_t beginCluster, uint32_t* size);
bool fatGet(uint32_t cluster, uint32_t* value); bool fatGet(uint32_t cluster, uint32_t* value);
bool fatPut(uint32_t cluster, uint32_t value); bool fatPut(uint32_t cluster, uint32_t value);
@ -187,19 +222,22 @@ class SdVolume {
return cluster >= FAT32EOC_MIN; return cluster >= FAT32EOC_MIN;
} }
bool readBlock(uint32_t block, uint8_t* dst) { bool readBlock(uint32_t block, uint8_t* dst) {
return sdCard_->readBlock(block, dst);} return sdCard_->readBlock(block, dst);
}
bool writeBlock(uint32_t block, const uint8_t* dst) { bool writeBlock(uint32_t block, const uint8_t* dst) {
return sdCard_->writeBlock(block, dst); return sdCard_->writeBlock(block, dst);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Deprecated functions - suppress cpplint warnings with NOLINT comment // Deprecated functions - suppress cpplint warnings with NOLINT comment
#if ALLOW_DEPRECATED_FUNCTIONS && !defined(DOXYGEN) #if ALLOW_DEPRECATED_FUNCTIONS && !defined(DOXYGEN)
public: public:
/** \deprecated Use: bool SdVolume::init(Sd2Card* dev); /** \deprecated Use: bool SdVolume::init(Sd2Card* dev);
* \param[in] dev The SD card where the volume is located. * \param[in] dev The SD card where the volume is located.
* \return true for success or false for failure. * \return true for success or false for failure.
*/ */
bool init(Sd2Card& dev) {return init(&dev);} // NOLINT bool init(Sd2Card& dev) {
return init(&dev); // NOLINT
}
/** \deprecated Use: bool SdVolume::init(Sd2Card* dev, uint8_t vol); /** \deprecated Use: bool SdVolume::init(Sd2Card* dev, uint8_t vol);
* \param[in] dev The SD card where the volume is located. * \param[in] dev The SD card where the volume is located.
* \param[in] part The partition to be used. * \param[in] part The partition to be used.

View File

@ -78,7 +78,7 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
{ {
if( Channel[timer] < 0 ) if( Channel[timer] < 0 )
*TCNTn = 0; // channel set to -1 indicated that refresh interval completed so reset the timer *TCNTn = 0; // channel set to -1 indicated that refresh interval completed so reset the timer
else{ else {
if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && SERVO(timer,Channel[timer]).Pin.isActive == true ) if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && SERVO(timer,Channel[timer]).Pin.isActive == true )
digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,LOW); // pulse this channel low if activated digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,LOW); // pulse this channel low if activated
} }
@ -211,19 +211,19 @@ static void finISR(timer16_Sequence_t timer)
//disable use of the given timer //disable use of the given timer
#if defined WIRING // Wiring #if defined WIRING // Wiring
if(timer == _timer1) { if(timer == _timer1) {
#if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
TIMSK1 &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt TIMSK1 &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt
#else #else
TIMSK &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt TIMSK &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt
#endif #endif
timerDetach(TIMER1OUTCOMPAREA_INT); timerDetach(TIMER1OUTCOMPAREA_INT);
} }
else if(timer == _timer3) { else if(timer == _timer3) {
#if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
TIMSK3 &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt TIMSK3 &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt
#else #else
ETIMSK &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt ETIMSK &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt
#endif #endif
timerDetach(TIMER3OUTCOMPAREA_INT); timerDetach(TIMER3OUTCOMPAREA_INT);
} }
#else #else
@ -263,7 +263,8 @@ uint8_t Servo::attach(int pin, int min, int max)
{ {
if(this->servoIndex < MAX_SERVOS ) { if(this->servoIndex < MAX_SERVOS ) {
#if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0) #if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
if (pin > 0) this->pin = pin; else pin = this->pin; if (pin > 0) this->pin = pin;
else pin = this->pin;
#endif #endif
pinMode( pin, OUTPUT) ; // set servo pin to output pinMode( pin, OUTPUT) ; // set servo pin to output
servos[this->servoIndex].Pin.nbr = pin; servos[this->servoIndex].Pin.nbr = pin;

View File

@ -19,11 +19,17 @@ class Timer
public: public:
Timer(); Timer();
void start(); void start();
void stop(){m_isRunning = false;} void stop() {
bool running(){return m_isRunning;} m_isRunning = false;
}
bool running() {
return m_isRunning;
}
bool expired(T msPeriod); bool expired(T msPeriod);
protected: protected:
T started(){return m_started;} T started() {
return m_started;
}
private: private:
bool m_isRunning; bool m_isRunning;
T m_started; T m_started;

View File

@ -13,7 +13,7 @@
class TimerRemaining : public LongTimer class TimerRemaining : public LongTimer
{ {
public: public:
TimerRemaining() : m_period(){} TimerRemaining() : m_period() {}
void start() = delete; void start() = delete;
bool expired(unsigned long msPeriod) = delete; bool expired(unsigned long msPeriod) = delete;
/** /**

View File

@ -12,7 +12,7 @@ uint16_t adc_sim_mask;
#ifdef ADC_CALLBACK #ifdef ADC_CALLBACK
extern void ADC_CALLBACK(void); extern void ADC_CALLBACK(void);
#endif //ADC_CALLBACK #endif //ADC_CALLBACK
@ -38,7 +38,8 @@ void adc_reset(void)
{ {
adc_state = 0; adc_state = 0;
adc_count = 0; adc_count = 0;
uint8_t i; for (i = 0; i < ADC_CHAN_CNT; i++) uint8_t i;
for (i = 0; i < ADC_CHAN_CNT; i++)
if ((adc_sim_mask & (1 << i)) == 0) if ((adc_sim_mask & (1 << i)) == 0)
adc_values[i] = 0; adc_values[i] = 0;
} }

View File

@ -26,7 +26,7 @@ void bootapp_ram2flash(uint16_t rptr, uint16_t fptr, uint16_t size)
boot_app_magic = BOOT_APP_MAGIC; boot_app_magic = BOOT_APP_MAGIC;
boot_app_flags |= BOOT_APP_FLG_COPY; boot_app_flags |= BOOT_APP_FLG_COPY;
boot_app_flags |= BOOT_APP_FLG_ERASE; boot_app_flags |= BOOT_APP_FLG_ERASE;
/* uint16_t ui; for (ui = 0; ui < size; ui++) /* uint16_t ui; for (ui = 0; ui < size; ui++)
{ {
uint8_t uc = ram_array[ui+rptr]; uint8_t uc = ram_array[ui+rptr];
if (pgm_read_byte(ui+fptr) & uc != uc) if (pgm_read_byte(ui+fptr) & uc != uc)

View File

@ -12,14 +12,14 @@
CardReader::CardReader() CardReader::CardReader()
{ {
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
sort_count = 0; sort_count = 0;
#if SDSORT_GCODE #if SDSORT_GCODE
sort_alpha = true; sort_alpha = true;
sort_folders = FOLDER_SORTING; sort_folders = FOLDER_SORTING;
//sort_reverse = false; //sort_reverse = false;
#endif #endif
#endif #endif
filesize = 0; filesize = 0;
sdpos = 0; sdpos = 0;
@ -36,10 +36,10 @@ CardReader::CardReader()
autostart_stilltocheck=true; //the SD start is delayed, because otherwise the serial cannot answer fast enough to make contact with the host software. autostart_stilltocheck=true; //the SD start is delayed, because otherwise the serial cannot answer fast enough to make contact with the host software.
lastnr=0; lastnr=0;
//power to SD reader //power to SD reader
#if SDPOWER > -1 #if SDPOWER > -1
SET_OUTPUT(SDPOWER); SET_OUTPUT(SDPOWER);
WRITE(SDPOWER,HIGH); WRITE(SDPOWER,HIGH);
#endif //SDPOWER #endif //SDPOWER
autostart_atmillis=millis()+5000; autostart_atmillis=millis()+5000;
} }
@ -169,15 +169,15 @@ void CardReader::initsd()
root.close(); root.close();
#ifdef SDSLOW #ifdef SDSLOW
if (!card.init(SPI_HALF_SPEED,SDSS) if (!card.init(SPI_HALF_SPEED,SDSS)
#if defined(LCD_SDSS) && (LCD_SDSS != SDSS) #if defined(LCD_SDSS) && (LCD_SDSS != SDSS)
&& !card.init(SPI_HALF_SPEED,LCD_SDSS) && !card.init(SPI_HALF_SPEED,LCD_SDSS)
#endif #endif
) )
#else #else
if (!card.init(SPI_FULL_SPEED,SDSS) if (!card.init(SPI_FULL_SPEED,SDSS)
#if defined(LCD_SDSS) && (LCD_SDSS != SDSS) #if defined(LCD_SDSS) && (LCD_SDSS != SDSS)
&& !card.init(SPI_FULL_SPEED,LCD_SDSS) && !card.init(SPI_FULL_SPEED,LCD_SDSS)
#endif #endif
) )
#endif #endif
{ {
@ -204,9 +204,9 @@ void CardReader::initsd()
workDir=root; workDir=root;
curDir=&root; curDir=&root;
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
presort(); presort();
#endif #endif
/* /*
if(!workDir.openRoot(&volume)) if(!workDir.openRoot(&volume))
@ -226,9 +226,9 @@ void CardReader::setroot()
workDir=root; workDir=root;
curDir=&workDir; curDir=&workDir;
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
presort(); presort();
#endif #endif
} }
void CardReader::release() void CardReader::release()
{ {
@ -242,9 +242,9 @@ void CardReader::startFileprint()
{ {
sdprinting = true; sdprinting = true;
paused = false; paused = false;
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
//flush_presort(); //flush_presort();
#endif #endif
} }
} }
@ -276,12 +276,17 @@ uint16_t CardReader::getWorkDirDepth() {
void CardReader::getAbsFilename(char *t) void CardReader::getAbsFilename(char *t)
{ {
uint8_t cnt=0; uint8_t cnt=0;
*t='/';t++;cnt++; *t='/';
for(uint8_t i=0;i<workDirDepth;i++) t++;
cnt++;
for(uint8_t i=0; i<workDirDepth; i++)
{ {
workDirParents[i].getFilename(t); //SDBaseFile.getfilename! workDirParents[i].getFilename(t); //SDBaseFile.getfilename!
while(*t!=0 && cnt< MAXPATHNAMELENGTH) while(*t!=0 && cnt< MAXPATHNAMELENGTH)
{t++;cnt++;} //crawl counter forward. {
t++; //crawl counter forward.
cnt++;
}
} }
if(cnt<MAXPATHNAMELENGTH-13) if(cnt<MAXPATHNAMELENGTH-13)
file.getFilename(t); file.getFilename(t);
@ -470,9 +475,9 @@ void CardReader::removeFile(const char* name)
SERIAL_PROTOCOLPGM("File deleted:"); SERIAL_PROTOCOLPGM("File deleted:");
SERIAL_PROTOCOLLN(fname); SERIAL_PROTOCOLLN(fname);
sdpos = 0; sdpos = 0;
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
presort(); presort();
#endif #endif
} }
else else
{ {
@ -490,7 +495,7 @@ uint32_t CardReader::getFileSize()
void CardReader::getStatus() void CardReader::getStatus()
{ {
if(sdprinting){ if(sdprinting) {
SERIAL_PROTOCOL(longFilename); SERIAL_PROTOCOL(longFilename);
SERIAL_PROTOCOLPGM("\n"); SERIAL_PROTOCOLPGM("\n");
SERIAL_PROTOCOLRPGM(_N("SD printing byte "));////MSG_SD_PRINTING_BYTE c=0 r=0 SERIAL_PROTOCOLRPGM(_N("SD printing byte "));////MSG_SD_PRINTING_BYTE c=0 r=0
@ -569,7 +574,7 @@ void CardReader::checkautostart(bool force)
char autoname[30]; char autoname[30];
sprintf_P(autoname, PSTR("auto%i.g"), lastnr); sprintf_P(autoname, PSTR("auto%i.g"), lastnr);
for(int8_t i=0;i<(int8_t)strlen(autoname);i++) for(int8_t i=0; i<(int8_t)strlen(autoname); i++)
autoname[i]=tolower(autoname[i]); autoname[i]=tolower(autoname[i]);
dir_t p; dir_t p;
@ -578,7 +583,7 @@ void CardReader::checkautostart(bool force)
bool found=false; bool found=false;
while (root.readDir(p, NULL) > 0) while (root.readDir(p, NULL) > 0)
{ {
for(int8_t i=0;i<(int8_t)strlen((char*)p.name);i++) for(int8_t i=0; i<(int8_t)strlen((char*)p.name); i++)
p.name[i]=tolower(p.name[i]); p.name[i]=tolower(p.name[i]);
//Serial.print((char*)p.name); //Serial.print((char*)p.name);
//Serial.print(" "); //Serial.print(" ");
@ -670,9 +675,9 @@ void CardReader::chdir(const char * relpath)
workDirParents[0]=*parent; workDirParents[0]=*parent;
} }
workDir=newfile; workDir=newfile;
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
presort(); presort();
#endif #endif
} }
} }
@ -686,9 +691,9 @@ void CardReader::updir()
{ {
workDirParents[d] = workDirParents[d+1]; workDirParents[d] = workDirParents[d+1];
} }
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
presort(); presort();
#endif #endif
} }
} }
@ -699,9 +704,9 @@ void CardReader::updir()
*/ */
void CardReader::getfilename_sorted(const uint16_t nr) { void CardReader::getfilename_sorted(const uint16_t nr) {
getfilename( getfilename(
#if SDSORT_GCODE #if SDSORT_GCODE
sort_alpha && sort_alpha &&
#endif #endif
(nr < sort_count) ? sort_order[nr] : nr (nr < sort_count) ? sort_order[nr] : nr
); );
} }
@ -720,9 +725,9 @@ void CardReader::presort() {
if (sdSort == SD_SORT_NONE) return; //sd sort is turned off if (sdSort == SD_SORT_NONE) return; //sd sort is turned off
#if SDSORT_GCODE #if SDSORT_GCODE
if (!sort_alpha) return; if (!sort_alpha) return;
#endif #endif
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
// Throw away old sort index // Throw away old sort index
@ -739,42 +744,42 @@ void CardReader::presort() {
fileCnt = SDSORT_LIMIT; fileCnt = SDSORT_LIMIT;
} }
lcd_clear(); lcd_clear();
#if !SDSORT_USES_RAM #if !SDSORT_USES_RAM
lcd_set_progress(); lcd_set_progress();
#endif #endif
lcd_puts_at_P(0, 1, _i("Sorting files"));////MSG_SORTING c=20 r=1 lcd_puts_at_P(0, 1, _i("Sorting files"));////MSG_SORTING c=20 r=1
// Sort order is always needed. May be static or dynamic. // Sort order is always needed. May be static or dynamic.
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
sort_order = new uint8_t[fileCnt]; sort_order = new uint8_t[fileCnt];
#endif #endif
// Use RAM to store the entire directory during pre-sort. // Use RAM to store the entire directory during pre-sort.
// SDSORT_LIMIT should be set to prevent over-allocation. // SDSORT_LIMIT should be set to prevent over-allocation.
#if SDSORT_USES_RAM #if SDSORT_USES_RAM
// If using dynamic ram for names, allocate on the heap. // If using dynamic ram for names, allocate on the heap.
#if SDSORT_CACHE_NAMES #if SDSORT_CACHE_NAMES
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
sortshort = new char*[fileCnt]; sortshort = new char*[fileCnt];
sortnames = new char*[fileCnt]; sortnames = new char*[fileCnt];
#endif #endif
#elif SDSORT_USES_STACK #elif SDSORT_USES_STACK
char sortnames[fileCnt][LONG_FILENAME_LENGTH]; char sortnames[fileCnt][LONG_FILENAME_LENGTH];
uint16_t creation_time[fileCnt]; uint16_t creation_time[fileCnt];
uint16_t creation_date[fileCnt]; uint16_t creation_date[fileCnt];
#endif #endif
// Folder sorting needs 1 bit per entry for flags. // Folder sorting needs 1 bit per entry for flags.
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
isDir = new uint8_t[(fileCnt + 7) >> 3]; isDir = new uint8_t[(fileCnt + 7) >> 3];
#elif SDSORT_USES_STACK #elif SDSORT_USES_STACK
uint8_t isDir[(fileCnt + 7) >> 3]; uint8_t isDir[(fileCnt + 7) >> 3];
#endif #endif
#endif #endif
#else // !SDSORT_USES_RAM #else // !SDSORT_USES_RAM
uint32_t positions[fileCnt]; uint32_t positions[fileCnt];
@ -785,7 +790,7 @@ void CardReader::presort() {
uint16_t creation_time_bckp; uint16_t creation_time_bckp;
uint16_t creation_date_bckp; uint16_t creation_date_bckp;
#endif #endif
position = 0; position = 0;
if (fileCnt > 1) { if (fileCnt > 1) {
// Init sort order. // Init sort order.
@ -796,34 +801,34 @@ void CardReader::presort() {
positions[i] = position; positions[i] = position;
getfilename(i); getfilename(i);
// If using RAM then read all filenames now. // If using RAM then read all filenames now.
#if SDSORT_USES_RAM #if SDSORT_USES_RAM
getfilename(i); getfilename(i);
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
// Use dynamic method to copy long filename // Use dynamic method to copy long filename
sortnames[i] = strdup(LONGEST_FILENAME); sortnames[i] = strdup(LONGEST_FILENAME);
#if SDSORT_CACHE_NAMES #if SDSORT_CACHE_NAMES
// When caching also store the short name, since // When caching also store the short name, since
// we're replacing the getfilename() behavior. // we're replacing the getfilename() behavior.
sortshort[i] = strdup(filename); sortshort[i] = strdup(filename);
#endif #endif
#else #else
// Copy filenames into the static array // Copy filenames into the static array
strcpy(sortnames[i], LONGEST_FILENAME); strcpy(sortnames[i], LONGEST_FILENAME);
creation_time[i] = creationTime; creation_time[i] = creationTime;
creation_date[i] = creationDate; creation_date[i] = creationDate;
#if SDSORT_CACHE_NAMES #if SDSORT_CACHE_NAMES
strcpy(sortshort[i], filename); strcpy(sortshort[i], filename);
#endif #endif
#endif #endif
// char out[30]; // char out[30];
// sprintf_P(out, PSTR("---- %i %s %s"), i, filenameIsDir ? "D" : " ", sortnames[i]); // sprintf_P(out, PSTR("---- %i %s %s"), i, filenameIsDir ? "D" : " ", sortnames[i]);
// SERIAL_ECHOLN(out); // SERIAL_ECHOLN(out);
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
const uint16_t bit = i & 0x07, ind = i >> 3; const uint16_t bit = i & 0x07, ind = i >> 3;
if (bit == 0) isDir[ind] = 0x00; if (bit == 0) isDir[ind] = 0x00;
if (filenameIsDir) isDir[ind] |= _BV(bit); if (filenameIsDir) isDir[ind] |= _BV(bit);
#endif #endif
#endif #endif
} }
#ifdef QUICKSORT #ifdef QUICKSORT
@ -833,41 +838,41 @@ void CardReader::presort() {
uint16_t total = 0.5*(fileCnt - 1)*(fileCnt); uint16_t total = 0.5*(fileCnt - 1)*(fileCnt);
// Compare names from the array or just the two buffered names // Compare names from the array or just the two buffered names
#if SDSORT_USES_RAM #if SDSORT_USES_RAM
#define _SORT_CMP_NODIR() (strcasecmp(sortnames[o1], sortnames[o2]) > 0) #define _SORT_CMP_NODIR() (strcasecmp(sortnames[o1], sortnames[o2]) > 0)
#define _SORT_CMP_TIME_NODIR() (((creation_date[o1] == creation_date[o2]) && (creation_time[o1] < creation_time[o2])) || \ #define _SORT_CMP_TIME_NODIR() (((creation_date[o1] == creation_date[o2]) && (creation_time[o1] < creation_time[o2])) || \
(creation_date[o1] < creation_date [o2])) (creation_date[o1] < creation_date [o2]))
#else #else
#define _SORT_CMP_NODIR() (strcasecmp(name1, name2) > 0) //true if lowercase(name1) > lowercase(name2) #define _SORT_CMP_NODIR() (strcasecmp(name1, name2) > 0) //true if lowercase(name1) > lowercase(name2)
#define _SORT_CMP_TIME_NODIR() (((creation_date_bckp == creationDate) && (creation_time_bckp > creationTime)) || \ #define _SORT_CMP_TIME_NODIR() (((creation_date_bckp == creationDate) && (creation_time_bckp > creationTime)) || \
(creation_date_bckp > creationDate)) (creation_date_bckp > creationDate))
#endif #endif
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
#if SDSORT_USES_RAM #if SDSORT_USES_RAM
// Folder sorting needs an index and bit to test for folder-ness. // Folder sorting needs an index and bit to test for folder-ness.
const uint8_t ind1 = o1 >> 3, bit1 = o1 & 0x07, const uint8_t ind1 = o1 >> 3, bit1 = o1 & 0x07,
ind2 = o2 >> 3, bit2 = o2 & 0x07; ind2 = o2 >> 3, bit2 = o2 & 0x07;
#define _SORT_CMP_DIR(fs) \ #define _SORT_CMP_DIR(fs) \
(((isDir[ind1] & _BV(bit1)) != 0) == ((isDir[ind2] & _BV(bit2)) != 0) \ (((isDir[ind1] & _BV(bit1)) != 0) == ((isDir[ind2] & _BV(bit2)) != 0) \
? _SORT_CMP_NODIR() \ ? _SORT_CMP_NODIR() \
: (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0) : (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0)
#define _SORT_CMP_TIME_DIR(fs) \ #define _SORT_CMP_TIME_DIR(fs) \
(((isDir[ind1] & _BV(bit1)) != 0) == ((isDir[ind2] & _BV(bit2)) != 0) \ (((isDir[ind1] & _BV(bit1)) != 0) == ((isDir[ind2] & _BV(bit2)) != 0) \
? _SORT_CMP_TIME_NODIR() \ ? _SORT_CMP_TIME_NODIR() \
: (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0) : (isDir[fs > 0 ? ind1 : ind2] & (fs > 0 ? _BV(bit1) : _BV(bit2))) != 0)
#else #else
#define _SORT_CMP_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? dir1 : !dir1)) #define _SORT_CMP_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? dir1 : !dir1))
#define _SORT_CMP_TIME_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_TIME_NODIR() : (fs < 0 ? dir1 : !dir1)) #define _SORT_CMP_TIME_DIR(fs) ((dir1 == filenameIsDir) ? _SORT_CMP_TIME_NODIR() : (fs < 0 ? dir1 : !dir1))
#endif #endif
#endif #endif
for (uint16_t i = fileCnt; --i;) { for (uint16_t i = fileCnt; --i;) {
if (!IS_SD_INSERTED) return; if (!IS_SD_INSERTED) return;
bool didSwap = false; bool didSwap = false;
#if !SDSORT_USES_RAM //show progresss bar only if slow sorting method is used #if !SDSORT_USES_RAM //show progresss bar only if slow sorting method is used
int8_t percent = (counter * 100) / total;//((counter * 100) / pow((fileCnt-1),2)); int8_t percent = (counter * 100) / total;//((counter * 100) / pow((fileCnt-1),2));
for (int column = 0; column < 20; column++) { for (int column = 0; column < 20; column++) {
if (column < (percent / 5)) if (column < (percent / 5))
@ -877,7 +882,7 @@ void CardReader::presort() {
} }
} }
counter++; counter++;
#endif #endif
//MYSERIAL.println(int(i)); //MYSERIAL.println(int(i));
for (uint16_t j = 0; j < i; ++j) { for (uint16_t j = 0; j < i; ++j) {
@ -887,27 +892,27 @@ void CardReader::presort() {
// The most economical method reads names as-needed // The most economical method reads names as-needed
// throughout the loop. Slow if there are many. // throughout the loop. Slow if there are many.
#if !SDSORT_USES_RAM #if !SDSORT_USES_RAM
counter++; counter++;
getfilename_simple(positions[o1]); getfilename_simple(positions[o1]);
strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it) strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it)
creation_date_bckp = creationDate; creation_date_bckp = creationDate;
creation_time_bckp = creationTime; creation_time_bckp = creationTime;
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
bool dir1 = filenameIsDir; bool dir1 = filenameIsDir;
#endif #endif
getfilename_simple(positions[o2]); getfilename_simple(positions[o2]);
char *name2 = LONGEST_FILENAME; // use the string in-place char *name2 = LONGEST_FILENAME; // use the string in-place
#endif // !SDSORT_USES_RAM #endif // !SDSORT_USES_RAM
// Sort the current pair according to settings. // Sort the current pair according to settings.
if ( if (
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
(sdSort == SD_SORT_TIME && _SORT_CMP_TIME_DIR(FOLDER_SORTING)) || (sdSort == SD_SORT_ALPHA && _SORT_CMP_DIR(FOLDER_SORTING)) (sdSort == SD_SORT_TIME && _SORT_CMP_TIME_DIR(FOLDER_SORTING)) || (sdSort == SD_SORT_ALPHA && _SORT_CMP_DIR(FOLDER_SORTING))
#else #else
(sdSort == SD_SORT_TIME && _SORT_CMP_TIME_NODIR()) || (sdSort == SD_SORT_ALPHA && _SORT_CMP_NODIR()) (sdSort == SD_SORT_TIME && _SORT_CMP_TIME_NODIR()) || (sdSort == SD_SORT_ALPHA && _SORT_CMP_NODIR())
#endif #endif
) )
{ {
sort_order[j] = o2; sort_order[j] = o2;
@ -919,31 +924,31 @@ void CardReader::presort() {
} //end of bubble sort loop } //end of bubble sort loop
#endif #endif
// Using RAM but not keeping names around // Using RAM but not keeping names around
#if (SDSORT_USES_RAM && !SDSORT_CACHE_NAMES) #if (SDSORT_USES_RAM && !SDSORT_CACHE_NAMES)
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
for (uint16_t i = 0; i < fileCnt; ++i) free(sortnames[i]); for (uint16_t i = 0; i < fileCnt; ++i) free(sortnames[i]);
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
free(isDir); free(isDir);
#endif #endif
#endif #endif
#endif #endif
} }
else { else {
sort_order[0] = 0; sort_order[0] = 0;
#if (SDSORT_USES_RAM && SDSORT_CACHE_NAMES) #if (SDSORT_USES_RAM && SDSORT_CACHE_NAMES)
getfilename(0); getfilename(0);
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
sortnames = new char*[1]; sortnames = new char*[1];
sortnames[0] = strdup(LONGEST_FILENAME); // malloc sortnames[0] = strdup(LONGEST_FILENAME); // malloc
sortshort = new char*[1]; sortshort = new char*[1];
sortshort[0] = strdup(filename); // malloc sortshort[0] = strdup(filename); // malloc
isDir = new uint8_t[1]; isDir = new uint8_t[1];
#else #else
strcpy(sortnames[0], LONGEST_FILENAME); strcpy(sortnames[0], LONGEST_FILENAME);
strcpy(sortshort[0], filename); strcpy(sortshort[0], filename);
#endif #endif
isDir[0] = filenameIsDir ? 0x01 : 0x00; isDir[0] = filenameIsDir ? 0x01 : 0x00;
#endif #endif
} }
sort_count = fileCnt; sort_count = fileCnt;
@ -965,17 +970,17 @@ void CardReader::presort() {
void CardReader::flush_presort() { void CardReader::flush_presort() {
if (sort_count > 0) { if (sort_count > 0) {
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
delete sort_order; delete sort_order;
#if SDSORT_CACHE_NAMES #if SDSORT_CACHE_NAMES
for (uint8_t i = 0; i < sort_count; ++i) { for (uint8_t i = 0; i < sort_count; ++i) {
free(sortshort[i]); // strdup free(sortshort[i]); // strdup
free(sortnames[i]); // strdup free(sortnames[i]); // strdup
} }
delete sortshort; delete sortshort;
delete sortnames; delete sortnames;
#endif #endif
#endif #endif
sort_count = 0; sort_count = 0;
} }
} }
@ -1006,9 +1011,9 @@ void CardReader::printingHasFinished()
//enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND)); //enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
} }
autotempShutdown(); autotempShutdown();
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
//presort(); //presort();
#endif #endif
} }
} }

View File

@ -44,30 +44,60 @@ public:
void updir(); void updir();
void setroot(); void setroot();
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
void presort(); void presort();
#ifdef SDSORT_QUICKSORT #ifdef SDSORT_QUICKSORT
void swap(uint8_t left, uint8_t right); void swap(uint8_t left, uint8_t right);
void quicksort(uint8_t left, uint8_t right); void quicksort(uint8_t left, uint8_t right);
#endif //SDSORT_QUICKSORT #endif //SDSORT_QUICKSORT
void getfilename_sorted(const uint16_t nr); void getfilename_sorted(const uint16_t nr);
#if SDSORT_GCODE #if SDSORT_GCODE
FORCE_INLINE void setSortOn(bool b) { sort_alpha = b; presort(); } FORCE_INLINE void setSortOn(bool b) {
FORCE_INLINE void setSortFolders(int i) { sort_folders = i; presort(); } sort_alpha = b;
presort();
}
FORCE_INLINE void setSortFolders(int i) {
sort_folders = i;
presort();
}
//FORCE_INLINE void setSortReverse(bool b) { sort_reverse = b; } //FORCE_INLINE void setSortReverse(bool b) { sort_reverse = b; }
#endif #endif
#endif #endif
FORCE_INLINE bool isFileOpen() { return file.isOpen(); } FORCE_INLINE bool isFileOpen() {
FORCE_INLINE bool eof() { return sdpos>=filesize ;}; return file.isOpen();
FORCE_INLINE int16_t get() { sdpos = file.curPosition();return (int16_t)file.read();}; }
FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);}; FORCE_INLINE bool eof() {
FORCE_INLINE uint8_t percentDone(){if(!isFileOpen()) return 0; if(filesize) return sdpos/((filesize+99)/100); else return 0;}; return sdpos>=filesize ;
FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;}; };
FORCE_INLINE uint32_t get_sdpos() { if (!isFileOpen()) return 0; else return(sdpos); }; FORCE_INLINE int16_t get() {
sdpos = file.curPosition();
return (int16_t)file.read();
};
FORCE_INLINE void setIndex(long index) {
sdpos = index;
file.seekSet(index);
};
FORCE_INLINE uint8_t percentDone() {
if(!isFileOpen()) return 0;
if(filesize) return sdpos/((filesize+99)/100);
else return 0;
};
FORCE_INLINE char* getWorkDirName() {
workDir.getFilename(filename);
return filename;
};
FORCE_INLINE uint32_t get_sdpos() {
if (!isFileOpen()) return 0;
else return(sdpos);
};
bool ToshibaFlashAir_isEnabled() const { return card.getFlashAirCompatible(); } bool ToshibaFlashAir_isEnabled() const {
void ToshibaFlashAir_enable(bool enable) { card.setFlashAirCompatible(enable); } return card.getFlashAirCompatible();
}
void ToshibaFlashAir_enable(bool enable) {
card.setFlashAirCompatible(enable);
}
bool ToshibaFlashAir_GetIP(uint8_t *ip); bool ToshibaFlashAir_GetIP(uint8_t *ip);
public: public:
@ -89,45 +119,45 @@ private:
// Sort files and folders alphabetically. // Sort files and folders alphabetically.
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
uint16_t sort_count; // Count of sorted items in the current directory uint16_t sort_count; // Count of sorted items in the current directory
#if SDSORT_GCODE #if SDSORT_GCODE
bool sort_alpha; // Flag to enable / disable the feature bool sort_alpha; // Flag to enable / disable the feature
int sort_folders; // Flag to enable / disable folder sorting int sort_folders; // Flag to enable / disable folder sorting
//bool sort_reverse; // Flag to enable / disable reverse sorting //bool sort_reverse; // Flag to enable / disable reverse sorting
#endif #endif
// By default the sort index is static // By default the sort index is static
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
uint8_t *sort_order; uint8_t *sort_order;
#else #else
uint8_t sort_order[SDSORT_LIMIT]; uint8_t sort_order[SDSORT_LIMIT];
#endif #endif
// Cache filenames to speed up SD menus. // Cache filenames to speed up SD menus.
#if SDSORT_USES_RAM #if SDSORT_USES_RAM
// If using dynamic ram for names, allocate on the heap. // If using dynamic ram for names, allocate on the heap.
#if SDSORT_CACHE_NAMES #if SDSORT_CACHE_NAMES
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
char **sortshort, **sortnames; char **sortshort, **sortnames;
#else #else
char sortshort[SDSORT_LIMIT][FILENAME_LENGTH]; char sortshort[SDSORT_LIMIT][FILENAME_LENGTH];
char sortnames[SDSORT_LIMIT][FILENAME_LENGTH]; char sortnames[SDSORT_LIMIT][FILENAME_LENGTH];
#endif #endif
#elif !SDSORT_USES_STACK #elif !SDSORT_USES_STACK
char sortnames[SDSORT_LIMIT][FILENAME_LENGTH]; char sortnames[SDSORT_LIMIT][FILENAME_LENGTH];
uint16_t creation_time[SDSORT_LIMIT]; uint16_t creation_time[SDSORT_LIMIT];
uint16_t creation_date[SDSORT_LIMIT]; uint16_t creation_date[SDSORT_LIMIT];
#endif #endif
// Folder sorting uses an isDir array when caching items. // Folder sorting uses an isDir array when caching items.
#if HAS_FOLDER_SORTING #if HAS_FOLDER_SORTING
#if SDSORT_DYNAMIC_RAM #if SDSORT_DYNAMIC_RAM
uint8_t *isDir; uint8_t *isDir;
#elif (SDSORT_CACHE_NAMES) || !(SDSORT_USES_STACK) #elif (SDSORT_CACHE_NAMES) || !(SDSORT_USES_STACK)
uint8_t isDir[(SDSORT_LIMIT + 7) >> 3]; uint8_t isDir[(SDSORT_LIMIT + 7) >> 3];
#endif #endif
#endif #endif
#endif // SDSORT_USES_RAM #endif // SDSORT_USES_RAM
#endif // SDCARD_SORT_ALPHA #endif // SDCARD_SORT_ALPHA
@ -139,8 +169,8 @@ public:
private: private:
SdVolume volume; SdVolume volume;
SdFile file; SdFile file;
#define SD_PROCEDURE_DEPTH 1 #define SD_PROCEDURE_DEPTH 1
#define MAXPATHNAMELENGTH (13*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1) #define MAXPATHNAMELENGTH (13*MAX_DIR_DEPTH+MAX_DIR_DEPTH+1)
uint8_t file_subcall_ctr; uint8_t file_subcall_ctr;
uint32_t filespos[SD_PROCEDURE_DEPTH]; uint32_t filespos[SD_PROCEDURE_DEPTH];
char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];

View File

@ -385,7 +385,7 @@ void get_command()
while (MYSERIAL.available() > 0 && !saved_printing) { //is print is saved (crash detection or filament detection), dont process data from serial line while (MYSERIAL.available() > 0 && !saved_printing) { //is print is saved (crash detection or filament detection), dont process data from serial line
char serial_char = MYSERIAL.read(); char serial_char = MYSERIAL.read();
/* if (selectedSerialPort == 1) /* if (selectedSerialPort == 1)
{ {
selectedSerialPort = 0; selectedSerialPort = 0;
MYSERIAL.write(serial_char); // for debuging serial line 2 in farm_mode MYSERIAL.write(serial_char); // for debuging serial line 2 in farm_mode
@ -409,7 +409,7 @@ void get_command()
return; return;
} }
cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0; //terminate string cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0; //terminate string
if(!comment_mode){ if(!comment_mode) {
gcode_N = 0; gcode_N = 0;
@ -526,7 +526,7 @@ void get_command()
} }
} // end of serial line processing loop } // end of serial line processing loop
if(farm_mode){ if(farm_mode) {
TimeNow = millis(); TimeNow = millis();
if ( ((TimeNow - TimeSent) > 800) && (serial_count > 0) ) { if ( ((TimeNow - TimeSent) > 800) && (serial_count > 0) ) {
cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0; cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0;
@ -544,8 +544,8 @@ void get_command()
} }
} }
#ifdef SDSUPPORT #ifdef SDSUPPORT
if(!card.sdprinting || serial_count!=0){ if(!card.sdprinting || serial_count!=0) {
// If there is a half filled buffer from serial line, wait until return before // If there is a half filled buffer from serial line, wait until return before
// continuing with the serial line. // continuing with the serial line.
return; return;
@ -574,7 +574,7 @@ void get_command()
((serial_char == '#' || serial_char == ':') && comment_mode == false) || ((serial_char == '#' || serial_char == ':') && comment_mode == false) ||
serial_count >= (MAX_CMD_SIZE - 1) || n==-1) serial_count >= (MAX_CMD_SIZE - 1) || n==-1)
{ {
if(card.eof()){ if(card.eof()) {
SERIAL_PROTOCOLLNRPGM(_n("Done printing file"));////MSG_FILE_PRINTED c=0 r=0 SERIAL_PROTOCOLLNRPGM(_n("Done printing file"));////MSG_FILE_PRINTED c=0 r=0
stoptime=millis(); stoptime=millis();
char time[30]; char time[30];
@ -656,7 +656,7 @@ void get_command()
} }
} }
#endif //SDSUPPORT #endif //SDSUPPORT
} }
uint16_t cmdqueue_calc_sd_length() uint16_t cmdqueue_calc_sd_length()

View File

@ -71,12 +71,24 @@ extern void get_command();
extern uint16_t cmdqueue_calc_sd_length(); extern uint16_t cmdqueue_calc_sd_length();
// Return True if a character was found // 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(char code) {
static inline bool code_seen(const char *code) { return (strchr_pointer = strstr(CMDBUFFER_CURRENT_STRING, code)) != NULL; } return (strchr_pointer = strchr(CMDBUFFER_CURRENT_STRING, code)) != 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 bool code_seen(const char *code) {
static inline int16_t code_value_short() { return int16_t(strtol(strchr_pointer+1, NULL, 10)); }; return (strchr_pointer = strstr(CMDBUFFER_CURRENT_STRING, code)) != NULL;
static inline uint8_t code_value_uint8() { return uint8_t(strtol(strchr_pointer+1, NULL, 10)); }; }
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));
};
static inline float code_value_float() static inline float code_value_float()
{ {

View File

@ -469,8 +469,12 @@ void fsensor_st_block_begin(block_t* bl)
((fsensor_st_cnt < 0) && !(bl->direction_bits & 0x8))) ((fsensor_st_cnt < 0) && !(bl->direction_bits & 0x8)))
{ {
// !!! bit toggling (PINxn <- 1) (for PinChangeInterrupt) does not work for some MCU pins // !!! bit toggling (PINxn <- 1) (for PinChangeInterrupt) does not work for some MCU pins
if (PIN_GET(FSENSOR_INT_PIN)) {PIN_VAL(FSENSOR_INT_PIN, LOW);} if (PIN_GET(FSENSOR_INT_PIN)) {
else {PIN_VAL(FSENSOR_INT_PIN, HIGH);} PIN_VAL(FSENSOR_INT_PIN, LOW);
}
else {
PIN_VAL(FSENSOR_INT_PIN, HIGH);
}
} }
} }
@ -481,8 +485,12 @@ void fsensor_st_block_chunk(block_t* bl, int cnt)
if ((fsensor_st_cnt >= fsensor_chunk_len) || (fsensor_st_cnt <= -fsensor_chunk_len)) if ((fsensor_st_cnt >= fsensor_chunk_len) || (fsensor_st_cnt <= -fsensor_chunk_len))
{ {
// !!! bit toggling (PINxn <- 1) (for PinChangeInterrupt) does not work for some MCU pins // !!! bit toggling (PINxn <- 1) (for PinChangeInterrupt) does not work for some MCU pins
if (PIN_GET(FSENSOR_INT_PIN)) {PIN_VAL(FSENSOR_INT_PIN, LOW);} if (PIN_GET(FSENSOR_INT_PIN)) {
else {PIN_VAL(FSENSOR_INT_PIN, HIGH);} PIN_VAL(FSENSOR_INT_PIN, LOW);
}
else {
PIN_VAL(FSENSOR_INT_PIN, HIGH);
}
} }
} }

View File

@ -17,12 +17,22 @@ uint8_t lang_selected = 0;
#if (LANG_MODE == 0) //primary language only #if (LANG_MODE == 0) //primary language only
uint8_t lang_select(uint8_t lang) { return 0; } uint8_t lang_select(uint8_t lang) {
uint8_t lang_get_count() { return 1; } return 0;
uint16_t lang_get_code(uint8_t lang) { return LANG_CODE_EN; } }
const char* lang_get_name_by_code(uint16_t code) { return _n("English"); } uint8_t lang_get_count() {
return 1;
}
uint16_t lang_get_code(uint8_t lang) {
return LANG_CODE_EN;
}
const char* lang_get_name_by_code(uint16_t code) {
return _n("English");
}
void lang_reset(void) { } void lang_reset(void) { }
uint8_t lang_is_selected(void) { return 1; } uint8_t lang_is_selected(void) {
return 1;
}
#else //(LANG_MODE == 0) //secondary languages in progmem or xflash #else //(LANG_MODE == 0) //secondary languages in progmem or xflash
@ -96,7 +106,8 @@ uint8_t lang_check(uint16_t addr)
uint16_t sum = 0; uint16_t sum = 0;
uint16_t size = pgm_read_word((uint16_t*)(addr + 4)); uint16_t size = pgm_read_word((uint16_t*)(addr + 4));
uint16_t lt_sum = pgm_read_word((uint16_t*)(addr + 8)); uint16_t lt_sum = pgm_read_word((uint16_t*)(addr + 8));
uint16_t i; for (i = 0; i < size; i++) uint16_t i;
for (i = 0; i < size; i++)
sum += (uint16_t)pgm_read_byte((uint8_t*)(addr + i)) << ((i & 1)?0:8); sum += (uint16_t)pgm_read_byte((uint8_t*)(addr + i)) << ((i & 1)?0:8);
sum -= lt_sum; //subtract checksum sum -= lt_sum; //subtract checksum
sum = (sum >> 8) | ((sum & 0xff) << 8); //swap bytes sum = (sum >> 8) | ((sum & 0xff) << 8); //swap bytes
@ -203,13 +214,20 @@ const char* lang_get_name_by_code(uint16_t code)
{ {
switch (code) switch (code)
{ {
case LANG_CODE_EN: return _n("English"); case LANG_CODE_EN:
case LANG_CODE_CZ: return _n("Cestina"); return _n("English");
case LANG_CODE_DE: return _n("Deutsch"); case LANG_CODE_CZ:
case LANG_CODE_ES: return _n("Espanol"); return _n("Cestina");
case LANG_CODE_FR: return _n("Francais"); case LANG_CODE_DE:
case LANG_CODE_IT: return _n("Italiano"); return _n("Deutsch");
case LANG_CODE_PL: return _n("Polski"); case LANG_CODE_ES:
return _n("Espanol");
case LANG_CODE_FR:
return _n("Francais");
case LANG_CODE_IT:
return _n("Italiano");
case LANG_CODE_PL:
return _n("Polski");
} }
return _n("??"); return _n("??");
} }

View File

@ -11,11 +11,11 @@
#define PROTOCOL_VERSION "1.0" #define PROTOCOL_VERSION "1.0"
#ifndef CUSTOM_MENDEL_NAME #ifndef CUSTOM_MENDEL_NAME
#define MACHINE_NAME "Mendel" #define MACHINE_NAME "Mendel"
#endif #endif
#ifndef MACHINE_UUID #ifndef MACHINE_UUID
#define MACHINE_UUID "00000000-0000-0000-0000-000000000000" #define MACHINE_UUID "00000000-0000-0000-0000-000000000000"
#endif #endif
#define MSG_FW_VERSION "Firmware" #define MSG_FW_VERSION "Firmware"

View File

@ -419,8 +419,10 @@ uint8_t lcd_escape_write(uint8_t chr)
case 2: case 2:
switch (chr) switch (chr)
{ {
case '2': return 1; // escape = "\x1b[2" case '2':
case '?': return 1; // escape = "\x1b[?" return 1; // escape = "\x1b[2"
case '?':
return 1; // escape = "\x1b[?"
default: default:
if (chr_is_num) return 1; // escape = "\x1b[%1d" if (chr_is_num) return 1; // escape = "\x1b[%1d"
} }
@ -433,7 +435,11 @@ uint8_t lcd_escape_write(uint8_t chr)
break; break;
case '2': case '2':
if (chr == 'J') // escape = "\x1b[2J" if (chr == 'J') // escape = "\x1b[2J"
{ lcd_clear(); lcd_currline = 0; break; } // EraseScreen {
lcd_clear(); // EraseScreen
lcd_currline = 0;
break;
}
default: default:
if (e_2_is_num && // escape = "\x1b[%1d" if (e_2_is_num && // escape = "\x1b[%1d"
((chr == ';') || // escape = "\x1b[%1d;" ((chr == ';') || // escape = "\x1b[%1d;"
@ -706,8 +712,8 @@ void lcd_beeper_quick_feedback(void)
{ {
SET_OUTPUT(BEEPER); SET_OUTPUT(BEEPER);
//-// //-//
Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
/* /*
for(int8_t i = 0; i < 10; i++) for(int8_t i = 0; i < 10; i++)
{ {
WRITE(BEEPER,HIGH); WRITE(BEEPER,HIGH);
@ -715,7 +721,7 @@ Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
WRITE(BEEPER,LOW); WRITE(BEEPER,LOW);
delayMicroseconds(100); delayMicroseconds(100);
} }
*/ */
} }
void lcd_quick_feedback(void) void lcd_quick_feedback(void)
@ -861,7 +867,8 @@ const uint8_t lcd_chardata_bedTemp[8] PROGMEM = {
B10101, B10101,
B11111, B11111,
B00000, B00000,
B00000}; //thanks Sonny Mounicou B00000
}; //thanks Sonny Mounicou
const uint8_t lcd_chardata_degree[8] PROGMEM = { const uint8_t lcd_chardata_degree[8] PROGMEM = {
B01100, B01100,
@ -871,7 +878,8 @@ const uint8_t lcd_chardata_degree[8] PROGMEM = {
B00000, B00000,
B00000, B00000,
B00000, B00000,
B00000}; B00000
};
const uint8_t lcd_chardata_thermometer[8] PROGMEM = { const uint8_t lcd_chardata_thermometer[8] PROGMEM = {
B00100, B00100,
@ -881,7 +889,8 @@ const uint8_t lcd_chardata_thermometer[8] PROGMEM = {
B01010, B01010,
B10001, B10001,
B10001, B10001,
B01110}; B01110
};
const uint8_t lcd_chardata_uplevel[8] PROGMEM = { const uint8_t lcd_chardata_uplevel[8] PROGMEM = {
B00100, B00100,
@ -891,7 +900,8 @@ const uint8_t lcd_chardata_uplevel[8] PROGMEM = {
B11100, B11100,
B00000, B00000,
B00000, B00000,
B00000}; //thanks joris B00000
}; //thanks joris
const uint8_t lcd_chardata_refresh[8] PROGMEM = { const uint8_t lcd_chardata_refresh[8] PROGMEM = {
B00000, B00000,
@ -901,7 +911,8 @@ const uint8_t lcd_chardata_refresh[8] PROGMEM = {
B00011, B00011,
B10011, B10011,
B01100, B01100,
B00000}; //thanks joris B00000
}; //thanks joris
const uint8_t lcd_chardata_folder[8] PROGMEM = { const uint8_t lcd_chardata_folder[8] PROGMEM = {
B00000, B00000,
@ -911,7 +922,8 @@ const uint8_t lcd_chardata_folder[8] PROGMEM = {
B10001, B10001,
B11111, B11111,
B00000, B00000,
B00000}; //thanks joris B00000
}; //thanks joris
/*const uint8_t lcd_chardata_feedrate[8] PROGMEM = { /*const uint8_t lcd_chardata_feedrate[8] PROGMEM = {
B11100, B11100,
@ -951,7 +963,8 @@ const uint8_t lcd_chardata_feedrate[8] PROGMEM = {
B10010, B10010,
B00100, B00100,
B00000, B00000,
B00000}; B00000
};
const uint8_t lcd_chardata_clock[8] PROGMEM = { const uint8_t lcd_chardata_clock[8] PROGMEM = {
B00000, B00000,
@ -961,7 +974,8 @@ const uint8_t lcd_chardata_clock[8] PROGMEM = {
B10001, B10001,
B01110, B01110,
B00000, B00000,
B00000}; //thanks Sonny Mounicou B00000
}; //thanks Sonny Mounicou
const uint8_t lcd_chardata_arrup[8] PROGMEM = { const uint8_t lcd_chardata_arrup[8] PROGMEM = {
B00100, B00100,
@ -971,7 +985,8 @@ const uint8_t lcd_chardata_arrup[8] PROGMEM = {
B00000, B00000,
B00000, B00000,
B00000, B00000,
B00000}; B00000
};
const uint8_t lcd_chardata_arrdown[8] PROGMEM = { const uint8_t lcd_chardata_arrdown[8] PROGMEM = {
B00000, B00000,
@ -981,7 +996,8 @@ const uint8_t lcd_chardata_arrdown[8] PROGMEM = {
B00000, B00000,
B10001, B10001,
B01010, B01010,
B00100}; B00100
};
@ -1012,7 +1028,8 @@ const uint8_t lcd_chardata_progress[8] PROGMEM = {
B11111, B11111,
B11111, B11111,
B11111, B11111,
B11111}; B11111
};
void lcd_set_custom_characters_progress(void) void lcd_set_custom_characters_progress(void)
{ {
@ -1027,7 +1044,8 @@ const uint8_t lcd_chardata_arr2down[8] PROGMEM = {
B00100, B00100,
B10001, B10001,
B01010, B01010,
B00100}; B00100
};
const uint8_t lcd_chardata_confirm[8] PROGMEM = { const uint8_t lcd_chardata_confirm[8] PROGMEM = {
B00000, B00000,
@ -1036,7 +1054,8 @@ const uint8_t lcd_chardata_confirm[8] PROGMEM = {
B10110, B10110,
B11100, B11100,
B01000, B01000,
B00000}; B00000
};
void lcd_set_custom_characters_nextpage(void) void lcd_set_custom_characters_nextpage(void)
{ {

View File

@ -129,7 +129,9 @@ const float bed_ref_points[] PROGMEM = {
#endif //not HEATBED_V2 #endif //not HEATBED_V2
static inline float sqr(float x) { return x * x; } static inline float sqr(float x) {
return x * x;
}
#ifdef HEATBED_V2 #ifdef HEATBED_V2
static inline bool point_on_1st_row(const uint8_t /*i*/) static inline bool point_on_1st_row(const uint8_t /*i*/)
@ -213,10 +215,10 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
verbosity_level verbosity_level
#endif //SUPPORT_VERBOSITY #endif //SUPPORT_VERBOSITY
) )
{ {
float angleDiff; float angleDiff;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) { if (verbosity_level >= 10) {
SERIAL_ECHOLNPGM("calculate machine skew and offset LS"); SERIAL_ECHOLNPGM("calculate machine skew and offset LS");
@ -258,7 +260,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
} }
delay_keep_alive(100); delay_keep_alive(100);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Run some iterations of the Gauss-Newton method of non-linear least squares. // Run some iterations of the Gauss-Newton method of non-linear least squares.
// Initial set of parameters: // Initial set of parameters:
@ -360,7 +362,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
a1 += h[2]; a1 += h[2];
a2 += h[3]; a2 += h[3];
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOPGM("iteration: "); SERIAL_ECHOPGM("iteration: ");
MYSERIAL.print(int(iter)); MYSERIAL.print(int(iter));
@ -384,7 +386,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
MYSERIAL.print(180.f * a2 / M_PI, 5); MYSERIAL.print(180.f * a2 / M_PI, 5);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
vec_x[0] = cos(a1) * MACHINE_AXIS_SCALE_X; vec_x[0] = cos(a1) * MACHINE_AXIS_SCALE_X;
@ -404,7 +406,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
fabs(a2) > bed_skew_angle_extreme) fabs(a2) > bed_skew_angle_extreme)
result = BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME; result = BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME;
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 1) { if (verbosity_level >= 1) {
SERIAL_ECHOPGM("correction angles: "); SERIAL_ECHOPGM("correction angles: ");
MYSERIAL.print(180.f * a1 / M_PI, 5); MYSERIAL.print(180.f * a1 / M_PI, 5);
@ -436,7 +438,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
SERIAL_ECHOLNPGM("Error after correction: "); SERIAL_ECHOLNPGM("Error after correction: ");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Measure the error after correction. // Measure the error after correction.
for (uint8_t i = 0; i < npts; ++i) { for (uint8_t i = 0; i < npts; ++i) {
float x = vec_x[0] * measured_pts[i * 2] + vec_y[0] * measured_pts[i * 2 + 1] + cntr[0]; float x = vec_x[0] * measured_pts[i * 2] + vec_y[0] * measured_pts[i * 2 + 1] + cntr[0];
@ -444,44 +446,44 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
float errX = sqr(pgm_read_float(true_pts + i * 2) - x); float errX = sqr(pgm_read_float(true_pts + i * 2) - x);
float errY = sqr(pgm_read_float(true_pts + i * 2 + 1) - y); float errY = sqr(pgm_read_float(true_pts + i * 2 + 1) - y);
float err = sqrt(errX + errY); float err = sqrt(errX + errY);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) { if (verbosity_level >= 10) {
SERIAL_ECHOPGM("point #"); SERIAL_ECHOPGM("point #");
MYSERIAL.print(int(i)); MYSERIAL.print(int(i));
SERIAL_ECHOLNPGM(":"); SERIAL_ECHOLNPGM(":");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
if (point_on_1st_row(i)) { if (point_on_1st_row(i)) {
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if(verbosity_level >= 20) SERIAL_ECHOPGM("Point on first row"); if(verbosity_level >= 20) SERIAL_ECHOPGM("Point on first row");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
float w = point_weight_y(i, measured_pts[2 * i + 1]); float w = point_weight_y(i, measured_pts[2 * i + 1]);
if (sqrt(errX) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X || if (sqrt(errX) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X ||
(w != 0.f && sqrt(errY) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y)) { (w != 0.f && sqrt(errY) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y)) {
result = BED_SKEW_OFFSET_DETECTION_FITTING_FAILED; result = BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOPGM(", weigth Y: "); SERIAL_ECHOPGM(", weigth Y: ");
MYSERIAL.print(w); MYSERIAL.print(w);
if (sqrt(errX) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X) SERIAL_ECHOPGM(", error X > max. error X"); if (sqrt(errX) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_X) SERIAL_ECHOPGM(", error X > max. error X");
if (w != 0.f && sqrt(errY) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y) SERIAL_ECHOPGM(", error Y > max. error Y"); if (w != 0.f && sqrt(errY) > BED_CALIBRATION_POINT_OFFSET_MAX_1ST_ROW_Y) SERIAL_ECHOPGM(", error Y > max. error Y");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
} }
else { else {
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if(verbosity_level >=20 ) SERIAL_ECHOPGM("Point not on first row"); if(verbosity_level >=20 ) SERIAL_ECHOPGM("Point not on first row");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
if (err > BED_CALIBRATION_POINT_OFFSET_MAX_EUCLIDIAN) { if (err > BED_CALIBRATION_POINT_OFFSET_MAX_EUCLIDIAN) {
result = BED_SKEW_OFFSET_DETECTION_FITTING_FAILED; result = BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if(verbosity_level >= 20) SERIAL_ECHOPGM(", error > max. error euclidian"); if(verbosity_level >= 20) SERIAL_ECHOPGM(", error > max. error euclidian");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) { if (verbosity_level >= 10) {
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
SERIAL_ECHOPGM("measured: ("); SERIAL_ECHOPGM("measured: (");
@ -506,9 +508,9 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOLNPGM("Max. errors:"); SERIAL_ECHOLNPGM("Max. errors:");
SERIAL_ECHOPGM("Max. error X:"); SERIAL_ECHOPGM("Max. error X:");
@ -519,26 +521,26 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
MYSERIAL.println(BED_CALIBRATION_POINT_OFFSET_MAX_EUCLIDIAN); MYSERIAL.println(BED_CALIBRATION_POINT_OFFSET_MAX_EUCLIDIAN);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
#if 0 #if 0
if (result == BED_SKEW_OFFSET_DETECTION_PERFECT && fabs(a1) < bed_skew_angle_mild && fabs(a2) < bed_skew_angle_mild) { if (result == BED_SKEW_OFFSET_DETECTION_PERFECT && fabs(a1) < bed_skew_angle_mild && fabs(a2) < bed_skew_angle_mild) {
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level > 0) if (verbosity_level > 0)
SERIAL_ECHOLNPGM("Very little skew detected. Disabling skew correction."); SERIAL_ECHOLNPGM("Very little skew detected. Disabling skew correction.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Just disable the skew correction. // Just disable the skew correction.
vec_x[0] = MACHINE_AXIS_SCALE_X; vec_x[0] = MACHINE_AXIS_SCALE_X;
vec_x[1] = 0.f; vec_x[1] = 0.f;
vec_y[0] = 0.f; vec_y[0] = 0.f;
vec_y[1] = MACHINE_AXIS_SCALE_Y; vec_y[1] = MACHINE_AXIS_SCALE_Y;
} }
#else #else
if (result == BED_SKEW_OFFSET_DETECTION_PERFECT) { if (result == BED_SKEW_OFFSET_DETECTION_PERFECT) {
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level > 0) if (verbosity_level > 0)
SERIAL_ECHOLNPGM("Very little skew detected. Orthogonalizing the axes."); SERIAL_ECHOLNPGM("Very little skew detected. Orthogonalizing the axes.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Orthogonalize the axes. // Orthogonalize the axes.
a1 = 0.5f * (a1 + a2); a1 = 0.5f * (a1 + a2);
vec_x[0] = cos(a1) * MACHINE_AXIS_SCALE_X; vec_x[0] = cos(a1) * MACHINE_AXIS_SCALE_X;
@ -556,7 +558,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
float w = point_weight_x(i, y); float w = point_weight_x(i, y);
cntr[0] += w * (pgm_read_float(true_pts + i * 2) - x); cntr[0] += w * (pgm_read_float(true_pts + i * 2) - x);
wx += w; wx += w;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
MYSERIAL.print(i); MYSERIAL.print(i);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
@ -569,11 +571,11 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
SERIAL_ECHOLNPGM("wx:"); SERIAL_ECHOLNPGM("wx:");
MYSERIAL.print(wx); MYSERIAL.print(wx);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
w = point_weight_y(i, y); w = point_weight_y(i, y);
cntr[1] += w * (pgm_read_float(true_pts + i * 2 + 1) - y); cntr[1] += w * (pgm_read_float(true_pts + i * 2 + 1) - y);
wy += w; wy += w;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
SERIAL_ECHOLNPGM("Weight_y:"); SERIAL_ECHOLNPGM("Weight_y:");
@ -587,12 +589,12 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
cntr[0] /= wx; cntr[0] /= wx;
cntr[1] /= wy; cntr[1] /= wy;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
SERIAL_ECHOLNPGM("Final cntr values:"); SERIAL_ECHOLNPGM("Final cntr values:");
@ -603,9 +605,9 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
MYSERIAL.print(cntr[1]); MYSERIAL.print(cntr[1]);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
#endif #endif
// Invert the transformation matrix made of vec_x, vec_y and cntr. // Invert the transformation matrix made of vec_x, vec_y and cntr.
{ {
@ -625,7 +627,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
cntr[0] = cntrInv[0]; cntr[0] = cntrInv[0];
cntr[1] = cntrInv[1]; cntr[1] = cntrInv[1];
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 1) { if (verbosity_level >= 1) {
// Show the adjusted state, before the fitting. // Show the adjusted state, before the fitting.
SERIAL_ECHOPGM("X vector, adjusted: "); SERIAL_ECHOPGM("X vector, adjusted: ");
@ -680,7 +682,7 @@ BedSkewOffsetDetectionResultType calculate_machine_skew_and_offset_LS(
} }
delay_keep_alive(100); delay_keep_alive(100);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
return result; return result;
@ -973,9 +975,9 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i
FORCE_HIGH_POWER_START; FORCE_HIGH_POWER_START;
#endif #endif
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if(verbosity_level >= 10) SERIAL_ECHOLNPGM("find bed induction sensor point z"); if(verbosity_level >= 10) SERIAL_ECHOLNPGM("find bed induction sensor point z");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
bool endstops_enabled = enable_endstops(true); bool endstops_enabled = enable_endstops(true);
bool endstop_z_enabled = enable_z_endstop(false); bool endstop_z_enabled = enable_z_endstop(false);
float z = 0.f; float z = 0.f;
@ -1063,9 +1065,9 @@ inline bool find_bed_induction_sensor_point_xy(int
#ifdef NEW_XYZCAL #ifdef NEW_XYZCAL
return xyzcal_find_bed_induction_sensor_point_xy(); return xyzcal_find_bed_induction_sensor_point_xy();
#else //NEW_XYZCAL #else //NEW_XYZCAL
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) MYSERIAL.println("find bed induction sensor point xy"); if (verbosity_level >= 10) MYSERIAL.println("find bed induction sensor point xy");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
float feedrate = homing_feedrate[X_AXIS] / 60.f; float feedrate = homing_feedrate[X_AXIS] / 60.f;
bool found = false; bool found = false;
@ -1078,27 +1080,27 @@ inline bool find_bed_induction_sensor_point_xy(int
uint8_t i; uint8_t i;
if (x0 < X_MIN_POS) { if (x0 < X_MIN_POS) {
x0 = X_MIN_POS; x0 = X_MIN_POS;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius lower than X_MIN. Clamping was done."); if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius lower than X_MIN. Clamping was done.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
if (x1 > X_MAX_POS) { if (x1 > X_MAX_POS) {
x1 = X_MAX_POS; x1 = X_MAX_POS;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius higher than X_MAX. Clamping was done."); if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius higher than X_MAX. Clamping was done.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
if (y0 < Y_MIN_POS_FOR_BED_CALIBRATION) { if (y0 < Y_MIN_POS_FOR_BED_CALIBRATION) {
y0 = Y_MIN_POS_FOR_BED_CALIBRATION; y0 = Y_MIN_POS_FOR_BED_CALIBRATION;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius lower than Y_MIN. Clamping was done."); if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius lower than Y_MIN. Clamping was done.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
if (y1 > Y_MAX_POS) { if (y1 > Y_MAX_POS) {
y1 = Y_MAX_POS; y1 = Y_MAX_POS;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius higher than X_MAX. Clamping was done."); if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius higher than X_MAX. Clamping was done.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
nsteps_y = int(ceil((y1 - y0) / FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP)); nsteps_y = int(ceil((y1 - y0) / FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP));
@ -1158,9 +1160,10 @@ inline bool find_bed_induction_sensor_point_xy(int
goto endloop; goto endloop;
} }
} }
endloop:; endloop:
;
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHO("First hit"); SERIAL_ECHO("First hit");
SERIAL_ECHO("- X: "); SERIAL_ECHO("- X: ");
@ -1170,7 +1173,7 @@ inline bool find_bed_induction_sensor_point_xy(int
SERIAL_ECHO("; Z: "); SERIAL_ECHO("; Z: ");
MYSERIAL.println(current_position[Z_AXIS]); MYSERIAL.println(current_position[Z_AXIS]);
} }
#endif //SUPPORT_VERBOSITY #endif //SUPPORT_VERBOSITY
//lcd_show_fullscreen_message_and_wait_P(PSTR("First hit")); //lcd_show_fullscreen_message_and_wait_P(PSTR("First hit"));
//lcd_update_enable(true); //lcd_update_enable(true);
@ -1253,7 +1256,7 @@ inline bool find_bed_induction_sensor_point_xy(int
current_position[Y_AXIS] = 0.5f * (a + b); current_position[Y_AXIS] = 0.5f * (a + b);
go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 5); go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate / 5);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOPGM("ITERATION: "); SERIAL_ECHOPGM("ITERATION: ");
MYSERIAL.println(iteration); MYSERIAL.println(iteration);
@ -1262,7 +1265,7 @@ inline bool find_bed_induction_sensor_point_xy(int
SERIAL_ECHOPGM("CURRENT POSITION Y: "); SERIAL_ECHOPGM("CURRENT POSITION Y: ");
MYSERIAL.println(current_position[Y_AXIS]); MYSERIAL.println(current_position[Y_AXIS]);
} }
#endif //SUPPORT_VERBOSITY #endif //SUPPORT_VERBOSITY
if (iteration > 0) { if (iteration > 0) {
// Average the last 7 measurements. // Average the last 7 measurements.
@ -1282,21 +1285,21 @@ inline bool find_bed_induction_sensor_point_xy(int
current_position[X_AXIS] = avg[X_AXIS]; current_position[X_AXIS] = avg[X_AXIS];
current_position[Y_AXIS] = avg[Y_AXIS]; current_position[Y_AXIS] = avg[Y_AXIS];
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOPGM("AVG CURRENT POSITION X: "); SERIAL_ECHOPGM("AVG CURRENT POSITION X: ");
MYSERIAL.println(current_position[X_AXIS]); MYSERIAL.println(current_position[X_AXIS]);
SERIAL_ECHOPGM("AVG CURRENT POSITION Y: "); SERIAL_ECHOPGM("AVG CURRENT POSITION Y: ");
MYSERIAL.println(current_position[Y_AXIS]); MYSERIAL.println(current_position[Y_AXIS]);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate); go_xy(current_position[X_AXIS], current_position[Y_AXIS], feedrate);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
lcd_show_fullscreen_message_and_wait_P(PSTR("Final position")); lcd_show_fullscreen_message_and_wait_P(PSTR("Final position"));
lcd_update_enable(true); lcd_update_enable(true);
} }
#endif //SUPPORT_VERBOSITY #endif //SUPPORT_VERBOSITY
break; break;
} }
@ -1313,9 +1316,9 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level)
#ifdef NEW_XYZCAL #ifdef NEW_XYZCAL
return xyzcal_find_bed_induction_sensor_point_xy(); return xyzcal_find_bed_induction_sensor_point_xy();
#else //NEW_XYZCAL #else //NEW_XYZCAL
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) MYSERIAL.println("find bed induction sensor point xy"); if (verbosity_level >= 10) MYSERIAL.println("find bed induction sensor point xy");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
float feedrate = homing_feedrate[X_AXIS] / 60.f; float feedrate = homing_feedrate[X_AXIS] / 60.f;
bool found = false; bool found = false;
@ -1328,27 +1331,27 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level)
uint8_t i; uint8_t i;
if (x0 < X_MIN_POS) { if (x0 < X_MIN_POS) {
x0 = X_MIN_POS; x0 = X_MIN_POS;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius lower than X_MIN. Clamping was done."); if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius lower than X_MIN. Clamping was done.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
if (x1 > X_MAX_POS) { if (x1 > X_MAX_POS) {
x1 = X_MAX_POS; x1 = X_MAX_POS;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius higher than X_MAX. Clamping was done."); if (verbosity_level >= 20) SERIAL_ECHOLNPGM("X searching radius higher than X_MAX. Clamping was done.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
if (y0 < Y_MIN_POS_FOR_BED_CALIBRATION) { if (y0 < Y_MIN_POS_FOR_BED_CALIBRATION) {
y0 = Y_MIN_POS_FOR_BED_CALIBRATION; y0 = Y_MIN_POS_FOR_BED_CALIBRATION;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius lower than Y_MIN. Clamping was done."); if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius lower than Y_MIN. Clamping was done.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
if (y1 > Y_MAX_POS) { if (y1 > Y_MAX_POS) {
y1 = Y_MAX_POS; y1 = Y_MAX_POS;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius higher than X_MAX. Clamping was done."); if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Y searching radius higher than X_MAX. Clamping was done.");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
nsteps_y = int(ceil((y1 - y0) / FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP)); nsteps_y = int(ceil((y1 - y0) / FIND_BED_INDUCTION_SENSOR_POINT_XY_STEP));
@ -1380,7 +1383,7 @@ inline bool find_bed_induction_sensor_point_xy(int verbosity_level)
goto endloop; goto endloop;
} }
} }
endloop: endloop:
// SERIAL_ECHOLN("First hit"); // SERIAL_ECHOLN("First hit");
// we have to let the planner know where we are right now as it is not where we said to go. // we have to let the planner know where we are right now as it is not where we said to go.
@ -1661,13 +1664,13 @@ inline bool improve_bed_induction_sensor_point2(bool lift_z_on_min_y, int8_t ver
} }
b = current_position[X_AXIS]; b = current_position[X_AXIS];
if (b - a < MIN_BED_SENSOR_POINT_RESPONSE_DMR) { if (b - a < MIN_BED_SENSOR_POINT_RESPONSE_DMR) {
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
SERIAL_ECHOPGM("Point width too small: "); SERIAL_ECHOPGM("Point width too small: ");
SERIAL_ECHO(b - a); SERIAL_ECHO(b - a);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// We force the calibration routine to move the Z axis slightly down to make the response more pronounced. // We force the calibration routine to move the Z axis slightly down to make the response more pronounced.
if (b - a < 0.5f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) { if (b - a < 0.5f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) {
// Don't use the new X value. // Don't use the new X value.
@ -1678,12 +1681,12 @@ inline bool improve_bed_induction_sensor_point2(bool lift_z_on_min_y, int8_t ver
point_small = true; point_small = true;
} }
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]);
debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Go to the center. // Go to the center.
enable_z_endstop(false); enable_z_endstop(false);
@ -1736,13 +1739,13 @@ inline bool improve_bed_induction_sensor_point2(bool lift_z_on_min_y, int8_t ver
b = current_position[Y_AXIS]; b = current_position[Y_AXIS];
if (b - a < MIN_BED_SENSOR_POINT_RESPONSE_DMR) { if (b - a < MIN_BED_SENSOR_POINT_RESPONSE_DMR) {
// We force the calibration routine to move the Z axis slightly down to make the response more pronounced. // We force the calibration routine to move the Z axis slightly down to make the response more pronounced.
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
SERIAL_ECHOPGM("Point height too small: "); SERIAL_ECHOPGM("Point height too small: ");
SERIAL_ECHO(b - a); SERIAL_ECHO(b - a);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
if (b - a < 0.5f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) { if (b - a < 0.5f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) {
// Don't use the new Y value. // Don't use the new Y value.
current_position[Y_AXIS] = center_old_y; current_position[Y_AXIS] = center_old_y;
@ -1752,12 +1755,12 @@ inline bool improve_bed_induction_sensor_point2(bool lift_z_on_min_y, int8_t ver
point_small = true; point_small = true;
} }
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
debug_output_point(PSTR("top" ), current_position[X_AXIS], a, current_position[Z_AXIS]); debug_output_point(PSTR("top" ), current_position[X_AXIS], a, current_position[Z_AXIS]);
debug_output_point(PSTR("bottom"), current_position[X_AXIS], b, current_position[Z_AXIS]); debug_output_point(PSTR("bottom"), current_position[X_AXIS], b, current_position[Z_AXIS]);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Go to the center. // Go to the center.
enable_z_endstop(false); enable_z_endstop(false);
@ -1792,9 +1795,9 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
float center_old_y = current_position[Y_AXIS]; float center_old_y = current_position[Y_AXIS];
float a, b; float a, b;
bool result = true; bool result = true;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) MYSERIAL.println("Improve bed induction sensor point3"); if (verbosity_level >= 20) MYSERIAL.println("Improve bed induction sensor point3");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Was the sensor point detected too far in the minus Y axis? // Was the sensor point detected too far in the minus Y axis?
// If yes, the center of the induction point cannot be reached by the machine. // If yes, the center of the induction point cannot be reached by the machine.
{ {
@ -1812,7 +1815,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
y0 = Y_MIN_POS_FOR_BED_CALIBRATION; y0 = Y_MIN_POS_FOR_BED_CALIBRATION;
if (y1 > Y_MAX_POS) if (y1 > Y_MAX_POS)
y1 = Y_MAX_POS; y1 = Y_MAX_POS;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOPGM("Initial position: "); SERIAL_ECHOPGM("Initial position: ");
SERIAL_ECHO(center_old_x); SERIAL_ECHO(center_old_x);
@ -1820,7 +1823,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
SERIAL_ECHO(center_old_y); SERIAL_ECHO(center_old_y);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Search in the positive Y direction, until a maximum diameter is found. // Search in the positive Y direction, until a maximum diameter is found.
// (the next diameter is smaller than the current one.) // (the next diameter is smaller than the current one.)
@ -1852,12 +1855,12 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
// goto canceled; // goto canceled;
} }
b = current_position[X_AXIS]; b = current_position[X_AXIS];
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]);
debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
float d = b - a; float d = b - a;
if (d > dmax) { if (d > dmax) {
xmax1 = 0.5f * (a + b); xmax1 = 0.5f * (a + b);
@ -1868,10 +1871,10 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
} }
} }
if (dmax == 0.) { if (dmax == 0.) {
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level > 0) if (verbosity_level > 0)
SERIAL_PROTOCOLPGM("failed - not found\n"); SERIAL_PROTOCOLPGM("failed - not found\n");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
current_position[X_AXIS] = center_old_x; current_position[X_AXIS] = center_old_x;
current_position[Y_AXIS] = center_old_y; current_position[Y_AXIS] = center_old_y;
goto canceled; goto canceled;
@ -1888,10 +1891,10 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
current_position[Y_AXIS] = center_old_y; current_position[Y_AXIS] = center_old_y;
goto canceled; goto canceled;
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) if (verbosity_level >= 5)
debug_output_point(PSTR("top" ), current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("top" ), current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
y1 = current_position[Y_AXIS]; y1 = current_position[Y_AXIS];
} }
@ -1934,12 +1937,12 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
*/ */
} }
b = current_position[X_AXIS]; b = current_position[X_AXIS];
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]);
debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
float d = b - a; float d = b - a;
if (d > dmax) { if (d > dmax) {
xmax2 = 0.5f * (a + b); xmax2 = 0.5f * (a + b);
@ -1987,12 +1990,12 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
*/ */
} }
b = current_position[X_AXIS]; b = current_position[X_AXIS];
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("left" ), a, current_position[Y_AXIS], current_position[Z_AXIS]);
debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("right"), b, current_position[Y_AXIS], current_position[Z_AXIS]);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
float d = b - a; float d = b - a;
if (d > dmax) { if (d > dmax) {
xmax = 0.5f * (a + b); xmax = 0.5f * (a + b);
@ -2014,28 +2017,28 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
current_position[Y_AXIS] = center_old_y; current_position[Y_AXIS] = center_old_y;
goto canceled; goto canceled;
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) if (verbosity_level >= 5)
debug_output_point(PSTR("top" ), current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]); debug_output_point(PSTR("top" ), current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
if (current_position[Y_AXIS] - Y_MIN_POS_FOR_BED_CALIBRATION < 0.5f * dmax) { if (current_position[Y_AXIS] - Y_MIN_POS_FOR_BED_CALIBRATION < 0.5f * dmax) {
// Probably not even a half circle was detected. The induction point is likely too far in the minus Y direction. // Probably not even a half circle was detected. The induction point is likely too far in the minus Y direction.
// First verify, if the measurement has been done at a sufficient height. If no, lower the Z axis a bit. // First verify, if the measurement has been done at a sufficient height. If no, lower the Z axis a bit.
if (current_position[Y_AXIS] < ymax || dmax < 0.5f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) { if (current_position[Y_AXIS] < ymax || dmax < 0.5f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) {
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
SERIAL_ECHOPGM("Partial point diameter too small: "); SERIAL_ECHOPGM("Partial point diameter too small: ");
SERIAL_ECHO(dmax); SERIAL_ECHO(dmax);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
result = false; result = false;
} else { } else {
// Estimate the circle radius from the maximum diameter and height: // Estimate the circle radius from the maximum diameter and height:
float h = current_position[Y_AXIS] - ymax; float h = current_position[Y_AXIS] - ymax;
float r = dmax * dmax / (8.f * h) + 0.5f * h; float r = dmax * dmax / (8.f * h) + 0.5f * h;
if (r < 0.8f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) { if (r < 0.8f * MIN_BED_SENSOR_POINT_RESPONSE_DMR) {
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
SERIAL_ECHOPGM("Partial point estimated radius too small: "); SERIAL_ECHOPGM("Partial point estimated radius too small: ");
SERIAL_ECHO(r); SERIAL_ECHO(r);
@ -2045,7 +2048,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
SERIAL_ECHO(h); SERIAL_ECHO(h);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
result = false; result = false;
} else { } else {
// The point may end up outside of the machine working space. // The point may end up outside of the machine working space.
@ -2072,7 +2075,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
enable_z_endstop(false); enable_z_endstop(false);
current_position[X_AXIS] = xmax; current_position[X_AXIS] = xmax;
current_position[Y_AXIS] = ymax; current_position[Y_AXIS] = ymax;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOPGM("Adjusted position: "); SERIAL_ECHOPGM("Adjusted position: ");
SERIAL_ECHO(current_position[X_AXIS]); SERIAL_ECHO(current_position[X_AXIS]);
@ -2080,7 +2083,7 @@ inline bool improve_bed_induction_sensor_point3(int verbosity_level)
SERIAL_ECHO(current_position[Y_AXIS]); SERIAL_ECHO(current_position[Y_AXIS]);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Don't clamp current_position[Y_AXIS], because the out-of-reach Y coordinate may actually be true. // Don't clamp current_position[Y_AXIS], because the out-of-reach Y coordinate may actually be true.
// Only clamp the coordinate to go. // Only clamp the coordinate to go.
@ -2178,7 +2181,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
SERIAL_ECHOPGM("Iteration: "); SERIAL_ECHOPGM("Iteration: ");
MYSERIAL.println(int(iteration + 1)); MYSERIAL.println(int(iteration + 1));
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOLNPGM("Vectors: "); SERIAL_ECHOLNPGM("Vectors: ");
@ -2201,7 +2204,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
MYSERIAL.print(cntr[1], 5); MYSERIAL.print(cntr[1], 5);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
#ifdef MESH_BED_CALIBRATION_SHOW_LCD #ifdef MESH_BED_CALIBRATION_SHOW_LCD
uint8_t next_line; uint8_t next_line;
lcd_display_message_fullscreen_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1), next_line); lcd_display_message_fullscreen_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1), next_line);
@ -2228,7 +2231,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
// Go up to z_initial. // Go up to z_initial.
go_to_current(homing_feedrate[Z_AXIS] / 60.f); go_to_current(homing_feedrate[Z_AXIS] / 60.f);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
// Go to Y0, wait, then go to Y-4. // Go to Y0, wait, then go to Y-4.
current_position[Y_AXIS] = 0.f; current_position[Y_AXIS] = 0.f;
@ -2240,7 +2243,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
SERIAL_ECHOLNPGM("At Y-4"); SERIAL_ECHOLNPGM("At Y-4");
delay_keep_alive(5000); delay_keep_alive(5000);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Go to the measurement point position. // Go to the measurement point position.
//if (iteration == 0) { //if (iteration == 0) {
current_position[X_AXIS] = pgm_read_float(bed_ref_points_4 + k * 2); current_position[X_AXIS] = pgm_read_float(bed_ref_points_4 + k * 2);
@ -2258,7 +2261,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
current_position[Y_AXIS] = Y_MIN_POS_FOR_BED_CALIBRATION; current_position[Y_AXIS] = Y_MIN_POS_FOR_BED_CALIBRATION;
}*/ }*/
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOPGM("current_position[X_AXIS]:"); SERIAL_ECHOPGM("current_position[X_AXIS]:");
MYSERIAL.print(current_position[X_AXIS], 5); MYSERIAL.print(current_position[X_AXIS], 5);
@ -2270,13 +2273,13 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
MYSERIAL.print(current_position[Z_AXIS], 5); MYSERIAL.print(current_position[Z_AXIS], 5);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
go_to_current(homing_feedrate[X_AXIS] / 60.f); go_to_current(homing_feedrate[X_AXIS] / 60.f);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) if (verbosity_level >= 10)
delay_keep_alive(3000); delay_keep_alive(3000);
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
if (!find_bed_induction_sensor_point_xy(verbosity_level)) if (!find_bed_induction_sensor_point_xy(verbosity_level))
return BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND; return BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND;
#ifndef NEW_XYZCAL #ifndef NEW_XYZCAL
@ -2303,19 +2306,19 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
} }
#endif //HEATBED_V2 #endif //HEATBED_V2
#endif #endif
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) if (verbosity_level >= 10)
delay_keep_alive(3000); delay_keep_alive(3000);
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Save the detected point position and then clamp the Y coordinate, which may have been estimated // Save the detected point position and then clamp the Y coordinate, which may have been estimated
// to lie outside the machine working space. // to lie outside the machine working space.
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOLNPGM("Measured:"); SERIAL_ECHOLNPGM("Measured:");
MYSERIAL.println(current_position[X_AXIS]); MYSERIAL.println(current_position[X_AXIS]);
MYSERIAL.println(current_position[Y_AXIS]); MYSERIAL.println(current_position[Y_AXIS]);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
pt[0] = (pt[0] * iteration) / (iteration + 1); pt[0] = (pt[0] * iteration) / (iteration + 1);
pt[0] += (current_position[X_AXIS]/(iteration + 1)); //count average pt[0] += (current_position[X_AXIS]/(iteration + 1)); //count average
pt[1] = (pt[1] * iteration) / (iteration + 1); pt[1] = (pt[1] * iteration) / (iteration + 1);
@ -2328,7 +2331,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
//pt[1] += current_position[Y_AXIS]; //pt[1] += current_position[Y_AXIS];
//if (iteration > 0) pt[1] = pt[1] / 2; //if (iteration > 0) pt[1] = pt[1] / 2;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
SERIAL_ECHOPGM("pt[0]:"); SERIAL_ECHOPGM("pt[0]:");
@ -2336,7 +2339,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
SERIAL_ECHOPGM("pt[1]:"); SERIAL_ECHOPGM("pt[1]:");
MYSERIAL.println(pt[1]); MYSERIAL.println(pt[1]);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
if (current_position[Y_AXIS] < Y_MIN_POS) if (current_position[Y_AXIS] < Y_MIN_POS)
current_position[Y_AXIS] = Y_MIN_POS; current_position[Y_AXIS] = Y_MIN_POS;
@ -2344,18 +2347,18 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
current_position[Z_AXIS] += 3.f + FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP * iteration * 0.3; current_position[Z_AXIS] += 3.f + FIND_BED_INDUCTION_SENSOR_POINT_Z_STEP * iteration * 0.3;
//cntr[0] += pt[0]; //cntr[0] += pt[0];
//cntr[1] += pt[1]; //cntr[1] += pt[1];
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10 && k == 0) { if (verbosity_level >= 10 && k == 0) {
// Show the zero. Test, whether the Y motor skipped steps. // Show the zero. Test, whether the Y motor skipped steps.
current_position[Y_AXIS] = MANUAL_Y_HOME_POS; current_position[Y_AXIS] = MANUAL_Y_HOME_POS;
go_to_current(homing_feedrate[X_AXIS] / 60.f); go_to_current(homing_feedrate[X_AXIS] / 60.f);
delay_keep_alive(3000); delay_keep_alive(3000);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
delay_keep_alive(0); //manage_heater, reset watchdog, manage inactivity delay_keep_alive(0); //manage_heater, reset watchdog, manage inactivity
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
// Test the positions. Are the positions reproducible? Now the calibration is active in the planner. // Test the positions. Are the positions reproducible? Now the calibration is active in the planner.
delay_keep_alive(3000); delay_keep_alive(3000);
@ -2370,7 +2373,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
delay_keep_alive(3000); delay_keep_alive(3000);
} }
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
if (pts[1] < Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH) { if (pts[1] < Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH) {
too_far_mask |= 1 << 1; //front center point is out of reach too_far_mask |= 1 << 1; //front center point is out of reach
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
@ -2393,7 +2396,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 0), vec_y[0]); eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 0), vec_y[0]);
eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 4), vec_y[1]); eeprom_update_float((float*)(EEPROM_BED_CALIBRATION_VEC_Y + 4), vec_y[1]);
#endif #endif
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) { if (verbosity_level >= 10) {
// Length of the vec_x // Length of the vec_x
float l = sqrt(vec_x[0] * vec_x[0] + vec_x[1] * vec_x[1]); float l = sqrt(vec_x[0] * vec_x[0] + vec_x[1] * vec_x[1]);
@ -2415,11 +2418,11 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
MYSERIAL.println(fabs(l)); MYSERIAL.println(fabs(l));
SERIAL_ECHOLNPGM("Saving bed calibration vectors to EEPROM"); SERIAL_ECHOLNPGM("Saving bed calibration vectors to EEPROM");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Correct the current_position to match the transformed coordinate system after world2machine_rotation_and_skew and world2machine_shift were set. // Correct the current_position to match the transformed coordinate system after world2machine_rotation_and_skew and world2machine_shift were set.
world2machine_update_current(); world2machine_update_current();
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
// Test the positions. Are the positions reproducible? Now the calibration is active in the planner. // Test the positions. Are the positions reproducible? Now the calibration is active in the planner.
delay_keep_alive(3000); delay_keep_alive(3000);
@ -2434,7 +2437,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level
delay_keep_alive(3000); delay_keep_alive(3000);
} }
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
return result; return result;
} }
if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED && too_far_mask == 2) return result; //if fitting failed and front center point is out of reach, terminate calibration and inform user if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED && too_far_mask == 2) return result; //if fitting failed and front center point is out of reach, terminate calibration and inform user
@ -2459,9 +2462,9 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
float *vec_y = vec_x + 2; float *vec_y = vec_x + 2;
float *cntr = vec_y + 2; float *cntr = vec_y + 2;
memset(pts, 0, sizeof(float) * 7 * 7); memset(pts, 0, sizeof(float) * 7 * 7);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) SERIAL_ECHOLNPGM("Improving bed offset and skew"); if (verbosity_level >= 10) SERIAL_ECHOLNPGM("Improving bed offset and skew");
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Cache the current correction matrix. // Cache the current correction matrix.
world2machine_initialize(); world2machine_initialize();
vec_x[0] = world2machine_rotation_and_skew[0][0]; vec_x[0] = world2machine_rotation_and_skew[0][0];
@ -2500,7 +2503,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
enable_endstops(false); enable_endstops(false);
enable_z_endstop(false); enable_z_endstop(false);
go_to_current(homing_feedrate[Z_AXIS]/60); go_to_current(homing_feedrate[Z_AXIS]/60);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
// Go to Y0, wait, then go to Y-4. // Go to Y0, wait, then go to Y-4.
current_position[Y_AXIS] = 0.f; current_position[Y_AXIS] = 0.f;
@ -2512,40 +2515,40 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
SERIAL_ECHOLNPGM("At Y_MIN_POS"); SERIAL_ECHOLNPGM("At Y_MIN_POS");
delay_keep_alive(5000); delay_keep_alive(5000);
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Go to the measurement point. // Go to the measurement point.
// Use the coorrected coordinate, which is a result of find_bed_offset_and_skew(). // Use the coorrected coordinate, which is a result of find_bed_offset_and_skew().
current_position[X_AXIS] = vec_x[0] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[0] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[0]; current_position[X_AXIS] = vec_x[0] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[0] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[0];
current_position[Y_AXIS] = vec_x[1] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[1]; current_position[Y_AXIS] = vec_x[1] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[1];
// The calibration points are very close to the min Y. // The calibration points are very close to the min Y.
if (current_position[Y_AXIS] < Y_MIN_POS_FOR_BED_CALIBRATION){ if (current_position[Y_AXIS] < Y_MIN_POS_FOR_BED_CALIBRATION) {
current_position[Y_AXIS] = Y_MIN_POS_FOR_BED_CALIBRATION; current_position[Y_AXIS] = Y_MIN_POS_FOR_BED_CALIBRATION;
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOPGM("Calibration point "); SERIAL_ECHOPGM("Calibration point ");
SERIAL_ECHO(mesh_point); SERIAL_ECHO(mesh_point);
SERIAL_ECHOPGM("lower than Ymin. Y coordinate clamping was used."); SERIAL_ECHOPGM("lower than Ymin. Y coordinate clamping was used.");
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
go_to_current(homing_feedrate[X_AXIS]/60); go_to_current(homing_feedrate[X_AXIS]/60);
// Find its Z position by running the normal vertical search. // Find its Z position by running the normal vertical search.
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) if (verbosity_level >= 10)
delay_keep_alive(3000); delay_keep_alive(3000);
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
find_bed_induction_sensor_point_z(); find_bed_induction_sensor_point_z();
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) if (verbosity_level >= 10)
delay_keep_alive(3000); delay_keep_alive(3000);
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
// Try to move the Z axis down a bit to increase a chance of the sensor to trigger. // Try to move the Z axis down a bit to increase a chance of the sensor to trigger.
current_position[Z_AXIS] -= 0.025f; current_position[Z_AXIS] -= 0.025f;
// Improve the point position by searching its center in a current plane. // Improve the point position by searching its center in a current plane.
int8_t n_errors = 3; int8_t n_errors = 3;
for (int8_t iter = 0; iter < 8; ) { for (int8_t iter = 0; iter < 8; ) {
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level > 20) { if (verbosity_level > 20) {
SERIAL_ECHOPGM("Improving bed point "); SERIAL_ECHOPGM("Improving bed point ");
SERIAL_ECHO(mesh_point); SERIAL_ECHO(mesh_point);
@ -2555,7 +2558,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
MYSERIAL.print(current_position[Z_AXIS], 5); MYSERIAL.print(current_position[Z_AXIS], 5);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
bool found = false; bool found = false;
if (mesh_point < 2) { if (mesh_point < 2) {
// Because the sensor cannot move in front of the first row // Because the sensor cannot move in front of the first row
@ -2565,9 +2568,14 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
found = improve_bed_induction_sensor_point3(verbosity_level); found = improve_bed_induction_sensor_point3(verbosity_level);
} else { } else {
switch (method) { switch (method) {
case 0: found = improve_bed_induction_sensor_point(); break; case 0:
case 1: found = improve_bed_induction_sensor_point2(mesh_point < 2, verbosity_level); break; found = improve_bed_induction_sensor_point();
default: break; break;
case 1:
found = improve_bed_induction_sensor_point2(mesh_point < 2, verbosity_level);
break;
default:
break;
} }
} }
if (found) { if (found) {
@ -2589,7 +2597,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
enable_endstops(false); enable_endstops(false);
enable_z_endstop(false); enable_z_endstop(false);
go_to_current(homing_feedrate[Z_AXIS]); go_to_current(homing_feedrate[Z_AXIS]);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
SERIAL_ECHOPGM("Improving bed point "); SERIAL_ECHOPGM("Improving bed point ");
SERIAL_ECHO(mesh_point); SERIAL_ECHO(mesh_point);
@ -2599,13 +2607,13 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
MYSERIAL.print(current_position[Z_AXIS], 5); MYSERIAL.print(current_position[Z_AXIS], 5);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
} }
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 10) if (verbosity_level >= 10)
delay_keep_alive(3000); delay_keep_alive(3000);
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
} }
// Don't let the manage_inactivity() function remove power from the motors. // Don't let the manage_inactivity() function remove power from the motors.
refresh_cmd_timeout(); refresh_cmd_timeout();
@ -2617,7 +2625,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
enable_endstops(false); enable_endstops(false);
enable_z_endstop(false); enable_z_endstop(false);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
// Test the positions. Are the positions reproducible? // Test the positions. Are the positions reproducible?
current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; current_position[Z_AXIS] = MESH_HOME_Z_SEARCH;
@ -2641,7 +2649,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
{ {
// First fill in the too_far_mask from the measured points. // First fill in the too_far_mask from the measured points.
@ -2656,7 +2664,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
// In case of success, update the too_far_mask from the calculated points. // In case of success, update the too_far_mask from the calculated points.
for (uint8_t mesh_point = 0; mesh_point < 2; ++ mesh_point) { for (uint8_t mesh_point = 0; mesh_point < 2; ++ mesh_point) {
float y = vec_x[1] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[1]; float y = vec_x[1] * pgm_read_float(bed_ref_points_4+mesh_point*2) + vec_y[1] * pgm_read_float(bed_ref_points_4+mesh_point*2+1) + cntr[1];
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 20) { if (verbosity_level >= 20) {
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
SERIAL_ECHOPGM("Distance from min:"); SERIAL_ECHOPGM("Distance from min:");
@ -2666,7 +2674,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
MYSERIAL.print(y); MYSERIAL.print(y);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
if (y < Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH) if (y < Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH)
too_far_mask |= 1 << mesh_point; too_far_mask |= 1 << mesh_point;
} }
@ -2688,7 +2696,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
enable_endstops(false); enable_endstops(false);
enable_z_endstop(false); enable_z_endstop(false);
#ifdef SUPPORT_VERBOSITY #ifdef SUPPORT_VERBOSITY
if (verbosity_level >= 5) { if (verbosity_level >= 5) {
// Test the positions. Are the positions reproducible? Now the calibration is active in the planner. // Test the positions. Are the positions reproducible? Now the calibration is active in the planner.
delay_keep_alive(3000); delay_keep_alive(3000);
@ -2717,7 +2725,7 @@ BedSkewOffsetDetectionResultType improve_bed_offset_and_skew(int8_t method, int8
} }
} }
} }
#endif // SUPPORT_VERBOSITY #endif // SUPPORT_VERBOSITY
if(!sample_z()) if(!sample_z())
goto canceled; goto canceled;
@ -2886,7 +2894,7 @@ bool sample_mesh_and_store_reference()
float dif = mbl.z_values[j][i] - mbl.z_values[0][0]; float dif = mbl.z_values[j][i] - mbl.z_values[0][0];
int16_t dif_quantized = int16_t(floor(dif * 100.f + 0.5f)); int16_t dif_quantized = int16_t(floor(dif * 100.f + 0.5f));
eeprom_update_word((uint16_t*)addr, *reinterpret_cast<uint16_t*>(&dif_quantized)); eeprom_update_word((uint16_t*)addr, *reinterpret_cast<uint16_t*>(&dif_quantized));
#if 0 #if 0
{ {
uint16_t z_offset_u = eeprom_read_word((uint16_t*)addr); uint16_t z_offset_u = eeprom_read_word((uint16_t*)addr);
float dif2 = *reinterpret_cast<int16_t*>(&z_offset_u) * 0.01; float dif2 = *reinterpret_cast<int16_t*>(&z_offset_u) * 0.01;
@ -2901,7 +2909,7 @@ bool sample_mesh_and_store_reference()
MYSERIAL.print(dif2, 5); MYSERIAL.print(dif2, 5);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
} }
#endif #endif
addr += 2; addr += 2;
} }
} }
@ -3005,7 +3013,7 @@ void babystep_load()
// End of G80: Apply the baby stepping value. // End of G80: Apply the baby stepping value.
EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ); EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
#if 0 #if 0
SERIAL_ECHO("Z baby step: "); SERIAL_ECHO("Z baby step: ");
SERIAL_ECHO(babystepLoadZ); SERIAL_ECHO(babystepLoadZ);
SERIAL_ECHO(", current Z: "); SERIAL_ECHO(", current Z: ");
@ -3013,7 +3021,7 @@ void babystep_load()
SERIAL_ECHO("correction: "); SERIAL_ECHO("correction: ");
SERIAL_ECHO(float(babystepLoadZ) / float(axis_steps_per_unit[Z_AXIS])); SERIAL_ECHO(float(babystepLoadZ) / float(axis_steps_per_unit[Z_AXIS]));
SERIAL_ECHOLN(""); SERIAL_ECHOLN("");
#endif #endif
} }
} }

View File

@ -6,7 +6,9 @@
mesh_bed_leveling mbl; mesh_bed_leveling mbl;
mesh_bed_leveling::mesh_bed_leveling() { reset(); } mesh_bed_leveling::mesh_bed_leveling() {
reset();
}
void mesh_bed_leveling::reset() { void mesh_bed_leveling::reset() {
active = 0; active = 0;
@ -116,16 +118,16 @@ void mesh_bed_leveling::upsample_3x3()
if (i == idx1) if (i == idx1)
continue; continue;
float x = get_x(i); float x = get_x(i);
#ifdef MBL_BILINEAR #ifdef MBL_BILINEAR
z_values[j][i] = (x < x1) ? z_values[j][i] = (x < x1) ?
((z_values[j][idx0] * (x - x0) + z_values[j][idx1] * (x1 - x)) / (x1 - x0)) : ((z_values[j][idx0] * (x - x0) + z_values[j][idx1] * (x1 - x)) / (x1 - x0)) :
((z_values[j][idx1] * (x - x1) + z_values[j][idx2] * (x2 - x)) / (x2 - x1)); ((z_values[j][idx1] * (x - x1) + z_values[j][idx2] * (x2 - x)) / (x2 - x1));
#else #else
z_values[j][i] = z_values[j][i] =
z_values[j][idx0] * (x - x1) * (x - x2) / ((x0 - x1) * (x0 - x2)) + z_values[j][idx0] * (x - x1) * (x - x2) / ((x0 - x1) * (x0 - x2)) +
z_values[j][idx1] * (x - x0) * (x - x2) / ((x1 - x0) * (x1 - x2)) + z_values[j][idx1] * (x - x0) * (x - x2) / ((x1 - x0) * (x1 - x2)) +
z_values[j][idx2] * (x - x0) * (x - x1) / ((x2 - x0) * (x2 - x1)); z_values[j][idx2] * (x - x0) * (x - x1) / ((x2 - x0) * (x2 - x1));
#endif #endif
} }
} }
} }
@ -143,21 +145,21 @@ void mesh_bed_leveling::upsample_3x3()
if (j == idx1) if (j == idx1)
continue; continue;
float y = get_y(j); float y = get_y(j);
#ifdef MBL_BILINEAR #ifdef MBL_BILINEAR
z_values[j][i] = (y < y1) ? z_values[j][i] = (y < y1) ?
((z_values[idx0][i] * (y - y0) + z_values[idx1][i] * (y1 - y)) / (y1 - y0)) : ((z_values[idx0][i] * (y - y0) + z_values[idx1][i] * (y1 - y)) / (y1 - y0)) :
((z_values[idx1][i] * (y - y1) + z_values[idx2][i] * (y2 - y)) / (y2 - y1)); ((z_values[idx1][i] * (y - y1) + z_values[idx2][i] * (y2 - y)) / (y2 - y1));
#else #else
z_values[j][i] = z_values[j][i] =
z_values[idx0][i] * (y - y1) * (y - y2) / ((y0 - y1) * (y0 - y2)) + z_values[idx0][i] * (y - y1) * (y - y2) / ((y0 - y1) * (y0 - y2)) +
z_values[idx1][i] * (y - y0) * (y - y2) / ((y1 - y0) * (y1 - y2)) + z_values[idx1][i] * (y - y0) * (y - y2) / ((y1 - y0) * (y1 - y2)) +
z_values[idx2][i] * (y - y0) * (y - y1) / ((y2 - y0) * (y2 - y1)); z_values[idx2][i] * (y - y0) * (y - y1) / ((y2 - y0) * (y2 - y1));
#endif #endif
} }
} }
} }
/* /*
// Relax the non-measured points. // Relax the non-measured points.
const float weight = 0.2f; const float weight = 0.2f;
for (uint8_t iter = 0; iter < 20; ++ iter) { for (uint8_t iter = 0; iter < 20; ++ iter) {
@ -172,7 +174,7 @@ void mesh_bed_leveling::upsample_3x3()
} }
} }
} }
*/ */
} }
#endif #endif

View File

@ -21,15 +21,21 @@ public:
void upsample_3x3(); void upsample_3x3();
#endif #endif
static float get_x(int i) { return float(MESH_MIN_X) + float(MESH_X_DIST) * float(i); } static float get_x(int i) {
static float get_y(int i) { return float(MESH_MIN_Y) + float(MESH_Y_DIST) * float(i); } return float(MESH_MIN_X) + float(MESH_X_DIST) * float(i);
}
static float get_y(int i) {
return float(MESH_MIN_Y) + float(MESH_Y_DIST) * float(i);
}
// Measurement point for the Z probe. // Measurement point for the Z probe.
// If use_default=true, then the default positions for a correctly built printer are used. // If use_default=true, then the default positions for a correctly built printer are used.
// Otherwise a correction matrix is pulled from the EEPROM if available. // Otherwise a correction matrix is pulled from the EEPROM if available.
static void get_meas_xy(int ix, int iy, float &x, float &y, bool use_default); static void get_meas_xy(int ix, int iy, float &x, float &y, bool use_default);
void set_z(int ix, int iy, float z) { z_values[iy][ix] = z; } void set_z(int ix, int iy, float z) {
z_values[iy][ix] = z;
}
int select_x_index(float x) { int select_x_index(float x) {
int i = 1; int i = 1;

View File

@ -1268,7 +1268,8 @@ void lcd_mmu_load_to_nozzle(uint8_t filament_nr)
tmp_extruder = filament_nr; tmp_extruder = filament_nr;
lcd_update_enable(false); lcd_update_enable(false);
lcd_clear(); lcd_clear();
lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT)); lcd_set_cursor(0, 1);
lcd_puts_P(_T(MSG_LOADING_FILAMENT));
lcd_print(" "); lcd_print(" ");
lcd_print(tmp_extruder + 1); lcd_print(tmp_extruder + 1);
mmu_command(MMU_CMD_T0 + tmp_extruder); mmu_command(MMU_CMD_T0 + tmp_extruder);

View File

@ -41,8 +41,12 @@ void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8
// CCW angle between position and target from circle center. Only one atan2() trig computation required. // CCW angle between position and target from circle center. Only one atan2() trig computation required.
float angular_travel = atan2(r_axis0*rt_axis1-r_axis1*rt_axis0, r_axis0*rt_axis0+r_axis1*rt_axis1); float angular_travel = atan2(r_axis0*rt_axis1-r_axis1*rt_axis0, r_axis0*rt_axis0+r_axis1*rt_axis1);
if (angular_travel < 0) { angular_travel += 2*M_PI; } if (angular_travel < 0) {
if (isclockwise) { angular_travel -= 2*M_PI; } angular_travel += 2*M_PI;
}
if (isclockwise) {
angular_travel -= 2*M_PI;
}
//20141002:full circle for G03 did not work, e.g. G03 X80 Y80 I20 J0 F2000 is giving an Angle of zero so head is not moving //20141002:full circle for G03 did not work, e.g. G03 X80 Y80 I20 J0 F2000 is giving an Angle of zero so head is not moving
//to compensate when start pos = target pos && angle is zero -> angle = 2Pi //to compensate when start pos = target pos && angle is zero -> angle = 2Pi
@ -53,7 +57,9 @@ void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8
//end fix G03 //end fix G03
float millimeters_of_travel = hypot(angular_travel*radius, fabs(linear_travel)); float millimeters_of_travel = hypot(angular_travel*radius, fabs(linear_travel));
if (millimeters_of_travel < 0.001) { return; } if (millimeters_of_travel < 0.001) {
return;
}
uint16_t segments = floor(millimeters_of_travel/MM_PER_ARC_SEGMENT); uint16_t segments = floor(millimeters_of_travel/MM_PER_ARC_SEGMENT);
if(segments == 0) segments = 1; if(segments == 0) segments = 1;

View File

@ -11,7 +11,7 @@
#define OPTIBOOT_CUSTOMVER 0 #define OPTIBOOT_CUSTOMVER 0
#define OPTIBOOT_MINVER 2 #define OPTIBOOT_MINVER 2
static unsigned const int __attribute__((section(".version"))) static unsigned const int __attribute__((section(".version")))
optiboot_version = 256*(OPTIBOOT_MAJVER + OPTIBOOT_CUSTOMVER) + OPTIBOOT_MINVER; optiboot_version = 256*(OPTIBOOT_MAJVER + OPTIBOOT_CUSTOMVER) + OPTIBOOT_MINVER;
/* Watchdog settings */ /* Watchdog settings */
#define WATCHDOG_OFF (0) #define WATCHDOG_OFF (0)
@ -84,7 +84,8 @@ static void verifySpace() {
} }
static void getNch(uint8_t count) { static void getNch(uint8_t count) {
do getch(); while (--count); do getch();
while (--count);
verifySpace(); verifySpace();
} }

View File

@ -42,44 +42,44 @@
//List of pins which to ignore when asked to change by gcode, 0 and 1 are RX and TX, do not mess with those! //List of pins which to ignore when asked to change by gcode, 0 and 1 are RX and TX, do not mess with those!
#define _E0_PINS E0_STEP_PIN, E0_DIR_PIN, E0_ENABLE_PIN, HEATER_0_PIN, #define _E0_PINS E0_STEP_PIN, E0_DIR_PIN, E0_ENABLE_PIN, HEATER_0_PIN,
#if EXTRUDERS > 1 #if EXTRUDERS > 1
#define _E1_PINS E1_STEP_PIN, E1_DIR_PIN, E1_ENABLE_PIN, HEATER_1_PIN, #define _E1_PINS E1_STEP_PIN, E1_DIR_PIN, E1_ENABLE_PIN, HEATER_1_PIN,
#else #else
#define _E1_PINS #define _E1_PINS
#endif #endif
#if EXTRUDERS > 2 #if EXTRUDERS > 2
#define _E2_PINS E2_STEP_PIN, E2_DIR_PIN, E2_ENABLE_PIN, HEATER_2_PIN, #define _E2_PINS E2_STEP_PIN, E2_DIR_PIN, E2_ENABLE_PIN, HEATER_2_PIN,
#else #else
#define _E2_PINS #define _E2_PINS
#endif #endif
#ifdef X_STOP_PIN #ifdef X_STOP_PIN
#if X_HOME_DIR < 0 #if X_HOME_DIR < 0
#define X_MIN_PIN X_STOP_PIN #define X_MIN_PIN X_STOP_PIN
#define X_MAX_PIN -1 #define X_MAX_PIN -1
#else #else
#define X_MIN_PIN -1 #define X_MIN_PIN -1
#define X_MAX_PIN X_STOP_PIN #define X_MAX_PIN X_STOP_PIN
#endif #endif
#endif #endif
#ifdef Y_STOP_PIN #ifdef Y_STOP_PIN
#if Y_HOME_DIR < 0 #if Y_HOME_DIR < 0
#define Y_MIN_PIN Y_STOP_PIN #define Y_MIN_PIN Y_STOP_PIN
#define Y_MAX_PIN -1 #define Y_MAX_PIN -1
#else #else
#define Y_MIN_PIN -1 #define Y_MIN_PIN -1
#define Y_MAX_PIN Y_STOP_PIN #define Y_MAX_PIN Y_STOP_PIN
#endif #endif
#endif #endif
#ifdef Z_STOP_PIN #ifdef Z_STOP_PIN
#if Z_HOME_DIR < 0 #if Z_HOME_DIR < 0
#define Z_MIN_PIN Z_STOP_PIN #define Z_MIN_PIN Z_STOP_PIN
#define Z_MAX_PIN -1 #define Z_MAX_PIN -1
#else #else
#define Z_MIN_PIN -1 #define Z_MIN_PIN -1
#define Z_MAX_PIN Z_STOP_PIN #define Z_MAX_PIN Z_STOP_PIN
#endif #endif
#endif #endif
#ifdef DISABLE_MAX_ENDSTOPS #ifdef DISABLE_MAX_ENDSTOPS

View File

@ -6,7 +6,7 @@
#define KNOWN_BOARD #define KNOWN_BOARD
#ifndef __AVR_ATmega2560__ #ifndef __AVR_ATmega2560__
#error Oops! Make sure you have 'Arduino Mega 2560 or Rambo' selected from the 'Tools -> Boards' menu. #error Oops! Make sure you have 'Arduino Mega 2560 or Rambo' selected from the 'Tools -> Boards' menu.
#endif #endif
#define TMC2130 #define TMC2130

View File

@ -6,7 +6,7 @@
#define KNOWN_BOARD #define KNOWN_BOARD
#ifndef __AVR_ATmega2560__ #ifndef __AVR_ATmega2560__
#error Oops! Make sure you have 'Arduino Mega 2560 or Rambo' selected from the 'Tools -> Boards' menu. #error Oops! Make sure you have 'Arduino Mega 2560 or Rambo' selected from the 'Tools -> Boards' menu.
#endif #endif
#define PINDA_THERMISTOR #define PINDA_THERMISTOR
@ -65,8 +65,8 @@
#define E0_MS2_PIN 66 #define E0_MS2_PIN 66
#ifdef SNMM #ifdef SNMM
#define E_MUX0_PIN 17 #define E_MUX0_PIN 17
#define E_MUX1_PIN 16 #define E_MUX1_PIN 16
#endif #endif

View File

@ -6,7 +6,7 @@
#define KNOWN_BOARD #define KNOWN_BOARD
#ifndef __AVR_ATmega2560__ #ifndef __AVR_ATmega2560__
#error Oops! Make sure you have 'Arduino Mega 2560 or Rambo' selected from the 'Tools -> Boards' menu. #error Oops! Make sure you have 'Arduino Mega 2560 or Rambo' selected from the 'Tools -> Boards' menu.
#endif #endif
#define PINDA_THERMISTOR #define PINDA_THERMISTOR
@ -65,8 +65,8 @@
#define E0_MS2_PIN 66 #define E0_MS2_PIN 66
#ifdef SNMM #ifdef SNMM
#define E_MUX0_PIN 17 #define E_MUX0_PIN 17
#define E_MUX1_PIN 16 #define E_MUX1_PIN 16
#endif #endif

View File

@ -126,7 +126,7 @@ float extrude_min_temp=EXTRUDE_MINTEMP;
#endif #endif
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
float extruder_advance_k = LIN_ADVANCE_K, float extruder_advance_k = LIN_ADVANCE_K,
advance_ed_ratio = LIN_ADVANCE_E_D_RATIO, advance_ed_ratio = LIN_ADVANCE_E_D_RATIO,
position_float[NUM_AXIS] = { 0 }; position_float[NUM_AXIS] = { 0 };
#endif #endif
@ -441,7 +441,7 @@ void plan_init() {
void getHighESpeed() void getHighESpeed()
{ {
static float oldt=0; static float oldt=0;
if(!autotemp_enabled){ if(!autotemp_enabled) {
return; return;
} }
if(degTargetHotend0()+2<autotemp_min) { //probably temperature set to zero. if(degTargetHotend0()+2<autotemp_min) { //probably temperature set to zero.
@ -530,7 +530,7 @@ void check_axes_activity()
disable_e2(); disable_e2();
} }
#if defined(FAN_PIN) && FAN_PIN > -1 #if defined(FAN_PIN) && FAN_PIN > -1
#ifdef FAN_KICKSTART_TIME #ifdef FAN_KICKSTART_TIME
static unsigned long fan_kick_end; static unsigned long fan_kick_end;
if (tail_fan_speed) { if (tail_fan_speed) {
if (fan_kick_end == 0) { if (fan_kick_end == 0) {
@ -543,12 +543,12 @@ void check_axes_activity()
} else { } else {
fan_kick_end = 0; fan_kick_end = 0;
} }
#endif//FAN_KICKSTART_TIME #endif//FAN_KICKSTART_TIME
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
fanSpeedSoftPwm = tail_fan_speed; fanSpeedSoftPwm = tail_fan_speed;
#else #else
analogWrite(FAN_PIN,tail_fan_speed); analogWrite(FAN_PIN,tail_fan_speed);
#endif//!FAN_SOFT_PWM #endif//!FAN_SOFT_PWM
#endif//FAN_PIN > -1 #endif//FAN_PIN > -1
#ifdef AUTOTEMP #ifdef AUTOTEMP
getHighESpeed(); getHighESpeed();
@ -683,7 +683,7 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate
// Apply the machine correction matrix. // Apply the machine correction matrix.
{ {
#if 0 #if 0
SERIAL_ECHOPGM("Planner, current position - servos: "); SERIAL_ECHOPGM("Planner, current position - servos: ");
MYSERIAL.print(st_get_position_mm(X_AXIS), 5); MYSERIAL.print(st_get_position_mm(X_AXIS), 5);
SERIAL_ECHOPGM(", "); SERIAL_ECHOPGM(", ");
@ -712,17 +712,17 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate
SERIAL_ECHOPGM(", "); SERIAL_ECHOPGM(", ");
MYSERIAL.print(world2machine_shift[1], 5); MYSERIAL.print(world2machine_shift[1], 5);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
#endif #endif
world2machine(x, y); world2machine(x, y);
#if 0 #if 0
SERIAL_ECHOPGM("Planner, target position, corrected: "); SERIAL_ECHOPGM("Planner, target position, corrected: ");
MYSERIAL.print(x, 5); MYSERIAL.print(x, 5);
SERIAL_ECHOPGM(", "); SERIAL_ECHOPGM(", ");
MYSERIAL.print(y, 5); MYSERIAL.print(y, 5);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
#endif #endif
} }
// The target position of the tool in absolute steps // The target position of the tool in absolute steps
@ -732,9 +732,9 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate
target[X_AXIS] = lround(x*cs.axis_steps_per_unit[X_AXIS]); target[X_AXIS] = lround(x*cs.axis_steps_per_unit[X_AXIS]);
target[Y_AXIS] = lround(y*cs.axis_steps_per_unit[Y_AXIS]); target[Y_AXIS] = lround(y*cs.axis_steps_per_unit[Y_AXIS]);
#ifdef MESH_BED_LEVELING #ifdef MESH_BED_LEVELING
if (mbl.active){ if (mbl.active) {
target[Z_AXIS] = lround((z+mbl.get_z(x, y))*cs.axis_steps_per_unit[Z_AXIS]); target[Z_AXIS] = lround((z+mbl.get_z(x, y))*cs.axis_steps_per_unit[Z_AXIS]);
}else{ } else {
target[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]); target[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]);
} }
#else #else
@ -747,7 +747,7 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate
float de_float = e - position_float[E_AXIS]; float de_float = e - position_float[E_AXIS];
#endif #endif
#ifdef PREVENT_DANGEROUS_EXTRUDE #ifdef PREVENT_DANGEROUS_EXTRUDE
if(target[E_AXIS]!=position[E_AXIS]) if(target[E_AXIS]!=position[E_AXIS])
{ {
if(degHotend(active_extruder)<extrude_min_temp) if(degHotend(active_extruder)<extrude_min_temp)
@ -761,7 +761,7 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate
SERIAL_ECHOLNRPGM(_i(" cold extrusion prevented"));////MSG_ERR_COLD_EXTRUDE_STOP c=0 r=0 SERIAL_ECHOLNRPGM(_i(" cold extrusion prevented"));////MSG_ERR_COLD_EXTRUDE_STOP c=0 r=0
} }
#ifdef PREVENT_LENGTHY_EXTRUDE #ifdef PREVENT_LENGTHY_EXTRUDE
if(labs(target[E_AXIS]-position[E_AXIS])>cs.axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH) if(labs(target[E_AXIS]-position[E_AXIS])>cs.axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH)
{ {
position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part
@ -772,9 +772,9 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNRPGM(_n(" too long extrusion prevented"));////MSG_ERR_LONG_EXTRUDE_STOP c=0 r=0 SERIAL_ECHOLNRPGM(_n(" too long extrusion prevented"));////MSG_ERR_LONG_EXTRUDE_STOP c=0 r=0
} }
#endif #endif
} }
#endif #endif
// Prepare to set up new block // Prepare to set up new block
block_t *block = &block_buffer[block_buffer_head]; block_t *block = &block_buffer[block_buffer_head];
@ -788,13 +788,13 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate
// Number of steps for each axis // Number of steps for each axis
#ifndef COREXY #ifndef COREXY
// default non-h-bot planning // default non-h-bot planning
block->steps_x.wide = labs(target[X_AXIS]-position[X_AXIS]); block->steps_x.wide = labs(target[X_AXIS]-position[X_AXIS]);
block->steps_y.wide = labs(target[Y_AXIS]-position[Y_AXIS]); block->steps_y.wide = labs(target[Y_AXIS]-position[Y_AXIS]);
#else #else
// corexy planning // corexy planning
// these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html // these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html
block->steps_x.wide = labs((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS])); block->steps_x.wide = labs((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS]));
block->steps_y.wide = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS])); block->steps_y.wide = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]));
#endif #endif
block->steps_z.wide = labs(target[Z_AXIS]-position[Z_AXIS]); block->steps_z.wide = labs(target[Z_AXIS]-position[Z_AXIS]);
block->steps_e.wide = labs(target[E_AXIS]-position[E_AXIS]); block->steps_e.wide = labs(target[E_AXIS]-position[E_AXIS]);
@ -844,16 +844,16 @@ block->steps_y.wide = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-p
block->active_extruder = extruder; block->active_extruder = extruder;
//enable active axes //enable active axes
#ifdef COREXY #ifdef COREXY
if((block->steps_x.wide != 0) || (block->steps_y.wide != 0)) if((block->steps_x.wide != 0) || (block->steps_y.wide != 0))
{ {
enable_x(); enable_x();
enable_y(); enable_y();
} }
#else #else
if(block->steps_x.wide != 0) enable_x(); if(block->steps_x.wide != 0) enable_x();
if(block->steps_y.wide != 0) enable_y(); if(block->steps_y.wide != 0) enable_y();
#endif #endif
if(block->steps_z.wide != 0) enable_z(); if(block->steps_z.wide != 0) enable_z();
// Enable extruder(s) // Enable extruder(s)
@ -872,22 +872,34 @@ block->steps_y.wide = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-p
enable_e0(); enable_e0();
g_uc_extruder_last_move[0] = BLOCK_BUFFER_SIZE*2; g_uc_extruder_last_move[0] = BLOCK_BUFFER_SIZE*2;
if(g_uc_extruder_last_move[1] == 0) {disable_e1();} if(g_uc_extruder_last_move[1] == 0) {
if(g_uc_extruder_last_move[2] == 0) {disable_e2();} disable_e1();
}
if(g_uc_extruder_last_move[2] == 0) {
disable_e2();
}
break; break;
case 1: case 1:
enable_e1(); enable_e1();
g_uc_extruder_last_move[1] = BLOCK_BUFFER_SIZE*2; g_uc_extruder_last_move[1] = BLOCK_BUFFER_SIZE*2;
if(g_uc_extruder_last_move[0] == 0) {disable_e0();} if(g_uc_extruder_last_move[0] == 0) {
if(g_uc_extruder_last_move[2] == 0) {disable_e2();} disable_e0();
}
if(g_uc_extruder_last_move[2] == 0) {
disable_e2();
}
break; break;
case 2: case 2:
enable_e2(); enable_e2();
g_uc_extruder_last_move[2] = BLOCK_BUFFER_SIZE*2; g_uc_extruder_last_move[2] = BLOCK_BUFFER_SIZE*2;
if(g_uc_extruder_last_move[0] == 0) {disable_e0();} if(g_uc_extruder_last_move[0] == 0) {
if(g_uc_extruder_last_move[1] == 0) {disable_e1();} disable_e0();
}
if(g_uc_extruder_last_move[1] == 0) {
disable_e1();
}
break; break;
} }
} }
@ -908,24 +920,24 @@ block->steps_y.wide = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-p
if(feed_rate<cs.minimumfeedrate) feed_rate=cs.minimumfeedrate; if(feed_rate<cs.minimumfeedrate) feed_rate=cs.minimumfeedrate;
} }
/* This part of the code calculates the total length of the movement. /* This part of the code calculates the total length of the movement.
For cartesian bots, the X_AXIS is the real X movement and same for Y_AXIS. For cartesian bots, the X_AXIS is the real X movement and same for Y_AXIS.
But for corexy bots, that is not true. The "X_AXIS" and "Y_AXIS" motors (that should be named to A_AXIS But for corexy bots, that is not true. The "X_AXIS" and "Y_AXIS" motors (that should be named to A_AXIS
and B_AXIS) cannot be used for X and Y length, because A=X+Y and B=X-Y. and B_AXIS) cannot be used for X and Y length, because A=X+Y and B=X-Y.
So we need to create other 2 "AXIS", named X_HEAD and Y_HEAD, meaning the real displacement of the Head. So we need to create other 2 "AXIS", named X_HEAD and Y_HEAD, meaning the real displacement of the Head.
Having the real displacement of the head, we can calculate the total movement length and apply the desired speed. Having the real displacement of the head, we can calculate the total movement length and apply the desired speed.
*/ */
#ifndef COREXY #ifndef COREXY
float delta_mm[4]; float delta_mm[4];
delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/cs.axis_steps_per_unit[X_AXIS]; delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/cs.axis_steps_per_unit[X_AXIS];
delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/cs.axis_steps_per_unit[Y_AXIS]; delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/cs.axis_steps_per_unit[Y_AXIS];
#else #else
float delta_mm[6]; float delta_mm[6];
delta_mm[X_HEAD] = (target[X_AXIS]-position[X_AXIS])/cs.axis_steps_per_unit[X_AXIS]; delta_mm[X_HEAD] = (target[X_AXIS]-position[X_AXIS])/cs.axis_steps_per_unit[X_AXIS];
delta_mm[Y_HEAD] = (target[Y_AXIS]-position[Y_AXIS])/cs.axis_steps_per_unit[Y_AXIS]; delta_mm[Y_HEAD] = (target[Y_AXIS]-position[Y_AXIS])/cs.axis_steps_per_unit[Y_AXIS];
delta_mm[X_AXIS] = ((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS]))/cs.axis_steps_per_unit[X_AXIS]; delta_mm[X_AXIS] = ((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS]))/cs.axis_steps_per_unit[X_AXIS];
delta_mm[Y_AXIS] = ((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]))/cs.axis_steps_per_unit[Y_AXIS]; delta_mm[Y_AXIS] = ((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]))/cs.axis_steps_per_unit[Y_AXIS];
#endif #endif
delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/cs.axis_steps_per_unit[Z_AXIS]; delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/cs.axis_steps_per_unit[Z_AXIS];
delta_mm[E_AXIS] = (target[E_AXIS]-position[E_AXIS])/cs.axis_steps_per_unit[E_AXIS]; delta_mm[E_AXIS] = (target[E_AXIS]-position[E_AXIS])/cs.axis_steps_per_unit[E_AXIS];
if ( block->steps_x.wide <=dropsegments && block->steps_y.wide <=dropsegments && block->steps_z.wide <=dropsegments ) if ( block->steps_x.wide <=dropsegments && block->steps_y.wide <=dropsegments && block->steps_z.wide <=dropsegments )
@ -934,11 +946,11 @@ Having the real displacement of the head, we can calculate the total movement le
} }
else else
{ {
#ifndef COREXY #ifndef COREXY
block->millimeters = sqrt(square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS])); block->millimeters = sqrt(square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS]));
#else #else
block->millimeters = sqrt(square(delta_mm[X_HEAD]) + square(delta_mm[Y_HEAD]) + square(delta_mm[Z_AXIS])); block->millimeters = sqrt(square(delta_mm[X_HEAD]) + square(delta_mm[Y_HEAD]) + square(delta_mm[Z_AXIS]));
#endif #endif
} }
float inverse_millimeters = 1.0/block->millimeters; // Inverse millimeters to remove multiple divides float inverse_millimeters = 1.0/block->millimeters; // Inverse millimeters to remove multiple divides
@ -1002,13 +1014,25 @@ Having the real displacement of the head, we can calculate the total movement le
// Limit acceleration per axis // Limit acceleration per axis
//FIXME Vojtech: One shall rather limit a projection of the acceleration vector instead of using the limit. //FIXME Vojtech: One shall rather limit a projection of the acceleration vector instead of using the limit.
if(((float)block->acceleration_st * (float)block->steps_x.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[X_AXIS]) if(((float)block->acceleration_st * (float)block->steps_x.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[X_AXIS])
{ block->acceleration_st = axis_steps_per_sqr_second[X_AXIS]; maxlimit_status |= (X_AXIS_MASK << 4); } {
block->acceleration_st = axis_steps_per_sqr_second[X_AXIS];
maxlimit_status |= (X_AXIS_MASK << 4);
}
if(((float)block->acceleration_st * (float)block->steps_y.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[Y_AXIS]) if(((float)block->acceleration_st * (float)block->steps_y.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[Y_AXIS])
{ block->acceleration_st = axis_steps_per_sqr_second[Y_AXIS]; maxlimit_status |= (Y_AXIS_MASK << 4); } {
block->acceleration_st = axis_steps_per_sqr_second[Y_AXIS];
maxlimit_status |= (Y_AXIS_MASK << 4);
}
if(((float)block->acceleration_st * (float)block->steps_e.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[E_AXIS]) if(((float)block->acceleration_st * (float)block->steps_e.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[E_AXIS])
{ block->acceleration_st = axis_steps_per_sqr_second[E_AXIS]; maxlimit_status |= (Z_AXIS_MASK << 4); } {
block->acceleration_st = axis_steps_per_sqr_second[E_AXIS];
maxlimit_status |= (Z_AXIS_MASK << 4);
}
if(((float)block->acceleration_st * (float)block->steps_z.wide / (float)block->step_event_count.wide ) > axis_steps_per_sqr_second[Z_AXIS]) if(((float)block->acceleration_st * (float)block->steps_z.wide / (float)block->step_event_count.wide ) > axis_steps_per_sqr_second[Z_AXIS])
{ block->acceleration_st = axis_steps_per_sqr_second[Z_AXIS]; maxlimit_status |= (E_AXIS_MASK << 4); } {
block->acceleration_st = axis_steps_per_sqr_second[Z_AXIS];
maxlimit_status |= (E_AXIS_MASK << 4);
}
} }
// Acceleration of the segment, in mm/sec^2 // Acceleration of the segment, in mm/sec^2
block->acceleration = block->acceleration_st / steps_per_mm; block->acceleration = block->acceleration_st / steps_per_mm;
@ -1276,18 +1300,18 @@ void plan_set_position(float x, float y, float z, const float &e)
// Only useful in the bed leveling routine, when the mesh bed leveling is off. // Only useful in the bed leveling routine, when the mesh bed leveling is off.
void plan_set_z_position(const float &z) void plan_set_z_position(const float &z)
{ {
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
position_float[Z_AXIS] = z; position_float[Z_AXIS] = z;
#endif #endif
position[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]); position[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]);
st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]); st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]);
} }
void plan_set_e_position(const float &e) void plan_set_e_position(const float &e)
{ {
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
position_float[E_AXIS] = e; position_float[E_AXIS] = e;
#endif #endif
position[E_AXIS] = lround(e*cs.axis_steps_per_unit[E_AXIS]); position[E_AXIS] = lround(e*cs.axis_steps_per_unit[E_AXIS]);
st_set_e_position(position[E_AXIS]); st_set_e_position(position[E_AXIS]);
} }

View File

@ -120,7 +120,7 @@ typedef struct {
} block_t; } block_t;
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
extern float extruder_advance_k, advance_ed_ratio; extern float extruder_advance_k, advance_ed_ratio;
#endif #endif
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
@ -171,10 +171,10 @@ extern uint8_t maxlimit_status;
#ifdef AUTOTEMP #ifdef AUTOTEMP
extern bool autotemp_enabled; extern bool autotemp_enabled;
extern float autotemp_max; extern float autotemp_max;
extern float autotemp_min; extern float autotemp_min;
extern float autotemp_factor; extern float autotemp_factor;
#endif #endif

View File

@ -379,10 +379,10 @@ void daxpy ( int n, double da, double dx[], int incx, double dy[], int incy )
{ {
return; return;
} }
/* /*
Code for unequal increments or equal increments Code for unequal increments or equal increments
not equal to 1. not equal to 1.
*/ */
if ( incx != 1 || incy != 1 ) if ( incx != 1 || incy != 1 )
{ {
if ( 0 <= incx ) if ( 0 <= incx )
@ -410,9 +410,9 @@ void daxpy ( int n, double da, double dx[], int incx, double dy[], int incy )
iy = iy + incy; iy = iy + incy;
} }
} }
/* /*
Code for both increments equal to 1. Code for both increments equal to 1.
*/ */
else else
{ {
m = n % 4; m = n % 4;
@ -498,10 +498,10 @@ double ddot ( int n, double dx[], int incx, double dy[], int incy )
{ {
return dtemp; return dtemp;
} }
/* /*
Code for unequal increments or equal increments Code for unequal increments or equal increments
not equal to 1. not equal to 1.
*/ */
if ( incx != 1 || incy != 1 ) if ( incx != 1 || incy != 1 )
{ {
if ( 0 <= incx ) if ( 0 <= incx )
@ -529,9 +529,9 @@ double ddot ( int n, double dx[], int incx, double dy[], int incy )
iy = iy + incy; iy = iy + incy;
} }
} }
/* /*
Code for both increments equal to 1. Code for both increments equal to 1.
*/ */
else else
{ {
m = n % 5; m = n % 5;
@ -853,9 +853,9 @@ void dqrdc ( double a[], int lda, int n, int p, double qraux[], int jpvt[],
pl = 1; pl = 1;
pu = 0; pu = 0;
/* /*
If pivoting is requested, rearrange the columns. If pivoting is requested, rearrange the columns.
*/ */
if ( job != 0 ) if ( job != 0 )
{ {
for ( j = 1; j <= p; j++ ) for ( j = 1; j <= p; j++ )
@ -901,9 +901,9 @@ void dqrdc ( double a[], int lda, int n, int p, double qraux[], int jpvt[],
} }
} }
} }
/* /*
Compute the norms of the free columns. Compute the norms of the free columns.
*/ */
for ( j = pl; j <= pu; j++ ) for ( j = pl; j <= pu; j++ )
{ {
qraux[j-1] = dnrm2 ( n, a+0+(j-1)*lda, 1 ); qraux[j-1] = dnrm2 ( n, a+0+(j-1)*lda, 1 );
@ -913,16 +913,16 @@ void dqrdc ( double a[], int lda, int n, int p, double qraux[], int jpvt[],
{ {
work[j-1] = qraux[j-1]; work[j-1] = qraux[j-1];
} }
/* /*
Perform the Householder reduction of A. Perform the Householder reduction of A.
*/ */
lup = i4_min ( n, p ); lup = i4_min ( n, p );
for ( l = 1; l <= lup; l++ ) for ( l = 1; l <= lup; l++ )
{ {
/* /*
Bring the column of largest norm into the pivot position. Bring the column of largest norm into the pivot position.
*/ */
if ( pl <= l && l < pu ) if ( pl <= l && l < pu )
{ {
maxnrm = 0.0; maxnrm = 0.0;
@ -946,9 +946,9 @@ void dqrdc ( double a[], int lda, int n, int p, double qraux[], int jpvt[],
jpvt[l-1] = jp; jpvt[l-1] = jp;
} }
} }
/* /*
Compute the Householder transformation for column L. Compute the Householder transformation for column L.
*/ */
qraux[l-1] = 0.0; qraux[l-1] = 0.0;
if ( l != n ) if ( l != n )
@ -964,9 +964,9 @@ void dqrdc ( double a[], int lda, int n, int p, double qraux[], int jpvt[],
dscal ( n-l+1, 1.0 / nrmxl, a+l-1+(l-1)*lda, 1 ); dscal ( n-l+1, 1.0 / nrmxl, a+l-1+(l-1)*lda, 1 );
a[l-1+(l-1)*lda] = 1.0 + a[l-1+(l-1)*lda]; a[l-1+(l-1)*lda] = 1.0 + a[l-1+(l-1)*lda];
/* /*
Apply the transformation to the remaining columns, updating the norms. Apply the transformation to the remaining columns, updating the norms.
*/ */
for ( j = l + 1; j <= p; j++ ) for ( j = l + 1; j <= p; j++ )
{ {
t = -ddot ( n-l+1, a+l-1+(l-1)*lda, 1, a+l-1+(j-1)*lda, 1 ) t = -ddot ( n-l+1, a+l-1+(l-1)*lda, 1, a+l-1+(j-1)*lda, 1 )
@ -994,9 +994,9 @@ void dqrdc ( double a[], int lda, int n, int p, double qraux[], int jpvt[],
} }
} }
} }
/* /*
Save the transformation. Save the transformation.
*/ */
qraux[l-1] = a[l-1+(l-1)*lda]; qraux[l-1] = a[l-1+(l-1)*lda];
a[l-1+(l-1)*lda] = -nrmxl; a[l-1+(l-1)*lda] = -nrmxl;
} }
@ -1144,16 +1144,16 @@ int dqrls ( double a[], int lda, int m, int n, double tol, int *kr, double b[],
} }
ind = 0; ind = 0;
/* /*
Factor the matrix. Factor the matrix.
*/ */
if ( itask == 1 ) if ( itask == 1 )
{ {
dqrank ( a, lda, m, n, tol, kr, jpvt, qraux ); dqrank ( a, lda, m, n, tol, kr, jpvt, qraux );
} }
/* /*
Solve the least-squares problem. Solve the least-squares problem.
*/ */
dqrlss ( a, lda, m, n, *kr, b, x, rsd, jpvt, qraux ); dqrlss ( a, lda, m, n, *kr, b, x, rsd, jpvt, qraux );
return ind; return ind;
@ -1429,13 +1429,13 @@ int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[],
int ju; int ju;
double t; double t;
double temp; double temp;
/* /*
Set INFO flag. Set INFO flag.
*/ */
info = 0; info = 0;
/* /*
Determine what is to be computed. Determine what is to be computed.
*/ */
cqy = ( job / 10000 != 0 ); cqy = ( job / 10000 != 0 );
cqty = ( ( job % 10000 ) != 0 ); cqty = ( ( job % 10000 ) != 0 );
cb = ( ( job % 1000 ) / 100 != 0 ); cb = ( ( job % 1000 ) / 100 != 0 );
@ -1443,9 +1443,9 @@ int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[],
cab = ( ( job % 10 ) != 0 ); cab = ( ( job % 10 ) != 0 );
ju = i4_min ( k, n-1 ); ju = i4_min ( k, n-1 );
/* /*
Special action when N = 1. Special action when N = 1.
*/ */
if ( ju == 0 ) if ( ju == 0 )
{ {
if ( cqy ) if ( cqy )
@ -1481,9 +1481,9 @@ int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[],
} }
return info; return info;
} }
/* /*
Set up to compute QY or QTY. Set up to compute QY or QTY.
*/ */
if ( cqy ) if ( cqy )
{ {
for ( i = 1; i <= n; i++ ) for ( i = 1; i <= n; i++ )
@ -1499,9 +1499,9 @@ int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[],
qty[i-1] = y[i-1]; qty[i-1] = y[i-1];
} }
} }
/* /*
Compute QY. Compute QY.
*/ */
if ( cqy ) if ( cqy )
{ {
for ( jj = 1; jj <= ju; jj++ ) for ( jj = 1; jj <= ju; jj++ )
@ -1518,9 +1518,9 @@ int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[],
} }
} }
} }
/* /*
Compute Q'*Y. Compute Q'*Y.
*/ */
if ( cqty ) if ( cqty )
{ {
for ( j = 1; j <= ju; j++ ) for ( j = 1; j <= ju; j++ )
@ -1535,9 +1535,9 @@ int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[],
} }
} }
} }
/* /*
Set up to compute B, RSD, or AB. Set up to compute B, RSD, or AB.
*/ */
if ( cb ) if ( cb )
{ {
for ( i = 1; i <= k; i++ ) for ( i = 1; i <= k; i++ )
@ -1577,9 +1577,9 @@ int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[],
rsd[i-1] = 0.0; rsd[i-1] = 0.0;
} }
} }
/* /*
Compute B. Compute B.
*/ */
if ( cb ) if ( cb )
{ {
for ( jj = 1; jj <= k; jj++ ) for ( jj = 1; jj <= k; jj++ )
@ -1601,9 +1601,9 @@ int dqrsl ( double a[], int lda, int n, int k, double qraux[], double y[],
} }
} }
} }
/* /*
Compute RSD or AB as required. Compute RSD or AB as required.
*/ */
if ( cr || cab ) if ( cr || cab )
{ {
for ( jj = 1; jj <= ju; jj++ ) for ( jj = 1; jj <= ju; jj++ )

View File

@ -50,15 +50,23 @@ uint8_t sm4_get_dir(uint8_t axis)
switch (axis) switch (axis)
{ {
#if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3)) #if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3))
case 0: return (PORTL & 2)?0:1; case 0:
case 1: return (PORTL & 1)?0:1; return (PORTL & 2)?0:1;
case 2: return (PORTL & 4)?0:1; case 1:
case 3: return (PORTL & 64)?1:0; return (PORTL & 1)?0:1;
case 2:
return (PORTL & 4)?0:1;
case 3:
return (PORTL & 64)?1:0;
#elif ((MOTHERBOARD == BOARD_EINSY_1_0a)) #elif ((MOTHERBOARD == BOARD_EINSY_1_0a))
case 0: return (PORTL & 1)?1:0; case 0:
case 1: return (PORTL & 2)?0:1; return (PORTL & 1)?1:0;
case 2: return (PORTL & 4)?1:0; case 1:
case 3: return (PORTL & 64)?0:1; return (PORTL & 2)?0:1;
case 2:
return (PORTL & 4)?1:0;
case 3:
return (PORTL & 64)?0:1;
#endif #endif
} }
return 0; return 0;
@ -69,15 +77,39 @@ void sm4_set_dir(uint8_t axis, uint8_t dir)
switch (axis) switch (axis)
{ {
#if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3)) #if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3))
case 0: if (!dir) PORTL |= 2; else PORTL &= ~2; break; case 0:
case 1: if (!dir) PORTL |= 1; else PORTL &= ~1; break; if (!dir) PORTL |= 2;
case 2: if (!dir) PORTL |= 4; else PORTL &= ~4; break; else PORTL &= ~2;
case 3: if (dir) PORTL |= 64; else PORTL &= ~64; break; break;
case 1:
if (!dir) PORTL |= 1;
else PORTL &= ~1;
break;
case 2:
if (!dir) PORTL |= 4;
else PORTL &= ~4;
break;
case 3:
if (dir) PORTL |= 64;
else PORTL &= ~64;
break;
#elif ((MOTHERBOARD == BOARD_EINSY_1_0a)) #elif ((MOTHERBOARD == BOARD_EINSY_1_0a))
case 0: if (dir) PORTL |= 1; else PORTL &= ~1; break; case 0:
case 1: if (!dir) PORTL |= 2; else PORTL &= ~2; break; if (dir) PORTL |= 1;
case 2: if (dir) PORTL |= 4; else PORTL &= ~4; break; else PORTL &= ~1;
case 3: if (!dir) PORTL |= 64; else PORTL &= ~64; break; break;
case 1:
if (!dir) PORTL |= 2;
else PORTL &= ~2;
break;
case 2:
if (dir) PORTL |= 4;
else PORTL &= ~4;
break;
case 3:
if (!dir) PORTL |= 64;
else PORTL &= ~64;
break;
#endif #endif
} }
asm("nop"); asm("nop");

View File

@ -21,26 +21,26 @@ static void Sound_DoSound_Alert(bool bOnce);
void Sound_Init(void) void Sound_Init(void)
{ {
SET_OUTPUT(BEEPER); SET_OUTPUT(BEEPER);
eSoundMode=(eSOUND_MODE)eeprom_read_byte((uint8_t*)EEPROM_SOUND_MODE); eSoundMode=(eSOUND_MODE)eeprom_read_byte((uint8_t*)EEPROM_SOUND_MODE);
if(eSoundMode==e_SOUND_MODE_NULL) if(eSoundMode==e_SOUND_MODE_NULL)
Sound_Default(); // je potreba provest i ulozeni do EEPROM Sound_Default(); // je potreba provest i ulozeni do EEPROM
} }
void Sound_Default(void) void Sound_Default(void)
{ {
eSoundMode=e_SOUND_MODE_DEFAULT; eSoundMode=e_SOUND_MODE_DEFAULT;
Sound_SaveMode(); Sound_SaveMode();
} }
void Sound_SaveMode(void) void Sound_SaveMode(void)
{ {
eeprom_update_byte((uint8_t*)EEPROM_SOUND_MODE,(uint8_t)eSoundMode); eeprom_update_byte((uint8_t*)EEPROM_SOUND_MODE,(uint8_t)eSoundMode);
} }
void Sound_CycleState(void) void Sound_CycleState(void)
{ {
switch(eSoundMode) switch(eSoundMode)
{ {
case e_SOUND_MODE_LOUD: case e_SOUND_MODE_LOUD:
eSoundMode=e_SOUND_MODE_ONCE; eSoundMode=e_SOUND_MODE_ONCE;
@ -57,12 +57,12 @@ switch(eSoundMode)
default: default:
eSoundMode=e_SOUND_MODE_LOUD; eSoundMode=e_SOUND_MODE_LOUD;
} }
Sound_SaveMode(); Sound_SaveMode();
} }
void Sound_MakeSound(eSOUND_TYPE eSoundType) void Sound_MakeSound(eSOUND_TYPE eSoundType)
{ {
switch(eSoundMode) switch(eSoundMode)
{ {
case e_SOUND_MODE_LOUD: case e_SOUND_MODE_LOUD:
if(eSoundType==e_SOUND_TYPE_ButtonEcho) if(eSoundType==e_SOUND_TYPE_ButtonEcho)
@ -94,9 +94,9 @@ switch(eSoundMode)
static void Sound_DoSound_Echo(void) static void Sound_DoSound_Echo(void)
{ {
uint8_t nI; uint8_t nI;
for(nI=0;nI<10;nI++) for(nI=0; nI<10; nI++)
{ {
WRITE(BEEPER,HIGH); WRITE(BEEPER,HIGH);
delayMicroseconds(100); delayMicroseconds(100);
@ -107,17 +107,17 @@ for(nI=0;nI<10;nI++)
static void Sound_DoSound_Prompt(void) static void Sound_DoSound_Prompt(void)
{ {
WRITE(BEEPER,HIGH); WRITE(BEEPER,HIGH);
delay_keep_alive(500); delay_keep_alive(500);
WRITE(BEEPER,LOW); WRITE(BEEPER,LOW);
} }
static void Sound_DoSound_Alert(bool bOnce) static void Sound_DoSound_Alert(bool bOnce)
{ {
uint8_t nI,nMax; uint8_t nI,nMax;
nMax=bOnce?1:3; nMax=bOnce?1:3;
for(nI=0;nI<nMax;nI++) for(nI=0; nI<nMax; nI++)
{ {
WRITE(BEEPER,HIGH); WRITE(BEEPER,HIGH);
delay_keep_alive(200); delay_keep_alive(200);

View File

@ -10,13 +10,13 @@
#define e_SOUND_MODE_NULL 0xFF #define e_SOUND_MODE_NULL 0xFF
typedef enum typedef enum
{e_SOUND_MODE_LOUD,e_SOUND_MODE_ONCE,e_SOUND_MODE_SILENT,e_SOUND_MODE_MUTE} eSOUND_MODE; {e_SOUND_MODE_LOUD,e_SOUND_MODE_ONCE,e_SOUND_MODE_SILENT,e_SOUND_MODE_MUTE} eSOUND_MODE;
#define e_SOUND_MODE_DEFAULT e_SOUND_MODE_LOUD #define e_SOUND_MODE_DEFAULT e_SOUND_MODE_LOUD
typedef enum typedef enum
{e_SOUND_TYPE_ButtonEcho,e_SOUND_TYPE_EncoderEcho,e_SOUND_TYPE_StandardPrompt,e_SOUND_TYPE_StandardConfirm,e_SOUND_TYPE_StandardWarning,e_SOUND_TYPE_StandardAlert} eSOUND_TYPE; {e_SOUND_TYPE_ButtonEcho,e_SOUND_TYPE_EncoderEcho,e_SOUND_TYPE_StandardPrompt,e_SOUND_TYPE_StandardConfirm,e_SOUND_TYPE_StandardWarning,e_SOUND_TYPE_StandardAlert} eSOUND_TYPE;
typedef enum typedef enum
{e_SOUND_CLASS_Echo,e_SOUND_CLASS_Prompt,e_SOUND_CLASS_Confirm,e_SOUND_CLASS_Warning,e_SOUND_CLASS_Alert} eSOUND_CLASS; {e_SOUND_CLASS_Echo,e_SOUND_CLASS_Prompt,e_SOUND_CLASS_Confirm,e_SOUND_CLASS_Warning,e_SOUND_CLASS_Alert} eSOUND_CLASS;
extern eSOUND_MODE eSoundMode; extern eSOUND_MODE eSoundMode;

View File

@ -6,73 +6,73 @@
#if F_CPU == 16000000 #if F_CPU == 16000000
const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {\ const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {\
{ 62500, 55556}, { 6944, 3268}, { 3676, 1176}, { 2500, 607}, { 1893, 369}, { 1524, 249}, { 1275, 179}, { 1096, 135}, { 62500, 55556}, { 6944, 3268}, { 3676, 1176}, { 2500, 607}, { 1893, 369}, { 1524, 249}, { 1275, 179}, { 1096, 135},
{ 961, 105}, { 856, 85}, { 771, 69}, { 702, 58}, { 644, 49}, { 595, 42}, { 553, 37}, { 516, 32}, { 961, 105}, { 856, 85}, { 771, 69}, { 702, 58}, { 644, 49}, { 595, 42}, { 553, 37}, { 516, 32},
{ 484, 28}, { 456, 25}, { 431, 23}, { 408, 20}, { 388, 19}, { 369, 16}, { 353, 16}, { 337, 14}, { 484, 28}, { 456, 25}, { 431, 23}, { 408, 20}, { 388, 19}, { 369, 16}, { 353, 16}, { 337, 14},
{ 323, 13}, { 310, 11}, { 299, 11}, { 288, 11}, { 277, 9}, { 268, 9}, { 259, 8}, { 251, 8}, { 323, 13}, { 310, 11}, { 299, 11}, { 288, 11}, { 277, 9}, { 268, 9}, { 259, 8}, { 251, 8},
{ 243, 8}, { 235, 7}, { 228, 6}, { 222, 6}, { 216, 6}, { 210, 6}, { 204, 5}, { 199, 5}, { 243, 8}, { 235, 7}, { 228, 6}, { 222, 6}, { 216, 6}, { 210, 6}, { 204, 5}, { 199, 5},
{ 194, 5}, { 189, 4}, { 185, 4}, { 181, 4}, { 177, 4}, { 173, 4}, { 169, 4}, { 165, 3}, { 194, 5}, { 189, 4}, { 185, 4}, { 181, 4}, { 177, 4}, { 173, 4}, { 169, 4}, { 165, 3},
{ 162, 3}, { 159, 4}, { 155, 3}, { 152, 3}, { 149, 2}, { 147, 3}, { 144, 3}, { 141, 2}, { 162, 3}, { 159, 4}, { 155, 3}, { 152, 3}, { 149, 2}, { 147, 3}, { 144, 3}, { 141, 2},
{ 139, 3}, { 136, 2}, { 134, 2}, { 132, 3}, { 129, 2}, { 127, 2}, { 125, 2}, { 123, 2}, { 139, 3}, { 136, 2}, { 134, 2}, { 132, 3}, { 129, 2}, { 127, 2}, { 125, 2}, { 123, 2},
{ 121, 2}, { 119, 1}, { 118, 2}, { 116, 2}, { 114, 1}, { 113, 2}, { 111, 2}, { 109, 1}, { 121, 2}, { 119, 1}, { 118, 2}, { 116, 2}, { 114, 1}, { 113, 2}, { 111, 2}, { 109, 1},
{ 108, 2}, { 106, 1}, { 105, 2}, { 103, 1}, { 102, 1}, { 101, 1}, { 100, 2}, { 98, 1}, { 108, 2}, { 106, 1}, { 105, 2}, { 103, 1}, { 102, 1}, { 101, 1}, { 100, 2}, { 98, 1},
{ 97, 1}, { 96, 1}, { 95, 2}, { 93, 1}, { 92, 1}, { 91, 1}, { 90, 1}, { 89, 1}, { 97, 1}, { 96, 1}, { 95, 2}, { 93, 1}, { 92, 1}, { 91, 1}, { 90, 1}, { 89, 1},
{ 88, 1}, { 87, 1}, { 86, 1}, { 85, 1}, { 84, 1}, { 83, 0}, { 83, 1}, { 82, 1}, { 88, 1}, { 87, 1}, { 86, 1}, { 85, 1}, { 84, 1}, { 83, 0}, { 83, 1}, { 82, 1},
{ 81, 1}, { 80, 1}, { 79, 1}, { 78, 0}, { 78, 1}, { 77, 1}, { 76, 1}, { 75, 0}, { 81, 1}, { 80, 1}, { 79, 1}, { 78, 0}, { 78, 1}, { 77, 1}, { 76, 1}, { 75, 0},
{ 75, 1}, { 74, 1}, { 73, 1}, { 72, 0}, { 72, 1}, { 71, 1}, { 70, 0}, { 70, 1}, { 75, 1}, { 74, 1}, { 73, 1}, { 72, 0}, { 72, 1}, { 71, 1}, { 70, 0}, { 70, 1},
{ 69, 0}, { 69, 1}, { 68, 1}, { 67, 0}, { 67, 1}, { 66, 0}, { 66, 1}, { 65, 0}, { 69, 0}, { 69, 1}, { 68, 1}, { 67, 0}, { 67, 1}, { 66, 0}, { 66, 1}, { 65, 0},
{ 65, 1}, { 64, 1}, { 63, 0}, { 63, 1}, { 62, 0}, { 62, 1}, { 61, 0}, { 61, 1}, { 65, 1}, { 64, 1}, { 63, 0}, { 63, 1}, { 62, 0}, { 62, 1}, { 61, 0}, { 61, 1},
{ 60, 0}, { 60, 0}, { 60, 1}, { 59, 0}, { 59, 1}, { 58, 0}, { 58, 1}, { 57, 0}, { 60, 0}, { 60, 0}, { 60, 1}, { 59, 0}, { 59, 1}, { 58, 0}, { 58, 1}, { 57, 0},
{ 57, 1}, { 56, 0}, { 56, 0}, { 56, 1}, { 55, 0}, { 55, 1}, { 54, 0}, { 54, 0}, { 57, 1}, { 56, 0}, { 56, 0}, { 56, 1}, { 55, 0}, { 55, 1}, { 54, 0}, { 54, 0},
{ 54, 1}, { 53, 0}, { 53, 0}, { 53, 1}, { 52, 0}, { 52, 0}, { 52, 1}, { 51, 0}, { 54, 1}, { 53, 0}, { 53, 0}, { 53, 1}, { 52, 0}, { 52, 0}, { 52, 1}, { 51, 0},
{ 51, 0}, { 51, 1}, { 50, 0}, { 50, 0}, { 50, 1}, { 49, 0}, { 49, 0}, { 49, 1}, { 51, 0}, { 51, 1}, { 50, 0}, { 50, 0}, { 50, 1}, { 49, 0}, { 49, 0}, { 49, 1},
{ 48, 0}, { 48, 0}, { 48, 1}, { 47, 0}, { 47, 0}, { 47, 0}, { 47, 1}, { 46, 0}, { 48, 0}, { 48, 0}, { 48, 1}, { 47, 0}, { 47, 0}, { 47, 0}, { 47, 1}, { 46, 0},
{ 46, 0}, { 46, 1}, { 45, 0}, { 45, 0}, { 45, 0}, { 45, 1}, { 44, 0}, { 44, 0}, { 46, 0}, { 46, 1}, { 45, 0}, { 45, 0}, { 45, 0}, { 45, 1}, { 44, 0}, { 44, 0},
{ 44, 0}, { 44, 1}, { 43, 0}, { 43, 0}, { 43, 0}, { 43, 1}, { 42, 0}, { 42, 0}, { 44, 0}, { 44, 1}, { 43, 0}, { 43, 0}, { 43, 0}, { 43, 1}, { 42, 0}, { 42, 0},
{ 42, 0}, { 42, 1}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 1}, { 40, 0}, { 42, 0}, { 42, 1}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 1}, { 40, 0},
{ 40, 0}, { 40, 0}, { 40, 0}, { 40, 1}, { 39, 0}, { 39, 0}, { 39, 0}, { 39, 0}, { 40, 0}, { 40, 0}, { 40, 0}, { 40, 1}, { 39, 0}, { 39, 0}, { 39, 0}, { 39, 0},
{ 39, 1}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 1}, { 37, 0}, { 37, 0}, { 39, 1}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 1}, { 37, 0}, { 37, 0},
{ 37, 0}, { 37, 0}, { 37, 0}, { 37, 1}, { 36, 0}, { 36, 0}, { 36, 0}, { 36, 0}, { 37, 0}, { 37, 0}, { 37, 0}, { 37, 1}, { 36, 0}, { 36, 0}, { 36, 0}, { 36, 0},
{ 36, 1}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 1}, { 36, 1}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 1},
{ 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 1}, { 33, 0}, { 33, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 1}, { 33, 0}, { 33, 0},
{ 33, 0}, { 33, 0}, { 33, 0}, { 33, 0}, { 33, 1}, { 32, 0}, { 32, 0}, { 32, 0}, { 33, 0}, { 33, 0}, { 33, 0}, { 33, 0}, { 33, 1}, { 32, 0}, { 32, 0}, { 32, 0},
{ 32, 0}, { 32, 0}, { 32, 0}, { 32, 0}, { 32, 1}, { 31, 0}, { 31, 0}, { 31, 0}, { 32, 0}, { 32, 0}, { 32, 0}, { 32, 0}, { 32, 1}, { 31, 0}, { 31, 0}, { 31, 0},
{ 31, 0}, { 31, 0}, { 31, 0}, { 31, 1}, { 30, 0}, { 30, 0}, { 30, 0}, { 30, 0} { 31, 0}, { 31, 0}, { 31, 0}, { 31, 1}, { 30, 0}, { 30, 0}, { 30, 0}, { 30, 0}
}; };
const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {\ const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {\
{ 62500, 12500}, { 50000, 8334}, { 41666, 5952}, { 35714, 4464}, { 31250, 3473}, { 27777, 2777}, { 25000, 2273}, { 22727, 1894}, { 62500, 12500}, { 50000, 8334}, { 41666, 5952}, { 35714, 4464}, { 31250, 3473}, { 27777, 2777}, { 25000, 2273}, { 22727, 1894},
{ 20833, 1603}, { 19230, 1373}, { 17857, 1191}, { 16666, 1041}, { 15625, 920}, { 14705, 817}, { 13888, 731}, { 13157, 657}, { 20833, 1603}, { 19230, 1373}, { 17857, 1191}, { 16666, 1041}, { 15625, 920}, { 14705, 817}, { 13888, 731}, { 13157, 657},
{ 12500, 596}, { 11904, 541}, { 11363, 494}, { 10869, 453}, { 10416, 416}, { 10000, 385}, { 9615, 356}, { 9259, 331}, { 12500, 596}, { 11904, 541}, { 11363, 494}, { 10869, 453}, { 10416, 416}, { 10000, 385}, { 9615, 356}, { 9259, 331},
{ 8928, 308}, { 8620, 287}, { 8333, 269}, { 8064, 252}, { 7812, 237}, { 7575, 223}, { 7352, 210}, { 7142, 198}, { 8928, 308}, { 8620, 287}, { 8333, 269}, { 8064, 252}, { 7812, 237}, { 7575, 223}, { 7352, 210}, { 7142, 198},
{ 6944, 188}, { 6756, 178}, { 6578, 168}, { 6410, 160}, { 6250, 153}, { 6097, 145}, { 5952, 139}, { 5813, 132}, { 6944, 188}, { 6756, 178}, { 6578, 168}, { 6410, 160}, { 6250, 153}, { 6097, 145}, { 5952, 139}, { 5813, 132},
{ 5681, 126}, { 5555, 121}, { 5434, 115}, { 5319, 111}, { 5208, 106}, { 5102, 102}, { 5000, 99}, { 4901, 94}, { 5681, 126}, { 5555, 121}, { 5434, 115}, { 5319, 111}, { 5208, 106}, { 5102, 102}, { 5000, 99}, { 4901, 94},
{ 4807, 91}, { 4716, 87}, { 4629, 84}, { 4545, 81}, { 4464, 79}, { 4385, 75}, { 4310, 73}, { 4237, 71}, { 4807, 91}, { 4716, 87}, { 4629, 84}, { 4545, 81}, { 4464, 79}, { 4385, 75}, { 4310, 73}, { 4237, 71},
{ 4166, 68}, { 4098, 66}, { 4032, 64}, { 3968, 62}, { 3906, 60}, { 3846, 59}, { 3787, 56}, { 3731, 55}, { 4166, 68}, { 4098, 66}, { 4032, 64}, { 3968, 62}, { 3906, 60}, { 3846, 59}, { 3787, 56}, { 3731, 55},
{ 3676, 53}, { 3623, 52}, { 3571, 50}, { 3521, 49}, { 3472, 48}, { 3424, 46}, { 3378, 45}, { 3333, 44}, { 3676, 53}, { 3623, 52}, { 3571, 50}, { 3521, 49}, { 3472, 48}, { 3424, 46}, { 3378, 45}, { 3333, 44},
{ 3289, 43}, { 3246, 41}, { 3205, 41}, { 3164, 39}, { 3125, 39}, { 3086, 38}, { 3048, 36}, { 3012, 36}, { 3289, 43}, { 3246, 41}, { 3205, 41}, { 3164, 39}, { 3125, 39}, { 3086, 38}, { 3048, 36}, { 3012, 36},
{ 2976, 35}, { 2941, 35}, { 2906, 33}, { 2873, 33}, { 2840, 32}, { 2808, 31}, { 2777, 30}, { 2747, 30}, { 2976, 35}, { 2941, 35}, { 2906, 33}, { 2873, 33}, { 2840, 32}, { 2808, 31}, { 2777, 30}, { 2747, 30},
{ 2717, 29}, { 2688, 29}, { 2659, 28}, { 2631, 27}, { 2604, 27}, { 2577, 26}, { 2551, 26}, { 2525, 25}, { 2717, 29}, { 2688, 29}, { 2659, 28}, { 2631, 27}, { 2604, 27}, { 2577, 26}, { 2551, 26}, { 2525, 25},
{ 2500, 25}, { 2475, 25}, { 2450, 23}, { 2427, 24}, { 2403, 23}, { 2380, 22}, { 2358, 22}, { 2336, 22}, { 2500, 25}, { 2475, 25}, { 2450, 23}, { 2427, 24}, { 2403, 23}, { 2380, 22}, { 2358, 22}, { 2336, 22},
{ 2314, 21}, { 2293, 21}, { 2272, 20}, { 2252, 20}, { 2232, 20}, { 2212, 20}, { 2192, 19}, { 2173, 18}, { 2314, 21}, { 2293, 21}, { 2272, 20}, { 2252, 20}, { 2232, 20}, { 2212, 20}, { 2192, 19}, { 2173, 18},
{ 2155, 19}, { 2136, 18}, { 2118, 18}, { 2100, 17}, { 2083, 17}, { 2066, 17}, { 2049, 17}, { 2032, 16}, { 2155, 19}, { 2136, 18}, { 2118, 18}, { 2100, 17}, { 2083, 17}, { 2066, 17}, { 2049, 17}, { 2032, 16},
{ 2016, 16}, { 2000, 16}, { 1984, 16}, { 1968, 15}, { 1953, 16}, { 1937, 14}, { 1923, 15}, { 1908, 15}, { 2016, 16}, { 2000, 16}, { 1984, 16}, { 1968, 15}, { 1953, 16}, { 1937, 14}, { 1923, 15}, { 1908, 15},
{ 1893, 14}, { 1879, 14}, { 1865, 14}, { 1851, 13}, { 1838, 14}, { 1824, 13}, { 1811, 13}, { 1798, 13}, { 1893, 14}, { 1879, 14}, { 1865, 14}, { 1851, 13}, { 1838, 14}, { 1824, 13}, { 1811, 13}, { 1798, 13},
{ 1785, 12}, { 1773, 13}, { 1760, 12}, { 1748, 12}, { 1736, 12}, { 1724, 12}, { 1712, 12}, { 1700, 11}, { 1785, 12}, { 1773, 13}, { 1760, 12}, { 1748, 12}, { 1736, 12}, { 1724, 12}, { 1712, 12}, { 1700, 11},
{ 1689, 12}, { 1677, 11}, { 1666, 11}, { 1655, 11}, { 1644, 11}, { 1633, 10}, { 1623, 11}, { 1612, 10}, { 1689, 12}, { 1677, 11}, { 1666, 11}, { 1655, 11}, { 1644, 11}, { 1633, 10}, { 1623, 11}, { 1612, 10},
{ 1602, 10}, { 1592, 10}, { 1582, 10}, { 1572, 10}, { 1562, 10}, { 1552, 9}, { 1543, 10}, { 1533, 9}, { 1602, 10}, { 1592, 10}, { 1582, 10}, { 1572, 10}, { 1562, 10}, { 1552, 9}, { 1543, 10}, { 1533, 9},
{ 1524, 9}, { 1515, 9}, { 1506, 9}, { 1497, 9}, { 1488, 9}, { 1479, 9}, { 1470, 9}, { 1461, 8}, { 1524, 9}, { 1515, 9}, { 1506, 9}, { 1497, 9}, { 1488, 9}, { 1479, 9}, { 1470, 9}, { 1461, 8},
{ 1453, 8}, { 1445, 9}, { 1436, 8}, { 1428, 8}, { 1420, 8}, { 1412, 8}, { 1404, 8}, { 1396, 8}, { 1453, 8}, { 1445, 9}, { 1436, 8}, { 1428, 8}, { 1420, 8}, { 1412, 8}, { 1404, 8}, { 1396, 8},
{ 1388, 7}, { 1381, 8}, { 1373, 7}, { 1366, 8}, { 1358, 7}, { 1351, 7}, { 1344, 8}, { 1336, 7}, { 1388, 7}, { 1381, 8}, { 1373, 7}, { 1366, 8}, { 1358, 7}, { 1351, 7}, { 1344, 8}, { 1336, 7},
{ 1329, 7}, { 1322, 7}, { 1315, 7}, { 1308, 6}, { 1302, 7}, { 1295, 7}, { 1288, 6}, { 1282, 7}, { 1329, 7}, { 1322, 7}, { 1315, 7}, { 1308, 6}, { 1302, 7}, { 1295, 7}, { 1288, 6}, { 1282, 7},
{ 1275, 6}, { 1269, 7}, { 1262, 6}, { 1256, 6}, { 1250, 7}, { 1243, 6}, { 1237, 6}, { 1231, 6}, { 1275, 6}, { 1269, 7}, { 1262, 6}, { 1256, 6}, { 1250, 7}, { 1243, 6}, { 1237, 6}, { 1231, 6},
{ 1225, 6}, { 1219, 6}, { 1213, 6}, { 1207, 6}, { 1201, 5}, { 1196, 6}, { 1190, 6}, { 1184, 5}, { 1225, 6}, { 1219, 6}, { 1213, 6}, { 1207, 6}, { 1201, 5}, { 1196, 6}, { 1190, 6}, { 1184, 5},
{ 1179, 6}, { 1173, 5}, { 1168, 6}, { 1162, 5}, { 1157, 5}, { 1152, 6}, { 1146, 5}, { 1141, 5}, { 1179, 6}, { 1173, 5}, { 1168, 6}, { 1162, 5}, { 1157, 5}, { 1152, 6}, { 1146, 5}, { 1141, 5},
{ 1136, 5}, { 1131, 5}, { 1126, 5}, { 1121, 5}, { 1116, 5}, { 1111, 5}, { 1106, 5}, { 1101, 5}, { 1136, 5}, { 1131, 5}, { 1126, 5}, { 1121, 5}, { 1116, 5}, { 1111, 5}, { 1106, 5}, { 1101, 5},
{ 1096, 5}, { 1091, 5}, { 1086, 4}, { 1082, 5}, { 1077, 5}, { 1072, 4}, { 1068, 5}, { 1063, 4}, { 1096, 5}, { 1091, 5}, { 1086, 4}, { 1082, 5}, { 1077, 5}, { 1072, 4}, { 1068, 5}, { 1063, 4},
{ 1059, 5}, { 1054, 4}, { 1050, 4}, { 1046, 5}, { 1041, 4}, { 1037, 4}, { 1033, 5}, { 1028, 4}, { 1059, 5}, { 1054, 4}, { 1050, 4}, { 1046, 5}, { 1041, 4}, { 1037, 4}, { 1033, 5}, { 1028, 4},
{ 1024, 4}, { 1020, 4}, { 1016, 4}, { 1012, 4}, { 1008, 4}, { 1004, 4}, { 1000, 4}, { 996, 4}, { 1024, 4}, { 1020, 4}, { 1016, 4}, { 1012, 4}, { 1008, 4}, { 1004, 4}, { 1000, 4}, { 996, 4},
{ 992, 4}, { 988, 4}, { 984, 4}, { 980, 4}, { 976, 4}, { 972, 4}, { 968, 3}, { 965, 3} { 992, 4}, { 988, 4}, { 984, 4}, { 980, 4}, { 976, 4}, { 972, 4}, { 968, 3}, { 965, 3}
}; };
#elif F_CPU == 20000000 #elif F_CPU == 20000000

View File

@ -9,14 +9,14 @@
// These can't be used after statements in c89. // These can't be used after statements in c89.
#ifdef __COUNTER__ #ifdef __COUNTER__
#define static_assert(e,m) \ #define static_assert(e,m) \
;enum { ASSERT_CONCAT(STATIC_ASSERT_, __COUNTER__) = 1/(int)(!!(e)) } ;enum { ASSERT_CONCAT(STATIC_ASSERT_, __COUNTER__) = 1/(int)(!!(e)) }
#else #else
//This can't be used twice on the same line so ensure if using in headers //This can't be used twice on the same line so ensure if using in headers
//that the headers are not included twice (by wrapping in #ifndef...#endif) //that the headers are not included twice (by wrapping in #ifndef...#endif)
//Note it doesn't cause an issue when used on same line of separate modules //Note it doesn't cause an issue when used on same line of separate modules
//compiled with gcc -combine -fwhole-program. //compiled with gcc -combine -fwhole-program.
#define static_assert(e,m) \ #define static_assert(e,m) \
;enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(int)(!!(e)) } ;enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(int)(!!(e)) }
#endif //__COUNTER__ #endif //__COUNTER__

View File

@ -66,10 +66,10 @@ bool z_max_endstop = false;
// Variables used by The Stepper Driver Interrupt // Variables used by The Stepper Driver Interrupt
static unsigned char out_bits; // The next stepping-bits to be output static unsigned char out_bits; // The next stepping-bits to be output
static dda_isteps_t static dda_isteps_t
counter_x, // Counter variables for the bresenham line tracer counter_x, // Counter variables for the bresenham line tracer
counter_y, counter_y,
counter_z, counter_z,
counter_e; counter_e;
volatile dda_usteps_t step_events_completed; // The number of step events executed in the current block volatile dda_usteps_t step_events_completed; // The number of step events executed in the current block
static int32_t acceleration_time, deceleration_time; static int32_t acceleration_time, deceleration_time;
//static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate; //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
@ -78,7 +78,7 @@ static uint8_t step_loops;
static uint16_t OCR1A_nominal; static uint16_t OCR1A_nominal;
static uint8_t step_loops_nominal; static uint8_t step_loops_nominal;
volatile long endstops_trigsteps[3]={0,0,0}; volatile long endstops_trigsteps[3]= {0,0,0};
volatile long endstops_stepsTotal,endstops_stepsDone; volatile long endstops_stepsTotal,endstops_stepsDone;
static volatile bool endstop_x_hit=false; static volatile bool endstop_x_hit=false;
static volatile bool endstop_y_hit=false; static volatile bool endstop_y_hit=false;
@ -87,9 +87,9 @@ static volatile bool endstop_z_hit=false;
bool abort_on_endstop_hit = false; bool abort_on_endstop_hit = false;
#endif #endif
#ifdef MOTOR_CURRENT_PWM_XY_PIN #ifdef MOTOR_CURRENT_PWM_XY_PIN
int motor_current_setting[3] = DEFAULT_PWM_MOTOR_CURRENT; int motor_current_setting[3] = DEFAULT_PWM_MOTOR_CURRENT;
int motor_current_setting_silent[3] = DEFAULT_PWM_MOTOR_CURRENT; int motor_current_setting_silent[3] = DEFAULT_PWM_MOTOR_CURRENT;
int motor_current_setting_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD; int motor_current_setting_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
#endif #endif
static bool old_x_min_endstop=false; static bool old_x_min_endstop=false;
@ -109,24 +109,24 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
static uint16_t nextMainISR = 0; static uint16_t nextMainISR = 0;
static uint16_t eISR_Rate; static uint16_t eISR_Rate;
// Extrusion steps to be executed by the stepper. // Extrusion steps to be executed by the stepper.
// If set to non zero, the timer ISR routine will tick the Linear Advance extruder ticks first. // If set to non zero, the timer ISR routine will tick the Linear Advance extruder ticks first.
// If e_steps is zero, then the timer ISR routine will perform the usual DDA step. // If e_steps is zero, then the timer ISR routine will perform the usual DDA step.
static volatile int16_t e_steps = 0; static volatile int16_t e_steps = 0;
// How many extruder steps shall be ticked at a single ISR invocation? // How many extruder steps shall be ticked at a single ISR invocation?
static uint8_t estep_loops; static uint8_t estep_loops;
// The current speed of the extruder, scaled by the linear advance constant, so it has the same measure // The current speed of the extruder, scaled by the linear advance constant, so it has the same measure
// as current_adv_steps. // as current_adv_steps.
static int current_estep_rate; static int current_estep_rate;
// The current pretension of filament expressed in extruder micro steps. // The current pretension of filament expressed in extruder micro steps.
static int current_adv_steps; static int current_adv_steps;
#define _NEXT_ISR(T) nextMainISR = T #define _NEXT_ISR(T) nextMainISR = T
#else #else
#define _NEXT_ISR(T) OCR1A = T #define _NEXT_ISR(T) OCR1A = T
#endif #endif
#ifdef DEBUG_STEPPER_TIMER_MISSED #ifdef DEBUG_STEPPER_TIMER_MISSED
@ -330,7 +330,7 @@ FORCE_INLINE unsigned short calc_timer(uint16_t step_rate) {
if(step_rate < (F_CPU/500000)) step_rate = (F_CPU/500000); if(step_rate < (F_CPU/500000)) step_rate = (F_CPU/500000);
step_rate -= (F_CPU/500000); // Correct for minimal speed step_rate -= (F_CPU/500000); // Correct for minimal speed
if(step_rate >= (8*256)){ // higher step rate if(step_rate >= (8*256)) { // higher step rate
unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0]; unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0];
unsigned char tmp_step_rate = (step_rate & 0x00ff); unsigned char tmp_step_rate = (step_rate & 0x00ff);
unsigned short gain = (unsigned short)pgm_read_word_near(table_address+2); unsigned short gain = (unsigned short)pgm_read_word_near(table_address+2);
@ -343,7 +343,11 @@ FORCE_INLINE unsigned short calc_timer(uint16_t step_rate) {
timer = (unsigned short)pgm_read_word_near(table_address); timer = (unsigned short)pgm_read_word_near(table_address);
timer -= (((unsigned short)pgm_read_word_near(table_address+2) * (unsigned char)(step_rate & 0x0007))>>3); timer -= (((unsigned short)pgm_read_word_near(table_address+2) * (unsigned char)(step_rate & 0x0007))>>3);
} }
if(timer < 100) { timer = 100; MYSERIAL.print(_N("Steprate too high: ")); MYSERIAL.println(step_rate); }//(20kHz this should never happen)////MSG_STEPPER_TOO_HIGH c=0 r=0 if(timer < 100) {
timer = 100; //(20kHz this should never happen)////MSG_STEPPER_TOO_HIGH c=0 r=0
MYSERIAL.print(_N("Steprate too high: "));
MYSERIAL.println(step_rate);
}
return timer; return timer;
} }
@ -522,14 +526,14 @@ FORCE_INLINE void stepper_next_block()
// Set directions. // Set directions.
out_bits = current_block->direction_bits; out_bits = current_block->direction_bits;
// Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY) // Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
if((out_bits & (1<<X_AXIS))!=0){ if((out_bits & (1<<X_AXIS))!=0) {
WRITE_NC(X_DIR_PIN, INVERT_X_DIR); WRITE_NC(X_DIR_PIN, INVERT_X_DIR);
count_direction[X_AXIS]=-1; count_direction[X_AXIS]=-1;
} else { } else {
WRITE_NC(X_DIR_PIN, !INVERT_X_DIR); WRITE_NC(X_DIR_PIN, !INVERT_X_DIR);
count_direction[X_AXIS]=1; count_direction[X_AXIS]=1;
} }
if((out_bits & (1<<Y_AXIS))!=0){ if((out_bits & (1<<Y_AXIS))!=0) {
WRITE_NC(Y_DIR_PIN, INVERT_Y_DIR); WRITE_NC(Y_DIR_PIN, INVERT_Y_DIR);
count_direction[Y_AXIS]=-1; count_direction[Y_AXIS]=-1;
} else { } else {
@ -546,18 +550,18 @@ FORCE_INLINE void stepper_next_block()
if ((out_bits & (1 << E_AXIS)) != 0) { // -direction if ((out_bits & (1 << E_AXIS)) != 0) { // -direction
#ifndef LIN_ADVANCE #ifndef LIN_ADVANCE
WRITE(E0_DIR_PIN, WRITE(E0_DIR_PIN,
#ifdef SNMM #ifdef SNMM
(mmu_extruder == 0 || mmu_extruder == 2) ? !INVERT_E0_DIR : (mmu_extruder == 0 || mmu_extruder == 2) ? !INVERT_E0_DIR :
#endif // SNMM #endif // SNMM
INVERT_E0_DIR); INVERT_E0_DIR);
#endif /* LIN_ADVANCE */ #endif /* LIN_ADVANCE */
count_direction[E_AXIS] = -1; count_direction[E_AXIS] = -1;
} else { // +direction } else { // +direction
#ifndef LIN_ADVANCE #ifndef LIN_ADVANCE
WRITE(E0_DIR_PIN, WRITE(E0_DIR_PIN,
#ifdef SNMM #ifdef SNMM
(mmu_extruder == 0 || mmu_extruder == 2) ? INVERT_E0_DIR : (mmu_extruder == 0 || mmu_extruder == 2) ? INVERT_E0_DIR :
#endif // SNMM #endif // SNMM
!INVERT_E0_DIR); !INVERT_E0_DIR);
#endif /* LIN_ADVANCE */ #endif /* LIN_ADVANCE */
count_direction[E_AXIS] = 1; count_direction[E_AXIS] = 1;
@ -574,89 +578,89 @@ FORCE_INLINE void stepper_check_endstops()
{ {
if(check_endstops) if(check_endstops)
{ {
#ifndef COREXY #ifndef COREXY
if ((out_bits & (1<<X_AXIS)) != 0) // stepping along -X axis if ((out_bits & (1<<X_AXIS)) != 0) // stepping along -X axis
#else #else
if ((((out_bits & (1<<X_AXIS)) != 0)&&(out_bits & (1<<Y_AXIS)) != 0)) //-X occurs for -A and -B if ((((out_bits & (1<<X_AXIS)) != 0)&&(out_bits & (1<<Y_AXIS)) != 0)) //-X occurs for -A and -B
#endif #endif
{ {
#if ( (defined(X_MIN_PIN) && (X_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMINLIMIT) #if ( (defined(X_MIN_PIN) && (X_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMINLIMIT)
#ifdef TMC2130_SG_HOMING #ifdef TMC2130_SG_HOMING
// Stall guard homing turned on // Stall guard homing turned on
x_min_endstop = (READ(X_TMC2130_DIAG) != 0); x_min_endstop = (READ(X_TMC2130_DIAG) != 0);
#else #else
// Normal homing // Normal homing
x_min_endstop = (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING); x_min_endstop = (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING);
#endif #endif
if(x_min_endstop && old_x_min_endstop && (current_block->steps_x.wide > 0)) { if(x_min_endstop && old_x_min_endstop && (current_block->steps_x.wide > 0)) {
endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
endstop_x_hit=true; endstop_x_hit=true;
step_events_completed.wide = current_block->step_event_count.wide; step_events_completed.wide = current_block->step_event_count.wide;
} }
old_x_min_endstop = x_min_endstop; old_x_min_endstop = x_min_endstop;
#endif #endif
} else { // +direction } else { // +direction
#if ( (defined(X_MAX_PIN) && (X_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMAXLIMIT) #if ( (defined(X_MAX_PIN) && (X_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMAXLIMIT)
#ifdef TMC2130_SG_HOMING #ifdef TMC2130_SG_HOMING
// Stall guard homing turned on // Stall guard homing turned on
x_max_endstop = (READ(X_TMC2130_DIAG) != 0); x_max_endstop = (READ(X_TMC2130_DIAG) != 0);
#else #else
// Normal homing // Normal homing
x_max_endstop = (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING); x_max_endstop = (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING);
#endif #endif
if(x_max_endstop && old_x_max_endstop && (current_block->steps_x.wide > 0)){ if(x_max_endstop && old_x_max_endstop && (current_block->steps_x.wide > 0)) {
endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
endstop_x_hit=true; endstop_x_hit=true;
step_events_completed.wide = current_block->step_event_count.wide; step_events_completed.wide = current_block->step_event_count.wide;
} }
old_x_max_endstop = x_max_endstop; old_x_max_endstop = x_max_endstop;
#endif #endif
} }
#ifndef COREXY #ifndef COREXY
if ((out_bits & (1<<Y_AXIS)) != 0) // -direction if ((out_bits & (1<<Y_AXIS)) != 0) // -direction
#else #else
if ((((out_bits & (1<<X_AXIS)) != 0)&&(out_bits & (1<<Y_AXIS)) == 0)) // -Y occurs for -A and +B if ((((out_bits & (1<<X_AXIS)) != 0)&&(out_bits & (1<<Y_AXIS)) == 0)) // -Y occurs for -A and +B
#endif #endif
{ {
#if ( (defined(Y_MIN_PIN) && (Y_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMINLIMIT) #if ( (defined(Y_MIN_PIN) && (Y_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMINLIMIT)
#ifdef TMC2130_SG_HOMING #ifdef TMC2130_SG_HOMING
// Stall guard homing turned on // Stall guard homing turned on
y_min_endstop = (READ(Y_TMC2130_DIAG) != 0); y_min_endstop = (READ(Y_TMC2130_DIAG) != 0);
#else #else
// Normal homing // Normal homing
y_min_endstop = (READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING); y_min_endstop = (READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING);
#endif #endif
if(y_min_endstop && old_y_min_endstop && (current_block->steps_y.wide > 0)) { if(y_min_endstop && old_y_min_endstop && (current_block->steps_y.wide > 0)) {
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
endstop_y_hit=true; endstop_y_hit=true;
step_events_completed.wide = current_block->step_event_count.wide; step_events_completed.wide = current_block->step_event_count.wide;
} }
old_y_min_endstop = y_min_endstop; old_y_min_endstop = y_min_endstop;
#endif #endif
} else { // +direction } else { // +direction
#if ( (defined(Y_MAX_PIN) && (Y_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMAXLIMIT) #if ( (defined(Y_MAX_PIN) && (Y_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMAXLIMIT)
#ifdef TMC2130_SG_HOMING #ifdef TMC2130_SG_HOMING
// Stall guard homing turned on // Stall guard homing turned on
y_max_endstop = (READ(Y_TMC2130_DIAG) != 0); y_max_endstop = (READ(Y_TMC2130_DIAG) != 0);
#else #else
// Normal homing // Normal homing
y_max_endstop = (READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING); y_max_endstop = (READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING);
#endif #endif
if(y_max_endstop && old_y_max_endstop && (current_block->steps_y.wide > 0)){ if(y_max_endstop && old_y_max_endstop && (current_block->steps_y.wide > 0)) {
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
endstop_y_hit=true; endstop_y_hit=true;
step_events_completed.wide = current_block->step_event_count.wide; step_events_completed.wide = current_block->step_event_count.wide;
} }
old_y_max_endstop = y_max_endstop; old_y_max_endstop = y_max_endstop;
#endif #endif
} }
if ((out_bits & (1<<Z_AXIS)) != 0) // -direction if ((out_bits & (1<<Z_AXIS)) != 0) // -direction
{ {
#if defined(Z_MIN_PIN) && (Z_MIN_PIN > -1) && !defined(DEBUG_DISABLE_ZMINLIMIT) #if defined(Z_MIN_PIN) && (Z_MIN_PIN > -1) && !defined(DEBUG_DISABLE_ZMINLIMIT)
if (! check_z_endstop) { if (! check_z_endstop) {
#ifdef TMC2130_SG_HOMING #ifdef TMC2130_SG_HOMING
// Stall guard homing turned on // Stall guard homing turned on
#ifdef TMC2130_STEALTH_Z #ifdef TMC2130_STEALTH_Z
if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04))
@ -664,9 +668,9 @@ FORCE_INLINE void stepper_check_endstops()
else else
#endif //TMC2130_STEALTH_Z #endif //TMC2130_STEALTH_Z
z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0); z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0);
#else #else
z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
#endif //TMC2130_SG_HOMING #endif //TMC2130_SG_HOMING
if(z_min_endstop && old_z_min_endstop && (current_block->steps_z.wide > 0)) { if(z_min_endstop && old_z_min_endstop && (current_block->steps_z.wide > 0)) {
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
endstop_z_hit=true; endstop_z_hit=true;
@ -674,10 +678,10 @@ FORCE_INLINE void stepper_check_endstops()
} }
old_z_min_endstop = z_min_endstop; old_z_min_endstop = z_min_endstop;
} }
#endif #endif
} else { // +direction } else { // +direction
#if defined(Z_MAX_PIN) && (Z_MAX_PIN > -1) && !defined(DEBUG_DISABLE_ZMAXLIMIT) #if defined(Z_MAX_PIN) && (Z_MAX_PIN > -1) && !defined(DEBUG_DISABLE_ZMAXLIMIT)
#ifdef TMC2130_SG_HOMING #ifdef TMC2130_SG_HOMING
// Stall guard homing turned on // Stall guard homing turned on
#ifdef TMC2130_STEALTH_Z #ifdef TMC2130_STEALTH_Z
if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04))
@ -685,25 +689,25 @@ FORCE_INLINE void stepper_check_endstops()
else else
#endif //TMC2130_STEALTH_Z #endif //TMC2130_STEALTH_Z
z_max_endstop = (READ(Z_TMC2130_DIAG) != 0); z_max_endstop = (READ(Z_TMC2130_DIAG) != 0);
#else #else
z_max_endstop = (READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING); z_max_endstop = (READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING);
#endif //TMC2130_SG_HOMING #endif //TMC2130_SG_HOMING
if(z_max_endstop && old_z_max_endstop && (current_block->steps_z.wide > 0)) { if(z_max_endstop && old_z_max_endstop && (current_block->steps_z.wide > 0)) {
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
endstop_z_hit=true; endstop_z_hit=true;
step_events_completed.wide = current_block->step_event_count.wide; step_events_completed.wide = current_block->step_event_count.wide;
} }
old_z_max_endstop = z_max_endstop; old_z_max_endstop = z_max_endstop;
#endif #endif
} }
} }
// Supporting stopping on a trigger of the Z-stop induction sensor, not only for the Z-minus movements. // Supporting stopping on a trigger of the Z-stop induction sensor, not only for the Z-minus movements.
#if defined(Z_MIN_PIN) && (Z_MIN_PIN > -1) && !defined(DEBUG_DISABLE_ZMINLIMIT) #if defined(Z_MIN_PIN) && (Z_MIN_PIN > -1) && !defined(DEBUG_DISABLE_ZMINLIMIT)
if (check_z_endstop) { if (check_z_endstop) {
// Check the Z min end-stop no matter what. // Check the Z min end-stop no matter what.
// Good for searching for the center of an induction target. // Good for searching for the center of an induction target.
#ifdef TMC2130_SG_HOMING #ifdef TMC2130_SG_HOMING
// Stall guard homing turned on // Stall guard homing turned on
#ifdef TMC2130_STEALTH_Z #ifdef TMC2130_STEALTH_Z
if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04))
@ -711,9 +715,9 @@ FORCE_INLINE void stepper_check_endstops()
else else
#endif //TMC2130_STEALTH_Z #endif //TMC2130_STEALTH_Z
z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0); z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0);
#else #else
z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
#endif //TMC2130_SG_HOMING #endif //TMC2130_SG_HOMING
if(z_min_endstop && old_z_min_endstop) { if(z_min_endstop && old_z_min_endstop) {
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
endstop_z_hit=true; endstop_z_hit=true;
@ -721,7 +725,7 @@ FORCE_INLINE void stepper_check_endstops()
} }
old_z_min_endstop = z_min_endstop; old_z_min_endstop = z_min_endstop;
} }
#endif #endif
} }
@ -776,9 +780,9 @@ FORCE_INLINE void stepper_tick_lowres()
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
++ e_steps; ++ e_steps;
#else #else
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
++ fsensor_counter; ++ fsensor_counter;
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN);
#endif #endif
} }
@ -838,9 +842,9 @@ FORCE_INLINE void stepper_tick_highres()
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
++ e_steps; ++ e_steps;
#else #else
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
++ fsensor_counter; ++ fsensor_counter;
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN);
#endif #endif
} }
@ -896,11 +900,11 @@ FORCE_INLINE void isr() {
bool neg = e_steps < 0; bool neg = e_steps < 0;
{ {
bool dir = bool dir =
#ifdef SNMM #ifdef SNMM
(neg == (mmu_extruder & 1)) (neg == (mmu_extruder & 1))
#else #else
neg neg
#endif #endif
? INVERT_E0_DIR : !INVERT_E0_DIR; //If we have SNMM, reverse every second extruder. ? INVERT_E0_DIR : !INVERT_E0_DIR; //If we have SNMM, reverse every second extruder.
WRITE_NC(E0_DIR_PIN, dir); WRITE_NC(E0_DIR_PIN, dir);
if (neg) if (neg)
@ -953,11 +957,11 @@ FORCE_INLINE void isr() {
uint16_t timer = calc_timer(acc_step_rate); uint16_t timer = calc_timer(acc_step_rate);
_NEXT_ISR(timer); _NEXT_ISR(timer);
acceleration_time += timer; acceleration_time += timer;
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
if (current_block->use_advance_lead) if (current_block->use_advance_lead)
// int32_t = (uint16_t * uint32_t) >> 17 // int32_t = (uint16_t * uint32_t) >> 17
current_estep_rate = ((uint32_t)acc_step_rate * current_block->abs_adv_steps_multiplier8) >> 17; current_estep_rate = ((uint32_t)acc_step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
#endif #endif
} }
else if (step_events_completed.wide > (unsigned long int)current_block->decelerate_after) { else if (step_events_completed.wide > (unsigned long int)current_block->decelerate_after) {
uint16_t step_rate; uint16_t step_rate;
@ -971,10 +975,10 @@ FORCE_INLINE void isr() {
uint16_t timer = calc_timer(step_rate); uint16_t timer = calc_timer(step_rate);
_NEXT_ISR(timer); _NEXT_ISR(timer);
deceleration_time += timer; deceleration_time += timer;
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
if (current_block->use_advance_lead) if (current_block->use_advance_lead)
current_estep_rate = ((uint32_t)step_rate * current_block->abs_adv_steps_multiplier8) >> 17; current_estep_rate = ((uint32_t)step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
#endif #endif
} }
else { else {
if (! step_loops_nominal) { if (! step_loops_nominal) {
@ -982,10 +986,10 @@ FORCE_INLINE void isr() {
// the initial interrupt blocking. // the initial interrupt blocking.
OCR1A_nominal = calc_timer(uint16_t(current_block->nominal_rate)); OCR1A_nominal = calc_timer(uint16_t(current_block->nominal_rate));
step_loops_nominal = step_loops; step_loops_nominal = step_loops;
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
if (current_block->use_advance_lead) if (current_block->use_advance_lead)
current_estep_rate = (current_block->nominal_rate * current_block->abs_adv_steps_multiplier8) >> 17; current_estep_rate = (current_block->nominal_rate * current_block->abs_adv_steps_multiplier8) >> 17;
#endif #endif
} }
_NEXT_ISR(OCR1A_nominal); _NEXT_ISR(OCR1A_nominal);
} }
@ -1128,80 +1132,80 @@ void st_init()
microstep_init(); //Initialize Microstepping Pins microstep_init(); //Initialize Microstepping Pins
//Initialize Dir Pins //Initialize Dir Pins
#if defined(X_DIR_PIN) && X_DIR_PIN > -1 #if defined(X_DIR_PIN) && X_DIR_PIN > -1
SET_OUTPUT(X_DIR_PIN); SET_OUTPUT(X_DIR_PIN);
#endif #endif
#if defined(X2_DIR_PIN) && X2_DIR_PIN > -1 #if defined(X2_DIR_PIN) && X2_DIR_PIN > -1
SET_OUTPUT(X2_DIR_PIN); SET_OUTPUT(X2_DIR_PIN);
#endif #endif
#if defined(Y_DIR_PIN) && Y_DIR_PIN > -1 #if defined(Y_DIR_PIN) && Y_DIR_PIN > -1
SET_OUTPUT(Y_DIR_PIN); SET_OUTPUT(Y_DIR_PIN);
#if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_DIR_PIN) && (Y2_DIR_PIN > -1) #if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_DIR_PIN) && (Y2_DIR_PIN > -1)
SET_OUTPUT(Y2_DIR_PIN); SET_OUTPUT(Y2_DIR_PIN);
#endif #endif
#endif #endif
#if defined(Z_DIR_PIN) && Z_DIR_PIN > -1 #if defined(Z_DIR_PIN) && Z_DIR_PIN > -1
SET_OUTPUT(Z_DIR_PIN); SET_OUTPUT(Z_DIR_PIN);
#if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_DIR_PIN) && (Z2_DIR_PIN > -1) #if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_DIR_PIN) && (Z2_DIR_PIN > -1)
SET_OUTPUT(Z2_DIR_PIN); SET_OUTPUT(Z2_DIR_PIN);
#endif #endif
#endif #endif
#if defined(E0_DIR_PIN) && E0_DIR_PIN > -1 #if defined(E0_DIR_PIN) && E0_DIR_PIN > -1
SET_OUTPUT(E0_DIR_PIN); SET_OUTPUT(E0_DIR_PIN);
#endif #endif
#if defined(E1_DIR_PIN) && (E1_DIR_PIN > -1) #if defined(E1_DIR_PIN) && (E1_DIR_PIN > -1)
SET_OUTPUT(E1_DIR_PIN); SET_OUTPUT(E1_DIR_PIN);
#endif #endif
#if defined(E2_DIR_PIN) && (E2_DIR_PIN > -1) #if defined(E2_DIR_PIN) && (E2_DIR_PIN > -1)
SET_OUTPUT(E2_DIR_PIN); SET_OUTPUT(E2_DIR_PIN);
#endif #endif
//Initialize Enable Pins - steppers default to disabled. //Initialize Enable Pins - steppers default to disabled.
#if defined(X_ENABLE_PIN) && X_ENABLE_PIN > -1 #if defined(X_ENABLE_PIN) && X_ENABLE_PIN > -1
SET_OUTPUT(X_ENABLE_PIN); SET_OUTPUT(X_ENABLE_PIN);
if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH); if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH);
#endif #endif
#if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1 #if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
SET_OUTPUT(X2_ENABLE_PIN); SET_OUTPUT(X2_ENABLE_PIN);
if(!X_ENABLE_ON) WRITE(X2_ENABLE_PIN,HIGH); if(!X_ENABLE_ON) WRITE(X2_ENABLE_PIN,HIGH);
#endif #endif
#if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1 #if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1
SET_OUTPUT(Y_ENABLE_PIN); SET_OUTPUT(Y_ENABLE_PIN);
if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH); if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH);
#if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_ENABLE_PIN) && (Y2_ENABLE_PIN > -1) #if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_ENABLE_PIN) && (Y2_ENABLE_PIN > -1)
SET_OUTPUT(Y2_ENABLE_PIN); SET_OUTPUT(Y2_ENABLE_PIN);
if(!Y_ENABLE_ON) WRITE(Y2_ENABLE_PIN,HIGH); if(!Y_ENABLE_ON) WRITE(Y2_ENABLE_PIN,HIGH);
#endif #endif
#endif #endif
#if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1 #if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
SET_OUTPUT(Z_ENABLE_PIN); SET_OUTPUT(Z_ENABLE_PIN);
if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH); if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
#if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_ENABLE_PIN) && (Z2_ENABLE_PIN > -1) #if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_ENABLE_PIN) && (Z2_ENABLE_PIN > -1)
SET_OUTPUT(Z2_ENABLE_PIN); SET_OUTPUT(Z2_ENABLE_PIN);
if(!Z_ENABLE_ON) WRITE(Z2_ENABLE_PIN,HIGH); if(!Z_ENABLE_ON) WRITE(Z2_ENABLE_PIN,HIGH);
#endif #endif
#endif #endif
#if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1) #if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
SET_OUTPUT(E0_ENABLE_PIN); SET_OUTPUT(E0_ENABLE_PIN);
if(!E_ENABLE_ON) WRITE(E0_ENABLE_PIN,HIGH); if(!E_ENABLE_ON) WRITE(E0_ENABLE_PIN,HIGH);
#endif #endif
#if defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1) #if defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
SET_OUTPUT(E1_ENABLE_PIN); SET_OUTPUT(E1_ENABLE_PIN);
if(!E_ENABLE_ON) WRITE(E1_ENABLE_PIN,HIGH); if(!E_ENABLE_ON) WRITE(E1_ENABLE_PIN,HIGH);
#endif #endif
#if defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1) #if defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
SET_OUTPUT(E2_ENABLE_PIN); SET_OUTPUT(E2_ENABLE_PIN);
if(!E_ENABLE_ON) WRITE(E2_ENABLE_PIN,HIGH); if(!E_ENABLE_ON) WRITE(E2_ENABLE_PIN,HIGH);
#endif #endif
//endstops and pullups //endstops and pullups
#ifdef TMC2130_SG_HOMING #ifdef TMC2130_SG_HOMING
SET_INPUT(X_TMC2130_DIAG); SET_INPUT(X_TMC2130_DIAG);
WRITE(X_TMC2130_DIAG,HIGH); WRITE(X_TMC2130_DIAG,HIGH);
@ -1214,56 +1218,56 @@ void st_init()
SET_INPUT(E0_TMC2130_DIAG); SET_INPUT(E0_TMC2130_DIAG);
WRITE(E0_TMC2130_DIAG,HIGH); WRITE(E0_TMC2130_DIAG,HIGH);
#endif #endif
#if defined(X_MIN_PIN) && X_MIN_PIN > -1 #if defined(X_MIN_PIN) && X_MIN_PIN > -1
SET_INPUT(X_MIN_PIN); SET_INPUT(X_MIN_PIN);
#ifdef ENDSTOPPULLUP_XMIN #ifdef ENDSTOPPULLUP_XMIN
WRITE(X_MIN_PIN,HIGH); WRITE(X_MIN_PIN,HIGH);
#endif #endif
#endif #endif
#if defined(Y_MIN_PIN) && Y_MIN_PIN > -1 #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
SET_INPUT(Y_MIN_PIN); SET_INPUT(Y_MIN_PIN);
#ifdef ENDSTOPPULLUP_YMIN #ifdef ENDSTOPPULLUP_YMIN
WRITE(Y_MIN_PIN,HIGH); WRITE(Y_MIN_PIN,HIGH);
#endif #endif
#endif #endif
#if defined(Z_MIN_PIN) && Z_MIN_PIN > -1 #if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
SET_INPUT(Z_MIN_PIN); SET_INPUT(Z_MIN_PIN);
#ifdef ENDSTOPPULLUP_ZMIN #ifdef ENDSTOPPULLUP_ZMIN
WRITE(Z_MIN_PIN,HIGH); WRITE(Z_MIN_PIN,HIGH);
#endif #endif
#endif #endif
#if defined(X_MAX_PIN) && X_MAX_PIN > -1 #if defined(X_MAX_PIN) && X_MAX_PIN > -1
SET_INPUT(X_MAX_PIN); SET_INPUT(X_MAX_PIN);
#ifdef ENDSTOPPULLUP_XMAX #ifdef ENDSTOPPULLUP_XMAX
WRITE(X_MAX_PIN,HIGH); WRITE(X_MAX_PIN,HIGH);
#endif #endif
#endif #endif
#if defined(Y_MAX_PIN) && Y_MAX_PIN > -1 #if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
SET_INPUT(Y_MAX_PIN); SET_INPUT(Y_MAX_PIN);
#ifdef ENDSTOPPULLUP_YMAX #ifdef ENDSTOPPULLUP_YMAX
WRITE(Y_MAX_PIN,HIGH); WRITE(Y_MAX_PIN,HIGH);
#endif #endif
#endif #endif
#if defined(Z_MAX_PIN) && Z_MAX_PIN > -1 #if defined(Z_MAX_PIN) && Z_MAX_PIN > -1
SET_INPUT(Z_MAX_PIN); SET_INPUT(Z_MAX_PIN);
#ifdef ENDSTOPPULLUP_ZMAX #ifdef ENDSTOPPULLUP_ZMAX
WRITE(Z_MAX_PIN,HIGH); WRITE(Z_MAX_PIN,HIGH);
#endif #endif
#endif #endif
#if (defined(FANCHECK) && defined(TACH_0) && (TACH_0 > -1)) #if (defined(FANCHECK) && defined(TACH_0) && (TACH_0 > -1))
SET_INPUT(TACH_0); SET_INPUT(TACH_0);
#ifdef TACH0PULLUP #ifdef TACH0PULLUP
WRITE(TACH_0, HIGH); WRITE(TACH_0, HIGH);
#endif #endif
#endif #endif
//Initialize Step Pins //Initialize Step Pins
@ -1275,49 +1279,49 @@ void st_init()
WRITE(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN); WRITE(DEBUG_XSTEP_DUP_PIN,INVERT_X_STEP_PIN);
#endif //DEBUG_XSTEP_DUP_PIN #endif //DEBUG_XSTEP_DUP_PIN
disable_x(); disable_x();
#endif #endif
#if defined(X2_STEP_PIN) && (X2_STEP_PIN > -1) #if defined(X2_STEP_PIN) && (X2_STEP_PIN > -1)
SET_OUTPUT(X2_STEP_PIN); SET_OUTPUT(X2_STEP_PIN);
WRITE(X2_STEP_PIN,INVERT_X_STEP_PIN); WRITE(X2_STEP_PIN,INVERT_X_STEP_PIN);
disable_x(); disable_x();
#endif #endif
#if defined(Y_STEP_PIN) && (Y_STEP_PIN > -1) #if defined(Y_STEP_PIN) && (Y_STEP_PIN > -1)
SET_OUTPUT(Y_STEP_PIN); SET_OUTPUT(Y_STEP_PIN);
WRITE(Y_STEP_PIN,INVERT_Y_STEP_PIN); WRITE(Y_STEP_PIN,INVERT_Y_STEP_PIN);
#ifdef DEBUG_YSTEP_DUP_PIN #ifdef DEBUG_YSTEP_DUP_PIN
SET_OUTPUT(DEBUG_YSTEP_DUP_PIN); SET_OUTPUT(DEBUG_YSTEP_DUP_PIN);
WRITE(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN); WRITE(DEBUG_YSTEP_DUP_PIN,INVERT_Y_STEP_PIN);
#endif //DEBUG_YSTEP_DUP_PIN #endif //DEBUG_YSTEP_DUP_PIN
#if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_STEP_PIN) && (Y2_STEP_PIN > -1) #if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_STEP_PIN) && (Y2_STEP_PIN > -1)
SET_OUTPUT(Y2_STEP_PIN); SET_OUTPUT(Y2_STEP_PIN);
WRITE(Y2_STEP_PIN,INVERT_Y_STEP_PIN); WRITE(Y2_STEP_PIN,INVERT_Y_STEP_PIN);
#endif #endif
disable_y(); disable_y();
#endif #endif
#if defined(Z_STEP_PIN) && (Z_STEP_PIN > -1) #if defined(Z_STEP_PIN) && (Z_STEP_PIN > -1)
SET_OUTPUT(Z_STEP_PIN); SET_OUTPUT(Z_STEP_PIN);
WRITE(Z_STEP_PIN,INVERT_Z_STEP_PIN); WRITE(Z_STEP_PIN,INVERT_Z_STEP_PIN);
#if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_STEP_PIN) && (Z2_STEP_PIN > -1) #if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_STEP_PIN) && (Z2_STEP_PIN > -1)
SET_OUTPUT(Z2_STEP_PIN); SET_OUTPUT(Z2_STEP_PIN);
WRITE(Z2_STEP_PIN,INVERT_Z_STEP_PIN); WRITE(Z2_STEP_PIN,INVERT_Z_STEP_PIN);
#endif #endif
disable_z(); disable_z();
#endif #endif
#if defined(E0_STEP_PIN) && (E0_STEP_PIN > -1) #if defined(E0_STEP_PIN) && (E0_STEP_PIN > -1)
SET_OUTPUT(E0_STEP_PIN); SET_OUTPUT(E0_STEP_PIN);
WRITE(E0_STEP_PIN,INVERT_E_STEP_PIN); WRITE(E0_STEP_PIN,INVERT_E_STEP_PIN);
disable_e0(); disable_e0();
#endif #endif
#if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1) #if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1)
SET_OUTPUT(E1_STEP_PIN); SET_OUTPUT(E1_STEP_PIN);
WRITE(E1_STEP_PIN,INVERT_E_STEP_PIN); WRITE(E1_STEP_PIN,INVERT_E_STEP_PIN);
disable_e1(); disable_e1();
#endif #endif
#if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1) #if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1)
SET_OUTPUT(E2_STEP_PIN); SET_OUTPUT(E2_STEP_PIN);
WRITE(E2_STEP_PIN,INVERT_E_STEP_PIN); WRITE(E2_STEP_PIN,INVERT_E_STEP_PIN);
disable_e2(); disable_e2();
#endif #endif
// waveform generation = 0100 = CTC // waveform generation = 0100 = CTC
TCCR1B &= ~(1<<WGM13); TCCR1B &= ~(1<<WGM13);
@ -1502,30 +1506,31 @@ void babystep(const uint8_t axis,const bool direction)
uint8_t old_z_dir_pin= READ(Z_DIR_PIN); //if dualzstepper, both point to same direction. uint8_t old_z_dir_pin= READ(Z_DIR_PIN); //if dualzstepper, both point to same direction.
//setup new step //setup new step
WRITE(Z_DIR_PIN,(INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z); WRITE(Z_DIR_PIN,(INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z);
#ifdef Z_DUAL_STEPPER_DRIVERS #ifdef Z_DUAL_STEPPER_DRIVERS
WRITE(Z2_DIR_PIN,(INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z); WRITE(Z2_DIR_PIN,(INVERT_Z_DIR)^direction^BABYSTEP_INVERT_Z);
#endif #endif
//perform step //perform step
WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN); WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
#ifdef Z_DUAL_STEPPER_DRIVERS #ifdef Z_DUAL_STEPPER_DRIVERS
WRITE(Z2_STEP_PIN, !INVERT_Z_STEP_PIN); WRITE(Z2_STEP_PIN, !INVERT_Z_STEP_PIN);
#endif #endif
delayMicroseconds(1); delayMicroseconds(1);
WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN); WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN);
#ifdef Z_DUAL_STEPPER_DRIVERS #ifdef Z_DUAL_STEPPER_DRIVERS
WRITE(Z2_STEP_PIN, INVERT_Z_STEP_PIN); WRITE(Z2_STEP_PIN, INVERT_Z_STEP_PIN);
#endif #endif
//get old pin state back. //get old pin state back.
WRITE(Z_DIR_PIN,old_z_dir_pin); WRITE(Z_DIR_PIN,old_z_dir_pin);
#ifdef Z_DUAL_STEPPER_DRIVERS #ifdef Z_DUAL_STEPPER_DRIVERS
WRITE(Z2_DIR_PIN,old_z_dir_pin); WRITE(Z2_DIR_PIN,old_z_dir_pin);
#endif #endif
} }
break; break;
default: break; default:
break;
} }
} }
#endif //BABYSTEPPING #endif //BABYSTEPPING
@ -1548,25 +1553,25 @@ void EEPROM_read_st(int pos, uint8_t* value, uint8_t size)
*value = eeprom_read_byte((unsigned char*)pos); *value = eeprom_read_byte((unsigned char*)pos);
pos++; pos++;
value++; value++;
}while(--size); } while(--size);
} }
void st_current_init() //Initialize Digipot Motor Current void st_current_init() //Initialize Digipot Motor Current
{ {
uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT); uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
SilentModeMenu = SilentMode; SilentModeMenu = SilentMode;
#ifdef MOTOR_CURRENT_PWM_XY_PIN #ifdef MOTOR_CURRENT_PWM_XY_PIN
pinMode(MOTOR_CURRENT_PWM_XY_PIN, OUTPUT); pinMode(MOTOR_CURRENT_PWM_XY_PIN, OUTPUT);
pinMode(MOTOR_CURRENT_PWM_Z_PIN, OUTPUT); pinMode(MOTOR_CURRENT_PWM_Z_PIN, OUTPUT);
pinMode(MOTOR_CURRENT_PWM_E_PIN, OUTPUT); pinMode(MOTOR_CURRENT_PWM_E_PIN, OUTPUT);
if((SilentMode == SILENT_MODE_OFF) || (farm_mode) ){ if((SilentMode == SILENT_MODE_OFF) || (farm_mode) ) {
motor_current_setting[0] = motor_current_setting_loud[0]; motor_current_setting[0] = motor_current_setting_loud[0];
motor_current_setting[1] = motor_current_setting_loud[1]; motor_current_setting[1] = motor_current_setting_loud[1];
motor_current_setting[2] = motor_current_setting_loud[2]; motor_current_setting[2] = motor_current_setting_loud[2];
}else{ } else {
motor_current_setting[0] = motor_current_setting_silent[0]; motor_current_setting[0] = motor_current_setting_silent[0];
motor_current_setting[1] = motor_current_setting_silent[1]; motor_current_setting[1] = motor_current_setting_silent[1];
@ -1578,7 +1583,7 @@ uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
st_current_set(2, motor_current_setting[2]); st_current_set(2, motor_current_setting[2]);
//Set timer5 to 31khz so the PWM of the motor power is as constant as possible. (removes a buzzing noise) //Set timer5 to 31khz so the PWM of the motor power is as constant as possible. (removes a buzzing noise)
TCCR5B = (TCCR5B & ~(_BV(CS50) | _BV(CS51) | _BV(CS52))) | _BV(CS50); TCCR5B = (TCCR5B & ~(_BV(CS50) | _BV(CS51) | _BV(CS52))) | _BV(CS50);
#endif #endif
} }
@ -1591,18 +1596,18 @@ void st_current_set(uint8_t driver, int current)
if (driver == 2) analogWrite(MOTOR_CURRENT_PWM_E_PIN, (long)current * 255L / (long)MOTOR_CURRENT_PWM_RANGE); if (driver == 2) analogWrite(MOTOR_CURRENT_PWM_E_PIN, (long)current * 255L / (long)MOTOR_CURRENT_PWM_RANGE);
} }
#else //MOTOR_CURRENT_PWM_XY_PIN #else //MOTOR_CURRENT_PWM_XY_PIN
void st_current_set(uint8_t, int ){} void st_current_set(uint8_t, int ) {}
#endif //MOTOR_CURRENT_PWM_XY_PIN #endif //MOTOR_CURRENT_PWM_XY_PIN
void microstep_init() void microstep_init()
{ {
#if defined(E1_MS1_PIN) && E1_MS1_PIN > -1 #if defined(E1_MS1_PIN) && E1_MS1_PIN > -1
pinMode(E1_MS1_PIN,OUTPUT); pinMode(E1_MS1_PIN,OUTPUT);
pinMode(E1_MS2_PIN,OUTPUT); pinMode(E1_MS2_PIN,OUTPUT);
#endif #endif
#if defined(X_MS1_PIN) && X_MS1_PIN > -1 #if defined(X_MS1_PIN) && X_MS1_PIN > -1
const uint8_t microstep_modes[] = MICROSTEP_MODES; const uint8_t microstep_modes[] = MICROSTEP_MODES;
pinMode(X_MS1_PIN,OUTPUT); pinMode(X_MS1_PIN,OUTPUT);
pinMode(X_MS2_PIN,OUTPUT); pinMode(X_MS2_PIN,OUTPUT);
@ -1612,8 +1617,8 @@ void microstep_init()
pinMode(Z_MS2_PIN,OUTPUT); pinMode(Z_MS2_PIN,OUTPUT);
pinMode(E0_MS1_PIN,OUTPUT); pinMode(E0_MS1_PIN,OUTPUT);
pinMode(E0_MS2_PIN,OUTPUT); pinMode(E0_MS2_PIN,OUTPUT);
for(int i=0;i<=4;i++) microstep_mode(i,microstep_modes[i]); for(int i=0; i<=4; i++) microstep_mode(i,microstep_modes[i]);
#endif #endif
} }
@ -1623,23 +1628,43 @@ void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2)
{ {
if(ms1 > -1) switch(driver) if(ms1 > -1) switch(driver)
{ {
case 0: digitalWrite( X_MS1_PIN,ms1); break; case 0:
case 1: digitalWrite( Y_MS1_PIN,ms1); break; digitalWrite( X_MS1_PIN,ms1);
case 2: digitalWrite( Z_MS1_PIN,ms1); break; break;
case 3: digitalWrite(E0_MS1_PIN,ms1); break; case 1:
#if defined(E1_MS1_PIN) && E1_MS1_PIN > -1 digitalWrite( Y_MS1_PIN,ms1);
case 4: digitalWrite(E1_MS1_PIN,ms1); break; break;
#endif case 2:
digitalWrite( Z_MS1_PIN,ms1);
break;
case 3:
digitalWrite(E0_MS1_PIN,ms1);
break;
#if defined(E1_MS1_PIN) && E1_MS1_PIN > -1
case 4:
digitalWrite(E1_MS1_PIN,ms1);
break;
#endif
} }
if(ms2 > -1) switch(driver) if(ms2 > -1) switch(driver)
{ {
case 0: digitalWrite( X_MS2_PIN,ms2); break; case 0:
case 1: digitalWrite( Y_MS2_PIN,ms2); break; digitalWrite( X_MS2_PIN,ms2);
case 2: digitalWrite( Z_MS2_PIN,ms2); break; break;
case 3: digitalWrite(E0_MS2_PIN,ms2); break; case 1:
#if defined(E1_MS2_PIN) && E1_MS2_PIN > -1 digitalWrite( Y_MS2_PIN,ms2);
case 4: digitalWrite(E1_MS2_PIN,ms2); break; break;
#endif case 2:
digitalWrite( Z_MS2_PIN,ms2);
break;
case 3:
digitalWrite(E0_MS2_PIN,ms2);
break;
#if defined(E1_MS2_PIN) && E1_MS2_PIN > -1
case 4:
digitalWrite(E1_MS2_PIN,ms2);
break;
#endif
} }
} }
@ -1647,11 +1672,21 @@ void microstep_mode(uint8_t driver, uint8_t stepping_mode)
{ {
switch(stepping_mode) switch(stepping_mode)
{ {
case 1: microstep_ms(driver,MICROSTEP1); break; case 1:
case 2: microstep_ms(driver,MICROSTEP2); break; microstep_ms(driver,MICROSTEP1);
case 4: microstep_ms(driver,MICROSTEP4); break; break;
case 8: microstep_ms(driver,MICROSTEP8); break; case 2:
case 16: microstep_ms(driver,MICROSTEP16); break; microstep_ms(driver,MICROSTEP2);
break;
case 4:
microstep_ms(driver,MICROSTEP4);
break;
case 8:
microstep_ms(driver,MICROSTEP8);
break;
case 16:
microstep_ms(driver,MICROSTEP16);
break;
} }
} }
@ -1670,10 +1705,10 @@ void microstep_readings()
SERIAL_PROTOCOLPGM("E0: "); SERIAL_PROTOCOLPGM("E0: ");
SERIAL_PROTOCOL( digitalRead(E0_MS1_PIN)); SERIAL_PROTOCOL( digitalRead(E0_MS1_PIN));
SERIAL_PROTOCOLLN( digitalRead(E0_MS2_PIN)); SERIAL_PROTOCOLLN( digitalRead(E0_MS2_PIN));
#if defined(E1_MS1_PIN) && E1_MS1_PIN > -1 #if defined(E1_MS1_PIN) && E1_MS1_PIN > -1
SERIAL_PROTOCOLPGM("E1: "); SERIAL_PROTOCOLPGM("E1: ");
SERIAL_PROTOCOL( digitalRead(E1_MS1_PIN)); SERIAL_PROTOCOL( digitalRead(E1_MS1_PIN));
SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN)); SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN));
#endif #endif
} }
#endif //TMC2130 #endif //TMC2130

View File

@ -38,9 +38,9 @@ void st_init();
void isr(); void isr();
#ifdef LIN_ADVANCE #ifdef LIN_ADVANCE
void advance_isr(); void advance_isr();
void advance_isr_scheduler(); void advance_isr_scheduler();
void clear_current_adv_vars(); //Used to reset the built up pretension and remaining esteps on filament change. void clear_current_adv_vars(); //Used to reset the built up pretension and remaining esteps on filament change.
#endif #endif
// Block until all buffered steps are executed // Block until all buffered steps are executed
@ -104,7 +104,7 @@ void microstep_init();
void microstep_readings(); void microstep_readings();
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
#endif #endif

View File

@ -25,7 +25,8 @@ void swi2c_init(void)
PIN_OUT(SWI2C_SCL); PIN_OUT(SWI2C_SCL);
PIN_SET(SWI2C_SDA); PIN_SET(SWI2C_SDA);
PIN_SET(SWI2C_SCL); PIN_SET(SWI2C_SCL);
uint8_t i; for (i = 0; i < 100; i++) uint8_t i;
for (i = 0; i < 100; i++)
__delay(); __delay();
} }
@ -81,7 +82,8 @@ uint8_t swi2c_read(void)
__delay(); __delay();
PIN_INP(SWI2C_SDA); PIN_INP(SWI2C_SDA);
uint8_t data = 0; uint8_t data = 0;
int8_t bit; for (bit = 7; bit >= 0; bit--) int8_t bit;
for (bit = 7; bit >= 0; bit--)
{ {
PIN_SET(SWI2C_SCL); PIN_SET(SWI2C_SCL);
__delay(); __delay();
@ -95,7 +97,8 @@ uint8_t swi2c_read(void)
void swi2c_write(uint8_t data) void swi2c_write(uint8_t data)
{ {
int8_t bit; for (bit = 7; bit >= 0; bit--) int8_t bit;
for (bit = 7; bit >= 0; bit--)
{ {
if (data & (1 << bit)) PIN_SET(SWI2C_SDA); if (data & (1 << bit)) PIN_SET(SWI2C_SDA);
else PIN_CLR(SWI2C_SDA); else PIN_CLR(SWI2C_SDA);
@ -111,7 +114,10 @@ uint8_t swi2c_check(uint8_t dev_addr)
{ {
swi2c_start(); swi2c_start();
swi2c_write((dev_addr & SWI2C_DMSK) << SWI2C_ASHF); swi2c_write((dev_addr & SWI2C_DMSK) << SWI2C_ASHF);
if (!swi2c_wait_ack()) { swi2c_stop(); return 0; } if (!swi2c_wait_ack()) {
swi2c_stop();
return 0;
}
swi2c_stop(); swi2c_stop();
return 1; return 1;
} }
@ -122,7 +128,10 @@ uint8_t swi2c_readByte_A8(uint8_t dev_addr, uint8_t addr, uint8_t* pbyte)
{ {
swi2c_start(); swi2c_start();
swi2c_write(SWI2C_WMSK | ((dev_addr & SWI2C_DMSK) << SWI2C_ASHF)); swi2c_write(SWI2C_WMSK | ((dev_addr & SWI2C_DMSK) << SWI2C_ASHF));
if (!swi2c_wait_ack()) { swi2c_stop(); return 0; } if (!swi2c_wait_ack()) {
swi2c_stop();
return 0;
}
swi2c_write(addr & 0xff); swi2c_write(addr & 0xff);
if (!swi2c_wait_ack()) return 0; if (!swi2c_wait_ack()) return 0;
swi2c_stop(); swi2c_stop();
@ -139,7 +148,10 @@ uint8_t swi2c_writeByte_A8(uint8_t dev_addr, uint8_t addr, uint8_t* pbyte)
{ {
swi2c_start(); swi2c_start();
swi2c_write(SWI2C_WMSK | ((dev_addr & SWI2C_DMSK) << SWI2C_ASHF)); swi2c_write(SWI2C_WMSK | ((dev_addr & SWI2C_DMSK) << SWI2C_ASHF));
if (!swi2c_wait_ack()) { swi2c_stop(); return 0; } if (!swi2c_wait_ack()) {
swi2c_stop();
return 0;
}
swi2c_write(addr & 0xff); swi2c_write(addr & 0xff);
if (!swi2c_wait_ack()) return 0; if (!swi2c_wait_ack()) return 0;
swi2c_write(*pbyte); swi2c_write(*pbyte);
@ -156,7 +168,10 @@ uint8_t swi2c_readByte_A16(uint8_t dev_addr, unsigned short addr, uint8_t* pbyte
{ {
swi2c_start(); swi2c_start();
swi2c_write(SWI2C_WMSK | ((dev_addr & SWI2C_DMSK) << SWI2C_ASHF)); swi2c_write(SWI2C_WMSK | ((dev_addr & SWI2C_DMSK) << SWI2C_ASHF));
if (!swi2c_wait_ack()) { swi2c_stop(); return 0; } if (!swi2c_wait_ack()) {
swi2c_stop();
return 0;
}
swi2c_write(addr >> 8); swi2c_write(addr >> 8);
if (!swi2c_wait_ack()) return 0; if (!swi2c_wait_ack()) return 0;
swi2c_write(addr & 0xff); swi2c_write(addr & 0xff);
@ -175,7 +190,10 @@ uint8_t swi2c_writeByte_A16(uint8_t dev_addr, unsigned short addr, uint8_t* pbyt
{ {
swi2c_start(); swi2c_start();
swi2c_write(SWI2C_WMSK | ((dev_addr & SWI2C_DMSK) << SWI2C_ASHF)); swi2c_write(SWI2C_WMSK | ((dev_addr & SWI2C_DMSK) << SWI2C_ASHF));
if (!swi2c_wait_ack()) { swi2c_stop(); return 0; } if (!swi2c_wait_ack()) {
swi2c_stop();
return 0;
}
swi2c_write(addr >> 8); swi2c_write(addr >> 8);
if (!swi2c_wait_ack()) return 0; if (!swi2c_wait_ack()) return 0;
swi2c_write(addr & 0xff); swi2c_write(addr & 0xff);

View File

@ -42,8 +42,9 @@ void swspi_tx(unsigned char tx)
{ {
int delay = 1 << (swspi_cfg & SWSPI_DEL)); int delay = 1 << (swspi_cfg & SWSPI_DEL));
if (swspi_miso == swspi_mosi) GPIO_OUT(swspi_mosi); if (swspi_miso == swspi_mosi) GPIO_OUT(swspi_mosi);
unsigned char i = 0; for (; i < 8; i++) unsigned char i = 0;
{ for (; i < 8; i++)
{
if (tx & 0x80) GPIO_SET(swspi_mosi); if (tx & 0x80) GPIO_SET(swspi_mosi);
else GPIO_CLR(swspi_mosi); else GPIO_CLR(swspi_mosi);
DELAY(delay); DELAY(delay);
@ -59,8 +60,9 @@ unsigned char swspi_rx()
int delay = 1 << (swspi_cfg & SWSPI_DEL)); int delay = 1 << (swspi_cfg & SWSPI_DEL));
if (swspi_miso == swspi_mosi) GPIO_OUT(swspi_mosi); if (swspi_miso == swspi_mosi) GPIO_OUT(swspi_mosi);
unsigned char rx = 0; unsigned char rx = 0;
unsigned char i = 0; for (; i < 8; i++) unsigned char i = 0;
{ for (; i < 8; i++)
{
rx <<= 1; rx <<= 1;
DELAY(delay); DELAY(delay);
SWSPI_SCK_UP; SWSPI_SCK_UP;
@ -75,8 +77,9 @@ unsigned char swspi_txrx(unsigned char tx)
{ {
int delay = 1 << (swspi_cfg & SWSPI_DEL)); int delay = 1 << (swspi_cfg & SWSPI_DEL));
unsigned char rx = 0; unsigned char rx = 0;
unsigned char i = 0; for (; i < 8; i++) unsigned char i = 0;
{ for (; i < 8; i++)
{
rx <<= 1; rx <<= 1;
if (tx & 0x80) GPIO_SET(swspi_mosi); if (tx & 0x80) GPIO_SET(swspi_mosi);
else GPIO_CLR(swspi_mosi); else GPIO_CLR(swspi_mosi);

View File

@ -71,29 +71,29 @@ int current_voltage_raw_bed = 0;
int current_temperature_bed_raw = 0; int current_temperature_bed_raw = 0;
float current_temperature_bed = 0.0; float current_temperature_bed = 0.0;
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #ifdef TEMP_SENSOR_1_AS_REDUNDANT
int redundant_temperature_raw = 0; int redundant_temperature_raw = 0;
float redundant_temperature = 0.0; float redundant_temperature = 0.0;
#endif #endif
#ifdef PIDTEMP #ifdef PIDTEMP
float _Kp, _Ki, _Kd; float _Kp, _Ki, _Kd;
int pid_cycle, pid_number_of_cycles; int pid_cycle, pid_number_of_cycles;
bool pid_tuning_finished = false; bool pid_tuning_finished = false;
#ifdef PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE
float Kc=DEFAULT_Kc; float Kc=DEFAULT_Kc;
#endif #endif
#endif //PIDTEMP #endif //PIDTEMP
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
unsigned char fanSpeedSoftPwm; unsigned char fanSpeedSoftPwm;
#endif #endif
unsigned char soft_pwm_bed; unsigned char soft_pwm_bed;
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
volatile int babystepsTodo[3]={0,0,0}; volatile int babystepsTodo[3]= {0,0,0};
#endif #endif
//=========================================================================== //===========================================================================
@ -102,59 +102,59 @@ unsigned char soft_pwm_bed;
static volatile bool temp_meas_ready = false; static volatile bool temp_meas_ready = false;
#ifdef PIDTEMP #ifdef PIDTEMP
//static cannot be external: //static cannot be external:
static float temp_iState[EXTRUDERS] = { 0 }; static float temp_iState[EXTRUDERS] = { 0 };
static float temp_dState[EXTRUDERS] = { 0 }; static float temp_dState[EXTRUDERS] = { 0 };
static float pTerm[EXTRUDERS]; static float pTerm[EXTRUDERS];
static float iTerm[EXTRUDERS]; static float iTerm[EXTRUDERS];
static float dTerm[EXTRUDERS]; static float dTerm[EXTRUDERS];
//int output; //int output;
static float pid_error[EXTRUDERS]; static float pid_error[EXTRUDERS];
static float temp_iState_min[EXTRUDERS]; static float temp_iState_min[EXTRUDERS];
static float temp_iState_max[EXTRUDERS]; static float temp_iState_max[EXTRUDERS];
// static float pid_input[EXTRUDERS]; // static float pid_input[EXTRUDERS];
// static float pid_output[EXTRUDERS]; // static float pid_output[EXTRUDERS];
static bool pid_reset[EXTRUDERS]; static bool pid_reset[EXTRUDERS];
#endif //PIDTEMP #endif //PIDTEMP
#ifdef PIDTEMPBED #ifdef PIDTEMPBED
//static cannot be external: //static cannot be external:
static float temp_iState_bed = { 0 }; static float temp_iState_bed = { 0 };
static float temp_dState_bed = { 0 }; static float temp_dState_bed = { 0 };
static float pTerm_bed; static float pTerm_bed;
static float iTerm_bed; static float iTerm_bed;
static float dTerm_bed; static float dTerm_bed;
//int output; //int output;
static float pid_error_bed; static float pid_error_bed;
static float temp_iState_min_bed; static float temp_iState_min_bed;
static float temp_iState_max_bed; static float temp_iState_max_bed;
#else //PIDTEMPBED #else //PIDTEMPBED
static unsigned long previous_millis_bed_heater; static unsigned long previous_millis_bed_heater;
#endif //PIDTEMPBED #endif //PIDTEMPBED
static unsigned char soft_pwm[EXTRUDERS]; static unsigned char soft_pwm[EXTRUDERS];
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
static unsigned char soft_pwm_fan; static unsigned char soft_pwm_fan;
#endif #endif
#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
static unsigned long extruder_autofan_last_check; static unsigned long extruder_autofan_last_check;
#endif #endif
#if EXTRUDERS > 3 #if EXTRUDERS > 3
# error Unsupported number of extruders # error Unsupported number of extruders
#elif EXTRUDERS > 2 #elif EXTRUDERS > 2
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2, v3 } # define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2, v3 }
#elif EXTRUDERS > 1 #elif EXTRUDERS > 1
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2 } # define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2 }
#else #else
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 } # define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 }
#endif #endif
// Init min and max temp with extreme values to prevent false errors during startup // Init min and max temp with extreme values to prevent false errors during startup
static int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP ); static int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_LO_TEMP, HEATER_1_RAW_LO_TEMP, HEATER_2_RAW_LO_TEMP );
static int maxttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP ); static int maxttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_HI_TEMP, HEATER_1_RAW_HI_TEMP, HEATER_2_RAW_HI_TEMP );
static int minttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 0, 0, 0 ); static int minttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 0, 0, 0 );
static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 16383, 16383, 16383 ); static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 16383, 16383, 16383 );
#ifdef BED_MINTEMP #ifdef BED_MINTEMP
@ -165,11 +165,11 @@ static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
#endif #endif
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #ifdef TEMP_SENSOR_1_AS_REDUNDANT
static void *heater_ttbl_map[2] = {(void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE }; static void *heater_ttbl_map[2] = {(void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE };
static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN }; static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
#else #else
static void *heater_ttbl_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( (void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE, (void *)HEATER_2_TEMPTABLE ); static void *heater_ttbl_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( (void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE, (void *)HEATER_2_TEMPTABLE );
static uint8_t heater_ttbllen_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN ); static uint8_t heater_ttbllen_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN );
#endif #endif
static float analog2temp(int raw, uint8_t e); static float analog2temp(int raw, uint8_t e);
@ -207,8 +207,8 @@ static void temp_runaway_check(int _heater_id, float _target_temperature, float
static void temp_runaway_stop(bool isPreheat, bool isBed); static void temp_runaway_stop(bool isPreheat, bool isBed);
#endif #endif
void PID_autotune(float temp, int extruder, int ncycles) void PID_autotune(float temp, int extruder, int ncycles)
{ {
pid_number_of_cycles = ncycles; pid_number_of_cycles = ncycles;
pid_tuning_finished = false; pid_tuning_finished = false;
float input = 0.0; float input = 0.0;
@ -235,10 +235,10 @@ static void temp_runaway_stop(bool isPreheat, bool isBed);
#endif #endif
if ((extruder >= EXTRUDERS) if ((extruder >= EXTRUDERS)
#if (TEMP_BED_PIN <= -1) #if (TEMP_BED_PIN <= -1)
||(extruder < 0) ||(extruder < 0)
#endif #endif
){ ) {
SERIAL_ECHOLN("PID Autotune failed. Bad extruder number."); SERIAL_ECHOLN("PID Autotune failed. Bad extruder number.");
pid_tuning_finished = true; pid_tuning_finished = true;
pid_cycle = 0; pid_cycle = 0;
@ -275,14 +275,14 @@ static void temp_runaway_stop(bool isPreheat, bool isBed);
max=max(max,input); max=max(max,input);
min=min(min,input); min=min(min,input);
#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
if(millis() - extruder_autofan_last_check > 2500) { if(millis() - extruder_autofan_last_check > 2500) {
checkExtruderAutoFans(); checkExtruderAutoFans();
extruder_autofan_last_check = millis(); extruder_autofan_last_check = millis();
} }
#endif #endif
if(heating == true && input > temp) { if(heating == true && input > temp) {
if(millis() - t2 > 5000) { if(millis() - t2 > 5000) {
@ -303,26 +303,35 @@ static void temp_runaway_stop(bool isPreheat, bool isBed);
t_low=t2 - t1; t_low=t2 - t1;
if(pid_cycle > 0) { if(pid_cycle > 0) {
bias += (d*(t_high - t_low))/(t_low + t_high); bias += (d*(t_high - t_low))/(t_low + t_high);
bias = constrain(bias, 20 ,(extruder<0?(MAX_BED_POWER):(PID_MAX))-20); bias = constrain(bias, 20,(extruder<0?(MAX_BED_POWER):(PID_MAX))-20);
if(bias > (extruder<0?(MAX_BED_POWER):(PID_MAX))/2) d = (extruder<0?(MAX_BED_POWER):(PID_MAX)) - 1 - bias; if(bias > (extruder<0?(MAX_BED_POWER):(PID_MAX))/2) d = (extruder<0?(MAX_BED_POWER):(PID_MAX)) - 1 - bias;
else d = bias; else d = bias;
SERIAL_PROTOCOLPGM(" bias: "); SERIAL_PROTOCOL(bias); SERIAL_PROTOCOLPGM(" bias: ");
SERIAL_PROTOCOLPGM(" d: "); SERIAL_PROTOCOL(d); SERIAL_PROTOCOL(bias);
SERIAL_PROTOCOLPGM(" min: "); SERIAL_PROTOCOL(min); SERIAL_PROTOCOLPGM(" d: ");
SERIAL_PROTOCOLPGM(" max: "); SERIAL_PROTOCOLLN(max); SERIAL_PROTOCOL(d);
SERIAL_PROTOCOLPGM(" min: ");
SERIAL_PROTOCOL(min);
SERIAL_PROTOCOLPGM(" max: ");
SERIAL_PROTOCOLLN(max);
if(pid_cycle > 2) { if(pid_cycle > 2) {
Ku = (4.0*d)/(3.14159*(max-min)/2.0); Ku = (4.0*d)/(3.14159*(max-min)/2.0);
Tu = ((float)(t_low + t_high)/1000.0); Tu = ((float)(t_low + t_high)/1000.0);
SERIAL_PROTOCOLPGM(" Ku: "); SERIAL_PROTOCOL(Ku); SERIAL_PROTOCOLPGM(" Ku: ");
SERIAL_PROTOCOLPGM(" Tu: "); SERIAL_PROTOCOLLN(Tu); SERIAL_PROTOCOL(Ku);
SERIAL_PROTOCOLPGM(" Tu: ");
SERIAL_PROTOCOLLN(Tu);
_Kp = 0.6*Ku; _Kp = 0.6*Ku;
_Ki = 2*_Kp/Tu; _Ki = 2*_Kp/Tu;
_Kd = _Kp*Tu/8; _Kd = _Kp*Tu/8;
SERIAL_PROTOCOLLNPGM(" Classic PID "); SERIAL_PROTOCOLLNPGM(" Classic PID ");
SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(_Kp); SERIAL_PROTOCOLPGM(" Kp: ");
SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(_Ki); SERIAL_PROTOCOLLN(_Kp);
SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(_Kd); SERIAL_PROTOCOLPGM(" Ki: ");
SERIAL_PROTOCOLLN(_Ki);
SERIAL_PROTOCOLPGM(" Kd: ");
SERIAL_PROTOCOLLN(_Kd);
/* /*
_Kp = 0.33*Ku; _Kp = 0.33*Ku;
_Ki = _Kp/Tu; _Ki = _Kp/Tu;
@ -358,10 +367,10 @@ static void temp_runaway_stop(bool isPreheat, bool isBed);
} }
if(millis() - temp_millis > 2000) { if(millis() - temp_millis > 2000) {
int p; int p;
if (extruder<0){ if (extruder<0) {
p=soft_pwm_bed; p=soft_pwm_bed;
SERIAL_PROTOCOLPGM("B:"); SERIAL_PROTOCOLPGM("B:");
}else{ } else {
p=soft_pwm[extruder]; p=soft_pwm[extruder];
SERIAL_PROTOCOLPGM("T:"); SERIAL_PROTOCOLPGM("T:");
} }
@ -378,7 +387,7 @@ static void temp_runaway_stop(bool isPreheat, bool isBed);
else if (safety_check_cycles < safety_check_cycles_count) { //delay else if (safety_check_cycles < safety_check_cycles_count) { //delay
safety_check_cycles++; safety_check_cycles++;
} }
else if (safety_check_cycles == safety_check_cycles_count){ //check that temperature is rising else if (safety_check_cycles == safety_check_cycles_count) { //check that temperature is rising
safety_check_cycles++; safety_check_cycles++;
//SERIAL_ECHOPGM("Time from beginning: "); //SERIAL_ECHOPGM("Time from beginning: ");
//MYSERIAL.print(safety_check_cycles_count * 2); //MYSERIAL.print(safety_check_cycles_count * 2);
@ -431,17 +440,17 @@ int getHeaterPower(int heater) {
(defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
#if defined(FAN_PIN) && FAN_PIN > -1 #if defined(FAN_PIN) && FAN_PIN > -1
#if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN" #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN"
#endif #endif
#if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN" #error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN"
#endif #endif
#if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN" #error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN"
#endif #endif
#endif #endif
void setExtruderAutoFanState(int pin, bool state) void setExtruderAutoFanState(int pin, bool state)
{ {
@ -511,7 +520,7 @@ void fanSpeedError(unsigned char _fan) {
case 0: case 0:
SERIAL_ECHOLNPGM("Extruder fan speed is lower then expected"); SERIAL_ECHOLNPGM("Extruder fan speed is lower then expected");
if (get_message_level() == 0) { if (get_message_level() == 0) {
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT)) if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
WRITE(BEEPER, HIGH); WRITE(BEEPER, HIGH);
delayMicroseconds(200); delayMicroseconds(200);
WRITE(BEEPER, LOW); WRITE(BEEPER, LOW);
@ -522,7 +531,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode
case 1: case 1:
SERIAL_ECHOLNPGM("Print fan speed is lower then expected"); SERIAL_ECHOLNPGM("Print fan speed is lower then expected");
if (get_message_level() == 0) { if (get_message_level() == 0) {
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT)) if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
WRITE(BEEPER, HIGH); WRITE(BEEPER, HIGH);
delayMicroseconds(200); delayMicroseconds(200);
WRITE(BEEPER, LOW); WRITE(BEEPER, LOW);
@ -540,11 +549,11 @@ void checkExtruderAutoFans()
uint8_t fanState = 0; uint8_t fanState = 0;
// which fan pins need to be turned on? // which fan pins need to be turned on?
#if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1 #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1
if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE)
fanState |= 1; fanState |= 1;
#endif #endif
#if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1
if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE)
{ {
if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
@ -552,8 +561,8 @@ void checkExtruderAutoFans()
else else
fanState |= 2; fanState |= 2;
} }
#endif #endif
#if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1 #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1
if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)
{ {
if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
@ -563,21 +572,21 @@ void checkExtruderAutoFans()
else else
fanState |= 4; fanState |= 4;
} }
#endif #endif
// update extruder auto fan states // update extruder auto fan states
#if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1 #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1
setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0); setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0);
#endif #endif
#if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1
if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0); setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0);
#endif #endif
#if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1 #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1
if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
&& EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN)
setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0); setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0);
#endif #endif
} }
#endif // any extruder auto fan pins set #endif // any extruder auto fan pins set
@ -607,10 +616,10 @@ void manage_heater()
temp_runaway_check(e+1, target_temperature[e], current_temperature[e], (int)soft_pwm[e], false); temp_runaway_check(e+1, target_temperature[e], current_temperature[e], (int)soft_pwm[e], false);
#endif #endif
#ifdef PIDTEMP #ifdef PIDTEMP
pid_input = current_temperature[e]; pid_input = current_temperature[e];
#ifndef PID_OPENLOOP #ifndef PID_OPENLOOP
pid_error[e] = target_temperature[e] - pid_input; pid_error[e] = target_temperature[e] - pid_input;
if(pid_error[e] > PID_FUNCTIONAL_RANGE) { if(pid_error[e] > PID_FUNCTIONAL_RANGE) {
pid_output = BANG_MAX; pid_output = BANG_MAX;
@ -631,22 +640,22 @@ void manage_heater()
iTerm[e] = cs.Ki * temp_iState[e]; iTerm[e] = cs.Ki * temp_iState[e];
//K1 defined in Configuration.h in the PID settings //K1 defined in Configuration.h in the PID settings
#define K2 (1.0-K1) #define K2 (1.0-K1)
dTerm[e] = (cs.Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); dTerm[e] = (cs.Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
pid_output = pTerm[e] + iTerm[e] - dTerm[e]; pid_output = pTerm[e] + iTerm[e] - dTerm[e];
if (pid_output > PID_MAX) { if (pid_output > PID_MAX) {
if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
pid_output=PID_MAX; pid_output=PID_MAX;
} else if (pid_output < 0){ } else if (pid_output < 0) {
if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
pid_output=0; pid_output=0;
} }
} }
temp_dState[e] = pid_input; temp_dState[e] = pid_input;
#else #else
pid_output = constrain(target_temperature[e], 0, PID_MAX); pid_output = constrain(target_temperature[e], 0, PID_MAX);
#endif //PID_OPENLOOP #endif //PID_OPENLOOP
#ifdef PID_DEBUG #ifdef PID_DEBUG
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHO(" PID_DEBUG "); SERIAL_ECHO(" PID_DEBUG ");
SERIAL_ECHO(e); SERIAL_ECHO(e);
@ -660,13 +669,13 @@ void manage_heater()
SERIAL_ECHO(iTerm[e]); SERIAL_ECHO(iTerm[e]);
SERIAL_ECHO(" dTerm "); SERIAL_ECHO(" dTerm ");
SERIAL_ECHOLN(dTerm[e]); SERIAL_ECHOLN(dTerm[e]);
#endif //PID_DEBUG #endif //PID_DEBUG
#else /* PID off */ #else /* PID off */
pid_output = 0; pid_output = 0;
if(current_temperature[e] < target_temperature[e]) { if(current_temperature[e] < target_temperature[e]) {
pid_output = PID_MAX; pid_output = PID_MAX;
} }
#endif #endif
// Check if temperature is within the correct range // Check if temperature is within the correct range
#ifdef AMBIENT_THERMISTOR #ifdef AMBIENT_THERMISTOR
@ -682,7 +691,7 @@ void manage_heater()
soft_pwm[e] = 0; soft_pwm[e] = 0;
} }
#ifdef WATCH_TEMP_PERIOD #ifdef WATCH_TEMP_PERIOD
if(watchmillis[e] && millis() - watchmillis[e] > WATCH_TEMP_PERIOD) if(watchmillis[e] && millis() - watchmillis[e] > WATCH_TEMP_PERIOD)
{ {
if(degHotend(e) < watch_start_temp[e] + WATCH_TEMP_INCREASE) if(degHotend(e) < watch_start_temp[e] + WATCH_TEMP_INCREASE)
@ -691,12 +700,12 @@ void manage_heater()
LCD_MESSAGEPGM("Heating failed"); LCD_MESSAGEPGM("Heating failed");
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLN("Heating failed"); SERIAL_ECHOLN("Heating failed");
}else{ } else {
watchmillis[e] = 0; watchmillis[e] = 0;
} }
} }
#endif #endif
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #ifdef TEMP_SENSOR_1_AS_REDUNDANT
if(fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) { if(fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) {
disable_heater(); disable_heater();
if(IsStopped() == false) { if(IsStopped() == false) {
@ -704,15 +713,15 @@ void manage_heater()
SERIAL_ERRORLNPGM("Extruder switched off. Temperature difference between temp sensors is too high !"); SERIAL_ERRORLNPGM("Extruder switched off. Temperature difference between temp sensors is too high !");
LCD_ALERTMESSAGEPGM("Err: REDUNDANT TEMP ERROR"); LCD_ALERTMESSAGEPGM("Err: REDUNDANT TEMP ERROR");
} }
#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
Stop(); Stop();
#endif #endif
} }
#endif #endif
} // End extruder for loop } // End extruder for loop
#ifndef DEBUG_DISABLE_FANCHECK #ifndef DEBUG_DISABLE_FANCHECK
#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
if(millis() - extruder_autofan_last_check > 1000) // only need to check fan state very infrequently if(millis() - extruder_autofan_last_check > 1000) // only need to check fan state very infrequently
@ -724,21 +733,21 @@ void manage_heater()
checkExtruderAutoFans(); checkExtruderAutoFans();
extruder_autofan_last_check = millis(); extruder_autofan_last_check = millis();
} }
#endif #endif
#endif //DEBUG_DISABLE_FANCHECK #endif //DEBUG_DISABLE_FANCHECK
#ifndef PIDTEMPBED #ifndef PIDTEMPBED
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
return; return;
previous_millis_bed_heater = millis(); previous_millis_bed_heater = millis();
#endif #endif
#if TEMP_SENSOR_BED != 0 #if TEMP_SENSOR_BED != 0
#ifdef PIDTEMPBED #ifdef PIDTEMPBED
pid_input = current_temperature_bed; pid_input = current_temperature_bed;
#ifndef PID_OPENLOOP #ifndef PID_OPENLOOP
pid_error_bed = target_temperature_bed - pid_input; pid_error_bed = target_temperature_bed - pid_input;
pTerm_bed = cs.bedKp * pid_error_bed; pTerm_bed = cs.bedKp * pid_error_bed;
temp_iState_bed += pid_error_bed; temp_iState_bed += pid_error_bed;
@ -746,7 +755,7 @@ void manage_heater()
iTerm_bed = cs.bedKi * temp_iState_bed; iTerm_bed = cs.bedKi * temp_iState_bed;
//K1 defined in Configuration.h in the PID settings //K1 defined in Configuration.h in the PID settings
#define K2 (1.0-K1) #define K2 (1.0-K1)
dTerm_bed= (cs.bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed); dTerm_bed= (cs.bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed);
temp_dState_bed = pid_input; temp_dState_bed = pid_input;
@ -754,14 +763,14 @@ void manage_heater()
if (pid_output > MAX_BED_POWER) { if (pid_output > MAX_BED_POWER) {
if (pid_error_bed > 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration if (pid_error_bed > 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration
pid_output=MAX_BED_POWER; pid_output=MAX_BED_POWER;
} else if (pid_output < 0){ } else if (pid_output < 0) {
if (pid_error_bed < 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration if (pid_error_bed < 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration
pid_output=0; pid_output=0;
} }
#else #else
pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER); pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
#endif //PID_OPENLOOP #endif //PID_OPENLOOP
#ifdef AMBIENT_THERMISTOR #ifdef AMBIENT_THERMISTOR
if(((current_temperature_bed > BED_MINTEMP) || (current_temperature_ambient < MINTEMP_MINAMBIENT)) && (current_temperature_bed < BED_MAXTEMP)) if(((current_temperature_bed > BED_MINTEMP) || (current_temperature_ambient < MINTEMP_MINAMBIENT)) && (current_temperature_bed < BED_MAXTEMP))
@ -775,7 +784,7 @@ void manage_heater()
soft_pwm_bed = 0; soft_pwm_bed = 0;
} }
#elif !defined(BED_LIMIT_SWITCHING) #elif !defined(BED_LIMIT_SWITCHING)
// Check if temperature is within the correct range // Check if temperature is within the correct range
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP))
{ {
@ -793,7 +802,7 @@ void manage_heater()
soft_pwm_bed = 0; soft_pwm_bed = 0;
WRITE(HEATER_BED_PIN,LOW); WRITE(HEATER_BED_PIN,LOW);
} }
#else //#ifdef BED_LIMIT_SWITCHING #else //#ifdef BED_LIMIT_SWITCHING
// Check if temperature is within the correct band // Check if temperature is within the correct band
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP))
{ {
@ -811,8 +820,8 @@ void manage_heater()
soft_pwm_bed = 0; soft_pwm_bed = 0;
WRITE(HEATER_BED_PIN,LOW); WRITE(HEATER_BED_PIN,LOW);
} }
#endif #endif
#endif #endif
#ifdef HOST_KEEPALIVE_FEATURE #ifdef HOST_KEEPALIVE_FEATURE
host_keepalive(); host_keepalive();
@ -835,12 +844,12 @@ static float analog2temp(int raw, uint8_t e) {
kill(PSTR(""), 6); kill(PSTR(""), 6);
return 0.0; return 0.0;
} }
#ifdef HEATER_0_USES_MAX6675 #ifdef HEATER_0_USES_MAX6675
if (e == 0) if (e == 0)
{ {
return 0.25 * raw; return 0.25 * raw;
} }
#endif #endif
if(heater_ttbl_map[e] != NULL) if(heater_ttbl_map[e] != NULL)
{ {
@ -871,7 +880,7 @@ static float analog2temp(int raw, uint8_t e) {
// Derived from RepRap FiveD extruder::getTemperature() // Derived from RepRap FiveD extruder::getTemperature()
// For bed temperature measurement. // For bed temperature measurement.
static float analog2tempBed(int raw) { static float analog2tempBed(int raw) {
#ifdef BED_USES_THERMISTOR #ifdef BED_USES_THERMISTOR
float celsius = 0; float celsius = 0;
byte i; byte i;
@ -916,11 +925,11 @@ static float analog2tempBed(int raw) {
return celsius; return celsius;
#elif defined BED_USES_AD595 #elif defined BED_USES_AD595
return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET; return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET;
#else #else
return 0; return 0;
#endif #endif
} }
#ifdef AMBIENT_THERMISTOR #ifdef AMBIENT_THERMISTOR
@ -950,7 +959,7 @@ static float analog2tempAmbient(int raw)
and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */ and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
static void updateTemperaturesFromRawValues() static void updateTemperaturesFromRawValues()
{ {
for(uint8_t e=0;e<EXTRUDERS;e++) for(uint8_t e=0; e<EXTRUDERS; e++)
{ {
current_temperature[e] = analog2temp(current_temperature_raw[e], e); current_temperature[e] = analog2temp(current_temperature_raw[e], e);
} }
@ -969,9 +978,9 @@ static void updateTemperaturesFromRawValues()
current_temperature_bed = analog2tempBed(current_temperature_bed_raw); current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
#endif //DEBUG_HEATER_BED_SIM #endif //DEBUG_HEATER_BED_SIM
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #ifdef TEMP_SENSOR_1_AS_REDUNDANT
redundant_temperature = analog2temp(redundant_temperature_raw, 1); redundant_temperature = analog2temp(redundant_temperature_raw, 1);
#endif #endif
//Reset the watchdog after we know we have a temperature measurement. //Reset the watchdog after we know we have a temperature measurement.
#ifdef WATCHDOG #ifdef WATCHDOG
@ -1006,30 +1015,30 @@ void tp_init()
#endif //PIDTEMPBED #endif //PIDTEMPBED
} }
#if defined(HEATER_0_PIN) && (HEATER_0_PIN > -1) #if defined(HEATER_0_PIN) && (HEATER_0_PIN > -1)
SET_OUTPUT(HEATER_0_PIN); SET_OUTPUT(HEATER_0_PIN);
#endif #endif
#if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1) #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1)
SET_OUTPUT(HEATER_1_PIN); SET_OUTPUT(HEATER_1_PIN);
#endif #endif
#if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1) #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1)
SET_OUTPUT(HEATER_2_PIN); SET_OUTPUT(HEATER_2_PIN);
#endif #endif
#if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1) #if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1)
SET_OUTPUT(HEATER_BED_PIN); SET_OUTPUT(HEATER_BED_PIN);
#endif #endif
#if defined(FAN_PIN) && (FAN_PIN > -1) #if defined(FAN_PIN) && (FAN_PIN > -1)
SET_OUTPUT(FAN_PIN); SET_OUTPUT(FAN_PIN);
#ifdef FAST_PWM_FAN #ifdef FAST_PWM_FAN
setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8 setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
#endif #endif
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
soft_pwm_fan = fanSpeedSoftPwm / 2; soft_pwm_fan = fanSpeedSoftPwm / 2;
#endif #endif
#endif #endif
#ifdef HEATER_0_USES_MAX6675 #ifdef HEATER_0_USES_MAX6675
#ifndef SDSUPPORT #ifndef SDSUPPORT
SET_OUTPUT(SCK_PIN); SET_OUTPUT(SCK_PIN);
WRITE(SCK_PIN,0); WRITE(SCK_PIN,0);
@ -1038,7 +1047,7 @@ void tp_init()
SET_INPUT(MISO_PIN); SET_INPUT(MISO_PIN);
WRITE(MISO_PIN,1); WRITE(MISO_PIN,1);
#endif #endif
/* Using pinMode and digitalWrite, as that was the only way I could get it to compile */ /* Using pinMode and digitalWrite, as that was the only way I could get it to compile */
//Have to toggle SD card CS pin to low first, to enable firmware to talk with SD card //Have to toggle SD card CS pin to low first, to enable firmware to talk with SD card
@ -1046,7 +1055,7 @@ void tp_init()
digitalWrite(SS_PIN,0); digitalWrite(SS_PIN,0);
pinMode(MAX6675_SS, OUTPUT); pinMode(MAX6675_SS, OUTPUT);
digitalWrite(MAX6675_SS,1); digitalWrite(MAX6675_SS,1);
#endif #endif
adc_init(); adc_init();
@ -1233,9 +1242,13 @@ void temp_runaway_check(int _heater_id, float _target_temperature, float _curren
if (__preheat_errors[_heater_id] > ((_isbed) ? 2 : 5)) if (__preheat_errors[_heater_id] > ((_isbed) ? 2 : 5))
{ {
if (farm_mode) { prusa_statistics(0); } if (farm_mode) {
prusa_statistics(0);
}
temp_runaway_stop(true, _isbed); temp_runaway_stop(true, _isbed);
if (farm_mode) { prusa_statistics(91); } if (farm_mode) {
prusa_statistics(91);
}
} }
__preheat_start[_heater_id] = _current_temperature; __preheat_start[_heater_id] = _current_temperature;
__preheat_counter[_heater_id] = 0; __preheat_counter[_heater_id] = 0;
@ -1269,9 +1282,13 @@ void temp_runaway_check(int _heater_id, float _target_temperature, float _curren
temp_runaway_error_counter[_heater_id]++; temp_runaway_error_counter[_heater_id]++;
if (temp_runaway_error_counter[_heater_id] * 2 > __timeout) if (temp_runaway_error_counter[_heater_id] * 2 > __timeout)
{ {
if (farm_mode) { prusa_statistics(0); } if (farm_mode) {
prusa_statistics(0);
}
temp_runaway_stop(false, _isbed); temp_runaway_stop(false, _isbed);
if (farm_mode) { prusa_statistics(90); } if (farm_mode) {
prusa_statistics(90);
}
} }
} }
} }
@ -1301,7 +1318,7 @@ void temp_runaway_stop(bool isPreheat, bool isBed)
disable_e2(); disable_e2();
manage_heater(); manage_heater();
lcd_update(0); lcd_update(0);
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT)) if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
WRITE(BEEPER, HIGH); WRITE(BEEPER, HIGH);
delayMicroseconds(500); delayMicroseconds(500);
WRITE(BEEPER, LOW); WRITE(BEEPER, LOW);
@ -1334,37 +1351,37 @@ void disable_heater()
{ {
setAllTargetHotends(0); setAllTargetHotends(0);
setTargetBed(0); setTargetBed(0);
#if defined(TEMP_0_PIN) && TEMP_0_PIN > -1 #if defined(TEMP_0_PIN) && TEMP_0_PIN > -1
target_temperature[0]=0; target_temperature[0]=0;
soft_pwm[0]=0; soft_pwm[0]=0;
#if defined(HEATER_0_PIN) && HEATER_0_PIN > -1 #if defined(HEATER_0_PIN) && HEATER_0_PIN > -1
WRITE(HEATER_0_PIN,LOW); WRITE(HEATER_0_PIN,LOW);
#endif #endif
#endif #endif
#if defined(TEMP_1_PIN) && TEMP_1_PIN > -1 && EXTRUDERS > 1 #if defined(TEMP_1_PIN) && TEMP_1_PIN > -1 && EXTRUDERS > 1
target_temperature[1]=0; target_temperature[1]=0;
soft_pwm[1]=0; soft_pwm[1]=0;
#if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 #if defined(HEATER_1_PIN) && HEATER_1_PIN > -1
WRITE(HEATER_1_PIN,LOW); WRITE(HEATER_1_PIN,LOW);
#endif #endif
#endif #endif
#if defined(TEMP_2_PIN) && TEMP_2_PIN > -1 && EXTRUDERS > 2 #if defined(TEMP_2_PIN) && TEMP_2_PIN > -1 && EXTRUDERS > 2
target_temperature[2]=0; target_temperature[2]=0;
soft_pwm[2]=0; soft_pwm[2]=0;
#if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 #if defined(HEATER_2_PIN) && HEATER_2_PIN > -1
WRITE(HEATER_2_PIN,LOW); WRITE(HEATER_2_PIN,LOW);
#endif #endif
#endif #endif
#if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1
target_temperature_bed=0; target_temperature_bed=0;
soft_pwm_bed=0; soft_pwm_bed=0;
#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
WRITE(HEATER_BED_PIN,LOW); WRITE(HEATER_BED_PIN,LOW);
#endif #endif
#endif #endif
} }
void max_temp_error(uint8_t e) { void max_temp_error(uint8_t e) {
@ -1375,22 +1392,24 @@ void max_temp_error(uint8_t e) {
SERIAL_ERRORLNPGM(": Extruder switched off. MAXTEMP triggered !"); SERIAL_ERRORLNPGM(": Extruder switched off. MAXTEMP triggered !");
LCD_ALERTMESSAGEPGM("Err: MAXTEMP"); LCD_ALERTMESSAGEPGM("Err: MAXTEMP");
} }
#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
Stop(); Stop();
#endif #endif
SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN); SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
SET_OUTPUT(FAN_PIN); SET_OUTPUT(FAN_PIN);
SET_OUTPUT(BEEPER); SET_OUTPUT(BEEPER);
WRITE(FAN_PIN, 1); WRITE(FAN_PIN, 1);
WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1); WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT)) if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
WRITE(BEEPER, 1); WRITE(BEEPER, 1);
// fanSpeed will consumed by the check_axes_activity() routine. // fanSpeed will consumed by the check_axes_activity() routine.
fanSpeed=255; fanSpeed=255;
if (farm_mode) { prusa_statistics(93); } if (farm_mode) {
prusa_statistics(93);
}
} }
void min_temp_error(uint8_t e) { void min_temp_error(uint8_t e) {
@ -1405,10 +1424,12 @@ void min_temp_error(uint8_t e) {
SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !"); SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !");
LCD_ALERTMESSAGEPGM("Err: MINTEMP"); LCD_ALERTMESSAGEPGM("Err: MINTEMP");
} }
#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
Stop(); Stop();
#endif #endif
if (farm_mode) { prusa_statistics(92); } if (farm_mode) {
prusa_statistics(92);
}
} }
@ -1421,9 +1442,9 @@ void bed_max_temp_error(void) {
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !"); SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !");
LCD_ALERTMESSAGEPGM("Err: MAXTEMP BED"); LCD_ALERTMESSAGEPGM("Err: MAXTEMP BED");
} }
#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
Stop(); Stop();
#endif #endif
} }
@ -1458,11 +1479,11 @@ int read_max6675()
max6675_previous_millis = millis(); max6675_previous_millis = millis();
max6675_temp = 0; max6675_temp = 0;
#ifdef PRR #ifdef PRR
PRR &= ~(1<<PRSPI); PRR &= ~(1<<PRSPI);
#elif defined PRR0 #elif defined PRR0
PRR0 &= ~(1<<PRSPI); PRR0 &= ~(1<<PRSPI);
#endif #endif
SPCR = (1<<MSTR) | (1<<SPE) | (1<<SPR0); SPCR = (1<<MSTR) | (1<<SPE) | (1<<SPR0);
@ -1475,13 +1496,13 @@ int read_max6675()
// read MSB // read MSB
SPDR = 0; SPDR = 0;
for (;(SPSR & (1<<SPIF)) == 0;); for (; (SPSR & (1<<SPIF)) == 0;);
max6675_temp = SPDR; max6675_temp = SPDR;
max6675_temp <<= 8; max6675_temp <<= 8;
// read LSB // read LSB
SPDR = 0; SPDR = 0;
for (;(SPSR & (1<<SPIF)) == 0;); for (; (SPSR & (1<<SPIF)) == 0;);
max6675_temp |= SPDR; max6675_temp |= SPDR;
// disable TT_MAX6675 // disable TT_MAX6675
@ -1505,8 +1526,8 @@ int read_max6675()
extern "C" { extern "C" {
void adc_ready(void) //callback from adc when sampling finished void adc_ready(void) //callback from adc when sampling finished
{ {
current_temperature_raw[0] = adc_values[ADC_PIN_IDX(TEMP_0_PIN)]; //heater current_temperature_raw[0] = adc_values[ADC_PIN_IDX(TEMP_0_PIN)]; //heater
current_temperature_raw_pinda = adc_values[ADC_PIN_IDX(TEMP_PINDA_PIN)]; current_temperature_raw_pinda = adc_values[ADC_PIN_IDX(TEMP_PINDA_PIN)];
current_temperature_bed_raw = adc_values[ADC_PIN_IDX(TEMP_BED_PIN)]; current_temperature_bed_raw = adc_values[ADC_PIN_IDX(TEMP_BED_PIN)];
@ -1520,7 +1541,7 @@ void adc_ready(void) //callback from adc when sampling finished
current_voltage_raw_bed = adc_values[ADC_PIN_IDX(VOLT_BED_PIN)]; // 6->9 current_voltage_raw_bed = adc_values[ADC_PIN_IDX(VOLT_BED_PIN)]; // 6->9
#endif #endif
temp_meas_ready = true; temp_meas_ready = true;
} }
} // extern "C" } // extern "C"
@ -1590,19 +1611,23 @@ ISR(TIMER0_COMPB_vect)
} else WRITE(HEATER_0_PIN,0); } else WRITE(HEATER_0_PIN,0);
#if EXTRUDERS > 1 #if EXTRUDERS > 1
soft_pwm_1 = soft_pwm[1]; soft_pwm_1 = soft_pwm[1];
if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1); else WRITE(HEATER_1_PIN,0); if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1);
else WRITE(HEATER_1_PIN,0);
#endif #endif
#if EXTRUDERS > 2 #if EXTRUDERS > 2
soft_pwm_2 = soft_pwm[2]; soft_pwm_2 = soft_pwm[2];
if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1); else WRITE(HEATER_2_PIN,0); if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1);
else WRITE(HEATER_2_PIN,0);
#endif #endif
#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
soft_pwm_b = soft_pwm_bed; soft_pwm_b = soft_pwm_bed;
if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1); else WRITE(HEATER_BED_PIN,0); if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1);
else WRITE(HEATER_BED_PIN,0);
#endif #endif
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
soft_pwm_fan = fanSpeedSoftPwm / 2; soft_pwm_fan = fanSpeedSoftPwm / 2;
if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0); if(soft_pwm_fan > 0) WRITE(FAN_PIN,1);
else WRITE(FAN_PIN,0);
#endif #endif
} }
if(soft_pwm_0 < pwm_count) if(soft_pwm_0 < pwm_count)
@ -1810,9 +1835,10 @@ ISR(TIMER0_COMPB_vect)
#endif #endif
#ifdef FAN_SOFT_PWM #ifdef FAN_SOFT_PWM
if (pwm_count == 0){ if (pwm_count == 0) {
soft_pwm_fan = fanSpeedSoftPwm / 2; soft_pwm_fan = fanSpeedSoftPwm / 2;
if (soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0); if (soft_pwm_fan > 0) WRITE(FAN_PIN,1);
else WRITE(FAN_PIN,0);
} }
if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0);
#endif #endif
@ -1853,7 +1879,7 @@ ISR(TIMER0_COMPB_vect)
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
for(uint8_t axis=0;axis<3;axis++) for(uint8_t axis=0; axis<3; axis++)
{ {
int curTodo=babystepsTodo[axis]; //get rid of volatile for performance int curTodo=babystepsTodo[axis]; //get rid of volatile for performance
@ -1864,8 +1890,7 @@ ISR(TIMER0_COMPB_vect)
babystepsTodo[axis]--; //less to do next time babystepsTodo[axis]--; //less to do next time
asm("sei"); asm("sei");
} }
else else if(curTodo<0)
if(curTodo<0)
{ {
asm("cli"); asm("cli");
babystep(axis,/*fwd*/false); babystep(axis,/*fwd*/false);

View File

@ -24,7 +24,7 @@
#include "Marlin.h" #include "Marlin.h"
#include "planner.h" #include "planner.h"
#ifdef PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE
#include "stepper.h" #include "stepper.h"
#endif #endif
#define ENABLE_TEMPERATURE_INTERRUPT() TIMSK0 |= (1<<OCIE0B) #define ENABLE_TEMPERATURE_INTERRUPT() TIMSK0 |= (1<<OCIE0B)
@ -39,8 +39,8 @@ void manage_heater(); //it is critical that this is called periodically.
extern int target_temperature[EXTRUDERS]; extern int target_temperature[EXTRUDERS];
extern float current_temperature[EXTRUDERS]; extern float current_temperature[EXTRUDERS];
#ifdef SHOW_TEMP_ADC_VALUES #ifdef SHOW_TEMP_ADC_VALUES
extern int current_temperature_raw[EXTRUDERS]; extern int current_temperature_raw[EXTRUDERS];
extern int current_temperature_bed_raw; extern int current_temperature_bed_raw;
#endif #endif
extern int target_temperature_bed; extern int target_temperature_bed;
extern float current_temperature_bed; extern float current_temperature_bed;
@ -64,27 +64,27 @@ extern int current_voltage_raw_bed;
#endif #endif
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #ifdef TEMP_SENSOR_1_AS_REDUNDANT
extern float redundant_temperature; extern float redundant_temperature;
#endif #endif
#if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1 #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
extern unsigned char soft_pwm_bed; extern unsigned char soft_pwm_bed;
#endif #endif
#ifdef PIDTEMP #ifdef PIDTEMP
extern int pid_cycle, pid_number_of_cycles; extern int pid_cycle, pid_number_of_cycles;
extern float Kc,_Kp,_Ki,_Kd; extern float Kc,_Kp,_Ki,_Kd;
extern bool pid_tuning_finished; extern bool pid_tuning_finished;
float scalePID_i(float i); float scalePID_i(float i);
float scalePID_d(float d); float scalePID_d(float d);
float unscalePID_i(float i); float unscalePID_i(float i);
float unscalePID_d(float d); float unscalePID_d(float d);
#endif #endif
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
extern volatile int babystepsTodo[3]; extern volatile int babystepsTodo[3];
#endif #endif
inline void babystepsTodoZadd(int n) inline void babystepsTodoZadd(int n)
@ -114,13 +114,13 @@ FORCE_INLINE float degHotend(uint8_t extruder) {
}; };
#ifdef SHOW_TEMP_ADC_VALUES #ifdef SHOW_TEMP_ADC_VALUES
FORCE_INLINE float rawHotendTemp(uint8_t extruder) { FORCE_INLINE float rawHotendTemp(uint8_t extruder) {
return current_temperature_raw[extruder]; return current_temperature_raw[extruder];
}; };
FORCE_INLINE float rawBedTemp() { FORCE_INLINE float rawBedTemp() {
return current_temperature_bed_raw; return current_temperature_bed_raw;
}; };
#endif #endif
FORCE_INLINE float degBed() { FORCE_INLINE float degBed() {
@ -146,14 +146,14 @@ static inline void setTargetHotendSafe(const float &celsius, uint8_t extruder)
static inline void setAllTargetHotends(const float &celsius) static inline void setAllTargetHotends(const float &celsius)
{ {
for(int i=0;i<EXTRUDERS;i++) setTargetHotend(celsius,i); for(int i=0; i<EXTRUDERS; i++) setTargetHotend(celsius,i);
} }
FORCE_INLINE void setTargetBed(const float &celsius) { FORCE_INLINE void setTargetBed(const float &celsius) {
target_temperature_bed = celsius; target_temperature_bed = celsius;
}; };
FORCE_INLINE bool isHeatingHotend(uint8_t extruder){ FORCE_INLINE bool isHeatingHotend(uint8_t extruder) {
return target_temperature[extruder] > current_temperature[extruder]; return target_temperature[extruder] > current_temperature[extruder];
}; };
@ -202,15 +202,15 @@ void setWatch();
void updatePID(); void updatePID();
FORCE_INLINE void autotempShutdown(){ FORCE_INLINE void autotempShutdown() {
#ifdef AUTOTEMP #ifdef AUTOTEMP
if(autotemp_enabled) if(autotemp_enabled)
{ {
autotemp_enabled=false; autotemp_enabled=false;
if(degTargetHotend(active_extruder)>autotemp_min) if(degTargetHotend(active_extruder)>autotemp_min)
setTargetHotend(0,active_extruder); setTargetHotend(0,active_extruder);
} }
#endif #endif
} }
void PID_autotune(float temp, int extruder, int ncycles); void PID_autotune(float temp, int extruder, int ncycles);

View File

@ -9,67 +9,67 @@
#if (THERMISTORHEATER_0 == 1) || (THERMISTORHEATER_1 == 1) || (THERMISTORHEATER_2 == 1) || (THERMISTORBED == 1) //100k bed thermistor #if (THERMISTORHEATER_0 == 1) || (THERMISTORHEATER_1 == 1) || (THERMISTORHEATER_2 == 1) || (THERMISTORBED == 1) //100k bed thermistor
const short temptable_1[][2] PROGMEM = { const short temptable_1[][2] PROGMEM = {
{ 23*OVERSAMPLENR , 300 }, { 23*OVERSAMPLENR, 300 },
{ 25*OVERSAMPLENR , 295 }, { 25*OVERSAMPLENR, 295 },
{ 27*OVERSAMPLENR , 290 }, { 27*OVERSAMPLENR, 290 },
{ 28*OVERSAMPLENR , 285 }, { 28*OVERSAMPLENR, 285 },
{ 31*OVERSAMPLENR , 280 }, { 31*OVERSAMPLENR, 280 },
{ 33*OVERSAMPLENR , 275 }, { 33*OVERSAMPLENR, 275 },
{ 35*OVERSAMPLENR , 270 }, { 35*OVERSAMPLENR, 270 },
{ 38*OVERSAMPLENR , 265 }, { 38*OVERSAMPLENR, 265 },
{ 41*OVERSAMPLENR , 260 }, { 41*OVERSAMPLENR, 260 },
{ 44*OVERSAMPLENR , 255 }, { 44*OVERSAMPLENR, 255 },
{ 48*OVERSAMPLENR , 250 }, { 48*OVERSAMPLENR, 250 },
{ 52*OVERSAMPLENR , 245 }, { 52*OVERSAMPLENR, 245 },
{ 56*OVERSAMPLENR , 240 }, { 56*OVERSAMPLENR, 240 },
{ 61*OVERSAMPLENR , 235 }, { 61*OVERSAMPLENR, 235 },
{ 66*OVERSAMPLENR , 230 }, { 66*OVERSAMPLENR, 230 },
{ 71*OVERSAMPLENR , 225 }, { 71*OVERSAMPLENR, 225 },
{ 78*OVERSAMPLENR , 220 }, { 78*OVERSAMPLENR, 220 },
{ 84*OVERSAMPLENR , 215 }, { 84*OVERSAMPLENR, 215 },
{ 92*OVERSAMPLENR , 210 }, { 92*OVERSAMPLENR, 210 },
{ 100*OVERSAMPLENR , 205 }, { 100*OVERSAMPLENR, 205 },
{ 109*OVERSAMPLENR , 200 }, { 109*OVERSAMPLENR, 200 },
{ 120*OVERSAMPLENR , 195 }, { 120*OVERSAMPLENR, 195 },
{ 131*OVERSAMPLENR , 190 }, { 131*OVERSAMPLENR, 190 },
{ 143*OVERSAMPLENR , 185 }, { 143*OVERSAMPLENR, 185 },
{ 156*OVERSAMPLENR , 180 }, { 156*OVERSAMPLENR, 180 },
{ 171*OVERSAMPLENR , 175 }, { 171*OVERSAMPLENR, 175 },
{ 187*OVERSAMPLENR , 170 }, { 187*OVERSAMPLENR, 170 },
{ 205*OVERSAMPLENR , 165 }, { 205*OVERSAMPLENR, 165 },
{ 224*OVERSAMPLENR , 160 }, { 224*OVERSAMPLENR, 160 },
{ 245*OVERSAMPLENR , 155 }, { 245*OVERSAMPLENR, 155 },
{ 268*OVERSAMPLENR , 150 }, { 268*OVERSAMPLENR, 150 },
{ 293*OVERSAMPLENR , 145 }, { 293*OVERSAMPLENR, 145 },
{ 320*OVERSAMPLENR , 140 }, { 320*OVERSAMPLENR, 140 },
{ 348*OVERSAMPLENR , 135 }, { 348*OVERSAMPLENR, 135 },
{ 379*OVERSAMPLENR , 130 }, { 379*OVERSAMPLENR, 130 },
{ 411*OVERSAMPLENR , 125 }, { 411*OVERSAMPLENR, 125 },
{ 445*OVERSAMPLENR , 120 }, { 445*OVERSAMPLENR, 120 },
{ 480*OVERSAMPLENR , 115 }, { 480*OVERSAMPLENR, 115 },
{ 516*OVERSAMPLENR , 110 }, { 516*OVERSAMPLENR, 110 },
{ 553*OVERSAMPLENR , 105 }, { 553*OVERSAMPLENR, 105 },
{ 591*OVERSAMPLENR , 100 }, { 591*OVERSAMPLENR, 100 },
{ 628*OVERSAMPLENR , 95 }, { 628*OVERSAMPLENR, 95 },
{ 665*OVERSAMPLENR , 90 }, { 665*OVERSAMPLENR, 90 },
{ 702*OVERSAMPLENR , 85 }, { 702*OVERSAMPLENR, 85 },
{ 737*OVERSAMPLENR , 80 }, { 737*OVERSAMPLENR, 80 },
{ 770*OVERSAMPLENR , 75 }, { 770*OVERSAMPLENR, 75 },
{ 801*OVERSAMPLENR , 70 }, { 801*OVERSAMPLENR, 70 },
{ 830*OVERSAMPLENR , 65 }, { 830*OVERSAMPLENR, 65 },
{ 857*OVERSAMPLENR , 60 }, { 857*OVERSAMPLENR, 60 },
{ 881*OVERSAMPLENR , 55 }, { 881*OVERSAMPLENR, 55 },
{ 903*OVERSAMPLENR , 50 }, { 903*OVERSAMPLENR, 50 },
{ 922*OVERSAMPLENR , 45 }, { 922*OVERSAMPLENR, 45 },
{ 939*OVERSAMPLENR , 40 }, { 939*OVERSAMPLENR, 40 },
{ 954*OVERSAMPLENR , 35 }, { 954*OVERSAMPLENR, 35 },
{ 966*OVERSAMPLENR , 30 }, { 966*OVERSAMPLENR, 30 },
{ 977*OVERSAMPLENR , 25 }, { 977*OVERSAMPLENR, 25 },
{ 985*OVERSAMPLENR , 20 }, { 985*OVERSAMPLENR, 20 },
{ 993*OVERSAMPLENR , 15 }, { 993*OVERSAMPLENR, 15 },
{ 999*OVERSAMPLENR , 10 }, { 999*OVERSAMPLENR, 10 },
{ 1004*OVERSAMPLENR , 5 }, { 1004*OVERSAMPLENR, 5 },
{ 1008*OVERSAMPLENR , 0 } //safety { 1008*OVERSAMPLENR, 0 } //safety
}; };
#endif #endif
#if (THERMISTORHEATER_0 == 2) || (THERMISTORHEATER_1 == 2) || (THERMISTORHEATER_2 == 2) || (THERMISTORBED == 2) //200k bed thermistor #if (THERMISTORHEATER_0 == 2) || (THERMISTORHEATER_1 == 2) || (THERMISTORHEATER_2 == 2) || (THERMISTORBED == 2) //200k bed thermistor
@ -142,7 +142,7 @@ const short temptable_3[][2] PROGMEM = {
{986*OVERSAMPLENR,20}, {986*OVERSAMPLENR,20},
{1008*OVERSAMPLENR,0}, {1008*OVERSAMPLENR,0},
{1018*OVERSAMPLENR,-20} {1018*OVERSAMPLENR,-20}
}; };
#endif #endif
#if (THERMISTORHEATER_0 == 4) || (THERMISTORHEATER_1 == 4) || (THERMISTORHEATER_2 == 4) || (THERMISTORBED == 4) //10k thermistor #if (THERMISTORHEATER_0 == 4) || (THERMISTORHEATER_1 == 4) || (THERMISTORHEATER_2 == 4) || (THERMISTORBED == 4) //10k thermistor
@ -627,68 +627,68 @@ const short temptable_11[][2] PROGMEM = {
const short temptable_13[][2] PROGMEM = { const short temptable_13[][2] PROGMEM = {
{ 22.5*OVERSAMPLENR, 300 }, { 22.5*OVERSAMPLENR, 300 },
{ 24.125*OVERSAMPLENR, 295 }, { 24.125*OVERSAMPLENR, 295 },
{ 25.875*OVERSAMPLENR, 290 }, { 25.875*OVERSAMPLENR, 290 },
{ 27.8125*OVERSAMPLENR, 285 }, { 27.8125*OVERSAMPLENR, 285 },
{ 29.9375*OVERSAMPLENR, 280 }, { 29.9375*OVERSAMPLENR, 280 },
{ 32.25*OVERSAMPLENR, 275 }, { 32.25*OVERSAMPLENR, 275 },
{ 34.8125*OVERSAMPLENR, 270 }, { 34.8125*OVERSAMPLENR, 270 },
{ 37.625*OVERSAMPLENR, 265 }, { 37.625*OVERSAMPLENR, 265 },
{ 40.6875*OVERSAMPLENR, 260 }, { 40.6875*OVERSAMPLENR, 260 },
{ 44.0625*OVERSAMPLENR, 255 }, { 44.0625*OVERSAMPLENR, 255 },
{ 47.75*OVERSAMPLENR, 250 }, { 47.75*OVERSAMPLENR, 250 },
{ 51.8125*OVERSAMPLENR, 245 }, { 51.8125*OVERSAMPLENR, 245 },
{ 56.3125*OVERSAMPLENR, 240 }, { 56.3125*OVERSAMPLENR, 240 },
{ 61.25*OVERSAMPLENR, 235 }, { 61.25*OVERSAMPLENR, 235 },
{ 66.75*OVERSAMPLENR, 230 }, { 66.75*OVERSAMPLENR, 230 },
{ 72.8125*OVERSAMPLENR, 225 }, { 72.8125*OVERSAMPLENR, 225 },
{ 79.5*OVERSAMPLENR, 220 }, { 79.5*OVERSAMPLENR, 220 },
{ 87*OVERSAMPLENR, 215 }, { 87*OVERSAMPLENR, 215 },
{ 95.3125*OVERSAMPLENR, 210 }, { 95.3125*OVERSAMPLENR, 210 },
{ 104.1875*OVERSAMPLENR, 205 }, { 104.1875*OVERSAMPLENR, 205 },
{ 112.75*OVERSAMPLENR, 200 }, { 112.75*OVERSAMPLENR, 200 },
{ 123.125*OVERSAMPLENR, 195 }, { 123.125*OVERSAMPLENR, 195 },
{ 135.75*OVERSAMPLENR, 190 }, { 135.75*OVERSAMPLENR, 190 },
{ 148.3125*OVERSAMPLENR, 185 }, { 148.3125*OVERSAMPLENR, 185 },
{ 163.8125*OVERSAMPLENR, 180 }, { 163.8125*OVERSAMPLENR, 180 },
{ 179*OVERSAMPLENR, 175 }, { 179*OVERSAMPLENR, 175 },
{ 211.125*OVERSAMPLENR, 170 }, { 211.125*OVERSAMPLENR, 170 },
{ 216.125*OVERSAMPLENR, 165 }, { 216.125*OVERSAMPLENR, 165 },
{ 236.5625*OVERSAMPLENR, 160 }, { 236.5625*OVERSAMPLENR, 160 },
{ 258.5*OVERSAMPLENR, 155 }, { 258.5*OVERSAMPLENR, 155 },
{ 279.875*OVERSAMPLENR, 150 }, { 279.875*OVERSAMPLENR, 150 },
{ 305.375*OVERSAMPLENR, 145 }, { 305.375*OVERSAMPLENR, 145 },
{ 333.25*OVERSAMPLENR, 140 }, { 333.25*OVERSAMPLENR, 140 },
{ 362.5625*OVERSAMPLENR, 135 }, { 362.5625*OVERSAMPLENR, 135 },
{ 393.6875*OVERSAMPLENR, 130 }, { 393.6875*OVERSAMPLENR, 130 },
{ 425*OVERSAMPLENR, 125 }, { 425*OVERSAMPLENR, 125 },
{ 460.625*OVERSAMPLENR, 120 }, { 460.625*OVERSAMPLENR, 120 },
{ 495.1875*OVERSAMPLENR, 115 }, { 495.1875*OVERSAMPLENR, 115 },
{ 530.875*OVERSAMPLENR, 110 }, { 530.875*OVERSAMPLENR, 110 },
{ 567.25*OVERSAMPLENR, 105 }, { 567.25*OVERSAMPLENR, 105 },
{ 601.625*OVERSAMPLENR, 100 }, { 601.625*OVERSAMPLENR, 100 },
{ 637.875*OVERSAMPLENR, 95 }, { 637.875*OVERSAMPLENR, 95 },
{ 674.5625*OVERSAMPLENR, 90 }, { 674.5625*OVERSAMPLENR, 90 },
{ 710*OVERSAMPLENR, 85 }, { 710*OVERSAMPLENR, 85 },
{ 744.125*OVERSAMPLENR, 80 }, { 744.125*OVERSAMPLENR, 80 },
{ 775.9375*OVERSAMPLENR, 75 }, { 775.9375*OVERSAMPLENR, 75 },
{ 806.875*OVERSAMPLENR, 70 }, { 806.875*OVERSAMPLENR, 70 },
{ 835.1875*OVERSAMPLENR, 65 }, { 835.1875*OVERSAMPLENR, 65 },
{ 861.125*OVERSAMPLENR, 60 }, { 861.125*OVERSAMPLENR, 60 },
{ 884.375*OVERSAMPLENR, 55 }, { 884.375*OVERSAMPLENR, 55 },
{ 904.5625*OVERSAMPLENR, 50 }, { 904.5625*OVERSAMPLENR, 50 },
{ 923.8125*OVERSAMPLENR, 45 }, { 923.8125*OVERSAMPLENR, 45 },
{ 940.375*OVERSAMPLENR, 40 }, { 940.375*OVERSAMPLENR, 40 },
{ 954.625*OVERSAMPLENR, 35 }, { 954.625*OVERSAMPLENR, 35 },
{ 966.875*OVERSAMPLENR, 30 }, { 966.875*OVERSAMPLENR, 30 },
{ 977.0625*OVERSAMPLENR, 25 }, { 977.0625*OVERSAMPLENR, 25 },
{ 986*OVERSAMPLENR, 20 }, { 986*OVERSAMPLENR, 20 },
{ 993.375*OVERSAMPLENR, 15 }, { 993.375*OVERSAMPLENR, 15 },
{ 999.5*OVERSAMPLENR, 10 }, { 999.5*OVERSAMPLENR, 10 },
{ 1004.5*OVERSAMPLENR, 5 }, { 1004.5*OVERSAMPLENR, 5 },
{ 1008.5*OVERSAMPLENR, 0 } { 1008.5*OVERSAMPLENR, 0 }
}; };
#endif #endif
#if (THERMISTORHEATER_0 == 20) || (THERMISTORHEATER_1 == 20) || (THERMISTORHEATER_2 == 20) || (THERMISTORBED == 20) // PT100 with INA826 amp on Ultimaker v2.0 electronics #if (THERMISTORHEATER_0 == 20) || (THERMISTORHEATER_1 == 20) || (THERMISTORHEATER_2 == 20) || (THERMISTORBED == 20) // PT100 with INA826 amp on Ultimaker v2.0 electronics
@ -711,55 +711,55 @@ This does not match the normal thermistor behaviour so we need to set the follow
# define HEATER_BED_RAW_LO_TEMP 0 # define HEATER_BED_RAW_LO_TEMP 0
#endif #endif
const short temptable_20[][2] PROGMEM = { const short temptable_20[][2] PROGMEM = {
{ 0*OVERSAMPLENR , 0 }, { 0*OVERSAMPLENR, 0 },
{ 227*OVERSAMPLENR , 1 }, { 227*OVERSAMPLENR, 1 },
{ 236*OVERSAMPLENR , 10 }, { 236*OVERSAMPLENR, 10 },
{ 245*OVERSAMPLENR , 20 }, { 245*OVERSAMPLENR, 20 },
{ 253*OVERSAMPLENR , 30 }, { 253*OVERSAMPLENR, 30 },
{ 262*OVERSAMPLENR , 40 }, { 262*OVERSAMPLENR, 40 },
{ 270*OVERSAMPLENR , 50 }, { 270*OVERSAMPLENR, 50 },
{ 279*OVERSAMPLENR , 60 }, { 279*OVERSAMPLENR, 60 },
{ 287*OVERSAMPLENR , 70 }, { 287*OVERSAMPLENR, 70 },
{ 295*OVERSAMPLENR , 80 }, { 295*OVERSAMPLENR, 80 },
{ 304*OVERSAMPLENR , 90 }, { 304*OVERSAMPLENR, 90 },
{ 312*OVERSAMPLENR , 100 }, { 312*OVERSAMPLENR, 100 },
{ 320*OVERSAMPLENR , 110 }, { 320*OVERSAMPLENR, 110 },
{ 329*OVERSAMPLENR , 120 }, { 329*OVERSAMPLENR, 120 },
{ 337*OVERSAMPLENR , 130 }, { 337*OVERSAMPLENR, 130 },
{ 345*OVERSAMPLENR , 140 }, { 345*OVERSAMPLENR, 140 },
{ 353*OVERSAMPLENR , 150 }, { 353*OVERSAMPLENR, 150 },
{ 361*OVERSAMPLENR , 160 }, { 361*OVERSAMPLENR, 160 },
{ 369*OVERSAMPLENR , 170 }, { 369*OVERSAMPLENR, 170 },
{ 377*OVERSAMPLENR , 180 }, { 377*OVERSAMPLENR, 180 },
{ 385*OVERSAMPLENR , 190 }, { 385*OVERSAMPLENR, 190 },
{ 393*OVERSAMPLENR , 200 }, { 393*OVERSAMPLENR, 200 },
{ 401*OVERSAMPLENR , 210 }, { 401*OVERSAMPLENR, 210 },
{ 409*OVERSAMPLENR , 220 }, { 409*OVERSAMPLENR, 220 },
{ 417*OVERSAMPLENR , 230 }, { 417*OVERSAMPLENR, 230 },
{ 424*OVERSAMPLENR , 240 }, { 424*OVERSAMPLENR, 240 },
{ 432*OVERSAMPLENR , 250 }, { 432*OVERSAMPLENR, 250 },
{ 440*OVERSAMPLENR , 260 }, { 440*OVERSAMPLENR, 260 },
{ 447*OVERSAMPLENR , 270 }, { 447*OVERSAMPLENR, 270 },
{ 455*OVERSAMPLENR , 280 }, { 455*OVERSAMPLENR, 280 },
{ 463*OVERSAMPLENR , 290 }, { 463*OVERSAMPLENR, 290 },
{ 470*OVERSAMPLENR , 300 }, { 470*OVERSAMPLENR, 300 },
{ 478*OVERSAMPLENR , 310 }, { 478*OVERSAMPLENR, 310 },
{ 485*OVERSAMPLENR , 320 }, { 485*OVERSAMPLENR, 320 },
{ 493*OVERSAMPLENR , 330 }, { 493*OVERSAMPLENR, 330 },
{ 500*OVERSAMPLENR , 340 }, { 500*OVERSAMPLENR, 340 },
{ 507*OVERSAMPLENR , 350 }, { 507*OVERSAMPLENR, 350 },
{ 515*OVERSAMPLENR , 360 }, { 515*OVERSAMPLENR, 360 },
{ 522*OVERSAMPLENR , 370 }, { 522*OVERSAMPLENR, 370 },
{ 529*OVERSAMPLENR , 380 }, { 529*OVERSAMPLENR, 380 },
{ 537*OVERSAMPLENR , 390 }, { 537*OVERSAMPLENR, 390 },
{ 544*OVERSAMPLENR , 400 }, { 544*OVERSAMPLENR, 400 },
{ 614*OVERSAMPLENR , 500 }, { 614*OVERSAMPLENR, 500 },
{ 681*OVERSAMPLENR , 600 }, { 681*OVERSAMPLENR, 600 },
{ 744*OVERSAMPLENR , 700 }, { 744*OVERSAMPLENR, 700 },
{ 805*OVERSAMPLENR , 800 }, { 805*OVERSAMPLENR, 800 },
{ 862*OVERSAMPLENR , 900 }, { 862*OVERSAMPLENR, 900 },
{ 917*OVERSAMPLENR , 1000 }, { 917*OVERSAMPLENR, 1000 },
{ 968*OVERSAMPLENR , 1100 } { 968*OVERSAMPLENR, 1100 }
}; };
#endif #endif
@ -1069,117 +1069,117 @@ const short temptable_147[][2] PROGMEM = {
const short temptable_148[][2] PROGMEM = { const short temptable_148[][2] PROGMEM = {
// These values have been calculated and tested over many days. See https://docs.google.com/spreadsheets/d/1MJXa6feEe0mGVCT2TrBwLxVOMoLDkJlvfQ4JXhAdV_E // These values have been calculated and tested over many days. See https://docs.google.com/spreadsheets/d/1MJXa6feEe0mGVCT2TrBwLxVOMoLDkJlvfQ4JXhAdV_E
// Values that are missing from the 5C gap are missing due to resolution limits. // Values that are missing from the 5C gap are missing due to resolution limits.
{19.00000 * OVERSAMPLENR, 0}, {19.00000 * OVERSAMPLENR, 0},
{19.25000 * OVERSAMPLENR, 5}, {19.25000 * OVERSAMPLENR, 5},
{19.50000 * OVERSAMPLENR, 10}, {19.50000 * OVERSAMPLENR, 10},
{19.87500 * OVERSAMPLENR, 15}, {19.87500 * OVERSAMPLENR, 15},
{20.25000 * OVERSAMPLENR, 20}, {20.25000 * OVERSAMPLENR, 20},
{21.00000 * OVERSAMPLENR, 25}, {21.00000 * OVERSAMPLENR, 25},
{21.75000 * OVERSAMPLENR, 35}, {21.75000 * OVERSAMPLENR, 35},
{22.00000 * OVERSAMPLENR, 40}, {22.00000 * OVERSAMPLENR, 40},
{23.00000 * OVERSAMPLENR, 50}, // 55C is more commonly used. {23.00000 * OVERSAMPLENR, 50}, // 55C is more commonly used.
{23.75000 * OVERSAMPLENR, 60}, {23.75000 * OVERSAMPLENR, 60},
{24.00000 * OVERSAMPLENR, 65}, {24.00000 * OVERSAMPLENR, 65},
{24.06250 * OVERSAMPLENR, 70}, {24.06250 * OVERSAMPLENR, 70},
{25.00000 * OVERSAMPLENR, 75}, {25.00000 * OVERSAMPLENR, 75},
{25.50000 * OVERSAMPLENR, 85}, {25.50000 * OVERSAMPLENR, 85},
{26.00000 * OVERSAMPLENR, 90}, {26.00000 * OVERSAMPLENR, 90},
{26.93750 * OVERSAMPLENR,100}, {26.93750 * OVERSAMPLENR,100},
{27.00000 * OVERSAMPLENR,105}, {27.00000 * OVERSAMPLENR,105},
{27.37500 * OVERSAMPLENR,110}, {27.37500 * OVERSAMPLENR,110},
{28.00000 * OVERSAMPLENR,115}, {28.00000 * OVERSAMPLENR,115},
{29.00000 * OVERSAMPLENR,125}, {29.00000 * OVERSAMPLENR,125},
{29.25000 * OVERSAMPLENR,135}, {29.25000 * OVERSAMPLENR,135},
{30.00000 * OVERSAMPLENR,140}, {30.00000 * OVERSAMPLENR,140},
{35.50000 * OVERSAMPLENR,150}, {35.50000 * OVERSAMPLENR,150},
{31.00000 * OVERSAMPLENR,155}, {31.00000 * OVERSAMPLENR,155},
{32.00000 * OVERSAMPLENR,165}, {32.00000 * OVERSAMPLENR,165},
{32.18750 * OVERSAMPLENR,175}, {32.18750 * OVERSAMPLENR,175},
{33.00000 * OVERSAMPLENR,180}, {33.00000 * OVERSAMPLENR,180},
{33.62500 * OVERSAMPLENR,190}, {33.62500 * OVERSAMPLENR,190},
{34.00000 * OVERSAMPLENR,195}, {34.00000 * OVERSAMPLENR,195},
{35.00000 * OVERSAMPLENR,205}, {35.00000 * OVERSAMPLENR,205},
{35.50000 * OVERSAMPLENR,215}, {35.50000 * OVERSAMPLENR,215},
{36.00000 * OVERSAMPLENR,220}, {36.00000 * OVERSAMPLENR,220},
{36.75000 * OVERSAMPLENR,230}, {36.75000 * OVERSAMPLENR,230},
{37.00000 * OVERSAMPLENR,235}, {37.00000 * OVERSAMPLENR,235},
{37.75000 * OVERSAMPLENR,245}, {37.75000 * OVERSAMPLENR,245},
{38.00000 * OVERSAMPLENR,250}, {38.00000 * OVERSAMPLENR,250},
{38.12500 * OVERSAMPLENR,255}, {38.12500 * OVERSAMPLENR,255},
{39.00000 * OVERSAMPLENR,260}, {39.00000 * OVERSAMPLENR,260},
{40.00000 * OVERSAMPLENR,275}, {40.00000 * OVERSAMPLENR,275},
{40.25000 * OVERSAMPLENR,285}, {40.25000 * OVERSAMPLENR,285},
{41.00000 * OVERSAMPLENR,290}, {41.00000 * OVERSAMPLENR,290},
{41.25000 * OVERSAMPLENR,300}, {41.25000 * OVERSAMPLENR,300},
{42.00000 * OVERSAMPLENR,305}, {42.00000 * OVERSAMPLENR,305},
{43.00000 * OVERSAMPLENR,315}, {43.00000 * OVERSAMPLENR,315},
{43.25000 * OVERSAMPLENR,325}, {43.25000 * OVERSAMPLENR,325},
{44.00000 * OVERSAMPLENR,330}, {44.00000 * OVERSAMPLENR,330},
{44.18750 * OVERSAMPLENR,340}, {44.18750 * OVERSAMPLENR,340},
{45.00000 * OVERSAMPLENR,345}, {45.00000 * OVERSAMPLENR,345},
{45.25000 * OVERSAMPLENR,355}, {45.25000 * OVERSAMPLENR,355},
{46.00000 * OVERSAMPLENR,360}, {46.00000 * OVERSAMPLENR,360},
{46.62500 * OVERSAMPLENR,370}, {46.62500 * OVERSAMPLENR,370},
{47.00000 * OVERSAMPLENR,375}, {47.00000 * OVERSAMPLENR,375},
{47.25000 * OVERSAMPLENR,385}, {47.25000 * OVERSAMPLENR,385},
{48.00000 * OVERSAMPLENR,390}, {48.00000 * OVERSAMPLENR,390},
{48.75000 * OVERSAMPLENR,400}, {48.75000 * OVERSAMPLENR,400},
{49.00000 * OVERSAMPLENR,405}, {49.00000 * OVERSAMPLENR,405},
}; };
#endif #endif
#if (THERMISTORHEATER_0 == 247) || (THERMISTORHEATER_1 == 247) || (THERMISTORHEATER_2 == 247) || (THERMISTORBED == 247) // Pt100 with 4k7 MiniRambo pullup & PT100 Amplifier #if (THERMISTORHEATER_0 == 247) || (THERMISTORHEATER_1 == 247) || (THERMISTORHEATER_2 == 247) || (THERMISTORBED == 247) // Pt100 with 4k7 MiniRambo pullup & PT100 Amplifier
const short temptable_247[][2] PROGMEM = { const short temptable_247[][2] PROGMEM = {
// Calculated from Bob-the-Kuhn's PT100 calculator listed in https://github.com/MarlinFirmware/Marlin/issues/5543 // Calculated from Bob-the-Kuhn's PT100 calculator listed in https://github.com/MarlinFirmware/Marlin/issues/5543
// and the table provided by E3D at http://wiki.e3d-online.com/wiki/E3D_PT100_Amplifier_Documentation#Output_Characteristics. // and the table provided by E3D at http://wiki.e3d-online.com/wiki/E3D_PT100_Amplifier_Documentation#Output_Characteristics.
{ 0 * OVERSAMPLENR, 0}, { 0 * OVERSAMPLENR, 0},
{241 * OVERSAMPLENR, 1}, {241 * OVERSAMPLENR, 1},
{249 * OVERSAMPLENR, 10}, {249 * OVERSAMPLENR, 10},
{259 * OVERSAMPLENR, 20}, {259 * OVERSAMPLENR, 20},
{267 * OVERSAMPLENR, 30}, {267 * OVERSAMPLENR, 30},
{275 * OVERSAMPLENR, 40}, {275 * OVERSAMPLENR, 40},
{283 * OVERSAMPLENR, 50}, {283 * OVERSAMPLENR, 50},
{291 * OVERSAMPLENR, 60}, {291 * OVERSAMPLENR, 60},
{299 * OVERSAMPLENR, 70}, {299 * OVERSAMPLENR, 70},
{307 * OVERSAMPLENR, 80}, {307 * OVERSAMPLENR, 80},
{315 * OVERSAMPLENR, 90}, {315 * OVERSAMPLENR, 90},
{323 * OVERSAMPLENR, 100}, {323 * OVERSAMPLENR, 100},
{331 * OVERSAMPLENR, 110}, {331 * OVERSAMPLENR, 110},
{340 * OVERSAMPLENR, 120}, {340 * OVERSAMPLENR, 120},
{348 * OVERSAMPLENR, 130}, {348 * OVERSAMPLENR, 130},
{354 * OVERSAMPLENR, 140}, {354 * OVERSAMPLENR, 140},
{362 * OVERSAMPLENR, 150}, {362 * OVERSAMPLENR, 150},
{370 * OVERSAMPLENR, 160}, {370 * OVERSAMPLENR, 160},
{378 * OVERSAMPLENR, 170}, {378 * OVERSAMPLENR, 170},
{386 * OVERSAMPLENR, 180}, {386 * OVERSAMPLENR, 180},
{394 * OVERSAMPLENR, 190}, {394 * OVERSAMPLENR, 190},
{402 * OVERSAMPLENR, 200}, {402 * OVERSAMPLENR, 200},
{410 * OVERSAMPLENR, 210}, {410 * OVERSAMPLENR, 210},
{418 * OVERSAMPLENR, 220}, {418 * OVERSAMPLENR, 220},
{426 * OVERSAMPLENR, 230}, {426 * OVERSAMPLENR, 230},
{432 * OVERSAMPLENR, 240}, {432 * OVERSAMPLENR, 240},
{440 * OVERSAMPLENR, 250}, {440 * OVERSAMPLENR, 250},
{448 * OVERSAMPLENR, 260}, {448 * OVERSAMPLENR, 260},
{454 * OVERSAMPLENR, 270}, {454 * OVERSAMPLENR, 270},
{462 * OVERSAMPLENR, 280}, {462 * OVERSAMPLENR, 280},
{469 * OVERSAMPLENR, 290}, {469 * OVERSAMPLENR, 290},
{475 * OVERSAMPLENR, 300}, {475 * OVERSAMPLENR, 300},
{483 * OVERSAMPLENR, 310}, {483 * OVERSAMPLENR, 310},
{491 * OVERSAMPLENR, 320}, {491 * OVERSAMPLENR, 320},
{499 * OVERSAMPLENR, 330}, {499 * OVERSAMPLENR, 330},
{505 * OVERSAMPLENR, 340}, {505 * OVERSAMPLENR, 340},
{513 * OVERSAMPLENR, 350}, {513 * OVERSAMPLENR, 350},
{519 * OVERSAMPLENR, 360}, {519 * OVERSAMPLENR, 360},
{527 * OVERSAMPLENR, 370}, {527 * OVERSAMPLENR, 370},
{533 * OVERSAMPLENR, 380}, {533 * OVERSAMPLENR, 380},
{541 * OVERSAMPLENR, 390}, {541 * OVERSAMPLENR, 390},
{549 * OVERSAMPLENR, 400}, {549 * OVERSAMPLENR, 400},
{616 * OVERSAMPLENR, 500}, {616 * OVERSAMPLENR, 500},
{682 * OVERSAMPLENR, 600}, {682 * OVERSAMPLENR, 600},
{741 * OVERSAMPLENR, 700}, {741 * OVERSAMPLENR, 700},
{801 * OVERSAMPLENR, 800}, {801 * OVERSAMPLENR, 800},
{856 * OVERSAMPLENR, 900}, {856 * OVERSAMPLENR, 900},
{910 * OVERSAMPLENR, 1000}, {910 * OVERSAMPLENR, 1000},
{960 * OVERSAMPLENR, 1100}, {960 * OVERSAMPLENR, 1100},
}; };
#endif #endif
#if (THERMISTORHEATER_0 == 1010) || (THERMISTORHEATER_1 == 1010) || (THERMISTORHEATER_2 == 1010) || (THERMISTORBED == 1010) // Pt1000 with 1k0 pullup #if (THERMISTORHEATER_0 == 1010) || (THERMISTORHEATER_1 == 1010) || (THERMISTORHEATER_2 == 1010) || (THERMISTORBED == 1010) // Pt1000 with 1k0 pullup
@ -1216,74 +1216,74 @@ const short temptable_1047[][2] PROGMEM = {
const short temptable_2000[][2] PROGMEM = { const short temptable_2000[][2] PROGMEM = {
// Source: https://product.tdk.com/info/en/catalog/datasheets/503021/tpd_ntc-thermistor_ntcg_en.pdf // Source: https://product.tdk.com/info/en/catalog/datasheets/503021/tpd_ntc-thermistor_ntcg_en.pdf
// Calculated using 4.7kohm pullup, voltage divider math, and manufacturer provided temp/resistance // Calculated using 4.7kohm pullup, voltage divider math, and manufacturer provided temp/resistance
/*{305*OVERSAMPLENR, 125}, /*{305*OVERSAMPLENR, 125},
{338*OVERSAMPLENR, 120}, {338*OVERSAMPLENR, 120},
{374*OVERSAMPLENR, 115}, {374*OVERSAMPLENR, 115},
{412*OVERSAMPLENR, 110}, {412*OVERSAMPLENR, 110},
{452*OVERSAMPLENR, 105}, {452*OVERSAMPLENR, 105},
{494*OVERSAMPLENR, 100}, {494*OVERSAMPLENR, 100},
{536*OVERSAMPLENR, 95}, {536*OVERSAMPLENR, 95},
{580*OVERSAMPLENR, 90}, {580*OVERSAMPLENR, 90},
{623*OVERSAMPLENR, 85}, {623*OVERSAMPLENR, 85},
{665*OVERSAMPLENR, 80}, {665*OVERSAMPLENR, 80},
{706*OVERSAMPLENR, 75}, {706*OVERSAMPLENR, 75},
{744*OVERSAMPLENR, 70}, {744*OVERSAMPLENR, 70},
{780*OVERSAMPLENR, 65}, {780*OVERSAMPLENR, 65},
{813*OVERSAMPLENR, 60}, {813*OVERSAMPLENR, 60},
{843*OVERSAMPLENR, 55}, {843*OVERSAMPLENR, 55},
{869*OVERSAMPLENR, 50}, {869*OVERSAMPLENR, 50},
{892*OVERSAMPLENR, 45}, {892*OVERSAMPLENR, 45},
{912*OVERSAMPLENR, 40}, {912*OVERSAMPLENR, 40},
{929*OVERSAMPLENR, 35}, {929*OVERSAMPLENR, 35},
{943*OVERSAMPLENR, 30}, {943*OVERSAMPLENR, 30},
{955*OVERSAMPLENR, 25}, {955*OVERSAMPLENR, 25},
{965*OVERSAMPLENR, 20}, {965*OVERSAMPLENR, 20},
{973*OVERSAMPLENR, 15}, {973*OVERSAMPLENR, 15},
{979*OVERSAMPLENR, 10}, {979*OVERSAMPLENR, 10},
{984*OVERSAMPLENR, 5}, {984*OVERSAMPLENR, 5},
{988*OVERSAMPLENR, 0}, {988*OVERSAMPLENR, 0},
{991*OVERSAMPLENR, -5}, {991*OVERSAMPLENR, -5},
{993*OVERSAMPLENR, -10}, {993*OVERSAMPLENR, -10},
{995*OVERSAMPLENR, -15}, {995*OVERSAMPLENR, -15},
{996*OVERSAMPLENR, -20}, {996*OVERSAMPLENR, -20},
{997*OVERSAMPLENR, -25}, {997*OVERSAMPLENR, -25},
{998*OVERSAMPLENR, -30}, {998*OVERSAMPLENR, -30},
{999*OVERSAMPLENR, -35}, {999*OVERSAMPLENR, -35},
{999*OVERSAMPLENR, -40},*/ {999*OVERSAMPLENR, -40},*/
{313*OVERSAMPLENR,125}, {313*OVERSAMPLENR,125},
{347*OVERSAMPLENR,120}, {347*OVERSAMPLENR,120},
{383*OVERSAMPLENR,115}, {383*OVERSAMPLENR,115},
{422*OVERSAMPLENR,110}, {422*OVERSAMPLENR,110},
{463*OVERSAMPLENR,105}, {463*OVERSAMPLENR,105},
{506*OVERSAMPLENR,100}, {506*OVERSAMPLENR,100},
{549*OVERSAMPLENR,95}, {549*OVERSAMPLENR,95},
{594*OVERSAMPLENR,90}, {594*OVERSAMPLENR,90},
{638*OVERSAMPLENR,85}, {638*OVERSAMPLENR,85},
{681*OVERSAMPLENR,80}, {681*OVERSAMPLENR,80},
{722*OVERSAMPLENR,75}, {722*OVERSAMPLENR,75},
{762*OVERSAMPLENR,70}, {762*OVERSAMPLENR,70},
{799*OVERSAMPLENR,65}, {799*OVERSAMPLENR,65},
{833*OVERSAMPLENR,60}, {833*OVERSAMPLENR,60},
{863*OVERSAMPLENR,55}, {863*OVERSAMPLENR,55},
{890*OVERSAMPLENR,50}, {890*OVERSAMPLENR,50},
{914*OVERSAMPLENR,45}, {914*OVERSAMPLENR,45},
{934*OVERSAMPLENR,40}, {934*OVERSAMPLENR,40},
{951*OVERSAMPLENR,35}, {951*OVERSAMPLENR,35},
{966*OVERSAMPLENR,30}, {966*OVERSAMPLENR,30},
{978*OVERSAMPLENR,25}, {978*OVERSAMPLENR,25},
{988*OVERSAMPLENR,20}, {988*OVERSAMPLENR,20},
{996*OVERSAMPLENR,15}, {996*OVERSAMPLENR,15},
{1002*OVERSAMPLENR,10}, {1002*OVERSAMPLENR,10},
{1007*OVERSAMPLENR,5}, {1007*OVERSAMPLENR,5},
{1012*OVERSAMPLENR,0}, {1012*OVERSAMPLENR,0},
{1015*OVERSAMPLENR,-5}, {1015*OVERSAMPLENR,-5},
{1017*OVERSAMPLENR,-10}, {1017*OVERSAMPLENR,-10},
{1019*OVERSAMPLENR,-15}, {1019*OVERSAMPLENR,-15},
{1020*OVERSAMPLENR,-20}, {1020*OVERSAMPLENR,-20},
{1021*OVERSAMPLENR,-25}, {1021*OVERSAMPLENR,-25},
{1022*OVERSAMPLENR,-30}, {1022*OVERSAMPLENR,-30},
{1023*OVERSAMPLENR,-35}, {1023*OVERSAMPLENR,-35},
{1023*OVERSAMPLENR,-40}, {1023*OVERSAMPLENR,-40},
}; };
#endif #endif

View File

@ -136,9 +136,12 @@ uint16_t __tcoolthrs(uint8_t axis)
{ {
switch (axis) switch (axis)
{ {
case X_AXIS: return TMC2130_TCOOLTHRS_X; case X_AXIS:
case Y_AXIS: return TMC2130_TCOOLTHRS_Y; return TMC2130_TCOOLTHRS_X;
case Z_AXIS: return TMC2130_TCOOLTHRS_Z; case Y_AXIS:
return TMC2130_TCOOLTHRS_Y;
case Z_AXIS:
return TMC2130_TCOOLTHRS_Z;
} }
return 0; return 0;
} }
@ -240,8 +243,7 @@ void tmc2130_st_isr()
{ {
uint8_t mask = (X_AXIS_MASK << axis); uint8_t mask = (X_AXIS_MASK << axis);
if (diag_mask & mask) tmc2130_sg_err[axis]++; if (diag_mask & mask) tmc2130_sg_err[axis]++;
else else if (tmc2130_sg_err[axis] > 0) tmc2130_sg_err[axis]--;
if (tmc2130_sg_err[axis] > 0) tmc2130_sg_err[axis]--;
if (tmc2130_sg_cnt[axis] < tmc2130_sg_err[axis]) if (tmc2130_sg_cnt[axis] < tmc2130_sg_err[axis])
{ {
tmc2130_sg_cnt[axis] = tmc2130_sg_err[axis]; tmc2130_sg_cnt[axis] = tmc2130_sg_err[axis];
@ -590,7 +592,8 @@ void tmc2130_wr_THIGH(uint8_t axis, uint32_t val32)
uint8_t tmc2130_usteps2mres(uint16_t usteps) uint8_t tmc2130_usteps2mres(uint16_t usteps)
{ {
uint8_t mres = 8; while (mres && (usteps >>= 1)) mres--; uint8_t mres = 8;
while (mres && (usteps >>= 1)) mres--;
return mres; return mres;
} }
@ -599,10 +602,18 @@ inline void tmc2130_cs_low(uint8_t axis)
{ {
switch (axis) switch (axis)
{ {
case X_AXIS: WRITE(X_TMC2130_CS, LOW); break; case X_AXIS:
case Y_AXIS: WRITE(Y_TMC2130_CS, LOW); break; WRITE(X_TMC2130_CS, LOW);
case Z_AXIS: WRITE(Z_TMC2130_CS, LOW); break; break;
case E_AXIS: WRITE(E0_TMC2130_CS, LOW); break; case Y_AXIS:
WRITE(Y_TMC2130_CS, LOW);
break;
case Z_AXIS:
WRITE(Z_TMC2130_CS, LOW);
break;
case E_AXIS:
WRITE(E0_TMC2130_CS, LOW);
break;
} }
} }
@ -610,10 +621,18 @@ inline void tmc2130_cs_high(uint8_t axis)
{ {
switch (axis) switch (axis)
{ {
case X_AXIS: WRITE(X_TMC2130_CS, HIGH); break; case X_AXIS:
case Y_AXIS: WRITE(Y_TMC2130_CS, HIGH); break; WRITE(X_TMC2130_CS, HIGH);
case Z_AXIS: WRITE(Z_TMC2130_CS, HIGH); break; break;
case E_AXIS: WRITE(E0_TMC2130_CS, HIGH); break; case Y_AXIS:
WRITE(Y_TMC2130_CS, HIGH);
break;
case Z_AXIS:
WRITE(Z_TMC2130_CS, HIGH);
break;
case E_AXIS:
WRITE(E0_TMC2130_CS, HIGH);
break;
} }
} }
@ -707,10 +726,14 @@ uint8_t tmc2130_get_pwr(uint8_t axis)
{ {
switch (axis) switch (axis)
{ {
case X_AXIS: return _GET_PWR_X; case X_AXIS:
case Y_AXIS: return _GET_PWR_Y; return _GET_PWR_X;
case Z_AXIS: return _GET_PWR_Z; case Y_AXIS:
case E_AXIS: return _GET_PWR_E; return _GET_PWR_Y;
case Z_AXIS:
return _GET_PWR_Z;
case E_AXIS:
return _GET_PWR_E;
} }
return 0; return 0;
} }
@ -719,10 +742,18 @@ void tmc2130_set_pwr(uint8_t axis, uint8_t pwr)
{ {
switch (axis) switch (axis)
{ {
case X_AXIS: _SET_PWR_X(pwr); break; case X_AXIS:
case Y_AXIS: _SET_PWR_Y(pwr); break; _SET_PWR_X(pwr);
case Z_AXIS: _SET_PWR_Z(pwr); break; break;
case E_AXIS: _SET_PWR_E(pwr); break; case Y_AXIS:
_SET_PWR_Y(pwr);
break;
case Z_AXIS:
_SET_PWR_Z(pwr);
break;
case E_AXIS:
_SET_PWR_E(pwr);
break;
} }
} }
@ -730,10 +761,14 @@ uint8_t tmc2130_get_inv(uint8_t axis)
{ {
switch (axis) switch (axis)
{ {
case X_AXIS: return INVERT_X_DIR; case X_AXIS:
case Y_AXIS: return INVERT_Y_DIR; return INVERT_X_DIR;
case Z_AXIS: return INVERT_Z_DIR; case Y_AXIS:
case E_AXIS: return INVERT_E0_DIR; return INVERT_Y_DIR;
case Z_AXIS:
return INVERT_Z_DIR;
case E_AXIS:
return INVERT_E0_DIR;
} }
return 0; return 0;
} }
@ -742,10 +777,14 @@ uint8_t tmc2130_get_dir(uint8_t axis)
{ {
switch (axis) switch (axis)
{ {
case X_AXIS: return _GET_DIR_X; case X_AXIS:
case Y_AXIS: return _GET_DIR_Y; return _GET_DIR_X;
case Z_AXIS: return _GET_DIR_Z; case Y_AXIS:
case E_AXIS: return _GET_DIR_E; return _GET_DIR_Y;
case Z_AXIS:
return _GET_DIR_Z;
case E_AXIS:
return _GET_DIR_E;
} }
return 0; return 0;
} }
@ -755,10 +794,18 @@ void tmc2130_set_dir(uint8_t axis, uint8_t dir)
{ {
switch (axis) switch (axis)
{ {
case X_AXIS: _SET_DIR_X(dir); break; case X_AXIS:
case Y_AXIS: _SET_DIR_Y(dir); break; _SET_DIR_X(dir);
case Z_AXIS: _SET_DIR_Z(dir); break; break;
case E_AXIS: _SET_DIR_E(dir); break; case Y_AXIS:
_SET_DIR_Y(dir);
break;
case Z_AXIS:
_SET_DIR_Z(dir);
break;
case E_AXIS:
_SET_DIR_E(dir);
break;
} }
} }
@ -766,10 +813,18 @@ void tmc2130_do_step(uint8_t axis)
{ {
switch (axis) switch (axis)
{ {
case X_AXIS: _DO_STEP_X; break; case X_AXIS:
case Y_AXIS: _DO_STEP_Y; break; _DO_STEP_X;
case Z_AXIS: _DO_STEP_Z; break; break;
case E_AXIS: _DO_STEP_E; break; case Y_AXIS:
_DO_STEP_Y;
break;
case Z_AXIS:
_DO_STEP_Z;
break;
case E_AXIS:
_DO_STEP_E;
break;
} }
} }
@ -787,7 +842,8 @@ void tmc2130_do_steps(uint8_t axis, uint16_t steps, uint8_t dir, uint16_t delay_
void tmc2130_goto_step(uint8_t axis, uint8_t step, uint8_t dir, uint16_t delay_us, uint16_t microstep_resolution) void tmc2130_goto_step(uint8_t axis, uint8_t step, uint8_t dir, uint16_t delay_us, uint16_t microstep_resolution)
{ {
printf_P(PSTR("tmc2130_goto_step %d %d %d %d \n"), axis, step, dir, delay_us, microstep_resolution); printf_P(PSTR("tmc2130_goto_step %d %d %d %d \n"), axis, step, dir, delay_us, microstep_resolution);
uint8_t shift; for (shift = 0; shift < 8; shift++) if (microstep_resolution == (256u >> shift)) break; uint8_t shift;
for (shift = 0; shift < 8; shift++) if (microstep_resolution == (256u >> shift)) break;
uint16_t cnt = 4 * (1 << (8 - shift)); uint16_t cnt = 4 * (1 << (8 - shift));
uint16_t mscnt = tmc2130_rd_MSCNT(axis); uint16_t mscnt = tmc2130_rd_MSCNT(axis);
if (dir == 2) if (dir == 2)
@ -888,12 +944,29 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000)
b = 0; b = 0;
switch (dA) switch (dA)
{ {
case -1: d0 = -1; d1 = 0; w[s+1] = 0; break; case -1:
case 0: d0 = 0; d1 = 1; w[s+1] = 1; break; d0 = -1;
case 1: d0 = 1; d1 = 2; w[s+1] = 2; break; d1 = 0;
default: b = -1; break; w[s+1] = 0;
break;
case 0:
d0 = 0;
d1 = 1;
w[s+1] = 1;
break;
case 1:
d0 = 1;
d1 = 2;
w[s+1] = 2;
break;
default:
b = -1;
break;
}
if (b >= 0) {
x[s] = i;
s++;
} }
if (b >= 0) { x[s] = i; s++; }
} }
else if (dA > d1) // delta > delta0 => switch wbit up else if (dA > d1) // delta > delta0 => switch wbit up
{ {
@ -901,12 +974,29 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000)
b = 1; b = 1;
switch (dA) switch (dA)
{ {
case 1: d0 = 0; d1 = 1; w[s+1] = 1; break; case 1:
case 2: d0 = 1; d1 = 2; w[s+1] = 2; break; d0 = 0;
case 3: d0 = 2; d1 = 3; w[s+1] = 3; break; d1 = 1;
default: b = -1; break; w[s+1] = 1;
break;
case 2:
d0 = 1;
d1 = 2;
w[s+1] = 2;
break;
case 3:
d0 = 2;
d1 = 3;
w[s+1] = 3;
break;
default:
b = -1;
break;
}
if (b >= 0) {
x[s] = i;
s++;
} }
if (b >= 0) { x[s] = i; s++; }
} }
} }
if (b < 0) break; // delta out of range (<-1 or >3) if (b < 0) break; // delta out of range (<-1 or >3)

View File

@ -171,7 +171,7 @@ static void lcd_disable_farm_mode();
static void lcd_set_fan_check(); static void lcd_set_fan_check();
static char snmm_stop_print_menu(); static char snmm_stop_print_menu();
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
static void lcd_sort_type_set(); static void lcd_sort_type_set();
#endif #endif
static float count_e(float layer_heigth, float extrusion_width, float extrusion_length); static float count_e(float layer_heigth, float extrusion_width, float extrusion_length);
static void lcd_babystep_z(); static void lcd_babystep_z();
@ -239,7 +239,7 @@ static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, char* longF
char c; char c;
int enc_dif = lcd_encoder_diff; int enc_dif = lcd_encoder_diff;
uint8_t n = LCD_WIDTH - 1; uint8_t n = LCD_WIDTH - 1;
for(int g = 0; g<4;g++){ for(int g = 0; g<4; g++) {
lcd_set_cursor(0, g); lcd_set_cursor(0, g);
lcd_print(' '); lcd_print(' ');
} }
@ -256,20 +256,20 @@ static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, char* longF
lcd_print(c); lcd_print(c);
i++; i++;
longFilenameTMP++; longFilenameTMP++;
if(i==LCD_WIDTH){ if(i==LCD_WIDTH) {
i=1; i=1;
j++; j++;
longFilenameTMP = longFilename + j; longFilenameTMP = longFilename + j;
n = LCD_WIDTH - 1; n = LCD_WIDTH - 1;
for(int g = 0; g<300 ;g++){ for(int g = 0; g<300 ; g++) {
manage_heater(); manage_heater();
if(LCD_CLICKED || ( enc_dif != lcd_encoder_diff )){ if(LCD_CLICKED || ( enc_dif != lcd_encoder_diff )) {
longFilenameTMP = longFilename; longFilenameTMP = longFilename;
*(longFilenameTMP + LCD_WIDTH - 2) = '\0'; *(longFilenameTMP + LCD_WIDTH - 2) = '\0';
i = 1; i = 1;
j = 0; j = 0;
break; break;
}else{ } else {
if (j == 1) delay(3); //wait around 1.2 s to start scrolling text if (j == 1) delay(3); //wait around 1.2 s to start scrolling text
delay(1); //then scroll with redrawing every 300 ms delay(1); //then scroll with redrawing every 300 ms
} }
@ -277,7 +277,7 @@ static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, char* longF
} }
} }
} }
if(c!='\0'){ if(c!='\0') {
lcd_set_cursor(i, row); lcd_set_cursor(i, row);
lcd_print(c); lcd_print(c);
i++; i++;
@ -426,7 +426,7 @@ static uint8_t menu_item_sdfile(const char*
{ {
// printf_P(PSTR("menu file %d %d '%s'\n"), menu_row, menuData.sdcard_menu.viewState, str_fnl[0]?str_fnl:str_fn); // printf_P(PSTR("menu file %d %d '%s'\n"), menu_row, menuData.sdcard_menu.viewState, str_fnl[0]?str_fnl:str_fn);
lcd_set_cursor(0, menu_row); lcd_set_cursor(0, menu_row);
/* if (lcd_encoder == menu_item) /* if (lcd_encoder == menu_item)
{ {
lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 1); lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 1);
if (menuData.sdcard_menu.viewState == 0) if (menuData.sdcard_menu.viewState == 0)
@ -549,7 +549,7 @@ void lcdui_print_farm(void)
{ {
int chars = lcd_printf_P(_N(" F0 ")); int chars = lcd_printf_P(_N(" F0 "));
// lcd_space(5 - chars); // lcd_space(5 - chars);
/* /*
// Farm number display // Farm number display
if (farm_mode) if (farm_mode)
{ {
@ -570,16 +570,16 @@ void lcdui_print_farm(void)
} }
else { else {
#ifdef SNMM #ifdef SNMM
lcd_puts_P(PSTR(" E")); lcd_puts_P(PSTR(" E"));
lcd_print(get_ext_nr() + 1); lcd_print(get_ext_nr() + 1);
#else #else
lcd_set_cursor(LCD_WIDTH - 8 - 2, 2); lcd_set_cursor(LCD_WIDTH - 8 - 2, 2);
lcd_puts_P(PSTR(" ")); lcd_puts_P(PSTR(" "));
#endif #endif
} }
*/ */
} }
#ifdef CMD_DIAGNOSTICS #ifdef CMD_DIAGNOSTICS
@ -1589,11 +1589,11 @@ void lcd_commands()
enquecommand_P(PSTR("G90")); enquecommand_P(PSTR("G90"));
// M83: Set extruder to relative mode. // M83: Set extruder to relative mode.
enquecommand_P(PSTR("M83")); enquecommand_P(PSTR("M83"));
#ifdef X_CANCEL_POS #ifdef X_CANCEL_POS
enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000")); enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
#else #else
enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000")); enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
#endif #endif
lcd_ignore_click(false); lcd_ignore_click(false);
if (mmu_enabled) if (mmu_enabled)
lcd_commands_step = 8; lcd_commands_step = 8;
@ -1628,10 +1628,18 @@ void lcd_commands()
else else
switch(snmm_stop_print_menu()) switch(snmm_stop_print_menu())
{ {
case 0: enquecommand_P(PSTR("M702")); break;//all case 0:
case 1: enquecommand_P(PSTR("M702 U")); break; //used enquecommand_P(PSTR("M702"));
case 2: enquecommand_P(PSTR("M702 C")); break; //current break;//all
default: enquecommand_P(PSTR("M702")); break; case 1:
enquecommand_P(PSTR("M702 U"));
break; //used
case 2:
enquecommand_P(PSTR("M702 C"));
break; //current
default:
enquecommand_P(PSTR("M702"));
break;
} }
lcd_commands_step = 3; lcd_commands_step = 3;
} }
@ -1648,7 +1656,9 @@ void lcd_commands()
if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm
{ {
if (lcd_commands_step == 0) { lcd_commands_step = 6; } if (lcd_commands_step == 0) {
lcd_commands_step = 6;
}
if (lcd_commands_step == 1 && !blocks_queued()) if (lcd_commands_step == 1 && !blocks_queued())
{ {
@ -1679,11 +1689,11 @@ void lcd_commands()
enquecommand_P(PSTR("G91")); enquecommand_P(PSTR("G91"));
enquecommand_P(PSTR("G1 Z15 F1500")); enquecommand_P(PSTR("G1 Z15 F1500"));
st_synchronize(); st_synchronize();
#ifdef SNMM #ifdef SNMM
lcd_commands_step = 7; lcd_commands_step = 7;
#else #else
lcd_commands_step = 5; lcd_commands_step = 5;
#endif #endif
} }
} }
@ -2130,7 +2140,7 @@ static void lcd_support_menu()
MENU_ITEM_BACK_P(PSTR(" repo " FW_REPOSITORY)); MENU_ITEM_BACK_P(PSTR(" repo " FW_REPOSITORY));
#endif #endif
// Ideally this block would be optimized out by the compiler. // Ideally this block would be optimized out by the compiler.
/* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P()); /* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
if (fw_string_len < 6) { if (fw_string_len < 6) {
MENU_ITEM_BACK_P(PSTR(MSG_FW_VERSION " - " FW_version)); MENU_ITEM_BACK_P(PSTR(MSG_FW_VERSION " - " FW_version));
} else { } else {
@ -2173,7 +2183,7 @@ static void lcd_support_menu()
///! MENU_ITEM(back_RAM, _md->ip_str, 0); ///! MENU_ITEM(back_RAM, _md->ip_str, 0);
} }
#ifndef MK1BP #ifndef MK1BP
MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_BACK_P(STR_SEPARATOR);
MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=19 r=1 MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=19 r=1
MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=15 r=1 MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=15 r=1
@ -2192,7 +2202,7 @@ static void lcd_support_menu()
MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug); MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);
#endif /* DEBUG_BUILD */ #endif /* DEBUG_BUILD */
#endif //MK1BP #endif //MK1BP
MENU_END(); MENU_END();
} }
@ -2842,10 +2852,10 @@ static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_ad
void lcd_adjust_bed_reset(void) void lcd_adjust_bed_reset(void)
{ {
eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0);
eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0);
_menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]); _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
_md->status = 0; _md->status = 0;
} }
@ -3001,7 +3011,7 @@ bool lcd_wait_for_pinda(float temp) {
pinda_timeout.start(); pinda_timeout.start();
bool target_temp_reached = true; bool target_temp_reached = true;
while (current_temperature_pinda > temp){ while (current_temperature_pinda > temp) {
lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3 lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
lcd_set_cursor(0, 4); lcd_set_cursor(0, 4);
@ -3277,8 +3287,8 @@ bool lcd_wait_for_click_delay(uint16_t nDelay)
// nDelay :: timeout [s] (0 ~ no timeout) // nDelay :: timeout [s] (0 ~ no timeout)
// true ~ clicked, false ~ delayed // true ~ clicked, false ~ delayed
{ {
bool bDelayed; bool bDelayed;
long nTime0 = millis()/1000; long nTime0 = millis()/1000;
KEEPALIVE_STATE(PAUSED_FOR_USER); KEEPALIVE_STATE(PAUSED_FOR_USER);
for (;;) { for (;;) {
@ -3295,7 +3305,7 @@ long nTime0 = millis()/1000;
void lcd_wait_for_click() void lcd_wait_for_click()
{ {
lcd_wait_for_click_delay(0); lcd_wait_for_click_delay(0);
} }
//! @brief Show multiple screen message with yes and no possible choices and wait with possible timeout //! @brief Show multiple screen message with yes and no possible choices and wait with possible timeout
@ -3566,17 +3576,17 @@ void lcd_diag_show_end_stops()
#ifdef TMC2130 #ifdef TMC2130
static void lcd_show_pinda_state() static void lcd_show_pinda_state()
{ {
lcd_set_cursor(0, 0); lcd_set_cursor(0, 0);
lcd_puts_P((PSTR("P.I.N.D.A. state"))); lcd_puts_P((PSTR("P.I.N.D.A. state")));
lcd_set_cursor(0, 2); lcd_set_cursor(0, 2);
lcd_puts_P(READ(Z_MIN_PIN)?(PSTR("Z1 (LED off)")):(PSTR("Z0 (LED on) "))); // !!! both strings must have same length (due to dynamic refreshing) lcd_puts_P(READ(Z_MIN_PIN)?(PSTR("Z1 (LED off)")):(PSTR("Z0 (LED on) "))); // !!! both strings must have same length (due to dynamic refreshing)
} }
static void menu_show_pinda_state() static void menu_show_pinda_state()
{ {
lcd_timeoutToStatus.stop(); lcd_timeoutToStatus.stop();
lcd_show_pinda_state(); lcd_show_pinda_state();
if(LCD_CLICKED) if(LCD_CLICKED)
{ {
lcd_timeoutToStatus.start(); lcd_timeoutToStatus.start();
menu_back(); menu_back();
@ -3945,9 +3955,14 @@ static void lcd_sort_type_set() {
uint8_t sdSort; uint8_t sdSort;
EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort)); EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
switch (sdSort) { switch (sdSort) {
case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break; case SD_SORT_TIME:
case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break; sdSort = SD_SORT_ALPHA;
default: sdSort = SD_SORT_TIME; break;
case SD_SORT_ALPHA:
sdSort = SD_SORT_NONE;
break;
default:
sdSort = SD_SORT_TIME;
} }
eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort); eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
presort_flag = true; presort_flag = true;
@ -3983,7 +3998,7 @@ static void lcd_crash_mode_info2()
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
static void lcd_filament_autoload_info() static void lcd_filament_autoload_info()
{ {
uint8_t nlines; uint8_t nlines;
lcd_update_enable(true); lcd_update_enable(true);
static uint32_t tim = 0; static uint32_t tim = 0;
if ((tim + 1000) < millis()) if ((tim + 1000) < millis())
@ -3996,7 +4011,7 @@ uint8_t nlines;
static void lcd_fsensor_fail() static void lcd_fsensor_fail()
{ {
uint8_t nlines; uint8_t nlines;
lcd_update_enable(true); lcd_update_enable(true);
static uint32_t tim = 0; static uint32_t tim = 0;
if ((tim + 1000) < millis()) if ((tim + 1000) < millis())
@ -4011,20 +4026,34 @@ uint8_t nlines;
//-// //-//
static void lcd_sound_state_set(void) static void lcd_sound_state_set(void)
{ {
Sound_CycleState(); Sound_CycleState();
} }
static void lcd_silent_mode_set() { static void lcd_silent_mode_set() {
switch (SilentModeMenu) { switch (SilentModeMenu) {
#ifdef TMC2130 #ifdef TMC2130
case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break; case SILENT_MODE_NORMAL:
case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break; SilentModeMenu = SILENT_MODE_STEALTH;
default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed break;
case SILENT_MODE_STEALTH:
SilentModeMenu = SILENT_MODE_NORMAL;
break;
default:
SilentModeMenu = SILENT_MODE_NORMAL;
break; // (probably) not needed
#else #else
case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break; case SILENT_MODE_POWER:
case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break; SilentModeMenu = SILENT_MODE_SILENT;
case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break; break;
default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed case SILENT_MODE_SILENT:
SilentModeMenu = SILENT_MODE_AUTO;
break;
case SILENT_MODE_AUTO:
SilentModeMenu = SILENT_MODE_POWER;
break;
default:
SilentModeMenu = SILENT_MODE_POWER;
break; // (probably) not needed
#endif //TMC2130 #endif //TMC2130
} }
eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu); eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
@ -4058,7 +4087,7 @@ static void lcd_crash_mode_set()
CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable() CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable()
if (CrashDetectMenu==0) { if (CrashDetectMenu==0) {
crashdet_disable(); crashdet_disable();
}else{ } else {
crashdet_enable(); crashdet_enable();
} }
if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) menu_goto(lcd_tune_menu, 9, true, true); if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) menu_goto(lcd_tune_menu, 9, true, true);
@ -4472,12 +4501,25 @@ void lcd_wizard(WizState state)
break; break;
case S::Restore: // restore calibration status case S::Restore: // restore calibration status
switch (calibration_status()) { switch (calibration_status()) {
case CALIBRATION_STATUS_ASSEMBLED: state = S::Selftest; break; //run selftest case CALIBRATION_STATUS_ASSEMBLED:
case CALIBRATION_STATUS_XYZ_CALIBRATION: state = S::Xyz; break; //run xyz cal. state = S::Selftest;
case CALIBRATION_STATUS_Z_CALIBRATION: state = S::Z; break; //run z cal. break; //run selftest
case CALIBRATION_STATUS_LIVE_ADJUST: state = S::IsFil; break; //run live adjust case CALIBRATION_STATUS_XYZ_CALIBRATION:
case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break; state = S::Xyz;
default: state = S::Selftest; break; //if calibration status is unknown, run wizard from the beginning break; //run xyz cal.
case CALIBRATION_STATUS_Z_CALIBRATION:
state = S::Z;
break; //run z cal.
case CALIBRATION_STATUS_LIVE_ADJUST:
state = S::IsFil;
break; //run live adjust
case CALIBRATION_STATUS_CALIBRATED:
end = true;
eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
break;
default:
state = S::Selftest;
break; //if calibration status is unknown, run wizard from the beginning
} }
break; break;
case S::Selftest: case S::Selftest:
@ -4583,7 +4625,8 @@ void lcd_wizard(WizState state)
end = true; end = true;
break; break;
default: break; default:
break;
} }
} }
@ -5075,8 +5118,10 @@ void bowden_menu() {
static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
lcd_clear(); lcd_clear();
lcd_puts_at_P(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd_print(":"); lcd_puts_at_P(0,0,_T(MSG_UNLOAD_FILAMENT));
lcd_set_cursor(0, 1); lcd_print(">"); lcd_print(":");
lcd_set_cursor(0, 1);
lcd_print(">");
lcd_puts_at_P(1,2,_i("Used during print"));////MSG_USED c=19 r=1 lcd_puts_at_P(1,2,_i("Used during print"));////MSG_USED c=19 r=1
lcd_puts_at_P(1,3,_i("Current"));////MSG_CURRENT c=19 r=1 lcd_puts_at_P(1,3,_i("Current"));////MSG_CURRENT c=19 r=1
char cursor_pos = 1; char cursor_pos = 1;
@ -5372,7 +5417,7 @@ static void fil_unload_menu()
} }
static void change_extr_menu(){ static void change_extr_menu() {
MENU_BEGIN(); MENU_BEGIN();
MENU_ITEM_BACK_P(_T(MSG_MAIN)); MENU_ITEM_BACK_P(_T(MSG_MAIN));
MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1 MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1
@ -5443,19 +5488,33 @@ static void lcd_farm_no()
if (abs((enc_dif - lcd_encoder_diff)) > 2) { if (abs((enc_dif - lcd_encoder_diff)) > 2) {
if (enc_dif > lcd_encoder_diff) { if (enc_dif > lcd_encoder_diff) {
switch (step) { switch (step) {
case(0): if (_farmno >= 100) _farmno -= 100; break; case(0):
case(1): if (_farmno % 100 >= 10) _farmno -= 10; break; if (_farmno >= 100) _farmno -= 100;
case(2): if (_farmno % 10 >= 1) _farmno--; break; break;
default: break; case(1):
if (_farmno % 100 >= 10) _farmno -= 10;
break;
case(2):
if (_farmno % 10 >= 1) _farmno--;
break;
default:
break;
} }
} }
if (enc_dif < lcd_encoder_diff) { if (enc_dif < lcd_encoder_diff) {
switch (step) { switch (step) {
case(0): if (_farmno < 900) _farmno += 100; break; case(0):
case(1): if (_farmno % 100 < 90) _farmno += 10; break; if (_farmno < 900) _farmno += 100;
case(2): if (_farmno % 10 <= 8)_farmno++; break; break;
default: break; case(1):
if (_farmno % 100 < 90) _farmno += 10;
break;
case(2):
if (_farmno % 10 <= 8)_farmno++;
break;
default:
break;
} }
} }
enc_dif = 0; enc_dif = 0;
@ -5564,9 +5623,15 @@ unsigned char lcd_choose_color() {
if (lcd_clicked()) { if (lcd_clicked()) {
switch(cursor_pos + first - 1) { switch(cursor_pos + first - 1) {
case 0: return 1; break; case 0:
case 1: return 0; break; return 1;
default: return 99; break; break;
case 1:
return 0;
break;
default:
return 99;
break;
} }
} }
@ -5601,11 +5666,17 @@ void lcd_confirm_print()
enc_dif = lcd_encoder_diff; enc_dif = lcd_encoder_diff;
} }
if (cursor_pos > 2) { cursor_pos = 2; } if (cursor_pos > 2) {
if (cursor_pos < 1) { cursor_pos = 1; } cursor_pos = 2;
}
if (cursor_pos < 1) {
cursor_pos = 1;
}
lcd_set_cursor(0, 2); lcd_print(" "); lcd_set_cursor(0, 2);
lcd_set_cursor(0, 3); lcd_print(" "); lcd_print(" ");
lcd_set_cursor(0, 3);
lcd_print(" ");
lcd_set_cursor(2, 2); lcd_set_cursor(2, 2);
lcd_puts_P(_T(MSG_YES)); lcd_puts_P(_T(MSG_YES));
lcd_set_cursor(2, 3); lcd_set_cursor(2, 3);
@ -5712,9 +5783,9 @@ static void lcd_main_menu()
card.getWorkDirName(); card.getWorkDirName();
if (card.filename[0] == '/') if (card.filename[0] == '/')
{ {
#if SDCARDDETECT == -1 #if SDCARDDETECT == -1
MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh); MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
#endif #endif
} else { } else {
MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
} }
@ -5723,11 +5794,11 @@ static void lcd_main_menu()
{ {
if (menu_item == menu_line) if (menu_item == menu_line)
{ {
#ifndef SDCARD_RATHERRECENTFIRST #ifndef SDCARD_RATHERRECENTFIRST
card.getfilename(i); card.getfilename(i);
#else #else
card.getfilename(fileCnt - 1 - i); card.getfilename(fileCnt - 1 - i);
#endif #endif
if (card.filenameIsDir) if (card.filenameIsDir)
{ {
MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename); MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename);
@ -5860,7 +5931,7 @@ static void lcd_main_menu()
void stack_error() { void stack_error() {
SET_OUTPUT(BEEPER); SET_OUTPUT(BEEPER);
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT)) if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
WRITE(BEEPER, HIGH); WRITE(BEEPER, HIGH);
delay(1000); delay(1000);
WRITE(BEEPER, LOW); WRITE(BEEPER, LOW);
@ -5969,10 +6040,18 @@ static void lcd_tune_menu()
#else //TMC2130 #else //TMC2130
if (!farm_mode) { //dont show in menu if we are in farm mode if (!farm_mode) { //dont show in menu if we are in farm mode
switch (SilentModeMenu) { switch (SilentModeMenu) {
case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; case SILENT_MODE_POWER:
case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break; MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set);
case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break; break;
default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed case SILENT_MODE_SILENT:
MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set);
break;
case SILENT_MODE_AUTO:
MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set);
break;
default:
MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set);
break; // (probably) not needed
} }
} }
#endif //TMC2130 #endif //TMC2130
@ -6088,11 +6167,17 @@ void lcd_sdcard_stop()
lcd_puts_P(_T(MSG_NO)); lcd_puts_P(_T(MSG_NO));
lcd_set_cursor(2, 3); lcd_set_cursor(2, 3);
lcd_puts_P(_T(MSG_YES)); lcd_puts_P(_T(MSG_YES));
lcd_set_cursor(0, 2); lcd_print(" "); lcd_set_cursor(0, 2);
lcd_set_cursor(0, 3); lcd_print(" "); lcd_print(" ");
lcd_set_cursor(0, 3);
lcd_print(" ");
if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; } if ((int32_t)lcd_encoder > 2) {
if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; } lcd_encoder = 2;
}
if ((int32_t)lcd_encoder < 1) {
lcd_encoder = 1;
}
lcd_set_cursor(0, 1 + lcd_encoder); lcd_set_cursor(0, 1 + lcd_encoder);
lcd_print(">"); lcd_print(">");
@ -6148,12 +6233,12 @@ void lcd_sdcard_menu()
#endif #endif
#endif #endif
i;*/ i;*/
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
if (sdSort == SD_SORT_NONE) card.getfilename(nr); if (sdSort == SD_SORT_NONE) card.getfilename(nr);
else card.getfilename_sorted(nr); else card.getfilename_sorted(nr);
#else #else
card.getfilename(nr); card.getfilename(nr);
#endif #endif
if (card.filenameIsDir) if (card.filenameIsDir)
MENU_ITEM_SDDIR(card.filename, card.longFilename); MENU_ITEM_SDDIR(card.filename, card.longFilename);
@ -6177,10 +6262,11 @@ bool lcd_selftest()
bool _result = true; bool _result = true;
lcd_wait_for_cool_down(); lcd_wait_for_cool_down();
lcd_clear(); lcd_clear();
lcd_set_cursor(0, 0); lcd_puts_P(_i("Self test start "));////MSG_SELFTEST_START c=20 r=0 lcd_set_cursor(0, 0);
#ifdef TMC2130 lcd_puts_P(_i("Self test start "));////MSG_SELFTEST_START c=20 r=0
#ifdef TMC2130
FORCE_HIGH_POWER_START; FORCE_HIGH_POWER_START;
#endif // TMC2130 #endif // TMC2130
delay(2000); delay(2000);
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
@ -6350,9 +6436,9 @@ bool lcd_selftest()
{ {
LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED)); LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
} }
#ifdef TMC2130 #ifdef TMC2130
FORCE_HIGH_POWER_END; FORCE_HIGH_POWER_END;
#endif // TMC2130 #endif // TMC2130
KEEPALIVE_STATE(NOT_BUSY); KEEPALIVE_STATE(NOT_BUSY);
return(_result); return(_result);
} }
@ -6373,9 +6459,15 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) {
float margin = 60; float margin = 60;
float max_error_mm = 5; float max_error_mm = 5;
switch (axis) { switch (axis) {
case 0: axis_length = X_MAX_POS; break; case 0:
case 1: axis_length = Y_MAX_POS + 8; break; axis_length = X_MAX_POS;
default: axis_length = 210; break; break;
case 1:
axis_length = Y_MAX_POS + 8;
break;
default:
axis_length = 210;
break;
} }
tmc2130_sg_stop_on_crash = false; tmc2130_sg_stop_on_crash = false;
@ -6439,7 +6531,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) {
//end of second measurement, now check for possible errors: //end of second measurement, now check for possible errors:
for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length for(int i = 0; i < 2; i++) { //check if measured axis length corresponds to expected length
printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]); printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
if (abs(measured_axis_length[i] - axis_length) > max_error_mm) { if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
enable_endstops(false); enable_endstops(false);
@ -6894,7 +6986,8 @@ static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
bool _result = check_opposite; bool _result = check_opposite;
lcd_clear(); lcd_clear();
lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_SELFTEST_FAN)); lcd_set_cursor(0, 0);
lcd_puts_P(_T(MSG_SELFTEST_FAN));
switch (_fan) switch (_fan)
{ {
@ -6917,9 +7010,12 @@ static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
} }
delay(500); delay(500);
lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES)); lcd_set_cursor(1, 2);
lcd_set_cursor(0, 3); lcd_print(">"); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO)); lcd_set_cursor(0, 3);
lcd_print(">");
lcd_set_cursor(1, 3);
lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
int8_t enc_dif = 0; int8_t enc_dif = 0;
KEEPALIVE_STATE(PAUSED_FOR_USER); KEEPALIVE_STATE(PAUSED_FOR_USER);
@ -6944,18 +7040,26 @@ static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
if (abs((enc_dif - lcd_encoder_diff)) > 2) { if (abs((enc_dif - lcd_encoder_diff)) > 2) {
if (enc_dif > lcd_encoder_diff) { if (enc_dif > lcd_encoder_diff) {
_result = !check_opposite; _result = !check_opposite;
lcd_set_cursor(0, 2); lcd_print(">"); lcd_set_cursor(0, 2);
lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES)); lcd_print(">");
lcd_set_cursor(0, 3); lcd_print(" "); lcd_set_cursor(1, 2);
lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO)); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
lcd_set_cursor(0, 3);
lcd_print(" ");
lcd_set_cursor(1, 3);
lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
} }
if (enc_dif < lcd_encoder_diff) { if (enc_dif < lcd_encoder_diff) {
_result = check_opposite; _result = check_opposite;
lcd_set_cursor(0, 2); lcd_print(" "); lcd_set_cursor(0, 2);
lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES)); lcd_print(" ");
lcd_set_cursor(0, 3); lcd_print(">"); lcd_set_cursor(1, 2);
lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO)); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
lcd_set_cursor(0, 3);
lcd_print(">");
lcd_set_cursor(1, 3);
lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
} }
enc_dif = 0; enc_dif = 0;
lcd_encoder_diff = 0; lcd_encoder_diff = 0;
@ -7014,7 +7118,8 @@ static bool lcd_selftest_fan_dialog(int _fan)
manage_heater(); //turn off fan manage_heater(); //turn off fan
manage_inactivity(true); //to turn off print fan manage_inactivity(true); //to turn off print fan
if (!fan_speed[1]) { if (!fan_speed[1]) {
_result = false; _errno = 6; //print fan not spinning _result = false;
_errno = 6; //print fan not spinning
} }
else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
//check fans manually //check fans manually

View File

@ -65,7 +65,7 @@ extern bool lcd_calibrate_z_end_stop_manual(bool only_z);
#endif #endif
// Show the result of the calibration process on the LCD screen. // Show the result of the calibration process on the LCD screen.
extern void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask); extern void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask);
extern void lcd_diag_show_end_stops(); extern void lcd_diag_show_end_stops();

View File

@ -1,31 +1,37 @@
// unification for AVR and RPI // unification for AVR and RPI
#ifdef __AVR #ifdef __AVR
//#include "Arduino.h" //#include "Arduino.h"
#include "Marlin.h" #include "Marlin.h"
#define GPIO_INP(gpio) pinMode(gpio, INPUT) #define GPIO_INP(gpio) pinMode(gpio, INPUT)
#define GPIO_OUT(gpio) pinMode(gpio, OUTPUT) #define GPIO_OUT(gpio) pinMode(gpio, OUTPUT)
#define GPIO_SET(gpio) digitalWrite(gpio, HIGH) #define GPIO_SET(gpio) digitalWrite(gpio, HIGH)
#define GPIO_CLR(gpio) digitalWrite(gpio, LOW) #define GPIO_CLR(gpio) digitalWrite(gpio, LOW)
#define GPIO_GET(gpio) (digitalRead(gpio) != LOW) #define GPIO_GET(gpio) (digitalRead(gpio) != LOW)
#define DELAY(delay) delayMicroseconds(delay) #define DELAY(delay) delayMicroseconds(delay)
#define PRINT MYSERIAL.print #define PRINT MYSERIAL.print
#endif //RC522_AVR #endif //RC522_AVR
#ifdef __RPI #ifdef __RPI
#include <bcm2835.h> #include <bcm2835.h>
#define GPIO_INP(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_INPT) #define GPIO_INP(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_INPT)
#define GPIO_OUT(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_OUTP) #define GPIO_OUT(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_OUTP)
#define GPIO_SET(gpio) bcm2835_gpio_write(gpio, HIGH) #define GPIO_SET(gpio) bcm2835_gpio_write(gpio, HIGH)
#define GPIO_CLR(gpio) bcm2835_gpio_write(gpio, LOW) #define GPIO_CLR(gpio) bcm2835_gpio_write(gpio, LOW)
#define GPIO_GET(gpio) (bcm2835_gpio_lev(gpio) != LOW) #define GPIO_GET(gpio) (bcm2835_gpio_lev(gpio) != LOW)
#include <unistd.h> #include <unistd.h>
#define DELAY(delay) usleep(delay) #define DELAY(delay) usleep(delay)
#define PRINT(p) print(p) #define PRINT(p) print(p)
#define DEC 10 #define DEC 10
#define HEX 16 #define HEX 16
void print(const char* pc) { printf("%s", pc); } void print(const char* pc) {
void print(int v) { printf("%d", v); } printf("%s", pc);
void print(float v) { printf("%f", v); } }
void print(int v) {
printf("%d", v);
}
void print(float v) {
printf("%f", v);
}
#endif //RC522_RPI #endif //RC522_RPI

View File

@ -165,7 +165,8 @@ inline bool parse_version_P(const char *str, uint16_t version[4])
uint8_t n = minor - major - 1; uint8_t n = minor - major - 1;
if (n > 4) if (n > 4)
return false; return false;
memcpy_P(buf, major, n); buf[n] = 0; memcpy_P(buf, major, n);
buf[n] = 0;
char *endptr = NULL; char *endptr = NULL;
version[0] = strtol(buf, &endptr, 10); version[0] = strtol(buf, &endptr, 10);
if (*endptr != 0) if (*endptr != 0)
@ -173,7 +174,8 @@ inline bool parse_version_P(const char *str, uint16_t version[4])
n = rev - minor - 1; n = rev - minor - 1;
if (n > 4) if (n > 4)
return false; return false;
memcpy_P(buf, minor, n); buf[n] = 0; memcpy_P(buf, minor, n);
buf[n] = 0;
version[1] = strtol(buf, &endptr, 10); version[1] = strtol(buf, &endptr, 10);
if (*endptr != 0) if (*endptr != 0)
return false; return false;
@ -295,12 +297,12 @@ bool show_upgrade_dialog_if_version_newer(const char *version_string)
for (const char *c = version_string; ! is_whitespace_or_nl_or_eol(*c); ++ c) for (const char *c = version_string; ! is_whitespace_or_nl_or_eol(*c); ++ c)
lcd_putc(*c); lcd_putc(*c);
lcd_puts_at_P(0, 3, _i("Please upgrade."));////MSG_NEW_FIRMWARE_PLEASE_UPGRADE c=20 r=0 lcd_puts_at_P(0, 3, _i("Please upgrade."));////MSG_NEW_FIRMWARE_PLEASE_UPGRADE c=20 r=0
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
tone(BEEPER, 1000); tone(BEEPER, 1000);
delay_keep_alive(50); delay_keep_alive(50);
noTone(BEEPER); noTone(BEEPER);
delay_keep_alive(500); delay_keep_alive(500);
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
tone(BEEPER, 1000); tone(BEEPER, 1000);
delay_keep_alive(50); delay_keep_alive(50);
noTone(BEEPER); noTone(BEEPER);

View File

@ -102,9 +102,15 @@ matrix_3x3 matrix_3x3::create_from_rows(vector_3 row_0, vector_3 row_1, vector_3
//row_1.debug("row_1"); //row_1.debug("row_1");
//row_2.debug("row_2"); //row_2.debug("row_2");
matrix_3x3 new_matrix; matrix_3x3 new_matrix;
new_matrix.matrix[0] = row_0.x; new_matrix.matrix[1] = row_0.y; new_matrix.matrix[2] = row_0.z; new_matrix.matrix[0] = row_0.x;
new_matrix.matrix[3] = row_1.x; new_matrix.matrix[4] = row_1.y; new_matrix.matrix[5] = row_1.z; new_matrix.matrix[1] = row_0.y;
new_matrix.matrix[6] = row_2.x; new_matrix.matrix[7] = row_2.y; new_matrix.matrix[8] = row_2.z; new_matrix.matrix[2] = row_0.z;
new_matrix.matrix[3] = row_1.x;
new_matrix.matrix[4] = row_1.y;
new_matrix.matrix[5] = row_1.z;
new_matrix.matrix[6] = row_2.x;
new_matrix.matrix[7] = row_2.y;
new_matrix.matrix[8] = row_2.z;
//new_matrix.debug("new_matrix"); //new_matrix.debug("new_matrix");
return new_matrix; return new_matrix;
@ -112,9 +118,15 @@ matrix_3x3 matrix_3x3::create_from_rows(vector_3 row_0, vector_3 row_1, vector_3
void matrix_3x3::set_to_identity() void matrix_3x3::set_to_identity()
{ {
matrix[0] = 1; matrix[1] = 0; matrix[2] = 0; matrix[0] = 1;
matrix[3] = 0; matrix[4] = 1; matrix[5] = 0; matrix[1] = 0;
matrix[6] = 0; matrix[7] = 0; matrix[8] = 1; matrix[2] = 0;
matrix[3] = 0;
matrix[4] = 1;
matrix[5] = 0;
matrix[6] = 0;
matrix[7] = 0;
matrix[8] = 1;
} }
matrix_3x3 matrix_3x3::create_look_at(vector_3 target) matrix_3x3 matrix_3x3::create_look_at(vector_3 target)
@ -131,7 +143,7 @@ matrix_3x3 matrix_3x3::create_look_at(vector_3 target)
// create the matrix already correctly transposed // create the matrix already correctly transposed
matrix_3x3 rot = matrix_3x3::create_from_rows(x_row, y_row, z_row); matrix_3x3 rot = matrix_3x3::create_from_rows(x_row, y_row, z_row);
// rot.debug("rot"); // rot.debug("rot");
return rot; return rot;
} }
@ -139,9 +151,15 @@ matrix_3x3 matrix_3x3::create_look_at(vector_3 target)
matrix_3x3 matrix_3x3::transpose(matrix_3x3 original) matrix_3x3 matrix_3x3::transpose(matrix_3x3 original)
{ {
matrix_3x3 new_matrix; matrix_3x3 new_matrix;
new_matrix.matrix[0] = original.matrix[0]; new_matrix.matrix[1] = original.matrix[3]; new_matrix.matrix[2] = original.matrix[6]; new_matrix.matrix[0] = original.matrix[0];
new_matrix.matrix[3] = original.matrix[1]; new_matrix.matrix[4] = original.matrix[4]; new_matrix.matrix[5] = original.matrix[7]; new_matrix.matrix[1] = original.matrix[3];
new_matrix.matrix[6] = original.matrix[2]; new_matrix.matrix[7] = original.matrix[5]; new_matrix.matrix[8] = original.matrix[8]; new_matrix.matrix[2] = original.matrix[6];
new_matrix.matrix[3] = original.matrix[1];
new_matrix.matrix[4] = original.matrix[4];
new_matrix.matrix[5] = original.matrix[7];
new_matrix.matrix[6] = original.matrix[2];
new_matrix.matrix[7] = original.matrix[5];
new_matrix.matrix[8] = original.matrix[8];
return new_matrix; return new_matrix;
} }

View File

@ -88,9 +88,12 @@ uint8_t xyzcal_dm = 0;
void xyzcal_update_pos(uint16_t dx, uint16_t dy, uint16_t dz, uint16_t) void xyzcal_update_pos(uint16_t dx, uint16_t dy, uint16_t dz, uint16_t)
{ {
// DBG(_n("xyzcal_update_pos dx=%d dy=%d dz=%d dir=%02x\n"), dx, dy, dz, xyzcal_dm); // DBG(_n("xyzcal_update_pos dx=%d dy=%d dz=%d dir=%02x\n"), dx, dy, dz, xyzcal_dm);
if (xyzcal_dm&1) count_position[0] -= dx; else count_position[0] += dx; if (xyzcal_dm&1) count_position[0] -= dx;
if (xyzcal_dm&2) count_position[1] -= dy; else count_position[1] += dy; else count_position[0] += dx;
if (xyzcal_dm&4) count_position[2] -= dz; else count_position[2] += dz; if (xyzcal_dm&2) count_position[1] -= dy;
else count_position[1] += dy;
if (xyzcal_dm&4) count_position[2] -= dz;
else count_position[2] += dz;
// DBG(_n(" after xyzcal_update_pos x=%ld y=%ld z=%ld\n"), count_position[0], count_position[1], count_position[2]); // DBG(_n(" after xyzcal_update_pos x=%ld y=%ld z=%ld\n"), count_position[0], count_position[1], count_position[2]);
} }
@ -554,7 +557,7 @@ int8_t xyzcal_find_point_center2(uint16_t delay_us)
return 0; return 0;
} }
xyzcal_lineXYZ_to(x0, y0, z0, delay_us, 0); xyzcal_lineXYZ_to(x0, y0, z0, delay_us, 0);
xyzcal_lineXYZ_to(x0 , y0 - MAX_DIAMETR, z0, delay_us, -1); xyzcal_lineXYZ_to(x0, y0 - MAX_DIAMETR, z0, delay_us, -1);
int16_t dy1 = y0 - _Y; int16_t dy1 = y0 - _Y;
if (dy1 >= MAX_DIAMETR) if (dy1 >= MAX_DIAMETR)
{ {
@ -641,7 +644,7 @@ int8_t xyzcal_find_point_center(int16_t x0, int16_t y0, int16_t z0, int16_t min_
if (x_max < x) x_max = (2*x + x_max) / 3; if (x_max < x) x_max = (2*x + x_max) / 3;
if (y_min > y) y_min = (2*y + y_min) / 3; if (y_min > y) y_min = (2*y + y_min) / 3;
if (y_max < y) y_max = (2*y + y_max) / 3; if (y_max < y) y_max = (2*y + y_max) / 3;
/* if (x_min > x) x_min = x; /* if (x_min > x) x_min = x;
if (x_max < x) x_max = x; if (x_max < x) x_max = x;
if (y_min > y) y_min = y; if (y_min > y) y_min = y;
if (y_max < y) y_max = y;*/ if (y_max < y) y_max = y;*/
@ -649,7 +652,7 @@ int8_t xyzcal_find_point_center(int16_t x0, int16_t y0, int16_t z0, int16_t min_
if (r_max < r) r_max = r; if (r_max < r) r_max = r;
} }
r_sum += r; r_sum += r;
/* if (_pinda != pinda) /* if (_pinda != pinda)
{ {
if (pinda) if (pinda)
DBG(_n("!1 x=%d y=%d\n"), x, y); DBG(_n("!1 x=%d y=%d\n"), x, y);
@ -792,7 +795,8 @@ bool xyzcal_find_bed_induction_sensor_point_xy(void)
{ {
uint32_t x_avg = 0; uint32_t x_avg = 0;
uint32_t y_avg = 0; uint32_t y_avg = 0;
uint8_t n; for (n = 0; n < 4; n++) uint8_t n;
for (n = 0; n < 4; n++)
{ {
if (!xyzcal_find_point_center2(1000)) break; if (!xyzcal_find_point_center2(1000)) break;
x_avg += _X; x_avg += _X;