|
@@ -55,10 +55,10 @@
|
|
|
#include "math.h"
|
|
|
#include "util.h"
|
|
|
|
|
|
-#include <avr/wdt.h>
|
|
|
+#include <avr/wdt.h>
|
|
|
|
|
|
#ifdef HAVE_PAT9125_SENSOR
|
|
|
-#include "swspi.h"
|
|
|
+#include "swspi.h"
|
|
|
#include "pat9125.h"
|
|
|
#endif //HAVE_PAT9125_SENSOR
|
|
|
|
|
@@ -210,6 +210,7 @@
|
|
|
// M540 - Use S[0|1] to enable or disable the stop SD card print on endstop hit (requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
|
|
|
// M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
|
|
|
// M605 - Set dual x-carriage movement mode: S<mode> [ X<duplication x-offset> R<duplication temp offset> ]
|
|
|
+// M900 - Set LIN_ADVANCE options, if enabled. See Configuration_adv.h for details.
|
|
|
// M907 - Set digital trimpot motor current using axis codes.
|
|
|
// M908 - Control digital trimpot directly.
|
|
|
// M350 - Set microstepping mode.
|
|
@@ -910,86 +911,86 @@ static void lcd_language_menu();
|
|
|
|
|
|
#ifdef HAVE_PAT9125_SENSOR
|
|
|
|
|
|
-bool fsensor_enabled = true;
|
|
|
-bool fsensor_ignore_error = true;
|
|
|
-bool fsensor_M600 = false;
|
|
|
-long prev_pos_e = 0;
|
|
|
-long err_cnt = 0;
|
|
|
-
|
|
|
-#define FSENS_ESTEPS 140 //extruder resolution [steps/mm]
|
|
|
-#define FSENS_MINDEL 280 //filament sensor min delta [steps] (3mm)
|
|
|
-#define FSENS_MINFAC 3 //filament sensor minimum factor [count/mm]
|
|
|
-#define FSENS_MAXFAC 50 //filament sensor maximum factor [count/mm]
|
|
|
-#define FSENS_MAXERR 2 //filament sensor max error count
|
|
|
-
|
|
|
-void fsensor_enable()
|
|
|
-{
|
|
|
+bool fsensor_enabled = true;
|
|
|
+bool fsensor_ignore_error = true;
|
|
|
+bool fsensor_M600 = false;
|
|
|
+long prev_pos_e = 0;
|
|
|
+long err_cnt = 0;
|
|
|
+
|
|
|
+#define FSENS_ESTEPS 140 //extruder resolution [steps/mm]
|
|
|
+#define FSENS_MINDEL 280 //filament sensor min delta [steps] (3mm)
|
|
|
+#define FSENS_MINFAC 3 //filament sensor minimum factor [count/mm]
|
|
|
+#define FSENS_MAXFAC 50 //filament sensor maximum factor [count/mm]
|
|
|
+#define FSENS_MAXERR 2 //filament sensor max error count
|
|
|
+
|
|
|
+void fsensor_enable()
|
|
|
+{
|
|
|
MYSERIAL.println("fsensor_enable");
|
|
|
- pat9125_y = 0;
|
|
|
- prev_pos_e = st_get_position(E_AXIS);
|
|
|
- err_cnt = 0;
|
|
|
- fsensor_enabled = true;
|
|
|
- fsensor_ignore_error = true;
|
|
|
- fsensor_M600 = false;
|
|
|
-}
|
|
|
-
|
|
|
-void fsensor_disable()
|
|
|
-{
|
|
|
+ pat9125_y = 0;
|
|
|
+ prev_pos_e = st_get_position(E_AXIS);
|
|
|
+ err_cnt = 0;
|
|
|
+ fsensor_enabled = true;
|
|
|
+ fsensor_ignore_error = true;
|
|
|
+ fsensor_M600 = false;
|
|
|
+}
|
|
|
+
|
|
|
+void fsensor_disable()
|
|
|
+{
|
|
|
MYSERIAL.println("fsensor_disable");
|
|
|
- fsensor_enabled = false;
|
|
|
-}
|
|
|
-
|
|
|
-void fsensor_update()
|
|
|
-{
|
|
|
- if (!fsensor_enabled) return;
|
|
|
- long pos_e = st_get_position(E_AXIS); //current position
|
|
|
- pat9125_update();
|
|
|
- long del_e = pos_e - prev_pos_e; //delta
|
|
|
- if (abs(del_e) < FSENS_MINDEL) return;
|
|
|
- float de = ((float)del_e / FSENS_ESTEPS);
|
|
|
- int cmin = de * FSENS_MINFAC;
|
|
|
- int cmax = de * FSENS_MAXFAC;
|
|
|
- int cnt = pat9125_y;
|
|
|
- prev_pos_e = pos_e;
|
|
|
- pat9125_y = 0;
|
|
|
- bool err = false;
|
|
|
- if ((del_e > 0) && ((cnt < cmin) || (cnt > cmax))) err = true;
|
|
|
- if ((del_e < 0) && ((cnt > cmin) || (cnt < cmax))) err = true;
|
|
|
- if (err)
|
|
|
- err_cnt++;
|
|
|
- else
|
|
|
- err_cnt = 0;
|
|
|
-
|
|
|
-/*
|
|
|
- MYSERIAL.print("de=");
|
|
|
- MYSERIAL.print(de);
|
|
|
- MYSERIAL.print(" cmin=");
|
|
|
- MYSERIAL.print((int)cmin);
|
|
|
- MYSERIAL.print(" cmax=");
|
|
|
- MYSERIAL.print((int)cmax);
|
|
|
- MYSERIAL.print(" cnt=");
|
|
|
- MYSERIAL.print((int)cnt);
|
|
|
- MYSERIAL.print(" err=");
|
|
|
- MYSERIAL.println((int)err_cnt);*/
|
|
|
-
|
|
|
- if (err_cnt > FSENS_MAXERR)
|
|
|
- {
|
|
|
+ fsensor_enabled = false;
|
|
|
+}
|
|
|
+
|
|
|
+void fsensor_update()
|
|
|
+{
|
|
|
+ if (!fsensor_enabled) return;
|
|
|
+ long pos_e = st_get_position(E_AXIS); //current position
|
|
|
+ pat9125_update();
|
|
|
+ long del_e = pos_e - prev_pos_e; //delta
|
|
|
+ if (abs(del_e) < FSENS_MINDEL) return;
|
|
|
+ float de = ((float)del_e / FSENS_ESTEPS);
|
|
|
+ int cmin = de * FSENS_MINFAC;
|
|
|
+ int cmax = de * FSENS_MAXFAC;
|
|
|
+ int cnt = pat9125_y;
|
|
|
+ prev_pos_e = pos_e;
|
|
|
+ pat9125_y = 0;
|
|
|
+ bool err = false;
|
|
|
+ if ((del_e > 0) && ((cnt < cmin) || (cnt > cmax))) err = true;
|
|
|
+ if ((del_e < 0) && ((cnt > cmin) || (cnt < cmax))) err = true;
|
|
|
+ if (err)
|
|
|
+ err_cnt++;
|
|
|
+ else
|
|
|
+ err_cnt = 0;
|
|
|
+
|
|
|
+/*
|
|
|
+ MYSERIAL.print("de=");
|
|
|
+ MYSERIAL.print(de);
|
|
|
+ MYSERIAL.print(" cmin=");
|
|
|
+ MYSERIAL.print((int)cmin);
|
|
|
+ MYSERIAL.print(" cmax=");
|
|
|
+ MYSERIAL.print((int)cmax);
|
|
|
+ MYSERIAL.print(" cnt=");
|
|
|
+ MYSERIAL.print((int)cnt);
|
|
|
+ MYSERIAL.print(" err=");
|
|
|
+ MYSERIAL.println((int)err_cnt);*/
|
|
|
+
|
|
|
+ if (err_cnt > FSENS_MAXERR)
|
|
|
+ {
|
|
|
MYSERIAL.println("fsensor_update (err_cnt > FSENS_MAXERR)");
|
|
|
- if (fsensor_ignore_error)
|
|
|
- {
|
|
|
+ if (fsensor_ignore_error)
|
|
|
+ {
|
|
|
MYSERIAL.println("fsensor_update - error ignored)");
|
|
|
- fsensor_ignore_error = false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ fsensor_ignore_error = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
MYSERIAL.println("fsensor_update - ERROR!!!");
|
|
|
planner_abort_hard();
|
|
|
// planner_pause_and_save();
|
|
|
- enquecommand_front_P((PSTR("M600")));
|
|
|
- fsensor_M600 = true;
|
|
|
- fsensor_enabled = false;
|
|
|
- }
|
|
|
- }
|
|
|
+ enquecommand_front_P((PSTR("M600")));
|
|
|
+ fsensor_M600 = true;
|
|
|
+ fsensor_enabled = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#endif //HAVE_PAT9125_SENSOR
|
|
@@ -1755,6 +1756,15 @@ static inline long code_value_long() { return strtol(strchr_pointer+1, NUL
|
|
|
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() {
|
|
|
+ char* e = strchr(strchr_pointer, 'E');
|
|
|
+ if (!e) return strtod(strchr_pointer + 1, NULL);
|
|
|
+ *e = 0;
|
|
|
+ float ret = strtod(strchr_pointer + 1, NULL);
|
|
|
+ *e = 'E';
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
#define DEFINE_PGM_READ_ANY(type, reader) \
|
|
|
static inline type pgm_read_any(const type *p) \
|
|
|
{ return pgm_read_##reader##_near(p); }
|
|
@@ -1940,6 +1950,40 @@ static float probe_pt(float x, float y, float z_before) {
|
|
|
|
|
|
#endif // #ifdef ENABLE_AUTO_BED_LEVELING
|
|
|
|
|
|
+
|
|
|
+#ifdef LIN_ADVANCE
|
|
|
+ /**
|
|
|
+ * M900: Set and/or Get advance K factor and WH/D ratio
|
|
|
+ *
|
|
|
+ * K<factor> Set advance K factor
|
|
|
+ * R<ratio> Set ratio directly (overrides WH/D)
|
|
|
+ * W<width> H<height> D<diam> Set ratio from WH/D
|
|
|
+ */
|
|
|
+inline void gcode_M900() {
|
|
|
+ st_synchronize();
|
|
|
+
|
|
|
+ const float newK = code_seen('K') ? code_value_float() : -1;
|
|
|
+ if (newK >= 0) extruder_advance_k = newK;
|
|
|
+
|
|
|
+ float newR = code_seen('R') ? code_value_float() : -1;
|
|
|
+ if (newR < 0) {
|
|
|
+ const float newD = code_seen('D') ? code_value_float() : -1,
|
|
|
+ newW = code_seen('W') ? code_value_float() : -1,
|
|
|
+ newH = code_seen('H') ? code_value_float() : -1;
|
|
|
+ if (newD >= 0 && newW >= 0 && newH >= 0)
|
|
|
+ newR = newD ? (newW * newH) / (sq(newD * 0.5) * M_PI) : 0;
|
|
|
+ }
|
|
|
+ if (newR >= 0) advance_ed_ratio = newR;
|
|
|
+
|
|
|
+ SERIAL_ECHO_START;
|
|
|
+ SERIAL_ECHOPGM("Advance K=");
|
|
|
+ SERIAL_ECHOLN(extruder_advance_k);
|
|
|
+ SERIAL_ECHOPGM(" E/D=");
|
|
|
+ const float ratio = advance_ed_ratio;
|
|
|
+ if (ratio) SERIAL_ECHOLN(ratio); else SERIAL_ECHOLNPGM("Auto");
|
|
|
+ }
|
|
|
+#endif // LIN_ADVANCE
|
|
|
+
|
|
|
void homeaxis(int axis) {
|
|
|
#define HOMEAXIS_DO(LETTER) \
|
|
|
((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
|
|
@@ -5567,6 +5611,12 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
|
|
|
if(lcd_commands_type == 0) lcd_commands_type = LCD_COMMAND_LONG_PAUSE_RESUME;
|
|
|
}
|
|
|
break;
|
|
|
+
|
|
|
+#ifdef LIN_ADVANCE
|
|
|
+ case 900: // M900: Set LIN_ADVANCE options.
|
|
|
+ gcode_M900();
|
|
|
+ break;
|
|
|
+#endif
|
|
|
|
|
|
case 907: // M907 Set digital trimpot motor current using axis codes.
|
|
|
{
|
|
@@ -5793,6 +5843,12 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
|
|
|
}
|
|
|
snmm_filaments_used |= (1 << tmp_extruder); //for stop print
|
|
|
#ifdef SNMM
|
|
|
+
|
|
|
+ #ifdef LIN_ADVANCE
|
|
|
+ if (snmm_extruder != tmp_extruder)
|
|
|
+ clear_current_adv_vars(); //Check if the selected extruder is not the active one and reset LIN_ADVANCE variables if so.
|
|
|
+ #endif
|
|
|
+
|
|
|
snmm_extruder = tmp_extruder;
|
|
|
|
|
|
st_synchronize();
|
|
@@ -5883,66 +5939,66 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
|
|
|
}
|
|
|
} // end if(code_seen('T')) (end of T codes)
|
|
|
|
|
|
- else if (code_seen('D')) // D codes (debug)
|
|
|
- {
|
|
|
- switch((int)code_value())
|
|
|
- {
|
|
|
- case 0: // D0 - Reset
|
|
|
- MYSERIAL.println("D0 - Reset");
|
|
|
- cli(); //disable interrupts
|
|
|
- wdt_reset(); //reset watchdog
|
|
|
- WDTCSR = (1<<WDCE) | (1<<WDE); //enable watchdog
|
|
|
- WDTCSR = (1<<WDE) | (1<<WDP0); //30ms prescaler
|
|
|
- while(1); //wait for reset
|
|
|
- break;
|
|
|
- case 1: // D1 - Clear EEPROM
|
|
|
- {
|
|
|
- MYSERIAL.println("D1 - Clear EEPROM");
|
|
|
- cli();
|
|
|
- for (int i = 0; i < 4096; i++)
|
|
|
- eeprom_write_byte((unsigned char*)i, (unsigned char)0);
|
|
|
- sei();
|
|
|
- }
|
|
|
- break;
|
|
|
- case 2: // D2 - read/write PIN
|
|
|
- {
|
|
|
- if (code_seen('P')) // Pin (0-255)
|
|
|
- {
|
|
|
- int pin = (int)code_value();
|
|
|
- if ((pin >= 0) && (pin <= 255))
|
|
|
- {
|
|
|
- if (code_seen('F')) // Function in/out (0/1)
|
|
|
- {
|
|
|
- int fnc = (int)code_value();
|
|
|
- if (fnc == 0) pinMode(pin, INPUT);
|
|
|
- else if (fnc == 1) pinMode(pin, OUTPUT);
|
|
|
- }
|
|
|
- if (code_seen('V')) // Value (0/1)
|
|
|
- {
|
|
|
- int val = (int)code_value();
|
|
|
- if (val == 0) digitalWrite(pin, LOW);
|
|
|
- else if (val == 1) digitalWrite(pin, HIGH);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- int val = (digitalRead(pin) != LOW)?1:0;
|
|
|
- MYSERIAL.print("PIN");
|
|
|
- MYSERIAL.print(pin);
|
|
|
- MYSERIAL.print("=");
|
|
|
- MYSERIAL.println(val);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- fsensor_enable();
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- fsensor_disable();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ else if (code_seen('D')) // D codes (debug)
|
|
|
+ {
|
|
|
+ switch((int)code_value())
|
|
|
+ {
|
|
|
+ case 0: // D0 - Reset
|
|
|
+ MYSERIAL.println("D0 - Reset");
|
|
|
+ cli(); //disable interrupts
|
|
|
+ wdt_reset(); //reset watchdog
|
|
|
+ WDTCSR = (1<<WDCE) | (1<<WDE); //enable watchdog
|
|
|
+ WDTCSR = (1<<WDE) | (1<<WDP0); //30ms prescaler
|
|
|
+ while(1); //wait for reset
|
|
|
+ break;
|
|
|
+ case 1: // D1 - Clear EEPROM
|
|
|
+ {
|
|
|
+ MYSERIAL.println("D1 - Clear EEPROM");
|
|
|
+ cli();
|
|
|
+ for (int i = 0; i < 4096; i++)
|
|
|
+ eeprom_write_byte((unsigned char*)i, (unsigned char)0);
|
|
|
+ sei();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2: // D2 - read/write PIN
|
|
|
+ {
|
|
|
+ if (code_seen('P')) // Pin (0-255)
|
|
|
+ {
|
|
|
+ int pin = (int)code_value();
|
|
|
+ if ((pin >= 0) && (pin <= 255))
|
|
|
+ {
|
|
|
+ if (code_seen('F')) // Function in/out (0/1)
|
|
|
+ {
|
|
|
+ int fnc = (int)code_value();
|
|
|
+ if (fnc == 0) pinMode(pin, INPUT);
|
|
|
+ else if (fnc == 1) pinMode(pin, OUTPUT);
|
|
|
+ }
|
|
|
+ if (code_seen('V')) // Value (0/1)
|
|
|
+ {
|
|
|
+ int val = (int)code_value();
|
|
|
+ if (val == 0) digitalWrite(pin, LOW);
|
|
|
+ else if (val == 1) digitalWrite(pin, HIGH);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int val = (digitalRead(pin) != LOW)?1:0;
|
|
|
+ MYSERIAL.print("PIN");
|
|
|
+ MYSERIAL.print(pin);
|
|
|
+ MYSERIAL.print("=");
|
|
|
+ MYSERIAL.println(val);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ fsensor_enable();
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ fsensor_disable();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
else
|
|
|
{
|