#include #include #include "thermoControl.h" thermoControl::thermoControl(uint8_t* input_temp, uint8_t* setpoint_temp, uint8_t* output_pwm, uint8_t* max_threshold, uint8_t* hysteresis) { output_pwm = output_pwm; input_temp = input_temp; setpoint_temp = setpoint_temp; outMax = 1000; outMin = 100; OpMode = OFF; SampleTime = 100; lastTime = millis()-SampleTime; } bool thermoControl::Compute() { unsigned long now = millis(); unsigned long timeChange = (now - lastTime); if(timeChange>=SampleTime && OpMode == AUTOMATIC) { uint8_t output; uint8_t error = *setpoint_temp - *input_temp; if (error >= *max_threshold) { output = outMax; } else if (error > *hysteresis) { output = 100 * error / *max_threshold; output = max(output, outMin); output = min(output, outMax); } else { output = 0; } *output_pwm = output; lastTime = now; return true; } else { return false; } } void thermoControl::SetSampleTime(int NewSampleTime) { if (NewSampleTime > 0) { SampleTime = (unsigned long)NewSampleTime; } } void thermoControl::SetPowerLimits(uint8_t Max, uint8_t Min) { if(Min >= Max) return; outMax = Max; outMin = Min; } void thermoControl::SetMode(modes newMode) { OpMode = newMode; } modes thermoControl::GetMode() { return OpMode; } modes thermoControl::CycleMode() { OpMode = (modes)(OpMode + 1); return OpMode; }