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.

change_filament_screen.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /******************************
  2. * change_filament_screen.cpp *
  3. ******************************/
  4. /****************************************************************************
  5. * Written By Mark Pelletier 2017 - Aleph Objects, Inc. *
  6. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  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. * To view a copy of the GNU General Public License, go to the following *
  19. * location: <http://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. #include "../config.h"
  22. #if ENABLED(TOUCH_UI_FTDI_EVE)
  23. #include "screens.h"
  24. #include "screen_data.h"
  25. using namespace ExtUI;
  26. using namespace FTDI;
  27. using namespace Theme;
  28. #define COOL_TEMP 40
  29. #define LOW_TEMP 180
  30. #define MED_TEMP 200
  31. #define HIGH_TEMP 220
  32. /****************** COLOR SCALE ***********************/
  33. uint32_t getWarmColor(uint16_t temp, uint16_t cool, uint16_t low, uint16_t med, uint16_t high) {
  34. rgb_t R0, R1, mix;
  35. float t;
  36. if (temp < cool) {
  37. R0 = cool_rgb;
  38. R1 = low_rgb;
  39. t = 0;
  40. }
  41. else if (temp < low) {
  42. R0 = cool_rgb;
  43. R1 = low_rgb;
  44. t = (float(temp)-cool)/(low-cool);
  45. }
  46. else if (temp < med) {
  47. R0 = low_rgb;
  48. R1 = med_rgb;
  49. t = (float(temp)-low)/(med-low);
  50. }
  51. else if (temp < high) {
  52. R0 = med_rgb;
  53. R1 = high_rgb;
  54. t = (float(temp)-med)/(high-med);
  55. }
  56. else if (temp >= high) {
  57. R0 = med_rgb;
  58. R1 = high_rgb;
  59. t = 1;
  60. }
  61. rgb_t::lerp(t, R0, R1, mix);
  62. return mix;
  63. }
  64. void ChangeFilamentScreen::drawTempGradient(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
  65. CommandProcessor cmd;
  66. cmd.cmd(SCISSOR_XY (x, y))
  67. .cmd(SCISSOR_SIZE (w, h/2))
  68. .gradient (x, y, high_rgb, x, y+h/2, med_rgb)
  69. .cmd(SCISSOR_XY (x, y+h/2))
  70. .cmd(SCISSOR_SIZE (w, h/2))
  71. .gradient (x, y+h/2, med_rgb, x, y+h, low_rgb)
  72. .cmd(SCISSOR_XY ())
  73. .cmd(SCISSOR_SIZE ());
  74. }
  75. void ChangeFilamentScreen::onEntry() {
  76. screen_data.ChangeFilamentScreen.e_tag = ExtUI::getActiveTool() + 10;
  77. screen_data.ChangeFilamentScreen.t_tag = 0;
  78. screen_data.ChangeFilamentScreen.repeat_tag = 0;
  79. screen_data.ChangeFilamentScreen.saved_extruder = getActiveTool();
  80. #if FILAMENT_UNLOAD_PURGE_LENGTH > 0
  81. screen_data.ChangeFilamentScreen.need_purge = true;
  82. #endif
  83. }
  84. void ChangeFilamentScreen::onExit() {
  85. setActiveTool(screen_data.ChangeFilamentScreen.saved_extruder, true);
  86. }
  87. void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
  88. CommandProcessor cmd;
  89. #ifdef TOUCH_UI_PORTRAIT
  90. #define GRID_COLS 2
  91. #define GRID_ROWS 11
  92. #else
  93. #define GRID_COLS 4
  94. #define GRID_ROWS 6
  95. #endif
  96. if (what & BACKGROUND) {
  97. cmd.cmd(CLEAR_COLOR_RGB(bg_color))
  98. .cmd(CLEAR(true,true,true))
  99. .tag(0)
  100. #ifdef TOUCH_UI_PORTRAIT
  101. .font(font_large)
  102. #else
  103. .font(font_medium)
  104. #endif
  105. .text(BTN_POS(1,1), BTN_SIZE(2,1), GET_TEXT_F(MSG_EXTRUDER_SELECTION))
  106. #ifdef TOUCH_UI_PORTRAIT
  107. .text(BTN_POS(1,7), BTN_SIZE(1,1), F(""))
  108. #else
  109. .text(BTN_POS(3,1), BTN_SIZE(2,1), GET_TEXT_F(MSG_CURRENT_TEMPERATURE))
  110. .font(font_small)
  111. #endif
  112. .text(BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_REMOVAL_TEMPERATURE));
  113. drawTempGradient(BTN_POS(1,4), BTN_SIZE(1,3));
  114. }
  115. if (what & FOREGROUND) {
  116. const extruder_t e = getExtruder();
  117. char e_str[15];
  118. if (isHeaterIdle(e))
  119. format_temp_and_idle(e_str, getActualTemp_celsius(e));
  120. else
  121. format_temp_and_temp(e_str, getActualTemp_celsius(e), getTargetTemp_celsius(e));
  122. const rgb_t tcol = getWarmColor(getActualTemp_celsius(e), COOL_TEMP, LOW_TEMP, MED_TEMP, HIGH_TEMP);
  123. cmd.cmd(COLOR_RGB(tcol))
  124. .tag(15)
  125. #ifdef TOUCH_UI_PORTRAIT
  126. .rectangle(BTN_POS(2,7), BTN_SIZE(1,1))
  127. #else
  128. .rectangle(BTN_POS(3,2), BTN_SIZE(2,1))
  129. #endif
  130. .cmd(COLOR_RGB(tcol.luminance() > 128 ? 0x000000 : 0xFFFFFF))
  131. .font(font_medium)
  132. #ifdef TOUCH_UI_PORTRAIT
  133. .text(BTN_POS(2,7), BTN_SIZE(1,1), e_str)
  134. #else
  135. .text(BTN_POS(3,2), BTN_SIZE(2,1), e_str)
  136. #endif
  137. .colors(normal_btn);
  138. const bool t_ok = getActualTemp_celsius(e) > getSoftenTemp() - 10;
  139. if (screen_data.ChangeFilamentScreen.t_tag && !t_ok) {
  140. cmd.text(BTN_POS(1,6), BTN_SIZE(1,1), GET_TEXT_F(MSG_HEATING));
  141. } else if (getActualTemp_celsius(e) > 100) {
  142. cmd.cmd(COLOR_RGB(0xFF0000))
  143. .text(BTN_POS(1,4), BTN_SIZE(1,1), GET_TEXT_F(MSG_CAUTION))
  144. .colors(normal_btn)
  145. .text(BTN_POS(1,6), BTN_SIZE(1,1), GET_TEXT_F(MSG_HOT));
  146. }
  147. #define TOG_STYLE(A) colors(A ? action_btn : normal_btn)
  148. const bool tog2 = screen_data.ChangeFilamentScreen.t_tag == 2;
  149. const bool tog3 = screen_data.ChangeFilamentScreen.t_tag == 3;
  150. const bool tog4 = screen_data.ChangeFilamentScreen.t_tag == 4;
  151. const bool tog10 = screen_data.ChangeFilamentScreen.e_tag == 10;
  152. #if HOTENDS > 1
  153. const bool tog11 = screen_data.ChangeFilamentScreen.e_tag == 11;
  154. #endif
  155. #ifdef TOUCH_UI_PORTRAIT
  156. cmd.font(font_large)
  157. #else
  158. cmd.font(font_medium)
  159. #endif
  160. .TOG_STYLE(tog10)
  161. .tag(10) .button (BTN_POS(1,2), BTN_SIZE(1,1), F("1"))
  162. #if HOTENDS < 2
  163. .enabled(false)
  164. #else
  165. .TOG_STYLE(tog11)
  166. #endif
  167. .tag(11) .button (BTN_POS(2,2), BTN_SIZE(1,1), F("2"));
  168. if (!t_ok) reset_menu_timeout();
  169. const bool tog7 = screen_data.ChangeFilamentScreen.repeat_tag == 7;
  170. const bool tog8 = screen_data.ChangeFilamentScreen.repeat_tag == 8;
  171. #ifdef TOUCH_UI_PORTRAIT
  172. cmd.font(font_large);
  173. #else
  174. cmd.font(font_small);
  175. #endif
  176. {
  177. char str[30];
  178. format_temp_and_material(str, LOW_TEMP, GET_TEXT(MSG_MATERIAL_PLA));
  179. cmd.tag(2) .TOG_STYLE(tog2) .button (BTN_POS(2,6), BTN_SIZE(1,1), str);
  180. format_temp_and_material(str, MED_TEMP, GET_TEXT(MSG_MATERIAL_ABS));
  181. cmd.tag(3) .TOG_STYLE(tog3) .button (BTN_POS(2,5), BTN_SIZE(1,1), str);
  182. format_temp_and_material(str, HIGH_TEMP, GET_TEXT(MSG_MATERIAL_HIGH_TEMP));
  183. cmd.tag(4) .TOG_STYLE(tog4) .button (BTN_POS(2,4), BTN_SIZE(1,1), str);
  184. }
  185. cmd.colors(normal_btn)
  186. // Add tags to color gradient
  187. .cmd(COLOR_MASK(0,0,0,0))
  188. .tag(2) .rectangle(BTN_POS(1,6), BTN_SIZE(1,1))
  189. .tag(3) .rectangle(BTN_POS(1,5), BTN_SIZE(1,1))
  190. .tag(4) .rectangle(BTN_POS(1,4), BTN_SIZE(1,1))
  191. .cmd(COLOR_MASK(1,1,1,1))
  192. .cmd(COLOR_RGB(t_ok ? bg_text_enabled : bg_text_disabled))
  193. #ifdef TOUCH_UI_PORTRAIT
  194. .font(font_large)
  195. .tag(0) .text (BTN_POS(1,8), BTN_SIZE(1,1), GET_TEXT_F(MSG_UNLOAD_FILAMENT))
  196. .text (BTN_POS(2,8), BTN_SIZE(1,1), GET_TEXT_F(MSG_LOAD_FILAMENT))
  197. .tag(5) .enabled(t_ok).button (BTN_POS(1,9), BTN_SIZE(1,1), GET_TEXT_F(MSG_MOMENTARY))
  198. .tag(6) .enabled(t_ok).button (BTN_POS(2,9), BTN_SIZE(1,1), GET_TEXT_F(MSG_MOMENTARY))
  199. .tag(7).TOG_STYLE(tog7).enabled(t_ok).button (BTN_POS(1,10), BTN_SIZE(1,1), GET_TEXT_F(MSG_CONTINUOUS))
  200. .tag(8).TOG_STYLE(tog8).enabled(t_ok).button (BTN_POS(2,10), BTN_SIZE(1,1), GET_TEXT_F(MSG_CONTINUOUS))
  201. .tag(1).colors(action_btn) .button (BTN_POS(1,11), BTN_SIZE(2,1), GET_TEXT_F(MSG_BACK));
  202. #else
  203. .font(font_small)
  204. .tag(0) .text (BTN_POS(3,3), BTN_SIZE(1,1), GET_TEXT_F(MSG_UNLOAD_FILAMENT))
  205. .text (BTN_POS(4,3), BTN_SIZE(1,1), GET_TEXT_F(MSG_LOAD_FILAMENT))
  206. .tag(5) .enabled(t_ok).button (BTN_POS(3,4), BTN_SIZE(1,1), GET_TEXT_F(MSG_MOMENTARY))
  207. .tag(6) .enabled(t_ok).button (BTN_POS(4,4), BTN_SIZE(1,1), GET_TEXT_F(MSG_MOMENTARY))
  208. .tag(7).TOG_STYLE(tog7).enabled(t_ok).button (BTN_POS(3,5), BTN_SIZE(1,1), GET_TEXT_F(MSG_CONTINUOUS))
  209. .tag(8).TOG_STYLE(tog8).enabled(t_ok).button (BTN_POS(4,5), BTN_SIZE(1,1), GET_TEXT_F(MSG_CONTINUOUS))
  210. .font(font_medium)
  211. .tag(1).colors(action_btn) .button (BTN_POS(3,6), BTN_SIZE(2,1), GET_TEXT_F(MSG_BACK));
  212. #endif
  213. }
  214. #undef GRID_COLS
  215. #undef GRID_ROWS
  216. }
  217. uint8_t ChangeFilamentScreen::getSoftenTemp() {
  218. switch (screen_data.ChangeFilamentScreen.t_tag) {
  219. case 2: return LOW_TEMP;
  220. case 3: return MED_TEMP;
  221. case 4: return HIGH_TEMP;
  222. default: return EXTRUDE_MINTEMP;
  223. }
  224. }
  225. ExtUI::extruder_t ChangeFilamentScreen::getExtruder() {
  226. switch (screen_data.ChangeFilamentScreen.e_tag) {
  227. case 13: return ExtUI::E3;
  228. case 12: return ExtUI::E2;
  229. case 11: return ExtUI::E1;
  230. default: return ExtUI::E0;
  231. }
  232. }
  233. void ChangeFilamentScreen::doPurge() {
  234. #if FILAMENT_UNLOAD_PURGE_LENGTH > 0
  235. constexpr float purge_distance_mm = FILAMENT_UNLOAD_PURGE_LENGTH;
  236. if (screen_data.ChangeFilamentScreen.need_purge) {
  237. screen_data.ChangeFilamentScreen.need_purge = false;
  238. MoveAxisScreen::setManualFeedrate(getExtruder(), purge_distance_mm);
  239. ExtUI::setAxisPosition_mm(ExtUI::getAxisPosition_mm(getExtruder()) + purge_distance_mm, getExtruder());
  240. }
  241. #endif
  242. }
  243. bool ChangeFilamentScreen::onTouchStart(uint8_t tag) {
  244. // Make the Momentary and Continuous buttons slightly more responsive
  245. switch (tag) {
  246. case 5: case 6: case 7: case 8:
  247. #if FILAMENT_UNLOAD_PURGE_LENGTH > 0
  248. if (tag == 5 || tag == 7) doPurge();
  249. #endif
  250. return ChangeFilamentScreen::onTouchHeld(tag);
  251. default:
  252. return false;
  253. }
  254. }
  255. bool ChangeFilamentScreen::onTouchEnd(uint8_t tag) {
  256. using namespace ExtUI;
  257. switch (tag) {
  258. case 1: GOTO_PREVIOUS(); break;
  259. case 2:
  260. case 3:
  261. case 4:
  262. // Change temperature
  263. screen_data.ChangeFilamentScreen.t_tag = tag;
  264. setTargetTemp_celsius(getSoftenTemp(), getExtruder());
  265. break;
  266. case 7:
  267. screen_data.ChangeFilamentScreen.repeat_tag = (screen_data.ChangeFilamentScreen.repeat_tag == 7) ? 0 : 7;
  268. break;
  269. case 8:
  270. screen_data.ChangeFilamentScreen.repeat_tag = (screen_data.ChangeFilamentScreen.repeat_tag == 8) ? 0 : 8;
  271. break;
  272. case 10:
  273. case 11:
  274. // Change extruder
  275. screen_data.ChangeFilamentScreen.e_tag = tag;
  276. screen_data.ChangeFilamentScreen.t_tag = 0;
  277. screen_data.ChangeFilamentScreen.repeat_tag = 0;
  278. #if FILAMENT_UNLOAD_PURGE_LENGTH > 0
  279. screen_data.ChangeFilamentScreen.need_purge = true;
  280. #endif
  281. setActiveTool(getExtruder(), true);
  282. break;
  283. case 15: GOTO_SCREEN(TemperatureScreen); break;
  284. }
  285. return true;
  286. }
  287. bool ChangeFilamentScreen::onTouchHeld(uint8_t tag) {
  288. if (ExtUI::isMoving()) return false; // Don't allow moves to accumulate
  289. constexpr float increment = 1;
  290. #define UI_INCREMENT_AXIS(axis) UI_INCREMENT(AxisPosition_mm, axis);
  291. #define UI_DECREMENT_AXIS(axis) UI_DECREMENT(AxisPosition_mm, axis);
  292. switch (tag) {
  293. case 5: case 7: UI_DECREMENT_AXIS(getExtruder()); break;
  294. case 6: case 8: UI_INCREMENT_AXIS(getExtruder()); break;
  295. default: return false;
  296. }
  297. #undef UI_DECREMENT_AXIS
  298. #undef UI_INCREMENT_AXIS
  299. return false;
  300. }
  301. void ChangeFilamentScreen::onIdle() {
  302. reset_menu_timeout();
  303. if (screen_data.ChangeFilamentScreen.repeat_tag) onTouchHeld(screen_data.ChangeFilamentScreen.repeat_tag);
  304. if (refresh_timer.elapsed(STATUS_UPDATE_INTERVAL)) {
  305. onRefresh();
  306. refresh_timer.start();
  307. }
  308. BaseScreen::onIdle();
  309. }
  310. #endif // TOUCH_UI_FTDI_EVE