AlexanderTonn / SolarPowerhouse

Solar balkony power plant, which includes control logic for switching between micro inverter and battery depending on the state of charge. The repository containing any drawings and manuals.
Apache License 2.0
0 stars 0 forks source link

[NEW] Standby Handler #29

Closed AlexanderTonn closed 12 months ago

AlexanderTonn commented 12 months ago

 :rocket: Please describe your feature request

auto StandbyHandler(uint32_t &uiElapsed, uint32_t uiTarget, bool xTouched) -> void
{
  static bool xStandby = false;

  if (!xTouched 
      && millis() - uiElapsed >= uiTarget * 1000 
      && !xStandby)
  {
    // fade out HMI if no touch input

      xStandby = true;
      for (auto i = uiTftBrightness; i > 0; i--)
      {
        analogWrite(TFT_LED, i);
        delay(10);
      }
  }
  // Turn on, if touch was pressed
  else if (xTouched && xStandby)
  {
    xStandby = false;
    for (auto i = 0; i < uiTftBrightness; i++)
    {
      analogWrite(TFT_LED, i);
      delay(10);
    }
  }

  if(xTouched)
    uiElapsed = millis(); // reset timer

}

I call the function in my hmi touch Loop. One time before touch was detected and one time after touch was detected. With this two calls i know with the passing of trueor falsewhether touch was detected and i can start timers for turning off the background light.

auto hmiTouch() -> void
{
  StandbyHandler(uiTimeWithNoTouch, uiStandbyTargetTime, false);

  if (touch.touched())
  {
    StandbyHandler(uiTimeWithNoTouch, uiStandbyTargetTime, true);
    TS_Point touchPoint = touch.getPoint();
    touchPoint.x = map(touchPoint.x, TOUCH_X_MIN, TOUCH_X_MAX, tft.width(), 0);
    touchPoint.y = map(touchPoint.y, TOUCH_Y_MIN, TOUCH_Y_MAX, 0, tft.height());

// ...

 :pushpin: Describe alternatives you've considered

Additional context

:white_check_mark: Tasks