My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dwin.cpp 130KB

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