My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

menus.h 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Menu functions for ProUI
  24. * Author: Miguel A. Risco-Castillo
  25. * Version: 1.4.1
  26. * Date: 2022/04/14
  27. *
  28. * This program is free software: you can redistribute it and/or modify
  29. * it under the terms of the GNU Lesser General Public License as
  30. * published by the Free Software Foundation, either version 3 of the License, or
  31. * (at your option) any later version.
  32. *
  33. * This program is distributed in the hope that it will be useful,
  34. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. * GNU General Public License for more details.
  37. *
  38. * You should have received a copy of the GNU Lesser General Public License
  39. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  40. *
  41. */
  42. #pragma once
  43. #include "dwinui.h"
  44. typedef struct {
  45. int32_t MaxValue = 0; // Auxiliar max integer/scaled float value
  46. int32_t MinValue = 0; // Auxiliar min integer/scaled float value
  47. int8_t dp = 0; // Auxiliar decimal places
  48. int32_t Value = 0; // Auxiliar integer / scaled float value
  49. int16_t *P_Int = nullptr; // Auxiliar pointer to 16 bit integer variable
  50. float *P_Float = nullptr; // Auxiliar pointer to float variable
  51. void (*Apply)() = nullptr; // Auxiliar apply function
  52. void (*LiveUpdate)() = nullptr; // Auxiliar live update function
  53. } MenuData_t;
  54. extern MenuData_t MenuData;
  55. extern void (*onCursorErase)(const int8_t line);
  56. extern void (*onCursorDraw)(const int8_t line);
  57. // Auxiliary Macros ===========================================================
  58. // Create and add a MenuItem object to the menu array
  59. #define BACK_ITEM(H) MenuItemsAdd(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawMenuItem, H)
  60. #define MENU_ITEM(V...) MenuItemsAdd(V)
  61. #define EDIT_ITEM(V...) MenuItemsAdd(V)
  62. #define MENU_ITEM_F(I,L,V...) MenuItemsAdd(I, GET_TEXT_F(L), V)
  63. #define EDIT_ITEM_F(I,L,V...) MenuItemsAdd(I, GET_TEXT_F(L), V)
  64. // Menu Classes ===============================================================
  65. class MenuItemClass {
  66. protected:
  67. public:
  68. int8_t pos = 0;
  69. uint8_t icon = 0;
  70. char caption[32] = "";
  71. uint8_t frameid = 0;
  72. rect_t frame = {0};
  73. void (*onDraw)(MenuItemClass* menuitem, int8_t line) = nullptr;
  74. void (*onClick)() = nullptr;
  75. MenuItemClass() {};
  76. MenuItemClass(uint8_t cicon, const char * const text=nullptr, void (*ondraw)(MenuItemClass* menuitem, int8_t line)=nullptr, void (*onclick)()=nullptr);
  77. // MenuItemClass(uint8_t cicon, FSTR_P text = nullptr, void (*ondraw)(MenuItemClass* menuitem, int8_t line)=nullptr, void (*onclick)()=nullptr) : MenuItemClass(cicon, FTOP(text), ondraw, onclick){}
  78. MenuItemClass(uint8_t cicon, uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, void (*ondraw)(MenuItemClass* menuitem, int8_t line)=nullptr, void (*onclick)()=nullptr);
  79. void SetFrame(uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
  80. virtual ~MenuItemClass(){};
  81. virtual void draw(int8_t line);
  82. void redraw();
  83. };
  84. class MenuItemPtrClass: public MenuItemClass {
  85. public:
  86. void *value = nullptr;
  87. using MenuItemClass::MenuItemClass;
  88. MenuItemPtrClass(uint8_t cicon, const char * const text, void (*ondraw)(MenuItemClass* menuitem, int8_t line), void (*onclick)(), void* val);
  89. MenuItemPtrClass(uint8_t cicon, FSTR_P text, void (*ondraw)(MenuItemClass* menuitem, int8_t line), void (*onclick)(), void* val) : MenuItemPtrClass(cicon, FTOP(text), ondraw, onclick, val){}
  90. };
  91. class MenuClass {
  92. public:
  93. int8_t topline = 0;
  94. int8_t selected = 0;
  95. TitleClass MenuTitle;
  96. MenuClass();
  97. virtual ~MenuClass(){};
  98. inline int8_t line() { return selected - topline; };
  99. inline int8_t line(uint8_t pos) {return pos - topline; };
  100. int8_t count();
  101. virtual void draw();
  102. virtual void onScroll(bool dir);
  103. void onClick();
  104. MenuItemClass* SelectedItem();
  105. static MenuItemClass** Items();
  106. };
  107. extern MenuClass *CurrentMenu;
  108. extern MenuClass *PreviousMenu;
  109. extern void (*onMenuDraw)(MenuClass* menu);
  110. // Menuitem Drawing functions =================================================
  111. void Draw_Title(TitleClass* title);
  112. void Draw_Menu(MenuClass* menu);
  113. void Draw_Menu_Cursor(const int8_t line);
  114. void Erase_Menu_Cursor(const int8_t line);
  115. void Draw_Menu_Line(const uint8_t line, const uint8_t icon=0, const char * const label=nullptr, bool more=false);
  116. void Draw_Chkb_Line(const uint8_t line, const bool checked);
  117. void Draw_Menu_IntValue(uint16_t bcolor, const uint8_t line, uint8_t iNum, const int32_t value=0);
  118. void onDrawMenuItem(MenuItemClass* menuitem, int8_t line);
  119. void onDrawSubMenu(MenuItemClass* menuitem, int8_t line);
  120. void onDrawIntMenu(MenuItemClass* menuitem, int8_t line, int32_t value);
  121. void onDrawPIntMenu(MenuItemClass* menuitem, int8_t line);
  122. void onDrawPInt8Menu(MenuItemClass* menuitem, int8_t line);
  123. void onDrawPInt32Menu(MenuItemClass* menuitem, int8_t line);
  124. void onDrawFloatMenu(MenuItemClass* menuitem, int8_t line, uint8_t dp, const float value);
  125. void onDrawPFloatMenu(MenuItemClass* menuitem, int8_t line);
  126. void onDrawPFloat2Menu(MenuItemClass* menuitem, int8_t line);
  127. void onDrawPFloat3Menu(MenuItemClass* menuitem, int8_t line);
  128. void onDrawChkbMenu(MenuItemClass* menuitem, int8_t line, bool checked);
  129. void onDrawChkbMenu(MenuItemClass* menuitem, int8_t line);
  130. // On click functions =========================================================
  131. void SetOnClick(uint8_t process, const int32_t lo, const int32_t hi, uint8_t dp, const int32_t val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr);
  132. void SetValueOnClick(uint8_t process, const int32_t lo, const int32_t hi, const int32_t val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr);
  133. void SetValueOnClick(uint8_t process, const float lo, const float hi, uint8_t dp, const float val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr);
  134. void SetIntOnClick(const int32_t lo, const int32_t hi, const int32_t val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr);
  135. void SetPIntOnClick(const int32_t lo, const int32_t hi, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr);
  136. void SetFloatOnClick(const float lo, const float hi, uint8_t dp, const float val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr);
  137. void SetPFloatOnClick(const float lo, const float hi, uint8_t dp, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr);
  138. // HMI user control functions =================================================
  139. void HMI_Menu();
  140. void HMI_SetInt();
  141. void HMI_SetPInt();
  142. void HMI_SetIntNoDraw();
  143. void HMI_SetFloat();
  144. void HMI_SetPFloat();
  145. // Menu auxiliary functions ===================================================
  146. // Create a new menu
  147. bool SetMenu(MenuClass* &menu, FSTR_P title, int8_t totalitems);
  148. //Update the Menu and Draw if it is valid
  149. void UpdateMenu(MenuClass* &menu);
  150. //Redraw the current Menu if it is valid
  151. void ReDrawMenu();
  152. // Clear MenuItems array and free MenuItems elements
  153. void MenuItemsClear();
  154. // Prepare MenuItems array
  155. void MenuItemsPrepare(int8_t totalitems);
  156. // Add elements to the MenuItems array
  157. MenuItemClass* MenuItemsAdd(uint8_t cicon, const char * const text=nullptr, void (*ondraw)(MenuItemClass* menuitem, int8_t line)=nullptr, void (*onclick)()=nullptr);
  158. inline MenuItemClass* MenuItemsAdd(uint8_t cicon, FSTR_P text = nullptr, void (*ondraw)(MenuItemClass* menuitem, int8_t line)=nullptr, void (*onclick)()=nullptr) {
  159. return MenuItemsAdd(cicon, FTOP(text), ondraw, onclick);
  160. }
  161. MenuItemClass* MenuItemsAdd(uint8_t cicon, uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, void (*ondraw)(MenuItemClass* menuitem, int8_t line)=nullptr, void (*onclick)()=nullptr);
  162. MenuItemClass* MenuItemsAdd(uint8_t cicon, const char * const text, void (*ondraw)(MenuItemClass* menuitem, int8_t line), void (*onclick)(), void* val);
  163. inline MenuItemClass* MenuItemsAdd(uint8_t cicon, FSTR_P text, void (*ondraw)(MenuItemClass* menuitem, int8_t line), void (*onclick)(), void* val) {
  164. return MenuItemsAdd(cicon, FTOP(text), ondraw, onclick, val);
  165. }