LCOV - code coverage report
Current view: top level - src/AH/Hardware - IncrementDecrementButtons.cpp (source / functions) Hit Total Coverage
Test: 169c36a3797bc662d84b5726f34a3f37d3c58247 Lines: 43 43 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 "IncrementDecrementButtons.hpp"
       2             : 
       3             : BEGIN_AH_NAMESPACE
       4             : 
       5             : IncrementDecrementButtons::State
       6          38 : IncrementDecrementButtons::updateImplementation() {
       7          38 :     Button::State incrState = incrementButton.update();
       8          38 :     Button::State decrState = decrementButton.update();
       9             : 
      10          38 :     if (decrState == Button::Released && incrState == Button::Released) {
      11             :         // Both released
      12          33 :     } else if ((decrState == Button::Rising && incrState == Button::Released) ||
      13          29 :                (incrState == Button::Rising && decrState == Button::Released) ||
      14           2 :                (incrState == Button::Rising && decrState == Button::Rising)) {
      15             :         // One released, the other rising → nothing
      16             :         // now both released, so go to initial state
      17           8 :         longPressState = Initial;
      18          25 :     } else if (incrState == Button::Falling && decrState == Button::Falling) {
      19             :         // Both falling → reset
      20             :         // (rather unlikely, but just in case)
      21           2 :         longPressState = AfterReset;
      22           2 :         return Reset;
      23          23 :     } else if (incrState == Button::Falling) {
      24           7 :         if (decrState == Button::Pressed) {
      25             :             // One pressed, the other falling → reset
      26           1 :             longPressState = AfterReset;
      27           1 :             return Reset;
      28             :         } else {
      29             :             // Increment falling, the other released → increment
      30           6 :             return IncrementShort;
      31             :         }
      32          16 :     } else if (decrState == Button::Falling) {
      33           7 :         if (incrState == Button::Pressed) {
      34             :             // One pressed, the other falling → reset
      35           1 :             longPressState = AfterReset;
      36           1 :             return Reset;
      37             :         } else {
      38             :             // Decrement falling, the other released → decrement
      39           6 :             return DecrementShort;
      40             :         }
      41           9 :     } else if (incrState == Button::Pressed && decrState == Button::Pressed) {
      42             :         // Both pressed → nothing
      43           9 :     } else if (longPressState != AfterReset && incrState == Button::Pressed) {
      44             :         // Not reset and increment pressed → long press?
      45           4 :         auto now = millis();
      46           4 :         if (longPressState == LongPress) {
      47           2 :             if (now - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
      48           1 :                 longPressRepeat += LONG_PRESS_REPEAT_DELAY;
      49           1 :                 return IncrementHold;
      50             :             }
      51           2 :         } else if (incrementButton.stableTime() >= LONG_PRESS_DELAY) {
      52           1 :             longPressState = LongPress;
      53           1 :             longPressRepeat = now;
      54           1 :             return IncrementLong;
      55             :         }
      56           7 :     } else if (longPressState != AfterReset && decrState == Button::Pressed) {
      57             :         // Not reset and decrement pressed → long press?
      58           4 :         auto now = millis();
      59           4 :         if (longPressState == LongPress) {
      60           2 :             if (now - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
      61           1 :                 longPressRepeat += LONG_PRESS_REPEAT_DELAY;
      62           1 :                 return DecrementHold;
      63             :             }
      64           2 :         } else if (decrementButton.stableTime() >= LONG_PRESS_DELAY) {
      65           1 :             longPressState = LongPress;
      66           1 :             longPressRepeat = now;
      67           1 :             return DecrementLong;
      68             :         }
      69             :     }
      70          18 :     return Nothing;
      71             : }
      72             : 
      73             : END_AH_NAMESPACE

Generated by: LCOV version 1.15