1 #include "devThermal.h"
3 #if defined(HAS_THERMAL) || defined(HAS_FAN)
6 #error "devThermal not supported on RX"
10 extern TxConfig config
;
12 #define THERMAL_DURATION 1000
14 #if defined(HAS_THERMAL)
17 extern bool IsArmed();
21 #if defined(HAS_SMART_FAN)
22 bool is_smart_fan_control
= false;
23 bool is_smart_fan_working
= false;
29 #include "POWERMGNT.h"
31 #if !defined(FAN_MIN_RUNTIME)
32 #define FAN_MIN_RUNTIME 30U // seconds
37 static void initialize()
39 #if defined(HAS_THERMAL)
43 pinMode(GPIO_PIN_FAN_EN
, OUTPUT
);
47 static void timeoutThermal()
49 #if defined(HAS_THERMAL)
50 if(!IsArmed() && connectionState
!= wifiUpdate
)
54 if(is_smart_fan_control
& !is_smart_fan_working
){
55 is_smart_fan_working
= true;
56 thermal
.update_threshold(USER_SMARTFAN_OFF
);
58 if(!is_smart_fan_control
& is_smart_fan_working
){
59 is_smart_fan_working
= false;
61 thermal
.update_threshold(config
.GetFanMode());
70 * Checks the PowerFanThreshold vs CurrPower and enables the fan if at or above the threshold
71 * using a hysteresis. To turn on it must be at/above the threshold for a small time
72 * and then to turn off it must be below the threshold for FAN_MIN_RUNTIME intervals
74 static void timeoutFan()
77 static uint8_t fanStateDuration
;
79 bool fanShouldBeOn
= POWERMGNT::currPower() >= (PowerLevels_e
)config
.GetPowerFanThreshold();
85 fanStateDuration
= 0; // reset the timeout
87 else if (fanStateDuration
< FAN_MIN_RUNTIME
)
89 ++fanStateDuration
; // counting to turn off
94 digitalWrite(GPIO_PIN_FAN_EN
, LOW
);
99 // vv else fan is off currently vv
100 else if (fanShouldBeOn
)
102 // Delay turning the fan on for 4 cycles to be sure it really should be on
103 if (fanStateDuration
< 3)
105 ++fanStateDuration
; // counting to turn on
109 digitalWrite(GPIO_PIN_FAN_EN
, HIGH
);
110 fanStateDuration
= 0;
119 #if defined(HAS_THERMAL)
121 if(!is_smart_fan_control
)
124 thermal
.update_threshold(config
.GetFanMode());
128 #endif // HAS_THERMAL
130 return THERMAL_DURATION
;
138 return THERMAL_DURATION
;
141 device_t Thermal_device
= {
142 .initialize
= initialize
,
148 #endif // HAS_THERMAL || HAS_FAN