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.1KB

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