fsensor.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. //! split the current gcode stream to insert new instructions
  19. extern void fsensor_checkpoint_print(void);
  20. //! @}
  21. #ifdef PAT9125
  22. //! update axis resolution
  23. extern void fsensor_set_axis_steps_per_unit(float u);
  24. #endif
  25. //! @name enable/disable
  26. //! @{
  27. extern bool fsensor_enable(bool bUpdateEEPROM=true);
  28. extern void fsensor_disable(bool bUpdateEEPROM=true);
  29. //! @}
  30. //autoload feature enabled
  31. extern bool fsensor_autoload_enabled;
  32. extern void fsensor_autoload_set(bool State);
  33. #ifdef PAT9125
  34. //! setup pin-change interrupt
  35. extern void fsensor_setup_interrupt(void);
  36. //! @name autoload support
  37. //! @{
  38. extern void fsensor_autoload_check_start(void);
  39. extern void fsensor_autoload_check_stop(void);
  40. #endif //PAT9125
  41. //! @}
  42. #ifdef PAT9125
  43. //! @name callbacks from stepper
  44. //! @{
  45. extern void fsensor_st_block_chunk(int cnt);
  46. // debugging
  47. extern uint8_t fsensor_log;
  48. // There's really nothing to do in block_begin: the stepper ISR likely has
  49. // called us already at the end of the last block, making this integration
  50. // redundant. LA1.5 might not always do that during a coasting move, so attempt
  51. // to drain fsensor_st_cnt anyway at the beginning of the new block.
  52. #define fsensor_st_block_begin(rev) fsensor_st_block_chunk(0)
  53. //! @}
  54. #endif //PAT9125
  55. #define VOLT_DIV_REF 5
  56. #ifdef IR_SENSOR_ANALOG
  57. #define IR_SENSOR_STEADY 10 // [ms]
  58. enum class ClFsensorPCB:uint_least8_t
  59. {
  60. _Old=0,
  61. _Rev04=1,
  62. _Undef=EEPROM_EMPTY_VALUE
  63. };
  64. enum class ClFsensorActionNA:uint_least8_t
  65. {
  66. _Continue=0,
  67. _Pause=1,
  68. _Undef=EEPROM_EMPTY_VALUE
  69. };
  70. extern ClFsensorPCB oFsensorPCB;
  71. extern ClFsensorActionNA oFsensorActionNA;
  72. extern const char* FsensorIRVersionText();
  73. extern bool fsensor_IR_check(uint16_t raw);
  74. constexpr uint16_t Voltage2Raw(float V){
  75. return ( V * 1023 * OVERSAMPLENR / VOLT_DIV_REF ) + 0.5F;
  76. }
  77. constexpr float Raw2Voltage(uint16_t raw){
  78. return VOLT_DIV_REF*(raw / (1023.F * OVERSAMPLENR) );
  79. }
  80. constexpr uint16_t IRsensor_Ldiode_TRESHOLD = Voltage2Raw(0.3F); // ~0.3V, raw value=982
  81. constexpr uint16_t IRsensor_Lmax_TRESHOLD = Voltage2Raw(1.5F); // ~1.5V (0.3*Vcc), raw value=4910
  82. constexpr uint16_t IRsensor_Hmin_TRESHOLD = Voltage2Raw(3.0F); // ~3.0V (0.6*Vcc), raw value=9821
  83. constexpr uint16_t IRsensor_Hopen_TRESHOLD = Voltage2Raw(4.6F); // ~4.6V (N.C. @ Ru~20-50k, Rd'=56k, Ru'=10k), raw value=15059
  84. constexpr uint16_t IRsensor_VMax_TRESHOLD = Voltage2Raw(5.F); // ~5V, raw value=16368
  85. #endif //IR_SENSOR_ANALOG
  86. #endif //FSENSOR_H