Fixed a bug for chlorPump.yaml where the target would not properly load on start

This commit is contained in:
2024-05-27 14:43:10 +02:00
parent 1bd3b7eb90
commit d21229fa73
3 changed files with 63 additions and 30 deletions

View File

@@ -22,8 +22,9 @@ class ChlorinePump : public Component {
CallbackManager<void(int, int)> callback_cycle_;
int tOn = 0;
int tOff = 0;
float target_ = 700.0f;
float target_ = -1;
float tOn_divider_;
std::function<float()> target_lambda_ = nullptr;
public:
@@ -62,6 +63,11 @@ class ChlorinePump : public Component {
});
}
}
void set_target_lambda(std::function<float()> callback){
target_lambda_ = std::move(callback);
}
void prime() {
tOn = 30;
tOff = 2;
@@ -79,6 +85,7 @@ class ChlorinePump : public Component {
bool get_state(){
return state;
}
void setMillisPrecies(unsigned long waitPeriod){
@@ -93,10 +100,18 @@ class ChlorinePump : public Component {
}
int calculatePumpTimeSeconds(float last_mesurement){
if(last_mesurement >= target_) return 0;
float currentVal = target_ - last_mesurement;
float used_target = -1;
if(target_ != -1){
used_target = target_;
}
else{
used_target = target_lambda_();
}
if(last_mesurement >= used_target) return 0;
float currentVal = used_target - last_mesurement;
float proportionalValue = (currentVal / (float) prop_band);
float timeInSeconds = proportionalValue * (float) cycle_time;
@@ -154,6 +169,10 @@ class ChlorinePump : public Component {
setMillisPrecies(1000);
}
}
void dump_config() override {
}
};
class ChlorSensorOutputTrigger : public Trigger<bool, int> {