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

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