iron.h 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * iron.h
  3. *
  4. * Created on: Jan 12, 2021
  5. * Author: David Original work by Jose (PTDreamer), 2017
  6. */
  7. #ifndef IRON_H_
  8. #define IRON_H_
  9. #include "pid.h"
  10. #include "settings.h"
  11. #define PWMminOutput 1 // Min pwm level to maintain iron detection
  12. typedef void (*setTemperatureReachedCallback)(uint16_t);
  13. typedef void (*currentModeChanged)(uint8_t);
  14. typedef union{
  15. uint8_t Flags; // Flag for errors (wrong iron connection, NTC, internal failure...)
  16. struct{
  17. unsigned noIron:1; // No iron detected
  18. unsigned NTC_high:1; // NTC too high
  19. unsigned NTC_low:1; // NTC too low
  20. unsigned V_low:1; // Voltage too low
  21. unsigned failState:1; // Internal fail-safe state (some undefined variable or data detected)
  22. unsigned unused_b5:1;
  23. unsigned unused_b6:1;
  24. unsigned globalFlag:1; // Global error flag
  25. };
  26. }IronError_t;
  27. # define ErrorMask (uint8_t)0b11111 // mask for used error bit fields (skipping global flag)
  28. typedef struct {
  29. TIM_HandleTypeDef *Pwm_Timer; // Pointer to the PWM timer
  30. uint8_t Pwm_Channel; // PWM channel
  31. uint16_t Pwm_Limit; // Max PWM output value possible
  32. uint16_t Pwm_Max; // Max PWM output based on power limit
  33. uint16_t Pwm_Out; // Last PWM value calculated
  34. TIM_HandleTypeDef *Delay_Timer; // Pointer to the Delay timer
  35. int8_t CurrentIronPower; // Last output power
  36. uint16_t CurrentSetTemperature; // Actual set temperature (Setpoint)
  37. uint16_t Debug_SetTemperature; // Debug mode temperature
  38. uint32_t LastSysChangeTime; // Last time a system setting was changed
  39. uint32_t LastModeChangeTime; // Last time the mode was changed (To provide debouncing)
  40. uint32_t LastErrorTime; // last time iron error was detected
  41. uint32_t lastActivityTime; // last time iron handle was moved (In shake mode)
  42. uint8_t CurrentMode; // Actual working mode (Standby, Sleep, Normal, Boost)
  43. uint8_t changeMode; // change working mode to (Standby, Sleep, Normal, Boost)
  44. uint32_t CurrentModeTimer; // Time since actual mode was set
  45. IronError_t Error; // Error flags
  46. uint32_t RunawayTimer; // Runaway timer
  47. uint8_t RunawayLevel; // Runaway actual level
  48. uint8_t prevRunawayLevel; // Runaway previous level
  49. bool RunawayStatus; // Runaway triggered flag
  50. bool updatePwm; // Set when timer values need to be updated
  51. bool calibrating; // Flag to indicate calibration state (don't save temperature settings)
  52. bool updateMode; // Flag to indicate the mode must be changed
  53. bool newActivity; // Flag to indicate handle movement
  54. bool Cal_TemperatureReachedFlag; // Flag for temperature calibration
  55. bool DebugMode; // Flag to indicate Debug is enabled
  56. }iron_t;
  57. extern volatile iron_t Iron;
  58. void IronWake(bool source);
  59. void checkIronError(void);
  60. bool GetIronError(void);
  61. void updatePowerLimit(void);
  62. void runAwayCheck(void);
  63. void SetFailState(bool FailState);
  64. bool GetFailState(void);
  65. void setCurrentMode(uint8_t mode);
  66. void setModefromStand(uint8_t mode);
  67. void setUserTemperature(uint16_t temperature);
  68. uint16_t getUserTemperature(void);
  69. uint8_t getCurrentMode(void);
  70. uint16_t getSetTemperature();
  71. uint16_t getCurrentTemperature();
  72. int8_t getCurrentPower();
  73. void initTimers(void);
  74. void setPwmPeriod(uint16_t period);
  75. void setPwmDelay(uint16_t delay);
  76. void setNoIronValue(uint16_t noiron);
  77. void setSystemTempUnit(bool unit);
  78. void addSetTemperatureReachedCallback(setTemperatureReachedCallback callback);
  79. void addModeChangedCallback(currentModeChanged callback);
  80. void handleIron(void);
  81. void ironInit(TIM_HandleTypeDef *delaytimer, TIM_HandleTypeDef *pwmtimer, uint32_t pwmchannel);
  82. uint8_t getIronOn();
  83. void setDebugTemp(uint16_t value);
  84. void setDebugMode(uint8_t value);
  85. void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *_htim);
  86. #endif /* IRON_H_ */