-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRTDTempProbeClass.cpp
106 lines (89 loc) · 2.85 KB
/
RTDTempProbeClass.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* @file RTDTempProbeClass.cpp
* @author Leonardo Cavagnis
* @brief Source file for the Resistance Temperature Detector (RTD) temperature sensor connector of the Portenta Machine Control.
*/
/* Includes -----------------------------------------------------------------*/
#include "RTDTempProbeClass.h"
#if __has_include("portenta_info.h")
#include "portenta_info.h"
#define TRY_REV2_RECOGNITION
uint8_t* boardInfo();
#define PMC_R2_SKU (24 << 8 | 3)
#endif
/* Functions -----------------------------------------------------------------*/
RTDTempProbeClass::RTDTempProbeClass(PinName rtd_cs_pin,
PinName ch_sel0_pin,
PinName ch_sel1_pin,
PinName ch_sel2_pin,
PinName rtd_th_pin)
: MAX31865Class(rtd_cs_pin), _rtd_cs{rtd_cs_pin}, _ch_sel0{ch_sel0_pin}, _ch_sel1{ch_sel1_pin}, _ch_sel2{ch_sel2_pin}, _rtd_th{rtd_th_pin}
{ }
RTDTempProbeClass::~RTDTempProbeClass()
{ }
bool RTDTempProbeClass::begin(uint8_t io_address) {
MAX31865Class::begin(io_address);
pinMode(_ch_sel0, OUTPUT);
pinMode(_ch_sel1, OUTPUT);
pinMode(_ch_sel2, OUTPUT);
pinMode(_rtd_th, OUTPUT);
pinMode(_rtd_cs, OUTPUT);
_enable();
return true;
}
void RTDTempProbeClass::selectChannel(int channel) {
#ifdef TRY_REV2_RECOGNITION
// check if OTP data is present AND the board is mounted on a r2 carrier
auto info = (PortentaBoardInfo*)boardInfo();
if (info->magic == 0xB5 && info->carrier == PMC_R2_SKU) {
// reverse channels 0 and 2
switch (channel) {
case 0:
channel = 2;
break;
case 2:
channel = 0;
break;
default:
break;
}
}
#endif
#undef TRY_REV2_RECOGNITION
switch(channel) {
case 0:
digitalWrite(_ch_sel0, HIGH);
digitalWrite(_ch_sel1, LOW);
digitalWrite(_ch_sel2, LOW);
break;
case 1:
digitalWrite(_ch_sel0, LOW);
digitalWrite(_ch_sel1, HIGH);
digitalWrite(_ch_sel2, LOW);
break;
case 2:
digitalWrite(_ch_sel0, LOW);
digitalWrite(_ch_sel1, LOW);
digitalWrite(_ch_sel2, HIGH);
break;
default:
digitalWrite(_ch_sel0, LOW);
digitalWrite(_ch_sel1, LOW);
digitalWrite(_ch_sel2, LOW);
break;
}
delay(150);
}
void RTDTempProbeClass::end() {
MAX31865Class::end();
_disable();
}
void RTDTempProbeClass::_enable() {
digitalWrite(_rtd_th, HIGH);
digitalWrite(_rtd_cs, LOW);
}
void RTDTempProbeClass::_disable() {
digitalWrite(_rtd_cs, HIGH);
}
RTDTempProbeClass MachineControl_RTDTempProbe;
/**** END OF FILE ****/