#include "ConfigHandler.h"
#include "BuzzerHdlr.h"
#include "SwitchHandler.h"
#include "FloatSwitchHandler.h"
#include "ButtonRotaryHandler.h"
#include "WaterBankHandler.h"
#include "SterilizationHandler.h"
#include "DisplayHandler.h"
#include "Dashboard.h"
#include "App.h"

uint32_t switchRefreshDuration = 2000;
uint32_t switchRefreshTick = 0;

void setup(){
  Serial.begin(115200);
  InitSwitchHandler();
  InitInSwitchHandler();
  
  InitButtonRotaryHandler();
  for(int i=0; i<2; i++){
    delay(1000);
    InitDisplay();
  }
  delay(50);
  InitDisplay();
  //delay(2000); //wait voltage stabilize
  
  delay(5);
  //bool b = WaterBankTestUnit();
  InitApp();
}

void loop(){
  // SwitchDemo();
  // return;

  // checkRelay();
  ButtonRotaryDebugRoutine();

  AppRoutine();

  //Wifi and AP routine here
  //..............................

  //lazy update floating switch states
  if (millis()-switchRefreshTick>switchRefreshDuration){
    switchRefreshTick = millis();
    RefreshInSwitchState();
  }

  WaterBankSystemRoutine();
  ChamberSystemRoutine();
  
}
