48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#ifndef IND_SENSOR_LUT_HPP
|
|
#define IND_SENSOR_LUT_HPP
|
|
|
|
#include <stdint.h>
|
|
|
|
// Piecewise-linear LUT calibration for an inductive sensor.
|
|
// adcTable is ADC value at mm = mmMin + i*mmStep, monotonically increasing in i.
|
|
typedef struct IndSensorLUT {
|
|
const uint16_t* adcTable;
|
|
uint16_t length;
|
|
float mmMin;
|
|
float mmStep;
|
|
} IndSensorLUT;
|
|
|
|
class IndSensorL {
|
|
public:
|
|
bool oor;
|
|
int8_t oorDir; // -1 = too close (below LUT), +1 = too far (above LUT), 0 = in range
|
|
float mmVal;
|
|
uint16_t analog;
|
|
float alpha;
|
|
|
|
IndSensorL(IndSensorLUT calibration, uint8_t analogPin, float emaAlpha = 0.3f);
|
|
float readMM();
|
|
|
|
private:
|
|
IndSensorLUT cal;
|
|
uint8_t pin;
|
|
float filteredRaw;
|
|
|
|
float toMM(uint16_t raw);
|
|
};
|
|
|
|
// Per-sensor LUTs generated from A0Calibration/data (4.0..18.0 mm @ 0.1 mm).
|
|
extern const IndSensorLUT ind0LUTCal;
|
|
extern const IndSensorLUT ind1LUTCal;
|
|
extern const IndSensorLUT ind2LUTCal;
|
|
extern const IndSensorLUT ind5LUTCal;
|
|
|
|
// Sensor instances — face → pin/LUT mapping defined in IndSensorLUT.cpp.
|
|
// Names shadow IndSensorMap; do not include both headers in the same sketch.
|
|
extern IndSensorL indF;
|
|
extern IndSensorL indB;
|
|
extern IndSensorL indL;
|
|
extern IndSensorL indR;
|
|
|
|
#endif // IND_SENSOR_LUT_HPP
|