LCOV - code coverage report
Current view: top level - src/AH/Hardware - IncrementButton.cpp (source / functions) Hit Total Coverage
Test: 169c36a3797bc662d84b5726f34a3f37d3c58247 Lines: 20 20 100.0 %
Date: 2024-11-09 15:32:27 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "IncrementButton.hpp"
       2             : 
       3             : BEGIN_AH_NAMESPACE
       4             : 
       5          16 : IncrementButton::State IncrementButton::updateImplementation() {
       6          16 :     Button::State incrState = button.update();
       7             : 
       8          16 :     if (incrState == Button::Released) {
       9             :         // Button released, don't do anything
      10             :         // This one is first to minimize overhead
      11             :         // because most of the time, the button will
      12             :         // be released
      13           2 :         return Nothing;
      14          14 :     } else if (incrState == Button::Rising) {
      15           4 :         auto res = longPressState == LongPress ? ReleasedLong : ReleasedShort;
      16           4 :         longPressState = Initial;
      17           4 :         return res;
      18          10 :     } else if (incrState == Button::Falling) {
      19           5 :         return IncrementShort;
      20             :     } else { // if (incrState == Button::Pressed)
      21           5 :         auto now = millis();
      22           5 :         if (longPressState == LongPress) {
      23             :             // still long pressed
      24           2 :             if (now - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
      25           1 :                 longPressRepeat += LONG_PRESS_REPEAT_DELAY;
      26           1 :                 return IncrementHold;
      27             :             }
      28           3 :         } else if (button.stableTime(now) >= LONG_PRESS_DELAY) {
      29             :             // long press starts
      30           1 :             longPressState = LongPress;
      31           1 :             longPressRepeat = now;
      32           1 :             return IncrementLong;
      33             :         }
      34             :     }
      35           3 :     return Nothing;
      36             : }
      37             : 
      38             : END_AH_NAMESPACE

Generated by: LCOV version 1.15