Fixed a bug for chlorPump.yaml where the target would not properly load on start
This commit is contained in:
@@ -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> {
|
||||
|
Reference in New Issue
Block a user