Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
buttons.h
Go to the documentation of this file.
1 #pragma once
3 
4 #include <stdint.h>
5 #include "debouncer.h"
6 #include "../config/config.h"
7 
9 namespace modules {
10 
12 namespace buttons {
13 
15 struct Button : public debounce::Debouncer {
16  inline constexpr Button()
18 
19 private:
20 };
21 
23 enum {
24  Right = 0,
25  Middle,
26  Left
27 };
28 
30 class Buttons {
31 public:
32  inline constexpr Buttons() = default;
33 
35  void Step();
36 
39  inline bool ButtonPressed(uint8_t index) const { return buttons[index].Pressed(); }
40 
42  inline bool AnyButtonPressed() const {
43  for (uint8_t i = 0; i < config::buttonCount; ++i) {
44  if (ButtonPressed(i))
45  return true;
46  }
47  return false;
48  }
49 
50 private:
51  Button buttons[config::buttonCount];
52 
55  static int8_t DecodeADC(uint16_t rawADC);
56 };
57 
59 extern Buttons buttons;
60 
61 } // namespace buttons
62 } // namespace modules
63 
64 namespace mb = modules::buttons;
A model of the 3 buttons on the MMU unit.
Definition: buttons.h:30
bool ButtonPressed(uint8_t index) const
Definition: buttons.h:39
void Step()
Performs one step of the state machine - reads the ADC, processes debouncing, updates states of indiv...
Definition: buttons.cpp:26
bool AnyButtonPressed() const
Definition: buttons.h:42
Definition: debouncer.h:12
bool Pressed() const
Definition: debouncer.h:21
static constexpr const uint16_t buttonsDebounceMs
tuned with a pack of highly trained monkeys :)
Definition: config.h:43
static constexpr const uint8_t buttonCount
number of buttons currently supported
Definition: config.h:42
The buttons namespace provides all necessary facilities related to the logical model of the physical ...
Definition: buttons.cpp:7
Buttons buttons
The one and only instance of Buttons in the FW.
Definition: buttons.cpp:9
The modules namespace contains models of MMU's components.
Definition: command_base.h:8
A model of a single button, performs automatic debouncing on top of the raw ADC API.
Definition: buttons.h:15