LiquidMenu.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 Copyright (c) 2016 Vasil Kalchev
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
35 #pragma once
36 
37 #include <LiquidCrystal.h>
38 
39 #include "LiquidMenu_config.h"
40 
41 #include "serial_debugging.h"
42 
43 #ifndef LiquidCrystal_h
44 #warning "LiquidCrystal library is required!"
45 #endif
46 
47 const char VERSION[] = "1.0";
48 const uint8_t MAX_VARIABLES = 4;
49 
51 
54 enum class DataType : uint8_t {
55  NOT_USED = 0,
56  BOOL = 1, BOOLEAN = 1,
57  INT8_T = 8,
58  UINT8_T = 9, BYTE = 9,
59  INT16_T = 16,
60  UINT16_T = 17,
61  INT32_T = 32,
62  UINT32_T = 33,
63  FLOAT = 50, DOUBLE = 50,
64  CHAR = 60,
65  CHAR_PTR = 61,
66  CONST_CHAR_PTR = 62,
67 };
68 
70 /*
71 Used to store and set the relative or absolute position of the focus indicator.
72 */
73 enum class Position : uint8_t {
74  RIGHT = 1, NORMAL = 1,
75  LEFT = 2,
76  CUSTOM = 3,
77 };
78 
80 
84 
90 DataType recognizeType(bool variable);
91 
96 DataType recognizeType(char variable);
97 
102 DataType recognizeType(char* variable);
103 
108 DataType recognizeType(const char* variable);
109 
114 DataType recognizeType(int8_t variable);
115 
120 DataType recognizeType(uint8_t variable);
121 
126 DataType recognizeType(int16_t variable);
127 
132 DataType recognizeType(uint16_t variable);
133 
138 DataType recognizeType(int32_t variable);
139 
144 DataType recognizeType(uint32_t variable);
145 
150 DataType recognizeType(float variable);
151 
153 
154 
156 
161 void print_me(uint16_t address);
162 
163 
165 
172 class LiquidLine {
173  friend class LiquidScreen;
174 
175 public:
178 
180 
187  template <typename A>
188  LiquidLine(uint8_t column, uint8_t row, A &variableA)
189  : _row(row), _column(column), _focusRow(row - 1),
190  _focusColumn(column - 1), _focusPosition(Position::NORMAL),
191  _focusable(false) {
192  for (uint8_t i = 0; i < MAX_VARIABLES; i++) {
193  _variable[i] = nullptr;
194  _variableType[i] = DataType::NOT_USED;
195  }
196  for (uint8_t f = 0; f < MAX_FUNCTIONS; f++) {
197  _function[f] = 0;
198  }
199  _variable[0] = (void*)&variableA;
200  _variableType[0] = recognizeType(variableA);
201  }
202 
204 
210  template <typename A, typename B>
211  LiquidLine(uint8_t column, uint8_t row,
212  A &variableA, B &variableB)
213  : LiquidLine(column, row, variableA) {
214  _variable[1] = (void*)&variableB;
215  _variableType[1] = recognizeType(variableB);
216  }
217 
219 
226  template <typename A, typename B, typename C>
227  LiquidLine(uint8_t column, uint8_t row,
228  A &variableA, B &variableB, C &variableC)
229  : LiquidLine(column, row, variableA, variableB) {
230  _variable[2] = (void*)&variableC;
231  _variableType[2] = recognizeType(variableC);
232  }
233 
235 
243  template <typename A, typename B, typename C, typename D>
244  LiquidLine(uint8_t column, uint8_t row,
245  A &variableA, B &variableB, C &variableC, D &variableD)
246  : LiquidLine(column, row, variableA, variableB, variableC) {
247  _variable[3] = (void*)&variableD;
248  _variableType[3] = recognizeType(variableD);
249  }
250 
252 
253 
256 
258 
276  bool attach_function(uint8_t number, void (*function)(void));
277 
279 
295  bool set_focusPosition(Position position,
296  uint8_t column = 0, uint8_t row = 0);
297 
299 
300 private:
302 
310  void print(LiquidCrystal *p_liquidCrystal, bool isFocused);
311 
313 
320  void print_variable(LiquidCrystal *p_liquidCrystal, uint8_t number);
321 
323 
331  bool call_function(uint8_t number) const;
332 
333  uint8_t _row, _column, _focusRow, _focusColumn;
334  Position _focusPosition;
335  void (*_function[MAX_FUNCTIONS])(void);
336  const void *_variable[MAX_VARIABLES];
337  DataType _variableType[MAX_VARIABLES];
338  bool _focusable;
339 };
340 
341 
343 
352  friend class LiquidMenu;
353 
354 public:
355 
358 
360 
363  LiquidScreen();
364 
366 
369  LiquidScreen(LiquidLine &liquidLine);
370 
372 
376  LiquidScreen(LiquidLine &liquidLine1, LiquidLine &liquidLine2);
377 
379 
384  LiquidScreen(LiquidLine &liquidLine1, LiquidLine &liquidLine2,
385  LiquidLine &liquidLine3);
386 
388 
394  LiquidScreen(LiquidLine &liquidLine1, LiquidLine &liquidLine2,
395  LiquidLine &liquidLine3, LiquidLine &liquidLine4);
396 
398 
401 
403 
414  bool add_line(LiquidLine &liquidLine);
415 
417 
431  bool set_focusPosition(Position position);
432 
434 
435 private:
437 
443  void print(LiquidCrystal *p_liquidCrystal) const;
444 
446 
452  void switch_focus(bool forward = true);
453 
454 
455 
457 
467  bool call_function(uint8_t number) const;
468 
469  LiquidLine *_p_liquidLine[MAX_LINES];
470  uint8_t _lineCount;
471  uint8_t _focus;
472 };
473 
474 
476 
485 class LiquidMenu {
486  friend class LiquidSystem;
487 
488 public:
489 
492 
494 
501  LiquidMenu(LiquidCrystal &liquidCrystal, uint8_t startingScreen = 1);
502 
504 
510  LiquidMenu(LiquidCrystal &liquidCrystal, LiquidScreen &liquidScreen,
511  uint8_t startingScreen = 1);
512 
514 
521  LiquidMenu(LiquidCrystal &liquidCrystal, LiquidScreen &liquidScreen1,
522  LiquidScreen &liquidScreen2, uint8_t startingScreen = 1);
523 
525 
533  LiquidMenu(LiquidCrystal &liquidCrystal, LiquidScreen &liquidScreen1,
534  LiquidScreen &liquidScreen2, LiquidScreen &liquidScreen3,
535  uint8_t startingScreen = 1);
536 
538 
547  LiquidMenu(LiquidCrystal &liquidCrystal, LiquidScreen &liquidScreen1,
548  LiquidScreen &liquidScreen2, LiquidScreen &liquidScreen3,
549  LiquidScreen &liquidScreen4, uint8_t startingScreen = 1);
550 
552 
555 
557 
568  bool add_screen(LiquidScreen &liquidScreen);
569 
571  void next_screen();
572 
574 
577  void operator++();
578 
580 
583  void operator++(int);
584 
586  void previous_screen();
587 
589 
592  void operator--();
593 
595 
598  void operator--(int);
599 
601 
605  bool change_screen(LiquidScreen &p_liquidScreen);
606 
608 
613  bool change_screen(uint8_t number);
614 
616 
620  bool operator=(LiquidScreen &p_liquidScreen);
621 
623 
628  bool operator=(uint8_t number);
629 
631 
637  void switch_focus(bool forward = true);
638 
640 
654  bool set_focusPosition(Position position);
655 
657 
670  bool set_focusSymbol(Position position, uint8_t symbol[8]);
671 
673 
684  bool call_function(uint8_t number) const;
685 
687 
690  void update() const;
691 
693 
694 private:
695  LiquidCrystal *_p_liquidCrystal;
696  LiquidScreen *_p_liquidScreen[MAX_SCREENS];
697  uint8_t _screenCount;
698  uint8_t _currentScreen;
699 };
700 
701 
703 
714 public:
715 
718 
720 
725  LiquidSystem(uint8_t startingMenu = 1);
726 
728 
733  LiquidSystem(LiquidMenu &liquidMenu1, LiquidMenu &liquidMenu2,
734  uint8_t startingMenu = 1);
735 
737 
743  LiquidSystem(LiquidMenu &liquidMenu1, LiquidMenu &liquidMenu2,
744  LiquidMenu &liquidMenu3, uint8_t startingMenu = 1);
745 
747 
754  LiquidSystem(LiquidMenu &liquidMenu1, LiquidMenu &liquidMenu2,
755  LiquidMenu &liquidMenu3, LiquidMenu &liquidMenu4,
756  uint8_t startingMenu = 1);
757 
759 
762 
764 
775  bool add_menu(LiquidMenu &liquidMenu);
776 
778 
782  bool change_menu(LiquidMenu &p_liquidMenu);
783 
785  void next_screen();
786 
788 
791  void operator++();
792 
794 
797  void operator++(int);
798 
800  void previous_screen();
801 
803 
806  void operator--();
807 
809 
812  void operator--(int);
813 
815 
819  bool change_screen(LiquidScreen &p_liquidScreen);
820 
822 
827  bool change_screen(uint8_t number);
828 
830 
834  bool operator=(LiquidScreen &p_liquidScreen);
835 
837 
842  bool operator=(uint8_t number);
843 
845 
851  void switch_focus(bool forward = true);
852 
854 
868  bool set_focusPosition(Position position);
869 
871 
884  bool set_focusSymbol(Position position, uint8_t symbol[8]);
885 
887 
898  bool call_function(uint8_t number) const;
899 
901 
904  void update() const;
905 
907 
908 private:
909  LiquidMenu *_p_liquidMenu[MAX_MENUS];
910  uint8_t _menuCount;
911  uint8_t _currentMenu;
912 };
LiquidLine(uint8_t column, uint8_t row, A &variableA, B &variableB, C &variableC)
Constructor for three variables/constants.
Definition: LiquidMenu.h:227
void operator--()
Switches to the previous screen.
Definition: LiquidSystem.cpp:97
void switch_focus(bool forward=true)
Switches the focus.
Definition: LiquidMenu.cpp:155
bool operator=(LiquidScreen &p_liquidScreen)
Switches to the specified screen.
Definition: LiquidSystem.cpp:117
Represents a collection of menus forming a menu system.
Definition: LiquidMenu.h:713
const char VERSION[]
The version of the library.
Definition: LiquidMenu.h:47
Definition: symbols.h:3
Represents the individual lines printed on the display.
Definition: LiquidMenu.h:172
void switch_focus(bool forward=true)
Switches the focus.
Definition: LiquidSystem.cpp:121
const uint8_t MAX_SCREENS
Configures the number of available screens per menu.
Definition: LiquidMenu_config.h:18
void previous_screen()
Switches to the previous screen.
Definition: LiquidSystem.cpp:93
bool set_focusPosition(Position position)
Sets the focus position for the whole menu at once.
Definition: LiquidMenu.cpp:161
bool set_focusPosition(Position position)
Sets the focus position for the whole menu at once.
Definition: LiquidSystem.cpp:125
LiquidLine(uint8_t column, uint8_t row, A &variableA, B &variableB)
Constructor for two variables/constants.
Definition: LiquidMenu.h:211
Represents a screen shown on the display.
Definition: LiquidMenu.h:351
bool set_focusSymbol(Position position, uint8_t symbol[8])
Changes the focus indicator&#39;s symbol.
Definition: LiquidSystem.cpp:129
const uint8_t MAX_LINES
Configures the number of available lines per screen.
Definition: LiquidMenu_config.h:15
bool change_screen(LiquidScreen &p_liquidScreen)
Switches to the specified screen.
Definition: LiquidSystem.cpp:109
const uint8_t MAX_VARIABLES
Sets the size of the void* array.
Definition: LiquidMenu.h:48
Represents a collection of screens forming a menu.
Definition: LiquidMenu.h:485
LiquidLine(uint8_t column, uint8_t row, A &variableA, B &variableB, C &variableC, D &variableD)
Constructor for four variables/constants.
Definition: LiquidMenu.h:244
Position
Position enum.
Definition: LiquidMenu.h:73
bool call_function(uint8_t number) const
Calls an attached function specified by the number.
Definition: LiquidMenu.cpp:205
DataType recognizeType(bool variable)
Definition: recognizeType.cpp:3
void update() const
Prints the current screen to the display.
Definition: LiquidSystem.cpp:140
void next_screen()
Switches to the next screen.
Definition: LiquidSystem.cpp:81
DataType
Data type enum.
Definition: LiquidMenu.h:54
const uint8_t MAX_MENUS
Configures the number of available manus per menus system.
Definition: LiquidMenu_config.h:21
const uint8_t MAX_FUNCTIONS
Configures the number of available functions per line.
Definition: LiquidMenu_config.h:12
LiquidLine(uint8_t column, uint8_t row, A &variableA)
Constructor for one variable/constant.
Definition: LiquidMenu.h:188
void print_me(uint16_t address)
Prints the number passed to it in a specific way.
Definition: LiquidLine.cpp:29
bool call_function(uint8_t number) const
Calls an attached function specified by the number.
Definition: LiquidSystem.cpp:133
void operator++()
Switches to the next screen.
Definition: LiquidSystem.cpp:85
bool set_focusPosition(Position position)
Sets the focus position for the whole screen at once.
Definition: LiquidScreen.cpp:66