fsensor.cpp 16 KB

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