-
Notifications
You must be signed in to change notification settings - Fork 0
/
thermistor.h
59 lines (47 loc) · 1007 Bytes
/
thermistor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef _THERMISTOR_H
#define _THERMISTOR_H
#include "ntc_tables.h"
#include "adc.h"
// Resistor values. Each value corresponds to
// the specific conversion table in ntc_tables.h
typedef enum
{
resistor_10K,
resistor_15K,
resistor_2_5K,
} resistorValues_t;
class thermistor
{
private:
uint32_t pin;
resistorValues_t val;
public:
thermistor(uint32_t, resistorValues_t);
int16_t getTemp(void);
};
thermistor::thermistor(uint32_t pin, resistorValues_t val)
{
this->pin = pin;
this->val = val;
}
int16_t thermistor::getTemp(void)
{
uint16_t adcResult;
adcResult = adc_get(this->pin);
if(adcResult >= 1022)
return INT16_MAX;
switch (this->val)
{
case resistor_10K:
return NTC_10K[adcResult - 1];
break;
case resistor_15K:
return NTC_15K[adcResult - 1];
break;
case resistor_2_5K:
return NTC_2_5K[adcResult - 1];
break;
}
return INT16_MAX;
}
#endif