fsensor.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //! @file
  2. #ifndef FSENSOR_H
  3. #define FSENSOR_H
  4. #include <inttypes.h>
  5. #include "config.h"
  6. //! @name filament sensor enable/disable flag
  7. //! @{
  8. bool fsensor_enabled();
  9. //! @}
  10. //! @name filament sensor not responding flag
  11. //! @{
  12. bool fsensor_not_responding();
  13. void fsensor_set_responding_ok();
  14. //! @}
  15. #ifdef PAT9125
  16. // optical checking "chunk lenght" (already in steps)
  17. extern int16_t fsensor_chunk_len;
  18. // count of soft failures
  19. extern uint8_t fsensor_softfail;
  20. #endif
  21. //! @name save restore printing
  22. //! @{
  23. extern void fsensor_stop_and_save_print(void);
  24. //! restore print - restore position and heatup to original temperature
  25. extern void fsensor_restore_print_and_continue(void);
  26. //! split the current gcode stream to insert new instructions
  27. extern void fsensor_checkpoint_print(void);
  28. //! @}
  29. //! initialize
  30. extern void fsensor_init(void);
  31. /// IR sensor detection originally for MMU?
  32. /// Note: the signature of this function intentionally differs upon IR_SENSOR macro to allow for best optimization.
  33. #ifdef IR_SENSOR
  34. constexpr bool fsensor_IR_detected() { return true; }
  35. #else
  36. bool fsensor_IR_detected();
  37. #endif
  38. #ifdef PAT9125
  39. //! update axis resolution
  40. extern void fsensor_set_axis_steps_per_unit(float u);
  41. #endif
  42. //! @name enable/disable
  43. //! @{
  44. extern bool fsensor_enable(bool bUpdateEEPROM=true);
  45. extern void fsensor_disable(bool bUpdateEEPROM=true);
  46. //! @}
  47. //autoload feature enabled
  48. extern void fsensor_autoload_set(bool State);
  49. bool fsensor_autoload_enabled();
  50. extern void fsensor_update(void);
  51. #ifdef PAT9125
  52. //! setup pin-change interrupt
  53. extern void fsensor_setup_interrupt(void);
  54. //! @name autoload support
  55. //! @{
  56. extern void fsensor_autoload_check_start(void);
  57. extern void fsensor_autoload_check_stop(void);
  58. #endif //PAT9125
  59. extern bool fsensor_check_autoload(void);
  60. //! @}
  61. #ifdef PAT9125
  62. //! @name optical quality measurement support
  63. //! @{
  64. extern bool fsensor_oq_meassure_enabled;
  65. extern void fsensor_oq_meassure_set(bool State);
  66. extern void fsensor_oq_meassure_start(uint8_t skip);
  67. extern void fsensor_oq_meassure_stop(void);
  68. extern bool fsensor_oq_result(void);
  69. //! @}
  70. //! @name callbacks from stepper
  71. //! @{
  72. extern void fsensor_st_block_chunk(int cnt);
  73. // debugging
  74. extern uint8_t fsensor_log;
  75. // There's really nothing to do in block_begin: the stepper ISR likely has
  76. // called us already at the end of the last block, making this integration
  77. // redundant. LA1.5 might not always do that during a coasting move, so attempt
  78. // to drain fsensor_st_cnt anyway at the beginning of the new block.
  79. #define fsensor_st_block_begin(rev) fsensor_st_block_chunk(0)
  80. //! @}
  81. #endif //PAT9125
  82. #define VOLT_DIV_REF 5
  83. #ifdef IR_SENSOR_ANALOG
  84. #define IR_SENSOR_STEADY 10 // [ms]
  85. enum class ClFsensorPCB:uint_least8_t
  86. {
  87. _Old=0,
  88. _Rev04=1,
  89. _Undef=EEPROM_EMPTY_VALUE
  90. };
  91. enum class ClFsensorActionNA:uint_least8_t
  92. {
  93. _Continue=0,
  94. _Pause=1,
  95. _Undef=EEPROM_EMPTY_VALUE
  96. };
  97. extern ClFsensorPCB oFsensorPCB;
  98. extern ClFsensorActionNA oFsensorActionNA;
  99. extern const char* FsensorIRVersionText();
  100. extern bool fsensor_IR_check();
  101. constexpr uint16_t Voltage2Raw(float V){
  102. return ( V * 1023 * OVERSAMPLENR / VOLT_DIV_REF ) + 0.5F;
  103. }
  104. constexpr float Raw2Voltage(uint16_t raw){
  105. return VOLT_DIV_REF*(raw / (1023.F * OVERSAMPLENR) );
  106. }
  107. constexpr uint16_t IRsensor_Ldiode_TRESHOLD = Voltage2Raw(0.3F); // ~0.3V, raw value=982
  108. constexpr uint16_t IRsensor_Lmax_TRESHOLD = Voltage2Raw(1.5F); // ~1.5V (0.3*Vcc), raw value=4910
  109. constexpr uint16_t IRsensor_Hmin_TRESHOLD = Voltage2Raw(3.0F); // ~3.0V (0.6*Vcc), raw value=9821
  110. constexpr uint16_t IRsensor_Hopen_TRESHOLD = Voltage2Raw(4.6F); // ~4.6V (N.C. @ Ru~20-50k, Rd'=56k, Ru'=10k), raw value=15059
  111. constexpr uint16_t IRsensor_VMax_TRESHOLD = Voltage2Raw(5.F); // ~5V, raw value=16368
  112. #endif //IR_SENSOR_ANALOG
  113. #endif //FSENSOR_H