RSeries astromech firmware
CommandScreenHandlerSMQ.h
Go to the documentation of this file.
1 #ifndef CommandScreenHandlerSMQ_h
2 #define CommandScreenHandlerSMQ_h
3 
4 #include "ReelTwo.h"
5 
7 {
8 public:
10  {
11  resetDisplay();
12  }
13 
14  inline void invertDisplay(bool invert)
15  {
16  fInvert = invert;
17  }
18 
19  inline void clearDisplay()
20  {
21  fClearDisplay = true;
22  }
23 
24  inline void setTextSize(int siz)
25  {
26  fTextSize = siz;
27  }
28 
29  void drawTextCentered(String text)
30  {
31  fCentered = true;
32  fString = text;
33  }
34 
35  void setCursor(uint8_t x, uint8_t y)
36  {
37  fX = x;
38  fY = y;
39  }
40 
41  void print(String text)
42  {
43  fString += text;
44  }
45 
46  void println(unsigned val)
47  {
48  fString += String("\n") + String(val);
49  }
50 
51  void println(String text)
52  {
53  fString += String("\n") + text;
54  }
55 
56  void display()
57  {
58  if (SMQ::sendTopic("LCD", "Remote"))
59  {
60  SMQ::send_uint8("x", fX);
61  SMQ::send_uint8("y", fY);
62  SMQ::send_boolean("invert", fInvert);
63  SMQ::send_boolean("centered", fCentered);
64  SMQ::send_uint8("size", fTextSize);
65  SMQ::send_string("text", fString.c_str());
66  SMQ::sendEnd();
67  resetDisplay();
68  }
69  else
70  {
71  printf("Failed to send LCD\n");
72  }
73  }
74 
75  void remoteDialEvent(long newValue, long oldValue)
76  {
77  fNewDialValue = newValue;
78  }
79 
80  void remoteButtonEvent(uint8_t id, bool pressed, bool repeat)
81  {
82  fButtonID = id;
83  fButtonPressed = pressed;
84  fButtonRepeat = repeat;
85  }
86 
87  void remoteActive()
88  {
89  setEnabled(true);
90  fRemoteActive = true;
91  }
92 
93  virtual void sleepDevice() override
94  {
95  }
96 
97  virtual bool handleEvent()
98  {
99  bool ret = false;
100  if (fRemoteActive)
101  {
102  restoreScreen();
103  switchToScreen(kMainScreen);
104  fRemoteActive = false;
105  }
106  CommandScreen* currentScr = current();
107  if (currentScr != nullptr)
108  {
109  if (fDialValue != fNewDialValue || fButtonID != 0)
110  {
111  // Reset the screen blanking timer if the encoder changed
112  // or if any of the buttons are currently pressed
113  ret = true;
114  }
115  if (fDialValue != fNewDialValue)
116  {
117  currentScr->buttonDial(fNewDialValue, fDialValue);
118  fDialValue = fNewDialValue;
119  }
120  if (fButtonID)
121  {
122  if (fButtonID == 1 && fButtonPressed)
123  currentScr->buttonUpPressed();
124  if (fButtonID == 2 && fButtonPressed)
125  currentScr->buttonLeftPressed();
126  if (fButtonID == 3 && fButtonPressed)
127  currentScr->buttonDownPressed();
128  if (fButtonID == 4 && fButtonPressed)
129  currentScr->buttonRightPressed();
130  if (fButtonID == 5 && fButtonPressed)
131  currentScr->buttonInPressed();
132  if (fLastScreenID == currentScr->ID())
133  {
134  if (fButtonID == 1 && !fButtonPressed)
135  currentScr->buttonUpReleased();
136  if (fButtonID == 2 && !fButtonPressed)
137  currentScr->buttonLeftReleased();
138  if (fButtonID == 3 && !fButtonPressed)
139  currentScr->buttonDownReleased();
140  if (fButtonID == 4 && !fButtonPressed)
141  currentScr->buttonRightReleased();
142  if (fButtonID == 5 && !fButtonPressed)
143  currentScr->buttonInReleased();
144  }
145  fLastScreenID = currentScr->ID();
146  }
147  else if (fLastScreenID == currentScr->ID())
148  {
149  if (fButtonID == 1 && fButtonPressed && fButtonRepeat)
150  {
151  currentScr->buttonUpPressed(true);
152  }
153  else if (fButtonID == 2 && fButtonPressed && fButtonRepeat)
154  {
155  currentScr->buttonLeftPressed(true);
156  }
157  else if (fButtonID == 3 && fButtonPressed && fButtonRepeat)
158  {
159  currentScr->buttonDownPressed(true);
160  }
161  else if (fButtonID == 4 && fButtonPressed && fButtonRepeat)
162  {
163  currentScr->buttonRightPressed(true);
164  }
165  else if (fButtonID == 5 && fButtonPressed && fButtonRepeat)
166  {
167  currentScr->buttonInPressed(true);
168  }
169  }
170  }
171  fButtonID = 0;
172  fButtonPressed = false;
173  fButtonRepeat = false;
174  fDialValue = fNewDialValue;
175  return ret;
176  }
177 
178 private:
179  long fDialValue = 0;
180  long fNewDialValue = 0;
181  uint8_t fButtonID = 0;
182  bool fRemoteActive = false;
183  bool fButtonPressed = false;
184  bool fButtonRepeat = false;
185  ScreenID fLastScreenID = kInvalid;
186  bool fInvert;
187  bool fClearDisplay;
188  bool fCentered;
189  String fString;
190  uint8_t fX;
191  uint8_t fY;
192  uint8_t fTextSize;
193 
194  void resetDisplay()
195  {
196  fInvert = false;
197  fClearDisplay = false;
198  fTextSize = 0;
199  fCentered = false;
200  fString = "";
201  fX = 0;
202  fY = 0;
203  }
204 };
205 #endif
CommandScreenHandlerSMQ::print
void print(String text)
Definition: CommandScreenHandlerSMQ.h:41
CommandScreen
Definition: CommandScreen.h:273
CommandScreen::buttonLeftPressed
virtual void buttonLeftPressed(bool repeat=false)
Definition: CommandScreen.h:328
CommandScreenHandlerSMQ::println
void println(unsigned val)
Definition: CommandScreenHandlerSMQ.h:46
CommandScreenHandlerSMQ::remoteActive
void remoteActive()
Definition: CommandScreenHandlerSMQ.h:87
CommandScreenHandlerSMQ::CommandScreenHandlerSMQ
CommandScreenHandlerSMQ()
Definition: CommandScreenHandlerSMQ.h:9
CommandScreenHandler::switchToScreen
void switchToScreen(ScreenID id, bool popStack=true)
Definition: CommandScreen.h:175
CommandScreenHandlerSMQ::setTextSize
void setTextSize(int siz)
Definition: CommandScreenHandlerSMQ.h:24
ReelTwo.h
CommandScreenHandler::current
CommandScreen * current()
Definition: CommandScreen.h:154
CommandScreenHandlerSMQ::remoteButtonEvent
void remoteButtonEvent(uint8_t id, bool pressed, bool repeat)
Definition: CommandScreenHandlerSMQ.h:80
CommandScreenHandlerSMQ::remoteDialEvent
void remoteDialEvent(long newValue, long oldValue)
Definition: CommandScreenHandlerSMQ.h:75
CommandScreenHandlerSMQ::invertDisplay
void invertDisplay(bool invert)
Definition: CommandScreenHandlerSMQ.h:14
CommandScreen::buttonInReleased
virtual void buttonInReleased()
Definition: CommandScreen.h:336
SMQ::sendTopic
static bool sendTopic(const smq_id id)
Definition: ReelTwoSMQ.h:155
CommandScreenHandler::restoreScreen
void restoreScreen()
Definition: CommandScreen.h:417
CommandScreenHandler
Definition: CommandScreen.h:147
CommandScreenHandlerSMQ
Definition: CommandScreenHandlerSMQ.h:6
CommandScreenHandler::setEnabled
void setEnabled(bool enabled)
Definition: CommandScreen.h:236
CommandScreenHandlerSMQ::drawTextCentered
void drawTextCentered(String text)
Definition: CommandScreenHandlerSMQ.h:29
CommandScreenHandlerSMQ::setCursor
void setCursor(uint8_t x, uint8_t y)
Definition: CommandScreenHandlerSMQ.h:35
CommandScreenHandlerSMQ::println
void println(String text)
Definition: CommandScreenHandlerSMQ.h:51
CommandScreen::buttonRightPressed
virtual void buttonRightPressed(bool repeat=false)
Definition: CommandScreen.h:330
CommandScreen::buttonLeftReleased
virtual void buttonLeftReleased()
Definition: CommandScreen.h:333
CommandScreen::ID
ScreenID ID() const
Definition: CommandScreen.h:286
CommandScreenHandlerSMQ::clearDisplay
void clearDisplay()
Definition: CommandScreenHandlerSMQ.h:19
CommandScreenHandlerSMQ::handleEvent
virtual bool handleEvent()
Definition: CommandScreenHandlerSMQ.h:97
CommandScreenHandlerSMQ::display
void display()
Definition: CommandScreenHandlerSMQ.h:56
CommandScreen::buttonDial
virtual void buttonDial(long newValue, long oldValue=0)
Definition: CommandScreen.h:337
CommandScreen::buttonUpPressed
virtual void buttonUpPressed(bool repeat=false)
Definition: CommandScreen.h:327
SMQ::send_uint8
static void send_uint8(const msg_id id, uint8_t val)
Definition: ReelTwoSMQ.h:292
CommandScreenHandlerSMQ::sleepDevice
virtual void sleepDevice() override
Definition: CommandScreenHandlerSMQ.h:93
CommandScreen::buttonDownReleased
virtual void buttonDownReleased()
Definition: CommandScreen.h:334
SMQ::send_boolean
static void send_boolean(const msg_id id, bool val)
Definition: ReelTwoSMQ.h:412
CommandScreen::buttonUpReleased
virtual void buttonUpReleased()
Definition: CommandScreen.h:332
CommandScreen::buttonRightReleased
virtual void buttonRightReleased()
Definition: CommandScreen.h:335
CommandScreen::buttonInPressed
virtual void buttonInPressed(bool repeat=false)
Definition: CommandScreen.h:331
CommandScreen::buttonDownPressed
virtual void buttonDownPressed(bool repeat=false)
Definition: CommandScreen.h:329
SMQ::send_string
static void send_string(const char *str)
Definition: ReelTwoSMQ.h:106
SMQ::sendEnd
static void sendEnd()
Definition: ReelTwoSMQ32.h:1103