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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 <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 "menu_addon.h"
  29. #include "../../feature/mixing.h"
  30. #define CHANNEL_MIX_EDITING !DUAL_MIXING_EXTRUDER
  31. #if ENABLED(GRADIENT_MIX)
  32. void lcd_mixer_gradient_z_start_edit() {
  33. ui.defer_status_screen();
  34. ENCODER_RATE_MULTIPLY(true);
  35. if (ui.encoderPosition != 0) {
  36. mixer.gradient.start_z += float(int32_t(ui.encoderPosition)) * 0.1;
  37. ui.encoderPosition = 0;
  38. NOLESS(mixer.gradient.start_z, 0);
  39. NOMORE(mixer.gradient.start_z, Z_MAX_POS);
  40. }
  41. if (ui.should_draw()) {
  42. char tmp[21];
  43. strcpy_P(tmp, GET_TEXT(MSG_START_Z));
  44. sprintf_P(tmp + strlen(tmp), PSTR(": %4d.%d mm"), int(mixer.gradient.start_z), int(mixer.gradient.start_z * 10) % 10);
  45. SETCURSOR(2, (LCD_HEIGHT - 1) / 2);
  46. lcd_put_u8str(tmp);
  47. }
  48. if (ui.lcd_clicked) {
  49. if (mixer.gradient.start_z > mixer.gradient.end_z)
  50. mixer.gradient.end_z = mixer.gradient.start_z;
  51. mixer.refresh_gradient();
  52. ui.goto_previous_screen();
  53. }
  54. }
  55. void lcd_mixer_gradient_z_end_edit() {
  56. ui.defer_status_screen();
  57. ENCODER_RATE_MULTIPLY(true);
  58. if (ui.encoderPosition != 0) {
  59. mixer.gradient.end_z += float(int32_t(ui.encoderPosition)) * 0.1;
  60. ui.encoderPosition = 0;
  61. NOLESS(mixer.gradient.end_z, 0);
  62. NOMORE(mixer.gradient.end_z, Z_MAX_POS);
  63. }
  64. if (ui.should_draw()) {
  65. char tmp[21];
  66. strcpy_P(tmp, GET_TEXT(MSG_END_Z));
  67. sprintf_P(tmp + strlen(tmp), PSTR(": %4d.%d mm"), int(mixer.gradient.end_z), int(mixer.gradient.end_z * 10) % 10);
  68. SETCURSOR(2, (LCD_HEIGHT - 1) / 2);
  69. lcd_put_u8str(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. BACK_ITEM(MSG_MIXER);
  81. EDIT_ITEM(int8, MSG_START_VTOOL, &mixer.gradient.start_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  82. EDIT_ITEM(int8, MSG_END_VTOOL, &mixer.gradient.end_vtool, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  83. #if ENABLED(GRADIENT_VTOOL)
  84. EDIT_ITEM(int8, MSG_GRADIENT_ALIAS, &mixer.gradient.vtool_index, 0, MIXING_VIRTUAL_TOOLS - 1, mixer.refresh_gradient);
  85. #endif
  86. char tmp[18];
  87. 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. lcd_put_u8str(tmp);
  91. MENU_ITEM_ADDON_END();
  92. 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. lcd_put_u8str(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[20]; // "100%_100%"
  104. sprintf_P(tmp, PSTR("%3d%% %3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
  105. SETCURSOR(2, y); lcd_put_u8str_P(GET_TEXT(MSG_MIX));
  106. SETCURSOR_RJ(9, y); lcd_put_u8str(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 DUAL_MIXING_EXTRUDER && !CHANNEL_MIX_EDITING
  131. // Adjust 2-channel mix from the encoder
  132. if (ui.encoderPosition != 0) {
  133. mixer.mix[0] += int32_t(ui.encoderPosition);
  134. ui.encoderPosition = 0;
  135. if (mixer.mix[0] < 0) mixer.mix[0] += 101;
  136. if (mixer.mix[0] > 100) mixer.mix[0] -= 101;
  137. mixer.mix[1] = 100 - mixer.mix[0];
  138. }
  139. _lcd_draw_mix((LCD_HEIGHT - 1) / 2);
  140. // Click to commit the change
  141. if (ui.lcd_clicked) {
  142. mixer.update_vtool_from_mix();
  143. ui.goto_previous_screen();
  144. }
  145. #else
  146. START_MENU();
  147. BACK_ITEM(MSG_MIXER);
  148. #if CHANNEL_MIX_EDITING
  149. LOOP_S_LE_N(n, 1, MIXING_STEPPERS)
  150. EDIT_ITEM_FAST_N(float52, n, MSG_MIX_COMPONENT_N, &mixer.collector[n-1], 0, 10);
  151. ACTION_ITEM(MSG_CYCLE_MIX, _lcd_mixer_cycle_mix);
  152. ACTION_ITEM(MSG_COMMIT_VTOOL, _lcd_mixer_commit_vtool);
  153. #endif
  154. END_MENU();
  155. #endif
  156. }
  157. #if DUAL_MIXING_EXTRUDER
  158. //
  159. // Toggle Dual-Mix
  160. //
  161. inline void _lcd_mixer_toggle_mix() {
  162. mixer.mix[0] = mixer.mix[0] == 100 ? 0 : 100;
  163. mixer.mix[1] = 100 - mixer.mix[0];
  164. mixer.update_vtool_from_mix();
  165. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  166. }
  167. #endif
  168. #if CHANNEL_MIX_EDITING
  169. //
  170. // Prepare and Edit Mix
  171. //
  172. inline void _lcd_goto_mix_edit() {
  173. mixer.refresh_collector(10, v_index);
  174. ui.goto_screen(lcd_mixer_mix_edit);
  175. lcd_mixer_mix_edit();
  176. }
  177. #endif
  178. #if ENABLED(GRADIENT_MIX)
  179. //
  180. // Reverse Gradient
  181. //
  182. inline void _lcd_mixer_reverse_gradient() {
  183. const uint8_t sv = mixer.gradient.start_vtool;
  184. mixer.gradient.start_vtool = mixer.gradient.end_vtool;
  185. mixer.gradient.end_vtool = sv;
  186. mixer.refresh_gradient();
  187. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  188. }
  189. #endif
  190. void menu_mixer() {
  191. START_MENU();
  192. BACK_ITEM(MSG_MAIN);
  193. v_index = mixer.get_current_vtool();
  194. EDIT_ITEM(uint8, MSG_ACTIVE_VTOOL, &v_index, 0, MIXING_VIRTUAL_TOOLS - 1, _lcd_mixer_select_vtool
  195. #if DUAL_MIXING_EXTRUDER
  196. , true
  197. #endif
  198. );
  199. #if DUAL_MIXING_EXTRUDER
  200. {
  201. char tmp[10];
  202. SUBMENU(MSG_MIX, lcd_mixer_mix_edit);
  203. MENU_ITEM_ADDON_START(10);
  204. mixer.update_mix_from_vtool();
  205. sprintf_P(tmp, PSTR("%3d;%3d%%"), int(mixer.mix[0]), int(mixer.mix[1]));
  206. lcd_put_u8str(tmp);
  207. MENU_ITEM_ADDON_END();
  208. ACTION_ITEM(MSG_TOGGLE_MIX, _lcd_mixer_toggle_mix);
  209. }
  210. #else
  211. SUBMENU(MSG_MIX, _lcd_goto_mix_edit);
  212. #endif
  213. //
  214. // Reset All V-Tools
  215. //
  216. CONFIRM_ITEM(MSG_RESET_VTOOLS,
  217. MSG_BUTTON_RESET, MSG_BUTTON_CANCEL,
  218. []{
  219. mixer.reset_vtools();
  220. LCD_MESSAGEPGM(MSG_VTOOLS_RESET);
  221. ui.return_to_status();
  222. },
  223. ui.goto_previous_screen,
  224. GET_TEXT(MSG_RESET_VTOOLS), (PGM_P)nullptr, PSTR("?")
  225. );
  226. #if ENABLED(GRADIENT_MIX)
  227. {
  228. char tmp[13];
  229. SUBMENU(MSG_GRADIENT, lcd_mixer_edit_gradient_menu);
  230. MENU_ITEM_ADDON_START(10);
  231. sprintf_P(tmp, PSTR("T%i->T%i"), mixer.gradient.start_vtool, mixer.gradient.end_vtool);
  232. lcd_put_u8str(tmp);
  233. MENU_ITEM_ADDON_END();
  234. ACTION_ITEM(MSG_REVERSE_GRADIENT, _lcd_mixer_reverse_gradient);
  235. }
  236. #endif
  237. END_MENU();
  238. }
  239. #endif // HAS_LCD_MENU && MIXING_EXTRUDER