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

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