0.1.05 2015-07-12 refactor robust constructor

This commit is contained in:
rob tillaart 2015-12-06 16:40:51 +01:00
parent 1f3495a4b2
commit 7993100516
3 changed files with 17 additions and 11 deletions

View File

@ -1,12 +1,13 @@
// //
// FILE: MAX31855.cpp // FILE: MAX31855.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.04 // VERSION: 0.1.05
// PURPOSE: MAX31855 - Thermocouple // PURPOSE: MAX31855 - Thermocouple
// DATE: 2014-01-01 // DATE: 2014-01-01
// URL: // URL:
// //
// HISTORY: // HISTORY:
// 0.1.05 2015-07-12 refactor robust constructor
// 0.1.04 2015-03-09 replaced float -> double (ARM support) // 0.1.04 2015-03-09 replaced float -> double (ARM support)
// 0.1.03 fixed negative temperature // 0.1.03 fixed negative temperature
// 0.1.02 added offset // 0.1.02 added offset
@ -24,6 +25,9 @@ MAX31855::MAX31855(uint8_t sclk, uint8_t cs, uint8_t miso)
_cs = cs; _cs = cs;
_miso = miso; _miso = miso;
_offset = 0; _offset = 0;
_status = STATUS_NOREAD;
_temperature = -999;
_internal = -999;
} }
void MAX31855::begin() void MAX31855::begin()

View File

@ -1,7 +1,7 @@
// //
// FILE: MAX31855.h // FILE: MAX31855.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.04 // VERSION: 0.1.05
// PURPOSE: MAX31855 - Thermocouple // PURPOSE: MAX31855 - Thermocouple
// DATE: 2014-01-01 // DATE: 2014-01-01
// URL: // URL:
@ -17,12 +17,14 @@
#include "Arduino.h" #include "Arduino.h"
#endif #endif
#define MAX31855_VERSION "0.1.04" #define MAX31855_VERSION "0.1.05"
#define STATUS_OK 0x00 #define STATUS_OK 0x00
#define STATUS_OPEN_CIRCUIT 0x01 #define STATUS_OPEN_CIRCUIT 0x01
#define STATUS_SHORT_TO_GND 0x02 #define STATUS_SHORT_TO_GND 0x02
#define STATUS_SHORT_TO_VCC 0x04 #define STATUS_SHORT_TO_VCC 0x04
#define STATUS_NOREAD 0x80
class MAX31855 class MAX31855
{ {
@ -32,12 +34,13 @@ public:
uint8_t read(); uint8_t read();
double getInternal(void) { return _internal; }; double getInternal(void) const { return _internal; };
double getTemperature(void) { return _temperature; }; double getTemperature(void) const { return _temperature; };
uint8_t getStatus(void) { return _status; };
void setOffset(double t) { _offset = t; }; uint8_t getStatus(void) const { return _status; };
double getOffset() { return _offset; };
void setOffset(const double t) { _offset = t; };
double getOffset() const { return _offset; };
private: private:
uint32_t _read(); uint32_t _read();

View File

@ -20,11 +20,10 @@ bit 0 set = thermocouple open circuit
bit 1 set = thermocouple short to GND bit 1 set = thermocouple short to GND
bit 2 set = thermocouple short to VCC bit 2 set = thermocouple short to VCC
After a tc.read() you can do tc.getTemperature() and tc.getInternal(). After a tc.read() you can do tc.getTemperature() and tc.getInternal().
repeated getTemperature() will give the same value until a new tc.read(); repeated getTemperature() will give the same value until a new tc.read();
The reason for this is that it allows the object holds its last known temperature. The reason for this is that it allows the object to hold its last known temperature.
Now one can do: Now one can do:
float last = tc.getTemperature(); float last = tc.getTemperature();