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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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(LULZBOT_TOUCH_UI)
  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. }
  81. void ChangeFilamentScreen::onExit() {
  82. setActiveTool(screen_data.ChangeFilamentScreen.saved_extruder, true);
  83. }
  84. void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
  85. CommandProcessor cmd;
  86. #ifdef TOUCH_UI_PORTRAIT
  87. #define GRID_COLS 2
  88. #define GRID_ROWS 11
  89. #else
  90. #define GRID_COLS 4
  91. #define GRID_ROWS 6
  92. #endif
  93. if (what & BACKGROUND) {
  94. cmd.cmd(CLEAR_COLOR_RGB(bg_color))
  95. .cmd(CLEAR(true,true,true))
  96. .tag(0)
  97. #ifdef TOUCH_UI_PORTRAIT
  98. .font(font_large)
  99. #else
  100. .font(font_medium)
  101. #endif
  102. .text(BTN_POS(1,1), BTN_SIZE(2,1), GET_TEXTF(EXTRUDER_SELECTION))
  103. #ifdef TOUCH_UI_PORTRAIT
  104. .text(BTN_POS(1,7), BTN_SIZE(1,1), F(""))
  105. #else
  106. .text(BTN_POS(3,1), BTN_SIZE(2,1), GET_TEXTF(CURRENT_TEMPERATURE))
  107. .font(font_small)
  108. #endif
  109. .text(BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXTF(REMOVAL_TEMPERATURE));
  110. drawTempGradient(BTN_POS(1,4), BTN_SIZE(1,3));
  111. }
  112. if (what & FOREGROUND) {
  113. char e_str[15];
  114. if (isHeaterIdle(getExtruder()))
  115. sprintf_P(e_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(getExtruder())), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE));
  116. else
  117. sprintf_P(e_str, PSTR("%3d / %3d%S"), ROUND(getActualTemp_celsius(getExtruder())), ROUND(getTargetTemp_celsius(getExtruder())), GET_TEXT(UNITS_C));
  118. const rgb_t tcol = getWarmColor(getActualTemp_celsius(getExtruder()), COOL_TEMP, LOW_TEMP, MED_TEMP, HIGH_TEMP);
  119. cmd.cmd(COLOR_RGB(tcol))
  120. .tag(15)
  121. #ifdef TOUCH_UI_PORTRAIT
  122. .rectangle(BTN_POS(2,7), BTN_SIZE(1,1))
  123. #else
  124. .rectangle(BTN_POS(3,2), BTN_SIZE(2,1))
  125. #endif
  126. .cmd(COLOR_RGB(tcol.luminance() > 128 ? 0x000000 : 0xFFFFFF))
  127. .font(font_medium)
  128. #ifdef TOUCH_UI_PORTRAIT
  129. .text(BTN_POS(2,7), BTN_SIZE(1,1), e_str)
  130. #else
  131. .text(BTN_POS(3,2), BTN_SIZE(2,1), e_str)
  132. #endif
  133. .colors(normal_btn);
  134. const bool t_ok = getActualTemp_celsius(getExtruder()) > getSoftenTemp() - 10;
  135. if (screen_data.ChangeFilamentScreen.t_tag && !t_ok) {
  136. cmd.text(BTN_POS(1,6), BTN_SIZE(1,1), GET_TEXTF(HEATING));
  137. } else if (getActualTemp_celsius(getExtruder()) > 100) {
  138. cmd.cmd(COLOR_RGB(0xFF0000))
  139. .text(BTN_POS(1,4), BTN_SIZE(1,1), GET_TEXTF(CAUTION))
  140. .colors(normal_btn)
  141. .text(BTN_POS(1,6), BTN_SIZE(1,1), GET_TEXTF(HOT));
  142. }
  143. #define TOG_STYLE(A) colors(A ? action_btn : normal_btn)
  144. const bool tog2 = screen_data.ChangeFilamentScreen.t_tag == 2;
  145. const bool tog3 = screen_data.ChangeFilamentScreen.t_tag == 3;
  146. const bool tog4 = screen_data.ChangeFilamentScreen.t_tag == 4;
  147. const bool tog10 = screen_data.ChangeFilamentScreen.e_tag == 10;
  148. #if HOTENDS > 1
  149. const bool tog11 = screen_data.ChangeFilamentScreen.e_tag == 11;
  150. #endif
  151. #ifdef TOUCH_UI_PORTRAIT
  152. cmd.font(font_large)
  153. #else
  154. cmd.font(font_medium)
  155. #endif
  156. .TOG_STYLE(tog10)
  157. .tag(10) .button (BTN_POS(1,2), BTN_SIZE(1,1), F("1"))
  158. #if HOTENDS < 2
  159. .enabled(false)
  160. #else
  161. .TOG_STYLE(tog11)
  162. #endif
  163. .tag(11) .button (BTN_POS(2,2), BTN_SIZE(1,1), F("2"));
  164. if (!t_ok) reset_menu_timeout();
  165. const bool tog7 = screen_data.ChangeFilamentScreen.repeat_tag == 7;
  166. const bool tog8 = screen_data.ChangeFilamentScreen.repeat_tag == 8;
  167. #ifdef TOUCH_UI_PORTRAIT
  168. cmd.font(font_large);
  169. #else
  170. cmd.font(font_small);
  171. #endif
  172. {
  173. char str[30];
  174. sprintf_P(str, PSTR("%3d%S (%S)"), LOW_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_PLA));
  175. cmd.tag(2) .TOG_STYLE(tog2) .button (BTN_POS(2,6), BTN_SIZE(1,1), str);
  176. }
  177. {
  178. char str[30];
  179. sprintf_P(str, PSTR("%3d%S (%S)"), MED_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_ABS));
  180. cmd.tag(3) .TOG_STYLE(tog3) .button (BTN_POS(2,5), BTN_SIZE(1,1), str);
  181. }
  182. {
  183. char str[30];
  184. sprintf_P(str, PSTR("%3d%S (%S)"), HIGH_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_HIGH_TEMP));
  185. cmd.tag(4) .TOG_STYLE(tog4) .button (BTN_POS(2,4), BTN_SIZE(1,1), str);
  186. }
  187. cmd.colors(normal_btn)
  188. // Add tags to color gradient
  189. .cmd(COLOR_MASK(0,0,0,0))
  190. .tag(2) .rectangle(BTN_POS(1,6), BTN_SIZE(1,1))
  191. .tag(3) .rectangle(BTN_POS(1,5), BTN_SIZE(1,1))
  192. .tag(4) .rectangle(BTN_POS(1,4), BTN_SIZE(1,1))
  193. .cmd(COLOR_MASK(1,1,1,1))
  194. .cmd(COLOR_RGB(t_ok ? bg_text_enabled : bg_text_disabled))
  195. #ifdef TOUCH_UI_PORTRAIT
  196. .font(font_large)
  197. .tag(0) .text (BTN_POS(1,8), BTN_SIZE(1,1), GET_TEXTF(UNLOAD_FILAMENT))
  198. .text (BTN_POS(2,8), BTN_SIZE(1,1), GET_TEXTF(LOAD_FILAMENT))
  199. .tag(5) .enabled(t_ok).button (BTN_POS(1,9), BTN_SIZE(1,1), GET_TEXTF(MOMENTARY))
  200. .tag(6) .enabled(t_ok).button (BTN_POS(2,9), BTN_SIZE(1,1), GET_TEXTF(MOMENTARY))
  201. .tag(7).TOG_STYLE(tog7).enabled(t_ok).button (BTN_POS(1,10), BTN_SIZE(1,1), GET_TEXTF(CONTINUOUS))
  202. .tag(8).TOG_STYLE(tog8).enabled(t_ok).button (BTN_POS(2,10), BTN_SIZE(1,1), GET_TEXTF(CONTINUOUS))
  203. .tag(1).colors(action_btn) .button (BTN_POS(1,11), BTN_SIZE(2,1), GET_TEXTF(BACK));
  204. #else
  205. .font(font_small)
  206. .tag(0) .text (BTN_POS(3,3), BTN_SIZE(1,1), GET_TEXTF(UNLOAD_FILAMENT))
  207. .text (BTN_POS(4,3), BTN_SIZE(1,1), GET_TEXTF(LOAD_FILAMENT))
  208. .tag(5) .enabled(t_ok).button (BTN_POS(3,4), BTN_SIZE(1,1), GET_TEXTF(MOMENTARY))
  209. .tag(6) .enabled(t_ok).button (BTN_POS(4,4), BTN_SIZE(1,1), GET_TEXTF(MOMENTARY))
  210. .tag(7).TOG_STYLE(tog7).enabled(t_ok).button (BTN_POS(3,5), BTN_SIZE(1,1), GET_TEXTF(CONTINUOUS))
  211. .tag(8).TOG_STYLE(tog8).enabled(t_ok).button (BTN_POS(4,5), BTN_SIZE(1,1), GET_TEXTF(CONTINUOUS))
  212. .font(font_medium)
  213. .tag(1).colors(action_btn) .button (BTN_POS(3,6), BTN_SIZE(2,1), GET_TEXTF(BACK));
  214. #endif
  215. }
  216. #undef GRID_COLS
  217. #undef GRID_ROWS
  218. }
  219. uint8_t ChangeFilamentScreen::getSoftenTemp() {
  220. switch (screen_data.ChangeFilamentScreen.t_tag) {
  221. case 2: return LOW_TEMP;
  222. case 3: return MED_TEMP;
  223. case 4: return HIGH_TEMP;
  224. default: return EXTRUDE_MINTEMP;
  225. }
  226. }
  227. ExtUI::extruder_t ChangeFilamentScreen::getExtruder() {
  228. switch (screen_data.ChangeFilamentScreen.e_tag) {
  229. case 13: return ExtUI::E3;
  230. case 12: return ExtUI::E2;
  231. case 11: return ExtUI::E1;
  232. default: return ExtUI::E0;
  233. }
  234. }
  235. bool ChangeFilamentScreen::onTouchStart(uint8_t tag) {
  236. // Make the Momentary and Continuous buttons slightly more responsive
  237. switch (tag) {
  238. case 5: case 6: case 7: case 8:
  239. return ChangeFilamentScreen::onTouchHeld(tag);
  240. default:
  241. return false;
  242. }
  243. }
  244. bool ChangeFilamentScreen::onTouchEnd(uint8_t tag) {
  245. using namespace ExtUI;
  246. switch (tag) {
  247. case 1: GOTO_PREVIOUS(); break;
  248. case 2:
  249. case 3:
  250. case 4:
  251. // Change temperature
  252. screen_data.ChangeFilamentScreen.t_tag = tag;
  253. setTargetTemp_celsius(getSoftenTemp(), getExtruder());
  254. break;
  255. case 7:
  256. screen_data.ChangeFilamentScreen.repeat_tag = (screen_data.ChangeFilamentScreen.repeat_tag == 7) ? 0 : 7;
  257. break;
  258. case 8:
  259. screen_data.ChangeFilamentScreen.repeat_tag = (screen_data.ChangeFilamentScreen.repeat_tag == 8) ? 0 : 8;
  260. break;
  261. case 10:
  262. case 11:
  263. // Change extruder
  264. screen_data.ChangeFilamentScreen.e_tag = tag;
  265. screen_data.ChangeFilamentScreen.t_tag = 0;
  266. screen_data.ChangeFilamentScreen.repeat_tag = 0;
  267. setActiveTool(getExtruder(), true);
  268. break;
  269. case 15: GOTO_SCREEN(TemperatureScreen); break;
  270. }
  271. return true;
  272. }
  273. bool ChangeFilamentScreen::onTouchHeld(uint8_t tag) {
  274. if (ExtUI::isMoving()) return false; // Don't allow moves to accumulate
  275. constexpr float increment = 1;
  276. #define UI_INCREMENT_AXIS(axis) MoveAxisScreen::setManualFeedrate(axis, increment); UI_INCREMENT(AxisPosition_mm, axis);
  277. #define UI_DECREMENT_AXIS(axis) MoveAxisScreen::setManualFeedrate(axis, increment); UI_DECREMENT(AxisPosition_mm, axis);
  278. switch (tag) {
  279. case 5: case 7: UI_DECREMENT_AXIS(getExtruder()); break;
  280. case 6: case 8: UI_INCREMENT_AXIS(getExtruder()); break;
  281. default: return false;
  282. }
  283. #undef UI_DECREMENT_AXIS
  284. #undef UI_INCREMENT_AXIS
  285. return false;
  286. }
  287. void ChangeFilamentScreen::onIdle() {
  288. if (screen_data.ChangeFilamentScreen.repeat_tag) onTouchHeld(screen_data.ChangeFilamentScreen.repeat_tag);
  289. if (refresh_timer.elapsed(STATUS_UPDATE_INTERVAL)) {
  290. onRefresh();
  291. refresh_timer.start();
  292. }
  293. BaseScreen::onIdle();
  294. }
  295. #endif // LULZBOT_TOUCH_UI