makes GPIO_PIN_RST optional for the sx1276
[ExpressLRS.git] / src / lib / THERMAL / thermal.cpp
blob9b425286934e7a27bbd16828a2c190acb1899d05
1 #ifdef HAS_THERMAL
2 #include "thermal.h"
3 #include "logging.h"
5 #ifdef HAS_THERMAL_LM75A
6 #include "lm75a.h"
7 LM75A lm75a;
8 #endif
10 uint8_t thermal_threshold_data[] = {
11 THERMAL_FAN_DEFAULT_HIGH_THRESHOLD,
12 THERMAL_FAN_DEFAULT_LOW_THRESHOLD,
13 THERMAL_FAN_ALWAYS_ON_HIGH_THRESHOLD,
14 THERMAL_FAN_ALWAYS_ON_LOW_THRESHOLD,
15 THERMAL_FAN_OFF_HIGH_THRESHOLD,
16 THERMAL_FAN_OFF_LOW_THRESHOLD
19 int thermal_status = THERMAL_STATUS_FAIL;
21 void Thermal::init()
23 int status = -1;
24 #ifdef HAS_THERMAL_LM75A
25 status = lm75a.init();
26 #endif
27 if(status == -1)
29 ERRLN("Thermal failed!");
31 else
33 DBGLN("Thermal OK!");
34 temp_value = 0;
35 thermal_status = THERMAL_STATUS_NORMAL;
36 update_threshold(0);
40 void Thermal::handle()
42 temp_value = read_temp();
45 uint8_t Thermal::read_temp()
47 if(thermal_status != THERMAL_STATUS_NORMAL)
49 ERRLN("thermal not ready!");
50 return 0;
52 #ifdef HAS_THERMAL_LM75A
53 return lm75a.read_lm75a();
54 #else
55 return 0;
56 #endif
59 void Thermal::update_threshold(int index)
61 if(thermal_status != THERMAL_STATUS_NORMAL)
63 ERRLN("thermal not ready!");
64 return;
66 int size = sizeof(thermal_threshold_data)/sizeof(thermal_threshold_data[0]);
67 if(index > size/2)
69 ERRLN("thermal index out of range!");
70 return;
72 uint8_t high = thermal_threshold_data[2*index];
73 uint8_t low = thermal_threshold_data[2*index+1];
74 #ifdef HAS_THERMAL_LM75A
75 lm75a.update_lm75a_threshold(high, low);
76 #endif
79 #endif