My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dwin.cpp 176KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683
  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. * lcd/e3v2/jyersui/dwin.cpp
  24. */
  25. #include "../../../inc/MarlinConfigPre.h"
  26. #if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
  27. #include "dwin.h"
  28. #include "../../marlinui.h"
  29. #include "../../../MarlinCore.h"
  30. #include "../../../gcode/gcode.h"
  31. #include "../../../module/temperature.h"
  32. #include "../../../module/planner.h"
  33. #include "../../../module/settings.h"
  34. #include "../../../libs/buzzer.h"
  35. #include "../../../inc/Conditionals_post.h"
  36. //#define DEBUG_OUT 1
  37. #include "../../../core/debug_out.h"
  38. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  39. #include "../../../feature/pause.h"
  40. #endif
  41. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  42. #include "../../../feature/runout.h"
  43. #endif
  44. #if ENABLED(HOST_ACTION_COMMANDS)
  45. #include "../../../feature/host_actions.h"
  46. #endif
  47. #if ANY(BABYSTEPPING, HAS_BED_PROBE, HAS_WORKSPACE_OFFSET)
  48. #define HAS_ZOFFSET_ITEM 1
  49. #endif
  50. #ifndef strcasecmp_P
  51. #define strcasecmp_P(a, b) strcasecmp((a), (b))
  52. #endif
  53. #if HAS_LEVELING
  54. #include "../../../feature/bedlevel/bedlevel.h"
  55. #endif
  56. #if ENABLED(AUTO_BED_LEVELING_UBL)
  57. #include "../../../libs/least_squares_fit.h"
  58. #include "../../../libs/vector_3.h"
  59. #endif
  60. #if HAS_BED_PROBE
  61. #include "../../../module/probe.h"
  62. #endif
  63. #if ENABLED(POWER_LOSS_RECOVERY)
  64. #include "../../../feature/powerloss.h"
  65. #endif
  66. #define MACHINE_SIZE STRINGIFY(X_BED_SIZE) "x" STRINGIFY(Y_BED_SIZE) "x" STRINGIFY(Z_MAX_POS)
  67. #define DWIN_FONT_MENU font8x16
  68. #define DWIN_FONT_STAT font10x20
  69. #define DWIN_FONT_HEAD font10x20
  70. #define MENU_CHAR_LIMIT 24
  71. #define STATUS_Y 352
  72. #define MAX_PRINT_SPEED 500
  73. #define MIN_PRINT_SPEED 10
  74. #if HAS_FAN
  75. #define MAX_FAN_SPEED 255
  76. #define MIN_FAN_SPEED 0
  77. #endif
  78. #define MAX_XY_OFFSET 100
  79. #if HAS_ZOFFSET_ITEM
  80. #define MAX_Z_OFFSET 9.99
  81. #if HAS_BED_PROBE
  82. #define MIN_Z_OFFSET -9.99
  83. #else
  84. #define MIN_Z_OFFSET -1
  85. #endif
  86. #endif
  87. #if HAS_HOTEND
  88. #define MAX_FLOW_RATE 200
  89. #define MIN_FLOW_RATE 10
  90. #define MAX_E_TEMP (HEATER_0_MAXTEMP - HOTEND_OVERSHOOT)
  91. #define MIN_E_TEMP 0
  92. #endif
  93. #if HAS_HEATED_BED
  94. #define MAX_BED_TEMP BED_MAXTEMP
  95. #define MIN_BED_TEMP 0
  96. #endif
  97. constexpr uint16_t TROWS = 6, MROWS = TROWS - 1,
  98. TITLE_HEIGHT = 30,
  99. MLINE = 53,
  100. LBLX = 60,
  101. MENU_CHR_W = 8, MENU_CHR_H = 16, STAT_CHR_W = 10;
  102. #define MBASE(L) (49 + MLINE * (L))
  103. constexpr float default_max_feedrate[] = DEFAULT_MAX_FEEDRATE;
  104. constexpr float default_max_acceleration[] = DEFAULT_MAX_ACCELERATION;
  105. constexpr float default_steps[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  106. #if HAS_CLASSIC_JERK
  107. constexpr float default_max_jerk[] = { DEFAULT_XJERK, DEFAULT_YJERK, DEFAULT_ZJERK, DEFAULT_EJERK };
  108. #endif
  109. enum SelectItem : uint8_t {
  110. PAGE_PRINT = 0,
  111. PAGE_PREPARE,
  112. PAGE_CONTROL,
  113. PAGE_INFO_LEVELING,
  114. PAGE_COUNT,
  115. PRINT_SETUP = 0,
  116. PRINT_PAUSE_RESUME,
  117. PRINT_STOP,
  118. PRINT_COUNT
  119. };
  120. uint8_t active_menu = MainMenu, last_menu = MainMenu;
  121. uint8_t selection = 0, last_selection = 0;
  122. uint8_t scrollpos = 0;
  123. uint8_t process = Main, last_process = Main;
  124. PopupID popup, last_popup;
  125. void (*funcpointer)() = nullptr;
  126. void *valuepointer = nullptr;
  127. float tempvalue;
  128. float valuemin;
  129. float valuemax;
  130. uint8_t valueunit;
  131. uint8_t valuetype;
  132. char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
  133. char statusmsg[64];
  134. char filename[LONG_FILENAME_LENGTH];
  135. bool printing = false;
  136. bool paused = false;
  137. bool sdprint = false;
  138. int16_t pausetemp, pausebed, pausefan;
  139. bool livemove = false;
  140. bool liveadjust = false;
  141. uint8_t preheatmode = 0;
  142. float zoffsetvalue = 0;
  143. uint8_t gridpoint;
  144. float corner_avg;
  145. float corner_pos;
  146. bool probe_deployed = false;
  147. CrealityDWINClass CrealityDWIN;
  148. #if HAS_MESH
  149. struct Mesh_Settings {
  150. bool viewer_asymmetric_range = false;
  151. bool viewer_print_value = false;
  152. bool goto_mesh_value = false;
  153. bool drawing_mesh = false;
  154. uint8_t mesh_x = 0;
  155. uint8_t mesh_y = 0;
  156. #if ENABLED(AUTO_BED_LEVELING_UBL)
  157. uint8_t tilt_grid = 1;
  158. void manual_value_update(bool undefined=false) {
  159. sprintf_P(cmd, PSTR("M421 I%i J%i Z%s %s"), mesh_x, mesh_y, dtostrf(current_position.z, 1, 3, str_1), undefined ? "N" : "");
  160. gcode.process_subcommands_now(cmd);
  161. planner.synchronize();
  162. }
  163. bool create_plane_from_mesh() {
  164. struct linear_fit_data lsf_results;
  165. incremental_LSF_reset(&lsf_results);
  166. GRID_LOOP(x, y) {
  167. if (!isnan(bedlevel.z_values[x][y])) {
  168. xy_pos_t rpos = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
  169. incremental_LSF(&lsf_results, rpos, bedlevel.z_values[x][y]);
  170. }
  171. }
  172. if (finish_incremental_LSF(&lsf_results)) {
  173. SERIAL_ECHOPGM("Could not complete LSF!");
  174. return true;
  175. }
  176. bedlevel.set_all_mesh_points_to_value(0);
  177. matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
  178. GRID_LOOP(i, j) {
  179. float mx = bedlevel.get_mesh_x(i),
  180. my = bedlevel.get_mesh_y(j),
  181. mz = bedlevel.z_values[i][j];
  182. if (DEBUGGING(LEVELING)) {
  183. DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
  184. DEBUG_CHAR(',');
  185. DEBUG_ECHO_F(my, 7);
  186. DEBUG_CHAR(',');
  187. DEBUG_ECHO_F(mz, 7);
  188. DEBUG_ECHOPGM("] ---> ");
  189. DEBUG_DELAY(20);
  190. }
  191. rotation.apply_rotation_xyz(mx, my, mz);
  192. if (DEBUGGING(LEVELING)) {
  193. DEBUG_ECHOPAIR_F("after rotation = [", mx, 7);
  194. DEBUG_CHAR(',');
  195. DEBUG_ECHO_F(my, 7);
  196. DEBUG_CHAR(',');
  197. DEBUG_ECHO_F(mz, 7);
  198. DEBUG_ECHOLNPGM("]");
  199. DEBUG_DELAY(20);
  200. }
  201. bedlevel.z_values[i][j] = mz - lsf_results.D;
  202. }
  203. return false;
  204. }
  205. #else
  206. void manual_value_update() {
  207. sprintf_P(cmd, PSTR("G29 I%i J%i Z%s"), mesh_x, mesh_y, dtostrf(current_position.z, 1, 3, str_1));
  208. gcode.process_subcommands_now(cmd);
  209. planner.synchronize();
  210. }
  211. #endif
  212. void manual_move(bool zmove=false) {
  213. if (zmove) {
  214. planner.synchronize();
  215. current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
  216. planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
  217. planner.synchronize();
  218. }
  219. else {
  220. CrealityDWIN.Popup_Handler(MoveWait);
  221. sprintf_P(cmd, PSTR("G0 F300 Z%s"), dtostrf(Z_CLEARANCE_BETWEEN_PROBES, 1, 3, str_1));
  222. gcode.process_subcommands_now(cmd);
  223. sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
  224. gcode.process_subcommands_now(cmd);
  225. planner.synchronize();
  226. current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
  227. planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
  228. planner.synchronize();
  229. CrealityDWIN.Redraw_Menu();
  230. }
  231. }
  232. float get_max_value() {
  233. float max = __FLT_MIN__;
  234. GRID_LOOP(x, y) {
  235. if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
  236. max = bedlevel.z_values[x][y];
  237. }
  238. return max;
  239. }
  240. float get_min_value() {
  241. float min = __FLT_MAX__;
  242. GRID_LOOP(x, y) {
  243. if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
  244. min = bedlevel.z_values[x][y];
  245. }
  246. return min;
  247. }
  248. void Draw_Bed_Mesh(int16_t selected = -1, uint8_t gridline_width = 1, uint16_t padding_x = 8, uint16_t padding_y_top = 40 + 53 - 7) {
  249. drawing_mesh = true;
  250. const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x,
  251. cell_width_px = total_width_px / (GRID_MAX_POINTS_X),
  252. cell_height_px = total_width_px / (GRID_MAX_POINTS_Y);
  253. const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
  254. // Clear background from previous selection and select new square
  255. DWIN_Draw_Rectangle(1, Color_Bg_Black, _MAX(0, padding_x - gridline_width), _MAX(0, padding_y_top - gridline_width), padding_x + total_width_px, padding_y_top + total_width_px);
  256. if (selected >= 0) {
  257. const auto selected_y = selected / (GRID_MAX_POINTS_X);
  258. const auto selected_x = selected - (GRID_MAX_POINTS_X) * selected_y;
  259. const auto start_y_px = padding_y_top + selected_y * cell_height_px;
  260. const auto start_x_px = padding_x + selected_x * cell_width_px;
  261. DWIN_Draw_Rectangle(1, Color_White, _MAX(0, start_x_px - gridline_width), _MAX(0, start_y_px - gridline_width), start_x_px + cell_width_px, start_y_px + cell_height_px);
  262. }
  263. // Draw value square grid
  264. char buf[8];
  265. GRID_LOOP(x, y) {
  266. const auto start_x_px = padding_x + x * cell_width_px;
  267. const auto end_x_px = start_x_px + cell_width_px - 1 - gridline_width;
  268. const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
  269. const auto end_y_px = start_y_px + cell_height_px - 1 - gridline_width;
  270. DWIN_Draw_Rectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
  271. isnan(bedlevel.z_values[x][y]) ? Color_Grey : ( // gray if undefined
  272. (bedlevel.z_values[x][y] < 0 ?
  273. (uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
  274. (uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
  275. _MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))), // + blue stepping for every mm
  276. start_x_px, start_y_px, end_x_px, end_y_px
  277. );
  278. safe_delay(10);
  279. LCD_SERIAL.flushTX();
  280. // Draw value text on
  281. if (viewer_print_value) {
  282. int8_t offset_x, offset_y = cell_height_px / 2 - 6;
  283. if (isnan(bedlevel.z_values[x][y])) { // undefined
  284. DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X"));
  285. }
  286. else { // has value
  287. if (GRID_MAX_POINTS_X < 10)
  288. sprintf_P(buf, PSTR("%s"), dtostrf(abs(bedlevel.z_values[x][y]), 1, 2, str_1));
  289. else
  290. sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(bedlevel.z_values[x][y] - (int16_t)bedlevel.z_values[x][y]) * 100));
  291. offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
  292. if (!(GRID_MAX_POINTS_X < 10))
  293. DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F("."));
  294. DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px + 1 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, buf);
  295. }
  296. safe_delay(10);
  297. LCD_SERIAL.flushTX();
  298. }
  299. }
  300. }
  301. void Set_Mesh_Viewer_Status() { // TODO: draw gradient with values as a legend instead
  302. float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
  303. if (v_min > 3e+10F) v_min = 0.0000001;
  304. if (v_max > 3e+10F) v_max = 0.0000001;
  305. if (range > 3e+10F) range = 0.0000001;
  306. char msg[46];
  307. if (viewer_asymmetric_range) {
  308. dtostrf(-v_min, 1, 3, str_1);
  309. dtostrf( v_max, 1, 3, str_2);
  310. }
  311. else {
  312. dtostrf(-range, 1, 3, str_1);
  313. dtostrf( range, 1, 3, str_2);
  314. }
  315. sprintf_P(msg, PSTR("Red %s..0..%s Green"), str_1, str_2);
  316. CrealityDWIN.Update_Status(msg);
  317. drawing_mesh = false;
  318. }
  319. };
  320. Mesh_Settings mesh_conf;
  321. #endif // HAS_MESH
  322. /* General Display Functions */
  323. struct CrealityDWINClass::EEPROM_Settings CrealityDWINClass::eeprom_settings{0};
  324. constexpr const char * const CrealityDWINClass::color_names[11];
  325. constexpr const char * const CrealityDWINClass::preheat_modes[3];
  326. // Clear a part of the screen
  327. // 4=Entire screen
  328. // 3=Title bar and Menu area (default)
  329. // 2=Menu area
  330. // 1=Title bar
  331. void CrealityDWINClass::Clear_Screen(uint8_t e/*=3*/) {
  332. if (e == 1 || e == 3 || e == 4) DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.menu_top_bg, Color_Bg_Blue, false), 0, 0, DWIN_WIDTH, TITLE_HEIGHT); // Clear Title Bar
  333. if (e == 2 || e == 3) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, STATUS_Y); // Clear Menu Area
  334. if (e == 4) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, DWIN_HEIGHT); // Clear Popup Area
  335. }
  336. void CrealityDWINClass::Draw_Float(float value, uint8_t row, bool selected/*=false*/, uint8_t minunit/*=10*/) {
  337. const uint8_t digits = (uint8_t)floor(log10(abs(value))) + log10(minunit) + (minunit > 1);
  338. const uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black;
  339. const uint16_t xpos = 240 - (digits * 8);
  340. DWIN_Draw_Rectangle(1, Color_Bg_Black, 194, MBASE(row), 234 - (digits * 8), MBASE(row) + 16);
  341. if (isnan(value))
  342. DWIN_Draw_String(true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), F(" NaN"));
  343. else {
  344. DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, Color_White, bColor, digits - log10(minunit) + 1, log10(minunit), xpos, MBASE(row), (value < 0 ? -value : value));
  345. DWIN_Draw_String(true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), value < 0 ? F("-") : F(" "));
  346. }
  347. }
  348. void CrealityDWINClass::Draw_Option(uint8_t value, const char * const * options, uint8_t row, bool selected/*=false*/, bool color/*=false*/) {
  349. uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black,
  350. tColor = (color) ? GetColor(value, Color_White, false) : Color_White;
  351. DWIN_Draw_Rectangle(1, bColor, 202, MBASE(row) + 14, 258, MBASE(row) - 2);
  352. DWIN_Draw_String(false, DWIN_FONT_MENU, tColor, bColor, 202, MBASE(row) - 1, options[value]);
  353. }
  354. uint16_t CrealityDWINClass::GetColor(uint8_t color, uint16_t original, bool light/*=false*/) {
  355. switch (color) {
  356. case Default:
  357. return original;
  358. break;
  359. case White:
  360. return (light) ? Color_Light_White : Color_White;
  361. break;
  362. case Green:
  363. return (light) ? Color_Light_Green : Color_Green;
  364. break;
  365. case Cyan:
  366. return (light) ? Color_Light_Cyan : Color_Cyan;
  367. break;
  368. case Blue:
  369. return (light) ? Color_Light_Blue : Color_Blue;
  370. break;
  371. case Magenta:
  372. return (light) ? Color_Light_Magenta : Color_Magenta;
  373. break;
  374. case Red:
  375. return (light) ? Color_Light_Red : Color_Red;
  376. break;
  377. case Orange:
  378. return (light) ? Color_Light_Orange : Color_Orange;
  379. break;
  380. case Yellow:
  381. return (light) ? Color_Light_Yellow : Color_Yellow;
  382. break;
  383. case Brown:
  384. return (light) ? Color_Light_Brown : Color_Brown;
  385. break;
  386. case Black:
  387. return Color_Black;
  388. break;
  389. }
  390. return Color_White;
  391. }
  392. void CrealityDWINClass::Draw_Title(const char * ctitle) {
  393. DWIN_Draw_String(false, DWIN_FONT_HEAD, GetColor(eeprom_settings.menu_top_txt, Color_White, false), Color_Bg_Blue, (DWIN_WIDTH - strlen(ctitle) * STAT_CHR_W) / 2, 5, ctitle);
  394. }
  395. void CrealityDWINClass::Draw_Title(FSTR_P const ftitle) {
  396. DWIN_Draw_String(false, DWIN_FONT_HEAD, GetColor(eeprom_settings.menu_top_txt, Color_White, false), Color_Bg_Blue, (DWIN_WIDTH - strlen_P(FTOP(ftitle)) * STAT_CHR_W) / 2, 5, ftitle);
  397. }
  398. void _Decorate_Menu_Item(uint8_t row, uint8_t icon, bool more) {
  399. if (icon) DWIN_ICON_Show(ICON, icon, 26, MBASE(row) - 3); //Draw Menu Icon
  400. if (more) DWIN_ICON_Show(ICON, ICON_More, 226, MBASE(row) - 3); // Draw More Arrow
  401. DWIN_Draw_Line(CrealityDWIN.GetColor(CrealityDWIN.eeprom_settings.menu_split_line, Line_Color, true), 16, MBASE(row) + 33, 256, MBASE(row) + 33); // Draw Menu Line
  402. }
  403. void CrealityDWINClass::Draw_Menu_Item(uint8_t row, uint8_t icon/*=0*/, const char * label1, const char * label2, bool more/*=false*/, bool centered/*=false*/) {
  404. const uint8_t label_offset_y = (label1 || label2) ? MENU_CHR_H * 3 / 5 : 0,
  405. label1_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label1 ? strlen(label1) : 0) * MENU_CHR_W) / 2),
  406. label2_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label2 ? strlen(label2) : 0) * MENU_CHR_W) / 2);
  407. if (label1) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label1_offset_x, MBASE(row) - 1 - label_offset_y, label1); // Draw Label
  408. if (label2) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label2_offset_x, MBASE(row) - 1 + label_offset_y, label2); // Draw Label
  409. _Decorate_Menu_Item(row, icon, more);
  410. }
  411. void CrealityDWINClass::Draw_Menu_Item(uint8_t row, uint8_t icon/*=0*/, FSTR_P const flabel1, FSTR_P const flabel2, bool more/*=false*/, bool centered/*=false*/) {
  412. const uint8_t label_offset_y = (flabel1 || flabel2) ? MENU_CHR_H * 3 / 5 : 0,
  413. label1_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (flabel1 ? strlen_P(FTOP(flabel1)) : 0) * MENU_CHR_W) / 2),
  414. label2_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (flabel2 ? strlen_P(FTOP(flabel2)) : 0) * MENU_CHR_W) / 2);
  415. if (flabel1) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label1_offset_x, MBASE(row) - 1 - label_offset_y, flabel1); // Draw Label
  416. if (flabel2) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label2_offset_x, MBASE(row) - 1 + label_offset_y, flabel2); // Draw Label
  417. _Decorate_Menu_Item(row, icon, more);
  418. }
  419. void CrealityDWINClass::Draw_Checkbox(uint8_t row, bool value) {
  420. #if ENABLED(DWIN_CREALITY_LCD_CUSTOM_ICONS) // Draw appropriate checkbox icon
  421. DWIN_ICON_Show(ICON, (value ? ICON_Checkbox_T : ICON_Checkbox_F), 226, MBASE(row) - 3);
  422. #else // Draw a basic checkbox using rectangles and lines
  423. DWIN_Draw_Rectangle(1, Color_Bg_Black, 226, MBASE(row) - 3, 226 + 20, MBASE(row) - 3 + 20);
  424. DWIN_Draw_Rectangle(0, Color_White, 226, MBASE(row) - 3, 226 + 20, MBASE(row) - 3 + 20);
  425. if (value) {
  426. DWIN_Draw_Line(Check_Color, 227, MBASE(row) - 3 + 11, 226 + 8, MBASE(row) - 3 + 17);
  427. DWIN_Draw_Line(Check_Color, 227 + 8, MBASE(row) - 3 + 17, 226 + 19, MBASE(row) - 3 + 1);
  428. DWIN_Draw_Line(Check_Color, 227, MBASE(row) - 3 + 12, 226 + 8, MBASE(row) - 3 + 18);
  429. DWIN_Draw_Line(Check_Color, 227 + 8, MBASE(row) - 3 + 18, 226 + 19, MBASE(row) - 3 + 2);
  430. DWIN_Draw_Line(Check_Color, 227, MBASE(row) - 3 + 13, 226 + 8, MBASE(row) - 3 + 19);
  431. DWIN_Draw_Line(Check_Color, 227 + 8, MBASE(row) - 3 + 19, 226 + 19, MBASE(row) - 3 + 3);
  432. }
  433. #endif
  434. }
  435. void CrealityDWINClass::Draw_Menu(uint8_t menu, uint8_t select/*=0*/, uint8_t scroll/*=0*/) {
  436. if (active_menu != menu) {
  437. last_menu = active_menu;
  438. if (process == Menu) last_selection = selection;
  439. }
  440. selection = _MIN(select, Get_Menu_Size(menu));
  441. scrollpos = scroll;
  442. if (selection - scrollpos > MROWS)
  443. scrollpos = selection - MROWS;
  444. process = Menu;
  445. active_menu = menu;
  446. Clear_Screen();
  447. Draw_Title(Get_Menu_Title(menu));
  448. LOOP_L_N(i, TROWS) Menu_Item_Handler(menu, i + scrollpos);
  449. DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
  450. }
  451. void CrealityDWINClass::Redraw_Menu(bool lastprocess/*=true*/, bool lastselection/*=false*/, bool lastmenu/*=false*/) {
  452. switch ((lastprocess) ? last_process : process) {
  453. case Menu:
  454. Draw_Menu((lastmenu) ? last_menu : active_menu, (lastselection) ? last_selection : selection, (lastmenu) ? 0 : scrollpos);
  455. break;
  456. case Main: Draw_Main_Menu((lastselection) ? last_selection : selection); break;
  457. case Print: Draw_Print_Screen(); break;
  458. case File: Draw_SD_List(); break;
  459. default: break;
  460. }
  461. }
  462. void CrealityDWINClass::Redraw_Screen() {
  463. Redraw_Menu(false);
  464. Draw_Status_Area(true);
  465. Update_Status_Bar(true);
  466. }
  467. /* Primary Menus and Screen Elements */
  468. void CrealityDWINClass::Main_Menu_Icons() {
  469. if (selection == 0) {
  470. DWIN_ICON_Show(ICON, ICON_Print_1, 17, 130);
  471. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 17, 130, 126, 229);
  472. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 52, 200, F("Print"));
  473. }
  474. else {
  475. DWIN_ICON_Show(ICON, ICON_Print_0, 17, 130);
  476. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 52, 200, F("Print"));
  477. }
  478. if (selection == 1) {
  479. DWIN_ICON_Show(ICON, ICON_Prepare_1, 145, 130);
  480. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 130, 254, 229);
  481. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 170, 200, F("Prepare"));
  482. }
  483. else {
  484. DWIN_ICON_Show(ICON, ICON_Prepare_0, 145, 130);
  485. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 170, 200, F("Prepare"));
  486. }
  487. if (selection == 2) {
  488. DWIN_ICON_Show(ICON, ICON_Control_1, 17, 246);
  489. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 17, 246, 126, 345);
  490. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 43, 317, F("Control"));
  491. }
  492. else {
  493. DWIN_ICON_Show(ICON, ICON_Control_0, 17, 246);
  494. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 43, 317, F("Control"));
  495. }
  496. #if HAS_ABL_OR_UBL
  497. if (selection == 3) {
  498. DWIN_ICON_Show(ICON, ICON_Leveling_1, 145, 246);
  499. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 246, 254, 345);
  500. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 179, 317, F("Level"));
  501. }
  502. else {
  503. DWIN_ICON_Show(ICON, ICON_Leveling_0, 145, 246);
  504. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 179, 317, F("Level"));
  505. }
  506. #else
  507. if (selection == 3) {
  508. DWIN_ICON_Show(ICON, ICON_Info_1, 145, 246);
  509. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 246, 254, 345);
  510. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 181, 317, F("Info"));
  511. }
  512. else {
  513. DWIN_ICON_Show(ICON, ICON_Info_0, 145, 246);
  514. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 181, 317, F("Info"));
  515. }
  516. #endif
  517. }
  518. void CrealityDWINClass::Draw_Main_Menu(uint8_t select/*=0*/) {
  519. process = Main;
  520. active_menu = MainMenu;
  521. selection = select;
  522. Clear_Screen();
  523. Draw_Title(Get_Menu_Title(MainMenu));
  524. SERIAL_ECHOPGM("\nDWIN handshake ");
  525. DWIN_ICON_Show(ICON, ICON_LOGO, 71, 72);
  526. Main_Menu_Icons();
  527. }
  528. void CrealityDWINClass::Print_Screen_Icons() {
  529. if (selection == 0) {
  530. DWIN_ICON_Show(ICON, ICON_Setup_1, 8, 252);
  531. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 8, 252, 87, 351);
  532. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 30, 322, F("Tune"));
  533. }
  534. else {
  535. DWIN_ICON_Show(ICON, ICON_Setup_0, 8, 252);
  536. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 30, 322, F("Tune"));
  537. }
  538. if (selection == 2) {
  539. DWIN_ICON_Show(ICON, ICON_Stop_1, 184, 252);
  540. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 184, 252, 263, 351);
  541. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 205, 322, F("Stop"));
  542. }
  543. else {
  544. DWIN_ICON_Show(ICON, ICON_Stop_0, 184, 252);
  545. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 205, 322, F("Stop"));
  546. }
  547. if (paused) {
  548. if (selection == 1) {
  549. DWIN_ICON_Show(ICON, ICON_Continue_1, 96, 252);
  550. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 96, 252, 175, 351);
  551. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Print"));
  552. }
  553. else {
  554. DWIN_ICON_Show(ICON, ICON_Continue_0, 96, 252);
  555. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Print"));
  556. }
  557. }
  558. else {
  559. if (selection == 1) {
  560. DWIN_ICON_Show(ICON, ICON_Pause_1, 96, 252);
  561. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 96, 252, 175, 351);
  562. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Pause"));
  563. }
  564. else {
  565. DWIN_ICON_Show(ICON, ICON_Pause_0, 96, 252);
  566. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Pause"));
  567. }
  568. }
  569. }
  570. void CrealityDWINClass::Draw_Print_Screen() {
  571. process = Print;
  572. selection = 0;
  573. Clear_Screen();
  574. DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
  575. Draw_Title("Printing...");
  576. Print_Screen_Icons();
  577. DWIN_ICON_Show(ICON, ICON_PrintTime, 14, 171);
  578. DWIN_ICON_Show(ICON, ICON_RemainTime, 147, 169);
  579. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, 41, 163, F("Elapsed"));
  580. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, 176, 163, F("Remaining"));
  581. Update_Status_Bar(true);
  582. Draw_Print_ProgressBar();
  583. Draw_Print_ProgressElapsed();
  584. TERN_(USE_M73_REMAINING_TIME, Draw_Print_ProgressRemain());
  585. Draw_Print_Filename(true);
  586. }
  587. void CrealityDWINClass::Draw_Print_Filename(const bool reset/*=false*/) {
  588. static uint8_t namescrl = 0;
  589. if (reset) namescrl = 0;
  590. if (process == Print) {
  591. constexpr int8_t maxlen = 30;
  592. char *outstr = filename;
  593. size_t slen = strlen(filename);
  594. int8_t outlen = slen;
  595. if (slen > maxlen) {
  596. char dispname[maxlen + 1];
  597. int8_t pos = slen - namescrl, len = maxlen;
  598. if (pos >= 0) {
  599. NOMORE(len, pos);
  600. LOOP_L_N(i, len) dispname[i] = filename[i + namescrl];
  601. }
  602. else {
  603. const int8_t mp = maxlen + pos;
  604. LOOP_L_N(i, mp) dispname[i] = ' ';
  605. LOOP_S_L_N(i, mp, maxlen) dispname[i] = filename[i - mp];
  606. if (mp <= 0) namescrl = 0;
  607. }
  608. dispname[len] = '\0';
  609. outstr = dispname;
  610. outlen = maxlen;
  611. namescrl++;
  612. }
  613. DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80);
  614. const int8_t npos = (DWIN_WIDTH - outlen * MENU_CHR_W) / 2;
  615. DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, outstr);
  616. }
  617. }
  618. void CrealityDWINClass::Draw_Print_ProgressBar() {
  619. uint8_t printpercent = sdprint ? card.percentDone() : (ui._get_progress() / 100);
  620. DWIN_ICON_Show(ICON, ICON_Bar, 15, 93);
  621. DWIN_Draw_Rectangle(1, BarFill_Color, 16 + printpercent * 240 / 100, 93, 256, 113);
  622. DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_percent, Percent_Color), Color_Bg_Black, 3, 109, 133, printpercent);
  623. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_percent, Percent_Color), Color_Bg_Black, 133, 133, F("%"));
  624. }
  625. #if ENABLED(USE_M73_REMAINING_TIME)
  626. void CrealityDWINClass::Draw_Print_ProgressRemain() {
  627. uint16_t remainingtime = ui.get_remaining_time();
  628. DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 176, 187, remainingtime / 3600);
  629. DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 200, 187, (remainingtime % 3600) / 60);
  630. if (eeprom_settings.time_format_textual) {
  631. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, F("h"));
  632. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 216, 187, F("m"));
  633. }
  634. else
  635. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, F(":"));
  636. }
  637. #endif
  638. void CrealityDWINClass::Draw_Print_ProgressElapsed() {
  639. duration_t elapsed = print_job_timer.duration();
  640. DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 42, 187, elapsed.value / 3600);
  641. DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 66, 187, (elapsed.value % 3600) / 60);
  642. if (eeprom_settings.time_format_textual) {
  643. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, F("h"));
  644. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 82, 187, F("m"));
  645. }
  646. else
  647. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, F(":"));
  648. }
  649. void CrealityDWINClass::Draw_Print_confirm() {
  650. Draw_Print_Screen();
  651. process = Confirm;
  652. popup = Complete;
  653. DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 252, 263, 351);
  654. DWIN_ICON_Show(ICON, ICON_Confirm_E, 87, 283);
  655. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 86, 282, 187, 321);
  656. DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 85, 281, 188, 322);
  657. }
  658. void CrealityDWINClass::Draw_SD_Item(uint8_t item, uint8_t row) {
  659. if (item == 0)
  660. Draw_Menu_Item(0, ICON_Back, card.flag.workDirIsRoot ? F("Back") : F(".."));
  661. else {
  662. card.getfilename_sorted(SD_ORDER(item - 1, card.get_num_Files()));
  663. char * const filename = card.longest_filename();
  664. size_t max = MENU_CHAR_LIMIT;
  665. size_t pos = strlen(filename), len = pos;
  666. if (!card.flag.filenameIsDir)
  667. while (pos && filename[pos] != '.') pos--;
  668. len = pos;
  669. if (len > max) len = max;
  670. char name[len + 1];
  671. LOOP_L_N(i, len) name[i] = filename[i];
  672. if (pos > max)
  673. LOOP_S_L_N(i, len - 3, len) name[i] = '.';
  674. name[len] = '\0';
  675. Draw_Menu_Item(row, card.flag.filenameIsDir ? ICON_More : ICON_File, name);
  676. }
  677. }
  678. void CrealityDWINClass::Draw_SD_List(bool removed/*=false*/) {
  679. Clear_Screen();
  680. Draw_Title("Select File");
  681. selection = 0;
  682. scrollpos = 0;
  683. process = File;
  684. if (card.isMounted() && !removed) {
  685. LOOP_L_N(i, _MIN(card.get_num_Files() + 1, TROWS))
  686. Draw_SD_Item(i, i);
  687. }
  688. else {
  689. Draw_Menu_Item(0, ICON_Back, F("Back"));
  690. DWIN_Draw_Rectangle(1, Color_Bg_Red, 10, MBASE(3) - 10, DWIN_WIDTH - 10, MBASE(4));
  691. DWIN_Draw_String(false, font16x32, Color_Yellow, Color_Bg_Red, ((DWIN_WIDTH) - 8 * 16) / 2, MBASE(3), F("No Media"));
  692. }
  693. DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(0) - 18, 14, MBASE(0) + 33);
  694. }
  695. void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) {
  696. if (icons) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, STATUS_Y, DWIN_WIDTH, DWIN_HEIGHT - 1);
  697. #if HAS_HOTEND
  698. static float hotend = -1;
  699. static int16_t hotendtarget = -1, flow = -1;
  700. if (icons) {
  701. hotend = -1;
  702. hotendtarget = -1;
  703. DWIN_ICON_Show(ICON, ICON_HotendTemp, 10, 383);
  704. DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 384, F("/"));
  705. }
  706. if (thermalManager.temp_hotend[0].celsius != hotend) {
  707. hotend = thermalManager.temp_hotend[0].celsius;
  708. DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 28, 384, thermalManager.temp_hotend[0].celsius);
  709. DWIN_Draw_DegreeSymbol(GetColor(eeprom_settings.status_area_text, Color_White), 25 + 3 * STAT_CHR_W + 5, 386);
  710. }
  711. if (thermalManager.temp_hotend[0].target != hotendtarget) {
  712. hotendtarget = thermalManager.temp_hotend[0].target;
  713. DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 384, thermalManager.temp_hotend[0].target);
  714. DWIN_Draw_DegreeSymbol(GetColor(eeprom_settings.status_area_text, Color_White), 25 + 4 * STAT_CHR_W + 39, 386);
  715. }
  716. if (icons) {
  717. flow = -1;
  718. DWIN_ICON_Show(ICON, ICON_StepE, 112, 417);
  719. DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 417, F("%"));
  720. }
  721. if (planner.flow_percentage[0] != flow) {
  722. flow = planner.flow_percentage[0];
  723. DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 417, planner.flow_percentage[0]);
  724. }
  725. #endif
  726. #if HAS_HEATED_BED
  727. static float bed = -1;
  728. static int16_t bedtarget = -1;
  729. if (icons) {
  730. bed = -1;
  731. bedtarget = -1;
  732. DWIN_ICON_Show(ICON, ICON_BedTemp, 10, 416);
  733. DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 417, F("/"));
  734. }
  735. if (thermalManager.temp_bed.celsius != bed) {
  736. bed = thermalManager.temp_bed.celsius;
  737. DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 28, 417, thermalManager.temp_bed.celsius);
  738. DWIN_Draw_DegreeSymbol(GetColor(eeprom_settings.status_area_text, Color_White), 25 + 3 * STAT_CHR_W + 5, 419);
  739. }
  740. if (thermalManager.temp_bed.target != bedtarget) {
  741. bedtarget = thermalManager.temp_bed.target;
  742. DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 417, thermalManager.temp_bed.target);
  743. DWIN_Draw_DegreeSymbol(GetColor(eeprom_settings.status_area_text, Color_White), 25 + 4 * STAT_CHR_W + 39, 419);
  744. }
  745. #endif
  746. #if HAS_FAN
  747. static uint8_t fan = -1;
  748. if (icons) {
  749. fan = -1;
  750. DWIN_ICON_Show(ICON, ICON_FanSpeed, 187, 383);
  751. }
  752. if (thermalManager.fan_speed[0] != fan) {
  753. fan = thermalManager.fan_speed[0];
  754. DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 195 + 2 * STAT_CHR_W, 384, thermalManager.fan_speed[0]);
  755. }
  756. #endif
  757. #if HAS_ZOFFSET_ITEM
  758. static float offset = -1;
  759. if (icons) {
  760. offset = -1;
  761. DWIN_ICON_Show(ICON, ICON_Zoffset, 187, 416);
  762. }
  763. if (zoffsetvalue != offset) {
  764. offset = zoffsetvalue;
  765. DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 2, 2, 207, 417, (zoffsetvalue < 0 ? -zoffsetvalue : zoffsetvalue));
  766. DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 205, 419, zoffsetvalue < 0 ? F("-") : F(" "));
  767. }
  768. #endif
  769. static int16_t feedrate = -1;
  770. if (icons) {
  771. feedrate = -1;
  772. DWIN_ICON_Show(ICON, ICON_Speed, 113, 383);
  773. DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 384, F("%"));
  774. }
  775. if (feedrate_percentage != feedrate) {
  776. feedrate = feedrate_percentage;
  777. DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 384, feedrate_percentage);
  778. }
  779. static float x = -1, y = -1, z = -1;
  780. static bool update_x = false, update_y = false, update_z = false;
  781. update_x = (current_position.x != x || axis_should_home(X_AXIS) || update_x);
  782. update_y = (current_position.y != y || axis_should_home(Y_AXIS) || update_y);
  783. update_z = (current_position.z != z || axis_should_home(Z_AXIS) || update_z);
  784. if (icons) {
  785. x = y = z = -1;
  786. DWIN_Draw_Line(GetColor(eeprom_settings.coordinates_split_line, Line_Color, true), 16, 450, 256, 450);
  787. DWIN_ICON_Show(ICON, ICON_MaxSpeedX, 10, 456);
  788. DWIN_ICON_Show(ICON, ICON_MaxSpeedY, 95, 456);
  789. DWIN_ICON_Show(ICON, ICON_MaxSpeedZ, 180, 456);
  790. }
  791. if (update_x) {
  792. x = current_position.x;
  793. if ((update_x = axis_should_home(X_AXIS) && ui.get_blink()))
  794. DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 35, 459, F(" -?- "));
  795. else
  796. DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 1, 35, 459, current_position.x);
  797. }
  798. if (update_y) {
  799. y = current_position.y;
  800. if ((update_y = axis_should_home(Y_AXIS) && ui.get_blink()))
  801. DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 120, 459, F(" -?- "));
  802. else
  803. DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 1, 120, 459, current_position.y);
  804. }
  805. if (update_z) {
  806. z = current_position.z;
  807. if ((update_z = axis_should_home(Z_AXIS) && ui.get_blink()))
  808. DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 205, 459, F(" -?- "));
  809. else
  810. DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 2, 205, 459, (current_position.z>=0) ? current_position.z : 0);
  811. }
  812. DWIN_UpdateLCD();
  813. }
  814. void CrealityDWINClass::Draw_Popup(FSTR_P const line1, FSTR_P const line2, FSTR_P const line3, uint8_t mode, uint8_t icon/*=0*/) {
  815. if (process != Confirm && process != Popup && process != Wait) last_process = process;
  816. if ((process == Menu || process == Wait) && mode == Popup) last_selection = selection;
  817. process = mode;
  818. Clear_Screen();
  819. DWIN_Draw_Rectangle(0, Color_White, 13, 59, 259, 351);
  820. DWIN_Draw_Rectangle(1, Color_Bg_Window, 14, 60, 258, 350);
  821. const uint8_t ypos = (mode == Popup || mode == Confirm) ? 150 : 230;
  822. if (icon > 0) DWIN_ICON_Show(ICON, icon, 101, 105);
  823. DWIN_Draw_String(true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(FTOP(line1))) / 2, ypos, line1);
  824. DWIN_Draw_String(true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(FTOP(line2))) / 2, ypos + 30, line2);
  825. DWIN_Draw_String(true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(FTOP(line3))) / 2, ypos + 60, line3);
  826. if (mode == Popup) {
  827. selection = 0;
  828. DWIN_Draw_Rectangle(1, Confirm_Color, 26, 280, 125, 317);
  829. DWIN_Draw_Rectangle(1, Cancel_Color, 146, 280, 245, 317);
  830. DWIN_Draw_String(false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 39, 290, F("Confirm"));
  831. DWIN_Draw_String(false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 165, 290, F("Cancel"));
  832. Popup_Select();
  833. }
  834. else if (mode == Confirm) {
  835. DWIN_Draw_Rectangle(1, Confirm_Color, 87, 280, 186, 317);
  836. DWIN_Draw_String(false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 96, 290, F("Continue"));
  837. }
  838. }
  839. void MarlinUI::kill_screen(FSTR_P const error, FSTR_P const) {
  840. CrealityDWIN.Draw_Popup(F("Printer Kill Reason:"), error, F("Restart Required"), Wait, ICON_BLTouch);
  841. }
  842. void CrealityDWINClass::Popup_Select() {
  843. const uint16_t c1 = (selection == 0) ? GetColor(eeprom_settings.highlight_box, Color_White) : Color_Bg_Window,
  844. c2 = (selection == 0) ? Color_Bg_Window : GetColor(eeprom_settings.highlight_box, Color_White);
  845. DWIN_Draw_Rectangle(0, c1, 25, 279, 126, 318);
  846. DWIN_Draw_Rectangle(0, c1, 24, 278, 127, 319);
  847. DWIN_Draw_Rectangle(0, c2, 145, 279, 246, 318);
  848. DWIN_Draw_Rectangle(0, c2, 144, 278, 247, 319);
  849. }
  850. void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) {
  851. static bool new_msg;
  852. static uint8_t msgscrl = 0;
  853. static char lastmsg[64];
  854. if (strcmp(lastmsg, statusmsg) != 0 || refresh) {
  855. strcpy(lastmsg, statusmsg);
  856. msgscrl = 0;
  857. new_msg = true;
  858. }
  859. size_t len = strlen(statusmsg);
  860. int8_t pos = len;
  861. if (pos > 30) {
  862. pos -= msgscrl;
  863. len = pos;
  864. if (len > 30)
  865. len = 30;
  866. char dispmsg[len + 1];
  867. if (pos >= 0) {
  868. LOOP_L_N(i, len) dispmsg[i] = statusmsg[i + msgscrl];
  869. }
  870. else {
  871. LOOP_L_N(i, 30 + pos) dispmsg[i] = ' ';
  872. LOOP_S_L_N(i, 30 + pos, 30) dispmsg[i] = statusmsg[i - (30 + pos)];
  873. }
  874. dispmsg[len] = '\0';
  875. if (process == Print) {
  876. DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238);
  877. const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2;
  878. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, dispmsg);
  879. }
  880. else {
  881. DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
  882. const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2;
  883. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, dispmsg);
  884. }
  885. if (-pos >= 30) msgscrl = 0;
  886. msgscrl++;
  887. }
  888. else {
  889. if (new_msg) {
  890. new_msg = false;
  891. if (process == Print) {
  892. DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238);
  893. const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2;
  894. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, statusmsg);
  895. }
  896. else {
  897. DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
  898. const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2;
  899. DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, statusmsg);
  900. }
  901. }
  902. }
  903. }
  904. /* Menu Item Config */
  905. void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/*=true*/) {
  906. const uint8_t row = item - scrollpos;
  907. #if HAS_LEVELING
  908. static bool level_state;
  909. #endif
  910. #if HAS_PREHEAT
  911. #define PREHEAT_BACK 0
  912. #define PREHEAT_SUBMENU_HOTEND (PREHEAT_BACK + ENABLED(HAS_HOTEND))
  913. #define PREHEAT_SUBMENU_BED (PREHEAT_SUBMENU_HOTEND + ENABLED(HAS_HEATED_BED))
  914. #define PREHEAT_SUBMENU_FAN (PREHEAT_SUBMENU_BED + ENABLED(HAS_FAN))
  915. #define PREHEAT_SUBMENU_TOTAL PREHEAT_SUBMENU_FAN
  916. auto preheat_submenu = [&](const int index, const uint8_t item, const uint8_t sel) {
  917. switch (item) {
  918. case PREHEAT_BACK:
  919. if (draw)
  920. Draw_Menu_Item(row, ICON_Back, F("Back"));
  921. else
  922. Draw_Menu(TempMenu, sel);
  923. break;
  924. #if HAS_HOTEND
  925. case PREHEAT_SUBMENU_HOTEND:
  926. if (draw) {
  927. Draw_Menu_Item(row, ICON_SetEndTemp, F("Hotend"));
  928. Draw_Float(ui.material_preset[index].hotend_temp, row, false, 1);
  929. }
  930. else
  931. Modify_Value(ui.material_preset[index].hotend_temp, MIN_E_TEMP, MAX_E_TEMP, 1);
  932. break;
  933. #endif
  934. #if HAS_HEATED_BED
  935. case PREHEAT_SUBMENU_BED:
  936. if (draw) {
  937. Draw_Menu_Item(row, ICON_SetBedTemp, F("Bed"));
  938. Draw_Float(ui.material_preset[index].bed_temp, row, false, 1);
  939. }
  940. else
  941. Modify_Value(ui.material_preset[index].bed_temp, MIN_BED_TEMP, MAX_BED_TEMP, 1);
  942. break;
  943. #endif
  944. #if HAS_FAN
  945. case PREHEAT_SUBMENU_FAN:
  946. if (draw) {
  947. Draw_Menu_Item(row, ICON_FanSpeed, F("Fan"));
  948. Draw_Float(ui.material_preset[index].fan_speed, row, false, 1);
  949. }
  950. else
  951. Modify_Value(ui.material_preset[index].fan_speed, MIN_FAN_SPEED, MAX_FAN_SPEED, 1);
  952. break;
  953. #endif
  954. }
  955. };
  956. #endif
  957. switch (menu) {
  958. case Prepare:
  959. #define PREPARE_BACK 0
  960. #define PREPARE_MOVE (PREPARE_BACK + 1)
  961. #define PREPARE_DISABLE (PREPARE_MOVE + 1)
  962. #define PREPARE_HOME (PREPARE_DISABLE + 1)
  963. #define PREPARE_MANUALLEVEL (PREPARE_HOME + 1)
  964. #define PREPARE_ZOFFSET (PREPARE_MANUALLEVEL + ENABLED(HAS_ZOFFSET_ITEM))
  965. #define PREPARE_PREHEAT (PREPARE_ZOFFSET + ENABLED(HAS_PREHEAT))
  966. #define PREPARE_COOLDOWN (PREPARE_PREHEAT + EITHER(HAS_HOTEND, HAS_HEATED_BED))
  967. #define PREPARE_CHANGEFIL (PREPARE_COOLDOWN + ENABLED(ADVANCED_PAUSE_FEATURE))
  968. #define PREPARE_TOTAL PREPARE_CHANGEFIL
  969. switch (item) {
  970. case PREPARE_BACK:
  971. if (draw)
  972. Draw_Menu_Item(row, ICON_Back, F("Back"));
  973. else
  974. Draw_Main_Menu(1);
  975. break;
  976. case PREPARE_MOVE:
  977. if (draw)
  978. Draw_Menu_Item(row, ICON_Axis, F("Move"), nullptr, true);
  979. else
  980. Draw_Menu(Move);
  981. break;
  982. case PREPARE_DISABLE:
  983. if (draw)
  984. Draw_Menu_Item(row, ICON_CloseMotor, F("Disable Stepper"));
  985. else
  986. queue.inject(F("M84"));
  987. break;
  988. case PREPARE_HOME:
  989. if (draw)
  990. Draw_Menu_Item(row, ICON_SetHome, F("Homing"), nullptr, true);
  991. else
  992. Draw_Menu(HomeMenu);
  993. break;
  994. case PREPARE_MANUALLEVEL:
  995. if (draw)
  996. Draw_Menu_Item(row, ICON_PrintSize, F("Manual Leveling"), nullptr, true);
  997. else {
  998. if (axes_should_home()) {
  999. Popup_Handler(Home);
  1000. gcode.home_all_axes(true);
  1001. }
  1002. #if HAS_LEVELING
  1003. level_state = planner.leveling_active;
  1004. set_bed_leveling_enabled(false);
  1005. #endif
  1006. Draw_Menu(ManualLevel);
  1007. }
  1008. break;
  1009. #if HAS_ZOFFSET_ITEM
  1010. case PREPARE_ZOFFSET:
  1011. if (draw)
  1012. Draw_Menu_Item(row, ICON_Zoffset, F("Z-Offset"), nullptr, true);
  1013. else {
  1014. #if HAS_LEVELING
  1015. level_state = planner.leveling_active;
  1016. set_bed_leveling_enabled(false);
  1017. #endif
  1018. Draw_Menu(ZOffset);
  1019. }
  1020. break;
  1021. #endif
  1022. #if HAS_PREHEAT
  1023. case PREPARE_PREHEAT:
  1024. if (draw)
  1025. Draw_Menu_Item(row, ICON_Temperature, F("Preheat"), nullptr, true);
  1026. else
  1027. Draw_Menu(Preheat);
  1028. break;
  1029. #endif
  1030. #if HAS_HOTEND || HAS_HEATED_BED
  1031. case PREPARE_COOLDOWN:
  1032. if (draw)
  1033. Draw_Menu_Item(row, ICON_Cool, F("Cooldown"));
  1034. else
  1035. thermalManager.cooldown();
  1036. break;
  1037. #endif
  1038. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1039. case PREPARE_CHANGEFIL:
  1040. if (draw) {
  1041. Draw_Menu_Item(row, ICON_ResumeEEPROM, F("Change Filament")
  1042. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  1043. , nullptr, true
  1044. #endif
  1045. );
  1046. }
  1047. else {
  1048. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  1049. Draw_Menu(ChangeFilament);
  1050. #else
  1051. if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
  1052. Popup_Handler(ETemp);
  1053. else {
  1054. if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
  1055. Popup_Handler(Heating);
  1056. thermalManager.wait_for_hotend(0);
  1057. }
  1058. Popup_Handler(FilChange);
  1059. sprintf_P(cmd, PSTR("M600 B1 R%i"), thermalManager.temp_hotend[0].target);
  1060. gcode.process_subcommands_now(cmd);
  1061. }
  1062. #endif
  1063. }
  1064. break;
  1065. #endif
  1066. }
  1067. break;
  1068. case HomeMenu:
  1069. #define HOME_BACK 0
  1070. #define HOME_ALL (HOME_BACK + 1)
  1071. #define HOME_X (HOME_ALL + 1)
  1072. #define HOME_Y (HOME_X + 1)
  1073. #define HOME_Z (HOME_Y + 1)
  1074. #define HOME_SET (HOME_Z + 1)
  1075. #define HOME_TOTAL HOME_SET
  1076. switch (item) {
  1077. case HOME_BACK:
  1078. if (draw)
  1079. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1080. else
  1081. Draw_Menu(Prepare, PREPARE_HOME);
  1082. break;
  1083. case HOME_ALL:
  1084. if (draw)
  1085. Draw_Menu_Item(row, ICON_Homing, F("Home All"));
  1086. else {
  1087. Popup_Handler(Home);
  1088. gcode.home_all_axes(true);
  1089. Redraw_Menu();
  1090. }
  1091. break;
  1092. case HOME_X:
  1093. if (draw)
  1094. Draw_Menu_Item(row, ICON_MoveX, F("Home X"));
  1095. else {
  1096. Popup_Handler(Home);
  1097. gcode.process_subcommands_now(F("G28 X"));
  1098. planner.synchronize();
  1099. Redraw_Menu();
  1100. }
  1101. break;
  1102. case HOME_Y:
  1103. if (draw)
  1104. Draw_Menu_Item(row, ICON_MoveY, F("Home Y"));
  1105. else {
  1106. Popup_Handler(Home);
  1107. gcode.process_subcommands_now(F("G28 Y"));
  1108. planner.synchronize();
  1109. Redraw_Menu();
  1110. }
  1111. break;
  1112. case HOME_Z:
  1113. if (draw)
  1114. Draw_Menu_Item(row, ICON_MoveZ, F("Home Z"));
  1115. else {
  1116. Popup_Handler(Home);
  1117. gcode.process_subcommands_now(F("G28 Z"));
  1118. planner.synchronize();
  1119. Redraw_Menu();
  1120. }
  1121. break;
  1122. case HOME_SET:
  1123. if (draw)
  1124. Draw_Menu_Item(row, ICON_SetHome, F("Set Home Position"));
  1125. else {
  1126. gcode.process_subcommands_now(F("G92X0Y0Z0"));
  1127. AudioFeedback();
  1128. }
  1129. break;
  1130. }
  1131. break;
  1132. case Move:
  1133. #define MOVE_BACK 0
  1134. #define MOVE_X (MOVE_BACK + 1)
  1135. #define MOVE_Y (MOVE_X + 1)
  1136. #define MOVE_Z (MOVE_Y + 1)
  1137. #define MOVE_E (MOVE_Z + ENABLED(HAS_HOTEND))
  1138. #define MOVE_P (MOVE_E + ENABLED(HAS_BED_PROBE))
  1139. #define MOVE_LIVE (MOVE_P + 1)
  1140. #define MOVE_TOTAL MOVE_LIVE
  1141. switch (item) {
  1142. case MOVE_BACK:
  1143. if (draw)
  1144. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1145. else {
  1146. #if HAS_BED_PROBE
  1147. probe_deployed = false;
  1148. probe.set_deployed(probe_deployed);
  1149. #endif
  1150. Draw_Menu(Prepare, PREPARE_MOVE);
  1151. }
  1152. break;
  1153. case MOVE_X:
  1154. if (draw) {
  1155. Draw_Menu_Item(row, ICON_MoveX, F("Move X"));
  1156. Draw_Float(current_position.x, row, false);
  1157. }
  1158. else
  1159. Modify_Value(current_position.x, X_MIN_POS, X_MAX_POS, 10);
  1160. break;
  1161. case MOVE_Y:
  1162. if (draw) {
  1163. Draw_Menu_Item(row, ICON_MoveY, F("Move Y"));
  1164. Draw_Float(current_position.y, row);
  1165. }
  1166. else
  1167. Modify_Value(current_position.y, Y_MIN_POS, Y_MAX_POS, 10);
  1168. break;
  1169. case MOVE_Z:
  1170. if (draw) {
  1171. Draw_Menu_Item(row, ICON_MoveZ, F("Move Z"));
  1172. Draw_Float(current_position.z, row);
  1173. }
  1174. else
  1175. Modify_Value(current_position.z, Z_MIN_POS, Z_MAX_POS, 10);
  1176. break;
  1177. #if HAS_HOTEND
  1178. case MOVE_E:
  1179. if (draw) {
  1180. Draw_Menu_Item(row, ICON_Extruder, F("Extruder"));
  1181. current_position.e = 0;
  1182. sync_plan_position();
  1183. Draw_Float(current_position.e, row);
  1184. }
  1185. else {
  1186. if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) {
  1187. Popup_Handler(ETemp);
  1188. }
  1189. else {
  1190. if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
  1191. Popup_Handler(Heating);
  1192. thermalManager.wait_for_hotend(0);
  1193. Redraw_Menu();
  1194. }
  1195. current_position.e = 0;
  1196. sync_plan_position();
  1197. Modify_Value(current_position.e, -500, 500, 10);
  1198. }
  1199. }
  1200. break;
  1201. #endif // HAS_HOTEND
  1202. #if HAS_BED_PROBE
  1203. case MOVE_P:
  1204. if (draw) {
  1205. Draw_Menu_Item(row, ICON_StockConfiguration, F("Probe"));
  1206. Draw_Checkbox(row, probe_deployed);
  1207. }
  1208. else {
  1209. probe_deployed = !probe_deployed;
  1210. probe.set_deployed(probe_deployed);
  1211. Draw_Checkbox(row, probe_deployed);
  1212. }
  1213. break;
  1214. #endif
  1215. case MOVE_LIVE:
  1216. if (draw) {
  1217. Draw_Menu_Item(row, ICON_Axis, F("Live Movement"));
  1218. Draw_Checkbox(row, livemove);
  1219. }
  1220. else {
  1221. livemove = !livemove;
  1222. Draw_Checkbox(row, livemove);
  1223. }
  1224. break;
  1225. }
  1226. break;
  1227. case ManualLevel:
  1228. #define MLEVEL_BACK 0
  1229. #define MLEVEL_PROBE (MLEVEL_BACK + ENABLED(HAS_BED_PROBE))
  1230. #define MLEVEL_BL (MLEVEL_PROBE + 1)
  1231. #define MLEVEL_TL (MLEVEL_BL + 1)
  1232. #define MLEVEL_TR (MLEVEL_TL + 1)
  1233. #define MLEVEL_BR (MLEVEL_TR + 1)
  1234. #define MLEVEL_C (MLEVEL_BR + 1)
  1235. #define MLEVEL_ZPOS (MLEVEL_C + 1)
  1236. #define MLEVEL_TOTAL MLEVEL_ZPOS
  1237. static float mlev_z_pos = 0;
  1238. static bool use_probe = false;
  1239. switch (item) {
  1240. case MLEVEL_BACK:
  1241. if (draw)
  1242. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1243. else {
  1244. TERN_(HAS_LEVELING, set_bed_leveling_enabled(level_state));
  1245. Draw_Menu(Prepare, PREPARE_MANUALLEVEL);
  1246. }
  1247. break;
  1248. #if HAS_BED_PROBE
  1249. case MLEVEL_PROBE:
  1250. if (draw) {
  1251. Draw_Menu_Item(row, ICON_Zoffset, F("Use Probe"));
  1252. Draw_Checkbox(row, use_probe);
  1253. }
  1254. else {
  1255. use_probe = !use_probe;
  1256. Draw_Checkbox(row, use_probe);
  1257. if (use_probe) {
  1258. Popup_Handler(Level);
  1259. corner_avg = 0;
  1260. #define PROBE_X_MIN _MAX(0 + corner_pos, X_MIN_POS + probe.offset.x, X_MIN_POS + PROBING_MARGIN) - probe.offset.x
  1261. #define PROBE_X_MAX _MIN((X_BED_SIZE + X_MIN_POS) - corner_pos, X_MAX_POS + probe.offset.x, X_MAX_POS - PROBING_MARGIN) - probe.offset.x
  1262. #define PROBE_Y_MIN _MAX(0 + corner_pos, Y_MIN_POS + probe.offset.y, Y_MIN_POS + PROBING_MARGIN) - probe.offset.y
  1263. #define PROBE_Y_MAX _MIN((Y_BED_SIZE + Y_MIN_POS) - corner_pos, Y_MAX_POS + probe.offset.y, Y_MAX_POS - PROBING_MARGIN) - probe.offset.y
  1264. corner_avg += probe.probe_at_point(PROBE_X_MIN, PROBE_Y_MIN, PROBE_PT_RAISE, 0, false);
  1265. corner_avg += probe.probe_at_point(PROBE_X_MIN, PROBE_Y_MAX, PROBE_PT_RAISE, 0, false);
  1266. corner_avg += probe.probe_at_point(PROBE_X_MAX, PROBE_Y_MAX, PROBE_PT_RAISE, 0, false);
  1267. corner_avg += probe.probe_at_point(PROBE_X_MAX, PROBE_Y_MIN, PROBE_PT_STOW, 0, false);
  1268. corner_avg /= 4;
  1269. Redraw_Menu();
  1270. }
  1271. }
  1272. break;
  1273. #endif
  1274. case MLEVEL_BL:
  1275. if (draw)
  1276. Draw_Menu_Item(row, ICON_AxisBL, F("Bottom Left"));
  1277. else {
  1278. Popup_Handler(MoveWait);
  1279. if (use_probe) {
  1280. #if HAS_BED_PROBE
  1281. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(PROBE_X_MIN, 1, 3, str_1), dtostrf(PROBE_Y_MIN, 1, 3, str_2));
  1282. gcode.process_subcommands_now(cmd);
  1283. planner.synchronize();
  1284. Popup_Handler(ManualProbing);
  1285. #endif
  1286. }
  1287. else {
  1288. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s\nG0 F300 Z%s"), dtostrf(corner_pos, 1, 3, str_1), dtostrf(corner_pos, 1, 3, str_2), dtostrf(mlev_z_pos, 1, 3, str_3));
  1289. gcode.process_subcommands_now(cmd);
  1290. planner.synchronize();
  1291. Redraw_Menu();
  1292. }
  1293. }
  1294. break;
  1295. case MLEVEL_TL:
  1296. if (draw)
  1297. Draw_Menu_Item(row, ICON_AxisTL, F("Top Left"));
  1298. else {
  1299. Popup_Handler(MoveWait);
  1300. if (use_probe) {
  1301. #if HAS_BED_PROBE
  1302. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(PROBE_X_MIN, 1, 3, str_1), dtostrf(PROBE_Y_MAX, 1, 3, str_2));
  1303. gcode.process_subcommands_now(cmd);
  1304. planner.synchronize();
  1305. Popup_Handler(ManualProbing);
  1306. #endif
  1307. }
  1308. else {
  1309. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s\nG0 F300 Z%s"), dtostrf(corner_pos, 1, 3, str_1), dtostrf((Y_BED_SIZE + Y_MIN_POS) - corner_pos, 1, 3, str_2), dtostrf(mlev_z_pos, 1, 3, str_3));
  1310. gcode.process_subcommands_now(cmd);
  1311. planner.synchronize();
  1312. Redraw_Menu();
  1313. }
  1314. }
  1315. break;
  1316. case MLEVEL_TR:
  1317. if (draw)
  1318. Draw_Menu_Item(row, ICON_AxisTR, F("Top Right"));
  1319. else {
  1320. Popup_Handler(MoveWait);
  1321. if (use_probe) {
  1322. #if HAS_BED_PROBE
  1323. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(PROBE_X_MAX, 1, 3, str_1), dtostrf(PROBE_Y_MAX, 1, 3, str_2));
  1324. gcode.process_subcommands_now(cmd);
  1325. planner.synchronize();
  1326. Popup_Handler(ManualProbing);
  1327. #endif
  1328. }
  1329. else {
  1330. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s\nG0 F300 Z%s"), dtostrf((X_BED_SIZE + X_MIN_POS) - corner_pos, 1, 3, str_1), dtostrf((Y_BED_SIZE + Y_MIN_POS) - corner_pos, 1, 3, str_2), dtostrf(mlev_z_pos, 1, 3, str_3));
  1331. gcode.process_subcommands_now(cmd);
  1332. planner.synchronize();
  1333. Redraw_Menu();
  1334. }
  1335. }
  1336. break;
  1337. case MLEVEL_BR:
  1338. if (draw)
  1339. Draw_Menu_Item(row, ICON_AxisBR, F("Bottom Right"));
  1340. else {
  1341. Popup_Handler(MoveWait);
  1342. if (use_probe) {
  1343. #if HAS_BED_PROBE
  1344. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(PROBE_X_MAX, 1, 3, str_1), dtostrf(PROBE_Y_MIN, 1, 3, str_2));
  1345. gcode.process_subcommands_now(cmd);
  1346. planner.synchronize();
  1347. Popup_Handler(ManualProbing);
  1348. #endif
  1349. }
  1350. else {
  1351. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s\nG0 F300 Z%s"), dtostrf((X_BED_SIZE + X_MIN_POS) - corner_pos, 1, 3, str_1), dtostrf(corner_pos, 1, 3, str_2), dtostrf(mlev_z_pos, 1, 3, str_3));
  1352. gcode.process_subcommands_now(cmd);
  1353. planner.synchronize();
  1354. Redraw_Menu();
  1355. }
  1356. }
  1357. break;
  1358. case MLEVEL_C:
  1359. if (draw)
  1360. Draw_Menu_Item(row, ICON_AxisC, F("Center"));
  1361. else {
  1362. Popup_Handler(MoveWait);
  1363. if (use_probe) {
  1364. #if HAS_BED_PROBE
  1365. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(X_MAX_POS / 2.0f - probe.offset.x, 1, 3, str_1), dtostrf(Y_MAX_POS / 2.0f - probe.offset.y, 1, 3, str_2));
  1366. gcode.process_subcommands_now(cmd);
  1367. planner.synchronize();
  1368. Popup_Handler(ManualProbing);
  1369. #endif
  1370. }
  1371. else {
  1372. sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s\nG0 F300 Z%s"), dtostrf((X_BED_SIZE + X_MIN_POS) / 2.0f, 1, 3, str_1), dtostrf((Y_BED_SIZE + Y_MIN_POS) / 2.0f, 1, 3, str_2), dtostrf(mlev_z_pos, 1, 3, str_3));
  1373. gcode.process_subcommands_now(cmd);
  1374. planner.synchronize();
  1375. Redraw_Menu();
  1376. }
  1377. }
  1378. break;
  1379. case MLEVEL_ZPOS:
  1380. if (draw) {
  1381. Draw_Menu_Item(row, ICON_SetZOffset, F("Z Position"));
  1382. Draw_Float(mlev_z_pos, row, false, 100);
  1383. }
  1384. else
  1385. Modify_Value(mlev_z_pos, 0, MAX_Z_OFFSET, 100);
  1386. break;
  1387. }
  1388. break;
  1389. #if HAS_ZOFFSET_ITEM
  1390. case ZOffset:
  1391. #define ZOFFSET_BACK 0
  1392. #define ZOFFSET_HOME (ZOFFSET_BACK + 1)
  1393. #define ZOFFSET_MODE (ZOFFSET_HOME + 1)
  1394. #define ZOFFSET_OFFSET (ZOFFSET_MODE + 1)
  1395. #define ZOFFSET_UP (ZOFFSET_OFFSET + 1)
  1396. #define ZOFFSET_DOWN (ZOFFSET_UP + 1)
  1397. #define ZOFFSET_SAVE (ZOFFSET_DOWN + ENABLED(EEPROM_SETTINGS))
  1398. #define ZOFFSET_TOTAL ZOFFSET_SAVE
  1399. switch (item) {
  1400. case ZOFFSET_BACK:
  1401. if (draw)
  1402. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1403. else {
  1404. liveadjust = false;
  1405. TERN_(HAS_LEVELING, set_bed_leveling_enabled(level_state));
  1406. Draw_Menu(Prepare, PREPARE_ZOFFSET);
  1407. }
  1408. break;
  1409. case ZOFFSET_HOME:
  1410. if (draw)
  1411. Draw_Menu_Item(row, ICON_Homing, F("Home Z Axis"));
  1412. else {
  1413. Popup_Handler(Home);
  1414. gcode.process_subcommands_now(F("G28 Z"));
  1415. Popup_Handler(MoveWait);
  1416. #if ENABLED(Z_SAFE_HOMING)
  1417. planner.synchronize();
  1418. sprintf_P(cmd, PSTR("G0 F4000 X%s Y%s"), dtostrf(Z_SAFE_HOMING_X_POINT, 1, 3, str_1), dtostrf(Z_SAFE_HOMING_Y_POINT, 1, 3, str_2));
  1419. gcode.process_subcommands_now(cmd);
  1420. #else
  1421. gcode.process_subcommands_now(F("G0 F4000 X117.5 Y117.5"));
  1422. #endif
  1423. gcode.process_subcommands_now(F("G0 F300 Z0"));
  1424. planner.synchronize();
  1425. Redraw_Menu();
  1426. }
  1427. break;
  1428. case ZOFFSET_MODE:
  1429. if (draw) {
  1430. Draw_Menu_Item(row, ICON_Zoffset, F("Live Adjustment"));
  1431. Draw_Checkbox(row, liveadjust);
  1432. }
  1433. else {
  1434. if (!liveadjust) {
  1435. if (axes_should_home()) {
  1436. Popup_Handler(Home);
  1437. gcode.home_all_axes(true);
  1438. }
  1439. Popup_Handler(MoveWait);
  1440. #if ENABLED(Z_SAFE_HOMING)
  1441. planner.synchronize();
  1442. sprintf_P(cmd, PSTR("G0 F4000 X%s Y%s"), dtostrf(Z_SAFE_HOMING_X_POINT, 1, 3, str_1), dtostrf(Z_SAFE_HOMING_Y_POINT, 1, 3, str_2));
  1443. gcode.process_subcommands_now(cmd);
  1444. #else
  1445. gcode.process_subcommands_now(F("G0 F4000 X117.5 Y117.5"));
  1446. #endif
  1447. gcode.process_subcommands_now(F("G0 F300 Z0"));
  1448. planner.synchronize();
  1449. Redraw_Menu();
  1450. }
  1451. liveadjust = !liveadjust;
  1452. Draw_Checkbox(row, liveadjust);
  1453. }
  1454. break;
  1455. case ZOFFSET_OFFSET:
  1456. if (draw) {
  1457. Draw_Menu_Item(row, ICON_SetZOffset, F("Z Offset"));
  1458. Draw_Float(zoffsetvalue, row, false, 100);
  1459. }
  1460. else
  1461. Modify_Value(zoffsetvalue, MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
  1462. break;
  1463. case ZOFFSET_UP:
  1464. if (draw)
  1465. Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
  1466. else {
  1467. if (zoffsetvalue < MAX_Z_OFFSET) {
  1468. if (liveadjust) {
  1469. gcode.process_subcommands_now(F("M290 Z0.01"));
  1470. planner.synchronize();
  1471. }
  1472. zoffsetvalue += 0.01;
  1473. Draw_Float(zoffsetvalue, row - 1, false, 100);
  1474. }
  1475. }
  1476. break;
  1477. case ZOFFSET_DOWN:
  1478. if (draw)
  1479. Draw_Menu_Item(row, ICON_AxisD, F("Microstep Down"));
  1480. else {
  1481. if (zoffsetvalue > MIN_Z_OFFSET) {
  1482. if (liveadjust) {
  1483. gcode.process_subcommands_now(F("M290 Z-0.01"));
  1484. planner.synchronize();
  1485. }
  1486. zoffsetvalue -= 0.01;
  1487. Draw_Float(zoffsetvalue, row - 2, false, 100);
  1488. }
  1489. }
  1490. break;
  1491. #if ENABLED(EEPROM_SETTINGS)
  1492. case ZOFFSET_SAVE:
  1493. if (draw)
  1494. Draw_Menu_Item(row, ICON_WriteEEPROM, F("Save"));
  1495. else
  1496. AudioFeedback(settings.save());
  1497. break;
  1498. #endif
  1499. }
  1500. break;
  1501. #endif
  1502. #if HAS_PREHEAT
  1503. case Preheat: {
  1504. #define PREHEAT_MODE (PREHEAT_BACK + 1)
  1505. #define PREHEAT_1 (PREHEAT_MODE + 1)
  1506. #define PREHEAT_2 (PREHEAT_1 + (PREHEAT_COUNT >= 2))
  1507. #define PREHEAT_3 (PREHEAT_2 + (PREHEAT_COUNT >= 3))
  1508. #define PREHEAT_4 (PREHEAT_3 + (PREHEAT_COUNT >= 4))
  1509. #define PREHEAT_5 (PREHEAT_4 + (PREHEAT_COUNT >= 5))
  1510. #define PREHEAT_TOTAL PREHEAT_5
  1511. auto do_preheat = [](const uint8_t m) {
  1512. thermalManager.cooldown();
  1513. if (preheatmode == 0 || preheatmode == 1) { ui.preheat_hotend_and_fan(m); }
  1514. if (preheatmode == 0 || preheatmode == 2) ui.preheat_bed(m);
  1515. };
  1516. switch (item) {
  1517. case PREHEAT_BACK:
  1518. if (draw)
  1519. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1520. else
  1521. Draw_Menu(Prepare, PREPARE_PREHEAT);
  1522. break;
  1523. case PREHEAT_MODE:
  1524. if (draw) {
  1525. Draw_Menu_Item(row, ICON_Homing, F("Preheat Mode"));
  1526. Draw_Option(preheatmode, preheat_modes, row);
  1527. }
  1528. else
  1529. Modify_Option(preheatmode, preheat_modes, 2);
  1530. break;
  1531. #define _PREHEAT_CASE(N) \
  1532. case PREHEAT_##N: { \
  1533. if (draw) Draw_Menu_Item(row, ICON_Temperature, F(PREHEAT_## N ##_LABEL)); \
  1534. else do_preheat(N - 1); \
  1535. } break;
  1536. REPEAT_1(PREHEAT_COUNT, _PREHEAT_CASE)
  1537. }
  1538. } break;
  1539. #endif // HAS_PREHEAT
  1540. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  1541. case ChangeFilament:
  1542. #define CHANGEFIL_BACK 0
  1543. #define CHANGEFIL_LOAD (CHANGEFIL_BACK + 1)
  1544. #define CHANGEFIL_UNLOAD (CHANGEFIL_LOAD + 1)
  1545. #define CHANGEFIL_CHANGE (CHANGEFIL_UNLOAD + 1)
  1546. #define CHANGEFIL_TOTAL CHANGEFIL_CHANGE
  1547. switch (item) {
  1548. case CHANGEFIL_BACK:
  1549. if (draw)
  1550. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1551. else
  1552. Draw_Menu(Prepare, PREPARE_CHANGEFIL);
  1553. break;
  1554. case CHANGEFIL_LOAD:
  1555. if (draw)
  1556. Draw_Menu_Item(row, ICON_WriteEEPROM, F("Load Filament"));
  1557. else {
  1558. if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
  1559. Popup_Handler(ETemp);
  1560. else {
  1561. if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
  1562. Popup_Handler(Heating);
  1563. thermalManager.wait_for_hotend(0);
  1564. }
  1565. Popup_Handler(FilLoad);
  1566. gcode.process_subcommands_now(F("M701"));
  1567. planner.synchronize();
  1568. Redraw_Menu();
  1569. }
  1570. }
  1571. break;
  1572. case CHANGEFIL_UNLOAD:
  1573. if (draw)
  1574. Draw_Menu_Item(row, ICON_ReadEEPROM, F("Unload Filament"));
  1575. else {
  1576. if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) {
  1577. Popup_Handler(ETemp);
  1578. }
  1579. else {
  1580. if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
  1581. Popup_Handler(Heating);
  1582. thermalManager.wait_for_hotend(0);
  1583. }
  1584. Popup_Handler(FilLoad, true);
  1585. gcode.process_subcommands_now(F("M702"));
  1586. planner.synchronize();
  1587. Redraw_Menu();
  1588. }
  1589. }
  1590. break;
  1591. case CHANGEFIL_CHANGE:
  1592. if (draw)
  1593. Draw_Menu_Item(row, ICON_ResumeEEPROM, F("Change Filament"));
  1594. else {
  1595. if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
  1596. Popup_Handler(ETemp);
  1597. else {
  1598. if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
  1599. Popup_Handler(Heating);
  1600. thermalManager.wait_for_hotend(0);
  1601. }
  1602. Popup_Handler(FilChange);
  1603. sprintf_P(cmd, PSTR("M600 B1 R%i"), thermalManager.temp_hotend[0].target);
  1604. gcode.process_subcommands_now(cmd);
  1605. }
  1606. }
  1607. break;
  1608. }
  1609. break;
  1610. #endif // FILAMENT_LOAD_UNLOAD_GCODES
  1611. case Control:
  1612. #define CONTROL_BACK 0
  1613. #define CONTROL_TEMP (CONTROL_BACK + 1)
  1614. #define CONTROL_MOTION (CONTROL_TEMP + 1)
  1615. #define CONTROL_VISUAL (CONTROL_MOTION + 1)
  1616. #define CONTROL_ADVANCED (CONTROL_VISUAL + 1)
  1617. #define CONTROL_SAVE (CONTROL_ADVANCED + ENABLED(EEPROM_SETTINGS))
  1618. #define CONTROL_RESTORE (CONTROL_SAVE + ENABLED(EEPROM_SETTINGS))
  1619. #define CONTROL_RESET (CONTROL_RESTORE + ENABLED(EEPROM_SETTINGS))
  1620. #define CONTROL_INFO (CONTROL_RESET + 1)
  1621. #define CONTROL_TOTAL CONTROL_INFO
  1622. switch (item) {
  1623. case CONTROL_BACK:
  1624. if (draw)
  1625. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1626. else
  1627. Draw_Main_Menu(2);
  1628. break;
  1629. case CONTROL_TEMP:
  1630. if (draw)
  1631. Draw_Menu_Item(row, ICON_Temperature, F("Temperature"), nullptr, true);
  1632. else
  1633. Draw_Menu(TempMenu);
  1634. break;
  1635. case CONTROL_MOTION:
  1636. if (draw)
  1637. Draw_Menu_Item(row, ICON_Motion, F("Motion"), nullptr, true);
  1638. else
  1639. Draw_Menu(Motion);
  1640. break;
  1641. case CONTROL_VISUAL:
  1642. if (draw)
  1643. Draw_Menu_Item(row, ICON_PrintSize, F("Visual"), nullptr, true);
  1644. else
  1645. Draw_Menu(Visual);
  1646. break;
  1647. case CONTROL_ADVANCED:
  1648. if (draw)
  1649. Draw_Menu_Item(row, ICON_Version, F("Advanced"), nullptr, true);
  1650. else
  1651. Draw_Menu(Advanced);
  1652. break;
  1653. #if ENABLED(EEPROM_SETTINGS)
  1654. case CONTROL_SAVE:
  1655. if (draw)
  1656. Draw_Menu_Item(row, ICON_WriteEEPROM, F("Store Settings"));
  1657. else
  1658. AudioFeedback(settings.save());
  1659. break;
  1660. case CONTROL_RESTORE:
  1661. if (draw)
  1662. Draw_Menu_Item(row, ICON_ReadEEPROM, F("Restore Settings"));
  1663. else
  1664. AudioFeedback(settings.load());
  1665. break;
  1666. case CONTROL_RESET:
  1667. if (draw)
  1668. Draw_Menu_Item(row, ICON_Temperature, F("Reset to Defaults"));
  1669. else {
  1670. settings.reset();
  1671. AudioFeedback();
  1672. }
  1673. break;
  1674. #endif
  1675. case CONTROL_INFO:
  1676. if (draw)
  1677. Draw_Menu_Item(row, ICON_Info, F("Info"));
  1678. else
  1679. Draw_Menu(Info);
  1680. break;
  1681. }
  1682. break;
  1683. case TempMenu:
  1684. #define TEMP_BACK 0
  1685. #define TEMP_HOTEND (TEMP_BACK + ENABLED(HAS_HOTEND))
  1686. #define TEMP_BED (TEMP_HOTEND + ENABLED(HAS_HEATED_BED))
  1687. #define TEMP_FAN (TEMP_BED + ENABLED(HAS_FAN))
  1688. #define TEMP_PID (TEMP_FAN + ANY(HAS_HOTEND, HAS_HEATED_BED))
  1689. #define TEMP_PREHEAT1 (TEMP_PID + (PREHEAT_COUNT >= 1))
  1690. #define TEMP_PREHEAT2 (TEMP_PREHEAT1 + (PREHEAT_COUNT >= 2))
  1691. #define TEMP_PREHEAT3 (TEMP_PREHEAT2 + (PREHEAT_COUNT >= 3))
  1692. #define TEMP_PREHEAT4 (TEMP_PREHEAT3 + (PREHEAT_COUNT >= 4))
  1693. #define TEMP_PREHEAT5 (TEMP_PREHEAT4 + (PREHEAT_COUNT >= 5))
  1694. #define TEMP_TOTAL TEMP_PREHEAT5
  1695. switch (item) {
  1696. case TEMP_BACK:
  1697. if (draw)
  1698. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1699. else
  1700. Draw_Menu(Control, CONTROL_TEMP);
  1701. break;
  1702. #if HAS_HOTEND
  1703. case TEMP_HOTEND:
  1704. if (draw) {
  1705. Draw_Menu_Item(row, ICON_SetEndTemp, F("Hotend"));
  1706. Draw_Float(thermalManager.temp_hotend[0].target, row, false, 1);
  1707. }
  1708. else
  1709. Modify_Value(thermalManager.temp_hotend[0].target, MIN_E_TEMP, MAX_E_TEMP, 1);
  1710. break;
  1711. #endif
  1712. #if HAS_HEATED_BED
  1713. case TEMP_BED:
  1714. if (draw) {
  1715. Draw_Menu_Item(row, ICON_SetBedTemp, F("Bed"));
  1716. Draw_Float(thermalManager.temp_bed.target, row, false, 1);
  1717. }
  1718. else
  1719. Modify_Value(thermalManager.temp_bed.target, MIN_BED_TEMP, MAX_BED_TEMP, 1);
  1720. break;
  1721. #endif
  1722. #if HAS_FAN
  1723. case TEMP_FAN:
  1724. if (draw) {
  1725. Draw_Menu_Item(row, ICON_FanSpeed, F("Fan"));
  1726. Draw_Float(thermalManager.fan_speed[0], row, false, 1);
  1727. }
  1728. else
  1729. Modify_Value(thermalManager.fan_speed[0], MIN_FAN_SPEED, MAX_FAN_SPEED, 1);
  1730. break;
  1731. #endif
  1732. #if HAS_HOTEND || HAS_HEATED_BED
  1733. case TEMP_PID:
  1734. if (draw)
  1735. Draw_Menu_Item(row, ICON_Step, F("PID"), nullptr, true);
  1736. else
  1737. Draw_Menu(PID);
  1738. break;
  1739. #endif
  1740. #define _TEMP_PREHEAT_CASE(N) \
  1741. case TEMP_PREHEAT##N: { \
  1742. if (draw) Draw_Menu_Item(row, ICON_Step, F(PREHEAT_## N ##_LABEL), nullptr, true); \
  1743. else Draw_Menu(Preheat##N); \
  1744. } break;
  1745. REPEAT_1(PREHEAT_COUNT, _TEMP_PREHEAT_CASE)
  1746. }
  1747. break;
  1748. #if HAS_HOTEND || HAS_HEATED_BED
  1749. case PID:
  1750. #define PID_BACK 0
  1751. #define PID_HOTEND (PID_BACK + ENABLED(HAS_HOTEND))
  1752. #define PID_BED (PID_HOTEND + ENABLED(HAS_HEATED_BED))
  1753. #define PID_CYCLES (PID_BED + 1)
  1754. #define PID_TOTAL PID_CYCLES
  1755. static uint8_t PID_cycles = 5;
  1756. switch (item) {
  1757. case PID_BACK:
  1758. if (draw)
  1759. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1760. else
  1761. Draw_Menu(TempMenu, TEMP_PID);
  1762. break;
  1763. #if HAS_HOTEND
  1764. case PID_HOTEND:
  1765. if (draw)
  1766. Draw_Menu_Item(row, ICON_HotendTemp, F("Hotend"), nullptr, true);
  1767. else
  1768. Draw_Menu(HotendPID);
  1769. break;
  1770. #endif
  1771. #if HAS_HEATED_BED
  1772. case PID_BED:
  1773. if (draw)
  1774. Draw_Menu_Item(row, ICON_BedTemp, F("Bed"), nullptr, true);
  1775. else
  1776. Draw_Menu(BedPID);
  1777. break;
  1778. #endif
  1779. case PID_CYCLES:
  1780. if (draw) {
  1781. Draw_Menu_Item(row, ICON_FanSpeed, F("Cycles"));
  1782. Draw_Float(PID_cycles, row, false, 1);
  1783. }
  1784. else
  1785. Modify_Value(PID_cycles, 3, 50, 1);
  1786. break;
  1787. }
  1788. break;
  1789. #endif // HAS_HOTEND || HAS_HEATED_BED
  1790. #if HAS_HOTEND
  1791. case HotendPID:
  1792. #define HOTENDPID_BACK 0
  1793. #define HOTENDPID_TUNE (HOTENDPID_BACK + 1)
  1794. #define HOTENDPID_TEMP (HOTENDPID_TUNE + 1)
  1795. #define HOTENDPID_KP (HOTENDPID_TEMP + 1)
  1796. #define HOTENDPID_KI (HOTENDPID_KP + 1)
  1797. #define HOTENDPID_KD (HOTENDPID_KI + 1)
  1798. #define HOTENDPID_TOTAL HOTENDPID_KD
  1799. static uint16_t PID_e_temp = 180;
  1800. switch (item) {
  1801. case HOTENDPID_BACK:
  1802. if (draw)
  1803. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1804. else
  1805. Draw_Menu(PID, PID_HOTEND);
  1806. break;
  1807. case HOTENDPID_TUNE:
  1808. if (draw)
  1809. Draw_Menu_Item(row, ICON_HotendTemp, F("Autotune"));
  1810. else {
  1811. Popup_Handler(PIDWait);
  1812. sprintf_P(cmd, PSTR("M303 E0 C%i S%i U1"), PID_cycles, PID_e_temp);
  1813. gcode.process_subcommands_now(cmd);
  1814. planner.synchronize();
  1815. Redraw_Menu();
  1816. }
  1817. break;
  1818. case HOTENDPID_TEMP:
  1819. if (draw) {
  1820. Draw_Menu_Item(row, ICON_Temperature, F("Temperature"));
  1821. Draw_Float(PID_e_temp, row, false, 1);
  1822. }
  1823. else
  1824. Modify_Value(PID_e_temp, MIN_E_TEMP, MAX_E_TEMP, 1);
  1825. break;
  1826. case HOTENDPID_KP:
  1827. if (draw) {
  1828. Draw_Menu_Item(row, ICON_Version, F("Kp Value"));
  1829. Draw_Float(thermalManager.temp_hotend[0].pid.Kp, row, false, 100);
  1830. }
  1831. else
  1832. Modify_Value(thermalManager.temp_hotend[0].pid.Kp, 0, 5000, 100, thermalManager.updatePID);
  1833. break;
  1834. case HOTENDPID_KI:
  1835. if (draw) {
  1836. Draw_Menu_Item(row, ICON_Version, F("Ki Value"));
  1837. Draw_Float(unscalePID_i(thermalManager.temp_hotend[0].pid.Ki), row, false, 100);
  1838. }
  1839. else
  1840. Modify_Value(thermalManager.temp_hotend[0].pid.Ki, 0, 5000, 100, thermalManager.updatePID);
  1841. break;
  1842. case HOTENDPID_KD:
  1843. if (draw) {
  1844. Draw_Menu_Item(row, ICON_Version, F("Kd Value"));
  1845. Draw_Float(unscalePID_d(thermalManager.temp_hotend[0].pid.Kd), row, false, 100);
  1846. }
  1847. else
  1848. Modify_Value(thermalManager.temp_hotend[0].pid.Kd, 0, 5000, 100, thermalManager.updatePID);
  1849. break;
  1850. }
  1851. break;
  1852. #endif // HAS_HOTEND
  1853. #if HAS_HEATED_BED
  1854. case BedPID:
  1855. #define BEDPID_BACK 0
  1856. #define BEDPID_TUNE (BEDPID_BACK + 1)
  1857. #define BEDPID_TEMP (BEDPID_TUNE + 1)
  1858. #define BEDPID_KP (BEDPID_TEMP + 1)
  1859. #define BEDPID_KI (BEDPID_KP + 1)
  1860. #define BEDPID_KD (BEDPID_KI + 1)
  1861. #define BEDPID_TOTAL BEDPID_KD
  1862. static uint16_t PID_bed_temp = 60;
  1863. switch (item) {
  1864. case BEDPID_BACK:
  1865. if (draw)
  1866. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1867. else
  1868. Draw_Menu(PID, PID_BED);
  1869. break;
  1870. case BEDPID_TUNE:
  1871. if (draw)
  1872. Draw_Menu_Item(row, ICON_HotendTemp, F("Autotune"));
  1873. else {
  1874. Popup_Handler(PIDWait);
  1875. sprintf_P(cmd, PSTR("M303 E-1 C%i S%i U1"), PID_cycles, PID_bed_temp);
  1876. gcode.process_subcommands_now(cmd);
  1877. planner.synchronize();
  1878. Redraw_Menu();
  1879. }
  1880. break;
  1881. case BEDPID_TEMP:
  1882. if (draw) {
  1883. Draw_Menu_Item(row, ICON_Temperature, F("Temperature"));
  1884. Draw_Float(PID_bed_temp, row, false, 1);
  1885. }
  1886. else
  1887. Modify_Value(PID_bed_temp, MIN_BED_TEMP, MAX_BED_TEMP, 1);
  1888. break;
  1889. case BEDPID_KP:
  1890. if (draw) {
  1891. Draw_Menu_Item(row, ICON_Version, F("Kp Value"));
  1892. Draw_Float(thermalManager.temp_bed.pid.Kp, row, false, 100);
  1893. }
  1894. else {
  1895. Modify_Value(thermalManager.temp_bed.pid.Kp, 0, 5000, 100, thermalManager.updatePID);
  1896. }
  1897. break;
  1898. case BEDPID_KI:
  1899. if (draw) {
  1900. Draw_Menu_Item(row, ICON_Version, F("Ki Value"));
  1901. Draw_Float(unscalePID_i(thermalManager.temp_bed.pid.Ki), row, false, 100);
  1902. }
  1903. else
  1904. Modify_Value(thermalManager.temp_bed.pid.Ki, 0, 5000, 100, thermalManager.updatePID);
  1905. break;
  1906. case BEDPID_KD:
  1907. if (draw) {
  1908. Draw_Menu_Item(row, ICON_Version, F("Kd Value"));
  1909. Draw_Float(unscalePID_d(thermalManager.temp_bed.pid.Kd), row, false, 100);
  1910. }
  1911. else
  1912. Modify_Value(thermalManager.temp_bed.pid.Kd, 0, 5000, 100, thermalManager.updatePID);
  1913. break;
  1914. }
  1915. break;
  1916. #endif // HAS_HEATED_BED
  1917. #if HAS_PREHEAT
  1918. #define _PREHEAT_SUBMENU_CASE(N) case Preheat##N: preheat_submenu((N) - 1, item, TEMP_PREHEAT##N); break;
  1919. REPEAT_1(PREHEAT_COUNT, _PREHEAT_SUBMENU_CASE)
  1920. #endif
  1921. case Motion:
  1922. #define MOTION_BACK 0
  1923. #define MOTION_HOMEOFFSETS (MOTION_BACK + 1)
  1924. #define MOTION_SPEED (MOTION_HOMEOFFSETS + 1)
  1925. #define MOTION_ACCEL (MOTION_SPEED + 1)
  1926. #define MOTION_JERK (MOTION_ACCEL + ENABLED(HAS_CLASSIC_JERK))
  1927. #define MOTION_STEPS (MOTION_JERK + 1)
  1928. #define MOTION_FLOW (MOTION_STEPS + ENABLED(HAS_HOTEND))
  1929. #define MOTION_TOTAL MOTION_FLOW
  1930. switch (item) {
  1931. case MOTION_BACK:
  1932. if (draw)
  1933. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1934. else
  1935. Draw_Menu(Control, CONTROL_MOTION);
  1936. break;
  1937. case MOTION_HOMEOFFSETS:
  1938. if (draw)
  1939. Draw_Menu_Item(row, ICON_SetHome, F("Home Offsets"), nullptr, true);
  1940. else
  1941. Draw_Menu(HomeOffsets);
  1942. break;
  1943. case MOTION_SPEED:
  1944. if (draw)
  1945. Draw_Menu_Item(row, ICON_MaxSpeed, F("Max Speed"), nullptr, true);
  1946. else
  1947. Draw_Menu(MaxSpeed);
  1948. break;
  1949. case MOTION_ACCEL:
  1950. if (draw)
  1951. Draw_Menu_Item(row, ICON_MaxAccelerated, F("Max Acceleration"), nullptr, true);
  1952. else
  1953. Draw_Menu(MaxAcceleration);
  1954. break;
  1955. #if HAS_CLASSIC_JERK
  1956. case MOTION_JERK:
  1957. if (draw)
  1958. Draw_Menu_Item(row, ICON_MaxJerk, F("Max Jerk"), nullptr, true);
  1959. else
  1960. Draw_Menu(MaxJerk);
  1961. break;
  1962. #endif
  1963. case MOTION_STEPS:
  1964. if (draw)
  1965. Draw_Menu_Item(row, ICON_Step, F("Steps/mm"), nullptr, true);
  1966. else
  1967. Draw_Menu(Steps);
  1968. break;
  1969. #if HAS_HOTEND
  1970. case MOTION_FLOW:
  1971. if (draw) {
  1972. Draw_Menu_Item(row, ICON_Speed, F("Flow Rate"));
  1973. Draw_Float(planner.flow_percentage[0], row, false, 1);
  1974. }
  1975. else
  1976. Modify_Value(planner.flow_percentage[0], MIN_FLOW_RATE, MAX_FLOW_RATE, 1);
  1977. break;
  1978. #endif
  1979. }
  1980. break;
  1981. case HomeOffsets:
  1982. #define HOMEOFFSETS_BACK 0
  1983. #define HOMEOFFSETS_XOFFSET (HOMEOFFSETS_BACK + 1)
  1984. #define HOMEOFFSETS_YOFFSET (HOMEOFFSETS_XOFFSET + 1)
  1985. #define HOMEOFFSETS_TOTAL HOMEOFFSETS_YOFFSET
  1986. switch (item) {
  1987. case HOMEOFFSETS_BACK:
  1988. if (draw)
  1989. Draw_Menu_Item(row, ICON_Back, F("Back"));
  1990. else
  1991. Draw_Menu(Motion, MOTION_HOMEOFFSETS);
  1992. break;
  1993. case HOMEOFFSETS_XOFFSET:
  1994. if (draw) {
  1995. Draw_Menu_Item(row, ICON_StepX, F("X Offset"));
  1996. Draw_Float(home_offset.x, row, false, 100);
  1997. }
  1998. else
  1999. Modify_Value(home_offset.x, -MAX_XY_OFFSET, MAX_XY_OFFSET, 100);
  2000. break;
  2001. case HOMEOFFSETS_YOFFSET:
  2002. if (draw) {
  2003. Draw_Menu_Item(row, ICON_StepY, F("Y Offset"));
  2004. Draw_Float(home_offset.y, row, false, 100);
  2005. }
  2006. else
  2007. Modify_Value(home_offset.y, -MAX_XY_OFFSET, MAX_XY_OFFSET, 100);
  2008. break;
  2009. }
  2010. break;
  2011. case MaxSpeed:
  2012. #define SPEED_BACK 0
  2013. #define SPEED_X (SPEED_BACK + 1)
  2014. #define SPEED_Y (SPEED_X + 1)
  2015. #define SPEED_Z (SPEED_Y + 1)
  2016. #define SPEED_E (SPEED_Z + ENABLED(HAS_HOTEND))
  2017. #define SPEED_TOTAL SPEED_E
  2018. switch (item) {
  2019. case SPEED_BACK:
  2020. if (draw)
  2021. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2022. else
  2023. Draw_Menu(Motion, MOTION_SPEED);
  2024. break;
  2025. case SPEED_X:
  2026. if (draw) {
  2027. Draw_Menu_Item(row, ICON_MaxSpeedX, F("X Axis"));
  2028. Draw_Float(planner.settings.max_feedrate_mm_s[X_AXIS], row, false, 1);
  2029. }
  2030. else
  2031. Modify_Value(planner.settings.max_feedrate_mm_s[X_AXIS], 0, default_max_feedrate[X_AXIS] * 2, 1);
  2032. break;
  2033. #if HAS_Y_AXIS
  2034. case SPEED_Y:
  2035. if (draw) {
  2036. Draw_Menu_Item(row, ICON_MaxSpeedY, F("Y Axis"));
  2037. Draw_Float(planner.settings.max_feedrate_mm_s[Y_AXIS], row, false, 1);
  2038. }
  2039. else
  2040. Modify_Value(planner.settings.max_feedrate_mm_s[Y_AXIS], 0, default_max_feedrate[Y_AXIS] * 2, 1);
  2041. break;
  2042. #endif
  2043. #if HAS_Z_AXIS
  2044. case SPEED_Z:
  2045. if (draw) {
  2046. Draw_Menu_Item(row, ICON_MaxSpeedZ, F("Z Axis"));
  2047. Draw_Float(planner.settings.max_feedrate_mm_s[Z_AXIS], row, false, 1);
  2048. }
  2049. else
  2050. Modify_Value(planner.settings.max_feedrate_mm_s[Z_AXIS], 0, default_max_feedrate[Z_AXIS] * 2, 1);
  2051. break;
  2052. #endif
  2053. #if HAS_HOTEND
  2054. case SPEED_E:
  2055. if (draw) {
  2056. Draw_Menu_Item(row, ICON_MaxSpeedE, F("Extruder"));
  2057. Draw_Float(planner.settings.max_feedrate_mm_s[E_AXIS], row, false, 1);
  2058. }
  2059. else
  2060. Modify_Value(planner.settings.max_feedrate_mm_s[E_AXIS], 0, default_max_feedrate[E_AXIS] * 2, 1);
  2061. break;
  2062. #endif
  2063. }
  2064. break;
  2065. case MaxAcceleration:
  2066. #define ACCEL_BACK 0
  2067. #define ACCEL_X (ACCEL_BACK + 1)
  2068. #define ACCEL_Y (ACCEL_X + 1)
  2069. #define ACCEL_Z (ACCEL_Y + 1)
  2070. #define ACCEL_E (ACCEL_Z + ENABLED(HAS_HOTEND))
  2071. #define ACCEL_TOTAL ACCEL_E
  2072. switch (item) {
  2073. case ACCEL_BACK:
  2074. if (draw)
  2075. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2076. else
  2077. Draw_Menu(Motion, MOTION_ACCEL);
  2078. break;
  2079. case ACCEL_X:
  2080. if (draw) {
  2081. Draw_Menu_Item(row, ICON_MaxAccX, F("X Axis"));
  2082. Draw_Float(planner.settings.max_acceleration_mm_per_s2[X_AXIS], row, false, 1);
  2083. }
  2084. else
  2085. Modify_Value(planner.settings.max_acceleration_mm_per_s2[X_AXIS], 0, default_max_acceleration[X_AXIS] * 2, 1);
  2086. break;
  2087. case ACCEL_Y:
  2088. if (draw) {
  2089. Draw_Menu_Item(row, ICON_MaxAccY, F("Y Axis"));
  2090. Draw_Float(planner.settings.max_acceleration_mm_per_s2[Y_AXIS], row, false, 1);
  2091. }
  2092. else
  2093. Modify_Value(planner.settings.max_acceleration_mm_per_s2[Y_AXIS], 0, default_max_acceleration[Y_AXIS] * 2, 1);
  2094. break;
  2095. case ACCEL_Z:
  2096. if (draw) {
  2097. Draw_Menu_Item(row, ICON_MaxAccZ, F("Z Axis"));
  2098. Draw_Float(planner.settings.max_acceleration_mm_per_s2[Z_AXIS], row, false, 1);
  2099. }
  2100. else
  2101. Modify_Value(planner.settings.max_acceleration_mm_per_s2[Z_AXIS], 0, default_max_acceleration[Z_AXIS] * 2, 1);
  2102. break;
  2103. #if HAS_HOTEND
  2104. case ACCEL_E:
  2105. if (draw) {
  2106. Draw_Menu_Item(row, ICON_MaxAccE, F("Extruder"));
  2107. Draw_Float(planner.settings.max_acceleration_mm_per_s2[E_AXIS], row, false, 1);
  2108. }
  2109. else
  2110. Modify_Value(planner.settings.max_acceleration_mm_per_s2[E_AXIS], 0, default_max_acceleration[E_AXIS] * 2, 1);
  2111. break;
  2112. #endif
  2113. }
  2114. break;
  2115. #if HAS_CLASSIC_JERK
  2116. case MaxJerk:
  2117. #define JERK_BACK 0
  2118. #define JERK_X (JERK_BACK + 1)
  2119. #define JERK_Y (JERK_X + 1)
  2120. #define JERK_Z (JERK_Y + 1)
  2121. #define JERK_E (JERK_Z + ENABLED(HAS_HOTEND))
  2122. #define JERK_TOTAL JERK_E
  2123. switch (item) {
  2124. case JERK_BACK:
  2125. if (draw)
  2126. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2127. else
  2128. Draw_Menu(Motion, MOTION_JERK);
  2129. break;
  2130. case JERK_X:
  2131. if (draw) {
  2132. Draw_Menu_Item(row, ICON_MaxSpeedJerkX, F("X Axis"));
  2133. Draw_Float(planner.max_jerk[X_AXIS], row, false, 10);
  2134. }
  2135. else
  2136. Modify_Value(planner.max_jerk[X_AXIS], 0, default_max_jerk[X_AXIS] * 2, 10);
  2137. break;
  2138. case JERK_Y:
  2139. if (draw) {
  2140. Draw_Menu_Item(row, ICON_MaxSpeedJerkY, F("Y Axis"));
  2141. Draw_Float(planner.max_jerk[Y_AXIS], row, false, 10);
  2142. }
  2143. else
  2144. Modify_Value(planner.max_jerk[Y_AXIS], 0, default_max_jerk[Y_AXIS] * 2, 10);
  2145. break;
  2146. case JERK_Z:
  2147. if (draw) {
  2148. Draw_Menu_Item(row, ICON_MaxSpeedJerkZ, F("Z Axis"));
  2149. Draw_Float(planner.max_jerk[Z_AXIS], row, false, 10);
  2150. }
  2151. else
  2152. Modify_Value(planner.max_jerk[Z_AXIS], 0, default_max_jerk[Z_AXIS] * 2, 10);
  2153. break;
  2154. #if HAS_HOTEND
  2155. case JERK_E:
  2156. if (draw) {
  2157. Draw_Menu_Item(row, ICON_MaxSpeedJerkE, F("Extruder"));
  2158. Draw_Float(planner.max_jerk[E_AXIS], row, false, 10);
  2159. }
  2160. else
  2161. Modify_Value(planner.max_jerk[E_AXIS], 0, default_max_jerk[E_AXIS] * 2, 10);
  2162. break;
  2163. #endif
  2164. }
  2165. break;
  2166. #endif
  2167. case Steps:
  2168. #define STEPS_BACK 0
  2169. #define STEPS_X (STEPS_BACK + 1)
  2170. #define STEPS_Y (STEPS_X + 1)
  2171. #define STEPS_Z (STEPS_Y + 1)
  2172. #define STEPS_E (STEPS_Z + ENABLED(HAS_HOTEND))
  2173. #define STEPS_TOTAL STEPS_E
  2174. switch (item) {
  2175. case STEPS_BACK:
  2176. if (draw)
  2177. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2178. else
  2179. Draw_Menu(Motion, MOTION_STEPS);
  2180. break;
  2181. case STEPS_X:
  2182. if (draw) {
  2183. Draw_Menu_Item(row, ICON_StepX, F("X Axis"));
  2184. Draw_Float(planner.settings.axis_steps_per_mm[X_AXIS], row, false, 10);
  2185. }
  2186. else
  2187. Modify_Value(planner.settings.axis_steps_per_mm[X_AXIS], 0, default_steps[X_AXIS] * 2, 10);
  2188. break;
  2189. case STEPS_Y:
  2190. if (draw) {
  2191. Draw_Menu_Item(row, ICON_StepY, F("Y Axis"));
  2192. Draw_Float(planner.settings.axis_steps_per_mm[Y_AXIS], row, false, 10);
  2193. }
  2194. else
  2195. Modify_Value(planner.settings.axis_steps_per_mm[Y_AXIS], 0, default_steps[Y_AXIS] * 2, 10);
  2196. break;
  2197. case STEPS_Z:
  2198. if (draw) {
  2199. Draw_Menu_Item(row, ICON_StepZ, F("Z Axis"));
  2200. Draw_Float(planner.settings.axis_steps_per_mm[Z_AXIS], row, false, 10);
  2201. }
  2202. else
  2203. Modify_Value(planner.settings.axis_steps_per_mm[Z_AXIS], 0, default_steps[Z_AXIS] * 2, 10);
  2204. break;
  2205. #if HAS_HOTEND
  2206. case STEPS_E:
  2207. if (draw) {
  2208. Draw_Menu_Item(row, ICON_StepE, F("Extruder"));
  2209. Draw_Float(planner.settings.axis_steps_per_mm[E_AXIS], row, false, 10);
  2210. }
  2211. else
  2212. Modify_Value(planner.settings.axis_steps_per_mm[E_AXIS], 0, 1000, 10);
  2213. break;
  2214. #endif
  2215. }
  2216. break;
  2217. case Visual:
  2218. #define VISUAL_BACK 0
  2219. #define VISUAL_BACKLIGHT (VISUAL_BACK + 1)
  2220. #define VISUAL_BRIGHTNESS (VISUAL_BACKLIGHT + 1)
  2221. #define VISUAL_TIME_FORMAT (VISUAL_BRIGHTNESS + 1)
  2222. #define VISUAL_COLOR_THEMES (VISUAL_TIME_FORMAT + 1)
  2223. #define VISUAL_TOTAL VISUAL_COLOR_THEMES
  2224. switch (item) {
  2225. case VISUAL_BACK:
  2226. if (draw)
  2227. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2228. else
  2229. Draw_Menu(Control, CONTROL_VISUAL);
  2230. break;
  2231. case VISUAL_BACKLIGHT:
  2232. if (draw)
  2233. Draw_Menu_Item(row, ICON_Brightness, F("Display Off"));
  2234. else
  2235. ui.set_brightness(0);
  2236. break;
  2237. case VISUAL_BRIGHTNESS:
  2238. if (draw) {
  2239. Draw_Menu_Item(row, ICON_Brightness, F("LCD Brightness"));
  2240. Draw_Float(ui.brightness, row, false, 1);
  2241. }
  2242. else
  2243. Modify_Value(ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, 1, ui.refresh_brightness);
  2244. break;
  2245. case VISUAL_TIME_FORMAT:
  2246. if (draw) {
  2247. Draw_Menu_Item(row, ICON_PrintTime, F("Progress as __h__m"));
  2248. Draw_Checkbox(row, eeprom_settings.time_format_textual);
  2249. }
  2250. else {
  2251. eeprom_settings.time_format_textual = !eeprom_settings.time_format_textual;
  2252. Draw_Checkbox(row, eeprom_settings.time_format_textual);
  2253. }
  2254. break;
  2255. case VISUAL_COLOR_THEMES:
  2256. if (draw)
  2257. Draw_Menu_Item(row, ICON_MaxSpeed, F("UI Color Settings"), nullptr, true);
  2258. else
  2259. Draw_Menu(ColorSettings);
  2260. break;
  2261. }
  2262. break;
  2263. case ColorSettings:
  2264. #define COLORSETTINGS_BACK 0
  2265. #define COLORSETTINGS_CURSOR (COLORSETTINGS_BACK + 1)
  2266. #define COLORSETTINGS_SPLIT_LINE (COLORSETTINGS_CURSOR + 1)
  2267. #define COLORSETTINGS_MENU_TOP_TXT (COLORSETTINGS_SPLIT_LINE + 1)
  2268. #define COLORSETTINGS_MENU_TOP_BG (COLORSETTINGS_MENU_TOP_TXT + 1)
  2269. #define COLORSETTINGS_HIGHLIGHT_BORDER (COLORSETTINGS_MENU_TOP_BG + 1)
  2270. #define COLORSETTINGS_PROGRESS_PERCENT (COLORSETTINGS_HIGHLIGHT_BORDER + 1)
  2271. #define COLORSETTINGS_PROGRESS_TIME (COLORSETTINGS_PROGRESS_PERCENT + 1)
  2272. #define COLORSETTINGS_PROGRESS_STATUS_BAR (COLORSETTINGS_PROGRESS_TIME + 1)
  2273. #define COLORSETTINGS_PROGRESS_STATUS_AREA (COLORSETTINGS_PROGRESS_STATUS_BAR + 1)
  2274. #define COLORSETTINGS_PROGRESS_COORDINATES (COLORSETTINGS_PROGRESS_STATUS_AREA + 1)
  2275. #define COLORSETTINGS_PROGRESS_COORDINATES_LINE (COLORSETTINGS_PROGRESS_COORDINATES + 1)
  2276. #define COLORSETTINGS_TOTAL COLORSETTINGS_PROGRESS_COORDINATES_LINE
  2277. switch (item) {
  2278. case COLORSETTINGS_BACK:
  2279. if (draw)
  2280. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2281. else
  2282. Draw_Menu(Visual, VISUAL_COLOR_THEMES);
  2283. break;
  2284. case COLORSETTINGS_CURSOR:
  2285. if (draw) {
  2286. Draw_Menu_Item(row, ICON_MaxSpeed, F("Cursor"));
  2287. Draw_Option(eeprom_settings.cursor_color, color_names, row, false, true);
  2288. }
  2289. else
  2290. Modify_Option(eeprom_settings.cursor_color, color_names, Custom_Colors);
  2291. break;
  2292. case COLORSETTINGS_SPLIT_LINE:
  2293. if (draw) {
  2294. Draw_Menu_Item(row, ICON_MaxSpeed, F("Menu Split Line"));
  2295. Draw_Option(eeprom_settings.menu_split_line, color_names, row, false, true);
  2296. }
  2297. else
  2298. Modify_Option(eeprom_settings.menu_split_line, color_names, Custom_Colors);
  2299. break;
  2300. case COLORSETTINGS_MENU_TOP_TXT:
  2301. if (draw) {
  2302. Draw_Menu_Item(row, ICON_MaxSpeed, F("Menu Header Text"));
  2303. Draw_Option(eeprom_settings.menu_top_txt, color_names, row, false, true);
  2304. }
  2305. else
  2306. Modify_Option(eeprom_settings.menu_top_txt, color_names, Custom_Colors);
  2307. break;
  2308. case COLORSETTINGS_MENU_TOP_BG:
  2309. if (draw) {
  2310. Draw_Menu_Item(row, ICON_MaxSpeed, F("Menu Header Bg"));
  2311. Draw_Option(eeprom_settings.menu_top_bg, color_names, row, false, true);
  2312. }
  2313. else
  2314. Modify_Option(eeprom_settings.menu_top_bg, color_names, Custom_Colors);
  2315. break;
  2316. case COLORSETTINGS_HIGHLIGHT_BORDER:
  2317. if (draw) {
  2318. Draw_Menu_Item(row, ICON_MaxSpeed, F("Highlight Box"));
  2319. Draw_Option(eeprom_settings.highlight_box, color_names, row, false, true);
  2320. }
  2321. else
  2322. Modify_Option(eeprom_settings.highlight_box, color_names, Custom_Colors);
  2323. break;
  2324. case COLORSETTINGS_PROGRESS_PERCENT:
  2325. if (draw) {
  2326. Draw_Menu_Item(row, ICON_MaxSpeed, F("Progress Percent"));
  2327. Draw_Option(eeprom_settings.progress_percent, color_names, row, false, true);
  2328. }
  2329. else
  2330. Modify_Option(eeprom_settings.progress_percent, color_names, Custom_Colors);
  2331. break;
  2332. case COLORSETTINGS_PROGRESS_TIME:
  2333. if (draw) {
  2334. Draw_Menu_Item(row, ICON_MaxSpeed, F("Progress Time"));
  2335. Draw_Option(eeprom_settings.progress_time, color_names, row, false, true);
  2336. }
  2337. else
  2338. Modify_Option(eeprom_settings.progress_time, color_names, Custom_Colors);
  2339. break;
  2340. case COLORSETTINGS_PROGRESS_STATUS_BAR:
  2341. if (draw) {
  2342. Draw_Menu_Item(row, ICON_MaxSpeed, F("Status Bar Text"));
  2343. Draw_Option(eeprom_settings.status_bar_text, color_names, row, false, true);
  2344. }
  2345. else
  2346. Modify_Option(eeprom_settings.status_bar_text, color_names, Custom_Colors);
  2347. break;
  2348. case COLORSETTINGS_PROGRESS_STATUS_AREA:
  2349. if (draw) {
  2350. Draw_Menu_Item(row, ICON_MaxSpeed, F("Status Area Text"));
  2351. Draw_Option(eeprom_settings.status_area_text, color_names, row, false, true);
  2352. }
  2353. else
  2354. Modify_Option(eeprom_settings.status_area_text, color_names, Custom_Colors);
  2355. break;
  2356. case COLORSETTINGS_PROGRESS_COORDINATES:
  2357. if (draw) {
  2358. Draw_Menu_Item(row, ICON_MaxSpeed, F("Coordinates Text"));
  2359. Draw_Option(eeprom_settings.coordinates_text, color_names, row, false, true);
  2360. }
  2361. else
  2362. Modify_Option(eeprom_settings.coordinates_text, color_names, Custom_Colors);
  2363. break;
  2364. case COLORSETTINGS_PROGRESS_COORDINATES_LINE:
  2365. if (draw) {
  2366. Draw_Menu_Item(row, ICON_MaxSpeed, F("Coordinates Line"));
  2367. Draw_Option(eeprom_settings.coordinates_split_line, color_names, row, false, true);
  2368. }
  2369. else
  2370. Modify_Option(eeprom_settings.coordinates_split_line, color_names, Custom_Colors);
  2371. break;
  2372. } // switch (item)
  2373. break;
  2374. case Advanced:
  2375. #define ADVANCED_BACK 0
  2376. #define ADVANCED_BEEPER (ADVANCED_BACK + ENABLED(SOUND_MENU_ITEM))
  2377. #define ADVANCED_PROBE (ADVANCED_BEEPER + ENABLED(HAS_BED_PROBE))
  2378. #define ADVANCED_CORNER (ADVANCED_PROBE + 1)
  2379. #define ADVANCED_LA (ADVANCED_CORNER + ENABLED(LIN_ADVANCE))
  2380. #define ADVANCED_LOAD (ADVANCED_LA + ENABLED(ADVANCED_PAUSE_FEATURE))
  2381. #define ADVANCED_UNLOAD (ADVANCED_LOAD + ENABLED(ADVANCED_PAUSE_FEATURE))
  2382. #define ADVANCED_COLD_EXTRUDE (ADVANCED_UNLOAD + ENABLED(PREVENT_COLD_EXTRUSION))
  2383. #define ADVANCED_FILSENSORENABLED (ADVANCED_COLD_EXTRUDE + ENABLED(FILAMENT_RUNOUT_SENSOR))
  2384. #define ADVANCED_FILSENSORDISTANCE (ADVANCED_FILSENSORENABLED + ENABLED(HAS_FILAMENT_RUNOUT_DISTANCE))
  2385. #define ADVANCED_POWER_LOSS (ADVANCED_FILSENSORDISTANCE + ENABLED(POWER_LOSS_RECOVERY))
  2386. #define ADVANCED_TOTAL ADVANCED_POWER_LOSS
  2387. switch (item) {
  2388. case ADVANCED_BACK:
  2389. if (draw)
  2390. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2391. else
  2392. Draw_Menu(Control, CONTROL_ADVANCED);
  2393. break;
  2394. #if ENABLED(SOUND_MENU_ITEM)
  2395. case ADVANCED_BEEPER:
  2396. if (draw) {
  2397. Draw_Menu_Item(row, ICON_Version, F("LCD Beeper"));
  2398. Draw_Checkbox(row, ui.sound_on);
  2399. }
  2400. else {
  2401. ui.sound_on = !ui.sound_on;
  2402. Draw_Checkbox(row, ui.sound_on);
  2403. }
  2404. break;
  2405. #endif
  2406. #if HAS_BED_PROBE
  2407. case ADVANCED_PROBE:
  2408. if (draw)
  2409. Draw_Menu_Item(row, ICON_StepX, F("Probe"), nullptr, true);
  2410. else
  2411. Draw_Menu(ProbeMenu);
  2412. break;
  2413. #endif
  2414. case ADVANCED_CORNER:
  2415. if (draw) {
  2416. Draw_Menu_Item(row, ICON_MaxAccelerated, F("Bed Screw Inset"));
  2417. Draw_Float(corner_pos, row, false, 10);
  2418. }
  2419. else
  2420. Modify_Value(corner_pos, 1, 100, 10);
  2421. break;
  2422. #if ENABLED(LIN_ADVANCE)
  2423. case ADVANCED_LA:
  2424. if (draw) {
  2425. Draw_Menu_Item(row, ICON_MaxAccelerated, F("Lin Advance Kp"));
  2426. Draw_Float(planner.extruder_advance_K[0], row, false, 100);
  2427. }
  2428. else
  2429. Modify_Value(planner.extruder_advance_K[0], 0, 10, 100);
  2430. break;
  2431. #endif
  2432. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2433. case ADVANCED_LOAD:
  2434. if (draw) {
  2435. Draw_Menu_Item(row, ICON_WriteEEPROM, F("Load Length"));
  2436. Draw_Float(fc_settings[0].load_length, row, false, 1);
  2437. }
  2438. else
  2439. Modify_Value(fc_settings[0].load_length, 0, EXTRUDE_MAXLENGTH, 1);
  2440. break;
  2441. case ADVANCED_UNLOAD:
  2442. if (draw) {
  2443. Draw_Menu_Item(row, ICON_ReadEEPROM, F("Unload Length"));
  2444. Draw_Float(fc_settings[0].unload_length, row, false, 1);
  2445. }
  2446. else
  2447. Modify_Value(fc_settings[0].unload_length, 0, EXTRUDE_MAXLENGTH, 1);
  2448. break;
  2449. #endif // ADVANCED_PAUSE_FEATURE
  2450. #if ENABLED(PREVENT_COLD_EXTRUSION)
  2451. case ADVANCED_COLD_EXTRUDE:
  2452. if (draw) {
  2453. Draw_Menu_Item(row, ICON_Cool, F("Min Extrusion T"));
  2454. Draw_Float(thermalManager.extrude_min_temp, row, false, 1);
  2455. }
  2456. else {
  2457. Modify_Value(thermalManager.extrude_min_temp, 0, MAX_E_TEMP, 1);
  2458. thermalManager.allow_cold_extrude = (thermalManager.extrude_min_temp == 0);
  2459. }
  2460. break;
  2461. #endif
  2462. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  2463. case ADVANCED_FILSENSORENABLED:
  2464. if (draw) {
  2465. Draw_Menu_Item(row, ICON_Extruder, F("Filament Sensor"));
  2466. Draw_Checkbox(row, runout.enabled);
  2467. }
  2468. else {
  2469. runout.enabled = !runout.enabled;
  2470. Draw_Checkbox(row, runout.enabled);
  2471. }
  2472. break;
  2473. #if ENABLED(HAS_FILAMENT_RUNOUT_DISTANCE)
  2474. case ADVANCED_FILSENSORDISTANCE:
  2475. if (draw) {
  2476. Draw_Menu_Item(row, ICON_MaxAccE, F("Runout Distance"));
  2477. Draw_Float(runout.runout_distance(), row, false, 10);
  2478. }
  2479. else
  2480. Modify_Value(runout.runout_distance(), 0, 999, 10);
  2481. break;
  2482. #endif
  2483. #endif // FILAMENT_RUNOUT_SENSOR
  2484. #if ENABLED(POWER_LOSS_RECOVERY)
  2485. case ADVANCED_POWER_LOSS:
  2486. if (draw) {
  2487. Draw_Menu_Item(row, ICON_Motion, F("Power-loss recovery"));
  2488. Draw_Checkbox(row, recovery.enabled);
  2489. }
  2490. else {
  2491. recovery.enable(!recovery.enabled);
  2492. Draw_Checkbox(row, recovery.enabled);
  2493. }
  2494. break;
  2495. #endif
  2496. }
  2497. break;
  2498. #if HAS_BED_PROBE
  2499. case ProbeMenu:
  2500. #define PROBE_BACK 0
  2501. #define PROBE_XOFFSET (PROBE_BACK + 1)
  2502. #define PROBE_YOFFSET (PROBE_XOFFSET + 1)
  2503. #define PROBE_TEST (PROBE_YOFFSET + 1)
  2504. #define PROBE_TEST_COUNT (PROBE_TEST + 1)
  2505. #define PROBE_TOTAL PROBE_TEST_COUNT
  2506. static uint8_t testcount = 4;
  2507. switch (item) {
  2508. case PROBE_BACK:
  2509. if (draw)
  2510. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2511. else
  2512. Draw_Menu(Advanced, ADVANCED_PROBE);
  2513. break;
  2514. case PROBE_XOFFSET:
  2515. if (draw) {
  2516. Draw_Menu_Item(row, ICON_StepX, F("Probe X Offset"));
  2517. Draw_Float(probe.offset.x, row, false, 10);
  2518. }
  2519. else
  2520. Modify_Value(probe.offset.x, -MAX_XY_OFFSET, MAX_XY_OFFSET, 10);
  2521. break;
  2522. case PROBE_YOFFSET:
  2523. if (draw) {
  2524. Draw_Menu_Item(row, ICON_StepY, F("Probe Y Offset"));
  2525. Draw_Float(probe.offset.y, row, false, 10);
  2526. }
  2527. else
  2528. Modify_Value(probe.offset.y, -MAX_XY_OFFSET, MAX_XY_OFFSET, 10);
  2529. break;
  2530. case PROBE_TEST:
  2531. if (draw)
  2532. Draw_Menu_Item(row, ICON_StepY, F("M48 Probe Test"));
  2533. else {
  2534. sprintf_P(cmd, PSTR("G28O\nM48 X%s Y%s P%i"), dtostrf((X_BED_SIZE + X_MIN_POS) / 2.0f, 1, 3, str_1), dtostrf((Y_BED_SIZE + Y_MIN_POS) / 2.0f, 1, 3, str_2), testcount);
  2535. gcode.process_subcommands_now(cmd);
  2536. }
  2537. break;
  2538. case PROBE_TEST_COUNT:
  2539. if (draw) {
  2540. Draw_Menu_Item(row, ICON_StepY, F("Probe Test Count"));
  2541. Draw_Float(testcount, row, false, 1);
  2542. }
  2543. else
  2544. Modify_Value(testcount, 4, 50, 1);
  2545. break;
  2546. }
  2547. break;
  2548. #endif
  2549. case InfoMain:
  2550. case Info:
  2551. #define INFO_BACK 0
  2552. #define INFO_PRINTCOUNT (INFO_BACK + ENABLED(PRINTCOUNTER))
  2553. #define INFO_PRINTTIME (INFO_PRINTCOUNT + ENABLED(PRINTCOUNTER))
  2554. #define INFO_SIZE (INFO_PRINTTIME + 1)
  2555. #define INFO_VERSION (INFO_SIZE + 1)
  2556. #define INFO_CONTACT (INFO_VERSION + 1)
  2557. #define INFO_TOTAL INFO_BACK
  2558. switch (item) {
  2559. case INFO_BACK:
  2560. if (draw) {
  2561. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2562. #if ENABLED(PRINTCOUNTER)
  2563. char row1[50], row2[50], buf[32];
  2564. printStatistics ps = print_job_timer.getStats();
  2565. sprintf_P(row1, PSTR("%i prints, %i finished"), ps.totalPrints, ps.finishedPrints);
  2566. sprintf_P(row2, PSTR("%s m filament used"), dtostrf(ps.filamentUsed / 1000, 1, 2, str_1));
  2567. Draw_Menu_Item(INFO_PRINTCOUNT, ICON_HotendTemp, row1, row2, false, true);
  2568. duration_t(print_job_timer.getStats().printTime).toString(buf);
  2569. sprintf_P(row1, PSTR("Printed: %s"), buf);
  2570. duration_t(print_job_timer.getStats().longestPrint).toString(buf);
  2571. sprintf_P(row2, PSTR("Longest: %s"), buf);
  2572. Draw_Menu_Item(INFO_PRINTTIME, ICON_PrintTime, row1, row2, false, true);
  2573. #endif
  2574. Draw_Menu_Item(INFO_SIZE, ICON_PrintSize, F(MACHINE_SIZE), nullptr, false, true);
  2575. Draw_Menu_Item(INFO_VERSION, ICON_Version, F(SHORT_BUILD_VERSION), nullptr, false, true);
  2576. Draw_Menu_Item(INFO_CONTACT, ICON_Contact, F(CORP_WEBSITE), nullptr, false, true);
  2577. }
  2578. else {
  2579. if (menu == Info)
  2580. Draw_Menu(Control, CONTROL_INFO);
  2581. else
  2582. Draw_Main_Menu(3);
  2583. }
  2584. break;
  2585. }
  2586. break;
  2587. #if HAS_MESH
  2588. case Leveling:
  2589. #define LEVELING_BACK 0
  2590. #define LEVELING_ACTIVE (LEVELING_BACK + 1)
  2591. #define LEVELING_GET_TILT (LEVELING_ACTIVE + BOTH(HAS_BED_PROBE, AUTO_BED_LEVELING_UBL))
  2592. #define LEVELING_GET_MESH (LEVELING_GET_TILT + 1)
  2593. #define LEVELING_MANUAL (LEVELING_GET_MESH + 1)
  2594. #define LEVELING_VIEW (LEVELING_MANUAL + 1)
  2595. #define LEVELING_SETTINGS (LEVELING_VIEW + 1)
  2596. #define LEVELING_SLOT (LEVELING_SETTINGS + ENABLED(AUTO_BED_LEVELING_UBL))
  2597. #define LEVELING_LOAD (LEVELING_SLOT + ENABLED(AUTO_BED_LEVELING_UBL))
  2598. #define LEVELING_SAVE (LEVELING_LOAD + ENABLED(AUTO_BED_LEVELING_UBL))
  2599. #define LEVELING_TOTAL LEVELING_SAVE
  2600. switch (item) {
  2601. case LEVELING_BACK:
  2602. if (draw)
  2603. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2604. else
  2605. Draw_Main_Menu(3);
  2606. break;
  2607. case LEVELING_ACTIVE:
  2608. if (draw) {
  2609. Draw_Menu_Item(row, ICON_StockConfiguration, F("Leveling Active"));
  2610. Draw_Checkbox(row, planner.leveling_active);
  2611. }
  2612. else {
  2613. if (!planner.leveling_active) {
  2614. set_bed_leveling_enabled(!planner.leveling_active);
  2615. if (!planner.leveling_active) {
  2616. Confirm_Handler(LevelError);
  2617. break;
  2618. }
  2619. }
  2620. else
  2621. set_bed_leveling_enabled(!planner.leveling_active);
  2622. Draw_Checkbox(row, planner.leveling_active);
  2623. }
  2624. break;
  2625. #if BOTH(HAS_BED_PROBE, AUTO_BED_LEVELING_UBL)
  2626. case LEVELING_GET_TILT:
  2627. if (draw)
  2628. Draw_Menu_Item(row, ICON_Tilt, F("Autotilt Current Mesh"));
  2629. else {
  2630. if (bedlevel.storage_slot < 0) {
  2631. Popup_Handler(MeshSlot);
  2632. break;
  2633. }
  2634. Popup_Handler(Home);
  2635. gcode.home_all_axes(true);
  2636. Popup_Handler(Level);
  2637. if (mesh_conf.tilt_grid > 1) {
  2638. sprintf_P(cmd, PSTR("G29 J%i"), mesh_conf.tilt_grid);
  2639. gcode.process_subcommands_now(cmd);
  2640. }
  2641. else
  2642. gcode.process_subcommands_now(F("G29 J"));
  2643. planner.synchronize();
  2644. Redraw_Menu();
  2645. }
  2646. break;
  2647. #endif
  2648. case LEVELING_GET_MESH:
  2649. if (draw)
  2650. Draw_Menu_Item(row, ICON_Mesh, F("Create New Mesh"));
  2651. else {
  2652. Popup_Handler(Home);
  2653. gcode.home_all_axes(true);
  2654. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2655. #if ENABLED(PREHEAT_BEFORE_LEVELING)
  2656. Popup_Handler(Heating);
  2657. probe.preheat_for_probing(LEVELING_NOZZLE_TEMP, LEVELING_BED_TEMP);
  2658. #endif
  2659. #if HAS_BED_PROBE
  2660. Popup_Handler(Level);
  2661. gcode.process_subcommands_now(F("G29 P0\nG29 P1"));
  2662. gcode.process_subcommands_now(F("G29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nG29 P3\nM420 S1"));
  2663. planner.synchronize();
  2664. Update_Status("Probed all reachable points");
  2665. Popup_Handler(SaveLevel);
  2666. #else
  2667. level_state = planner.leveling_active;
  2668. set_bed_leveling_enabled(false);
  2669. mesh_conf.goto_mesh_value = true;
  2670. mesh_conf.mesh_x = mesh_conf.mesh_y = 0;
  2671. Popup_Handler(MoveWait);
  2672. mesh_conf.manual_move();
  2673. Draw_Menu(UBLMesh);
  2674. #endif
  2675. #elif HAS_BED_PROBE
  2676. Popup_Handler(Level);
  2677. gcode.process_subcommands_now(F("G29"));
  2678. planner.synchronize();
  2679. Popup_Handler(SaveLevel);
  2680. #else
  2681. level_state = planner.leveling_active;
  2682. set_bed_leveling_enabled(false);
  2683. gridpoint = 1;
  2684. Popup_Handler(MoveWait);
  2685. gcode.process_subcommands_now(F("G29"));
  2686. planner.synchronize();
  2687. Draw_Menu(ManualMesh);
  2688. #endif
  2689. }
  2690. break;
  2691. case LEVELING_MANUAL:
  2692. if (draw)
  2693. Draw_Menu_Item(row, ICON_Mesh, F("Manual Tuning"), nullptr, true);
  2694. else {
  2695. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  2696. if (!leveling_is_valid()) {
  2697. Confirm_Handler(InvalidMesh);
  2698. break;
  2699. }
  2700. #endif
  2701. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2702. if (bedlevel.storage_slot < 0) {
  2703. Popup_Handler(MeshSlot);
  2704. break;
  2705. }
  2706. #endif
  2707. if (axes_should_home()) {
  2708. Popup_Handler(Home);
  2709. gcode.home_all_axes(true);
  2710. }
  2711. level_state = planner.leveling_active;
  2712. set_bed_leveling_enabled(false);
  2713. mesh_conf.goto_mesh_value = false;
  2714. #if ENABLED(PREHEAT_BEFORE_LEVELING)
  2715. Popup_Handler(Heating);
  2716. #if HAS_HOTEND
  2717. if (thermalManager.degTargetHotend(0) < LEVELING_NOZZLE_TEMP)
  2718. thermalManager.setTargetHotend(LEVELING_NOZZLE_TEMP, 0);
  2719. #endif
  2720. #if HAS_HEATED_BED
  2721. if (thermalManager.degTargetBed() < LEVELING_BED_TEMP)
  2722. thermalManager.setTargetBed(LEVELING_BED_TEMP);
  2723. #endif
  2724. TERN_(HAS_HOTEND, thermalManager.wait_for_hotend(0));
  2725. TERN_(HAS_HEATED_BED, thermalManager.wait_for_bed_heating());
  2726. #endif
  2727. Popup_Handler(MoveWait);
  2728. mesh_conf.manual_move();
  2729. Draw_Menu(LevelManual);
  2730. }
  2731. break;
  2732. case LEVELING_VIEW:
  2733. if (draw)
  2734. Draw_Menu_Item(row, ICON_Mesh, GET_TEXT(MSG_MESH_VIEW), nullptr, true);
  2735. else {
  2736. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2737. if (bedlevel.storage_slot < 0) {
  2738. Popup_Handler(MeshSlot);
  2739. break;
  2740. }
  2741. #endif
  2742. Draw_Menu(LevelView);
  2743. }
  2744. break;
  2745. case LEVELING_SETTINGS:
  2746. if (draw)
  2747. Draw_Menu_Item(row, ICON_Step, F("Leveling Settings"), nullptr, true);
  2748. else
  2749. Draw_Menu(LevelSettings);
  2750. break;
  2751. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2752. case LEVELING_SLOT:
  2753. if (draw) {
  2754. Draw_Menu_Item(row, ICON_PrintSize, F("Mesh Slot"));
  2755. Draw_Float(bedlevel.storage_slot, row, false, 1);
  2756. }
  2757. else
  2758. Modify_Value(bedlevel.storage_slot, 0, settings.calc_num_meshes() - 1, 1);
  2759. break;
  2760. case LEVELING_LOAD:
  2761. if (draw)
  2762. Draw_Menu_Item(row, ICON_ReadEEPROM, F("Load Mesh"));
  2763. else {
  2764. if (bedlevel.storage_slot < 0) {
  2765. Popup_Handler(MeshSlot);
  2766. break;
  2767. }
  2768. gcode.process_subcommands_now(F("G29 L"));
  2769. planner.synchronize();
  2770. AudioFeedback(true);
  2771. }
  2772. break;
  2773. case LEVELING_SAVE:
  2774. if (draw)
  2775. Draw_Menu_Item(row, ICON_WriteEEPROM, F("Save Mesh"));
  2776. else {
  2777. if (bedlevel.storage_slot < 0) {
  2778. Popup_Handler(MeshSlot);
  2779. break;
  2780. }
  2781. gcode.process_subcommands_now(F("G29 S"));
  2782. planner.synchronize();
  2783. AudioFeedback(true);
  2784. }
  2785. break;
  2786. #endif
  2787. }
  2788. break;
  2789. case LevelView:
  2790. #define LEVELING_VIEW_BACK 0
  2791. #define LEVELING_VIEW_MESH (LEVELING_VIEW_BACK + 1)
  2792. #define LEVELING_VIEW_TEXT (LEVELING_VIEW_MESH + 1)
  2793. #define LEVELING_VIEW_ASYMMETRIC (LEVELING_VIEW_TEXT + 1)
  2794. #define LEVELING_VIEW_TOTAL LEVELING_VIEW_ASYMMETRIC
  2795. switch (item) {
  2796. case LEVELING_VIEW_BACK:
  2797. if (draw)
  2798. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2799. else
  2800. Draw_Menu(Leveling, LEVELING_VIEW);
  2801. break;
  2802. case LEVELING_VIEW_MESH:
  2803. if (draw)
  2804. Draw_Menu_Item(row, ICON_PrintSize, GET_TEXT(MSG_MESH_VIEW), nullptr, true);
  2805. else
  2806. Draw_Menu(MeshViewer);
  2807. break;
  2808. case LEVELING_VIEW_TEXT:
  2809. if (draw) {
  2810. Draw_Menu_Item(row, ICON_Contact, F("Viewer Show Values"));
  2811. Draw_Checkbox(row, mesh_conf.viewer_print_value);
  2812. }
  2813. else {
  2814. mesh_conf.viewer_print_value = !mesh_conf.viewer_print_value;
  2815. Draw_Checkbox(row, mesh_conf.viewer_print_value);
  2816. }
  2817. break;
  2818. case LEVELING_VIEW_ASYMMETRIC:
  2819. if (draw) {
  2820. Draw_Menu_Item(row, ICON_Axis, F("Viewer Asymmetric"));
  2821. Draw_Checkbox(row, mesh_conf.viewer_asymmetric_range);
  2822. }
  2823. else {
  2824. mesh_conf.viewer_asymmetric_range = !mesh_conf.viewer_asymmetric_range;
  2825. Draw_Checkbox(row, mesh_conf.viewer_asymmetric_range);
  2826. }
  2827. break;
  2828. }
  2829. break;
  2830. case LevelSettings:
  2831. #define LEVELING_SETTINGS_BACK 0
  2832. #define LEVELING_SETTINGS_FADE (LEVELING_SETTINGS_BACK + 1)
  2833. #define LEVELING_SETTINGS_TILT (LEVELING_SETTINGS_FADE + ENABLED(AUTO_BED_LEVELING_UBL))
  2834. #define LEVELING_SETTINGS_PLANE (LEVELING_SETTINGS_TILT + ENABLED(AUTO_BED_LEVELING_UBL))
  2835. #define LEVELING_SETTINGS_ZERO (LEVELING_SETTINGS_PLANE + ENABLED(AUTO_BED_LEVELING_UBL))
  2836. #define LEVELING_SETTINGS_UNDEF (LEVELING_SETTINGS_ZERO + ENABLED(AUTO_BED_LEVELING_UBL))
  2837. #define LEVELING_SETTINGS_TOTAL LEVELING_SETTINGS_UNDEF
  2838. switch (item) {
  2839. case LEVELING_SETTINGS_BACK:
  2840. if (draw)
  2841. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2842. else
  2843. Draw_Menu(Leveling, LEVELING_SETTINGS);
  2844. break;
  2845. case LEVELING_SETTINGS_FADE:
  2846. if (draw) {
  2847. Draw_Menu_Item(row, ICON_Fade, F("Fade Mesh within"));
  2848. Draw_Float(planner.z_fade_height, row, false, 1);
  2849. }
  2850. else {
  2851. Modify_Value(planner.z_fade_height, 0, Z_MAX_POS, 1);
  2852. planner.z_fade_height = -1;
  2853. set_z_fade_height(planner.z_fade_height);
  2854. }
  2855. break;
  2856. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2857. case LEVELING_SETTINGS_TILT:
  2858. if (draw) {
  2859. Draw_Menu_Item(row, ICON_Tilt, F("Tilting Grid Size"));
  2860. Draw_Float(mesh_conf.tilt_grid, row, false, 1);
  2861. }
  2862. else
  2863. Modify_Value(mesh_conf.tilt_grid, 1, 8, 1);
  2864. break;
  2865. case LEVELING_SETTINGS_PLANE:
  2866. if (draw)
  2867. Draw_Menu_Item(row, ICON_ResumeEEPROM, F("Convert Mesh to Plane"));
  2868. else {
  2869. if (mesh_conf.create_plane_from_mesh()) break;
  2870. gcode.process_subcommands_now(F("M420 S1"));
  2871. planner.synchronize();
  2872. AudioFeedback(true);
  2873. }
  2874. break;
  2875. case LEVELING_SETTINGS_ZERO:
  2876. if (draw)
  2877. Draw_Menu_Item(row, ICON_Mesh, F("Zero Current Mesh"));
  2878. else
  2879. ZERO(bedlevel.z_values);
  2880. break;
  2881. case LEVELING_SETTINGS_UNDEF:
  2882. if (draw)
  2883. Draw_Menu_Item(row, ICON_Mesh, F("Clear Current Mesh"));
  2884. else
  2885. bedlevel.invalidate();
  2886. break;
  2887. #endif // AUTO_BED_LEVELING_UBL
  2888. }
  2889. break;
  2890. case MeshViewer:
  2891. #define MESHVIEW_BACK 0
  2892. #define MESHVIEW_TOTAL MESHVIEW_BACK
  2893. if (item == MESHVIEW_BACK) {
  2894. if (draw) {
  2895. Draw_Menu_Item(0, ICON_Back, F("Back"));
  2896. mesh_conf.Draw_Bed_Mesh();
  2897. mesh_conf.Set_Mesh_Viewer_Status();
  2898. }
  2899. else if (!mesh_conf.drawing_mesh) {
  2900. Draw_Menu(LevelView, LEVELING_VIEW_MESH);
  2901. Update_Status("");
  2902. }
  2903. }
  2904. break;
  2905. case LevelManual:
  2906. #define LEVELING_M_BACK 0
  2907. #define LEVELING_M_X (LEVELING_M_BACK + 1)
  2908. #define LEVELING_M_Y (LEVELING_M_X + 1)
  2909. #define LEVELING_M_NEXT (LEVELING_M_Y + 1)
  2910. #define LEVELING_M_OFFSET (LEVELING_M_NEXT + 1)
  2911. #define LEVELING_M_UP (LEVELING_M_OFFSET + 1)
  2912. #define LEVELING_M_DOWN (LEVELING_M_UP + 1)
  2913. #define LEVELING_M_GOTO_VALUE (LEVELING_M_DOWN + 1)
  2914. #define LEVELING_M_UNDEF (LEVELING_M_GOTO_VALUE + ENABLED(AUTO_BED_LEVELING_UBL))
  2915. #define LEVELING_M_TOTAL LEVELING_M_UNDEF
  2916. switch (item) {
  2917. case LEVELING_M_BACK:
  2918. if (draw)
  2919. Draw_Menu_Item(row, ICON_Back, F("Back"));
  2920. else {
  2921. set_bed_leveling_enabled(level_state);
  2922. TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
  2923. Draw_Menu(Leveling, LEVELING_MANUAL);
  2924. }
  2925. break;
  2926. case LEVELING_M_X:
  2927. if (draw) {
  2928. Draw_Menu_Item(row, ICON_MoveX, F("Mesh Point X"));
  2929. Draw_Float(mesh_conf.mesh_x, row, 0, 1);
  2930. }
  2931. else
  2932. Modify_Value(mesh_conf.mesh_x, 0, GRID_MAX_POINTS_X - 1, 1);
  2933. break;
  2934. case LEVELING_M_Y:
  2935. if (draw) {
  2936. Draw_Menu_Item(row, ICON_MoveY, F("Mesh Point Y"));
  2937. Draw_Float(mesh_conf.mesh_y, row, 0, 1);
  2938. }
  2939. else
  2940. Modify_Value(mesh_conf.mesh_y, 0, GRID_MAX_POINTS_Y - 1, 1);
  2941. break;
  2942. case LEVELING_M_NEXT:
  2943. if (draw)
  2944. Draw_Menu_Item(row, ICON_More, F("Next Point"));
  2945. else {
  2946. if (mesh_conf.mesh_x != (GRID_MAX_POINTS_X - 1) || mesh_conf.mesh_y != (GRID_MAX_POINTS_Y - 1)) {
  2947. if ((mesh_conf.mesh_x == (GRID_MAX_POINTS_X - 1) && mesh_conf.mesh_y % 2 == 0) || (mesh_conf.mesh_x == 0 && mesh_conf.mesh_y % 2 == 1))
  2948. mesh_conf.mesh_y++;
  2949. else if (mesh_conf.mesh_y % 2 == 0)
  2950. mesh_conf.mesh_x++;
  2951. else
  2952. mesh_conf.mesh_x--;
  2953. mesh_conf.manual_move();
  2954. }
  2955. }
  2956. break;
  2957. case LEVELING_M_OFFSET:
  2958. if (draw) {
  2959. Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset"));
  2960. Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
  2961. }
  2962. else {
  2963. if (isnan(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
  2964. bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
  2965. Modify_Value(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
  2966. }
  2967. break;
  2968. case LEVELING_M_UP:
  2969. if (draw)
  2970. Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
  2971. else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
  2972. bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
  2973. gcode.process_subcommands_now(F("M290 Z0.01"));
  2974. planner.synchronize();
  2975. current_position.z += 0.01f;
  2976. sync_plan_position();
  2977. Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
  2978. }
  2979. break;
  2980. case LEVELING_M_DOWN:
  2981. if (draw)
  2982. Draw_Menu_Item(row, ICON_AxisD, F("Microstep Down"));
  2983. else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
  2984. bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
  2985. gcode.process_subcommands_now(F("M290 Z-0.01"));
  2986. planner.synchronize();
  2987. current_position.z -= 0.01f;
  2988. sync_plan_position();
  2989. Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
  2990. }
  2991. break;
  2992. case LEVELING_M_GOTO_VALUE:
  2993. if (draw) {
  2994. Draw_Menu_Item(row, ICON_StockConfiguration, F("Go to Mesh Z Value"));
  2995. Draw_Checkbox(row, mesh_conf.goto_mesh_value);
  2996. }
  2997. else {
  2998. mesh_conf.goto_mesh_value = !mesh_conf.goto_mesh_value;
  2999. current_position.z = 0;
  3000. mesh_conf.manual_move(true);
  3001. Draw_Checkbox(row, mesh_conf.goto_mesh_value);
  3002. }
  3003. break;
  3004. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3005. case LEVELING_M_UNDEF:
  3006. if (draw)
  3007. Draw_Menu_Item(row, ICON_ResumeEEPROM, F("Clear Point Value"));
  3008. else {
  3009. mesh_conf.manual_value_update(true);
  3010. Redraw_Menu(false);
  3011. }
  3012. break;
  3013. #endif
  3014. }
  3015. break;
  3016. #endif // HAS_MESH
  3017. #if ENABLED(AUTO_BED_LEVELING_UBL) && !HAS_BED_PROBE
  3018. case UBLMesh:
  3019. #define UBL_M_BACK 0
  3020. #define UBL_M_NEXT (UBL_M_BACK + 1)
  3021. #define UBL_M_PREV (UBL_M_NEXT + 1)
  3022. #define UBL_M_OFFSET (UBL_M_PREV + 1)
  3023. #define UBL_M_UP (UBL_M_OFFSET + 1)
  3024. #define UBL_M_DOWN (UBL_M_UP + 1)
  3025. #define UBL_M_TOTAL UBL_M_DOWN
  3026. switch (item) {
  3027. case UBL_M_BACK:
  3028. if (draw)
  3029. Draw_Menu_Item(row, ICON_Back, F("Back"));
  3030. else {
  3031. set_bed_leveling_enabled(level_state);
  3032. Draw_Menu(Leveling, LEVELING_GET_MESH);
  3033. }
  3034. break;
  3035. case UBL_M_NEXT:
  3036. if (draw) {
  3037. if (mesh_conf.mesh_x != (GRID_MAX_POINTS_X - 1) || mesh_conf.mesh_y != (GRID_MAX_POINTS_Y - 1))
  3038. Draw_Menu_Item(row, ICON_More, F("Next Point"));
  3039. else
  3040. Draw_Menu_Item(row, ICON_More, F("Save Mesh"));
  3041. }
  3042. else {
  3043. if (mesh_conf.mesh_x != (GRID_MAX_POINTS_X - 1) || mesh_conf.mesh_y != (GRID_MAX_POINTS_Y - 1)) {
  3044. if ((mesh_conf.mesh_x == (GRID_MAX_POINTS_X - 1) && mesh_conf.mesh_y % 2 == 0) || (mesh_conf.mesh_x == 0 && mesh_conf.mesh_y % 2 == 1))
  3045. mesh_conf.mesh_y++;
  3046. else if (mesh_conf.mesh_y % 2 == 0)
  3047. mesh_conf.mesh_x++;
  3048. else
  3049. mesh_conf.mesh_x--;
  3050. mesh_conf.manual_move();
  3051. }
  3052. else {
  3053. gcode.process_subcommands_now(F("G29 S"));
  3054. planner.synchronize();
  3055. AudioFeedback(true);
  3056. Draw_Menu(Leveling, LEVELING_GET_MESH);
  3057. }
  3058. }
  3059. break;
  3060. case UBL_M_PREV:
  3061. if (draw)
  3062. Draw_Menu_Item(row, ICON_More, F("Previous Point"));
  3063. else {
  3064. if (mesh_conf.mesh_x != 0 || mesh_conf.mesh_y != 0) {
  3065. if ((mesh_conf.mesh_x == (GRID_MAX_POINTS_X - 1) && mesh_conf.mesh_y % 2 == 1) || (mesh_conf.mesh_x == 0 && mesh_conf.mesh_y % 2 == 0))
  3066. mesh_conf.mesh_y--;
  3067. else if (mesh_conf.mesh_y % 2 == 0)
  3068. mesh_conf.mesh_x--;
  3069. else
  3070. mesh_conf.mesh_x++;
  3071. mesh_conf.manual_move();
  3072. }
  3073. }
  3074. break;
  3075. case UBL_M_OFFSET:
  3076. if (draw) {
  3077. Draw_Menu_Item(row, ICON_SetZOffset, F("Point Z Offset"));
  3078. Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row, false, 100);
  3079. }
  3080. else {
  3081. if (isnan(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y]))
  3082. bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] = 0;
  3083. Modify_Value(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
  3084. }
  3085. break;
  3086. case UBL_M_UP:
  3087. if (draw)
  3088. Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
  3089. else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] < MAX_Z_OFFSET) {
  3090. bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] += 0.01;
  3091. gcode.process_subcommands_now(F("M290 Z0.01"));
  3092. planner.synchronize();
  3093. current_position.z += 0.01f;
  3094. sync_plan_position();
  3095. Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 1, false, 100);
  3096. }
  3097. break;
  3098. case UBL_M_DOWN:
  3099. if (draw)
  3100. Draw_Menu_Item(row, ICON_Axis, F("Microstep Down"));
  3101. else if (bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] > MIN_Z_OFFSET) {
  3102. bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y] -= 0.01;
  3103. gcode.process_subcommands_now(F("M290 Z-0.01"));
  3104. planner.synchronize();
  3105. current_position.z -= 0.01f;
  3106. sync_plan_position();
  3107. Draw_Float(bedlevel.z_values[mesh_conf.mesh_x][mesh_conf.mesh_y], row - 2, false, 100);
  3108. }
  3109. break;
  3110. }
  3111. break;
  3112. #endif // AUTO_BED_LEVELING_UBL && !HAS_BED_PROBE
  3113. #if ENABLED(PROBE_MANUALLY)
  3114. case ManualMesh:
  3115. #define MMESH_BACK 0
  3116. #define MMESH_NEXT (MMESH_BACK + 1)
  3117. #define MMESH_OFFSET (MMESH_NEXT + 1)
  3118. #define MMESH_UP (MMESH_OFFSET + 1)
  3119. #define MMESH_DOWN (MMESH_UP + 1)
  3120. #define MMESH_OLD (MMESH_DOWN + 1)
  3121. #define MMESH_TOTAL MMESH_OLD
  3122. switch (item) {
  3123. case MMESH_BACK:
  3124. if (draw)
  3125. Draw_Menu_Item(row, ICON_Back, F("Cancel"));
  3126. else {
  3127. gcode.process_subcommands_now(F("G29 A"));
  3128. planner.synchronize();
  3129. set_bed_leveling_enabled(level_state);
  3130. Draw_Menu(Leveling, LEVELING_GET_MESH);
  3131. }
  3132. break;
  3133. case MMESH_NEXT:
  3134. if (draw) {
  3135. if (gridpoint < GRID_MAX_POINTS)
  3136. Draw_Menu_Item(row, ICON_More, F("Next Point"));
  3137. else
  3138. Draw_Menu_Item(row, ICON_More, F("Save Mesh"));
  3139. }
  3140. else if (gridpoint < GRID_MAX_POINTS) {
  3141. Popup_Handler(MoveWait);
  3142. gcode.process_subcommands_now(F("G29"));
  3143. planner.synchronize();
  3144. gridpoint++;
  3145. Redraw_Menu();
  3146. }
  3147. else {
  3148. gcode.process_subcommands_now(F("G29"));
  3149. planner.synchronize();
  3150. AudioFeedback(settings.save());
  3151. Draw_Menu(Leveling, LEVELING_GET_MESH);
  3152. }
  3153. break;
  3154. case MMESH_OFFSET:
  3155. if (draw) {
  3156. Draw_Menu_Item(row, ICON_SetZOffset, F("Z Position"));
  3157. current_position.z = MANUAL_PROBE_START_Z;
  3158. Draw_Float(current_position.z, row, false, 100);
  3159. }
  3160. else
  3161. Modify_Value(current_position.z, MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
  3162. break;
  3163. case MMESH_UP:
  3164. if (draw)
  3165. Draw_Menu_Item(row, ICON_Axis, F("Microstep Up"));
  3166. else if (current_position.z < MAX_Z_OFFSET) {
  3167. gcode.process_subcommands_now(F("M290 Z0.01"));
  3168. planner.synchronize();
  3169. current_position.z += 0.01f;
  3170. sync_plan_position();
  3171. Draw_Float(current_position.z, row - 1, false, 100);
  3172. }
  3173. break;
  3174. case MMESH_DOWN:
  3175. if (draw)
  3176. Draw_Menu_Item(row, ICON_AxisD, F("Microstep Down"));
  3177. else if (current_position.z > MIN_Z_OFFSET) {
  3178. gcode.process_subcommands_now(F("M290 Z-0.01"));
  3179. planner.synchronize();
  3180. current_position.z -= 0.01f;
  3181. sync_plan_position();
  3182. Draw_Float(current_position.z, row - 2, false, 100);
  3183. }
  3184. break;
  3185. case MMESH_OLD:
  3186. uint8_t mesh_x, mesh_y;
  3187. // 0,0 -> 1,0 -> 2,0 -> 2,1 -> 1,1 -> 0,1 -> 0,2 -> 1,2 -> 2,2
  3188. mesh_y = (gridpoint - 1) / (GRID_MAX_POINTS_Y);
  3189. mesh_x = (gridpoint - 1) % (GRID_MAX_POINTS_X);
  3190. if (mesh_y % 2 == 1)
  3191. mesh_x = (GRID_MAX_POINTS_X) - mesh_x - 1;
  3192. const float currval = bedlevel.z_values[mesh_x][mesh_y];
  3193. if (draw) {
  3194. Draw_Menu_Item(row, ICON_Zoffset, F("Goto Mesh Value"));
  3195. Draw_Float(currval, row, false, 100);
  3196. }
  3197. else if (!isnan(currval)) {
  3198. current_position.z = currval;
  3199. planner.synchronize();
  3200. planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
  3201. planner.synchronize();
  3202. Draw_Float(current_position.z, row - 3, false, 100);
  3203. }
  3204. break;
  3205. }
  3206. break;
  3207. #endif // PROBE_MANUALLY
  3208. case Tune:
  3209. #define TUNE_BACK 0
  3210. #define TUNE_SPEED (TUNE_BACK + 1)
  3211. #define TUNE_FLOW (TUNE_SPEED + ENABLED(HAS_HOTEND))
  3212. #define TUNE_HOTEND (TUNE_FLOW + ENABLED(HAS_HOTEND))
  3213. #define TUNE_BED (TUNE_HOTEND + ENABLED(HAS_HEATED_BED))
  3214. #define TUNE_FAN (TUNE_BED + ENABLED(HAS_FAN))
  3215. #define TUNE_ZOFFSET (TUNE_FAN + ENABLED(HAS_ZOFFSET_ITEM))
  3216. #define TUNE_ZUP (TUNE_ZOFFSET + ENABLED(HAS_ZOFFSET_ITEM))
  3217. #define TUNE_ZDOWN (TUNE_ZUP + ENABLED(HAS_ZOFFSET_ITEM))
  3218. #define TUNE_CHANGEFIL (TUNE_ZDOWN + ENABLED(FILAMENT_LOAD_UNLOAD_GCODES))
  3219. #define TUNE_FILSENSORENABLED (TUNE_CHANGEFIL + ENABLED(FILAMENT_RUNOUT_SENSOR))
  3220. #define TUNE_BACKLIGHT_OFF (TUNE_FILSENSORENABLED + 1)
  3221. #define TUNE_BACKLIGHT (TUNE_BACKLIGHT_OFF + 1)
  3222. #define TUNE_TOTAL TUNE_BACKLIGHT
  3223. switch (item) {
  3224. case TUNE_BACK:
  3225. if (draw)
  3226. Draw_Menu_Item(row, ICON_Back, F("Back"));
  3227. else
  3228. Draw_Print_Screen();
  3229. break;
  3230. case TUNE_SPEED:
  3231. if (draw) {
  3232. Draw_Menu_Item(row, ICON_Speed, F("Print Speed"));
  3233. Draw_Float(feedrate_percentage, row, false, 1);
  3234. }
  3235. else
  3236. Modify_Value(feedrate_percentage, MIN_PRINT_SPEED, MAX_PRINT_SPEED, 1);
  3237. break;
  3238. #if HAS_HOTEND
  3239. case TUNE_FLOW:
  3240. if (draw) {
  3241. Draw_Menu_Item(row, ICON_Speed, F("Flow Rate"));
  3242. Draw_Float(planner.flow_percentage[0], row, false, 1);
  3243. }
  3244. else
  3245. Modify_Value(planner.flow_percentage[0], MIN_FLOW_RATE, MAX_FLOW_RATE, 1);
  3246. break;
  3247. case TUNE_HOTEND:
  3248. if (draw) {
  3249. Draw_Menu_Item(row, ICON_SetEndTemp, F("Hotend"));
  3250. Draw_Float(thermalManager.temp_hotend[0].target, row, false, 1);
  3251. }
  3252. else
  3253. Modify_Value(thermalManager.temp_hotend[0].target, MIN_E_TEMP, MAX_E_TEMP, 1);
  3254. break;
  3255. #endif
  3256. #if HAS_HEATED_BED
  3257. case TUNE_BED:
  3258. if (draw) {
  3259. Draw_Menu_Item(row, ICON_SetBedTemp, F("Bed"));
  3260. Draw_Float(thermalManager.temp_bed.target, row, false, 1);
  3261. }
  3262. else
  3263. Modify_Value(thermalManager.temp_bed.target, MIN_BED_TEMP, MAX_BED_TEMP, 1);
  3264. break;
  3265. #endif
  3266. #if HAS_FAN
  3267. case TUNE_FAN:
  3268. if (draw) {
  3269. Draw_Menu_Item(row, ICON_FanSpeed, F("Fan"));
  3270. Draw_Float(thermalManager.fan_speed[0], row, false, 1);
  3271. }
  3272. else
  3273. Modify_Value(thermalManager.fan_speed[0], MIN_FAN_SPEED, MAX_FAN_SPEED, 1);
  3274. break;
  3275. #endif
  3276. #if HAS_ZOFFSET_ITEM
  3277. case TUNE_ZOFFSET:
  3278. if (draw) {
  3279. Draw_Menu_Item(row, ICON_FanSpeed, F("Z-Offset"));
  3280. Draw_Float(zoffsetvalue, row, false, 100);
  3281. }
  3282. else
  3283. Modify_Value(zoffsetvalue, MIN_Z_OFFSET, MAX_Z_OFFSET, 100);
  3284. break;
  3285. case TUNE_ZUP:
  3286. if (draw)
  3287. Draw_Menu_Item(row, ICON_Axis, F("Z-Offset Up"));
  3288. else if (zoffsetvalue < MAX_Z_OFFSET) {
  3289. gcode.process_subcommands_now(F("M290 Z0.01"));
  3290. zoffsetvalue += 0.01;
  3291. Draw_Float(zoffsetvalue, row - 1, false, 100);
  3292. }
  3293. break;
  3294. case TUNE_ZDOWN:
  3295. if (draw)
  3296. Draw_Menu_Item(row, ICON_AxisD, F("Z-Offset Down"));
  3297. else if (zoffsetvalue > MIN_Z_OFFSET) {
  3298. gcode.process_subcommands_now(F("M290 Z-0.01"));
  3299. zoffsetvalue -= 0.01;
  3300. Draw_Float(zoffsetvalue, row - 2, false, 100);
  3301. }
  3302. break;
  3303. #endif
  3304. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  3305. case TUNE_CHANGEFIL:
  3306. if (draw)
  3307. Draw_Menu_Item(row, ICON_ResumeEEPROM, F("Change Filament"));
  3308. else
  3309. Popup_Handler(ConfFilChange);
  3310. break;
  3311. #endif
  3312. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  3313. case TUNE_FILSENSORENABLED:
  3314. if (draw) {
  3315. Draw_Menu_Item(row, ICON_Extruder, F("Filament Sensor"));
  3316. Draw_Checkbox(row, runout.enabled);
  3317. }
  3318. else {
  3319. runout.enabled = !runout.enabled;
  3320. Draw_Checkbox(row, runout.enabled);
  3321. }
  3322. break;
  3323. #endif
  3324. case TUNE_BACKLIGHT_OFF:
  3325. if (draw)
  3326. Draw_Menu_Item(row, ICON_Brightness, F("Display Off"));
  3327. else
  3328. ui.set_brightness(0);
  3329. break;
  3330. case TUNE_BACKLIGHT:
  3331. if (draw) {
  3332. Draw_Menu_Item(row, ICON_Brightness, F("LCD Brightness"));
  3333. Draw_Float(ui.brightness, row, false, 1);
  3334. }
  3335. else
  3336. Modify_Value(ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, 1, ui.refresh_brightness);
  3337. break;
  3338. }
  3339. break;
  3340. #if HAS_PREHEAT && HAS_HOTEND
  3341. case PreheatHotend:
  3342. #define PREHEATHOTEND_BACK 0
  3343. #define PREHEATHOTEND_CONTINUE (PREHEATHOTEND_BACK + 1)
  3344. #define PREHEATHOTEND_1 (PREHEATHOTEND_CONTINUE + (PREHEAT_COUNT >= 1))
  3345. #define PREHEATHOTEND_2 (PREHEATHOTEND_1 + (PREHEAT_COUNT >= 2))
  3346. #define PREHEATHOTEND_3 (PREHEATHOTEND_2 + (PREHEAT_COUNT >= 3))
  3347. #define PREHEATHOTEND_4 (PREHEATHOTEND_3 + (PREHEAT_COUNT >= 4))
  3348. #define PREHEATHOTEND_5 (PREHEATHOTEND_4 + (PREHEAT_COUNT >= 5))
  3349. #define PREHEATHOTEND_CUSTOM (PREHEATHOTEND_5 + 1)
  3350. #define PREHEATHOTEND_TOTAL PREHEATHOTEND_CUSTOM
  3351. switch (item) {
  3352. case PREHEATHOTEND_BACK:
  3353. if (draw)
  3354. Draw_Menu_Item(row, ICON_Back, F("Cancel"));
  3355. else {
  3356. thermalManager.setTargetHotend(0, 0);
  3357. thermalManager.set_fan_speed(0, 0);
  3358. Redraw_Menu(false, true, true);
  3359. }
  3360. break;
  3361. case PREHEATHOTEND_CONTINUE:
  3362. if (draw)
  3363. Draw_Menu_Item(row, ICON_SetEndTemp, F("Continue"));
  3364. else {
  3365. Popup_Handler(Heating);
  3366. thermalManager.wait_for_hotend(0);
  3367. switch (last_menu) {
  3368. case Prepare:
  3369. Popup_Handler(FilChange);
  3370. sprintf_P(cmd, PSTR("M600 B1 R%i"), thermalManager.temp_hotend[0].target);
  3371. gcode.process_subcommands_now(cmd);
  3372. break;
  3373. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  3374. case ChangeFilament:
  3375. switch (last_selection) {
  3376. case CHANGEFIL_LOAD:
  3377. Popup_Handler(FilLoad);
  3378. gcode.process_subcommands_now(F("M701"));
  3379. planner.synchronize();
  3380. Redraw_Menu(true, true, true);
  3381. break;
  3382. case CHANGEFIL_UNLOAD:
  3383. Popup_Handler(FilLoad, true);
  3384. gcode.process_subcommands_now(F("M702"));
  3385. planner.synchronize();
  3386. Redraw_Menu(true, true, true);
  3387. break;
  3388. case CHANGEFIL_CHANGE:
  3389. Popup_Handler(FilChange);
  3390. sprintf_P(cmd, PSTR("M600 B1 R%i"), thermalManager.temp_hotend[0].target);
  3391. gcode.process_subcommands_now(cmd);
  3392. break;
  3393. }
  3394. break;
  3395. #endif
  3396. default:
  3397. Redraw_Menu(true, true, true);
  3398. break;
  3399. }
  3400. }
  3401. break;
  3402. #define _PREHEAT_HOTEND_CASE(N) \
  3403. case PREHEATHOTEND_##N: \
  3404. if (draw) Draw_Menu_Item(row, ICON_Temperature, F(PREHEAT_## N ##_LABEL)); \
  3405. else ui.preheat_hotend_and_fan((N) - 1); \
  3406. break;
  3407. REPEAT_1(PREHEAT_COUNT, _PREHEAT_HOTEND_CASE)
  3408. case PREHEATHOTEND_CUSTOM:
  3409. if (draw) {
  3410. Draw_Menu_Item(row, ICON_Temperature, F("Custom"));
  3411. Draw_Float(thermalManager.temp_hotend[0].target, row, false, 1);
  3412. }
  3413. else
  3414. Modify_Value(thermalManager.temp_hotend[0].target, EXTRUDE_MINTEMP, MAX_E_TEMP, 1);
  3415. break;
  3416. }
  3417. break;
  3418. #endif // HAS_PREHEAT && HAS_HOTEND
  3419. }
  3420. }
  3421. FSTR_P CrealityDWINClass::Get_Menu_Title(uint8_t menu) {
  3422. switch (menu) {
  3423. case MainMenu: return F("Main Menu");
  3424. case Prepare: return F("Prepare");
  3425. case HomeMenu: return F("Homing Menu");
  3426. case Move: return F("Move");
  3427. case ManualLevel: return F("Manual Leveling");
  3428. #if HAS_ZOFFSET_ITEM
  3429. case ZOffset: return F("Z Offset");
  3430. #endif
  3431. #if HAS_PREHEAT
  3432. case Preheat: return F("Preheat");
  3433. #endif
  3434. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  3435. case ChangeFilament: return F("Change Filament");
  3436. #endif
  3437. case Control: return F("Control");
  3438. case TempMenu: return F("Temperature");
  3439. #if HAS_HOTEND || HAS_HEATED_BED
  3440. case PID: return F("PID Menu");
  3441. #endif
  3442. #if HAS_HOTEND
  3443. case HotendPID: return F("Hotend PID Settings");
  3444. #endif
  3445. #if HAS_HEATED_BED
  3446. case BedPID: return F("Bed PID Settings");
  3447. #endif
  3448. #if HAS_PREHEAT
  3449. #define _PREHEAT_TITLE_CASE(N) case Preheat##N: return F(PREHEAT_## N ##_LABEL " Settings");
  3450. REPEAT_1(PREHEAT_COUNT, _PREHEAT_TITLE_CASE)
  3451. #endif
  3452. case Motion: return F("Motion Settings");
  3453. case HomeOffsets: return F("Home Offsets");
  3454. case MaxSpeed: return F("Max Speed");
  3455. case MaxAcceleration: return F("Max Acceleration");
  3456. #if HAS_CLASSIC_JERK
  3457. case MaxJerk: return F("Max Jerk");
  3458. #endif
  3459. case Steps: return F("Steps/mm");
  3460. case Visual: return F("Visual Settings");
  3461. case Advanced: return F("Advanced Settings");
  3462. #if HAS_BED_PROBE
  3463. case ProbeMenu: return F("Probe Menu");
  3464. #endif
  3465. case ColorSettings: return F("UI Color Settings");
  3466. case Info: return F("Info");
  3467. case InfoMain: return F("Info");
  3468. #if HAS_MESH
  3469. case Leveling: return F("Leveling");
  3470. case LevelView: return GET_TEXT_F(MSG_MESH_VIEW);
  3471. case LevelSettings: return F("Leveling Settings");
  3472. case MeshViewer: return GET_TEXT_F(MSG_MESH_VIEW);
  3473. case LevelManual: return F("Manual Tuning");
  3474. #endif
  3475. #if ENABLED(AUTO_BED_LEVELING_UBL) && !HAS_BED_PROBE
  3476. case UBLMesh: return F("UBL Bed Leveling");
  3477. #endif
  3478. #if ENABLED(PROBE_MANUALLY)
  3479. case ManualMesh: return F("Mesh Bed Leveling");
  3480. #endif
  3481. case Tune: return F("Tune");
  3482. case PreheatHotend: return F("Preheat Hotend");
  3483. }
  3484. return F("");
  3485. }
  3486. uint8_t CrealityDWINClass::Get_Menu_Size(uint8_t menu) {
  3487. switch (menu) {
  3488. case Prepare: return PREPARE_TOTAL;
  3489. case HomeMenu: return HOME_TOTAL;
  3490. case Move: return MOVE_TOTAL;
  3491. case ManualLevel: return MLEVEL_TOTAL;
  3492. #if HAS_ZOFFSET_ITEM
  3493. case ZOffset: return ZOFFSET_TOTAL;
  3494. #endif
  3495. #if HAS_PREHEAT
  3496. case Preheat: return PREHEAT_TOTAL;
  3497. #endif
  3498. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  3499. case ChangeFilament: return CHANGEFIL_TOTAL;
  3500. #endif
  3501. case Control: return CONTROL_TOTAL;
  3502. case TempMenu: return TEMP_TOTAL;
  3503. #if HAS_HOTEND || HAS_HEATED_BED
  3504. case PID: return PID_TOTAL;
  3505. #endif
  3506. #if HAS_HOTEND
  3507. case HotendPID: return HOTENDPID_TOTAL;
  3508. #endif
  3509. #if HAS_HEATED_BED
  3510. case BedPID: return BEDPID_TOTAL;
  3511. #endif
  3512. #if HAS_PREHEAT
  3513. case Preheat1 ... CAT(Preheat, PREHEAT_COUNT):
  3514. return PREHEAT_SUBMENU_TOTAL;
  3515. #endif
  3516. case Motion: return MOTION_TOTAL;
  3517. case HomeOffsets: return HOMEOFFSETS_TOTAL;
  3518. case MaxSpeed: return SPEED_TOTAL;
  3519. case MaxAcceleration: return ACCEL_TOTAL;
  3520. #if HAS_CLASSIC_JERK
  3521. case MaxJerk: return JERK_TOTAL;
  3522. #endif
  3523. case Steps: return STEPS_TOTAL;
  3524. case Visual: return VISUAL_TOTAL;
  3525. case Advanced: return ADVANCED_TOTAL;
  3526. #if HAS_BED_PROBE
  3527. case ProbeMenu: return PROBE_TOTAL;
  3528. #endif
  3529. case Info: return INFO_TOTAL;
  3530. case InfoMain: return INFO_TOTAL;
  3531. #if ENABLED(AUTO_BED_LEVELING_UBL) && !HAS_BED_PROBE
  3532. case UBLMesh: return UBL_M_TOTAL;
  3533. #endif
  3534. #if ENABLED(PROBE_MANUALLY)
  3535. case ManualMesh: return MMESH_TOTAL;
  3536. #endif
  3537. #if HAS_MESH
  3538. case Leveling: return LEVELING_TOTAL;
  3539. case LevelView: return LEVELING_VIEW_TOTAL;
  3540. case LevelSettings: return LEVELING_SETTINGS_TOTAL;
  3541. case MeshViewer: return MESHVIEW_TOTAL;
  3542. case LevelManual: return LEVELING_M_TOTAL;
  3543. #endif
  3544. case Tune: return TUNE_TOTAL;
  3545. #if HAS_PREHEAT && HAS_HOTEND
  3546. case PreheatHotend: return PREHEATHOTEND_TOTAL;
  3547. #endif
  3548. case ColorSettings: return COLORSETTINGS_TOTAL;
  3549. }
  3550. return 0;
  3551. }
  3552. /* Popup Config */
  3553. void CrealityDWINClass::Popup_Handler(PopupID popupid, bool option/*=false*/) {
  3554. popup = last_popup = popupid;
  3555. switch (popupid) {
  3556. case Pause: Draw_Popup(F("Pause Print"), F(""), F(""), Popup); break;
  3557. case Stop: Draw_Popup(F("Stop Print"), F(""), F(""), Popup); break;
  3558. case Resume: Draw_Popup(F("Resume Print?"), F("Looks Like the last"), F("print was interrupted."), Popup); break;
  3559. case ConfFilChange: Draw_Popup(F("Confirm Filament Change"), F(""), F(""), Popup); break;
  3560. case PurgeMore: Draw_Popup(F("Purge more filament?"), F("(Cancel to finish process)"), F(""), Popup); break;
  3561. case SaveLevel: Draw_Popup(F("Leveling Complete"), F("Save to EEPROM?"), F(""), Popup); break;
  3562. case MeshSlot: Draw_Popup(F("Mesh slot not selected"), F("(Confirm to select slot 0)"), F(""), Popup); break;
  3563. case ETemp: Draw_Popup(F("Nozzle is too cold"), F("Open Preheat Menu?"), F(""), Popup); break;
  3564. case ManualProbing: Draw_Popup(F("Manual Probing"), F("(Confirm to probe)"), F("(cancel to exit)"), Popup); break;
  3565. case Level: Draw_Popup(F("Auto Bed Leveling"), F("Please wait until done."), F(""), Wait, ICON_AutoLeveling); break;
  3566. case Home: Draw_Popup(option ? F("Parking") : F("Homing"), F("Please wait until done."), F(""), Wait, ICON_BLTouch); break;
  3567. case MoveWait: Draw_Popup(F("Moving to Point"), F("Please wait until done."), F(""), Wait, ICON_BLTouch); break;
  3568. case Heating: Draw_Popup(F("Heating"), F("Please wait until done."), F(""), Wait, ICON_BLTouch); break;
  3569. case FilLoad: Draw_Popup(option ? F("Unloading Filament") : F("Loading Filament"), F("Please wait until done."), F(""), Wait, ICON_BLTouch); break;
  3570. case FilChange: Draw_Popup(F("Filament Change"), F("Please wait for prompt."), F(""), Wait, ICON_BLTouch); break;
  3571. case TempWarn: Draw_Popup(option ? F("Nozzle temp too low!") : F("Nozzle temp too high!"), F(""), F(""), Wait, option ? ICON_TempTooLow : ICON_TempTooHigh); break;
  3572. case Runout: Draw_Popup(F("Filament Runout"), F(""), F(""), Wait, ICON_BLTouch); break;
  3573. case PIDWait: Draw_Popup(F("PID Autotune"), F("in process"), F("Please wait until done."), Wait, ICON_BLTouch); break;
  3574. case Resuming: Draw_Popup(F("Resuming Print"), F("Please wait until done."), F(""), Wait, ICON_BLTouch); break;
  3575. default: break;
  3576. }
  3577. }
  3578. void CrealityDWINClass::Confirm_Handler(PopupID popupid) {
  3579. popup = popupid;
  3580. switch (popupid) {
  3581. case FilInsert: Draw_Popup(F("Insert Filament"), F("Press to Continue"), F(""), Confirm); break;
  3582. case HeaterTime: Draw_Popup(F("Heater Timed Out"), F("Press to Reheat"), F(""), Confirm); break;
  3583. case UserInput: Draw_Popup(F("Waiting for Input"), F("Press to Continue"), F(""), Confirm); break;
  3584. case LevelError: Draw_Popup(F("Couldn't enable Leveling"), F("(Valid mesh must exist)"), F(""), Confirm); break;
  3585. case InvalidMesh: Draw_Popup(F("Valid mesh must exist"), F("before tuning can be"), F("performed"), Confirm); break;
  3586. default: break;
  3587. }
  3588. }
  3589. /* Navigation and Control */
  3590. void CrealityDWINClass::Main_Menu_Control() {
  3591. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  3592. if (encoder_diffState == ENCODER_DIFF_NO) return;
  3593. if (encoder_diffState == ENCODER_DIFF_CW && selection < PAGE_COUNT - 1) {
  3594. selection++; // Select Down
  3595. Main_Menu_Icons();
  3596. }
  3597. else if (encoder_diffState == ENCODER_DIFF_CCW && selection > 0) {
  3598. selection--; // Select Up
  3599. Main_Menu_Icons();
  3600. }
  3601. else if (encoder_diffState == ENCODER_DIFF_ENTER)
  3602. switch (selection) {
  3603. case PAGE_PRINT: card.mount(); Draw_SD_List(); break;
  3604. case PAGE_PREPARE: Draw_Menu(Prepare); break;
  3605. case PAGE_CONTROL: Draw_Menu(Control); break;
  3606. case PAGE_INFO_LEVELING: Draw_Menu(TERN(HAS_MESH, Leveling, InfoMain)); break;
  3607. }
  3608. DWIN_UpdateLCD();
  3609. }
  3610. void CrealityDWINClass::Menu_Control() {
  3611. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  3612. if (encoder_diffState == ENCODER_DIFF_NO) return;
  3613. if (encoder_diffState == ENCODER_DIFF_CW && selection < Get_Menu_Size(active_menu)) {
  3614. DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
  3615. selection++; // Select Down
  3616. if (selection > scrollpos+MROWS) {
  3617. scrollpos++;
  3618. DWIN_Frame_AreaMove(1, 2, MLINE, Color_Bg_Black, 0, 31, DWIN_WIDTH, 349);
  3619. Menu_Item_Handler(active_menu, selection);
  3620. }
  3621. DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
  3622. }
  3623. else if (encoder_diffState == ENCODER_DIFF_CCW && selection > 0) {
  3624. DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
  3625. selection--; // Select Up
  3626. if (selection < scrollpos) {
  3627. scrollpos--;
  3628. DWIN_Frame_AreaMove(1, 3, MLINE, Color_Bg_Black, 0, 31, DWIN_WIDTH, 349);
  3629. Menu_Item_Handler(active_menu, selection);
  3630. }
  3631. DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
  3632. }
  3633. else if (encoder_diffState == ENCODER_DIFF_ENTER)
  3634. Menu_Item_Handler(active_menu, selection, false);
  3635. DWIN_UpdateLCD();
  3636. }
  3637. void CrealityDWINClass::Value_Control() {
  3638. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  3639. if (encoder_diffState == ENCODER_DIFF_NO) return;
  3640. if (encoder_diffState == ENCODER_DIFF_CW)
  3641. tempvalue += EncoderRate.encoderMoveValue;
  3642. else if (encoder_diffState == ENCODER_DIFF_CCW)
  3643. tempvalue -= EncoderRate.encoderMoveValue;
  3644. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  3645. process = Menu;
  3646. EncoderRate.enabled = false;
  3647. Draw_Float(tempvalue / valueunit, selection - scrollpos, false, valueunit);
  3648. DWIN_UpdateLCD();
  3649. if (active_menu == ZOffset && liveadjust) {
  3650. planner.synchronize();
  3651. current_position.z += (tempvalue / valueunit - zoffsetvalue);
  3652. planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
  3653. current_position.z = 0;
  3654. sync_plan_position();
  3655. }
  3656. else if (active_menu == Tune && selection == TUNE_ZOFFSET) {
  3657. sprintf_P(cmd, PSTR("M290 Z%s"), dtostrf((tempvalue / valueunit - zoffsetvalue), 1, 3, str_1));
  3658. gcode.process_subcommands_now(cmd);
  3659. }
  3660. if (TERN0(HAS_HOTEND, valuepointer == &thermalManager.temp_hotend[0].pid.Ki) || TERN0(HAS_HEATED_BED, valuepointer == &thermalManager.temp_bed.pid.Ki))
  3661. tempvalue = scalePID_i(tempvalue);
  3662. if (TERN0(HAS_HOTEND, valuepointer == &thermalManager.temp_hotend[0].pid.Kd) || TERN0(HAS_HEATED_BED, valuepointer == &thermalManager.temp_bed.pid.Kd))
  3663. tempvalue = scalePID_d(tempvalue);
  3664. switch (valuetype) {
  3665. case 0: *(float*)valuepointer = tempvalue / valueunit; break;
  3666. case 1: *(uint8_t*)valuepointer = tempvalue / valueunit; break;
  3667. case 2: *(uint16_t*)valuepointer = tempvalue / valueunit; break;
  3668. case 3: *(int16_t*)valuepointer = tempvalue / valueunit; break;
  3669. case 4: *(uint32_t*)valuepointer = tempvalue / valueunit; break;
  3670. case 5: *(int8_t*)valuepointer = tempvalue / valueunit; break;
  3671. }
  3672. switch (active_menu) {
  3673. case Move:
  3674. planner.synchronize();
  3675. planner.buffer_line(current_position, manual_feedrate_mm_s[selection - 1], active_extruder);
  3676. break;
  3677. #if HAS_MESH
  3678. case ManualMesh:
  3679. planner.synchronize();
  3680. planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
  3681. planner.synchronize();
  3682. break;
  3683. case UBLMesh: mesh_conf.manual_move(true); break;
  3684. case LevelManual: mesh_conf.manual_move(selection == LEVELING_M_OFFSET); break;
  3685. #endif
  3686. }
  3687. if (valuepointer == &planner.flow_percentage[0])
  3688. planner.refresh_e_factor(0);
  3689. if (funcpointer) funcpointer();
  3690. return;
  3691. }
  3692. NOLESS(tempvalue, (valuemin * valueunit));
  3693. NOMORE(tempvalue, (valuemax * valueunit));
  3694. Draw_Float(tempvalue / valueunit, selection - scrollpos, true, valueunit);
  3695. DWIN_UpdateLCD();
  3696. if (active_menu == Move && livemove) {
  3697. *(float*)valuepointer = tempvalue / valueunit;
  3698. planner.buffer_line(current_position, manual_feedrate_mm_s[selection - 1], active_extruder);
  3699. }
  3700. }
  3701. void CrealityDWINClass::Option_Control() {
  3702. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  3703. if (encoder_diffState == ENCODER_DIFF_NO) return;
  3704. if (encoder_diffState == ENCODER_DIFF_CW)
  3705. tempvalue += EncoderRate.encoderMoveValue;
  3706. else if (encoder_diffState == ENCODER_DIFF_CCW)
  3707. tempvalue -= EncoderRate.encoderMoveValue;
  3708. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  3709. process = Menu;
  3710. EncoderRate.enabled = false;
  3711. if (valuepointer == &color_names) {
  3712. switch (selection) {
  3713. case COLORSETTINGS_CURSOR: eeprom_settings.cursor_color = tempvalue; break;
  3714. case COLORSETTINGS_SPLIT_LINE: eeprom_settings.menu_split_line = tempvalue; break;
  3715. case COLORSETTINGS_MENU_TOP_BG: eeprom_settings.menu_top_bg = tempvalue; break;
  3716. case COLORSETTINGS_MENU_TOP_TXT: eeprom_settings.menu_top_txt = tempvalue; break;
  3717. case COLORSETTINGS_HIGHLIGHT_BORDER: eeprom_settings.highlight_box = tempvalue; break;
  3718. case COLORSETTINGS_PROGRESS_PERCENT: eeprom_settings.progress_percent = tempvalue; break;
  3719. case COLORSETTINGS_PROGRESS_TIME: eeprom_settings.progress_time = tempvalue; break;
  3720. case COLORSETTINGS_PROGRESS_STATUS_BAR: eeprom_settings.status_bar_text = tempvalue; break;
  3721. case COLORSETTINGS_PROGRESS_STATUS_AREA: eeprom_settings.status_area_text = tempvalue; break;
  3722. case COLORSETTINGS_PROGRESS_COORDINATES: eeprom_settings.coordinates_text = tempvalue; break;
  3723. case COLORSETTINGS_PROGRESS_COORDINATES_LINE: eeprom_settings.coordinates_split_line = tempvalue; break;
  3724. }
  3725. Redraw_Screen();
  3726. }
  3727. else if (valuepointer == &preheat_modes)
  3728. preheatmode = tempvalue;
  3729. Draw_Option(tempvalue, static_cast<const char * const *>(valuepointer), selection - scrollpos, false, (valuepointer == &color_names));
  3730. DWIN_UpdateLCD();
  3731. return;
  3732. }
  3733. NOLESS(tempvalue, valuemin);
  3734. NOMORE(tempvalue, valuemax);
  3735. Draw_Option(tempvalue, static_cast<const char * const *>(valuepointer), selection - scrollpos, true);
  3736. DWIN_UpdateLCD();
  3737. }
  3738. void CrealityDWINClass::File_Control() {
  3739. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  3740. static uint8_t filescrl = 0;
  3741. if (encoder_diffState == ENCODER_DIFF_NO) {
  3742. if (selection > 0) {
  3743. card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
  3744. char * const filename = card.longest_filename();
  3745. size_t len = strlen(filename);
  3746. int8_t pos = len;
  3747. if (!card.flag.filenameIsDir)
  3748. while (pos && filename[pos] != '.') pos--;
  3749. if (pos > MENU_CHAR_LIMIT) {
  3750. static millis_t time = 0;
  3751. if (PENDING(millis(), time)) return;
  3752. time = millis() + 200;
  3753. pos -= filescrl;
  3754. len = _MIN(pos, MENU_CHAR_LIMIT);
  3755. char name[len + 1];
  3756. if (pos >= 0) {
  3757. LOOP_L_N(i, len) name[i] = filename[i + filescrl];
  3758. }
  3759. else {
  3760. LOOP_L_N(i, MENU_CHAR_LIMIT + pos) name[i] = ' ';
  3761. LOOP_S_L_N(i, MENU_CHAR_LIMIT + pos, MENU_CHAR_LIMIT) name[i] = filename[i - (MENU_CHAR_LIMIT + pos)];
  3762. }
  3763. name[len] = '\0';
  3764. DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
  3765. Draw_Menu_Item(selection - scrollpos, card.flag.filenameIsDir ? ICON_More : ICON_File, name);
  3766. if (-pos >= MENU_CHAR_LIMIT) filescrl = 0;
  3767. filescrl++;
  3768. DWIN_UpdateLCD();
  3769. }
  3770. }
  3771. return;
  3772. }
  3773. if (encoder_diffState == ENCODER_DIFF_CW && selection < card.get_num_Files()) {
  3774. DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
  3775. if (selection > 0) {
  3776. DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
  3777. Draw_SD_Item(selection, selection - scrollpos);
  3778. }
  3779. filescrl = 0;
  3780. selection++; // Select Down
  3781. if (selection > scrollpos + MROWS) {
  3782. scrollpos++;
  3783. DWIN_Frame_AreaMove(1, 2, MLINE, Color_Bg_Black, 0, 31, DWIN_WIDTH, 349);
  3784. Draw_SD_Item(selection, selection - scrollpos);
  3785. }
  3786. DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
  3787. }
  3788. else if (encoder_diffState == ENCODER_DIFF_CCW && selection > 0) {
  3789. DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
  3790. DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
  3791. Draw_SD_Item(selection, selection - scrollpos);
  3792. filescrl = 0;
  3793. selection--; // Select Up
  3794. if (selection < scrollpos) {
  3795. scrollpos--;
  3796. DWIN_Frame_AreaMove(1, 3, MLINE, Color_Bg_Black, 0, 31, DWIN_WIDTH, 349);
  3797. Draw_SD_Item(selection, selection - scrollpos);
  3798. }
  3799. DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
  3800. }
  3801. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  3802. if (selection == 0) {
  3803. if (card.flag.workDirIsRoot) {
  3804. process = Main;
  3805. Draw_Main_Menu();
  3806. }
  3807. else {
  3808. card.cdup();
  3809. Draw_SD_List();
  3810. }
  3811. }
  3812. else {
  3813. card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
  3814. if (card.flag.filenameIsDir) {
  3815. card.cd(card.filename);
  3816. Draw_SD_List();
  3817. }
  3818. else {
  3819. card.openAndPrintFile(card.filename);
  3820. }
  3821. }
  3822. }
  3823. DWIN_UpdateLCD();
  3824. }
  3825. void CrealityDWINClass::Print_Screen_Control() {
  3826. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  3827. if (encoder_diffState == ENCODER_DIFF_NO) return;
  3828. if (encoder_diffState == ENCODER_DIFF_CW && selection < PRINT_COUNT - 1) {
  3829. selection++; // Select Down
  3830. Print_Screen_Icons();
  3831. }
  3832. else if (encoder_diffState == ENCODER_DIFF_CCW && selection > 0) {
  3833. selection--; // Select Up
  3834. Print_Screen_Icons();
  3835. }
  3836. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  3837. switch (selection) {
  3838. case PRINT_SETUP:
  3839. Draw_Menu(Tune);
  3840. Update_Status_Bar(true);
  3841. break;
  3842. case PRINT_PAUSE_RESUME:
  3843. if (paused) {
  3844. if (sdprint) {
  3845. wait_for_user = false;
  3846. #if ENABLED(PARK_HEAD_ON_PAUSE)
  3847. card.startOrResumeFilePrinting();
  3848. TERN_(POWER_LOSS_RECOVERY, recovery.prepare());
  3849. #else
  3850. char cmnd[20];
  3851. #if HAS_HEATED_BED
  3852. cmnd[sprintf_P(cmnd, PSTR("M140 S%i"), pausebed)] = '\0';
  3853. gcode.process_subcommands_now(cmnd);
  3854. #endif
  3855. #if HAS_EXTRUDERS
  3856. cmnd[sprintf_P(cmnd, PSTR("M109 S%i"), pausetemp)] = '\0';
  3857. gcode.process_subcommands_now(cmnd);
  3858. #endif
  3859. TERN_(HAS_FAN, thermalManager.fan_speed[0] = pausefan);
  3860. planner.synchronize();
  3861. TERN_(SDSUPPORT, queue.inject(F("M24")));
  3862. #endif
  3863. }
  3864. else {
  3865. TERN_(HOST_ACTION_COMMANDS, hostui.resume());
  3866. }
  3867. Draw_Print_Screen();
  3868. }
  3869. else
  3870. Popup_Handler(Pause);
  3871. break;
  3872. case PRINT_STOP: Popup_Handler(Stop); break;
  3873. }
  3874. }
  3875. DWIN_UpdateLCD();
  3876. }
  3877. void CrealityDWINClass::Popup_Control() {
  3878. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  3879. if (encoder_diffState == ENCODER_DIFF_NO) return;
  3880. if (encoder_diffState == ENCODER_DIFF_CW && selection < 1) {
  3881. selection++;
  3882. Popup_Select();
  3883. }
  3884. else if (encoder_diffState == ENCODER_DIFF_CCW && selection > 0) {
  3885. selection--;
  3886. Popup_Select();
  3887. }
  3888. else if (encoder_diffState == ENCODER_DIFF_ENTER) {
  3889. switch (popup) {
  3890. case Pause:
  3891. if (selection == 0) {
  3892. if (sdprint) {
  3893. #if ENABLED(POWER_LOSS_RECOVERY)
  3894. if (recovery.enabled) recovery.save(true);
  3895. #endif
  3896. #if ENABLED(PARK_HEAD_ON_PAUSE)
  3897. Popup_Handler(Home, true);
  3898. #if ENABLED(SDSUPPORT)
  3899. if (IS_SD_PRINTING()) card.pauseSDPrint();
  3900. #endif
  3901. planner.synchronize();
  3902. queue.inject(F("M125"));
  3903. planner.synchronize();
  3904. #else
  3905. queue.inject(F("M25"));
  3906. TERN_(HAS_HOTEND, pausetemp = thermalManager.temp_hotend[0].target);
  3907. TERN_(HAS_HEATED_BED, pausebed = thermalManager.temp_bed.target);
  3908. TERN_(HAS_FAN, pausefan = thermalManager.fan_speed[0]);
  3909. thermalManager.cooldown();
  3910. #endif
  3911. }
  3912. else {
  3913. TERN_(HOST_ACTION_COMMANDS, hostui.pause());
  3914. }
  3915. }
  3916. Draw_Print_Screen();
  3917. break;
  3918. case Stop:
  3919. if (selection == 0) {
  3920. if (sdprint) {
  3921. ui.abort_print();
  3922. thermalManager.cooldown();
  3923. }
  3924. else {
  3925. TERN_(HOST_ACTION_COMMANDS, hostui.cancel());
  3926. }
  3927. }
  3928. else
  3929. Draw_Print_Screen();
  3930. break;
  3931. case Resume:
  3932. if (selection == 0)
  3933. queue.inject(F("M1000"));
  3934. else {
  3935. queue.inject(F("M1000 C"));
  3936. Draw_Main_Menu();
  3937. }
  3938. break;
  3939. #if HAS_HOTEND
  3940. case ETemp:
  3941. if (selection == 0) {
  3942. thermalManager.setTargetHotend(EXTRUDE_MINTEMP, 0);
  3943. thermalManager.set_fan_speed(0, MAX_FAN_SPEED);
  3944. Draw_Menu(PreheatHotend);
  3945. }
  3946. else
  3947. Redraw_Menu(true, true, false);
  3948. break;
  3949. #endif
  3950. #if HAS_BED_PROBE
  3951. case ManualProbing:
  3952. if (selection == 0) {
  3953. char buf[80];
  3954. const float dif = probe.probe_at_point(current_position.x, current_position.y, PROBE_PT_STOW, 0, false) - corner_avg;
  3955. sprintf_P(buf, dif > 0 ? PSTR("Corner is %smm high") : PSTR("Corner is %smm low"), dtostrf(abs(dif), 1, 3, str_1));
  3956. Update_Status(buf);
  3957. }
  3958. else {
  3959. Redraw_Menu(true, true, false);
  3960. Update_Status("");
  3961. }
  3962. break;
  3963. #endif
  3964. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  3965. case ConfFilChange:
  3966. if (selection == 0) {
  3967. if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp)
  3968. Popup_Handler(ETemp);
  3969. else {
  3970. if (thermalManager.temp_hotend[0].celsius < thermalManager.temp_hotend[0].target - 2) {
  3971. Popup_Handler(Heating);
  3972. thermalManager.wait_for_hotend(0);
  3973. }
  3974. Popup_Handler(FilChange);
  3975. sprintf_P(cmd, PSTR("M600 B1 R%i"), thermalManager.temp_hotend[0].target);
  3976. gcode.process_subcommands_now(cmd);
  3977. }
  3978. }
  3979. else
  3980. Redraw_Menu(true, true, false);
  3981. break;
  3982. case PurgeMore:
  3983. if (selection == 0) {
  3984. pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE;
  3985. Popup_Handler(FilChange);
  3986. }
  3987. else {
  3988. pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT;
  3989. if (printing) Popup_Handler(Resuming);
  3990. else Redraw_Menu(true, true, (active_menu==PreheatHotend));
  3991. }
  3992. break;
  3993. #endif // ADVANCED_PAUSE_FEATURE
  3994. #if HAS_MESH
  3995. case SaveLevel:
  3996. if (selection == 0) {
  3997. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3998. gcode.process_subcommands_now(F("G29 S"));
  3999. planner.synchronize();
  4000. AudioFeedback(true);
  4001. #else
  4002. AudioFeedback(settings.save());
  4003. #endif
  4004. }
  4005. Draw_Menu(Leveling, LEVELING_GET_MESH);
  4006. break;
  4007. #endif
  4008. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4009. case MeshSlot:
  4010. if (selection == 0) bedlevel.storage_slot = 0;
  4011. Redraw_Menu(true, true);
  4012. break;
  4013. #endif
  4014. default: break;
  4015. }
  4016. }
  4017. DWIN_UpdateLCD();
  4018. }
  4019. void CrealityDWINClass::Confirm_Control() {
  4020. EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
  4021. if (encoder_diffState == ENCODER_DIFF_NO) return;
  4022. if (encoder_diffState == ENCODER_DIFF_ENTER) {
  4023. switch (popup) {
  4024. case Complete:
  4025. Draw_Main_Menu();
  4026. break;
  4027. case FilInsert:
  4028. Popup_Handler(FilChange);
  4029. wait_for_user = false;
  4030. break;
  4031. case HeaterTime:
  4032. Popup_Handler(Heating);
  4033. wait_for_user = false;
  4034. break;
  4035. default:
  4036. Redraw_Menu(true, true, false);
  4037. wait_for_user = false;
  4038. break;
  4039. }
  4040. }
  4041. DWIN_UpdateLCD();
  4042. }
  4043. /* In-Menu Value Modification */
  4044. void CrealityDWINClass::Setup_Value(float value, float min, float max, float unit, uint8_t type) {
  4045. if (TERN0(HAS_HOTEND, valuepointer == &thermalManager.temp_hotend[0].pid.Ki) || TERN0(HAS_HEATED_BED, valuepointer == &thermalManager.temp_bed.pid.Ki))
  4046. tempvalue = unscalePID_i(value) * unit;
  4047. else if (TERN0(HAS_HOTEND, valuepointer == &thermalManager.temp_hotend[0].pid.Kd) || TERN0(HAS_HEATED_BED, valuepointer == &thermalManager.temp_bed.pid.Kd))
  4048. tempvalue = unscalePID_d(value) * unit;
  4049. else
  4050. tempvalue = value * unit;
  4051. valuemin = min;
  4052. valuemax = max;
  4053. valueunit = unit;
  4054. valuetype = type;
  4055. process = Value;
  4056. EncoderRate.enabled = true;
  4057. Draw_Float(tempvalue / unit, selection - scrollpos, true, valueunit);
  4058. }
  4059. void CrealityDWINClass::Modify_Value(float &value, float min, float max, float unit, void (*f)()/*=nullptr*/) {
  4060. valuepointer = &value;
  4061. funcpointer = f;
  4062. Setup_Value((float)value, min, max, unit, 0);
  4063. }
  4064. void CrealityDWINClass::Modify_Value(uint8_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) {
  4065. valuepointer = &value;
  4066. funcpointer = f;
  4067. Setup_Value((float)value, min, max, unit, 1);
  4068. }
  4069. void CrealityDWINClass::Modify_Value(uint16_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) {
  4070. valuepointer = &value;
  4071. funcpointer = f;
  4072. Setup_Value((float)value, min, max, unit, 2);
  4073. }
  4074. void CrealityDWINClass::Modify_Value(int16_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) {
  4075. valuepointer = &value;
  4076. funcpointer = f;
  4077. Setup_Value((float)value, min, max, unit, 3);
  4078. }
  4079. void CrealityDWINClass::Modify_Value(uint32_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) {
  4080. valuepointer = &value;
  4081. funcpointer = f;
  4082. Setup_Value((float)value, min, max, unit, 4);
  4083. }
  4084. void CrealityDWINClass::Modify_Value(int8_t &value, float min, float max, float unit, void (*f)()/*=nullptr*/) {
  4085. valuepointer = &value;
  4086. funcpointer = f;
  4087. Setup_Value((float)value, min, max, unit, 5);
  4088. }
  4089. void CrealityDWINClass::Modify_Option(uint8_t value, const char * const * options, uint8_t max) {
  4090. tempvalue = value;
  4091. valuepointer = const_cast<const char * *>(options);
  4092. valuemin = 0;
  4093. valuemax = max;
  4094. process = Option;
  4095. EncoderRate.enabled = true;
  4096. Draw_Option(value, options, selection - scrollpos, true);
  4097. }
  4098. /* Main Functions */
  4099. void CrealityDWINClass::Update_Status(const char * const text) {
  4100. if (strncmp_P(text, PSTR("<F>"), 3) == 0) {
  4101. LOOP_L_N(i, _MIN((size_t)LONG_FILENAME_LENGTH, strlen(text))) filename[i] = text[i + 3];
  4102. filename[_MIN((size_t)LONG_FILENAME_LENGTH - 1, strlen(text))] = '\0';
  4103. Draw_Print_Filename(true);
  4104. }
  4105. else {
  4106. LOOP_L_N(i, _MIN((size_t)64, strlen(text))) statusmsg[i] = text[i];
  4107. statusmsg[_MIN((size_t)64, strlen(text))] = '\0';
  4108. }
  4109. }
  4110. void CrealityDWINClass::Start_Print(bool sd) {
  4111. sdprint = sd;
  4112. if (!printing) {
  4113. printing = true;
  4114. statusmsg[0] = '\0';
  4115. if (sd) {
  4116. #if ENABLED(POWER_LOSS_RECOVERY)
  4117. if (recovery.valid()) {
  4118. SdFile *diveDir = nullptr;
  4119. const char * const fname = card.diveToFile(true, diveDir, recovery.info.sd_filename);
  4120. card.selectFileByName(fname);
  4121. }
  4122. #endif
  4123. strcpy(filename, card.longest_filename());
  4124. }
  4125. else
  4126. strcpy_P(filename, PSTR("Host Print"));
  4127. TERN_(LCD_SET_PROGRESS_MANUALLY, ui.set_progress(0));
  4128. TERN_(USE_M73_REMAINING_TIME, ui.set_remaining_time(0));
  4129. Draw_Print_Screen();
  4130. }
  4131. }
  4132. void CrealityDWINClass::Stop_Print() {
  4133. printing = false;
  4134. sdprint = false;
  4135. thermalManager.cooldown();
  4136. TERN_(LCD_SET_PROGRESS_MANUALLY, ui.set_progress(100 * (PROGRESS_SCALE)));
  4137. TERN_(USE_M73_REMAINING_TIME, ui.set_remaining_time(0));
  4138. Draw_Print_confirm();
  4139. }
  4140. void CrealityDWINClass::Update() {
  4141. State_Update();
  4142. Screen_Update();
  4143. switch (process) {
  4144. case Main: Main_Menu_Control(); break;
  4145. case Menu: Menu_Control(); break;
  4146. case Value: Value_Control(); break;
  4147. case Option: Option_Control(); break;
  4148. case File: File_Control(); break;
  4149. case Print: Print_Screen_Control(); break;
  4150. case Popup: Popup_Control(); break;
  4151. case Confirm: Confirm_Control(); break;
  4152. }
  4153. }
  4154. void MarlinUI::update() { CrealityDWIN.Update(); }
  4155. #if HAS_LCD_BRIGHTNESS
  4156. void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
  4157. #endif
  4158. void CrealityDWINClass::State_Update() {
  4159. if ((print_job_timer.isRunning() || print_job_timer.isPaused()) != printing) {
  4160. if (!printing) Start_Print(card.isFileOpen() || TERN0(POWER_LOSS_RECOVERY, recovery.valid()));
  4161. else Stop_Print();
  4162. }
  4163. if (print_job_timer.isPaused() != paused) {
  4164. paused = print_job_timer.isPaused();
  4165. if (process == Print) Print_Screen_Icons();
  4166. if (process == Wait && !paused) Redraw_Menu(true, true);
  4167. }
  4168. if (wait_for_user && !(process == Confirm) && !print_job_timer.isPaused())
  4169. Confirm_Handler(UserInput);
  4170. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  4171. if (process == Popup && popup == PurgeMore) {
  4172. if (pause_menu_response == PAUSE_RESPONSE_EXTRUDE_MORE)
  4173. Popup_Handler(FilChange);
  4174. else if (pause_menu_response == PAUSE_RESPONSE_RESUME_PRINT) {
  4175. if (printing) Popup_Handler(Resuming);
  4176. else Redraw_Menu(true, true, (active_menu==PreheatHotend));
  4177. }
  4178. }
  4179. #endif
  4180. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  4181. static bool ranout = false;
  4182. if (runout.filament_ran_out != ranout) {
  4183. ranout = runout.filament_ran_out;
  4184. if (ranout) Popup_Handler(Runout);
  4185. }
  4186. #endif
  4187. }
  4188. void CrealityDWINClass::Screen_Update() {
  4189. const millis_t ms = millis();
  4190. static millis_t scrltime = 0;
  4191. if (ELAPSED(ms, scrltime)) {
  4192. scrltime = ms + 200;
  4193. Update_Status_Bar();
  4194. if (process == Print) Draw_Print_Filename();
  4195. }
  4196. static millis_t statustime = 0;
  4197. if (ELAPSED(ms, statustime)) {
  4198. statustime = ms + 500;
  4199. Draw_Status_Area();
  4200. }
  4201. static millis_t printtime = 0;
  4202. if (ELAPSED(ms, printtime)) {
  4203. printtime = ms + 1000;
  4204. if (process == Print) {
  4205. Draw_Print_ProgressBar();
  4206. Draw_Print_ProgressElapsed();
  4207. TERN_(USE_M73_REMAINING_TIME, Draw_Print_ProgressRemain());
  4208. }
  4209. }
  4210. static bool mounted = card.isMounted();
  4211. if (mounted != card.isMounted()) {
  4212. mounted = card.isMounted();
  4213. if (process == File)
  4214. Draw_SD_List();
  4215. }
  4216. #if HAS_HOTEND
  4217. static int16_t hotendtarget = -1;
  4218. #endif
  4219. #if HAS_HEATED_BED
  4220. static int16_t bedtarget = -1;
  4221. #endif
  4222. #if HAS_FAN
  4223. static int16_t fanspeed = -1;
  4224. #endif
  4225. #if HAS_ZOFFSET_ITEM
  4226. static float lastzoffset = zoffsetvalue;
  4227. if (zoffsetvalue != lastzoffset) {
  4228. lastzoffset = zoffsetvalue;
  4229. #if HAS_BED_PROBE
  4230. probe.offset.z = zoffsetvalue;
  4231. #else
  4232. set_home_offset(Z_AXIS, -zoffsetvalue);
  4233. #endif
  4234. }
  4235. #if HAS_BED_PROBE
  4236. if (probe.offset.z != lastzoffset)
  4237. zoffsetvalue = lastzoffset = probe.offset.z;
  4238. #else
  4239. if (-home_offset.z != lastzoffset)
  4240. zoffsetvalue = lastzoffset = -home_offset.z;
  4241. #endif
  4242. #endif // HAS_ZOFFSET_ITEM
  4243. if (process == Menu || process == Value) {
  4244. switch (active_menu) {
  4245. case TempMenu:
  4246. #if HAS_HOTEND
  4247. if (thermalManager.temp_hotend[0].target != hotendtarget) {
  4248. hotendtarget = thermalManager.temp_hotend[0].target;
  4249. if (scrollpos <= TEMP_HOTEND && TEMP_HOTEND <= scrollpos + MROWS) {
  4250. if (process != Value || selection != TEMP_HOTEND - scrollpos)
  4251. Draw_Float(thermalManager.temp_hotend[0].target, TEMP_HOTEND - scrollpos, false, 1);
  4252. }
  4253. }
  4254. #endif
  4255. #if HAS_HEATED_BED
  4256. if (thermalManager.temp_bed.target != bedtarget) {
  4257. bedtarget = thermalManager.temp_bed.target;
  4258. if (scrollpos <= TEMP_BED && TEMP_BED <= scrollpos + MROWS) {
  4259. if (process != Value || selection != TEMP_HOTEND - scrollpos)
  4260. Draw_Float(thermalManager.temp_bed.target, TEMP_BED - scrollpos, false, 1);
  4261. }
  4262. }
  4263. #endif
  4264. #if HAS_FAN
  4265. if (thermalManager.fan_speed[0] != fanspeed) {
  4266. fanspeed = thermalManager.fan_speed[0];
  4267. if (scrollpos <= TEMP_FAN && TEMP_FAN <= scrollpos + MROWS) {
  4268. if (process != Value || selection != TEMP_HOTEND - scrollpos)
  4269. Draw_Float(thermalManager.fan_speed[0], TEMP_FAN - scrollpos, false, 1);
  4270. }
  4271. }
  4272. #endif
  4273. break;
  4274. case Tune:
  4275. #if HAS_HOTEND
  4276. if (thermalManager.temp_hotend[0].target != hotendtarget) {
  4277. hotendtarget = thermalManager.temp_hotend[0].target;
  4278. if (scrollpos <= TUNE_HOTEND && TUNE_HOTEND <= scrollpos + MROWS) {
  4279. if (process != Value || selection != TEMP_HOTEND - scrollpos)
  4280. Draw_Float(thermalManager.temp_hotend[0].target, TUNE_HOTEND - scrollpos, false, 1);
  4281. }
  4282. }
  4283. #endif
  4284. #if HAS_HEATED_BED
  4285. if (thermalManager.temp_bed.target != bedtarget) {
  4286. bedtarget = thermalManager.temp_bed.target;
  4287. if (scrollpos <= TUNE_BED && TUNE_BED <= scrollpos + MROWS) {
  4288. if (process != Value || selection != TEMP_HOTEND - scrollpos)
  4289. Draw_Float(thermalManager.temp_bed.target, TUNE_BED - scrollpos, false, 1);
  4290. }
  4291. }
  4292. #endif
  4293. #if HAS_FAN
  4294. if (thermalManager.fan_speed[0] != fanspeed) {
  4295. fanspeed = thermalManager.fan_speed[0];
  4296. if (scrollpos <= TUNE_FAN && TUNE_FAN <= scrollpos + MROWS) {
  4297. if (process != Value || selection != TEMP_HOTEND - scrollpos)
  4298. Draw_Float(thermalManager.fan_speed[0], TUNE_FAN - scrollpos, false, 1);
  4299. }
  4300. }
  4301. #endif
  4302. break;
  4303. }
  4304. }
  4305. }
  4306. void CrealityDWINClass::AudioFeedback(const bool success/*=true*/) {
  4307. if (ui.sound_on)
  4308. DONE_BUZZ(success);
  4309. else
  4310. Update_Status(success ? "Success" : "Failed");
  4311. }
  4312. void CrealityDWINClass::Save_Settings(char *buff) {
  4313. TERN_(AUTO_BED_LEVELING_UBL, eeprom_settings.tilt_grid_size = mesh_conf.tilt_grid - 1);
  4314. eeprom_settings.corner_pos = corner_pos * 10;
  4315. memcpy(buff, &eeprom_settings, _MIN(sizeof(eeprom_settings), eeprom_data_size));
  4316. }
  4317. void CrealityDWINClass::Load_Settings(const char *buff) {
  4318. memcpy(&eeprom_settings, buff, _MIN(sizeof(eeprom_settings), eeprom_data_size));
  4319. TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1);
  4320. if (eeprom_settings.corner_pos == 0) eeprom_settings.corner_pos = 325;
  4321. corner_pos = eeprom_settings.corner_pos / 10.0f;
  4322. Redraw_Screen();
  4323. #if ENABLED(POWER_LOSS_RECOVERY)
  4324. static bool init = true;
  4325. if (init) {
  4326. init = false;
  4327. queue.inject(F("M1000 S"));
  4328. }
  4329. #endif
  4330. }
  4331. void CrealityDWINClass::Reset_Settings() {
  4332. eeprom_settings.time_format_textual = false;
  4333. TERN_(AUTO_BED_LEVELING_UBL, eeprom_settings.tilt_grid_size = 0);
  4334. eeprom_settings.corner_pos = 325;
  4335. eeprom_settings.cursor_color = 0;
  4336. eeprom_settings.menu_split_line = 0;
  4337. eeprom_settings.menu_top_bg = 0;
  4338. eeprom_settings.menu_top_txt = 0;
  4339. eeprom_settings.highlight_box = 0;
  4340. eeprom_settings.progress_percent = 0;
  4341. eeprom_settings.progress_time = 0;
  4342. eeprom_settings.status_bar_text = 0;
  4343. eeprom_settings.status_area_text = 0;
  4344. eeprom_settings.coordinates_text = 0;
  4345. eeprom_settings.coordinates_split_line = 0;
  4346. TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1);
  4347. corner_pos = eeprom_settings.corner_pos / 10.0f;
  4348. TERN_(SOUND_MENU_ITEM, ui.sound_on = ENABLED(SOUND_ON_DEFAULT));
  4349. Redraw_Screen();
  4350. }
  4351. void MarlinUI::init_lcd() {
  4352. delay(800);
  4353. SERIAL_ECHOPGM("\nDWIN handshake ");
  4354. if (DWIN_Handshake()) SERIAL_ECHOLNPGM("ok."); else SERIAL_ECHOLNPGM("error.");
  4355. DWIN_Frame_SetDir(1); // Orientation 90°
  4356. DWIN_UpdateLCD(); // Show bootscreen (first image)
  4357. Encoder_Configuration();
  4358. for (uint16_t t = 0; t <= 100; t += 2) {
  4359. DWIN_ICON_Show(ICON, ICON_Bar, 15, 260);
  4360. DWIN_Draw_Rectangle(1, Color_Bg_Black, 15 + t * 242 / 100, 260, 257, 280);
  4361. DWIN_UpdateLCD();
  4362. delay(20);
  4363. }
  4364. DWIN_JPG_ShowAndCache(3);
  4365. DWIN_JPG_CacheTo1(Language_English);
  4366. CrealityDWIN.Redraw_Screen();
  4367. }
  4368. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  4369. void MarlinUI::pause_show_message(const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, const uint8_t extruder/*=active_extruder*/) {
  4370. switch (message) {
  4371. case PAUSE_MESSAGE_INSERT: CrealityDWIN.Confirm_Handler(FilInsert); break;
  4372. case PAUSE_MESSAGE_PURGE:
  4373. case PAUSE_MESSAGE_OPTION: CrealityDWIN.Popup_Handler(PurgeMore); break;
  4374. case PAUSE_MESSAGE_HEAT: CrealityDWIN.Confirm_Handler(HeaterTime); break;
  4375. case PAUSE_MESSAGE_WAITING: CrealityDWIN.Draw_Print_Screen(); break;
  4376. default: break;
  4377. }
  4378. }
  4379. #endif
  4380. #endif // DWIN_CREALITY_LCD_JYERSUI