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 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // Mixer Menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if HAS_LCD_MENU && ENABLED(MIXING_EXTRUDER)
  27. #include "menu.h"
  28. #include "../../feature/mixing.h"
  29. #include "../dogm/ultralcd_DOGM.h"
  30. #include "../ultralcd.h"
  31. #include "../lcdprint.h"
  32. #define CHANNEL_MIX_EDITING !DUAL_MIXING_EXTRUDER
  33. #if ENABLED(GRADIENT_MIX)
  34. void lcd_mixer_gradient_z_start_edit() {
  35. ui.defer_status_screen();
  36. ui.encoder_direction_normal();
  37. ENCODER_RATE_MULTIPLY(true);
  38. if (ui.encoderPosition != 0) {
  39. mixer.gradient.start_z += float(int16_t(ui.encoderPosition)) * 0.1;
  40. ui.encoderPosition = 0;
  41. NOLESS(mixer.gradient.start_z, 0);
  42. NOMORE(mixer.gradient.start_z, Z_MAX_POS);
  43. }
  44. if (ui.should_draw()) {
  45. char tmp[21];
  46. sprintf_P(tmp, PSTR(MSG_START_Z ": %4d.%d mm"), int(mixer.gradient.start_z), int(mixer.gradient.start_z * 10) % 10);
  47. SETCURSOR(2, (LCD_HEIGHT - 1) / 2);
  48. LCDPRINT(tmp);
  49. }
  50. if (ui.lcd_clicked) {
  51. if (mixer.gradient.start_z > mixer.gradient.end_z)
  52. mixer.gradient.end_z = mixer.gradient.start_z;
  53. mixer.refresh_gradient();
  54. ui.goto_previous_screen();
  55. }
  56. }
  57. void lcd_mixer_gradient_z_end_edit() {
  58. ui.defer_status_screen();
  59. ui.encoder_direction_normal();
  60. ENCODER_RATE_MULTIPLY(true);
  61. if (ui.encoderPosition != 0) {
  62. mixer.gradient.end_z += float(int16_t(ui.encoderPosition)) * 0.1;
  63. ui.encoderPosition = 0;
  64. NOLESS(mixer.gradient.end_z, 0);
  65. NOMORE(mixer.gradient.end_z, Z_MAX_POS);
  66. }
  67. if (ui.should_draw()) {
  68. char tmp[21];
  69. sprintf_P(tmp, PSTR(MSG_END_Z ": %4d.%d mm"), int(mixer.gradient.end_z), int(mixer.gradient.end_z * 10) % 10);
  70. SETCURSOR(2, (LCD_HEIGHT - 1) / 2);
  71. LCDPRINT(tmp);
  72. }
  73. if (ui.lcd_clicked) {
  74. if (mixer.gradient.end_z < mixer.gradient.start_z)
  75. mixer.gradient.start_z = mixer.gradient.end_z;
  76. mixer.refresh_gradient();
  77. ui.goto_previous_screen();
  78. }
  79. }
  80. void lcd_mixer_edit_gradient_menu() {
  81. START_MENU();
  82. MENU_BACK(MSG_MIXER);
  83. MENU_ITEM_EDIT_CALLBACK(int8, MSG_START_VTOOL, &mixer.gradient.start_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  84. MENU_ITEM_EDIT_CALLBACK(int8, MSG_END_VTOOL, &mixer.gradient.end_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  85. #if ENABLED(GRADIENT_VTOOL)
  86. MENU_ITEM_EDIT_CALLBACK(int8, MSG_GRADIENT_ALIAS, &mixer.gradient.vtool_index, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  87. #endif
  88. char tmp[10];
  89. MENU_ITEM(submenu, MSG_START_Z ":", lcd_mixer_gradient_z_start_edit);
  90. MENU_ITEM_ADDON_START(9);
  91. sprintf_P(tmp, PSTR("%4d.%d mm"), int(mixer.gradient.start_z), int(mixer.gradient.start_z * 10) % 10);
  92. LCDPRINT(tmp);
  93. MENU_ITEM_ADDON_END();
  94. MENU_ITEM(submenu, MSG_END_Z ":", lcd_mixer_gradient_z_end_edit);
  95. MENU_ITEM_ADDON_START(9);
  96. sprintf_P(tmp, PSTR("%4d.%d mm"), int(mixer.gradient.end_z), int(mixer.gradient.end_z * 10) % 10);
  97. LCDPRINT(tmp);
  98. MENU_ITEM_ADDON_END();
  99. END_MENU();
  100. }
  101. #endif // GRADIENT_MIX
  102. static uint8_t v_index;
  103. #if DUAL_MIXING_EXTRUDER
  104. void _lcd_draw_mix(const uint8_t y) {
  105. char tmp[21];
  106. sprintf_P(tmp, PSTR(MSG_MIX ": %3d%% %3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
  107. SETCURSOR(2, y);
  108. LCDPRINT(tmp);
  109. }
  110. #endif
  111. void _lcd_mixer_select_vtool() {
  112. mixer.T(v_index);
  113. #if DUAL_MIXING_EXTRUDER
  114. _lcd_draw_mix(LCD_HEIGHT - 1);
  115. #endif
  116. }
  117. #if CHANNEL_MIX_EDITING
  118. void _lcd_mixer_cycle_mix() {
  119. uint16_t bits = 0;
  120. MIXER_STEPPER_LOOP(i) if (mixer.collector[i]) SBI(bits, i);
  121. bits = (bits + 1) & (_BV(MIXING_STEPPERS) - 1);
  122. if (!bits) ++bits;
  123. MIXER_STEPPER_LOOP(i) mixer.collector[i] = TEST(bits, i) ? 10.0f : 0.0f;
  124. ui.refresh();
  125. }
  126. void _lcd_mixer_commit_vtool() {
  127. mixer.normalize();
  128. ui.goto_previous_screen();
  129. }
  130. #endif
  131. void lcd_mixer_mix_edit() {
  132. #if CHANNEL_MIX_EDITING
  133. #define EDIT_COLOR(N) MENU_MULTIPLIER_ITEM_EDIT(float52, MSG_MIX_COMPONENT " " STRINGIFY(N), &mixer.collector[N-1], 0, 10);
  134. START_MENU();
  135. MENU_BACK(MSG_MIXER);
  136. EDIT_COLOR(1);
  137. EDIT_COLOR(2);
  138. #if MIXING_STEPPERS > 2
  139. EDIT_COLOR(3);
  140. #if MIXING_STEPPERS > 3
  141. EDIT_COLOR(4);
  142. #if MIXING_STEPPERS > 4
  143. EDIT_COLOR(5);
  144. #if MIXING_STEPPERS > 5
  145. EDIT_COLOR(6);
  146. #endif
  147. #endif
  148. #endif
  149. #endif
  150. MENU_ITEM(function, MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);
  151. MENU_ITEM(function, MSG_COMMIT_VTOOL, _lcd_mixer_commit_vtool);
  152. END_MENU();
  153. #elif DUAL_MIXING_EXTRUDER
  154. if (ui.encoderPosition != 0) {
  155. mixer.mix[0] += int16_t(ui.encoderPosition);
  156. ui.encoderPosition = 0;
  157. if (mixer.mix[0] < 0) mixer.mix[0] += 101;
  158. if (mixer.mix[0] > 100) mixer.mix[0] -= 101;
  159. mixer.mix[1] = 100 - mixer.mix[0];
  160. }
  161. _lcd_draw_mix((LCD_HEIGHT - 1) / 2);
  162. if (ui.lcd_clicked) {
  163. mixer.update_vtool_from_mix();
  164. ui.goto_previous_screen();
  165. }
  166. #else
  167. START_MENU();
  168. MENU_BACK(MSG_MIXER);
  169. END_MENU();
  170. #endif
  171. }
  172. #if DUAL_MIXING_EXTRUDER
  173. //
  174. // Toggle Dual-Mix
  175. //
  176. inline void _lcd_mixer_toggle_mix() {
  177. mixer.mix[0] = mixer.mix[0] == 100 ? 0 : 100;
  178. mixer.mix[1] = 100 - mixer.mix[0];
  179. mixer.update_vtool_from_mix();
  180. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  181. }
  182. #endif
  183. #if CHANNEL_MIX_EDITING
  184. //
  185. // Prepare and Edit Mix
  186. //
  187. inline void _lcd_goto_mix_edit() {
  188. mixer.refresh_collector(10, v_index);
  189. ui.goto_screen(lcd_mixer_mix_edit);
  190. lcd_mixer_mix_edit();
  191. }
  192. #endif
  193. #if ENABLED(GRADIENT_MIX)
  194. //
  195. // Reverse Gradient
  196. //
  197. inline void _lcd_mixer_reverse_gradient() {
  198. const uint8_t sv = mixer.gradient.start_vtool;
  199. mixer.gradient.start_vtool = mixer.gradient.end_vtool;
  200. mixer.gradient.end_vtool = sv;
  201. mixer.refresh_gradient();
  202. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  203. }
  204. #endif
  205. //
  206. // Reset All V-Tools
  207. //
  208. void menu_mixer_vtools_reset_confirm() {
  209. do_select_screen(
  210. PSTR(MSG_BUTTON_RESET), PSTR(MSG_BUTTON_CANCEL),
  211. []{
  212. mixer.reset_vtools();
  213. LCD_MESSAGEPGM(MSG_VTOOLS_RESET);
  214. ui.return_to_status();
  215. },
  216. ui.goto_previous_screen,
  217. PSTR(MSG_RESET_VTOOLS), NULL, PSTR("?")
  218. );
  219. }
  220. void menu_mixer() {
  221. START_MENU();
  222. MENU_BACK(MSG_MAIN);
  223. v_index = mixer.get_current_vtool();
  224. MENU_ITEM_EDIT_CALLBACK(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool
  225. #if DUAL_MIXING_EXTRUDER
  226. , true
  227. #endif
  228. );
  229. MENU_ITEM(submenu, MSG_MIX,
  230. #if CHANNEL_MIX_EDITING
  231. _lcd_goto_mix_edit
  232. #elif DUAL_MIXING_EXTRUDER
  233. lcd_mixer_mix_edit
  234. #endif
  235. );
  236. #if DUAL_MIXING_EXTRUDER
  237. {
  238. char tmp[10];
  239. MENU_ITEM_ADDON_START(10);
  240. mixer.update_mix_from_vtool();
  241. sprintf_P(tmp, PSTR("%3d;%3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
  242. LCDPRINT(tmp);
  243. MENU_ITEM_ADDON_END();
  244. MENU_ITEM(function, MSG_TOGGLE_MIX, _lcd_mixer_toggle_mix);
  245. }
  246. #endif
  247. MENU_ITEM(submenu, MSG_RESET_VTOOLS, menu_mixer_vtools_reset_confirm);
  248. #if ENABLED(GRADIENT_MIX)
  249. {
  250. char tmp[10];
  251. MENU_ITEM(submenu, MSG_GRADIENT, lcd_mixer_edit_gradient_menu);
  252. MENU_ITEM_ADDON_START(10);
  253. sprintf_P(tmp, PSTR("T%i->T%i"), mixer.gradient.start_vtool, mixer.gradient.end_vtool);
  254. LCDPRINT(tmp);
  255. MENU_ITEM_ADDON_END();
  256. MENU_ITEM(function, MSG_REVERSE_GRADIENT, _lcd_mixer_reverse_gradient);
  257. }
  258. #endif
  259. END_MENU();
  260. }
  261. #endif // HAS_LCD_MENU && MIXING_EXTRUDER