fsensor.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. //! @file
  2. #include "Marlin.h"
  3. #include "fsensor.h"
  4. #include <avr/pgmspace.h>
  5. #include "pat9125.h"
  6. #include "stepper.h"
  7. #include "planner.h"
  8. #include "fastio.h"
  9. #include "cmdqueue.h"
  10. #include "ultralcd.h"
  11. #include "ConfigurationStore.h"
  12. #include "mmu.h"
  13. //! @name Basic parameters
  14. //! @{
  15. #define FSENSOR_CHUNK_LEN 0.64F //!< filament sensor chunk length 0.64mm
  16. #define FSENSOR_ERR_MAX 17 //!< filament sensor maximum error count for runout detection
  17. //! @}
  18. //! @name Optical quality measurement parameters
  19. //! @{
  20. #define FSENSOR_OQ_MAX_ES 6 //!< maximum error sum while loading (length ~64mm = 100chunks)
  21. #define FSENSOR_OQ_MAX_EM 2 //!< maximum error counter value while loading
  22. #define FSENSOR_OQ_MIN_YD 2 //!< minimum yd per chunk (applied to avg value)
  23. #define FSENSOR_OQ_MAX_YD 200 //!< maximum yd per chunk (applied to avg value)
  24. #define FSENSOR_OQ_MAX_PD 4 //!< maximum positive deviation (= yd_max/yd_avg)
  25. #define FSENSOR_OQ_MAX_ND 5 //!< maximum negative deviation (= yd_avg/yd_min)
  26. #define FSENSOR_OQ_MAX_SH 13 //!< maximum shutter value
  27. //! @}
  28. const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n";
  29. #define FSENSOR_INT_PIN 63 //!< filament sensor interrupt pin PK1
  30. #define FSENSOR_INT_PIN_MSK 0x02 //!< filament sensor interrupt pin mask (bit1)
  31. //uint8_t fsensor_int_pin = FSENSOR_INT_PIN;
  32. uint8_t fsensor_int_pin_old = 0;
  33. int16_t fsensor_chunk_len = 0;
  34. //! enabled = initialized and sampled every chunk event
  35. bool fsensor_enabled = true;
  36. //! runout watching is done in fsensor_update (called from main loop)
  37. bool fsensor_watch_runout = true;
  38. //! not responding - is set if any communication error occurred during initialization or readout
  39. bool fsensor_not_responding = false;
  40. //! printing saved
  41. bool fsensor_printing_saved = false;
  42. //! enable/disable quality meassurement
  43. bool fsensor_oq_meassure_enabled = false;
  44. //! number of errors, updated in ISR
  45. uint8_t fsensor_err_cnt = 0;
  46. //! variable for accumulating step count (updated callbacks from stepper and ISR)
  47. int16_t fsensor_st_cnt = 0;
  48. //! last dy value from pat9125 sensor (used in ISR)
  49. int16_t fsensor_dy_old = 0;
  50. //! log flag: 0=log disabled, 1=log enabled
  51. uint8_t fsensor_log = 1;
  52. //! @name filament autoload variables
  53. //! @{
  54. //! autoload feature enabled
  55. bool fsensor_autoload_enabled = true;
  56. //! autoload watching enable/disable flag
  57. bool fsensor_watch_autoload = false;
  58. //
  59. uint16_t fsensor_autoload_y;
  60. //
  61. uint8_t fsensor_autoload_c;
  62. //
  63. uint32_t fsensor_autoload_last_millis;
  64. //
  65. uint8_t fsensor_autoload_sum;
  66. //! @}
  67. //! @name filament optical quality measurement variables
  68. //! @{
  69. //! Measurement enable/disable flag
  70. bool fsensor_oq_meassure = false;
  71. //! skip-chunk counter, for accurate measurement is necessary to skip first chunk...
  72. uint8_t fsensor_oq_skipchunk;
  73. //! number of samples from start of measurement
  74. uint8_t fsensor_oq_samples;
  75. //! sum of steps in positive direction movements
  76. uint16_t fsensor_oq_st_sum;
  77. //! sum of deltas in positive direction movements
  78. uint16_t fsensor_oq_yd_sum;
  79. //! sum of errors during measurement
  80. uint16_t fsensor_oq_er_sum;
  81. //! max error counter value during measurement
  82. uint8_t fsensor_oq_er_max;
  83. //! minimum delta value
  84. int16_t fsensor_oq_yd_min;
  85. //! maximum delta value
  86. int16_t fsensor_oq_yd_max;
  87. //! sum of shutter value
  88. uint16_t fsensor_oq_sh_sum;
  89. //! @}
  90. void fsensor_stop_and_save_print(void)
  91. {
  92. printf_P(PSTR("fsensor_stop_and_save_print\n"));
  93. stop_and_save_print_to_ram(0, 0); //XYZE - no change
  94. }
  95. void fsensor_restore_print_and_continue(void)
  96. {
  97. printf_P(PSTR("fsensor_restore_print_and_continue\n"));
  98. fsensor_watch_runout = true;
  99. fsensor_err_cnt = 0;
  100. restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change
  101. }
  102. void fsensor_init(void)
  103. {
  104. uint8_t pat9125 = pat9125_init();
  105. printf_P(PSTR("PAT9125_init:%hhu\n"), pat9125);
  106. uint8_t fsensor = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR);
  107. fsensor_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED);
  108. uint8_t oq_meassure_enabled = eeprom_read_byte((uint8_t*)EEPROM_FSENS_OQ_MEASS_ENABLED);
  109. fsensor_oq_meassure_enabled = (oq_meassure_enabled == 1)?true:false;
  110. fsensor_chunk_len = (int16_t)(FSENSOR_CHUNK_LEN * cs.axis_steps_per_unit[E_AXIS]);
  111. if (!pat9125)
  112. {
  113. fsensor = 0; //disable sensor
  114. fsensor_not_responding = true;
  115. }
  116. else
  117. fsensor_not_responding = false;
  118. if (fsensor)
  119. fsensor_enable();
  120. else
  121. fsensor_disable();
  122. printf_P(PSTR("FSensor %S\n"), (fsensor_enabled?PSTR("ENABLED"):PSTR("DISABLED\n")));
  123. }
  124. bool fsensor_enable(void)
  125. {
  126. if (mmu_enabled == false) { //filament sensor is pat9125, enable only if it is working
  127. uint8_t pat9125 = pat9125_init();
  128. printf_P(PSTR("PAT9125_init:%hhu\n"), pat9125);
  129. if (pat9125)
  130. fsensor_not_responding = false;
  131. else
  132. fsensor_not_responding = true;
  133. fsensor_enabled = pat9125 ? true : false;
  134. fsensor_watch_runout = true;
  135. fsensor_oq_meassure = false;
  136. fsensor_err_cnt = 0;
  137. fsensor_dy_old = 0;
  138. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled ? 0x01 : 0x00);
  139. FSensorStateMenu = fsensor_enabled ? 1 : 0;
  140. }
  141. else //filament sensor is FINDA, always enable
  142. {
  143. fsensor_enabled = true;
  144. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, 0x01);
  145. FSensorStateMenu = 1;
  146. }
  147. return fsensor_enabled;
  148. }
  149. void fsensor_disable(void)
  150. {
  151. fsensor_enabled = false;
  152. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, 0x00);
  153. FSensorStateMenu = 0;
  154. }
  155. void fsensor_autoload_set(bool State)
  156. {
  157. fsensor_autoload_enabled = State;
  158. eeprom_update_byte((unsigned char *)EEPROM_FSENS_AUTOLOAD_ENABLED, fsensor_autoload_enabled);
  159. }
  160. void pciSetup(byte pin)
  161. {
  162. *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin
  163. PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
  164. PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
  165. }
  166. void fsensor_autoload_check_start(void)
  167. {
  168. // puts_P(_N("fsensor_autoload_check_start\n"));
  169. if (!fsensor_enabled) return;
  170. if (!fsensor_autoload_enabled) return;
  171. if (fsensor_watch_autoload) return;
  172. if (!pat9125_update_y()) //update sensor
  173. {
  174. fsensor_disable();
  175. fsensor_not_responding = true;
  176. fsensor_watch_autoload = false;
  177. printf_P(ERRMSG_PAT9125_NOT_RESP, 3);
  178. return;
  179. }
  180. puts_P(_N("fsensor_autoload_check_start - autoload ENABLED\n"));
  181. fsensor_autoload_y = pat9125_y; //save current y value
  182. fsensor_autoload_c = 0; //reset number of changes counter
  183. fsensor_autoload_sum = 0;
  184. fsensor_autoload_last_millis = millis();
  185. fsensor_watch_runout = false;
  186. fsensor_watch_autoload = true;
  187. fsensor_err_cnt = 0;
  188. }
  189. void fsensor_autoload_check_stop(void)
  190. {
  191. // puts_P(_N("fsensor_autoload_check_stop\n"));
  192. if (!fsensor_enabled) return;
  193. // puts_P(_N("fsensor_autoload_check_stop 1\n"));
  194. if (!fsensor_autoload_enabled) return;
  195. // puts_P(_N("fsensor_autoload_check_stop 2\n"));
  196. if (!fsensor_watch_autoload) return;
  197. puts_P(_N("fsensor_autoload_check_stop - autoload DISABLED\n"));
  198. fsensor_autoload_sum = 0;
  199. fsensor_watch_autoload = false;
  200. fsensor_watch_runout = true;
  201. fsensor_err_cnt = 0;
  202. }
  203. bool fsensor_check_autoload(void)
  204. {
  205. if (!fsensor_enabled) return false;
  206. if (!fsensor_autoload_enabled) return false;
  207. if (!fsensor_watch_autoload)
  208. {
  209. fsensor_autoload_check_start();
  210. return false;
  211. }
  212. #if 0
  213. uint8_t fsensor_autoload_c_old = fsensor_autoload_c;
  214. #endif
  215. if ((millis() - fsensor_autoload_last_millis) < 25) return false;
  216. fsensor_autoload_last_millis = millis();
  217. if (!pat9125_update_y()) //update sensor
  218. {
  219. fsensor_disable();
  220. fsensor_not_responding = true;
  221. printf_P(ERRMSG_PAT9125_NOT_RESP, 2);
  222. return false;
  223. }
  224. int16_t dy = pat9125_y - fsensor_autoload_y;
  225. if (dy) //? dy value is nonzero
  226. {
  227. if (dy > 0) //? delta-y value is positive (inserting)
  228. {
  229. fsensor_autoload_sum += dy;
  230. fsensor_autoload_c += 3; //increment change counter by 3
  231. }
  232. else if (fsensor_autoload_c > 1)
  233. fsensor_autoload_c -= 2; //decrement change counter by 2
  234. fsensor_autoload_y = pat9125_y; //save current value
  235. }
  236. else if (fsensor_autoload_c > 0)
  237. fsensor_autoload_c--;
  238. if (fsensor_autoload_c == 0) fsensor_autoload_sum = 0;
  239. #if 0
  240. puts_P(_N("fsensor_check_autoload\n"));
  241. if (fsensor_autoload_c != fsensor_autoload_c_old)
  242. printf_P(PSTR("fsensor_check_autoload dy=%d c=%d sum=%d\n"), dy, fsensor_autoload_c, fsensor_autoload_sum);
  243. #endif
  244. // if ((fsensor_autoload_c >= 15) && (fsensor_autoload_sum > 30))
  245. if ((fsensor_autoload_c >= 12) && (fsensor_autoload_sum > 20))
  246. {
  247. // puts_P(_N("fsensor_check_autoload = true !!!\n"));
  248. return true;
  249. }
  250. return false;
  251. }
  252. void fsensor_oq_meassure_set(bool State)
  253. {
  254. fsensor_oq_meassure_enabled = State;
  255. eeprom_update_byte((unsigned char *)EEPROM_FSENS_OQ_MEASS_ENABLED, fsensor_oq_meassure_enabled);
  256. }
  257. void fsensor_oq_meassure_start(uint8_t skip)
  258. {
  259. if (!fsensor_enabled) return;
  260. if (!fsensor_oq_meassure_enabled) return;
  261. printf_P(PSTR("fsensor_oq_meassure_start\n"));
  262. fsensor_oq_skipchunk = skip;
  263. fsensor_oq_samples = 0;
  264. fsensor_oq_st_sum = 0;
  265. fsensor_oq_yd_sum = 0;
  266. fsensor_oq_er_sum = 0;
  267. fsensor_oq_er_max = 0;
  268. fsensor_oq_yd_min = FSENSOR_OQ_MAX_YD;
  269. fsensor_oq_yd_max = 0;
  270. fsensor_oq_sh_sum = 0;
  271. pat9125_update();
  272. pat9125_y = 0;
  273. fsensor_watch_runout = false;
  274. fsensor_oq_meassure = true;
  275. }
  276. void fsensor_oq_meassure_stop(void)
  277. {
  278. if (!fsensor_enabled) return;
  279. if (!fsensor_oq_meassure_enabled) return;
  280. printf_P(PSTR("fsensor_oq_meassure_stop, %hhu samples\n"), fsensor_oq_samples);
  281. 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);
  282. 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));
  283. fsensor_oq_meassure = false;
  284. fsensor_watch_runout = true;
  285. fsensor_err_cnt = 0;
  286. }
  287. const char _OK[] PROGMEM = "OK";
  288. const char _NG[] PROGMEM = "NG!";
  289. bool fsensor_oq_result(void)
  290. {
  291. if (!fsensor_enabled) return true;
  292. if (!fsensor_oq_meassure_enabled) return true;
  293. printf_P(_N("fsensor_oq_result\n"));
  294. bool res_er_sum = (fsensor_oq_er_sum <= FSENSOR_OQ_MAX_ES);
  295. printf_P(_N(" er_sum = %u %S\n"), fsensor_oq_er_sum, (res_er_sum?_OK:_NG));
  296. bool res_er_max = (fsensor_oq_er_max <= FSENSOR_OQ_MAX_EM);
  297. printf_P(_N(" er_max = %hhu %S\n"), fsensor_oq_er_max, (res_er_max?_OK:_NG));
  298. uint8_t yd_avg = ((uint32_t)fsensor_oq_yd_sum * fsensor_chunk_len / fsensor_oq_st_sum);
  299. bool res_yd_avg = (yd_avg >= FSENSOR_OQ_MIN_YD) && (yd_avg <= FSENSOR_OQ_MAX_YD);
  300. printf_P(_N(" yd_avg = %hhu %S\n"), yd_avg, (res_yd_avg?_OK:_NG));
  301. bool res_yd_max = (fsensor_oq_yd_max <= (yd_avg * FSENSOR_OQ_MAX_PD));
  302. printf_P(_N(" yd_max = %u %S\n"), fsensor_oq_yd_max, (res_yd_max?_OK:_NG));
  303. bool res_yd_min = (fsensor_oq_yd_min >= (yd_avg / FSENSOR_OQ_MAX_ND));
  304. printf_P(_N(" yd_min = %u %S\n"), fsensor_oq_yd_min, (res_yd_min?_OK:_NG));
  305. uint16_t yd_dev = (fsensor_oq_yd_max - yd_avg) + (yd_avg - fsensor_oq_yd_min);
  306. printf_P(_N(" yd_dev = %u\n"), yd_dev);
  307. uint16_t yd_qua = 10 * yd_avg / (yd_dev + 1);
  308. printf_P(_N(" yd_qua = %u %S\n"), yd_qua, ((yd_qua >= 8)?_OK:_NG));
  309. uint8_t sh_avg = (fsensor_oq_sh_sum / fsensor_oq_samples);
  310. bool res_sh_avg = (sh_avg <= FSENSOR_OQ_MAX_SH);
  311. if (yd_qua >= 8) res_sh_avg = true;
  312. printf_P(_N(" sh_avg = %hhu %S\n"), sh_avg, (res_sh_avg?_OK:_NG));
  313. bool res = res_er_sum && res_er_max && res_yd_avg && res_yd_max && res_yd_min && res_sh_avg;
  314. printf_P(_N("fsensor_oq_result %S\n"), (res?_OK:_NG));
  315. return res;
  316. }
  317. ISR(PCINT2_vect)
  318. {
  319. if (!((fsensor_int_pin_old ^ PINK) & FSENSOR_INT_PIN_MSK)) return;
  320. fsensor_int_pin_old = PINK;
  321. static bool _lock = false;
  322. if (_lock) return;
  323. _lock = true;
  324. int st_cnt = fsensor_st_cnt;
  325. fsensor_st_cnt = 0;
  326. sei();
  327. uint8_t old_err_cnt = fsensor_err_cnt;
  328. uint8_t pat9125_res = fsensor_oq_meassure?pat9125_update():pat9125_update_y();
  329. if (!pat9125_res)
  330. {
  331. fsensor_disable();
  332. fsensor_not_responding = true;
  333. printf_P(ERRMSG_PAT9125_NOT_RESP, 1);
  334. }
  335. if (st_cnt != 0)
  336. { //movement
  337. if (st_cnt > 0) //positive movement
  338. {
  339. if (pat9125_y < 0)
  340. {
  341. if (fsensor_err_cnt)
  342. fsensor_err_cnt += 2;
  343. else
  344. fsensor_err_cnt++;
  345. }
  346. else if (pat9125_y > 0)
  347. {
  348. if (fsensor_err_cnt)
  349. fsensor_err_cnt--;
  350. }
  351. else //(pat9125_y == 0)
  352. if (((fsensor_dy_old <= 0) || (fsensor_err_cnt)) && (st_cnt > (fsensor_chunk_len >> 1)))
  353. fsensor_err_cnt++;
  354. if (fsensor_oq_meassure)
  355. {
  356. if (fsensor_oq_skipchunk)
  357. {
  358. fsensor_oq_skipchunk--;
  359. fsensor_err_cnt = 0;
  360. }
  361. else
  362. {
  363. if (st_cnt == fsensor_chunk_len)
  364. {
  365. if (pat9125_y > 0) if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2;
  366. if (pat9125_y >= 0) if (fsensor_oq_yd_max < pat9125_y) fsensor_oq_yd_max = (fsensor_oq_yd_max + pat9125_y) / 2;
  367. }
  368. fsensor_oq_samples++;
  369. fsensor_oq_st_sum += st_cnt;
  370. if (pat9125_y > 0) fsensor_oq_yd_sum += pat9125_y;
  371. if (fsensor_err_cnt > old_err_cnt)
  372. fsensor_oq_er_sum += (fsensor_err_cnt - old_err_cnt);
  373. if (fsensor_oq_er_max < fsensor_err_cnt)
  374. fsensor_oq_er_max = fsensor_err_cnt;
  375. fsensor_oq_sh_sum += pat9125_s;
  376. }
  377. }
  378. }
  379. else //negative movement
  380. {
  381. }
  382. }
  383. else
  384. { //no movement
  385. }
  386. #ifdef DEBUG_FSENSOR_LOG
  387. if (fsensor_log)
  388. {
  389. printf_P(_N("FSENSOR cnt=%d dy=%d err=%hhu %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK"));
  390. if (fsensor_oq_meassure) printf_P(_N("FSENSOR st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu yd_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max, fsensor_oq_yd_max);
  391. }
  392. #endif //DEBUG_FSENSOR_LOG
  393. fsensor_dy_old = pat9125_y;
  394. pat9125_y = 0;
  395. _lock = false;
  396. return;
  397. }
  398. void fsensor_st_block_begin(block_t* bl)
  399. {
  400. if (!fsensor_enabled) return;
  401. if (((fsensor_st_cnt > 0) && (bl->direction_bits & 0x8)) ||
  402. ((fsensor_st_cnt < 0) && !(bl->direction_bits & 0x8)))
  403. {
  404. if (_READ(63)) _WRITE(63, LOW);
  405. else _WRITE(63, HIGH);
  406. }
  407. }
  408. void fsensor_st_block_chunk(block_t* bl, int cnt)
  409. {
  410. if (!fsensor_enabled) return;
  411. fsensor_st_cnt += (bl->direction_bits & 0x8)?-cnt:cnt;
  412. if ((fsensor_st_cnt >= fsensor_chunk_len) || (fsensor_st_cnt <= -fsensor_chunk_len))
  413. {
  414. if (_READ(63)) _WRITE(63, LOW);
  415. else _WRITE(63, HIGH);
  416. }
  417. }
  418. //! @brief filament sensor update (perform M600 on filament runout)
  419. //!
  420. //! Works only if filament sensor is enabled.
  421. //! When the filament sensor error count is larger then FSENSOR_ERR_MAX, pauses print, tries to move filament back and forth.
  422. //! If there is still no plausible signal from filament sensor plans M600 (Filament change).
  423. void fsensor_update(void)
  424. {
  425. if (fsensor_enabled && fsensor_watch_runout && (fsensor_err_cnt > FSENSOR_ERR_MAX))
  426. {
  427. bool autoload_enabled_tmp = fsensor_autoload_enabled;
  428. fsensor_autoload_enabled = false;
  429. bool oq_meassure_enabled_tmp = fsensor_oq_meassure_enabled;
  430. fsensor_oq_meassure_enabled = true;
  431. fsensor_stop_and_save_print();
  432. fsensor_err_cnt = 0;
  433. fsensor_oq_meassure_start(0);
  434. enquecommand_front_P((PSTR("G1 E-3 F200")));
  435. process_commands();
  436. KEEPALIVE_STATE(IN_HANDLER);
  437. cmdqueue_pop_front();
  438. st_synchronize();
  439. enquecommand_front_P((PSTR("G1 E3 F200")));
  440. process_commands();
  441. KEEPALIVE_STATE(IN_HANDLER);
  442. cmdqueue_pop_front();
  443. st_synchronize();
  444. uint8_t err_cnt = fsensor_err_cnt;
  445. fsensor_oq_meassure_stop();
  446. bool err = false;
  447. err |= (err_cnt > 1);
  448. err |= (fsensor_oq_er_sum > 2);
  449. err |= (fsensor_oq_yd_sum < (4 * FSENSOR_OQ_MIN_YD));
  450. if (!err)
  451. {
  452. printf_P(PSTR("fsensor_err_cnt = 0\n"));
  453. fsensor_restore_print_and_continue();
  454. }
  455. else
  456. {
  457. printf_P(PSTR("fsensor_update - M600\n"));
  458. eeprom_update_byte((uint8_t*)EEPROM_FERROR_COUNT, eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) + 1);
  459. eeprom_update_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) + 1);
  460. enquecommand_front_P(PSTR("FSENSOR_RECOVER"));
  461. enquecommand_front_P((PSTR("M600")));
  462. fsensor_watch_runout = false;
  463. }
  464. fsensor_autoload_enabled = autoload_enabled_tmp;
  465. fsensor_oq_meassure_enabled = oq_meassure_enabled_tmp;
  466. }
  467. }
  468. void fsensor_setup_interrupt(void)
  469. {
  470. pinMode(FSENSOR_INT_PIN, OUTPUT);
  471. digitalWrite(FSENSOR_INT_PIN, LOW);
  472. fsensor_int_pin_old = 0;
  473. pciSetup(FSENSOR_INT_PIN);
  474. }