ultralcd.cpp 201 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "MarlinConfig.h"
  23. #if ENABLED(ULTRA_LCD)
  24. #include "ultralcd.h"
  25. #include "Marlin.h"
  26. #include "language.h"
  27. #include "cardreader.h"
  28. #include "temperature.h"
  29. #include "planner.h"
  30. #include "stepper.h"
  31. #include "configuration_store.h"
  32. #include "utility.h"
  33. #include "parser.h"
  34. #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
  35. #include "buzzer.h"
  36. #endif
  37. #include "printcounter.h"
  38. #if ENABLED(PRINTCOUNTER)
  39. #include "duration_t.h"
  40. #endif
  41. #if ENABLED(BLTOUCH)
  42. #include "endstops.h"
  43. #endif
  44. #if ENABLED(AUTO_BED_LEVELING_UBL)
  45. #include "ubl.h"
  46. #elif HAS_ABL
  47. #include "planner.h"
  48. #elif ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  49. #include "mesh_bed_leveling.h"
  50. #endif
  51. #if ENABLED(FWRETRACT)
  52. #include "fwretract.h"
  53. #endif
  54. #if ENABLED(POWER_LOSS_RECOVERY)
  55. #include "power_loss_recovery.h"
  56. #endif
  57. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  58. #if LONG_FILENAME_LENGTH > CHARSIZE * 2 * (LCD_WIDTH)
  59. #define MAX_MESSAGE_LENGTH LONG_FILENAME_LENGTH
  60. #else
  61. #define MAX_MESSAGE_LENGTH CHARSIZE * 2 * (LCD_WIDTH)
  62. #endif
  63. uint8_t status_scroll_offset = 0;
  64. #else
  65. #define MAX_MESSAGE_LENGTH CHARSIZE * (LCD_WIDTH)
  66. #endif
  67. char lcd_status_message[MAX_MESSAGE_LENGTH + 1];
  68. uint8_t lcd_status_update_delay = 1, // First update one loop delayed
  69. lcd_status_message_level; // Higher level blocks lower level
  70. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  71. millis_t previous_lcd_status_ms = 0;
  72. #endif
  73. #if ENABLED(ULTIPANEL) && ENABLED(SCROLL_LONG_FILENAMES)
  74. uint8_t filename_scroll_pos, filename_scroll_max, filename_scroll_hash;
  75. #endif
  76. #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
  77. uint8_t progress_bar_percent;
  78. #endif
  79. #if ENABLED(DOGLCD)
  80. #include "ultralcd_impl_DOGM.h"
  81. #include <U8glib.h>
  82. bool drawing_screen, first_page; // = false
  83. #else
  84. #include "ultralcd_impl_HD44780.h"
  85. constexpr bool first_page = true;
  86. #endif
  87. // The main status screen
  88. void lcd_status_screen();
  89. millis_t next_lcd_update_ms;
  90. uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
  91. uint16_t max_display_update_time = 0;
  92. #if ENABLED(ULTIPANEL)
  93. #define DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(_type, _name, _strFunc) \
  94. inline void lcd_implementation_drawmenu_setting_edit_ ## _name (const bool sel, const uint8_t row, const char* pstr, const char* pstr2, _type * const data, ...) { \
  95. UNUSED(pstr2); \
  96. DRAWMENU_SETTING_EDIT_GENERIC(_strFunc(*(data))); \
  97. } \
  98. inline void lcd_implementation_drawmenu_setting_edit_callback_ ## _name (const bool sel, const uint8_t row, const char* pstr, const char* pstr2, _type * const data, ...) { \
  99. UNUSED(pstr2); \
  100. DRAWMENU_SETTING_EDIT_GENERIC(_strFunc(*(data))); \
  101. } \
  102. inline void lcd_implementation_drawmenu_setting_edit_accessor_ ## _name (const bool sel, const uint8_t row, const char* pstr, const char* pstr2, _type (*pget)(), void (*pset)(_type), ...) { \
  103. UNUSED(pstr2); UNUSED(pset); \
  104. DRAWMENU_SETTING_EDIT_GENERIC(_strFunc(pget())); \
  105. } \
  106. typedef void _name##_void
  107. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int16_t, int3, itostr3);
  108. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
  109. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
  110. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52);
  111. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float43, ftostr43sign);
  112. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float5, ftostr5rj);
  113. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
  114. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52sign, ftostr52sign);
  115. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
  116. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint32_t, long5, ftostr5rj);
  117. #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) DRAW_BOOL_SETTING(sel, row, pstr, data)
  118. #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) DRAW_BOOL_SETTING(sel, row, pstr, data)
  119. #define lcd_implementation_drawmenu_setting_edit_accessor_bool(sel, row, pstr, pstr2, pget, pset) DRAW_BOOL_SETTING(sel, row, pstr, data)
  120. #ifndef TALL_FONT_CORRECTION
  121. #define TALL_FONT_CORRECTION 0
  122. #endif
  123. bool no_reentry = false;
  124. constexpr int8_t menu_bottom = LCD_HEIGHT - (TALL_FONT_CORRECTION);
  125. // Initialized by settings.load()
  126. int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  127. #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
  128. bool lcd_external_control; // = false
  129. #endif
  130. #if ENABLED(BABYSTEPPING)
  131. long babysteps_done = 0;
  132. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  133. static void lcd_babystep_zoffset();
  134. #else
  135. static void lcd_babystep_z();
  136. #endif
  137. #endif
  138. #if ENABLED(DAC_STEPPER_CURRENT)
  139. #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
  140. uint8_t driverPercent[XYZE];
  141. #endif
  142. ////////////////////////////////////////////
  143. ///////////////// Menu Tree ////////////////
  144. ////////////////////////////////////////////
  145. void lcd_main_menu();
  146. void lcd_tune_menu();
  147. void lcd_prepare_menu();
  148. void lcd_move_menu();
  149. void lcd_control_menu();
  150. void lcd_control_temperature_menu();
  151. void lcd_control_motion_menu();
  152. #if DISABLED(SLIM_LCD_MENUS)
  153. void lcd_control_temperature_preheat_material1_settings_menu();
  154. void lcd_control_temperature_preheat_material2_settings_menu();
  155. #endif
  156. #if DISABLED(NO_VOLUMETRICS) || ENABLED(ADVANCED_PAUSE_FEATURE)
  157. void lcd_control_filament_menu();
  158. #endif
  159. #if ENABLED(LCD_INFO_MENU)
  160. #if ENABLED(PRINTCOUNTER)
  161. void lcd_info_stats_menu();
  162. #endif
  163. void lcd_info_thermistors_menu();
  164. void lcd_info_board_menu();
  165. void lcd_info_menu();
  166. #endif // LCD_INFO_MENU
  167. #if ENABLED(LED_CONTROL_MENU)
  168. #include "leds.h"
  169. void lcd_led_menu();
  170. #endif
  171. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  172. #if E_STEPPERS > 1 || ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  173. void lcd_change_filament_menu();
  174. #else
  175. void lcd_temp_menu_e0_filament_change();
  176. #endif
  177. #endif
  178. #if ENABLED(DAC_STEPPER_CURRENT)
  179. void dac_driver_commit();
  180. void dac_driver_getValues();
  181. void lcd_dac_menu();
  182. void lcd_dac_write_eeprom();
  183. #endif
  184. #if ENABLED(FWRETRACT)
  185. void lcd_control_retract_menu();
  186. #endif
  187. #if ENABLED(DELTA_CALIBRATION_MENU) || ENABLED(DELTA_AUTO_CALIBRATION)
  188. void lcd_delta_calibrate_menu();
  189. #endif
  190. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  191. static float new_z_fade_height;
  192. void _lcd_set_z_fade_height() { set_z_fade_height(new_z_fade_height); }
  193. #endif
  194. ////////////////////////////////////////////
  195. //////////// Menu System Actions ///////////
  196. ////////////////////////////////////////////
  197. #define menu_action_back(dummy) _menu_action_back()
  198. void _menu_action_back();
  199. void menu_action_submenu(screenFunc_t data);
  200. void menu_action_gcode(const char* pgcode);
  201. void menu_action_function(menuAction_t data);
  202. #define DECLARE_MENU_EDIT_TYPE(_type, _name) \
  203. bool _menu_edit_ ## _name(); \
  204. void menu_edit_ ## _name(); \
  205. void menu_edit_callback_ ## _name(); \
  206. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
  207. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
  208. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback=NULL, const bool live=false); \
  209. typedef void _name##_void
  210. DECLARE_MENU_EDIT_TYPE(int16_t, int3);
  211. DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
  212. DECLARE_MENU_EDIT_TYPE(float, float3);
  213. DECLARE_MENU_EDIT_TYPE(float, float52);
  214. DECLARE_MENU_EDIT_TYPE(float, float43);
  215. DECLARE_MENU_EDIT_TYPE(float, float5);
  216. DECLARE_MENU_EDIT_TYPE(float, float51);
  217. DECLARE_MENU_EDIT_TYPE(float, float52sign);
  218. DECLARE_MENU_EDIT_TYPE(float, float62);
  219. DECLARE_MENU_EDIT_TYPE(uint32_t, long5);
  220. void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  221. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
  222. #if ENABLED(SDSUPPORT)
  223. void lcd_sdcard_menu();
  224. void menu_action_sdfile(CardReader& theCard);
  225. void menu_action_sddirectory(CardReader& theCard);
  226. #endif
  227. ////////////////////////////////////////////
  228. //////////// Menu System Macros ////////////
  229. ////////////////////////////////////////////
  230. /**
  231. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  232. *
  233. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  234. * menu_action_[type](arg3...)
  235. *
  236. * Examples:
  237. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  238. * or
  239. * MENU_BACK(MSG_WATCH)
  240. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  241. * menu_action_back()
  242. *
  243. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  244. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  245. * menu_action_function(lcd_sdcard_pause)
  246. *
  247. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  248. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  249. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  250. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  251. *
  252. */
  253. #define _MENU_ITEM_PART_1(TYPE, ...) \
  254. if (_menuLineNr == _thisItemNr) { \
  255. if (encoderLine == _thisItemNr && lcd_clicked) { \
  256. lcd_clicked = false
  257. #define _MENU_ITEM_PART_2(TYPE, PLABEL, ...) \
  258. menu_action_ ## TYPE(__VA_ARGS__); \
  259. if (screen_changed) return; \
  260. } \
  261. if (lcdDrawUpdate) \
  262. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PLABEL, ## __VA_ARGS__); \
  263. } \
  264. ++_thisItemNr
  265. #define MENU_ITEM_P(TYPE, PLABEL, ...) do { \
  266. _skipStatic = false; \
  267. _MENU_ITEM_PART_1(TYPE, ## __VA_ARGS__); \
  268. _MENU_ITEM_PART_2(TYPE, PLABEL, ## __VA_ARGS__); \
  269. }while(0)
  270. #define MENU_ITEM(TYPE, LABEL, ...) MENU_ITEM_P(TYPE, PSTR(LABEL), ## __VA_ARGS__)
  271. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
  272. // Used to print static text with no visible cursor.
  273. // Parameters: label [, bool center [, bool invert [, char *value] ] ]
  274. #define STATIC_ITEM_P(LABEL, ...) \
  275. if (_menuLineNr == _thisItemNr) { \
  276. if (_skipStatic && encoderLine <= _thisItemNr) { \
  277. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  278. ++encoderLine; \
  279. } \
  280. if (lcdDrawUpdate) \
  281. lcd_implementation_drawmenu_static(_lcdLineNr, LABEL, ## __VA_ARGS__); \
  282. } \
  283. ++_thisItemNr
  284. #define STATIC_ITEM(LABEL, ...) STATIC_ITEM_P(PSTR(LABEL), ## __VA_ARGS__)
  285. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  286. bool encoderRateMultiplierEnabled;
  287. #define ENCODER_RATE_MULTIPLY(F) (encoderRateMultiplierEnabled = F)
  288. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  289. /**
  290. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  291. */
  292. #define MENU_MULTIPLIER_ITEM(TYPE, LABEL, ...) do { \
  293. _MENU_ITEM_PART_1(TYPE, ## __VA_ARGS__); \
  294. encoderRateMultiplierEnabled = true; \
  295. lastEncoderMovementMillis = 0; \
  296. _MENU_ITEM_PART_2(TYPE, PSTR(LABEL), ## __VA_ARGS__); \
  297. }while(0)
  298. #else // !ENCODER_RATE_MULTIPLIER
  299. #define ENCODER_RATE_MULTIPLY(F) NOOP
  300. #endif // !ENCODER_RATE_MULTIPLIER
  301. #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
  302. #define MENU_ITEM_EDIT(TYPE, LABEL, ...) MENU_ITEM(setting_edit_ ## TYPE, LABEL, PSTR(LABEL), ## __VA_ARGS__)
  303. #define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) MENU_ITEM(setting_edit_callback_ ## TYPE, LABEL, PSTR(LABEL), ## __VA_ARGS__)
  304. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  305. #define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## TYPE, LABEL, PSTR(LABEL), ## __VA_ARGS__)
  306. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## TYPE, LABEL, PSTR(LABEL), ## __VA_ARGS__)
  307. #else // !ENCODER_RATE_MULTIPLIER
  308. #define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, ...) MENU_ITEM(setting_edit_ ## TYPE, LABEL, PSTR(LABEL), ## __VA_ARGS__)
  309. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) MENU_ITEM(setting_edit_callback_ ## TYPE, LABEL, PSTR(LABEL), ## __VA_ARGS__)
  310. #endif // !ENCODER_RATE_MULTIPLIER
  311. #define SCREEN_OR_MENU_LOOP() \
  312. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  313. for (int8_t _lcdLineNr = 0; _lcdLineNr < menu_bottom; _lcdLineNr++, _menuLineNr++) { \
  314. _thisItemNr = 0
  315. /**
  316. * START_SCREEN Opening code for a screen having only static items.
  317. * Do simplified scrolling of the entire screen.
  318. *
  319. * START_MENU Opening code for a screen with menu items.
  320. * Scroll as-needed to keep the selected line in view.
  321. */
  322. #define START_SCREEN() \
  323. scroll_screen(menu_bottom, false); \
  324. bool _skipStatic = false; \
  325. SCREEN_OR_MENU_LOOP()
  326. #define START_MENU() \
  327. scroll_screen(1, true); \
  328. bool _skipStatic = true; \
  329. SCREEN_OR_MENU_LOOP()
  330. #define END_SCREEN() \
  331. } \
  332. screen_items = _thisItemNr
  333. #define END_MENU() \
  334. } \
  335. screen_items = _thisItemNr; \
  336. UNUSED(_skipStatic)
  337. ////////////////////////////////////////////
  338. ///////////// Global Variables /////////////
  339. ////////////////////////////////////////////
  340. /**
  341. * REVERSE_MENU_DIRECTION
  342. *
  343. * To reverse the menu direction we need a general way to reverse
  344. * the direction of the encoder everywhere. So encoderDirection is
  345. * added to allow the encoder to go the other way.
  346. *
  347. * This behavior is limited to scrolling Menus and SD card listings,
  348. * and is disabled in other contexts.
  349. */
  350. #if ENABLED(REVERSE_MENU_DIRECTION)
  351. int8_t encoderDirection = 1;
  352. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  353. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  354. #else
  355. #define ENCODER_DIRECTION_NORMAL() ;
  356. #define ENCODER_DIRECTION_MENUS() ;
  357. #endif
  358. // Encoder Movement
  359. volatile int8_t encoderDiff; // Updated in lcd_buttons_update, added to encoderPosition every LCD update
  360. uint32_t encoderPosition;
  361. millis_t lastEncoderMovementMillis = 0;
  362. // Button States
  363. bool lcd_clicked, wait_for_unclick;
  364. volatile uint8_t buttons;
  365. millis_t next_button_update_ms;
  366. #if ENABLED(REPRAPWORLD_KEYPAD)
  367. volatile uint8_t buttons_reprapworld_keypad;
  368. #endif
  369. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  370. volatile uint8_t slow_buttons;
  371. #endif
  372. // Menu System Navigation
  373. screenFunc_t currentScreen = lcd_status_screen;
  374. int8_t encoderTopLine;
  375. typedef struct {
  376. screenFunc_t menu_function;
  377. uint32_t encoder_position;
  378. } menuPosition;
  379. menuPosition screen_history[6];
  380. uint8_t screen_history_depth = 0;
  381. bool screen_changed, defer_return_to_status;
  382. // Value Editing
  383. const char *editLabel;
  384. void *editValue;
  385. int32_t minEditValue, maxEditValue;
  386. screenFunc_t callbackFunc;
  387. bool liveEdit;
  388. // Manual Moves
  389. const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
  390. millis_t manual_move_start_time = 0;
  391. int8_t manual_move_axis = (int8_t)NO_AXIS;
  392. #if EXTRUDERS > 1
  393. int8_t manual_move_e_index = 0;
  394. #else
  395. #define manual_move_e_index 0
  396. #endif
  397. #if IS_KINEMATIC
  398. bool processing_manual_move = false;
  399. float manual_move_offset = 0;
  400. #else
  401. constexpr bool processing_manual_move = false;
  402. #endif
  403. #if PIN_EXISTS(SD_DETECT)
  404. uint8_t lcd_sd_status;
  405. #endif
  406. #if ENABLED(PIDTEMP)
  407. float raw_Ki, raw_Kd; // place-holders for Ki and Kd edits
  408. #endif
  409. inline bool use_click() {
  410. const bool click = lcd_clicked;
  411. lcd_clicked = false;
  412. return click;
  413. }
  414. /**
  415. * General function to go directly to a screen
  416. */
  417. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) {
  418. if (currentScreen != screen) {
  419. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  420. // Shadow for editing the fade height
  421. new_z_fade_height = planner.z_fade_height;
  422. #endif
  423. #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
  424. static millis_t doubleclick_expire_ms = 0;
  425. // Going to lcd_main_menu from status screen? Remember first click time.
  426. // Going back to status screen within a very short time? Go to Z babystepping.
  427. if (screen == lcd_main_menu) {
  428. if (currentScreen == lcd_status_screen)
  429. doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
  430. }
  431. else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms) && (planner.movesplanned() || IS_SD_PRINTING()))
  432. screen =
  433. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  434. lcd_babystep_zoffset
  435. #else
  436. lcd_babystep_z
  437. #endif
  438. ;
  439. #endif
  440. currentScreen = screen;
  441. encoderPosition = encoder;
  442. if (screen == lcd_status_screen) {
  443. defer_return_to_status = false;
  444. #if ENABLED(AUTO_BED_LEVELING_UBL)
  445. ubl.lcd_map_control = false;
  446. #endif
  447. screen_history_depth = 0;
  448. }
  449. lcd_implementation_clear();
  450. // Re-initialize custom characters that may be re-used
  451. #if DISABLED(DOGLCD) && ENABLED(AUTO_BED_LEVELING_UBL)
  452. if (!ubl.lcd_map_control) {
  453. lcd_set_custom_characters(
  454. #if ENABLED(LCD_PROGRESS_BAR)
  455. screen == lcd_status_screen ? CHARSET_INFO : CHARSET_MENU
  456. #endif
  457. );
  458. }
  459. #elif ENABLED(LCD_PROGRESS_BAR)
  460. lcd_set_custom_characters(screen == lcd_status_screen ? CHARSET_INFO : CHARSET_MENU);
  461. #endif
  462. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  463. screen_changed = true;
  464. #if ENABLED(DOGLCD)
  465. drawing_screen = false;
  466. #endif
  467. }
  468. }
  469. /**
  470. * Show "Moving..." till moves are done, then revert to previous display.
  471. */
  472. static const char moving[] PROGMEM = MSG_MOVING;
  473. static const char *sync_message = moving;
  474. //
  475. // Display the synchronize screen until moves are
  476. // finished, and don't return to the caller until
  477. // done. ** This blocks the command queue! **
  478. //
  479. void _lcd_synchronize() {
  480. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
  481. if (no_reentry) return;
  482. // Make this the current handler till all moves are done
  483. no_reentry = true;
  484. const screenFunc_t old_screen = currentScreen;
  485. lcd_goto_screen(_lcd_synchronize);
  486. planner.synchronize(); // idle() is called until moves complete
  487. no_reentry = false;
  488. lcd_goto_screen(old_screen);
  489. }
  490. // Display the synchronize screen with a custom message
  491. // ** This blocks the command queue! **
  492. void lcd_synchronize(const char * const msg=NULL) {
  493. sync_message = msg ? msg : moving;
  494. _lcd_synchronize();
  495. }
  496. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  497. void lcd_save_previous_screen() {
  498. if (screen_history_depth < COUNT(screen_history)) {
  499. screen_history[screen_history_depth].menu_function = currentScreen;
  500. screen_history[screen_history_depth].encoder_position = encoderPosition;
  501. ++screen_history_depth;
  502. }
  503. }
  504. void lcd_goto_previous_menu() {
  505. if (screen_history_depth > 0) {
  506. --screen_history_depth;
  507. lcd_goto_screen(
  508. screen_history[screen_history_depth].menu_function,
  509. screen_history[screen_history_depth].encoder_position
  510. );
  511. }
  512. else
  513. lcd_return_to_status();
  514. }
  515. void lcd_goto_previous_menu_no_defer() {
  516. defer_return_to_status = false;
  517. lcd_goto_previous_menu();
  518. }
  519. /**
  520. * Scrolling for menus and other line-based screens
  521. *
  522. * encoderLine is the position based on the encoder
  523. * encoderTopLine is the top menu line to display
  524. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  525. * _menuLineNr is the menu item to draw and process
  526. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  527. * screen_items is the total number of items in the menu (after one call)
  528. */
  529. int8_t encoderLine, screen_items;
  530. void scroll_screen(const uint8_t limit, const bool is_menu) {
  531. ENCODER_DIRECTION_MENUS();
  532. ENCODER_RATE_MULTIPLY(false);
  533. if (encoderPosition > 0x8000) encoderPosition = 0;
  534. if (first_page) {
  535. encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM);
  536. screen_changed = false;
  537. }
  538. if (screen_items > 0 && encoderLine >= screen_items - limit) {
  539. encoderLine = MAX(0, screen_items - limit);
  540. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM);
  541. }
  542. if (is_menu) {
  543. NOMORE(encoderTopLine, encoderLine);
  544. if (encoderLine >= encoderTopLine + menu_bottom)
  545. encoderTopLine = encoderLine - menu_bottom + 1;
  546. }
  547. else
  548. encoderTopLine = encoderLine;
  549. }
  550. #endif // ULTIPANEL
  551. /**
  552. *
  553. * "Info Screen"
  554. *
  555. * This is very display-dependent, so the lcd implementation draws this.
  556. */
  557. void lcd_status_screen() {
  558. #if ENABLED(ULTIPANEL)
  559. ENCODER_DIRECTION_NORMAL();
  560. ENCODER_RATE_MULTIPLY(false);
  561. #endif
  562. #if ENABLED(LCD_SET_PROGRESS_MANUALLY) && ENABLED(SDSUPPORT) && (ENABLED(LCD_PROGRESS_BAR) || ENABLED(DOGLCD))
  563. // Progress bar % comes from SD when actively printing
  564. if (IS_SD_PRINTING())
  565. progress_bar_percent = card.percentDone();
  566. #endif
  567. #if ENABLED(LCD_PROGRESS_BAR)
  568. //
  569. // HD44780 implements the following message blinking and
  570. // message expiration because Status Line and Progress Bar
  571. // share the same line on the display.
  572. //
  573. millis_t ms = millis();
  574. // If the message will blink rather than expire...
  575. #if DISABLED(PROGRESS_MSG_ONCE)
  576. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME))
  577. progress_bar_ms = ms;
  578. #endif
  579. #if PROGRESS_MSG_EXPIRE > 0
  580. // Handle message expire
  581. if (expire_status_ms > 0) {
  582. #if DISABLED(LCD_SET_PROGRESS_MANUALLY)
  583. const uint8_t progress_bar_percent = card.percentDone();
  584. #endif
  585. // Expire the message if a job is active and the bar has ticks
  586. if (progress_bar_percent > 2 && !print_job_timer.isPaused()) {
  587. if (ELAPSED(ms, expire_status_ms)) {
  588. lcd_status_message[0] = '\0';
  589. expire_status_ms = 0;
  590. }
  591. }
  592. else {
  593. // Defer message expiration before bar appears
  594. // and during any pause (not just SD)
  595. expire_status_ms += LCD_UPDATE_INTERVAL;
  596. }
  597. }
  598. #endif // PROGRESS_MSG_EXPIRE
  599. #endif // LCD_PROGRESS_BAR
  600. #if ENABLED(ULTIPANEL)
  601. if (use_click()) {
  602. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  603. previous_lcd_status_ms = millis(); // get status message to show up for a while
  604. #endif
  605. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  606. #if ENABLED(LCD_PROGRESS_BAR)
  607. CHARSET_MENU
  608. #endif
  609. );
  610. lcd_goto_screen(lcd_main_menu);
  611. return;
  612. }
  613. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  614. const int16_t new_frm = feedrate_percentage + (int32_t)encoderPosition;
  615. // Dead zone at 100% feedrate
  616. if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
  617. feedrate_percentage = 100;
  618. encoderPosition = 0;
  619. }
  620. else if (feedrate_percentage == 100) {
  621. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  622. feedrate_percentage += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  623. encoderPosition = 0;
  624. }
  625. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  626. feedrate_percentage += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  627. encoderPosition = 0;
  628. }
  629. }
  630. else {
  631. feedrate_percentage = new_frm;
  632. encoderPosition = 0;
  633. }
  634. #endif // ULTIPANEL_FEEDMULTIPLY
  635. feedrate_percentage = constrain(feedrate_percentage, 10, 999);
  636. #endif // ULTIPANEL
  637. lcd_implementation_status_screen();
  638. }
  639. /**
  640. * Reset the status message
  641. */
  642. void lcd_reset_status() {
  643. static const char paused[] PROGMEM = MSG_PRINT_PAUSED;
  644. static const char printing[] PROGMEM = MSG_PRINTING;
  645. static const char welcome[] PROGMEM = WELCOME_MSG;
  646. const char *msg;
  647. if (print_job_timer.isPaused())
  648. msg = paused;
  649. #if ENABLED(SDSUPPORT)
  650. else if (card.sdprinting)
  651. return lcd_setstatus(card.longest_filename(), true);
  652. #endif
  653. else if (print_job_timer.isRunning())
  654. msg = printing;
  655. else
  656. msg = welcome;
  657. lcd_setstatusPGM(msg, -1);
  658. }
  659. /**
  660. *
  661. * draw the kill screen
  662. *
  663. */
  664. void kill_screen(const char* lcd_msg) {
  665. lcd_init();
  666. lcd_setalertstatusPGM(lcd_msg);
  667. lcd_kill_screen();
  668. }
  669. /**
  670. *
  671. * Audio feedback for controller clicks
  672. *
  673. */
  674. void lcd_buzz(const long duration, const uint16_t freq) {
  675. #if ENABLED(LCD_USE_I2C_BUZZER)
  676. lcd.buzz(duration, freq);
  677. #elif PIN_EXISTS(BEEPER)
  678. buzzer.tone(duration, freq);
  679. #else
  680. UNUSED(duration); UNUSED(freq);
  681. #endif
  682. }
  683. void lcd_quick_feedback(const bool clear_buttons) {
  684. #if ENABLED(ULTIPANEL)
  685. lcd_refresh();
  686. if (clear_buttons) buttons = 0;
  687. next_button_update_ms = millis() + 500;
  688. #else
  689. UNUSED(clear_buttons);
  690. #endif
  691. // Buzz and wait. The delay is needed for buttons to settle!
  692. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  693. #if ENABLED(ULTIPANEL)
  694. #if ENABLED(LCD_USE_I2C_BUZZER)
  695. delay(10);
  696. #elif PIN_EXISTS(BEEPER)
  697. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  698. #endif
  699. #endif
  700. }
  701. #if ENABLED(ULTIPANEL)
  702. void lcd_completion_feedback(const bool good/*=true*/) {
  703. if (good) {
  704. lcd_buzz(100, 659);
  705. lcd_buzz(100, 698);
  706. }
  707. else lcd_buzz(20, 440);
  708. }
  709. inline void line_to_current_z() {
  710. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[Z_AXIS]), active_extruder);
  711. }
  712. inline void line_to_z(const float &z) {
  713. current_position[Z_AXIS] = z;
  714. line_to_current_z();
  715. }
  716. #if ENABLED(SDSUPPORT)
  717. void lcd_sdcard_pause() {
  718. card.pauseSDPrint();
  719. print_job_timer.pause();
  720. #if ENABLED(PARK_HEAD_ON_PAUSE)
  721. enqueue_and_echo_commands_P(PSTR("M125"));
  722. #endif
  723. lcd_reset_status();
  724. }
  725. void lcd_sdcard_resume() {
  726. #if ENABLED(PARK_HEAD_ON_PAUSE)
  727. enqueue_and_echo_commands_P(PSTR("M24"));
  728. #else
  729. card.startFileprint();
  730. print_job_timer.start();
  731. #endif
  732. lcd_reset_status();
  733. }
  734. void lcd_sdcard_stop() {
  735. wait_for_heatup = wait_for_user = false;
  736. card.abort_sd_printing = true;
  737. lcd_setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1);
  738. lcd_return_to_status();
  739. }
  740. #endif // SDSUPPORT
  741. #if ENABLED(POWER_LOSS_RECOVERY)
  742. static void lcd_power_loss_recovery_resume() {
  743. char cmd[20];
  744. // Return to status now
  745. lcd_return_to_status();
  746. // Turn leveling off and home
  747. enqueue_and_echo_commands_P(PSTR("M420 S0\nG28 R0"
  748. #if ENABLED(MARLIN_DEV_MODE)
  749. " S"
  750. #elif !IS_KINEMATIC
  751. " X Y"
  752. #endif
  753. ));
  754. #if HAS_HEATED_BED
  755. const int16_t bt = job_recovery_info.target_temperature_bed;
  756. if (bt) {
  757. // Restore the bed temperature
  758. sprintf_P(cmd, PSTR("M190 S%i"), bt);
  759. enqueue_and_echo_command(cmd);
  760. }
  761. #endif
  762. // Restore all hotend temperatures
  763. HOTEND_LOOP() {
  764. const int16_t et = job_recovery_info.target_temperature[e];
  765. if (et) {
  766. #if HOTENDS > 1
  767. sprintf_P(cmd, PSTR("T%i"), e);
  768. enqueue_and_echo_command(cmd);
  769. #endif
  770. sprintf_P(cmd, PSTR("M109 S%i"), et);
  771. enqueue_and_echo_command(cmd);
  772. }
  773. }
  774. #if HOTENDS > 1
  775. sprintf_P(cmd, PSTR("T%i"), job_recovery_info.active_hotend);
  776. enqueue_and_echo_command(cmd);
  777. #endif
  778. // Restore print cooling fan speeds
  779. for (uint8_t i = 0; i < FAN_COUNT; i++) {
  780. int16_t f = job_recovery_info.fanSpeeds[i];
  781. if (f) {
  782. sprintf_P(cmd, PSTR("M106 P%i S%i"), i, f);
  783. enqueue_and_echo_command(cmd);
  784. }
  785. }
  786. // Start draining the job recovery command queue
  787. job_recovery_phase = JOB_RECOVERY_YES;
  788. }
  789. static void lcd_power_loss_recovery_cancel() {
  790. card.removeJobRecoveryFile();
  791. card.autostart_index = 0;
  792. lcd_return_to_status();
  793. }
  794. static void lcd_job_recovery_menu() {
  795. defer_return_to_status = true;
  796. START_MENU();
  797. STATIC_ITEM(MSG_POWER_LOSS_RECOVERY);
  798. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_power_loss_recovery_resume);
  799. MENU_ITEM(function, MSG_STOP_PRINT, lcd_power_loss_recovery_cancel);
  800. END_MENU();
  801. }
  802. #endif // POWER_LOSS_RECOVERY
  803. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  804. extern uint8_t case_light_brightness;
  805. extern bool case_light_on;
  806. extern void update_case_light();
  807. void case_light_menu() {
  808. START_MENU();
  809. //
  810. // ^ Main
  811. //
  812. MENU_BACK(MSG_MAIN);
  813. MENU_ITEM_EDIT_CALLBACK(int8, MSG_CASE_LIGHT_BRIGHTNESS, &case_light_brightness, 0, 255, update_case_light, true);
  814. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  815. END_MENU();
  816. }
  817. #endif // MENU_ITEM_CASE_LIGHT
  818. #if ENABLED(BLTOUCH)
  819. extern void _bltouch_reset();
  820. extern void _bltouch_selftest();
  821. extern void _bltouch_deploy();
  822. extern void _bltouch_stow();
  823. extern void _bltouch_set_SW_mode();
  824. extern void _bltouch_set_5V_mode();
  825. extern void _bltouch_set_OD_mode();
  826. extern void _bltouch_mode_store();
  827. extern void bltouch_mode_conv_5V();
  828. extern void bltouch_mode_conv_OD();
  829. extern bool bltouch_last_written_mode;
  830. #if ENABLED(BLTOUCH_LCD_VOLTAGE_MENU)
  831. void bltouch_report() {
  832. SERIAL_ECHOLNPAIR("EEPROM Last BLTouch Mode - ", (int)bltouch_last_written_mode);
  833. SERIAL_ECHOLNPGM("Configuration BLTouch Mode - "
  834. #if ENABLED(BLTOUCH_SET_5V_MODE)
  835. "5V"
  836. #else
  837. "OD"
  838. #endif
  839. );
  840. char mess[21];
  841. strcpy_P(mess, PSTR("BLTouch Mode - "));
  842. strcpy_P(&mess[15], bltouch_last_written_mode ? PSTR("5V") : PSTR("OD"));
  843. lcd_setalertstatusPGM(mess);
  844. lcd_return_to_status();
  845. }
  846. #endif
  847. void bltouch_menu() {
  848. START_MENU();
  849. MENU_BACK(MSG_MAIN);
  850. MENU_ITEM(function, MSG_BLTOUCH_RESET, _bltouch_reset);
  851. MENU_ITEM(function, MSG_BLTOUCH_SELFTEST, _bltouch_selftest);
  852. MENU_ITEM(function, MSG_BLTOUCH_DEPLOY, _bltouch_deploy);
  853. MENU_ITEM(function, MSG_BLTOUCH_STOW, _bltouch_stow);
  854. MENU_ITEM(function, MSG_BLTOUCH_SW_MODE, _bltouch_set_SW_mode);
  855. #if ENABLED(BLTOUCH_LCD_VOLTAGE_MENU)
  856. MENU_ITEM(function, MSG_BLTOUCH_5V_MODE, _bltouch_set_5V_mode);
  857. MENU_ITEM(function, MSG_BLTOUCH_OD_MODE, _bltouch_set_OD_mode);
  858. MENU_ITEM(function, MSG_BLTOUCH_MODE_STORE, _bltouch_mode_store);
  859. MENU_ITEM(function, MSG_BLTOUCH_MODE_STORE_5V, bltouch_mode_conv_5V);
  860. MENU_ITEM(function, MSG_BLTOUCH_MODE_STORE_OD, bltouch_mode_conv_OD);
  861. MENU_ITEM(function, MSG_BLTOUCH_MODE_ECHO, bltouch_report);
  862. #endif
  863. END_MENU();
  864. }
  865. #endif
  866. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  867. static void progress_bar_test() {
  868. static int8_t bar_percent = 0;
  869. if (use_click()) {
  870. lcd_goto_previous_menu();
  871. lcd_set_custom_characters(CHARSET_MENU);
  872. return;
  873. }
  874. bar_percent += (int8_t)encoderPosition;
  875. bar_percent = constrain(bar_percent, 0, 100);
  876. encoderPosition = 0;
  877. lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
  878. lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
  879. lcd.print(itostr3(bar_percent)); lcd.write('%');
  880. lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
  881. }
  882. void _progress_bar_test() {
  883. lcd_goto_screen(progress_bar_test);
  884. lcd_set_custom_characters();
  885. }
  886. #endif // LCD_PROGRESS_BAR_TEST
  887. #if HAS_DEBUG_MENU
  888. void lcd_debug_menu() {
  889. START_MENU();
  890. MENU_BACK(MSG_MAIN); // ^ Main
  891. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  892. MENU_ITEM(submenu, MSG_PROGRESS_BAR_TEST, _progress_bar_test);
  893. #endif
  894. END_MENU();
  895. }
  896. #endif // HAS_DEBUG_MENU
  897. #if ENABLED(CUSTOM_USER_MENUS)
  898. #ifdef USER_SCRIPT_DONE
  899. #define _DONE_SCRIPT "\n" USER_SCRIPT_DONE
  900. #else
  901. #define _DONE_SCRIPT ""
  902. #endif
  903. void _lcd_user_gcode(const char * const cmd) {
  904. enqueue_and_echo_commands_P(cmd);
  905. #if ENABLED(USER_SCRIPT_AUDIBLE_FEEDBACK)
  906. lcd_completion_feedback();
  907. #endif
  908. #if ENABLED(USER_SCRIPT_RETURN)
  909. lcd_return_to_status();
  910. #endif
  911. }
  912. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  913. void lcd_user_gcode_1() { _lcd_user_gcode(PSTR(USER_GCODE_1 _DONE_SCRIPT)); }
  914. #endif
  915. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  916. void lcd_user_gcode_2() { _lcd_user_gcode(PSTR(USER_GCODE_2 _DONE_SCRIPT)); }
  917. #endif
  918. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  919. void lcd_user_gcode_3() { _lcd_user_gcode(PSTR(USER_GCODE_3 _DONE_SCRIPT)); }
  920. #endif
  921. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  922. void lcd_user_gcode_4() { _lcd_user_gcode(PSTR(USER_GCODE_4 _DONE_SCRIPT)); }
  923. #endif
  924. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  925. void lcd_user_gcode_5() { _lcd_user_gcode(PSTR(USER_GCODE_5 _DONE_SCRIPT)); }
  926. #endif
  927. void _lcd_user_menu() {
  928. START_MENU();
  929. MENU_BACK(MSG_MAIN);
  930. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  931. MENU_ITEM(function, USER_DESC_1, lcd_user_gcode_1);
  932. #endif
  933. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  934. MENU_ITEM(function, USER_DESC_2, lcd_user_gcode_2);
  935. #endif
  936. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  937. MENU_ITEM(function, USER_DESC_3, lcd_user_gcode_3);
  938. #endif
  939. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  940. MENU_ITEM(function, USER_DESC_4, lcd_user_gcode_4);
  941. #endif
  942. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  943. MENU_ITEM(function, USER_DESC_5, lcd_user_gcode_5);
  944. #endif
  945. END_MENU();
  946. }
  947. #endif
  948. /**
  949. *
  950. * "Main" menu
  951. *
  952. */
  953. void lcd_main_menu() {
  954. START_MENU();
  955. MENU_BACK(MSG_WATCH);
  956. #if ENABLED(CUSTOM_USER_MENUS)
  957. MENU_ITEM(submenu, MSG_USER_MENU, _lcd_user_menu);
  958. #endif
  959. //
  960. // Debug Menu when certain options are enabled
  961. //
  962. #if HAS_DEBUG_MENU
  963. MENU_ITEM(submenu, MSG_DEBUG_MENU, lcd_debug_menu);
  964. #endif
  965. //
  966. // Set Case light on/off/brightness
  967. //
  968. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  969. if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) {
  970. MENU_ITEM(submenu, MSG_CASE_LIGHT, case_light_menu);
  971. }
  972. else
  973. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  974. #endif
  975. if (planner.movesplanned() || IS_SD_PRINTING())
  976. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  977. else
  978. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  979. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  980. #if ENABLED(SDSUPPORT)
  981. if (card.cardOK) {
  982. if (card.isFileOpen()) {
  983. if (card.sdprinting)
  984. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  985. else
  986. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  987. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  988. }
  989. else {
  990. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  991. #if !PIN_EXISTS(SD_DETECT)
  992. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  993. #endif
  994. }
  995. }
  996. else {
  997. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  998. #if !PIN_EXISTS(SD_DETECT)
  999. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  1000. #endif
  1001. }
  1002. #endif // SDSUPPORT
  1003. #if ENABLED(LCD_INFO_MENU)
  1004. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  1005. #endif
  1006. #if ENABLED(LED_CONTROL_MENU)
  1007. MENU_ITEM(submenu, MSG_LED_CONTROL, lcd_led_menu);
  1008. #endif
  1009. END_MENU();
  1010. }
  1011. /**
  1012. *
  1013. * "Tune" submenu items
  1014. *
  1015. */
  1016. #if HAS_M206_COMMAND
  1017. /**
  1018. * Set the home offset based on the current_position
  1019. */
  1020. void lcd_set_home_offsets() {
  1021. // M428 Command
  1022. enqueue_and_echo_commands_P(PSTR("M428"));
  1023. lcd_return_to_status();
  1024. }
  1025. #endif
  1026. #if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY) || ENABLED(MESH_EDIT_GFX_OVERLAY)
  1027. void _lcd_zoffset_overlay_gfx(const float zvalue) {
  1028. // Determine whether the user is raising or lowering the nozzle.
  1029. static int8_t dir;
  1030. static float old_zvalue;
  1031. if (zvalue != old_zvalue) {
  1032. dir = zvalue ? zvalue < old_zvalue ? -1 : 1 : 0;
  1033. old_zvalue = zvalue;
  1034. }
  1035. #if ENABLED(OVERLAY_GFX_REVERSE)
  1036. const unsigned char *rot_up = ccw_bmp, *rot_down = cw_bmp;
  1037. #else
  1038. const unsigned char *rot_up = cw_bmp, *rot_down = ccw_bmp;
  1039. #endif
  1040. #if ENABLED(USE_BIG_EDIT_FONT)
  1041. const int left = 0, right = 45, nozzle = 95;
  1042. #else
  1043. const int left = 5, right = 90, nozzle = 60;
  1044. #endif
  1045. // Draw a representation of the nozzle
  1046. if (PAGE_CONTAINS(3, 16)) u8g.drawBitmapP(nozzle + 6, 4 - dir, 2, 12, nozzle_bmp);
  1047. if (PAGE_CONTAINS(20, 20)) u8g.drawBitmapP(nozzle + 0, 20, 3, 1, offset_bedline_bmp);
  1048. // Draw cw/ccw indicator and up/down arrows.
  1049. if (PAGE_CONTAINS(47, 62)) {
  1050. u8g.drawBitmapP(left + 0, 47, 3, 16, rot_down);
  1051. u8g.drawBitmapP(right + 0, 47, 3, 16, rot_up);
  1052. u8g.drawBitmapP(right + 20, 48 - dir, 2, 13, up_arrow_bmp);
  1053. u8g.drawBitmapP(left + 20, 49 - dir, 2, 13, down_arrow_bmp);
  1054. }
  1055. }
  1056. #endif // BABYSTEP_ZPROBE_GFX_OVERLAY || MESH_EDIT_GFX_OVERLAY
  1057. #if ENABLED(BABYSTEPPING)
  1058. void _lcd_babystep(const AxisEnum axis, const char* msg) {
  1059. if (use_click()) { return lcd_goto_previous_menu_no_defer(); }
  1060. ENCODER_DIRECTION_NORMAL();
  1061. if (encoderPosition) {
  1062. const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  1063. encoderPosition = 0;
  1064. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1065. thermalManager.babystep_axis(axis, babystep_increment);
  1066. babysteps_done += babystep_increment;
  1067. }
  1068. if (lcdDrawUpdate)
  1069. lcd_implementation_drawedit(msg, ftostr43sign(planner.steps_to_mm[axis] * babysteps_done));
  1070. }
  1071. #if ENABLED(BABYSTEP_XY)
  1072. void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEP_X)); }
  1073. void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEP_Y)); }
  1074. void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
  1075. void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
  1076. #endif
  1077. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1078. void lcd_babystep_zoffset() {
  1079. if (use_click()) { return lcd_goto_previous_menu_no_defer(); }
  1080. defer_return_to_status = true;
  1081. ENCODER_DIRECTION_NORMAL();
  1082. if (encoderPosition) {
  1083. const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  1084. encoderPosition = 0;
  1085. const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
  1086. if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
  1087. thermalManager.babystep_axis(Z_AXIS, babystep_increment);
  1088. zprobe_zoffset = new_zoffset;
  1089. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1090. }
  1091. }
  1092. if (lcdDrawUpdate) {
  1093. lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
  1094. #if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY)
  1095. _lcd_zoffset_overlay_gfx(zprobe_zoffset);
  1096. #endif
  1097. }
  1098. }
  1099. #else // !BABYSTEP_ZPROBE_OFFSET
  1100. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEP_Z)); }
  1101. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  1102. #endif // !BABYSTEP_ZPROBE_OFFSET
  1103. #endif // BABYSTEPPING
  1104. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1105. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  1106. // separate value that doesn't lose precision.
  1107. static int16_t ubl_encoderPosition = 0;
  1108. static void _lcd_mesh_fine_tune(const char* msg) {
  1109. defer_return_to_status = true;
  1110. if (ubl.encoder_diff) {
  1111. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  1112. ubl.encoder_diff = 0;
  1113. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005f * 0.5f;
  1114. mesh_edit_value = mesh_edit_accumulator;
  1115. encoderPosition = 0;
  1116. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1117. const int32_t rounded = (int32_t)(mesh_edit_value * 1000);
  1118. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000;
  1119. }
  1120. if (lcdDrawUpdate) {
  1121. lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
  1122. #if ENABLED(MESH_EDIT_GFX_OVERLAY)
  1123. _lcd_zoffset_overlay_gfx(mesh_edit_value);
  1124. #endif
  1125. }
  1126. }
  1127. void _lcd_mesh_edit_NOP() {
  1128. defer_return_to_status = true;
  1129. }
  1130. float lcd_mesh_edit() {
  1131. lcd_goto_screen(_lcd_mesh_edit_NOP);
  1132. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1133. _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
  1134. return mesh_edit_value;
  1135. }
  1136. void lcd_mesh_edit_setup(const float &initial) {
  1137. mesh_edit_value = mesh_edit_accumulator = initial;
  1138. lcd_goto_screen(_lcd_mesh_edit_NOP);
  1139. }
  1140. void _lcd_z_offset_edit() {
  1141. _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
  1142. }
  1143. float lcd_z_offset_edit() {
  1144. lcd_goto_screen(_lcd_z_offset_edit);
  1145. return mesh_edit_value;
  1146. }
  1147. void lcd_z_offset_edit_setup(const float &initial) {
  1148. mesh_edit_value = mesh_edit_accumulator = initial;
  1149. lcd_goto_screen(_lcd_z_offset_edit);
  1150. }
  1151. #endif // AUTO_BED_LEVELING_UBL
  1152. /**
  1153. * Watch temperature callbacks
  1154. */
  1155. #if HAS_TEMP_HOTEND
  1156. #if WATCH_HOTENDS
  1157. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  1158. #else
  1159. #define _WATCH_FUNC(N) NOOP
  1160. #endif
  1161. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  1162. #if HOTENDS > 1
  1163. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  1164. #if HOTENDS > 2
  1165. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  1166. #if HOTENDS > 3
  1167. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  1168. #if HOTENDS > 4
  1169. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  1170. #endif // HOTENDS > 4
  1171. #endif // HOTENDS > 3
  1172. #endif // HOTENDS > 2
  1173. #endif // HOTENDS > 1
  1174. #endif // HAS_TEMP_HOTEND
  1175. void watch_temp_callback_bed() {
  1176. #if WATCH_THE_BED
  1177. thermalManager.start_watching_bed();
  1178. #endif
  1179. }
  1180. // First Fan Speed title in "Tune" and "Control>Temperature" menus
  1181. #if FAN_COUNT > 0 && HAS_FAN0
  1182. #if FAN_COUNT > 1
  1183. #define FAN_SPEED_1_SUFFIX " 1"
  1184. #else
  1185. #define FAN_SPEED_1_SUFFIX ""
  1186. #endif
  1187. #endif
  1188. // Refresh the E factor after changing flow
  1189. inline void _lcd_refresh_e_factor_0() { planner.refresh_e_factor(0); }
  1190. #if EXTRUDERS > 1
  1191. inline void _lcd_refresh_e_factor() { planner.refresh_e_factor(active_extruder); }
  1192. inline void _lcd_refresh_e_factor_1() { planner.refresh_e_factor(1); }
  1193. #if EXTRUDERS > 2
  1194. inline void _lcd_refresh_e_factor_2() { planner.refresh_e_factor(2); }
  1195. #if EXTRUDERS > 3
  1196. inline void _lcd_refresh_e_factor_3() { planner.refresh_e_factor(3); }
  1197. #if EXTRUDERS > 4
  1198. inline void _lcd_refresh_e_factor_4() { planner.refresh_e_factor(4); }
  1199. #endif // EXTRUDERS > 4
  1200. #endif // EXTRUDERS > 3
  1201. #endif // EXTRUDERS > 2
  1202. #endif // EXTRUDERS > 1
  1203. /**
  1204. *
  1205. * "Tune" submenu
  1206. *
  1207. */
  1208. void lcd_tune_menu() {
  1209. START_MENU();
  1210. //
  1211. // ^ Main
  1212. //
  1213. MENU_BACK(MSG_MAIN);
  1214. //
  1215. // Speed:
  1216. //
  1217. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  1218. //
  1219. // Manual bed leveling, Bed Z:
  1220. //
  1221. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  1222. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  1223. #endif
  1224. //
  1225. // Leveling Fade Height
  1226. //
  1227. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(SLIM_LCD_MENUS)
  1228. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0, 100, _lcd_set_z_fade_height);
  1229. #endif
  1230. //
  1231. // Nozzle:
  1232. // Nozzle [1-4]:
  1233. //
  1234. #if HOTENDS == 1
  1235. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1236. #else // HOTENDS > 1
  1237. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1238. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1239. #if HOTENDS > 2
  1240. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1241. #if HOTENDS > 3
  1242. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1243. #if HOTENDS > 4
  1244. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  1245. #endif // HOTENDS > 4
  1246. #endif // HOTENDS > 3
  1247. #endif // HOTENDS > 2
  1248. #endif // HOTENDS > 1
  1249. //
  1250. // Bed:
  1251. //
  1252. #if HAS_HEATED_BED
  1253. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  1254. #endif
  1255. //
  1256. // Fan Speed:
  1257. //
  1258. #if FAN_COUNT > 0
  1259. #if HAS_FAN0
  1260. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED FAN_SPEED_1_SUFFIX, &fanSpeeds[0], 0, 255);
  1261. #if ENABLED(EXTRA_FAN_SPEED)
  1262. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_EXTRA_FAN_SPEED FAN_SPEED_1_SUFFIX, &new_fanSpeeds[0], 3, 255);
  1263. #endif
  1264. #endif
  1265. #if HAS_FAN1
  1266. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1267. #if ENABLED(EXTRA_FAN_SPEED)
  1268. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_EXTRA_FAN_SPEED " 2", &new_fanSpeeds[1], 3, 255);
  1269. #endif
  1270. #endif
  1271. #if HAS_FAN2
  1272. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1273. #if ENABLED(EXTRA_FAN_SPEED)
  1274. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_EXTRA_FAN_SPEED " 3", &new_fanSpeeds[2], 3, 255);
  1275. #endif
  1276. #endif
  1277. #endif // FAN_COUNT > 0
  1278. //
  1279. // Flow:
  1280. // Flow [1-5]:
  1281. //
  1282. #if EXTRUDERS == 1
  1283. MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW, &planner.flow_percentage[0], 10, 999, _lcd_refresh_e_factor_0);
  1284. #else // EXTRUDERS > 1
  1285. MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW, &planner.flow_percentage[active_extruder], 10, 999, _lcd_refresh_e_factor);
  1286. MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N1, &planner.flow_percentage[0], 10, 999, _lcd_refresh_e_factor_0);
  1287. MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N2, &planner.flow_percentage[1], 10, 999, _lcd_refresh_e_factor_1);
  1288. #if EXTRUDERS > 2
  1289. MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N3, &planner.flow_percentage[2], 10, 999, _lcd_refresh_e_factor_2);
  1290. #if EXTRUDERS > 3
  1291. MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N4, &planner.flow_percentage[3], 10, 999, _lcd_refresh_e_factor_3);
  1292. #if EXTRUDERS > 4
  1293. MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N5, &planner.flow_percentage[4], 10, 999, _lcd_refresh_e_factor_4);
  1294. #endif // EXTRUDERS > 4
  1295. #endif // EXTRUDERS > 3
  1296. #endif // EXTRUDERS > 2
  1297. #endif // EXTRUDERS > 1
  1298. //
  1299. // Babystep X:
  1300. // Babystep Y:
  1301. // Babystep Z:
  1302. //
  1303. #if ENABLED(BABYSTEPPING)
  1304. #if ENABLED(BABYSTEP_XY)
  1305. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  1306. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  1307. #endif
  1308. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1309. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  1310. #else
  1311. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  1312. #endif
  1313. #endif
  1314. //
  1315. // Change filament
  1316. //
  1317. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1318. #if E_STEPPERS == 1 && !ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  1319. if (thermalManager.targetHotEnoughToExtrude(active_extruder))
  1320. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600 B0"));
  1321. else
  1322. MENU_ITEM(submenu, MSG_FILAMENTCHANGE, lcd_temp_menu_e0_filament_change);
  1323. #else
  1324. MENU_ITEM(submenu, MSG_FILAMENTCHANGE, lcd_change_filament_menu);
  1325. #endif
  1326. #endif
  1327. END_MENU();
  1328. }
  1329. /**
  1330. *
  1331. * "Driver current control" submenu items
  1332. *
  1333. */
  1334. #if ENABLED(DAC_STEPPER_CURRENT)
  1335. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  1336. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  1337. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  1338. void lcd_dac_menu() {
  1339. dac_driver_getValues();
  1340. START_MENU();
  1341. MENU_BACK(MSG_CONTROL);
  1342. MENU_ITEM_EDIT_CALLBACK(int8, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  1343. MENU_ITEM_EDIT_CALLBACK(int8, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  1344. MENU_ITEM_EDIT_CALLBACK(int8, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  1345. MENU_ITEM_EDIT_CALLBACK(int8, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  1346. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  1347. END_MENU();
  1348. }
  1349. #endif // DAC_STEPPER_CURRENT
  1350. #if HAS_MOTOR_CURRENT_PWM
  1351. void lcd_pwm_menu() {
  1352. START_MENU();
  1353. MENU_BACK(MSG_CONTROL);
  1354. #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
  1355. MENU_ITEM_EDIT_CALLBACK(long5, MSG_X MSG_Y, &stepper.motor_current_setting[0], 100, 2000, Stepper::refresh_motor_power);
  1356. #endif
  1357. #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
  1358. MENU_ITEM_EDIT_CALLBACK(long5, MSG_Z, &stepper.motor_current_setting[1], 100, 2000, Stepper::refresh_motor_power);
  1359. #endif
  1360. #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
  1361. MENU_ITEM_EDIT_CALLBACK(long5, MSG_E, &stepper.motor_current_setting[2], 100, 2000, Stepper::refresh_motor_power);
  1362. #endif
  1363. END_MENU();
  1364. }
  1365. #endif // HAS_MOTOR_CURRENT_PWM
  1366. constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  1367. /**
  1368. *
  1369. * "Prepare" submenu items
  1370. *
  1371. */
  1372. void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb, const int16_t fan) {
  1373. if (temph > 0) thermalManager.setTargetHotend(MIN(heater_maxtemp[endnum], temph), endnum);
  1374. #if HAS_HEATED_BED
  1375. if (tempb >= 0) thermalManager.setTargetBed(tempb);
  1376. #else
  1377. UNUSED(tempb);
  1378. #endif
  1379. #if FAN_COUNT > 0
  1380. #if FAN_COUNT > 1
  1381. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  1382. #else
  1383. fanSpeeds[0] = fan;
  1384. #endif
  1385. #else
  1386. UNUSED(fan);
  1387. #endif
  1388. lcd_return_to_status();
  1389. }
  1390. #if HAS_TEMP_HOTEND
  1391. void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1392. void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1393. #if HAS_HEATED_BED
  1394. void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1395. void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1396. #endif
  1397. #endif
  1398. #if HOTENDS > 1
  1399. void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1400. void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1401. #if HAS_HEATED_BED
  1402. void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1403. void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1404. #endif
  1405. #if HOTENDS > 2
  1406. void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1407. void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1408. #if HAS_HEATED_BED
  1409. void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1410. void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1411. #endif
  1412. #if HOTENDS > 3
  1413. void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1414. void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1415. #if HAS_HEATED_BED
  1416. void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1417. void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1418. #endif
  1419. #if HOTENDS > 4
  1420. void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1421. void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1422. #if HAS_HEATED_BED
  1423. void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1424. void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1425. #endif
  1426. #endif // HOTENDS > 4
  1427. #endif // HOTENDS > 3
  1428. #endif // HOTENDS > 2
  1429. void lcd_preheat_m1_all() {
  1430. #if HOTENDS > 1
  1431. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  1432. #if HOTENDS > 2
  1433. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  1434. #if HOTENDS > 3
  1435. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  1436. #if HOTENDS > 4
  1437. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 4);
  1438. #endif // HOTENDS > 4
  1439. #endif // HOTENDS > 3
  1440. #endif // HOTENDS > 2
  1441. #endif // HOTENDS > 1
  1442. #if HAS_HEATED_BED
  1443. lcd_preheat_m1_e0();
  1444. #else
  1445. lcd_preheat_m1_e0_only();
  1446. #endif
  1447. }
  1448. void lcd_preheat_m2_all() {
  1449. #if HOTENDS > 1
  1450. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  1451. #if HOTENDS > 2
  1452. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  1453. #if HOTENDS > 3
  1454. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  1455. #if HOTENDS > 4
  1456. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 4);
  1457. #endif // HOTENDS > 4
  1458. #endif // HOTENDS > 3
  1459. #endif // HOTENDS > 2
  1460. #endif // HOTENDS > 1
  1461. #if HAS_HEATED_BED
  1462. lcd_preheat_m2_e0();
  1463. #else
  1464. lcd_preheat_m2_e0_only();
  1465. #endif
  1466. }
  1467. #endif // HOTENDS > 1
  1468. #if HAS_HEATED_BED
  1469. void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1470. void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1471. #endif
  1472. #if HAS_TEMP_HOTEND || HAS_HEATED_BED
  1473. void lcd_preheat_m1_menu() {
  1474. START_MENU();
  1475. MENU_BACK(MSG_PREPARE);
  1476. #if HOTENDS == 1
  1477. #if HAS_HEATED_BED
  1478. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
  1479. MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
  1480. #else
  1481. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1482. #endif
  1483. #elif HOTENDS > 1
  1484. #if HAS_HEATED_BED
  1485. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
  1486. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
  1487. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
  1488. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E2, lcd_preheat_m1_e1_only);
  1489. #else
  1490. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0_only);
  1491. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
  1492. #endif
  1493. #if HOTENDS > 2
  1494. #if HAS_HEATED_BED
  1495. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
  1496. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
  1497. #else
  1498. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
  1499. #endif
  1500. #if HOTENDS > 3
  1501. #if HAS_HEATED_BED
  1502. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
  1503. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
  1504. #else
  1505. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
  1506. #endif
  1507. #if HOTENDS > 4
  1508. #if HAS_HEATED_BED
  1509. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
  1510. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
  1511. #else
  1512. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4_only);
  1513. #endif
  1514. #endif // HOTENDS > 4
  1515. #endif // HOTENDS > 3
  1516. #endif // HOTENDS > 2
  1517. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
  1518. #endif // HOTENDS > 1
  1519. #if HAS_HEATED_BED
  1520. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
  1521. #endif
  1522. END_MENU();
  1523. }
  1524. void lcd_preheat_m2_menu() {
  1525. START_MENU();
  1526. MENU_BACK(MSG_PREPARE);
  1527. #if HOTENDS == 1
  1528. #if HAS_HEATED_BED
  1529. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
  1530. MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
  1531. #else
  1532. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1533. #endif
  1534. #elif HOTENDS > 1
  1535. #if HAS_HEATED_BED
  1536. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
  1537. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
  1538. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
  1539. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E2, lcd_preheat_m2_e1_only);
  1540. #else
  1541. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0_only);
  1542. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
  1543. #endif
  1544. #if HOTENDS > 2
  1545. #if HAS_HEATED_BED
  1546. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
  1547. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
  1548. #else
  1549. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
  1550. #endif
  1551. #if HOTENDS > 3
  1552. #if HAS_HEATED_BED
  1553. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
  1554. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
  1555. #else
  1556. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
  1557. #endif
  1558. #if HOTENDS > 4
  1559. #if HAS_HEATED_BED
  1560. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
  1561. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
  1562. #else
  1563. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4_only);
  1564. #endif
  1565. #endif // HOTENDS > 4
  1566. #endif // HOTENDS > 3
  1567. #endif // HOTENDS > 2
  1568. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
  1569. #endif // HOTENDS > 1
  1570. #if HAS_HEATED_BED
  1571. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
  1572. #endif
  1573. END_MENU();
  1574. }
  1575. #endif // HAS_TEMP_HOTEND || HAS_HEATED_BED
  1576. void lcd_cooldown() {
  1577. #if FAN_COUNT > 0
  1578. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  1579. #endif
  1580. thermalManager.disable_all_heaters();
  1581. lcd_return_to_status();
  1582. }
  1583. #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(PID_AUTOTUNE_MENU) || ENABLED(ADVANCED_PAUSE_FEATURE)
  1584. /**
  1585. * If the queue is full, the command will fail, so we have to loop
  1586. * with idle() to make sure the command has been enqueued.
  1587. */
  1588. void lcd_enqueue_command(char * const cmd) {
  1589. no_reentry = true;
  1590. enqueue_and_echo_command_now(cmd);
  1591. no_reentry = false;
  1592. }
  1593. void lcd_enqueue_commands_P(const char * const cmd) {
  1594. no_reentry = true;
  1595. enqueue_and_echo_commands_now_P(cmd);
  1596. no_reentry = false;
  1597. }
  1598. #endif
  1599. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1600. void lcd_autostart_sd() { card.beginautostart(); }
  1601. #endif
  1602. #if ENABLED(EEPROM_SETTINGS)
  1603. static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  1604. static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  1605. #endif
  1606. #if ENABLED(LEVEL_BED_CORNERS)
  1607. #ifndef LEVEL_CORNERS_Z_HOP
  1608. #define LEVEL_CORNERS_Z_HOP 4.0
  1609. #endif
  1610. static_assert(LEVEL_CORNERS_Z_HOP >= 0, "LEVEL_CORNERS_Z_HOP must be >= 0. Please update your configuration.");
  1611. /**
  1612. * Level corners, starting in the front-left corner.
  1613. */
  1614. static int8_t bed_corner;
  1615. void _lcd_goto_next_corner() {
  1616. line_to_z(LEVEL_CORNERS_Z_HOP);
  1617. switch (bed_corner) {
  1618. case 0:
  1619. current_position[X_AXIS] = X_MIN_BED + LEVEL_CORNERS_INSET;
  1620. current_position[Y_AXIS] = Y_MIN_BED + LEVEL_CORNERS_INSET;
  1621. break;
  1622. case 1:
  1623. current_position[X_AXIS] = X_MAX_BED - LEVEL_CORNERS_INSET;
  1624. break;
  1625. case 2:
  1626. current_position[Y_AXIS] = Y_MAX_BED - LEVEL_CORNERS_INSET;
  1627. break;
  1628. case 3:
  1629. current_position[X_AXIS] = X_MIN_BED + LEVEL_CORNERS_INSET;
  1630. break;
  1631. #if ENABLED(LEVEL_CENTER_TOO)
  1632. case 4:
  1633. current_position[X_AXIS] = X_CENTER;
  1634. current_position[Y_AXIS] = Y_CENTER;
  1635. break;
  1636. #endif
  1637. }
  1638. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[X_AXIS]), active_extruder);
  1639. line_to_z(0.0);
  1640. if (++bed_corner > 3
  1641. #if ENABLED(LEVEL_CENTER_TOO)
  1642. + 1
  1643. #endif
  1644. ) bed_corner = 0;
  1645. }
  1646. void _lcd_corner_submenu() {
  1647. START_MENU();
  1648. MENU_ITEM(function,
  1649. #if ENABLED(LEVEL_CENTER_TOO)
  1650. MSG_LEVEL_BED_NEXT_POINT
  1651. #else
  1652. MSG_NEXT_CORNER
  1653. #endif
  1654. , _lcd_goto_next_corner);
  1655. MENU_ITEM(function, MSG_BACK, lcd_goto_previous_menu_no_defer);
  1656. END_MENU();
  1657. }
  1658. void _lcd_level_bed_corners() {
  1659. defer_return_to_status = true;
  1660. lcd_goto_screen(_lcd_corner_submenu);
  1661. bed_corner = 0;
  1662. _lcd_goto_next_corner();
  1663. }
  1664. #endif // LEVEL_BED_CORNERS
  1665. #if ENABLED(LCD_BED_LEVELING) && (ENABLED(PROBE_MANUALLY) || ENABLED(MESH_BED_LEVELING))
  1666. /**
  1667. *
  1668. * "Prepare" > "Level Bed" handlers
  1669. *
  1670. */
  1671. static uint8_t manual_probe_index;
  1672. // LCD probed points are from defaults
  1673. constexpr uint8_t total_probe_points = (
  1674. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  1675. 3
  1676. #elif ABL_GRID || ENABLED(MESH_BED_LEVELING)
  1677. GRID_MAX_POINTS
  1678. #endif
  1679. );
  1680. bool lcd_wait_for_move;
  1681. //
  1682. // Bed leveling is done. Wait for G29 to complete.
  1683. // A flag is used so that this can release control
  1684. // and allow the command queue to be processed.
  1685. //
  1686. // When G29 finishes the last move:
  1687. // - Raise Z to the "manual probe height"
  1688. // - Don't return until done.
  1689. //
  1690. // ** This blocks the command queue! **
  1691. //
  1692. void _lcd_level_bed_done() {
  1693. if (!lcd_wait_for_move) {
  1694. #if MANUAL_PROBE_HEIGHT > 0 && DISABLED(MESH_BED_LEVELING)
  1695. // Display "Done" screen and wait for moves to complete
  1696. line_to_z(MANUAL_PROBE_HEIGHT);
  1697. lcd_synchronize(PSTR(MSG_LEVEL_BED_DONE));
  1698. #endif
  1699. lcd_goto_previous_menu_no_defer();
  1700. lcd_completion_feedback();
  1701. }
  1702. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_DONE));
  1703. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1704. }
  1705. void _lcd_level_goto_next_point();
  1706. /**
  1707. * Step 7: Get the Z coordinate, click goes to the next point or exits
  1708. */
  1709. void _lcd_level_bed_get_z() {
  1710. ENCODER_DIRECTION_NORMAL();
  1711. if (use_click()) {
  1712. //
  1713. // Save the current Z position and move
  1714. //
  1715. // If done...
  1716. if (++manual_probe_index >= total_probe_points) {
  1717. //
  1718. // The last G29 records the point and enables bed leveling
  1719. //
  1720. lcd_wait_for_move = true;
  1721. lcd_goto_screen(_lcd_level_bed_done);
  1722. #if ENABLED(MESH_BED_LEVELING)
  1723. enqueue_and_echo_commands_P(PSTR("G29 S2"));
  1724. #elif ENABLED(PROBE_MANUALLY)
  1725. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1726. #endif
  1727. }
  1728. else
  1729. _lcd_level_goto_next_point();
  1730. return;
  1731. }
  1732. //
  1733. // Encoder knob or keypad buttons adjust the Z position
  1734. //
  1735. if (encoderPosition) {
  1736. const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP);
  1737. line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5f, (LCD_PROBE_Z_RANGE) * 0.5f));
  1738. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1739. encoderPosition = 0;
  1740. }
  1741. //
  1742. // Draw on first display, then only on Z change
  1743. //
  1744. if (lcdDrawUpdate) {
  1745. const float v = current_position[Z_AXIS];
  1746. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001f : 0.0001f), '+'));
  1747. }
  1748. }
  1749. /**
  1750. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  1751. */
  1752. void _lcd_level_bed_moving() {
  1753. if (lcdDrawUpdate) {
  1754. char msg[10];
  1755. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  1756. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  1757. }
  1758. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1759. if (!lcd_wait_for_move) lcd_goto_screen(_lcd_level_bed_get_z);
  1760. }
  1761. /**
  1762. * Step 5: Initiate a move to the next point
  1763. */
  1764. void _lcd_level_goto_next_point() {
  1765. lcd_goto_screen(_lcd_level_bed_moving);
  1766. // G29 Records Z, moves, and signals when it pauses
  1767. lcd_wait_for_move = true;
  1768. #if ENABLED(MESH_BED_LEVELING)
  1769. enqueue_and_echo_commands_P(manual_probe_index ? PSTR("G29 S2") : PSTR("G29 S1"));
  1770. #elif ENABLED(PROBE_MANUALLY)
  1771. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1772. #endif
  1773. }
  1774. /**
  1775. * Step 4: Display "Click to Begin", wait for click
  1776. * Move to the first probe position
  1777. */
  1778. void _lcd_level_bed_homing_done() {
  1779. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1780. if (use_click()) {
  1781. manual_probe_index = 0;
  1782. _lcd_level_goto_next_point();
  1783. }
  1784. }
  1785. /**
  1786. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1787. */
  1788. void _lcd_level_bed_homing() {
  1789. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1790. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1791. if (all_axes_homed()) lcd_goto_screen(_lcd_level_bed_homing_done);
  1792. }
  1793. #if ENABLED(PROBE_MANUALLY)
  1794. extern bool g29_in_progress;
  1795. #endif
  1796. /**
  1797. * Step 2: Continue Bed Leveling...
  1798. */
  1799. void _lcd_level_bed_continue() {
  1800. defer_return_to_status = true;
  1801. axis_homed = 0;
  1802. lcd_goto_screen(_lcd_level_bed_homing);
  1803. enqueue_and_echo_commands_P(PSTR("G28"));
  1804. }
  1805. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1806. void _lcd_ubl_level_bed();
  1807. static int16_t ubl_storage_slot = 0,
  1808. custom_hotend_temp = 190,
  1809. side_points = 3,
  1810. ubl_fillin_amount = 5,
  1811. ubl_height_amount = 1,
  1812. n_edit_pts = 1,
  1813. x_plot = 0,
  1814. y_plot = 0;
  1815. #if HAS_HEATED_BED
  1816. static int16_t custom_bed_temp = 50;
  1817. #endif
  1818. /**
  1819. * UBL Build Custom Mesh Command
  1820. */
  1821. void _lcd_ubl_build_custom_mesh() {
  1822. char UBL_LCD_GCODE[20];
  1823. enqueue_and_echo_commands_P(PSTR("G28"));
  1824. #if HAS_HEATED_BED
  1825. sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
  1826. lcd_enqueue_command(UBL_LCD_GCODE);
  1827. #endif
  1828. sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
  1829. lcd_enqueue_command(UBL_LCD_GCODE);
  1830. enqueue_and_echo_commands_P(PSTR("G29 P1"));
  1831. }
  1832. /**
  1833. * UBL Custom Mesh submenu
  1834. *
  1835. * << Build Mesh
  1836. * Hotend Temp: ---
  1837. * Bed Temp: ---
  1838. * Build Custom Mesh
  1839. */
  1840. void _lcd_ubl_custom_mesh() {
  1841. START_MENU();
  1842. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1843. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_HOTEND_TEMP, &custom_hotend_temp, EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP - 10));
  1844. #if HAS_HEATED_BED
  1845. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_BED_TEMP, &custom_bed_temp, BED_MINTEMP, (BED_MAXTEMP - 15));
  1846. #endif
  1847. MENU_ITEM(function, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
  1848. END_MENU();
  1849. }
  1850. /**
  1851. * UBL Adjust Mesh Height Command
  1852. */
  1853. void _lcd_ubl_adjust_height_cmd() {
  1854. char UBL_LCD_GCODE[16];
  1855. const int ind = ubl_height_amount > 0 ? 9 : 10;
  1856. strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6 C -"));
  1857. sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), ABS(ubl_height_amount));
  1858. lcd_enqueue_command(UBL_LCD_GCODE);
  1859. }
  1860. /**
  1861. * UBL Adjust Mesh Height submenu
  1862. *
  1863. * << Edit Mesh
  1864. * Height Amount: ---
  1865. * Adjust Mesh Height
  1866. * << Info Screen
  1867. */
  1868. void _lcd_ubl_height_adjust_menu() {
  1869. START_MENU();
  1870. MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
  1871. MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9, _lcd_ubl_adjust_height_cmd);
  1872. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1873. END_MENU();
  1874. }
  1875. /**
  1876. * UBL Edit Mesh submenu
  1877. *
  1878. * << UBL Tools
  1879. * Fine Tune All
  1880. * Fine Tune Closest
  1881. * - Adjust Mesh Height >>
  1882. * << Info Screen
  1883. */
  1884. void _lcd_ubl_edit_mesh() {
  1885. START_MENU();
  1886. MENU_BACK(MSG_UBL_TOOLS);
  1887. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  1888. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
  1889. MENU_ITEM(submenu, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_height_adjust_menu);
  1890. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1891. END_MENU();
  1892. }
  1893. /**
  1894. * UBL Validate Custom Mesh Command
  1895. */
  1896. void _lcd_ubl_validate_custom_mesh() {
  1897. char UBL_LCD_GCODE[24];
  1898. const int temp =
  1899. #if HAS_HEATED_BED
  1900. custom_bed_temp
  1901. #else
  1902. 0
  1903. #endif
  1904. ;
  1905. sprintf_P(UBL_LCD_GCODE, PSTR("G26 C B%i H%i P"), temp, custom_hotend_temp);
  1906. lcd_enqueue_commands_P(PSTR("G28"));
  1907. lcd_enqueue_command(UBL_LCD_GCODE);
  1908. }
  1909. /**
  1910. * UBL Validate Mesh submenu
  1911. *
  1912. * << UBL Tools
  1913. * PLA Mesh Validation
  1914. * ABS Mesh Validation
  1915. * Validate Custom Mesh
  1916. * << Info Screen
  1917. */
  1918. void _lcd_ubl_validate_mesh() {
  1919. START_MENU();
  1920. MENU_BACK(MSG_UBL_TOOLS);
  1921. #if HAS_HEATED_BED
  1922. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_1_TEMP_BED) " H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1923. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_2_TEMP_BED) " H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1924. #else
  1925. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1926. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1927. #endif
  1928. MENU_ITEM(function, MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
  1929. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1930. END_MENU();
  1931. }
  1932. /**
  1933. * UBL Grid Leveling Command
  1934. */
  1935. void _lcd_ubl_grid_level_cmd() {
  1936. char UBL_LCD_GCODE[10];
  1937. sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
  1938. lcd_enqueue_command(UBL_LCD_GCODE);
  1939. }
  1940. /**
  1941. * UBL Grid Leveling submenu
  1942. *
  1943. * << UBL Tools
  1944. * Side points: ---
  1945. * Level Mesh
  1946. */
  1947. void _lcd_ubl_grid_level() {
  1948. START_MENU();
  1949. MENU_BACK(MSG_UBL_TOOLS);
  1950. MENU_ITEM_EDIT(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
  1951. MENU_ITEM(function, MSG_UBL_MESH_LEVEL, _lcd_ubl_grid_level_cmd);
  1952. END_MENU();
  1953. }
  1954. /**
  1955. * UBL Mesh Leveling submenu
  1956. *
  1957. * << UBL Tools
  1958. * 3-Point Mesh Leveling
  1959. * - Grid Mesh Leveling >>
  1960. * << Info Screen
  1961. */
  1962. void _lcd_ubl_mesh_leveling() {
  1963. START_MENU();
  1964. MENU_BACK(MSG_UBL_TOOLS);
  1965. MENU_ITEM(gcode, MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
  1966. MENU_ITEM(submenu, MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
  1967. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1968. END_MENU();
  1969. }
  1970. /**
  1971. * UBL Fill-in Amount Mesh Command
  1972. */
  1973. void _lcd_ubl_fillin_amount_cmd() {
  1974. char UBL_LCD_GCODE[16];
  1975. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
  1976. lcd_enqueue_command(UBL_LCD_GCODE);
  1977. }
  1978. /**
  1979. * UBL Fill-in Mesh submenu
  1980. *
  1981. * << Build Mesh
  1982. * Fill-in Amount: ---
  1983. * Fill-in Mesh
  1984. * Smart Fill-in
  1985. * Manual Fill-in
  1986. * << Info Screen
  1987. */
  1988. void _lcd_ubl_fillin_menu() {
  1989. START_MENU();
  1990. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1991. MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
  1992. MENU_ITEM(gcode, MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
  1993. MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
  1994. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1995. END_MENU();
  1996. }
  1997. void _lcd_ubl_invalidate() {
  1998. ubl.invalidate();
  1999. SERIAL_PROTOCOLLNPGM("Mesh invalidated.");
  2000. }
  2001. /**
  2002. * UBL Build Mesh submenu
  2003. *
  2004. * << UBL Tools
  2005. * Build PLA Mesh
  2006. * Build ABS Mesh
  2007. * - Build Custom Mesh >>
  2008. * Build Cold Mesh
  2009. * - Fill-in Mesh >>
  2010. * Continue Bed Mesh
  2011. * Invalidate All
  2012. * Invalidate Closest
  2013. * << Info Screen
  2014. */
  2015. void _lcd_ubl_build_mesh() {
  2016. START_MENU();
  2017. MENU_BACK(MSG_UBL_TOOLS);
  2018. #if HAS_HEATED_BED
  2019. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  2020. "G28\n"
  2021. "M190 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\n"
  2022. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  2023. "G29 P1\n"
  2024. "M104 S0\n"
  2025. "M140 S0"
  2026. ));
  2027. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  2028. "G28\n"
  2029. "M190 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\n"
  2030. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  2031. "G29 P1\n"
  2032. "M104 S0\n"
  2033. "M140 S0"
  2034. ));
  2035. #else
  2036. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  2037. "G28\n"
  2038. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  2039. "G29 P1\n"
  2040. "M104 S0"
  2041. ));
  2042. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  2043. "G28\n"
  2044. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  2045. "G29 P1\n"
  2046. "M104 S0"
  2047. ));
  2048. #endif
  2049. MENU_ITEM(submenu, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  2050. MENU_ITEM(gcode, MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  2051. MENU_ITEM(submenu, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_menu);
  2052. MENU_ITEM(gcode, MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
  2053. MENU_ITEM(function, MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  2054. MENU_ITEM(gcode, MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
  2055. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  2056. END_MENU();
  2057. }
  2058. /**
  2059. * UBL Load Mesh Command
  2060. */
  2061. void _lcd_ubl_load_mesh_cmd() {
  2062. char UBL_LCD_GCODE[25];
  2063. sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
  2064. lcd_enqueue_command(UBL_LCD_GCODE);
  2065. sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_LOADED), ubl_storage_slot);
  2066. lcd_enqueue_command(UBL_LCD_GCODE);
  2067. }
  2068. /**
  2069. * UBL Save Mesh Command
  2070. */
  2071. void _lcd_ubl_save_mesh_cmd() {
  2072. char UBL_LCD_GCODE[25];
  2073. sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
  2074. lcd_enqueue_command(UBL_LCD_GCODE);
  2075. sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_SAVED), ubl_storage_slot);
  2076. lcd_enqueue_command(UBL_LCD_GCODE);
  2077. }
  2078. /**
  2079. * UBL Mesh Storage submenu
  2080. *
  2081. * << Unified Bed Leveling
  2082. * Memory Slot: ---
  2083. * Load Bed Mesh
  2084. * Save Bed Mesh
  2085. */
  2086. void _lcd_ubl_storage_mesh() {
  2087. int16_t a = settings.calc_num_meshes();
  2088. START_MENU();
  2089. MENU_BACK(MSG_UBL_LEVEL_BED);
  2090. if (!WITHIN(ubl_storage_slot, 0, a - 1)) {
  2091. STATIC_ITEM(MSG_NO_STORAGE);
  2092. }
  2093. else {
  2094. MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
  2095. MENU_ITEM(function, MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  2096. MENU_ITEM(function, MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  2097. }
  2098. END_MENU();
  2099. }
  2100. /**
  2101. * UBL LCD "radar" map homing
  2102. */
  2103. void _lcd_ubl_output_map_lcd();
  2104. void _lcd_ubl_map_homing() {
  2105. defer_return_to_status = true;
  2106. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT < 3 ? 0 : (LCD_HEIGHT > 4 ? 2 : 1), PSTR(MSG_LEVEL_BED_HOMING));
  2107. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  2108. if (all_axes_homed()) {
  2109. ubl.lcd_map_control = true; // Return to the map screen
  2110. lcd_goto_screen(_lcd_ubl_output_map_lcd);
  2111. }
  2112. }
  2113. /**
  2114. * UBL LCD "radar" map point editing
  2115. */
  2116. void _lcd_ubl_map_lcd_edit_cmd() {
  2117. char UBL_LCD_GCODE[50], str[10], str2[10];
  2118. dtostrf(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]), 0, 2, str);
  2119. dtostrf(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]), 0, 2, str2);
  2120. snprintf_P(UBL_LCD_GCODE, sizeof(UBL_LCD_GCODE), PSTR("G29 P4 X%s Y%s R%i"), str, str2, n_edit_pts);
  2121. lcd_enqueue_command(UBL_LCD_GCODE);
  2122. }
  2123. /**
  2124. * UBL LCD Map Movement
  2125. */
  2126. void ubl_map_move_to_xy() {
  2127. current_position[X_AXIS] = pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]);
  2128. current_position[Y_AXIS] = pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]);
  2129. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  2130. }
  2131. /**
  2132. * UBL LCD "radar" map
  2133. */
  2134. void set_current_from_steppers_for_axis(const AxisEnum axis);
  2135. void _lcd_do_nothing() {}
  2136. void _lcd_hard_stop() {
  2137. const screenFunc_t old_screen = currentScreen;
  2138. currentScreen = _lcd_do_nothing;
  2139. planner.quick_stop();
  2140. currentScreen = old_screen;
  2141. set_current_from_steppers_for_axis(ALL_AXES);
  2142. sync_plan_position();
  2143. }
  2144. void _lcd_ubl_output_map_lcd() {
  2145. static int16_t step_scaler = 0;
  2146. if (use_click()) return _lcd_ubl_map_lcd_edit_cmd();
  2147. ENCODER_DIRECTION_NORMAL();
  2148. if (encoderPosition) {
  2149. step_scaler += (int32_t)encoderPosition;
  2150. x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
  2151. if (ABS(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
  2152. encoderPosition = 0;
  2153. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2154. }
  2155. // Encoder to the right (++)
  2156. if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
  2157. if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
  2158. // Encoder to the left (--)
  2159. if (x_plot <= GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1)) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
  2160. if (y_plot <= GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1)) y_plot = GRID_MAX_POINTS_Y - 1;
  2161. // Prevent underrun/overrun of plot numbers
  2162. x_plot = constrain(x_plot, GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1), GRID_MAX_POINTS_X + 1);
  2163. y_plot = constrain(y_plot, GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1), GRID_MAX_POINTS_Y + 1);
  2164. // Determine number of points to edit
  2165. #if IS_KINEMATIC
  2166. n_edit_pts = 9; //TODO: Delta accessible edit points
  2167. #else
  2168. const bool xc = WITHIN(x_plot, 1, GRID_MAX_POINTS_X - 2),
  2169. yc = WITHIN(y_plot, 1, GRID_MAX_POINTS_Y - 2);
  2170. n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
  2171. #endif
  2172. if (lcdDrawUpdate) {
  2173. lcd_implementation_ubl_plot(x_plot, y_plot);
  2174. if (planner.movesplanned()) // If the nozzle is already moving, cancel the move.
  2175. _lcd_hard_stop();
  2176. ubl_map_move_to_xy(); // Move to new location
  2177. }
  2178. }
  2179. /**
  2180. * UBL Homing before LCD map
  2181. */
  2182. void _lcd_ubl_output_map_lcd_cmd() {
  2183. if (!all_axes_known()) {
  2184. axis_homed = 0;
  2185. enqueue_and_echo_commands_P(PSTR("G28"));
  2186. }
  2187. lcd_goto_screen(_lcd_ubl_map_homing);
  2188. }
  2189. /**
  2190. * UBL Output map submenu
  2191. *
  2192. * << Unified Bed Leveling
  2193. * Output for Host
  2194. * Output for CSV
  2195. * Off Printer Backup
  2196. * Output Mesh Map
  2197. */
  2198. void _lcd_ubl_output_map() {
  2199. START_MENU();
  2200. MENU_BACK(MSG_UBL_LEVEL_BED);
  2201. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29 T0"));
  2202. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29 T1"));
  2203. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29 S-1"));
  2204. MENU_ITEM(function, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map_lcd_cmd);
  2205. END_MENU();
  2206. }
  2207. /**
  2208. * UBL Tools submenu
  2209. *
  2210. * << Unified Bed Leveling
  2211. * - Build Mesh >>
  2212. * - Validate Mesh >>
  2213. * - Edit Mesh >>
  2214. * - Mesh Leveling >>
  2215. */
  2216. void _lcd_ubl_tools_menu() {
  2217. START_MENU();
  2218. MENU_BACK(MSG_UBL_LEVEL_BED);
  2219. MENU_ITEM(submenu, MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  2220. MENU_ITEM(gcode, MSG_UBL_MANUAL_MESH, PSTR("G29 I999\nG29 P2 B T0"));
  2221. MENU_ITEM(submenu, MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  2222. MENU_ITEM(submenu, MSG_UBL_EDIT_MESH_MENU, _lcd_ubl_edit_mesh);
  2223. MENU_ITEM(submenu, MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  2224. END_MENU();
  2225. }
  2226. /**
  2227. * UBL Step-By-Step submenu
  2228. *
  2229. * << Unified Bed Leveling
  2230. * 1 Build Cold Mesh
  2231. * 2 Smart Fill-in
  2232. * - 3 Validate Mesh >>
  2233. * 4 Fine Tune All
  2234. * - 5 Validate Mesh >>
  2235. * 6 Fine Tune All
  2236. * 7 Save Bed Mesh
  2237. */
  2238. void _lcd_ubl_step_by_step() {
  2239. START_MENU();
  2240. MENU_BACK(MSG_UBL_LEVEL_BED);
  2241. MENU_ITEM(gcode, "1 " MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  2242. MENU_ITEM(gcode, "2 " MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
  2243. MENU_ITEM(submenu, "3 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  2244. MENU_ITEM(gcode, "4 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  2245. MENU_ITEM(submenu, "5 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  2246. MENU_ITEM(gcode, "6 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  2247. MENU_ITEM(function, "7 " MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  2248. END_MENU();
  2249. }
  2250. /**
  2251. * UBL System submenu
  2252. *
  2253. * << Prepare
  2254. * - Manually Build Mesh >>
  2255. * - Activate UBL >>
  2256. * - Deactivate UBL >>
  2257. * - Step-By-Step UBL >>
  2258. * - Mesh Storage >>
  2259. * - Output Map >>
  2260. * - UBL Tools >>
  2261. * - Output UBL Info >>
  2262. */
  2263. void _lcd_ubl_level_bed() {
  2264. START_MENU();
  2265. MENU_BACK(MSG_PREPARE);
  2266. MENU_ITEM(gcode, MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
  2267. MENU_ITEM(gcode, MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
  2268. MENU_ITEM(submenu, MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
  2269. MENU_ITEM(function, MSG_UBL_MESH_EDIT, _lcd_ubl_output_map_lcd_cmd);
  2270. MENU_ITEM(submenu, MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  2271. MENU_ITEM(submenu, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  2272. MENU_ITEM(submenu, MSG_UBL_TOOLS, _lcd_ubl_tools_menu);
  2273. MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
  2274. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  2275. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0, 100, _lcd_set_z_fade_height);
  2276. #endif
  2277. END_MENU();
  2278. }
  2279. #endif // AUTO_BED_LEVELING_UBL
  2280. #if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
  2281. void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(!planner.leveling_active); }
  2282. #endif
  2283. #if ENABLED(LCD_BED_LEVELING)
  2284. /**
  2285. * Step 1: Bed Level entry-point
  2286. *
  2287. * << Prepare
  2288. * Auto Home (if homing needed)
  2289. * Leveling On/Off (if data exists, and homed)
  2290. * Fade Height: --- (Req: ENABLE_LEVELING_FADE_HEIGHT)
  2291. * Mesh Z Offset: --- (Req: MESH_BED_LEVELING)
  2292. * Z Probe Offset: --- (Req: HAS_BED_PROBE, Opt: BABYSTEP_ZPROBE_OFFSET)
  2293. * Level Bed >
  2294. * Level Corners > (if homed)
  2295. * Load Settings (Req: EEPROM_SETTINGS)
  2296. * Save Settings (Req: EEPROM_SETTINGS)
  2297. */
  2298. void lcd_bed_leveling() {
  2299. START_MENU();
  2300. MENU_BACK(MSG_PREPARE);
  2301. const bool is_homed = all_axes_known();
  2302. // Auto Home if not using manual probing
  2303. #if DISABLED(PROBE_MANUALLY) && DISABLED(MESH_BED_LEVELING)
  2304. if (!is_homed) MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2305. #endif
  2306. // Level Bed
  2307. #if ENABLED(PROBE_MANUALLY) || ENABLED(MESH_BED_LEVELING)
  2308. // Manual leveling uses a guided procedure
  2309. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  2310. #else
  2311. // Automatic leveling can just run the G-code
  2312. MENU_ITEM(gcode, MSG_LEVEL_BED, is_homed ? PSTR("G29") : PSTR("G28\nG29"));
  2313. #endif
  2314. // Homed and leveling is valid? Then leveling can be toggled.
  2315. if (is_homed && leveling_is_valid()) {
  2316. bool new_level_state = planner.leveling_active;
  2317. MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
  2318. }
  2319. // Z Fade Height
  2320. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  2321. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0, 100, _lcd_set_z_fade_height);
  2322. #endif
  2323. //
  2324. // MBL Z Offset
  2325. //
  2326. #if ENABLED(MESH_BED_LEVELING)
  2327. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  2328. #endif
  2329. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  2330. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  2331. #elif HAS_BED_PROBE
  2332. MENU_ITEM_EDIT(float52, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  2333. #endif
  2334. #if ENABLED(LEVEL_BED_CORNERS)
  2335. // Move to the next corner for leveling
  2336. if (all_axes_homed()) MENU_ITEM(submenu, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
  2337. #endif
  2338. #if ENABLED(EEPROM_SETTINGS)
  2339. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2340. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2341. #endif
  2342. END_MENU();
  2343. }
  2344. #endif // LCD_BED_LEVELING
  2345. /**
  2346. *
  2347. * "Prepare" submenu
  2348. *
  2349. */
  2350. void lcd_prepare_menu() {
  2351. START_MENU();
  2352. //
  2353. // ^ Main
  2354. //
  2355. MENU_BACK(MSG_MAIN);
  2356. //
  2357. // Move Axis
  2358. //
  2359. #if ENABLED(DELTA)
  2360. if (all_axes_homed())
  2361. #endif
  2362. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  2363. //
  2364. // Auto Home
  2365. //
  2366. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2367. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  2368. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  2369. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  2370. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  2371. #endif
  2372. //
  2373. // TMC Z Calibration
  2374. //
  2375. #if ENABLED(TMC_Z_CALIBRATION)
  2376. MENU_ITEM(gcode, MSG_TMC_Z_CALIBRATION, PSTR("G28\nM915"));
  2377. #endif
  2378. //
  2379. // Level Bed
  2380. //
  2381. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2382. MENU_ITEM(submenu, MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  2383. #elif ENABLED(LCD_BED_LEVELING)
  2384. #if ENABLED(PROBE_MANUALLY)
  2385. if (!g29_in_progress)
  2386. #endif
  2387. MENU_ITEM(submenu, MSG_BED_LEVELING, lcd_bed_leveling);
  2388. #elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
  2389. #if DISABLED(PROBE_MANUALLY)
  2390. MENU_ITEM(gcode, MSG_LEVEL_BED, PSTR("G28\nG29"));
  2391. #endif
  2392. if (leveling_is_valid()) {
  2393. bool new_level_state = planner.leveling_active;
  2394. MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
  2395. }
  2396. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  2397. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0, 100, _lcd_set_z_fade_height);
  2398. #endif
  2399. #endif
  2400. #if ENABLED(LEVEL_BED_CORNERS) && DISABLED(LCD_BED_LEVELING)
  2401. if (all_axes_homed())
  2402. MENU_ITEM(function, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
  2403. #endif
  2404. #if HAS_M206_COMMAND && DISABLED(SLIM_LCD_MENUS)
  2405. //
  2406. // Set Home Offsets
  2407. //
  2408. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  2409. #endif
  2410. //
  2411. // Disable Steppers
  2412. //
  2413. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  2414. //
  2415. // Change filament
  2416. //
  2417. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2418. if (!IS_SD_FILE_OPEN()) {
  2419. #if E_STEPPERS == 1 && !ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  2420. if (thermalManager.targetHotEnoughToExtrude(active_extruder))
  2421. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600 B0"));
  2422. else
  2423. MENU_ITEM(submenu, MSG_FILAMENTCHANGE, lcd_temp_menu_e0_filament_change);
  2424. #else
  2425. MENU_ITEM(submenu, MSG_FILAMENTCHANGE, lcd_change_filament_menu);
  2426. #endif
  2427. }
  2428. #endif // ADVANCED_PAUSE_FEATURE
  2429. #if HAS_TEMP_HOTEND
  2430. //
  2431. // Cooldown
  2432. //
  2433. bool has_heat = false;
  2434. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  2435. #if HAS_HEATED_BED
  2436. if (thermalManager.target_temperature_bed) has_heat = true;
  2437. #endif
  2438. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  2439. //
  2440. // Preheat for Material 1 and 2
  2441. //
  2442. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || HAS_HEATED_BED
  2443. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
  2444. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
  2445. #else
  2446. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  2447. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  2448. #endif
  2449. #endif // HAS_TEMP_HOTEND
  2450. //
  2451. // BLTouch Self-Test and Reset
  2452. //
  2453. #if ENABLED(BLTOUCH)
  2454. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_PROBE_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  2455. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  2456. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_PROBE_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  2457. #endif
  2458. //
  2459. // Switch power on/off
  2460. //
  2461. #if HAS_POWER_SWITCH
  2462. if (powersupply_on)
  2463. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  2464. else
  2465. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  2466. #endif
  2467. //
  2468. // Autostart
  2469. //
  2470. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  2471. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  2472. #endif
  2473. //
  2474. // Delta Calibration
  2475. //
  2476. #if ENABLED(DELTA_CALIBRATION_MENU) || ENABLED(DELTA_AUTO_CALIBRATION)
  2477. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  2478. #endif
  2479. END_MENU();
  2480. }
  2481. float move_menu_scale;
  2482. #if ENABLED(DELTA_CALIBRATION_MENU) || ENABLED(DELTA_AUTO_CALIBRATION)
  2483. void lcd_move_z();
  2484. void _man_probe_pt(const float &rx, const float &ry) {
  2485. do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
  2486. do_blocking_move_to_xy(rx, ry);
  2487. lcd_synchronize();
  2488. move_menu_scale = MAX(PROBE_MANUALLY_STEP, MIN_STEPS_PER_SEGMENT / float(DEFAULT_XYZ_STEPS_PER_UNIT));
  2489. lcd_goto_screen(lcd_move_z);
  2490. }
  2491. #endif // DELTA_CALIBRATION_MENU || DELTA_AUTO_CALIBRATION
  2492. #if ENABLED(DELTA_AUTO_CALIBRATION)
  2493. float lcd_probe_pt(const float &rx, const float &ry) {
  2494. _man_probe_pt(rx, ry);
  2495. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2496. defer_return_to_status = true;
  2497. wait_for_user = true;
  2498. while (wait_for_user) idle();
  2499. KEEPALIVE_STATE(IN_HANDLER);
  2500. lcd_goto_previous_menu_no_defer();
  2501. return current_position[Z_AXIS];
  2502. }
  2503. #endif // DELTA_AUTO_CALIBRATION
  2504. #if ENABLED(DELTA_CALIBRATION_MENU)
  2505. void _lcd_calibrate_homing() {
  2506. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  2507. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  2508. if (all_axes_homed())
  2509. lcd_goto_previous_menu();
  2510. }
  2511. void _lcd_delta_calibrate_home() {
  2512. enqueue_and_echo_commands_P(PSTR("G28"));
  2513. lcd_goto_screen(_lcd_calibrate_homing);
  2514. }
  2515. void _goto_tower_x() { _man_probe_pt(cos(RADIANS(210)) * delta_calibration_radius, sin(RADIANS(210)) * delta_calibration_radius); }
  2516. void _goto_tower_y() { _man_probe_pt(cos(RADIANS(330)) * delta_calibration_radius, sin(RADIANS(330)) * delta_calibration_radius); }
  2517. void _goto_tower_z() { _man_probe_pt(cos(RADIANS( 90)) * delta_calibration_radius, sin(RADIANS( 90)) * delta_calibration_radius); }
  2518. void _goto_center() { _man_probe_pt(0,0); }
  2519. #endif // DELTA_CALIBRATION_MENU
  2520. #if ENABLED(DELTA_CALIBRATION_MENU) || ENABLED(DELTA_AUTO_CALIBRATION)
  2521. void _recalc_delta_settings() {
  2522. #if HAS_LEVELING
  2523. reset_bed_level(); // After changing kinematics bed-level data is no longer valid
  2524. #endif
  2525. recalc_delta_settings();
  2526. }
  2527. void lcd_delta_settings() {
  2528. START_MENU();
  2529. MENU_BACK(MSG_DELTA_CALIBRATE);
  2530. MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_DELTA_HEIGHT, &delta_height, delta_height - 10, delta_height + 10, _recalc_delta_settings);
  2531. MENU_ITEM_EDIT_CALLBACK(float43, "Ex", &delta_endstop_adj[A_AXIS], -5, 5, _recalc_delta_settings);
  2532. MENU_ITEM_EDIT_CALLBACK(float43, "Ey", &delta_endstop_adj[B_AXIS], -5, 5, _recalc_delta_settings);
  2533. MENU_ITEM_EDIT_CALLBACK(float43, "Ez", &delta_endstop_adj[C_AXIS], -5, 5, _recalc_delta_settings);
  2534. MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_DELTA_RADIUS, &delta_radius, delta_radius - 5, delta_radius + 5, _recalc_delta_settings);
  2535. MENU_ITEM_EDIT_CALLBACK(float43, "Tx", &delta_tower_angle_trim[A_AXIS], -5, 5, _recalc_delta_settings);
  2536. MENU_ITEM_EDIT_CALLBACK(float43, "Ty", &delta_tower_angle_trim[B_AXIS], -5, 5, _recalc_delta_settings);
  2537. MENU_ITEM_EDIT_CALLBACK(float43, "Tz", &delta_tower_angle_trim[C_AXIS], -5, 5, _recalc_delta_settings);
  2538. MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_DELTA_DIAG_ROD, &delta_diagonal_rod, delta_diagonal_rod - 5, delta_diagonal_rod + 5, _recalc_delta_settings);
  2539. END_MENU();
  2540. }
  2541. void lcd_delta_calibrate_menu() {
  2542. START_MENU();
  2543. MENU_BACK(MSG_MAIN);
  2544. #if ENABLED(DELTA_AUTO_CALIBRATION)
  2545. MENU_ITEM(gcode, MSG_DELTA_AUTO_CALIBRATE, PSTR("G33"));
  2546. #if ENABLED(EEPROM_SETTINGS)
  2547. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2548. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2549. #endif
  2550. #endif
  2551. MENU_ITEM(submenu, MSG_DELTA_SETTINGS, lcd_delta_settings);
  2552. #if ENABLED(DELTA_CALIBRATION_MENU)
  2553. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  2554. if (all_axes_homed()) {
  2555. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  2556. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  2557. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  2558. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  2559. }
  2560. #endif
  2561. END_MENU();
  2562. }
  2563. #endif // DELTA_CALIBRATION_MENU || DELTA_AUTO_CALIBRATION
  2564. /**
  2565. * If the most recent manual move hasn't been fed to the planner yet,
  2566. * and the planner can accept one, send immediately
  2567. */
  2568. inline void manage_manual_move() {
  2569. if (processing_manual_move) return;
  2570. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  2571. #if IS_KINEMATIC
  2572. const float old_feedrate = feedrate_mm_s;
  2573. feedrate_mm_s = MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]);
  2574. #if EXTRUDERS > 1
  2575. const int8_t old_extruder = active_extruder;
  2576. if (manual_move_axis == E_AXIS) active_extruder = manual_move_e_index;
  2577. #endif
  2578. // Set movement on a single axis
  2579. set_destination_from_current();
  2580. destination[manual_move_axis] += manual_move_offset;
  2581. // Reset for the next move
  2582. manual_move_offset = 0;
  2583. manual_move_axis = (int8_t)NO_AXIS;
  2584. // DELTA and SCARA machines use segmented moves, which could fill the planner during the call to
  2585. // move_to_destination. This will cause idle() to be called, which can then call this function while the
  2586. // previous invocation is being blocked. Modifications to manual_move_offset shouldn't be made while
  2587. // processing_manual_move is true or the planner will get out of sync.
  2588. processing_manual_move = true;
  2589. prepare_move_to_destination(); // will call set_current_from_destination()
  2590. processing_manual_move = false;
  2591. feedrate_mm_s = old_feedrate;
  2592. #if EXTRUDERS > 1
  2593. active_extruder = old_extruder;
  2594. #endif
  2595. #else
  2596. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_axis == E_AXIS ? manual_move_e_index : active_extruder);
  2597. manual_move_axis = (int8_t)NO_AXIS;
  2598. #endif
  2599. }
  2600. }
  2601. /**
  2602. * Set a flag that lcd_update() should start a move
  2603. * to "current_position" after a short delay.
  2604. */
  2605. inline void manual_move_to_current(AxisEnum axis
  2606. #if E_MANUAL > 1
  2607. , const int8_t eindex=-1
  2608. #endif
  2609. ) {
  2610. #if ENABLED(DUAL_X_CARRIAGE) || E_MANUAL > 1
  2611. #if E_MANUAL > 1
  2612. if (axis == E_AXIS)
  2613. #endif
  2614. manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  2615. #endif
  2616. manual_move_start_time = millis() + (move_menu_scale < 0.99f ? 0UL : 250UL); // delay for bigger moves
  2617. manual_move_axis = (int8_t)axis;
  2618. }
  2619. /**
  2620. *
  2621. * "Prepare" > "Move Axis" submenu
  2622. *
  2623. */
  2624. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  2625. if (use_click()) { return lcd_goto_previous_menu_no_defer(); }
  2626. ENCODER_DIRECTION_NORMAL();
  2627. if (encoderPosition && !processing_manual_move) {
  2628. // Start with no limits to movement
  2629. float min = current_position[axis] - 1000,
  2630. max = current_position[axis] + 1000;
  2631. // Limit to software endstops, if enabled
  2632. #if ENABLED(MIN_SOFTWARE_ENDSTOPS) || ENABLED(MAX_SOFTWARE_ENDSTOPS)
  2633. if (soft_endstops_enabled) switch (axis) {
  2634. case X_AXIS:
  2635. #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
  2636. min = soft_endstop_min[X_AXIS];
  2637. #endif
  2638. #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
  2639. max = soft_endstop_max[X_AXIS];
  2640. #endif
  2641. break;
  2642. case Y_AXIS:
  2643. #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
  2644. min = soft_endstop_min[Y_AXIS];
  2645. #endif
  2646. #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
  2647. max = soft_endstop_max[Y_AXIS];
  2648. #endif
  2649. break;
  2650. case Z_AXIS:
  2651. #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
  2652. min = soft_endstop_min[Z_AXIS];
  2653. #endif
  2654. #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
  2655. max = soft_endstop_max[Z_AXIS];
  2656. #endif
  2657. default: break;
  2658. }
  2659. #endif // MIN_SOFTWARE_ENDSTOPS || MAX_SOFTWARE_ENDSTOPS
  2660. // Delta limits XY based on the current offset from center
  2661. // This assumes the center is 0,0
  2662. #if ENABLED(DELTA)
  2663. if (axis != Z_AXIS) {
  2664. max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis
  2665. min = -max;
  2666. }
  2667. #endif
  2668. // Get the new position
  2669. const float diff = float((int32_t)encoderPosition) * move_menu_scale;
  2670. #if IS_KINEMATIC
  2671. manual_move_offset += diff;
  2672. if ((int32_t)encoderPosition < 0)
  2673. NOLESS(manual_move_offset, min - current_position[axis]);
  2674. else
  2675. NOMORE(manual_move_offset, max - current_position[axis]);
  2676. #else
  2677. current_position[axis] += diff;
  2678. if ((int32_t)encoderPosition < 0)
  2679. NOLESS(current_position[axis], min);
  2680. else
  2681. NOMORE(current_position[axis], max);
  2682. #endif
  2683. manual_move_to_current(axis);
  2684. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2685. }
  2686. encoderPosition = 0;
  2687. if (lcdDrawUpdate) {
  2688. const float pos = NATIVE_TO_LOGICAL(processing_manual_move ? destination[axis] : current_position[axis]
  2689. #if IS_KINEMATIC
  2690. + manual_move_offset
  2691. #endif
  2692. , axis);
  2693. lcd_implementation_drawedit(name, move_menu_scale >= 0.1f ? ftostr41sign(pos) : ftostr43sign(pos));
  2694. }
  2695. }
  2696. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  2697. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  2698. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  2699. void _lcd_move_e(
  2700. #if E_MANUAL > 1
  2701. const int8_t eindex=-1
  2702. #endif
  2703. ) {
  2704. if (use_click()) { return lcd_goto_previous_menu_no_defer(); }
  2705. ENCODER_DIRECTION_NORMAL();
  2706. if (encoderPosition) {
  2707. if (!processing_manual_move) {
  2708. const float diff = float((int32_t)encoderPosition) * move_menu_scale;
  2709. #if IS_KINEMATIC
  2710. manual_move_offset += diff;
  2711. #else
  2712. current_position[E_CART] += diff;
  2713. #endif
  2714. manual_move_to_current(E_AXIS
  2715. #if E_MANUAL > 1
  2716. , eindex
  2717. #endif
  2718. );
  2719. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2720. }
  2721. encoderPosition = 0;
  2722. }
  2723. if (lcdDrawUpdate) {
  2724. PGM_P pos_label;
  2725. #if E_MANUAL == 1
  2726. pos_label = PSTR(MSG_MOVE_E);
  2727. #else
  2728. switch (eindex) {
  2729. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  2730. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  2731. #if E_MANUAL > 2
  2732. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  2733. #if E_MANUAL > 3
  2734. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  2735. #if E_MANUAL > 4
  2736. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  2737. #endif // E_MANUAL > 4
  2738. #endif // E_MANUAL > 3
  2739. #endif // E_MANUAL > 2
  2740. }
  2741. #endif // E_MANUAL > 1
  2742. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_CART]
  2743. #if IS_KINEMATIC
  2744. + manual_move_offset
  2745. #endif
  2746. ));
  2747. }
  2748. }
  2749. void lcd_move_e() { _lcd_move_e(); }
  2750. #if E_MANUAL > 1
  2751. void lcd_move_e0() { _lcd_move_e(0); }
  2752. void lcd_move_e1() { _lcd_move_e(1); }
  2753. #if E_MANUAL > 2
  2754. void lcd_move_e2() { _lcd_move_e(2); }
  2755. #if E_MANUAL > 3
  2756. void lcd_move_e3() { _lcd_move_e(3); }
  2757. #if E_MANUAL > 4
  2758. void lcd_move_e4() { _lcd_move_e(4); }
  2759. #endif // E_MANUAL > 4
  2760. #endif // E_MANUAL > 3
  2761. #endif // E_MANUAL > 2
  2762. #endif // E_MANUAL > 1
  2763. /**
  2764. *
  2765. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  2766. *
  2767. */
  2768. screenFunc_t _manual_move_func_ptr;
  2769. void _goto_manual_move(const float scale) {
  2770. defer_return_to_status = true;
  2771. move_menu_scale = scale;
  2772. lcd_goto_screen(_manual_move_func_ptr);
  2773. }
  2774. void lcd_move_menu_10mm() { _goto_manual_move(10); }
  2775. void lcd_move_menu_1mm() { _goto_manual_move( 1); }
  2776. void lcd_move_menu_01mm() { _goto_manual_move( 0.1f); }
  2777. void _lcd_move_distance_menu(const AxisEnum axis, const screenFunc_t func) {
  2778. _manual_move_func_ptr = func;
  2779. START_MENU();
  2780. if (LCD_HEIGHT >= 4) {
  2781. switch (axis) {
  2782. case X_AXIS:
  2783. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  2784. case Y_AXIS:
  2785. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  2786. case Z_AXIS:
  2787. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  2788. default:
  2789. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  2790. }
  2791. }
  2792. MENU_BACK(MSG_MOVE_AXIS);
  2793. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  2794. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  2795. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  2796. END_MENU();
  2797. }
  2798. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  2799. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  2800. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  2801. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  2802. #if E_MANUAL > 1
  2803. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  2804. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  2805. #if E_MANUAL > 2
  2806. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  2807. #if E_MANUAL > 3
  2808. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  2809. #if E_MANUAL > 4
  2810. void lcd_move_get_e4_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e4); }
  2811. #endif // E_MANUAL > 4
  2812. #endif // E_MANUAL > 3
  2813. #endif // E_MANUAL > 2
  2814. #endif // E_MANUAL > 1
  2815. /**
  2816. *
  2817. * "Prepare" > "Move Axis" submenu
  2818. *
  2819. */
  2820. #if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
  2821. #define _MOVE_XYZ_ALLOWED (all_axes_homed())
  2822. #else
  2823. #define _MOVE_XYZ_ALLOWED true
  2824. #endif
  2825. #if ENABLED(DELTA)
  2826. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  2827. void lcd_lower_z_to_clip_height() {
  2828. line_to_z(delta_clip_start_height);
  2829. lcd_synchronize();
  2830. }
  2831. #else
  2832. #define _MOVE_XY_ALLOWED true
  2833. #endif
  2834. void lcd_move_menu() {
  2835. START_MENU();
  2836. MENU_BACK(MSG_PREPARE);
  2837. #if HAS_SOFTWARE_ENDSTOPS && ENABLED(SOFT_ENDSTOPS_MENU_ITEM)
  2838. MENU_ITEM_EDIT(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled);
  2839. #endif
  2840. if (_MOVE_XYZ_ALLOWED) {
  2841. if (_MOVE_XY_ALLOWED) {
  2842. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  2843. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  2844. }
  2845. #if ENABLED(DELTA)
  2846. else
  2847. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  2848. #endif
  2849. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  2850. }
  2851. else
  2852. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2853. #if ENABLED(SWITCHING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE)
  2854. #if EXTRUDERS == 4
  2855. switch (active_extruder) {
  2856. case 0: MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1")); break;
  2857. case 1: MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0")); break;
  2858. case 2: MENU_ITEM(gcode, MSG_SELECT " " MSG_E4, PSTR("T3")); break;
  2859. case 3: MENU_ITEM(gcode, MSG_SELECT " " MSG_E3, PSTR("T2")); break;
  2860. }
  2861. #elif EXTRUDERS == 3
  2862. if (active_extruder < 2) {
  2863. if (active_extruder)
  2864. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  2865. else
  2866. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  2867. }
  2868. #else
  2869. if (active_extruder)
  2870. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  2871. else
  2872. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  2873. #endif
  2874. #elif ENABLED(DUAL_X_CARRIAGE)
  2875. if (active_extruder)
  2876. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  2877. else
  2878. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  2879. #endif
  2880. #if ENABLED(SWITCHING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE)
  2881. // Only the current...
  2882. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  2883. // ...and the non-switching
  2884. #if E_MANUAL == 5
  2885. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  2886. #elif E_MANUAL == 3
  2887. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  2888. #endif
  2889. #else
  2890. // Independent extruders with one E-stepper per hotend
  2891. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  2892. #if E_MANUAL > 1
  2893. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  2894. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  2895. #if E_MANUAL > 2
  2896. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  2897. #if E_MANUAL > 3
  2898. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  2899. #if E_MANUAL > 4
  2900. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  2901. #endif // E_MANUAL > 4
  2902. #endif // E_MANUAL > 3
  2903. #endif // E_MANUAL > 2
  2904. #endif // E_MANUAL > 1
  2905. #endif
  2906. END_MENU();
  2907. }
  2908. /**
  2909. *
  2910. * "Control" submenu
  2911. *
  2912. */
  2913. #if HAS_LCD_CONTRAST
  2914. void lcd_callback_set_contrast() { set_lcd_contrast(lcd_contrast); }
  2915. #endif
  2916. static void lcd_factory_settings() {
  2917. settings.reset();
  2918. lcd_completion_feedback();
  2919. }
  2920. #if ENABLED(EEPROM_SETTINGS) && DISABLED(SLIM_LCD_MENUS)
  2921. static void lcd_init_eeprom() {
  2922. lcd_completion_feedback(settings.init_eeprom());
  2923. lcd_goto_previous_menu();
  2924. }
  2925. static void lcd_init_eeprom_confirm() {
  2926. START_MENU();
  2927. MENU_BACK(MSG_CONTROL);
  2928. MENU_ITEM(function, MSG_INIT_EEPROM, lcd_init_eeprom);
  2929. END_MENU();
  2930. }
  2931. #endif
  2932. void lcd_control_menu() {
  2933. START_MENU();
  2934. MENU_BACK(MSG_MAIN);
  2935. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  2936. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  2937. #if DISABLED(NO_VOLUMETRICS) || ENABLED(ADVANCED_PAUSE_FEATURE)
  2938. MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
  2939. #elif ENABLED(LIN_ADVANCE)
  2940. MENU_ITEM_EDIT(float52, MSG_ADVANCE_K, &planner.extruder_advance_K, 0, 999);
  2941. #endif
  2942. #if HAS_LCD_CONTRAST
  2943. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
  2944. #endif
  2945. #if ENABLED(FWRETRACT)
  2946. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  2947. #endif
  2948. #if ENABLED(DAC_STEPPER_CURRENT)
  2949. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  2950. #endif
  2951. #if HAS_MOTOR_CURRENT_PWM
  2952. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_pwm_menu);
  2953. #endif
  2954. #if ENABLED(BLTOUCH)
  2955. MENU_ITEM(submenu, MSG_BLTOUCH, bltouch_menu);
  2956. #endif
  2957. #if ENABLED(EEPROM_SETTINGS)
  2958. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2959. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2960. #endif
  2961. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, lcd_factory_settings);
  2962. #if ENABLED(EEPROM_SETTINGS) && DISABLED(SLIM_LCD_MENUS)
  2963. MENU_ITEM(submenu, MSG_INIT_EEPROM, lcd_init_eeprom_confirm);
  2964. #endif
  2965. END_MENU();
  2966. }
  2967. /**
  2968. *
  2969. * "Temperature" submenu
  2970. *
  2971. */
  2972. #if ENABLED(PID_AUTOTUNE_MENU)
  2973. #if ENABLED(PIDTEMP)
  2974. int16_t autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  2975. #endif
  2976. #if ENABLED(PIDTEMPBED)
  2977. int16_t autotune_temp_bed = 70;
  2978. #endif
  2979. void _lcd_autotune(int16_t e) {
  2980. char cmd[30];
  2981. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  2982. #if HAS_PID_FOR_BOTH
  2983. e < 0 ? autotune_temp_bed : autotune_temp[e]
  2984. #elif ENABLED(PIDTEMPBED)
  2985. autotune_temp_bed
  2986. #else
  2987. autotune_temp[e]
  2988. #endif
  2989. );
  2990. lcd_enqueue_command(cmd);
  2991. }
  2992. #endif // PID_AUTOTUNE_MENU
  2993. #if ENABLED(PIDTEMP)
  2994. // Helpers for editing PID Ki & Kd values
  2995. // grab the PID value out of the temp variable; scale it; then update the PID driver
  2996. void copy_and_scalePID_i(int16_t e) {
  2997. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2998. UNUSED(e);
  2999. #endif
  3000. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  3001. thermalManager.update_pid();
  3002. }
  3003. void copy_and_scalePID_d(int16_t e) {
  3004. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  3005. UNUSED(e);
  3006. #endif
  3007. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  3008. thermalManager.update_pid();
  3009. }
  3010. #define _DEFINE_PIDTEMP_BASE_FUNCS(N) \
  3011. void copy_and_scalePID_i_E ## N() { copy_and_scalePID_i(N); } \
  3012. void copy_and_scalePID_d_E ## N() { copy_and_scalePID_d(N); }
  3013. #if ENABLED(PID_AUTOTUNE_MENU)
  3014. #define DEFINE_PIDTEMP_FUNCS(N) \
  3015. _DEFINE_PIDTEMP_BASE_FUNCS(N); \
  3016. void lcd_autotune_callback_E ## N() { _lcd_autotune(N); } typedef void _pid_##N##_void
  3017. #else
  3018. #define DEFINE_PIDTEMP_FUNCS(N) _DEFINE_PIDTEMP_BASE_FUNCS(N) typedef void _pid_##N##_void
  3019. #endif
  3020. DEFINE_PIDTEMP_FUNCS(0);
  3021. #if ENABLED(PID_PARAMS_PER_HOTEND)
  3022. #if HOTENDS > 1
  3023. DEFINE_PIDTEMP_FUNCS(1);
  3024. #if HOTENDS > 2
  3025. DEFINE_PIDTEMP_FUNCS(2);
  3026. #if HOTENDS > 3
  3027. DEFINE_PIDTEMP_FUNCS(3);
  3028. #if HOTENDS > 4
  3029. DEFINE_PIDTEMP_FUNCS(4);
  3030. #endif // HOTENDS > 4
  3031. #endif // HOTENDS > 3
  3032. #endif // HOTENDS > 2
  3033. #endif // HOTENDS > 1
  3034. #endif // PID_PARAMS_PER_HOTEND
  3035. #endif // PIDTEMP
  3036. /**
  3037. *
  3038. * "Control" > "Temperature" submenu
  3039. *
  3040. */
  3041. void lcd_control_temperature_menu() {
  3042. START_MENU();
  3043. //
  3044. // ^ Control
  3045. //
  3046. MENU_BACK(MSG_CONTROL);
  3047. //
  3048. // Nozzle:
  3049. // Nozzle [1-5]:
  3050. //
  3051. #if HOTENDS == 1
  3052. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  3053. #else // HOTENDS > 1
  3054. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  3055. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  3056. #if HOTENDS > 2
  3057. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  3058. #if HOTENDS > 3
  3059. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  3060. #if HOTENDS > 4
  3061. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  3062. #endif // HOTENDS > 4
  3063. #endif // HOTENDS > 3
  3064. #endif // HOTENDS > 2
  3065. #endif // HOTENDS > 1
  3066. //
  3067. // Bed:
  3068. //
  3069. #if HAS_HEATED_BED
  3070. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  3071. #endif
  3072. //
  3073. // Fan Speed:
  3074. //
  3075. #if FAN_COUNT > 0
  3076. #if HAS_FAN0
  3077. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED FAN_SPEED_1_SUFFIX, &fanSpeeds[0], 0, 255);
  3078. #if ENABLED(EXTRA_FAN_SPEED)
  3079. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_EXTRA_FAN_SPEED FAN_SPEED_1_SUFFIX, &new_fanSpeeds[0], 3, 255);
  3080. #endif
  3081. #endif
  3082. #if HAS_FAN1
  3083. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  3084. #if ENABLED(EXTRA_FAN_SPEED)
  3085. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_EXTRA_FAN_SPEED " 2", &new_fanSpeeds[1], 3, 255);
  3086. #endif
  3087. #endif
  3088. #if HAS_FAN2
  3089. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  3090. #if ENABLED(EXTRA_FAN_SPEED)
  3091. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_EXTRA_FAN_SPEED " 3", &new_fanSpeeds[2], 3, 255);
  3092. #endif
  3093. #endif
  3094. #endif // FAN_COUNT > 0
  3095. //
  3096. // Autotemp, Min, Max, Fact
  3097. //
  3098. #if ENABLED(AUTOTEMP) && HAS_TEMP_HOTEND
  3099. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  3100. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, float(HEATER_0_MAXTEMP) - 15);
  3101. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, float(HEATER_0_MAXTEMP) - 15);
  3102. MENU_ITEM_EDIT(float52, MSG_FACTOR, &planner.autotemp_factor, 0, 10);
  3103. #endif
  3104. //
  3105. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  3106. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  3107. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  3108. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  3109. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  3110. // PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
  3111. //
  3112. #if ENABLED(PIDTEMP)
  3113. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  3114. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  3115. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  3116. MENU_ITEM_EDIT(float52sign, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  3117. MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_PID_I ELABEL, &raw_Ki, 0.01f, 9990, copy_and_scalePID_i_E ## eindex); \
  3118. MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  3119. #if ENABLED(PID_EXTRUSION_SCALING)
  3120. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  3121. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  3122. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  3123. #else
  3124. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  3125. #endif
  3126. #if ENABLED(PID_AUTOTUNE_MENU)
  3127. #define PID_MENU_ITEMS(ELABEL, eindex) \
  3128. _PID_MENU_ITEMS(ELABEL, eindex); \
  3129. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  3130. #else
  3131. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  3132. #endif
  3133. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  3134. PID_MENU_ITEMS(" " MSG_E1, 0);
  3135. PID_MENU_ITEMS(" " MSG_E2, 1);
  3136. #if HOTENDS > 2
  3137. PID_MENU_ITEMS(" " MSG_E3, 2);
  3138. #if HOTENDS > 3
  3139. PID_MENU_ITEMS(" " MSG_E4, 3);
  3140. #if HOTENDS > 4
  3141. PID_MENU_ITEMS(" " MSG_E5, 4);
  3142. #endif // HOTENDS > 4
  3143. #endif // HOTENDS > 3
  3144. #endif // HOTENDS > 2
  3145. #else // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  3146. PID_MENU_ITEMS("", 0);
  3147. #endif // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  3148. #endif // PIDTEMP
  3149. #if DISABLED(SLIM_LCD_MENUS)
  3150. //
  3151. // Preheat Material 1 conf
  3152. //
  3153. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  3154. //
  3155. // Preheat Material 2 conf
  3156. //
  3157. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  3158. #endif
  3159. END_MENU();
  3160. }
  3161. #if DISABLED(SLIM_LCD_MENUS)
  3162. void _lcd_control_temperature_preheat_settings_menu(const uint8_t material) {
  3163. #if HOTENDS > 4
  3164. #define MINTEMP_ALL MIN5(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP)
  3165. #define MAXTEMP_ALL MAX5(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP)
  3166. #elif HOTENDS > 3
  3167. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  3168. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  3169. #elif HOTENDS > 2
  3170. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  3171. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  3172. #elif HOTENDS > 1
  3173. #define MINTEMP_ALL MIN(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  3174. #define MAXTEMP_ALL MAX(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  3175. #else
  3176. #define MINTEMP_ALL HEATER_0_MINTEMP
  3177. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  3178. #endif
  3179. START_MENU();
  3180. MENU_BACK(MSG_TEMPERATURE);
  3181. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  3182. #if HAS_TEMP_HOTEND
  3183. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  3184. #endif
  3185. #if HAS_HEATED_BED
  3186. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  3187. #endif
  3188. #if ENABLED(EEPROM_SETTINGS)
  3189. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  3190. #endif
  3191. END_MENU();
  3192. }
  3193. /**
  3194. *
  3195. * "Temperature" > "Preheat Material 1 conf" submenu
  3196. *
  3197. */
  3198. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  3199. /**
  3200. *
  3201. * "Temperature" > "Preheat Material 2 conf" submenu
  3202. *
  3203. */
  3204. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  3205. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  3206. #if ENABLED(DISTINCT_E_FACTORS)
  3207. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  3208. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  3209. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  3210. #if E_STEPPERS > 2
  3211. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  3212. #if E_STEPPERS > 3
  3213. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  3214. #if E_STEPPERS > 4
  3215. void _reset_e4_acceleration_rate() { _reset_e_acceleration_rate(4); }
  3216. #endif // E_STEPPERS > 4
  3217. #endif // E_STEPPERS > 3
  3218. #endif // E_STEPPERS > 2
  3219. #endif
  3220. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  3221. #if ENABLED(DISTINCT_E_FACTORS)
  3222. void _planner_refresh_e_positioning(const uint8_t e) {
  3223. if (e == active_extruder)
  3224. _planner_refresh_positioning();
  3225. else
  3226. planner.steps_to_mm[E_AXIS + e] = 1.0f / planner.axis_steps_per_mm[E_AXIS + e];
  3227. }
  3228. void _planner_refresh_e0_positioning() { _planner_refresh_e_positioning(0); }
  3229. void _planner_refresh_e1_positioning() { _planner_refresh_e_positioning(1); }
  3230. #if E_STEPPERS > 2
  3231. void _planner_refresh_e2_positioning() { _planner_refresh_e_positioning(2); }
  3232. #if E_STEPPERS > 3
  3233. void _planner_refresh_e3_positioning() { _planner_refresh_e_positioning(3); }
  3234. #if E_STEPPERS > 4
  3235. void _planner_refresh_e4_positioning() { _planner_refresh_e_positioning(4); }
  3236. #endif // E_STEPPERS > 4
  3237. #endif // E_STEPPERS > 3
  3238. #endif // E_STEPPERS > 2
  3239. #endif
  3240. // M203 / M205 Velocity options
  3241. void lcd_control_motion_velocity_menu() {
  3242. START_MENU();
  3243. MENU_BACK(MSG_MOTION);
  3244. // M203 Max Feedrate
  3245. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_A, &planner.max_feedrate_mm_s[A_AXIS], 1, 999);
  3246. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_B, &planner.max_feedrate_mm_s[B_AXIS], 1, 999);
  3247. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_C, &planner.max_feedrate_mm_s[C_AXIS], 1, 999);
  3248. #if ENABLED(DISTINCT_E_FACTORS)
  3249. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  3250. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  3251. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  3252. #if E_STEPPERS > 2
  3253. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  3254. #if E_STEPPERS > 3
  3255. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  3256. #if E_STEPPERS > 4
  3257. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
  3258. #endif // E_STEPPERS > 4
  3259. #endif // E_STEPPERS > 3
  3260. #endif // E_STEPPERS > 2
  3261. #else
  3262. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  3263. #endif
  3264. // M205 S Min Feedrate
  3265. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  3266. // M205 T Min Travel Feedrate
  3267. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  3268. END_MENU();
  3269. }
  3270. // M201 / M204 Accelerations
  3271. void lcd_control_motion_acceleration_menu() {
  3272. START_MENU();
  3273. MENU_BACK(MSG_MOTION);
  3274. // M204 P Acceleration
  3275. MENU_MULTIPLIER_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  3276. // M204 R Retract Acceleration
  3277. MENU_MULTIPLIER_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  3278. // M204 T Travel Acceleration
  3279. MENU_MULTIPLIER_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  3280. // M201 settings
  3281. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_A, &planner.max_acceleration_mm_per_s2[A_AXIS], 100, 99000, _reset_acceleration_rates);
  3282. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_B, &planner.max_acceleration_mm_per_s2[B_AXIS], 100, 99000, _reset_acceleration_rates);
  3283. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_C, &planner.max_acceleration_mm_per_s2[C_AXIS], 10, 99000, _reset_acceleration_rates);
  3284. #if ENABLED(DISTINCT_E_FACTORS)
  3285. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  3286. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  3287. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  3288. #if E_STEPPERS > 2
  3289. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  3290. #if E_STEPPERS > 3
  3291. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  3292. #if E_STEPPERS > 4
  3293. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
  3294. #endif // E_STEPPERS > 4
  3295. #endif // E_STEPPERS > 3
  3296. #endif // E_STEPPERS > 2
  3297. #else
  3298. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  3299. #endif
  3300. END_MENU();
  3301. }
  3302. // M205 Jerk
  3303. void lcd_control_motion_jerk_menu() {
  3304. START_MENU();
  3305. MENU_BACK(MSG_MOTION);
  3306. #if ENABLED(JUNCTION_DEVIATION)
  3307. MENU_ITEM_EDIT_CALLBACK(float43, MSG_JUNCTION_DEVIATION, &planner.junction_deviation_mm, 0.01f, 0.3f, planner.recalculate_max_e_jerk);
  3308. #else
  3309. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VA_JERK, &planner.max_jerk[A_AXIS], 1, 990);
  3310. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VB_JERK, &planner.max_jerk[B_AXIS], 1, 990);
  3311. #if ENABLED(DELTA)
  3312. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VC_JERK, &planner.max_jerk[C_AXIS], 1, 990);
  3313. #else
  3314. MENU_MULTIPLIER_ITEM_EDIT(float52sign, MSG_VC_JERK, &planner.max_jerk[C_AXIS], 0.1f, 990);
  3315. #endif
  3316. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  3317. #endif
  3318. END_MENU();
  3319. }
  3320. // M92 Steps-per-mm
  3321. void lcd_control_motion_steps_per_mm_menu() {
  3322. START_MENU();
  3323. MENU_BACK(MSG_MOTION);
  3324. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ASTEPS, &planner.axis_steps_per_mm[A_AXIS], 5, 9999, _planner_refresh_positioning);
  3325. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_BSTEPS, &planner.axis_steps_per_mm[B_AXIS], 5, 9999, _planner_refresh_positioning);
  3326. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_CSTEPS, &planner.axis_steps_per_mm[C_AXIS], 5, 9999, _planner_refresh_positioning);
  3327. #if ENABLED(DISTINCT_E_FACTORS)
  3328. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  3329. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  3330. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  3331. #if E_STEPPERS > 2
  3332. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  3333. #if E_STEPPERS > 3
  3334. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  3335. #if E_STEPPERS > 4
  3336. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E5STEPS, &planner.axis_steps_per_mm[E_AXIS + 4], 5, 9999, _planner_refresh_e4_positioning);
  3337. #endif // E_STEPPERS > 4
  3338. #endif // E_STEPPERS > 3
  3339. #endif // E_STEPPERS > 2
  3340. #else
  3341. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  3342. #endif
  3343. END_MENU();
  3344. }
  3345. #endif // !SLIM_LCD_MENUS
  3346. /**
  3347. *
  3348. * "Control" > "Motion" submenu
  3349. *
  3350. */
  3351. void lcd_control_motion_menu() {
  3352. START_MENU();
  3353. MENU_BACK(MSG_CONTROL);
  3354. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  3355. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  3356. #elif HAS_BED_PROBE
  3357. MENU_ITEM_EDIT(float52, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  3358. #endif
  3359. #if DISABLED(SLIM_LCD_MENUS)
  3360. // M203 / M205 - Feedrate items
  3361. MENU_ITEM(submenu, MSG_VELOCITY, lcd_control_motion_velocity_menu);
  3362. // M201 - Acceleration items
  3363. MENU_ITEM(submenu, MSG_ACCELERATION, lcd_control_motion_acceleration_menu);
  3364. // M205 - Max Jerk
  3365. MENU_ITEM(submenu, MSG_JERK, lcd_control_motion_jerk_menu);
  3366. // M92 - Steps Per mm
  3367. MENU_ITEM(submenu, MSG_STEPS_PER_MM, lcd_control_motion_steps_per_mm_menu);
  3368. #endif // !SLIM_LCD_MENUS
  3369. // M540 S - Abort on endstop hit when SD printing
  3370. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  3371. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &planner.abort_on_endstop_hit);
  3372. #endif
  3373. END_MENU();
  3374. }
  3375. #if DISABLED(NO_VOLUMETRICS) || ENABLED(ADVANCED_PAUSE_FEATURE)
  3376. /**
  3377. *
  3378. * "Control" > "Filament" submenu
  3379. *
  3380. */
  3381. void lcd_control_filament_menu() {
  3382. START_MENU();
  3383. MENU_BACK(MSG_CONTROL);
  3384. #if ENABLED(LIN_ADVANCE)
  3385. MENU_ITEM_EDIT(float52, MSG_ADVANCE_K, &planner.extruder_advance_K, 0, 999);
  3386. #endif
  3387. #if DISABLED(NO_VOLUMETRICS)
  3388. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &parser.volumetric_enabled, planner.calculate_volumetric_multipliers);
  3389. if (parser.volumetric_enabled) {
  3390. #if EXTRUDERS == 1
  3391. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &planner.filament_size[0], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
  3392. #else // EXTRUDERS > 1
  3393. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
  3394. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &planner.filament_size[0], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
  3395. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &planner.filament_size[1], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
  3396. #if EXTRUDERS > 2
  3397. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &planner.filament_size[2], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
  3398. #if EXTRUDERS > 3
  3399. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &planner.filament_size[3], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
  3400. #if EXTRUDERS > 4
  3401. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &planner.filament_size[4], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
  3402. #endif // EXTRUDERS > 4
  3403. #endif // EXTRUDERS > 3
  3404. #endif // EXTRUDERS > 2
  3405. #endif // EXTRUDERS > 1
  3406. }
  3407. #endif
  3408. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  3409. const float extrude_maxlength =
  3410. #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
  3411. EXTRUDE_MAXLENGTH
  3412. #else
  3413. 999
  3414. #endif
  3415. ;
  3416. #if EXTRUDERS == 1
  3417. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD, &filament_change_unload_length[0], 0, extrude_maxlength);
  3418. #else // EXTRUDERS > 1
  3419. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD, &filament_change_unload_length[active_extruder], 0, extrude_maxlength);
  3420. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E1, &filament_change_unload_length[0], 0, extrude_maxlength);
  3421. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E2, &filament_change_unload_length[1], 0, extrude_maxlength);
  3422. #if EXTRUDERS > 2
  3423. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E3, &filament_change_unload_length[2], 0, extrude_maxlength);
  3424. #if EXTRUDERS > 3
  3425. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E4, &filament_change_unload_length[3], 0, extrude_maxlength);
  3426. #if EXTRUDERS > 4
  3427. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E5, &filament_change_unload_length[4], 0, extrude_maxlength);
  3428. #endif // EXTRUDERS > 4
  3429. #endif // EXTRUDERS > 3
  3430. #endif // EXTRUDERS > 2
  3431. #endif // EXTRUDERS > 1
  3432. #if EXTRUDERS == 1
  3433. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD, &filament_change_load_length[0], 0, extrude_maxlength);
  3434. #else // EXTRUDERS > 1
  3435. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD, &filament_change_load_length[active_extruder], 0, extrude_maxlength);
  3436. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E1, &filament_change_load_length[0], 0, extrude_maxlength);
  3437. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E2, &filament_change_load_length[1], 0, extrude_maxlength);
  3438. #if EXTRUDERS > 2
  3439. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E3, &filament_change_load_length[2], 0, extrude_maxlength);
  3440. #if EXTRUDERS > 3
  3441. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E4, &filament_change_load_length[3], 0, extrude_maxlength);
  3442. #if EXTRUDERS > 4
  3443. MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E5, &filament_change_load_length[4], 0, extrude_maxlength);
  3444. #endif // EXTRUDERS > 4
  3445. #endif // EXTRUDERS > 3
  3446. #endif // EXTRUDERS > 2
  3447. #endif // EXTRUDERS > 1
  3448. #endif
  3449. END_MENU();
  3450. }
  3451. #endif // !NO_VOLUMETRICS || ADVANCED_PAUSE_FEATURE
  3452. /**
  3453. *
  3454. * "Control" > "Retract" submenu
  3455. *
  3456. */
  3457. #if ENABLED(FWRETRACT)
  3458. void lcd_control_retract_menu() {
  3459. START_MENU();
  3460. MENU_BACK(MSG_CONTROL);
  3461. MENU_ITEM_EDIT_CALLBACK(bool, MSG_AUTORETRACT, &fwretract.autoretract_enabled, fwretract.refresh_autoretract);
  3462. MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT, &fwretract.retract_length, 0, 100);
  3463. #if EXTRUDERS > 1
  3464. MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT_SWAP, &fwretract.swap_retract_length, 0, 100);
  3465. #endif
  3466. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &fwretract.retract_feedrate_mm_s, 1, 999);
  3467. MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT_ZLIFT, &fwretract.retract_zlift, 0, 999);
  3468. MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT_RECOVER, &fwretract.retract_recover_length, -100, 100);
  3469. #if EXTRUDERS > 1
  3470. MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT_RECOVER_SWAP, &fwretract.swap_retract_recover_length, -100, 100);
  3471. #endif
  3472. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &fwretract.retract_recover_feedrate_mm_s, 1, 999);
  3473. #if EXTRUDERS > 1
  3474. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVER_SWAPF, &fwretract.swap_retract_recover_feedrate_mm_s, 1, 999);
  3475. #endif
  3476. END_MENU();
  3477. }
  3478. #endif // FWRETRACT
  3479. #if ENABLED(SDSUPPORT)
  3480. #if !PIN_EXISTS(SD_DETECT)
  3481. void lcd_sd_refresh() {
  3482. card.initsd();
  3483. encoderTopLine = 0;
  3484. }
  3485. #endif
  3486. void lcd_sd_updir() {
  3487. encoderPosition = card.updir() ? ENCODER_STEPS_PER_MENU_ITEM : 0;
  3488. encoderTopLine = 0;
  3489. screen_changed = true;
  3490. lcd_refresh();
  3491. }
  3492. /**
  3493. *
  3494. * "Print from SD" submenu
  3495. *
  3496. */
  3497. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  3498. uint32_t last_sdfile_encoderPosition = 0xFFFF;
  3499. void lcd_reselect_last_file() {
  3500. if (last_sdfile_encoderPosition == 0xFFFF) return;
  3501. #if ENABLED(DOGLCD)
  3502. // Some of this is a hack to force the screen update to work.
  3503. // TODO: Fix the real issue that causes this!
  3504. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  3505. _lcd_synchronize();
  3506. safe_delay(50);
  3507. _lcd_synchronize();
  3508. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  3509. drawing_screen = screen_changed = true;
  3510. #endif
  3511. lcd_goto_screen(lcd_sdcard_menu, last_sdfile_encoderPosition);
  3512. defer_return_to_status = true;
  3513. last_sdfile_encoderPosition = 0xFFFF;
  3514. #if ENABLED(DOGLCD)
  3515. lcd_update();
  3516. #endif
  3517. }
  3518. #endif
  3519. void lcd_sdcard_menu() {
  3520. ENCODER_DIRECTION_MENUS();
  3521. const uint16_t fileCnt = card.get_num_Files();
  3522. START_MENU();
  3523. MENU_BACK(MSG_MAIN);
  3524. card.getWorkDirName();
  3525. if (card.filename[0] == '/') {
  3526. #if !PIN_EXISTS(SD_DETECT)
  3527. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  3528. #endif
  3529. }
  3530. else {
  3531. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  3532. }
  3533. for (uint16_t i = 0; i < fileCnt; i++) {
  3534. if (_menuLineNr == _thisItemNr) {
  3535. const uint16_t nr =
  3536. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  3537. fileCnt - 1 -
  3538. #endif
  3539. i;
  3540. #if ENABLED(SDCARD_SORT_ALPHA)
  3541. card.getfilename_sorted(nr);
  3542. #else
  3543. card.getfilename(nr);
  3544. #endif
  3545. if (card.filenameIsDir)
  3546. MENU_ITEM(sddirectory, MSG_CARD_MENU, card);
  3547. else
  3548. MENU_ITEM(sdfile, MSG_CARD_MENU, card);
  3549. }
  3550. else {
  3551. MENU_ITEM_DUMMY();
  3552. }
  3553. }
  3554. END_MENU();
  3555. }
  3556. #endif // SDSUPPORT
  3557. #if ENABLED(LCD_INFO_MENU)
  3558. #if ENABLED(PRINTCOUNTER)
  3559. /**
  3560. *
  3561. * About Printer > Statistics submenu
  3562. *
  3563. */
  3564. void lcd_info_stats_menu() {
  3565. if (use_click()) { return lcd_goto_previous_menu(); }
  3566. char buffer[21];
  3567. printStatistics stats = print_job_timer.getStats();
  3568. START_SCREEN(); // 12345678901234567890
  3569. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  3570. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  3571. duration_t elapsed = stats.printTime;
  3572. elapsed.toString(buffer);
  3573. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  3574. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3575. elapsed = stats.longestPrint;
  3576. elapsed.toString(buffer);
  3577. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  3578. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3579. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10);
  3580. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  3581. STATIC_ITEM("", false, false, buffer); // 125m
  3582. END_SCREEN();
  3583. }
  3584. #endif // PRINTCOUNTER
  3585. /**
  3586. *
  3587. * About Printer > Thermistors
  3588. *
  3589. */
  3590. void lcd_info_thermistors_menu() {
  3591. if (use_click()) { return lcd_goto_previous_menu(); }
  3592. START_SCREEN();
  3593. #define THERMISTOR_ID TEMP_SENSOR_0
  3594. #include "thermistornames.h"
  3595. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  3596. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  3597. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  3598. #if TEMP_SENSOR_1 != 0
  3599. #undef THERMISTOR_ID
  3600. #define THERMISTOR_ID TEMP_SENSOR_1
  3601. #include "thermistornames.h"
  3602. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  3603. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  3604. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  3605. #endif
  3606. #if TEMP_SENSOR_2 != 0
  3607. #undef THERMISTOR_ID
  3608. #define THERMISTOR_ID TEMP_SENSOR_2
  3609. #include "thermistornames.h"
  3610. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  3611. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  3612. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  3613. #endif
  3614. #if TEMP_SENSOR_3 != 0
  3615. #undef THERMISTOR_ID
  3616. #define THERMISTOR_ID TEMP_SENSOR_3
  3617. #include "thermistornames.h"
  3618. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  3619. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  3620. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  3621. #endif
  3622. #if TEMP_SENSOR_4 != 0
  3623. #undef THERMISTOR_ID
  3624. #define THERMISTOR_ID TEMP_SENSOR_4
  3625. #include "thermistornames.h"
  3626. STATIC_ITEM("T4: " THERMISTOR_NAME, false, true);
  3627. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_4_MINTEMP), false);
  3628. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_4_MAXTEMP), false);
  3629. #endif
  3630. #if HAS_HEATED_BED
  3631. #undef THERMISTOR_ID
  3632. #define THERMISTOR_ID TEMP_SENSOR_BED
  3633. #include "thermistornames.h"
  3634. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  3635. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  3636. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  3637. #endif
  3638. END_SCREEN();
  3639. }
  3640. /**
  3641. *
  3642. * About Printer > Board Info
  3643. *
  3644. */
  3645. void lcd_info_board_menu() {
  3646. if (use_click()) { return lcd_goto_previous_menu(); }
  3647. START_SCREEN();
  3648. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  3649. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  3650. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  3651. #if POWER_SUPPLY == 0
  3652. STATIC_ITEM(MSG_INFO_PSU ": Generic", true);
  3653. #elif POWER_SUPPLY == 1
  3654. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  3655. #elif POWER_SUPPLY == 2
  3656. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  3657. #endif
  3658. END_SCREEN();
  3659. }
  3660. /**
  3661. *
  3662. * About Printer > Printer Info
  3663. *
  3664. */
  3665. void lcd_info_printer_menu() {
  3666. if (use_click()) { return lcd_goto_previous_menu(); }
  3667. START_SCREEN();
  3668. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  3669. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  3670. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  3671. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  3672. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  3673. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  3674. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  3675. STATIC_ITEM(MSG_3POINT_LEVELING, true); // 3-Point Leveling
  3676. #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
  3677. STATIC_ITEM(MSG_LINEAR_LEVELING, true); // Linear Leveling
  3678. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  3679. STATIC_ITEM(MSG_BILINEAR_LEVELING, true); // Bi-linear Leveling
  3680. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  3681. STATIC_ITEM(MSG_UBL_LEVELING, true); // Unified Bed Leveling
  3682. #elif ENABLED(MESH_BED_LEVELING)
  3683. STATIC_ITEM(MSG_MESH_LEVELING, true); // Mesh Leveling
  3684. #endif
  3685. END_SCREEN();
  3686. }
  3687. /**
  3688. *
  3689. * "About Printer" submenu
  3690. *
  3691. */
  3692. void lcd_info_menu() {
  3693. START_MENU();
  3694. MENU_BACK(MSG_MAIN);
  3695. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  3696. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  3697. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  3698. #if ENABLED(PRINTCOUNTER)
  3699. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  3700. #endif
  3701. END_MENU();
  3702. }
  3703. #endif // LCD_INFO_MENU
  3704. /**
  3705. *
  3706. * LED Menu
  3707. *
  3708. */
  3709. #if ENABLED(LED_CONTROL_MENU)
  3710. #if ENABLED(LED_COLOR_PRESETS)
  3711. void lcd_led_presets_menu() {
  3712. START_MENU();
  3713. #if LCD_HEIGHT > 2
  3714. STATIC_ITEM(MSG_LED_PRESETS, true, true);
  3715. #endif
  3716. MENU_BACK(MSG_LED_CONTROL);
  3717. MENU_ITEM(function, MSG_SET_LEDS_WHITE, leds.set_white);
  3718. MENU_ITEM(function, MSG_SET_LEDS_RED, leds.set_red);
  3719. MENU_ITEM(function, MSG_SET_LEDS_ORANGE, leds.set_orange);
  3720. MENU_ITEM(function, MSG_SET_LEDS_YELLOW,leds.set_yellow);
  3721. MENU_ITEM(function, MSG_SET_LEDS_GREEN, leds.set_green);
  3722. MENU_ITEM(function, MSG_SET_LEDS_BLUE, leds.set_blue);
  3723. MENU_ITEM(function, MSG_SET_LEDS_INDIGO, leds.set_indigo);
  3724. MENU_ITEM(function, MSG_SET_LEDS_VIOLET, leds.set_violet);
  3725. END_MENU();
  3726. }
  3727. #endif // LED_COLOR_PRESETS
  3728. void lcd_led_custom_menu() {
  3729. START_MENU();
  3730. MENU_BACK(MSG_LED_CONTROL);
  3731. MENU_ITEM_EDIT_CALLBACK(int8, MSG_INTENSITY_R, &leds.color.r, 0, 255, leds.update, true);
  3732. MENU_ITEM_EDIT_CALLBACK(int8, MSG_INTENSITY_G, &leds.color.g, 0, 255, leds.update, true);
  3733. MENU_ITEM_EDIT_CALLBACK(int8, MSG_INTENSITY_B, &leds.color.b, 0, 255, leds.update, true);
  3734. #if ENABLED(RGBW_LED) || ENABLED(NEOPIXEL_LED)
  3735. MENU_ITEM_EDIT_CALLBACK(int8, MSG_INTENSITY_W, &leds.color.w, 0, 255, leds.update, true);
  3736. #if ENABLED(NEOPIXEL_LED)
  3737. MENU_ITEM_EDIT_CALLBACK(int8, MSG_LED_BRIGHTNESS, &leds.color.i, 0, 255, leds.update, true);
  3738. #endif
  3739. #endif
  3740. END_MENU();
  3741. }
  3742. void lcd_led_menu() {
  3743. START_MENU();
  3744. MENU_BACK(MSG_MAIN);
  3745. bool led_on = leds.lights_on;
  3746. MENU_ITEM_EDIT_CALLBACK(bool, MSG_LEDS, &led_on, leds.toggle);
  3747. MENU_ITEM(function, MSG_SET_LEDS_DEFAULT, leds.set_default);
  3748. #if ENABLED(LED_COLOR_PRESETS)
  3749. MENU_ITEM(submenu, MSG_LED_PRESETS, lcd_led_presets_menu);
  3750. #endif
  3751. MENU_ITEM(submenu, MSG_CUSTOM_LEDS, lcd_led_custom_menu);
  3752. END_MENU();
  3753. }
  3754. #endif // LED_CONTROL_MENU
  3755. /**
  3756. *
  3757. * Filament Change Feature Screens
  3758. *
  3759. */
  3760. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  3761. /**
  3762. *
  3763. * "Change Filament" > "Change/Unload/Load Filament" submenu
  3764. *
  3765. */
  3766. static AdvancedPauseMode _change_filament_temp_mode;
  3767. static int8_t _change_filament_temp_extruder;
  3768. static const char* _change_filament_temp_command() {
  3769. switch (_change_filament_temp_mode) {
  3770. case ADVANCED_PAUSE_MODE_LOAD_FILAMENT:
  3771. return PSTR("M701 T%d");
  3772. case ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT:
  3773. return _change_filament_temp_extruder >= 0 ? PSTR("M702 T%d") : PSTR("M702 ;%d");
  3774. case ADVANCED_PAUSE_MODE_PAUSE_PRINT:
  3775. default:
  3776. return PSTR("M600 B0 T%d");
  3777. }
  3778. return PSTR(MSG_FILAMENTCHANGE);
  3779. }
  3780. void _change_filament_temp(const uint8_t index) {
  3781. char cmd[11];
  3782. sprintf_P(cmd, _change_filament_temp_command(), _change_filament_temp_extruder);
  3783. thermalManager.setTargetHotend(index == 1 ? PREHEAT_1_TEMP_HOTEND : PREHEAT_2_TEMP_HOTEND, _change_filament_temp_extruder);
  3784. lcd_enqueue_command(cmd);
  3785. }
  3786. void _lcd_change_filament_temp_1_menu() { _change_filament_temp(1); }
  3787. void _lcd_change_filament_temp_2_menu() { _change_filament_temp(2); }
  3788. static const char* change_filament_header(const AdvancedPauseMode mode) {
  3789. switch (mode) {
  3790. case ADVANCED_PAUSE_MODE_LOAD_FILAMENT:
  3791. return PSTR(MSG_FILAMENTLOAD);
  3792. case ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT:
  3793. return PSTR(MSG_FILAMENTUNLOAD);
  3794. default: break;
  3795. }
  3796. return PSTR(MSG_FILAMENTCHANGE);
  3797. }
  3798. void _lcd_temp_menu_filament_op(const AdvancedPauseMode mode, const int8_t extruder) {
  3799. _change_filament_temp_mode = mode;
  3800. _change_filament_temp_extruder = extruder;
  3801. START_MENU();
  3802. if (LCD_HEIGHT >= 4) STATIC_ITEM_P(change_filament_header(mode), true, true);
  3803. MENU_BACK(MSG_FILAMENTCHANGE);
  3804. MENU_ITEM(submenu, MSG_PREHEAT_1, _lcd_change_filament_temp_1_menu);
  3805. MENU_ITEM(submenu, MSG_PREHEAT_2, _lcd_change_filament_temp_2_menu);
  3806. END_MENU();
  3807. }
  3808. void lcd_temp_menu_e0_filament_change() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_PAUSE_PRINT, 0); }
  3809. void lcd_temp_menu_e0_filament_load() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_LOAD_FILAMENT, 0); }
  3810. void lcd_temp_menu_e0_filament_unload() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT, 0); }
  3811. #if E_STEPPERS > 1
  3812. void lcd_temp_menu_e1_filament_change() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_PAUSE_PRINT, 1); }
  3813. void lcd_temp_menu_e1_filament_load() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_LOAD_FILAMENT, 1); }
  3814. void lcd_temp_menu_e1_filament_unload() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT, 1); }
  3815. #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  3816. void lcd_unload_filament_all_temp_menu() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT, -1); }
  3817. #endif
  3818. #if E_STEPPERS > 2
  3819. void lcd_temp_menu_e2_filament_change() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_PAUSE_PRINT, 2); }
  3820. void lcd_temp_menu_e2_filament_load() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_LOAD_FILAMENT, 2); }
  3821. void lcd_temp_menu_e2_filament_unload() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT, 2); }
  3822. #if E_STEPPERS > 3
  3823. void lcd_temp_menu_e3_filament_change() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_PAUSE_PRINT, 3); }
  3824. void lcd_temp_menu_e3_filament_load() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_LOAD_FILAMENT, 3); }
  3825. void lcd_temp_menu_e3_filament_unload() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT, 3); }
  3826. #if E_STEPPERS > 4
  3827. void lcd_temp_menu_e4_filament_change() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_PAUSE_PRINT, 4); }
  3828. void lcd_temp_menu_e4_filament_load() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_LOAD_FILAMENT, 4); }
  3829. void lcd_temp_menu_e4_filament_unload() { _lcd_temp_menu_filament_op(ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT, 4); }
  3830. #endif // E_STEPPERS > 4
  3831. #endif // E_STEPPERS > 3
  3832. #endif // E_STEPPERS > 2
  3833. #endif // E_STEPPERS > 1
  3834. /**
  3835. *
  3836. * "Change Filament" submenu
  3837. *
  3838. */
  3839. #if E_STEPPERS > 1 || ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  3840. void lcd_change_filament_menu() {
  3841. START_MENU();
  3842. MENU_BACK(MSG_PREPARE);
  3843. // Change filament
  3844. #if E_STEPPERS == 1
  3845. PGM_P msg0 = PSTR(MSG_FILAMENTCHANGE);
  3846. if (thermalManager.targetTooColdToExtrude(active_extruder))
  3847. MENU_ITEM_P(submenu, msg0, lcd_temp_menu_e0_filament_change);
  3848. else
  3849. MENU_ITEM_P(gcode, msg0, PSTR("M600 B0"));
  3850. #else
  3851. PGM_P msg0 = PSTR(MSG_FILAMENTCHANGE " " MSG_E1);
  3852. PGM_P msg1 = PSTR(MSG_FILAMENTCHANGE " " MSG_E2);
  3853. if (thermalManager.targetTooColdToExtrude(0))
  3854. MENU_ITEM_P(submenu, msg0, lcd_temp_menu_e0_filament_change);
  3855. else
  3856. MENU_ITEM_P(gcode, msg0, PSTR("M600 B0 T0"));
  3857. if (thermalManager.targetTooColdToExtrude(1))
  3858. MENU_ITEM_P(submenu, msg1, lcd_temp_menu_e1_filament_change);
  3859. else
  3860. MENU_ITEM_P(gcode, msg1, PSTR("M600 B0 T1"));
  3861. #if E_STEPPERS > 2
  3862. PGM_P msg2 = PSTR(MSG_FILAMENTCHANGE " " MSG_E3);
  3863. if (thermalManager.targetTooColdToExtrude(2))
  3864. MENU_ITEM_P(submenu, msg2, lcd_temp_menu_e2_filament_change);
  3865. else
  3866. MENU_ITEM_P(gcode, msg2, PSTR("M600 B0 T2"));
  3867. #if E_STEPPERS > 3
  3868. PGM_P msg3 = PSTR(MSG_FILAMENTCHANGE " " MSG_E4);
  3869. if (thermalManager.targetTooColdToExtrude(3))
  3870. MENU_ITEM_P(submenu, msg3, lcd_temp_menu_e3_filament_change);
  3871. else
  3872. MENU_ITEM_P(gcode, msg3, PSTR("M600 B0 T3"));
  3873. #if E_STEPPERS > 4
  3874. PGM_P msg4 = PSTR(MSG_FILAMENTCHANGE " " MSG_E5);
  3875. if (thermalManager.targetTooColdToExtrude(4))
  3876. MENU_ITEM_P(submenu, msg4, lcd_temp_menu_e4_filament_change);
  3877. else
  3878. MENU_ITEM_P(gcode, msg4, PSTR("M600 B0 T4"));
  3879. #endif // E_STEPPERS > 4
  3880. #endif // E_STEPPERS > 3
  3881. #endif // E_STEPPERS > 2
  3882. #endif // E_STEPPERS == 1
  3883. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  3884. if (!planner.movesplanned() && !IS_SD_FILE_OPEN()) {
  3885. // Load filament
  3886. #if E_STEPPERS == 1
  3887. PGM_P msg0 = PSTR(MSG_FILAMENTLOAD);
  3888. if (thermalManager.targetTooColdToExtrude(active_extruder))
  3889. MENU_ITEM_P(submenu, msg0, lcd_temp_menu_e0_filament_load);
  3890. else
  3891. MENU_ITEM_P(gcode, msg0, PSTR("M701"));
  3892. #else
  3893. PGM_P msg0 = PSTR(MSG_FILAMENTLOAD " " MSG_E1);
  3894. PGM_P msg1 = PSTR(MSG_FILAMENTLOAD " " MSG_E2);
  3895. if (thermalManager.targetTooColdToExtrude(0))
  3896. MENU_ITEM_P(submenu, msg0, lcd_temp_menu_e0_filament_load);
  3897. else
  3898. MENU_ITEM_P(gcode, msg0, PSTR("M701 T0"));
  3899. if (thermalManager.targetTooColdToExtrude(1))
  3900. MENU_ITEM_P(submenu, msg1, lcd_temp_menu_e1_filament_load);
  3901. else
  3902. MENU_ITEM_P(gcode, msg1, PSTR("M701 T1"));
  3903. #if E_STEPPERS > 2
  3904. PGM_P msg2 = PSTR(MSG_FILAMENTLOAD " " MSG_E3);
  3905. if (thermalManager.targetTooColdToExtrude(2))
  3906. MENU_ITEM_P(submenu, msg2, lcd_temp_menu_e2_filament_load);
  3907. else
  3908. MENU_ITEM_P(gcode, msg2, PSTR("M701 T2"));
  3909. #if E_STEPPERS > 3
  3910. PGM_P msg3 = PSTR(MSG_FILAMENTLOAD " " MSG_E4);
  3911. if (thermalManager.targetTooColdToExtrude(3))
  3912. MENU_ITEM_P(submenu, msg3, lcd_temp_menu_e3_filament_load);
  3913. else
  3914. MENU_ITEM_P(gcode, msg3, PSTR("M701 T3"));
  3915. #if E_STEPPERS > 4
  3916. PGM_P msg4 = PSTR(MSG_FILAMENTLOAD " " MSG_E5);
  3917. if (thermalManager.targetTooColdToExtrude(4))
  3918. MENU_ITEM_P(submenu, msg4, lcd_temp_menu_e4_filament_load);
  3919. else
  3920. MENU_ITEM_P(gcode, msg4, PSTR("M701 T4"));
  3921. #endif // E_STEPPERS > 4
  3922. #endif // E_STEPPERS > 3
  3923. #endif // E_STEPPERS > 2
  3924. #endif // E_STEPPERS == 1
  3925. // Unload filament
  3926. #if E_STEPPERS == 1
  3927. if (thermalManager.targetHotEnoughToExtrude(active_extruder))
  3928. MENU_ITEM(gcode, MSG_FILAMENTUNLOAD, PSTR("M702"));
  3929. else
  3930. MENU_ITEM(submenu, MSG_FILAMENTUNLOAD, lcd_temp_menu_e0_filament_unload);
  3931. #else
  3932. #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  3933. if (thermalManager.targetHotEnoughToExtrude(0)
  3934. #if E_STEPPERS > 1
  3935. && thermalManager.targetHotEnoughToExtrude(1)
  3936. #if E_STEPPERS > 2
  3937. && thermalManager.targetHotEnoughToExtrude(2)
  3938. #if E_STEPPERS > 3
  3939. && thermalManager.targetHotEnoughToExtrude(3)
  3940. #if E_STEPPERS > 4
  3941. && thermalManager.targetHotEnoughToExtrude(4)
  3942. #endif // E_STEPPERS > 4
  3943. #endif // E_STEPPERS > 3
  3944. #endif // E_STEPPERS > 2
  3945. #endif // E_STEPPERS > 1
  3946. )
  3947. MENU_ITEM(gcode, MSG_FILAMENTUNLOAD_ALL, PSTR("M702"));
  3948. else
  3949. MENU_ITEM(submenu, MSG_FILAMENTUNLOAD_ALL, lcd_unload_filament_all_temp_menu);
  3950. #endif
  3951. if (thermalManager.targetHotEnoughToExtrude(0))
  3952. MENU_ITEM(gcode, MSG_FILAMENTUNLOAD " " MSG_E1, PSTR("M702 T0"));
  3953. else
  3954. MENU_ITEM(submenu, MSG_FILAMENTUNLOAD " " MSG_E1, lcd_temp_menu_e0_filament_unload);
  3955. if (thermalManager.targetHotEnoughToExtrude(1))
  3956. MENU_ITEM(gcode, MSG_FILAMENTUNLOAD " " MSG_E2, PSTR("M702 T1"));
  3957. else
  3958. MENU_ITEM(submenu, MSG_FILAMENTUNLOAD " " MSG_E2, lcd_temp_menu_e1_filament_unload);
  3959. #if E_STEPPERS > 2
  3960. if (thermalManager.targetHotEnoughToExtrude(2))
  3961. MENU_ITEM(gcode, MSG_FILAMENTUNLOAD " " MSG_E3, PSTR("M702 T2"));
  3962. else
  3963. MENU_ITEM(submenu, MSG_FILAMENTUNLOAD " " MSG_E3, lcd_temp_menu_e2_filament_unload);
  3964. #if E_STEPPERS > 3
  3965. if (thermalManager.targetHotEnoughToExtrude(3))
  3966. MENU_ITEM(gcode, MSG_FILAMENTUNLOAD " " MSG_E4, PSTR("M702 T3"));
  3967. else
  3968. MENU_ITEM(submenu, MSG_FILAMENTUNLOAD " " MSG_E4, lcd_temp_menu_e3_filament_unload);
  3969. #if E_STEPPERS > 4
  3970. if (thermalManager.targetHotEnoughToExtrude(4))
  3971. MENU_ITEM(gcode, MSG_FILAMENTUNLOAD " " MSG_E5, PSTR("M702 T4"));
  3972. else
  3973. MENU_ITEM(submenu, MSG_FILAMENTUNLOAD " " MSG_E5, lcd_temp_menu_e4_filament_unload);
  3974. #endif // E_STEPPERS > 4
  3975. #endif // E_STEPPERS > 3
  3976. #endif // E_STEPPERS > 2
  3977. #endif // E_STEPPERS == 1
  3978. }
  3979. #endif
  3980. END_MENU();
  3981. }
  3982. #endif
  3983. static AdvancedPauseMode advanced_pause_mode = ADVANCED_PAUSE_MODE_PAUSE_PRINT;
  3984. static uint8_t hotend_status_extruder = 0;
  3985. static const char* advanced_pause_header() {
  3986. switch (advanced_pause_mode) {
  3987. case ADVANCED_PAUSE_MODE_LOAD_FILAMENT:
  3988. return PSTR(MSG_FILAMENT_CHANGE_HEADER_LOAD);
  3989. case ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT:
  3990. return PSTR(MSG_FILAMENT_CHANGE_HEADER_UNLOAD);
  3991. default: break;
  3992. }
  3993. return PSTR(MSG_FILAMENT_CHANGE_HEADER_PAUSE);
  3994. }
  3995. // Portions from STATIC_ITEM...
  3996. #define HOTEND_STATUS_ITEM() do { \
  3997. if (_menuLineNr == _thisItemNr) { \
  3998. if (lcdDrawUpdate) { \
  3999. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  4000. lcd_implementation_hotend_status(_lcdLineNr, hotend_status_extruder); \
  4001. } \
  4002. if (_skipStatic && encoderLine <= _thisItemNr) { \
  4003. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  4004. ++encoderLine; \
  4005. } \
  4006. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  4007. } \
  4008. ++_thisItemNr; \
  4009. }while(0)
  4010. void lcd_advanced_pause_resume_print() {
  4011. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_RESUME_PRINT;
  4012. }
  4013. void lcd_advanced_pause_extrude_more() {
  4014. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE;
  4015. }
  4016. void lcd_advanced_pause_option_menu() {
  4017. START_MENU();
  4018. #if LCD_HEIGHT > 2
  4019. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  4020. #endif
  4021. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_advanced_pause_resume_print);
  4022. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_PURGE, lcd_advanced_pause_extrude_more);
  4023. END_MENU();
  4024. }
  4025. void lcd_advanced_pause_init_message() {
  4026. START_SCREEN();
  4027. STATIC_ITEM_P(advanced_pause_header(), true, true);
  4028. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  4029. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  4030. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  4031. #define __FC_LINES_A 3
  4032. #else
  4033. #define __FC_LINES_A 2
  4034. #endif
  4035. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  4036. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  4037. #define _FC_LINES_A (__FC_LINES_A + 1)
  4038. #else
  4039. #define _FC_LINES_A __FC_LINES_A
  4040. #endif
  4041. #if LCD_HEIGHT > _FC_LINES_A + 1
  4042. STATIC_ITEM(" ");
  4043. #endif
  4044. HOTEND_STATUS_ITEM();
  4045. END_SCREEN();
  4046. }
  4047. void lcd_advanced_pause_unload_message() {
  4048. START_SCREEN();
  4049. STATIC_ITEM_P(advanced_pause_header(), true, true);
  4050. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  4051. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  4052. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  4053. #define __FC_LINES_B 3
  4054. #else
  4055. #define __FC_LINES_B 2
  4056. #endif
  4057. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  4058. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  4059. #define _FC_LINES_B (__FC_LINES_B + 1)
  4060. #else
  4061. #define _FC_LINES_B __FC_LINES_B
  4062. #endif
  4063. #if LCD_HEIGHT > _FC_LINES_B + 1
  4064. STATIC_ITEM(" ");
  4065. #endif
  4066. HOTEND_STATUS_ITEM();
  4067. END_SCREEN();
  4068. }
  4069. void lcd_advanced_pause_wait_for_nozzles_to_heat() {
  4070. START_SCREEN();
  4071. STATIC_ITEM_P(advanced_pause_header(), true, true);
  4072. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  4073. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  4074. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  4075. #define _FC_LINES_C 3
  4076. #else
  4077. #define _FC_LINES_C 2
  4078. #endif
  4079. #if LCD_HEIGHT > _FC_LINES_C + 1
  4080. STATIC_ITEM(" ");
  4081. #endif
  4082. HOTEND_STATUS_ITEM();
  4083. END_SCREEN();
  4084. }
  4085. void lcd_advanced_pause_heat_nozzle() {
  4086. START_SCREEN();
  4087. STATIC_ITEM_P(advanced_pause_header(), true, true);
  4088. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  4089. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  4090. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  4091. #define _FC_LINES_D 3
  4092. #else
  4093. #define _FC_LINES_D 2
  4094. #endif
  4095. #if LCD_HEIGHT > _FC_LINES_D + 1
  4096. STATIC_ITEM(" ");
  4097. #endif
  4098. HOTEND_STATUS_ITEM();
  4099. END_SCREEN();
  4100. }
  4101. void lcd_advanced_pause_insert_message() {
  4102. START_SCREEN();
  4103. STATIC_ITEM_P(advanced_pause_header(), true, true);
  4104. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  4105. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  4106. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  4107. #define __FC_LINES_E 3
  4108. #else
  4109. #define __FC_LINES_E 2
  4110. #endif
  4111. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  4112. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  4113. #define _FC_LINES_E (__FC_LINES_E + 1)
  4114. #else
  4115. #define _FC_LINES_E __FC_LINES_E
  4116. #endif
  4117. #if LCD_HEIGHT > _FC_LINES_E + 1
  4118. STATIC_ITEM(" ");
  4119. #endif
  4120. HOTEND_STATUS_ITEM();
  4121. END_SCREEN();
  4122. }
  4123. void lcd_advanced_pause_load_message() {
  4124. START_SCREEN();
  4125. STATIC_ITEM_P(advanced_pause_header(), true, true);
  4126. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  4127. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  4128. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  4129. #define __FC_LINES_F 3
  4130. #else
  4131. #define __FC_LINES_F 2
  4132. #endif
  4133. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  4134. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  4135. #define _FC_LINES_F (__FC_LINES_F + 1)
  4136. #else
  4137. #define _FC_LINES_F __FC_LINES_F
  4138. #endif
  4139. #if LCD_HEIGHT > _FC_LINES_F + 1
  4140. STATIC_ITEM(" ");
  4141. #endif
  4142. HOTEND_STATUS_ITEM();
  4143. END_SCREEN();
  4144. }
  4145. void lcd_advanced_pause_purge_message() {
  4146. START_SCREEN();
  4147. STATIC_ITEM_P(advanced_pause_header(), true, true);
  4148. STATIC_ITEM(MSG_FILAMENT_CHANGE_PURGE_1);
  4149. #ifdef MSG_FILAMENT_CHANGE_PURGE_2
  4150. STATIC_ITEM(MSG_FILAMENT_CHANGE_PURGE_2);
  4151. #define __FC_LINES_G 3
  4152. #else
  4153. #define __FC_LINES_G 2
  4154. #endif
  4155. #ifdef MSG_FILAMENT_CHANGE_PURGE_3
  4156. STATIC_ITEM(MSG_FILAMENT_CHANGE_PURGE_3);
  4157. #define _FC_LINES_G (__FC_LINES_G + 1)
  4158. #else
  4159. #define _FC_LINES_G __FC_LINES_G
  4160. #endif
  4161. #if LCD_HEIGHT > _FC_LINES_G + 1
  4162. STATIC_ITEM(" ");
  4163. #endif
  4164. HOTEND_STATUS_ITEM();
  4165. END_SCREEN();
  4166. }
  4167. #if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE)
  4168. void lcd_advanced_pause_continuous_purge_menu() {
  4169. START_SCREEN();
  4170. STATIC_ITEM(MSG_FILAMENT_CHANGE_PURGE_1);
  4171. #ifdef MSG_FILAMENT_CHANGE_PURGE_2
  4172. STATIC_ITEM(MSG_FILAMENT_CHANGE_PURGE_2);
  4173. #define __FC_LINES_G 3
  4174. #else
  4175. #define __FC_LINES_G 2
  4176. #endif
  4177. #ifdef MSG_FILAMENT_CHANGE_PURGE_3
  4178. STATIC_ITEM(MSG_FILAMENT_CHANGE_PURGE_3);
  4179. #define _FC_LINES_G (__FC_LINES_G + 1)
  4180. #else
  4181. #define _FC_LINES_G __FC_LINES_G
  4182. #endif
  4183. #if LCD_HEIGHT > _FC_LINES_G + 1
  4184. STATIC_ITEM(" ");
  4185. #endif
  4186. HOTEND_STATUS_ITEM();
  4187. STATIC_ITEM(MSG_USERWAIT);
  4188. END_SCREEN();
  4189. }
  4190. #endif
  4191. void lcd_advanced_pause_resume_message() {
  4192. START_SCREEN();
  4193. STATIC_ITEM_P(advanced_pause_header(), true, true);
  4194. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  4195. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  4196. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  4197. #endif
  4198. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  4199. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  4200. #endif
  4201. END_SCREEN();
  4202. }
  4203. FORCE_INLINE screenFunc_t ap_message_screen(const AdvancedPauseMessage message) {
  4204. switch (message) {
  4205. case ADVANCED_PAUSE_MESSAGE_INIT: return lcd_advanced_pause_init_message;
  4206. case ADVANCED_PAUSE_MESSAGE_UNLOAD: return lcd_advanced_pause_unload_message;
  4207. case ADVANCED_PAUSE_MESSAGE_INSERT: return lcd_advanced_pause_insert_message;
  4208. case ADVANCED_PAUSE_MESSAGE_LOAD: return lcd_advanced_pause_load_message;
  4209. case ADVANCED_PAUSE_MESSAGE_PURGE: return lcd_advanced_pause_purge_message;
  4210. case ADVANCED_PAUSE_MESSAGE_RESUME: return lcd_advanced_pause_resume_message;
  4211. case ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE: return lcd_advanced_pause_heat_nozzle;
  4212. case ADVANCED_PAUSE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT: return lcd_advanced_pause_wait_for_nozzles_to_heat;
  4213. case ADVANCED_PAUSE_MESSAGE_OPTION: advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_WAIT_FOR;
  4214. return lcd_advanced_pause_option_menu;
  4215. #if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE)
  4216. case ADVANCED_PAUSE_MESSAGE_CONTINUOUS_PURGE: return lcd_advanced_pause_continuous_purge_menu;
  4217. #endif
  4218. case ADVANCED_PAUSE_MESSAGE_STATUS:
  4219. default: break;
  4220. }
  4221. return NULL;
  4222. }
  4223. void lcd_advanced_pause_show_message(
  4224. const AdvancedPauseMessage message,
  4225. const AdvancedPauseMode mode/*=ADVANCED_PAUSE_MODE_PAUSE_PRINT*/,
  4226. const uint8_t extruder/*=active_extruder*/
  4227. ) {
  4228. advanced_pause_mode = mode;
  4229. hotend_status_extruder = extruder;
  4230. const screenFunc_t next_screen = ap_message_screen(message);
  4231. if (next_screen) {
  4232. defer_return_to_status = true;
  4233. lcd_goto_screen(next_screen);
  4234. }
  4235. else
  4236. lcd_return_to_status();
  4237. }
  4238. #endif // ADVANCED_PAUSE_FEATURE
  4239. /**
  4240. *
  4241. * Functions for editing single values
  4242. *
  4243. * The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value.
  4244. *
  4245. * For example, DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1) expands into these functions:
  4246. *
  4247. * bool _menu_edit_int3();
  4248. * void menu_edit_int3(); // edit int16_t (interactively)
  4249. * void menu_edit_callback_int3(); // edit int16_t (interactively) with callback on completion
  4250. * void _menu_action_setting_edit_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
  4251. * void menu_action_setting_edit_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
  4252. * void menu_action_setting_edit_callback_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue, const screenFunc_t callback, const bool live); // edit int16_t with callback
  4253. *
  4254. * You can then use one of the menu macros to present the edit interface:
  4255. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  4256. *
  4257. * This expands into a more primitive menu item:
  4258. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  4259. *
  4260. * ...which calls:
  4261. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  4262. */
  4263. #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
  4264. bool _menu_edit_ ## _name() { \
  4265. ENCODER_DIRECTION_NORMAL(); \
  4266. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  4267. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  4268. if (lcdDrawUpdate) \
  4269. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0f / _scale))); \
  4270. if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
  4271. _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0f / _scale); \
  4272. if (editValue != NULL) *((_type*)editValue) = value; \
  4273. if (callbackFunc && (liveEdit || lcd_clicked)) (*callbackFunc)(); \
  4274. if (lcd_clicked) lcd_goto_previous_menu(); \
  4275. } \
  4276. return use_click(); \
  4277. } \
  4278. void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
  4279. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  4280. lcd_save_previous_screen(); \
  4281. lcd_refresh(); \
  4282. \
  4283. editLabel = pstr; \
  4284. editValue = ptr; \
  4285. minEditValue = minValue * _scale; \
  4286. maxEditValue = maxValue * _scale - minEditValue; \
  4287. encoderPosition = (*ptr) * _scale - minEditValue; \
  4288. } \
  4289. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live) { \
  4290. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  4291. currentScreen = menu_edit_ ## _name; \
  4292. callbackFunc = callback; \
  4293. liveEdit = live; \
  4294. } \
  4295. FORCE_INLINE void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  4296. menu_action_setting_edit_callback_ ## _name(pstr, ptr, minValue, maxValue); \
  4297. } \
  4298. typedef void _name##_void
  4299. DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1);
  4300. DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
  4301. DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1);
  4302. DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52, 100);
  4303. DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000);
  4304. DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01f);
  4305. DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10);
  4306. DEFINE_MENU_EDIT_TYPE(float, float52sign, ftostr52sign, 100);
  4307. DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100);
  4308. DEFINE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01f);
  4309. /**
  4310. *
  4311. * Handlers for Keypad input
  4312. *
  4313. */
  4314. #if ENABLED(ADC_KEYPAD)
  4315. inline bool handle_adc_keypad() {
  4316. #define ADC_MIN_KEY_DELAY 100
  4317. if (buttons_reprapworld_keypad) {
  4318. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  4319. if (encoderDirection == -1) { // side effect which signals we are inside a menu
  4320. if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_DOWN) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM;
  4321. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_UP) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM;
  4322. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_LEFT) { menu_action_back(); lcd_quick_feedback(true); }
  4323. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_RIGHT) { lcd_return_to_status(); lcd_quick_feedback(true); }
  4324. }
  4325. else {
  4326. if (buttons_reprapworld_keypad & (EN_REPRAPWORLD_KEYPAD_DOWN|EN_REPRAPWORLD_KEYPAD_UP|EN_REPRAPWORLD_KEYPAD_RIGHT)) {
  4327. if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_DOWN) encoderPosition += ENCODER_PULSES_PER_STEP;
  4328. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_UP) encoderPosition -= ENCODER_PULSES_PER_STEP;
  4329. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_RIGHT) encoderPosition = 0;
  4330. }
  4331. }
  4332. #if ENABLED(ADC_KEYPAD_DEBUG)
  4333. SERIAL_PROTOCOLLNPAIR("buttons_reprapworld_keypad = ", (uint32_t)buttons_reprapworld_keypad);
  4334. SERIAL_PROTOCOLLNPAIR("encoderPosition = ", (uint32_t)encoderPosition);
  4335. #endif
  4336. next_button_update_ms = millis() + ADC_MIN_KEY_DELAY;
  4337. return true;
  4338. }
  4339. return false;
  4340. }
  4341. #elif ENABLED(REPRAPWORLD_KEYPAD)
  4342. void _reprapworld_keypad_move(const AxisEnum axis, const int16_t dir) {
  4343. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  4344. encoderPosition = dir;
  4345. switch (axis) {
  4346. case X_AXIS: lcd_move_x(); break;
  4347. case Y_AXIS: lcd_move_y(); break;
  4348. case Z_AXIS: lcd_move_z();
  4349. default: break;
  4350. }
  4351. }
  4352. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  4353. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  4354. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  4355. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  4356. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  4357. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  4358. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  4359. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  4360. inline void handle_reprapworld_keypad() {
  4361. static uint8_t keypad_debounce = 0;
  4362. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  4363. if (keypad_debounce > 0) keypad_debounce--;
  4364. }
  4365. else if (!keypad_debounce) {
  4366. keypad_debounce = 2;
  4367. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  4368. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  4369. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  4370. #endif
  4371. if (all_axes_homed()) {
  4372. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  4373. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  4374. #endif
  4375. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  4376. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  4377. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  4378. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  4379. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  4380. }
  4381. else {
  4382. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  4383. }
  4384. }
  4385. }
  4386. #endif // REPRAPWORLD_KEYPAD
  4387. /**
  4388. *
  4389. * Menu actions
  4390. *
  4391. */
  4392. void _menu_action_back() { lcd_goto_previous_menu(); }
  4393. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  4394. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  4395. void menu_action_function(screenFunc_t func) { (*func)(); }
  4396. #if ENABLED(SDSUPPORT)
  4397. void menu_action_sdfile(CardReader& theCard) {
  4398. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  4399. last_sdfile_encoderPosition = encoderPosition; // Save which file was selected for later use
  4400. #endif
  4401. card.openAndPrintFile(theCard.filename);
  4402. lcd_return_to_status();
  4403. lcd_reset_status();
  4404. }
  4405. void menu_action_sddirectory(CardReader& theCard) {
  4406. card.chdir(theCard.filename);
  4407. encoderTopLine = 0;
  4408. encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
  4409. screen_changed = true;
  4410. #if ENABLED(DOGLCD)
  4411. drawing_screen = false;
  4412. #endif
  4413. lcd_refresh();
  4414. }
  4415. #endif // SDSUPPORT
  4416. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { UNUSED(pstr); *ptr ^= true; lcd_refresh(); }
  4417. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  4418. menu_action_setting_edit_bool(pstr, ptr);
  4419. (*callback)();
  4420. }
  4421. #endif // ULTIPANEL
  4422. void lcd_init() {
  4423. lcd_implementation_init();
  4424. #if ENABLED(NEWPANEL)
  4425. #if BUTTON_EXISTS(EN1)
  4426. SET_INPUT_PULLUP(BTN_EN1);
  4427. #endif
  4428. #if BUTTON_EXISTS(EN2)
  4429. SET_INPUT_PULLUP(BTN_EN2);
  4430. #endif
  4431. #if BUTTON_EXISTS(ENC)
  4432. SET_INPUT_PULLUP(BTN_ENC);
  4433. #endif
  4434. #if ENABLED(REPRAPWORLD_KEYPAD) && DISABLED(ADC_KEYPAD)
  4435. SET_OUTPUT(SHIFT_CLK);
  4436. OUT_WRITE(SHIFT_LD, HIGH);
  4437. SET_INPUT_PULLUP(SHIFT_OUT);
  4438. #endif
  4439. #if BUTTON_EXISTS(UP)
  4440. SET_INPUT(BTN_UP);
  4441. #endif
  4442. #if BUTTON_EXISTS(DWN)
  4443. SET_INPUT(BTN_DWN);
  4444. #endif
  4445. #if BUTTON_EXISTS(LFT)
  4446. SET_INPUT(BTN_LFT);
  4447. #endif
  4448. #if BUTTON_EXISTS(RT)
  4449. SET_INPUT(BTN_RT);
  4450. #endif
  4451. #else // !NEWPANEL
  4452. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  4453. SET_OUTPUT(SR_DATA_PIN);
  4454. SET_OUTPUT(SR_CLK_PIN);
  4455. #elif defined(SHIFT_CLK)
  4456. SET_OUTPUT(SHIFT_CLK);
  4457. OUT_WRITE(SHIFT_LD, HIGH);
  4458. OUT_WRITE(SHIFT_EN, LOW);
  4459. SET_INPUT_PULLUP(SHIFT_OUT);
  4460. #endif // SR_LCD_2W_NL
  4461. #endif // !NEWPANEL
  4462. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  4463. SET_INPUT_PULLUP(SD_DETECT_PIN);
  4464. lcd_sd_status = 2; // UNKNOWN
  4465. #endif
  4466. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  4467. slow_buttons = 0;
  4468. #endif
  4469. lcd_buttons_update();
  4470. #if ENABLED(ULTIPANEL)
  4471. encoderDiff = 0;
  4472. #endif
  4473. }
  4474. int16_t utf8_strlen(const char* s) {
  4475. int16_t i = 0, j = 0;
  4476. while (s[i]) {
  4477. if (START_OF_UTF8_CHAR(s[i])) j++;
  4478. i++;
  4479. }
  4480. return j;
  4481. }
  4482. int16_t utf8_strlen_P(const char* s) {
  4483. int16_t j = 0;
  4484. while (pgm_read_byte(s)) {
  4485. if (START_OF_UTF8_CHAR(pgm_read_byte(s))) j++;
  4486. s++;
  4487. }
  4488. return j;
  4489. }
  4490. bool lcd_blink() {
  4491. static uint8_t blink = 0;
  4492. static millis_t next_blink_ms = 0;
  4493. millis_t ms = millis();
  4494. if (ELAPSED(ms, next_blink_ms)) {
  4495. blink ^= 0xFF;
  4496. next_blink_ms = ms + 1000 - (LCD_UPDATE_INTERVAL) / 2;
  4497. }
  4498. return blink != 0;
  4499. }
  4500. /**
  4501. * Update the LCD, read encoder buttons, etc.
  4502. * - Read button states
  4503. * - Check the SD Card slot state
  4504. * - Act on RepRap World keypad input
  4505. * - Update the encoder position
  4506. * - Apply acceleration to the encoder position
  4507. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  4508. * - Reset the Info Screen timeout if there's any input
  4509. * - Update status indicators, if any
  4510. *
  4511. * Run the current LCD menu handler callback function:
  4512. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  4513. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  4514. * - Call the menu handler. Menu handlers should do the following:
  4515. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  4516. * (Encoder events automatically set lcdDrawUpdate for you.)
  4517. * - if (lcdDrawUpdate) { redraw }
  4518. * - Before exiting the handler set lcdDrawUpdate to:
  4519. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  4520. * - LCDVIEW_REDRAW_NOW to draw now (including remaining stripes).
  4521. * - LCDVIEW_CALL_REDRAW_NEXT to draw now and get LCDVIEW_REDRAW_NOW on the next loop.
  4522. * - LCDVIEW_CALL_NO_REDRAW to draw now and get LCDVIEW_NONE on the next loop.
  4523. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  4524. * so don't change lcdDrawUpdate without considering this.
  4525. *
  4526. * After the menu handler callback runs (or not):
  4527. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  4528. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  4529. *
  4530. * No worries. This function is only called from the main thread.
  4531. */
  4532. void lcd_update() {
  4533. #if ENABLED(ULTIPANEL)
  4534. static millis_t return_to_status_ms = 0;
  4535. // Handle any queued Move Axis motion
  4536. manage_manual_move();
  4537. // Update button states for LCD_CLICKED, etc.
  4538. // After state changes the next button update
  4539. // may be delayed 300-500ms.
  4540. lcd_buttons_update();
  4541. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4542. // Don't run the debouncer if UBL owns the display
  4543. #define UBL_CONDITION !lcd_external_control
  4544. #else
  4545. #define UBL_CONDITION true
  4546. #endif
  4547. // If the action button is pressed...
  4548. if (UBL_CONDITION && LCD_CLICKED) {
  4549. if (!wait_for_unclick) { // If not waiting for a debounce release:
  4550. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  4551. lcd_clicked = !wait_for_user && !no_reentry; // Keep the click if not waiting for a user-click
  4552. wait_for_user = false; // Any click clears wait for user
  4553. lcd_quick_feedback(true); // Always make a click sound
  4554. }
  4555. }
  4556. else wait_for_unclick = false;
  4557. #if BUTTON_EXISTS(BACK)
  4558. if (LCD_BACK_CLICKED) {
  4559. lcd_quick_feedback(true);
  4560. lcd_goto_previous_menu();
  4561. }
  4562. #endif
  4563. #endif // ULTIPANEL
  4564. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  4565. const uint8_t sd_status = (uint8_t)IS_SD_INSERTED();
  4566. if (sd_status != lcd_sd_status && lcd_detected()) {
  4567. uint8_t old_sd_status = lcd_sd_status; // prevent re-entry to this block!
  4568. lcd_sd_status = sd_status;
  4569. if (sd_status) {
  4570. safe_delay(500); // Some boards need a delay to get settled
  4571. card.initsd();
  4572. if (old_sd_status == 2)
  4573. card.beginautostart(); // Initial boot
  4574. else
  4575. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  4576. }
  4577. else {
  4578. card.release();
  4579. if (old_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  4580. }
  4581. lcd_refresh();
  4582. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  4583. #if ENABLED(LCD_PROGRESS_BAR)
  4584. currentScreen == lcd_status_screen ? CHARSET_INFO : CHARSET_MENU
  4585. #endif
  4586. );
  4587. }
  4588. #endif // SDSUPPORT && SD_DETECT_PIN
  4589. #if ENABLED(POWER_LOSS_RECOVERY)
  4590. if (job_recovery_commands_count && job_recovery_phase == JOB_RECOVERY_IDLE) {
  4591. lcd_goto_screen(lcd_job_recovery_menu);
  4592. job_recovery_phase = JOB_RECOVERY_MAYBE; // Waiting for a response
  4593. }
  4594. #endif
  4595. const millis_t ms = millis();
  4596. if (ELAPSED(ms, next_lcd_update_ms)
  4597. #if ENABLED(DOGLCD)
  4598. || drawing_screen
  4599. #endif
  4600. ) {
  4601. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  4602. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  4603. lcd_implementation_update_indicators();
  4604. #endif
  4605. #if ENABLED(ULTIPANEL)
  4606. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  4607. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  4608. #endif
  4609. #if ENABLED(ADC_KEYPAD)
  4610. if (handle_adc_keypad())
  4611. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  4612. #elif ENABLED(REPRAPWORLD_KEYPAD)
  4613. handle_reprapworld_keypad();
  4614. #endif
  4615. const bool encoderPastThreshold = (ABS(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  4616. if (encoderPastThreshold || lcd_clicked) {
  4617. if (encoderPastThreshold) {
  4618. int32_t encoderMultiplier = 1;
  4619. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  4620. if (encoderRateMultiplierEnabled) {
  4621. int32_t encoderMovementSteps = ABS(encoderDiff) / ENCODER_PULSES_PER_STEP;
  4622. if (lastEncoderMovementMillis) {
  4623. // Note that the rate is always calculated between two passes through the
  4624. // loop and that the abs of the encoderDiff value is tracked.
  4625. float encoderStepRate = float(encoderMovementSteps) / float(ms - lastEncoderMovementMillis) * 1000;
  4626. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  4627. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  4628. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  4629. SERIAL_ECHO_START();
  4630. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  4631. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  4632. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  4633. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  4634. SERIAL_EOL();
  4635. #endif // ENCODER_RATE_MULTIPLIER_DEBUG
  4636. }
  4637. lastEncoderMovementMillis = ms;
  4638. } // encoderRateMultiplierEnabled
  4639. #endif // ENCODER_RATE_MULTIPLIER
  4640. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  4641. encoderDiff = 0;
  4642. }
  4643. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  4644. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  4645. }
  4646. #endif // ULTIPANEL
  4647. // We arrive here every ~100ms when idling often enough.
  4648. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  4649. if (
  4650. #if ENABLED(ULTIPANEL)
  4651. currentScreen == lcd_status_screen &&
  4652. #endif
  4653. !lcd_status_update_delay--
  4654. ) {
  4655. lcd_status_update_delay = 9
  4656. #if ENABLED(DOGLCD)
  4657. + 3
  4658. #endif
  4659. ;
  4660. max_display_update_time--;
  4661. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  4662. }
  4663. #if ENABLED(ULTIPANEL) && ENABLED(SCROLL_LONG_FILENAMES)
  4664. // If scrolling of long file names is enabled and we are in the sd card menu,
  4665. // cause a refresh to occur until all the text has scrolled into view.
  4666. if (currentScreen == lcd_sdcard_menu && filename_scroll_pos < filename_scroll_max && !lcd_status_update_delay--) {
  4667. lcd_status_update_delay = 6;
  4668. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  4669. filename_scroll_pos++;
  4670. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  4671. }
  4672. #endif
  4673. // then we want to use 1/2 of the time only.
  4674. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  4675. #if ENABLED(DOGLCD)
  4676. #define IS_DRAWING drawing_screen
  4677. #else
  4678. #define IS_DRAWING false
  4679. #endif
  4680. if ((lcdDrawUpdate || IS_DRAWING) && (!bbr2 || bbr2 > max_display_update_time)) {
  4681. // Change state of drawing flag between screen updates
  4682. if (!IS_DRAWING) switch (lcdDrawUpdate) {
  4683. case LCDVIEW_CALL_NO_REDRAW:
  4684. lcdDrawUpdate = LCDVIEW_NONE;
  4685. break;
  4686. case LCDVIEW_CLEAR_CALL_REDRAW:
  4687. case LCDVIEW_CALL_REDRAW_NEXT:
  4688. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  4689. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  4690. case LCDVIEW_NONE:
  4691. break;
  4692. } // switch
  4693. #if ENABLED(ADC_KEYPAD)
  4694. buttons_reprapworld_keypad = 0;
  4695. #endif
  4696. #if ENABLED(ULTIPANEL)
  4697. #define CURRENTSCREEN() (*currentScreen)()
  4698. #else
  4699. #define CURRENTSCREEN() lcd_status_screen()
  4700. #endif
  4701. #if ENABLED(DOGLCD)
  4702. #if ENABLED(LIGHTWEIGHT_UI)
  4703. #if ENABLED(ULTIPANEL)
  4704. const bool in_status = currentScreen == lcd_status_screen;
  4705. #else
  4706. constexpr bool in_status = true;
  4707. #endif
  4708. const bool do_u8g_loop = !in_status;
  4709. lcd_in_status(in_status);
  4710. if (in_status) lcd_status_screen();
  4711. #else
  4712. constexpr bool do_u8g_loop = true;
  4713. #endif
  4714. if (do_u8g_loop) {
  4715. if (!drawing_screen) { // If not already drawing pages
  4716. u8g.firstPage(); // Start the first page
  4717. drawing_screen = first_page = true; // Flag as drawing pages
  4718. }
  4719. lcd_setFont(FONT_MENU); // Setup font for every page draw
  4720. u8g.setColorIndex(1); // And reset the color
  4721. CURRENTSCREEN(); // Draw and process the current screen
  4722. first_page = false;
  4723. // The screen handler can clear drawing_screen for an action that changes the screen.
  4724. // If still drawing and there's another page, update max-time and return now.
  4725. // The nextPage will already be set up on the next call.
  4726. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  4727. NOLESS(max_display_update_time, millis() - ms);
  4728. return;
  4729. }
  4730. }
  4731. #else
  4732. CURRENTSCREEN();
  4733. #endif
  4734. #if ENABLED(ULTIPANEL)
  4735. lcd_clicked = false;
  4736. #endif
  4737. // Keeping track of the longest time for an individual LCD update.
  4738. // Used to do screen throttling when the planner starts to fill up.
  4739. NOLESS(max_display_update_time, millis() - ms);
  4740. }
  4741. #if ENABLED(ULTIPANEL)
  4742. // Return to Status Screen after a timeout
  4743. if (currentScreen == lcd_status_screen || defer_return_to_status)
  4744. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  4745. else if (ELAPSED(ms, return_to_status_ms))
  4746. lcd_return_to_status();
  4747. #endif // ULTIPANEL
  4748. // Change state of drawing flag between screen updates
  4749. if (!IS_DRAWING) switch (lcdDrawUpdate) {
  4750. case LCDVIEW_CLEAR_CALL_REDRAW:
  4751. lcd_implementation_clear(); break;
  4752. case LCDVIEW_REDRAW_NOW:
  4753. lcdDrawUpdate = LCDVIEW_NONE;
  4754. case LCDVIEW_NONE:
  4755. case LCDVIEW_CALL_REDRAW_NEXT:
  4756. case LCDVIEW_CALL_NO_REDRAW:
  4757. default: break;
  4758. } // switch
  4759. } // ELAPSED(ms, next_lcd_update_ms)
  4760. }
  4761. void lcd_finishstatus(const bool persist=false) {
  4762. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  4763. UNUSED(persist);
  4764. #endif
  4765. #if ENABLED(LCD_PROGRESS_BAR)
  4766. progress_bar_ms = millis();
  4767. #if PROGRESS_MSG_EXPIRE > 0
  4768. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  4769. #endif
  4770. #endif
  4771. lcd_refresh();
  4772. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  4773. previous_lcd_status_ms = millis(); //get status message to show up for a while
  4774. #endif
  4775. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  4776. status_scroll_offset = 0;
  4777. #endif
  4778. }
  4779. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  4780. void dontExpireStatus() { expire_status_ms = 0; }
  4781. #endif
  4782. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  4783. void lcd_setstatus(const char * const message, const bool persist) {
  4784. if (lcd_status_message_level > 0) return;
  4785. // Here we have a problem. The message is encoded in UTF8, so
  4786. // arbitrarily cutting it will be a problem. We MUST be sure
  4787. // that there is no cutting in the middle of a multibyte character!
  4788. // Get a pointer to the null terminator
  4789. const char* pend = message + strlen(message);
  4790. // If length of supplied UTF8 string is greater than
  4791. // our buffer size, start cutting whole UTF8 chars
  4792. while ((pend - message) > MAX_MESSAGE_LENGTH) {
  4793. --pend;
  4794. while (!START_OF_UTF8_CHAR(*pend)) --pend;
  4795. };
  4796. // At this point, we have the proper cut point. Use it
  4797. uint8_t maxLen = pend - message;
  4798. strncpy(lcd_status_message, message, maxLen);
  4799. lcd_status_message[maxLen] = '\0';
  4800. lcd_finishstatus(persist);
  4801. }
  4802. void lcd_setstatusPGM(const char * const message, int8_t level) {
  4803. if (level < 0) level = lcd_status_message_level = 0;
  4804. if (level < lcd_status_message_level) return;
  4805. lcd_status_message_level = level;
  4806. // Here we have a problem. The message is encoded in UTF8, so
  4807. // arbitrarily cutting it will be a problem. We MUST be sure
  4808. // that there is no cutting in the middle of a multibyte character!
  4809. // Get a pointer to the null terminator
  4810. const char* pend = message + strlen_P(message);
  4811. // If length of supplied UTF8 string is greater than
  4812. // our buffer size, start cutting whole UTF8 chars
  4813. while ((pend - message) > MAX_MESSAGE_LENGTH) {
  4814. --pend;
  4815. while (!START_OF_UTF8_CHAR(pgm_read_byte(pend))) --pend;
  4816. };
  4817. // At this point, we have the proper cut point. Use it
  4818. uint8_t maxLen = pend - message;
  4819. strncpy_P(lcd_status_message, message, maxLen);
  4820. lcd_status_message[maxLen] = '\0';
  4821. lcd_finishstatus(level > 0);
  4822. }
  4823. void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
  4824. if (level < lcd_status_message_level) return;
  4825. lcd_status_message_level = level;
  4826. va_list args;
  4827. va_start(args, fmt);
  4828. vsnprintf_P(lcd_status_message, MAX_MESSAGE_LENGTH, fmt, args);
  4829. va_end(args);
  4830. lcd_finishstatus(level > 0);
  4831. }
  4832. void lcd_setalertstatusPGM(const char * const message) {
  4833. lcd_setstatusPGM(message, 1);
  4834. #if ENABLED(ULTIPANEL)
  4835. lcd_return_to_status();
  4836. #endif
  4837. }
  4838. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  4839. #if HAS_LCD_CONTRAST
  4840. void set_lcd_contrast(const int16_t value) {
  4841. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  4842. u8g.setContrast(lcd_contrast);
  4843. }
  4844. #endif
  4845. #if ENABLED(ULTIPANEL)
  4846. /**
  4847. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  4848. * These values are independent of which pins are used for EN_A and EN_B indications
  4849. * The rotary encoder part is also independent to the chipset used for the LCD
  4850. */
  4851. #if defined(EN_A) && defined(EN_B)
  4852. #define encrot0 0
  4853. #define encrot1 2
  4854. #define encrot2 3
  4855. #define encrot3 1
  4856. #endif
  4857. #define GET_SHIFT_BUTTON_STATES(DST) \
  4858. uint8_t new_##DST = 0; \
  4859. WRITE(SHIFT_LD, LOW); \
  4860. WRITE(SHIFT_LD, HIGH); \
  4861. for (int8_t i = 0; i < 8; i++) { \
  4862. new_##DST >>= 1; \
  4863. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  4864. WRITE(SHIFT_CLK, HIGH); \
  4865. WRITE(SHIFT_CLK, LOW); \
  4866. } \
  4867. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  4868. /**
  4869. * Read encoder buttons from the hardware registers
  4870. * Warning: This function is called from interrupt context!
  4871. */
  4872. void lcd_buttons_update() {
  4873. static uint8_t lastEncoderBits;
  4874. const millis_t now = millis();
  4875. if (ELAPSED(now, next_button_update_ms)) {
  4876. #if ENABLED(NEWPANEL)
  4877. uint8_t newbutton = 0;
  4878. #if BUTTON_EXISTS(EN1)
  4879. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  4880. #endif
  4881. #if BUTTON_EXISTS(EN2)
  4882. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  4883. #endif
  4884. #if BUTTON_EXISTS(ENC)
  4885. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  4886. #endif
  4887. #if BUTTON_EXISTS(BACK)
  4888. if (BUTTON_PRESSED(BACK)) newbutton |= EN_D;
  4889. #endif
  4890. //
  4891. // Directional buttons
  4892. //
  4893. #if LCD_HAS_DIRECTIONAL_BUTTONS
  4894. #if ENABLED(REVERSE_MENU_DIRECTION)
  4895. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  4896. #else
  4897. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  4898. #endif
  4899. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  4900. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  4901. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  4902. #else
  4903. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  4904. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  4905. #endif
  4906. if (false) {
  4907. // for the else-ifs below
  4908. }
  4909. #if BUTTON_EXISTS(UP)
  4910. else if (BUTTON_PRESSED(UP)) {
  4911. encoderDiff = -(ENCODER_UD_STEPS);
  4912. next_button_update_ms = now + 300;
  4913. }
  4914. #endif
  4915. #if BUTTON_EXISTS(DWN)
  4916. else if (BUTTON_PRESSED(DWN)) {
  4917. encoderDiff = ENCODER_UD_STEPS;
  4918. next_button_update_ms = now + 300;
  4919. }
  4920. #endif
  4921. #if BUTTON_EXISTS(LFT)
  4922. else if (BUTTON_PRESSED(LFT)) {
  4923. encoderDiff = -(ENCODER_LR_PULSES);
  4924. next_button_update_ms = now + 300;
  4925. }
  4926. #endif
  4927. #if BUTTON_EXISTS(RT)
  4928. else if (BUTTON_PRESSED(RT)) {
  4929. encoderDiff = ENCODER_LR_PULSES;
  4930. next_button_update_ms = now + 300;
  4931. }
  4932. #endif
  4933. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  4934. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  4935. newbutton |= slow_buttons;
  4936. #endif
  4937. buttons = newbutton;
  4938. #if ENABLED(ADC_KEYPAD)
  4939. uint8_t newbutton_reprapworld_keypad = 0;
  4940. if (buttons_reprapworld_keypad == 0) {
  4941. newbutton_reprapworld_keypad = get_ADC_keyValue();
  4942. if (WITHIN(newbutton_reprapworld_keypad, 1, 8))
  4943. buttons_reprapworld_keypad = _BV(newbutton_reprapworld_keypad - 1);
  4944. }
  4945. #elif ENABLED(REPRAPWORLD_KEYPAD)
  4946. GET_SHIFT_BUTTON_STATES(buttons_reprapworld_keypad);
  4947. #endif
  4948. #else // !NEWPANEL
  4949. GET_SHIFT_BUTTON_STATES(buttons);
  4950. #endif
  4951. } // next_button_update_ms
  4952. // Manage encoder rotation
  4953. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  4954. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  4955. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  4956. #elif ENABLED(REVERSE_MENU_DIRECTION)
  4957. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  4958. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  4959. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  4960. #define ENCODER_DIFF_CW (encoderDiff--)
  4961. #define ENCODER_DIFF_CCW (encoderDiff++)
  4962. #else
  4963. #define ENCODER_DIFF_CW (encoderDiff++)
  4964. #define ENCODER_DIFF_CCW (encoderDiff--)
  4965. #endif
  4966. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  4967. uint8_t enc = 0;
  4968. if (buttons & EN_A) enc |= B01;
  4969. if (buttons & EN_B) enc |= B10;
  4970. if (enc != lastEncoderBits) {
  4971. switch (enc) {
  4972. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  4973. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  4974. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  4975. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  4976. }
  4977. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4978. if (lcd_external_control) {
  4979. ubl.encoder_diff = encoderDiff; // Make encoder rotation available to UBL G29 mesh editing.
  4980. encoderDiff = 0; // Hide the encoder event from the current screen handler.
  4981. }
  4982. #endif
  4983. lastEncoderBits = enc;
  4984. }
  4985. }
  4986. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  4987. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  4988. #else
  4989. bool lcd_detected() { return true; }
  4990. #endif
  4991. #if ENABLED(G26_MESH_VALIDATION)
  4992. void lcd_chirp() {
  4993. #if ENABLED(LCD_USE_I2C_BUZZER)
  4994. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4995. #elif PIN_EXISTS(BEEPER)
  4996. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4997. #endif
  4998. }
  4999. #endif
  5000. #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
  5001. bool is_lcd_clicked() { return LCD_CLICKED; }
  5002. void wait_for_release() {
  5003. while (is_lcd_clicked()) safe_delay(50);
  5004. safe_delay(50);
  5005. }
  5006. #endif
  5007. #endif // ULTIPANEL
  5008. #if ENABLED(ADC_KEYPAD)
  5009. typedef struct {
  5010. uint16_t ADCKeyValueMin, ADCKeyValueMax;
  5011. uint8_t ADCKeyNo;
  5012. } _stADCKeypadTable_;
  5013. static const _stADCKeypadTable_ stADCKeyTable[] PROGMEM = {
  5014. // VALUE_MIN, VALUE_MAX, KEY
  5015. { 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F1 + 1 }, // F1
  5016. { 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F2 + 1 }, // F2
  5017. { 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F3 + 1 }, // F3
  5018. { 300, 500, BLEN_REPRAPWORLD_KEYPAD_LEFT + 1 }, // LEFT
  5019. { 1900, 2200, BLEN_REPRAPWORLD_KEYPAD_RIGHT + 1 }, // RIGHT
  5020. { 570, 870, BLEN_REPRAPWORLD_KEYPAD_UP + 1 }, // UP
  5021. { 2670, 2870, BLEN_REPRAPWORLD_KEYPAD_DOWN + 1 }, // DOWN
  5022. { 1150, 1450, BLEN_REPRAPWORLD_KEYPAD_MIDDLE + 1 }, // ENTER
  5023. };
  5024. uint8_t get_ADC_keyValue(void) {
  5025. if (thermalManager.ADCKey_count >= 16) {
  5026. const uint16_t currentkpADCValue = thermalManager.current_ADCKey_raw >> 2;
  5027. #if ENABLED(ADC_KEYPAD_DEBUG)
  5028. SERIAL_PROTOCOLLN(currentkpADCValue);
  5029. #endif
  5030. thermalManager.current_ADCKey_raw = 0;
  5031. thermalManager.ADCKey_count = 0;
  5032. if (currentkpADCValue < 4000)
  5033. for (uint8_t i = 0; i < ADC_KEY_NUM; i++) {
  5034. const uint16_t lo = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMin),
  5035. hi = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMax);
  5036. if (WITHIN(currentkpADCValue, lo, hi)) return pgm_read_byte(&stADCKeyTable[i].ADCKeyNo);
  5037. }
  5038. }
  5039. return 0;
  5040. }
  5041. #endif
  5042. #endif // ULTRA_LCD