Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
user_input.h
Go to the documentation of this file.
1 #pragma once
3 #include <stdint.h>
4 #include "../hal/circular_buffer.h"
5 
6 namespace modules {
7 
9 namespace user_input {
10 
12 enum Event : uint8_t {
13  NoEvent = 0x7f,
14  Right = 0,
15  Middle = 1,
16  Left = 2,
17  FromPrinter = 0x80
18 };
19 
20 class UserInput {
21 
22 public:
23  UserInput() = default;
24 
26  void Step();
27 
29  void ProcessMessage(uint8_t ev);
30 
36 
40 
42  bool AnyEvent() const { return !eventQueue.empty(); }
43 
45  void Clear();
46 
50  inline void SetPrinterInCharge(bool pc) {
51  printerInCharge = pc;
52  }
53 
55  inline bool PrinterInCharge() const {
56  return printerInCharge;
57  }
58 
59 #ifndef UNITTEST
60 private:
61 #endif
63  bool printerInCharge = false;
64  uint8_t lastButtonStates = 0;
65 
66  constexpr bool LastButtonState(uint8_t button) const {
67  return (lastButtonStates & (1 << button)) != 0;
68  }
69  void FlipLastButtonState(uint8_t button) {
70  lastButtonStates ^= (1 << button);
71  }
72  void StepOneButton(uint8_t button);
73 
74  static Event StripFromPrinterBit(uint8_t e);
75 };
76 
77 extern UserInput userInput;
78 
79 } // namespace user_input
80 } // namespace modules
81 
82 namespace mui = modules::user_input;
Definition: user_input.h:20
bool AnyEvent() const
Definition: user_input.h:42
Event ConsumeEvent()
Definition: user_input.cpp:43
void Step()
collects the buttons' state and enqueues the corresponding event
Definition: user_input.cpp:26
Event ConsumeEventForPrinter()
Definition: user_input.cpp:60
void Clear()
Remove all buffered events from the event queue.
Definition: user_input.cpp:72
void SetPrinterInCharge(bool pc)
Definition: user_input.h:50
bool PrinterInCharge() const
Definition: user_input.h:55
void ProcessMessage(uint8_t ev)
enqueues a user event coming from a communication
Definition: user_input.cpp:34
User input module collects input from buttons and from communication for the logic layer.
Definition: user_input.cpp:6
Event
Beware - button codes intentionally match the protocol button encoding for optimization purposes.
Definition: user_input.h:12
The modules namespace contains models of MMU's components.
Definition: command_base.h:8