first cali refactor step
This commit is contained in:
@ -20,7 +20,7 @@ const uint8_t ADC_1_RDY_PIN = 7;
|
|||||||
const uint8_t ADC_2_CS_PIN = 2;
|
const uint8_t ADC_2_CS_PIN = 2;
|
||||||
const uint8_t ADC_2_RDY_PIN = 3;
|
const uint8_t ADC_2_RDY_PIN = 3;
|
||||||
|
|
||||||
const uint8_t CAL_ENABLE = 14;
|
const uint8_t DEBUG = 14;
|
||||||
const uint8_t CAL_OFFSET_ENABLE = 15;
|
const uint8_t CAL_OFFSET_ENABLE = 15;
|
||||||
const uint8_t CAL_FACTOR_ENABLE = 16;
|
const uint8_t CAL_FACTOR_ENABLE = 16;
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ uint32_t uptimeSeconds = 0;
|
|||||||
|
|
||||||
typedef enum { e_CAL_IDLE, e_CAL_RUNNING, e_CAL_SET, e_CAL_COMPLETE } tCalibrationState;
|
typedef enum { e_CAL_IDLE, e_CAL_RUNNING, e_CAL_SET, e_CAL_COMPLETE } tCalibrationState;
|
||||||
|
|
||||||
|
bool debug = false;
|
||||||
bool calibrationOffsetEnable = false;
|
bool calibrationOffsetEnable = false;
|
||||||
bool calibrationFactorEnable = false;
|
bool calibrationFactorEnable = false;
|
||||||
tCalibrationState calibrationState = e_CAL_IDLE;
|
tCalibrationState calibrationState = e_CAL_IDLE;
|
||||||
@ -92,14 +93,15 @@ struct {
|
|||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(CAL_ENABLE, INPUT_PULLUP);
|
pinMode(DEBUG, INPUT_PULLUP);
|
||||||
pinMode(CAL_FACTOR_ENABLE, INPUT_PULLUP);
|
pinMode(CAL_FACTOR_ENABLE, INPUT_PULLUP);
|
||||||
pinMode(CAL_OFFSET_ENABLE, INPUT_PULLUP);
|
pinMode(CAL_OFFSET_ENABLE, INPUT_PULLUP);
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
calibrationOffsetEnable = (digitalRead(CAL_ENABLE) == 0) && (digitalRead(CAL_OFFSET_ENABLE) == 0);
|
debug = (digitalRead(DEBUG) == 0);
|
||||||
calibrationFactorEnable = (digitalRead(CAL_ENABLE) == 0) && (digitalRead(CAL_FACTOR_ENABLE) == 0);
|
calibrationOffsetEnable = debug && (digitalRead(CAL_OFFSET_ENABLE) == 0);
|
||||||
|
calibrationFactorEnable = debug && (digitalRead(CAL_FACTOR_ENABLE) == 0);
|
||||||
|
|
||||||
bool initializeConfig = Config::initialize();
|
bool initializeConfig = Config::initialize();
|
||||||
led.begin(LED_PIN);
|
led.begin(LED_PIN);
|
||||||
@ -108,7 +110,7 @@ void setup() {
|
|||||||
thermometer[0].begin(initializeConfig, Config::THERMO1START);
|
thermometer[0].begin(initializeConfig, Config::THERMO1START);
|
||||||
thermometer[1].begin(initializeConfig, Config::THERMO2START);
|
thermometer[1].begin(initializeConfig, Config::THERMO2START);
|
||||||
|
|
||||||
if (calibrationOffsetEnable || calibrationFactorEnable) {
|
if (debug) {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
} else {
|
} else {
|
||||||
modbus_configure(&Serial, MODBUS_BAUD, SERIAL_8N2, MODBUS_ID, MODBUS_TX_ENABLE_PIN,
|
modbus_configure(&Serial, MODBUS_BAUD, SERIAL_8N2, MODBUS_ID, MODBUS_TX_ENABLE_PIN,
|
||||||
@ -142,7 +144,7 @@ void loop() {
|
|||||||
|
|
||||||
|
|
||||||
if (secondTick.check() == 1) {
|
if (secondTick.check() == 1) {
|
||||||
if (calibrationOffsetEnable || calibrationFactorEnable) {
|
if (debug) {
|
||||||
for (uint8_t i = 0; i < NUM_OF_CHANNELS; i++) {
|
for (uint8_t i = 0; i < NUM_OF_CHANNELS; i++) {
|
||||||
Serial << "Last measurement: Offset: " << ads1210[i].getCalOffset() << ", Factor: " << ads1210[i].getCalFactor();
|
Serial << "Last measurement: Offset: " << ads1210[i].getCalOffset() << ", Factor: " << ads1210[i].getCalFactor();
|
||||||
Serial << ", R_Raw: " << ads1210[i].getRRaw() << ", R: " << ads1210[i].getR() << endl;
|
Serial << ", R_Raw: " << ads1210[i].getRRaw() << ", R: " << ads1210[i].getR() << endl;
|
||||||
@ -220,7 +222,7 @@ void loop() {
|
|||||||
modbusHoldingRegisters.uptimeSeconds.in = uptimeSeconds;
|
modbusHoldingRegisters.uptimeSeconds.in = uptimeSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! (calibrationOffsetEnable || calibrationFactorEnable)) {
|
if (! debug) {
|
||||||
modbus_update();
|
modbus_update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user