Skip to content

Commit

Permalink
Fix checkFault() and clang
Browse files Browse the repository at this point in the history
  • Loading branch information
AnHardt committed Mar 13, 2020
1 parent fbb3b65 commit 85ee5e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions Adafruit_MAX31865.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ bool Adafruit_MAX31865::begin(max31865_numwires_t wires) {
@return true if the bit was set during the last readRTD()
*/
/**************************************************************************/
bool Adafruit_MAX31865::checkFault(void) {return _fault; }
bool Adafruit_MAX31865::checkFault(void) { return _fault; }

/**************************************************************************/
/*!
Expand All @@ -122,11 +122,12 @@ uint8_t Adafruit_MAX31865::readFault(void) {
uint8_t Adafruit_MAX31865::readFault(boolean b) {
uint8_t t = readRegister8(MAX31865_CONFIG_REG);
if (b) {
t |= MAX31865_CONFIG_FAULTDETCYCLE; // trigger automatic fault-detection cycle
t |= MAX31865_CONFIG_FAULTDETCYCLE; // trigger automatic fault-detection
// cycle
writeRegister8(MAX31865_CONFIG_REG, t);
delay(5); // wait for 5ms
delay(5); // wait for 5ms
}

return readRegister8(MAX31865_FAULTSTAT_REG);
}

Expand Down Expand Up @@ -216,7 +217,8 @@ float Adafruit_MAX31865::temperature(float RTDnominal, float refResistor) {
// Serial.print("\nResistance: "); Serial.println(Rt, 8);

// first, if needed, normalize to 100 ohm
if (RTDnominal != 100.0) Rt *= 100.0/RTDnominal;
if (RTDnominal != 100.0)
Rt *= 100.0 / RTDnominal;

if (Rt >= 100.0) { // above 100 Ohm temperature will become positive
Z1 = -RTD_A;
Expand All @@ -226,7 +228,7 @@ float Adafruit_MAX31865::temperature(float RTDnominal, float refResistor) {

temp = Z2 + (Z3 * Rt);
temp = (sqrt(temp) + Z1) / Z4;
} else {
} else {
float rpoly = Rt;

temp = -242.02;
Expand Down Expand Up @@ -260,11 +262,11 @@ uint16_t Adafruit_MAX31865::readRTD(void) {

uint16_t rtd = readRegister16(MAX31865_RTDMSB_REG);

enableBias(false); // to lessen sensor self-heating
enableBias(false); // to lessen sensor self-heating

_fault = rtd & 0x0001; // Store the fault flag

rtd >>= 1; // remove fault
rtd >>= 1; // remove fault

return rtd;
}
Expand Down
2 changes: 1 addition & 1 deletion Adafruit_MAX31865.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define MAX31865_CONFIG_1SHOT 0x20
#define MAX31865_CONFIG_3WIRE 0x10
#define MAX31865_CONFIG_24WIRE 0x00
#define MAX31865_CONFIG_FAULTDETCYCLE 0x84
#define MAX31865_CONFIG_FAULTDETCYCLE 0x84
#define MAX31865_CONFIG_FAULTSTAT 0x02
#define MAX31865_CONFIG_FILT50HZ 0x01
#define MAX31865_CONFIG_FILT60HZ 0x00
Expand Down
2 changes: 1 addition & 1 deletion examples/max31865/max31865.ino
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void loop() {
Serial.print("Temperature = "); Serial.println(thermo.temperature(RNOMINAL, RREF));

// Check and print any faults
if (checkFault()) {
if (thermo.checkFault()) {
uint8_t fault = thermo.readFault();
if (fault) {
Serial.print("Fault 0x"); Serial.println(fault, HEX);
Expand Down

0 comments on commit 85ee5e8

Please sign in to comment.