LCOV - code coverage report
Current view: top level - src/Hardware - IncrementDecrementButtons.cpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 18 42 42.9 %
Date: 2019-11-24 14:50:27 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "IncrementDecrementButtons.hpp"
       2             : 
       3             : BEGIN_CS_NAMESPACE
       4             : 
       5             : IncrementDecrementButtons::State
       6          19 : IncrementDecrementButtons::updateImplementation() {
       7          19 :     Button::State incrState = incrementButton.update();
       8          19 :     Button::State decrState = decrementButton.update();
       9             : 
      10          19 :     if (decrState == Button::Released && incrState == Button::Released) {
      11             :         // Both released
      12          22 :     } else if ((decrState == Button::Rising && incrState == Button::Released) ||
      13          14 :                (incrState == Button::Rising && decrState == Button::Released)) {
      14             :         // One released, the other rising → nothing
      15             :         // now both released, so go to initial state
      16           6 :         longPressState = Initial;
      17          17 :     } else if (incrState == Button::Falling && decrState == Button::Falling) {
      18             :         // Both falling → reset
      19             :         // (rather unlikely, but just in case)
      20           1 :         longPressState = AfterReset;
      21           1 :         return Reset;
      22          10 :     } else if (incrState == Button::Falling) {
      23           5 :         if (decrState == Button::Pressed) {
      24             :             // One pressed, the other falling → reset
      25           0 :             longPressState = AfterReset;
      26           0 :             return Reset;
      27             :         } else {
      28             :             // Increment falling, the other released → increment
      29           5 :             return Increment;
      30             :         }
      31           5 :     } else if (decrState == Button::Falling) {
      32           5 :         if (incrState == Button::Pressed) {
      33             :             // One pressed, the other falling → reset
      34           0 :             longPressState = AfterReset;
      35           0 :             return Reset;
      36             :         } else {
      37             :             // Decrement falling, the other released → decrement
      38           5 :             return Decrement;
      39             :         }
      40           0 :     } else if (incrState == Button::Pressed && decrState == Button::Pressed) {
      41             :         // Both pressed → nothing
      42           0 :     } else if (longPressState != AfterReset && incrState == Button::Pressed) {
      43             :         // Not reset and increment pressed → long press?
      44           0 :         if (longPressState == LongPress) {
      45           0 :             if (millis() - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
      46           0 :                 longPressRepeat += LONG_PRESS_REPEAT_DELAY;
      47           0 :                 return Increment;
      48             :             }
      49           0 :         } else if (incrementButton.stableTime() >= LONG_PRESS_DELAY) {
      50           0 :             longPressState = LongPress;
      51           0 :             longPressRepeat = millis();
      52           0 :             return Increment;
      53             :         }
      54           0 :     } else if (longPressState != AfterReset && decrState == Button::Pressed) {
      55             :         // Not reset and decrement pressed → long press?
      56           0 :         if (longPressState == LongPress) {
      57           0 :             if (millis() - longPressRepeat >= LONG_PRESS_REPEAT_DELAY) {
      58           0 :                 longPressRepeat += LONG_PRESS_REPEAT_DELAY;
      59           0 :                 return Decrement;
      60             :             }
      61           0 :         } else if (decrementButton.stableTime() >= LONG_PRESS_DELAY) {
      62           0 :             longPressState = LongPress;
      63           0 :             longPressRepeat = millis();
      64           0 :             return Decrement;
      65             :         }
      66           0 :     }
      67           8 :     return Nothing;
      68          19 : }
      69             : 
      70             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6