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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. strcpy_P(tmp, GET_TEXT(MSG_START_Z));
  46. sprintf_P(tmp + strlen(tmp), PSTR(": %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. ENCODER_RATE_MULTIPLY(true);
  60. if (ui.encoderPosition != 0) {
  61. mixer.gradient.end_z += float(int16_t(ui.encoderPosition)) * 0.1;
  62. ui.encoderPosition = 0;
  63. NOLESS(mixer.gradient.end_z, 0);
  64. NOMORE(mixer.gradient.end_z, Z_MAX_POS);
  65. }
  66. if (ui.should_draw()) {
  67. char tmp[21];
  68. strcpy_P(tmp, GET_TEXT(MSG_END_Z));
  69. sprintf_P(tmp + strlen(tmp), PSTR(": %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. BACK_ITEM(MSG_MIXER);
  83. EDIT_ITEM(int8, MSG_START_VTOOL, &mixer.gradient.start_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  84. EDIT_ITEM(int8, MSG_END_VTOOL, &mixer.gradient.end_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  85. #if ENABLED(GRADIENT_VTOOL)
  86. EDIT_ITEM(int8, MSG_GRADIENT_ALIAS, &mixer.gradient.vtool_index, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  87. #endif
  88. char tmp[18];
  89. 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. 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[10]; // "100%_100%"
  106. SETCURSOR(2, y);
  107. lcd_put_u8str_P(GET_TEXT(MSG_MIX));
  108. SETCURSOR(LCD_WIDTH - 9, y);
  109. sprintf_P(tmp, PSTR("%3d%% %3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
  110. LCDPRINT(tmp);
  111. }
  112. #endif
  113. void _lcd_mixer_select_vtool() {
  114. mixer.T(v_index);
  115. #if DUAL_MIXING_EXTRUDER
  116. _lcd_draw_mix(LCD_HEIGHT - 1);
  117. #endif
  118. }
  119. #if CHANNEL_MIX_EDITING
  120. void _lcd_mixer_cycle_mix() {
  121. uint16_t bits = 0;
  122. MIXER_STEPPER_LOOP(i) if (mixer.collector[i]) SBI(bits, i);
  123. bits = (bits + 1) & (_BV(MIXING_STEPPERS) - 1);
  124. if (!bits) ++bits;
  125. MIXER_STEPPER_LOOP(i) mixer.collector[i] = TEST(bits, i) ? 10.0f : 0.0f;
  126. ui.refresh();
  127. }
  128. void _lcd_mixer_commit_vtool() {
  129. mixer.normalize();
  130. ui.goto_previous_screen();
  131. }
  132. #endif
  133. void lcd_mixer_mix_edit() {
  134. #if CHANNEL_MIX_EDITING
  135. #define EDIT_COLOR(N) EDIT_ITEM_FAST(float52, MSG_MIX_COMPONENT_##N, &mixer.collector[N-1], 0, 10);
  136. START_MENU();
  137. BACK_ITEM(MSG_MIXER);
  138. EDIT_COLOR(1);
  139. EDIT_COLOR(2);
  140. #if MIXING_STEPPERS > 2
  141. EDIT_COLOR(3);
  142. #if MIXING_STEPPERS > 3
  143. EDIT_COLOR(4);
  144. #if MIXING_STEPPERS > 4
  145. EDIT_COLOR(5);
  146. #if MIXING_STEPPERS > 5
  147. EDIT_COLOR(6);
  148. #endif
  149. #endif
  150. #endif
  151. #endif
  152. ACTION_ITEM(MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);
  153. ACTION_ITEM(MSG_COMMIT_VTOOL, _lcd_mixer_commit_vtool);
  154. END_MENU();
  155. #elif DUAL_MIXING_EXTRUDER
  156. if (ui.encoderPosition != 0) {
  157. mixer.mix[0] += int16_t(ui.encoderPosition);
  158. ui.encoderPosition = 0;
  159. if (mixer.mix[0] < 0) mixer.mix[0] += 101;
  160. if (mixer.mix[0] > 100) mixer.mix[0] -= 101;
  161. mixer.mix[1] = 100 - mixer.mix[0];
  162. }
  163. _lcd_draw_mix((LCD_HEIGHT - 1) / 2);
  164. if (ui.lcd_clicked) {
  165. mixer.update_vtool_from_mix();
  166. ui.goto_previous_screen();
  167. }
  168. #else
  169. START_MENU();
  170. BACK_ITEM(MSG_MIXER);
  171. END_MENU();
  172. #endif
  173. }
  174. #if DUAL_MIXING_EXTRUDER
  175. //
  176. // Toggle Dual-Mix
  177. //
  178. inline void _lcd_mixer_toggle_mix() {
  179. mixer.mix[0] = mixer.mix[0] == 100 ? 0 : 100;
  180. mixer.mix[1] = 100 - mixer.mix[0];
  181. mixer.update_vtool_from_mix();
  182. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  183. }
  184. #endif
  185. #if CHANNEL_MIX_EDITING
  186. //
  187. // Prepare and Edit Mix
  188. //
  189. inline void _lcd_goto_mix_edit() {
  190. mixer.refresh_collector(10, v_index);
  191. ui.goto_screen(lcd_mixer_mix_edit);
  192. lcd_mixer_mix_edit();
  193. }
  194. #endif
  195. #if ENABLED(GRADIENT_MIX)
  196. //
  197. // Reverse Gradient
  198. //
  199. inline void _lcd_mixer_reverse_gradient() {
  200. const uint8_t sv = mixer.gradient.start_vtool;
  201. mixer.gradient.start_vtool = mixer.gradient.end_vtool;
  202. mixer.gradient.end_vtool = sv;
  203. mixer.refresh_gradient();
  204. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  205. }
  206. #endif
  207. //
  208. // Reset All V-Tools
  209. //
  210. void menu_mixer_vtools_reset_confirm() {
  211. do_select_screen(
  212. GET_TEXT(MSG_BUTTON_RESET), GET_TEXT(MSG_BUTTON_CANCEL),
  213. []{
  214. mixer.reset_vtools();
  215. LCD_MESSAGEPGM(MSG_VTOOLS_RESET);
  216. ui.return_to_status();
  217. },
  218. ui.goto_previous_screen,
  219. GET_TEXT(MSG_RESET_VTOOLS), nullptr, PSTR("?")
  220. );
  221. }
  222. void menu_mixer() {
  223. START_MENU();
  224. BACK_ITEM(MSG_MAIN);
  225. v_index = mixer.get_current_vtool();
  226. EDIT_ITEM(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool
  227. #if DUAL_MIXING_EXTRUDER
  228. , true
  229. #endif
  230. );
  231. #if DUAL_MIXING_EXTRUDER
  232. {
  233. char tmp[10];
  234. SUBMENU(MSG_MIX, lcd_mixer_mix_edit);
  235. MENU_ITEM_ADDON_START(10);
  236. mixer.update_mix_from_vtool();
  237. sprintf_P(tmp, PSTR("%3d;%3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
  238. LCDPRINT(tmp);
  239. MENU_ITEM_ADDON_END();
  240. ACTION_ITEM(MSG_TOGGLE_MIX, _lcd_mixer_toggle_mix);
  241. }
  242. #else
  243. SUBMENU(MSG_MIX, _lcd_goto_mix_edit);
  244. #endif
  245. SUBMENU(MSG_RESET_VTOOLS, menu_mixer_vtools_reset_confirm);
  246. #if ENABLED(GRADIENT_MIX)
  247. {
  248. char tmp[13];
  249. 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. ACTION_ITEM(MSG_REVERSE_GRADIENT, _lcd_mixer_reverse_gradient);
  255. }
  256. #endif
  257. END_MENU();
  258. }
  259. #endif // HAS_LCD_MENU && MIXING_EXTRUDER