LCOV - code coverage report
Current view: top level - src/AH/Hardware - IncrementButton.cpp (source / functions) Hit Total Coverage
Test: e224b347cd670555e44f06608ac41bd1ace9d9d8 Lines: 22 22 100.0 %
Date: 2020-09-08 17:44:46 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14-6-g40580cd