From 1d47154445a9af78521e57c09348d69e58001309 Mon Sep 17 00:00:00 2001 From: Torsten Date: Mon, 5 Jul 2021 14:26:32 +0300 Subject: [PATCH] not started state where collector does not switch --- fan_control/include/collector.hpp | 3 +++ fan_control/src/collector.cpp | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/fan_control/include/collector.hpp b/fan_control/include/collector.hpp index f2ab706..43d6913 100644 --- a/fan_control/include/collector.hpp +++ b/fan_control/include/collector.hpp @@ -25,6 +25,8 @@ protected: int week_counter = 0; int month_counter = 0; + boolean started = false; + void add_month(int from ) ; void switch_logic(float in , float out); @@ -37,6 +39,7 @@ public: void add_week(float in , float out) ; void add(float in , float out) ; + void start(); // fake data before, no switching String week_data( int at); String month_data(int at); diff --git a/fan_control/src/collector.cpp b/fan_control/src/collector.cpp index 6dc9ab7..ac5c4c7 100644 --- a/fan_control/src/collector.cpp +++ b/fan_control/src/collector.cpp @@ -43,6 +43,7 @@ void collector_setup(){ last_in = next_rand(last_in); last_out = next_rand(last_out); } + collector.start(); } void collector_loop(){ @@ -70,18 +71,23 @@ void Collector::add(float in , float out) } } +void Collector::start(){ + started = true; + week_counter = 0; + month_counter = 0; +} + void Collector::switch_logic(float in , float out){ - u_int8_t on; - String msg; - if(in < out){ - on = 1 ; - msg = "Switching on"; - }else{ - on = 0 ; - msg = "Switching off"; + if( !started ) return ; + if(out > (in + 1.0) ){ + digitalWrite( RELAY , 1); + DEBUG_OUT.println("Switching on"); + }else if( in > (out - 0.5 ) ) { + digitalWrite( RELAY , 0); + DEBUG_OUT.println( "Switching off" ); + } else { + DEBUG_OUT.println( "No Switching" ); } - digitalWrite( RELAY , on); - DEBUG_OUT.println(msg); } void Collector::add_week(float in , float out){