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.

dwin.cpp 136KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529
  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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * DWIN by Creality3D
  24. */
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if ENABLED(DWIN_CREALITY_LCD)
  27. #include "dwin.h"
  28. #include <WString.h>
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include "../fontutils.h"
  32. #include "../ultralcd.h"
  33. #include "../../sd/cardreader.h"
  34. #include "../../MarlinCore.h"
  35. #include "../../core/serial.h"
  36. #include "../../core/macros.h"
  37. #include "../../gcode/queue.h"
  38. #include "../../feature/powerloss.h"
  39. #include "../../feature/babystep.h"
  40. #include "../../module/configuration_store.h"
  41. #include "../../module/temperature.h"
  42. #include "../../module/printcounter.h"
  43. #include "../../module/motion.h"
  44. #include "../../module/planner.h"
  45. #if HAS_LEVELING
  46. #include "../../feature/bedlevel/bedlevel.h"
  47. #endif
  48. #if HAS_BED_PROBE
  49. #include "../../module/probe.h"
  50. #endif
  51. #include "../../libs/buzzer.h"
  52. #ifndef MACHINE_SIZE
  53. #define MACHINE_SIZE "220x220x250"
  54. #endif
  55. #ifndef CORP_WEBSITE_C
  56. #define CORP_WEBSITE_C "www.cxsw3d.com"
  57. #endif
  58. #ifndef CORP_WEBSITE_E
  59. #define CORP_WEBSITE_E "www.creality.com"
  60. #endif
  61. #define PAUSE_HEAT true
  62. #define USE_STRING_HEADINGS
  63. #define MENU_FONT font8x16
  64. #define STAT_FONT font10x20
  65. #define HEADER_FONT font10x20
  66. #define MENU_CHAR_LIMIT 24
  67. // Fan speed limit
  68. #define FANON 255
  69. #define FANOFF 0
  70. // Print speed limit
  71. #define MAX_PRINT_SPEED 999
  72. #define MIN_PRINT_SPEED 10
  73. // Temp limits
  74. #if HAS_HOTEND
  75. #define MAX_E_TEMP (HEATER_0_MAXTEMP - (HOTEND_OVERSHOOT))
  76. #define MIN_E_TEMP HEATER_0_MINTEMP
  77. #endif
  78. #if HAS_HEATED_BED
  79. #define MIN_BED_TEMP BED_MINTEMP
  80. #endif
  81. // Feedspeed limit (max feedspeed = DEFAULT_MAX_FEEDRATE * 2)
  82. #define MIN_MAXFEEDSPEED 1
  83. #define MIN_MAXACCELERATION 1
  84. #define MIN_MAXCORNER 0.1
  85. #define MIN_STEP 1
  86. #define FEEDRATE_E (60)
  87. // Mininum unit (0.1) : multiple (10)
  88. #define MINUNITMULT 10
  89. #define ENCODER_WAIT 20
  90. #define DWIN_SCROLL_UPDATE_INTERVAL 2000
  91. #define DWIN_REMAIN_TIME_UPDATE_INTERVAL 20000
  92. constexpr uint16_t TROWS = 6, MROWS = TROWS - 1, // Total rows, and other-than-Back
  93. TITLE_HEIGHT = 30, // Title bar height
  94. MLINE = 53, // Menu line height
  95. LBLX = 60, // Menu item label X
  96. MENU_CHR_W = 8, STAT_CHR_W = 10;
  97. #define MBASE(L) (49 + (L)*MLINE)
  98. #define BABY_Z_VAR TERN(HAS_LEVELING, probe.offset.z, zprobe_zoffset)
  99. /* Value Init */
  100. HMI_value_t HMI_ValueStruct;
  101. HMI_Flag HMI_flag{0};
  102. millis_t Encoder_ms = 0;
  103. millis_t Wait_ms = 0;
  104. millis_t dwin_heat_time = 0;
  105. int checkkey = 0, last_checkkey = 0;
  106. typedef struct {
  107. uint8_t now, last;
  108. void set(uint8_t v) { now = last = v; }
  109. void reset() { set(0); }
  110. bool changed() { bool c = (now != last); if (c) last = now; return c; }
  111. bool dec() { if (now) now--; return changed(); }
  112. bool inc(uint8_t v) { if (now < v) now++; else now = v; return changed(); }
  113. } select_t;
  114. select_t select_page{0}, select_file{0}, select_print{0}, select_prepare{0}
  115. , select_control{0}, select_axis{0}, select_temp{0}, select_motion{0}, select_tune{0}
  116. , select_PLA{0}, select_ABS{0}
  117. , select_speed{0}
  118. , select_acc{0}
  119. , select_corner{0}
  120. , select_step{0}
  121. // , select_leveling{0}
  122. ;
  123. uint8_t index_file = MROWS,
  124. index_prepare = MROWS,
  125. index_control = MROWS,
  126. index_leveling = MROWS,
  127. index_tune = 5;
  128. // char filebuf[50];
  129. uint8_t countbuf = 0;
  130. bool recovery_flag = false, abort_flag = false;
  131. constexpr float default_max_feedrate[] = DEFAULT_MAX_FEEDRATE;
  132. constexpr float default_max_acceleration[] = DEFAULT_MAX_ACCELERATION;
  133. constexpr float default_max_jerk[] = { DEFAULT_XJERK, DEFAULT_YJERK, DEFAULT_ZJERK, DEFAULT_EJERK };
  134. constexpr float default_axis_steps_per_unit[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  135. uint8_t Percentrecord = 0;
  136. uint16_t last_Printtime = 0, remain_time = 0;
  137. float last_temp_hotend_target = 0, last_temp_bed_target = 0;
  138. float last_temp_hotend_current = 0, last_temp_bed_current = 0;
  139. uint8_t last_fan_speed = 0;
  140. uint16_t last_speed = 0;
  141. float last_E_scale = 0;
  142. bool DWIN_lcd_sd_status = 0;
  143. bool pause_action_flag = 0;
  144. int temphot = 0, tempbed = 0;
  145. float zprobe_zoffset = 0;
  146. float last_zoffset = 0, last_probe_zoffset = 0;
  147. #define DWIN_LANGUAGE_EEPROM_ADDRESS 0x01 // Between 0x01 and 0x63 (EEPROM_OFFSET-1)
  148. // BL24CXX::check() uses 0x00
  149. void lcd_select_language(void) {
  150. BL24CXX::read(DWIN_LANGUAGE_EEPROM_ADDRESS, (uint8_t*)&HMI_flag.language_flag, sizeof(HMI_flag.language_flag));
  151. if (HMI_flag.language_flag)
  152. DWIN_JPG_CacheTo1(Language_Chinese);
  153. else
  154. DWIN_JPG_CacheTo1(Language_English);
  155. }
  156. void set_english_to_eeprom(void) {
  157. HMI_flag.language_flag = 0;
  158. DWIN_JPG_CacheTo1(Language_English);
  159. BL24CXX::write(DWIN_LANGUAGE_EEPROM_ADDRESS, (uint8_t*)&HMI_flag.language_flag, sizeof(HMI_flag.language_flag));
  160. }
  161. void set_chinese_to_eeprom(void) {
  162. HMI_flag.language_flag = 1;
  163. DWIN_JPG_CacheTo1(Language_Chinese);
  164. BL24CXX::write(DWIN_LANGUAGE_EEPROM_ADDRESS, (uint8_t*)&HMI_flag.language_flag, sizeof(HMI_flag.language_flag));
  165. }
  166. void show_plus_or_minus(uint8_t size, uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value) {
  167. if (value < 0) {
  168. DWIN_Draw_String(false, true, size, White, bColor, x - 6, y, (char*)"-");
  169. DWIN_Draw_FloatValue(true, true, 0, size, White, bColor, iNum, fNum, x, y, -value);
  170. }
  171. else {
  172. DWIN_Draw_String(false, true, size, White, bColor, x - 6, y, (char*)" ");
  173. DWIN_Draw_FloatValue(true, true, 0, size, White, bColor, iNum, fNum, x, y, value);
  174. }
  175. }
  176. void ICON_Print() {
  177. if (select_page.now == 0) {
  178. DWIN_ICON_Show(ICON, ICON_Print_1, 17, 130);
  179. if (HMI_flag.language_flag)
  180. DWIN_Frame_AreaCopy(1, 1, 447, 271 - 243, 479 - 19, 58, 201);
  181. else
  182. DWIN_Frame_AreaCopy(1, 1, 451, 271 - 240, 479 - 16, 72 - 15, 201);
  183. }
  184. else {
  185. DWIN_ICON_Show(ICON, ICON_Print_0, 17, 130);
  186. if (HMI_flag.language_flag)
  187. DWIN_Frame_AreaCopy(1, 1, 405, 271 - 243, 420, 58, 201);
  188. else
  189. DWIN_Frame_AreaCopy(1, 1, 423, 271 - 240, 423 + 12, 72 - 15, 201);
  190. }
  191. }
  192. void ICON_Prepare() {
  193. if (select_page.now == 1) {
  194. DWIN_ICON_Show(ICON, ICON_Prepare_1, 145, 130);
  195. if (HMI_flag.language_flag)
  196. DWIN_Frame_AreaCopy(1, 31, 447, 271 - 213, 479 - 19, 186, 201);
  197. else
  198. DWIN_Frame_AreaCopy(1, 33, 451, 271 - 189, 479 - 13, 200 - 25, 201);
  199. }
  200. else {
  201. DWIN_ICON_Show(ICON, ICON_Prepare_0, 145, 130);
  202. if (HMI_flag.language_flag)
  203. DWIN_Frame_AreaCopy(1, 31, 405, 271 - 213, 420, 186, 201);
  204. else
  205. DWIN_Frame_AreaCopy(1, 33, 423, 271 - 189, 423 + 15, 200 - 25, 201);
  206. }
  207. }
  208. void ICON_Control() {
  209. if (select_page.now == 2) {
  210. DWIN_ICON_Show(ICON, ICON_Control_1, 17, 246);
  211. if (HMI_flag.language_flag)
  212. DWIN_Frame_AreaCopy(1, 61, 447, 271 - 183, 479 - 19, 58, 318);
  213. else
  214. DWIN_Frame_AreaCopy(1, 85, 451, 271 - 139, 479 - 16, 72 - 24, 318);
  215. }
  216. else {
  217. DWIN_ICON_Show(ICON, ICON_Control_0, 17, 246);
  218. if (HMI_flag.language_flag)
  219. DWIN_Frame_AreaCopy(1, 61, 405, 271 - 183, 420, 58, 318);
  220. else
  221. DWIN_Frame_AreaCopy(1, 85, 423, 271 - 139, 479 - 45, 72 - 24, 318);
  222. }
  223. }
  224. void ICON_StartInfo(bool show) {
  225. if (show) {
  226. DWIN_ICON_Show(ICON, ICON_Info_1, 145, 246);
  227. if (HMI_flag.language_flag)
  228. DWIN_Frame_AreaCopy(1, 91, 447, 271 - 153, 479 - 19, 186, 318);
  229. else
  230. DWIN_Frame_AreaCopy(1, 132, 451, 159, 479 - 13, 186, 318);
  231. }
  232. else {
  233. DWIN_ICON_Show(ICON, ICON_Info_0, 145, 246);
  234. if (HMI_flag.language_flag)
  235. DWIN_Frame_AreaCopy(1, 91, 405, 271 - 153, 420, 186, 318);
  236. else
  237. DWIN_Frame_AreaCopy(1, 132, 423, 159, 423 + 12, 186, 318);
  238. }
  239. }
  240. void ICON_Leveling(bool show) {
  241. if (show) {
  242. DWIN_ICON_Show(ICON, ICON_Leveling_1, 145, 246);
  243. if (HMI_flag.language_flag)
  244. DWIN_Frame_AreaCopy(1, 211, 447, 238, 479 - 19, 186, 318);
  245. else
  246. DWIN_Frame_AreaCopy(1, 84, 437, 120, 449, 200 - 18, 318);
  247. }
  248. else {
  249. DWIN_ICON_Show(ICON, ICON_Leveling_0, 145, 246);
  250. if (HMI_flag.language_flag)
  251. DWIN_Frame_AreaCopy(1, 211, 405, 238, 420, 186, 318);
  252. else
  253. DWIN_Frame_AreaCopy(1, 84, 465, 120, 478, 200 - 18, 318);
  254. }
  255. }
  256. void ICON_Tune() {
  257. if (select_print.now == 0) {
  258. DWIN_ICON_Show(ICON, ICON_Setup_1, 8, 252);
  259. if (HMI_flag.language_flag)
  260. DWIN_Frame_AreaCopy(1, 121, 447, 271 - 123, 479 - 21, 34, 325);
  261. else
  262. DWIN_Frame_AreaCopy(1, 1, 465, 271 - 237, 479 - 2, 48 - 17, 325);
  263. }
  264. else {
  265. DWIN_ICON_Show(ICON, ICON_Setup_0, 8, 252);
  266. if (HMI_flag.language_flag)
  267. DWIN_Frame_AreaCopy(1, 121, 405, 271 - 123, 420, 34, 325);
  268. else
  269. DWIN_Frame_AreaCopy(1, 1, 438, 271 - 239, 479 - 31, 48 - 17, 325);
  270. }
  271. }
  272. void ICON_Pause() {
  273. if (select_print.now == 1) {
  274. DWIN_ICON_Show(ICON, ICON_Pause_1, 96, 252);
  275. if (HMI_flag.language_flag)
  276. DWIN_Frame_AreaCopy(1, 181, 447, 271 - 63, 479 - 20, 124, 325);
  277. else
  278. DWIN_Frame_AreaCopy(1, 177, 451, 271 - 55, 479 - 17, 136 - 20, 325);
  279. }
  280. else {
  281. DWIN_ICON_Show(ICON, ICON_Pause_0, 96, 252);
  282. if (HMI_flag.language_flag)
  283. DWIN_Frame_AreaCopy(1, 181, 405, 271 - 63, 420, 124, 325);
  284. else
  285. DWIN_Frame_AreaCopy(1, 177, 423, 271 - 56, 479 - 46, 136 - 20, 325);
  286. }
  287. }
  288. void ICON_Continue() {
  289. if (select_print.now == 1) {
  290. DWIN_ICON_Show(ICON, ICON_Continue_1, 96, 252);
  291. if (HMI_flag.language_flag)
  292. DWIN_Frame_AreaCopy(1, 1, 447, 271 - 243, 479 - 19, 124, 325);
  293. else
  294. DWIN_Frame_AreaCopy(1, 1, 451, 271 - 239, 479 - 16, 136 - 15, 325);
  295. }
  296. else {
  297. DWIN_ICON_Show(ICON, ICON_Continue_0, 96, 252);
  298. if (HMI_flag.language_flag)
  299. DWIN_Frame_AreaCopy(1, 1, 405, 271 - 243, 420, 124, 325);
  300. else
  301. DWIN_Frame_AreaCopy(1, 1, 424, 271 - 240, 479 - 45, 136 - 15, 325);
  302. }
  303. }
  304. void ICON_Stop() {
  305. if (select_print.now == 2) {
  306. DWIN_ICON_Show(ICON, ICON_Stop_1, 184, 252);
  307. if (HMI_flag.language_flag)
  308. DWIN_Frame_AreaCopy(1, 151, 447, 271 - 93, 479 - 20, 210, 325);
  309. else
  310. DWIN_Frame_AreaCopy(1, 218, 451, 271 - 22, 479 - 14, 224 - 15, 325);
  311. }
  312. else {
  313. DWIN_ICON_Show(ICON, ICON_Stop_0, 184, 252);
  314. if (HMI_flag.language_flag)
  315. DWIN_Frame_AreaCopy(1, 151, 405, 271 - 93, 420, 210, 325);
  316. else
  317. DWIN_Frame_AreaCopy(1, 218, 423, 271 - 24, 479 - 43, 224 - 15, 325);
  318. }
  319. }
  320. inline void Clear_Title_Bar(void) {
  321. DWIN_Draw_Rectangle(1, Background_blue, 0, 0, DWIN_WIDTH, 30);
  322. }
  323. inline void Draw_Title(const char * const title) {
  324. DWIN_Draw_String(false, false, HEADER_FONT, White, Background_blue, 14, 4, (char*)title);
  325. }
  326. inline void Clear_Menu_Area(void) {
  327. DWIN_Draw_Rectangle(1, Background_black, 0, 31, 272, 360);
  328. }
  329. inline void Clear_Main_Window(void) {
  330. Clear_Title_Bar();
  331. Clear_Menu_Area();
  332. }
  333. inline void Clear_Popup_Area(void) {
  334. Clear_Title_Bar();
  335. DWIN_Draw_Rectangle(1, Background_black, 0, 31, 272, 480);
  336. }
  337. void Draw_Popup_Bkgd_105(void) {
  338. DWIN_Draw_Rectangle(1, Background_window, 14, 105, 271 - 13, 479 - 105);
  339. }
  340. inline void Draw_More_Icon(const uint8_t line) {
  341. DWIN_ICON_Show(ICON, ICON_More, 226, 46 + line * MLINE);
  342. }
  343. inline void Draw_Menu_Cursor(const uint8_t line) {
  344. // DWIN_ICON_Show(ICON,ICON_Rectangle, 0, 31 + line * MLINE);
  345. DWIN_Draw_Rectangle(1, Rectangle_Color, 0, 31 + line * MLINE, 14, 31 + (line + 1) * MLINE - 2);
  346. }
  347. inline void Erase_Menu_Cursor(const uint8_t line) {
  348. DWIN_Draw_Rectangle(1, Background_black, 0, 31 + line * MLINE, 14, 31 + (line + 1) * MLINE - 2);
  349. }
  350. inline void Move_Highlight(const int16_t from, const uint16_t newline) {
  351. Erase_Menu_Cursor(newline - from);
  352. Draw_Menu_Cursor(newline);
  353. }
  354. inline void Add_Menu_Line() {
  355. Move_Highlight(1, MROWS);
  356. DWIN_Draw_Line(Line_Color, 16, 82 + MROWS * MLINE, 256, 83 + MROWS * MLINE);
  357. }
  358. inline void Scroll_Menu(const uint8_t dir) {
  359. DWIN_Frame_AreaMove(1, dir, MLINE, Background_black, 0, 31, 272, 349);
  360. switch (dir) {
  361. case DWIN_SCROLL_DOWN: Move_Highlight(-1, 0); break;
  362. case DWIN_SCROLL_UP: Add_Menu_Line(); break;
  363. }
  364. }
  365. inline uint16_t nr_sd_menu_items() {
  366. return card.get_num_Files() + !card.flag.workDirIsRoot;
  367. }
  368. inline void Draw_Menu_Icon(const uint8_t line, const uint8_t icon) {
  369. DWIN_ICON_Show(ICON, icon, 26, 46 + line * MLINE);
  370. }
  371. inline void Erase_Menu_Text(const uint8_t line) {
  372. DWIN_Draw_Rectangle(1, Background_black, LBLX, 31 + line * MLINE + 4, 271, 28 + (line + 1) * MLINE - 4);
  373. }
  374. inline void Draw_Menu_Line(const uint8_t line, const uint8_t icon=0, const char * const label=nullptr) {
  375. if (label) DWIN_Draw_String(false, false, font8x16, White, Background_black, LBLX, 48 + line * MLINE, (char*)label);
  376. if (icon) Draw_Menu_Icon(line, icon);
  377. DWIN_Draw_Line(Line_Color, 16, 29 + (line + 1) * MLINE, 256, 30 + (line + 1) * MLINE);
  378. }
  379. // The "Back" label is always on the first line
  380. inline void Draw_Back_Label(void) {
  381. if (HMI_flag.language_flag)
  382. DWIN_Frame_AreaCopy(1, 129, 72, 271 - 115, 479 - 395, LBLX, MBASE(0));
  383. else
  384. DWIN_Frame_AreaCopy(1, 226, 179, 271 - 15, 479 - 290, LBLX, MBASE(0));
  385. }
  386. // Draw "Back" line at the top
  387. inline void Draw_Back_First(const bool is_sel=true) {
  388. Draw_Menu_Line(0, ICON_Back);
  389. Draw_Back_Label();
  390. if (is_sel) Draw_Menu_Cursor(0);
  391. }
  392. //
  393. // Draw Menus
  394. //
  395. inline void draw_move_en(const uint16_t line) {
  396. DWIN_Frame_AreaCopy(1, 69, 61, 271 - 169, 479 - 408, LBLX, line); // "Move"
  397. }
  398. inline void Prepare_Item_Move(const uint8_t row) {
  399. if (HMI_flag.language_flag)
  400. DWIN_Frame_AreaCopy(1, 159, 70, 271 - 71, 479 - 395, LBLX, MBASE(row));
  401. else
  402. draw_move_en(MBASE(row)); // "Move >"
  403. Draw_Menu_Line(row, ICON_Axis);
  404. Draw_More_Icon(row);
  405. }
  406. inline void Prepare_Item_Disable(const uint8_t row) {
  407. if (HMI_flag.language_flag)
  408. DWIN_Frame_AreaCopy(1, 204, 70, 271 - 12, 479 - 397, LBLX, MBASE(row));
  409. else
  410. DWIN_Frame_AreaCopy(1, 103, 59, 271 - 71, 479 - 405, LBLX, MBASE(row)); // "Disable Stepper"
  411. Draw_Menu_Line(row, ICON_CloseMotor);
  412. }
  413. inline void Prepare_Item_Home(const uint8_t row) {
  414. if (HMI_flag.language_flag)
  415. DWIN_Frame_AreaCopy(1, 0, 89, 271 - 230, 479 - 378, LBLX, MBASE(row));
  416. else
  417. DWIN_Frame_AreaCopy(1, 202, 61, 271 - 0, 479 - 408, LBLX, MBASE(row)); // "Auto Home"
  418. Draw_Menu_Line(row, ICON_Homing);
  419. }
  420. inline void Prepare_Item_Offset(const uint8_t row) {
  421. if (HMI_flag.language_flag) {
  422. #if HAS_BED_PROBE
  423. DWIN_Frame_AreaCopy(1, 174, 164, 271 - 48, 479 - 302, LBLX, MBASE(row));
  424. show_plus_or_minus(font8x16, Background_black, 2, 2, 202, MBASE(row), probe.offset.z * 100);
  425. #else
  426. DWIN_Frame_AreaCopy(1, 43, 89, 271 - 173, 479 - 378, LBLX, MBASE(row));
  427. #endif
  428. }
  429. else {
  430. #if HAS_BED_PROBE
  431. DWIN_Frame_AreaCopy(1, 93, 179, 271 - 130, 479 - 290, LBLX, MBASE(row)); // "Z-Offset"
  432. show_plus_or_minus(font8x16, Background_black, 2, 2, 202, MBASE(row), probe.offset.z * 100);
  433. #else
  434. DWIN_Frame_AreaCopy(1, 1, 76, 271 - 165, 479 - 393, LBLX, MBASE(row)); // "..."
  435. #endif
  436. }
  437. Draw_Menu_Line(row, ICON_SetHome);
  438. }
  439. inline void Prepare_Item_PLA(const uint8_t row) {
  440. if (HMI_flag.language_flag) {
  441. DWIN_Frame_AreaCopy(1, 100, 89, 271 - 93 - 27, 479 - 378, LBLX, MBASE(row));
  442. }
  443. else {
  444. DWIN_Frame_AreaCopy(1, 107, 76, 271 - 115, 479 - 393, LBLX, MBASE(row)); // "Preheat"
  445. DWIN_Frame_AreaCopy(1, 157, 76, 181, 479 - 393, LBLX + 49 + 3, MBASE(row)); // "PLA"
  446. }
  447. Draw_Menu_Line(row, ICON_PLAPreheat);
  448. }
  449. inline void Prepare_Item_ABS(const uint8_t row) {
  450. if (HMI_flag.language_flag) {
  451. DWIN_Frame_AreaCopy(1, 180, 89, 271 - 11 - 27, 479 - 379, LBLX, MBASE(row));
  452. }
  453. else {
  454. DWIN_Frame_AreaCopy(1, 107, 76, 271 - 115, 479 - 393, LBLX, MBASE(row)); // "Preheat"
  455. DWIN_Frame_AreaCopy(1, 172, 76, 198, 479 - 393, LBLX + 49 + 3, MBASE(row)); // "ABS"
  456. }
  457. Draw_Menu_Line(row, ICON_ABSPreheat);
  458. }
  459. inline void Prepare_Item_Cool(const uint8_t row) {
  460. if (HMI_flag.language_flag)
  461. DWIN_Frame_AreaCopy(1, 1, 104, 271 - 215, 479 - 362, LBLX, MBASE(row));
  462. else
  463. DWIN_Frame_AreaCopy(1, 200, 76, 271 - 7, 479 - 393, LBLX, MBASE(row));// "Cooldown"
  464. Draw_Menu_Line(row, ICON_Cool);
  465. }
  466. inline void Prepare_Item_Lang(const uint8_t row) {
  467. if (HMI_flag.language_flag) {
  468. DWIN_Frame_AreaCopy(1, 239, 134, 271 - 5, 479 - 333, LBLX, MBASE(row));
  469. DWIN_Draw_String(false, false, font8x16, White, Background_black, 226, MBASE(row), (char*)"CN");
  470. }
  471. else {
  472. DWIN_Frame_AreaCopy(1, 0, 194, 271 - 150, 479 - 272, LBLX, MBASE(row)); // "Language selection"
  473. DWIN_Draw_String(false, false, font8x16, White, Background_black, 226, MBASE(row), (char*)"EN");
  474. }
  475. Draw_Menu_Icon(row, ICON_Language);
  476. }
  477. inline void Draw_Prepare_Menu() {
  478. Clear_Main_Window();
  479. const int16_t scroll = MROWS - index_prepare; // Scrolled-up lines
  480. #define PSCROL(L) (scroll + (L))
  481. #define PVISI(L) WITHIN(PSCROL(L), 0, MROWS)
  482. if (HMI_flag.language_flag) {
  483. DWIN_Frame_AreaCopy(1, 133, 1, 271 - 111, 479 - 465 - 1, 14, 8); // "Prepare"
  484. }
  485. else {
  486. #ifdef USE_STRING_HEADINGS
  487. Draw_Title("Prepare"); // TODO: GET_TEXT_F
  488. #else
  489. DWIN_Frame_AreaCopy(1, 178, 2, 271 - 42, 479 - 464 - 1, 14, 8); // "Prepare"
  490. #endif
  491. }
  492. if (PVISI(0)) Draw_Back_First(select_prepare.now == 0); // < Back
  493. if (PVISI(1)) Prepare_Item_Move(PSCROL(1)); // Move >
  494. if (PVISI(2)) Prepare_Item_Disable(PSCROL(2)); // Disable Stepper
  495. if (PVISI(3)) Prepare_Item_Home(PSCROL(3)); // Auto Home
  496. if (PVISI(4)) Prepare_Item_Offset(PSCROL(4)); // Z-Offset
  497. if (PVISI(5)) Prepare_Item_PLA(PSCROL(5)); // Preheat PLA
  498. if (PVISI(6)) Prepare_Item_ABS(PSCROL(6)); // Preheat ABS
  499. if (PVISI(7)) Prepare_Item_Cool(PSCROL(7)); // Cooldown
  500. if (PVISI(8)) Prepare_Item_Lang(PSCROL(8)); // Language CN/EN
  501. if (select_prepare.now) Draw_Menu_Cursor(PSCROL(select_prepare.now));
  502. }
  503. inline void Draw_Control_Menu() {
  504. Clear_Main_Window();
  505. const int16_t scroll = TERN(HAS_LEVELING, MROWS - index_control, 0); // Scrolled-up lines
  506. #define CSCROL(L) (scroll + (L))
  507. #define CLINE(L) MBASE(CSCROL(L))
  508. #define CVISI(L) WITHIN(CSCROL(L), 0, MROWS)
  509. if (CVISI(0)) Draw_Back_First(select_control.now == 0); // < Back
  510. if (HMI_flag.language_flag) {
  511. DWIN_Frame_AreaCopy(1, 103, 1, 271 - 141, 479 - 465, 14, 8);
  512. DWIN_Frame_AreaCopy(1, 57, 104, 271 - 187, 479 - 363, LBLX, CLINE(1)); // Temperature >
  513. DWIN_Frame_AreaCopy(1, 87, 104, 271 - 157, 479 - 363, LBLX, CLINE(2)); // Motion >
  514. DWIN_Frame_AreaCopy(1, 117, 104, 271 - 99, 479 - 363, LBLX, CLINE(3)); // Store Config
  515. DWIN_Frame_AreaCopy(1, 174, 103, 271 - 42, 479 - 363, LBLX, CLINE(4)); // Read Config
  516. DWIN_Frame_AreaCopy(1, 1, 118, 271 - 215, 479 - 348, LBLX, CLINE(5)); // Reset Config
  517. if (CVISI(6))
  518. DWIN_Frame_AreaCopy(1, 231, 104, 271 - 13, 479 - 363, LBLX, CLINE(6)); // Info >
  519. }
  520. else {
  521. #ifdef USE_STRING_HEADINGS
  522. Draw_Title("Control"); // TODO: GET_TEXT_F
  523. #else
  524. DWIN_Frame_AreaCopy(1, 128, 2, 271 - 95, 479 - 467, 14, 8);
  525. #endif
  526. DWIN_Frame_AreaCopy(1, 1, 89, 271 - 188, 479 - 377 - 1, LBLX, CLINE(1));// Temperature >
  527. DWIN_Frame_AreaCopy(1, 84, 89, 271 - 143, 479 - 380, LBLX, CLINE(2));// Motion >
  528. DWIN_Frame_AreaCopy(1, 131 + 17, 89, 271 - 3, 479 - 377 - 1, LBLX, CLINE(3));// "Store Configuration"
  529. DWIN_Frame_AreaCopy(1, 26, 104, 271 - 214, 479 - 365, LBLX, CLINE(4)); // "Read"
  530. DWIN_Frame_AreaCopy(1, 131 + 51, 89, 271 - 3, 479 - 377 - 1, LBLX + 31 + 3, CLINE(4)); // "Configuration"
  531. DWIN_Frame_AreaCopy(1, 59, 104, 271 - 178, 479 - 365, LBLX, CLINE(5)); // "Reset"
  532. DWIN_Frame_AreaCopy(1, 131 + 51, 89, 271 - 3, 479 - 377 - 1, LBLX + 34 + 3, CLINE(5)); // "Configuration"
  533. if (CVISI(6))
  534. DWIN_Frame_AreaCopy(1, 0, 104, 25, 115, LBLX, CLINE(6)); // Info >
  535. }
  536. if (select_control.now && CVISI(select_control.now))
  537. Draw_Menu_Cursor(CSCROL(select_control.now));
  538. // Draw icons and lines
  539. LOOP_L_N(i, 6)
  540. if (CVISI(i + 1)) Draw_Menu_Line(CSCROL(i + 1), ICON_Temperature + i);
  541. Draw_More_Icon(CSCROL(1));
  542. Draw_More_Icon(CSCROL(2));
  543. if (CVISI(6)) Draw_More_Icon(CSCROL(6));
  544. }
  545. inline void Draw_Tune_Menu() {
  546. Clear_Main_Window();
  547. if (HMI_flag.language_flag) {
  548. DWIN_Frame_AreaCopy(1, 73, 2, 271 - 171, 479 - 466, 14, 9);
  549. DWIN_Frame_AreaCopy(1, 116, 164, 271 - 100, 479 - 303, LBLX, MBASE(1));
  550. DWIN_Frame_AreaCopy(1, 1, 134, 271 - 215, 479 - 333, LBLX, MBASE(2));
  551. DWIN_Frame_AreaCopy(1, 58, 134, 271 - 158, 479 - 333, LBLX, MBASE(3));
  552. DWIN_Frame_AreaCopy(1, 115, 134, 271 - 101, 479 - 333, LBLX, MBASE(4));
  553. DWIN_Frame_AreaCopy(1, 174, 164, 271 - 48, 479 - 302, LBLX, MBASE(5));
  554. }
  555. else {
  556. #ifdef USE_STRING_HEADINGS
  557. Draw_Title("Tune"); // TODO: GET_TEXT
  558. #else
  559. DWIN_Frame_AreaCopy(1, 94, 2, 271 - 145, 479 - 467, 14, 9);
  560. #endif
  561. DWIN_Frame_AreaCopy(1, 1, 179, 271 - 179, 479 - 287 - 2, LBLX, MBASE(1)); // print speed
  562. DWIN_Frame_AreaCopy(1, 197, 104, 271 - 33, 479 - 365, LBLX, MBASE(2)); // Hotend...
  563. DWIN_Frame_AreaCopy(1, 1, 89, 271 - 188, 479 - 377 - 1, LBLX + 41 + 3, MBASE(2)); // ...Temperature
  564. DWIN_Frame_AreaCopy(1, 240, 104, 271 - 7, 479 - 365, LBLX, MBASE(3)); // Bed...
  565. DWIN_Frame_AreaCopy(1, 1, 89, 271 - 188, 479 - 377 - 1, LBLX + 24 + 3, MBASE(3)); // ...Temperature
  566. DWIN_Frame_AreaCopy(1, 0, 119, 271 - 207, 479 - 347, LBLX, MBASE(4)); // fan speed
  567. DWIN_Frame_AreaCopy(1, 93, 179, 271 - 130, 479 - 290, LBLX, MBASE(5)); // Z-offset
  568. }
  569. Draw_Back_First(select_tune.now == 0);
  570. if (select_tune.now) Draw_Menu_Cursor(select_tune.now);
  571. Draw_Menu_Line(1, ICON_Speed);
  572. Draw_Menu_Line(2, ICON_HotendTemp);
  573. Draw_Menu_Line(3, ICON_BedTemp);
  574. Draw_Menu_Line(4, ICON_FanSpeed);
  575. Draw_Menu_Line(5, ICON_Zoffset);
  576. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(1), feedrate_percentage);
  577. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2), thermalManager.temp_hotend[0].target);
  578. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3), thermalManager.temp_bed.target);
  579. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(4), thermalManager.fan_speed[0]);
  580. show_plus_or_minus(font8x16, Background_black, 2, 2, 202, MBASE(5), BABY_Z_VAR * 100);
  581. }
  582. inline void draw_max_en(const uint16_t line) {
  583. DWIN_Frame_AreaCopy(1, 245, 119, 271 - 2, 479 - 350, LBLX, line); // "Max"
  584. }
  585. inline void draw_max_accel_en(const uint16_t line) {
  586. draw_max_en(line);
  587. DWIN_Frame_AreaCopy(1, 1, 135, 271 - 192, 479 - 334, LBLX + 24 + 3, line); // "Acceleration"
  588. }
  589. inline void draw_speed_en(const uint16_t inset, const uint16_t line) {
  590. DWIN_Frame_AreaCopy(1, 184, 119, 224, 479 - 347, LBLX + inset, line); // "Speed"
  591. }
  592. inline void draw_corner_en(const uint16_t line) {
  593. DWIN_Frame_AreaCopy(1, 64, 119, 271 - 165, 479 - 350, LBLX + 24 + 3, line); // "Corner"
  594. }
  595. inline void draw_steps_per_mm(const uint16_t line) {
  596. DWIN_Frame_AreaCopy(1, 1, 151, 271 - 170, 479 - 318, LBLX, line); // "Steps-per-mm"
  597. }
  598. inline void say_x(const uint16_t inset, const uint16_t line) {
  599. DWIN_Frame_AreaCopy(1, 95, 104, 271 - 169, 479 - 365, LBLX + inset, line); // "X"
  600. }
  601. inline void say_y(const uint16_t inset, const uint16_t line) {
  602. DWIN_Frame_AreaCopy(1, 104, 104, 271 - 161, 479 - 365, LBLX + inset, line); // "Y"
  603. }
  604. inline void say_z(const uint16_t inset, const uint16_t line) {
  605. DWIN_Frame_AreaCopy(1, 112, 104, 271 - 151, 479 - 365, LBLX + inset, line); // "Z"
  606. }
  607. inline void say_e(const uint16_t inset, const uint16_t line) {
  608. DWIN_Frame_AreaCopy(1, 237, 119, 271 - 27, 479 - 350, LBLX + inset, line); // "E"
  609. }
  610. inline void Draw_Motion_Menu() {
  611. Clear_Main_Window();
  612. if (HMI_flag.language_flag) {
  613. DWIN_Frame_AreaCopy(1, 1, 16, 271 - 243, 479 - 451, 14, 8);
  614. DWIN_Frame_AreaCopy(1, 173, 133, 228, 479 - 332, LBLX, MBASE(1)); // max speed
  615. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(2)); // max...
  616. DWIN_Frame_AreaCopy(1, 28, 149, 271 - 202, 479 - 318, LBLX + 27, MBASE(2) + 1); // ...acceleration
  617. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(3)); // max...
  618. DWIN_Frame_AreaCopy(1, 1, 180, 271 - 243, 479 - 287, LBLX + 27, MBASE(3) + 1); // ...
  619. DWIN_Frame_AreaCopy(1, 202, 133, 228, 479 - 332, LBLX + 54, MBASE(3)); // ...jerk
  620. DWIN_Frame_AreaCopy(1, 153, 148, 271 - 77, 479 - 318, LBLX, MBASE(4)); // flow ratio
  621. }
  622. else {
  623. #ifdef USE_STRING_HEADINGS
  624. Draw_Title("Motion"); // TODO: GET_TEXT_F
  625. #else
  626. DWIN_Frame_AreaCopy(1, 144, 16, 271 - 82, 479 - 453, 14, 8);
  627. #endif
  628. draw_max_en(MBASE(1)); draw_speed_en(24 + 3, MBASE(1)); // "Max Speed"
  629. draw_max_accel_en(MBASE(2)); // "Max Acceleration"
  630. draw_max_en(MBASE(3)); draw_corner_en(MBASE(3)); // "Max Corner"
  631. draw_steps_per_mm(MBASE(4)); // "Steps-per-mm"
  632. }
  633. Draw_Back_First(select_motion.now == 0);
  634. if (select_motion.now) Draw_Menu_Cursor(select_motion.now);
  635. LOOP_L_N(i, 4) Draw_Menu_Line(i + 1, ICON_MaxSpeed + i);
  636. Draw_More_Icon(1);
  637. Draw_More_Icon(2);
  638. Draw_More_Icon(3);
  639. Draw_More_Icon(4);
  640. }
  641. //
  642. // Draw Popup Windows
  643. //
  644. void Popup_Window_Temperature(const bool toohigh) {
  645. Clear_Popup_Area();
  646. Draw_Popup_Bkgd_105();
  647. if (toohigh) {
  648. DWIN_ICON_Show(ICON, ICON_TempTooHigh, 102, 165);
  649. if (HMI_flag.language_flag) {
  650. DWIN_Frame_AreaCopy(1, 103, 371, 237, 479 - 93, 52, 285);
  651. DWIN_Frame_AreaCopy(1, 151, 389, 185, 402, 187, 285);
  652. DWIN_Frame_AreaCopy(1, 189, 389, 271 - 0, 402, 95, 310);
  653. }
  654. else {
  655. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 36, 300, (char*)"Nozzle or Bed temperature");
  656. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 92, 300, (char*)"is too high");
  657. }
  658. }
  659. else {
  660. DWIN_ICON_Show(ICON, ICON_TempTooLow, 102, 165);
  661. if (HMI_flag.language_flag) {
  662. DWIN_Frame_AreaCopy(1, 103, 371, 271 - 1, 479 - 93, 52, 285);
  663. DWIN_Frame_AreaCopy(1, 189, 389, 271 - 0, 402, 95, 310);
  664. }
  665. else {
  666. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 36, 300, (char*)"Nozzle or Bed temperature");
  667. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 92, 300, (char*)"is too low");
  668. }
  669. }
  670. }
  671. inline void Draw_Popup_Bkgd_60() {
  672. DWIN_Draw_Rectangle(1, Background_window, 14, 60, 271 - 13, 330);
  673. }
  674. #if HAS_HOTEND
  675. void Popup_Window_ETempTooLow(void) {
  676. Clear_Main_Window();
  677. Draw_Popup_Bkgd_60();
  678. DWIN_ICON_Show(ICON, ICON_TempTooLow, 102, 105);
  679. if (HMI_flag.language_flag) {
  680. DWIN_Frame_AreaCopy(1, 103, 371, 136, 479 - 93, 69, 240);
  681. DWIN_Frame_AreaCopy(1, 170, 371, 271 - 1, 479 - 93, 69 + 33, 240);
  682. DWIN_ICON_Show(ICON, ICON_Confirm_C, 86, 280);
  683. }
  684. else {
  685. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 20, 235, (char*)"Nozzle is too cold");
  686. DWIN_ICON_Show(ICON, ICON_Confirm_E, 86, 280);
  687. }
  688. }
  689. #endif
  690. void Popup_Window_Resume(void) {
  691. Clear_Popup_Area();
  692. Draw_Popup_Bkgd_105();
  693. if (HMI_flag.language_flag) {
  694. DWIN_Frame_AreaCopy(1, 160, 338, 271 - 36, 479 - 125, 98, 135);
  695. DWIN_Frame_AreaCopy(1, 103, 321, 271 - 0, 479 - 144, 52, 192);
  696. DWIN_ICON_Show(ICON, ICON_Continue_C, 26, 307);
  697. DWIN_ICON_Show(ICON, ICON_Cancel_C, 146, 307);
  698. }
  699. else {
  700. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 120, 115, (char*)"Tips");
  701. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 24, 192, (char*)"I see the file stopped");
  702. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 68, 212, (char*)"unexpectedly last time");
  703. DWIN_ICON_Show(ICON, ICON_Continue_E, 26, 307);
  704. DWIN_ICON_Show(ICON, ICON_Cancel_E, 146, 307);
  705. }
  706. }
  707. void Popup_Window_Home(void) {
  708. Clear_Main_Window();
  709. Draw_Popup_Bkgd_60();
  710. DWIN_ICON_Show(ICON, ICON_BLTouch, 101, 105);
  711. if (HMI_flag.language_flag) {
  712. DWIN_Frame_AreaCopy(1, 0, 371, 33, 386, 85, 240);
  713. DWIN_Frame_AreaCopy(1, 203, 286, 271, 302, 118, 240);
  714. DWIN_Frame_AreaCopy(1, 0, 389, 150, 402, 61, 280);
  715. }
  716. else {
  717. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 80, 230, (char*)"Auto homing...");
  718. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 24, 260, (char*)"Please wait until completed");
  719. }
  720. }
  721. void Popup_Window_Leveling(void) {
  722. Clear_Main_Window();
  723. Draw_Popup_Bkgd_60();
  724. DWIN_ICON_Show(ICON, ICON_AutoLeveling, 101, 105);
  725. if (HMI_flag.language_flag) {
  726. DWIN_Frame_AreaCopy(1, 0, 371, 100, 386, 84, 240);
  727. DWIN_Frame_AreaCopy(1, 0, 389, 150, 402, 61, 280);
  728. }
  729. else {
  730. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 76, 230, (char*)"Auto leveling...");
  731. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 24, 260, (char*)"Please wait until completed");
  732. }
  733. }
  734. void Draw_Select_Highlight(const bool sel) {
  735. HMI_flag.select_flag = sel;
  736. const uint16_t c1 = sel ? Select_Color : Background_window,
  737. c2 = sel ? Background_window : Select_Color;
  738. DWIN_Draw_Rectangle(0, c1, 25, 279, 126, 318);
  739. DWIN_Draw_Rectangle(0, c1, 24, 278, 127, 319);
  740. DWIN_Draw_Rectangle(0, c2, 145, 279, 246, 318);
  741. DWIN_Draw_Rectangle(0, c2, 144, 278, 247, 319);
  742. }
  743. void Popup_window_PauseOrStop(void) {
  744. Clear_Main_Window();
  745. Draw_Popup_Bkgd_60();
  746. if (HMI_flag.language_flag) {
  747. if (select_print.now == 1) DWIN_Frame_AreaCopy(1, 237, 338, 269, 356, 98, 150);
  748. else if (select_print.now == 2) DWIN_Frame_AreaCopy(1, 221, 320, 253, 336, 98, 150);
  749. DWIN_Frame_AreaCopy(1, 220, 304, 264, 319, 130, 150);
  750. DWIN_ICON_Show(ICON, ICON_Confirm_C, 26, 280);
  751. DWIN_ICON_Show(ICON, ICON_Cancel_C, 146, 280);
  752. }
  753. else {
  754. if (select_print.now == 1) DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 88, 150, (char*)"Pause print?");
  755. else if (select_print.now == 2) DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, 92, 150, (char*)"Stop print?");
  756. DWIN_ICON_Show(ICON, ICON_Confirm_E, 26, 280);
  757. DWIN_ICON_Show(ICON, ICON_Cancel_E, 146, 280);
  758. }
  759. Draw_Select_Highlight(true);
  760. }
  761. void Draw_Printing_Screen(void) {
  762. if (HMI_flag.language_flag) {
  763. DWIN_Frame_AreaCopy(1, 30, 1, 271 - 200, 479 - 465, 14, 9);// Tune
  764. DWIN_Frame_AreaCopy(1, 0, 72, 271 - 208, 479 - 393, 41, 188);// Pause
  765. DWIN_Frame_AreaCopy(1, 65, 72, 271 - 143, 479 - 393, 176, 188); // Stop
  766. }
  767. else {
  768. DWIN_Frame_AreaCopy(1, 40, 2, 271 - 179, 479 - 464 - 1, 14, 9);// Tune
  769. DWIN_Frame_AreaCopy(1, 0, 44, 271 - 175, 479 - 420 - 1, 41, 188);// Pause
  770. DWIN_Frame_AreaCopy(1, 98, 44, 271 - 119, 479 - 420 - 1, 176, 188); // Stop
  771. }
  772. }
  773. void Draw_Print_ProgressBar() {
  774. DWIN_ICON_Show(ICON, ICON_Bar, 15, 93);
  775. DWIN_Draw_Rectangle(1, BarFill_Color, 16 + Percentrecord * 240 / 100, 93, 256, 113);
  776. DWIN_Draw_IntValue(true, true, 0, font8x16, Percent_Color, Background_black, 2, 117, 133, Percentrecord);
  777. DWIN_Draw_String(false, false, font8x16, Percent_Color, Background_black, 117 + 16, 133, (char*)"%");
  778. }
  779. void Draw_Print_ProgressElapsed() {
  780. duration_t elapsed = print_job_timer.duration(); // print timer
  781. DWIN_Draw_IntValue(true, true, 1, font8x16, White, Background_black, 2, 42, 212, elapsed.value / 3600);
  782. DWIN_Draw_String(false, false, font8x16, White, Background_black, 42 + 16, 212, (char*)":");
  783. DWIN_Draw_IntValue(true, true, 1, font8x16, White, Background_black, 2, 42 + 24, 212, (elapsed.value % 3600) / 60);
  784. }
  785. void Draw_Print_ProgressRemain() {
  786. DWIN_Draw_IntValue(true, true, 1, font8x16, White, Background_black, 2, 176, 212, remain_time / 3600);
  787. DWIN_Draw_String(false, false, font8x16, White, Background_black, 176 + 16, 212, (char*)":");
  788. DWIN_Draw_IntValue(true, true, 1, font8x16, White, Background_black, 2, 176 + 24, 212, (remain_time % 3600) / 60);
  789. }
  790. void Goto_PrintProcess(void) {
  791. checkkey = PrintProcess;
  792. Clear_Main_Window();
  793. Draw_Printing_Screen();
  794. ICON_Tune();
  795. if (printingIsPaused()) ICON_Continue(); else ICON_Pause();
  796. ICON_Stop();
  797. // Copy into filebuf string before entry
  798. char * const name = card.longest_filename();
  799. DWIN_Draw_String(false, false, font8x16, White, Background_black, (DWIN_WIDTH - strlen(name) * MENU_CHR_W) / 2, 60, name);
  800. DWIN_ICON_Show(ICON, ICON_PrintTime, 17, 193);
  801. DWIN_ICON_Show(ICON, ICON_RemainTime, 150, 191);
  802. Draw_Print_ProgressBar();
  803. Draw_Print_ProgressElapsed();
  804. Draw_Print_ProgressRemain();
  805. }
  806. void Goto_MainMenu(void) {
  807. checkkey = MainMenu;
  808. Clear_Main_Window();
  809. if (HMI_flag.language_flag) {
  810. DWIN_Frame_AreaCopy(1, 2, 2, 271 - 244, 479 - 465, 14, 9); // "Home"
  811. }
  812. else {
  813. #ifdef USE_STRING_HEADINGS
  814. Draw_Title("Home"); // TODO: GET_TEXT
  815. #else
  816. DWIN_Frame_AreaCopy(1, 0, 2, 271 - 232, 479 - 467, 14, 9);
  817. #endif
  818. }
  819. DWIN_ICON_Show(ICON, ICON_LOGO, 71, 52);
  820. ICON_Print();
  821. ICON_Prepare();
  822. ICON_Control();
  823. TERN(HAS_LEVELING, ICON_Leveling, ICON_StartInfo)(select_page.now == 3);
  824. }
  825. inline ENCODER_DiffState get_encoder_state() {
  826. const millis_t ms = millis();
  827. if (PENDING(ms, Encoder_ms)) return ENCODER_DIFF_NO;
  828. const ENCODER_DiffState state = Encoder_ReceiveAnalyze();
  829. if (state != ENCODER_DIFF_NO) Encoder_ms = ms + ENCODER_WAIT;
  830. return state;
  831. }
  832. void HMI_Move_X(void) {
  833. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  834. if (encoder_diffState != ENCODER_DIFF_NO) {
  835. if (encoder_diffState == ENCODER_DIFF_CW) {
  836. HMI_ValueStruct.Move_X_scale += EncoderRate.encoderMoveValue;
  837. }
  838. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  839. HMI_ValueStruct.Move_X_scale -= EncoderRate.encoderMoveValue;
  840. }
  841. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  842. checkkey = AxisMove;
  843. EncoderRate.encoderRateEnabled = 0;
  844. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 216, MBASE(1), HMI_ValueStruct.Move_X_scale);
  845. if (!planner.is_full()) {
  846. // Wait for planner moves to finish!
  847. planner.synchronize();
  848. planner.buffer_line(current_position, MMM_TO_MMS(HOMING_FEEDRATE_XY), active_extruder);
  849. }
  850. DWIN_UpdateLCD();
  851. return;
  852. }
  853. NOLESS(HMI_ValueStruct.Move_X_scale, (X_MIN_POS) * MINUNITMULT);
  854. NOMORE(HMI_ValueStruct.Move_X_scale, (X_MAX_POS) * MINUNITMULT);
  855. current_position[X_AXIS] = HMI_ValueStruct.Move_X_scale / 10;
  856. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 216, MBASE(1), HMI_ValueStruct.Move_X_scale);
  857. DWIN_UpdateLCD();
  858. }
  859. }
  860. void HMI_Move_Y(void) {
  861. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  862. if (encoder_diffState != ENCODER_DIFF_NO) {
  863. if (encoder_diffState == ENCODER_DIFF_CW) {
  864. HMI_ValueStruct.Move_Y_scale += EncoderRate.encoderMoveValue;
  865. }
  866. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  867. HMI_ValueStruct.Move_Y_scale -= EncoderRate.encoderMoveValue;
  868. }
  869. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  870. checkkey = AxisMove;
  871. EncoderRate.encoderRateEnabled = 0;
  872. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale);
  873. if (!planner.is_full()) {
  874. // Wait for planner moves to finish!
  875. planner.synchronize();
  876. planner.buffer_line(current_position, MMM_TO_MMS(HOMING_FEEDRATE_XY), active_extruder);
  877. }
  878. DWIN_UpdateLCD();
  879. return;
  880. }
  881. NOLESS(HMI_ValueStruct.Move_Y_scale, (Y_MIN_POS) * MINUNITMULT);
  882. NOMORE(HMI_ValueStruct.Move_Y_scale, (Y_MAX_POS) * MINUNITMULT);
  883. current_position[Y_AXIS] = HMI_ValueStruct.Move_Y_scale / 10;
  884. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale);
  885. DWIN_UpdateLCD();
  886. }
  887. }
  888. void HMI_Move_Z(void) {
  889. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  890. if (encoder_diffState != ENCODER_DIFF_NO) {
  891. if (encoder_diffState == ENCODER_DIFF_CW) {
  892. HMI_ValueStruct.Move_Z_scale += EncoderRate.encoderMoveValue;
  893. }
  894. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  895. HMI_ValueStruct.Move_Z_scale -= EncoderRate.encoderMoveValue;
  896. }
  897. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  898. checkkey = AxisMove;
  899. EncoderRate.encoderRateEnabled = 0;
  900. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale);
  901. if (!planner.is_full()) {
  902. // Wait for planner moves to finish!
  903. planner.synchronize();
  904. planner.buffer_line(current_position, MMM_TO_MMS(HOMING_FEEDRATE_Z), active_extruder);
  905. }
  906. DWIN_UpdateLCD();
  907. return;
  908. }
  909. NOLESS(HMI_ValueStruct.Move_Z_scale, Z_MIN_POS * MINUNITMULT);
  910. NOMORE(HMI_ValueStruct.Move_Z_scale, Z_MAX_POS * MINUNITMULT);
  911. current_position[Z_AXIS] = HMI_ValueStruct.Move_Z_scale / 10;
  912. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale);
  913. DWIN_UpdateLCD();
  914. }
  915. }
  916. void HMI_Move_E(void) {
  917. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  918. if (encoder_diffState != ENCODER_DIFF_NO) {
  919. if (encoder_diffState == ENCODER_DIFF_CW) {
  920. HMI_ValueStruct.Move_E_scale += EncoderRate.encoderMoveValue;
  921. }
  922. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  923. HMI_ValueStruct.Move_E_scale -= EncoderRate.encoderMoveValue;
  924. }
  925. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  926. checkkey = AxisMove;
  927. EncoderRate.encoderRateEnabled = 0;
  928. last_E_scale = HMI_ValueStruct.Move_E_scale;
  929. show_plus_or_minus(font8x16, Background_black, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale);
  930. if (!planner.is_full()) {
  931. planner.synchronize(); // Wait for planner moves to finish!
  932. planner.buffer_line(current_position, MMM_TO_MMS(FEEDRATE_E), active_extruder);
  933. }
  934. DWIN_UpdateLCD();
  935. return;
  936. }
  937. if ((HMI_ValueStruct.Move_E_scale - last_E_scale) > (EXTRUDE_MAXLENGTH) * MINUNITMULT)
  938. HMI_ValueStruct.Move_E_scale = last_E_scale + (EXTRUDE_MAXLENGTH) * MINUNITMULT;
  939. else if ((last_E_scale - HMI_ValueStruct.Move_E_scale) > (EXTRUDE_MAXLENGTH) * MINUNITMULT)
  940. HMI_ValueStruct.Move_E_scale = last_E_scale - (EXTRUDE_MAXLENGTH) * MINUNITMULT;
  941. current_position.e = HMI_ValueStruct.Move_E_scale / 10;
  942. show_plus_or_minus(font8x16, Select_Color, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale);
  943. DWIN_UpdateLCD();
  944. }
  945. }
  946. void HMI_Zoffset(void) {
  947. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  948. if (encoder_diffState != ENCODER_DIFF_NO) {
  949. last_zoffset = zprobe_zoffset;
  950. if (encoder_diffState == ENCODER_DIFF_CW) {
  951. HMI_ValueStruct.offset_value += EncoderRate.encoderMoveValue;
  952. }
  953. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  954. HMI_ValueStruct.offset_value -= EncoderRate.encoderMoveValue;
  955. }
  956. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  957. EncoderRate.encoderRateEnabled = 0;
  958. zprobe_zoffset = HMI_ValueStruct.offset_value / 100;
  959. #if HAS_BED_PROBE
  960. if (WITHIN(zprobe_zoffset - last_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX))
  961. probe.offset.z = zprobe_zoffset;
  962. settings.save();
  963. #elif ENABLED(BABYSTEPPING)
  964. babystep.add_mm(Z_AXIS, (zprobe_zoffset - last_zoffset));
  965. #else
  966. UNUSED(zprobe_zoffset - last_zoffset);
  967. #endif
  968. if (HMI_ValueStruct.show_mode == -4) {
  969. checkkey = Prepare;
  970. show_plus_or_minus(font8x16, Background_black, 2, 2, 202, MBASE(4 + MROWS - index_prepare), TERN(HAS_LEVELING, probe.offset.z * 100, HMI_ValueStruct.offset_value));
  971. }
  972. else {
  973. checkkey = Tune;
  974. show_plus_or_minus(font8x16, Background_black, 2, 2, 202, MBASE(5 + MROWS - index_tune), TERN(HAS_LEVELING, probe.offset.z * 100, HMI_ValueStruct.offset_value));
  975. }
  976. DWIN_UpdateLCD();
  977. return;
  978. }
  979. NOLESS(HMI_ValueStruct.offset_value, (Z_PROBE_OFFSET_RANGE_MIN) * 100);
  980. NOMORE(HMI_ValueStruct.offset_value, (Z_PROBE_OFFSET_RANGE_MAX) * 100);
  981. if (HMI_ValueStruct.show_mode == -4)
  982. show_plus_or_minus(font8x16, Select_Color, 2, 2, 202, MBASE(4 + MROWS - index_prepare), HMI_ValueStruct.offset_value);
  983. else
  984. show_plus_or_minus(font8x16, Select_Color, 2, 2, 202, MBASE(5 + MROWS - index_tune), HMI_ValueStruct.offset_value);
  985. DWIN_UpdateLCD();
  986. }
  987. }
  988. #if HAS_HOTEND
  989. void HMI_ETemp(void) {
  990. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  991. if (encoder_diffState != ENCODER_DIFF_NO) {
  992. if (encoder_diffState == ENCODER_DIFF_CW) {
  993. HMI_ValueStruct.E_Temp += EncoderRate.encoderMoveValue;
  994. }
  995. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  996. HMI_ValueStruct.E_Temp -= EncoderRate.encoderMoveValue;
  997. }
  998. else if (encoder_diffState == ENCODER_DIFF_ENTER) { // return
  999. EncoderRate.encoderRateEnabled = 0;
  1000. if (HMI_ValueStruct.show_mode == -1) { // temperature
  1001. checkkey = TemperatureID;
  1002. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(1), HMI_ValueStruct.E_Temp);
  1003. }
  1004. else if (HMI_ValueStruct.show_mode == -2) {
  1005. checkkey = PLAPreheat;
  1006. ui.material_preset[0].hotend_temp = HMI_ValueStruct.E_Temp;
  1007. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(1), ui.material_preset[0].hotend_temp);
  1008. return;
  1009. }
  1010. else if (HMI_ValueStruct.show_mode == -3) {
  1011. checkkey = ABSPreheat;
  1012. ui.material_preset[1].hotend_temp = HMI_ValueStruct.E_Temp;
  1013. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(1), ui.material_preset[1].hotend_temp);
  1014. return;
  1015. }
  1016. else { // tune
  1017. checkkey = Tune;
  1018. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2 + MROWS - index_tune), HMI_ValueStruct.E_Temp);
  1019. }
  1020. thermalManager.setTargetHotend(HMI_ValueStruct.E_Temp, 0);
  1021. return;
  1022. }
  1023. // E_Temp limit
  1024. NOMORE(HMI_ValueStruct.E_Temp, MAX_E_TEMP);
  1025. NOLESS(HMI_ValueStruct.E_Temp, MIN_E_TEMP);
  1026. // E_Temp value
  1027. if (HMI_ValueStruct.show_mode >= 0) // tune
  1028. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(2 + MROWS - index_tune), HMI_ValueStruct.E_Temp);
  1029. else // other page
  1030. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(1), HMI_ValueStruct.E_Temp);
  1031. }
  1032. }
  1033. #endif // if HAS_HOTEND
  1034. #if HAS_HEATED_BED
  1035. void HMI_BedTemp(void) {
  1036. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  1037. if (encoder_diffState != ENCODER_DIFF_NO) {
  1038. if (encoder_diffState == ENCODER_DIFF_CW) {
  1039. HMI_ValueStruct.Bed_Temp += EncoderRate.encoderMoveValue;
  1040. }
  1041. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1042. HMI_ValueStruct.Bed_Temp -= EncoderRate.encoderMoveValue;
  1043. }
  1044. else if (encoder_diffState == ENCODER_DIFF_ENTER) { // return
  1045. EncoderRate.encoderRateEnabled = 0;
  1046. if (HMI_ValueStruct.show_mode == -1) {
  1047. checkkey = TemperatureID;
  1048. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2), HMI_ValueStruct.Bed_Temp);
  1049. }
  1050. else if (HMI_ValueStruct.show_mode == -2) {
  1051. checkkey = PLAPreheat;
  1052. ui.material_preset[0].bed_temp = HMI_ValueStruct.Bed_Temp;
  1053. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2), ui.material_preset[0].bed_temp);
  1054. return;
  1055. }
  1056. else if (HMI_ValueStruct.show_mode == -3) {
  1057. checkkey = ABSPreheat;
  1058. ui.material_preset[1].bed_temp = HMI_ValueStruct.Bed_Temp;
  1059. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2), ui.material_preset[1].bed_temp);
  1060. return;
  1061. }
  1062. else {
  1063. checkkey = Tune;
  1064. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3 + MROWS - index_tune), HMI_ValueStruct.Bed_Temp);
  1065. }
  1066. thermalManager.setTargetBed(HMI_ValueStruct.Bed_Temp);
  1067. return;
  1068. }
  1069. // Bed_Temp limit
  1070. NOMORE(HMI_ValueStruct.Bed_Temp, BED_MAX_TARGET);
  1071. NOLESS(HMI_ValueStruct.Bed_Temp, MIN_BED_TEMP);
  1072. // Bed_Temp value
  1073. if (HMI_ValueStruct.show_mode >= 0) // tune page
  1074. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(3 + MROWS - index_tune), HMI_ValueStruct.Bed_Temp);
  1075. else // other page
  1076. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(2), HMI_ValueStruct.Bed_Temp);
  1077. }
  1078. }
  1079. #endif // if HAS_HEATED_BED
  1080. #if HAS_FAN
  1081. void HMI_FanSpeed(void) {
  1082. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  1083. if (encoder_diffState != ENCODER_DIFF_NO) {
  1084. if (encoder_diffState == ENCODER_DIFF_CW) {
  1085. HMI_ValueStruct.Fan_speed += EncoderRate.encoderMoveValue;
  1086. }
  1087. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1088. HMI_ValueStruct.Fan_speed -= EncoderRate.encoderMoveValue;
  1089. }
  1090. else if (encoder_diffState == ENCODER_DIFF_ENTER) { // return
  1091. EncoderRate.encoderRateEnabled = 0;
  1092. if (HMI_ValueStruct.show_mode == -1) {
  1093. checkkey = TemperatureID;
  1094. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3), HMI_ValueStruct.Fan_speed);
  1095. }
  1096. else if (HMI_ValueStruct.show_mode == -2) {
  1097. checkkey = PLAPreheat;
  1098. ui.material_preset[0].fan_speed = HMI_ValueStruct.Fan_speed;
  1099. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3), ui.material_preset[0].fan_speed);
  1100. return;
  1101. }
  1102. else if (HMI_ValueStruct.show_mode == -3) {
  1103. checkkey = ABSPreheat;
  1104. ui.material_preset[1].fan_speed = HMI_ValueStruct.Fan_speed;
  1105. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3), ui.material_preset[1].fan_speed);
  1106. return;
  1107. }
  1108. else {
  1109. checkkey = Tune;
  1110. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(4 + MROWS - index_tune), HMI_ValueStruct.Fan_speed);
  1111. }
  1112. thermalManager.set_fan_speed(0, HMI_ValueStruct.Fan_speed);
  1113. return;
  1114. }
  1115. // Fan_speed limit
  1116. NOMORE(HMI_ValueStruct.Fan_speed, FANON);
  1117. NOLESS(HMI_ValueStruct.Fan_speed, FANOFF);
  1118. // Fan_speed value
  1119. if (HMI_ValueStruct.show_mode >= 0) // tune page
  1120. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(4 + MROWS - index_tune), HMI_ValueStruct.Fan_speed);
  1121. else // other page
  1122. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(3), HMI_ValueStruct.Fan_speed);
  1123. }
  1124. }
  1125. #endif // if HAS_FAN
  1126. void HMI_PrintSpeed(void) {
  1127. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  1128. if (encoder_diffState != ENCODER_DIFF_NO) {
  1129. if (encoder_diffState == ENCODER_DIFF_CW) {
  1130. HMI_ValueStruct.print_speed += EncoderRate.encoderMoveValue;
  1131. }
  1132. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1133. HMI_ValueStruct.print_speed -= EncoderRate.encoderMoveValue;
  1134. }
  1135. else if (encoder_diffState == ENCODER_DIFF_ENTER) { // return
  1136. checkkey = Tune;
  1137. EncoderRate.encoderRateEnabled = 0;
  1138. feedrate_percentage = HMI_ValueStruct.print_speed;
  1139. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(1 + MROWS - index_tune), HMI_ValueStruct.print_speed);
  1140. return;
  1141. }
  1142. // print_speed limit
  1143. NOMORE(HMI_ValueStruct.print_speed, MAX_PRINT_SPEED);
  1144. NOLESS(HMI_ValueStruct.print_speed, MIN_PRINT_SPEED);
  1145. // print_speed value
  1146. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(1 + MROWS - index_tune), HMI_ValueStruct.print_speed);
  1147. }
  1148. }
  1149. void HMI_MaxFeedspeedXYZE(void) {
  1150. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  1151. if (encoder_diffState != ENCODER_DIFF_NO) {
  1152. if (encoder_diffState == ENCODER_DIFF_CW) {
  1153. HMI_ValueStruct.Max_Feedspeed += EncoderRate.encoderMoveValue;
  1154. }
  1155. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1156. HMI_ValueStruct.Max_Feedspeed -= EncoderRate.encoderMoveValue;
  1157. }
  1158. else if (encoder_diffState == ENCODER_DIFF_ENTER) { // return
  1159. checkkey = MaxSpeed;
  1160. EncoderRate.encoderRateEnabled = 0;
  1161. if (HMI_flag.feedspeed_flag == X_AXIS) planner.set_max_feedrate(X_AXIS, HMI_ValueStruct.Max_Feedspeed);
  1162. else if (HMI_flag.feedspeed_flag == Y_AXIS) planner.set_max_feedrate(Y_AXIS, HMI_ValueStruct.Max_Feedspeed);
  1163. else if (HMI_flag.feedspeed_flag == Z_AXIS) planner.set_max_feedrate(Z_AXIS, HMI_ValueStruct.Max_Feedspeed);
  1164. #if HAS_HOTEND
  1165. else if (HMI_flag.feedspeed_flag == E_AXIS) planner.set_max_feedrate(E_AXIS, HMI_ValueStruct.Max_Feedspeed);
  1166. #endif
  1167. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(select_speed.now), HMI_ValueStruct.Max_Feedspeed);
  1168. return;
  1169. }
  1170. // MaxFeedspeed limit
  1171. if (HMI_flag.feedspeed_flag == X_AXIS) {if (HMI_ValueStruct.Max_Feedspeed > default_max_feedrate[X_AXIS] * 2) HMI_ValueStruct.Max_Feedspeed = default_max_feedrate[X_AXIS] * 2; }
  1172. else if (HMI_flag.feedspeed_flag == Y_AXIS) {if (HMI_ValueStruct.Max_Feedspeed > default_max_feedrate[Y_AXIS] * 2) HMI_ValueStruct.Max_Feedspeed = default_max_feedrate[Y_AXIS] * 2; }
  1173. else if (HMI_flag.feedspeed_flag == Z_AXIS) {if (HMI_ValueStruct.Max_Feedspeed > default_max_feedrate[Z_AXIS] * 2) HMI_ValueStruct.Max_Feedspeed = default_max_feedrate[Z_AXIS] * 2; }
  1174. #if HAS_HOTEND
  1175. else if (HMI_flag.feedspeed_flag == E_AXIS) {if (HMI_ValueStruct.Max_Feedspeed > default_max_feedrate[E_AXIS] * 2) HMI_ValueStruct.Max_Feedspeed = default_max_feedrate[E_AXIS] * 2; }
  1176. #endif
  1177. if (HMI_ValueStruct.Max_Feedspeed < MIN_MAXFEEDSPEED) HMI_ValueStruct.Max_Feedspeed = MIN_MAXFEEDSPEED;
  1178. // MaxFeedspeed value
  1179. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_speed.now), HMI_ValueStruct.Max_Feedspeed);
  1180. }
  1181. }
  1182. void HMI_MaxAccelerationXYZE(void) {
  1183. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  1184. if (encoder_diffState != ENCODER_DIFF_NO) {
  1185. if (encoder_diffState == ENCODER_DIFF_CW) { HMI_ValueStruct.Max_Acceleration += EncoderRate.encoderMoveValue;}
  1186. else if (encoder_diffState == ENCODER_DIFF_CCW) { HMI_ValueStruct.Max_Acceleration -= EncoderRate.encoderMoveValue;}
  1187. else if (encoder_diffState == ENCODER_DIFF_ENTER) { // return
  1188. checkkey = MaxAcceleration;
  1189. EncoderRate.encoderRateEnabled = 0;
  1190. if (HMI_flag.acc_flag == X_AXIS) planner.set_max_acceleration(X_AXIS, HMI_ValueStruct.Max_Acceleration);
  1191. else if (HMI_flag.acc_flag == Y_AXIS) planner.set_max_acceleration(Y_AXIS, HMI_ValueStruct.Max_Acceleration);
  1192. else if (HMI_flag.acc_flag == Z_AXIS) planner.set_max_acceleration(Z_AXIS, HMI_ValueStruct.Max_Acceleration);
  1193. #if HAS_HOTEND
  1194. else if (HMI_flag.acc_flag == E_AXIS) planner.set_max_acceleration(E_AXIS, HMI_ValueStruct.Max_Acceleration);
  1195. #endif
  1196. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(select_acc.now), HMI_ValueStruct.Max_Acceleration);
  1197. return;
  1198. }
  1199. // MaxAcceleration limit
  1200. if (HMI_flag.acc_flag == X_AXIS) {if (HMI_ValueStruct.Max_Acceleration > default_max_acceleration[X_AXIS] * 2) HMI_ValueStruct.Max_Acceleration = default_max_acceleration[X_AXIS] * 2; }
  1201. else if (HMI_flag.acc_flag == Y_AXIS) {if (HMI_ValueStruct.Max_Acceleration > default_max_acceleration[Y_AXIS] * 2) HMI_ValueStruct.Max_Acceleration = default_max_acceleration[Y_AXIS] * 2; }
  1202. else if (HMI_flag.acc_flag == Z_AXIS) {if (HMI_ValueStruct.Max_Acceleration > default_max_acceleration[Z_AXIS] * 2) HMI_ValueStruct.Max_Acceleration = default_max_acceleration[Z_AXIS] * 2; }
  1203. #if HAS_HOTEND
  1204. else if (HMI_flag.acc_flag == E_AXIS) {if (HMI_ValueStruct.Max_Acceleration > default_max_acceleration[E_AXIS] * 2) HMI_ValueStruct.Max_Acceleration = default_max_acceleration[E_AXIS] * 2; }
  1205. #endif
  1206. if (HMI_ValueStruct.Max_Acceleration < MIN_MAXACCELERATION) HMI_ValueStruct.Max_Acceleration = MIN_MAXACCELERATION;
  1207. // MaxAcceleration value
  1208. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_acc.now), HMI_ValueStruct.Max_Acceleration);
  1209. }
  1210. }
  1211. void HMI_MaxCornerXYZE(void) {
  1212. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  1213. if (encoder_diffState != ENCODER_DIFF_NO) {
  1214. if (encoder_diffState == ENCODER_DIFF_CW) {
  1215. HMI_ValueStruct.Max_Corner += EncoderRate.encoderMoveValue;
  1216. }
  1217. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1218. HMI_ValueStruct.Max_Corner -= EncoderRate.encoderMoveValue;
  1219. }
  1220. else if (encoder_diffState == ENCODER_DIFF_ENTER) { // return
  1221. checkkey = MaxCorner;
  1222. EncoderRate.encoderRateEnabled = 0;
  1223. if (HMI_flag.corner_flag == X_AXIS) planner.set_max_jerk(X_AXIS, HMI_ValueStruct.Max_Corner / 10);
  1224. else if (HMI_flag.corner_flag == Y_AXIS) planner.set_max_jerk(Y_AXIS, HMI_ValueStruct.Max_Corner / 10);
  1225. else if (HMI_flag.corner_flag == Z_AXIS) planner.set_max_jerk(Z_AXIS, HMI_ValueStruct.Max_Corner / 10);
  1226. else if (HMI_flag.corner_flag == E_AXIS) planner.set_max_jerk(E_AXIS, HMI_ValueStruct.Max_Corner / 10);
  1227. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(select_corner.now), HMI_ValueStruct.Max_Corner);
  1228. return;
  1229. }
  1230. // MaxCorner limit
  1231. if (HMI_flag.corner_flag == X_AXIS)
  1232. NOMORE(HMI_ValueStruct.Max_Corner, default_max_jerk[X_AXIS] * 2 * MINUNITMULT);
  1233. else if (HMI_flag.corner_flag == Y_AXIS)
  1234. NOMORE(HMI_ValueStruct.Max_Corner, default_max_jerk[Y_AXIS] * 2 * MINUNITMULT);
  1235. else if (HMI_flag.corner_flag == Z_AXIS)
  1236. NOMORE(HMI_ValueStruct.Max_Corner, default_max_jerk[Z_AXIS] * 2 * MINUNITMULT);
  1237. else if (HMI_flag.corner_flag == E_AXIS)
  1238. NOMORE(HMI_ValueStruct.Max_Corner, default_max_jerk[E_AXIS] * 2 * MINUNITMULT);
  1239. NOLESS(HMI_ValueStruct.Max_Corner, (MIN_MAXCORNER) * MINUNITMULT);
  1240. // MaxCorner value
  1241. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_corner.now), HMI_ValueStruct.Max_Corner);
  1242. }
  1243. }
  1244. void HMI_StepXYZE(void) {
  1245. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  1246. if (encoder_diffState != ENCODER_DIFF_NO) {
  1247. if (encoder_diffState == ENCODER_DIFF_CW) {
  1248. HMI_ValueStruct.Max_Step += EncoderRate.encoderMoveValue;
  1249. }
  1250. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1251. HMI_ValueStruct.Max_Step -= EncoderRate.encoderMoveValue;
  1252. }
  1253. else if (encoder_diffState == ENCODER_DIFF_ENTER) { // return
  1254. checkkey = Step;
  1255. EncoderRate.encoderRateEnabled = 0;
  1256. if (HMI_flag.step_flag == X_AXIS) planner.settings.axis_steps_per_mm[X_AXIS] = HMI_ValueStruct.Max_Step / 10;
  1257. else if (HMI_flag.step_flag == Y_AXIS) planner.settings.axis_steps_per_mm[Y_AXIS] = HMI_ValueStruct.Max_Step / 10;
  1258. else if (HMI_flag.step_flag == Z_AXIS) planner.settings.axis_steps_per_mm[Z_AXIS] = HMI_ValueStruct.Max_Step / 10;
  1259. else if (HMI_flag.step_flag == E_AXIS) planner.settings.axis_steps_per_mm[E_AXIS] = HMI_ValueStruct.Max_Step / 10;
  1260. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step);
  1261. return;
  1262. }
  1263. // Step limit
  1264. if (HMI_flag.step_flag == X_AXIS)
  1265. NOMORE(HMI_ValueStruct.Max_Step, default_axis_steps_per_unit[X_AXIS] * 2 * MINUNITMULT);
  1266. else if (HMI_flag.step_flag == Y_AXIS)
  1267. NOMORE(HMI_ValueStruct.Max_Step, default_axis_steps_per_unit[Y_AXIS] * 2 * MINUNITMULT);
  1268. else if (HMI_flag.step_flag == Z_AXIS)
  1269. NOMORE(HMI_ValueStruct.Max_Step, default_axis_steps_per_unit[Z_AXIS] * 2 * MINUNITMULT);
  1270. else if (HMI_flag.step_flag == E_AXIS)
  1271. NOMORE(HMI_ValueStruct.Max_Step, default_axis_steps_per_unit[E_AXIS] * 2 * MINUNITMULT);
  1272. NOLESS(HMI_ValueStruct.Max_Step, MIN_STEP);
  1273. // Step value
  1274. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step);
  1275. }
  1276. }
  1277. void update_variable(void) {
  1278. /* Tune page temperature update */
  1279. if (checkkey == Tune) {
  1280. if (last_temp_hotend_target != thermalManager.temp_hotend[0].target)
  1281. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2 + MROWS - index_tune), thermalManager.temp_hotend[0].target);
  1282. if (last_temp_bed_target != thermalManager.temp_bed.target)
  1283. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3 + MROWS - index_tune), thermalManager.temp_bed.target);
  1284. if (last_fan_speed != thermalManager.fan_speed[0]) {
  1285. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(4 + MROWS - index_tune), thermalManager.fan_speed[0]);
  1286. last_fan_speed = thermalManager.fan_speed[0];
  1287. }
  1288. }
  1289. /* Temperature page temperature update */
  1290. if (checkkey == TemperatureID) {
  1291. if (last_temp_hotend_target != thermalManager.temp_hotend[0].target)
  1292. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(1), thermalManager.temp_hotend[0].target);
  1293. if (last_temp_bed_target != thermalManager.temp_bed.target)
  1294. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2), thermalManager.temp_bed.target);
  1295. if (last_fan_speed != thermalManager.fan_speed[0]) {
  1296. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3), thermalManager.fan_speed[0]);
  1297. last_fan_speed = thermalManager.fan_speed[0];
  1298. }
  1299. }
  1300. /* Bottom temperature update */
  1301. if (last_temp_hotend_current != thermalManager.temp_hotend[0].celsius) {
  1302. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 33, 382, thermalManager.temp_hotend[0].celsius);
  1303. last_temp_hotend_current = thermalManager.temp_hotend[0].celsius;
  1304. }
  1305. if (last_temp_hotend_target != thermalManager.temp_hotend[0].target) {
  1306. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 33 + 4 * STAT_CHR_W + 6, 382, thermalManager.temp_hotend[0].target);
  1307. last_temp_hotend_target = thermalManager.temp_hotend[0].target;
  1308. }
  1309. if (last_temp_bed_current != thermalManager.temp_bed.celsius) {
  1310. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 178, 382, thermalManager.temp_bed.celsius);
  1311. last_temp_bed_current = thermalManager.temp_bed.celsius;
  1312. }
  1313. if (last_temp_bed_target != thermalManager.temp_bed.target) {
  1314. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 178 + 4 * STAT_CHR_W + 6, 382, thermalManager.temp_bed.target);
  1315. last_temp_bed_target = thermalManager.temp_bed.target;
  1316. }
  1317. if (last_speed != feedrate_percentage) {
  1318. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 33 + 2 * STAT_CHR_W, 429, feedrate_percentage);
  1319. last_speed = feedrate_percentage;
  1320. }
  1321. #if HAS_LEVELING
  1322. if (last_probe_zoffset != probe.offset.z) {
  1323. show_plus_or_minus(STAT_FONT, Background_black, 2, 2, 178 + STAT_CHR_W, 429, probe.offset.z * 100);
  1324. last_probe_zoffset = probe.offset.z;
  1325. }
  1326. #else
  1327. if (last_zoffset != zprobe_zoffset) {
  1328. show_plus_or_minus(STAT_FONT, Background_black, 2, 2, 178 + STAT_CHR_W, 429, zprobe_zoffset * 100);
  1329. last_zoffset = zprobe_zoffset;
  1330. }
  1331. #endif
  1332. }
  1333. /**
  1334. * Read and cache the working directory.
  1335. *
  1336. * TODO: New code can follow the pattern of menu_media.cpp
  1337. * and rely on Marlin caching for performance. No need to
  1338. * cache files here.
  1339. *
  1340. */
  1341. #ifndef strcasecmp_P
  1342. #define strcasecmp_P(a, b) strcasecmp((a), (b))
  1343. #endif
  1344. inline void make_name_without_ext(char *dst, char *src, int maxlen=MENU_CHAR_LIMIT) {
  1345. char * const name = card.longest_filename();
  1346. size_t pos = strlen(name); // index of ending nul
  1347. // For files, remove the extension
  1348. // which may be .gcode, .gco, or .g
  1349. if (!card.flag.filenameIsDir)
  1350. while (pos && src[pos] != '.') pos--; // find last '.' (stop at 0)
  1351. int len = pos; // nul or '.'
  1352. if (len > maxlen) { // Keep the name short
  1353. pos = len = maxlen; // move nul down
  1354. dst[--pos] = '.'; // insert dots
  1355. dst[--pos] = '.';
  1356. dst[--pos] = '.';
  1357. }
  1358. dst[len] = '\0'; // end it
  1359. // Copy down to 0
  1360. while (pos--) dst[pos] = src[pos];
  1361. }
  1362. inline void HMI_SDCardInit(void) { card.cdroot(); }
  1363. void MarlinUI::refresh() {
  1364. // The card was mounted or unmounted
  1365. // or some other status change occurred
  1366. // DWIN_lcd_sd_status = false; // On next DWIN_Update
  1367. // HMI_SDCardUpdate();
  1368. }
  1369. #define ICON_Folder ICON_More
  1370. char shift_name[LONG_FILENAME_LENGTH + 1];
  1371. int8_t shift_amt; // = 0
  1372. millis_t shift_ms; // = 0
  1373. // Init the shift name based on the highlighted item
  1374. inline void Init_Shift_Name() {
  1375. const bool is_subdir = !card.flag.workDirIsRoot;
  1376. const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".."
  1377. const uint16_t fileCnt = card.get_num_Files();
  1378. if (WITHIN(filenum, 0, fileCnt - 1)) {
  1379. card.getfilename_sorted(SD_ORDER(filenum, fileCnt));
  1380. char * const name = card.longest_filename();
  1381. make_name_without_ext(shift_name, name, 100);
  1382. }
  1383. }
  1384. inline void Init_SDItem_Shift() {
  1385. shift_amt = 0;
  1386. shift_ms = select_file.now > 0 && strlen(shift_name) > MENU_CHAR_LIMIT
  1387. ? millis() + 750UL : 0;
  1388. }
  1389. /**
  1390. * Display an SD item, adding a CDUP for subfolders.
  1391. */
  1392. inline void Draw_SDItem(const uint16_t item, int16_t row=-1) {
  1393. if (row < 0) row = item + 1 + MROWS - index_file;
  1394. const bool is_subdir = !card.flag.workDirIsRoot;
  1395. if (is_subdir && item == 0) {
  1396. Draw_Menu_Line(row, ICON_Folder, (char*)"..");
  1397. return;
  1398. }
  1399. card.getfilename_sorted(item - is_subdir);
  1400. char * const name = card.longest_filename();
  1401. // Init the current selected name
  1402. // This is used during scroll drawing
  1403. if (item == select_file.now - 1) {
  1404. make_name_without_ext(shift_name, name, 100);
  1405. Init_SDItem_Shift();
  1406. }
  1407. char str[strlen(name) + 1];
  1408. make_name_without_ext(str, name);
  1409. Draw_Menu_Line(row, card.flag.filenameIsDir ? ICON_Folder : ICON_File, str);
  1410. }
  1411. inline void Draw_SDItem_Shifted(int8_t &shift) {
  1412. // Limit to the number of chars past the cutoff
  1413. const size_t len = strlen(shift_name);
  1414. NOMORE(shift, _MAX((signed)len - MENU_CHAR_LIMIT, 0));
  1415. // Shorten to the available space
  1416. const size_t lastchar = _MIN((signed)len, shift + MENU_CHAR_LIMIT);
  1417. const char c = shift_name[lastchar];
  1418. shift_name[lastchar] = '\0';
  1419. const uint8_t row = select_file.now + MROWS - index_file; // skip "Back" and scroll
  1420. Erase_Menu_Text(row);
  1421. Draw_Menu_Line(row, 0, &shift_name[shift]);
  1422. shift_name[lastchar] = c;
  1423. }
  1424. // Redraw the first set of SD Files
  1425. inline void Redraw_SD_List() {
  1426. select_file.reset();
  1427. index_file = MROWS;
  1428. Clear_Menu_Area(); // Leave title bar unchanged
  1429. Draw_Back_First();
  1430. // As many files as will fit
  1431. LOOP_L_N(i, _MIN(nr_sd_menu_items(), MROWS))
  1432. Draw_SDItem(i, i + 1);
  1433. Init_SDItem_Shift();
  1434. }
  1435. inline void SDCard_Up(void) {
  1436. card.cdup();
  1437. Redraw_SD_List();
  1438. DWIN_lcd_sd_status = false; // On next DWIN_Update
  1439. }
  1440. inline void SDCard_Folder(char * const dirname) {
  1441. card.cd(dirname);
  1442. Redraw_SD_List();
  1443. DWIN_lcd_sd_status = false; // On next DWIN_Update
  1444. }
  1445. //
  1446. // Watch for media mount / unmount
  1447. //
  1448. void HMI_SDCardUpdate(void) {
  1449. if (HMI_flag.home_flag) return;
  1450. if (DWIN_lcd_sd_status != card.isMounted()) {
  1451. DWIN_lcd_sd_status = card.isMounted();
  1452. // SERIAL_ECHOLNPAIR("HMI_SDCardUpdate: ", int(DWIN_lcd_sd_status));
  1453. if (card.isMounted()) {
  1454. if (checkkey == SelectFile)
  1455. Redraw_SD_List();
  1456. }
  1457. else {
  1458. // clean file icon
  1459. if (checkkey == SelectFile) {
  1460. Redraw_SD_List();
  1461. }
  1462. else if (checkkey == PrintProcess || checkkey == Tune || printingIsActive()) {
  1463. // TODO: Move card removed abort handling
  1464. // to CardReader::manage_media.
  1465. card.flag.abort_sd_printing = true;
  1466. wait_for_heatup = false;
  1467. abort_flag = true;
  1468. }
  1469. }
  1470. DWIN_UpdateLCD();
  1471. }
  1472. }
  1473. /* Start */
  1474. void HMI_StartFrame(const bool with_update) {
  1475. Goto_MainMenu();
  1476. DWIN_Draw_Rectangle(1, Background_black, 0, 360, 272, 479);
  1477. DWIN_ICON_Show(ICON, ICON_HotendTemp, 13, 381);
  1478. #if HOTENDS > 1
  1479. // DWIN_ICON_Show(ICON,ICON_HotendTemp, 13, 381);
  1480. #endif
  1481. DWIN_ICON_Show(ICON, ICON_BedTemp, 158, 381);
  1482. DWIN_ICON_Show(ICON, ICON_Speed, 13, 429);
  1483. DWIN_ICON_Show(ICON, ICON_Zoffset, 158, 428);
  1484. // Draw initial Status Area
  1485. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 33, 382, thermalManager.temp_hotend[0].celsius);
  1486. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 33 + 4 * STAT_CHR_W + 6, 382, thermalManager.temp_hotend[0].target);
  1487. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 178, 382, thermalManager.temp_bed.celsius);
  1488. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 178 + 4 * STAT_CHR_W + 6, 382, thermalManager.temp_bed.target);
  1489. DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 33 + 2 * STAT_CHR_W, 429, feedrate_percentage);
  1490. DWIN_Draw_String(false, false, STAT_FONT, White, Background_black, 33 + (2 + 3) * STAT_CHR_W + 2, 429, (char*)"%");
  1491. show_plus_or_minus(STAT_FONT, Background_black, 2, 2, 178, 429, BABY_Z_VAR * 100);
  1492. DWIN_Draw_String(false, false, STAT_FONT, White, Background_black, 33 + 3 * STAT_CHR_W + 5, 383, (char*)"/");
  1493. DWIN_Draw_String(false, false, STAT_FONT, White, Background_black, 178 + 3 * STAT_CHR_W + 5, 383, (char*)"/");
  1494. if (with_update) {
  1495. DWIN_UpdateLCD();
  1496. delay(5);
  1497. }
  1498. }
  1499. inline void Draw_Info_Menu() {
  1500. Clear_Main_Window();
  1501. DWIN_Draw_String(false, false, font8x16, White, Background_black, (DWIN_WIDTH - strlen(MACHINE_SIZE) * MENU_CHR_W) / 2, 122, (char*)MACHINE_SIZE);
  1502. DWIN_Draw_String(false, false, font8x16, White, Background_black, (DWIN_WIDTH - strlen(SHORT_BUILD_VERSION) * MENU_CHR_W) / 2, 195, (char*)SHORT_BUILD_VERSION);
  1503. if (HMI_flag.language_flag) {
  1504. DWIN_Frame_AreaCopy(1, 30, 17, 271 - 214, 479 - 450, 14, 8);
  1505. DWIN_Frame_AreaCopy(1, 197, 149, 271 - 19, 479 - 318, 108, 102);
  1506. DWIN_Frame_AreaCopy(1, 1, 164, 271 - 215, 479 - 303, 108, 175);
  1507. DWIN_Frame_AreaCopy(1, 58, 164, 271 - 158, 479 - 303, 105, 248);
  1508. DWIN_Draw_String(false, false, font8x16, White, Background_black, (DWIN_WIDTH - strlen(CORP_WEBSITE_C) * MENU_CHR_W) / 2, 268, (char*)CORP_WEBSITE_C);
  1509. }
  1510. else {
  1511. #ifdef USE_STRING_HEADINGS
  1512. Draw_Title("Info"); // TODO: GET_TEXT_F
  1513. #else
  1514. DWIN_Frame_AreaCopy(1, 190, 16, 271 - 56, 479 - 453, 14, 8);
  1515. #endif
  1516. DWIN_Frame_AreaCopy(1, 120, 150, 146, 479 - 318, 124, 102);
  1517. DWIN_Frame_AreaCopy(1, 146, 151, 271 - 17, 479 - 318, 82, 175);
  1518. DWIN_Frame_AreaCopy(1, 0, 165, 271 - 177, 479 - 304, 89, 248);
  1519. DWIN_Draw_String(false, false, font8x16, White, Background_black, (DWIN_WIDTH - strlen(CORP_WEBSITE_E) * MENU_CHR_W) / 2, 268, (char*)CORP_WEBSITE_E);
  1520. }
  1521. Draw_Back_First();
  1522. LOOP_L_N(i, 3) {
  1523. DWIN_ICON_Show(ICON, ICON_PrintSize + i, 26, 99 + i * 73);
  1524. DWIN_Draw_Line(Line_Color, 16, MBASE(2) + i * 73, 256, 156 + i * 73);
  1525. }
  1526. }
  1527. inline void Draw_Print_File_Menu() {
  1528. Clear_Title_Bar();
  1529. if (HMI_flag.language_flag) {
  1530. DWIN_Frame_AreaCopy(1, 0, 31, 271 - 216, 479 - 435, 14, 8);
  1531. }
  1532. else {
  1533. #ifdef USE_STRING_HEADINGS
  1534. Draw_Title("Print file"); // TODO: GET_TEXT_F
  1535. #else
  1536. DWIN_Frame_AreaCopy(1, 52, 31, 271 - 134, 479 - 438, 14, 8); // "Print file"
  1537. #endif
  1538. }
  1539. Redraw_SD_List();
  1540. }
  1541. /* Main Process */
  1542. void HMI_MainMenu(void) {
  1543. ENCODER_DiffState encoder_diffState = get_encoder_state();
  1544. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1545. if (encoder_diffState == ENCODER_DIFF_CW) {
  1546. if (select_page.inc(3)) {
  1547. switch (select_page.now) {
  1548. case 0: ICON_Print(); break;
  1549. case 1: ICON_Print(); ICON_Prepare(); break;
  1550. case 2: ICON_Prepare(); ICON_Control(); break;
  1551. case 3: ICON_Control(); TERN(HAS_LEVELING, ICON_Leveling, ICON_StartInfo)(1); break;
  1552. }
  1553. }
  1554. }
  1555. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1556. if (select_page.dec()) {
  1557. switch (select_page.now) {
  1558. case 0: ICON_Print(); ICON_Prepare(); break;
  1559. case 1: ICON_Prepare(); ICON_Control(); break;
  1560. case 2: ICON_Control(); TERN(HAS_LEVELING, ICON_Leveling, ICON_StartInfo)(0); break;
  1561. case 3: TERN(HAS_LEVELING, ICON_Leveling, ICON_StartInfo)(1); break;
  1562. }
  1563. }
  1564. }
  1565. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1566. switch (select_page.now) {
  1567. /* Print File */
  1568. case 0:
  1569. checkkey = SelectFile;
  1570. Draw_Print_File_Menu();
  1571. break;
  1572. /* Prepare */
  1573. case 1:
  1574. checkkey = Prepare;
  1575. select_prepare.reset();
  1576. index_prepare = MROWS;
  1577. Draw_Prepare_Menu();
  1578. break;
  1579. /* Control */
  1580. case 2:
  1581. checkkey = Control;
  1582. select_control.reset();
  1583. index_control = MROWS;
  1584. Draw_Control_Menu();
  1585. break;
  1586. /* Leveling */
  1587. case 3:
  1588. #if HAS_LEVELING
  1589. checkkey = Leveling;
  1590. HMI_Leveling();
  1591. #else
  1592. checkkey = Info;
  1593. Draw_Info_Menu();
  1594. #endif
  1595. break;
  1596. }
  1597. }
  1598. DWIN_UpdateLCD();
  1599. }
  1600. /* Select (and Print) File */
  1601. void HMI_SelectFile(void) {
  1602. ENCODER_DiffState encoder_diffState = get_encoder_state();
  1603. const uint16_t hasUpDir = !card.flag.workDirIsRoot;
  1604. if (encoder_diffState == ENCODER_DIFF_NO) {
  1605. if (shift_ms && select_file.now >= 1 + hasUpDir) {
  1606. // Scroll selected filename every second
  1607. const millis_t ms = millis();
  1608. if (ELAPSED(ms, shift_ms)) {
  1609. const bool was_reset = shift_amt < 0;
  1610. shift_ms = ms + 375UL + was_reset * 250UL; // ms per character
  1611. int8_t shift_new = shift_amt + 1; // Try to shift by...
  1612. Draw_SDItem_Shifted(shift_new); // Draw the item
  1613. if (!was_reset && shift_new == 0) // Was it limited to 0?
  1614. shift_ms = 0; // No scrolling needed
  1615. else if (shift_new == shift_amt) // Scroll reached the end
  1616. shift_new = -1; // Reset
  1617. shift_amt = shift_new; // Set new scroll
  1618. }
  1619. }
  1620. return;
  1621. }
  1622. // First pause is long. Easy.
  1623. // On reset, long pause must be after 0.
  1624. const uint16_t fullCnt = nr_sd_menu_items();
  1625. if (encoder_diffState == ENCODER_DIFF_CW && fullCnt) {
  1626. if (select_file.inc(fullCnt)) {
  1627. const uint8_t itemnum = select_file.now - 1; // -1 for "Back"
  1628. if (shift_ms) { // If line was shifted
  1629. Erase_Menu_Text(select_file.now - 1 + MROWS - index_file); // Erase and
  1630. Draw_SDItem(itemnum - 1); // redraw
  1631. }
  1632. if (select_file.now > MROWS && select_file.now > index_file) { // Cursor past the bottom
  1633. index_file = select_file.now; // New bottom line
  1634. Scroll_Menu(DWIN_SCROLL_UP);
  1635. Draw_SDItem(itemnum, MROWS); // Draw and init the shift name
  1636. }
  1637. else {
  1638. Move_Highlight(1, select_file.now + MROWS - index_file); // Just move highlight
  1639. Init_Shift_Name(); // ...and init the shift name
  1640. }
  1641. Init_SDItem_Shift();
  1642. }
  1643. }
  1644. else if (encoder_diffState == ENCODER_DIFF_CCW && fullCnt) {
  1645. if (select_file.dec()) {
  1646. const uint8_t itemnum = select_file.now - 1; // -1 for "Back"
  1647. if (shift_ms) { // If line was shifted
  1648. Erase_Menu_Text(select_file.now + 1 + MROWS - index_file); // Erase and
  1649. Draw_SDItem(itemnum + 1); // redraw
  1650. }
  1651. if (select_file.now < index_file - MROWS) { // Cursor past the top
  1652. index_file--; // New bottom line
  1653. Scroll_Menu(DWIN_SCROLL_DOWN);
  1654. if (index_file == MROWS) {
  1655. Draw_Back_First();
  1656. shift_ms = 0;
  1657. }
  1658. else {
  1659. Draw_SDItem(itemnum, 0); // Draw the item (and init shift name)
  1660. }
  1661. }
  1662. else {
  1663. Move_Highlight(-1, select_file.now + MROWS - index_file); // Just move highlight
  1664. Init_Shift_Name(); // ...and init the shift name
  1665. }
  1666. Init_SDItem_Shift(); // Reset left. Init timer.
  1667. }
  1668. }
  1669. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1670. if (select_file.now == 0) {
  1671. /* back */
  1672. select_page.set(0);
  1673. Goto_MainMenu();
  1674. }
  1675. else if (hasUpDir && select_file.now == 1) {
  1676. /* CDUP */
  1677. SDCard_Up();
  1678. goto HMI_SelectFileExit;
  1679. }
  1680. else {
  1681. const uint16_t filenum = select_file.now - 1 - hasUpDir;
  1682. card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
  1683. // Enter that folder!
  1684. if (card.flag.filenameIsDir) {
  1685. SDCard_Folder(card.filename);
  1686. goto HMI_SelectFileExit;
  1687. }
  1688. // Reset highlight for next entry
  1689. select_print.reset();
  1690. select_file.reset();
  1691. // Start choice and print SD file
  1692. HMI_flag.heat_flag = 1;
  1693. HMI_flag.print_finish = 0;
  1694. HMI_ValueStruct.show_mode = 0;
  1695. card.openAndPrintFile(card.filename);
  1696. #if FAN_COUNT > 0
  1697. // All fans on for Ender 3 v2 ?
  1698. // The slicer should manage this for us.
  1699. // for (uint8_t i = 0; i < FAN_COUNT; i++)
  1700. // thermalManager.fan_speed[i] = FANON;
  1701. #endif
  1702. Goto_PrintProcess();
  1703. }
  1704. }
  1705. HMI_SelectFileExit:
  1706. DWIN_UpdateLCD();
  1707. }
  1708. /* Printing */
  1709. void HMI_Printing(void) {
  1710. ENCODER_DiffState encoder_diffState = get_encoder_state();
  1711. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1712. if (HMI_flag.confirm_flag) {
  1713. if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1714. HMI_flag.confirm_flag = 0;
  1715. abort_flag = 1;
  1716. }
  1717. return;
  1718. }
  1719. // Avoid flicker by updating only the previous menu
  1720. if (encoder_diffState == ENCODER_DIFF_CW) {
  1721. if (select_print.inc(2)) {
  1722. switch (select_print.now) {
  1723. case 0: ICON_Tune(); break;
  1724. case 1:
  1725. ICON_Tune();
  1726. if (printingIsPaused()) ICON_Continue(); else ICON_Pause();
  1727. break;
  1728. case 2:
  1729. if (printingIsPaused()) ICON_Continue(); else ICON_Pause();
  1730. ICON_Stop();
  1731. break;
  1732. }
  1733. }
  1734. }
  1735. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1736. if (select_print.dec()) {
  1737. switch (select_print.now) {
  1738. case 0:
  1739. ICON_Tune();
  1740. if (printingIsPaused()) ICON_Continue(); else ICON_Pause();
  1741. break;
  1742. case 1:
  1743. if (printingIsPaused()) ICON_Continue(); else ICON_Pause();
  1744. ICON_Stop();
  1745. break;
  1746. case 2: ICON_Stop(); break;
  1747. }
  1748. }
  1749. }
  1750. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1751. switch (select_print.now) {
  1752. case 0: // setting
  1753. checkkey = Tune;
  1754. HMI_ValueStruct.show_mode = 0;
  1755. select_tune.reset();
  1756. index_tune = 5;
  1757. Draw_Tune_Menu();
  1758. break;
  1759. case 1: // pause
  1760. /* pause */
  1761. if (HMI_flag.pause_flag) {
  1762. ICON_Pause();
  1763. char cmd[40];
  1764. cmd[0] = '\0';
  1765. #if ENABLED(PAUSE_HEAT)
  1766. if (tempbed) sprintf_P(cmd, PSTR("M190 S%i\n"), tempbed);
  1767. if (temphot) sprintf_P(&cmd[strlen(cmd)], PSTR("M109 S%i\n"), temphot);
  1768. #endif
  1769. strcat_P(cmd, PSTR("M24"));
  1770. queue.inject(cmd);
  1771. }
  1772. else {
  1773. HMI_flag.select_flag = 1;
  1774. checkkey = Print_window;
  1775. Popup_window_PauseOrStop();
  1776. }
  1777. break;
  1778. case 2: // stop
  1779. /* stop */
  1780. HMI_flag.select_flag = 1;
  1781. checkkey = Print_window;
  1782. Popup_window_PauseOrStop();
  1783. break;
  1784. default:
  1785. break;
  1786. }
  1787. }
  1788. DWIN_UpdateLCD();
  1789. }
  1790. /* pause and stop window */
  1791. void HMI_PauseOrStop(void) {
  1792. ENCODER_DiffState encoder_diffState = get_encoder_state();
  1793. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1794. if (encoder_diffState == ENCODER_DIFF_CW) {
  1795. Draw_Select_Highlight(false);
  1796. }
  1797. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1798. Draw_Select_Highlight(true);
  1799. }
  1800. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1801. if (select_print.now == 1) { // pause window
  1802. if (HMI_flag.select_flag) {
  1803. pause_action_flag = 1;
  1804. ICON_Continue();
  1805. #if ENABLED(POWER_LOSS_RECOVERY)
  1806. if (recovery.enabled) recovery.save(true);
  1807. #endif
  1808. queue.inject_P(PSTR("M25"));
  1809. }
  1810. else {
  1811. // cancel pause
  1812. }
  1813. Goto_PrintProcess();
  1814. }
  1815. else if (select_print.now == 2) { // stop window
  1816. if (HMI_flag.select_flag) {
  1817. wait_for_heatup = false; // Stop waiting for heater
  1818. #if 0
  1819. // TODO: In ExtUI or MarlinUI add a common stop event
  1820. // card.flag.abort_sd_printing = true;
  1821. #else
  1822. checkkey = Back_Main;
  1823. // Wait for planner moves to finish!
  1824. if (HMI_flag.home_flag) planner.synchronize();
  1825. card.endFilePrint();
  1826. #ifdef ACTION_ON_CANCEL
  1827. host_action_cancel();
  1828. #endif
  1829. #ifdef EVENT_GCODE_SD_STOP
  1830. Popup_Window_Home();
  1831. queue.inject_P(PSTR(EVENT_GCODE_SD_STOP)); // For Ender 3 "G28 X Y"
  1832. #endif
  1833. abort_flag = true;
  1834. #endif
  1835. }
  1836. else {
  1837. Goto_PrintProcess(); // cancel stop
  1838. }
  1839. }
  1840. }
  1841. DWIN_UpdateLCD();
  1842. }
  1843. inline void Draw_Move_Menu() {
  1844. Clear_Main_Window();
  1845. if (HMI_flag.language_flag) {
  1846. DWIN_Frame_AreaCopy(1, 192, 1, 271 - 38, 479 - 465, 14, 8);
  1847. DWIN_Frame_AreaCopy(1, 58, 118, 271 - 165, 479 - 347, LBLX, MBASE(1));
  1848. DWIN_Frame_AreaCopy(1, 109, 118, 271 - 114, 479 - 347, LBLX, MBASE(2));
  1849. DWIN_Frame_AreaCopy(1, 160, 118, 271 - 62, 479 - 347, LBLX, MBASE(3));
  1850. DWIN_Frame_AreaCopy(1, 212, 118, 271 - 18, 479 - 348, LBLX, MBASE(4));
  1851. }
  1852. else {
  1853. #ifdef USE_STRING_HEADINGS
  1854. Draw_Title("Move"); // TODO: GET_TEXT_F
  1855. #else
  1856. DWIN_Frame_AreaCopy(1, 231, 2, 271 - 6, 479 - 467, 14, 8);
  1857. #endif
  1858. draw_move_en(MBASE(1)); say_x(33 + 3, MBASE(1)); // "Move X"
  1859. draw_move_en(MBASE(2)); say_y(33 + 3, MBASE(2)); // "Move Y"
  1860. draw_move_en(MBASE(3)); say_z(33 + 3, MBASE(3)); // "Move Z"
  1861. DWIN_Frame_AreaCopy(1, 123, 192, 271 - 95, 479 - 277, LBLX, MBASE(4)); // "Extruder"
  1862. }
  1863. Draw_Back_First(select_axis.now == 0);
  1864. if (select_axis.now) Draw_Menu_Cursor(select_axis.now);
  1865. LOOP_L_N(i, MROWS) Draw_Menu_Line(i + 1, ICON_MoveX + i);
  1866. }
  1867. /* Prepare */
  1868. void HMI_Prepare(void) {
  1869. ENCODER_DiffState encoder_diffState = get_encoder_state();
  1870. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1871. // Avoid flicker by updating only the previous menu
  1872. if (encoder_diffState == ENCODER_DIFF_CW) {
  1873. if (select_prepare.inc(8)) {
  1874. if (select_prepare.now > MROWS && select_prepare.now > index_prepare) {
  1875. index_prepare = select_prepare.now;
  1876. // Scroll up and draw a blank bottom line
  1877. Scroll_Menu(DWIN_SCROLL_UP);
  1878. Draw_Menu_Icon(MROWS, ICON_Axis + select_prepare.now - 1);
  1879. // Draw "More" icon for sub-menus
  1880. if (index_prepare < 7) Draw_More_Icon(MROWS - index_prepare + 1);
  1881. if (index_prepare == 6) Prepare_Item_ABS(MROWS);
  1882. else if (index_prepare == 7) Prepare_Item_Cool(MROWS);
  1883. else if (index_prepare == 8) Prepare_Item_Lang(MROWS);
  1884. }
  1885. else {
  1886. Move_Highlight(1, select_prepare.now + MROWS - index_prepare);
  1887. }
  1888. }
  1889. }
  1890. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1891. if (select_prepare.dec()) {
  1892. if (select_prepare.now < index_prepare - MROWS) {
  1893. index_prepare--;
  1894. Scroll_Menu(DWIN_SCROLL_DOWN);
  1895. if (index_prepare == MROWS)
  1896. Draw_Back_First();
  1897. else
  1898. Draw_Menu_Line(0, ICON_Axis + select_prepare.now - 1);
  1899. if (index_prepare < 7) Draw_More_Icon(MROWS - index_prepare + 1);
  1900. if (index_prepare == 6) Prepare_Item_Move(0);
  1901. else if (index_prepare == 7) Prepare_Item_Disable(0);
  1902. else if (index_prepare == 8) Prepare_Item_Home(0);
  1903. }
  1904. else {
  1905. Move_Highlight(-1, select_prepare.now + MROWS - index_prepare);
  1906. }
  1907. }
  1908. }
  1909. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1910. switch (select_prepare.now) {
  1911. case 0: // back
  1912. select_page.set(1);
  1913. Goto_MainMenu();
  1914. break;
  1915. case 1: // axis move
  1916. checkkey = AxisMove;
  1917. select_axis.reset();
  1918. Draw_Move_Menu();
  1919. queue.inject_P(PSTR("G92 E0"));
  1920. current_position.e = HMI_ValueStruct.Move_E_scale = 0;
  1921. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 216, MBASE(1), current_position[X_AXIS] * MINUNITMULT);
  1922. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 216, MBASE(2), current_position[Y_AXIS] * MINUNITMULT);
  1923. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 216, MBASE(3), current_position[Z_AXIS] * MINUNITMULT);
  1924. show_plus_or_minus(font8x16, Background_black, 3, 1, 216, MBASE(4), current_position.e * MINUNITMULT);
  1925. break;
  1926. case 2: // close motion
  1927. queue.inject_P(PSTR("M84"));
  1928. break;
  1929. case 3: // homing
  1930. checkkey = Last_Prepare;
  1931. index_prepare = MROWS;
  1932. queue.inject_P(PSTR("G28")); // G28 will set home_flag
  1933. Popup_Window_Home();
  1934. break;
  1935. case 4: // Z-offset
  1936. #if HAS_LEVELING
  1937. checkkey = Homeoffset;
  1938. HMI_ValueStruct.show_mode = -4;
  1939. HMI_ValueStruct.offset_value = probe.offset.z * 100;
  1940. show_plus_or_minus(font8x16, Select_Color, 2, 2, 202, MBASE(4 + MROWS - index_prepare), HMI_ValueStruct.offset_value);
  1941. EncoderRate.encoderRateEnabled = 1;
  1942. #else
  1943. // Apply workspace offset, making the current position 0,0,0
  1944. queue.inject_P(PSTR("G92 X0 Y0 Z0"));
  1945. buzzer.tone(100, 659);
  1946. buzzer.tone(100, 698);
  1947. #endif
  1948. break;
  1949. case 5: // PLA preheat
  1950. thermalManager.setTargetHotend(ui.material_preset[0].hotend_temp, 0);
  1951. thermalManager.setTargetBed(ui.material_preset[0].bed_temp);
  1952. thermalManager.set_fan_speed(0, ui.material_preset[0].fan_speed);
  1953. break;
  1954. case 6: // ABS preheat
  1955. thermalManager.setTargetHotend(ui.material_preset[1].hotend_temp, 0);
  1956. thermalManager.setTargetBed(ui.material_preset[1].bed_temp);
  1957. thermalManager.set_fan_speed(0, ui.material_preset[1].fan_speed);
  1958. break;
  1959. case 7: // cool
  1960. thermalManager.zero_fan_speeds();
  1961. thermalManager.disable_all_heaters();
  1962. break;
  1963. case 8: // language
  1964. /* select language */
  1965. HMI_flag.language_flag = !HMI_flag.language_flag;
  1966. if (HMI_flag.language_flag) {
  1967. set_chinese_to_eeprom();
  1968. DWIN_JPG_CacheTo1(Language_Chinese);
  1969. }
  1970. else {
  1971. set_english_to_eeprom();
  1972. DWIN_JPG_CacheTo1(Language_English);
  1973. }
  1974. Draw_Prepare_Menu();
  1975. break;
  1976. default:
  1977. break;
  1978. }
  1979. }
  1980. DWIN_UpdateLCD();
  1981. }
  1982. void Draw_Temperature_Menu() {
  1983. Clear_Main_Window();
  1984. if (HMI_flag.language_flag) {
  1985. DWIN_Frame_AreaCopy(1, 236, 2, 271 - 8, 479 - 466, 14, 8);
  1986. DWIN_Frame_AreaCopy(1, 1, 134, 271 - 215, 479 - 333, LBLX, MBASE(1));
  1987. DWIN_Frame_AreaCopy(1, 58, 134, 271 - 158, 479 - 333, LBLX, MBASE(2));
  1988. DWIN_Frame_AreaCopy(1, 115, 134, 271 - 101, 479 - 333, LBLX, MBASE(3));
  1989. DWIN_Frame_AreaCopy(1, 100, 89, 271 - 93, 479 - 378, LBLX, MBASE(4));
  1990. DWIN_Frame_AreaCopy(1, 180, 89, 271 - 11, 479 - 379, LBLX, MBASE(5));
  1991. }
  1992. else {
  1993. #ifdef USE_STRING_HEADINGS
  1994. Draw_Title("Temperature"); // TODO: GET_TEXT_F
  1995. #else
  1996. DWIN_Frame_AreaCopy(1, 56, 16, 271 - 130, 479 - 450 - 1, 14, 8);
  1997. #endif
  1998. DWIN_Frame_AreaCopy(1, 197, 104, 271 - 33, 479 - 365, LBLX, MBASE(1)); // Nozzle...
  1999. DWIN_Frame_AreaCopy(1, 1, 89, 271 - 188, 479 - 377 - 1, LBLX + 41 + 3, MBASE(1)); // ...Temperature
  2000. DWIN_Frame_AreaCopy(1, 240, 104, 271 - 7, 479 - 365, LBLX, MBASE(2)); // Bed...
  2001. DWIN_Frame_AreaCopy(1, 1, 89, 271 - 188, 479 - 377 - 1, LBLX + 24 + 3, MBASE(2)); // ...Temperature
  2002. DWIN_Frame_AreaCopy(1, 0, 119, 271 - 207, 479 - 347, LBLX, MBASE(3)); // Fan speed
  2003. DWIN_Frame_AreaCopy(1, 107, 76, 271 - 115, 479 - 393, LBLX, MBASE(4)); // Preheat...
  2004. DWIN_Frame_AreaCopy(1, 157, 76, 181, 479 - 393, LBLX + 49 + 3, MBASE(4)); // ...PLA
  2005. DWIN_Frame_AreaCopy(1, 131, 119, 271 - 89, 479 - 347, LBLX + 49 + 24 + 6, MBASE(4)); // PLA setting
  2006. DWIN_Frame_AreaCopy(1, 107, 76, 271 - 115, 479 - 393, LBLX, MBASE(5)); // Preheat...
  2007. DWIN_Frame_AreaCopy(1, 172, 76, 198, 479 - 393, LBLX + 49 + 3, MBASE(5)); // ...ABS
  2008. DWIN_Frame_AreaCopy(1, 131, 119, 271 - 89, 479 - 347, LBLX + 49 + 3 + 26 + 3, MBASE(5)); // ABS setting
  2009. }
  2010. Draw_Back_First(select_temp.now == 0);
  2011. if (select_temp.now) Draw_Menu_Cursor(select_temp.now);
  2012. LOOP_L_N(i, 5) Draw_Menu_Line(i + 1, ICON_SetEndTemp + i);
  2013. Draw_More_Icon(4);
  2014. Draw_More_Icon(5);
  2015. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(1), thermalManager.temp_hotend[0].target);
  2016. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2), thermalManager.temp_bed.target);
  2017. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3), thermalManager.fan_speed[0]);
  2018. }
  2019. /* Control */
  2020. void HMI_Control(void) {
  2021. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2022. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2023. // Avoid flicker by updating only the previous menu
  2024. if (encoder_diffState == ENCODER_DIFF_CW) {
  2025. #define CONTROL_ITEMS (5 + ENABLED(HAS_LEVELING))
  2026. if (select_control.inc(CONTROL_ITEMS)) {
  2027. if (select_control.now > MROWS && select_control.now > index_control) {
  2028. index_control = select_control.now;
  2029. Scroll_Menu(DWIN_SCROLL_UP);
  2030. Draw_Menu_Icon(MROWS, ICON_Temperature + select_control.now - 1);
  2031. Draw_More_Icon(1 + MROWS - index_control); // Temperature >
  2032. Draw_More_Icon(2 + MROWS - index_control); // Motion >
  2033. if (index_control > MROWS) {
  2034. Draw_More_Icon(6 + MROWS - index_control); // Info >
  2035. if (HMI_flag.language_flag)
  2036. DWIN_Frame_AreaCopy(1, 231, 104, 271 - 13, 479 - 363, LBLX, MBASE(5));
  2037. else
  2038. DWIN_Frame_AreaCopy(1, 0, 104, 271 - 247, 479 - 365, LBLX, MBASE(5));
  2039. }
  2040. }
  2041. else {
  2042. Move_Highlight(1, select_control.now + MROWS - index_control);
  2043. }
  2044. }
  2045. }
  2046. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2047. if (select_control.dec()) {
  2048. if (select_control.now < index_control - MROWS) {
  2049. index_control--;
  2050. Scroll_Menu(DWIN_SCROLL_DOWN);
  2051. if (index_control == MROWS)
  2052. Draw_Back_First();
  2053. else
  2054. Draw_Menu_Line(0, ICON_Temperature + select_control.now - 1);
  2055. Draw_More_Icon(0 + MROWS - index_control + 1); // Temperature >
  2056. Draw_More_Icon(1 + MROWS - index_control + 1); // Motion >
  2057. }
  2058. else {
  2059. Move_Highlight(-1, select_control.now + MROWS - index_control);
  2060. }
  2061. }
  2062. }
  2063. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2064. switch (select_control.now) {
  2065. case 0: // back
  2066. select_page.set(2);
  2067. Goto_MainMenu();
  2068. break;
  2069. case 1: // temperature
  2070. checkkey = TemperatureID;
  2071. HMI_ValueStruct.show_mode = -1;
  2072. select_temp.reset();
  2073. Draw_Temperature_Menu();
  2074. break;
  2075. case 2: // motion
  2076. checkkey = Motion;
  2077. select_motion.reset();
  2078. Draw_Motion_Menu();
  2079. break;
  2080. case 3: // write EEPROM
  2081. if (settings.save()) {
  2082. buzzer.tone(100, 659);
  2083. buzzer.tone(100, 698);
  2084. }
  2085. else
  2086. buzzer.tone(20, 440);
  2087. break;
  2088. case 4: // read EEPROM
  2089. if (settings.load()) {
  2090. buzzer.tone(100, 659);
  2091. buzzer.tone(100, 698);
  2092. }
  2093. else {buzzer.tone(20, 440);}
  2094. break;
  2095. case 5: // resume EEPROM
  2096. settings.reset();
  2097. #if HAS_BUZZER
  2098. buzzer.tone(100, 659);
  2099. buzzer.tone(100, 698);
  2100. #endif
  2101. break;
  2102. case 6: // info
  2103. checkkey = Info;
  2104. Draw_Info_Menu();
  2105. break;
  2106. default:
  2107. break;
  2108. }
  2109. }
  2110. DWIN_UpdateLCD();
  2111. }
  2112. /* Leveling */
  2113. void HMI_Leveling(void) {
  2114. Popup_Window_Leveling();
  2115. DWIN_UpdateLCD();
  2116. queue.inject_P(PSTR("G28O\nG29"));
  2117. }
  2118. /* Axis Move */
  2119. void HMI_AxisMove(void) {
  2120. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2121. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2122. #if HAS_HOTEND
  2123. // popup window resume
  2124. if (HMI_flag.ETempTooLow_flag) {
  2125. if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2126. HMI_flag.ETempTooLow_flag = 0;
  2127. Draw_Move_Menu();
  2128. current_position.e = HMI_ValueStruct.Move_E_scale = 0;
  2129. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 216, MBASE(1), HMI_ValueStruct.Move_X_scale);
  2130. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale);
  2131. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale);
  2132. show_plus_or_minus(font8x16, Background_black, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale);
  2133. DWIN_UpdateLCD();
  2134. }
  2135. return;
  2136. }
  2137. #endif
  2138. // Avoid flicker by updating only the previous menu
  2139. if (encoder_diffState == ENCODER_DIFF_CW) {
  2140. if (select_axis.inc(4)) Move_Highlight(1, select_axis.now);
  2141. }
  2142. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2143. if (select_axis.dec()) Move_Highlight(-1, select_axis.now);
  2144. }
  2145. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2146. switch (select_axis.now) {
  2147. case 0: // back
  2148. checkkey = Prepare;
  2149. select_prepare.set(1);
  2150. index_prepare = MROWS;
  2151. Draw_Prepare_Menu();
  2152. break;
  2153. case 1: // X axis move
  2154. checkkey = Move_X;
  2155. HMI_ValueStruct.Move_X_scale = current_position[X_AXIS] * MINUNITMULT;
  2156. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 216, MBASE(1), HMI_ValueStruct.Move_X_scale);
  2157. EncoderRate.encoderRateEnabled = 1;
  2158. break;
  2159. case 2: // Y axis move
  2160. checkkey = Move_Y;
  2161. HMI_ValueStruct.Move_Y_scale = current_position[Y_AXIS] * MINUNITMULT;
  2162. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale);
  2163. EncoderRate.encoderRateEnabled = 1;
  2164. break;
  2165. case 3: // Z axis move
  2166. checkkey = Move_Z;
  2167. HMI_ValueStruct.Move_Z_scale = current_position[Z_AXIS] * MINUNITMULT;
  2168. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale);
  2169. EncoderRate.encoderRateEnabled = 1;
  2170. break;
  2171. #if HAS_HOTEND
  2172. case 4: // Extruder
  2173. // window tips
  2174. #ifdef PREVENT_COLD_EXTRUSION
  2175. if (thermalManager.temp_hotend[0].celsius < EXTRUDE_MINTEMP) {
  2176. HMI_flag.ETempTooLow_flag = 1;
  2177. Popup_Window_ETempTooLow();
  2178. DWIN_UpdateLCD();
  2179. return;
  2180. }
  2181. #endif
  2182. checkkey = Extruder;
  2183. HMI_ValueStruct.Move_E_scale = current_position.e * MINUNITMULT;
  2184. show_plus_or_minus(font8x16, Select_Color, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale);
  2185. EncoderRate.encoderRateEnabled = 1;
  2186. break;
  2187. #endif
  2188. }
  2189. }
  2190. DWIN_UpdateLCD();
  2191. }
  2192. /* TemperatureID */
  2193. void HMI_Temperature(void) {
  2194. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2195. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2196. // Avoid flicker by updating only the previous menu
  2197. if (encoder_diffState == ENCODER_DIFF_CW) {
  2198. if (select_temp.inc(5)) Move_Highlight(1, select_temp.now);
  2199. }
  2200. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2201. if (select_temp.dec()) Move_Highlight(-1, select_temp.now);
  2202. }
  2203. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2204. switch (select_temp.now) {
  2205. case 0: // back
  2206. checkkey = Control;
  2207. select_control.set(1);
  2208. index_control = MROWS;
  2209. Draw_Control_Menu();
  2210. break;
  2211. #if HAS_HOTEND
  2212. case 1: // nozzle temperature
  2213. checkkey = ETemp;
  2214. HMI_ValueStruct.E_Temp = thermalManager.temp_hotend[0].target;
  2215. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(1), thermalManager.temp_hotend[0].target);
  2216. EncoderRate.encoderRateEnabled = 1;
  2217. break;
  2218. #endif
  2219. #if HAS_HEATED_BED
  2220. case 2: // bed temperature
  2221. checkkey = BedTemp;
  2222. HMI_ValueStruct.Bed_Temp = thermalManager.temp_bed.target;
  2223. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(2), thermalManager.temp_bed.target);
  2224. EncoderRate.encoderRateEnabled = 1;
  2225. break;
  2226. #endif
  2227. #if HAS_FAN
  2228. case 3: // fan speed
  2229. checkkey = FanSpeed;
  2230. HMI_ValueStruct.Fan_speed = thermalManager.fan_speed[0];
  2231. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(3), thermalManager.fan_speed[0]);
  2232. EncoderRate.encoderRateEnabled = 1;
  2233. break;
  2234. #endif
  2235. #if HAS_HOTEND
  2236. case 4: // PLA preheat setting
  2237. checkkey = PLAPreheat;
  2238. select_PLA.reset();
  2239. HMI_ValueStruct.show_mode = -2;
  2240. Clear_Main_Window();
  2241. if (HMI_flag.language_flag) {
  2242. DWIN_Frame_AreaCopy(1, 59, 16, 271 - 132, 479 - 450, 14, 8);
  2243. DWIN_Frame_AreaCopy(1, 100, 89, 124, 479 - 378, LBLX, MBASE(1));
  2244. DWIN_Frame_AreaCopy(1, 1, 134, 271 - 215, 479 - 333, LBLX + 24, MBASE(1)); // PLA nozzle temp
  2245. DWIN_Frame_AreaCopy(1, 100, 89, 124, 479 - 378, LBLX, MBASE(2));
  2246. DWIN_Frame_AreaCopy(1, 58, 134, 271 - 158, 479 - 333, LBLX + 24, MBASE(2)); // PLA bed temp
  2247. DWIN_Frame_AreaCopy(1, 100, 89, 124, 479 - 378, LBLX, MBASE(3));
  2248. DWIN_Frame_AreaCopy(1, 115, 134, 271 - 101, 479 - 333, LBLX + 24, MBASE(3)); // PLA fan speed
  2249. DWIN_Frame_AreaCopy(1, 72, 148, 271 - 120, 479 - 317, LBLX, MBASE(4)); // save PLA configuration
  2250. }
  2251. else {
  2252. #ifdef USE_STRING_HEADINGS
  2253. Draw_Title("PLA Settings"); // TODO: GET_TEXT_F
  2254. #else
  2255. DWIN_Frame_AreaCopy(1, 56, 16, 271 - 130, 479 - 450 - 1, 14, 8);
  2256. #endif
  2257. DWIN_Frame_AreaCopy(1, 157, 76, 181, 479 - 393, LBLX, MBASE(1));
  2258. DWIN_Frame_AreaCopy(1, 197, 104, 271 - 33, 479 - 365, LBLX + 24 + 3, MBASE(1));
  2259. DWIN_Frame_AreaCopy(1, 1, 89, 271 - 188, 479 - 377 - 1, LBLX + 24 + 41 + 6, MBASE(1)); // PLA nozzle temp
  2260. DWIN_Frame_AreaCopy(1, 157, 76, 181, 479 - 393, LBLX, MBASE(2) + 3);
  2261. DWIN_Frame_AreaCopy(1, 240, 104, 271 - 7, 479 - 365, LBLX + 24 + 3, MBASE(2) + 3);
  2262. DWIN_Frame_AreaCopy(1, 1, 89, 271 - 188, 479 - 377 - 1, LBLX + 24 + 24 + 6, MBASE(2) + 3); // PLA bed temp
  2263. DWIN_Frame_AreaCopy(1, 157, 76, 181, 479 - 393, LBLX, MBASE(3));
  2264. DWIN_Frame_AreaCopy(1, 0, 119, 271 - 207, 479 - 347, LBLX + 24 + 3, MBASE(3)); // PLA fan speed
  2265. DWIN_Frame_AreaCopy(1, 97, 165, 271 - 42, 479 - 301 - 1, LBLX, MBASE(4)); // save PLA configuration
  2266. }
  2267. Draw_Back_First();
  2268. Draw_Menu_Line(1, ICON_SetEndTemp);
  2269. Draw_Menu_Line(2, ICON_SetBedTemp);
  2270. Draw_Menu_Line(3, ICON_FanSpeed);
  2271. Draw_Menu_Line(4, ICON_WriteEEPROM);
  2272. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(1), ui.material_preset[0].hotend_temp);
  2273. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2), ui.material_preset[0].bed_temp);
  2274. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3), ui.material_preset[0].fan_speed);
  2275. break;
  2276. case 5: // ABS preheat setting
  2277. checkkey = ABSPreheat;
  2278. select_ABS.reset();
  2279. HMI_ValueStruct.show_mode = -3;
  2280. Clear_Main_Window();
  2281. if (HMI_flag.language_flag) {
  2282. DWIN_Frame_AreaCopy(1, 142, 16, 271 - 48, 479 - 450, 14, 8);
  2283. DWIN_Frame_AreaCopy(1, 180, 89, 204, 479 - 379, LBLX, MBASE(1));
  2284. DWIN_Frame_AreaCopy(1, 1, 134, 271 - 215, 479 - 333, LBLX + 24, MBASE(1)); // ABS nozzle temp
  2285. DWIN_Frame_AreaCopy(1, 180, 89, 204, 479 - 379, LBLX, MBASE(2));
  2286. DWIN_Frame_AreaCopy(1, 58, 134, 271 - 158, 479 - 333, LBLX + 24, MBASE(2)); // ABS bed temp
  2287. DWIN_Frame_AreaCopy(1, 180, 89, 204, 479 - 379, LBLX, MBASE(3));
  2288. DWIN_Frame_AreaCopy(1, 115, 134, 271 - 101, 479 - 333, LBLX + 24, MBASE(3)); // ABS fan speed
  2289. DWIN_Frame_AreaCopy(1, 72, 148, 271 - 120, 479 - 317, LBLX, MBASE(4));
  2290. DWIN_Frame_AreaCopy(1, 180, 89, 204, 479 - 379, LBLX + 28, MBASE(4) + 2); // save ABS configuration
  2291. }
  2292. else {
  2293. #ifdef USE_STRING_HEADINGS
  2294. Draw_Title("ABS Settings"); // TODO: GET_TEXT_F
  2295. #else
  2296. DWIN_Frame_AreaCopy(1, 56, 16, 271 - 130, 479 - 450 - 1, 14, 8);
  2297. #endif
  2298. DWIN_Frame_AreaCopy(1, 172, 76, 198, 479 - 393, LBLX, MBASE(1));
  2299. DWIN_Frame_AreaCopy(1, 197, 104, 271 - 33, 479 - 365, LBLX + 24 + 3, MBASE(1));
  2300. DWIN_Frame_AreaCopy(1, 1, 89, 271 - 188, 479 - 377 - 1, LBLX + 24 + 41 + 6, MBASE(1)); // ABS nozzle temp
  2301. DWIN_Frame_AreaCopy(1, 172, 76, 198, 479 - 393, LBLX, MBASE(2) + 3);
  2302. DWIN_Frame_AreaCopy(1, 240, 104, 271 - 7, 479 - 365, LBLX + 24 + 3, MBASE(2) + 3);
  2303. DWIN_Frame_AreaCopy(1, 1, 89, 271 - 188, 479 - 377 - 1, LBLX + 24 + 24 + 6, MBASE(2) + 3); // ABS bed temp
  2304. DWIN_Frame_AreaCopy(1, 172, 76, 198, 479 - 393, LBLX, MBASE(3));
  2305. DWIN_Frame_AreaCopy(1, 0, 119, 271 - 207, 479 - 347, LBLX + 24 + 3, MBASE(3)); // ABS fan speed
  2306. DWIN_Frame_AreaCopy(1, 97, 165, 271 - 42, 479 - 301 - 1, LBLX, MBASE(4));
  2307. DWIN_Frame_AreaCopy(1, 172, 76, 198, 479 - 393, LBLX + 33, MBASE(4)); // save ABS configuration
  2308. }
  2309. Draw_Back_First();
  2310. Draw_Menu_Line(1, ICON_SetEndTemp);
  2311. Draw_Menu_Line(2, ICON_SetBedTemp);
  2312. Draw_Menu_Line(3, ICON_FanSpeed);
  2313. Draw_Menu_Line(4, ICON_WriteEEPROM);
  2314. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(1), ui.material_preset[1].hotend_temp);
  2315. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(2), ui.material_preset[1].bed_temp);
  2316. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 3, 216, MBASE(3), ui.material_preset[1].fan_speed);
  2317. break;
  2318. #endif // if HAS_HOTEND
  2319. }
  2320. }
  2321. DWIN_UpdateLCD();
  2322. }
  2323. inline void Draw_Max_Speed_Menu() {
  2324. Clear_Main_Window();
  2325. if (HMI_flag.language_flag) {
  2326. DWIN_Frame_AreaCopy(1, 1, 16, 271 - 243, 479 - 451, 14, 8);
  2327. auto say_max_speed = [](const uint16_t row) {
  2328. DWIN_Frame_AreaCopy(1, 173, 133, 228, 479 - 332, LBLX, row); // "Max speed"
  2329. };
  2330. say_max_speed(MBASE(1)); // "Max speed"
  2331. DWIN_Frame_AreaCopy(1, 229, 133, 236, 479 - 332, LBLX + 55 + 3, MBASE(1)); // X
  2332. say_max_speed(MBASE(2)); // "Max speed"
  2333. DWIN_Frame_AreaCopy(1, 1, 150, 271 - 264, 479 - 319, LBLX + 55 + 3, MBASE(2) + 3); // Y
  2334. say_max_speed(MBASE(3)); // "Max speed"
  2335. DWIN_Frame_AreaCopy(1, 9, 150, 271 - 255, 479 - 319, LBLX + 55 + 3, MBASE(3) + 3); // Z
  2336. say_max_speed(MBASE(4)); // "Max speed"
  2337. DWIN_Frame_AreaCopy(1, 18, 150, 271 - 246, 479 - 319, LBLX + 55 + 3, MBASE(4) + 3); // E
  2338. }
  2339. else {
  2340. #ifdef USE_STRING_HEADINGS
  2341. Draw_Title("Max Speed (mm/s)"); // TODO: GET_TEXT_F
  2342. #else
  2343. DWIN_Frame_AreaCopy(1, 144, 16, 271 - 82, 479 - 453, 14, 8);
  2344. #endif
  2345. draw_max_en(MBASE(1)); // "Max"
  2346. DWIN_Frame_AreaCopy(1, 184, 119, 271 - 37, 479 - 347, LBLX + 24 + 3, MBASE(1)); // "Speed X"
  2347. draw_max_en(MBASE(2)); // "Max"
  2348. draw_speed_en(24 + 3, MBASE(2)); // "Speed"
  2349. say_y(24 + 40 + 6, MBASE(2)); // "Y"
  2350. draw_max_en(MBASE(3)); // "Max"
  2351. draw_speed_en(24 + 3, MBASE(3)); // "Speed"
  2352. say_z(24 + 40 + 6, MBASE(3)); // "Z"
  2353. draw_max_en(MBASE(4)); // "Max"
  2354. draw_speed_en(24 + 3, MBASE(4)); // "Speed"
  2355. say_e(24 + 40 + 6, MBASE(4)); // "E"
  2356. }
  2357. Draw_Back_First();
  2358. LOOP_L_N(i, 4) Draw_Menu_Line(i + 1, ICON_MaxSpeedX + i);
  2359. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(1), planner.settings.max_feedrate_mm_s[X_AXIS]);
  2360. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(2), planner.settings.max_feedrate_mm_s[Y_AXIS]);
  2361. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(3), planner.settings.max_feedrate_mm_s[Z_AXIS]);
  2362. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(4), planner.settings.max_feedrate_mm_s[E_AXIS]);
  2363. }
  2364. inline void Draw_Max_Accel_Menu() {
  2365. Clear_Main_Window();
  2366. if (HMI_flag.language_flag) {
  2367. DWIN_Frame_AreaCopy(1, 1, 16, 271 - 243, 479 - 451, 14, 8);
  2368. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(1));
  2369. DWIN_Frame_AreaCopy(1, 28, 149, 271 - 202, 479 - 318, LBLX + 27, MBASE(1) + 1);
  2370. DWIN_Frame_AreaCopy(1, 229, 133, 236, 479 - 332, LBLX + 27 + 41 + 3, MBASE(1)); // max acceleration X
  2371. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(2));
  2372. DWIN_Frame_AreaCopy(1, 28, 149, 271 - 202, 479 - 318, LBLX + 27, MBASE(2) + 1);
  2373. DWIN_Frame_AreaCopy(1, 1, 150, 271 - 264, 479 - 319, LBLX + 27 + 41 + 3, MBASE(2) + 2); // max acceleration Y
  2374. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(3));
  2375. DWIN_Frame_AreaCopy(1, 28, 149, 271 - 202, 479 - 318, LBLX + 27, MBASE(3) + 1);
  2376. DWIN_Frame_AreaCopy(1, 9, 150, 271 - 255, 479 - 319, LBLX + 27 + 41 + 3, MBASE(3) + 2); // max acceleration Z
  2377. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(4));
  2378. DWIN_Frame_AreaCopy(1, 28, 149, 271 - 202, 479 - 318, LBLX + 27, MBASE(4) + 1);
  2379. DWIN_Frame_AreaCopy(1, 18, 150, 271 - 246, 479 - 319, LBLX + 27 + 41 + 3, MBASE(4) + 2); // max acceleration E
  2380. }
  2381. else {
  2382. #ifdef USE_STRING_HEADINGS
  2383. Draw_Title("Max Accel (mm/s/s)"); // TODO: GET_TEXT_F
  2384. #else
  2385. DWIN_Frame_AreaCopy(1, 144, 16, 271 - 82, 479 - 453, 14, 8);
  2386. #endif
  2387. draw_max_accel_en(MBASE(1)); say_x(24 + 78 + 6, MBASE(1)); // "Max Acceleration X"
  2388. draw_max_accel_en(MBASE(2)); say_y(24 + 78 + 6, MBASE(2)); // "Max Acceleration Y"
  2389. draw_max_accel_en(MBASE(3)); say_z(24 + 78 + 6, MBASE(3)); // "Max Acceleration Z"
  2390. draw_max_accel_en(MBASE(4)); say_e(24 + 78 + 6, MBASE(4)); // "Max Acceleration E"
  2391. }
  2392. Draw_Back_First();
  2393. LOOP_L_N(i, 4) Draw_Menu_Line(i + 1, ICON_MaxAccX + i);
  2394. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(1), planner.settings.max_acceleration_mm_per_s2[X_AXIS]);
  2395. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(2), planner.settings.max_acceleration_mm_per_s2[Y_AXIS]);
  2396. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(3), planner.settings.max_acceleration_mm_per_s2[Z_AXIS]);
  2397. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Background_black, 4, 210, MBASE(4), planner.settings.max_acceleration_mm_per_s2[E_AXIS]);
  2398. }
  2399. inline void Draw_Max_Jerk_Menu() {
  2400. Clear_Main_Window();
  2401. if (HMI_flag.language_flag) {
  2402. DWIN_Frame_AreaCopy(1, 1, 16, 271 - 243, 479 - 451, 14, 8);
  2403. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(1));
  2404. DWIN_Frame_AreaCopy(1, 1, 180, 271 - 243, 479 - 287, LBLX + 27, MBASE(1) + 1);
  2405. DWIN_Frame_AreaCopy(1, 202, 133, 228, 479 - 332, LBLX + 53, MBASE(1));
  2406. DWIN_Frame_AreaCopy(1, 229, 133, 236, 479 - 332, LBLX + 80 + 3, MBASE(1)); // max corner speed X
  2407. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(2));
  2408. DWIN_Frame_AreaCopy(1, 1, 180, 271 - 243, 479 - 287, LBLX + 27, MBASE(2) + 1);
  2409. DWIN_Frame_AreaCopy(1, 202, 133, 228, 479 - 332, LBLX + 53, MBASE(2));
  2410. DWIN_Frame_AreaCopy(1, 1, 150, 271 - 264, 479 - 319, LBLX + 80 + 3, MBASE(2) + 3); // max corner speed Y
  2411. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(3));
  2412. DWIN_Frame_AreaCopy(1, 1, 180, 271 - 243, 479 - 287, LBLX + 27, MBASE(3) + 1);
  2413. DWIN_Frame_AreaCopy(1, 202, 133, 228, 479 - 332, LBLX + 53, MBASE(3));
  2414. DWIN_Frame_AreaCopy(1, 9, 150, 271 - 255, 479 - 319, LBLX + 80 + 3, MBASE(3) + 3); // max corner speed Z
  2415. DWIN_Frame_AreaCopy(1, 173, 133, 200, 479 - 332, LBLX, MBASE(4));
  2416. DWIN_Frame_AreaCopy(1, 1, 180, 271 - 243, 479 - 287, LBLX + 27, MBASE(4) + 1);
  2417. DWIN_Frame_AreaCopy(1, 202, 133, 228, 479 - 332, LBLX + 53, MBASE(4));
  2418. DWIN_Frame_AreaCopy(1, 18, 150, 271 - 246, 479 - 319, LBLX + 80 + 3, MBASE(4) + 3); // max corner speed E
  2419. }
  2420. else {
  2421. #ifdef USE_STRING_HEADINGS
  2422. Draw_Title("Max Corner"); // TODO: GET_TEXT_F
  2423. #else
  2424. DWIN_Frame_AreaCopy(1, 144, 16, 271 - 82, 479 - 453, 14, 8);
  2425. #endif
  2426. draw_max_en(MBASE(1)); // "Max"
  2427. draw_corner_en(MBASE(1)); // "Corner"
  2428. draw_speed_en(66 + 6, MBASE(1)); // "Speed"
  2429. say_x(106 + 9, MBASE(1)); // "X"
  2430. draw_max_en(MBASE(2)); // "Max"
  2431. draw_corner_en(MBASE(2)); // "Corner"
  2432. draw_speed_en(66 + 6, MBASE(2)); // "Speed"
  2433. say_y(106 + 9, MBASE(2)); // "Y"
  2434. draw_max_en(MBASE(3)); // "Max"
  2435. draw_corner_en(MBASE(3)); // "Corner"
  2436. draw_speed_en(66 + 6, MBASE(3)); // "Speed"
  2437. say_z(106 + 9, MBASE(3)); // "Z"
  2438. draw_max_en(MBASE(4)); // "Max"
  2439. draw_corner_en(MBASE(4)); // "Corner"
  2440. draw_speed_en(66 + 6, MBASE(4)); // "Speed"
  2441. say_e(106 + 9, MBASE(4)); // "E"
  2442. }
  2443. Draw_Back_First();
  2444. LOOP_L_N(i, 4) Draw_Menu_Line(i + 1, ICON_MaxSpeedCornerX + i);
  2445. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(1), planner.max_jerk[X_AXIS] * MINUNITMULT);
  2446. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(2), planner.max_jerk[Y_AXIS] * MINUNITMULT);
  2447. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(3), planner.max_jerk[Z_AXIS] * MINUNITMULT);
  2448. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(4), planner.max_jerk[E_AXIS] * MINUNITMULT);
  2449. }
  2450. inline void Draw_Steps_Menu() {
  2451. Clear_Main_Window();
  2452. if (HMI_flag.language_flag) {
  2453. DWIN_Frame_AreaCopy(1, 1, 16, 271 - 243, 479 - 451, 14, 8);
  2454. DWIN_Frame_AreaCopy(1, 153, 148, 271 - 77, 479 - 318, LBLX, MBASE(1));
  2455. DWIN_Frame_AreaCopy(1, 229, 133, 236, 479 - 332, LBLX + 41 + 3, MBASE(1)); // Transmission Ratio X
  2456. DWIN_Frame_AreaCopy(1, 153, 148, 271 - 77, 479 - 318, LBLX, MBASE(2));
  2457. DWIN_Frame_AreaCopy(1, 1, 150, 271 - 264, 479 - 319, LBLX + 41 + 3, MBASE(2) + 3); // Transmission Ratio Y
  2458. DWIN_Frame_AreaCopy(1, 153, 148, 271 - 77, 479 - 318, LBLX, MBASE(3));
  2459. DWIN_Frame_AreaCopy(1, 9, 150, 271 - 255, 479 - 319, LBLX + 41 + 3, MBASE(3) + 3); // Transmission Ratio Z
  2460. DWIN_Frame_AreaCopy(1, 153, 148, 271 - 77, 479 - 318, LBLX, MBASE(4));
  2461. DWIN_Frame_AreaCopy(1, 18, 150, 271 - 246, 479 - 319, LBLX + 41 + 3, MBASE(4) + 3); // Transmission Ratio E
  2462. }
  2463. else {
  2464. #ifdef USE_STRING_HEADINGS
  2465. Draw_Title("Steps-per-mm"); // TODO: GET_TEXT_F
  2466. #else
  2467. DWIN_Frame_AreaCopy(1, 144, 16, 271 - 82, 479 - 453, 14, 8);
  2468. #endif
  2469. draw_steps_per_mm(MBASE(1)); say_x(100 + 3, MBASE(1)); // "Steps-per-mm X"
  2470. draw_steps_per_mm(MBASE(2)); say_y(100 + 3, MBASE(2)); // "Y"
  2471. draw_steps_per_mm(MBASE(3)); say_z(100 + 3, MBASE(3)); // "Z"
  2472. draw_steps_per_mm(MBASE(4)); say_e(100 + 3, MBASE(4)); // "E"
  2473. }
  2474. Draw_Back_First();
  2475. LOOP_L_N(i, 4) Draw_Menu_Line(i + 1, ICON_StepX + i);
  2476. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(1), planner.settings.axis_steps_per_mm[X_AXIS] * MINUNITMULT);
  2477. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(2), planner.settings.axis_steps_per_mm[Y_AXIS] * MINUNITMULT);
  2478. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(3), planner.settings.axis_steps_per_mm[Z_AXIS] * MINUNITMULT);
  2479. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Background_black, 3, 1, 210, MBASE(4), planner.settings.axis_steps_per_mm[E_AXIS] * MINUNITMULT);
  2480. }
  2481. /* Motion */
  2482. void HMI_Motion(void) {
  2483. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2484. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2485. // Avoid flicker by updating only the previous menu
  2486. if (encoder_diffState == ENCODER_DIFF_CW) {
  2487. if (select_motion.inc(4)) Move_Highlight(1, select_motion.now);
  2488. }
  2489. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2490. if (select_motion.dec()) Move_Highlight(-1, select_motion.now);
  2491. }
  2492. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2493. switch (select_motion.now) {
  2494. case 0: // back
  2495. checkkey = Control;
  2496. select_control.set(2);
  2497. index_control = MROWS;
  2498. Draw_Control_Menu();
  2499. break;
  2500. case 1: // max speed
  2501. checkkey = MaxSpeed;
  2502. select_speed.reset();
  2503. Draw_Max_Speed_Menu();
  2504. break;
  2505. case 2: // max acceleration
  2506. checkkey = MaxAcceleration;
  2507. select_acc.reset();
  2508. Draw_Max_Accel_Menu();
  2509. break;
  2510. case 3: // max corner speed
  2511. checkkey = MaxCorner;
  2512. select_corner.reset();
  2513. Draw_Max_Jerk_Menu();
  2514. break;
  2515. case 4: // transmission ratio
  2516. checkkey = Step;
  2517. select_step.reset();
  2518. Draw_Steps_Menu();
  2519. break;
  2520. default:
  2521. break;
  2522. }
  2523. }
  2524. DWIN_UpdateLCD();
  2525. }
  2526. /* Info */
  2527. void HMI_Info(void) {
  2528. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2529. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2530. if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2531. #if HAS_LEVELING
  2532. checkkey = Control;
  2533. select_control.set(CONTROL_ITEMS);
  2534. Draw_Control_Menu();
  2535. #else
  2536. select_page.set(3);
  2537. Goto_MainMenu();
  2538. #endif
  2539. }
  2540. DWIN_UpdateLCD();
  2541. }
  2542. /* Tune */
  2543. void HMI_Tune(void) {
  2544. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2545. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2546. // Avoid flicker by updating only the previous menu
  2547. if (encoder_diffState == ENCODER_DIFF_CW) {
  2548. if (select_tune.inc(6)) {
  2549. if (select_tune.now > MROWS && select_tune.now > index_tune) {
  2550. index_tune = select_tune.now;
  2551. Scroll_Menu(DWIN_SCROLL_UP);
  2552. Prepare_Item_Lang(5);
  2553. }
  2554. else {
  2555. Move_Highlight(1, select_tune.now + MROWS - index_tune);
  2556. }
  2557. }
  2558. }
  2559. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2560. if (select_tune.dec()) {
  2561. if (select_tune.now < index_tune - MROWS) {
  2562. index_tune--;
  2563. Scroll_Menu(DWIN_SCROLL_DOWN);
  2564. if (index_tune == MROWS) Draw_Back_First();
  2565. }
  2566. else {
  2567. Move_Highlight(-1, select_tune.now + MROWS - index_tune);
  2568. }
  2569. }
  2570. }
  2571. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2572. switch (select_tune.now) {
  2573. case 0: { // Back
  2574. select_print.set(0);
  2575. Goto_PrintProcess();
  2576. }
  2577. break;
  2578. case 1: // Print speed
  2579. checkkey = PrintSpeed;
  2580. HMI_ValueStruct.print_speed = feedrate_percentage;
  2581. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(1 + MROWS - index_tune), feedrate_percentage);
  2582. EncoderRate.encoderRateEnabled = 1;
  2583. break;
  2584. #if HAS_HOTEND
  2585. case 2: // Nozzle temp
  2586. checkkey = ETemp;
  2587. HMI_ValueStruct.E_Temp = thermalManager.temp_hotend[0].target;
  2588. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(2 + MROWS - index_tune), thermalManager.temp_hotend[0].target);
  2589. EncoderRate.encoderRateEnabled = 1;
  2590. break;
  2591. #endif
  2592. #if HAS_HEATED_BED
  2593. case 3: // Bed temp
  2594. checkkey = BedTemp;
  2595. HMI_ValueStruct.Bed_Temp = thermalManager.temp_bed.target;
  2596. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(3 + MROWS - index_tune), thermalManager.temp_bed.target);
  2597. EncoderRate.encoderRateEnabled = 1;
  2598. break;
  2599. #endif
  2600. #if HAS_FAN
  2601. case 4: // Fan speed
  2602. checkkey = FanSpeed;
  2603. HMI_ValueStruct.Fan_speed = thermalManager.fan_speed[0];
  2604. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(4 + MROWS - index_tune), thermalManager.fan_speed[0]);
  2605. EncoderRate.encoderRateEnabled = 1;
  2606. break;
  2607. #endif
  2608. case 5: // Z-offset
  2609. checkkey = Homeoffset;
  2610. HMI_ValueStruct.offset_value = BABY_Z_VAR * 100;
  2611. show_plus_or_minus(font8x16, Select_Color, 2, 2, 202, MBASE(5 + MROWS - index_tune), HMI_ValueStruct.offset_value);
  2612. EncoderRate.encoderRateEnabled = 1;
  2613. break;
  2614. case 6: // Language
  2615. // Select language
  2616. HMI_flag.language_flag = !HMI_flag.language_flag;
  2617. Clear_Main_Window();
  2618. if (HMI_flag.language_flag) {
  2619. set_chinese_to_eeprom();
  2620. DWIN_JPG_CacheTo1(Language_Chinese);
  2621. }
  2622. else {
  2623. set_english_to_eeprom();
  2624. DWIN_JPG_CacheTo1(Language_English);
  2625. }
  2626. Draw_Tune_Menu();
  2627. break;
  2628. default: break;
  2629. }
  2630. }
  2631. DWIN_UpdateLCD();
  2632. }
  2633. /* PLA Preheat */
  2634. void HMI_PLAPreheatSetting(void) {
  2635. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2636. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2637. // Avoid flicker by updating only the previous menu
  2638. if (encoder_diffState == ENCODER_DIFF_CW) {
  2639. if (select_PLA.inc(4)) Move_Highlight(1, select_PLA.now);
  2640. }
  2641. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2642. if (select_PLA.dec()) Move_Highlight(-1, select_PLA.now);
  2643. }
  2644. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2645. switch (select_PLA.now) {
  2646. case 0: // back
  2647. checkkey = TemperatureID;
  2648. select_temp.now = 4;
  2649. HMI_ValueStruct.show_mode = -1;
  2650. Draw_Temperature_Menu();
  2651. break;
  2652. #if HAS_HOTEND
  2653. case 1: // set nozzle temperature
  2654. checkkey = ETemp;
  2655. HMI_ValueStruct.E_Temp = ui.material_preset[0].hotend_temp;
  2656. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(1), ui.material_preset[0].hotend_temp);
  2657. EncoderRate.encoderRateEnabled = 1;
  2658. break;
  2659. #endif
  2660. #if HAS_HEATED_BED
  2661. case 2: // set bed temperature
  2662. checkkey = BedTemp;
  2663. HMI_ValueStruct.Bed_Temp = ui.material_preset[0].bed_temp;
  2664. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(2), ui.material_preset[0].bed_temp);
  2665. EncoderRate.encoderRateEnabled = 1;
  2666. break;
  2667. #endif
  2668. #if HAS_FAN
  2669. case 3: // set fan speed
  2670. checkkey = FanSpeed;
  2671. HMI_ValueStruct.Fan_speed = ui.material_preset[0].fan_speed;
  2672. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(3), ui.material_preset[0].fan_speed);
  2673. EncoderRate.encoderRateEnabled = 1;
  2674. break;
  2675. #endif
  2676. case 4: // save PLA configuration
  2677. if (settings.save()) {
  2678. buzzer.tone(100, 659);
  2679. buzzer.tone(100, 698);
  2680. }
  2681. else
  2682. buzzer.tone(20, 440);
  2683. break;
  2684. default: break;
  2685. }
  2686. }
  2687. DWIN_UpdateLCD();
  2688. }
  2689. /* ABS Preheat */
  2690. void HMI_ABSPreheatSetting(void) {
  2691. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2692. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2693. // Avoid flicker by updating only the previous menu
  2694. if (encoder_diffState == ENCODER_DIFF_CW) {
  2695. if (select_ABS.inc(4)) Move_Highlight(1, select_ABS.now);
  2696. }
  2697. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2698. if (select_ABS.dec()) Move_Highlight(-1, select_ABS.now);
  2699. }
  2700. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2701. switch (select_ABS.now) {
  2702. case 0: // back
  2703. checkkey = TemperatureID;
  2704. select_temp.now = 5;
  2705. HMI_ValueStruct.show_mode = -1;
  2706. Draw_Temperature_Menu();
  2707. break;
  2708. #if HAS_HOTEND
  2709. case 1: // set nozzle temperature
  2710. checkkey = ETemp;
  2711. HMI_ValueStruct.E_Temp = ui.material_preset[1].hotend_temp;
  2712. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(1), ui.material_preset[1].hotend_temp);
  2713. EncoderRate.encoderRateEnabled = 1;
  2714. break;
  2715. #endif
  2716. #if HAS_HEATED_BED
  2717. case 2: // set bed temperature
  2718. checkkey = BedTemp;
  2719. HMI_ValueStruct.Bed_Temp = ui.material_preset[1].bed_temp;
  2720. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(2), ui.material_preset[1].bed_temp);
  2721. EncoderRate.encoderRateEnabled = 1;
  2722. break;
  2723. #endif
  2724. #if HAS_FAN
  2725. case 3: // set fan speed
  2726. checkkey = FanSpeed;
  2727. HMI_ValueStruct.Fan_speed = ui.material_preset[1].fan_speed;
  2728. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 3, 216, MBASE(3), ui.material_preset[1].fan_speed);
  2729. EncoderRate.encoderRateEnabled = 1;
  2730. break;
  2731. #endif
  2732. case 4: // save PLA configuration
  2733. if (settings.save()) {
  2734. buzzer.tone(100, 659);
  2735. buzzer.tone(100, 698);
  2736. }
  2737. else
  2738. buzzer.tone(20, 440);
  2739. break;
  2740. default:
  2741. break;
  2742. }
  2743. }
  2744. DWIN_UpdateLCD();
  2745. }
  2746. /* Max Speed */
  2747. void HMI_MaxSpeed(void) {
  2748. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2749. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2750. // Avoid flicker by updating only the previous menu
  2751. if (encoder_diffState == ENCODER_DIFF_CW) {
  2752. if (select_speed.inc(4)) Move_Highlight(1, select_speed.now);
  2753. }
  2754. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2755. if (select_speed.dec()) Move_Highlight(-1, select_speed.now);
  2756. }
  2757. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2758. switch (select_speed.now) {
  2759. case 0: // back
  2760. checkkey = Motion;
  2761. select_motion.now = 1;
  2762. Draw_Motion_Menu();
  2763. break;
  2764. case 1: // max Speed X
  2765. checkkey = MaxSpeed_value;
  2766. HMI_flag.feedspeed_flag = X_AXIS;
  2767. HMI_ValueStruct.Max_Feedspeed = planner.settings.max_feedrate_mm_s[X_AXIS];
  2768. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_speed.now), HMI_ValueStruct.Max_Feedspeed);
  2769. EncoderRate.encoderRateEnabled = 1;
  2770. break;
  2771. case 2: // max Speed Y
  2772. checkkey = MaxSpeed_value;
  2773. HMI_flag.feedspeed_flag = Y_AXIS;
  2774. HMI_ValueStruct.Max_Feedspeed = planner.settings.max_feedrate_mm_s[Y_AXIS];
  2775. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_speed.now), HMI_ValueStruct.Max_Feedspeed);
  2776. EncoderRate.encoderRateEnabled = 1;
  2777. break;
  2778. case 3: // max Speed Z
  2779. checkkey = MaxSpeed_value;
  2780. HMI_flag.feedspeed_flag = Z_AXIS;
  2781. HMI_ValueStruct.Max_Feedspeed = planner.settings.max_feedrate_mm_s[Z_AXIS];
  2782. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_speed.now), HMI_ValueStruct.Max_Feedspeed);
  2783. EncoderRate.encoderRateEnabled = 1;
  2784. break;
  2785. case 4: // max Speed E
  2786. checkkey = MaxSpeed_value;
  2787. HMI_flag.feedspeed_flag = E_AXIS;
  2788. HMI_ValueStruct.Max_Feedspeed = planner.settings.max_feedrate_mm_s[E_AXIS];
  2789. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_speed.now), HMI_ValueStruct.Max_Feedspeed);
  2790. EncoderRate.encoderRateEnabled = 1;
  2791. break;
  2792. default:
  2793. break;
  2794. }
  2795. }
  2796. DWIN_UpdateLCD();
  2797. }
  2798. /* Max Acceleration */
  2799. void HMI_MaxAcceleration(void) {
  2800. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2801. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2802. // Avoid flicker by updating only the previous menu
  2803. if (encoder_diffState == ENCODER_DIFF_CW) {
  2804. if (select_acc.inc(4)) Move_Highlight(1, select_acc.now);
  2805. }
  2806. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2807. if (select_acc.dec()) Move_Highlight(-1, select_acc.now);
  2808. }
  2809. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2810. switch (select_acc.now) {
  2811. case 0: // back
  2812. checkkey = Motion;
  2813. select_motion.now = 2;
  2814. Draw_Motion_Menu();
  2815. break;
  2816. case 1: // max acceleration X
  2817. checkkey = MaxAcceleration_value;
  2818. HMI_flag.acc_flag = X_AXIS;
  2819. HMI_ValueStruct.Max_Acceleration = planner.settings.max_acceleration_mm_per_s2[X_AXIS];
  2820. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_acc.now), HMI_ValueStruct.Max_Acceleration);
  2821. EncoderRate.encoderRateEnabled = 1;
  2822. break;
  2823. case 2: // max acceleration Y
  2824. checkkey = MaxAcceleration_value;
  2825. HMI_flag.acc_flag = Y_AXIS;
  2826. HMI_ValueStruct.Max_Acceleration = planner.settings.max_acceleration_mm_per_s2[Y_AXIS];
  2827. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_acc.now), HMI_ValueStruct.Max_Acceleration);
  2828. EncoderRate.encoderRateEnabled = 1;
  2829. break;
  2830. case 3: // max acceleration Z
  2831. checkkey = MaxAcceleration_value;
  2832. HMI_flag.acc_flag = Z_AXIS;
  2833. HMI_ValueStruct.Max_Acceleration = planner.settings.max_acceleration_mm_per_s2[Z_AXIS];
  2834. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_acc.now), HMI_ValueStruct.Max_Acceleration);
  2835. EncoderRate.encoderRateEnabled = 1;
  2836. break;
  2837. case 4: // max acceleration E
  2838. checkkey = MaxAcceleration_value;
  2839. HMI_flag.acc_flag = E_AXIS;
  2840. HMI_ValueStruct.Max_Acceleration = planner.settings.max_acceleration_mm_per_s2[E_AXIS];
  2841. DWIN_Draw_IntValue(true, true, 0, font8x16, White, Select_Color, 4, 210, MBASE(select_acc.now), HMI_ValueStruct.Max_Acceleration);
  2842. EncoderRate.encoderRateEnabled = 1;
  2843. break;
  2844. default:
  2845. break;
  2846. }
  2847. }
  2848. DWIN_UpdateLCD();
  2849. }
  2850. /* Max Corner */
  2851. void HMI_MaxCorner(void) {
  2852. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2853. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2854. // Avoid flicker by updating only the previous menu
  2855. if (encoder_diffState == ENCODER_DIFF_CW) {
  2856. if (select_corner.inc(4)) Move_Highlight(1, select_corner.now);
  2857. }
  2858. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2859. if (select_corner.dec()) Move_Highlight(-1, select_corner.now);
  2860. }
  2861. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2862. switch (select_corner.now) {
  2863. case 0: // back
  2864. checkkey = Motion;
  2865. select_motion.now = 3;
  2866. Draw_Motion_Menu();
  2867. break;
  2868. case 1: // max corner X
  2869. checkkey = MaxCorner_value;
  2870. HMI_flag.corner_flag = X_AXIS;
  2871. HMI_ValueStruct.Max_Corner = planner.max_jerk[X_AXIS] * MINUNITMULT;
  2872. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_corner.now), HMI_ValueStruct.Max_Corner);
  2873. EncoderRate.encoderRateEnabled = 1;
  2874. break;
  2875. case 2: // max corner Y
  2876. checkkey = MaxCorner_value;
  2877. HMI_flag.corner_flag = Y_AXIS;
  2878. HMI_ValueStruct.Max_Corner = planner.max_jerk[Y_AXIS] * MINUNITMULT;
  2879. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_corner.now), HMI_ValueStruct.Max_Corner);
  2880. EncoderRate.encoderRateEnabled = 1;
  2881. break;
  2882. case 3: // max corner Z
  2883. checkkey = MaxCorner_value;
  2884. HMI_flag.corner_flag = Z_AXIS;
  2885. HMI_ValueStruct.Max_Corner = planner.max_jerk[Z_AXIS] * MINUNITMULT;
  2886. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_corner.now), HMI_ValueStruct.Max_Corner);
  2887. EncoderRate.encoderRateEnabled = 1;
  2888. break;
  2889. case 4: // max corner E
  2890. checkkey = MaxCorner_value;
  2891. HMI_flag.corner_flag = E_AXIS;
  2892. HMI_ValueStruct.Max_Corner = planner.max_jerk[E_AXIS] * MINUNITMULT;
  2893. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_corner.now), HMI_ValueStruct.Max_Corner);
  2894. EncoderRate.encoderRateEnabled = 1;
  2895. break;
  2896. default:
  2897. break;
  2898. }
  2899. }
  2900. DWIN_UpdateLCD();
  2901. }
  2902. /* Step */
  2903. void HMI_Step(void) {
  2904. ENCODER_DiffState encoder_diffState = get_encoder_state();
  2905. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2906. // Avoid flicker by updating only the previous menu
  2907. if (encoder_diffState == ENCODER_DIFF_CW) {
  2908. if (select_step.inc(4)) Move_Highlight(1, select_step.now);
  2909. }
  2910. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  2911. if (select_step.dec()) Move_Highlight(-1, select_step.now);
  2912. }
  2913. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2914. switch (select_step.now) {
  2915. case 0: // back
  2916. checkkey = Motion;
  2917. select_motion.now = 4;
  2918. Draw_Motion_Menu();
  2919. break;
  2920. case 1: // max step X
  2921. checkkey = Step_value;
  2922. HMI_flag.step_flag = X_AXIS;
  2923. HMI_ValueStruct.Max_Step = planner.settings.axis_steps_per_mm[X_AXIS] * MINUNITMULT;
  2924. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step);
  2925. EncoderRate.encoderRateEnabled = 1;
  2926. break;
  2927. case 2: // max step Y
  2928. checkkey = Step_value;
  2929. HMI_flag.step_flag = Y_AXIS;
  2930. HMI_ValueStruct.Max_Step = planner.settings.axis_steps_per_mm[Y_AXIS] * MINUNITMULT;
  2931. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step);
  2932. EncoderRate.encoderRateEnabled = 1;
  2933. break;
  2934. case 3: // max step Z
  2935. checkkey = Step_value;
  2936. HMI_flag.step_flag = Z_AXIS;
  2937. HMI_ValueStruct.Max_Step = planner.settings.axis_steps_per_mm[Z_AXIS] * MINUNITMULT;
  2938. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step);
  2939. EncoderRate.encoderRateEnabled = 1;
  2940. break;
  2941. case 4: // max step E
  2942. checkkey = Step_value;
  2943. HMI_flag.step_flag = E_AXIS;
  2944. HMI_ValueStruct.Max_Step = planner.settings.axis_steps_per_mm[E_AXIS] * MINUNITMULT;
  2945. DWIN_Draw_FloatValue(true, true, 0, font8x16, White, Select_Color, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step);
  2946. EncoderRate.encoderRateEnabled = 1;
  2947. break;
  2948. default:
  2949. break;
  2950. }
  2951. }
  2952. DWIN_UpdateLCD();
  2953. }
  2954. void HMI_Init(void) {
  2955. HMI_SDCardInit();
  2956. for (uint16_t t = 0; t <= 100; t += 2) {
  2957. DWIN_ICON_Show(ICON, ICON_Bar, 15, 260);
  2958. DWIN_Draw_Rectangle(1, Background_black, 15 + t * 242 / 100, 260, 257, 280);
  2959. DWIN_UpdateLCD();
  2960. delay(20);
  2961. }
  2962. lcd_select_language();
  2963. #if ENABLED(FIX_MOUNTED_PROBE) // For "CREALITY_TOUCH" probe too?
  2964. SET_OUTPUT(COM_PIN);
  2965. WRITE(COM_PIN, 1);
  2966. #endif
  2967. delay(200);
  2968. }
  2969. void DWIN_Update(void) {
  2970. EachMomentUpdate(); // Status update
  2971. HMI_SDCardUpdate(); // SD card update
  2972. DWIN_HandleScreen(); // Rotary encoder update
  2973. }
  2974. void EachMomentUpdate(void) {
  2975. static millis_t next_rts_update_ms = 0;
  2976. const millis_t ms = millis();
  2977. if (PENDING(ms, next_rts_update_ms)) return;
  2978. next_rts_update_ms = ms + DWIN_SCROLL_UPDATE_INTERVAL;
  2979. // variable update
  2980. update_variable();
  2981. if (checkkey == PrintProcess) {
  2982. // if print done
  2983. if (HMI_flag.print_finish && !HMI_flag.confirm_flag) {
  2984. HMI_flag.print_finish = 0;
  2985. HMI_flag.confirm_flag = 1;
  2986. TERN_(POWER_LOSS_RECOVERY, recovery.cancel());
  2987. planner.finish_and_disable();
  2988. // show percent bar and value
  2989. Percentrecord = 0;
  2990. Draw_Print_ProgressBar();
  2991. // show print done confirm
  2992. DWIN_Draw_Rectangle(1, Background_black, 0, 250, 271, 360);
  2993. DWIN_ICON_Show(ICON, HMI_flag.language_flag ? ICON_Confirm_C : ICON_Confirm_E, 86, 302 - 19);
  2994. }
  2995. else if (HMI_flag.pause_flag != printingIsPaused()) {
  2996. // print status update
  2997. HMI_flag.pause_flag = printingIsPaused();
  2998. if (HMI_flag.pause_flag) ICON_Continue(); else ICON_Pause();
  2999. }
  3000. }
  3001. // pause after homing
  3002. if (pause_action_flag && printingIsPaused() && !planner.has_blocks_queued()) {
  3003. pause_action_flag = 0;
  3004. #if ENABLED(PAUSE_HEAT)
  3005. tempbed = thermalManager.temp_bed.target;
  3006. temphot = thermalManager.temp_hotend[0].target;
  3007. thermalManager.disable_all_heaters();
  3008. #endif
  3009. queue.inject_P(PSTR("G1 F1200 X0 Y0"));
  3010. }
  3011. if (card.isPrinting() && checkkey == PrintProcess) { // print process
  3012. const uint8_t card_pct = card.percentDone();
  3013. static uint8_t last_cardpercentValue = 101;
  3014. if (last_cardpercentValue != card_pct) { // print percent
  3015. last_cardpercentValue = card_pct;
  3016. if (card_pct) {
  3017. Percentrecord = card_pct;
  3018. Draw_Print_ProgressBar();
  3019. }
  3020. }
  3021. duration_t elapsed = print_job_timer.duration(); // print timer
  3022. /* already print time */
  3023. const uint16_t min = (elapsed.value % 3600) / 60;
  3024. if (last_Printtime != min) { // 1 minute update
  3025. last_Printtime = min;
  3026. Draw_Print_ProgressElapsed();
  3027. }
  3028. /* remain print time */
  3029. static millis_t next_remain_time_update = 0;
  3030. if (elapsed.minute() > 5 && ELAPSED(ms, next_remain_time_update) && HMI_flag.heat_flag == 0) { // show after 5 min and 20s update
  3031. remain_time = ((elapsed.value - dwin_heat_time) * ((float)card.getFileSize() / (float)card.getIndex())) - (elapsed.value - dwin_heat_time);
  3032. next_remain_time_update += 20 * 1000UL;
  3033. Draw_Print_ProgressRemain();
  3034. }
  3035. }
  3036. else if (abort_flag && !HMI_flag.home_flag) { // Print Stop
  3037. abort_flag = 0;
  3038. HMI_ValueStruct.print_speed = feedrate_percentage = 100;
  3039. zprobe_zoffset = TERN(HAS_LEVELING, probe.offset.z, 0);
  3040. planner.finish_and_disable();
  3041. #if DISABLED(SD_ABORT_NO_COOLDOWN)
  3042. thermalManager.disable_all_heaters();
  3043. #endif
  3044. select_page.set(0);
  3045. Goto_MainMenu();
  3046. }
  3047. else if (DWIN_lcd_sd_status && recovery.dwin_flag) { // resume print before power off
  3048. recovery.dwin_flag = false;
  3049. recovery.load();
  3050. if (!recovery.valid()) return recovery.purge();
  3051. auto draw_first_option = [](const bool sel) {
  3052. const uint16_t c1 = sel ? Background_window : Select_Color;
  3053. DWIN_Draw_Rectangle(0, c1, 25, 306, 126, 345);
  3054. DWIN_Draw_Rectangle(0, c1, 24, 305, 127, 346);
  3055. };
  3056. auto update_selection = [&](const bool sel) {
  3057. HMI_flag.select_flag = sel;
  3058. draw_first_option(sel);
  3059. const uint16_t c2 = sel ? Select_Color : Background_window;
  3060. DWIN_Draw_Rectangle(0, c2, 145, 306, 246, 345);
  3061. DWIN_Draw_Rectangle(0, c2, 144, 305, 247, 346);
  3062. };
  3063. const uint16_t fileCnt = card.get_num_Files();
  3064. for (uint16_t i = 0; i < fileCnt; i++) {
  3065. // TODO: Resume print via M1000 then update the UI
  3066. // with the active filename which can come from CardReader.
  3067. card.getfilename_sorted(SD_ORDER(i, fileCnt));
  3068. if (!strcmp(card.filename, &recovery.info.sd_filename[1])) { // Resume print before power failure while have the same file
  3069. recovery_flag = 1;
  3070. HMI_flag.select_flag = 1;
  3071. Popup_Window_Resume();
  3072. draw_first_option(false);
  3073. char * const name = card.longest_filename();
  3074. DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, (DWIN_WIDTH - strlen(name) * MENU_CHR_W) / 2, 252, name);
  3075. DWIN_UpdateLCD();
  3076. break;
  3077. }
  3078. }
  3079. // if hasn't resumable G-code file
  3080. if (!recovery_flag) return;
  3081. while (recovery_flag) {
  3082. ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze();
  3083. if (encoder_diffState != ENCODER_DIFF_NO) {
  3084. if (encoder_diffState == ENCODER_DIFF_ENTER) {
  3085. recovery_flag = 0;
  3086. if (HMI_flag.select_flag) break;
  3087. TERN_(POWER_LOSS_RECOVERY, recovery.cancel());
  3088. HMI_StartFrame(true);
  3089. return;
  3090. }
  3091. else
  3092. update_selection(encoder_diffState == ENCODER_DIFF_CCW);
  3093. DWIN_UpdateLCD();
  3094. }
  3095. }
  3096. select_print.set(0);
  3097. HMI_ValueStruct.show_mode = 0;
  3098. HMI_StartFrame(false);
  3099. recovery.resume();
  3100. return;
  3101. }
  3102. DWIN_UpdateLCD();
  3103. }
  3104. void DWIN_HandleScreen(void) {
  3105. switch (checkkey) {
  3106. case MainMenu: HMI_MainMenu(); break;
  3107. case SelectFile: HMI_SelectFile(); break;
  3108. case Prepare: HMI_Prepare(); break;
  3109. case Control: HMI_Control(); break;
  3110. case Leveling: break;
  3111. case PrintProcess: HMI_Printing(); break;
  3112. case Print_window: HMI_PauseOrStop(); break;
  3113. case AxisMove: HMI_AxisMove(); break;
  3114. case TemperatureID: HMI_Temperature(); break;
  3115. case Motion: HMI_Motion(); break;
  3116. case Info: HMI_Info(); break;
  3117. case Tune: HMI_Tune(); break;
  3118. case PLAPreheat: HMI_PLAPreheatSetting(); break;
  3119. case ABSPreheat: HMI_ABSPreheatSetting(); break;
  3120. case MaxSpeed: HMI_MaxSpeed(); break;
  3121. case MaxAcceleration: HMI_MaxAcceleration(); break;
  3122. case MaxCorner: HMI_MaxCorner(); break;
  3123. case Step: HMI_Step(); break;
  3124. case Move_X: HMI_Move_X(); break;
  3125. case Move_Y: HMI_Move_Y(); break;
  3126. case Move_Z: HMI_Move_Z(); break;
  3127. case Extruder: HMI_Move_E(); break;
  3128. case Homeoffset: HMI_Zoffset(); break;
  3129. #if HAS_HOTEND
  3130. case ETemp: HMI_ETemp(); break;
  3131. #endif
  3132. #if HAS_HEATED_BED
  3133. case BedTemp: HMI_BedTemp(); break;
  3134. #endif
  3135. #if HAS_FAN
  3136. case FanSpeed: HMI_FanSpeed(); break;
  3137. #endif
  3138. case PrintSpeed: HMI_PrintSpeed(); break;
  3139. case MaxSpeed_value: HMI_MaxFeedspeedXYZE(); break;
  3140. case MaxAcceleration_value: HMI_MaxAccelerationXYZE(); break;
  3141. case MaxCorner_value: HMI_MaxCornerXYZE(); break;
  3142. case Step_value: HMI_StepXYZE(); break;
  3143. default: break;
  3144. }
  3145. }
  3146. void DWIN_CompletedHoming(void) {
  3147. HMI_flag.home_flag = false;
  3148. if (checkkey == Last_Prepare) {
  3149. checkkey = Prepare;
  3150. select_prepare.now = 3;
  3151. index_prepare = MROWS;
  3152. Draw_Prepare_Menu();
  3153. }
  3154. else if (checkkey == Back_Main) {
  3155. HMI_ValueStruct.print_speed = feedrate_percentage = 100;
  3156. zprobe_zoffset = TERN0(BLTOUCH, probe.offset.z);
  3157. planner.finish_and_disable();
  3158. Goto_MainMenu();
  3159. }
  3160. }
  3161. void DWIN_CompletedLeveling(void) {
  3162. if (checkkey == Leveling) Goto_MainMenu();
  3163. }
  3164. #endif // DWIN_CREALITY_LCD