|
@@ -18,8 +18,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
-#define FSENSOR_CHUNK_LEN 0.64F
|
|
|
-#define FSENSOR_ERR_MAX 17
|
|
|
+#define FSENSOR_CHUNK_LEN 1.25
|
|
|
+#define FSENSOR_ERR_MAX 4
|
|
|
+
|
|
|
+#define FSENSOR_SOFTERR_CMAX 3
|
|
|
+#define FSENSOR_SOFTERR_DELTA 30000
|
|
|
|
|
|
|
|
|
|
|
@@ -44,25 +47,30 @@ const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n";
|
|
|
#define FSENSOR_INT_PIN_PCMSK_BIT PCINT13
|
|
|
#define FSENSOR_INT_PIN_PCICR_BIT PCIE1
|
|
|
|
|
|
-
|
|
|
-uint8_t fsensor_int_pin_old = 0;
|
|
|
-int16_t fsensor_chunk_len = 0;
|
|
|
-
|
|
|
|
|
|
bool fsensor_enabled = true;
|
|
|
|
|
|
bool fsensor_watch_runout = true;
|
|
|
|
|
|
bool fsensor_not_responding = false;
|
|
|
+
|
|
|
+#ifdef PAT9125
|
|
|
+uint8_t fsensor_int_pin_old = 0;
|
|
|
+
|
|
|
+int16_t fsensor_chunk_len = 0;
|
|
|
|
|
|
bool fsensor_oq_meassure_enabled = false;
|
|
|
-
|
|
|
|
|
|
uint8_t fsensor_err_cnt = 0;
|
|
|
|
|
|
int16_t fsensor_st_cnt = 0;
|
|
|
-
|
|
|
-int16_t fsensor_dy_old = 0;
|
|
|
+
|
|
|
+uint8_t fsensor_softfail = 0;
|
|
|
+
|
|
|
+unsigned long fsensor_softfail_last = 0;
|
|
|
+
|
|
|
+uint8_t fsensor_softfail_ccnt = 0;
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
uint8_t fsensor_log = 1;
|
|
@@ -75,6 +83,8 @@ uint8_t fsensor_log = 1;
|
|
|
bool fsensor_autoload_enabled = true;
|
|
|
|
|
|
bool fsensor_watch_autoload = false;
|
|
|
+
|
|
|
+#ifdef PAT9125
|
|
|
|
|
|
uint16_t fsensor_autoload_y;
|
|
|
|
|
@@ -84,6 +94,7 @@ uint32_t fsensor_autoload_last_millis;
|
|
|
|
|
|
uint8_t fsensor_autoload_sum;
|
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
|
@@ -125,11 +136,29 @@ void fsensor_stop_and_save_print(void)
|
|
|
fsensor_watch_runout = false;
|
|
|
}
|
|
|
|
|
|
+#ifdef PAT9125
|
|
|
+
|
|
|
+void fsensor_reset_err_cnt()
|
|
|
+{
|
|
|
+ fsensor_err_cnt = 0;
|
|
|
+ pat9125_y = 0;
|
|
|
+ st_reset_fsensor();
|
|
|
+}
|
|
|
+
|
|
|
+void fsensor_set_axis_steps_per_unit(float u)
|
|
|
+{
|
|
|
+ fsensor_chunk_len = (int16_t)(FSENSOR_CHUNK_LEN * u);
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
void fsensor_restore_print_and_continue(void)
|
|
|
{
|
|
|
printf_P(PSTR("fsensor_restore_print_and_continue\n"));
|
|
|
fsensor_watch_runout = true;
|
|
|
- fsensor_err_cnt = 0;
|
|
|
+#ifdef PAT9125
|
|
|
+ fsensor_reset_err_cnt();
|
|
|
+#endif
|
|
|
restore_print_from_ram_and_continue(0);
|
|
|
}
|
|
|
|
|
@@ -154,7 +183,7 @@ void fsensor_init(void)
|
|
|
#ifdef PAT9125
|
|
|
uint8_t oq_meassure_enabled = eeprom_read_byte((uint8_t*)EEPROM_FSENS_OQ_MEASS_ENABLED);
|
|
|
fsensor_oq_meassure_enabled = (oq_meassure_enabled == 1)?true:false;
|
|
|
- fsensor_chunk_len = (int16_t)(FSENSOR_CHUNK_LEN * cs.axis_steps_per_unit[E_AXIS]);
|
|
|
+ fsensor_set_axis_steps_per_unit(cs.axis_steps_per_unit[E_AXIS]);
|
|
|
|
|
|
if (!pat9125)
|
|
|
{
|
|
@@ -194,8 +223,7 @@ bool fsensor_enable(bool bUpdateEEPROM)
|
|
|
fsensor_enabled = pat9125 ? true : false;
|
|
|
fsensor_watch_runout = true;
|
|
|
fsensor_oq_meassure = false;
|
|
|
- fsensor_err_cnt = 0;
|
|
|
- fsensor_dy_old = 0;
|
|
|
+ fsensor_reset_err_cnt();
|
|
|
eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled ? 0x01 : 0x00);
|
|
|
FSensorStateMenu = fsensor_enabled ? 1 : 0;
|
|
|
}
|
|
@@ -275,12 +303,11 @@ void fsensor_autoload_check_start(void)
|
|
|
fsensor_autoload_last_millis = _millis();
|
|
|
fsensor_watch_runout = false;
|
|
|
fsensor_watch_autoload = true;
|
|
|
- fsensor_err_cnt = 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
void fsensor_autoload_check_stop(void)
|
|
|
{
|
|
|
-
|
|
|
|
|
|
if (!fsensor_enabled) return;
|
|
|
|
|
@@ -291,7 +318,7 @@ void fsensor_autoload_check_stop(void)
|
|
|
fsensor_autoload_sum = 0;
|
|
|
fsensor_watch_autoload = false;
|
|
|
fsensor_watch_runout = true;
|
|
|
- fsensor_err_cnt = 0;
|
|
|
+ fsensor_reset_err_cnt();
|
|
|
}
|
|
|
#endif
|
|
|
|
|
@@ -356,6 +383,7 @@ bool fsensor_check_autoload(void)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+#ifdef PAT9125
|
|
|
void fsensor_oq_meassure_set(bool State)
|
|
|
{
|
|
|
fsensor_oq_meassure_enabled = State;
|
|
@@ -389,7 +417,6 @@ void fsensor_oq_meassure_stop(void)
|
|
|
printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max);
|
|
|
printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u sh_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * fsensor_chunk_len / fsensor_oq_st_sum), (uint16_t)(fsensor_oq_sh_sum / fsensor_oq_samples));
|
|
|
fsensor_oq_meassure = false;
|
|
|
- fsensor_err_cnt = 0;
|
|
|
}
|
|
|
|
|
|
const char _OK[] PROGMEM = "OK";
|
|
@@ -427,18 +454,23 @@ bool fsensor_oq_result(void)
|
|
|
printf_P(_N("fsensor_oq_result %S\n"), (res?_OK:_NG));
|
|
|
return res;
|
|
|
}
|
|
|
-#ifdef PAT9125
|
|
|
+
|
|
|
ISR(FSENSOR_INT_PIN_VECT)
|
|
|
{
|
|
|
if (mmu_enabled || ir_sensor_detected) return;
|
|
|
if (!((fsensor_int_pin_old ^ FSENSOR_INT_PIN_PIN_REG) & FSENSOR_INT_PIN_MASK)) return;
|
|
|
fsensor_int_pin_old = FSENSOR_INT_PIN_PIN_REG;
|
|
|
+
|
|
|
+
|
|
|
static bool _lock = false;
|
|
|
if (_lock) return;
|
|
|
_lock = true;
|
|
|
+
|
|
|
+
|
|
|
int st_cnt = fsensor_st_cnt;
|
|
|
fsensor_st_cnt = 0;
|
|
|
sei();
|
|
|
+
|
|
|
uint8_t old_err_cnt = fsensor_err_cnt;
|
|
|
uint8_t pat9125_res = fsensor_oq_meassure?pat9125_update():pat9125_update_y();
|
|
|
if (!pat9125_res)
|
|
@@ -447,56 +479,71 @@ ISR(FSENSOR_INT_PIN_VECT)
|
|
|
fsensor_not_responding = true;
|
|
|
printf_P(ERRMSG_PAT9125_NOT_RESP, 1);
|
|
|
}
|
|
|
+
|
|
|
if (st_cnt != 0)
|
|
|
- {
|
|
|
- if (st_cnt > 0)
|
|
|
- {
|
|
|
- if (pat9125_y < 0)
|
|
|
- {
|
|
|
- if (fsensor_err_cnt)
|
|
|
- fsensor_err_cnt += 2;
|
|
|
- else
|
|
|
- fsensor_err_cnt++;
|
|
|
- }
|
|
|
- else if (pat9125_y > 0)
|
|
|
- {
|
|
|
- if (fsensor_err_cnt)
|
|
|
- fsensor_err_cnt--;
|
|
|
- }
|
|
|
- else
|
|
|
- if (((fsensor_dy_old <= 0) || (fsensor_err_cnt)) && (st_cnt > (fsensor_chunk_len >> 1)))
|
|
|
- fsensor_err_cnt++;
|
|
|
- if (fsensor_oq_meassure)
|
|
|
- {
|
|
|
- if (fsensor_oq_skipchunk)
|
|
|
- {
|
|
|
- fsensor_oq_skipchunk--;
|
|
|
- fsensor_err_cnt = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (st_cnt == fsensor_chunk_len)
|
|
|
- {
|
|
|
- if (pat9125_y > 0) if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2;
|
|
|
- if (pat9125_y >= 0) if (fsensor_oq_yd_max < pat9125_y) fsensor_oq_yd_max = (fsensor_oq_yd_max + pat9125_y) / 2;
|
|
|
- }
|
|
|
- fsensor_oq_samples++;
|
|
|
- fsensor_oq_st_sum += st_cnt;
|
|
|
- if (pat9125_y > 0) fsensor_oq_yd_sum += pat9125_y;
|
|
|
- if (fsensor_err_cnt > old_err_cnt)
|
|
|
- fsensor_oq_er_sum += (fsensor_err_cnt - old_err_cnt);
|
|
|
- if (fsensor_oq_er_max < fsensor_err_cnt)
|
|
|
- fsensor_oq_er_max = fsensor_err_cnt;
|
|
|
- fsensor_oq_sh_sum += pat9125_s;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ {
|
|
|
+
|
|
|
+ int8_t st_dir = st_cnt >= 0;
|
|
|
+ int8_t pat9125_dir = pat9125_y >= 0;
|
|
|
+
|
|
|
+ if (pat9125_y == 0)
|
|
|
+ {
|
|
|
+ if (st_dir)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ if (!fsensor_oq_meassure)
|
|
|
+ pat9125_update_bs();
|
|
|
+
|
|
|
+
|
|
|
+ if ((pat9125_b < 80) && (pat9125_s > 10))
|
|
|
+ {
|
|
|
+
|
|
|
+ ++fsensor_err_cnt;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ if(fsensor_err_cnt) --fsensor_err_cnt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (pat9125_dir != st_dir)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (st_dir) ++fsensor_err_cnt;
|
|
|
+ }
|
|
|
+ else if (pat9125_dir == st_dir)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (fsensor_err_cnt) --fsensor_err_cnt;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (st_dir && fsensor_oq_meassure)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (fsensor_oq_skipchunk)
|
|
|
+ {
|
|
|
+ fsensor_oq_skipchunk--;
|
|
|
+ fsensor_err_cnt = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (st_cnt == fsensor_chunk_len)
|
|
|
+ {
|
|
|
+ if (pat9125_y > 0) if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2;
|
|
|
+ if (pat9125_y >= 0) if (fsensor_oq_yd_max < pat9125_y) fsensor_oq_yd_max = (fsensor_oq_yd_max + pat9125_y) / 2;
|
|
|
+ }
|
|
|
+ fsensor_oq_samples++;
|
|
|
+ fsensor_oq_st_sum += st_cnt;
|
|
|
+ if (pat9125_y > 0) fsensor_oq_yd_sum += pat9125_y;
|
|
|
+ if (fsensor_err_cnt > old_err_cnt)
|
|
|
+ fsensor_oq_er_sum += (fsensor_err_cnt - old_err_cnt);
|
|
|
+ if (fsensor_oq_er_max < fsensor_err_cnt)
|
|
|
+ fsensor_oq_er_max = fsensor_err_cnt;
|
|
|
+ fsensor_oq_sh_sum += pat9125_s;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG_FSENSOR_LOG
|
|
@@ -507,9 +554,7 @@ ISR(FSENSOR_INT_PIN_VECT)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- fsensor_dy_old = pat9125_y;
|
|
|
pat9125_y = 0;
|
|
|
-
|
|
|
_lock = false;
|
|
|
return;
|
|
|
}
|
|
@@ -529,19 +574,16 @@ void fsensor_setup_interrupt(void)
|
|
|
PCICR |= bit(FSENSOR_INT_PIN_PCICR_BIT);
|
|
|
}
|
|
|
|
|
|
-#endif
|
|
|
-
|
|
|
void fsensor_st_block_chunk(int cnt)
|
|
|
{
|
|
|
if (!fsensor_enabled) return;
|
|
|
fsensor_st_cnt += cnt;
|
|
|
- if (abs(fsensor_st_cnt) >= fsensor_chunk_len)
|
|
|
- {
|
|
|
-
|
|
|
- if (PIN_GET(FSENSOR_INT_PIN)) {PIN_VAL(FSENSOR_INT_PIN, LOW);}
|
|
|
- else {PIN_VAL(FSENSOR_INT_PIN, HIGH);}
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+ if (PIN_GET(FSENSOR_INT_PIN)) {PIN_VAL(FSENSOR_INT_PIN, LOW);}
|
|
|
+ else {PIN_VAL(FSENSOR_INT_PIN, HIGH);}
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
|
@@ -578,32 +620,41 @@ void fsensor_update(void)
|
|
|
st_synchronize();
|
|
|
|
|
|
|
|
|
- fsensor_err_cnt = 0;
|
|
|
+ fsensor_reset_err_cnt();
|
|
|
fsensor_oq_meassure_start(0);
|
|
|
float e_tmp = current_position[E_AXIS];
|
|
|
current_position[E_AXIS] -= 3;
|
|
|
- plan_buffer_line_curposXYZE(200/60, active_extruder);
|
|
|
+ plan_buffer_line_curposXYZE(250/60, active_extruder);
|
|
|
current_position[E_AXIS] = e_tmp;
|
|
|
plan_buffer_line_curposXYZE(200/60, active_extruder);
|
|
|
st_synchronize();
|
|
|
-
|
|
|
- uint8_t err_cnt = fsensor_err_cnt;
|
|
|
fsensor_oq_meassure_stop();
|
|
|
|
|
|
bool err = false;
|
|
|
- err |= (err_cnt > 1);
|
|
|
-
|
|
|
+ err |= (fsensor_err_cnt > 1);
|
|
|
err |= (fsensor_oq_er_sum > 2);
|
|
|
err |= (fsensor_oq_yd_sum < (4 * FSENSOR_OQ_MIN_YD));
|
|
|
|
|
|
fsensor_restore_print_and_continue();
|
|
|
- fsensor_autoload_enabled = autoload_enabled_tmp;
|
|
|
- fsensor_oq_meassure_enabled = oq_meassure_enabled_tmp;
|
|
|
-
|
|
|
- if (!err)
|
|
|
- printf_P(PSTR("fsensor_err_cnt = 0\n"));
|
|
|
- else
|
|
|
- fsensor_enque_M600();
|
|
|
+ fsensor_autoload_enabled = autoload_enabled_tmp;
|
|
|
+ fsensor_oq_meassure_enabled = oq_meassure_enabled_tmp;
|
|
|
+
|
|
|
+ unsigned long now = _millis();
|
|
|
+ if (!err && (now - fsensor_softfail_last) > FSENSOR_SOFTERR_DELTA)
|
|
|
+ fsensor_softfail_ccnt = 0;
|
|
|
+ if (!err && fsensor_softfail_ccnt <= FSENSOR_SOFTERR_CMAX)
|
|
|
+ {
|
|
|
+ printf_P(PSTR("fsensor_err_cnt = 0\n"));
|
|
|
+ ++fsensor_softfail;
|
|
|
+ ++fsensor_softfail_ccnt;
|
|
|
+ fsensor_softfail_last = now;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fsensor_softfail_ccnt = 0;
|
|
|
+ fsensor_softfail_last = 0;
|
|
|
+ fsensor_enque_M600();
|
|
|
+ }
|
|
|
}
|
|
|
#else
|
|
|
if (CHECK_FSENSOR && ir_sensor_detected)
|