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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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 UI Enhanced implementation
  24. * Author: Miguel A. Risco-Castillo
  25. * Version: 3.6.3
  26. * Date: 2021/09/10
  27. */
  28. #include "../../../inc/MarlinConfigPre.h"
  29. #if ENABLED(DWIN_CREALITY_LCD_ENHANCED)
  30. #include "dwin.h"
  31. #include "../../fontutils.h"
  32. #include "../../marlinui.h"
  33. #include "../../../sd/cardreader.h"
  34. #include "../../../MarlinCore.h"
  35. #include "../../../core/serial.h"
  36. #include "../../../core/macros.h"
  37. #include "../../../module/temperature.h"
  38. #include "../../../module/printcounter.h"
  39. #include "../../../module/motion.h"
  40. #include "../../../module/planner.h"
  41. #include "../../../gcode/gcode.h"
  42. #include "../../../gcode/queue.h"
  43. #if HAS_FILAMENT_SENSOR
  44. #include "../../../feature/runout.h"
  45. #endif
  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_MESH || 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 EITHER(BABYSTEP_ZPROBE_OFFSET, JUST_BABYSTEP)
  59. #include "../../../feature/babystep.h"
  60. #endif
  61. #if ENABLED(POWER_LOSS_RECOVERY)
  62. #include "../../../feature/powerloss.h"
  63. #endif
  64. #if HAS_MESH
  65. #include "meshviewer.h"
  66. #endif
  67. #include <WString.h>
  68. #include <stdio.h>
  69. #include <string.h>
  70. #ifndef MACHINE_SIZE
  71. #define MACHINE_SIZE STRINGIFY(X_BED_SIZE) "x" STRINGIFY(Y_BED_SIZE) "x" STRINGIFY(Z_MAX_POS)
  72. #endif
  73. #include "lockscreen.h"
  74. #ifndef CORP_WEBSITE
  75. #define CORP_WEBSITE WEBSITE_URL
  76. #endif
  77. #define PAUSE_HEAT
  78. #define MENU_CHAR_LIMIT 24
  79. // Print speed limit
  80. #define MIN_PRINT_SPEED 10
  81. #define MAX_PRINT_SPEED 999
  82. // Print flow limit
  83. #define MIN_PRINT_FLOW 10
  84. #define MAX_PRINT_FLOW 299
  85. // Load and Unload limits
  86. #define MAX_LOAD_UNLOAD 500
  87. // Feedspeed limit (max feedspeed = DEFAULT_MAX_FEEDRATE * 2)
  88. #define MIN_MAXFEEDSPEED 1
  89. #define MIN_MAXACCELERATION 1
  90. #define MIN_MAXJERK 0.1
  91. #define MIN_STEP 1
  92. #define MAX_STEP 999.9
  93. // Extruder's temperature limits
  94. #define MIN_ETEMP HEATER_0_MINTEMP
  95. #define MAX_ETEMP (HEATER_0_MAXTEMP - HOTEND_OVERSHOOT)
  96. #define FEEDRATE_E (60)
  97. // Minimum unit (0.1) : multiple (10)
  98. #define UNITFDIGITS 1
  99. #define MINUNITMULT POW(10, UNITFDIGITS)
  100. #define ENCODER_WAIT_MS 20
  101. #define DWIN_VAR_UPDATE_INTERVAL 1024
  102. #define DWIN_SCROLL_UPDATE_INTERVAL SEC_TO_MS(2)
  103. #define DWIN_REMAIN_TIME_UPDATE_INTERVAL SEC_TO_MS(20)
  104. #define BABY_Z_VAR TERN(HAS_BED_PROBE, probe.offset.z, dwin_zoffset)
  105. // Structs
  106. HMI_value_t HMI_value;
  107. HMI_flag_t HMI_flag{0};
  108. HMI_data_t HMI_data;
  109. millis_t dwin_heat_time = 0;
  110. uint8_t checkkey = MainMenu, last_checkkey = MainMenu;
  111. enum SelectItem : uint8_t {
  112. PAGE_PRINT = 0,
  113. PAGE_PREPARE,
  114. PAGE_CONTROL,
  115. PAGE_INFO_LEVELING,
  116. PAGE_COUNT,
  117. PRINT_SETUP = 0,
  118. PRINT_PAUSE_RESUME,
  119. PRINT_STOP,
  120. PRINT_COUNT
  121. };
  122. typedef struct {
  123. uint8_t now, last;
  124. void set(uint8_t v) { now = last = v; }
  125. void reset() { set(0); }
  126. bool changed() { bool c = (now != last); if (c) last = now; return c; }
  127. bool dec() { if (now) now--; return changed(); }
  128. bool inc(uint8_t v) { if (now < (v - 1)) now++; else now = (v - 1); return changed(); }
  129. } select_t;
  130. select_t select_page{0}, select_file{0}, select_print{0};
  131. uint8_t index_file = MROWS;
  132. bool dwin_abort_flag = false; // Flag to reset feedrate, return to Home
  133. constexpr float default_max_feedrate[] = DEFAULT_MAX_FEEDRATE;
  134. constexpr float default_max_acceleration[] = DEFAULT_MAX_ACCELERATION;
  135. #if HAS_CLASSIC_JERK
  136. constexpr float default_max_jerk[] = { DEFAULT_XJERK, DEFAULT_YJERK, DEFAULT_ZJERK, DEFAULT_EJERK };
  137. #endif
  138. static uint8_t _percent_done = 0;
  139. static uint32_t _remain_time = 0;
  140. // Additional Aux Host Support
  141. static bool sdprint = false;
  142. #if ENABLED(PAUSE_HEAT)
  143. #if HAS_HOTEND
  144. celsius_t resume_hotend_temp = 0;
  145. #endif
  146. #if HAS_HEATED_BED
  147. celsius_t resume_bed_temp = 0;
  148. #endif
  149. #if HAS_FAN
  150. uint16_t resume_fan = 0;
  151. #endif
  152. #endif
  153. #if HAS_ZOFFSET_ITEM
  154. float dwin_zoffset = 0, last_zoffset = 0;
  155. #endif
  156. #if HAS_HOTEND
  157. float last_E = 0;
  158. #endif
  159. // New menu system pointers
  160. MenuClass *PrepareMenu = nullptr;
  161. MenuClass *LevBedMenu = nullptr;
  162. MenuClass *MoveMenu = nullptr;
  163. MenuClass *ControlMenu = nullptr;
  164. MenuClass *AdvancedSettings = nullptr;
  165. #if HAS_HOME_OFFSET
  166. MenuClass *HomeOffMenu = nullptr;
  167. #endif
  168. #if HAS_BED_PROBE
  169. MenuClass *ProbeSetMenu = nullptr;
  170. #endif
  171. MenuClass *FilSetMenu = nullptr;
  172. MenuClass *SelectColorMenu = nullptr;
  173. MenuClass *GetColorMenu = nullptr;
  174. MenuClass *TuneMenu = nullptr;
  175. MenuClass *MotionMenu = nullptr;
  176. MenuClass *FilamentMenu = nullptr;
  177. #if ENABLED(MESH_BED_LEVELING)
  178. MenuClass *ManualMesh = nullptr;
  179. #endif
  180. #if HAS_HOTEND
  181. MenuClass *PreheatMenu = nullptr;
  182. #endif
  183. MenuClass *TemperatureMenu = nullptr;
  184. MenuClass *MaxSpeedMenu = nullptr;
  185. MenuClass *MaxAccelMenu = nullptr;
  186. MenuClass *MaxJerkMenu = nullptr;
  187. MenuClass *StepsMenu = nullptr;
  188. MenuClass *HotendPIDMenu = nullptr;
  189. MenuClass *BedPIDMenu = nullptr;
  190. #if EITHER(HAS_BED_PROBE, BABYSTEPPING)
  191. MenuClass *ZOffsetWizMenu = nullptr;
  192. #endif
  193. // Updatable menuitems pointers
  194. MenuItemClass *HotendTargetItem = nullptr;
  195. MenuItemClass *BedTargetItem = nullptr;
  196. MenuItemClass *FanSpeedItem = nullptr;
  197. MenuItemClass *MMeshMoveZItem = nullptr;
  198. #define DWIN_LANGUAGE_EEPROM_ADDRESS 0x01 // Between 0x01 and 0x63 (EEPROM_OFFSET-1)
  199. // BL24CXX::check() uses 0x00
  200. inline bool HMI_IsChinese() { return HMI_flag.language == DWIN_CHINESE; }
  201. void HMI_SetLanguageCache() {
  202. DWIN_JPG_CacheTo1(HMI_IsChinese() ? Language_Chinese : Language_English);
  203. }
  204. void HMI_SetLanguage() {
  205. #if BOTH(EEPROM_SETTINGS, IIC_BL24CXX_EEPROM)
  206. BL24CXX::read(DWIN_LANGUAGE_EEPROM_ADDRESS, (uint8_t*)&HMI_flag.language, sizeof(HMI_flag.language));
  207. #endif
  208. HMI_SetLanguageCache();
  209. }
  210. void HMI_ToggleLanguage() {
  211. HMI_flag.language = HMI_IsChinese() ? DWIN_ENGLISH : DWIN_CHINESE;
  212. HMI_SetLanguageCache();
  213. #if BOTH(EEPROM_SETTINGS, IIC_BL24CXX_EEPROM)
  214. BL24CXX::write(DWIN_LANGUAGE_EEPROM_ADDRESS, (uint8_t*)&HMI_flag.language, sizeof(HMI_flag.language));
  215. #endif
  216. }
  217. typedef struct { uint16_t x, y[2], w, h; } text_info_t;
  218. void ICON_Button(const bool here, const int iconid, const frame_rect_t &ico, const text_info_t (&txt)[2]) {
  219. const bool cn = HMI_IsChinese();
  220. DWIN_ICON_Show(true, false, false, ICON, iconid + here, ico.x, ico.y);
  221. if (here) DWIN_Draw_Rectangle(0, HMI_data.Highlight_Color, ico.x, ico.y, ico.x + ico.w - 1, ico.y + ico.h - 1);
  222. DWIN_Frame_AreaCopy(1, txt[cn].x, txt[cn].y[here], txt[cn].x + txt[cn].w - 1, txt[cn].y[here] + txt[cn].h - 1, ico.x + (ico.w - txt[cn].w) / 2, (ico.y + ico.h - 28) - txt[cn].h/2);
  223. }
  224. //
  225. // Main Menu: "Print"
  226. //
  227. void ICON_Print() {
  228. constexpr frame_rect_t ico = { 17, 110, 110, 100 };
  229. constexpr text_info_t txt[2] = {
  230. { 1, { 417, 449 }, 30, 14 },
  231. { 1, { 405, 447 }, 27, 15 }
  232. };
  233. ICON_Button(select_page.now == PAGE_PRINT, ICON_Print_0, ico, txt);
  234. }
  235. //
  236. // Main Menu: "Prepare"
  237. //
  238. void ICON_Prepare() {
  239. constexpr frame_rect_t ico = { 145, 110, 110, 100 };
  240. constexpr text_info_t txt[2] = {
  241. { 33, { 417, 449 }, 51, 14 },
  242. { 31, { 405, 447 }, 27, 15 }
  243. };
  244. ICON_Button(select_page.now == PAGE_PREPARE, ICON_Prepare_0, ico, txt);
  245. }
  246. //
  247. // Main Menu: "Control"
  248. //
  249. void ICON_Control() {
  250. constexpr frame_rect_t ico = { 17, 226, 110, 100 };
  251. constexpr text_info_t txt[2] = {
  252. { 85, { 417, 449 }, 46, 14 },
  253. { 61, { 405, 447 }, 27, 15 }
  254. };
  255. ICON_Button(select_page.now == PAGE_CONTROL, ICON_Control_0, ico, txt);
  256. }
  257. //
  258. // Main Menu: "Info"
  259. //
  260. void ICON_StartInfo() {
  261. constexpr frame_rect_t ico = { 145, 226, 110, 100 };
  262. constexpr text_info_t txt[2] = {
  263. { 133, { 417, 449 }, 23, 14 },
  264. { 91, { 405, 447 }, 27, 15 }
  265. };
  266. ICON_Button(select_page.now == PAGE_INFO_LEVELING, ICON_Info_0, ico, txt);
  267. }
  268. //
  269. // Main Menu: "Level"
  270. //
  271. void ICON_Leveling() {
  272. constexpr frame_rect_t ico = { 145, 226, 110, 100 };
  273. constexpr text_info_t txt[2] = {
  274. { 88, { 433, 464 }, 36, 14 },
  275. { 211, { 405, 447 }, 27, 15 }
  276. };
  277. ICON_Button(select_page.now == PAGE_INFO_LEVELING, ICON_Leveling_0, ico, txt);
  278. }
  279. //
  280. // Printing: "Tune"
  281. //
  282. void ICON_Tune() {
  283. constexpr frame_rect_t ico = { 8, 232, 80, 100 };
  284. constexpr text_info_t txt[2] = {
  285. { 0, { 433, 464 }, 32, 14 },
  286. { 121, { 405, 447 }, 27, 15 }
  287. };
  288. ICON_Button(select_print.now == PRINT_SETUP, ICON_Setup_0, ico, txt);
  289. }
  290. //
  291. // Printing: "Pause"
  292. //
  293. void ICON_Pause() {
  294. constexpr frame_rect_t ico = { 96, 232, 80, 100 };
  295. constexpr text_info_t txt[2] = {
  296. { 157, { 417, 449 }, 39, 14 },
  297. { 181, { 405, 447 }, 27, 15 }
  298. };
  299. ICON_Button(select_print.now == PRINT_PAUSE_RESUME, ICON_Pause_0, ico, txt);
  300. }
  301. //
  302. // Printing: "Resume"
  303. //
  304. void ICON_Resume() {
  305. constexpr frame_rect_t ico = { 96, 232, 80, 100 };
  306. constexpr text_info_t txt[2] = {
  307. { 33, { 433, 464 }, 53, 14 },
  308. { 1, { 405, 447 }, 27, 15 }
  309. };
  310. ICON_Button(select_print.now == PRINT_PAUSE_RESUME, ICON_Continue_0, ico, txt);
  311. }
  312. //
  313. // Printing: "Stop"
  314. //
  315. void ICON_Stop() {
  316. constexpr frame_rect_t ico = { 184, 232, 80, 100 };
  317. constexpr text_info_t txt[2] = {
  318. { 196, { 417, 449 }, 29, 14 },
  319. { 151, { 405, 447 }, 27, 12 }
  320. };
  321. ICON_Button(select_print.now == PRINT_STOP, ICON_Stop_0, ico, txt);
  322. }
  323. void Draw_Menu_Cursor(const uint8_t line) {
  324. DWIN_Draw_Rectangle(1, HMI_data.Cursor_color, 0, MBASE(line) - 18, 14, MBASE(line + 1) - 20);
  325. }
  326. void Erase_Menu_Cursor(const uint8_t line) {
  327. DWIN_Draw_Rectangle(1, HMI_data.Background_Color, 0, MBASE(line) - 18, 14, MBASE(line + 1) - 20);
  328. }
  329. void Move_Highlight(const int16_t from, const uint16_t newline) {
  330. Erase_Menu_Cursor(newline - from);
  331. Draw_Menu_Cursor(newline);
  332. }
  333. void Add_Menu_Line() {
  334. Move_Highlight(1, MROWS);
  335. DWIN_Draw_Line(HMI_data.SplitLine_Color, 16, MBASE(MROWS + 1) - 20, 256, MBASE(MROWS + 1) - 19);
  336. }
  337. void Scroll_Menu(const uint8_t dir) {
  338. DWIN_Frame_AreaMove(1, dir, MLINE, HMI_data.Background_Color, 0, 31, DWIN_WIDTH, 349);
  339. switch (dir) {
  340. case DWIN_SCROLL_DOWN: Move_Highlight(-1, 0); break;
  341. case DWIN_SCROLL_UP: Add_Menu_Line(); break;
  342. }
  343. }
  344. inline uint16_t nr_sd_menu_items() {
  345. return card.get_num_Files() + !card.flag.workDirIsRoot;
  346. }
  347. void Erase_Menu_Text(const uint8_t line) {
  348. DWIN_Draw_Rectangle(1, HMI_data.Background_Color, LBLX, MBASE(line) - 14, 271, MBASE(line) + 28);
  349. }
  350. void Draw_Menu_Line(const uint8_t line, const uint8_t icon=0, const char * const label=nullptr, bool more=false) {
  351. if (label) DWINUI::Draw_String(LBLX, MBASE(line) - 1, (char*)label);
  352. if (icon) DWINUI::Draw_Icon(icon, 26, MBASE(line) - 3);
  353. if (more) DWINUI::Draw_Icon(ICON_More, 226, MBASE(line) - 3);
  354. DWIN_Draw_Line(HMI_data.SplitLine_Color, 16, MBASE(line) + 33, 256, MBASE(line) + 33);
  355. }
  356. void Draw_Chkb_Line(const uint8_t line, const bool checked) {
  357. DWINUI::Draw_Checkbox(HMI_data.Text_Color, HMI_data.Background_Color, VALX + 16, MBASE(line) - 1, checked);
  358. }
  359. void Draw_Menu_IntValue(uint16_t bcolor, const uint8_t line, uint8_t iNum, const uint16_t value=0) {
  360. DWINUI::Draw_Int(HMI_data.Text_Color, bcolor, iNum , VALX, MBASE(line) - 1, value);
  361. }
  362. // The "Back" label is always on the first line
  363. void Draw_Back_Label() {
  364. if (HMI_IsChinese())
  365. DWIN_Frame_AreaCopy(1, 129, 72, 156, 84, LBLX, MBASE(0));
  366. else
  367. DWIN_Frame_AreaCopy(1, 223, 179, 254, 189, LBLX, MBASE(0));
  368. }
  369. // Draw "Back" line at the top
  370. void Draw_Back_First(const bool is_sel=true) {
  371. Draw_Menu_Line(0, ICON_Back);
  372. Draw_Back_Label();
  373. if (is_sel) Draw_Menu_Cursor(0);
  374. }
  375. inline EncoderState get_encoder_state() {
  376. static millis_t Encoder_ms = 0;
  377. const millis_t ms = millis();
  378. if (PENDING(ms, Encoder_ms)) return ENCODER_DIFF_NO;
  379. const EncoderState state = Encoder_ReceiveAnalyze();
  380. if (state != ENCODER_DIFF_NO) Encoder_ms = ms + ENCODER_WAIT_MS;
  381. return state;
  382. }
  383. template<typename T>
  384. inline bool Apply_Encoder(const EncoderState &encoder_diffState, T &valref) {
  385. if (encoder_diffState == ENCODER_DIFF_CW)
  386. valref += EncoderRate.encoderMoveValue;
  387. else if (encoder_diffState == ENCODER_DIFF_CCW)
  388. valref -= EncoderRate.encoderMoveValue;
  389. return encoder_diffState == ENCODER_DIFF_ENTER;
  390. }
  391. //
  392. // Draw Popup Windows
  393. //
  394. inline void Draw_Popup_Bkgd_60() {
  395. DWIN_Draw_Rectangle(1, HMI_data.PopupBg_color, 14, 60, 258, 330);
  396. DWIN_Draw_Rectangle(0, HMI_data.Highlight_Color, 14, 60, 258, 330);
  397. }
  398. inline void Draw_Popup_Bkgd_105() {
  399. DWIN_Draw_Rectangle(1, HMI_data.PopupBg_color, 14, 105, 258, 374);
  400. DWIN_Draw_Rectangle(0, HMI_data.Highlight_Color, 14, 105, 258, 374);
  401. }
  402. void Clear_Popup_Area() {
  403. DWIN_Draw_Rectangle(1, HMI_data.Background_Color, 0, 31, DWIN_WIDTH, DWIN_HEIGHT);
  404. }
  405. void DWIN_Draw_Popup1(const uint8_t icon) {
  406. DWINUI::ClearMenuArea();
  407. Draw_Popup_Bkgd_60();
  408. if (icon) DWINUI::Draw_Icon(icon, 101, 105);
  409. }
  410. void DWIN_Draw_Popup2(FSTR_P const fmsg2, uint8_t button) {
  411. if (fmsg2) DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 240, fmsg2);
  412. if (button) DWINUI::Draw_Icon(button, 86, 280);
  413. }
  414. void DWIN_Draw_Popup(const uint8_t icon, const char * const cmsg1, FSTR_P const fmsg2, uint8_t button) {
  415. DWIN_Draw_Popup1(icon);
  416. if (cmsg1) DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 210, cmsg1);
  417. DWIN_Draw_Popup2(fmsg2, button);
  418. }
  419. void DWIN_Draw_Popup(const uint8_t icon, FSTR_P const fmsg1, FSTR_P const fmsg2, uint8_t button) {
  420. DWIN_Draw_Popup1(icon);
  421. if (fmsg1) DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 210, fmsg1);
  422. DWIN_Draw_Popup2(fmsg2, button);
  423. }
  424. void DWIN_Popup_Continue(const uint8_t icon, FSTR_P const fmsg1, FSTR_P const fmsg2) {
  425. HMI_SaveProcessID(WaitResponse);
  426. DWIN_Draw_Popup(icon, fmsg1, fmsg2, ICON_Continue_E); // Button Continue
  427. DWIN_UpdateLCD();
  428. }
  429. #if HAS_HOTEND
  430. void Popup_Window_ETempTooLow() {
  431. if (HMI_IsChinese()) {
  432. HMI_SaveProcessID(WaitResponse);
  433. DWINUI::ClearMenuArea();
  434. Draw_Popup_Bkgd_60();
  435. DWINUI::Draw_Icon(ICON_TempTooLow, 102, 105);
  436. DWIN_Frame_AreaCopy(1, 103, 371, 136, 386, 69, 240);
  437. DWIN_Frame_AreaCopy(1, 170, 371, 270, 386, 102, 240);
  438. DWINUI::Draw_Icon(ICON_Confirm_C, 86, 280);
  439. DWIN_UpdateLCD();
  440. }
  441. else
  442. DWIN_Popup_Confirm(ICON_TempTooLow, F("Nozzle is too cold"), F("Preheat the hotend"));
  443. }
  444. #endif
  445. void Popup_Window_Resume() {
  446. Clear_Popup_Area();
  447. Draw_Popup_Bkgd_105();
  448. if (HMI_IsChinese()) {
  449. DWIN_Frame_AreaCopy(1, 160, 338, 235, 354, 98, 135);
  450. DWIN_Frame_AreaCopy(1, 103, 321, 271, 335, 52, 192);
  451. DWINUI::Draw_Icon(ICON_Cancel_C, 26, 307);
  452. DWINUI::Draw_Icon(ICON_Continue_C, 146, 307);
  453. }
  454. else {
  455. DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 115, F("Continue Print"));
  456. DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 192, F("It looks like the last"));
  457. DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 212, F("file was interrupted."));
  458. DWINUI::Draw_Icon(ICON_Cancel_E, 26, 307);
  459. DWINUI::Draw_Icon(ICON_Continue_E, 146, 307);
  460. }
  461. }
  462. void Draw_Select_Highlight(const bool sel) {
  463. HMI_flag.select_flag = sel;
  464. const uint16_t c1 = sel ? HMI_data.Highlight_Color : HMI_data.PopupBg_color,
  465. c2 = sel ? HMI_data.PopupBg_color : HMI_data.Highlight_Color;
  466. DWIN_Draw_Rectangle(0, c1, 25, 279, 126, 318);
  467. DWIN_Draw_Rectangle(0, c1, 24, 278, 127, 319);
  468. DWIN_Draw_Rectangle(0, c2, 145, 279, 246, 318);
  469. DWIN_Draw_Rectangle(0, c2, 144, 278, 247, 319);
  470. }
  471. void Popup_window_PauseOrStop() {
  472. if (HMI_IsChinese()) {
  473. DWINUI::ClearMenuArea();
  474. Draw_Popup_Bkgd_60();
  475. if (select_print.now == PRINT_PAUSE_RESUME) DWIN_Frame_AreaCopy(1, 237, 338, 269, 356, 98, 150);
  476. else if (select_print.now == PRINT_STOP) DWIN_Frame_AreaCopy(1, 221, 320, 253, 336, 98, 150);
  477. DWIN_Frame_AreaCopy(1, 220, 304, 264, 319, 130, 150);
  478. DWINUI::Draw_Icon(ICON_Confirm_C, 26, 280);
  479. DWINUI::Draw_Icon(ICON_Cancel_C, 146, 280);
  480. }
  481. else {
  482. DWIN_Draw_Popup(ICON_BLTouch, F("Please confirm"), select_print.now == PRINT_PAUSE_RESUME ? GET_TEXT_F(MSG_PAUSE_PRINT) : GET_TEXT_F(MSG_STOP_PRINT));
  483. DWINUI::Draw_Icon(ICON_Confirm_E, 26, 280);
  484. DWINUI::Draw_Icon(ICON_Cancel_E, 146, 280);
  485. }
  486. Draw_Select_Highlight(true);
  487. }
  488. #if HAS_HOTEND || HAS_HEATED_BED
  489. void DWIN_Popup_Temperature(const bool toohigh) {
  490. Clear_Popup_Area();
  491. Draw_Popup_Bkgd_105();
  492. if (toohigh) {
  493. DWINUI::Draw_Icon(ICON_TempTooHigh, 102, 165);
  494. if (HMI_IsChinese()) {
  495. DWIN_Frame_AreaCopy(1, 103, 371, 237, 386, 52, 285);
  496. DWIN_Frame_AreaCopy(1, 151, 389, 185, 402, 187, 285);
  497. DWIN_Frame_AreaCopy(1, 189, 389, 271, 402, 95, 310);
  498. }
  499. else {
  500. DWINUI::Draw_String(HMI_data.PopupTxt_Color, 36, 300, F("Nozzle or Bed temperature"));
  501. DWINUI::Draw_String(HMI_data.PopupTxt_Color, 92, 300, F("is too high"));
  502. }
  503. }
  504. else {
  505. DWINUI::Draw_Icon(ICON_TempTooLow, 102, 165);
  506. if (HMI_IsChinese()) {
  507. DWIN_Frame_AreaCopy(1, 103, 371, 270, 386, 52, 285);
  508. DWIN_Frame_AreaCopy(1, 189, 389, 271, 402, 95, 310);
  509. }
  510. else {
  511. DWINUI::Draw_String(HMI_data.PopupTxt_Color, 36, 300, F("Nozzle or Bed temperature"));
  512. DWINUI::Draw_String(HMI_data.PopupTxt_Color, 92, 300, F("is too low"));
  513. }
  514. }
  515. }
  516. #endif
  517. void Draw_Print_Labels() {
  518. if (HMI_IsChinese()) {
  519. Title.FrameCopy(30, 1, 42, 14); // "Printing"
  520. DWIN_Frame_AreaCopy(1, 0, 72, 63, 86, 41, 173); // Printing Time
  521. DWIN_Frame_AreaCopy(1, 65, 72, 128, 86, 176, 173); // Remain
  522. }
  523. else {
  524. Title.ShowCaption(GET_TEXT(MSG_PRINTING));
  525. DWINUI::Draw_String( 46, 173, F("Print Time"));
  526. DWINUI::Draw_String(181, 173, F("Remain"));
  527. }
  528. }
  529. void Draw_Print_ProgressBar() {
  530. DWINUI::Draw_Icon(ICON_Bar, 15, 93);
  531. DWIN_Draw_Rectangle(1, HMI_data.Barfill_Color, 16 + _percent_done * 240 / 100, 93, 256, 113);
  532. DWINUI::Draw_Int(HMI_data.PercentTxt_Color, HMI_data.Background_Color, 3, 117, 133, _percent_done);
  533. DWINUI::Draw_String(HMI_data.PercentTxt_Color, 142, 133, F("%"));
  534. }
  535. void Draw_Print_ProgressElapsed() {
  536. char buf[10];
  537. duration_t elapsed = print_job_timer.duration(); // print timer
  538. sprintf_P(buf, PSTR("%02i:%02i"), (uint16_t)(elapsed.value / 3600), ((uint16_t)elapsed.value % 3600) / 60);
  539. DWINUI::Draw_String(HMI_data.Text_Color, HMI_data.Background_Color, 47, 192, buf);
  540. }
  541. void Draw_Print_ProgressRemain() {
  542. char buf[10];
  543. sprintf_P(buf, PSTR("%02i:%02i"), (uint16_t)(_remain_time / 3600), ((uint16_t)_remain_time % 3600) / 60);
  544. DWINUI::Draw_String(HMI_data.Text_Color, HMI_data.Background_Color, 181, 192, buf);
  545. }
  546. void ICON_ResumeOrPause() {
  547. if (printingIsPaused() || HMI_flag.pause_flag || HMI_flag.pause_action)
  548. ICON_Resume();
  549. else
  550. ICON_Pause();
  551. }
  552. void Draw_PrintProcess() {
  553. DWINUI::ClearMenuArea();
  554. Draw_Print_Labels();
  555. ICON_Tune();
  556. ICON_ResumeOrPause();
  557. ICON_Stop();
  558. DWIN_Print_Header(sdprint ? card.longest_filename() : nullptr);
  559. DWINUI::Draw_Icon(ICON_PrintTime, 15, 173);
  560. DWINUI::Draw_Icon(ICON_RemainTime, 150, 171);
  561. Draw_Print_ProgressBar();
  562. Draw_Print_ProgressElapsed();
  563. Draw_Print_ProgressRemain();
  564. DWIN_UpdateLCD();
  565. }
  566. void Goto_PrintProcess() {
  567. checkkey = PrintProcess;
  568. Draw_PrintProcess();
  569. }
  570. void Draw_PrintDone() {
  571. // show percent bar and value
  572. _percent_done = 100;
  573. _remain_time = 0;
  574. DWINUI::ClearMenuArea();
  575. DWIN_Print_Header(nullptr);
  576. Draw_Print_Labels();
  577. DWINUI::Draw_Icon(ICON_PrintTime, 15, 173);
  578. DWINUI::Draw_Icon(ICON_RemainTime, 150, 171);
  579. Draw_Print_ProgressBar();
  580. Draw_Print_ProgressElapsed();
  581. Draw_Print_ProgressRemain();
  582. // show print done confirm
  583. DWIN_Draw_Rectangle(1, HMI_data.Background_Color, 0, 240, DWIN_WIDTH - 1, STATUS_Y - 1);
  584. DWINUI::Draw_Icon(HMI_IsChinese() ? ICON_Confirm_C : ICON_Confirm_E, 86, 283);
  585. }
  586. void Draw_Main_Menu() {
  587. DWINUI::ClearMenuArea();
  588. if (HMI_IsChinese())
  589. Title.FrameCopy(2, 2, 26, 13); // "Home" etc
  590. else
  591. Title.ShowCaption(MACHINE_NAME);
  592. DWINUI::Draw_Icon(ICON_LOGO, 71, 52); // CREALITY logo
  593. ICON_Print();
  594. ICON_Prepare();
  595. ICON_Control();
  596. TERN(HAS_ONESTEP_LEVELING, ICON_Leveling, ICON_StartInfo)();
  597. DWIN_UpdateLCD();
  598. }
  599. void Goto_Main_Menu() {
  600. checkkey = MainMenu;
  601. DWIN_StatusChanged(nullptr);
  602. Draw_Main_Menu();
  603. }
  604. // Draw X, Y, Z and blink if in an un-homed or un-trusted state
  605. void _update_axis_value(const AxisEnum axis, const uint16_t x, const uint16_t y, const bool blink, const bool force) {
  606. const bool draw_qmark = axis_should_home(axis),
  607. draw_empty = NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !draw_qmark && !axis_is_trusted(axis);
  608. // Check for a position change
  609. static xyz_pos_t oldpos = { -1, -1, -1 };
  610. const float p = current_position[axis];
  611. const bool changed = oldpos[axis] != p;
  612. if (changed) oldpos[axis] = p;
  613. if (force || changed || draw_qmark || draw_empty) {
  614. if (blink && draw_qmark)
  615. DWINUI::Draw_String(HMI_data.Coordinate_Color, HMI_data.Background_Color, x, y, F("--?--"));
  616. else if (blink && draw_empty)
  617. DWINUI::Draw_String(HMI_data.Coordinate_Color, HMI_data.Background_Color, x, y, F(" "));
  618. else
  619. DWINUI::Draw_Signed_Float(HMI_data.Coordinate_Color, HMI_data.Background_Color, 3, 1, x, y, p);
  620. }
  621. }
  622. void _draw_xyz_position(const bool force) {
  623. //SERIAL_ECHOPGM("Draw XYZ:");
  624. static bool _blink = false;
  625. const bool blink = !!(millis() & 0x400UL);
  626. if (force || blink != _blink) {
  627. _blink = blink;
  628. //SERIAL_ECHOPGM(" (blink)");
  629. _update_axis_value(X_AXIS, 35, 459, blink, true);
  630. _update_axis_value(Y_AXIS, 120, 459, blink, true);
  631. _update_axis_value(Z_AXIS, 205, 459, blink, true);
  632. }
  633. //SERIAL_EOL();
  634. }
  635. void update_variable() {
  636. #if HAS_HOTEND
  637. static celsius_t _hotendtemp = 0, _hotendtarget = 0;
  638. const celsius_t hc = thermalManager.wholeDegHotend(0),
  639. ht = thermalManager.degTargetHotend(0);
  640. const bool _new_hotend_temp = _hotendtemp != hc,
  641. _new_hotend_target = _hotendtarget != ht;
  642. if (_new_hotend_temp) _hotendtemp = hc;
  643. if (_new_hotend_target) _hotendtarget = ht;
  644. #endif
  645. #if HAS_HEATED_BED
  646. static celsius_t _bedtemp = 0, _bedtarget = 0;
  647. const celsius_t bc = thermalManager.wholeDegBed(),
  648. bt = thermalManager.degTargetBed();
  649. const bool _new_bed_temp = _bedtemp != bc,
  650. _new_bed_target = _bedtarget != bt;
  651. if (_new_bed_temp) _bedtemp = bc;
  652. if (_new_bed_target) _bedtarget = bt;
  653. #endif
  654. #if HAS_FAN
  655. static uint8_t _fanspeed = 0;
  656. const bool _new_fanspeed = _fanspeed != thermalManager.fan_speed[0];
  657. if (_new_fanspeed) _fanspeed = thermalManager.fan_speed[0];
  658. #endif
  659. if (checkkey == Menu && (CurrentMenu == TuneMenu || CurrentMenu == TemperatureMenu)) {
  660. // Tune page temperature update
  661. #if HAS_HOTEND
  662. if (_new_hotend_target)
  663. HotendTargetItem->draw(CurrentMenu->line(HotendTargetItem->pos));
  664. #endif
  665. #if HAS_HEATED_BED
  666. if (_new_bed_target)
  667. BedTargetItem->draw(CurrentMenu->line(BedTargetItem->pos));
  668. #endif
  669. #if HAS_FAN
  670. if (_new_fanspeed)
  671. FanSpeedItem->draw(CurrentMenu->line(FanSpeedItem->pos));
  672. #endif
  673. }
  674. // Bottom temperature update
  675. #if HAS_HOTEND
  676. if (_new_hotend_temp)
  677. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 28, 384, _hotendtemp);
  678. if (_new_hotend_target)
  679. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 25 + 4 * STAT_CHR_W + 6, 384, _hotendtarget);
  680. static int16_t _flow = planner.flow_percentage[0];
  681. if (_flow != planner.flow_percentage[0]) {
  682. _flow = planner.flow_percentage[0];
  683. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 116 + 2 * STAT_CHR_W, 417, _flow);
  684. }
  685. #endif
  686. #if HAS_HEATED_BED
  687. if (_new_bed_temp)
  688. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 28, 417, _bedtemp);
  689. if (_new_bed_target)
  690. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 25 + 4 * STAT_CHR_W + 6, 417, _bedtarget);
  691. #endif
  692. static int16_t _feedrate = 100;
  693. if (_feedrate != feedrate_percentage) {
  694. _feedrate = feedrate_percentage;
  695. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 116 + 2 * STAT_CHR_W, 384, _feedrate);
  696. }
  697. #if HAS_FAN
  698. if (_new_fanspeed) {
  699. _fanspeed = thermalManager.fan_speed[0];
  700. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 195 + 2 * STAT_CHR_W, 384, _fanspeed);
  701. }
  702. #endif
  703. static float _offset = 0;
  704. if (BABY_Z_VAR != _offset) {
  705. _offset = BABY_Z_VAR;
  706. DWINUI::Draw_Signed_Float(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 2, 2, 210, 417, _offset);
  707. }
  708. _draw_xyz_position(false);
  709. }
  710. /**
  711. * Read and cache the working directory.
  712. *
  713. * TODO: New code can follow the pattern of menu_media.cpp
  714. * and rely on Marlin caching for performance. No need to
  715. * cache files here.
  716. */
  717. #ifndef strcasecmp_P
  718. #define strcasecmp_P(a, b) strcasecmp((a), (b))
  719. #endif
  720. void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_LIMIT) {
  721. char * const name = card.longest_filename();
  722. size_t pos = strlen(name); // index of ending nul
  723. // For files, remove the extension
  724. // which may be .gcode, .gco, or .g
  725. if (!card.flag.filenameIsDir)
  726. while (pos && src[pos] != '.') pos--; // find last '.' (stop at 0)
  727. size_t len = pos; // nul or '.'
  728. if (len > maxlen) { // Keep the name short
  729. pos = len = maxlen; // move nul down
  730. dst[--pos] = '.'; // insert dots
  731. dst[--pos] = '.';
  732. dst[--pos] = '.';
  733. }
  734. dst[len] = '\0'; // end it
  735. // Copy down to 0
  736. while (pos--) dst[pos] = src[pos];
  737. }
  738. void HMI_SDCardInit() { card.cdroot(); }
  739. void MarlinUI::refresh() { /* Nothing to see here */ }
  740. #if HAS_LCD_BRIGHTNESS
  741. void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
  742. #endif
  743. #define ICON_Folder ICON_More
  744. #if ENABLED(SCROLL_LONG_FILENAMES)
  745. char shift_name[LONG_FILENAME_LENGTH + 1];
  746. int8_t shift_amt; // = 0
  747. millis_t shift_ms; // = 0
  748. // Init the shift name based on the highlighted item
  749. void Init_Shift_Name() {
  750. const bool is_subdir = !card.flag.workDirIsRoot;
  751. const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".."
  752. const uint16_t fileCnt = card.get_num_Files();
  753. if (WITHIN(filenum, 0, fileCnt - 1)) {
  754. card.getfilename_sorted(SD_ORDER(filenum, fileCnt));
  755. char * const name = card.longest_filename();
  756. make_name_without_ext(shift_name, name, 100);
  757. }
  758. }
  759. void Init_SDItem_Shift() {
  760. shift_amt = 0;
  761. shift_ms = select_file.now > 0 && strlen(shift_name) > MENU_CHAR_LIMIT ? millis() + 750UL : 0;
  762. }
  763. #endif
  764. /**
  765. * Display an SD item, adding a CDUP for subfolders.
  766. */
  767. void Draw_SDItem(const uint16_t item, int16_t row=-1) {
  768. if (row < 0) row = item + 1 + MROWS - index_file;
  769. const bool is_subdir = !card.flag.workDirIsRoot;
  770. if (is_subdir && item == 0)
  771. return Draw_Menu_Line(row, ICON_Folder, "..");
  772. card.getfilename_sorted(SD_ORDER(item - is_subdir, card.get_num_Files()));
  773. char * const name = card.longest_filename();
  774. #if ENABLED(SCROLL_LONG_FILENAMES)
  775. // Init the current selected name
  776. // This is used during scroll drawing
  777. if (item == select_file.now - 1) {
  778. make_name_without_ext(shift_name, name, 100);
  779. Init_SDItem_Shift();
  780. }
  781. #endif
  782. // Draw the file/folder with name aligned left
  783. char str[strlen(name) + 1];
  784. make_name_without_ext(str, name);
  785. Draw_Menu_Line(row, card.flag.filenameIsDir ? ICON_Folder : ICON_File, str);
  786. }
  787. #if ENABLED(SCROLL_LONG_FILENAMES)
  788. void Draw_SDItem_Shifted(uint8_t &shift) {
  789. // Limit to the number of chars past the cutoff
  790. const size_t len = strlen(shift_name);
  791. NOMORE(shift, _MAX(len - MENU_CHAR_LIMIT, 0U));
  792. // Shorten to the available space
  793. const size_t lastchar = _MIN((signed)len, shift + MENU_CHAR_LIMIT);
  794. const char c = shift_name[lastchar];
  795. shift_name[lastchar] = '\0';
  796. const uint8_t row = select_file.now + MROWS - index_file; // skip "Back" and scroll
  797. Erase_Menu_Text(row);
  798. Draw_Menu_Line(row, 0, &shift_name[shift]);
  799. shift_name[lastchar] = c;
  800. }
  801. #endif
  802. // Redraw the first set of SD Files
  803. void Redraw_SD_List() {
  804. select_file.reset();
  805. index_file = MROWS;
  806. DWINUI::ClearMenuArea(); // Leave title bar unchanged
  807. Draw_Back_First();
  808. if (card.isMounted()) {
  809. // As many files as will fit
  810. LOOP_L_N(i, _MIN(nr_sd_menu_items(), MROWS))
  811. Draw_SDItem(i, i + 1);
  812. TERN_(SCROLL_LONG_FILENAMES, Init_SDItem_Shift());
  813. }
  814. else {
  815. DWIN_Draw_Rectangle(1, HMI_data.AlertBg_Color, 10, MBASE(3) - 10, DWIN_WIDTH - 10, MBASE(4));
  816. DWINUI::Draw_CenteredString(font16x32, HMI_data.AlertTxt_Color, MBASE(3), F("No Media"));
  817. }
  818. }
  819. bool DWIN_lcd_sd_status = false;
  820. void SDCard_Up() {
  821. card.cdup();
  822. Redraw_SD_List();
  823. DWIN_lcd_sd_status = false; // On next DWIN_Update
  824. }
  825. void SDCard_Folder(char * const dirname) {
  826. card.cd(dirname);
  827. Redraw_SD_List();
  828. DWIN_lcd_sd_status = false; // On next DWIN_Update
  829. }
  830. //
  831. // Watch for media mount / unmount
  832. //
  833. void HMI_SDCardUpdate() {
  834. if (HMI_flag.home_flag) return;
  835. if (DWIN_lcd_sd_status != card.isMounted()) {
  836. DWIN_lcd_sd_status = card.isMounted();
  837. //SERIAL_ECHOLNPGM("HMI_SDCardUpdate: ", DWIN_lcd_sd_status);
  838. if (DWIN_lcd_sd_status) {
  839. if (checkkey == SelectFile)
  840. Redraw_SD_List();
  841. }
  842. else {
  843. // clean file icon
  844. if (checkkey == SelectFile) {
  845. Redraw_SD_List();
  846. }
  847. else if (sdprint && card.isPrinting() && printingIsActive()) {
  848. // TODO: Move card removed abort handling
  849. // to CardReader::manage_media.
  850. card.abortFilePrintSoon();
  851. wait_for_heatup = wait_for_user = false;
  852. dwin_abort_flag = true; // Reset feedrate, return to Home
  853. }
  854. }
  855. DWIN_UpdateLCD();
  856. }
  857. }
  858. //
  859. // The status area is always on-screen, except during
  860. // full-screen modal dialogs. (TODO: Keep alive during dialogs)
  861. //
  862. void Draw_Status_Area(const bool with_update) {
  863. DWIN_Draw_Rectangle(1, HMI_data.Background_Color, 0, STATUS_Y + 21, DWIN_WIDTH, DWIN_HEIGHT - 1);
  864. #if HAS_HOTEND
  865. DWINUI::Draw_Icon(ICON_HotendTemp, 10, 383);
  866. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 28, 384, thermalManager.wholeDegHotend(0));
  867. DWINUI::Draw_String(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 25 + 3 * STAT_CHR_W + 5, 384, F("/"));
  868. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 25 + 4 * STAT_CHR_W + 6, 384, thermalManager.degTargetHotend(0));
  869. DWINUI::Draw_Icon(ICON_StepE, 112, 417);
  870. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 116 + 2 * STAT_CHR_W, 417, planner.flow_percentage[0]);
  871. DWINUI::Draw_String(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 116 + 5 * STAT_CHR_W + 2, 417, F("%"));
  872. #endif
  873. #if HAS_HEATED_BED
  874. DWINUI::Draw_Icon(ICON_BedTemp, 10, 416);
  875. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 28, 417, thermalManager.wholeDegBed());
  876. DWINUI::Draw_String(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 25 + 3 * STAT_CHR_W + 5, 417, F("/"));
  877. DWINUI::Draw_Int(true, true, 0, DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 25 + 4 * STAT_CHR_W + 6, 417, thermalManager.degTargetBed());
  878. #endif
  879. DWINUI::Draw_Icon(ICON_Speed, 113, 383);
  880. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 116 + 2 * STAT_CHR_W, 384, feedrate_percentage);
  881. DWINUI::Draw_String(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 116 + 5 * STAT_CHR_W + 2, 384, F("%"));
  882. #if HAS_FAN
  883. DWINUI::Draw_Icon(ICON_FanSpeed, 187, 383);
  884. DWINUI::Draw_Int(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 3, 195 + 2 * STAT_CHR_W, 384, thermalManager.fan_speed[0]);
  885. #endif
  886. #if HAS_ZOFFSET_ITEM
  887. DWINUI::Draw_Icon(ICON_Zoffset, 187, 416);
  888. #endif
  889. DWINUI::Draw_Signed_Float(DWIN_FONT_STAT, HMI_data.Indicator_Color, HMI_data.Background_Color, 2, 2, 210, 417, BABY_Z_VAR);
  890. DWIN_Draw_Rectangle(1, HMI_data.SplitLine_Color, 0, 449, DWIN_WIDTH, 451);
  891. DWINUI::Draw_Icon(ICON_MaxSpeedX, 10, 456);
  892. DWINUI::Draw_Icon(ICON_MaxSpeedY, 95, 456);
  893. DWINUI::Draw_Icon(ICON_MaxSpeedZ, 180, 456);
  894. _draw_xyz_position(true);
  895. if (with_update) {
  896. DWIN_UpdateLCD();
  897. delay(5);
  898. }
  899. }
  900. void HMI_StartFrame(const bool with_update) {
  901. Goto_Main_Menu();
  902. Draw_Status_Area(with_update);
  903. }
  904. void Draw_Info_Menu() {
  905. DWINUI::ClearMenuArea();
  906. Draw_Back_First();
  907. DWINUI::Draw_CenteredString(122, F(MACHINE_SIZE));
  908. DWINUI::Draw_CenteredString(195, F(SHORT_BUILD_VERSION));
  909. if (HMI_IsChinese()) {
  910. Title.FrameCopy(30, 17, 28, 13); // "Info"
  911. DWIN_Frame_AreaCopy(1, 197, 149, 252, 161, 108, 102); // "Size"
  912. DWIN_Frame_AreaCopy(1, 1, 164, 56, 176, 108, 175); // "Firmware Version"
  913. DWIN_Frame_AreaCopy(1, 58, 164, 113, 176, 105, 248); // "Contact Details"
  914. }
  915. else {
  916. Title.ShowCaption(GET_TEXT_F(MSG_INFO_SCREEN));
  917. DWIN_Frame_AreaCopy(1, 120, 150, 146, 161, 124, 102); // "Size"
  918. DWIN_Frame_AreaCopy(1, 146, 151, 254, 161, 82, 175); // "Firmware Version"
  919. DWIN_Frame_AreaCopy(1, 1, 164, 96, 175, 89, 248); // "Contact details"
  920. }
  921. DWINUI::Draw_CenteredString(268, F(CORP_WEBSITE));
  922. LOOP_L_N(i, 3) {
  923. DWINUI::Draw_Icon(ICON_PrintSize + i, 26, 99 + i * 73);
  924. DWIN_Draw_Line(HMI_data.SplitLine_Color, 16, MBASE(2) + i * 73, 256, 156 + i * 73);
  925. }
  926. DWIN_UpdateLCD();
  927. }
  928. void Draw_Print_File_Menu() {
  929. if (HMI_IsChinese())
  930. Title.FrameCopy(0, 31, 56, 14); // "Print file"
  931. else
  932. Title.ShowCaption(GET_TEXT_F(MSG_MEDIA_MENU));
  933. Redraw_SD_List();
  934. }
  935. // Main Process
  936. void HMI_MainMenu() {
  937. EncoderState encoder_diffState = get_encoder_state();
  938. if (encoder_diffState == ENCODER_DIFF_NO) return;
  939. if (encoder_diffState == ENCODER_DIFF_CW) {
  940. if (select_page.inc(PAGE_COUNT)) {
  941. switch (select_page.now) {
  942. case PAGE_PRINT: ICON_Print(); break;
  943. case PAGE_PREPARE: ICON_Print(); ICON_Prepare(); break;
  944. case PAGE_CONTROL: ICON_Prepare(); ICON_Control(); break;
  945. case PAGE_INFO_LEVELING: ICON_Control(); TERN(HAS_ONESTEP_LEVELING, ICON_Leveling, ICON_StartInfo)(); break;
  946. }
  947. }
  948. }
  949. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  950. if (select_page.dec()) {
  951. switch (select_page.now) {
  952. case PAGE_PRINT: ICON_Print(); ICON_Prepare(); break;
  953. case PAGE_PREPARE: ICON_Prepare(); ICON_Control(); break;
  954. case PAGE_CONTROL: ICON_Control(); TERN(HAS_ONESTEP_LEVELING, ICON_Leveling, ICON_StartInfo)(); break;
  955. case PAGE_INFO_LEVELING: TERN(HAS_ONESTEP_LEVELING, ICON_Leveling, ICON_StartInfo)(); break;
  956. }
  957. }
  958. }
  959. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  960. switch (select_page.now) {
  961. case PAGE_PRINT:
  962. checkkey = SelectFile;
  963. Draw_Print_File_Menu();
  964. break;
  965. case PAGE_PREPARE: Draw_Prepare_Menu(); break;
  966. case PAGE_CONTROL: Draw_Control_Menu(); break;
  967. case PAGE_INFO_LEVELING:
  968. #if HAS_ONESTEP_LEVELING
  969. queue.inject(F("G28XYO\nG28Z\nG29")); // TODO: 'G29' should be homing when needed. Does it make sense for every LCD to do this differently?
  970. #else
  971. checkkey = Info;
  972. Draw_Info_Menu();
  973. #endif
  974. break;
  975. }
  976. }
  977. DWIN_UpdateLCD();
  978. }
  979. // Select (and Print) File
  980. void HMI_SelectFile() {
  981. EncoderState encoder_diffState = get_encoder_state();
  982. const uint16_t hasUpDir = !card.flag.workDirIsRoot;
  983. if (encoder_diffState == ENCODER_DIFF_NO) {
  984. #if ENABLED(SCROLL_LONG_FILENAMES)
  985. if (shift_ms && select_file.now >= 1 + hasUpDir) {
  986. // Scroll selected filename every second
  987. const millis_t ms = millis();
  988. if (ELAPSED(ms, shift_ms)) {
  989. const bool was_reset = shift_amt < 0;
  990. shift_ms = ms + 375UL + was_reset * 250UL; // ms per character
  991. uint8_t shift_new = shift_amt + 1; // Try to shift by...
  992. Draw_SDItem_Shifted(shift_new); // Draw the item
  993. if (!was_reset && shift_new == 0) // Was it limited to 0?
  994. shift_ms = 0; // No scrolling needed
  995. else if (shift_new == shift_amt) // Scroll reached the end
  996. shift_new = -1; // Reset
  997. shift_amt = shift_new; // Set new scroll
  998. }
  999. }
  1000. #endif
  1001. return;
  1002. }
  1003. // First pause is long. Easy.
  1004. // On reset, long pause must be after 0.
  1005. const uint16_t fullCnt = nr_sd_menu_items();
  1006. if (encoder_diffState == ENCODER_DIFF_CW && fullCnt) {
  1007. if (select_file.inc(1 + fullCnt)) {
  1008. const uint8_t itemnum = select_file.now - 1; // -1 for "Back"
  1009. if (TERN0(SCROLL_LONG_FILENAMES, shift_ms)) { // If line was shifted
  1010. Erase_Menu_Text(itemnum + MROWS - index_file); // Erase and
  1011. Draw_SDItem(itemnum - 1); // redraw
  1012. }
  1013. if (select_file.now > MROWS && select_file.now > index_file) { // Cursor past the bottom
  1014. index_file = select_file.now; // New bottom line
  1015. Scroll_Menu(DWIN_SCROLL_UP);
  1016. Draw_SDItem(itemnum, MROWS); // Draw and init the shift name
  1017. }
  1018. else {
  1019. Move_Highlight(1, select_file.now + MROWS - index_file); // Just move highlight
  1020. TERN_(SCROLL_LONG_FILENAMES, Init_Shift_Name()); // ...and init the shift name
  1021. }
  1022. TERN_(SCROLL_LONG_FILENAMES, Init_SDItem_Shift());
  1023. }
  1024. }
  1025. else if (encoder_diffState == ENCODER_DIFF_CCW && fullCnt) {
  1026. if (select_file.dec()) {
  1027. const uint8_t itemnum = select_file.now - 1; // -1 for "Back"
  1028. if (TERN0(SCROLL_LONG_FILENAMES, shift_ms)) { // If line was shifted
  1029. Erase_Menu_Text(select_file.now + 1 + MROWS - index_file); // Erase and
  1030. Draw_SDItem(itemnum + 1); // redraw
  1031. }
  1032. if (select_file.now < index_file - MROWS) { // Cursor past the top
  1033. index_file--; // New bottom line
  1034. Scroll_Menu(DWIN_SCROLL_DOWN);
  1035. if (index_file == MROWS) {
  1036. Draw_Back_First();
  1037. TERN_(SCROLL_LONG_FILENAMES, shift_ms = 0);
  1038. }
  1039. else {
  1040. Draw_SDItem(itemnum, 0); // Draw the item (and init shift name)
  1041. }
  1042. }
  1043. else {
  1044. Move_Highlight(-1, select_file.now + MROWS - index_file); // Just move highlight
  1045. TERN_(SCROLL_LONG_FILENAMES, Init_Shift_Name()); // ...and init the shift name
  1046. }
  1047. TERN_(SCROLL_LONG_FILENAMES, Init_SDItem_Shift()); // Reset left. Init timer.
  1048. }
  1049. }
  1050. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1051. if (select_file.now == 0) {
  1052. select_page.set(PAGE_PRINT);
  1053. Goto_Main_Menu();
  1054. }
  1055. else if (hasUpDir && select_file.now == 1) { // CD-Up
  1056. SDCard_Up();
  1057. goto HMI_SelectFileExit;
  1058. }
  1059. else {
  1060. const uint16_t filenum = select_file.now - 1 - hasUpDir;
  1061. card.getfilename_sorted(SD_ORDER(filenum, card.get_num_Files()));
  1062. // Enter that folder!
  1063. if (card.flag.filenameIsDir) {
  1064. SDCard_Folder(card.filename);
  1065. goto HMI_SelectFileExit;
  1066. }
  1067. // Reset highlight for next entry
  1068. select_print.reset();
  1069. select_file.reset();
  1070. // Start choice and print SD file
  1071. HMI_flag.heat_flag = true;
  1072. HMI_flag.print_finish = false;
  1073. card.openAndPrintFile(card.filename);
  1074. #if HAS_FAN
  1075. // All fans on for Ender 3 v2 ?
  1076. // The slicer should manage this for us.
  1077. //for (uint8_t i = 0; i < FAN_COUNT; i++)
  1078. // thermalManager.fan_speed[i] = 255;
  1079. #endif
  1080. DWIN_Print_Started(true);
  1081. }
  1082. }
  1083. HMI_SelectFileExit:
  1084. DWIN_UpdateLCD();
  1085. }
  1086. // Printing
  1087. void HMI_Printing() {
  1088. EncoderState encoder_diffState = get_encoder_state();
  1089. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1090. // Avoid flicker by updating only the previous menu
  1091. if (encoder_diffState == ENCODER_DIFF_CW) {
  1092. if (select_print.inc(PRINT_COUNT)) {
  1093. switch (select_print.now) {
  1094. case PRINT_SETUP: ICON_Tune(); break;
  1095. case PRINT_PAUSE_RESUME: ICON_Tune(); ICON_ResumeOrPause(); break;
  1096. case PRINT_STOP: ICON_ResumeOrPause(); ICON_Stop(); break;
  1097. }
  1098. }
  1099. }
  1100. else if (encoder_diffState == ENCODER_DIFF_CCW) {
  1101. if (select_print.dec()) {
  1102. switch (select_print.now) {
  1103. case PRINT_SETUP: ICON_Tune(); ICON_ResumeOrPause(); break;
  1104. case PRINT_PAUSE_RESUME: ICON_ResumeOrPause(); ICON_Stop(); break;
  1105. case PRINT_STOP: ICON_Stop(); break;
  1106. }
  1107. }
  1108. }
  1109. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1110. switch (select_print.now) {
  1111. case PRINT_SETUP: Draw_Tune_Menu(); break;
  1112. case PRINT_PAUSE_RESUME:
  1113. if (HMI_flag.pause_flag) {
  1114. ICON_Pause();
  1115. #if DISABLED(ADVANCED_PAUSE_FEATURE)
  1116. char cmd[40];
  1117. cmd[0] = '\0';
  1118. #if BOTH(HAS_HEATED_BED, PAUSE_HEAT)
  1119. if (resume_bed_temp) sprintf_P(cmd, PSTR("M190 S%i\n"), resume_bed_temp);
  1120. #endif
  1121. #if BOTH(HAS_HOTEND, PAUSE_HEAT)
  1122. if (resume_hotend_temp) sprintf_P(&cmd[strlen(cmd)], PSTR("M109 S%i\n"), resume_hotend_temp);
  1123. #endif
  1124. #if HAS_FAN
  1125. if (resume_fan) thermalManager.fan_speed[0] = resume_fan;
  1126. #endif
  1127. strcat_P(cmd, M24_STR);
  1128. queue.inject(cmd);
  1129. #endif
  1130. }
  1131. else {
  1132. HMI_flag.select_flag = true;
  1133. checkkey = PauseOrStop;
  1134. Popup_window_PauseOrStop();
  1135. }
  1136. break;
  1137. case PRINT_STOP:
  1138. HMI_flag.select_flag = true;
  1139. checkkey = PauseOrStop;
  1140. Popup_window_PauseOrStop();
  1141. break;
  1142. default: break;
  1143. }
  1144. }
  1145. DWIN_UpdateLCD();
  1146. }
  1147. // Print done
  1148. void HMI_PrintDone() {
  1149. EncoderState encoder_diffState = get_encoder_state();
  1150. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1151. if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1152. dwin_abort_flag = true; // Reset feedrate, return to Home
  1153. Goto_Main_Menu(); // Return to Main menu after print done
  1154. }
  1155. }
  1156. // Pause or Stop popup
  1157. void HMI_PauseOrStop() {
  1158. EncoderState encoder_diffState = get_encoder_state();
  1159. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1160. if (encoder_diffState == ENCODER_DIFF_CW)
  1161. Draw_Select_Highlight(false);
  1162. else if (encoder_diffState == ENCODER_DIFF_CCW)
  1163. Draw_Select_Highlight(true);
  1164. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1165. if (select_print.now == PRINT_PAUSE_RESUME) {
  1166. if (HMI_flag.select_flag) {
  1167. HMI_flag.pause_action = true;
  1168. ICON_Resume();
  1169. queue.inject(F("M25"));
  1170. }
  1171. else {
  1172. // cancel pause
  1173. }
  1174. Goto_PrintProcess();
  1175. }
  1176. else if (select_print.now == PRINT_STOP) {
  1177. if (HMI_flag.select_flag) {
  1178. checkkey = MainMenu;
  1179. if (HMI_flag.home_flag) planner.synchronize(); // Wait for planner moves to finish!
  1180. wait_for_heatup = wait_for_user = false; // Stop waiting for heating/user
  1181. card.abortFilePrintSoon(); // Let the main loop handle SD abort
  1182. dwin_abort_flag = true; // Reset feedrate, return to Home
  1183. #ifdef ACTION_ON_CANCEL
  1184. host_action_cancel();
  1185. #endif
  1186. DWIN_Draw_Popup(ICON_BLTouch, F("Stopping...") , F("Please wait until done."));
  1187. }
  1188. else
  1189. Goto_PrintProcess(); // cancel stop
  1190. }
  1191. }
  1192. DWIN_UpdateLCD();
  1193. }
  1194. #include "../../../libs/buzzer.h"
  1195. void HMI_AudioFeedback(const bool success/*=true*/) {
  1196. #if HAS_BUZZER
  1197. if (success) {
  1198. BUZZ(100, 659);
  1199. BUZZ(10, 0);
  1200. BUZZ(100, 698);
  1201. }
  1202. else
  1203. BUZZ(40, 440);
  1204. #endif
  1205. }
  1206. void Draw_Main_Area() {
  1207. switch (checkkey) {
  1208. case MainMenu: Draw_Main_Menu(); break;
  1209. case SelectFile: Draw_Print_File_Menu(); break;
  1210. case PrintProcess: Draw_PrintProcess(); break;
  1211. case PrintDone: Draw_PrintDone(); break;
  1212. case Info: Draw_Info_Menu(); break;
  1213. case PauseOrStop: Popup_window_PauseOrStop(); break;
  1214. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1215. case FilamentPurge: Draw_Popup_FilamentPurge(); break;
  1216. #endif
  1217. case Locked: lockScreen.draw(); break;
  1218. case Menu:
  1219. case SetInt:
  1220. case SetPInt:
  1221. case SetIntNoDraw:
  1222. case SetFloat:
  1223. case SetPFloat: CurrentMenu->draw(); break;
  1224. default: break;
  1225. }
  1226. }
  1227. void HMI_ReturnScreen() {
  1228. checkkey = last_checkkey;
  1229. Draw_Main_Area();
  1230. DWIN_UpdateLCD();
  1231. return;
  1232. }
  1233. void HMI_Popup() {
  1234. EncoderState encoder_diffState = get_encoder_state();
  1235. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1236. if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1237. wait_for_user = false;
  1238. HMI_ReturnScreen();
  1239. }
  1240. }
  1241. void HMI_Init() {
  1242. HMI_SDCardInit();
  1243. for (uint16_t t = 0; t <= 100; t += 2) {
  1244. DWINUI::Draw_Icon(ICON_Bar, 15, 260);
  1245. DWIN_Draw_Rectangle(1, HMI_data.Background_Color, 15 + t * 242 / 100, 260, 257, 280);
  1246. DWIN_UpdateLCD();
  1247. delay(20);
  1248. }
  1249. HMI_SetLanguage();
  1250. }
  1251. void DWIN_Update() {
  1252. EachMomentUpdate(); // Status update
  1253. HMI_SDCardUpdate(); // SD card update
  1254. DWIN_HandleScreen(); // Rotary encoder update
  1255. }
  1256. void EachMomentUpdate() {
  1257. static millis_t next_var_update_ms = 0, next_rts_update_ms = 0;
  1258. const millis_t ms = millis();
  1259. if (ELAPSED(ms, next_var_update_ms)) {
  1260. next_var_update_ms = ms + DWIN_VAR_UPDATE_INTERVAL;
  1261. update_variable();
  1262. }
  1263. if (PENDING(ms, next_rts_update_ms)) return;
  1264. next_rts_update_ms = ms + DWIN_SCROLL_UPDATE_INTERVAL;
  1265. if (checkkey == PrintProcess) {
  1266. // if print done
  1267. if (HMI_flag.print_finish) {
  1268. HMI_flag.print_finish = false;
  1269. TERN_(POWER_LOSS_RECOVERY, recovery.cancel());
  1270. planner.finish_and_disable();
  1271. checkkey = PrintDone;
  1272. Draw_PrintDone();
  1273. }
  1274. else if (HMI_flag.pause_flag != printingIsPaused()) {
  1275. // print status update
  1276. HMI_flag.pause_flag = printingIsPaused();
  1277. ICON_ResumeOrPause();
  1278. }
  1279. }
  1280. // pause after homing
  1281. if (HMI_flag.pause_action && printingIsPaused() && !planner.has_blocks_queued()) {
  1282. HMI_flag.pause_action = false;
  1283. #if ENABLED(PAUSE_HEAT)
  1284. TERN_(HAS_HOTEND, resume_hotend_temp = sdprint ? thermalManager.degTargetHotend(0) : thermalManager.wholeDegHotend(0));
  1285. TERN_(HAS_HEATED_BED, resume_bed_temp = sdprint ? thermalManager.degTargetBed() : thermalManager.wholeDegBed());
  1286. TERN_(HAS_FAN, resume_fan = thermalManager.fan_speed[0]);
  1287. #endif
  1288. IF_DISABLED(ADVANCED_PAUSE_FEATURE, thermalManager.disable_all_heaters());
  1289. IF_DISABLED(PARK_HEAD_ON_PAUSE, queue.inject(F("G1 F1200 X0 Y0")));
  1290. }
  1291. if (checkkey == PrintProcess) { // print process
  1292. duration_t elapsed = print_job_timer.duration(); // print timer
  1293. if (sdprint && card.isPrinting()) {
  1294. uint8_t percentDone = card.percentDone();
  1295. static uint8_t last_percentValue = 101;
  1296. if (last_percentValue != percentDone) { // print percent
  1297. last_percentValue = percentDone;
  1298. if (percentDone) {
  1299. _percent_done = percentDone;
  1300. Draw_Print_ProgressBar();
  1301. }
  1302. }
  1303. // Estimate remaining time every 20 seconds
  1304. static millis_t next_remain_time_update = 0;
  1305. if (_percent_done > 1 && ELAPSED(ms, next_remain_time_update) && !HMI_flag.heat_flag) {
  1306. _remain_time = (elapsed.value - dwin_heat_time) / (_percent_done * 0.01f) - (elapsed.value - dwin_heat_time);
  1307. next_remain_time_update += DWIN_REMAIN_TIME_UPDATE_INTERVAL;
  1308. Draw_Print_ProgressRemain();
  1309. }
  1310. }
  1311. // Print time so far
  1312. static uint16_t last_Printtime = 0;
  1313. const uint16_t min = (elapsed.value % 3600) / 60;
  1314. if (last_Printtime != min) { // 1 minute update
  1315. last_Printtime = min;
  1316. Draw_Print_ProgressElapsed();
  1317. }
  1318. }
  1319. else if (dwin_abort_flag && !HMI_flag.home_flag) { // Print Stop
  1320. dwin_abort_flag = false;
  1321. dwin_zoffset = BABY_Z_VAR;
  1322. select_page.set(PAGE_PRINT);
  1323. Goto_Main_Menu();
  1324. }
  1325. #if ENABLED(POWER_LOSS_RECOVERY)
  1326. else if (DWIN_lcd_sd_status && recovery.dwin_flag) { // resume print before power off
  1327. static bool recovery_flag = false;
  1328. recovery.dwin_flag = false;
  1329. recovery_flag = true;
  1330. auto update_selection = [&](const bool sel) {
  1331. HMI_flag.select_flag = sel;
  1332. const uint16_t c1 = sel ? HMI_data.PopupBg_color : HMI_data.Highlight_Color;
  1333. DWIN_Draw_Rectangle(0, c1, 25, 306, 126, 345);
  1334. DWIN_Draw_Rectangle(0, c1, 24, 305, 127, 346);
  1335. const uint16_t c2 = sel ? HMI_data.Highlight_Color : HMI_data.PopupBg_color;
  1336. DWIN_Draw_Rectangle(0, c2, 145, 306, 246, 345);
  1337. DWIN_Draw_Rectangle(0, c2, 144, 305, 247, 346);
  1338. };
  1339. Popup_Window_Resume();
  1340. update_selection(true);
  1341. // TODO: Get the name of the current file from someplace
  1342. //
  1343. //(void)recovery.interrupted_file_exists();
  1344. SdFile *dir = nullptr;
  1345. const char * const filename = card.diveToFile(true, dir, recovery.info.sd_filename);
  1346. card.selectFileByName(filename);
  1347. DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 252, card.longest_filename());
  1348. DWIN_UpdateLCD();
  1349. while (recovery_flag) {
  1350. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  1351. if (encoder_diffState != ENCODER_DIFF_NO) {
  1352. if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1353. recovery_flag = false;
  1354. if (HMI_flag.select_flag) break;
  1355. TERN_(POWER_LOSS_RECOVERY, queue.inject(F("M1000C")));
  1356. return HMI_StartFrame(true);
  1357. }
  1358. else
  1359. update_selection(encoder_diffState == ENCODER_DIFF_CW);
  1360. DWIN_UpdateLCD();
  1361. }
  1362. watchdog_refresh();
  1363. }
  1364. select_print.set(PRINT_SETUP);
  1365. queue.inject(F("M1000"));
  1366. sdprint = true;
  1367. Goto_PrintProcess();
  1368. Draw_Status_Area(true);
  1369. }
  1370. #endif // POWER_LOSS_RECOVERY
  1371. DWIN_UpdateLCD();
  1372. }
  1373. void DWIN_HandleScreen() {
  1374. switch (checkkey) {
  1375. case MainMenu: HMI_MainMenu(); break;
  1376. case Menu: HMI_Menu(); break;
  1377. case SetInt: HMI_SetInt(); break;
  1378. case SetPInt: HMI_SetPInt(); break;
  1379. case SetIntNoDraw: HMI_SetIntNoDraw(); break;
  1380. case SetFloat: HMI_SetFloat(); break;
  1381. case SetPFloat: HMI_SetPFloat(); break;
  1382. case SelectFile: HMI_SelectFile(); break;
  1383. case Homing: break;
  1384. case Leveling: break;
  1385. case PrintProcess: HMI_Printing(); break;
  1386. case PrintDone: HMI_PrintDone(); break;
  1387. case PauseOrStop: HMI_PauseOrStop(); break;
  1388. case Info: HMI_Popup(); break;
  1389. case WaitResponse: HMI_Popup(); break;
  1390. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1391. case FilamentPurge: HMI_FilamentPurge(); break;
  1392. #endif
  1393. case NothingToDo: break;
  1394. case Locked: HMI_LockScreen(); break;
  1395. default: break;
  1396. }
  1397. }
  1398. void HMI_SaveProcessID(const uint8_t id) {
  1399. if (checkkey != id) {
  1400. if ((checkkey != NothingToDo) &&
  1401. (checkkey != WaitResponse) &&
  1402. (checkkey != Homing) &&
  1403. (checkkey != Leveling) &&
  1404. (checkkey != PauseOrStop) &&
  1405. (checkkey != FilamentPurge)) last_checkkey = checkkey; // if not a popup
  1406. checkkey = id;
  1407. }
  1408. }
  1409. void DWIN_StartHoming() {
  1410. HMI_flag.home_flag = true;
  1411. HMI_SaveProcessID(Homing);
  1412. DWIN_Draw_Popup(ICON_BLTouch, F("Axis Homing"), F("Please wait until done."));
  1413. }
  1414. void DWIN_CompletedHoming() {
  1415. HMI_flag.home_flag = false;
  1416. dwin_zoffset = TERN0(HAS_BED_PROBE, probe.offset.z);
  1417. if (dwin_abort_flag) {
  1418. planner.finish_and_disable();
  1419. }
  1420. HMI_ReturnScreen();
  1421. }
  1422. void DWIN_MeshLevelingStart() {
  1423. #if HAS_ONESTEP_LEVELING
  1424. HMI_SaveProcessID(Leveling);
  1425. DWIN_Draw_Popup(ICON_AutoLeveling, GET_TEXT_F(MSG_BED_LEVELING), F("Please wait until done."));
  1426. #elif ENABLED(MESH_BED_LEVELING)
  1427. Draw_ManualMesh_Menu();
  1428. #endif
  1429. }
  1430. void DWIN_CompletedLeveling() { TERN_(HAS_MESH, DWIN_MeshViewer()); }
  1431. #if HAS_MESH
  1432. void DWIN_MeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
  1433. char msg[33] = "";
  1434. char str_1[6] = "";
  1435. sprintf_P(msg, PSTR(S_FMT " %i/%i Z=%s"), GET_TEXT(MSG_PROBING_POINT), xpos, ypos,
  1436. dtostrf(zval, 1, 2, str_1));
  1437. ui.set_status(msg);
  1438. }
  1439. #endif
  1440. // PID process
  1441. void DWIN_PidTuning(pidresult_t result) {
  1442. switch (result) {
  1443. case PID_BED_START:
  1444. HMI_SaveProcessID(NothingToDo);
  1445. DWIN_Draw_Popup(ICON_TempTooHigh, GET_TEXT_F(MSG_PID_AUTOTUNE), F("for BED is running."));
  1446. break;
  1447. case PID_EXTR_START:
  1448. HMI_SaveProcessID(NothingToDo);
  1449. DWIN_Draw_Popup(ICON_TempTooHigh, GET_TEXT_F(MSG_PID_AUTOTUNE), F("for Nozzle is running."));
  1450. break;
  1451. case PID_BAD_EXTRUDER_NUM:
  1452. checkkey = last_checkkey;
  1453. DWIN_Popup_Confirm(ICON_TempTooLow, F("PID Autotune failed!"), F("Bad extruder"));
  1454. break;
  1455. case PID_TUNING_TIMEOUT:
  1456. checkkey = last_checkkey;
  1457. DWIN_Popup_Confirm(ICON_TempTooHigh, F("Error"), GET_TEXT_F(MSG_PID_TIMEOUT));
  1458. break;
  1459. case PID_TEMP_TOO_HIGH:
  1460. checkkey = last_checkkey;
  1461. DWIN_Popup_Confirm(ICON_TempTooHigh, F("PID Autotune failed!"), F("Temperature too high"));
  1462. break;
  1463. case PID_DONE:
  1464. checkkey = last_checkkey;
  1465. DWIN_Popup_Confirm(ICON_TempTooLow, GET_TEXT_F(MSG_PID_AUTOTUNE), GET_TEXT_F(MSG_BUTTON_DONE));
  1466. break;
  1467. default:
  1468. checkkey = last_checkkey;
  1469. break;
  1470. }
  1471. }
  1472. // Update filename on print
  1473. void DWIN_Print_Header(const char *text = nullptr) {
  1474. static char headertxt[31] = ""; // Print header text
  1475. if (text != nullptr) {
  1476. const int8_t size = _MIN((unsigned) 30, strlen_P(text));
  1477. LOOP_L_N(i, size) headertxt[i] = text[i];
  1478. headertxt[size] = '\0';
  1479. }
  1480. if (checkkey == PrintProcess || checkkey == PrintDone) {
  1481. DWIN_Draw_Rectangle(1, HMI_data.Background_Color, 0, 60, DWIN_WIDTH, 60+16);
  1482. DWINUI::Draw_CenteredString(60, headertxt);
  1483. }
  1484. }
  1485. void Draw_Title(TitleClass* title) {
  1486. DWIN_Draw_Rectangle(1, HMI_data.TitleBg_color, 0, 0, DWIN_WIDTH - 1, TITLE_HEIGHT - 1);
  1487. if (title->frameid)
  1488. DWIN_Frame_AreaCopy(title->frameid, title->frame.left, title->frame.top, title->frame.right, title->frame.bottom, 14, (TITLE_HEIGHT - (title->frame.bottom - title->frame.top)) / 2 - 1);
  1489. else
  1490. DWIN_Draw_String(false, DWIN_FONT_HEAD, HMI_data.TitleTxt_color, HMI_data.TitleBg_color, 14, (TITLE_HEIGHT - DWINUI::fontHeight(DWIN_FONT_HEAD)) / 2 - 1, title->caption);
  1491. }
  1492. void Draw_Menu(MenuClass* menu) {
  1493. DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color);
  1494. DWIN_Draw_Rectangle(1, DWINUI::backcolor, 0, TITLE_HEIGHT, DWIN_WIDTH - 1, STATUS_Y - 1);
  1495. ui.set_status("");
  1496. }
  1497. // Startup routines
  1498. void DWIN_Startup() {
  1499. DWINUI::init();
  1500. DWINUI::onCursorDraw = Draw_Menu_Cursor;
  1501. DWINUI::onCursorErase = Erase_Menu_Cursor;
  1502. DWINUI::onTitleDraw = Draw_Title;
  1503. DWINUI::onMenuDraw = Draw_Menu;
  1504. HMI_SetLanguage();
  1505. }
  1506. void DWIN_DrawStatusLine(const uint16_t color, const uint16_t bgcolor, const char *text) {
  1507. DWIN_Draw_Rectangle(1, bgcolor, 0, STATUS_Y, DWIN_WIDTH, STATUS_Y + 20);
  1508. if (text) DWINUI::Draw_CenteredString(color, STATUS_Y + 2, text);
  1509. DWIN_UpdateLCD();
  1510. }
  1511. // Update Status line
  1512. void DWIN_StatusChanged(const char *text) {
  1513. DWIN_DrawStatusLine(HMI_data.StatusTxt_Color, HMI_data.StatusBg_Color, text);
  1514. }
  1515. void DWIN_StatusChanged_P(PGM_P const pstr) {
  1516. char str[strlen_P((const char*)pstr) + 1];
  1517. strcpy_P(str, (const char*)pstr);
  1518. DWIN_StatusChanged(str);
  1519. }
  1520. // Started a Print Job
  1521. void DWIN_Print_Started(const bool sd) {
  1522. sdprint = card.isPrinting() || sd;
  1523. _percent_done = 0;
  1524. _remain_time = 0;
  1525. HMI_flag.print_finish = false;
  1526. Goto_PrintProcess();
  1527. }
  1528. // Ended print job
  1529. void DWIN_Print_Finished() {
  1530. if (checkkey == PrintProcess || printingIsActive()) {
  1531. thermalManager.disable_all_heaters();
  1532. thermalManager.zero_fan_speeds();
  1533. HMI_flag.print_finish = true;
  1534. }
  1535. }
  1536. // Progress Bar update
  1537. void DWIN_Progress_Update() {
  1538. if (parser.seenval('P')) _percent_done = parser.byteval('P');
  1539. if (parser.seenval('R')) _remain_time = parser.ulongval('R') * 60;
  1540. if (checkkey == PrintProcess) {
  1541. Draw_Print_ProgressBar();
  1542. Draw_Print_ProgressRemain();
  1543. Draw_Print_ProgressElapsed();
  1544. }
  1545. }
  1546. #if HAS_FILAMENT_SENSOR
  1547. // Filament Runout process
  1548. void DWIN_FilamentRunout(const uint8_t extruder) { ui.set_status_P(GET_TEXT(MSG_RUNOUT_SENSOR)); }
  1549. #endif
  1550. void DWIN_SetColorDefaults() {
  1551. HMI_data.Background_Color = Def_Background_Color;
  1552. HMI_data.Cursor_color = Def_Cursor_color;
  1553. HMI_data.TitleBg_color = Def_TitleBg_color;
  1554. HMI_data.TitleTxt_color = Def_TitleTxt_color;
  1555. HMI_data.Text_Color = Def_Text_Color;
  1556. HMI_data.Selected_Color = Def_Selected_Color;
  1557. HMI_data.SplitLine_Color = Def_SplitLine_Color;
  1558. HMI_data.Highlight_Color = Def_Highlight_Color;
  1559. HMI_data.StatusBg_Color = Def_StatusBg_Color;
  1560. HMI_data.StatusTxt_Color = Def_StatusTxt_Color;
  1561. HMI_data.PopupBg_color = Def_PopupBg_color;
  1562. HMI_data.PopupTxt_Color = Def_PopupTxt_Color;
  1563. HMI_data.AlertBg_Color = Def_AlertBg_Color;
  1564. HMI_data.AlertTxt_Color = Def_AlertTxt_Color;
  1565. HMI_data.PercentTxt_Color = Def_PercentTxt_Color;
  1566. HMI_data.Barfill_Color = Def_Barfill_Color;
  1567. HMI_data.Indicator_Color = Def_Indicator_Color;
  1568. HMI_data.Coordinate_Color = Def_Coordinate_Color;
  1569. }
  1570. void DWIN_SetDataDefaults() {
  1571. DWIN_SetColorDefaults();
  1572. DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color);
  1573. TERN_(HAS_HOTEND, HMI_data.HotendPidT = PREHEAT_1_TEMP_HOTEND);
  1574. TERN_(HAS_HEATED_BED, HMI_data.BedPidT = PREHEAT_1_TEMP_BED);
  1575. TERN_(HAS_HOTEND, HMI_data.PidCycles = 5);
  1576. TERN_(PREVENT_COLD_EXTRUSION, HMI_data.ExtMinT = EXTRUDE_MINTEMP);
  1577. }
  1578. void DWIN_StoreSettings(char *buff) {
  1579. memcpy(buff, &HMI_data, _MIN(sizeof(HMI_data), eeprom_data_size));
  1580. }
  1581. void DWIN_LoadSettings(const char *buff) {
  1582. memcpy(&HMI_data, buff, _MIN(sizeof(HMI_data), eeprom_data_size));
  1583. dwin_zoffset = TERN0(HAS_BED_PROBE, probe.offset.z);
  1584. if (HMI_data.Text_Color == HMI_data.Background_Color) DWIN_SetColorDefaults();
  1585. DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color);
  1586. TERN_(PREVENT_COLD_EXTRUSION, ApplyExtMinT());
  1587. feedrate_percentage = 100;
  1588. }
  1589. void MarlinUI::kill_screen(PGM_P lcd_error, PGM_P lcd_component) {
  1590. DWIN_Draw_Popup(ICON_BLTouch, lcd_error, lcd_component);
  1591. DWIN_UpdateLCD();
  1592. }
  1593. void DWIN_RebootScreen() {
  1594. DWIN_Frame_Clear(Color_Bg_Black);
  1595. DWINUI::Draw_Icon(ICON_LOGO, 71, 150); // CREALITY logo
  1596. DWINUI::Draw_CenteredString(Color_White, 200, F("Please wait until reboot."));
  1597. DWIN_UpdateLCD();
  1598. delay(500);
  1599. }
  1600. void DWIN_Redraw_screen() {
  1601. Draw_Main_Area();
  1602. DWIN_StatusChanged(ui.status_message);
  1603. Draw_Status_Area(false);
  1604. }
  1605. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1606. void DWIN_Popup_Pause(FSTR_P const fmsg, uint8_t button = 0) {
  1607. HMI_SaveProcessID(button ? WaitResponse : NothingToDo);
  1608. DWIN_Draw_Popup(ICON_BLTouch, F("Advanced Pause"), fmsg, button);
  1609. ui.reset_status(true);
  1610. }
  1611. void MarlinUI::pause_show_message(const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, const uint8_t extruder/*=active_extruder*/) {
  1612. switch (message) {
  1613. case PAUSE_MESSAGE_PARKING: DWIN_Popup_Pause(GET_TEXT_F(MSG_PAUSE_PRINT_PARKING)); break;
  1614. case PAUSE_MESSAGE_CHANGING: DWIN_Popup_Pause(GET_TEXT_F(MSG_FILAMENT_CHANGE_INIT)); break;
  1615. case PAUSE_MESSAGE_UNLOAD: DWIN_Popup_Pause(GET_TEXT_F(MSG_FILAMENT_CHANGE_UNLOAD)); break;
  1616. case PAUSE_MESSAGE_WAITING: DWIN_Popup_Pause(GET_TEXT_F(MSG_ADVANCED_PAUSE_WAITING), ICON_Continue_E); break;
  1617. case PAUSE_MESSAGE_INSERT: DWIN_Popup_Continue(ICON_BLTouch, F("Advanced Pause"), GET_TEXT_F(MSG_FILAMENT_CHANGE_INSERT)); break;
  1618. case PAUSE_MESSAGE_LOAD: DWIN_Popup_Pause(GET_TEXT_F(MSG_FILAMENT_CHANGE_LOAD)); break;
  1619. case PAUSE_MESSAGE_PURGE: DWIN_Popup_Pause(GET_TEXT_F(MSG_FILAMENT_CHANGE_PURGE)); break;
  1620. case PAUSE_MESSAGE_OPTION: DWIN_Popup_FilamentPurge(); break;
  1621. case PAUSE_MESSAGE_RESUME: DWIN_Popup_Pause(GET_TEXT_F(MSG_FILAMENT_CHANGE_RESUME)); break;
  1622. case PAUSE_MESSAGE_HEAT: DWIN_Popup_Pause(GET_TEXT_F(MSG_FILAMENT_CHANGE_HEAT), ICON_Continue_E); break;
  1623. case PAUSE_MESSAGE_HEATING: ui.set_status_P(GET_TEXT(MSG_FILAMENT_CHANGE_HEATING)); break;
  1624. case PAUSE_MESSAGE_STATUS: HMI_ReturnScreen(); break;
  1625. default: break;
  1626. }
  1627. }
  1628. void Draw_Popup_FilamentPurge() {
  1629. DWIN_Draw_Popup(ICON_BLTouch, F("Advanced Pause"), F("Purge or Continue?"));
  1630. DWINUI::Draw_Icon(ICON_Confirm_E, 26, 280);
  1631. DWINUI::Draw_Icon(ICON_Continue_E, 146, 280);
  1632. Draw_Select_Highlight(true);
  1633. DWIN_UpdateLCD();
  1634. }
  1635. // Handle responses such as:
  1636. // - Purge More, Continue
  1637. // - General "Continue" response
  1638. void DWIN_Popup_FilamentPurge() {
  1639. HMI_SaveProcessID(FilamentPurge);
  1640. pause_menu_response = PAUSE_RESPONSE_WAIT_FOR;
  1641. Draw_Popup_FilamentPurge();
  1642. }
  1643. void HMI_FilamentPurge() {
  1644. EncoderState encoder_diffState = get_encoder_state();
  1645. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1646. if (encoder_diffState == ENCODER_DIFF_CW)
  1647. Draw_Select_Highlight(false);
  1648. else if (encoder_diffState == ENCODER_DIFF_CCW)
  1649. Draw_Select_Highlight(true);
  1650. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  1651. if (HMI_flag.select_flag)
  1652. pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; // "Purge More" button
  1653. else {
  1654. HMI_SaveProcessID(NothingToDo);
  1655. pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; // "Continue" button
  1656. }
  1657. }
  1658. DWIN_UpdateLCD();
  1659. }
  1660. #endif // ADVANCED_PAUSE_FEATURE
  1661. #if HAS_MESH
  1662. void DWIN_MeshViewer() {
  1663. if (!leveling_is_valid())
  1664. DWIN_Popup_Continue(ICON_BLTouch, F("Mesh viewer"), F("No valid mesh"));
  1665. else {
  1666. HMI_SaveProcessID(WaitResponse);
  1667. MeshViewer.Draw();
  1668. }
  1669. }
  1670. #endif
  1671. void HMI_LockScreen() {
  1672. EncoderState encoder_diffState = get_encoder_state();
  1673. if (encoder_diffState == ENCODER_DIFF_NO) return;
  1674. lockScreen.onEncoder(encoder_diffState);
  1675. if (lockScreen.isUnlocked()) {
  1676. if (CurrentMenu == AdvancedSettings)
  1677. Draw_AdvancedSettings_Menu();
  1678. else
  1679. Draw_Tune_Menu();
  1680. }
  1681. }
  1682. void DWIN_LockScreen(const bool flag) {
  1683. HMI_flag.lock_flag = flag;
  1684. checkkey = Locked;
  1685. lockScreen.init();
  1686. }
  1687. //
  1688. // NEW MENU SUBSYSTEM =========================================================
  1689. //
  1690. // On click functions
  1691. // Generic onclick event without draw anything
  1692. // process: process id HMI destiny
  1693. // lo: low limit
  1694. // hi: high limit
  1695. // dp: decimal places, 0 for integers
  1696. // val: value / scaled value
  1697. // LiveUpdate: live update function when the encoder changes
  1698. // Apply: update function when the encoder is pressed
  1699. void SetOnClick(uint8_t process, const int32_t lo, const int32_t hi, uint8_t dp, const int32_t val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr) {
  1700. checkkey = process;
  1701. HMI_value.MinValue = lo;
  1702. HMI_value.MaxValue = hi;
  1703. HMI_value.dp = dp;
  1704. HMI_value.Apply = Apply;
  1705. HMI_value.LiveUpdate = LiveUpdate;
  1706. HMI_value.Value = val;
  1707. EncoderRate.enabled = true;
  1708. }
  1709. // Generic onclick event for integer values
  1710. // process: process id HMI destiny
  1711. // lo: scaled low limit
  1712. // hi: scaled high limit
  1713. // val: value
  1714. // LiveUpdate: live update function when the encoder changes
  1715. // Apply: update function when the encoder is pressed
  1716. void SetValueOnClick(uint8_t process, const int32_t lo, const int32_t hi, const int32_t val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr) {
  1717. SetOnClick(process, lo, hi, 0, val, Apply, LiveUpdate);
  1718. Draw_Menu_IntValue(HMI_data.Selected_Color, CurrentMenu->line(), 4, HMI_value.Value);
  1719. }
  1720. // Generic onclick event for float values
  1721. // process: process id HMI destiny
  1722. // lo: scaled low limit
  1723. // hi: scaled high limit
  1724. // val: value
  1725. // LiveUpdate: live update function when the encoder changes
  1726. // Apply: update function when the encoder is pressed
  1727. void SetValueOnClick(uint8_t process, const float lo, const float hi, uint8_t dp, const float val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr) {
  1728. const int32_t value = round(val * POW(10, dp));
  1729. SetOnClick(process, lo * POW(10, dp), hi * POW(10, dp), dp, value, Apply, LiveUpdate);
  1730. DWINUI::Draw_Signed_Float(HMI_data.Text_Color, HMI_data.Selected_Color, 3, dp, VALX - dp * DWINUI::fontWidth(DWIN_FONT_MENU), MBASE(CurrentMenu->line()), val);
  1731. }
  1732. // Generic onclick event for integer values
  1733. // lo: scaled low limit
  1734. // hi: scaled high limit
  1735. // val: value
  1736. // LiveUpdate: live update function when the encoder changes
  1737. // Apply: update function when the encoder is pressed
  1738. inline void SetIntOnClick(const int32_t lo, const int32_t hi, const int32_t val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr) {
  1739. SetValueOnClick(SetInt, lo, hi, val, Apply, LiveUpdate);
  1740. }
  1741. // Generic onclick event for set pointer to 16 bit uinteger values
  1742. // lo: low limit
  1743. // hi: high limit
  1744. // LiveUpdate: live update function when the encoder changes
  1745. // Apply: update function when the encoder is pressed
  1746. void SetPIntOnClick(const int32_t lo, const int32_t hi, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr) {
  1747. HMI_value.P_Int = (int16_t*)static_cast<MenuItemPtrClass*>(CurrentMenu->SelectedItem())->value;
  1748. const int32_t value = *HMI_value.P_Int;
  1749. SetValueOnClick(SetPInt, lo, hi, value, Apply, LiveUpdate);
  1750. }
  1751. // Generic onclick event for float values
  1752. // process: process id HMI destiny
  1753. // lo: low limit
  1754. // hi: high limit
  1755. // dp: decimal places
  1756. // val: value
  1757. inline void SetFloatOnClick(const float lo, const float hi, uint8_t dp, const float val, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr) {
  1758. SetValueOnClick(SetFloat, lo, hi, dp, val, Apply, LiveUpdate);
  1759. }
  1760. // Generic onclick event for set pointer to float values
  1761. // lo: low limit
  1762. // hi: high limit
  1763. // LiveUpdate: live update function when the encoder changes
  1764. // Apply: update function when the encoder is pressed
  1765. void SetPFloatOnClick(const float lo, const float hi, uint8_t dp, void (*Apply)() = nullptr, void (*LiveUpdate)() = nullptr) {
  1766. HMI_value.P_Float = (float*)static_cast<MenuItemPtrClass*>(CurrentMenu->SelectedItem())->value;
  1767. SetValueOnClick(SetPFloat, lo, hi, dp, *HMI_value.P_Float, Apply, LiveUpdate);
  1768. }
  1769. #if ENABLED(EEPROM_SETTINGS)
  1770. void WriteEeprom() {
  1771. const bool success = settings.save();
  1772. HMI_AudioFeedback(success);
  1773. }
  1774. void ReadEeprom() {
  1775. const bool success = settings.load();
  1776. DWIN_Redraw_screen();
  1777. HMI_AudioFeedback(success);
  1778. }
  1779. void ResetEeprom() {
  1780. settings.reset();
  1781. DWIN_Redraw_screen();
  1782. HMI_AudioFeedback();
  1783. }
  1784. #endif
  1785. // Reset Printer
  1786. void RebootPrinter() {
  1787. dwin_abort_flag = true;
  1788. wait_for_heatup = wait_for_user = false; // Stop waiting for heating/user
  1789. thermalManager.disable_all_heaters();
  1790. planner.finish_and_disable();
  1791. DWIN_RebootScreen();
  1792. HAL_reboot();
  1793. }
  1794. void Goto_InfoMenu(){
  1795. checkkey = Info;
  1796. Draw_Info_Menu();
  1797. }
  1798. void DisableMotors() { queue.inject(F("M84")); }
  1799. void AutoHome() { queue.inject_P(G28_STR); }
  1800. void SetHome() {
  1801. // Apply workspace offset, making the current position 0,0,0
  1802. queue.inject(F("G92 X0 Y0 Z0"));
  1803. HMI_AudioFeedback();
  1804. }
  1805. #if HAS_ZOFFSET_ITEM
  1806. bool printer_busy() { return planner.movesplanned() || printingIsActive(); }
  1807. void ApplyZOffset() { TERN_(EEPROM_SETTINGS, settings.save()); }
  1808. void LiveZOffset() {
  1809. last_zoffset = dwin_zoffset;
  1810. dwin_zoffset = HMI_value.Value / 100.0f;
  1811. #if EITHER(BABYSTEP_ZPROBE_OFFSET, JUST_BABYSTEP)
  1812. if (BABYSTEP_ALLOWED()) babystep.add_mm(Z_AXIS, dwin_zoffset - last_zoffset);
  1813. #endif
  1814. }
  1815. #if EITHER(HAS_BED_PROBE, BABYSTEPPING)
  1816. void SetZOffset() {
  1817. SetPFloatOnClick(Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, 2, ApplyZOffset, LiveZOffset);
  1818. }
  1819. #endif
  1820. #endif
  1821. #if HAS_PREHEAT
  1822. void SetPreheat(const uint8_t i) {
  1823. TERN_(HAS_HOTEND, thermalManager.setTargetHotend(ui.material_preset[i].hotend_temp, 0));
  1824. TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(ui.material_preset[i].bed_temp));
  1825. TERN_(HAS_FAN, thermalManager.set_fan_speed(0, ui.material_preset[i].fan_speed));
  1826. }
  1827. void SetPreheat0() { SetPreheat(0); }
  1828. void SetPreheat1() { SetPreheat(1); }
  1829. void SetPreheat2() { SetPreheat(2); }
  1830. void SetCoolDown() {
  1831. TERN_(HAS_FAN, thermalManager.zero_fan_speeds());
  1832. #if HAS_HOTEND || HAS_HEATED_BED
  1833. thermalManager.disable_all_heaters();
  1834. #endif
  1835. }
  1836. #endif
  1837. void SetLanguage() {
  1838. HMI_ToggleLanguage();
  1839. CurrentMenu = nullptr; // Invalidate menu to full redraw
  1840. Draw_Prepare_Menu();
  1841. }
  1842. void LiveMove() {
  1843. *HMI_value.P_Float = HMI_value.Value / MINUNITMULT;
  1844. if (!planner.is_full()) {
  1845. planner.synchronize();
  1846. planner.buffer_line(current_position, homing_feedrate(HMI_value.axis));
  1847. }
  1848. }
  1849. void ApplyMoveE() {
  1850. last_E = HMI_value.Value / MINUNITMULT;
  1851. if (!planner.is_full()) {
  1852. planner.synchronize();
  1853. planner.buffer_line(current_position, MMM_TO_MMS(FEEDRATE_E));
  1854. }
  1855. }
  1856. void SetMoveX() { HMI_value.axis = X_AXIS; SetPFloatOnClick(X_MIN_POS, X_MAX_POS, UNITFDIGITS, planner.synchronize, LiveMove);}
  1857. void SetMoveY() { HMI_value.axis = Y_AXIS; SetPFloatOnClick(Y_MIN_POS, Y_MAX_POS, UNITFDIGITS, planner.synchronize, LiveMove);}
  1858. void SetMoveZ() { HMI_value.axis = Z_AXIS; SetPFloatOnClick(Z_MIN_POS, Z_MAX_POS, UNITFDIGITS, planner.synchronize, LiveMove);}
  1859. #if HAS_HOTEND
  1860. void SetMoveE() {
  1861. #if ENABLED(PREVENT_COLD_EXTRUSION)
  1862. if (thermalManager.tooColdToExtrude(0)) {
  1863. Popup_Window_ETempTooLow();
  1864. return;
  1865. }
  1866. #endif
  1867. SetPFloatOnClick(last_E - (EXTRUDE_MAXLENGTH), last_E + (EXTRUDE_MAXLENGTH), UNITFDIGITS, ApplyMoveE);
  1868. }
  1869. #endif
  1870. void SetMoveZto0() {
  1871. char cmd[48] = "";
  1872. char str_1[5] = "", str_2[5] = "";
  1873. sprintf_P(cmd, PSTR("G28OXY\nG28Z\nG0X%sY%sF5000\nG0Z0F300"),
  1874. #if ENABLED(MESH_BED_LEVELING)
  1875. dtostrf(0, 1, 1, str_1),
  1876. dtostrf(0, 1, 1, str_2)
  1877. #else
  1878. dtostrf(X_CENTER, 1, 1, str_1),
  1879. dtostrf(Y_CENTER, 1, 1, str_2)
  1880. #endif
  1881. );
  1882. gcode.process_subcommands_now(cmd);
  1883. planner.synchronize();
  1884. ui.set_status_P(PSTR("Now adjust Z Offset"));
  1885. HMI_AudioFeedback(true);
  1886. }
  1887. void SetPID(celsius_t t, heater_id_t h) {
  1888. char cmd[48] = "";
  1889. char str_1[5] = "", str_2[5] = "";
  1890. sprintf_P(cmd, PSTR("G28OXY\nG0Z5F300\nG0X%sY%sF5000\nM84"),
  1891. dtostrf(X_CENTER, 1, 1, str_1),
  1892. dtostrf(Y_CENTER, 1, 1, str_2)
  1893. );
  1894. gcode.process_subcommands_now(cmd);
  1895. planner.synchronize();
  1896. thermalManager.PID_autotune(t, h, HMI_data.PidCycles, true);
  1897. }
  1898. #if HAS_HOTEND
  1899. void HotendPID() { SetPID(HMI_data.HotendPidT, H_E0); }
  1900. #endif
  1901. #if HAS_HEATED_BED
  1902. void BedPID() { SetPID(HMI_data.BedPidT, H_BED); }
  1903. #endif
  1904. #if ENABLED(POWER_LOSS_RECOVERY)
  1905. void SetPwrLossr() {
  1906. recovery.enable(!recovery.enabled);
  1907. Draw_Chkb_Line(CurrentMenu->line(), recovery.enabled);
  1908. DWIN_UpdateLCD();
  1909. }
  1910. #endif
  1911. #if HAS_LCD_BRIGHTNESS
  1912. void LiveBrightness() { ui.set_brightness(HMI_value.Value); }
  1913. void SetBrightness() { SetIntOnClick(LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, ui.brightness, nullptr, LiveBrightness); }
  1914. #endif
  1915. #if ENABLED(SOUND_MENU_ITEM)
  1916. void SetEnableSound() {
  1917. ui.buzzer_enabled = !ui.buzzer_enabled;
  1918. Draw_Chkb_Line(CurrentMenu->line(), ui.buzzer_enabled);
  1919. DWIN_UpdateLCD();
  1920. }
  1921. #endif
  1922. void Goto_LockScreen() { DWIN_LockScreen(true); }
  1923. #if HAS_HOME_OFFSET
  1924. void ApplyHomeOffset() { set_home_offset(HMI_value.axis, HMI_value.Value / MINUNITMULT); }
  1925. void SetHomeOffsetX() { HMI_value.axis = X_AXIS; SetPFloatOnClick(-50, 50, UNITFDIGITS, ApplyHomeOffset); }
  1926. void SetHomeOffsetY() { HMI_value.axis = Y_AXIS; SetPFloatOnClick(-50, 50, UNITFDIGITS, ApplyHomeOffset); }
  1927. void SetHomeOffsetZ() { HMI_value.axis = Z_AXIS; SetPFloatOnClick( -2, 2, UNITFDIGITS, ApplyHomeOffset); }
  1928. #endif
  1929. #if HAS_BED_PROBE
  1930. void SetProbeOffsetX() { SetPFloatOnClick(-50, 50, UNITFDIGITS); }
  1931. void SetProbeOffsetY() { SetPFloatOnClick(-50, 50, UNITFDIGITS); }
  1932. void SetProbeOffsetZ() { SetPFloatOnClick(-10, 10, 2); }
  1933. void ProbeTest() {
  1934. ui.set_status_P(GET_TEXT(MSG_M48_TEST));
  1935. queue.inject(F("G28O\nM48 P10"));
  1936. }
  1937. #endif
  1938. #if HAS_FILAMENT_SENSOR
  1939. void SetRunoutEnable() {
  1940. runout.reset();
  1941. runout.enabled = !runout.enabled;
  1942. Draw_Chkb_Line(CurrentMenu->line(), runout.enabled);
  1943. DWIN_UpdateLCD();
  1944. }
  1945. #if HAS_FILAMENT_RUNOUT_DISTANCE
  1946. void ApplyRunoutDistance() { runout.set_runout_distance(HMI_value.Value / MINUNITMULT); }
  1947. void SetRunoutDistance() { SetFloatOnClick(0, 999, UNITFDIGITS, runout.runout_distance(), ApplyRunoutDistance); }
  1948. #endif
  1949. #endif
  1950. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1951. void SetFilLoad() { SetPFloatOnClick(0, MAX_LOAD_UNLOAD, UNITFDIGITS); }
  1952. void SetFilUnload() { SetPFloatOnClick(0, MAX_LOAD_UNLOAD, UNITFDIGITS); }
  1953. #endif
  1954. #if ENABLED(PREVENT_COLD_EXTRUSION)
  1955. void ApplyExtMinT() { thermalManager.extrude_min_temp = HMI_data.ExtMinT; thermalManager.allow_cold_extrude = (HMI_data.ExtMinT == 0); }
  1956. void SetExtMinT() { SetPIntOnClick(MIN_ETEMP, MAX_ETEMP, ApplyExtMinT); }
  1957. #endif
  1958. void RestoreDefaultsColors() {
  1959. DWIN_SetColorDefaults();
  1960. DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color);
  1961. DWIN_Redraw_screen();
  1962. }
  1963. void SelColor() {
  1964. HMI_value.P_Int = (int16_t*)static_cast<MenuItemPtrClass*>(CurrentMenu->SelectedItem())->value;
  1965. HMI_value.Color[0] = GetRColor(*HMI_value.P_Int); // Red
  1966. HMI_value.Color[1] = GetGColor(*HMI_value.P_Int); // Green
  1967. HMI_value.Color[2] = GetBColor(*HMI_value.P_Int); // Blue
  1968. Draw_GetColor_Menu();
  1969. }
  1970. void LiveRGBColor() {
  1971. HMI_value.Color[CurrentMenu->line() - 2] = HMI_value.Value;
  1972. uint16_t color = RGB(HMI_value.Color[0], HMI_value.Color[1], HMI_value.Color[2]);
  1973. DWIN_Draw_Rectangle(1, color, 20, 315, DWIN_WIDTH - 20, 335);
  1974. }
  1975. void SetRGBColor() {
  1976. const uint8_t color = CurrentMenu->SelectedItem()->icon;
  1977. SetIntOnClick(0, (color == 1) ? 63 : 31, HMI_value.Color[color], nullptr, LiveRGBColor);
  1978. }
  1979. void DWIN_ApplyColor() {
  1980. *HMI_value.P_Int = RGB(HMI_value.Color[0], HMI_value.Color[1], HMI_value.Color[2]);
  1981. DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color);
  1982. Draw_Status_Area(false);
  1983. Draw_SelectColors_Menu();
  1984. ui.set_status_P(PSTR("Colors applied"));
  1985. }
  1986. void SetSpeed() { SetPIntOnClick(MIN_PRINT_SPEED, MAX_PRINT_SPEED); }
  1987. #if HAS_HOTEND
  1988. void ApplyHotendTemp() { thermalManager.setTargetHotend(HMI_value.Value, 0); }
  1989. void SetHotendTemp() { SetIntOnClick(MIN_ETEMP, MAX_ETEMP, thermalManager.degTargetHotend(0), ApplyHotendTemp); }
  1990. #endif
  1991. #if HAS_HEATED_BED
  1992. void ApplyBedTemp() { thermalManager.setTargetBed(HMI_value.Value); }
  1993. void SetBedTemp() { SetIntOnClick(BED_MINTEMP, BED_MAX_TARGET, thermalManager.degTargetBed(), ApplyBedTemp); }
  1994. #endif
  1995. #if HAS_FAN
  1996. void ApplyFanSpeed() { thermalManager.set_fan_speed(0, HMI_value.Value); }
  1997. void SetFanSpeed() { SetIntOnClick(0, 255, thermalManager.fan_speed[0], ApplyFanSpeed); }
  1998. #endif
  1999. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2000. void ChangeFilament() {
  2001. HMI_SaveProcessID(NothingToDo);
  2002. queue.inject(F("M600 B2"));
  2003. }
  2004. void ParkHead(){
  2005. ui.set_status_P(GET_TEXT(MSG_FILAMENT_PARK_ENABLED));
  2006. queue.inject(F("G28O\nG27"));
  2007. }
  2008. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  2009. void UnloadFilament(){
  2010. ui.set_status_P(GET_TEXT(MSG_FILAMENTUNLOAD));
  2011. queue.inject(F("M702 Z20"));
  2012. }
  2013. void LoadFilament(){
  2014. ui.set_status_P(GET_TEXT(MSG_FILAMENTLOAD));
  2015. queue.inject(F("M701 Z20"));
  2016. }
  2017. #endif
  2018. #endif // ADVANCED_PAUSE_FEATURE
  2019. void SetFlow() { SetPIntOnClick(MIN_PRINT_FLOW, MAX_PRINT_FLOW); }
  2020. // Leveling Bed Corners
  2021. void LevBed(uint8_t point) {
  2022. char cmd[100] = "";
  2023. #if HAS_ONESTEP_LEVELING
  2024. char str_1[6] = "", str_2[6] = "", str_3[6] = "";
  2025. #define fmt "X:%s, Y:%s, Z:%s"
  2026. float xpos = 0, ypos = 0, zval = 0;
  2027. float margin = PROBING_MARGIN;
  2028. #else
  2029. #define fmt "M420 S0\nG28O\nG90\nG0 Z5 F300\nG0 X%i Y%i F5000\nG0 Z0 F300"
  2030. int16_t xpos = 0, ypos = 0;
  2031. int16_t margin = 30;
  2032. #endif
  2033. switch (point) {
  2034. case 0:
  2035. ui.set_status_P(GET_TEXT(MSG_LEVBED_FL));
  2036. xpos = ypos = margin;
  2037. break;
  2038. case 1:
  2039. ui.set_status_P(GET_TEXT(MSG_LEVBED_FR));
  2040. xpos = X_BED_SIZE - margin; ypos = margin;
  2041. break;
  2042. case 2:
  2043. ui.set_status_P(GET_TEXT(MSG_LEVBED_BR));
  2044. xpos = X_BED_SIZE - margin; ypos = Y_BED_SIZE - margin;
  2045. break;
  2046. case 3:
  2047. ui.set_status_P(GET_TEXT(MSG_LEVBED_BL));
  2048. xpos = margin; ypos = Y_BED_SIZE - margin;
  2049. break;
  2050. case 4:
  2051. ui.set_status_P(GET_TEXT(MSG_LEVBED_C));
  2052. xpos = X_BED_SIZE / 2; ypos = Y_BED_SIZE / 2;
  2053. break;
  2054. }
  2055. #if HAS_ONESTEP_LEVELING
  2056. planner.synchronize();
  2057. gcode.process_subcommands_now(F("M420S0\nG28O"));
  2058. planner.synchronize();
  2059. zval = probe.probe_at_point(xpos, ypos, PROBE_PT_STOW);
  2060. sprintf_P(cmd, PSTR(fmt),
  2061. dtostrf(xpos, 1, 1, str_1),
  2062. dtostrf(ypos, 1, 1, str_2),
  2063. dtostrf(zval, 1, 2, str_3)
  2064. );
  2065. ui.set_status_P(cmd);
  2066. #else
  2067. planner.synchronize();
  2068. sprintf_P(cmd, PSTR(fmt), xpos, ypos);
  2069. queue.inject(cmd);
  2070. #endif
  2071. }
  2072. void LevBedFL() { LevBed(0); }
  2073. void LevBedFR() { LevBed(1); }
  2074. void LevBedBR() { LevBed(2); }
  2075. void LevBedBL() { LevBed(3); }
  2076. void LevBedC () { LevBed(4); }
  2077. #if ENABLED(MESH_BED_LEVELING)
  2078. void ManualMeshStart(){
  2079. ui.set_status_P(GET_TEXT(MSG_UBL_BUILD_MESH_MENU));
  2080. gcode.process_subcommands_now(F("G28 XYO\nG28 Z\nM211 S0\nG29S1"));
  2081. planner.synchronize();
  2082. #ifdef MANUAL_PROBE_START_Z
  2083. const uint8_t line = CurrentMenu->line(MMeshMoveZItem->pos);
  2084. DWINUI::Draw_Signed_Float(HMI_data.Text_Color, HMI_data.Background_Color, 3, 2, VALX - 2 * DWINUI::fontWidth(DWIN_FONT_MENU), MBASE(line), MANUAL_PROBE_START_Z);
  2085. #endif
  2086. }
  2087. void LiveMeshMoveZ() {
  2088. *HMI_value.P_Float = HMI_value.Value / POW(10, 2);
  2089. if (!planner.is_full()) {
  2090. planner.synchronize();
  2091. planner.buffer_line(current_position, homing_feedrate(Z_AXIS));
  2092. }
  2093. }
  2094. void SetMMeshMoveZ() { SetPFloatOnClick(-1, 1, 2, planner.synchronize, LiveMeshMoveZ);}
  2095. void ManualMeshContinue(){
  2096. gcode.process_subcommands_now(F("G29S2"));
  2097. planner.synchronize();
  2098. MMeshMoveZItem->draw(CurrentMenu->line(MMeshMoveZItem->pos));
  2099. }
  2100. void ManualMeshSave(){
  2101. ui.set_status_P(GET_TEXT(MSG_UBL_STORAGE_MESH_MENU));
  2102. queue.inject(F("M211 S1\nM500"));
  2103. }
  2104. #endif // MESH_BED_LEVELING
  2105. #if HAS_PREHEAT
  2106. #if HAS_HOTEND
  2107. void SetPreheatEndTemp() { SetPIntOnClick(MIN_ETEMP, MAX_ETEMP); }
  2108. #endif
  2109. #if HAS_HEATED_BED
  2110. void SetPreheatBedTemp() { SetPIntOnClick(BED_MINTEMP, BED_MAX_TARGET); }
  2111. #endif
  2112. #if HAS_FAN
  2113. void SetPreheatFanSpeed() { SetPIntOnClick(0, 255); }
  2114. #endif
  2115. #endif
  2116. void ApplyMaxSpeed() { planner.set_max_feedrate(HMI_value.axis, HMI_value.Value / MINUNITMULT); }
  2117. void SetMaxSpeedX() { HMI_value.axis = X_AXIS, SetFloatOnClick(MIN_MAXFEEDSPEED, default_max_feedrate[X_AXIS] * 2, UNITFDIGITS, planner.settings.max_feedrate_mm_s[X_AXIS], ApplyMaxSpeed); }
  2118. void SetMaxSpeedY() { HMI_value.axis = Y_AXIS, SetFloatOnClick(MIN_MAXFEEDSPEED, default_max_feedrate[Y_AXIS] * 2, UNITFDIGITS, planner.settings.max_feedrate_mm_s[Y_AXIS], ApplyMaxSpeed); }
  2119. void SetMaxSpeedZ() { HMI_value.axis = Z_AXIS, SetFloatOnClick(MIN_MAXFEEDSPEED, default_max_feedrate[Z_AXIS] * 2, UNITFDIGITS, planner.settings.max_feedrate_mm_s[Z_AXIS], ApplyMaxSpeed); }
  2120. #if HAS_HOTEND
  2121. void SetMaxSpeedE() { HMI_value.axis = E_AXIS; SetFloatOnClick(MIN_MAXFEEDSPEED, default_max_feedrate[E_AXIS] * 2, UNITFDIGITS, planner.settings.max_feedrate_mm_s[E_AXIS], ApplyMaxSpeed); }
  2122. #endif
  2123. void ApplyMaxAccel() { planner.set_max_acceleration(HMI_value.axis, HMI_value.Value); }
  2124. void SetMaxAccelX() { HMI_value.axis = X_AXIS, SetIntOnClick(MIN_MAXACCELERATION, default_max_acceleration[X_AXIS] * 2, planner.settings.max_acceleration_mm_per_s2[X_AXIS], ApplyMaxAccel); }
  2125. void SetMaxAccelY() { HMI_value.axis = Y_AXIS, SetIntOnClick(MIN_MAXACCELERATION, default_max_acceleration[Y_AXIS] * 2, planner.settings.max_acceleration_mm_per_s2[Y_AXIS], ApplyMaxAccel); }
  2126. void SetMaxAccelZ() { HMI_value.axis = Z_AXIS, SetIntOnClick(MIN_MAXACCELERATION, default_max_acceleration[Z_AXIS] * 2, planner.settings.max_acceleration_mm_per_s2[Z_AXIS], ApplyMaxAccel); }
  2127. #if HAS_HOTEND
  2128. void SetMaxAccelE() { HMI_value.axis = E_AXIS; SetIntOnClick(MIN_MAXACCELERATION, default_max_acceleration[E_AXIS] * 2, planner.settings.max_acceleration_mm_per_s2[E_AXIS], ApplyMaxAccel); }
  2129. #endif
  2130. #if HAS_CLASSIC_JERK
  2131. void ApplyMaxJerk() { planner.set_max_jerk(HMI_value.axis, HMI_value.Value / MINUNITMULT); }
  2132. void SetMaxJerkX() { HMI_value.axis = X_AXIS, SetFloatOnClick(MIN_MAXJERK, default_max_jerk[X_AXIS] * 2, UNITFDIGITS, planner.max_jerk[X_AXIS], ApplyMaxJerk); }
  2133. void SetMaxJerkY() { HMI_value.axis = Y_AXIS, SetFloatOnClick(MIN_MAXJERK, default_max_jerk[Y_AXIS] * 2, UNITFDIGITS, planner.max_jerk[Y_AXIS], ApplyMaxJerk); }
  2134. void SetMaxJerkZ() { HMI_value.axis = Z_AXIS, SetFloatOnClick(MIN_MAXJERK, default_max_jerk[Z_AXIS] * 2, UNITFDIGITS, planner.max_jerk[Z_AXIS], ApplyMaxJerk); }
  2135. #if HAS_HOTEND
  2136. void SetMaxJerkE() { HMI_value.axis = E_AXIS; SetFloatOnClick(MIN_MAXJERK, default_max_jerk[E_AXIS] * 2, UNITFDIGITS, planner.max_jerk[E_AXIS], ApplyMaxJerk); }
  2137. #endif
  2138. #endif
  2139. void SetStepsX() { HMI_value.axis = X_AXIS, SetPFloatOnClick( MIN_STEP, MAX_STEP, UNITFDIGITS); }
  2140. void SetStepsY() { HMI_value.axis = Y_AXIS, SetPFloatOnClick( MIN_STEP, MAX_STEP, UNITFDIGITS); }
  2141. void SetStepsZ() { HMI_value.axis = Z_AXIS, SetPFloatOnClick( MIN_STEP, MAX_STEP, UNITFDIGITS); }
  2142. #if HAS_HOTEND
  2143. void SetStepsE() { HMI_value.axis = E_AXIS; SetPFloatOnClick( MIN_STEP, MAX_STEP, UNITFDIGITS); }
  2144. void SetHotendPidT() { SetPIntOnClick(MIN_ETEMP, MAX_ETEMP); }
  2145. #endif
  2146. #if HAS_HEATED_BED
  2147. void SetBedPidT() { SetPIntOnClick(BED_MINTEMP, BED_MAX_TARGET); }
  2148. #endif
  2149. #if HAS_HOTEND || HAS_HEATED_BED
  2150. void SetPidCycles() { SetPIntOnClick(3, 50); }
  2151. void SetKp() { SetPFloatOnClick(0, 1000, 2); }
  2152. void ApplyPIDi() {
  2153. *HMI_value.P_Float = scalePID_i(HMI_value.Value / POW(10, 2));
  2154. thermalManager.updatePID();
  2155. }
  2156. void ApplyPIDd() {
  2157. *HMI_value.P_Float = scalePID_d(HMI_value.Value / POW(10, 2));
  2158. thermalManager.updatePID();
  2159. }
  2160. void SetKi() {
  2161. HMI_value.P_Float = (float*)static_cast<MenuItemPtrClass*>(CurrentMenu->SelectedItem())->value;
  2162. const float value = unscalePID_i(*HMI_value.P_Float);
  2163. SetFloatOnClick(0, 1000, 2, value, ApplyPIDi);
  2164. }
  2165. void SetKd() {
  2166. HMI_value.P_Float = (float*)static_cast<MenuItemPtrClass*>(CurrentMenu->SelectedItem())->value;
  2167. const float value = unscalePID_d(*HMI_value.P_Float);
  2168. SetFloatOnClick(0, 1000, 2, value, ApplyPIDd);
  2169. }
  2170. #endif
  2171. // Menuitem Drawing functions =================================================
  2172. void onDrawMenuItem(MenuItemClass* menuitem, int8_t line) {
  2173. if (menuitem->icon) DWINUI::Draw_Icon(menuitem->icon, ICOX, MBASE(line) - 3);
  2174. if (menuitem->frameid)
  2175. DWIN_Frame_AreaCopy(menuitem->frameid, menuitem->frame.left, menuitem->frame.top, menuitem->frame.right, menuitem->frame.bottom, LBLX, MBASE(line));
  2176. else if (menuitem->caption)
  2177. DWINUI::Draw_String(LBLX, MBASE(line) - 1, menuitem->caption);
  2178. DWIN_Draw_HLine(HMI_data.SplitLine_Color, 16, MYPOS(line + 1), 240);
  2179. }
  2180. void onDrawSubMenu(MenuItemClass* menuitem, int8_t line) {
  2181. onDrawMenuItem(menuitem, line);
  2182. DWINUI::Draw_Icon(ICON_More, VALX + 16, MBASE(line) - 3);
  2183. }
  2184. void onDrawIntMenu(MenuItemClass* menuitem, int8_t line, uint16_t value) {
  2185. onDrawMenuItem(menuitem, line);
  2186. Draw_Menu_IntValue(HMI_data.Background_Color, line, 4, value);
  2187. }
  2188. void onDrawPIntMenu(MenuItemClass* menuitem, int8_t line) {
  2189. const uint16_t value = *(uint16_t*)static_cast<MenuItemPtrClass*>(menuitem)->value;
  2190. onDrawIntMenu(menuitem, line, value);
  2191. }
  2192. void onDrawPInt8Menu(MenuItemClass* menuitem, int8_t line) {
  2193. const uint8_t value = *(uint8_t*)static_cast<MenuItemPtrClass*>(menuitem)->value;
  2194. onDrawIntMenu(menuitem, line, value);
  2195. }
  2196. void onDrawPInt32Menu(MenuItemClass* menuitem, int8_t line) {
  2197. const uint32_t value = *(uint32_t*)static_cast<MenuItemPtrClass*>(menuitem)->value;
  2198. onDrawIntMenu(menuitem, line, value);
  2199. }
  2200. void onDrawFloatMenu(MenuItemClass* menuitem, int8_t line, uint8_t dp, const float value) {
  2201. onDrawMenuItem(menuitem, line);
  2202. DWINUI::Draw_Signed_Float(HMI_data.Text_Color, HMI_data.Background_Color, 3, dp, VALX - dp * DWINUI::fontWidth(DWIN_FONT_MENU), MBASE(line), value);
  2203. }
  2204. void onDrawPFloatMenu(MenuItemClass* menuitem, int8_t line) {
  2205. const float value = *(float*)static_cast<MenuItemPtrClass*>(menuitem)->value;
  2206. const int8_t dp = UNITFDIGITS;
  2207. onDrawFloatMenu(menuitem, line, dp, value);
  2208. }
  2209. void onDrawPFloat2Menu(MenuItemClass* menuitem, int8_t line) {
  2210. const float value = *(float*)static_cast<MenuItemPtrClass*>(menuitem)->value;
  2211. onDrawFloatMenu(menuitem, line, 2, value);
  2212. }
  2213. void onDrawChkbMenu(MenuItemClass* menuitem, int8_t line, bool checked) {
  2214. onDrawMenuItem(menuitem, line);
  2215. Draw_Chkb_Line(line, checked);
  2216. }
  2217. void onDrawBack(MenuItemClass* menuitem, int8_t line) {
  2218. if (HMI_IsChinese()) menuitem->SetFrame(1, 129, 72, 156, 84);
  2219. onDrawMenuItem(menuitem, line);
  2220. }
  2221. void onDrawTempSubMenu(MenuItemClass* menuitem, int8_t line) {
  2222. if (HMI_IsChinese()) menuitem->SetFrame(1, 57, 104, 84, 116);
  2223. onDrawSubMenu(menuitem, line);
  2224. }
  2225. void onDrawMotionSubMenu(MenuItemClass* menuitem, int8_t line) {
  2226. if (HMI_IsChinese()) menuitem->SetFrame(1, 87, 104, 114, 116);
  2227. onDrawSubMenu(menuitem, line);
  2228. }
  2229. #if ENABLED(EEPROM_SETTINGS)
  2230. void onDrawWriteEeprom(MenuItemClass* menuitem, int8_t line) {
  2231. if (HMI_IsChinese()) menuitem->SetFrame(1, 117, 104, 172, 116);
  2232. onDrawMenuItem(menuitem, line);
  2233. }
  2234. void onDrawReadEeprom(MenuItemClass* menuitem, int8_t line) {
  2235. if (HMI_IsChinese()) menuitem->SetFrame(1, 174, 103, 229, 116);
  2236. onDrawMenuItem(menuitem, line);
  2237. }
  2238. void onDrawResetEeprom(MenuItemClass* menuitem, int8_t line) {
  2239. if (HMI_IsChinese()) menuitem->SetFrame(1, 1, 118, 56, 131);
  2240. onDrawMenuItem(menuitem, line);
  2241. }
  2242. #endif
  2243. void onDrawInfoSubMenu(MenuItemClass* menuitem, int8_t line) {
  2244. if (HMI_IsChinese()) menuitem->SetFrame(1, 231, 104, 258, 116);
  2245. onDrawSubMenu(menuitem, line);
  2246. }
  2247. void onDrawMoveX(MenuItemClass* menuitem, int8_t line) {
  2248. if (HMI_IsChinese()) menuitem->SetFrame(1, 58, 118, 106, 132);
  2249. onDrawPFloatMenu(menuitem, line);
  2250. }
  2251. void onDrawMoveY(MenuItemClass* menuitem, int8_t line) {
  2252. if (HMI_IsChinese()) menuitem->SetFrame(1, 109, 118, 157, 132);
  2253. onDrawPFloatMenu(menuitem, line);
  2254. }
  2255. void onDrawMoveZ(MenuItemClass* menuitem, int8_t line) {
  2256. if (HMI_IsChinese()) menuitem->SetFrame(1, 160, 118, 209, 132);
  2257. onDrawPFloatMenu(menuitem, line);
  2258. }
  2259. #if HAS_HOTEND
  2260. void onDrawMoveE(MenuItemClass* menuitem, int8_t line) {
  2261. if (HMI_IsChinese()) menuitem->SetFrame(1, 212, 118, 253, 131);
  2262. onDrawPFloatMenu(menuitem, line);
  2263. }
  2264. #endif
  2265. void onDrawMoveSubMenu(MenuItemClass* menuitem, int8_t line) {
  2266. if (HMI_IsChinese()) menuitem->SetFrame(1, 159, 70, 200, 84);
  2267. onDrawSubMenu(menuitem, line);
  2268. }
  2269. void onDrawDisableMotors(MenuItemClass* menuitem, int8_t line) {
  2270. if (HMI_IsChinese()) menuitem->SetFrame(1, 204, 70, 259, 82);
  2271. onDrawMenuItem(menuitem, line);
  2272. }
  2273. void onDrawAutoHome(MenuItemClass* menuitem, int8_t line) {
  2274. if (HMI_IsChinese()) menuitem->SetFrame(1, 0, 89, 41, 101);
  2275. onDrawMenuItem(menuitem, line);
  2276. }
  2277. #if HAS_ZOFFSET_ITEM
  2278. #if EITHER(HAS_BED_PROBE, BABYSTEPPING)
  2279. void onDrawZOffset(MenuItemClass* menuitem, int8_t line) {
  2280. if (HMI_IsChinese()) menuitem->SetFrame(1, 174, 164, 223, 177);
  2281. onDrawPFloat2Menu(menuitem, line);
  2282. }
  2283. #else
  2284. void onDrawHomeOffset(MenuItemClass* menuitem, int8_t line) {
  2285. if (HMI_IsChinese()) menuitem->SetFrame(1, 43, 89, 98, 101);
  2286. onDrawMenuItem(menuitem, line);
  2287. }
  2288. #endif
  2289. #endif
  2290. #if HAS_HOTEND
  2291. void onDrawPreheat1(MenuItemClass* menuitem, int8_t line) {
  2292. if (HMI_IsChinese()) menuitem->SetFrame(1, 100, 89, 151, 101);
  2293. onDrawMenuItem(menuitem, line);
  2294. }
  2295. void onDrawPreheat2(MenuItemClass* menuitem, int8_t line) {
  2296. if (HMI_IsChinese()) menuitem->SetFrame(1, 180, 89, 233, 100);
  2297. onDrawMenuItem(menuitem, line);
  2298. }
  2299. #endif
  2300. #if HAS_PREHEAT
  2301. void onDrawCooldown(MenuItemClass* menuitem, int8_t line) {
  2302. if (HMI_IsChinese()) menuitem->SetFrame(1, 1, 104, 56, 117);
  2303. onDrawMenuItem(menuitem, line);
  2304. }
  2305. #endif
  2306. void onDrawLanguage(MenuItemClass* menuitem, int8_t line) {
  2307. if (HMI_IsChinese()) menuitem->SetFrame(1, 239, 134, 266, 146);
  2308. onDrawMenuItem(menuitem, line);
  2309. DWINUI::Draw_String(VALX, MBASE(line), HMI_IsChinese() ? F("CN") : F("EN"));
  2310. }
  2311. #if ENABLED(POWER_LOSS_RECOVERY)
  2312. void onDrawPwrLossR(MenuItemClass* menuitem, int8_t line) { onDrawChkbMenu(menuitem, line, recovery.enabled); }
  2313. #endif
  2314. void onDrawEnableSound(MenuItemClass* menuitem, int8_t line) { onDrawChkbMenu(menuitem, line, ui.buzzer_enabled); }
  2315. void onDrawSelColorItem(MenuItemClass* menuitem, int8_t line) {
  2316. const uint16_t color = *(uint16_t*)static_cast<MenuItemPtrClass*>(menuitem)->value;
  2317. DWIN_Draw_Rectangle(0, HMI_data.Highlight_Color, ICOX + 1, MBASE(line) - 1 + 1, ICOX + 18, MBASE(line) - 1 + 18);
  2318. DWIN_Draw_Rectangle(1, color, ICOX + 2, MBASE(line) - 1 + 2, ICOX + 17, MBASE(line) - 1 + 17);
  2319. onDrawMenuItem(menuitem, line);
  2320. }
  2321. void onDrawGetColorItem(MenuItemClass* menuitem, int8_t line) {
  2322. const uint8_t i = menuitem->icon;
  2323. uint16_t color;
  2324. switch (i) {
  2325. case 0: color = RGB(31, 0, 0); break; // Red
  2326. case 1: color = RGB(0, 63, 0); break; // Green
  2327. case 2: color = RGB(0, 0, 31); break; // Blue
  2328. default: color = 0; break;
  2329. }
  2330. DWIN_Draw_Rectangle(0, HMI_data.Highlight_Color, ICOX + 1, MBASE(line) - 1 + 1, ICOX + 18, MBASE(line) - 1 + 18);
  2331. DWIN_Draw_Rectangle(1, color, ICOX + 2, MBASE(line) - 1 + 2, ICOX + 17, MBASE(line) - 1 + 17);
  2332. DWINUI::Draw_String(LBLX, MBASE(line) - 1, menuitem->caption);
  2333. Draw_Menu_IntValue(HMI_data.Background_Color, line, 4, HMI_value.Color[i]);
  2334. DWIN_Draw_HLine(HMI_data.SplitLine_Color, 16, MYPOS(line + 1), 240);
  2335. }
  2336. #if HAS_FILAMENT_SENSOR
  2337. void onDrawRunoutEnable(MenuItemClass* menuitem, int8_t line) { onDrawChkbMenu(menuitem, line, runout.enabled); }
  2338. #endif
  2339. void onDrawPIDi(MenuItemClass* menuitem, int8_t line) { onDrawFloatMenu(menuitem, line, 2, unscalePID_i(*(float*)static_cast<MenuItemPtrClass*>(menuitem)->value)); }
  2340. void onDrawPIDd(MenuItemClass* menuitem, int8_t line) { onDrawFloatMenu(menuitem, line, 2, unscalePID_d(*(float*)static_cast<MenuItemPtrClass*>(menuitem)->value)); }
  2341. void onDrawSpeedItem(MenuItemClass* menuitem, int8_t line) {
  2342. if (HMI_IsChinese()) menuitem->SetFrame(1, 116, 164, 171, 176);
  2343. onDrawPIntMenu(menuitem, line);
  2344. }
  2345. #if HAS_HOTEND
  2346. void onDrawHotendTemp(MenuItemClass* menuitem, int8_t line) {
  2347. if (HMI_IsChinese()) menuitem->SetFrame(1, 1, 134, 56, 146);
  2348. onDrawPIntMenu(menuitem, line);
  2349. }
  2350. #endif
  2351. #if HAS_HEATED_BED
  2352. void onDrawBedTemp(MenuItemClass* menuitem, int8_t line) {
  2353. if (HMI_IsChinese()) menuitem->SetFrame(1, 58, 134, 113, 146);
  2354. onDrawPIntMenu(menuitem, line);
  2355. }
  2356. #endif
  2357. #if HAS_FAN
  2358. void onDrawFanSpeed(MenuItemClass* menuitem, int8_t line) {
  2359. if (HMI_IsChinese()) menuitem->SetFrame(1, 115, 134, 170, 146);
  2360. onDrawPInt8Menu(menuitem, line);
  2361. }
  2362. #endif
  2363. void onDrawSteps(MenuItemClass* menuitem, int8_t line) {
  2364. if (HMI_IsChinese()) menuitem->SetFrame(1, 153, 148, 194, 161);
  2365. onDrawSubMenu(menuitem, line);
  2366. }
  2367. #if ENABLED(MESH_BED_LEVELING)
  2368. void onDrawMMeshMoveZ(MenuItemClass* menuitem, int8_t line) {
  2369. if (HMI_IsChinese()) menuitem->SetFrame(1, 160, 118, 209, 132);
  2370. onDrawPFloatMenu(menuitem, line);
  2371. }
  2372. #endif
  2373. #if HAS_PREHEAT
  2374. #if HAS_HOTEND
  2375. void onDrawSetPreheatHotend(MenuItemClass* menuitem, int8_t line) {
  2376. if (HMI_IsChinese()) menuitem->SetFrame(1, 1, 134, 56, 146);
  2377. onDrawPIntMenu(menuitem, line);
  2378. }
  2379. #endif
  2380. #if HAS_HEATED_BED
  2381. void onDrawSetPreheatBed(MenuItemClass* menuitem, int8_t line) {
  2382. if (HMI_IsChinese()) menuitem->SetFrame(1, 58, 134, 113, 146);
  2383. onDrawPIntMenu(menuitem, line);
  2384. }
  2385. #endif
  2386. #if HAS_FAN
  2387. void onDrawSetPreheatFan(MenuItemClass* menuitem, int8_t line) {
  2388. if (HMI_IsChinese()) menuitem->SetFrame(1, 115, 134, 170, 146);
  2389. onDrawPIntMenu(menuitem, line);
  2390. }
  2391. #endif
  2392. void onDrawPLAPreheatSubMenu(MenuItemClass* menuitem, int8_t line) {
  2393. if (HMI_IsChinese()) menuitem->SetFrame(1, 100, 89, 178, 101);
  2394. onDrawSubMenu(menuitem,line);
  2395. }
  2396. void onDrawABSPreheatSubMenu(MenuItemClass* menuitem, int8_t line) {
  2397. if (HMI_IsChinese()) menuitem->SetFrame(1, 180, 89, 260, 100);
  2398. onDrawSubMenu(menuitem,line);
  2399. }
  2400. #endif // HAS_PREHEAT
  2401. void onDrawSpeed(MenuItemClass* menuitem, int8_t line) {
  2402. if (HMI_IsChinese())
  2403. menuitem->SetFrame(1, 173, 133, 228, 147);
  2404. onDrawSubMenu(menuitem, line);
  2405. }
  2406. void onDrawMaxSpeedX(MenuItemClass* menuitem, int8_t line) {
  2407. if (HMI_IsChinese()) {
  2408. menuitem->SetFrame(1, 173, 133, 228, 147);
  2409. DWIN_Frame_AreaCopy(1, 229, 133, 236, 147, LBLX + 58, MBASE(line)); // X
  2410. }
  2411. onDrawPFloatMenu(menuitem, line);
  2412. }
  2413. void onDrawMaxSpeedY(MenuItemClass* menuitem, int8_t line) {
  2414. if (HMI_IsChinese()) {
  2415. menuitem->SetFrame(1, 173, 133, 228, 147);
  2416. DWIN_Frame_AreaCopy(1, 1, 150, 7, 160, LBLX + 58, MBASE(line)); // Y
  2417. }
  2418. onDrawPFloatMenu(menuitem, line);
  2419. }
  2420. void onDrawMaxSpeedZ(MenuItemClass* menuitem, int8_t line) {
  2421. if (HMI_IsChinese()) {
  2422. menuitem->SetFrame(1, 173, 133, 228, 147);
  2423. DWIN_Frame_AreaCopy(1, 9, 150, 16, 160, LBLX + 58, MBASE(line) + 3); // Z
  2424. }
  2425. onDrawPFloatMenu(menuitem, line);
  2426. }
  2427. #if HAS_HOTEND
  2428. void onDrawMaxSpeedE(MenuItemClass* menuitem, int8_t line) {
  2429. if (HMI_IsChinese()) {
  2430. menuitem->SetFrame(1, 173, 133, 228, 147);
  2431. DWIN_Frame_AreaCopy(1, 18, 150, 25, 160, LBLX + 58, MBASE(line)); // E
  2432. }
  2433. onDrawPFloatMenu(menuitem, line);
  2434. }
  2435. #endif
  2436. void onDrawAcc(MenuItemClass* menuitem, int8_t line) {
  2437. if (HMI_IsChinese()) {
  2438. menuitem->SetFrame(1, 173, 133, 200, 147);
  2439. DWIN_Frame_AreaCopy(1, 28, 149, 69, 161, LBLX + 27, MBASE(line) + 1); // ...Acceleration
  2440. }
  2441. onDrawSubMenu(menuitem, line);
  2442. }
  2443. void onDrawMaxAccelX(MenuItemClass* menuitem, int8_t line) {
  2444. if (HMI_IsChinese()) {
  2445. menuitem->SetFrame(1, 173, 133, 200, 147);
  2446. DWIN_Frame_AreaCopy(1, 28, 149, 69, 161, LBLX + 27, MBASE(line));
  2447. DWIN_Frame_AreaCopy(1, 229, 133, 236, 147, LBLX + 71, MBASE(line)); // X
  2448. }
  2449. onDrawPInt32Menu(menuitem, line);
  2450. }
  2451. void onDrawMaxAccelY(MenuItemClass* menuitem, int8_t line) {
  2452. if (HMI_IsChinese()) {
  2453. menuitem->SetFrame(1, 173, 133, 200, 147);
  2454. DWIN_Frame_AreaCopy(1, 28, 149, 69, 161, LBLX + 27, MBASE(line));
  2455. DWIN_Frame_AreaCopy(1, 1, 150, 7, 160, LBLX + 71, MBASE(line)); // Y
  2456. }
  2457. onDrawPInt32Menu(menuitem, line);
  2458. }
  2459. void onDrawMaxAccelZ(MenuItemClass* menuitem, int8_t line) {
  2460. if (HMI_IsChinese()) {
  2461. menuitem->SetFrame(1, 173, 133, 200, 147);
  2462. DWIN_Frame_AreaCopy(1, 28, 149, 69, 161, LBLX + 27, MBASE(line));
  2463. DWIN_Frame_AreaCopy(1, 9, 150, 16, 160, LBLX + 71, MBASE(line)); // Z
  2464. }
  2465. onDrawPInt32Menu(menuitem, line);
  2466. }
  2467. #if HAS_HOTEND
  2468. void onDrawMaxAccelE(MenuItemClass* menuitem, int8_t line) {
  2469. if (HMI_IsChinese()) {
  2470. menuitem->SetFrame(1, 173, 133, 200, 147);
  2471. DWIN_Frame_AreaCopy(1, 28, 149, 69, 161, LBLX + 27, MBASE(line));
  2472. DWIN_Frame_AreaCopy(1, 18, 150, 25, 160, LBLX + 71, MBASE(line)); // E
  2473. }
  2474. onDrawPInt32Menu(menuitem, line);
  2475. }
  2476. #endif
  2477. #if HAS_CLASSIC_JERK
  2478. void onDrawJerk(MenuItemClass* menuitem, int8_t line) {
  2479. if (HMI_IsChinese()) {
  2480. menuitem->SetFrame(1, 173, 133, 200, 147);
  2481. DWIN_Frame_AreaCopy(1, 1, 180, 28, 192, LBLX + 27, MBASE(line) + 1); // ...
  2482. DWIN_Frame_AreaCopy(1, 202, 133, 228, 147, LBLX + 54, MBASE(line)); // ...Jerk
  2483. }
  2484. onDrawSubMenu(menuitem, line);
  2485. }
  2486. void onDrawMaxJerkX(MenuItemClass* menuitem, int8_t line) {
  2487. if (HMI_IsChinese()) {
  2488. menuitem->SetFrame(1, 173, 133, 200, 147);
  2489. DWIN_Frame_AreaCopy(1, 1, 180, 28, 192, LBLX + 27, MBASE(line));
  2490. DWIN_Frame_AreaCopy(1, 202, 133, 228, 147, LBLX + 53, MBASE(line));
  2491. DWIN_Frame_AreaCopy(1, 229, 133, 236, 147, LBLX + 83, MBASE(line));
  2492. }
  2493. onDrawPFloatMenu(menuitem, line);
  2494. }
  2495. void onDrawMaxJerkY(MenuItemClass* menuitem, int8_t line) {
  2496. if (HMI_IsChinese()) {
  2497. menuitem->SetFrame(1, 173, 133, 200, 147);
  2498. DWIN_Frame_AreaCopy(1, 1, 180, 28, 192, LBLX + 27, MBASE(line));
  2499. DWIN_Frame_AreaCopy(1, 202, 133, 228, 147, LBLX + 53, MBASE(line));
  2500. DWIN_Frame_AreaCopy(1, 1, 150, 7, 160, LBLX + 83, MBASE(line));
  2501. }
  2502. onDrawPFloatMenu(menuitem, line);
  2503. }
  2504. void onDrawMaxJerkZ(MenuItemClass* menuitem, int8_t line) {
  2505. if (HMI_IsChinese()) {
  2506. menuitem->SetFrame(1, 173, 133, 200, 147);
  2507. DWIN_Frame_AreaCopy(1, 1, 180, 28, 192, LBLX + 27, MBASE(line));
  2508. DWIN_Frame_AreaCopy(1, 202, 133, 228, 147, LBLX + 53, MBASE(line));
  2509. DWIN_Frame_AreaCopy(1, 9, 150, 16, 160, LBLX + 83, MBASE(line));
  2510. }
  2511. onDrawPFloatMenu(menuitem, line);
  2512. }
  2513. #if HAS_HOTEND
  2514. void onDrawMaxJerkE(MenuItemClass* menuitem, int8_t line) {
  2515. if (HMI_IsChinese()) {
  2516. menuitem->SetFrame(1, 173, 133, 200, 147);
  2517. DWIN_Frame_AreaCopy(1, 1, 180, 28, 192, LBLX + 27, MBASE(line));
  2518. DWIN_Frame_AreaCopy(1, 202, 133, 228, 147, LBLX + 53, MBASE(line));
  2519. DWIN_Frame_AreaCopy(1, 18, 150, 25, 160, LBLX + 83, MBASE(line));
  2520. }
  2521. onDrawPFloatMenu(menuitem, line);
  2522. }
  2523. #endif
  2524. #endif // HAS_CLASSIC_JERK
  2525. void onDrawStepsX(MenuItemClass* menuitem, int8_t line) {
  2526. if (HMI_IsChinese()) {
  2527. menuitem->SetFrame(1, 153, 148, 194, 161);
  2528. DWIN_Frame_AreaCopy(1, 229, 133, 236, 147, LBLX + 44, MBASE(line)); // X
  2529. }
  2530. onDrawPFloatMenu(menuitem, line);
  2531. }
  2532. void onDrawStepsY(MenuItemClass* menuitem, int8_t line) {
  2533. if (HMI_IsChinese()) {
  2534. menuitem->SetFrame(1, 153, 148, 194, 161);
  2535. DWIN_Frame_AreaCopy(1, 1, 150, 7, 160, LBLX + 44, MBASE(line)); // Y
  2536. }
  2537. onDrawPFloatMenu(menuitem, line);
  2538. }
  2539. void onDrawStepsZ(MenuItemClass* menuitem, int8_t line) {
  2540. if (HMI_IsChinese()) {
  2541. menuitem->SetFrame(1, 153, 148, 194, 161);
  2542. DWIN_Frame_AreaCopy(1, 9, 150, 16, 160, LBLX + 44, MBASE(line)); // Z
  2543. }
  2544. onDrawPFloatMenu(menuitem, line);
  2545. }
  2546. #if HAS_HOTEND
  2547. void onDrawStepsE(MenuItemClass* menuitem, int8_t line) {
  2548. if (HMI_IsChinese()) {
  2549. menuitem->SetFrame(1, 153, 148, 194, 161);
  2550. DWIN_Frame_AreaCopy(1, 18, 150, 25, 160, LBLX + 44, MBASE(line)); // E
  2551. }
  2552. onDrawPFloatMenu(menuitem, line);
  2553. }
  2554. #endif
  2555. // HMI Control functions ======================================================
  2556. // Generic menu control using the encoder
  2557. void HMI_Menu() {
  2558. EncoderState encoder_diffState = get_encoder_state();
  2559. if (encoder_diffState == ENCODER_DIFF_NO) return;
  2560. if (encoder_diffState == ENCODER_DIFF_ENTER) {
  2561. if (CurrentMenu != nullptr) CurrentMenu->onClick();
  2562. } else if (CurrentMenu != nullptr) CurrentMenu->onScroll(encoder_diffState == ENCODER_DIFF_CW);
  2563. }
  2564. // Get an integer value using the encoder without draw anything
  2565. // lo: low limit
  2566. // hi: high limit
  2567. // Return value:
  2568. // 0 : no change
  2569. // 1 : live change
  2570. // 2 : apply change
  2571. int8_t HMI_GetIntNoDraw(const int32_t lo, const int32_t hi) {
  2572. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  2573. if (encoder_diffState != ENCODER_DIFF_NO) {
  2574. if (Apply_Encoder(encoder_diffState, HMI_value.Value)) {
  2575. EncoderRate.enabled = false;
  2576. checkkey = Menu;
  2577. return 2;
  2578. }
  2579. LIMIT(HMI_value.Value, lo, hi);
  2580. return 1;
  2581. }
  2582. return 0;
  2583. }
  2584. // Get an integer value using the encoder
  2585. // lo: low limit
  2586. // hi: high limit
  2587. // Return value:
  2588. // 0 : no change
  2589. // 1 : live change
  2590. // 2 : apply change
  2591. int8_t HMI_GetInt(const int32_t lo, const int32_t hi) {
  2592. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  2593. if (encoder_diffState != ENCODER_DIFF_NO) {
  2594. if (Apply_Encoder(encoder_diffState, HMI_value.Value)) {
  2595. EncoderRate.enabled = false;
  2596. DWINUI::Draw_Int(HMI_data.Text_Color, HMI_data.Background_Color, 4 , VALX, MBASE(CurrentMenu->line()) - 1, HMI_value.Value);
  2597. checkkey = Menu;
  2598. return 2;
  2599. }
  2600. LIMIT(HMI_value.Value, lo, hi);
  2601. DWINUI::Draw_Int(HMI_data.Text_Color, HMI_data.Selected_Color, 4 , VALX, MBASE(CurrentMenu->line()) - 1, HMI_value.Value);
  2602. return 1;
  2603. }
  2604. return 0;
  2605. }
  2606. // Set an integer using the encoder
  2607. void HMI_SetInt() {
  2608. int8_t val = HMI_GetInt(HMI_value.MinValue, HMI_value.MaxValue);
  2609. switch (val) {
  2610. case 0: return; break;
  2611. case 1: if (HMI_value.LiveUpdate != nullptr) HMI_value.LiveUpdate(); break;
  2612. case 2: if (HMI_value.Apply != nullptr) HMI_value.Apply(); break;
  2613. }
  2614. }
  2615. // Set an integer without drawing
  2616. void HMI_SetIntNoDraw() {
  2617. int8_t val = HMI_GetIntNoDraw(HMI_value.MinValue, HMI_value.MaxValue);
  2618. switch (val) {
  2619. case 0: return; break;
  2620. case 1: if (HMI_value.LiveUpdate != nullptr) HMI_value.LiveUpdate(); break;
  2621. case 2: if (HMI_value.Apply != nullptr) HMI_value.Apply(); break;
  2622. }
  2623. }
  2624. // Set an integer pointer variable using the encoder
  2625. void HMI_SetPInt() {
  2626. int8_t val = HMI_GetInt(HMI_value.MinValue, HMI_value.MaxValue);
  2627. if (!val) return;
  2628. else if (val == 2) { // Apply
  2629. *HMI_value.P_Int = HMI_value.Value;
  2630. if (HMI_value.Apply != nullptr) HMI_value.Apply();
  2631. } else if (HMI_value.LiveUpdate != nullptr) HMI_value.LiveUpdate();
  2632. }
  2633. // Get a scaled float value using the encoder
  2634. // dp: decimal places
  2635. // lo: scaled low limit
  2636. // hi: scaled high limit
  2637. // Return value:
  2638. // 0 : no change
  2639. // 1 : live change
  2640. // 2 : apply change
  2641. int8_t HMI_GetFloat(uint8_t dp, int32_t lo, int32_t hi) {
  2642. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  2643. if (encoder_diffState != ENCODER_DIFF_NO) {
  2644. if (Apply_Encoder(encoder_diffState, HMI_value.Value)) {
  2645. EncoderRate.enabled = false;
  2646. DWINUI::Draw_Signed_Float(HMI_data.Text_Color, HMI_data.Background_Color, 3, dp, VALX - dp * DWINUI::fontWidth(DWIN_FONT_MENU), MBASE(CurrentMenu->line()), HMI_value.Value / POW(10, dp));
  2647. checkkey = Menu;
  2648. return 2;
  2649. }
  2650. LIMIT(HMI_value.Value, lo, hi);
  2651. DWINUI::Draw_Signed_Float(HMI_data.Text_Color, HMI_data.Selected_Color, 3, dp, VALX - dp * DWINUI::fontWidth(DWIN_FONT_MENU), MBASE(CurrentMenu->line()), HMI_value.Value / POW(10, dp));
  2652. return 1;
  2653. }
  2654. return 0;
  2655. }
  2656. // Set a scaled float using the encoder
  2657. void HMI_SetFloat() {
  2658. const int8_t val = HMI_GetFloat(HMI_value.dp, HMI_value.MinValue, HMI_value.MaxValue);
  2659. switch (val) {
  2660. case 0: return;
  2661. case 1: if (HMI_value.LiveUpdate != nullptr) HMI_value.LiveUpdate(); break;
  2662. case 2: if (HMI_value.Apply != nullptr) HMI_value.Apply(); break;
  2663. }
  2664. }
  2665. // Set a scaled float pointer variable using the encoder
  2666. void HMI_SetPFloat() {
  2667. const int8_t val = HMI_GetFloat(HMI_value.dp, HMI_value.MinValue, HMI_value.MaxValue);
  2668. if (!val) return;
  2669. if (val == 2) { // Apply
  2670. *HMI_value.P_Float = HMI_value.Value / POW(10, HMI_value.dp);
  2671. if (HMI_value.Apply != nullptr) HMI_value.Apply();
  2672. }
  2673. else if (HMI_value.LiveUpdate != nullptr) HMI_value.LiveUpdate();
  2674. }
  2675. // Menu Creation and Drawing functions ======================================================
  2676. void SetMenuTitle(frame_rect_t cn, frame_rect_t en, const __FlashStringHelper* text) {
  2677. if (HMI_IsChinese() && (cn.w != 0))
  2678. CurrentMenu->MenuTitle.SetFrame(cn.x, cn.y, cn.w, cn.h);
  2679. else
  2680. CurrentMenu->MenuTitle.SetCaption(text);
  2681. }
  2682. void Draw_Prepare_Menu() {
  2683. checkkey = Menu;
  2684. if (PrepareMenu == nullptr) PrepareMenu = new MenuClass();
  2685. if (CurrentMenu != PrepareMenu) {
  2686. CurrentMenu = PrepareMenu;
  2687. SetMenuTitle({133, 1, 28, 13}, {179, 0, 48, 14}, GET_TEXT_F(MSG_PREPARE));
  2688. DWINUI::MenuItemsPrepare(13);
  2689. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Goto_Main_Menu);
  2690. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2691. ADDMENUITEM(ICON_FilMan, GET_TEXT_F(MSG_FILAMENT_MAN), onDrawSubMenu, Draw_FilamentMan_Menu);
  2692. #endif
  2693. ADDMENUITEM(ICON_Axis, GET_TEXT_F(MSG_MOVE_AXIS), onDrawMoveSubMenu, Draw_Move_Menu);
  2694. ADDMENUITEM(ICON_LevBed, GET_TEXT_F(MSG_BED_LEVELING), onDrawSubMenu, Draw_LevBedCorners_Menu);
  2695. ADDMENUITEM(ICON_CloseMotor, GET_TEXT_F(MSG_DISABLE_STEPPERS), onDrawDisableMotors, DisableMotors);
  2696. ADDMENUITEM(ICON_Homing, GET_TEXT_F(MSG_AUTO_HOME), onDrawAutoHome, AutoHome);
  2697. #if ENABLED(MESH_BED_LEVELING)
  2698. ADDMENUITEM(ICON_ManualMesh, GET_TEXT_F(MSG_MANUAL_MESH), onDrawSubMenu, Draw_ManualMesh_Menu);
  2699. #endif
  2700. #if HAS_ZOFFSET_ITEM
  2701. #if EITHER(HAS_BED_PROBE, BABYSTEPPING)
  2702. ADDMENUITEM(ICON_SetZOffset, GET_TEXT_F(MSG_PROBE_WIZARD), onDrawSubMenu, Draw_ZOffsetWiz_Menu);
  2703. #else
  2704. ADDMENUITEM(ICON_SetHome, GET_TEXT_F(MSG_SET_HOME_OFFSETS), onDrawHomeOffset, SetHome);
  2705. #endif
  2706. #endif
  2707. #if HAS_HOTEND
  2708. ADDMENUITEM(ICON_PLAPreheat, GET_TEXT_F(MSG_PREHEAT_1), onDrawPreheat1, SetPreheat0);
  2709. ADDMENUITEM(ICON_ABSPreheat, PSTR("Preheat " PREHEAT_2_LABEL), onDrawPreheat2, SetPreheat1);
  2710. ADDMENUITEM(ICON_CustomPreheat, GET_TEXT_F(MSG_PREHEAT_CUSTOM), onDrawMenuItem, SetPreheat2);
  2711. #endif
  2712. #if HAS_PREHEAT
  2713. ADDMENUITEM(ICON_Cool, GET_TEXT_F(MSG_COOLDOWN), onDrawCooldown, SetCoolDown);
  2714. #endif
  2715. ADDMENUITEM(ICON_Language, PSTR("UI Language"), onDrawLanguage, SetLanguage);
  2716. }
  2717. CurrentMenu->draw();
  2718. }
  2719. void Draw_LevBedCorners_Menu() {
  2720. DWINUI::ClearMenuArea();
  2721. checkkey = Menu;
  2722. if (LevBedMenu == nullptr) LevBedMenu = new MenuClass();
  2723. if (CurrentMenu != LevBedMenu) {
  2724. CurrentMenu = LevBedMenu;
  2725. SetMenuTitle({0}, {0}, GET_TEXT_F(MSG_BED_TRAMMING)); // TODO: Chinese, English "Bed Tramming" JPG
  2726. DWINUI::MenuItemsPrepare(6);
  2727. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Prepare_Menu);
  2728. ADDMENUITEM(ICON_Axis, GET_TEXT_F(MSG_LEVBED_FL), onDrawMenuItem, LevBedFL);
  2729. ADDMENUITEM(ICON_Axis, GET_TEXT_F(MSG_LEVBED_FR), onDrawMenuItem, LevBedFR);
  2730. ADDMENUITEM(ICON_Axis, GET_TEXT_F(MSG_LEVBED_BR), onDrawMenuItem, LevBedBR);
  2731. ADDMENUITEM(ICON_Axis, GET_TEXT_F(MSG_LEVBED_BL), onDrawMenuItem, LevBedBL);
  2732. ADDMENUITEM(ICON_Axis, GET_TEXT_F(MSG_LEVBED_C ), onDrawMenuItem, LevBedC );
  2733. }
  2734. CurrentMenu->draw();
  2735. }
  2736. void Draw_Control_Menu() {
  2737. checkkey = Menu;
  2738. if (ControlMenu == nullptr) ControlMenu = new MenuClass();
  2739. if (CurrentMenu != ControlMenu) {
  2740. CurrentMenu = ControlMenu;
  2741. SetMenuTitle({103, 1, 28, 14}, {128, 2, 49, 11}, GET_TEXT_F(MSG_CONTROL));
  2742. DWINUI::MenuItemsPrepare(9);
  2743. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Goto_Main_Menu);
  2744. ADDMENUITEM(ICON_Temperature, GET_TEXT_F(MSG_TEMPERATURE), onDrawTempSubMenu, Draw_Temperature_Menu);
  2745. ADDMENUITEM(ICON_Motion, GET_TEXT_F(MSG_MOTION), onDrawMotionSubMenu, Draw_Motion_Menu);
  2746. #if ENABLED(EEPROM_SETTINGS)
  2747. ADDMENUITEM(ICON_WriteEEPROM, GET_TEXT_F(MSG_STORE_EEPROM), onDrawWriteEeprom, WriteEeprom);
  2748. ADDMENUITEM(ICON_ReadEEPROM, GET_TEXT_F(MSG_LOAD_EEPROM), onDrawReadEeprom, ReadEeprom);
  2749. ADDMENUITEM(ICON_ResumeEEPROM, GET_TEXT_F(MSG_RESTORE_DEFAULTS), onDrawResetEeprom, ResetEeprom);
  2750. #endif
  2751. ADDMENUITEM(ICON_Reboot, GET_TEXT_F(MSG_RESET_PRINTER), onDrawMenuItem, RebootPrinter);
  2752. ADDMENUITEM(ICON_AdvSet, GET_TEXT_F(MSG_ADVANCED_SETTINGS), onDrawSubMenu, Draw_AdvancedSettings_Menu);
  2753. ADDMENUITEM(ICON_Info, GET_TEXT_F(MSG_INFO_SCREEN), onDrawInfoSubMenu, Goto_InfoMenu);
  2754. }
  2755. CurrentMenu->draw();
  2756. }
  2757. void Draw_AdvancedSettings_Menu() {
  2758. checkkey = Menu;
  2759. if (AdvancedSettings == nullptr) AdvancedSettings = new MenuClass();
  2760. if (CurrentMenu != AdvancedSettings) {
  2761. CurrentMenu = AdvancedSettings;
  2762. SetMenuTitle({0}, {0}, GET_TEXT_F(MSG_ADVANCED_SETTINGS)); // TODO: Chinese, English "Advanced Settings" JPG
  2763. DWINUI::MenuItemsPrepare(11);
  2764. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Control_Menu);
  2765. #if HAS_HOME_OFFSET
  2766. ADDMENUITEM(ICON_HomeOffset, GET_TEXT_F(MSG_SET_HOME_OFFSETS), onDrawSubMenu, Draw_HomeOffset_Menu);
  2767. #endif
  2768. #if HAS_BED_PROBE
  2769. ADDMENUITEM(ICON_ProbeSet, GET_TEXT_F(MSG_ZPROBE_SETTINGS), onDrawSubMenu, Draw_ProbeSet_Menu);
  2770. #endif
  2771. #if HAS_HOTEND
  2772. ADDMENUITEM(ICON_PIDNozzle, F("Hotend PID Settings"), onDrawSubMenu, Draw_HotendPID_Menu);
  2773. #endif
  2774. #if HAS_HEATED_BED
  2775. ADDMENUITEM(ICON_PIDbed, F("Bed PID Settings"), onDrawSubMenu, Draw_BedPID_Menu);
  2776. #endif
  2777. #if HAS_FILAMENT_SENSOR
  2778. ADDMENUITEM(ICON_FilSet, GET_TEXT_F(MSG_FILAMENT_SET), onDrawSubMenu, Draw_FilSet_Menu);
  2779. #endif
  2780. #if ENABLED(POWER_LOSS_RECOVERY)
  2781. ADDMENUITEM(ICON_Pwrlossr, GET_TEXT_F(MSG_OUTAGE_RECOVERY), onDrawPwrLossR, SetPwrLossr);
  2782. #endif
  2783. #if HAS_LCD_BRIGHTNESS
  2784. ADDMENUITEM_P(ICON_Brightness, GET_TEXT_F(MSG_BRIGHTNESS), onDrawPInt8Menu, SetBrightness, &ui.brightness);
  2785. #endif
  2786. ADDMENUITEM(ICON_Scolor, F("Select Colors"), onDrawSubMenu, Draw_SelectColors_Menu);
  2787. #if ENABLED(SOUND_MENU_ITEM)
  2788. ADDMENUITEM(ICON_Sound, F("Enable Sound"), onDrawEnableSound, SetEnableSound);
  2789. #endif
  2790. #if HAS_MESH
  2791. ADDMENUITEM(ICON_MeshViewer, GET_TEXT_F(MSG_MESH_VIEW), onDrawSubMenu, DWIN_MeshViewer);
  2792. #endif
  2793. ADDMENUITEM(ICON_Lock, F("Lock Screen"), onDrawMenuItem, Goto_LockScreen);
  2794. }
  2795. CurrentMenu->draw();
  2796. }
  2797. void Draw_Move_Menu() {
  2798. checkkey = Menu;
  2799. if (MoveMenu == nullptr) MoveMenu = new MenuClass();
  2800. if (CurrentMenu != MoveMenu) {
  2801. CurrentMenu = MoveMenu;
  2802. SetMenuTitle({192, 1, 42, 14}, {231, 2, 35, 11}, GET_TEXT_F(MSG_MOVE_AXIS));
  2803. DWINUI::MenuItemsPrepare(5);
  2804. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Prepare_Menu);
  2805. ADDMENUITEM_P(ICON_MoveX, GET_TEXT_F(MSG_MOVE_X), onDrawMoveX, SetMoveX, &current_position.x);
  2806. ADDMENUITEM_P(ICON_MoveY, GET_TEXT_F(MSG_MOVE_Y), onDrawMoveY, SetMoveY, &current_position.y);
  2807. ADDMENUITEM_P(ICON_MoveZ, GET_TEXT_F(MSG_MOVE_Z), onDrawMoveZ, SetMoveZ, &current_position.z);
  2808. #if HAS_HOTEND
  2809. ADDMENUITEM_P(ICON_Extruder, GET_TEXT_F(MSG_MOVE_E), onDrawMoveE, SetMoveE, &current_position.e);
  2810. #endif
  2811. }
  2812. CurrentMenu->draw();
  2813. if (!all_axes_trusted()) ui.set_status_P(PSTR("WARNING: position is unknow"));
  2814. }
  2815. #if HAS_HOME_OFFSET
  2816. void Draw_HomeOffset_Menu() {
  2817. checkkey = Menu;
  2818. if (HomeOffMenu == nullptr) HomeOffMenu = new MenuClass();
  2819. if (CurrentMenu != HomeOffMenu) {
  2820. CurrentMenu = HomeOffMenu;
  2821. SetMenuTitle({0}, {0}, GET_TEXT_F(MSG_SET_HOME_OFFSETS)); // TODO: Chinese, English "Set Home Offsets" JPG
  2822. DWINUI::MenuItemsPrepare(4);
  2823. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_AdvancedSettings_Menu);
  2824. ADDMENUITEM_P(ICON_HomeOffsetX, GET_TEXT_F(MSG_HOME_OFFSET_X), onDrawPFloatMenu, SetHomeOffsetX, &home_offset[X_AXIS]);
  2825. ADDMENUITEM_P(ICON_HomeOffsetY, GET_TEXT_F(MSG_HOME_OFFSET_Y), onDrawPFloatMenu, SetHomeOffsetY, &home_offset[Y_AXIS]);
  2826. ADDMENUITEM_P(ICON_HomeOffsetZ, GET_TEXT_F(MSG_HOME_OFFSET_Z), onDrawPFloatMenu, SetHomeOffsetZ, &home_offset[Z_AXIS]);
  2827. }
  2828. CurrentMenu->draw();
  2829. }
  2830. #endif
  2831. #if HAS_BED_PROBE
  2832. void Draw_ProbeSet_Menu() {
  2833. checkkey = Menu;
  2834. if (ProbeSetMenu == nullptr) ProbeSetMenu = new MenuClass();
  2835. if (CurrentMenu != ProbeSetMenu) {
  2836. CurrentMenu = ProbeSetMenu;
  2837. SetMenuTitle({0}, {0}, GET_TEXT_F(MSG_ZPROBE_SETTINGS)); // TODO: Chinese, English "Probe Settings" JPG
  2838. DWINUI::MenuItemsPrepare(5);
  2839. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_AdvancedSettings_Menu);
  2840. ADDMENUITEM_P(ICON_ProbeOffsetX, GET_TEXT_F(MSG_ZPROBE_XOFFSET), onDrawPFloatMenu, SetProbeOffsetX, &probe.offset.x);
  2841. ADDMENUITEM_P(ICON_ProbeOffsetY, GET_TEXT_F(MSG_ZPROBE_YOFFSET), onDrawPFloatMenu, SetProbeOffsetY, &probe.offset.y);
  2842. ADDMENUITEM_P(ICON_ProbeOffsetZ, GET_TEXT_F(MSG_ZPROBE_ZOFFSET), onDrawPFloat2Menu, SetProbeOffsetZ, &probe.offset.z);
  2843. ADDMENUITEM(ICON_ProbeTest, GET_TEXT_F(MSG_M48_TEST), onDrawMenuItem, ProbeTest);
  2844. }
  2845. CurrentMenu->draw();
  2846. }
  2847. #endif
  2848. #if HAS_FILAMENT_SENSOR
  2849. void Draw_FilSet_Menu() {
  2850. checkkey = Menu;
  2851. if (FilSetMenu == nullptr) FilSetMenu = new MenuClass();
  2852. if (CurrentMenu != FilSetMenu) {
  2853. CurrentMenu = FilSetMenu;
  2854. CurrentMenu->MenuTitle.SetCaption(GET_TEXT_F(MSG_FILAMENT_SET));
  2855. DWINUI::MenuItemsPrepare(6);
  2856. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawMenuItem, Draw_AdvancedSettings_Menu);
  2857. #if HAS_FILAMENT_SENSOR
  2858. ADDMENUITEM(ICON_Runout, GET_TEXT_F(MSG_RUNOUT_ENABLE), onDrawRunoutEnable, SetRunoutEnable);
  2859. #endif
  2860. #if HAS_FILAMENT_RUNOUT_DISTANCE
  2861. ADDMENUITEM_P(ICON_Runout, F("Runout Distance"), onDrawPFloatMenu, SetRunoutDistance, &runout.runout_distance());
  2862. #endif
  2863. #if ENABLED(PREVENT_COLD_EXTRUSION)
  2864. ADDMENUITEM_P(ICON_ExtrudeMinT, F("Extrude Min Temp."), onDrawPIntMenu, SetExtMinT, &HMI_data.ExtMinT);
  2865. #endif
  2866. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2867. ADDMENUITEM_P(ICON_FilLoad, GET_TEXT_F(MSG_FILAMENT_LOAD), onDrawPFloatMenu, SetFilLoad, &fc_settings[0].load_length);
  2868. ADDMENUITEM_P(ICON_FilUnload, GET_TEXT_F(MSG_FILAMENT_UNLOAD), onDrawPFloatMenu, SetFilUnload, &fc_settings[0].unload_length);
  2869. #endif
  2870. }
  2871. CurrentMenu->draw();
  2872. }
  2873. #endif // HAS_FILAMENT_SENSOR
  2874. void Draw_SelectColors_Menu() {
  2875. checkkey = Menu;
  2876. if (SelectColorMenu == nullptr) SelectColorMenu = new MenuClass();
  2877. if (CurrentMenu != SelectColorMenu) {
  2878. CurrentMenu = SelectColorMenu;
  2879. SetMenuTitle({0}, {0}, F("Select Colors")); // TODO: Chinese, English "Select Color" JPG
  2880. DWINUI::MenuItemsPrepare(20);
  2881. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_AdvancedSettings_Menu);
  2882. ADDMENUITEM(ICON_StockConfiguration, GET_TEXT_F(MSG_RESTORE_DEFAULTS), onDrawMenuItem, RestoreDefaultsColors);
  2883. ADDMENUITEM_P(0, "Screen Background", onDrawSelColorItem, SelColor, &HMI_data.Background_Color);
  2884. ADDMENUITEM_P(0, "Cursor", onDrawSelColorItem, SelColor, &HMI_data.Cursor_color);
  2885. ADDMENUITEM_P(0, "Title Background", onDrawSelColorItem, SelColor, &HMI_data.TitleBg_color);
  2886. ADDMENUITEM_P(0, "Title Text", onDrawSelColorItem, SelColor, &HMI_data.TitleTxt_color);
  2887. ADDMENUITEM_P(0, "Text", onDrawSelColorItem, SelColor, &HMI_data.Text_Color);
  2888. ADDMENUITEM_P(0, "Selected", onDrawSelColorItem, SelColor, &HMI_data.Selected_Color);
  2889. ADDMENUITEM_P(0, "Split Line", onDrawSelColorItem, SelColor, &HMI_data.SplitLine_Color);
  2890. ADDMENUITEM_P(0, "Highlight", onDrawSelColorItem, SelColor, &HMI_data.Highlight_Color);
  2891. ADDMENUITEM_P(0, "Status Background", onDrawSelColorItem, SelColor, &HMI_data.StatusBg_Color);
  2892. ADDMENUITEM_P(0, "Status Text", onDrawSelColorItem, SelColor, &HMI_data.StatusTxt_Color);
  2893. ADDMENUITEM_P(0, "Popup Background", onDrawSelColorItem, SelColor, &HMI_data.PopupBg_color);
  2894. ADDMENUITEM_P(0, "Popup Text", onDrawSelColorItem, SelColor, &HMI_data.PopupTxt_Color);
  2895. ADDMENUITEM_P(0, "Alert Background", onDrawSelColorItem, SelColor, &HMI_data.AlertBg_Color);
  2896. ADDMENUITEM_P(0, "Alert Text", onDrawSelColorItem, SelColor, &HMI_data.AlertTxt_Color);
  2897. ADDMENUITEM_P(0, "Percent Text", onDrawSelColorItem, SelColor, &HMI_data.PercentTxt_Color);
  2898. ADDMENUITEM_P(0, "Bar Fill", onDrawSelColorItem, SelColor, &HMI_data.Barfill_Color);
  2899. ADDMENUITEM_P(0, "Indicator value", onDrawSelColorItem, SelColor, &HMI_data.Indicator_Color);
  2900. ADDMENUITEM_P(0, "Coordinate value", onDrawSelColorItem, SelColor, &HMI_data.Coordinate_Color);
  2901. }
  2902. CurrentMenu->draw();
  2903. }
  2904. void Draw_GetColor_Menu() {
  2905. checkkey = Menu;
  2906. if (GetColorMenu == nullptr) GetColorMenu = new MenuClass();
  2907. if (CurrentMenu != GetColorMenu) {
  2908. CurrentMenu = GetColorMenu;
  2909. SetMenuTitle({0}, {0}, F("Get Color")); // TODO: Chinese, English "Get Color" JPG
  2910. DWINUI::MenuItemsPrepare(5);
  2911. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, DWIN_ApplyColor);
  2912. ADDMENUITEM(ICON_Cancel, GET_TEXT_F(MSG_BUTTON_CANCEL), onDrawMenuItem, Draw_SelectColors_Menu);
  2913. ADDMENUITEM(0, "Red", onDrawGetColorItem, SetRGBColor);
  2914. ADDMENUITEM(1, "Green", onDrawGetColorItem, SetRGBColor);
  2915. ADDMENUITEM(2, "Blue", onDrawGetColorItem, SetRGBColor);
  2916. }
  2917. CurrentMenu->draw();
  2918. DWIN_Draw_Rectangle(1, *HMI_value.P_Int, 20, 315, DWIN_WIDTH - 20, 335);
  2919. }
  2920. void Draw_Tune_Menu() {
  2921. checkkey = Menu;
  2922. if (TuneMenu == nullptr) TuneMenu = new MenuClass();
  2923. if (CurrentMenu != TuneMenu) {
  2924. CurrentMenu = TuneMenu;
  2925. SetMenuTitle({73, 2, 28, 12}, {94, 2, 33, 11}, GET_TEXT_F(MSG_TUNE)); // TODO: Chinese, English "Tune" JPG
  2926. DWINUI::MenuItemsPrepare(10);
  2927. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Goto_PrintProcess);
  2928. ADDMENUITEM_P(ICON_Speed, GET_TEXT_F(MSG_SPEED), onDrawSpeedItem, SetSpeed, &feedrate_percentage);
  2929. #if HAS_HOTEND
  2930. HotendTargetItem = ADDMENUITEM_P(ICON_HotendTemp, GET_TEXT_F(MSG_UBL_SET_TEMP_HOTEND), onDrawHotendTemp, SetHotendTemp, &thermalManager.temp_hotend[0].target);
  2931. #endif
  2932. #if HAS_HEATED_BED
  2933. BedTargetItem = ADDMENUITEM_P(ICON_BedTemp, GET_TEXT_F(MSG_UBL_SET_TEMP_BED), onDrawBedTemp, SetBedTemp, &thermalManager.temp_bed.target);
  2934. #endif
  2935. #if HAS_FAN
  2936. FanSpeedItem = ADDMENUITEM_P(ICON_FanSpeed, GET_TEXT_F(MSG_FAN_SPEED), onDrawFanSpeed, SetFanSpeed, &thermalManager.fan_speed[0]);
  2937. #endif
  2938. #if HAS_ZOFFSET_ITEM && EITHER(HAS_BED_PROBE, BABYSTEPPING)
  2939. ADDMENUITEM_P(ICON_Zoffset, GET_TEXT_F(MSG_ZPROBE_ZOFFSET), onDrawZOffset, SetZOffset, &BABY_Z_VAR);
  2940. #endif
  2941. ADDMENUITEM_P(ICON_Flow, GET_TEXT_F(MSG_FLOW), onDrawPIntMenu, SetFlow, &planner.flow_percentage[0]);
  2942. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2943. ADDMENUITEM(ICON_FilMan, GET_TEXT_F(MSG_FILAMENTCHANGE), onDrawMenuItem, ChangeFilament);
  2944. #endif
  2945. ADDMENUITEM(ICON_Lock, F("Lock Screen"), onDrawMenuItem, Goto_LockScreen);
  2946. #if HAS_LCD_BRIGHTNESS
  2947. ADDMENUITEM_P(ICON_Brightness, F("LCD Brightness"), onDrawPInt8Menu, SetBrightness, &ui.brightness);
  2948. #endif
  2949. }
  2950. CurrentMenu->draw();
  2951. }
  2952. void Draw_Motion_Menu() {
  2953. checkkey = Menu;
  2954. if (MotionMenu == nullptr) MotionMenu = new MenuClass();
  2955. if (CurrentMenu != MotionMenu) {
  2956. CurrentMenu = MotionMenu;
  2957. SetMenuTitle({1, 16, 28, 13}, {144, 16, 46, 11}, GET_TEXT_F(MSG_MOTION)); // TODO: Chinese, English "Motion" JPG
  2958. DWINUI::MenuItemsPrepare(6);
  2959. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Control_Menu);
  2960. ADDMENUITEM(ICON_MaxSpeed, GET_TEXT_F(MSG_SPEED), onDrawSpeed, Draw_MaxSpeed_Menu);
  2961. ADDMENUITEM(ICON_MaxAccelerated, GET_TEXT_F(MSG_ACCELERATION), onDrawAcc, Draw_MaxAccel_Menu);
  2962. #if HAS_CLASSIC_JERK
  2963. ADDMENUITEM(ICON_MaxJerk, GET_TEXT_F(MSG_JERK), onDrawJerk, Draw_MaxJerk_Menu);
  2964. #endif
  2965. ADDMENUITEM(ICON_Step, GET_TEXT_F(MSG_STEPS_PER_MM), onDrawSteps, Draw_Steps_Menu);
  2966. ADDMENUITEM_P(ICON_Flow, GET_TEXT_F(MSG_FLOW), onDrawPIntMenu, SetFlow, &planner.flow_percentage[0]);
  2967. }
  2968. CurrentMenu->draw();
  2969. }
  2970. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2971. void Draw_FilamentMan_Menu() {
  2972. checkkey = Menu;
  2973. if (FilamentMenu == nullptr) FilamentMenu = new MenuClass();
  2974. if (CurrentMenu != FilamentMenu) {
  2975. CurrentMenu = FilamentMenu;
  2976. SetMenuTitle({0}, {0}, GET_TEXT_F(MSG_FILAMENT_MAN)); // TODO: Chinese, English "Filament Management" JPG
  2977. DWINUI::MenuItemsPrepare(5);
  2978. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Prepare_Menu);
  2979. ADDMENUITEM(ICON_Park, GET_TEXT_F(MSG_FILAMENT_PARK_ENABLED), onDrawMenuItem, ParkHead);
  2980. ADDMENUITEM(ICON_FilMan, GET_TEXT_F(MSG_FILAMENTCHANGE), onDrawMenuItem, ChangeFilament);
  2981. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  2982. ADDMENUITEM(ICON_FilUnload, GET_TEXT_F(MSG_FILAMENTUNLOAD), onDrawMenuItem, UnloadFilament);
  2983. ADDMENUITEM(ICON_FilLoad, GET_TEXT_F(MSG_FILAMENTLOAD), onDrawMenuItem, LoadFilament);
  2984. #endif
  2985. }
  2986. CurrentMenu->draw();
  2987. }
  2988. #endif
  2989. #if ENABLED(MESH_BED_LEVELING)
  2990. void Draw_ManualMesh_Menu() {
  2991. checkkey = Menu;
  2992. if (ManualMesh == nullptr) ManualMesh = new MenuClass();
  2993. if (CurrentMenu != ManualMesh) {
  2994. CurrentMenu = ManualMesh;
  2995. SetMenuTitle({0}, {0}, GET_TEXT_F(MSG_MANUAL_MESH)); // TODO: Chinese, English "Manual Mesh Leveling" JPG
  2996. DWINUI::MenuItemsPrepare(5);
  2997. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Prepare_Menu);
  2998. ADDMENUITEM(ICON_ManualMesh, GET_TEXT_F(MSG_LEVEL_BED), onDrawMenuItem, ManualMeshStart);
  2999. MMeshMoveZItem = ADDMENUITEM_P(ICON_Zoffset, GET_TEXT_F(MSG_MOVE_Z), onDrawMMeshMoveZ, SetMMeshMoveZ, &current_position.z);
  3000. ADDMENUITEM(ICON_Axis, GET_TEXT_F(MSG_UBL_CONTINUE_MESH), onDrawMenuItem, ManualMeshContinue);
  3001. ADDMENUITEM(ICON_MeshViewer, GET_TEXT_F(MSG_MESH_VIEW), onDrawSubMenu, DWIN_MeshViewer);
  3002. ADDMENUITEM(ICON_MeshSave, GET_TEXT_F(MSG_UBL_SAVE_MESH), onDrawMenuItem, ManualMeshSave);
  3003. }
  3004. CurrentMenu->draw();
  3005. }
  3006. #endif
  3007. #if HAS_PREHEAT
  3008. void Draw_Preheat_Menu(frame_rect_t cn, frame_rect_t en, const __FlashStringHelper* text) {
  3009. checkkey = Menu;
  3010. if (CurrentMenu != PreheatMenu) {
  3011. CurrentMenu = PreheatMenu;
  3012. SetMenuTitle(cn, en, text);
  3013. DWINUI::MenuItemsPrepare(5);
  3014. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Temperature_Menu);
  3015. #if HAS_HOTEND
  3016. ADDMENUITEM_P(ICON_SetEndTemp, GET_TEXT_F(MSG_UBL_SET_TEMP_HOTEND), onDrawSetPreheatHotend, SetPreheatEndTemp, &ui.material_preset[HMI_value.Preheat].hotend_temp);
  3017. #endif
  3018. #if HAS_HEATED_BED
  3019. ADDMENUITEM_P(ICON_SetBedTemp, GET_TEXT_F(MSG_UBL_SET_TEMP_BED), onDrawSetPreheatBed, SetPreheatBedTemp, &ui.material_preset[HMI_value.Preheat].bed_temp);
  3020. #endif
  3021. #if HAS_FAN
  3022. ADDMENUITEM_P(ICON_FanSpeed, GET_TEXT_F(MSG_FAN_SPEED), onDrawSetPreheatFan, SetPreheatFanSpeed, &ui.material_preset[HMI_value.Preheat].fan_speed);
  3023. #endif
  3024. #if ENABLED(EEPROM_SETTINGS)
  3025. ADDMENUITEM(ICON_WriteEEPROM, GET_TEXT_F(MSG_STORE_EEPROM), onDrawWriteEeprom, WriteEeprom);
  3026. #endif
  3027. }
  3028. CurrentMenu->draw();
  3029. }
  3030. void Draw_Preheat1_Menu() {
  3031. HMI_value.Preheat = 0;
  3032. if (PreheatMenu == nullptr) PreheatMenu = new MenuClass();
  3033. Draw_Preheat_Menu({59, 16, 81, 14}, {56, 15, 85, 14}, F(PREHEAT_1_LABEL " Preheat Settings")); // TODO: English "PLA Settings" JPG
  3034. }
  3035. void Draw_Preheat2_Menu() {
  3036. HMI_value.Preheat = 1;
  3037. if (PreheatMenu == nullptr) PreheatMenu = new MenuClass();
  3038. Draw_Preheat_Menu({142, 16, 82, 14}, {56, 15, 85, 14}, F(PREHEAT_2_LABEL " Preheat Settings")); // TODO: English "ABS Settings" JPG
  3039. }
  3040. #ifdef PREHEAT_3_LABEL
  3041. void Draw_Preheat3_Menu() {
  3042. HMI_value.Preheat = 2;
  3043. if (PreheatMenu == nullptr) PreheatMenu = new MenuClass();
  3044. #define PREHEAT_3_TITLE PREHEAT_3_LABEL " Preheat Set."
  3045. Draw_Preheat_Menu({0}, {0}, F(PREHEAT_3_TITLE)); // TODO: Chinese, English "Custom Preheat Settings" JPG
  3046. }
  3047. #endif
  3048. #endif // HAS_PREHEAT
  3049. void Draw_Temperature_Menu() {
  3050. checkkey = Menu;
  3051. if (TemperatureMenu == nullptr) TemperatureMenu = new MenuClass();
  3052. if (CurrentMenu != TemperatureMenu) {
  3053. CurrentMenu = TemperatureMenu;
  3054. SetMenuTitle({236, 2, 28, 12}, {56, 15, 85, 14}, GET_TEXT_F(MSG_TEMPERATURE));
  3055. DWINUI::MenuItemsPrepare(7);
  3056. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Control_Menu);
  3057. #if HAS_HOTEND
  3058. HotendTargetItem = ADDMENUITEM_P(ICON_SetEndTemp, GET_TEXT_F(MSG_UBL_SET_TEMP_HOTEND), onDrawHotendTemp, SetHotendTemp, &thermalManager.temp_hotend[0].target);
  3059. #endif
  3060. #if HAS_HEATED_BED
  3061. BedTargetItem = ADDMENUITEM_P(ICON_SetBedTemp, GET_TEXT_F(MSG_UBL_SET_TEMP_BED), onDrawBedTemp, SetBedTemp, &thermalManager.temp_bed.target);
  3062. #endif
  3063. #if HAS_FAN
  3064. FanSpeedItem = ADDMENUITEM_P(ICON_FanSpeed, GET_TEXT_F(MSG_FAN_SPEED), onDrawFanSpeed, SetFanSpeed, &thermalManager.fan_speed[0]);
  3065. #endif
  3066. #if HAS_HOTEND
  3067. ADDMENUITEM(ICON_SetPLAPreheat, F(PREHEAT_1_LABEL " Preheat Settings"), onDrawPLAPreheatSubMenu, Draw_Preheat1_Menu);
  3068. ADDMENUITEM(ICON_SetABSPreheat, F(PREHEAT_2_LABEL " Preheat Settings"), onDrawABSPreheatSubMenu, Draw_Preheat2_Menu);
  3069. #ifdef PREHEAT_3_LABEL
  3070. ADDMENUITEM(ICON_SetCustomPreheat, PREHEAT_3_TITLE, onDrawSubMenu, Draw_Preheat3_Menu);
  3071. #endif
  3072. #endif
  3073. }
  3074. CurrentMenu->draw();
  3075. }
  3076. void Draw_MaxSpeed_Menu() {
  3077. checkkey = Menu;
  3078. if (MaxSpeedMenu == nullptr) MaxSpeedMenu = new MenuClass();
  3079. if (CurrentMenu != MaxSpeedMenu) {
  3080. CurrentMenu = MaxSpeedMenu;
  3081. SetMenuTitle({1, 16, 28, 13}, {144, 16, 46, 11}, GET_TEXT_F(MSG_MAXSPEED));
  3082. DWINUI::MenuItemsPrepare(5);
  3083. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Motion_Menu);
  3084. ADDMENUITEM_P(ICON_MaxSpeedX, GET_TEXT_F(MSG_MAXSPEED_X), onDrawMaxSpeedX, SetMaxSpeedX, &planner.settings.max_feedrate_mm_s[X_AXIS]);
  3085. ADDMENUITEM_P(ICON_MaxSpeedY, GET_TEXT_F(MSG_MAXSPEED_Y), onDrawMaxSpeedY, SetMaxSpeedY, &planner.settings.max_feedrate_mm_s[Y_AXIS]);
  3086. ADDMENUITEM_P(ICON_MaxSpeedZ, GET_TEXT_F(MSG_MAXSPEED_Z), onDrawMaxSpeedZ, SetMaxSpeedZ, &planner.settings.max_feedrate_mm_s[Z_AXIS]);
  3087. #if HAS_HOTEND
  3088. ADDMENUITEM_P(ICON_MaxSpeedE, GET_TEXT_F(MSG_MAXSPEED_E), onDrawMaxSpeedE, SetMaxSpeedE, &planner.settings.max_feedrate_mm_s[Z_AXIS]);
  3089. #endif
  3090. }
  3091. CurrentMenu->draw();
  3092. }
  3093. void Draw_MaxAccel_Menu() {
  3094. checkkey = Menu;
  3095. if (MaxAccelMenu == nullptr) MaxAccelMenu = new MenuClass();
  3096. if (CurrentMenu != MaxAccelMenu) {
  3097. CurrentMenu = MaxAccelMenu;
  3098. SetMenuTitle({1, 16, 28, 13}, {144, 16, 46, 11}, GET_TEXT_F(MSG_ACCELERATION));
  3099. DWINUI::MenuItemsPrepare(5);
  3100. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Motion_Menu);
  3101. ADDMENUITEM_P(ICON_MaxAccX, GET_TEXT_F(MSG_AMAX_A), onDrawMaxAccelX, SetMaxAccelX, &planner.settings.max_acceleration_mm_per_s2[X_AXIS]);
  3102. ADDMENUITEM_P(ICON_MaxAccY, GET_TEXT_F(MSG_AMAX_B), onDrawMaxAccelY, SetMaxAccelY, &planner.settings.max_acceleration_mm_per_s2[Y_AXIS]);
  3103. ADDMENUITEM_P(ICON_MaxAccZ, GET_TEXT_F(MSG_AMAX_C), onDrawMaxAccelZ, SetMaxAccelZ, &planner.settings.max_acceleration_mm_per_s2[Z_AXIS]);
  3104. #if HAS_HOTEND
  3105. ADDMENUITEM_P(ICON_MaxAccE, GET_TEXT_F(MSG_AMAX_E), onDrawMaxAccelE, SetMaxAccelE, &planner.settings.max_acceleration_mm_per_s2[E_AXIS]);
  3106. #endif
  3107. }
  3108. CurrentMenu->draw();
  3109. }
  3110. #if HAS_CLASSIC_JERK
  3111. void Draw_MaxJerk_Menu() {
  3112. checkkey = Menu;
  3113. if (MaxJerkMenu == nullptr) MaxJerkMenu = new MenuClass();
  3114. if (CurrentMenu != MaxJerkMenu) {
  3115. CurrentMenu = MaxJerkMenu;
  3116. SetMenuTitle({1, 16, 28, 13}, {144, 16, 46, 11}, GET_TEXT_F(MSG_JERK));
  3117. DWINUI::MenuItemsPrepare(5);
  3118. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Motion_Menu);
  3119. ADDMENUITEM_P(ICON_MaxSpeedJerkX, GET_TEXT_F(MSG_VA_JERK), onDrawMaxJerkX, SetMaxJerkX, &planner.max_jerk[X_AXIS]);
  3120. ADDMENUITEM_P(ICON_MaxSpeedJerkY, GET_TEXT_F(MSG_VB_JERK), onDrawMaxJerkY, SetMaxJerkY, &planner.max_jerk[Y_AXIS]);
  3121. ADDMENUITEM_P(ICON_MaxSpeedJerkZ, GET_TEXT_F(MSG_VC_JERK), onDrawMaxJerkZ, SetMaxJerkZ, &planner.max_jerk[Z_AXIS]);
  3122. #if HAS_HOTEND
  3123. ADDMENUITEM_P(ICON_MaxSpeedJerkE, GET_TEXT_F(MSG_VE_JERK), onDrawMaxJerkE, SetMaxJerkE, &planner.max_jerk[E_AXIS]);
  3124. #endif
  3125. }
  3126. CurrentMenu->draw();
  3127. }
  3128. #endif
  3129. void Draw_Steps_Menu() {
  3130. checkkey = Menu;
  3131. if (StepsMenu == nullptr) StepsMenu = new MenuClass();
  3132. if (CurrentMenu != StepsMenu) {
  3133. CurrentMenu = StepsMenu;
  3134. SetMenuTitle({1, 16, 28, 13}, {144, 16, 46, 11}, GET_TEXT_F(MSG_STEPS_PER_MM));
  3135. DWINUI::MenuItemsPrepare(5);
  3136. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawBack, Draw_Motion_Menu);
  3137. ADDMENUITEM_P(ICON_StepX, GET_TEXT_F(MSG_A_STEPS), onDrawStepsX, SetStepsX, &planner.settings.axis_steps_per_mm[X_AXIS]);
  3138. ADDMENUITEM_P(ICON_StepY, GET_TEXT_F(MSG_B_STEPS), onDrawStepsY, SetStepsY, &planner.settings.axis_steps_per_mm[Y_AXIS]);
  3139. ADDMENUITEM_P(ICON_StepZ, GET_TEXT_F(MSG_C_STEPS), onDrawStepsZ, SetStepsZ, &planner.settings.axis_steps_per_mm[Z_AXIS]);
  3140. #if HAS_HOTEND
  3141. ADDMENUITEM_P(ICON_StepE, GET_TEXT_F(MSG_E_STEPS), onDrawStepsE, SetStepsE, &planner.settings.axis_steps_per_mm[E_AXIS]);
  3142. #endif
  3143. }
  3144. CurrentMenu->draw();
  3145. }
  3146. #if HAS_HOTEND
  3147. void Draw_HotendPID_Menu() {
  3148. checkkey = Menu;
  3149. if (HotendPIDMenu == nullptr) HotendPIDMenu = new MenuClass();
  3150. if (CurrentMenu != HotendPIDMenu) {
  3151. CurrentMenu = HotendPIDMenu;
  3152. CurrentMenu->MenuTitle.SetCaption(F("Hotend PID Settings"));
  3153. DWINUI::MenuItemsPrepare(8);
  3154. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawMenuItem, Draw_AdvancedSettings_Menu);
  3155. ADDMENUITEM(ICON_PIDNozzle, F("Hotend PID"), onDrawMenuItem, HotendPID);
  3156. ADDMENUITEM_P(ICON_PIDValue, F("Set" STR_KP), onDrawPFloat2Menu, SetKp, &thermalManager.temp_hotend[0].pid.Kp);
  3157. ADDMENUITEM_P(ICON_PIDValue, F("Set" STR_KI), onDrawPIDi, SetKi, &thermalManager.temp_hotend[0].pid.Ki);
  3158. ADDMENUITEM_P(ICON_PIDValue, F("Set" STR_KD), onDrawPIDd, SetKd, &thermalManager.temp_hotend[0].pid.Kd);
  3159. ADDMENUITEM_P(ICON_Temperature, GET_TEXT_F(MSG_TEMPERATURE), onDrawPIntMenu, SetHotendPidT, &HMI_data.HotendPidT);
  3160. ADDMENUITEM_P(ICON_PIDcycles, GET_TEXT_F(MSG_PID_CYCLE), onDrawPIntMenu, SetPidCycles, &HMI_data.PidCycles);
  3161. #if ENABLED(EEPROM_SETTINGS)
  3162. ADDMENUITEM(ICON_WriteEEPROM, GET_TEXT_F(MSG_STORE_EEPROM), onDrawMenuItem, WriteEeprom);
  3163. #endif
  3164. }
  3165. CurrentMenu->draw();
  3166. }
  3167. #endif
  3168. #if HAS_HEATED_BED
  3169. void Draw_BedPID_Menu() {
  3170. checkkey = Menu;
  3171. if (BedPIDMenu == nullptr) BedPIDMenu = new MenuClass();
  3172. if (CurrentMenu != BedPIDMenu) {
  3173. CurrentMenu = BedPIDMenu;
  3174. CurrentMenu->MenuTitle.SetCaption(F("Bed PID Settings"));
  3175. DWINUI::MenuItemsPrepare(8);
  3176. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawMenuItem, Draw_AdvancedSettings_Menu);
  3177. ADDMENUITEM(ICON_PIDNozzle, F("Bed PID"), onDrawMenuItem,BedPID);
  3178. ADDMENUITEM_P(ICON_PIDValue, F("Set" STR_KP), onDrawPFloat2Menu, SetKp, &thermalManager.temp_bed.pid.Kp);
  3179. ADDMENUITEM_P(ICON_PIDValue, F("Set" STR_KI), onDrawPIDi, SetKi, &thermalManager.temp_bed.pid.Ki);
  3180. ADDMENUITEM_P(ICON_PIDValue, F("Set" STR_KD), onDrawPIDd, SetKd, &thermalManager.temp_bed.pid.Kd);
  3181. ADDMENUITEM_P(ICON_Temperature, GET_TEXT_F(MSG_TEMPERATURE), onDrawPIntMenu, SetBedPidT, &HMI_data.BedPidT);
  3182. ADDMENUITEM_P(ICON_PIDcycles, GET_TEXT_F(MSG_PID_CYCLE), onDrawPIntMenu, SetPidCycles, &HMI_data.PidCycles);
  3183. #if ENABLED(EEPROM_SETTINGS)
  3184. ADDMENUITEM(ICON_WriteEEPROM, GET_TEXT_F(MSG_STORE_EEPROM), onDrawMenuItem, WriteEeprom);
  3185. #endif
  3186. }
  3187. CurrentMenu->draw();
  3188. }
  3189. #endif
  3190. #if EITHER(HAS_BED_PROBE, BABYSTEPPING)
  3191. void Draw_ZOffsetWiz_Menu() {
  3192. checkkey = Menu;
  3193. if (ZOffsetWizMenu == nullptr) ZOffsetWizMenu = new MenuClass();
  3194. if (CurrentMenu != ZOffsetWizMenu) {
  3195. CurrentMenu = ZOffsetWizMenu;
  3196. CurrentMenu->MenuTitle.SetCaption(GET_TEXT_F(MSG_PROBE_WIZARD));
  3197. DWINUI::MenuItemsPrepare(4);
  3198. ADDMENUITEM(ICON_Back, GET_TEXT_F(MSG_BUTTON_BACK), onDrawMenuItem, Draw_Prepare_Menu);
  3199. ADDMENUITEM(ICON_Homing, GET_TEXT_F(MSG_AUTO_HOME), onDrawMenuItem, AutoHome);
  3200. ADDMENUITEM(ICON_MoveZ0, F("Move Z to Home"), onDrawMenuItem, SetMoveZto0);
  3201. ADDMENUITEM_P(ICON_Zoffset, GET_TEXT_F(MSG_ZPROBE_ZOFFSET), onDrawPFloat2Menu, SetZOffset, &BABY_Z_VAR);
  3202. }
  3203. CurrentMenu->draw();
  3204. if (!axis_is_trusted(Z_AXIS)) ui.set_status_P(PSTR("WARNING: Z position is unknow, move Z to home"));
  3205. }
  3206. #endif
  3207. #endif // DWIN_CREALITY_LCD_ENHANCED