-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensorManager.h
More file actions
50 lines (43 loc) · 1.62 KB
/
Copy pathSensorManager.h
File metadata and controls
50 lines (43 loc) · 1.62 KB
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
#ifndef SENSOR_MANAGER_H
#define SENSOR_MANAGER_H
#include <Arduino.h>
#include <Adafruit_MAX31865.h>
#include <atomic>
// Define HSPI Pins
#define MAX_CS 25
// #define MAX_DI 25
// #define MAX_DO 13
// #define MAX_CLK 16
// The value of the reference resistor on the board in ohms.
// Should be 430 (+- 1%) from factory. Measured ~427.1.
#define RREF 427.1
// The 'nominal' resistance of the sensor at 0C (100 for PT100)
#define RNOMINAL 100.0
class SensorManager {
private:
Adafruit_MAX31865* thermo; // Pointer to the library object
SPIClass* maxSPI; // Shared bus with SD
SemaphoreHandle_t spiMutex = NULL;
std::atomic<int>* _ghTargetRef = nullptr;
std::atomic<float>* _tauRef = nullptr;
unsigned long lastReadTime;
float currentTemp;
bool isMeasuring;
unsigned long measureStartTime;
float _initialGroupheadTemp = 40.0f; // assumed GH temp when boiler first reaches target
bool _tempSeeded = false; // accept the first valid reading directly (seeds currentTemp)
int _rejectCount = 0; // consecutive outlier rejections; escape hatch for genuine sustained change
public:
SensorManager(SPIClass* sharedSPI);
void init();
void setSpiMutex(SemaphoreHandle_t m);
void setGroupheadTargetRef(std::atomic<int>* ref);
void setTauRef(std::atomic<float>* ref);
float getInitialGroupheadTemp() const { return _initialGroupheadTemp; }
void update();
float getTemp();
float getEstimatedGroupheadTemp(unsigned long timeSinceBoilerReadyMs);
bool checkFaults();
uint8_t detectFault(); // blocking one-shot check for use at startup only
};
#endif