ultralcd.cpp 199 KB

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