Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
debouncer.h
Go to the documentation of this file.
1 #pragma once
3 #include <stdint.h>
4 
5 namespace modules {
6 
8 namespace debounce {
9 
12 class Debouncer {
13 public:
16  inline constexpr Debouncer(uint8_t debounceTimeout)
17  : timeLastChange(0)
18  , debounceTimeout(debounceTimeout) {}
19 
21  inline bool Pressed() const { return f.state == State::WaitForRelease; }
22 
24  void Step(uint16_t time, bool press);
25 
26 private:
31  enum State {
32  Waiting = 0,
33  Detected,
34  WaitForRelease,
35  Update
36  };
37 
39  struct Flags {
40  uint8_t state : 2;
41  uint8_t tmp : 1;
42  inline constexpr Flags()
43  : state(State::Waiting)
44  , tmp(false) {}
45  };
46 
48  Flags f;
49 
51  uint16_t timeLastChange;
52  uint8_t debounceTimeout;
53 };
54 
55 } // namespace debounce
56 } // namespace modules
57 
58 namespace md = modules::debounce;
Definition: debouncer.h:12
constexpr Debouncer(uint8_t debounceTimeout)
Definition: debouncer.h:16
bool Pressed() const
Definition: debouncer.h:21
void Step(uint16_t time, bool press)
State machine stepping routine.
Definition: debouncer.cpp:8
The debounce namespace provides a generic debouncing algorithm.
Definition: debouncer.cpp:5
The modules namespace contains models of MMU's components.
Definition: command_base.h:8