| 19 | ButtonLowLevel::~ButtonLowLevel() FL_NOEXCEPT {} |
| 20 | |
| 21 | bool ButtonLowLevel::highLowFloating() { |
| 22 | // High-low floating detection: Set pin to high, check if high, |
| 23 | // set pin to low, check if low. If both conditions are true, |
| 24 | // the pin is floating and therefore the button is not pressed. |
| 25 | mPin.setPinMode(DigitalPin::kOutput); |
| 26 | mPin.write(true); // set pin to high |
| 27 | mPin.setPinMode(DigitalPin::kInput); |
| 28 | const bool was_high = mPin.high(); // check if pin is high |
| 29 | mPin.setPinMode(DigitalPin::kOutput); |
| 30 | mPin.write(false); // set pin to low |
| 31 | mPin.setPinMode(DigitalPin::kInput); |
| 32 | const bool was_low = !mPin.high(); // check if pin is low |
| 33 | const bool floating = |
| 34 | was_high && was_low; // if both are true, then the pin is floating |
| 35 | const bool pressed = |
| 36 | !floating; // if the pin is floating, then the button is not pressed |
| 37 | return pressed; |
| 38 | } |
| 39 | |
| 40 | bool ButtonLowLevel::isPressed() { |
| 41 | switch (mStrategy) { |
nothing calls this directly
no test coverage detected