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

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