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.

menu_mixer.cpp 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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. // Mixer Menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if BOTH(HAS_MARLINUI_MENU, MIXING_EXTRUDER)
  27. #include "menu_item.h"
  28. #include "menu_addon.h"
  29. #include "../../feature/mixing.h"
  30. #if HAS_GRAPHICAL_TFT
  31. #include "../tft/tft.h"
  32. #endif
  33. #define CHANNEL_MIX_EDITING !HAS_DUAL_MIXING
  34. #if ENABLED(GRADIENT_MIX)
  35. void _lcd_mixer_gradient_z_edit(const bool isend) {
  36. ui.defer_status_screen();
  37. ENCODER_RATE_MULTIPLY(true);
  38. float &zvar = isend ? mixer.gradient.end_z : mixer.gradient.start_z;
  39. if (ui.encoderPosition) {
  40. zvar += float(int32_t(ui.encoderPosition)) * 0.1;
  41. ui.encoderPosition = 0;
  42. NOLESS(zvar, 0);
  43. NOMORE(zvar, Z_MAX_POS);
  44. }
  45. if (ui.should_draw()) {
  46. char tmp[16];
  47. SETCURSOR(1, (LCD_HEIGHT - 1) / 2);
  48. lcd_put_u8str(isend ? GET_TEXT_F(MSG_END_Z) : GET_TEXT_F(MSG_START_Z));
  49. sprintf_P(tmp, PSTR("%4d.%d mm"), int(zvar), int(zvar * 10) % 10);
  50. SETCURSOR_RJ(9, (LCD_HEIGHT - 1) / 2);
  51. lcd_put_u8str(tmp);
  52. }
  53. if (ui.lcd_clicked) {
  54. if (isend && zvar < mixer.gradient.start_z)
  55. mixer.gradient.start_z = zvar;
  56. else if (!isend && zvar > mixer.gradient.end_z)
  57. mixer.gradient.end_z = zvar;
  58. mixer.refresh_gradient();
  59. ui.goto_previous_screen();
  60. }
  61. else {
  62. TERN_(HAS_GRAPHICAL_TFT, tft.draw_edit_screen_buttons());
  63. }
  64. }
  65. void lcd_mixer_edit_gradient_menu() {
  66. START_MENU();
  67. BACK_ITEM(MSG_MIXER);
  68. EDIT_ITEM(int8, MSG_START_VTOOL, &mixer.gradient.start_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  69. EDIT_ITEM(int8, MSG_END_VTOOL, &mixer.gradient.end_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  70. #if ENABLED(GRADIENT_VTOOL)
  71. EDIT_ITEM(int8, MSG_GRADIENT_ALIAS, &mixer.gradient.vtool_index, -1, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  72. #endif
  73. char tmp[18];
  74. FSTR_P const slabel = GET_TEXT_F(MSG_START_Z);
  75. SUBMENU_F(slabel, []{ _lcd_mixer_gradient_z_edit(false); });
  76. MENU_ITEM_ADDON_START_RJ(11);
  77. sprintf_P(tmp, PSTR("%4d.%d mm"), int(mixer.gradient.start_z), int(mixer.gradient.start_z * 10) % 10);
  78. lcd_put_u8str(tmp);
  79. MENU_ITEM_ADDON_END();
  80. FSTR_P const elabel = GET_TEXT_F(MSG_END_Z);
  81. SUBMENU_F(elabel, []{ _lcd_mixer_gradient_z_edit(true); });
  82. MENU_ITEM_ADDON_START_RJ(11);
  83. sprintf_P(tmp, PSTR("%4d.%d mm"), int(mixer.gradient.end_z), int(mixer.gradient.end_z * 10) % 10);
  84. lcd_put_u8str(tmp);
  85. MENU_ITEM_ADDON_END();
  86. END_MENU();
  87. }
  88. #endif // GRADIENT_MIX
  89. static uint8_t v_index;
  90. #if HAS_DUAL_MIXING
  91. void _lcd_draw_mix(const uint8_t y) {
  92. char tmp[20]; // "100%_100%"
  93. sprintf_P(tmp, PSTR("%3d%% %3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
  94. SETCURSOR(2, y); lcd_put_u8str(GET_TEXT_F(MSG_MIX));
  95. SETCURSOR_RJ(10, y); lcd_put_u8str(tmp);
  96. }
  97. #endif
  98. void _lcd_mixer_select_vtool() {
  99. mixer.T(v_index);
  100. TERN_(HAS_DUAL_MIXING, _lcd_draw_mix(LCD_HEIGHT - 1));
  101. }
  102. #if CHANNEL_MIX_EDITING
  103. void _lcd_mixer_cycle_mix() {
  104. uint16_t bits = 0;
  105. MIXER_STEPPER_LOOP(i) if (mixer.collector[i]) SBI(bits, i);
  106. bits = (bits + 1) & (_BV(MIXING_STEPPERS) - 1);
  107. if (!bits) ++bits;
  108. MIXER_STEPPER_LOOP(i) mixer.collector[i] = TEST(bits, i) ? 10.0f : 0.0f;
  109. ui.refresh();
  110. }
  111. void _lcd_mixer_commit_vtool() {
  112. mixer.normalize();
  113. ui.goto_previous_screen();
  114. }
  115. #endif
  116. void lcd_mixer_mix_edit() {
  117. #if HAS_DUAL_MIXING && !CHANNEL_MIX_EDITING
  118. // Adjust 2-channel mix from the encoder
  119. if (ui.encoderPosition) {
  120. mixer.mix[0] += int32_t(ui.encoderPosition);
  121. ui.encoderPosition = 0;
  122. if (mixer.mix[0] < 0) mixer.mix[0] += 101;
  123. if (mixer.mix[0] > 100) mixer.mix[0] -= 101;
  124. mixer.mix[1] = 100 - mixer.mix[0];
  125. }
  126. _lcd_draw_mix((LCD_HEIGHT - 1) / 2);
  127. // Click to commit the change
  128. if (ui.lcd_clicked) {
  129. mixer.update_vtool_from_mix();
  130. ui.goto_previous_screen();
  131. }
  132. TERN_(HAS_GRAPHICAL_TFT, tft.draw_edit_screen_buttons());
  133. #else
  134. START_MENU();
  135. BACK_ITEM(MSG_MIXER);
  136. #if CHANNEL_MIX_EDITING
  137. LOOP_S_LE_N(n, 1, MIXING_STEPPERS)
  138. EDIT_ITEM_FAST_N(float42_52, n, MSG_MIX_COMPONENT_N, &mixer.collector[n-1], 0, 10);
  139. ACTION_ITEM(MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);
  140. ACTION_ITEM(MSG_COMMIT_VTOOL, _lcd_mixer_commit_vtool);
  141. #endif
  142. END_MENU();
  143. #endif
  144. }
  145. #if HAS_DUAL_MIXING
  146. //
  147. // Toggle Dual-Mix
  148. //
  149. inline void _lcd_mixer_toggle_mix() {
  150. mixer.mix[0] = mixer.mix[0] == 100 ? 0 : 100;
  151. mixer.mix[1] = 100 - mixer.mix[0];
  152. mixer.update_vtool_from_mix();
  153. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  154. }
  155. #endif
  156. #if CHANNEL_MIX_EDITING
  157. //
  158. // Prepare and Edit Mix
  159. //
  160. inline void _lcd_goto_mix_edit() {
  161. mixer.refresh_collector(10, v_index);
  162. ui.goto_screen(lcd_mixer_mix_edit);
  163. lcd_mixer_mix_edit();
  164. }
  165. #endif
  166. #if ENABLED(GRADIENT_MIX)
  167. //
  168. // Reverse Gradient
  169. //
  170. inline void _lcd_mixer_reverse_gradient() {
  171. const uint8_t sv = mixer.gradient.start_vtool;
  172. mixer.gradient.start_vtool = mixer.gradient.end_vtool;
  173. mixer.gradient.end_vtool = sv;
  174. mixer.refresh_gradient();
  175. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  176. }
  177. #endif
  178. void menu_mixer() {
  179. START_MENU();
  180. BACK_ITEM(MSG_MAIN);
  181. v_index = mixer.get_current_vtool();
  182. EDIT_ITEM(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool, ENABLED(HAS_DUAL_MIXING));
  183. #if HAS_DUAL_MIXING
  184. {
  185. char tmp[11];
  186. SUBMENU(MSG_MIX, lcd_mixer_mix_edit);
  187. MENU_ITEM_ADDON_START_RJ(9);
  188. mixer.update_mix_from_vtool();
  189. sprintf_P(tmp, PSTR("%3d;%3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
  190. lcd_put_u8str(tmp);
  191. MENU_ITEM_ADDON_END();
  192. ACTION_ITEM(MSG_TOGGLE_MIX, _lcd_mixer_toggle_mix);
  193. }
  194. #else
  195. SUBMENU(MSG_MIX, _lcd_goto_mix_edit);
  196. #endif
  197. //
  198. // Reset All V-Tools
  199. //
  200. CONFIRM_ITEM(MSG_RESET_VTOOLS,
  201. MSG_BUTTON_RESET, MSG_BUTTON_CANCEL,
  202. []{
  203. mixer.reset_vtools();
  204. LCD_MESSAGE(MSG_VTOOLS_RESET);
  205. ui.return_to_status();
  206. },
  207. nullptr,
  208. GET_TEXT_F(MSG_RESET_VTOOLS), (const char *)nullptr, F("?")
  209. );
  210. #if ENABLED(GRADIENT_MIX)
  211. {
  212. char tmp[13];
  213. SUBMENU(MSG_GRADIENT, lcd_mixer_edit_gradient_menu);
  214. MENU_ITEM_ADDON_START_RJ(9);
  215. sprintf_P(tmp, PSTR("T%i->T%i"), mixer.gradient.start_vtool, mixer.gradient.end_vtool);
  216. lcd_put_u8str(tmp);
  217. MENU_ITEM_ADDON_END();
  218. ACTION_ITEM(MSG_REVERSE_GRADIENT, _lcd_mixer_reverse_gradient);
  219. }
  220. #endif
  221. END_MENU();
  222. }
  223. #endif // HAS_MARLINUI_MENU && MIXING_EXTRUDER