fsensor.h 3.6 KB

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