Skip to content

Commit 76f88a0

Browse files
committed
Formating of MAX31865Class
1 parent 952590a commit 76f88a0

File tree

2 files changed

+8
-55
lines changed

2 files changed

+8
-55
lines changed

src/utility/RTD/MAX31865.cpp

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
/*
2-
This file is part of the MachineControl library.
3-
Copyright (c) 2021 Arduino SA.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
9-
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
14-
15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
19-
201
#include "MAX31865.h"
212

22-
233
MAX31865Class::MAX31865Class(PinName cs) : _spi(SPI), _cs(cs) {
244
}
255

@@ -30,11 +10,11 @@ bool MAX31865Class::begin(int wires) {
3010

3111
pinMode(_cs, OUTPUT);
3212
digitalWrite(_cs, HIGH);
13+
3314
// sets 2 or 4 wire
3415
if (wires == THREE_WIRE) {
3516
writeByte(MAX31856_CONFIG_REG, (readByte(MAX31856_CONFIG_REG) | MAX31856_CONFIG_3_WIRE));
3617
} else {
37-
3818
writeByte(MAX31856_CONFIG_REG, (readByte(MAX31856_CONFIG_REG) & MAX31856_CONFIG_WIRE_MASK));
3919
}
4020

@@ -76,23 +56,20 @@ bool MAX31865Class::getLowThresholdFault(uint8_t fault) {
7656
}
7757

7858
bool MAX31865Class::getLowREFINFault(uint8_t fault) {
79-
8059
if (fault & MAX31865_FAULT_LOW_REFIN) {
8160
return true;
8261
}
8362
return false;
8463
}
8564

8665
bool MAX31865Class::getHighREFINFault(uint8_t fault) {
87-
8866
if (fault & MAX31865_FAULT_HIGH_REFIN) {
8967
return true;
9068
}
9169
return false;
9270
}
9371

9472
bool MAX31865Class::getLowRTDINFault(uint8_t fault) {
95-
9673
if (fault & MAX31865_FAULT_LOW_RTDIN) {
9774
return true;
9875
}
@@ -113,7 +90,6 @@ float MAX31865Class::readTemperature(float RTDnominal, float refResistor) {
11390
Rt /= 32768;
11491
Rt *= refResistor;
11592

116-
11793
Z1 = -RTD_A;
11894
Z2 = RTD_A * RTD_A - (4 * RTD_B);
11995
Z3 = (4 * RTD_B) / RTDnominal;
@@ -146,7 +122,6 @@ float MAX31865Class::readTemperature(float RTDnominal, float refResistor) {
146122
}
147123

148124
uint32_t MAX31865Class::readRTD() {
149-
150125
// clear fault
151126
writeByte(MAX31856_CONFIG_REG, (readByte(MAX31856_CONFIG_REG) & MAX31856_CONFIG_CLEAR_FAULT_CYCLE) | MAX31856_CONFIG_CLEAR_FAULT);
152127

@@ -161,6 +136,7 @@ uint32_t MAX31865Class::readRTD() {
161136
//readings bytes
162137
uint16_t read = (readBytes(MAX31856_RTD_MSB_REG));
163138
read = read >>1;
139+
164140
// disable bias
165141
writeByte(MAX31856_CONFIG_REG, readByte(MAX31856_CONFIG_REG) & (MAX31856_CONFIG_BIAS_MASK));
166142

@@ -170,6 +146,7 @@ uint32_t MAX31865Class::readRTD() {
170146
uint8_t MAX31865Class::readByte(uint8_t addr) {
171147
addr &= 0x7F;
172148
uint8_t read = 0;
149+
173150
digitalWrite(_cs, LOW);
174151

175152
_spi.beginTransaction(_spiSettings);
@@ -183,16 +160,16 @@ uint8_t MAX31865Class::readByte(uint8_t addr) {
183160
}
184161

185162
uint16_t MAX31865Class::readBytes(uint8_t addr) {
186-
digitalWrite(_cs, LOW);
187163
uint16_t read = 0x00;
164+
165+
digitalWrite(_cs, LOW);
166+
188167
_spi.beginTransaction(_spiSettings);
189168
_spi.transfer(addr);
190-
int i;
191-
for (i = 0; i<2; i++) {
169+
for (int i = 0; i < 2; i++) {
192170
read = read << 8;
193171
read |= _spi.transfer(0);
194172
}
195-
196173
_spi.endTransaction();
197174

198175
digitalWrite(_cs, HIGH);
@@ -203,11 +180,11 @@ uint16_t MAX31865Class::readBytes(uint8_t addr) {
203180
void MAX31865Class::writeByte(uint8_t addr, uint8_t data) {
204181
addr |= 0x80; // make sure top bit is set
205182
uint8_t buffer[2] = {addr, data};
183+
206184
digitalWrite(_cs, LOW);
207185

208186
_spi.beginTransaction(_spiSettings);
209187
_spi.transfer(buffer,2);
210-
211188
_spi.endTransaction();
212189

213190
digitalWrite(_cs, HIGH);

src/utility/RTD/MAX31865.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
1-
/*
2-
This file is part of the MachineControl library.
3-
Copyright (c) 2021 Arduino SA.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
9-
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
14-
15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
19-
201
#ifndef MAX31865_H
212
#define MAX31865_H
223

234
#include <Arduino.h>
245
#include <mbed.h>
256
#include <SPI.h>
267

27-
288
#define MAX31856_CONFIG_REG 0x00
299
#define MAX31856_RTD_MSB_REG 0x01
3010
#define MAX31856_FAULT_STATUS_REG 0x07
@@ -70,7 +50,6 @@
7050
#define TWO_WIRE 0
7151
#define THREE_WIRE 1
7252

73-
7453
class MAX31865Class {
7554
public:
7655
MAX31865Class(PinName cs = PA_6);
@@ -89,8 +68,6 @@ class MAX31865Class {
8968
bool getLowRTDINFault(uint8_t fault);
9069
bool getVoltageFault(uint8_t fault);
9170

92-
93-
9471
private:
9572
uint8_t readByte(uint8_t addr);
9673
uint16_t readBytes(uint8_t addr);
@@ -100,5 +77,4 @@ class MAX31865Class {
10077
SPIClass& _spi;
10178
};
10279

103-
10480
#endif

0 commit comments

Comments
 (0)