From 9a535c665b3cc7df4c9a51585e185028dcd6feba Mon Sep 17 00:00:00 2001 From: Chris Giacofei Date: Fri, 21 Jan 2022 11:35:09 -0500 Subject: [PATCH] Use simpler constructor. --- boil_kettle/boil_kettle.ino | 5 +++-- boil_kettle/globals.h | 2 ++ boil_kettle/thermoControl.cpp | 25 ++++++++++++++++--------- boil_kettle/thermoControl.h | 6 ++++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/boil_kettle/boil_kettle.ino b/boil_kettle/boil_kettle.ino index a73bdef..ee8c41a 100644 --- a/boil_kettle/boil_kettle.ino +++ b/boil_kettle/boil_kettle.ino @@ -102,7 +102,6 @@ void setup() { ConfigData config; EEPROM.get(ConfAddress, config); - unsigned long lastRun = millis() - UpdateInterval; Serial.begin(9600); rotary.begin(); @@ -120,7 +119,9 @@ void setup() { mqtt_client.setClient(net); mqtt_client.setCallback(MessageReceived); - KettleController.begin((int8_t)I_CS1, 0, 0, config.threshold, config.hysteresis); + KettleController.begin(I_CS1); + KettleController.SetHysteresis(config.hysteresis); + KettleController.SetThreshPWR(config.threshold); // if you get a connection, report back via serial: if (Ethernet.linkStatus() == LinkON) { diff --git a/boil_kettle/globals.h b/boil_kettle/globals.h index c831bb9..ff4b0bb 100644 --- a/boil_kettle/globals.h +++ b/boil_kettle/globals.h @@ -68,4 +68,6 @@ unsigned long lastRun = 0; #ifndef I_CS2 #define I_CS2 48 #endif + + #endif diff --git a/boil_kettle/thermoControl.cpp b/boil_kettle/thermoControl.cpp index 4f20ccf..c78f428 100644 --- a/boil_kettle/thermoControl.cpp +++ b/boil_kettle/thermoControl.cpp @@ -1,37 +1,44 @@ #include -#include #include "thermoControl.h" -void thermoControl::begin(int8_t pinRTD) { +void thermoControl::begin(int pinRTD) { RTD = new Adafruit_MAX31865(pinRTD); + r_ref = 430.0; + r_nominal = 100.0; outMax = 100; outMin = 10; OpMode = OFF; SampleTime = 100; lastTime = millis()-SampleTime; + output_pwm = 0; + control_temp = 0; + hysteresis = 1.0; + max_pwr_threshold = 5.0; } -void thermoControl::begin(int8_t pinRTD, double temp, double output_pwm, double max_pwr_threshold, double hysteresis) { - output_pwm = output_pwm; - +void thermoControl::begin(int pinRTD, double temp, double duty, double mpt, double hyst) { RTD = new Adafruit_MAX31865(pinRTD); - control_temp = temp; - + r_ref = 430.0; + r_nominal = 100.0; outMax = 100; outMin = 10; - OpMode = OFF; SampleTime = 100; lastTime = millis()-SampleTime; + + output_pwm = duty; + control_temp = temp; + hysteresis = hyst; + max_pwr_threshold = mpt; } bool thermoControl::Compute() { unsigned long now = millis(); unsigned long timeChange = (now - lastTime); - double temp = RTD->readRTD(); + double temp = RTD->temperature(r_nominal, r_ref); if(timeChange>=SampleTime && OpMode == AUTOMATIC) { double output; diff --git a/boil_kettle/thermoControl.h b/boil_kettle/thermoControl.h index ca0f2af..93e8830 100644 --- a/boil_kettle/thermoControl.h +++ b/boil_kettle/thermoControl.h @@ -8,6 +8,8 @@ enum modes : uint8_t {OFF, AUTOMATIC, MANUAL, OVERFLOW}; class thermoControl { private: Adafruit_MAX31865* RTD; + double r_nominal; + double r_ref; double output_pwm; double control_temp; double hysteresis; @@ -21,8 +23,8 @@ class thermoControl { unsigned long lastTime; public: - void begin(int8_t, double, double, double, double); - void begin(int8_t); + void begin(int, double, double, double, double); + void begin(int); bool Compute(); double Power(); void Power(double);