ultralcd.cpp 244 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763
  1. //! @file
  2. //! @date Aug 28, 2019
  3. //! @author mkbel
  4. //! @brief LCD
  5. #include "temperature.h"
  6. #include "ultralcd.h"
  7. #include "conv2str.h"
  8. #include "Marlin.h"
  9. #include "language.h"
  10. #include "cardreader.h"
  11. #include "fancheck.h"
  12. #include "stepper.h"
  13. #include "ConfigurationStore.h"
  14. #include "printers.h"
  15. #include <string.h>
  16. #include "lcd.h"
  17. #include "menu.h"
  18. #include "backlight.h"
  19. #include "util.h"
  20. #include "mesh_bed_leveling.h"
  21. #include "mesh_bed_calibration.h"
  22. //#include "Configuration.h"
  23. #include "cmdqueue.h"
  24. #include "Filament_sensor.h"
  25. #ifdef TMC2130
  26. #include "tmc2130.h"
  27. #endif //TMC2130
  28. #include "sound.h"
  29. #include "mmu2.h"
  30. #include "SpoolJoin.h"
  31. #include "static_assert.h"
  32. #include "first_lay_cal.h"
  33. #include "adc.h"
  34. #include "config.h"
  35. #ifndef LA_NOCOMPAT
  36. #include "la10compat.h"
  37. #endif
  38. #include "Prusa_farm.h"
  39. int clock_interval = 0;
  40. static void lcd_sd_updir();
  41. static void lcd_mesh_bed_leveling_settings();
  42. #ifdef LCD_BL_PIN
  43. static void lcd_backlight_menu();
  44. #endif
  45. int8_t ReInitLCD = 0;
  46. uint8_t scrollstuff = 0;
  47. int8_t SilentModeMenu = SILENT_MODE_OFF;
  48. uint8_t SilentModeMenu_MMU = 1; //activate mmu unit stealth mode
  49. int8_t FSensorStateMenu = 1;
  50. LcdCommands lcd_commands_type = LcdCommands::Idle;
  51. static uint8_t lcd_commands_step = 0;
  52. CustomMsg custom_message_type = CustomMsg::Status;
  53. uint8_t custom_message_state = 0;
  54. bool isPrintPaused = false;
  55. static ShortTimer display_time; //just timer for showing pid finished message on lcd;
  56. static uint16_t pid_temp = DEFAULT_PID_TEMP;
  57. static float manual_feedrate[] = MANUAL_FEEDRATE;
  58. /* LCD message status */
  59. static LongTimer lcd_status_message_timeout;
  60. static uint8_t lcd_status_message_level;
  61. static char lcd_status_message[LCD_WIDTH + 1];
  62. /* !Configuration settings */
  63. static uint8_t lay1cal_filament = 0;
  64. static const char separator[] PROGMEM = "--------------------";
  65. /** forward declarations **/
  66. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg);
  67. // void copy_and_scalePID_i();
  68. // void copy_and_scalePID_d();
  69. /* Different menus */
  70. //static void lcd_status_screen(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  71. #if (LANG_MODE != 0)
  72. static void lcd_language_menu();
  73. #endif
  74. static void lcd_main_menu();
  75. static void lcd_tune_menu();
  76. //static void lcd_move_menu();
  77. static void lcd_settings_menu();
  78. static void lcd_calibration_menu();
  79. static void lcd_control_temperature_menu();
  80. #ifdef TMC2130
  81. static void lcd_settings_linearity_correction_menu_save();
  82. #endif
  83. static void lcd_menu_xyz_y_min();
  84. static void lcd_menu_xyz_skew();
  85. static void lcd_menu_xyz_offset();
  86. static void lcd_menu_fails_stats_mmu();
  87. static void lcd_menu_fails_stats_mmu_print();
  88. static void lcd_menu_fails_stats_mmu_total();
  89. static void lcd_menu_toolchange_stats_mmu_total();
  90. static void mmu_unload_filament();
  91. static void lcd_v2_calibration();
  92. //static void lcd_menu_show_sensors_state(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  93. static void mmu_fil_eject_menu();
  94. static void mmu_load_to_nozzle_menu();
  95. static void mmu_loading_test_menu();
  96. static void preheat_or_continue();
  97. #ifdef MMU_HAS_CUTTER
  98. static void mmu_cut_filament_menu();
  99. #endif //MMU_HAS_CUTTER
  100. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  101. static void lcd_menu_fails_stats();
  102. #endif //TMC2130 or FILAMENT_SENSOR
  103. #ifdef TMC2130
  104. static void lcd_belttest_v();
  105. #endif //TMC2130
  106. static void lcd_selftest_v();
  107. #ifdef TMC2130
  108. static void reset_crash_det(uint8_t axis);
  109. static bool lcd_selfcheck_axis_sg(uint8_t axis);
  110. #else
  111. static bool lcd_selfcheck_axis(int _axis, int _travel);
  112. static bool lcd_selfcheck_pulleys(int axis);
  113. #endif //TMC2130
  114. static bool lcd_selfcheck_endstops();
  115. static bool lcd_selfcheck_check_heater(bool _isbed);
  116. enum class TestScreen : uint_least8_t
  117. {
  118. ExtruderFan,
  119. PrintFan,
  120. FansOk,
  121. EndStops,
  122. AxisX,
  123. AxisY,
  124. AxisZ,
  125. Bed,
  126. Hotend,
  127. HotendOk,
  128. Fsensor,
  129. FsensorOk,
  130. AllCorrect,
  131. Failed,
  132. Home,
  133. };
  134. enum class TestError : uint_least8_t
  135. {
  136. Heater,
  137. Bed,
  138. Endstops,
  139. Motor,
  140. Endstop,
  141. PrintFan,
  142. ExtruderFan,
  143. Pulley,
  144. Axis,
  145. SwappedFan,
  146. WiringFsensor,
  147. TriggeringFsensor,
  148. FsensorLevel
  149. };
  150. static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay);
  151. static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name, const char *_indicator);
  152. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  153. bool _default=false);
  154. #ifdef FANCHECK
  155. /** Enumerate for lcd_selftest_fan_auto function.
  156. */
  157. enum class FanCheck : uint_least8_t {
  158. Success,
  159. PrintFan,
  160. ExtruderFan,
  161. SwappedFan,
  162. };
  163. /**
  164. * Try to check fan working and wiring.
  165. *
  166. * @param _fan i fan number 0 means hotend fan, 1 means print fan.
  167. *
  168. * @returns a TestError noerror, extruderFan, printFan or swappedFan.
  169. */
  170. static FanCheck lcd_selftest_fan_auto(uint8_t _fan);
  171. #endif //FANCHECK
  172. #ifdef FILAMENT_SENSOR
  173. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  174. static bool lcd_selftest_fsensor();
  175. #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR
  176. static bool selftest_irsensor();
  177. #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG
  178. static bool selftest_irsensor();
  179. static bool lcd_selftest_IRsensor(bool bStandalone=false);
  180. static void lcd_detect_IRsensor();
  181. #endif
  182. #endif //FILAMENT_SENSOR
  183. static void lcd_selftest_error(TestError error, const char *_error_1, const char *_error_2);
  184. static void lcd_colorprint_change();
  185. static void lcd_disable_farm_mode();
  186. static void lcd_set_fan_check();
  187. #ifdef MMU_HAS_CUTTER
  188. static void lcd_cutter_enabled();
  189. #endif
  190. #ifdef SDCARD_SORT_ALPHA
  191. static void lcd_sort_type_set();
  192. #endif
  193. static void lcd_babystep_z();
  194. static void lcd_sdcard_menu();
  195. static void lcd_sheet_menu();
  196. #ifdef DELTA_CALIBRATION_MENU
  197. static void lcd_delta_calibrate_menu();
  198. #endif // DELTA_CALIBRATION_MENU
  199. /* Different types of actions that can be used in menu items. */
  200. static void menu_action_sdfile(const char* filename);
  201. static void menu_action_sddirectory(const char* filename);
  202. #define ENCODER_FEEDRATE_DEADZONE 10
  203. #define STATE_NA 255
  204. #define STATE_OFF 0
  205. #define STATE_ON 1
  206. /*
  207. #define MENU_ITEM(type, label, args...) do { \
  208. if (menu_item == menu_line) { \
  209. if (lcd_draw_update) { \
  210. const char* _label_pstr = (label); \
  211. if (lcd_encoder == menu_item) { \
  212. lcd_implementation_drawmenu_ ## type ## _selected (menu_row, _label_pstr , ## args ); \
  213. }else{\
  214. lcd_implementation_drawmenu_ ## type (menu_row, _label_pstr , ## args ); \
  215. }\
  216. }\
  217. if (menu_clicked && (lcd_encoder == menu_item)) {\
  218. lcd_quick_feedback(); \
  219. menu_action_ ## type ( args ); \
  220. return;\
  221. }\
  222. }\
  223. menu_item++;\
  224. } while(0)
  225. */
  226. #if (SDCARDDETECT > 0)
  227. bool lcd_oldcardstatus;
  228. #endif
  229. uint8_t selected_sheet = 0;
  230. bool ignore_click = false;
  231. bool wait_for_unclick;
  232. // place-holders for Ki and Kd edits
  233. #ifdef PIDTEMP
  234. // float raw_Ki, raw_Kd;
  235. #endif
  236. bool bMain; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  237. bool bSettings; // flag (i.e. 'fake parameter') for 'lcd_hw_setup_menu()' function
  238. const char STR_SEPARATOR[] PROGMEM = "------------";
  239. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* longFilename)
  240. {
  241. uint8_t len = LCD_WIDTH - 1;
  242. lcd_set_cursor(0, row);
  243. lcd_print((lcd_encoder == menu_item)?'>':' ');
  244. lcd_print_pad(longFilename, len);
  245. }
  246. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* longFilename)
  247. {
  248. uint8_t len = LCD_WIDTH - 2;
  249. lcd_set_cursor(0, row);
  250. lcd_print((lcd_encoder == menu_item)?'>':' ');
  251. lcd_print(LCD_STR_FOLDER[0]);
  252. lcd_print_pad(longFilename, len);
  253. }
  254. #define MENU_ITEM_SDDIR(str_fn, str_fnl) do { if (menu_item_sddir(str_fn, str_fnl)) return; } while (0)
  255. #define MENU_ITEM_SDFILE(str_fn, str_fnl) do { if (menu_item_sdfile(str_fn, str_fnl)) return; } while (0)
  256. uint8_t menu_item_sddir(const char* str_fn, char* str_fnl)
  257. {
  258. if (menu_item == menu_line)
  259. {
  260. if (lcd_draw_update)
  261. {
  262. lcd_implementation_drawmenu_sddirectory(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl);
  263. }
  264. if (menu_clicked && (lcd_encoder == menu_item))
  265. {
  266. menu_clicked = false;
  267. lcd_consume_click();
  268. lcd_update_enabled = false;
  269. menu_action_sddirectory(str_fn);
  270. lcd_update_enabled = true;
  271. return menu_item_ret();
  272. }
  273. }
  274. menu_item++;
  275. return 0;
  276. }
  277. static uint8_t menu_item_sdfile(const char* str_fn, char* str_fnl)
  278. {
  279. if (menu_item == menu_line)
  280. {
  281. if (lcd_draw_update)
  282. {
  283. lcd_implementation_drawmenu_sdfile(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl);
  284. }
  285. if (menu_clicked && (lcd_encoder == menu_item))
  286. {
  287. menu_clicked = false;
  288. lcd_consume_click();
  289. lcd_update_enabled = false;
  290. menu_action_sdfile(str_fn);
  291. lcd_update_enabled = true;
  292. return menu_item_ret();
  293. }
  294. }
  295. menu_item++;
  296. return 0;
  297. }
  298. // Print temperature (nozzle/bed) (9 chars total)
  299. void lcdui_print_temp(char type, int val_current, int val_target)
  300. {
  301. int chars = lcd_printf_P(_N("%c%3d/%d%c"), type, val_current, val_target, LCD_STR_DEGREE[0]);
  302. lcd_space(9 - chars);
  303. }
  304. // Print Z-coordinate (8 chars total)
  305. void lcdui_print_Z_coord(void)
  306. {
  307. if (custom_message_type == CustomMsg::MeshBedLeveling)
  308. lcd_puts_P(_N("Z --- "));
  309. else
  310. lcd_printf_P(_N("Z%6.2f%c"), current_position[Z_AXIS], axis_known_position[Z_AXIS]?' ':'?');
  311. }
  312. #ifdef PLANNER_DIAGNOSTICS
  313. // Print planner diagnostics (8 chars total)
  314. void lcdui_print_planner_diag(void)
  315. {
  316. lcd_set_cursor(LCD_WIDTH - 8-2, 1);
  317. lcd_print(LCD_STR_FEEDRATE[0]);
  318. lcd_print(itostr3(feedmultiply));
  319. lcd_puts_P(PSTR("% Q"));
  320. {
  321. uint8_t queue = planner_queue_min();
  322. if (queue < (BLOCK_BUFFER_SIZE >> 1))
  323. lcd_putc('!');
  324. else
  325. {
  326. lcd_putc((char)(queue / 10) + '0');
  327. queue %= 10;
  328. }
  329. lcd_putc((char)queue + '0');
  330. planner_queue_min_reset();
  331. }
  332. }
  333. #endif // PLANNER_DIAGNOSTICS
  334. // Print feedrate (8 chars total)
  335. void lcdui_print_feedrate(void)
  336. {
  337. int chars = lcd_printf_P(_N("%c%3d%%"), LCD_STR_FEEDRATE[0], feedmultiply);
  338. lcd_space(8 - chars);
  339. }
  340. // Print percent done in form "USB---%", " SD---%", " ---%" (7 chars total)
  341. void lcdui_print_percent_done(void)
  342. {
  343. const char* src = usb_timer.running()?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" "));
  344. char per[4];
  345. bool num = IS_SD_PRINTING || (printer_active() && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT));
  346. if (!num || heating_status != HeatingStatus::NO_HEATING) // either not printing or heating
  347. {
  348. const int8_t sheetNR = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  349. const int8_t nextSheet = eeprom_next_initialized_sheet(sheetNR);
  350. if ((nextSheet >= 0) && (sheetNR != nextSheet))
  351. {
  352. char sheet[8];
  353. eeprom_read_block(sheet, EEPROM_Sheets_base->s[sheetNR].name, 7);
  354. sheet[7] = '\0';
  355. lcd_printf_P(PSTR("%-7s"),sheet);
  356. return; //do not also print the percentage
  357. }
  358. }
  359. sprintf_P(per, num?_N("%3d"):_N("---"), calc_percent_done());
  360. lcd_printf_P(_N("%3S%3s%%"), src, per);
  361. }
  362. // Print extruder status (5 chars total)
  363. // Scenario 1: "F?"
  364. // There is no filament loaded and no tool change is in progress
  365. // Scenario 2: "F[nr.]"
  366. // [nr.] ranges from 1 to 5.
  367. // Shows which filament is loaded. No tool change is in progress
  368. // Scenario 3: "?>[nr.]"
  369. // [nr.] ranges from 1 to 5.
  370. // There is no filament currently loaded, but [nr.] is currently being loaded via tool change
  371. // Scenario 4: "[nr1.] > [nr2.]"
  372. // [nr1.] ranges from 1 to 5.
  373. // [nr2.] ranges from 1 to 5.
  374. // Filament [nr1.] was loaded, but [nr2.] is currently being loaded via tool change
  375. uint8_t lcdui_print_extruder(void) {
  376. uint8_t chars = 0;
  377. if (MMU2::mmu2.get_current_tool() == MMU2::mmu2.get_tool_change_tool()) {
  378. if (MMU2::mmu2.get_current_tool() == (uint8_t)MMU2::FILAMENT_UNKNOWN) {
  379. chars = lcd_printf_P(_N(" F?"));
  380. } else {
  381. chars = lcd_printf_P(_N(" F%u"), MMU2::mmu2.get_current_tool() + 1);
  382. }
  383. } else {
  384. if (MMU2::mmu2.get_current_tool() == (uint8_t)MMU2::FILAMENT_UNKNOWN) {
  385. chars = lcd_printf_P(_N(" ?>%u"), MMU2::mmu2.get_tool_change_tool() + 1);
  386. } else {
  387. chars = lcd_printf_P(_N(" %u>%u"), MMU2::mmu2.get_current_tool() + 1, MMU2::mmu2.get_tool_change_tool() + 1);
  388. }
  389. }
  390. return chars;
  391. }
  392. // Print farm number (5 chars total)
  393. static void lcdui_print_farm(void)
  394. {
  395. lcd_printf_P(_N(" FRM "));
  396. }
  397. #ifdef CMD_DIAGNOSTICS
  398. // Print CMD queue diagnostic (8 chars total)
  399. void lcdui_print_cmd_diag(void)
  400. {
  401. lcd_set_cursor(LCD_WIDTH - 8 -1, 2);
  402. lcd_puts_P(PSTR(" C"));
  403. lcd_print(buflen); // number of commands in cmd buffer
  404. if (buflen < 9) lcd_print(' ');
  405. }
  406. #endif //CMD_DIAGNOSTICS
  407. // Print time (8 chars total)
  408. void lcdui_print_time(void)
  409. {
  410. //if remaining print time estimation is available print it else print elapsed time
  411. int chars = 0;
  412. if (printer_active()) {
  413. uint16_t print_t = PRINT_TIME_REMAINING_INIT;
  414. uint16_t print_tr = PRINT_TIME_REMAINING_INIT;
  415. uint16_t print_tc = PRINT_TIME_REMAINING_INIT;
  416. char suff = ' ';
  417. char suff_doubt = ' ';
  418. #ifdef TMC2130
  419. if (SilentModeMenu != SILENT_MODE_OFF) {
  420. if (print_time_remaining_silent != PRINT_TIME_REMAINING_INIT)
  421. print_tr = print_time_remaining_silent;
  422. //#ifdef CLOCK_INTERVAL_TIME
  423. if (print_time_to_change_silent != PRINT_TIME_REMAINING_INIT)
  424. print_tc = print_time_to_change_silent;
  425. //#endif //CLOCK_INTERVAL_TIME
  426. } else {
  427. #endif //TMC2130
  428. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)
  429. print_tr = print_time_remaining_normal;
  430. //#ifdef CLOCK_INTERVAL_TIME
  431. if (print_time_to_change_normal != PRINT_TIME_REMAINING_INIT)
  432. print_tc = print_time_to_change_normal;
  433. //#endif //CLOCK_INTERVAL_TIME
  434. #ifdef TMC2130
  435. }
  436. #endif //TMC2130
  437. //#ifdef CLOCK_INTERVAL_TIME
  438. if (clock_interval == CLOCK_INTERVAL_TIME*2)
  439. clock_interval = 0;
  440. clock_interval++;
  441. if (print_tc != PRINT_TIME_REMAINING_INIT && clock_interval > CLOCK_INTERVAL_TIME) {
  442. print_t = print_tc;
  443. suff = 'C';
  444. } else
  445. //#endif //CLOCK_INTERVAL_TIME
  446. if (print_tr != PRINT_TIME_REMAINING_INIT) {
  447. print_t = print_tr;
  448. suff = 'R';
  449. } else
  450. print_t = _millis() / 60000 - starttime / 60000;
  451. if (feedmultiply != 100 && (print_t == print_tr || print_t == print_tc)) {
  452. suff_doubt = '?';
  453. print_t = 100ul * print_t / feedmultiply;
  454. }
  455. if (print_t < 6000) //time<100h
  456. chars = lcd_printf_P(_N("%c%02u:%02u%c%c"), LCD_STR_CLOCK[0], print_t / 60, print_t % 60, suff, suff_doubt);
  457. else //time>=100h
  458. chars = lcd_printf_P(_N("%c%3uh %c%c"), LCD_STR_CLOCK[0], print_t / 60, suff, suff_doubt);
  459. }
  460. else
  461. chars = lcd_printf_P(_N("%c--:-- "), LCD_STR_CLOCK[0]);
  462. lcd_space(8 - chars);
  463. }
  464. //! @Brief Print status line on status screen
  465. void lcdui_print_status_line(void) {
  466. if (heating_status != HeatingStatus::NO_HEATING) { // If heating flag, show progress of heating
  467. heating_status_counter++;
  468. if (heating_status_counter > 13) {
  469. heating_status_counter = 0;
  470. }
  471. lcd_set_cursor(7, 3);
  472. lcd_space(13);
  473. for (uint8_t dots = 0; dots < heating_status_counter; dots++) {
  474. lcd_putc_at(7 + dots, 3, '.');
  475. }
  476. switch (heating_status) {
  477. case HeatingStatus::EXTRUDER_HEATING:
  478. lcd_puts_at_P(0, 3, _T(MSG_HEATING));
  479. break;
  480. case HeatingStatus::EXTRUDER_HEATING_COMPLETE:
  481. lcd_puts_at_P(0, 3, _T(MSG_HEATING_COMPLETE));
  482. heating_status = HeatingStatus::NO_HEATING;
  483. heating_status_counter = 0;
  484. break;
  485. case HeatingStatus::BED_HEATING:
  486. lcd_puts_at_P(0, 3, _T(MSG_BED_HEATING));
  487. break;
  488. case HeatingStatus::BED_HEATING_COMPLETE:
  489. lcd_puts_at_P(0, 3, _T(MSG_BED_DONE));
  490. heating_status = HeatingStatus::NO_HEATING;
  491. heating_status_counter = 0;
  492. break;
  493. default:
  494. break;
  495. }
  496. }
  497. else if ((IS_SD_PRINTING) &&
  498. (custom_message_type == CustomMsg::Status) &&
  499. (lcd_status_message_level <= LCD_STATUS_INFO) &&
  500. lcd_status_message_timeout.expired_cont(LCD_STATUS_INFO_TIMEOUT))
  501. {
  502. // If printing from SD, show what we are printing
  503. const char* longFilenameOLD = (card.longFilename[0] ? card.longFilename : card.filename);
  504. if( lcd_print_pad(&longFilenameOLD[scrollstuff], LCD_WIDTH) )
  505. {
  506. scrollstuff++;
  507. } else {
  508. scrollstuff = 0;
  509. }
  510. } else { // Otherwise check for other special events
  511. switch (custom_message_type) {
  512. case CustomMsg::M117: // M117 Set the status line message on the LCD
  513. case CustomMsg::Status: // Nothing special, print status message normally
  514. case CustomMsg::M0Wait: // M0/M1 Wait command working even from SD
  515. case CustomMsg::FilamentLoading: // If loading filament, print status
  516. case CustomMsg::MMUProgress: // MMU Progress Codes
  517. lcd_print_pad(lcd_status_message, LCD_WIDTH);
  518. break;
  519. case CustomMsg::MeshBedLeveling: // If mesh bed leveling in progress, show the status
  520. if (custom_message_state > 10) {
  521. lcd_set_cursor(0, 3);
  522. lcd_space(LCD_WIDTH);
  523. lcd_puts_at_P(0, 3, _T(MSG_CALIBRATE_Z_AUTO));
  524. lcd_puts_P(PSTR(" : "));
  525. lcd_print(custom_message_state - 10);
  526. } else {
  527. if (custom_message_state == 3) {
  528. lcd_setstatuspgm(MSG_WELCOME);
  529. custom_message_type = CustomMsg::Status;
  530. }
  531. if (custom_message_state > 3 && custom_message_state <= 10) {
  532. lcd_set_cursor(0, 3);
  533. lcd_space(19);
  534. lcd_puts_at_P(0, 3, _i("Calibration done")); ////MSG_HOMEYZ_DONE c=20
  535. custom_message_state--;
  536. }
  537. }
  538. break;
  539. case CustomMsg::PidCal: // PID tuning in progress
  540. lcd_print_pad(lcd_status_message, LCD_WIDTH);
  541. if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0) {
  542. lcd_set_cursor(10, 3);
  543. lcd_print(itostr3(pid_cycle));
  544. lcd_print('/');
  545. lcd_print(itostr3left(pid_number_of_cycles));
  546. }
  547. break;
  548. case CustomMsg::TempCal: // PINDA temp calibration in progress
  549. lcd_set_cursor(0, 3);
  550. lcd_printf_P(PSTR("%-12.12S%-d/6"), _T(MSG_PINDA_CALIBRATION), custom_message_state);
  551. break;
  552. case CustomMsg::TempCompPreheat: // temp compensation preheat
  553. lcd_puts_at_P(0, 3, _i("PINDA Heating")); ////MSG_PINDA_PREHEAT c=20
  554. if (custom_message_state <= PINDA_HEAT_T) {
  555. lcd_puts_P(PSTR(": "));
  556. lcd_print(custom_message_state); // seconds
  557. lcd_print(' ');
  558. }
  559. break;
  560. case CustomMsg::Resuming: // Resuming
  561. lcd_puts_at_P(0, 3, _T(MSG_RESUMING_PRINT));
  562. break;
  563. }
  564. }
  565. }
  566. //! @brief Show Status Screen
  567. //!
  568. //! @code{.unparsed}
  569. //! |01234567890123456789|
  570. //! |N 000/000D Z000.0 |
  571. //! |B 000/000D F100% |
  572. //! |USB100% T0 t--:-- |
  573. //! |Status line.........|
  574. //! ----------------------
  575. //! N - nozzle temp symbol LCD_STR_THERMOMETER
  576. //! D - Degree sysmbol LCD_STR_DEGREE
  577. //! B - bed temp symbol LCD_STR_BEDTEMP
  578. //! F - feedrate symbol LCD_STR_FEEDRATE
  579. //! t - clock symbol LCD_STR_THERMOMETER
  580. //! @endcode
  581. void lcdui_print_status_screen(void)
  582. {
  583. lcd_set_cursor(0, 0); //line 0
  584. //Print the hotend temperature (9 chars total)
  585. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  586. lcd_space(3); //3 spaces
  587. //Print Z-coordinate (8 chars total)
  588. lcdui_print_Z_coord();
  589. lcd_set_cursor(0, 1); //line 1
  590. //Print the Bed temperature (9 chars total)
  591. lcdui_print_temp(LCD_STR_BEDTEMP[0], (int)(degBed() + 0.5), (int)(degTargetBed() + 0.5));
  592. lcd_space(3); //3 spaces
  593. #ifdef PLANNER_DIAGNOSTICS
  594. //Print planner diagnostics (8 chars)
  595. lcdui_print_planner_diag();
  596. #else // PLANNER_DIAGNOSTICS
  597. //Print Feedrate (8 chars)
  598. lcdui_print_feedrate();
  599. #endif // PLANNER_DIAGNOSTICS
  600. lcd_set_cursor(0, 2); //line 2
  601. //Print SD status (7 chars)
  602. lcdui_print_percent_done();
  603. if (MMU2::mmu2.Enabled()) {
  604. // Print extruder status (5 chars)
  605. lcd_space(5 - lcdui_print_extruder());
  606. } else if (farm_mode) {
  607. // Print farm number (5 chars)
  608. lcdui_print_farm();
  609. } else {
  610. lcd_space(5); // 5 spaces
  611. }
  612. #ifdef CMD_DIAGNOSTICS
  613. //Print cmd queue diagnostics (8chars)
  614. lcdui_print_cmd_diag();
  615. #else
  616. //Print time (8chars)
  617. lcdui_print_time();
  618. #endif //CMD_DIAGNOSTICS
  619. lcd_set_cursor(0, 3); //line 3
  620. #ifndef DEBUG_DISABLE_LCD_STATUS_LINE
  621. lcdui_print_status_line();
  622. #endif //DEBUG_DISABLE_LCD_STATUS_LINE
  623. }
  624. // Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent
  625. void lcd_status_screen() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  626. {
  627. static uint8_t lcd_status_update_delay = 0;
  628. #ifdef ULTIPANEL_FEEDMULTIPLY
  629. // Dead zone at 100% feedrate
  630. if ((feedmultiply < 100 && (feedmultiply + int(lcd_encoder)) > 100) ||
  631. (feedmultiply > 100 && (feedmultiply + int(lcd_encoder)) < 100))
  632. {
  633. lcd_encoder = 0;
  634. feedmultiply = 100;
  635. }
  636. if (feedmultiply == 100 && int(lcd_encoder) > ENCODER_FEEDRATE_DEADZONE)
  637. {
  638. feedmultiply += int(lcd_encoder) - ENCODER_FEEDRATE_DEADZONE;
  639. lcd_encoder = 0;
  640. }
  641. else if (feedmultiply == 100 && int(lcd_encoder) < -ENCODER_FEEDRATE_DEADZONE)
  642. {
  643. feedmultiply += int(lcd_encoder) + ENCODER_FEEDRATE_DEADZONE;
  644. lcd_encoder = 0;
  645. }
  646. else if (feedmultiply != 100)
  647. {
  648. feedmultiply += int(lcd_encoder);
  649. lcd_encoder = 0;
  650. }
  651. #endif //ULTIPANEL_FEEDMULTIPLY
  652. if (feedmultiply < 10)
  653. feedmultiply = 10;
  654. else if (feedmultiply > 999)
  655. feedmultiply = 999;
  656. if (lcd_draw_update) {
  657. // Update the status screen immediately
  658. lcd_status_update_delay = 0;
  659. }
  660. if (lcd_status_update_delay)
  661. lcd_status_update_delay--;
  662. else
  663. { // Redraw the main screen every second (see LCD_UPDATE_INTERVAL).
  664. // This is easier then trying keep track of all things that change on the screen
  665. lcd_status_update_delay = 10;
  666. ReInitLCD++;
  667. if (ReInitLCD == 30)
  668. {
  669. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  670. ReInitLCD = 0 ;
  671. }
  672. else
  673. {
  674. if ((ReInitLCD % 10) == 0)
  675. lcd_refresh_noclear(); //to maybe revive the LCD if static electricity killed it.
  676. }
  677. lcdui_print_status_screen();
  678. prusa_statistics_update_from_status_screen();
  679. if (lcd_commands_type != LcdCommands::Idle)
  680. lcd_commands();
  681. }
  682. bool current_click = LCD_CLICKED;
  683. if (ignore_click)
  684. {
  685. if (wait_for_unclick)
  686. {
  687. if (!current_click)
  688. ignore_click = wait_for_unclick = false;
  689. else
  690. current_click = false;
  691. }
  692. else if (current_click)
  693. {
  694. lcd_quick_feedback();
  695. wait_for_unclick = true;
  696. current_click = false;
  697. }
  698. }
  699. if (current_click
  700. && ( menu_block_mask == MENU_BLOCK_NONE ) // or a serious error blocks entering the menu
  701. )
  702. {
  703. menu_depth = 0; //redundant, as already done in lcd_return_to_status(), just to be sure
  704. menu_submenu(lcd_main_menu);
  705. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  706. }
  707. }
  708. void print_stop();
  709. void lcd_commands()
  710. {
  711. if (planner_aborted) {
  712. // we are still within an aborted command. do not process any LCD command until we return
  713. return;
  714. }
  715. if (lcd_commands_type == LcdCommands::StopPrint)
  716. {
  717. if (!blocks_queued() && !homing_flag)
  718. {
  719. custom_message_type = CustomMsg::Status;
  720. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  721. lcd_commands_type = LcdCommands::Idle;
  722. lcd_commands_step = 0;
  723. print_stop();
  724. }
  725. }
  726. if (lcd_commands_type == LcdCommands::LongPause)
  727. {
  728. if (!blocks_queued() && !homing_flag)
  729. {
  730. if (custom_message_type != CustomMsg::M117)
  731. {
  732. custom_message_type = CustomMsg::Status;
  733. lcd_setstatuspgm(_i("Print paused"));////MSG_PRINT_PAUSED c=20
  734. }
  735. lcd_commands_type = LcdCommands::Idle;
  736. lcd_commands_step = 0;
  737. long_pause();
  738. }
  739. }
  740. if (lcd_commands_type == LcdCommands::Layer1Cal)
  741. {
  742. char cmd1[30];
  743. if(lcd_commands_step>1) lcd_timeoutToStatus.start(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  744. if (!blocks_queued() && cmd_buffer_empty() && !saved_printing)
  745. {
  746. switch(lcd_commands_step)
  747. {
  748. case 0:
  749. lcd_commands_step = 11;
  750. break;
  751. case 11:
  752. lay1cal_wait_preheat();
  753. lcd_commands_step = 10;
  754. break;
  755. case 10:
  756. lay1cal_load_filament(cmd1, lay1cal_filament);
  757. lcd_commands_step = 9;
  758. break;
  759. case 9:
  760. lcd_clear();
  761. menu_depth = 0;
  762. menu_submenu(lcd_babystep_z);
  763. lay1cal_intro_line();
  764. lcd_commands_step = 8;
  765. break;
  766. case 8:
  767. lay1cal_before_meander();
  768. lcd_commands_step = 7;
  769. break;
  770. case 7:
  771. lay1cal_meander(cmd1);
  772. lcd_commands_step = 6;
  773. break;
  774. case 6:
  775. for (uint8_t i = 0; i < 4; i++)
  776. {
  777. lay1cal_square(cmd1, i);
  778. }
  779. lcd_commands_step = 5;
  780. break;
  781. case 5:
  782. for (uint8_t i = 4; i < 8; i++)
  783. {
  784. lay1cal_square(cmd1, i);
  785. }
  786. lcd_commands_step = 4;
  787. break;
  788. case 4:
  789. for (uint8_t i = 8; i < 12; i++)
  790. {
  791. lay1cal_square(cmd1, i);
  792. }
  793. lcd_commands_step = 3;
  794. break;
  795. case 3:
  796. for (uint8_t i = 12; i < 16; i++)
  797. {
  798. lay1cal_square(cmd1, i);
  799. }
  800. lcd_commands_step = 2;
  801. break;
  802. case 2:
  803. enquecommand_P(PSTR("M107")); //turn off printer fan
  804. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000")); //retract
  805. enquecommand_P(PSTR("M104 S0")); // turn off temperature
  806. enquecommand_P(PSTR("M140 S0")); // turn off heatbed
  807. enquecommand_P(PSTR("G1 Z10 F1300.000")); //lift Z
  808. enquecommand_P(PSTR("G1 X10 Y180 F4000")); //Go to parking position
  809. if (MMU2::mmu2.Enabled()) enquecommand_P(PSTR("M702")); //unload from nozzle
  810. enquecommand_P(PSTR("M84"));// disable motors
  811. lcd_return_to_status(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  812. lcd_commands_step = 1;
  813. break;
  814. case 1:
  815. lcd_setstatuspgm(MSG_WELCOME);
  816. lcd_commands_step = 0;
  817. lcd_commands_type = LcdCommands::Idle;
  818. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1)
  819. {
  820. lcd_wizard(WizState::RepeatLay1Cal);
  821. }
  822. break;
  823. }
  824. }
  825. }
  826. if (lcd_commands_type == LcdCommands::PidExtruder) {
  827. char cmd1[30];
  828. if (lcd_commands_step == 0) {
  829. custom_message_type = CustomMsg::PidCal;
  830. custom_message_state = 1;
  831. lcd_draw_update = 3;
  832. lcd_commands_step = 3;
  833. }
  834. if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
  835. preparePidTuning(); // ensure we don't move to the next step early
  836. sprintf_P(cmd1, PSTR("M303 E0 S%3u"), pid_temp);
  837. // setting the correct target temperature (for visualization) is done in PID_autotune
  838. enquecommand(cmd1);
  839. lcd_setstatuspgm(_i("PID cal."));////MSG_PID_RUNNING c=20
  840. lcd_commands_step = 2;
  841. }
  842. if (lcd_commands_step == 2 && !pidTuningRunning()) { //saving to eeprom
  843. custom_message_state = 0;
  844. lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20
  845. setAllTargetHotends(0); // reset all hotends temperature including the number displayed on the main screen
  846. if (_Kp != 0 || _Ki != 0 || _Kd != 0) {
  847. sprintf_P(cmd1, PSTR("M301 P%.2f I%.2f D%.2f"), _Kp, _Ki, _Kd);
  848. enquecommand(cmd1);
  849. enquecommand_P(PSTR("M500"));
  850. }
  851. else {
  852. SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
  853. }
  854. display_time.start();
  855. lcd_commands_step = 1;
  856. }
  857. if ((lcd_commands_step == 1) && display_time.expired(2000)) { //calibration finished message
  858. lcd_setstatuspgm(MSG_WELCOME);
  859. custom_message_type = CustomMsg::Status;
  860. pid_temp = DEFAULT_PID_TEMP;
  861. lcd_commands_step = 0;
  862. lcd_commands_type = LcdCommands::Idle;
  863. }
  864. }
  865. #ifdef TEMP_MODEL
  866. if (lcd_commands_type == LcdCommands::TempModel) {
  867. if (lcd_commands_step == 0) {
  868. lcd_commands_step = 3;
  869. }
  870. if (lcd_commands_step == 3) {
  871. enquecommand_P(PSTR("M310 A F0"));
  872. lcd_commands_step = 2;
  873. }
  874. if (lcd_commands_step ==2 && temp_model_valid()) {
  875. enquecommand_P(PSTR("M310 S1"));
  876. lcd_commands_step = 1;
  877. }
  878. //if (lcd_commands_step == 1 && calibrated()) {
  879. if (lcd_commands_step == 1 && temp_model_valid()) {
  880. enquecommand_P(PSTR("M500"));
  881. lcd_commands_step = 0;
  882. lcd_commands_type = LcdCommands::Idle;
  883. }
  884. }
  885. #endif //TEMP_MODEL
  886. }
  887. void lcd_return_to_status()
  888. {
  889. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  890. menu_goto(lcd_status_screen, 0, false, true);
  891. menu_depth = 0;
  892. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  893. }
  894. //! @brief Pause print, disable nozzle heater, move to park position, send host action "paused"
  895. void lcd_pause_print()
  896. {
  897. stop_and_save_print_to_ram(0.0, -default_retraction);
  898. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_PAUSED);
  899. isPrintPaused = true;
  900. // return to status is required to continue processing in the main loop!
  901. lcd_commands_type = LcdCommands::LongPause;
  902. lcd_return_to_status();
  903. }
  904. //! @brief Send host action "pause"
  905. void lcd_pause_usb_print()
  906. {
  907. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_ASK_PAUSE);
  908. }
  909. static void lcd_move_menu_axis();
  910. /* Menu implementation */
  911. static void lcd_cooldown()
  912. {
  913. setAllTargetHotends(0);
  914. setTargetBed(0);
  915. fanSpeed = 0;
  916. lcd_return_to_status();
  917. }
  918. //! @brief append text label with a colon and format it into a fixed size output buffer
  919. //! It would have been much easier if there was a ':' in the labels.
  920. //! But since the texts like Bed, Nozzle and PINDA are used in other places
  921. //! it is better to reuse these texts even though it requires some extra formatting code.
  922. //! @param [in] ipgmLabel pointer to string in PROGMEM
  923. //! @param [out] pointer to string in RAM which will receive the formatted text. Must be allocated to appropriate size
  924. //! @param [in] dstSize allocated length of dst
  925. static void pgmtext_with_colon(const char *ipgmLabel, char *dst, uint8_t dstSize){
  926. uint8_t i = 0;
  927. for(; i < dstSize - 2; ++i){ // 2 byte less than buffer, we'd be adding a ':' to the end
  928. uint8_t b = pgm_read_byte(ipgmLabel + i);
  929. if( ! b )
  930. break;
  931. dst[i] = b;
  932. }
  933. dst[i] = ':'; // append the colon
  934. ++i;
  935. for(; i < dstSize - 1; ++i) // fill the rest with spaces
  936. dst[i] = ' ';
  937. dst[dstSize-1] = '\0'; // terminate the string properly
  938. }
  939. //! @brief Show Extruder Info
  940. //!
  941. //! @code{.unparsed}
  942. //! |01234567890123456789|
  943. //! |Hotend fan: 0000| MSG_HOTEND_FAN_SPEED c=15
  944. //! |Print fan: 0000| MSG_PRINT_FAN_SPEED c=15
  945. //! | |
  946. //! | |
  947. //! ----------------------
  948. //! @endcode
  949. void lcd_menu_extruder_info() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  950. {
  951. lcd_timeoutToStatus.stop(); //infinite timeout
  952. lcd_home();
  953. lcd_printf_P(PSTR("%-15.15S%-5d\n" "%-15.15S%-5d\n"), _T(MSG_HOTEND_FAN_SPEED), 60*fan_speed[0], _T(MSG_PRINT_FAN_SPEED), 60*fan_speed[1] );
  954. menu_back_if_clicked();
  955. }
  956. static uint16_t __attribute__((noinline)) clamp999(uint16_t v){
  957. return v > 999 ? 999 : v;
  958. }
  959. //! @brief Show Fails Statistics MMU
  960. //!
  961. //! @code{.unparsed}
  962. //! |01234567890123456789|
  963. //! | Main | MSG_MAIN c=18
  964. //! | Last print | MSG_LAST_PRINT c=18
  965. //! | Total | MSG_TOTAL c=6
  966. //! | |
  967. //! ----------------------
  968. //! @endcode
  969. static void lcd_menu_fails_stats_mmu()
  970. {
  971. MENU_BEGIN();
  972. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  973. MENU_ITEM_SUBMENU_P(_T(MSG_LAST_PRINT), lcd_menu_fails_stats_mmu_print);
  974. MENU_ITEM_SUBMENU_P(_T(MSG_TOTAL), lcd_menu_fails_stats_mmu_total);
  975. MENU_ITEM_SUBMENU_P(_O(PSTR("Toolchange count")), lcd_menu_toolchange_stats_mmu_total);
  976. MENU_END();
  977. }
  978. //! @brief Show Last Print Failures Statistics MMU
  979. //!
  980. //! @code{.unparsed}
  981. //! |01234567890123456789|
  982. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  983. //! | MMU fails 000| MSG_MMU_FAILS c=15
  984. //! | MMU load fails 000| MSG_MMU_LOAD_FAILS c=15
  985. //! | |
  986. //! ----------------------
  987. //! @endcode
  988. static void lcd_menu_fails_stats_mmu_print()
  989. {
  990. lcd_timeoutToStatus.stop(); //infinite timeout
  991. lcd_home();
  992. lcd_printf_P(PSTR("%S\n" " %-16.16S%-3d\n" " %-16.16S%-3d"),
  993. _T(MSG_LAST_PRINT_FAILURES),
  994. _T(MSG_MMU_FAILS), clamp999( eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL) ),
  995. _T(MSG_MMU_LOAD_FAILS), clamp999( eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL) ));
  996. menu_back_if_clicked_fb();
  997. }
  998. //! @brief Show Total Failures Statistics MMU
  999. //!
  1000. //! @code{.unparsed}
  1001. //! |01234567890123456789|
  1002. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1003. //! | MMU fails 000| MSG_MMU_FAILS c=15
  1004. //! | MMU load fails 000| MSG_MMU_LOAD_FAILS c=15
  1005. //! | MMU power fails 000| MSG_MMU_POWER_FAILS c=15
  1006. //! ----------------------
  1007. //! @endcode
  1008. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1009. static void lcd_menu_fails_stats_mmu_total()
  1010. {
  1011. typedef struct
  1012. {
  1013. bool initialized; // 1byte
  1014. } _menu_data_t;
  1015. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1016. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1017. if(_md->initialized) {
  1018. MMU2::mmu2.get_statistics();
  1019. lcd_timeoutToStatus.stop(); //infinite timeout
  1020. _md->initialized = false;
  1021. }
  1022. lcd_home();
  1023. lcd_printf_P(PSTR("%S\n" " %-16.16S%-3d\n"/* " %-16.16S%-3d\n" " %-16.16S%-3d"*/),
  1024. _T(MSG_TOTAL_FAILURES),
  1025. _T(MSG_MMU_FAILS), clamp999( MMU2::mmu2.TotalFailStatistics() ));//,
  1026. //_T(MSG_MMU_LOAD_FAILS), clamp999( eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT) ),
  1027. //_i("MMU power fails"), clamp999( mmu_power_failures )); ////MSG_MMU_POWER_FAILS c=15
  1028. if (lcd_clicked())
  1029. {
  1030. lcd_quick_feedback();
  1031. menu_back();
  1032. }
  1033. }
  1034. //! @brief Show Total Failures Statistics MMU
  1035. //!
  1036. //! @code{.unparsed}
  1037. //! |01234567890123456789|
  1038. //! |Toolchange count: |
  1039. //! | 4294967295|
  1040. //! | |
  1041. //! | |
  1042. //! ----------------------
  1043. //! @endcode
  1044. static void lcd_menu_toolchange_stats_mmu_total()
  1045. {
  1046. typedef struct
  1047. {
  1048. bool initialized; // 1byte
  1049. } _menu_data_t;
  1050. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1051. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1052. if(_md->initialized) {
  1053. lcd_set_cursor(0, 0);
  1054. lcd_puts_P(PSTR("Toolchange count:"));
  1055. lcd_set_cursor(10, 1);
  1056. lcd_print(eeprom_read_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT));
  1057. _md->initialized = false;
  1058. }
  1059. menu_back_if_clicked_fb();
  1060. }
  1061. #if defined(TMC2130) && defined(FILAMENT_SENSOR)
  1062. static const char failStatsFmt[] PROGMEM = "%S\n" " %-16.16S%-3d\n" " %-16.16S%-3d\n" " %-7.7SX %-3d Y %-3d";
  1063. //! @brief Show Total Failures Statistics MMU
  1064. //!
  1065. //! @code{.unparsed}
  1066. //! |01234567890123456789|
  1067. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1068. //! | Power failures 000| MSG_POWER_FAILURES c=15
  1069. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1070. //! | Crash X:000 Y:000| MSG_CRASH c=7
  1071. //! ----------------------
  1072. //! @endcode
  1073. static void lcd_menu_fails_stats_total()
  1074. {
  1075. lcd_timeoutToStatus.stop(); //infinite timeout
  1076. lcd_home();
  1077. lcd_printf_P(failStatsFmt,
  1078. _T(MSG_TOTAL_FAILURES),
  1079. _T(MSG_POWER_FAILURES), clamp999( eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) ),
  1080. _T(MSG_FIL_RUNOUTS), clamp999( eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) ),
  1081. _T(MSG_CRASH),
  1082. clamp999( eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT) ),
  1083. clamp999( eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT) ));
  1084. menu_back_if_clicked_fb();
  1085. }
  1086. //! @brief Show Last Print Failures Statistics
  1087. //!
  1088. //! @code{.unparsed}
  1089. //! |01234567890123456789|
  1090. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1091. //! | Power failures 000| MSG_POWER_FAILURES c=15
  1092. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1093. //! | Crash X 000 Y 000| MSG_CRASH c=7
  1094. //! ----------------------
  1095. //! @endcode
  1096. //! @todo leptun refactor this piece of code please
  1097. static void lcd_menu_fails_stats_print()
  1098. {
  1099. lcd_timeoutToStatus.stop(); //infinite timeout
  1100. uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT);
  1101. uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1102. uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
  1103. uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y);
  1104. lcd_home();
  1105. lcd_printf_P(failStatsFmt,
  1106. _T(MSG_LAST_PRINT_FAILURES),
  1107. _T(MSG_POWER_FAILURES), power,
  1108. _T(MSG_FIL_RUNOUTS), filam,
  1109. _T(MSG_CRASH), crashX, crashY);
  1110. menu_back_if_clicked_fb();
  1111. }
  1112. //! @brief Open fail statistics menu
  1113. //!
  1114. //! This version of function is used, when there is filament sensor,
  1115. //! power failure and crash detection.
  1116. //! There are Last print and Total menu items.
  1117. //!
  1118. //! @code{.unparsed}
  1119. //! |01234567890123456789|
  1120. //! | Main | MSG_MAIN c=18
  1121. //! | Last print | MSG_LAST_PRINT c=18
  1122. //! | Total | MSG_TOTAL c=6
  1123. //! | |
  1124. //! ----------------------
  1125. //! @endcode
  1126. static void lcd_menu_fails_stats()
  1127. {
  1128. MENU_BEGIN();
  1129. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1130. MENU_ITEM_SUBMENU_P(_T(MSG_LAST_PRINT), lcd_menu_fails_stats_print);
  1131. MENU_ITEM_SUBMENU_P(_T(MSG_TOTAL), lcd_menu_fails_stats_total);
  1132. MENU_END();
  1133. }
  1134. #elif defined(FILAMENT_SENSOR)
  1135. static const char failStatsFmt[] PROGMEM = "%S\n" " %-16.16S%-3d\n" "%S\n" " %-16.16S%-3d\n";
  1136. //!
  1137. //! @brief Print last print and total filament run outs
  1138. //!
  1139. //! This version of function is used, when there is filament sensor,
  1140. //! but no other sensors (e.g. power failure, crash detection).
  1141. //!
  1142. //! Example screen:
  1143. //! @code{.unparsed}
  1144. //! |01234567890123456789|
  1145. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1146. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1147. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1148. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1149. //! ----------------------
  1150. //! @endcode
  1151. static void lcd_menu_fails_stats()
  1152. {
  1153. lcd_timeoutToStatus.stop(); //infinite timeout
  1154. uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1155. uint16_t filamentTotal = clamp999( eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) );
  1156. lcd_home();
  1157. lcd_printf_P(failStatsFmt,
  1158. _T(MSG_LAST_PRINT_FAILURES),
  1159. _T(MSG_FIL_RUNOUTS), filamentLast,
  1160. _T(MSG_TOTAL_FAILURES),
  1161. _T(MSG_FIL_RUNOUTS), filamentTotal);
  1162. menu_back_if_clicked();
  1163. }
  1164. #else
  1165. static void lcd_menu_fails_stats()
  1166. {
  1167. lcd_timeoutToStatus.stop(); //infinite timeout
  1168. MENU_BEGIN();
  1169. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1170. MENU_END();
  1171. }
  1172. #endif //TMC2130
  1173. #ifdef DEBUG_BUILD
  1174. #ifdef DEBUG_STACK_MONITOR
  1175. extern uint16_t SP_min;
  1176. extern char* __malloc_heap_start;
  1177. extern char* __malloc_heap_end;
  1178. #endif //DEBUG_STACK_MONITOR
  1179. //! @brief Show Debug Information
  1180. //!
  1181. //! @code{.unparsed}
  1182. //! |01234567890123456789|
  1183. //! |RAM statistics | c=20
  1184. //! | SP_min: 0000| c=14
  1185. //! | heap_start: 0000| c=14
  1186. //! | heap_end: 0000| c=14
  1187. //! ----------------------
  1188. //! @endcode
  1189. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1190. static void lcd_menu_debug()
  1191. {
  1192. #ifdef DEBUG_STACK_MONITOR
  1193. lcd_home();
  1194. lcd_printf_P(PSTR("RAM statistics\n" ////c=20
  1195. " SP_min: 0x%04x\n" ////c=14
  1196. " heap_start: 0x%04x\n" ////c=14
  1197. " heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end); ////c=14
  1198. #endif //DEBUG_STACK_MONITOR
  1199. menu_back_if_clicked_fb();
  1200. }
  1201. #endif /* DEBUG_BUILD */
  1202. //! @brief common line print for lcd_menu_temperatures
  1203. //! @param [in] ipgmLabel pointer to string in PROGMEM
  1204. //! @param [in] value to be printed behind the label
  1205. static void lcd_menu_temperatures_line(const char *ipgmLabel, int value){
  1206. static const size_t maxChars = 15;
  1207. char tmp[maxChars];
  1208. pgmtext_with_colon(ipgmLabel, tmp, maxChars);
  1209. lcd_printf_P(PSTR(" %s%3d\x01 \n"), tmp, value); // no need to add -14.14 to string alignment
  1210. }
  1211. //! @brief Show Temperatures
  1212. //!
  1213. //! @code{.unparsed}
  1214. //! |01234567890123456789|
  1215. //! | Nozzle: 000D| MSG_NOZZLE c=10
  1216. //! | Bed: 000D| MSG_BED c=13
  1217. //! | Ambient: 000D| MSG_AMBIENTc=14
  1218. //! | PINDA: 000D| MSG_PINDA c=14
  1219. //! ----------------------
  1220. //! D - Degree sysmbol LCD_STR_DEGREE
  1221. //! @endcode
  1222. static void lcd_menu_temperatures()
  1223. {
  1224. lcd_timeoutToStatus.stop(); //infinite timeout
  1225. lcd_home();
  1226. lcd_menu_temperatures_line( _T(MSG_NOZZLE), (int)current_temperature[0] );
  1227. lcd_menu_temperatures_line( _T(MSG_BED), (int)current_temperature_bed );
  1228. #ifdef AMBIENT_THERMISTOR
  1229. lcd_menu_temperatures_line( _i("Ambient"), (int)current_temperature_ambient ); ////MSG_AMBIENT c=14
  1230. #endif //AMBIENT_THERMISTOR
  1231. #ifdef PINDA_THERMISTOR
  1232. lcd_menu_temperatures_line(MSG_PINDA, (int)current_temperature_pinda ); ////MSG_PINDA
  1233. #endif //PINDA_THERMISTOR
  1234. menu_back_if_clicked();
  1235. }
  1236. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || (defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG))
  1237. #define VOLT_DIV_R1 10000
  1238. #define VOLT_DIV_R2 2370
  1239. #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1))
  1240. //! @brief Show Voltages
  1241. //!
  1242. //! @code{.unparsed}
  1243. //! |01234567890123456789|
  1244. //! | |
  1245. //! | PWR: 00.0V | c=12
  1246. //! | Bed: 00.0V | c=12
  1247. //! | IR : 00.0V | c=12 optional
  1248. //! ----------------------
  1249. //! @endcode
  1250. static void lcd_menu_voltages()
  1251. {
  1252. lcd_timeoutToStatus.stop(); //infinite timeout
  1253. float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1254. float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1255. lcd_home();
  1256. lcd_printf_P(PSTR(" PWR: %4.1fV\n" " BED: %4.1fV"), volt_pwr, volt_bed);
  1257. #ifdef IR_SENSOR_ANALOG
  1258. lcd_printf_P(PSTR("\n IR : %3.1fV"), fsensor.Raw2Voltage(fsensor.getVoltRaw()));
  1259. #endif //IR_SENSOR_ANALOG
  1260. menu_back_if_clicked();
  1261. }
  1262. #endif //defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || defined(IR_SENSOR_ANALOG)
  1263. #ifdef TMC2130
  1264. //! @brief Show Belt Status
  1265. //!
  1266. //! @code{.unparsed}
  1267. //! |01234567890123456789|
  1268. //! | Belt status | c=18
  1269. //! | X: 000 |
  1270. //! | Y: 000 |
  1271. //! | |
  1272. //! ----------------------
  1273. //! @endcode
  1274. static void lcd_menu_belt_status()
  1275. {
  1276. lcd_home();
  1277. lcd_printf_P(PSTR("%S\n" " X %d\n" " Y %d"), _T(MSG_BELT_STATUS), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)));
  1278. menu_back_if_clicked();
  1279. }
  1280. #endif //TMC2130
  1281. #ifdef RESUME_DEBUG
  1282. extern void stop_and_save_print_to_ram(float z_move, float e_move);
  1283. extern void restore_print_from_ram_and_continue(float e_move);
  1284. static void lcd_menu_test_save()
  1285. {
  1286. stop_and_save_print_to_ram(10, -0.8);
  1287. }
  1288. static void lcd_menu_test_restore()
  1289. {
  1290. restore_print_from_ram_and_continue(0.8);
  1291. }
  1292. #endif //RESUME_DEBUG
  1293. //! @brief Show Preheat Menu
  1294. static void lcd_preheat_menu()
  1295. {
  1296. eFilamentAction = FilamentAction::Preheat;
  1297. lcd_generic_preheat_menu();
  1298. }
  1299. #ifdef MENU_DUMP
  1300. #include "xflash_dump.h"
  1301. static void lcd_dump_memory()
  1302. {
  1303. lcd_beeper_quick_feedback();
  1304. xfdump_dump();
  1305. lcd_return_to_status();
  1306. }
  1307. #endif //MENU_DUMP
  1308. #ifdef MENU_SERIAL_DUMP
  1309. #include "Dcodes.h"
  1310. static void lcd_serial_dump()
  1311. {
  1312. serial_dump_and_reset(dump_crash_reason::manual);
  1313. }
  1314. #endif //MENU_SERIAL_DUMP
  1315. #if defined(DEBUG_BUILD) && defined(EMERGENCY_HANDLERS)
  1316. #include <avr/wdt.h>
  1317. #ifdef WATCHDOG
  1318. static void lcd_wdr_crash()
  1319. {
  1320. while (1);
  1321. }
  1322. #endif
  1323. static uint8_t lcd_stack_crash_(uint8_t arg, uint32_t sp = 0)
  1324. {
  1325. // populate the stack with an increasing value for ease of testing
  1326. volatile uint16_t tmp __attribute__((unused)) = sp;
  1327. _delay(arg);
  1328. uint8_t ret = lcd_stack_crash_(arg, SP);
  1329. // required to avoid tail call elimination and to slow down the stack growth
  1330. _delay(ret);
  1331. return ret;
  1332. }
  1333. static void lcd_stack_crash()
  1334. {
  1335. #ifdef WATCHDOG
  1336. wdt_disable();
  1337. #endif
  1338. // delay choosen in order to hit the stack-check in the temperature isr reliably
  1339. lcd_stack_crash_(10);
  1340. }
  1341. #endif
  1342. #ifdef DEBUG_PULLUP_CRASH
  1343. void TestPullupCrash() {
  1344. PORTF |= 0x01;
  1345. }
  1346. #endif // DEBUG_PULLUP_CRASH
  1347. //! @brief Show Support Menu
  1348. //!
  1349. //! @code{.unparsed}
  1350. //! |01234567890123456789|
  1351. //! | Main | MSG_MAIN c=18
  1352. //! | Firmware: | c=18
  1353. //! | 3.7.2.-2363 | c=16
  1354. //! | prusa3d.com | MSG_PRUSA3D
  1355. //! | forum.prusa3d.com | MSG_PRUSA3D_FORUM
  1356. //! | help.prusa3d.com | MSG_PRUSA3D_HELP
  1357. //! | -------------- | STR_SEPARATOR
  1358. //! | 1_75mm_MK3 | FILAMENT_SIZE
  1359. //! | help.prusa3d.com | ELECTRONICS
  1360. //! | help.prusa3d.com | NOZZLE_TYPE
  1361. //! | -------------- | STR_SEPARATOR
  1362. //! | Date: | c=17
  1363. //! | MMM DD YYYY | __DATE__
  1364. //! | -------------- | STR_SEPARATOR
  1365. //! @endcode
  1366. //!
  1367. //! If MMU is connected
  1368. //!
  1369. //! @code{.unparsed}
  1370. //! | MMU2 connected | c=18
  1371. //! | FW: 1.0.6-7064523 |
  1372. //! @endcode
  1373. //!
  1374. //! If MMU is not connected
  1375. //!
  1376. //! @code{.unparsed}
  1377. //! | MMU2 N/A | c=18
  1378. //! @endcode
  1379. //!
  1380. //! If Flash Air is connected
  1381. //!
  1382. //! @code{.unparsed}
  1383. //! | -------------- | STR_SEPARATOR
  1384. //! | FlashAir IP Addr: | c=18
  1385. //! | 192.168.1.100 |
  1386. //! @endcode
  1387. //!
  1388. //! @code{.unparsed}
  1389. //! | -------------- | STR_SEPARATOR
  1390. //! | XYZ cal. details | MSG_XYZ_DETAILS c=18
  1391. //! | Extruder info | MSG_INFO_EXTRUDER
  1392. //! | XYZ cal. details | MSG_INFO_SENSORS
  1393. //! @endcode
  1394. //!
  1395. //! If TMC2130 defined
  1396. //!
  1397. //! @code{.unparsed}
  1398. //! | Belt status | MSG_BELT_STATUS
  1399. //! @endcode
  1400. //!
  1401. //! @code{.unparsed}
  1402. //! | Temperatures | MSG_MENU_TEMPERATURES
  1403. //! @endcode
  1404. //!
  1405. //! If Voltage Bed and PWR Pin are defined
  1406. //!
  1407. //! @code{.unparsed}
  1408. //! | Voltages | MSG_MENU_VOLTAGES
  1409. //! @endcode
  1410. //!
  1411. //!
  1412. //! If DEBUG_BUILD is defined
  1413. //!
  1414. //! @code{.unparsed}
  1415. //! | Debug | c=18
  1416. //! @endcode
  1417. //! ----------------------
  1418. //! @endcode
  1419. static void lcd_support_menu()
  1420. {
  1421. typedef struct
  1422. { // 22bytes total
  1423. int8_t status; // 1byte
  1424. bool is_flash_air; // 1byte
  1425. uint32_t ip; // 4bytes
  1426. char ip_str[IP4_STR_SIZE]; // 16bytes
  1427. } _menu_data_t;
  1428. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1429. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1430. if (_md->status == 0 || lcd_draw_update == 2)
  1431. {
  1432. // Menu was entered or SD card status has changed (plugged in or removed).
  1433. // Initialize its status.
  1434. _md->status = 1;
  1435. _md->is_flash_air = card.ToshibaFlashAir_isEnabled();
  1436. if (_md->is_flash_air) {
  1437. card.ToshibaFlashAir_GetIP((uint8_t*)(&_md->ip)); // ip == 0 if it failed
  1438. }
  1439. } else if (_md->is_flash_air && _md->ip == 0 && ++ _md->status == 16)
  1440. {
  1441. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  1442. _md->status = 0;
  1443. }
  1444. MENU_BEGIN();
  1445. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1446. MENU_ITEM_BACK_P(PSTR("Firmware:"));
  1447. MENU_ITEM_BACK_P(PSTR(" " FW_VERSION_FULL));
  1448. #if (FW_DEV_VERSION != FW_VERSION_GOLD) && (FW_DEV_VERSION != FW_VERSION_RC)
  1449. MENU_ITEM_BACK_P(PSTR(" repo " FW_REPOSITORY));
  1450. #endif
  1451. // Ideally this block would be optimized out by the compiler.
  1452. /* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  1453. if (fw_string_len < 6) {
  1454. MENU_ITEM_BACK_P(PSTR(MSG_FW_VERSION " - " FW_version));
  1455. } else {
  1456. MENU_ITEM_BACK_P(PSTR("FW - " FW_version));
  1457. }*/
  1458. MENU_ITEM_BACK_P(_n("prusa3d.com"));////MSG_PRUSA3D c=18
  1459. MENU_ITEM_BACK_P(_n("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM c=18
  1460. MENU_ITEM_BACK_P(_n("help.prusa3d.com"));////MSG_PRUSA3D_HELP c=18
  1461. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1462. MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE));
  1463. MENU_ITEM_BACK_P(PSTR(ELECTRONICS));
  1464. MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE));
  1465. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1466. MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17
  1467. MENU_ITEM_BACK_P(PSTR(SOURCE_DATE_EPOCH));
  1468. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  1469. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1470. MENU_ITEM_BACK_P(PSTR("Fil. sensor v.:"));
  1471. MENU_ITEM_BACK_P(fsensor.getIRVersionText());
  1472. #endif // IR_SENSOR_ANALOG
  1473. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1474. if (MMU2::mmu2.Enabled())
  1475. {
  1476. MENU_ITEM_BACK_P(_i("MMU2 connected")); ////MSG_MMU_CONNECTED c=18
  1477. MENU_ITEM_BACK_P(PSTR(" FW:")); ////c=17
  1478. if (((menu_item - 1) == menu_line) && lcd_draw_update)
  1479. {
  1480. lcd_set_cursor(6, menu_row);
  1481. MMU2::Version mmu_version = MMU2::mmu2.GetMMUFWVersion();
  1482. if (mmu_version.major > 0)
  1483. lcd_printf_P(PSTR("%d.%d.%d"), mmu_version.major, mmu_version.minor, mmu_version.build);
  1484. else
  1485. lcd_puts_P(_i("unknown")); ////MSG_UNKNOWN c=13
  1486. }
  1487. }
  1488. else
  1489. MENU_ITEM_BACK_P(PSTR("MMU2 N/A"));
  1490. // Show the FlashAir IP address, if the card is available.
  1491. if (_md->is_flash_air) {
  1492. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1493. MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:")); ////MSG_FLASHAIR c=18
  1494. MENU_ITEM_BACK_P(PSTR(" "));
  1495. if (((menu_item - 1) == menu_line) && lcd_draw_update) {
  1496. lcd_set_cursor(2, menu_row);
  1497. ip4_to_str(_md->ip_str, (uint8_t*)(&_md->ip));
  1498. lcd_print(_md->ip_str);
  1499. }
  1500. }
  1501. // Show the printer IP address, if it is available.
  1502. if (IP_address) {
  1503. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1504. MENU_ITEM_BACK_P(_i("Printer IP Addr:")); ////MSG_PRINTER_IP c=18
  1505. MENU_ITEM_BACK_P(PSTR(" "));
  1506. if (((menu_item - 1) == menu_line) && lcd_draw_update) {
  1507. lcd_set_cursor(2, menu_row);
  1508. ip4_to_str(_md->ip_str, (uint8_t*)(&IP_address));
  1509. lcd_print(_md->ip_str);
  1510. }
  1511. }
  1512. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1513. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=18
  1514. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=18
  1515. MENU_ITEM_SUBMENU_P(_i("Sensor info"), lcd_menu_show_sensors_state);////MSG_INFO_SENSORS c=18
  1516. #ifdef TMC2130
  1517. MENU_ITEM_SUBMENU_P(_T(MSG_BELT_STATUS), lcd_menu_belt_status);
  1518. #endif //TMC2130
  1519. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=18
  1520. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1521. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=18
  1522. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1523. #ifdef MENU_DUMP
  1524. MENU_ITEM_FUNCTION_P(_n("Dump memory"), lcd_dump_memory);
  1525. #endif //MENU_DUMP
  1526. #ifdef MENU_SERIAL_DUMP
  1527. if (emergency_serial_dump)
  1528. MENU_ITEM_FUNCTION_P(_n("Dump to serial"), lcd_serial_dump);
  1529. #endif
  1530. #ifdef DEBUG_BUILD
  1531. #ifdef EMERGENCY_HANDLERS
  1532. #ifdef WATCHDOG
  1533. MENU_ITEM_FUNCTION_P(PSTR("WDR crash"), lcd_wdr_crash);
  1534. #endif //WATCHDOG
  1535. MENU_ITEM_FUNCTION_P(PSTR("Stack crash"), lcd_stack_crash);
  1536. #endif //EMERGENCY_HANDLERS
  1537. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);////MSG_DEBUG c=18
  1538. #endif /* DEBUG_BUILD */
  1539. MENU_END();
  1540. }
  1541. void lcd_set_fan_check() {
  1542. fans_check_enabled = !fans_check_enabled;
  1543. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1544. #ifdef FANCHECK
  1545. if (fans_check_enabled == false) fan_check_error = EFCE_OK; //reset error if fanCheck is disabled during error. Allows resuming print.
  1546. #endif //FANCHECK
  1547. }
  1548. #ifdef MMU_HAS_CUTTER
  1549. void lcd_cutter_enabled()
  1550. {
  1551. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1552. {
  1553. #ifndef MMU_ALWAYS_CUT
  1554. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1555. }
  1556. #else //MMU_ALWAYS_CUT
  1557. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_always);
  1558. }
  1559. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1560. {
  1561. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1562. }
  1563. #endif //MMU_ALWAYS_CUT
  1564. else
  1565. {
  1566. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_enabled);
  1567. }
  1568. }
  1569. #endif //MMU_HAS_CUTTER
  1570. void lcd_set_filament_autoload() {
  1571. fsensor.setAutoLoadEnabled(!fsensor.getAutoLoadEnabled());
  1572. }
  1573. #if defined(FILAMENT_SENSOR) && defined(PAT9125)
  1574. void lcd_set_filament_oq_meass()
  1575. {
  1576. fsensor_oq_meassure_set(!fsensor_oq_meassure_enabled);
  1577. }
  1578. #endif
  1579. FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad'
  1580. bool bFilamentPreheatState;
  1581. bool bFilamentAction=false;
  1582. static bool bFilamentWaitingFlag=false;
  1583. static void mFilamentPrompt()
  1584. {
  1585. uint8_t nLevel;
  1586. lcd_set_cursor(0,0);
  1587. lcdui_print_temp(LCD_STR_THERMOMETER[0],(int)degHotend(0),(int)degTargetHotend(0));
  1588. lcd_puts_at_P(0,1, _i("Press the knob")); ////MSG_PRESS_KNOB c=20
  1589. lcd_set_cursor(0,2);
  1590. switch(eFilamentAction)
  1591. {
  1592. case FilamentAction::Load:
  1593. case FilamentAction::AutoLoad:
  1594. case FilamentAction::MmuLoad:
  1595. case FilamentAction::MmuLoadingTest:
  1596. lcd_puts_P(_i("to load filament")); ////MSG_TO_LOAD_FIL c=20
  1597. break;
  1598. case FilamentAction::UnLoad:
  1599. case FilamentAction::MmuUnLoad:
  1600. lcd_puts_P(_i("to unload filament")); ////MSG_TO_UNLOAD_FIL c=20
  1601. break;
  1602. case FilamentAction::MmuEject:
  1603. case FilamentAction::MmuCut:
  1604. case FilamentAction::None:
  1605. case FilamentAction::Preheat:
  1606. case FilamentAction::Lay1Cal:
  1607. break;
  1608. }
  1609. if(lcd_clicked()
  1610. #ifdef FILAMENT_SENSOR
  1611. /// @todo leptun - add this as a specific retest item
  1612. || (((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad)) && fsensor.getFilamentLoadEvent())
  1613. #endif //FILAMENT_SENSOR
  1614. ) {
  1615. nLevel=2;
  1616. if(!bFilamentPreheatState)
  1617. {
  1618. nLevel++;
  1619. // setTargetHotend0(0.0); // uncoment if return to base-state is required
  1620. }
  1621. menu_back(nLevel);
  1622. switch(eFilamentAction)
  1623. {
  1624. case FilamentAction::AutoLoad:
  1625. eFilamentAction=FilamentAction::None; // i.e. non-autoLoad
  1626. // FALLTHRU
  1627. case FilamentAction::Load:
  1628. loading_flag=true;
  1629. enquecommand_P(PSTR("M701")); // load filament
  1630. break;
  1631. case FilamentAction::UnLoad:
  1632. enquecommand_P(PSTR("M702")); // unload filament
  1633. break;
  1634. case FilamentAction::MmuLoad:
  1635. case FilamentAction::MmuLoadingTest:
  1636. case FilamentAction::MmuUnLoad:
  1637. case FilamentAction::MmuEject:
  1638. case FilamentAction::MmuCut:
  1639. case FilamentAction::None:
  1640. case FilamentAction::Preheat:
  1641. case FilamentAction::Lay1Cal:
  1642. break;
  1643. }
  1644. }
  1645. }
  1646. void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
  1647. {
  1648. static int nTargetOld;
  1649. static int nTargetBedOld;
  1650. uint8_t nLevel;
  1651. nTargetOld = target_temperature[0];
  1652. nTargetBedOld = target_temperature_bed;
  1653. setTargetHotend0((float )nTemp);
  1654. setTargetBed((float) nTempBed);
  1655. {
  1656. const FilamentAction action = eFilamentAction;
  1657. if (action == FilamentAction::Preheat || action == FilamentAction::Lay1Cal)
  1658. {
  1659. lcd_return_to_status();
  1660. if (action == FilamentAction::Lay1Cal)
  1661. {
  1662. lcd_commands_type = LcdCommands::Layer1Cal;
  1663. }
  1664. else
  1665. {
  1666. raise_z_above(MIN_Z_FOR_PREHEAT);
  1667. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1668. lcd_wizard(WizState::LoadFilHot);
  1669. }
  1670. return;
  1671. }
  1672. }
  1673. lcd_timeoutToStatus.stop();
  1674. if (current_temperature[0] > (target_temperature[0] * 0.95))
  1675. {
  1676. switch (eFilamentAction)
  1677. {
  1678. case FilamentAction::Load:
  1679. case FilamentAction::AutoLoad:
  1680. case FilamentAction::UnLoad:
  1681. if (bFilamentWaitingFlag) menu_submenu(mFilamentPrompt);
  1682. else
  1683. {
  1684. nLevel = bFilamentPreheatState ? 1 : 2;
  1685. menu_back(nLevel);
  1686. if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad))
  1687. {
  1688. loading_flag = true;
  1689. enquecommand_P(PSTR("M701")); // load filament
  1690. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1691. }
  1692. if (eFilamentAction == FilamentAction::UnLoad)
  1693. enquecommand_P(PSTR("M702")); // unload filament
  1694. }
  1695. break;
  1696. case FilamentAction::MmuLoad:
  1697. nLevel = bFilamentPreheatState ? 1 : 2;
  1698. bFilamentAction = true;
  1699. menu_back(nLevel);
  1700. menu_submenu(mmu_load_to_nozzle_menu);
  1701. break;
  1702. case FilamentAction::MmuLoadingTest:
  1703. nLevel = bFilamentPreheatState ? 1 : 2;
  1704. bFilamentAction = true;
  1705. menu_back(nLevel);
  1706. menu_submenu(mmu_loading_test_menu);
  1707. break;
  1708. case FilamentAction::MmuUnLoad:
  1709. nLevel = bFilamentPreheatState ? 1 : 2;
  1710. bFilamentAction = true;
  1711. menu_back(nLevel);
  1712. MMU2::mmu2.unload();
  1713. break;
  1714. case FilamentAction::MmuEject:
  1715. nLevel = bFilamentPreheatState ? 1 : 2;
  1716. bFilamentAction = true;
  1717. menu_back(nLevel);
  1718. menu_submenu(mmu_fil_eject_menu);
  1719. break;
  1720. case FilamentAction::MmuCut:
  1721. #ifdef MMU_HAS_CUTTER
  1722. nLevel=bFilamentPreheatState?1:2;
  1723. bFilamentAction=true;
  1724. menu_back(nLevel);
  1725. menu_submenu(mmu_cut_filament_menu);
  1726. #endif //MMU_HAS_CUTTER
  1727. break;
  1728. case FilamentAction::None:
  1729. case FilamentAction::Preheat:
  1730. case FilamentAction::Lay1Cal:
  1731. // handled earlier
  1732. break;
  1733. }
  1734. if (bFilamentWaitingFlag) Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  1735. bFilamentWaitingFlag = false;
  1736. }
  1737. else
  1738. {
  1739. if (!bFilamentWaitingFlag || lcd_draw_update)
  1740. {
  1741. // First entry from another menu OR first run after the filament preheat selection. Use
  1742. // bFilamentWaitingFlag to distinguish: this flag is reset exactly once when entering
  1743. // the menu and is used to raise the carriage *once*. In other cases, the LCD has been
  1744. // modified elsewhere and needs to be redrawn in full.
  1745. // reset bFilamentWaitingFlag immediately to avoid re-entry from raise_z_above()!
  1746. bool once = !bFilamentWaitingFlag;
  1747. bFilamentWaitingFlag = true;
  1748. // also force-enable lcd_draw_update (might be 0 when called from outside a menu)
  1749. lcd_draw_update = 1;
  1750. lcd_clear();
  1751. lcd_puts_at_P(0, 3, _T(MSG_CANCEL));
  1752. lcd_set_cursor(0, 1);
  1753. switch (eFilamentAction)
  1754. {
  1755. case FilamentAction::Load:
  1756. case FilamentAction::AutoLoad:
  1757. case FilamentAction::MmuLoad:
  1758. case FilamentAction::MmuLoadingTest:
  1759. lcd_puts_P(_i("Preheating to load")); ////MSG_PREHEATING_TO_LOAD c=20
  1760. if (once) raise_z_above(MIN_Z_FOR_LOAD);
  1761. break;
  1762. case FilamentAction::UnLoad:
  1763. case FilamentAction::MmuUnLoad:
  1764. lcd_puts_P(_i("Preheating to unload")); ////MSG_PREHEATING_TO_UNLOAD c=20
  1765. if (once) raise_z_above(MIN_Z_FOR_UNLOAD);
  1766. break;
  1767. case FilamentAction::MmuEject:
  1768. lcd_puts_P(_i("Preheating to eject")); ////MSG_PREHEATING_TO_EJECT c=20
  1769. break;
  1770. case FilamentAction::MmuCut:
  1771. lcd_puts_P(_i("Preheating to cut")); ////MSG_PREHEATING_TO_CUT c=20
  1772. break;
  1773. case FilamentAction::None:
  1774. case FilamentAction::Preheat:
  1775. case FilamentAction::Lay1Cal:
  1776. // handled earlier
  1777. break;
  1778. }
  1779. }
  1780. if (bFilamentWaitingFlag) {
  1781. lcd_set_cursor(0, 0);
  1782. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int) degHotend(0), (int) degTargetHotend(0));
  1783. }
  1784. if (lcd_clicked())
  1785. {
  1786. bFilamentWaitingFlag = false;
  1787. if (!bFilamentPreheatState)
  1788. {
  1789. setTargetHotend0(0.0);
  1790. setTargetBed(0.0);
  1791. menu_back();
  1792. }
  1793. else
  1794. {
  1795. setTargetHotend0((float )nTargetOld);
  1796. setTargetBed((float) nTargetBedOld);
  1797. }
  1798. menu_back();
  1799. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1800. }
  1801. }
  1802. }
  1803. static void mFilamentItem_farm()
  1804. {
  1805. bFilamentPreheatState = false;
  1806. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, FARM_PREHEAT_HPB_TEMP);
  1807. }
  1808. static void mFilamentItem_farm_nozzle()
  1809. {
  1810. bFilamentPreheatState = false;
  1811. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, 0);
  1812. }
  1813. static void mFilamentItem_PLA()
  1814. {
  1815. bFilamentPreheatState = false;
  1816. mFilamentItem(PLA_PREHEAT_HOTEND_TEMP, PLA_PREHEAT_HPB_TEMP);
  1817. }
  1818. static void mFilamentItem_PET()
  1819. {
  1820. bFilamentPreheatState = false;
  1821. mFilamentItem(PET_PREHEAT_HOTEND_TEMP, PET_PREHEAT_HPB_TEMP);
  1822. }
  1823. static void mFilamentItem_ASA()
  1824. {
  1825. bFilamentPreheatState = false;
  1826. mFilamentItem(ASA_PREHEAT_HOTEND_TEMP, ASA_PREHEAT_HPB_TEMP);
  1827. }
  1828. static void mFilamentItem_PC()
  1829. {
  1830. bFilamentPreheatState = false;
  1831. mFilamentItem(PC_PREHEAT_HOTEND_TEMP, PC_PREHEAT_HPB_TEMP);
  1832. }
  1833. static void mFilamentItem_ABS()
  1834. {
  1835. bFilamentPreheatState = false;
  1836. mFilamentItem(ABS_PREHEAT_HOTEND_TEMP, ABS_PREHEAT_HPB_TEMP);
  1837. }
  1838. static void mFilamentItem_HIPS()
  1839. {
  1840. bFilamentPreheatState = false;
  1841. mFilamentItem(HIPS_PREHEAT_HOTEND_TEMP, HIPS_PREHEAT_HPB_TEMP);
  1842. }
  1843. static void mFilamentItem_PP()
  1844. {
  1845. bFilamentPreheatState = false;
  1846. mFilamentItem(PP_PREHEAT_HOTEND_TEMP, PP_PREHEAT_HPB_TEMP);
  1847. }
  1848. static void mFilamentItem_FLEX()
  1849. {
  1850. bFilamentPreheatState = false;
  1851. mFilamentItem(FLEX_PREHEAT_HOTEND_TEMP, FLEX_PREHEAT_HPB_TEMP);
  1852. }
  1853. static void mFilamentItem_PVB()
  1854. {
  1855. bFilamentPreheatState = false;
  1856. mFilamentItem(PVB_PREHEAT_HOTEND_TEMP, PVB_PREHEAT_HPB_TEMP);
  1857. }
  1858. void mFilamentBack()
  1859. {
  1860. if (eFilamentAction == FilamentAction::AutoLoad ||
  1861. eFilamentAction == FilamentAction::Preheat ||
  1862. eFilamentAction == FilamentAction::Lay1Cal)
  1863. {
  1864. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1865. }
  1866. }
  1867. void lcd_generic_preheat_menu()
  1868. {
  1869. MENU_BEGIN();
  1870. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1871. {
  1872. ON_MENU_LEAVE(
  1873. mFilamentBack();
  1874. );
  1875. MENU_ITEM_BACK_P(_T(eFilamentAction == FilamentAction::Lay1Cal ? MSG_BACK : MSG_MAIN));
  1876. }
  1877. if (farm_mode)
  1878. {
  1879. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), mFilamentItem_farm);
  1880. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), mFilamentItem_farm_nozzle);
  1881. }
  1882. else
  1883. {
  1884. MENU_ITEM_SUBMENU_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)),mFilamentItem_PLA);
  1885. MENU_ITEM_SUBMENU_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)),mFilamentItem_PET);
  1886. MENU_ITEM_SUBMENU_P(PSTR("ASA - " STRINGIFY(ASA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ASA_PREHEAT_HPB_TEMP)),mFilamentItem_ASA);
  1887. MENU_ITEM_SUBMENU_P(PSTR("PC - " STRINGIFY(PC_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PC_PREHEAT_HPB_TEMP)),mFilamentItem_PC);
  1888. MENU_ITEM_SUBMENU_P(PSTR("PVB - " STRINGIFY(PVB_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PVB_PREHEAT_HPB_TEMP)),mFilamentItem_PVB);
  1889. MENU_ITEM_SUBMENU_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)),mFilamentItem_ABS);
  1890. MENU_ITEM_SUBMENU_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)),mFilamentItem_HIPS);
  1891. MENU_ITEM_SUBMENU_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)),mFilamentItem_PP);
  1892. MENU_ITEM_SUBMENU_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)),mFilamentItem_FLEX);
  1893. }
  1894. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) && eFilamentAction == FilamentAction::Preheat) MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  1895. MENU_END();
  1896. }
  1897. void mFilamentItemForce()
  1898. {
  1899. mFilamentItem(target_temperature[0],target_temperature_bed);
  1900. }
  1901. void lcd_unLoadFilament()
  1902. {
  1903. eFilamentAction=FilamentAction::UnLoad;
  1904. preheat_or_continue();
  1905. }
  1906. static void mmu_unload_filament()
  1907. {
  1908. eFilamentAction = FilamentAction::MmuUnLoad;
  1909. preheat_or_continue();
  1910. }
  1911. void lcd_wait_interact() {
  1912. lcd_clear();
  1913. lcd_puts_at_P(0, 1, _i("Insert filament"));////MSG_INSERT_FILAMENT c=20
  1914. #ifdef FILAMENT_SENSOR
  1915. if (!fsensor.getAutoLoadEnabled())
  1916. #endif //FILAMENT_SENSOR
  1917. {
  1918. lcd_puts_at_P(0, 2, _i("and press the knob"));////MSG_PRESS c=20 r=2
  1919. }
  1920. }
  1921. void lcd_change_success() {
  1922. lcd_clear();
  1923. lcd_puts_at_P(0, 2, _i("Change success!"));////MSG_CHANGE_SUCCESS c=20
  1924. }
  1925. static void lcd_loading_progress_bar(uint16_t loading_time_ms) {
  1926. for (uint_least8_t i = 0; i < LCD_WIDTH; i++) {
  1927. lcd_putc_at(i, 3, '.');
  1928. //loading_time_ms/20 delay
  1929. for (uint_least8_t j = 0; j < 5; j++) {
  1930. delay_keep_alive(loading_time_ms / 100);
  1931. }
  1932. }
  1933. }
  1934. void lcd_loading_color() {
  1935. //we are extruding 25mm with feedrate 200mm/min -> 7.5 seconds for whole action, 0.375 s for one character
  1936. lcd_clear();
  1937. lcd_puts_at_P(0, 0, _i("Loading color"));////MSG_LOADING_COLOR c=20
  1938. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  1939. lcd_loading_progress_bar((FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL); //show progress bar during filament loading slow sequence
  1940. }
  1941. void lcd_loading_filament() {
  1942. lcd_clear();
  1943. lcd_puts_at_P(0, 0, _T(MSG_LOADING_FILAMENT));
  1944. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  1945. uint16_t slow_seq_time = (FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL;
  1946. uint16_t fast_seq_time = (FILAMENTCHANGE_FIRSTFEED * 1000ul) / FILAMENTCHANGE_EFEED_FIRST;
  1947. lcd_loading_progress_bar(slow_seq_time + fast_seq_time); //show progress bar for total time of filament loading fast + slow sequence
  1948. }
  1949. uint8_t lcd_alright() {
  1950. int8_t enc_dif = 0;
  1951. uint8_t cursor_pos = 1;
  1952. lcd_clear();
  1953. lcd_puts_at_P(0, 0, _i("Changed correctly?"));////MSG_CORRECTLY c=20
  1954. lcd_puts_at_P(1, 1, _T(MSG_YES));
  1955. lcd_puts_at_P(1, 2, _i("Filament not loaded"));////MSG_NOT_LOADED c=19
  1956. lcd_puts_at_P(1, 3, _i("Color not correct"));////MSG_NOT_COLOR c=19
  1957. lcd_putc_at(0, 1, '>');
  1958. enc_dif = lcd_encoder_diff;
  1959. lcd_consume_click();
  1960. while (1)
  1961. {
  1962. manage_heater();
  1963. manage_inactivity(true);
  1964. if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  1965. {
  1966. if (enc_dif > lcd_encoder_diff ) {
  1967. // Rotating knob counter clockwise
  1968. cursor_pos--;
  1969. } else if (enc_dif < lcd_encoder_diff) {
  1970. // Rotating knob clockwise
  1971. cursor_pos++;
  1972. }
  1973. if (cursor_pos > 3) {
  1974. cursor_pos = 3;
  1975. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  1976. } else if (cursor_pos < 1) {
  1977. cursor_pos = 1;
  1978. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  1979. }
  1980. // Update '>' render only
  1981. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  1982. lcd_putc_at(0, cursor_pos, '>');
  1983. // Consume rotation event and make feedback sound
  1984. enc_dif = lcd_encoder_diff;
  1985. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  1986. _delay(100);
  1987. }
  1988. if (lcd_clicked())
  1989. {
  1990. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  1991. lcd_clear();
  1992. lcd_return_to_status();
  1993. return cursor_pos;
  1994. }
  1995. };
  1996. }
  1997. void show_preheat_nozzle_warning()
  1998. {
  1999. lcd_clear();
  2000. lcd_puts_at_P(0, 0, _T(MSG_ERROR));
  2001. lcd_puts_at_P(0, 2, _T(MSG_PREHEAT_NOZZLE));
  2002. _delay(2000);
  2003. lcd_clear();
  2004. }
  2005. void lcd_load_filament_color_check()
  2006. {
  2007. uint8_t clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, LCD_LEFT_BUTTON_CHOICE);
  2008. while (clean == LCD_MIDDLE_BUTTON_CHOICE) {
  2009. load_filament_final_feed();
  2010. st_synchronize();
  2011. clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, LCD_LEFT_BUTTON_CHOICE);
  2012. }
  2013. }
  2014. #ifdef FILAMENT_SENSOR
  2015. static void lcd_menu_AutoLoadFilament()
  2016. {
  2017. lcd_display_message_fullscreen_nonBlocking_P(_i("Autoloading filament is active, just press the knob and insert filament..."));////MSG_AUTOLOADING_ENABLED c=20 r=4
  2018. menu_back_if_clicked();
  2019. }
  2020. #endif //FILAMENT_SENSOR
  2021. static void preheat_or_continue() {
  2022. if (target_temperature[0] >= extrude_min_temp) {
  2023. bFilamentPreheatState = true;
  2024. mFilamentItem(target_temperature[0], target_temperature_bed);
  2025. } else {
  2026. lcd_generic_preheat_menu();
  2027. }
  2028. }
  2029. static void lcd_LoadFilament()
  2030. {
  2031. eFilamentAction = FilamentAction::Load;
  2032. preheat_or_continue();
  2033. }
  2034. //! @brief Show filament used a print time
  2035. //!
  2036. //! If printing current print statistics are shown
  2037. //!
  2038. //! @code{.unparsed}
  2039. //! |01234567890123456789|
  2040. //! |Filament used: | MSG_FILAMENT_USED c=19
  2041. //! | 0000.00m |
  2042. //! |Print time: | MSG_PRINT_TIME c=19
  2043. //! | 00h 00m 00s |
  2044. //! ----------------------
  2045. //! @endcode
  2046. //!
  2047. //! If not printing, total statistics are shown
  2048. //!
  2049. //! @code{.unparsed}
  2050. //! |01234567890123456789|
  2051. //! |Total filament: | MSG_TOTAL_FILAMENT c=19
  2052. //! | 0000.00m |
  2053. //! |Total print time: | MSG_TOTAL_PRINT_TIME c=19
  2054. //! | 00d 00h 00m |
  2055. //! ----------------------
  2056. //! @endcode
  2057. void lcd_menu_statistics()
  2058. {
  2059. lcd_timeoutToStatus.stop(); //infinite timeout
  2060. if (IS_SD_PRINTING)
  2061. {
  2062. const float _met = ((float)total_filament_used) / (100000.f);
  2063. const uint32_t _t = (_millis() - starttime) / 1000ul;
  2064. const uint32_t _h = _t / 3600;
  2065. const uint8_t _m = (_t - (_h * 3600ul)) / 60ul;
  2066. const uint8_t _s = _t - ((_h * 3600ul) + (_m * 60ul));
  2067. lcd_home();
  2068. lcd_printf_P(_N(
  2069. "%S:\n"
  2070. "%18.2fm \n"
  2071. "%S:\n"
  2072. "%10ldh %02dm %02ds"
  2073. ),
  2074. _i("Filament used"), _met, ////MSG_FILAMENT_USED c=19
  2075. _i("Print time"), _h, _m, _s); ////MSG_PRINT_TIME c=19
  2076. menu_back_if_clicked_fb();
  2077. }
  2078. else
  2079. {
  2080. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2081. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2082. uint8_t _hours, _minutes;
  2083. uint32_t _days;
  2084. float _filament_m = (float)_filament/100;
  2085. _days = _time / 1440;
  2086. _hours = (_time - (_days * 1440)) / 60;
  2087. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2088. lcd_home();
  2089. lcd_printf_P(_N(
  2090. "%S:\n"
  2091. "%18.2fm \n"
  2092. "%S:\n"
  2093. "%10ldd %02dh %02dm"
  2094. ),
  2095. _i("Total filament"), _filament_m, ////MSG_TOTAL_FILAMENT c=19
  2096. _i("Total print time"), _days, _hours, _minutes); ////MSG_TOTAL_PRINT_TIME c=19
  2097. menu_back_if_clicked_fb();
  2098. }
  2099. }
  2100. static void _lcd_move(const char *name, uint8_t axis, int min, int max)
  2101. {
  2102. if (homing_flag || mesh_bed_leveling_flag)
  2103. {
  2104. // printer entered a new state where axis move is forbidden
  2105. menu_back();
  2106. return;
  2107. }
  2108. typedef struct
  2109. { // 2bytes total
  2110. bool initialized; // 1byte
  2111. bool endstopsEnabledPrevious; // 1byte
  2112. } _menu_data_t;
  2113. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2114. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2115. if (!_md->initialized)
  2116. {
  2117. _md->endstopsEnabledPrevious = enable_endstops(false);
  2118. _md->initialized = true;
  2119. }
  2120. if (lcd_encoder != 0)
  2121. {
  2122. refresh_cmd_timeout();
  2123. if (! planner_queue_full())
  2124. {
  2125. current_position[axis] += float((int)lcd_encoder);
  2126. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2127. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2128. lcd_encoder = 0;
  2129. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2130. plan_buffer_line_curposXYZE(manual_feedrate[axis] / 60);
  2131. lcd_draw_update = 1;
  2132. }
  2133. }
  2134. if (lcd_draw_update)
  2135. {
  2136. lcd_set_cursor(0, 1);
  2137. menu_draw_float31(name, current_position[axis]);
  2138. }
  2139. if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious);
  2140. if (LCD_CLICKED) menu_back();
  2141. }
  2142. void lcd_move_e()
  2143. {
  2144. if ((int)degHotend0() > extrude_min_temp)
  2145. {
  2146. if (lcd_encoder != 0)
  2147. {
  2148. refresh_cmd_timeout();
  2149. if (! planner_queue_full())
  2150. {
  2151. current_position[E_AXIS] += float((int)lcd_encoder);
  2152. lcd_encoder = 0;
  2153. plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60);
  2154. lcd_draw_update = 1;
  2155. }
  2156. }
  2157. if (lcd_draw_update)
  2158. {
  2159. lcd_set_cursor(0, 1);
  2160. // Note: the colon behind the text is necessary to greatly shorten
  2161. // the implementation of menu_draw_float31
  2162. menu_draw_float31(PSTR("Extruder:"), current_position[E_AXIS]);
  2163. }
  2164. if (LCD_CLICKED) menu_back();
  2165. }
  2166. else
  2167. {
  2168. show_preheat_nozzle_warning();
  2169. lcd_return_to_status();
  2170. }
  2171. }
  2172. //! @brief Show measured Y distance of front calibration points from Y_MIN_POS
  2173. //! If those points are detected too close to edge of reachable area, their confidence is lowered.
  2174. //! This functionality is applied more often for MK2 printers.
  2175. //! @code{.unparsed}
  2176. //! |01234567890123456789|
  2177. //! |Y distance from min | MSG_Y_DIST_FROM_MIN
  2178. //! | -------------- | STR_SEPARATOR
  2179. //! |Left: 00.00mm| MSG_LEFT c=10, c=8
  2180. //! |Right: 00.00mm| MSG_RIGHT c=10, c=8
  2181. //! ----------------------
  2182. //! @endcode
  2183. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2184. static void lcd_menu_xyz_y_min()
  2185. {
  2186. float distanceMin[2];
  2187. count_xyz_details(distanceMin);
  2188. lcd_home();
  2189. lcd_printf_P(_N(
  2190. "%S\n"
  2191. "%S\n"
  2192. "%S:\n"
  2193. "%S:"
  2194. ),
  2195. _i("Y distance from min"), ////MSG_Y_DIST_FROM_MIN c=20
  2196. separator,
  2197. _i("Left"), ////MSG_LEFT c=10
  2198. _i("Right") ////MSG_RIGHT c=10
  2199. );
  2200. for (uint8_t i = 0; i < 2; i++)
  2201. {
  2202. lcd_set_cursor(11,2+i);
  2203. if (distanceMin[i] >= 200) lcd_puts_P(_T(MSG_NA));
  2204. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2205. }
  2206. if (lcd_clicked())
  2207. menu_goto(lcd_menu_xyz_skew, 0, true, true);
  2208. }
  2209. //@brief Show measured axis skewness
  2210. float _deg(float rad)
  2211. {
  2212. return rad * 180 / M_PI;
  2213. }
  2214. //! @brief Show Measured XYZ Skew
  2215. //!
  2216. //! @code{.unparsed}
  2217. //! |01234567890123456789|
  2218. //! |Measured skew :0.00D| MSG_MEASURED_SKEW c=14
  2219. //! | -------------- | STR_SEPARATOR
  2220. //! |Slight skew :0.12D| MSG_SLIGHT_SKEW c=14
  2221. //! |Severe skew :0.25D| MSG_SEVERE_SKEW c=14
  2222. //! ----------------------
  2223. //! D - Degree sysmbol LCD_STR_DEGREE
  2224. //! @endcode
  2225. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2226. static void lcd_menu_xyz_skew()
  2227. {
  2228. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2229. lcd_home();
  2230. lcd_printf_P(_N(
  2231. "%-14.14S:\n"
  2232. "%S\n"
  2233. "%-14.14S:%3.2f\x01\n"
  2234. "%-14.14S:%3.2f\x01"
  2235. ),
  2236. _i("Measured skew"), ////MSG_MEASURED_SKEW c=14
  2237. separator,
  2238. _i("Slight skew"), _deg(bed_skew_angle_mild), ////MSG_SLIGHT_SKEW c=14
  2239. _i("Severe skew"), _deg(bed_skew_angle_extreme) ////MSG_SEVERE_SKEW c=14
  2240. );
  2241. if (angleDiff < 100){
  2242. lcd_set_cursor(15,0);
  2243. lcd_printf_P(_N("%3.2f\x01"), _deg(angleDiff));
  2244. }
  2245. else{
  2246. lcd_puts_at_P(15,0, _T(MSG_NA));
  2247. }
  2248. if (lcd_clicked())
  2249. menu_goto(lcd_menu_xyz_offset, 0, true, true);
  2250. }
  2251. //! @brief Show measured bed offset from expected position
  2252. //!
  2253. //! @code{.unparsed}
  2254. //! |01234567890123456789|
  2255. //! |[0;0] point offset | MSG_MEASURED_OFFSET c=20
  2256. //! | -------------- | STR_SEPARATOR
  2257. //! |X 00.00mm| c=10
  2258. //! |Y 00.00mm| c=10
  2259. //! ----------------------
  2260. //! @endcode
  2261. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2262. static void lcd_menu_xyz_offset()
  2263. {
  2264. lcd_puts_at_P(0, 0, _i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=20
  2265. lcd_puts_at_P(0, 1, separator);
  2266. lcd_puts_at_P(0, 2, PSTR("X"));
  2267. lcd_puts_at_P(0, 3, PSTR("Y"));
  2268. float vec_x[2];
  2269. float vec_y[2];
  2270. float cntr[2];
  2271. world2machine_read_valid(vec_x, vec_y, cntr);
  2272. for (uint_least8_t i = 0; i < 2; i++)
  2273. {
  2274. lcd_set_cursor((cntr[i] < 0) ? 13 : 14, i+2);
  2275. lcd_print(cntr[i]);
  2276. lcd_puts_at_P(18, i + 2, PSTR("mm"));
  2277. }
  2278. menu_back_if_clicked();
  2279. }
  2280. // Note: the colon behind the text (X, Y, Z) is necessary to greatly shorten
  2281. // the implementation of menu_draw_float31
  2282. static void lcd_move_x() {
  2283. _lcd_move(PSTR("X:"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2284. }
  2285. static void lcd_move_y() {
  2286. _lcd_move(PSTR("Y:"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2287. }
  2288. static void lcd_move_z() {
  2289. _lcd_move(PSTR("Z:"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2290. }
  2291. /**
  2292. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2293. *
  2294. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2295. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2296. * Purpose of this function for other axis then Z is unknown.
  2297. *
  2298. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2299. * other value leads to storing Z_AXIS
  2300. * @param msg text to be displayed
  2301. */
  2302. static void lcd_babystep_z()
  2303. {
  2304. if (homing_flag || mesh_bed_leveling_flag)
  2305. {
  2306. // printer changed to a new state where live Z is forbidden
  2307. menu_back();
  2308. return;
  2309. }
  2310. typedef struct
  2311. {
  2312. int8_t status;
  2313. int16_t babystepMemZ;
  2314. float babystepMemMMZ;
  2315. } _menu_data_t;
  2316. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2317. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2318. if (_md->status == 0)
  2319. {
  2320. // Menu was entered.
  2321. // Initialize its status.
  2322. _md->status = 1;
  2323. check_babystep();
  2324. if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){
  2325. _md->babystepMemZ = 0;
  2326. }
  2327. else{
  2328. _md->babystepMemZ = eeprom_read_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->
  2329. s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)));
  2330. }
  2331. // same logic as in babystep_load
  2332. if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST)
  2333. _md->babystepMemZ = 0;
  2334. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2335. lcd_draw_update = 1;
  2336. //SERIAL_ECHO("Z baby step: ");
  2337. //SERIAL_ECHO(_md->babystepMem[2]);
  2338. }
  2339. if (lcd_encoder != 0)
  2340. {
  2341. _md->babystepMemZ += (int)lcd_encoder;
  2342. if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2343. else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0
  2344. else babystepsTodoZadd(lcd_encoder);
  2345. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2346. _delay(50);
  2347. lcd_encoder = 0;
  2348. lcd_draw_update = 1;
  2349. }
  2350. if (lcd_draw_update)
  2351. {
  2352. SheetFormatBuffer buffer;
  2353. menu_format_sheet_E(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))], buffer);
  2354. lcd_set_cursor(0, 0);
  2355. lcd_print(buffer.c);
  2356. lcd_set_cursor(0, 1);
  2357. menu_draw_float13(_i("Adjusting Z:"), _md->babystepMemMMZ); ////MSG_BABYSTEPPING_Z c=15 // Beware: must include the ':' as its last character
  2358. }
  2359. if (LCD_CLICKED || menu_leaving)
  2360. {
  2361. // Only update the EEPROM when leaving the menu.
  2362. uint8_t active_sheet=eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  2363. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[active_sheet].z_offset)),_md->babystepMemZ);
  2364. // NOTE: bed_temp and pinda_temp are not currently read/used anywhere.
  2365. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].bed_temp),target_temperature_bed);
  2366. #ifdef PINDA_THERMISTOR
  2367. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].pinda_temp),current_temperature_pinda);
  2368. #endif //PINDA_THERMISTOR
  2369. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2370. }
  2371. if (LCD_CLICKED) menu_back();
  2372. }
  2373. typedef struct
  2374. { // 12bytes + 9bytes = 21bytes total
  2375. menu_data_edit_t reserved; //12 bytes reserved for number editing functions
  2376. int8_t status; // 1byte
  2377. int16_t left; // 2byte
  2378. int16_t right; // 2byte
  2379. int16_t front; // 2byte
  2380. int16_t rear; // 2byte
  2381. } _menu_data_adjust_bed_t;
  2382. static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data");
  2383. void lcd_adjust_bed_reset(void)
  2384. {
  2385. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2386. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2387. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2388. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2389. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2390. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2391. _md->status = 0;
  2392. }
  2393. //! @brief Show Bed level correct
  2394. //!
  2395. //! @code{.unparsed}
  2396. //! |01234567890123456789|
  2397. //! |Settings: | MSG_SETTINGS
  2398. //! |Left side [μm]: | MSG_BED_CORRECTION_LEFT
  2399. //! |Right side[μm]: | MSG_BED_CORRECTION_RIGHT
  2400. //! |Front side[μm]: | MSG_BED_CORRECTION_FRONT
  2401. //! |Rear side [μm]: | MSG_BED_CORRECTION_REAR
  2402. //! |Reset | MSG_BED_CORRECTION_RESET
  2403. //! ----------------------
  2404. //! @endcode
  2405. void lcd_adjust_bed(void)
  2406. {
  2407. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2408. if (_md->status == 0)
  2409. {
  2410. // Menu was entered.
  2411. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1)
  2412. {
  2413. _md->left = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_LEFT);
  2414. _md->right = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_RIGHT);
  2415. _md->front = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_FRONT);
  2416. _md->rear = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_REAR);
  2417. }
  2418. _md->status = 1;
  2419. }
  2420. MENU_BEGIN();
  2421. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  2422. ON_MENU_LEAVE(
  2423. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_LEFT, (uint8_t)_md->left);
  2424. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_FRONT, (uint8_t)_md->front);
  2425. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_REAR, (uint8_t)_md->rear);
  2426. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_RIGHT, (uint8_t)_md->right);
  2427. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_VALID, 1);
  2428. );
  2429. MENU_ITEM_BACK_P(_T(MSG_BACK));
  2430. MENU_ITEM_EDIT_int3_P(_i("Left side [\xe4m]"), &_md->left, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14
  2431. MENU_ITEM_EDIT_int3_P(_i("Right side[\xe4m]"), &_md->right, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_RIGHT c=14
  2432. MENU_ITEM_EDIT_int3_P(_i("Front side[\xe4m]"), &_md->front, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_FRONT c=14
  2433. MENU_ITEM_EDIT_int3_P(_i("Rear side [\xe4m]"), &_md->rear, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_REAR c=14
  2434. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_adjust_bed_reset);
  2435. MENU_END();
  2436. }
  2437. //! @brief Show PID Extruder
  2438. //!
  2439. //! @code{.unparsed}
  2440. //! |01234567890123456789|
  2441. //! |Set temperature: |
  2442. //! | |
  2443. //! | 210 |
  2444. //! | |
  2445. //! ----------------------
  2446. //! @endcode
  2447. void pid_extruder()
  2448. {
  2449. lcd_clear();
  2450. lcd_puts_at_P(0, 0, _i("Set temperature:"));////MSG_SET_TEMPERATURE c=20
  2451. pid_temp += int(lcd_encoder);
  2452. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2453. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2454. lcd_encoder = 0;
  2455. lcd_set_cursor(1, 2);
  2456. lcd_printf_P(PSTR("%3u"), pid_temp);
  2457. if (lcd_clicked()) {
  2458. lcd_commands_type = LcdCommands::PidExtruder;
  2459. lcd_return_to_status();
  2460. lcd_update(2);
  2461. }
  2462. }
  2463. /*
  2464. void lcd_adjust_z() {
  2465. int enc_dif = 0;
  2466. int cursor_pos = 1;
  2467. int fsm = 0;
  2468. lcd_clear();
  2469. lcd_set_cursor(0, 0);
  2470. lcd_puts_P(_n("Auto adjust Z?"));////MSG_ADJUSTZ
  2471. lcd_set_cursor(1, 1);
  2472. lcd_puts_P(_T(MSG_YES));
  2473. lcd_set_cursor(1, 2);
  2474. lcd_puts_P(_T(MSG_NO));
  2475. lcd_set_cursor(0, 1);
  2476. lcd_print('>');
  2477. enc_dif = lcd_encoder_diff;
  2478. while (fsm == 0) {
  2479. manage_heater();
  2480. manage_inactivity(true);
  2481. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2482. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2483. if (enc_dif > lcd_encoder_diff ) {
  2484. cursor_pos --;
  2485. }
  2486. if (enc_dif < lcd_encoder_diff ) {
  2487. cursor_pos ++;
  2488. }
  2489. if (cursor_pos > 2) {
  2490. cursor_pos = 2;
  2491. }
  2492. if (cursor_pos < 1) {
  2493. cursor_pos = 1;
  2494. }
  2495. lcd_set_cursor(0, 1);
  2496. lcd_print(' ');
  2497. lcd_set_cursor(0, 2);
  2498. lcd_print(' ');
  2499. lcd_set_cursor(0, cursor_pos);
  2500. lcd_print('>');
  2501. enc_dif = lcd_encoder_diff;
  2502. _delay(100);
  2503. }
  2504. }
  2505. if (lcd_clicked()) {
  2506. fsm = cursor_pos;
  2507. if (fsm == 1) {
  2508. int babystepLoadZ = 0;
  2509. babystepLoadZ = eeprom_read_word((uint16_t*)EEPROM_BABYSTEP_Z);
  2510. CRITICAL_SECTION_START
  2511. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2512. CRITICAL_SECTION_END
  2513. } else {
  2514. int zero = 0;
  2515. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_X, zero);
  2516. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Y, zero);
  2517. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Z, zero);
  2518. }
  2519. _delay(500);
  2520. }
  2521. };
  2522. lcd_clear();
  2523. lcd_return_to_status();
  2524. }*/
  2525. #ifdef PINDA_THERMISTOR
  2526. bool lcd_wait_for_pinda(float temp) {
  2527. setAllTargetHotends(0);
  2528. setTargetBed(0);
  2529. LongTimer pinda_timeout;
  2530. pinda_timeout.start();
  2531. bool target_temp_reached = true;
  2532. while (current_temperature_pinda > temp){
  2533. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2534. lcd_set_cursor(0, 4);
  2535. lcd_print(LCD_STR_THERMOMETER[0]);
  2536. lcd_printf_P(PSTR("%3d/%3d"), (int16_t)current_temperature_pinda, (int16_t) temp);
  2537. lcd_print(LCD_STR_DEGREE[0]);
  2538. delay_keep_alive(1000);
  2539. serialecho_temperatures();
  2540. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2541. target_temp_reached = false;
  2542. break;
  2543. }
  2544. }
  2545. lcd_update_enable(true);
  2546. return target_temp_reached;
  2547. }
  2548. #endif //PINDA_THERMISTOR
  2549. void lcd_wait_for_heater() {
  2550. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2551. lcd_set_cursor(0, 4);
  2552. lcd_print(LCD_STR_THERMOMETER[0]);
  2553. lcd_printf_P(PSTR("%3d/%3d"), (int16_t)degHotend(active_extruder), (int16_t) degTargetHotend(active_extruder));
  2554. lcd_print(LCD_STR_DEGREE[0]);
  2555. }
  2556. void lcd_wait_for_cool_down() {
  2557. setAllTargetHotends(0);
  2558. setTargetBed(0);
  2559. int fanSpeedBckp = fanSpeed;
  2560. fanSpeed = 255;
  2561. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2562. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=4
  2563. lcd_set_cursor(0, 4);
  2564. lcd_print(LCD_STR_THERMOMETER[0]);
  2565. lcd_printf_P(PSTR("%3d/0"), (int16_t)degHotend(0));
  2566. lcd_print(LCD_STR_DEGREE[0]);
  2567. lcd_set_cursor(9, 4);
  2568. lcd_print(LCD_STR_BEDTEMP[0]);
  2569. lcd_printf_P(PSTR("%3d/0"), (int16_t)degBed());
  2570. lcd_print(LCD_STR_DEGREE[0]);
  2571. delay_keep_alive(1000);
  2572. serialecho_temperatures();
  2573. }
  2574. fanSpeed = fanSpeedBckp;
  2575. lcd_update_enable(true);
  2576. }
  2577. // Lets the user move the Z carriage up to the end stoppers.
  2578. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2579. // Otherwise the Z calibration is not changed and false is returned.
  2580. #ifndef TMC2130
  2581. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2582. {
  2583. // Don't know where we are. Let's claim we are Z=0, so the soft end stops will not be triggered when moving up.
  2584. current_position[Z_AXIS] = 0;
  2585. plan_set_position_curposXYZE();
  2586. // Until confirmed by the confirmation dialog.
  2587. for (;;) {
  2588. const char *msg = only_z
  2589. ? _i("Calibrating Z. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.")////MSG_MOVE_CARRIAGE_TO_THE_TOP_Z c=20 r=8
  2590. : _i("Calibrating XYZ. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.");////MSG_MOVE_CARRIAGE_TO_THE_TOP c=20 r=8
  2591. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2592. const bool multi_screen = msg_next != NULL;
  2593. unsigned long previous_millis_msg = _millis();
  2594. // Until the user finishes the z up movement.
  2595. lcd_encoder_diff = 0;
  2596. lcd_encoder = 0;
  2597. for (;;) {
  2598. manage_heater();
  2599. manage_inactivity(true);
  2600. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2601. _delay(50);
  2602. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2603. lcd_encoder_diff = 0;
  2604. if (! planner_queue_full()) {
  2605. // Only move up, whatever direction the user rotates the encoder.
  2606. current_position[Z_AXIS] += fabs(lcd_encoder);
  2607. lcd_encoder = 0;
  2608. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  2609. }
  2610. }
  2611. if (lcd_clicked()) {
  2612. // Abort a move if in progress.
  2613. planner_abort_hard();
  2614. planner_aborted = false;
  2615. while (lcd_clicked()) ;
  2616. _delay(10);
  2617. while (lcd_clicked()) ;
  2618. break;
  2619. }
  2620. if (multi_screen && _millis() - previous_millis_msg > 5000) {
  2621. if (msg_next == NULL)
  2622. msg_next = msg;
  2623. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2624. previous_millis_msg = _millis();
  2625. }
  2626. }
  2627. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2628. uint8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Are left and right Z~carriages all up?"), false);////MSG_CONFIRM_CARRIAGE_AT_THE_TOP c=20 r=2
  2629. if (result == LCD_BUTTON_TIMEOUT)
  2630. goto canceled;
  2631. else if (result == LCD_LEFT_BUTTON_CHOICE)
  2632. goto calibrated;
  2633. // otherwise perform another round of the Z up dialog.
  2634. }
  2635. calibrated:
  2636. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2637. // during the search for the induction points.
  2638. if ((PRINTER_TYPE == PRINTER_MK25) || (PRINTER_TYPE == PRINTER_MK2) || (PRINTER_TYPE == PRINTER_MK2_SNMM)) {
  2639. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2640. }
  2641. else {
  2642. current_position[Z_AXIS] = Z_MAX_POS+4.f;
  2643. }
  2644. plan_set_position_curposXYZE();
  2645. return true;
  2646. canceled:
  2647. return false;
  2648. }
  2649. #endif // TMC2130
  2650. static inline bool pgm_is_whitespace(const char *c_addr)
  2651. {
  2652. const char c = pgm_read_byte(c_addr);
  2653. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2654. }
  2655. static inline bool pgm_is_interpunction(const char *c_addr)
  2656. {
  2657. const char c = pgm_read_byte(c_addr);
  2658. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2659. }
  2660. /**
  2661. * @brief show full screen message
  2662. *
  2663. * This function is non-blocking
  2664. * @param msg message to be displayed from PROGMEM
  2665. * @return rest of the text (to be displayed on next page)
  2666. */
  2667. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg)
  2668. {
  2669. lcd_set_cursor(0, 0);
  2670. const char *msgend = msg;
  2671. uint8_t row = 0;
  2672. bool multi_screen = false;
  2673. for (; row < 4; ++ row) {
  2674. while (pgm_is_whitespace(msg))
  2675. ++ msg;
  2676. if (pgm_read_byte(msg) == 0)
  2677. // End of the message.
  2678. break;
  2679. lcd_set_cursor(0, row);
  2680. uint8_t linelen = min(strlen_P(msg), LCD_WIDTH);
  2681. const char *msgend2 = msg + linelen;
  2682. msgend = msgend2;
  2683. if (row == 3 && linelen == LCD_WIDTH) {
  2684. // Last line of the display, full line shall be displayed.
  2685. // Find out, whether this message will be split into multiple screens.
  2686. while (pgm_is_whitespace(msgend))
  2687. ++ msgend;
  2688. multi_screen = pgm_read_byte(msgend) != 0;
  2689. if (multi_screen)
  2690. msgend = (msgend2 -= 2);
  2691. }
  2692. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2693. // Splitting a word. Find the start of the current word.
  2694. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2695. -- msgend;
  2696. if (msgend == msg)
  2697. // Found a single long word, which cannot be split. Just cut it.
  2698. msgend = msgend2;
  2699. }
  2700. for (; msg < msgend; ++ msg) {
  2701. char c = char(pgm_read_byte(msg));
  2702. if (c == '~')
  2703. c = ' ';
  2704. lcd_print(c);
  2705. }
  2706. }
  2707. if (multi_screen) {
  2708. // Display the "next screen" indicator character.
  2709. lcd_set_custom_characters_nextpage();
  2710. lcd_set_cursor(19, 3);
  2711. // Display the double down arrow.
  2712. lcd_print(LCD_STR_ARROW_2_DOWN[0]);
  2713. }
  2714. return multi_screen ? msgend : NULL;
  2715. }
  2716. const char* lcd_display_message_fullscreen_P(const char *msg)
  2717. {
  2718. // Disable update of the screen by the usual lcd_update(0) routine.
  2719. lcd_update_enable(false);
  2720. lcd_clear();
  2721. return lcd_display_message_fullscreen_nonBlocking_P(msg);
  2722. }
  2723. /**
  2724. * @brief show full screen message and wait
  2725. *
  2726. * This function is blocking.
  2727. * @param msg message to be displayed from PROGMEM
  2728. */
  2729. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2730. {
  2731. LcdUpdateDisabler lcdUpdateDisabler;
  2732. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2733. bool multi_screen = msg_next != NULL;
  2734. lcd_set_custom_characters_nextpage();
  2735. lcd_consume_click();
  2736. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2737. // Until confirmed by a button click.
  2738. for (;;) {
  2739. if (!multi_screen) {
  2740. lcd_set_cursor(19, 3);
  2741. // Display the confirm char.
  2742. lcd_print(LCD_STR_CONFIRM[0]);
  2743. }
  2744. // Wait for 5 seconds before displaying the next text.
  2745. for (uint8_t i = 0; i < 100; ++ i) {
  2746. delay_keep_alive(50);
  2747. if (lcd_clicked()) {
  2748. if (msg_next == NULL) {
  2749. KEEPALIVE_STATE(IN_HANDLER);
  2750. lcd_set_custom_characters();
  2751. return;
  2752. }
  2753. else {
  2754. break;
  2755. }
  2756. }
  2757. }
  2758. if (multi_screen) {
  2759. if (msg_next == NULL)
  2760. msg_next = msg;
  2761. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2762. if (msg_next == NULL) {
  2763. lcd_set_cursor(19, 3);
  2764. // Display the confirm char.
  2765. lcd_print(LCD_STR_CONFIRM[0]);
  2766. }
  2767. }
  2768. }
  2769. }
  2770. bool lcd_wait_for_click_delay(uint16_t nDelay)
  2771. // nDelay :: timeout [s] (0 ~ no timeout)
  2772. // true ~ clicked, false ~ delayed
  2773. {
  2774. bool bDelayed;
  2775. long nTime0 = _millis()/1000;
  2776. lcd_consume_click();
  2777. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2778. for (;;) {
  2779. manage_heater();
  2780. manage_inactivity(true);
  2781. bDelayed = ((_millis()/1000-nTime0) > nDelay);
  2782. bDelayed = (bDelayed && (nDelay != 0)); // 0 ~ no timeout, always waiting for click
  2783. if (lcd_clicked() || bDelayed) {
  2784. KEEPALIVE_STATE(IN_HANDLER);
  2785. return(!bDelayed);
  2786. }
  2787. }
  2788. }
  2789. void lcd_wait_for_click()
  2790. {
  2791. lcd_wait_for_click_delay(0);
  2792. }
  2793. //! @brief Show multiple screen message with yes and no possible choices and wait with possible timeout
  2794. //! @param msg Message to show. If NULL, do not clear the screen and handle choice selection only.
  2795. //! @param allow_timeouting if true, allows time outing of the screen
  2796. //! @param default_selection if 0, 'Yes' choice is selected by default, otherwise 'No' choice is preselected
  2797. //! @retval 0 yes choice selected by user
  2798. //! @retval 1 no choice selected by user
  2799. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2800. uint8_t lcd_show_multiscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, uint8_t default_selection) //currently just max. n*4 + 3 lines supported (set in language header files)
  2801. {
  2802. return lcd_show_multiscreen_message_with_choices_and_wait_P(msg, allow_timeouting, default_selection, _T(MSG_YES), _T(MSG_NO), nullptr, 10);
  2803. }
  2804. //! @brief Show a two-choice prompt on the last line of the LCD
  2805. //! @param selected Show first choice as selected if true, the second otherwise
  2806. //! @param first_choice text caption of first possible choice
  2807. //! @param second_choice text caption of second possible choice
  2808. //! @param second_col column on LCD where second choice is rendered.
  2809. //! @param third_choice text caption of third, optional, choice.
  2810. void lcd_show_choices_prompt_P(uint8_t selected, const char *first_choice, const char *second_choice, uint8_t second_col, const char *third_choice)
  2811. {
  2812. lcd_set_cursor(0, 3);
  2813. lcd_print(selected == LCD_LEFT_BUTTON_CHOICE ? '>': ' ');
  2814. lcd_puts_P(first_choice);
  2815. lcd_set_cursor(second_col, 3);
  2816. lcd_print(selected == LCD_MIDDLE_BUTTON_CHOICE ? '>': ' ');
  2817. lcd_puts_P(second_choice);
  2818. if (third_choice)
  2819. {
  2820. lcd_set_cursor(18, 3);
  2821. lcd_print(selected == LCD_RIGHT_BUTTON_CHOICE ? '>': ' ');
  2822. lcd_puts_P(third_choice);
  2823. }
  2824. }
  2825. //! @brief Show single or multiple screen message with two possible choices and wait with possible timeout
  2826. //! @param msg Message to show. If NULL, do not clear the screen and handle choice selection only.
  2827. //! @param allow_timeouting bool, if true, allows time outing of the screen
  2828. //! @param default_selection uint8_t, Control which choice is selected first. 0: left most, 1: middle, 2: right most choice. The left most choice is selected by default
  2829. //! @param first_choice text caption of first possible choice. Must be in PROGMEM
  2830. //! @param second_choice text caption of second possible choice. Must be in PROGMEM
  2831. //! @param third_choice text caption of second possible choice. Must be in PROGMEM. When not set to nullptr first_choice and second_choice may not be more than 5 characters long.
  2832. //! @param second_col column on LCD where second_choice starts
  2833. //! @retval 0 first choice selected by user
  2834. //! @retval 1 first choice selected by user
  2835. //! @retval 2 third choice selected by user
  2836. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2837. uint8_t lcd_show_multiscreen_message_with_choices_and_wait_P(
  2838. const char *const msg, bool allow_timeouting, uint8_t default_selection,
  2839. const char *const first_choice, const char *const second_choice, const char *const third_choice,
  2840. uint8_t second_col
  2841. ) {
  2842. const char *msg_next = msg ? lcd_display_message_fullscreen_P(msg) : NULL;
  2843. bool multi_screen = msg_next != NULL;
  2844. lcd_set_custom_characters_nextpage();
  2845. // Initial status/prompt on single-screen messages
  2846. uint8_t current_selection = default_selection;
  2847. if (!msg_next) {
  2848. lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice);
  2849. }
  2850. // Wait for user confirmation or a timeout.
  2851. unsigned long previous_millis_cmd = _millis();
  2852. int8_t enc_dif = lcd_encoder_diff;
  2853. lcd_consume_click();
  2854. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2855. for (;;) {
  2856. for (uint8_t i = 0; i < 100; ++i) {
  2857. delay_keep_alive(50);
  2858. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS) {
  2859. return LCD_BUTTON_TIMEOUT;
  2860. }
  2861. manage_heater();
  2862. manage_inactivity(true);
  2863. if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2864. if (msg_next == NULL) {
  2865. if (third_choice) { // third_choice is not nullptr, safe to dereference
  2866. if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) {
  2867. // Rotating knob counter clockwise
  2868. current_selection--;
  2869. } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_RIGHT_BUTTON_CHOICE) {
  2870. // Rotating knob clockwise
  2871. current_selection++;
  2872. }
  2873. } else {
  2874. if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) {
  2875. // Rotating knob counter clockwise
  2876. current_selection = LCD_LEFT_BUTTON_CHOICE;
  2877. } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_MIDDLE_BUTTON_CHOICE) {
  2878. // Rotating knob clockwise
  2879. current_selection = LCD_MIDDLE_BUTTON_CHOICE;
  2880. }
  2881. }
  2882. lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice);
  2883. enc_dif = lcd_encoder_diff;
  2884. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  2885. } else {
  2886. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2887. break; // turning knob skips waiting loop
  2888. }
  2889. }
  2890. if (lcd_clicked()) {
  2891. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  2892. if (msg_next == NULL) {
  2893. KEEPALIVE_STATE(IN_HANDLER);
  2894. lcd_set_custom_characters();
  2895. lcd_update_enable(true);
  2896. return current_selection;
  2897. } else
  2898. break;
  2899. }
  2900. }
  2901. if (multi_screen) {
  2902. if (msg_next == NULL) {
  2903. msg_next = msg;
  2904. }
  2905. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2906. }
  2907. if (msg_next == NULL) {
  2908. lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice);
  2909. }
  2910. }
  2911. }
  2912. //! @brief Display and wait for a Yes/No choice using the last line of the LCD
  2913. //! @param allow_timeouting if true, allows time outing of the screen
  2914. //! @param default_selection if 0, 'Yes' choice is selected by default, otherwise 'No' choice is preselected
  2915. //! @retval 0 yes choice selected by user
  2916. //! @retval 1 no choice selected by user
  2917. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2918. uint8_t lcd_show_yes_no_and_wait(bool allow_timeouting, uint8_t default_selection)
  2919. {
  2920. return lcd_show_multiscreen_message_yes_no_and_wait_P(NULL, allow_timeouting, default_selection);
  2921. }
  2922. //! @brief Show single screen message with yes and no possible choices and wait with possible timeout
  2923. //! @param msg Message to show. If NULL, do not clear the screen and handle choice selection only.
  2924. //! @param allow_timeouting if true, allows time outing of the screen
  2925. //! @param default_selection if 0, 'Yes' choice is selected by default, otherwise 'No' choice is preselected
  2926. //! @retval 0 yes choice selected by user
  2927. //! @retval 1 no choice selected by user
  2928. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2929. //! @relates lcd_show_yes_no_and_wait
  2930. uint8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, uint8_t default_selection)
  2931. {
  2932. return lcd_show_multiscreen_message_yes_no_and_wait_P(msg, allow_timeouting, default_selection);
  2933. }
  2934. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  2935. {
  2936. const char *msg = NULL;
  2937. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  2938. lcd_show_fullscreen_message_and_wait_P(_i("XYZ calibration failed. Bed calibration point was not found."));////MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND c=20 r=6
  2939. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  2940. if (point_too_far_mask == 0)
  2941. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2942. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2943. // Only the center point or all the three front points.
  2944. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=6
  2945. else if ((point_too_far_mask & 1) == 0)
  2946. // The right and maybe the center point out of reach.
  2947. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=6
  2948. else
  2949. // The left and maybe the center point out of reach. //@todo Why isn't it found in the firmware.map
  2950. msg = _n("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  2951. lcd_show_fullscreen_message_and_wait_P(msg);
  2952. } else {
  2953. if (point_too_far_mask != 0) {
  2954. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2955. // Only the center point or all the three front points.
  2956. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  2957. else if ((point_too_far_mask & 1) == 0)
  2958. // The right and maybe the center point out of reach.
  2959. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  2960. else
  2961. // The left and maybe the center point out of reach. //@todo Why isn't it found in the firmware.map
  2962. msg = _n("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  2963. lcd_show_fullscreen_message_and_wait_P(msg);
  2964. }
  2965. if (point_too_far_mask == 0 || result > 0) {
  2966. switch (result) {
  2967. default:
  2968. // should not happen
  2969. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2970. break;
  2971. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  2972. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  2973. break;
  2974. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  2975. msg = _i("XYZ calibration all right. X/Y axes are slightly skewed. Good job!");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD c=20 r=8
  2976. break;
  2977. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  2978. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  2979. break;
  2980. }
  2981. lcd_show_fullscreen_message_and_wait_P(msg);
  2982. }
  2983. }
  2984. }
  2985. void lcd_temp_cal_show_result(bool result) {
  2986. custom_message_type = CustomMsg::Status;
  2987. disable_x();
  2988. disable_y();
  2989. disable_z();
  2990. disable_e0();
  2991. disable_e1();
  2992. disable_e2();
  2993. setTargetBed(0); //set bed target temperature back to 0
  2994. if (result == true) {
  2995. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  2996. SERIAL_ECHOLNPGM("PINDA calibration done. Continue with pressing the knob.");
  2997. lcd_show_fullscreen_message_and_wait_P(_T(MSG_PINDA_CALIBRATION_DONE));
  2998. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  2999. }
  3000. else {
  3001. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  3002. SERIAL_ECHOLNPGM("PINDA calibration failed. Continue with pressing the knob.");
  3003. lcd_show_fullscreen_message_and_wait_P(_i("PINDA calibration failed"));////MSG_PINDA_CAL_FAILED c=20 r=4
  3004. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  3005. }
  3006. lcd_update_enable(true);
  3007. lcd_update(2);
  3008. }
  3009. static void lcd_show_end_stops() {
  3010. lcd_puts_at_P(0, 0, (PSTR("End stops diag")));
  3011. lcd_puts_at_P(0, 1, (READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  3012. lcd_puts_at_P(0, 2, (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  3013. lcd_puts_at_P(0, 3, (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  3014. }
  3015. #ifndef TMC2130
  3016. static void menu_show_end_stops() {
  3017. lcd_show_end_stops();
  3018. if (LCD_CLICKED) menu_back();
  3019. }
  3020. #endif // not defined TMC2130
  3021. // Lets the user move the Z carriage up to the end stoppers.
  3022. // When done, it sets the current Z to Z_MAX_POS and returns true.
  3023. // Otherwise the Z calibration is not changed and false is returned.
  3024. void lcd_diag_show_end_stops()
  3025. {
  3026. lcd_clear();
  3027. lcd_consume_click();
  3028. for (;;) {
  3029. manage_heater();
  3030. manage_inactivity(true);
  3031. lcd_show_end_stops();
  3032. if (lcd_clicked()) {
  3033. break;
  3034. }
  3035. }
  3036. lcd_clear();
  3037. lcd_return_to_status();
  3038. }
  3039. static void lcd_print_state(uint8_t state)
  3040. {
  3041. switch (state) {
  3042. case STATE_ON:
  3043. lcd_puts_P(_N(" 1"));
  3044. break;
  3045. case STATE_OFF:
  3046. lcd_puts_P(_N(" 0"));
  3047. break;
  3048. default:
  3049. lcd_puts_P(_T(MSG_NA));
  3050. break;
  3051. }
  3052. }
  3053. //! @brief Show sensor state
  3054. //!
  3055. //! @code{.unparsed}
  3056. //! |01234567890123456789|
  3057. //! |PINDA N/A FINDA N/A| MSG_PINDA c=5 MSG_FINDA c=5
  3058. //! |Fil. sensor N/A| MSG_FSENSOR
  3059. //! | Int: 000 Xd:+00000|
  3060. //! |Shut: 000 Yd:+00000|
  3061. //! ----------------------
  3062. //! @endcode
  3063. static void lcd_show_sensors_state()
  3064. {
  3065. //0: N/A; 1: OFF; 2: ON
  3066. uint8_t pinda_state = STATE_NA;
  3067. uint8_t finda_state = STATE_NA;
  3068. uint8_t idler_state = STATE_NA;
  3069. pinda_state = READ(Z_MIN_PIN);
  3070. if (MMU2::mmu2.Enabled())
  3071. {
  3072. finda_state = MMU2::mmu2.FindaDetectsFilament();
  3073. }
  3074. lcd_puts_at_P(0, 0, MSG_PINDA);
  3075. lcd_set_cursor(LCD_WIDTH - 14, 0);
  3076. lcd_print_state(pinda_state);
  3077. if (MMU2::mmu2.Enabled())
  3078. {
  3079. lcd_puts_at_P(10, 0, _n("FINDA"));////MSG_FINDA c=5
  3080. lcd_set_cursor(LCD_WIDTH - 3, 0);
  3081. lcd_print_state(finda_state);
  3082. }
  3083. #ifdef FILAMENT_SENSOR
  3084. idler_state = fsensor.getFilamentPresent();
  3085. lcd_puts_at_P(0, 1, _T(MSG_FSENSOR));
  3086. lcd_set_cursor(LCD_WIDTH - 3, 1);
  3087. lcd_print_state(idler_state);
  3088. #endif //FILAMENT_SENSOR
  3089. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3090. // Display X and Y difference from Filament sensor
  3091. // Display Light intensity from Filament sensor
  3092. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  3093. // value ranges from 0(darkest) to 255(brightest).
  3094. // Display LASER shutter time from Filament sensor
  3095. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  3096. // auto-exposure algorithm. When the chip is tracking on a reflective surface, the Shutter is small.
  3097. // When the chip is tracking on a surface that absorbs IR (or doesn't reflect it), the Shutter is large.
  3098. // The maximum value of the shutter is 17. The value of 16 seems to be reported as 17 even though the
  3099. // Brightness value changes correctly as if the shutter changed to 16 (probably some bug with the sensor).
  3100. // The shutter algorithm tries to keep the B value in the 70-110 range.
  3101. lcd_set_cursor(0, 2);
  3102. lcd_printf_P(_N("B: %3d Xd:%6d\n"
  3103. "S: %3d Yd:%6d"),
  3104. pat9125_b, pat9125_x,
  3105. pat9125_s, pat9125_y);
  3106. #endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3107. }
  3108. void lcd_menu_show_sensors_state() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  3109. {
  3110. lcd_timeoutToStatus.stop();
  3111. lcd_show_sensors_state();
  3112. menu_back_if_clicked();
  3113. }
  3114. void lcd_move_menu_axis()
  3115. {
  3116. MENU_BEGIN();
  3117. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3118. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=18
  3119. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=18
  3120. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=18
  3121. MENU_ITEM_SUBMENU_P(_T(MSG_EXTRUDER), lcd_move_e);
  3122. MENU_END();
  3123. }
  3124. #ifdef SDCARD_SORT_ALPHA
  3125. static void lcd_sort_type_set() {
  3126. uint8_t sdSort;
  3127. sdSort = eeprom_read_byte((uint8_t*) EEPROM_SD_SORT);
  3128. switch (sdSort) {
  3129. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3130. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3131. default: sdSort = SD_SORT_TIME;
  3132. }
  3133. eeprom_update_byte((uint8_t*)EEPROM_SD_SORT, sdSort);
  3134. card.presort_flag = true;
  3135. }
  3136. #endif //SDCARD_SORT_ALPHA
  3137. #ifdef TMC2130
  3138. static void lcd_crash_mode_info()
  3139. {
  3140. lcd_update_enable(true);
  3141. static uint32_t tim = 0;
  3142. if ((tim + 1000) < _millis())
  3143. {
  3144. lcd_clear();
  3145. fputs_P(_i("Crash detection can\nbe turned on only in\nNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
  3146. tim = _millis();
  3147. }
  3148. menu_back_if_clicked();
  3149. }
  3150. static void lcd_crash_mode_info2()
  3151. {
  3152. lcd_update_enable(true);
  3153. static uint32_t tim = 0;
  3154. if ((tim + 1000) < _millis())
  3155. {
  3156. lcd_clear();
  3157. fputs_P(_i("WARNING:\nCrash detection\ndisabled in\nStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
  3158. tim = _millis();
  3159. }
  3160. menu_back_if_clicked();
  3161. }
  3162. #endif //TMC2130
  3163. //-//
  3164. static void lcd_sound_state_set(void)
  3165. {
  3166. Sound_CycleState();
  3167. }
  3168. #ifndef MMU_FORCE_STEALTH_MODE
  3169. static void lcd_silent_mode_mmu_set() {
  3170. if (SilentModeMenu_MMU == 1) SilentModeMenu_MMU = 0;
  3171. else SilentModeMenu_MMU = 1;
  3172. //saving to eeprom is done in mmu_loop() after mmu actually switches state and confirms with "ok"
  3173. }
  3174. #endif //MMU_FORCE_STEALTH_MODE
  3175. static void lcd_silent_mode_set() {
  3176. switch (SilentModeMenu) {
  3177. #ifdef TMC2130
  3178. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3179. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3180. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3181. #else
  3182. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3183. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3184. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3185. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3186. #endif //TMC2130
  3187. }
  3188. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3189. #ifdef TMC2130
  3190. lcd_display_message_fullscreen_P(_i("Mode change in progress..."));////MSG_MODE_CHANGE_IN_PROGRESS c=20 r=3
  3191. // Wait until the planner queue is drained and the stepper routine achieves
  3192. // an idle state.
  3193. st_synchronize();
  3194. if (tmc2130_wait_standstill_xy(1000)) {}
  3195. // MYSERIAL.print("standstill OK");
  3196. // else
  3197. // MYSERIAL.print("standstill NG!");
  3198. cli();
  3199. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3200. update_mode_profile();
  3201. tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  3202. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3203. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3204. st_reset_timer();
  3205. sei();
  3206. #endif //TMC2130
  3207. st_current_init();
  3208. #ifdef TMC2130
  3209. if (lcd_crash_detect_enabled() && (SilentModeMenu != SILENT_MODE_NORMAL))
  3210. menu_submenu(lcd_crash_mode_info2);
  3211. lcd_encoder_diff=0; // reset 'encoder buffer'
  3212. #endif //TMC2130
  3213. }
  3214. #ifdef TMC2130
  3215. static void crash_mode_switch()
  3216. {
  3217. if (lcd_crash_detect_enabled())
  3218. {
  3219. lcd_crash_detect_disable();
  3220. }
  3221. else
  3222. {
  3223. lcd_crash_detect_enable();
  3224. }
  3225. if (IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true);
  3226. else menu_goto(lcd_settings_menu, 9, true, true);
  3227. }
  3228. #endif //TMC2130
  3229. #if (LANG_MODE != 0)
  3230. void menu_setlang(unsigned char lang)
  3231. {
  3232. if (!lang_select(lang))
  3233. {
  3234. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language?"), false, LCD_LEFT_BUTTON_CHOICE) == LCD_LEFT_BUTTON_CHOICE)////MSG_COPY_SEL_LANG c=20 r=3
  3235. lang_boot_update_start(lang);
  3236. lcd_update_enable(true);
  3237. lcd_clear();
  3238. menu_goto(lcd_language_menu, 0, true, true);
  3239. lcd_timeoutToStatus.stop(); //infinite timeout
  3240. lcd_draw_update = 2;
  3241. }
  3242. }
  3243. #ifdef COMMUNITY_LANGUAGE_SUPPORT
  3244. #ifdef XFLASH
  3245. static void lcd_community_language_menu()
  3246. {
  3247. MENU_BEGIN();
  3248. uint8_t cnt = lang_get_count();
  3249. MENU_ITEM_BACK_P(_T(MSG_SELECT_LANGUAGE)); //Back to previous Menu
  3250. for (int i = 8; i < cnt; i++) //all community languages
  3251. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3252. {
  3253. menu_setlang(i);
  3254. return;
  3255. }
  3256. MENU_END();
  3257. }
  3258. #endif //XFLASH
  3259. #endif //COMMUNITY_LANGUAGE_SUPPORT && W52X20CL
  3260. static void lcd_language_menu()
  3261. {
  3262. MENU_BEGIN();
  3263. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3264. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3265. {
  3266. menu_setlang(0);
  3267. return;
  3268. }
  3269. uint8_t cnt = lang_get_count();
  3270. #ifdef XFLASH
  3271. if (cnt == 2) //display secondary language in case of clear xflash
  3272. {
  3273. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3274. {
  3275. menu_setlang(1);
  3276. return;
  3277. }
  3278. }
  3279. else
  3280. for (int i = 2; i < 8; i++) //skip seconday language - solved in lang_select (MK3) 'i < 8' for 7 official languages
  3281. #else //XFLASH
  3282. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3283. #endif //XFLASH
  3284. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3285. {
  3286. menu_setlang(i);
  3287. return;
  3288. }
  3289. #ifdef COMMUNITY_LANGUAGE_SUPPORT
  3290. #ifdef XFLASH
  3291. MENU_ITEM_SUBMENU_P(_T(MSG_COMMUNITY_MADE), lcd_community_language_menu);
  3292. #endif //XFLASH
  3293. #endif //COMMUNITY_LANGUAGE_SUPPORT && W52X20CL
  3294. MENU_END();
  3295. }
  3296. #endif //(LANG_MODE != 0)
  3297. void lcd_mesh_bedleveling()
  3298. {
  3299. enquecommand_P(PSTR("G80"));
  3300. lcd_return_to_status();
  3301. }
  3302. void lcd_mesh_calibration()
  3303. {
  3304. enquecommand_P(PSTR("M45"));
  3305. lcd_return_to_status();
  3306. }
  3307. void lcd_mesh_calibration_z()
  3308. {
  3309. enquecommand_P(PSTR("M45 Z"));
  3310. lcd_return_to_status();
  3311. }
  3312. void lcd_temp_calibration_set() {
  3313. bool temp_cal_active = eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE);
  3314. temp_cal_active = !temp_cal_active;
  3315. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3316. }
  3317. #ifdef HAS_SECOND_SERIAL_PORT
  3318. void lcd_second_serial_set() {
  3319. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3320. else selectedSerialPort = 1;
  3321. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3322. MYSERIAL.begin(BAUDRATE);
  3323. }
  3324. #endif //HAS_SECOND_SERIAL_PORT
  3325. void lcd_calibrate_pinda() {
  3326. enquecommand_P(PSTR("G76"));
  3327. lcd_return_to_status();
  3328. }
  3329. void lcd_toshiba_flash_air_compatibility_toggle()
  3330. {
  3331. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3332. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3333. }
  3334. //! @brief Continue first layer calibration with previous value or start from zero?
  3335. //!
  3336. //! @code{.unparsed}
  3337. //! |01234567890123456789|
  3338. //! |Sheet Smooth1| MSG_SHEET c=12, MSG_SHEET_NAME c=7
  3339. //! |Z offset: -1.480mm| MSG_Z_OFFSET c=11
  3340. //! |>Continue | MSG_CONTINUE
  3341. //! | Reset | MSG_RESET
  3342. //! ----------------------
  3343. //! @endcode
  3344. void lcd_first_layer_calibration_reset()
  3345. {
  3346. typedef struct
  3347. {
  3348. bool reset;
  3349. } MenuData;
  3350. static_assert(sizeof(menu_data)>= sizeof(MenuData),"_menu_data_t doesn't fit into menu_data");
  3351. MenuData* menuData = (MenuData*)&(menu_data[0]);
  3352. if(LCD_CLICKED || !eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))) ||
  3353. (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST) ||
  3354. (0 == static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>
  3355. (&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))))
  3356. {
  3357. if (menuData->reset)
  3358. {
  3359. eeprom_update_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset), 0xffff);
  3360. }
  3361. menu_goto(lcd_v2_calibration,0,true,true);
  3362. }
  3363. if (lcd_encoder > 0)
  3364. {
  3365. menuData->reset = true;
  3366. lcd_encoder = 1;
  3367. }
  3368. else if (lcd_encoder < 1)
  3369. {
  3370. menuData->reset = false;
  3371. lcd_encoder = 0;
  3372. }
  3373. char sheet_name[sizeof(Sheet::name)];
  3374. eeprom_read_block(sheet_name, &EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].name, sizeof(Sheet::name));
  3375. lcd_set_cursor(0, 0);
  3376. float offset = static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))/cs.axis_steps_per_unit[Z_AXIS];
  3377. lcd_printf_P(_i("Sheet %.7s\nZ offset: %+1.3fmm\n%cContinue\n%cReset"),////MSG_SHEET_OFFSET c=20 r=4
  3378. sheet_name, offset, menuData->reset ? ' ' : '>', menuData->reset ? '>' : ' ');// \n denotes line break, %.7s is replaced by 7 character long sheet name, %+1.3f is replaced by 6 character long floating point number, %c is replaced by > or white space (one character) based on whether first or second option is selected. % denoted place holders can not be reordered.
  3379. }
  3380. void lcd_v2_calibration()
  3381. {
  3382. if (MMU2::mmu2.Enabled())
  3383. {
  3384. const uint8_t filament = choose_menu_P(
  3385. _T(MSG_SELECT_FILAMENT),
  3386. _T(MSG_FILAMENT),(_T(MSG_CANCEL)+1)); //Hack to reuse MSG but strip 1st char off
  3387. if (filament < 5)
  3388. {
  3389. lay1cal_filament = filament;
  3390. }
  3391. else
  3392. {
  3393. menu_back();
  3394. return;
  3395. }
  3396. }
  3397. #ifdef FILAMENT_SENSOR
  3398. else if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  3399. {
  3400. bool loaded = false;
  3401. if (fsensor.isReady())
  3402. {
  3403. loaded = fsensor.getFilamentPresent();
  3404. }
  3405. else
  3406. {
  3407. loaded = !lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), false, LCD_LEFT_BUTTON_CHOICE);
  3408. lcd_update_enabled = true;
  3409. }
  3410. if (!loaded)
  3411. {
  3412. lcd_display_message_fullscreen_P(_i("Please load filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3413. lcd_consume_click();
  3414. for (uint_least8_t i = 0; i < 20; i++) { //wait max. 2s
  3415. delay_keep_alive(100);
  3416. if (lcd_clicked()) {
  3417. break;
  3418. }
  3419. }
  3420. lcd_update_enabled = true;
  3421. menu_back();
  3422. return;
  3423. }
  3424. }
  3425. #endif //FILAMENT_SENSOR
  3426. eFilamentAction = FilamentAction::Lay1Cal;
  3427. menu_goto(lcd_generic_preheat_menu, 0, true, true);
  3428. }
  3429. void lcd_wizard() {
  3430. bool result = true;
  3431. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3432. result = !lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Running Wizard will delete current calibration results and start from the beginning. Continue?"), false);////MSG_WIZARD_RERUN c=20 r=7
  3433. }
  3434. if (result) {
  3435. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3436. lcd_wizard(WizState::Run);
  3437. }
  3438. else {
  3439. lcd_return_to_status();
  3440. lcd_update_enable(true);
  3441. lcd_update(2);
  3442. }
  3443. }
  3444. #if (LANG_MODE != 0)
  3445. void lcd_language()
  3446. {
  3447. lcd_update_enable(true);
  3448. lcd_clear();
  3449. menu_goto(lcd_language_menu, 0, true, true);
  3450. lcd_timeoutToStatus.stop(); //infinite timeout
  3451. lcd_draw_update = 2;
  3452. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  3453. {
  3454. _delay(50);
  3455. lcd_update(0);
  3456. manage_heater();
  3457. manage_inactivity(true);
  3458. }
  3459. if (lang_is_selected())
  3460. lcd_return_to_status();
  3461. else
  3462. lang_select(LANG_ID_PRI);
  3463. }
  3464. #endif
  3465. static void wait_preheat()
  3466. {
  3467. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3468. plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS] / 60);
  3469. delay_keep_alive(2000);
  3470. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3471. while (fabs(degHotend(0) - degTargetHotend(0)) > 3) {
  3472. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3473. lcd_set_cursor(0, 4);
  3474. //Print the hotend temperature (9 chars total)
  3475. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  3476. delay_keep_alive(1000);
  3477. }
  3478. }
  3479. static void lcd_wizard_load() {
  3480. if (MMU2::mmu2.Enabled()) {
  3481. lcd_show_fullscreen_message_and_wait_P(
  3482. _i("Please insert filament into the first tube of the MMU, then press the knob to load it.")); ////MSG_MMU_INSERT_FILAMENT_FIRST_TUBE c=20 r=6
  3483. } else {
  3484. lcd_show_fullscreen_message_and_wait_P(
  3485. _i("Please insert filament into the extruder, then press the knob to load it.")); ////MSG_WIZARD_LOAD_FILAMENT c=20 r=6
  3486. }
  3487. lcd_update_enable(false);
  3488. lcd_clear();
  3489. lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
  3490. loading_flag = true;
  3491. gcode_M701(FILAMENTCHANGE_FIRSTFEED, 0);
  3492. //enquecommand_P(PSTR("M701"));
  3493. }
  3494. static void wizard_lay1cal_message(bool cold)
  3495. {
  3496. lcd_show_fullscreen_message_and_wait_P(
  3497. _i("Now I will calibrate distance between tip of the nozzle and heatbed surface.")); ////MSG_WIZARD_V2_CAL c=20 r=8
  3498. if (MMU2::mmu2.Enabled())
  3499. {
  3500. lcd_show_fullscreen_message_and_wait_P(
  3501. _i("Select a filament for the First Layer Calibration and select it in the on-screen menu."));////MSG_SELECT_FIL_1ST_LAYERCAL c=20 r=7
  3502. }
  3503. else if (cold)
  3504. {
  3505. lcd_show_fullscreen_message_and_wait_P(
  3506. _i("Select temperature which matches your material."));////MSG_SELECT_TEMP_MATCHES_MATERIAL c=20 r=4
  3507. }
  3508. lcd_show_fullscreen_message_and_wait_P(
  3509. _i("The printer will start printing a zig-zag line. Rotate the knob until you reach the optimal height. Check the pictures in the handbook (Calibration chapter).")); ////MSG_WIZARD_V2_CAL_2 c=20 r=12
  3510. }
  3511. //! @brief Printer first run wizard (Selftest and calibration)
  3512. //!
  3513. //!
  3514. //! First layer calibration with MMU state diagram
  3515. //!
  3516. //! @startuml
  3517. //! [*] --> IsFil
  3518. //! IsFil : Is any filament loaded?
  3519. //! LoadFilCold : Push the button to start loading Filament 1
  3520. //!
  3521. //! IsFil --> Lay1CalCold : yes
  3522. //! IsFil --> LoadFilCold : no
  3523. //! LoadFilCold --> Lay1CalCold : click
  3524. //! @enduml
  3525. //!
  3526. //! First layer calibration without MMU state diagram
  3527. //!
  3528. //! @startuml
  3529. //! [*] --> IsFil
  3530. //! IsFil : Is filament loaded?
  3531. //! Preheat : Select nozle temperature which matches your material.
  3532. //! LoadFilHot : Insert filament to extruder and press the knob.
  3533. //!
  3534. //! IsFil --> Lay1CalCold : yes
  3535. //! IsFil --> Preheat : no
  3536. //! Preheat --> LoadFilHot : select
  3537. //! LoadFilHot --> Lay1CalHot : click
  3538. //! @enduml
  3539. //!
  3540. //! @param state Entry point of the wizard
  3541. //!
  3542. //! state | description
  3543. //! ---------------------- | ----------------
  3544. //! WizState::Run | Main entry point
  3545. //! WizState::RepeatLay1Cal | Entry point after passing 1st layer calibration
  3546. //! WizState::LoadFilHot | Entry point after temporarily left for preheat before load filament
  3547. void lcd_wizard(WizState state)
  3548. {
  3549. using S = WizState;
  3550. bool end = false;
  3551. uint8_t wizard_event;
  3552. const char *msg = NULL;
  3553. // Make sure EEPROM_WIZARD_ACTIVE is true if entering using different entry point
  3554. // other than WizState::Run - it is useful for debugging wizard.
  3555. if (state != S::Run) eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3556. FORCE_BL_ON_START;
  3557. while (!end) {
  3558. printf_P(PSTR("Wizard state: %d\n"), state);
  3559. switch (state) {
  3560. case S::Run: //Run wizard?
  3561. // 2019-08-07 brutal hack - solving the "viper" situation.
  3562. // It is caused by the fact, that tmc2130_st_isr makes a crash detection before the printers really starts.
  3563. // And thus it calles stop_and_save_print_to_ram which sets the saved_printing flag.
  3564. // Having this flag set during normal printing is lethal - mesh_plan_buffer_line exist in the middle of planning long travels
  3565. // which results in distorted print.
  3566. // This primarily happens when the printer is new and parked in 0,0
  3567. // So any new printer will fail the first layer calibration unless being reset or the Stop function gets called.
  3568. // We really must find a way to prevent the crash from happening before the printer is started - that would be the correct solution.
  3569. // Btw. the flag may even trigger the viper situation on normal start this way and the user won't be able to find out why.
  3570. saved_printing = false;
  3571. if( eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)==2){
  3572. lcd_show_fullscreen_message_and_wait_P(_T(MSG_WIZARD_WELCOME_SHIPPING));
  3573. state = S::Restore;
  3574. } else {
  3575. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_T(MSG_WIZARD_WELCOME), false, LCD_LEFT_BUTTON_CHOICE);
  3576. if (wizard_event == LCD_LEFT_BUTTON_CHOICE) {
  3577. state = S::Restore;
  3578. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3579. } else { // MIDDLE_BUTTON_CHOICE
  3580. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3581. end = true;
  3582. }
  3583. }
  3584. break;
  3585. case S::Restore:
  3586. switch (calibration_status()) {
  3587. case CALIBRATION_STATUS_ASSEMBLED: state = S::Selftest; break; //run selftest
  3588. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = S::Xyz; break; //run xyz cal.
  3589. case CALIBRATION_STATUS_Z_CALIBRATION: state = S::Z; break; //run z cal.
  3590. case CALIBRATION_STATUS_LIVE_ADJUST: state = S::IsFil; break; //run live adjust
  3591. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3592. default: state = S::Selftest; break; //if calibration status is unknown, run wizard from the beginning
  3593. }
  3594. break;
  3595. case S::Selftest:
  3596. lcd_show_fullscreen_message_and_wait_P(_i("First, I will run the selftest to check most common assembly problems."));////MSG_WIZARD_SELFTEST c=20 r=8
  3597. wizard_event = lcd_selftest();
  3598. if (wizard_event) {
  3599. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3600. state = S::Xyz;
  3601. }
  3602. else end = true;
  3603. break;
  3604. case S::Xyz:
  3605. lcd_show_fullscreen_message_and_wait_P(_i("I will run xyz calibration now. It will take approx. 12 mins."));////MSG_WIZARD_XYZ_CAL c=20 r=8
  3606. wizard_event = gcode_M45(false, 0);
  3607. if (wizard_event) state = S::IsFil;
  3608. else end = true;
  3609. break;
  3610. case S::Z:
  3611. lcd_show_fullscreen_message_and_wait_P(_i("Please remove shipping helpers first."));////MSG_REMOVE_SHIPPING_HELPERS c=20 r=3
  3612. lcd_show_fullscreen_message_and_wait_P(_i("Now remove the test print from steel sheet."));////MSG_REMOVE_TEST_PRINT c=20 r=4
  3613. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3614. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false);
  3615. if (wizard_event == LCD_MIDDLE_BUTTON_CHOICE) {
  3616. lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3617. }
  3618. wizard_event = gcode_M45(true, 0);
  3619. if (wizard_event) {
  3620. //current filament needs to be unloaded and then new filament should be loaded
  3621. //start to preheat nozzle for unloading remaining PLA filament
  3622. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3623. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA.")); ////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3624. wait_preheat();
  3625. //unload current filament
  3626. unload_filament(FILAMENTCHANGE_FINALRETRACT, true);
  3627. //load filament
  3628. lcd_wizard_load();
  3629. setTargetHotend(0, 0); //we are finished, cooldown nozzle
  3630. state = S::Finish; //shipped, no need to set first layer, go to final message directly
  3631. }
  3632. else end = true;
  3633. break;
  3634. case S::IsFil:
  3635. //start to preheat nozzle and bed to save some time later
  3636. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3637. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3638. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), true);
  3639. if (wizard_event == LCD_LEFT_BUTTON_CHOICE) {
  3640. state = S::Lay1CalCold;
  3641. } else { // MIDDLE_BUTTON_CHOICE
  3642. if(MMU2::mmu2.Enabled()) state = S::LoadFilCold;
  3643. else state = S::Preheat;
  3644. }
  3645. break;
  3646. case S::Preheat:
  3647. menu_goto(lcd_preheat_menu,0,false,true);
  3648. lcd_show_fullscreen_message_and_wait_P(_i("Select nozzle preheat temperature which matches your material."));////MSG_SEL_PREHEAT_TEMP c=20 r=6
  3649. end = true; // Leave wizard temporarily for lcd_preheat_menu
  3650. break;
  3651. case S::LoadFilHot:
  3652. wait_preheat();
  3653. lcd_wizard_load();
  3654. state = S::Lay1CalHot;
  3655. break;
  3656. case S::LoadFilCold:
  3657. lcd_wizard_load();
  3658. state = S::Lay1CalCold;
  3659. break;
  3660. case S::Lay1CalCold:
  3661. wizard_lay1cal_message(true);
  3662. menu_goto(lcd_v2_calibration,0,false,true);
  3663. end = true; // Leave wizard temporarily for lcd_v2_calibration
  3664. break;
  3665. case S::Lay1CalHot:
  3666. wizard_lay1cal_message(false);
  3667. lcd_commands_type = LcdCommands::Layer1Cal;
  3668. end = true; // Leave wizard temporarily for lcd_v2_calibration
  3669. break;
  3670. case S::RepeatLay1Cal:
  3671. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Do you want to repeat last step to readjust distance between nozzle and heatbed?"), false);////MSG_WIZARD_REPEAT_V2_CAL c=20 r=7
  3672. if (wizard_event == LCD_LEFT_BUTTON_CHOICE)
  3673. {
  3674. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3675. state = S::Lay1CalCold;
  3676. }
  3677. else
  3678. {
  3679. lcd_show_fullscreen_message_and_wait_P(_i("If you have additional steel sheets, calibrate their presets in Settings - HW Setup - Steel sheets."));////MSG_ADDITIONAL_SHEETS c=20 r=9
  3680. state = S::Finish;
  3681. }
  3682. break;
  3683. case S::Finish:
  3684. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3685. end = true;
  3686. break;
  3687. default: break;
  3688. }
  3689. }
  3690. FORCE_BL_ON_END;
  3691. printf_P(_N("Wizard end state: %d\n"), state);
  3692. switch (state) { //final message
  3693. case S::Restore: //printer was already calibrated
  3694. msg = _T(MSG_WIZARD_DONE);
  3695. break;
  3696. case S::Selftest: //selftest
  3697. case S::Xyz: //xyz cal.
  3698. case S::Z: //z cal.
  3699. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3700. break;
  3701. case S::Finish: //we are finished
  3702. msg = _T(MSG_WIZARD_DONE);
  3703. lcd_reset_alert_level();
  3704. lcd_setstatuspgm(MSG_WELCOME);
  3705. lcd_return_to_status();
  3706. break;
  3707. default:
  3708. msg = _T(MSG_WIZARD_QUIT);
  3709. break;
  3710. }
  3711. if (!((S::Lay1CalCold == state) || (S::Lay1CalHot == state) || (S::Preheat == state)))
  3712. {
  3713. lcd_show_fullscreen_message_and_wait_P(msg);
  3714. }
  3715. lcd_update_enable(true);
  3716. lcd_update(2);
  3717. }
  3718. #ifdef TMC2130
  3719. void lcd_settings_linearity_correction_menu(void)
  3720. {
  3721. MENU_BEGIN();
  3722. ON_MENU_LEAVE(
  3723. lcd_settings_linearity_correction_menu_save();
  3724. );
  3725. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3726. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3727. //tmc2130_wave_fac[X_AXIS]
  3728. MENU_ITEM_EDIT_int3_P(_i("X-correct:"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_X_CORRECTION c=13
  3729. MENU_ITEM_EDIT_int3_P(_i("Y-correct:"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_Y_CORRECTION c=13
  3730. MENU_ITEM_EDIT_int3_P(_i("Z-correct:"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_Z_CORRECTION c=13
  3731. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3732. MENU_ITEM_EDIT_int3_P(_i("E-correct:"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_EXTRUDER_CORRECTION c=13
  3733. MENU_END();
  3734. }
  3735. #endif // TMC2130
  3736. #ifdef FILAMENT_SENSOR
  3737. static void fsensor_reinit() {
  3738. fsensor.init();
  3739. }
  3740. static void lcd_fsensor_enabled_set(void) {
  3741. fsensor.setEnabled(!fsensor.isEnabled());
  3742. }
  3743. static void lcd_fsensor_runout_set() {
  3744. fsensor.setRunoutEnabled(!fsensor.getRunoutEnabled(), true);
  3745. }
  3746. static void lcd_fsensor_autoload_set() {
  3747. fsensor.setAutoLoadEnabled(!fsensor.getAutoLoadEnabled(), true);
  3748. }
  3749. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  3750. static void lcd_fsensor_jam_detection_set() {
  3751. fsensor.setJamDetectionEnabled(!fsensor.getJamDetectionEnabled(), true);
  3752. }
  3753. #endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  3754. static void lcd_fsensor_actionNA_set(void)
  3755. {
  3756. Filament_sensor::SensorActionOnError act = fsensor.getActionOnError();
  3757. switch(act) {
  3758. case Filament_sensor::SensorActionOnError::_Continue:
  3759. act = Filament_sensor::SensorActionOnError::_Pause;
  3760. break;
  3761. case Filament_sensor::SensorActionOnError::_Pause:
  3762. act = Filament_sensor::SensorActionOnError::_Continue;
  3763. break;
  3764. default:
  3765. act = Filament_sensor::SensorActionOnError::_Continue;
  3766. }
  3767. fsensor.setActionOnError(act, true);
  3768. }
  3769. static void lcd_fsensor_settings_menu() {
  3770. MENU_BEGIN();
  3771. MENU_ITEM_BACK_P(_T(MSG_BACK));
  3772. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), fsensor.isEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_enabled_set);
  3773. if (fsensor.isEnabled()) {
  3774. if (fsensor.isError()) {
  3775. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_RUNOUT), _T(MSG_NA), fsensor_reinit);
  3776. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_NA), fsensor_reinit);
  3777. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3778. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_JAM_DETECTION), _T(MSG_NA), fsensor_reinit);
  3779. #endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3780. }
  3781. else {
  3782. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_RUNOUT), fsensor.getRunoutEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_runout_set);
  3783. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), fsensor.getAutoLoadEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_autoload_set);
  3784. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3785. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_JAM_DETECTION), fsensor.getJamDetectionEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_jam_detection_set);
  3786. #endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3787. }
  3788. switch(fsensor.getActionOnError()) {
  3789. case Filament_sensor::SensorActionOnError::_Continue:
  3790. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_CONTINUE_SHORT), lcd_fsensor_actionNA_set);
  3791. break;
  3792. case Filament_sensor::SensorActionOnError::_Pause:
  3793. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_PAUSE), lcd_fsensor_actionNA_set);
  3794. break;
  3795. default:
  3796. lcd_fsensor_actionNA_set();
  3797. }
  3798. }
  3799. MENU_END();
  3800. }
  3801. #endif //FILAMENT_SENSOR
  3802. static void settingsSpoolJoin()
  3803. {
  3804. MENU_ITEM_TOGGLE_P(MSG_SPOOL_JOIN, SpoolJoin::spooljoin.isSpoolJoinEnabled() ? _T(MSG_ON) : _T(MSG_OFF), SpoolJoin::spooljoin.toggleSpoolJoin);
  3805. }
  3806. #define SETTINGS_SPOOLJOIN \
  3807. do\
  3808. {\
  3809. settingsSpoolJoin();\
  3810. }\
  3811. while(0)\
  3812. #ifdef MMU_HAS_CUTTER
  3813. static void settingsCutter()
  3814. {
  3815. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  3816. {
  3817. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_ON), lcd_cutter_enabled);
  3818. }
  3819. #ifdef MMU_ALWAYS_CUT
  3820. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  3821. {
  3822. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_ALWAYS), lcd_cutter_enabled);
  3823. }
  3824. #endif
  3825. else
  3826. {
  3827. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_OFF), lcd_cutter_enabled);
  3828. }
  3829. }
  3830. #define SETTINGS_CUTTER \
  3831. do\
  3832. {\
  3833. settingsCutter();\
  3834. }\
  3835. while(0)
  3836. #else
  3837. #define SETTINGS_CUTTER
  3838. #endif //MMU_HAS_CUTTER
  3839. static void mmu_enable_switch()
  3840. {
  3841. uint8_t current_state = eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED);
  3842. // EEPROM update is handled by the stop and start functions.
  3843. if (current_state)
  3844. {
  3845. MMU2::mmu2.Stop();
  3846. }
  3847. else
  3848. {
  3849. MMU2::mmu2.Start();
  3850. }
  3851. }
  3852. static void mmu_reset()
  3853. {
  3854. MMU2::mmu2.Reset(MMU2::MMU2::ResetForm::Software);
  3855. }
  3856. #ifdef TMC2130
  3857. #define SETTINGS_SILENT_MODE \
  3858. do\
  3859. {\
  3860. if(!farm_mode)\
  3861. {\
  3862. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  3863. {\
  3864. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\
  3865. }\
  3866. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);\
  3867. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  3868. {\
  3869. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);\
  3870. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);\
  3871. }\
  3872. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);\
  3873. }\
  3874. }\
  3875. while (0)
  3876. #else //TMC2130
  3877. #define SETTINGS_SILENT_MODE \
  3878. do\
  3879. {\
  3880. if(!farm_mode)\
  3881. {\
  3882. switch (SilentModeMenu)\
  3883. {\
  3884. case SILENT_MODE_POWER:\
  3885. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  3886. break;\
  3887. case SILENT_MODE_SILENT:\
  3888. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set);\
  3889. break;\
  3890. case SILENT_MODE_AUTO:\
  3891. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set);\
  3892. break;\
  3893. default:\
  3894. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  3895. break; /* (probably) not needed*/\
  3896. }\
  3897. }\
  3898. }\
  3899. while (0)
  3900. #endif //TMC2130
  3901. #ifndef MMU_FORCE_STEALTH_MODE
  3902. #define SETTINGS_MMU_MODE \
  3903. do\
  3904. {\
  3905. if (MMU2::mmu2.Enabled())\
  3906. {\
  3907. if (SilentModeMenu_MMU == 0) MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_NORMAL), lcd_silent_mode_mmu_set);\
  3908. else MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_STEALTH), lcd_silent_mode_mmu_set);\
  3909. }\
  3910. }\
  3911. while (0)
  3912. #else //MMU_FORCE_STEALTH_MODE
  3913. #define SETTINGS_MMU_MODE
  3914. #endif //MMU_FORCE_STEALTH_MODE
  3915. /*
  3916. #define SETTINGS_MBL_MODE \
  3917. do\
  3918. {\
  3919. switch(e_mbl_type)\
  3920. {\
  3921. case e_MBL_FAST:\
  3922. MENU_ITEM_FUNCTION_P(_n("Mode [Fast]"),mbl_mode_set);\
  3923. break; \
  3924. case e_MBL_OPTIMAL:\
  3925. MENU_ITEM_FUNCTION_P(_n("Mode [Optimal]"), mbl_mode_set); \
  3926. break; \
  3927. case e_MBL_PREC:\
  3928. MENU_ITEM_FUNCTION_P(_n("Mode [Precise]"), mbl_mode_set); \
  3929. break; \
  3930. default:\
  3931. MENU_ITEM_FUNCTION_P(_n("Mode [Optimal]"), mbl_mode_set); \
  3932. break; \
  3933. }\
  3934. }\
  3935. while (0)
  3936. */
  3937. #define SETTINGS_MMU_LOADING_TEST \
  3938. do\
  3939. {\
  3940. MENU_ITEM_SUBMENU_P(_T(MSG_LOADING_TEST), mmu_loading_test_menu); \
  3941. }\
  3942. while (0)
  3943. #define SETTINGS_SOUND \
  3944. do\
  3945. {\
  3946. switch(eSoundMode)\
  3947. {\
  3948. case e_SOUND_MODE_LOUD:\
  3949. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  3950. break;\
  3951. case e_SOUND_MODE_ONCE:\
  3952. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_ONCE), lcd_sound_state_set);\
  3953. break;\
  3954. case e_SOUND_MODE_SILENT:\
  3955. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SILENT), lcd_sound_state_set);\
  3956. break;\
  3957. case e_SOUND_MODE_BLIND:\
  3958. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_BLIND), lcd_sound_state_set);\
  3959. break;\
  3960. default:\
  3961. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  3962. }\
  3963. }\
  3964. while (0)
  3965. //-//
  3966. static void lcd_check_mode_set(void)
  3967. {
  3968. switch(oCheckMode)
  3969. {
  3970. case ClCheckMode::_None:
  3971. oCheckMode=ClCheckMode::_Warn;
  3972. break;
  3973. case ClCheckMode::_Warn:
  3974. oCheckMode=ClCheckMode::_Strict;
  3975. break;
  3976. case ClCheckMode::_Strict:
  3977. oCheckMode=ClCheckMode::_None;
  3978. break;
  3979. default:
  3980. oCheckMode=ClCheckMode::_None;
  3981. }
  3982. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)oCheckMode);
  3983. }
  3984. #define SETTINGS_MODE \
  3985. do\
  3986. {\
  3987. switch(oCheckMode)\
  3988. {\
  3989. case ClCheckMode::_None:\
  3990. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  3991. break;\
  3992. case ClCheckMode::_Warn:\
  3993. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_WARN), lcd_check_mode_set);\
  3994. break;\
  3995. case ClCheckMode::_Strict:\
  3996. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_STRICT), lcd_check_mode_set);\
  3997. break;\
  3998. default:\
  3999. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  4000. }\
  4001. }\
  4002. while (0)
  4003. static void lcd_nozzle_diameter_cycle(void) {
  4004. uint16_t nDiameter;
  4005. switch(oNozzleDiameter){
  4006. case ClNozzleDiameter::_Diameter_250:
  4007. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4008. nDiameter=400;
  4009. break;
  4010. case ClNozzleDiameter::_Diameter_400:
  4011. oNozzleDiameter=ClNozzleDiameter::_Diameter_600;
  4012. nDiameter=600;
  4013. break;
  4014. case ClNozzleDiameter::_Diameter_600:
  4015. oNozzleDiameter=ClNozzleDiameter::_Diameter_800;
  4016. nDiameter=800;
  4017. break;
  4018. case ClNozzleDiameter::_Diameter_800:
  4019. oNozzleDiameter=ClNozzleDiameter::_Diameter_250;
  4020. nDiameter=250;
  4021. break;
  4022. default:
  4023. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4024. nDiameter=400;
  4025. }
  4026. eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)oNozzleDiameter);
  4027. eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter);
  4028. }
  4029. #define SETTINGS_NOZZLE \
  4030. do\
  4031. {\
  4032. float fNozzleDiam;\
  4033. switch(oNozzleDiameter)\
  4034. {\
  4035. case ClNozzleDiameter::_Diameter_250: fNozzleDiam = 0.25f; break;\
  4036. case ClNozzleDiameter::_Diameter_400: fNozzleDiam = 0.4f; break;\
  4037. case ClNozzleDiameter::_Diameter_600: fNozzleDiam = 0.6f; break;\
  4038. case ClNozzleDiameter::_Diameter_800: fNozzleDiam = 0.8f; break;\
  4039. default: fNozzleDiam = 0.4f; break;\
  4040. }\
  4041. MENU_ITEM_TOGGLE(_T(MSG_NOZZLE_DIAMETER), ftostr12ns(fNozzleDiam), lcd_nozzle_diameter_cycle);\
  4042. }\
  4043. while (0)
  4044. static void lcd_check_model_set(void)
  4045. {
  4046. switch(oCheckModel)
  4047. {
  4048. case ClCheckModel::_None:
  4049. oCheckModel=ClCheckModel::_Warn;
  4050. break;
  4051. case ClCheckModel::_Warn:
  4052. oCheckModel=ClCheckModel::_Strict;
  4053. break;
  4054. case ClCheckModel::_Strict:
  4055. oCheckModel=ClCheckModel::_None;
  4056. break;
  4057. default:
  4058. oCheckModel=ClCheckModel::_None;
  4059. }
  4060. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODEL,(uint8_t)oCheckModel);
  4061. }
  4062. #define SETTINGS_MODEL \
  4063. do\
  4064. {\
  4065. switch(oCheckModel)\
  4066. {\
  4067. case ClCheckModel::_None:\
  4068. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4069. break;\
  4070. case ClCheckModel::_Warn:\
  4071. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_WARN), lcd_check_model_set);\
  4072. break;\
  4073. case ClCheckModel::_Strict:\
  4074. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_STRICT), lcd_check_model_set);\
  4075. break;\
  4076. default:\
  4077. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4078. }\
  4079. }\
  4080. while (0)
  4081. static void lcd_check_version_set(void)
  4082. {
  4083. switch(oCheckVersion)
  4084. {
  4085. case ClCheckVersion::_None:
  4086. oCheckVersion=ClCheckVersion::_Warn;
  4087. break;
  4088. case ClCheckVersion::_Warn:
  4089. oCheckVersion=ClCheckVersion::_Strict;
  4090. break;
  4091. case ClCheckVersion::_Strict:
  4092. oCheckVersion=ClCheckVersion::_None;
  4093. break;
  4094. default:
  4095. oCheckVersion=ClCheckVersion::_None;
  4096. }
  4097. eeprom_update_byte((uint8_t*)EEPROM_CHECK_VERSION,(uint8_t)oCheckVersion);
  4098. }
  4099. #define SETTINGS_VERSION \
  4100. do\
  4101. {\
  4102. switch(oCheckVersion)\
  4103. {\
  4104. case ClCheckVersion::_None:\
  4105. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_NONE), lcd_check_version_set);\
  4106. break;\
  4107. case ClCheckVersion::_Warn:\
  4108. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_WARN), lcd_check_version_set);\
  4109. break;\
  4110. case ClCheckVersion::_Strict:\
  4111. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_STRICT), lcd_check_version_set);\
  4112. break;\
  4113. default:\
  4114. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_NONE), lcd_check_version_set);\
  4115. }\
  4116. }\
  4117. while (0)
  4118. static void lcd_checking_menu(void)
  4119. {
  4120. MENU_BEGIN();
  4121. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4122. SETTINGS_MODE;
  4123. SETTINGS_MODEL;
  4124. SETTINGS_VERSION;
  4125. MENU_END();
  4126. }
  4127. template <uint8_t number>
  4128. static void select_sheet_menu()
  4129. {
  4130. selected_sheet = number;
  4131. lcd_sheet_menu();
  4132. }
  4133. static void sheets_menu()
  4134. {
  4135. MENU_BEGIN();
  4136. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4137. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[0], select_sheet_menu<0>);
  4138. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[1], select_sheet_menu<1>);
  4139. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[2], select_sheet_menu<2>);
  4140. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[3], select_sheet_menu<3>);
  4141. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[4], select_sheet_menu<4>);
  4142. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[5], select_sheet_menu<5>);
  4143. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[6], select_sheet_menu<6>);
  4144. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[7], select_sheet_menu<7>);
  4145. MENU_END();
  4146. }
  4147. void lcd_hw_setup_menu(void) // can not be "static"
  4148. {
  4149. typedef struct
  4150. {// 2bytes total
  4151. int8_t status;
  4152. uint8_t experimental_menu_visibility;
  4153. } _menu_data_t;
  4154. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  4155. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  4156. if (_md->status == 0 || lcd_draw_update)
  4157. {
  4158. _md->status = 1;
  4159. _md->experimental_menu_visibility = eeprom_init_default_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, 0);
  4160. }
  4161. MENU_BEGIN();
  4162. MENU_ITEM_BACK_P(_T(bSettings?MSG_SETTINGS:MSG_BACK)); // i.e. default menu-item / menu-item after checking mismatch
  4163. MENU_ITEM_SUBMENU_P(_T(MSG_STEEL_SHEETS), sheets_menu);
  4164. SETTINGS_NOZZLE;
  4165. MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu); ////MSG_CHECKS c=18
  4166. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  4167. //! Fsensor Detection isn't ready for mmu yet it is temporarily disabled.
  4168. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  4169. if(!MMU2::mmu2.Enabled()) MENU_ITEM_FUNCTION_P(PSTR("Fsensor Detection"), lcd_detect_IRsensor);
  4170. #endif //IR_SENSOR_ANALOG
  4171. if (_md->experimental_menu_visibility)
  4172. {
  4173. MENU_ITEM_SUBMENU_P(PSTR("Experimental"), lcd_experimental_menu);////MSG_MENU_EXPERIMENTAL c=18
  4174. }
  4175. #ifdef PINDA_TEMP_COMP
  4176. //! The SuperPINDA is detected when the PINDA temp is below its defined limit.
  4177. //! This works well on the EINSY board but not on the miniRAMBo board as
  4178. //! as a disconnected SuperPINDA will show higher temps compared to an EINSY board.
  4179. //!
  4180. //! This menu allows the user to en-/disable the SuperPINDA manualy
  4181. MENU_ITEM_TOGGLE_P(_N("SuperPINDA"), eeprom_read_byte((uint8_t *)EEPROM_PINDA_TEMP_COMPENSATION) ? _T(MSG_YES) : _T(MSG_NO), lcd_pinda_temp_compensation_toggle);
  4182. #endif //PINDA_TEMP_COMP
  4183. MENU_END();
  4184. }
  4185. static void lcd_settings_menu()
  4186. {
  4187. SilentModeMenu = eeprom_read_byte((uint8_t*) EEPROM_SILENT);
  4188. MENU_BEGIN();
  4189. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4190. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=18
  4191. if (!printer_active() || isPrintPaused)
  4192. {
  4193. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_axis);////MSG_MOVE_AXIS c=18
  4194. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18
  4195. }
  4196. #ifdef FILAMENT_SENSOR
  4197. MENU_ITEM_SUBMENU_P(_T(MSG_FSENSOR), lcd_fsensor_settings_menu);
  4198. #endif //FILAMENT_SENSOR
  4199. MENU_ITEM_TOGGLE_P(PSTR("MMU"), eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED) ? _T(MSG_ON) : _T(MSG_OFF), mmu_enable_switch);
  4200. if (MMU2::mmu2.Enabled())
  4201. { // Only show menus when communicating with MMU
  4202. SETTINGS_SPOOLJOIN;
  4203. SETTINGS_CUTTER;
  4204. SETTINGS_MMU_MODE;
  4205. SETTINGS_MMU_LOADING_TEST;
  4206. }
  4207. if (eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED))
  4208. { // Communication with MMU not required to reset MMU
  4209. MENU_ITEM_FUNCTION_P(PSTR("Reset MMU"), mmu_reset);
  4210. }
  4211. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  4212. SETTINGS_SILENT_MODE;
  4213. if(!farm_mode)
  4214. {
  4215. bSettings=true; // flag ('fake parameter') for 'lcd_hw_setup_menu()' function
  4216. MENU_ITEM_SUBMENU_P(_T(MSG_HW_SETUP), lcd_hw_setup_menu);
  4217. }
  4218. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bed_leveling_settings);
  4219. #if defined (TMC2130) && defined (LINEARITY_CORRECTION)
  4220. MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu);////MSG_LIN_CORRECTION c=18
  4221. #endif //LINEARITY_CORRECTION && TMC2130
  4222. if(has_temperature_compensation())
  4223. {
  4224. MENU_ITEM_TOGGLE_P(_T(MSG_PINDA_CALIBRATION), eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE) ? _T(MSG_ON) : _T(MSG_OFF), lcd_temp_calibration_set);
  4225. }
  4226. #ifdef HAS_SECOND_SERIAL_PORT
  4227. MENU_ITEM_TOGGLE_P(_T(MSG_RPI_PORT), (selectedSerialPort == 0) ? _T(MSG_OFF) : _T(MSG_ON), lcd_second_serial_set);
  4228. #endif //HAS_SECOND_SERIAL
  4229. if (!isPrintPaused && !homing_flag && !mesh_bed_leveling_flag)
  4230. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  4231. #if (LANG_MODE != 0)
  4232. MENU_ITEM_SUBMENU_P(_T(MSG_SELECT_LANGUAGE), lcd_language_menu);
  4233. #endif //(LANG_MODE != 0)
  4234. if (!farm_mode) { //SD related settings are not available in farm mode
  4235. if (card.ToshibaFlashAir_isEnabled())
  4236. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY, lcd_toshiba_flash_air_compatibility_toggle);
  4237. else
  4238. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_NORMAL), lcd_toshiba_flash_air_compatibility_toggle);
  4239. #ifdef SDCARD_SORT_ALPHA
  4240. switch (eeprom_read_byte((uint8_t*) EEPROM_SD_SORT)) {
  4241. case SD_SORT_TIME: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_TIME), lcd_sort_type_set); break;
  4242. case SD_SORT_ALPHA: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_ALPHA), lcd_sort_type_set); break;
  4243. default: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_NONE), lcd_sort_type_set);
  4244. }
  4245. }
  4246. #endif //SDCARD_SORT_ALPHA
  4247. SETTINGS_SOUND;
  4248. #ifdef LCD_BL_PIN
  4249. if (backlightSupport)
  4250. {
  4251. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  4252. }
  4253. #endif //LCD_BL_PIN
  4254. if (farm_mode)
  4255. {
  4256. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  4257. }
  4258. MENU_END();
  4259. }
  4260. #ifdef TMC2130
  4261. static void lcd_ustep_linearity_menu_save()
  4262. {
  4263. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  4264. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  4265. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  4266. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  4267. }
  4268. #endif //TMC2130
  4269. #ifdef TMC2130
  4270. static void lcd_settings_linearity_correction_menu_save()
  4271. {
  4272. bool changed = false;
  4273. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  4274. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  4275. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  4276. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  4277. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  4278. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  4279. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  4280. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  4281. lcd_ustep_linearity_menu_save();
  4282. if (changed) tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  4283. }
  4284. #endif //TMC2130
  4285. static void lcd_calibration_menu()
  4286. {
  4287. MENU_BEGIN();
  4288. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4289. if (!isPrintPaused)
  4290. {
  4291. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17
  4292. if (lcd_commands_type == LcdCommands::Idle)
  4293. {
  4294. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_first_layer_calibration_reset);
  4295. }
  4296. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  4297. #ifdef TMC2130
  4298. MENU_ITEM_FUNCTION_P(_i("Belt test"), lcd_belttest_v);////MSG_BELTTEST c=18
  4299. #endif //TMC2130
  4300. MENU_ITEM_FUNCTION_P(_i("Selftest"), lcd_selftest_v);////MSG_SELFTEST c=18
  4301. // MK2
  4302. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=18
  4303. // "Calibrate Z" with storing the reference values to EEPROM.
  4304. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  4305. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bedleveling); ////MSG_MESH_BED_LEVELING c=18
  4306. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=18
  4307. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17
  4308. #ifndef TMC2130
  4309. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=18
  4310. #endif
  4311. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=18
  4312. if(has_temperature_compensation())
  4313. {
  4314. MENU_ITEM_FUNCTION_P(_T(MSG_PINDA_CALIBRATION), lcd_calibrate_pinda);
  4315. }
  4316. }
  4317. #ifdef TEMP_MODEL
  4318. MENU_ITEM_SUBMENU_P(_n("Temp Model cal."), lcd_temp_model_cal);
  4319. #endif //TEMP_MODEL
  4320. MENU_END();
  4321. }
  4322. //! @brief Select one of numbered items
  4323. //!
  4324. //! Create list of items with header. Header can not be selected.
  4325. //! Each item has text description passed by function parameter and
  4326. //! number. There are 5 numbered items, if MMU2::mmu2.Enabled(), 4 otherwise.
  4327. //! Items are numbered from 1 to 4 or 5. But index returned starts at 0.
  4328. //! There can be last item with different text and no number.
  4329. //!
  4330. //! @param header Header text
  4331. //! @param item Item text
  4332. //! @param last_item Last item text, or nullptr if there is no Last item
  4333. //! @return selected item index, first item index is 0
  4334. uint8_t choose_menu_P(const char *header, const char *item, const char *last_item)
  4335. {
  4336. //following code should handle 3 to 127 number of items well
  4337. const int8_t items_no = last_item?(MMU2::mmu2.Enabled()?6:5):(MMU2::mmu2.Enabled()?5:4);
  4338. const uint8_t item_len = item?strlen_P(item):0;
  4339. int8_t first = 0;
  4340. int8_t enc_dif = lcd_encoder_diff;
  4341. int8_t cursor_pos = 1;
  4342. lcd_clear();
  4343. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4344. while (1)
  4345. {
  4346. manage_heater();
  4347. manage_inactivity(true);
  4348. if (abs((enc_dif - lcd_encoder_diff)) > 4)
  4349. {
  4350. if (enc_dif > lcd_encoder_diff)
  4351. {
  4352. cursor_pos--;
  4353. }
  4354. if (enc_dif < lcd_encoder_diff)
  4355. {
  4356. cursor_pos++;
  4357. }
  4358. enc_dif = lcd_encoder_diff;
  4359. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  4360. }
  4361. if (cursor_pos > 3)
  4362. {
  4363. cursor_pos = 3;
  4364. if (first < items_no - 3)
  4365. {
  4366. first++;
  4367. lcd_clear();
  4368. } else { // here we are at the very end of the list
  4369. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4370. }
  4371. }
  4372. if (cursor_pos < 1)
  4373. {
  4374. cursor_pos = 1;
  4375. if (first > 0)
  4376. {
  4377. first--;
  4378. lcd_clear();
  4379. } else { // here we are at the very end of the list
  4380. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4381. }
  4382. }
  4383. if (header) lcd_puts_at_P(0,0,header);
  4384. const bool last_visible = (first == items_no - 3);
  4385. const uint_least8_t ordinary_items = (last_item&&last_visible)?2:3;
  4386. for (uint_least8_t i = 0; i < ordinary_items; i++)
  4387. {
  4388. if (item) lcd_puts_at_P(1, i + 1, item);
  4389. }
  4390. for (uint_least8_t i = 0; i < ordinary_items; i++)
  4391. {
  4392. lcd_set_cursor(2 + item_len, i+1);
  4393. lcd_print(first + i + 1);
  4394. }
  4395. if (last_item&&last_visible) lcd_puts_at_P(1, 3, last_item);
  4396. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  4397. lcd_putc_at(0, cursor_pos, '>');
  4398. _delay(100);
  4399. if (lcd_clicked())
  4400. {
  4401. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  4402. KEEPALIVE_STATE(IN_HANDLER);
  4403. lcd_encoder_diff = 0;
  4404. return(cursor_pos + first - 1);
  4405. }
  4406. }
  4407. }
  4408. char reset_menu() {
  4409. static int8_t first = 0;
  4410. int8_t enc_dif = 0;
  4411. char cursor_pos = 0;
  4412. const char *const item[] = {
  4413. PSTR("Language"),
  4414. PSTR("Statistics"),
  4415. PSTR("Shipping prep"),
  4416. PSTR("Service prep"),
  4417. PSTR("All Data"),
  4418. };
  4419. enc_dif = lcd_encoder_diff;
  4420. lcd_clear();
  4421. lcd_set_cursor(0, 0);
  4422. lcd_putc('>');
  4423. lcd_consume_click();
  4424. while (1) {
  4425. for (uint_least8_t i = 0; i < 4; i++) {
  4426. lcd_puts_at_P(1, i, item[first + i]);
  4427. }
  4428. manage_heater();
  4429. manage_inactivity(true);
  4430. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4431. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4432. if (enc_dif > lcd_encoder_diff) {
  4433. cursor_pos--;
  4434. }
  4435. if (enc_dif < lcd_encoder_diff) {
  4436. cursor_pos++;
  4437. }
  4438. if (cursor_pos > 3) {
  4439. cursor_pos = 3;
  4440. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4441. if (first < (uint8_t)(sizeof(item) / sizeof(item[0])) - 4) {
  4442. first++;
  4443. lcd_clear();
  4444. }
  4445. }
  4446. if (cursor_pos < 0) {
  4447. cursor_pos = 0;
  4448. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4449. if (first > 0) {
  4450. first--;
  4451. lcd_clear();
  4452. }
  4453. }
  4454. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  4455. lcd_set_cursor(0, cursor_pos);
  4456. lcd_putc('>');
  4457. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  4458. enc_dif = lcd_encoder_diff;
  4459. _delay(100);
  4460. }
  4461. }
  4462. if (lcd_clicked()) {
  4463. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  4464. return(cursor_pos + first);
  4465. }
  4466. }
  4467. }
  4468. static void lcd_disable_farm_mode()
  4469. {
  4470. uint8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true); //allow timeouting, default no
  4471. if (disable == LCD_LEFT_BUTTON_CHOICE)
  4472. {
  4473. enquecommand_P(PSTR("G99"));
  4474. lcd_return_to_status();
  4475. }
  4476. lcd_update_enable(true);
  4477. lcd_draw_update = 2;
  4478. }
  4479. static inline void load_all_wrapper(){
  4480. for(uint8_t i = 0; i < 5; ++i){
  4481. MMU2::mmu2.load_filament(i);
  4482. }
  4483. }
  4484. static inline void load_filament_wrapper(uint8_t i){
  4485. MMU2::mmu2.load_filament(i);
  4486. }
  4487. static void mmu_load_filament_menu() {
  4488. MENU_BEGIN();
  4489. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4490. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_ALL), load_all_wrapper);
  4491. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4492. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), i + '1', load_filament_wrapper, i); ////MSG_LOAD_FILAMENT c=16
  4493. MENU_END();
  4494. }
  4495. static inline void lcd_mmu_load_to_nozzle_wrapper(uint8_t index){
  4496. MMU2::mmu2.load_filament_to_nozzle(index);
  4497. // Ask user if the extruded color is correct:
  4498. lcd_return_to_status();
  4499. lcd_load_filament_color_check();
  4500. lcd_setstatuspgm(MSG_WELCOME);
  4501. custom_message_type = CustomMsg::Status;
  4502. }
  4503. static void mmu_load_to_nozzle_menu() {
  4504. if (bFilamentAction) {
  4505. MENU_BEGIN();
  4506. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4507. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4508. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), i + '1', lcd_mmu_load_to_nozzle_wrapper, i); ////MSG_LOAD_FILAMENT c=16
  4509. MENU_END();
  4510. } else {
  4511. eFilamentAction = FilamentAction::MmuLoad;
  4512. preheat_or_continue();
  4513. }
  4514. }
  4515. static void mmu_eject_filament(uint8_t filament) {
  4516. menu_back();
  4517. MMU2::mmu2.eject_filament(filament, true);
  4518. }
  4519. static void mmu_fil_eject_menu() {
  4520. if (bFilamentAction) {
  4521. MENU_BEGIN();
  4522. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4523. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4524. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), i + '1', mmu_eject_filament, i); ////MSG_EJECT_FILAMENT c=16
  4525. MENU_END();
  4526. } else {
  4527. eFilamentAction = FilamentAction::MmuEject;
  4528. preheat_or_continue();
  4529. }
  4530. }
  4531. #ifdef MMU_HAS_CUTTER
  4532. static inline void mmu_cut_filament_wrapper(uint8_t index){
  4533. MMU2::mmu2.cut_filament(index);
  4534. }
  4535. static void mmu_cut_filament_menu() {
  4536. if (bFilamentAction) {
  4537. MENU_BEGIN();
  4538. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4539. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4540. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), i + '1', mmu_cut_filament_wrapper, i); ////MSG_CUT_FILAMENT c=16
  4541. MENU_END();
  4542. } else {
  4543. eFilamentAction=FilamentAction::MmuCut;
  4544. preheat_or_continue();
  4545. }
  4546. }
  4547. #endif //MMU_HAS_CUTTER
  4548. static inline void loading_test_all_wrapper(){
  4549. for(uint8_t i = 0; i < 5; ++i){
  4550. MMU2::mmu2.loading_test(i);
  4551. }
  4552. }
  4553. static inline void loading_test_wrapper(uint8_t i){
  4554. MMU2::mmu2.loading_test(i);
  4555. }
  4556. static void mmu_loading_test_menu() {
  4557. if (bFilamentAction) {
  4558. MENU_BEGIN();
  4559. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4560. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_ALL), loading_test_all_wrapper);
  4561. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4562. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), i + '1', loading_test_wrapper, i); ////MSG_LOAD_FILAMENT c=16
  4563. MENU_END();
  4564. } else {
  4565. eFilamentAction = FilamentAction::MmuLoadingTest;
  4566. preheat_or_continue();
  4567. }
  4568. }
  4569. // unload filament for single material printer (used in M702 gcode)
  4570. // @param automatic: If true, unload_filament is part of a unload+load sequence (M600)
  4571. void unload_filament(float unloadLength, bool automatic)
  4572. {
  4573. custom_message_type = CustomMsg::FilamentLoading;
  4574. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  4575. FSensorBlockRunout fsBlockRunout;
  4576. if (automatic)
  4577. {
  4578. // M600
  4579. raise_z_above(MIN_Z_FOR_SWAP);
  4580. }
  4581. // Retract filament
  4582. current_position[E_AXIS] += -FILAMENT_UNLOAD_PURGE_RETRACT;
  4583. plan_buffer_line_curposXYZE(PAUSE_PARK_RETRACT_FEEDRATE);
  4584. st_synchronize();
  4585. // Wait for filament to cool
  4586. delay_keep_alive(FILAMENT_UNLOAD_PURGE_DELAY);
  4587. // Quickly purge
  4588. current_position[E_AXIS] += (FILAMENT_UNLOAD_PURGE_RETRACT + FILAMENT_UNLOAD_PURGE_LENGTH);
  4589. plan_buffer_line_curposXYZE(FILAMENT_UNLOAD_PURGE_FEEDRATE);
  4590. st_synchronize();
  4591. // Configurable length
  4592. current_position[E_AXIS] += unloadLength;
  4593. plan_buffer_line_curposXYZE(FILAMENT_CHANGE_UNLOAD_FEEDRATE);
  4594. st_synchronize();
  4595. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  4596. //disable extruder steppers so filament can be removed
  4597. disable_e0();
  4598. disable_e1();
  4599. disable_e2();
  4600. _delay(100);
  4601. Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  4602. uint8_t counterBeep = 0;
  4603. while (!lcd_clicked() && (counterBeep < 50)) {
  4604. delay_keep_alive(100);
  4605. counterBeep++;
  4606. }
  4607. st_synchronize();
  4608. while (lcd_clicked()) delay_keep_alive(100);
  4609. lcd_update_enable(true);
  4610. lcd_setstatuspgm(MSG_WELCOME);
  4611. custom_message_type = CustomMsg::Status;
  4612. eFilamentAction = FilamentAction::None;
  4613. }
  4614. #include "xflash.h"
  4615. #ifdef LCD_TEST
  4616. static void lcd_test_menu()
  4617. {
  4618. XFLASH_SPI_ENTER();
  4619. xflash_enable_wr();
  4620. xflash_chip_erase();
  4621. xflash_disable_wr();
  4622. }
  4623. #endif //LCD_TEST
  4624. static bool fan_error_selftest()
  4625. {
  4626. #ifdef FANCHECK
  4627. if (!fans_check_enabled) return 0;
  4628. fanSpeed = 255;
  4629. #ifdef FAN_SOFT_PWM
  4630. fanSpeedSoftPwm = 255;
  4631. #endif //FAN_SOFT_PWM
  4632. manage_heater(); //enables print fan
  4633. setExtruderAutoFanState(3); //force enables the hotend fan
  4634. #ifdef FAN_SOFT_PWM
  4635. extruder_autofan_last_check = _millis();
  4636. fan_measuring = true;
  4637. #endif //FAN_SOFT_PWM
  4638. _delay(1000); //delay_keep_alive would turn off hotend fan, because temerature is too low (maybe)
  4639. manage_heater();
  4640. fanSpeed = 0;
  4641. setExtruderAutoFanState(1); //releases lock on the hotend fan
  4642. #ifdef FAN_SOFT_PWM
  4643. fanSpeedSoftPwm = 0;
  4644. #endif //FAN_SOFT_PWM
  4645. manage_heater();
  4646. #ifdef TACH_0
  4647. if (fan_speed[0] <= 20) { //hotend fan error
  4648. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_HOTEND);
  4649. return 1;
  4650. }
  4651. #endif
  4652. #ifdef TACH_1
  4653. if (fan_speed[1] <= 20) { //print fan error
  4654. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_PRINT);
  4655. return 1;
  4656. }
  4657. #endif
  4658. #endif //FANCHECK
  4659. return 0;
  4660. }
  4661. bool resume_print_checks() {
  4662. // reset the lcd status so that a newer error will be shown
  4663. lcd_return_to_status();
  4664. lcd_reset_alert_level();
  4665. // ensure thermal issues (temp or fan) are resolved before we allow to resume
  4666. if (get_temp_error()
  4667. #ifdef FANCHECK
  4668. || fan_error_selftest()
  4669. #endif
  4670. ) {
  4671. return false; // abort if error persists
  4672. }
  4673. return true;
  4674. }
  4675. //! @brief Resume paused print, send host action "resumed"
  4676. //! @todo It is not good to call restore_print_from_ram_and_continue() from function called by lcd_update(),
  4677. //! as restore_print_from_ram_and_continue() calls lcd_update() internally.
  4678. void lcd_resume_print()
  4679. {
  4680. // reset lcd and ensure we can resume first
  4681. if (!resume_print_checks()) return;
  4682. cmdqueue_serial_disabled = false;
  4683. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  4684. st_synchronize();
  4685. custom_message_type = CustomMsg::Resuming;
  4686. isPrintPaused = false;
  4687. Stopped = false; // resume processing USB commands again
  4688. restore_print_from_ram_and_continue(default_retraction);
  4689. pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  4690. refresh_cmd_timeout();
  4691. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUMED); //resume octoprint
  4692. custom_message_type = CustomMsg::Status;
  4693. }
  4694. //! @brief Resume paused USB/host print, send host action "resume"
  4695. void lcd_resume_usb_print()
  4696. {
  4697. // reset lcd and ensure we can resume first
  4698. if (!resume_print_checks()) return;
  4699. // resume the usb host
  4700. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_ASK_RESUME);
  4701. }
  4702. static void change_sheet()
  4703. {
  4704. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  4705. menu_back(3);
  4706. }
  4707. static void lcd_rename_sheet_menu()
  4708. {
  4709. struct MenuData
  4710. {
  4711. bool initialized;
  4712. uint8_t selected;
  4713. char name[sizeof(Sheet::name)];
  4714. };
  4715. static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data");
  4716. MenuData* menuData = (MenuData*)&(menu_data[0]);
  4717. if (!menuData->initialized)
  4718. {
  4719. eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name));
  4720. lcd_encoder = menuData->name[0];
  4721. menuData->initialized = true;
  4722. }
  4723. if (lcd_encoder < '\x20') lcd_encoder = '\x20';
  4724. if (lcd_encoder > '\x7F') lcd_encoder = '\x7F';
  4725. menuData->name[menuData->selected] = lcd_encoder;
  4726. lcd_set_cursor(0,0);
  4727. for (uint_least8_t i = 0; i < sizeof(Sheet::name); ++i)
  4728. {
  4729. lcd_putc(menuData->name[i]);
  4730. }
  4731. lcd_set_cursor(menuData->selected, 1);
  4732. lcd_putc('^');
  4733. if (lcd_clicked())
  4734. {
  4735. if ((menuData->selected + 1u) < sizeof(Sheet::name))
  4736. {
  4737. lcd_encoder = menuData->name[++(menuData->selected)];
  4738. }
  4739. else
  4740. {
  4741. eeprom_update_block(menuData->name,
  4742. EEPROM_Sheets_base->s[selected_sheet].name,
  4743. sizeof(Sheet::name));
  4744. menu_back();
  4745. }
  4746. }
  4747. }
  4748. static void lcd_reset_sheet()
  4749. {
  4750. SheetName sheetName;
  4751. eeprom_default_sheet_name(selected_sheet, sheetName);
  4752. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),EEPROM_EMPTY_VALUE16);
  4753. eeprom_update_block(sheetName.c,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name));
  4754. if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))
  4755. {
  4756. eeprom_switch_to_next_sheet();
  4757. if((-1 == eeprom_next_initialized_sheet(0)) && (CALIBRATION_STATUS_CALIBRATED == calibration_status()))
  4758. {
  4759. calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
  4760. }
  4761. }
  4762. menu_back();
  4763. }
  4764. //! @brief Activate selected_sheet and run first layer calibration
  4765. static void activate_calibrate_sheet()
  4766. {
  4767. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  4768. lcd_first_layer_calibration_reset();
  4769. }
  4770. static void lcd_sheet_menu()
  4771. {
  4772. MENU_BEGIN();
  4773. MENU_ITEM_BACK_P(_T(MSG_STEEL_SHEETS));
  4774. if(eeprom_is_sheet_initialized(selected_sheet)){
  4775. MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); ////MSG_SELECT c=18
  4776. }
  4777. if (lcd_commands_type == LcdCommands::Idle)
  4778. {
  4779. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), activate_calibrate_sheet);
  4780. }
  4781. MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); ////MSG_RENAME c=18
  4782. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_reset_sheet);
  4783. MENU_END();
  4784. }
  4785. //! @brief Show Main Menu
  4786. //!
  4787. //! @code{.unparsed}
  4788. //! |01234567890123456789|
  4789. //! | Info screen | allways
  4790. //!
  4791. //! | tst - Save | ifdef RESUME_DEBUG
  4792. //! | tst - Restore | ifdef RESUME_DEBUG
  4793. //!
  4794. //! | recover print | ifdef TMC2130_DEBUG
  4795. //! | power panic | ifdef TMC2130_DEBUG
  4796. //!
  4797. //! | Live adjust Z | printing + Z low
  4798. //!
  4799. //! | Change filament | farm mode
  4800. //!
  4801. //! | Tune | printing + paused
  4802. //! | Pause print | printing + not paused
  4803. //! | Resume print | printing + paused
  4804. //! | Stop print | printing or paused + NOT MBL
  4805. //! | Preheat | not printing + not paused
  4806. //! | Print from SD | not printing or paused
  4807. //!
  4808. //! | Switch sheet | farm mode
  4809. //!
  4810. //! | AutoLoad filament | not printing + not mmu or paused
  4811. //! | Load filament | not printing + mmu or paused
  4812. //! | Load to nozzle | not printing + mmu or paused
  4813. //! | Unload filament | not printing or paused
  4814. //! | Eject filament | not printing + mmu or paused
  4815. //! | Cut filament | not printing + mmu or paused + cut atctive
  4816. //! | Settings | not printing or paused
  4817. //! | Calibration | not printing
  4818. //! | Statistics | not printing
  4819. //! | Fail stats | allways
  4820. //! | Fail stats MMU | mmu
  4821. //! | Support | allways
  4822. //! @endcode
  4823. static void lcd_main_menu()
  4824. {
  4825. MENU_BEGIN();
  4826. // Majkl superawesome menu
  4827. MENU_ITEM_BACK_P(_T(MSG_INFO_SCREEN));
  4828. #ifdef RESUME_DEBUG
  4829. if (!saved_printing)
  4830. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  4831. else
  4832. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  4833. #endif //RESUME_DEBUG
  4834. #ifdef TMC2130_DEBUG
  4835. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  4836. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  4837. #endif //TMC2130_DEBUG
  4838. if ( ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) {
  4839. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4840. }
  4841. if (farm_mode)
  4842. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  4843. if ( moves_planned() || printer_active() ) {
  4844. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=18
  4845. } else {
  4846. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=18
  4847. }
  4848. if (mesh_bed_leveling_flag == false && homing_flag == false && !isPrintPaused) {
  4849. if (usb_timer.running()) {
  4850. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_usb_print);
  4851. } else if (IS_SD_PRINTING) {
  4852. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_print);
  4853. }
  4854. }
  4855. if(isPrintPaused)
  4856. {
  4857. // only allow resuming if hardware errors (temperature or fan) are cleared
  4858. if(!get_temp_error()
  4859. #ifdef FANCHECK
  4860. && ((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK))
  4861. #endif //FANCHECK
  4862. ) {
  4863. if (saved_printing) {
  4864. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);
  4865. } else {
  4866. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_usb_print);
  4867. }
  4868. }
  4869. }
  4870. if((IS_SD_PRINTING || usb_timer.running() || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling)) {
  4871. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4872. }
  4873. #ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code
  4874. if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) {
  4875. if (!card.isFileOpen()) {
  4876. if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  4877. bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
  4878. MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  4879. }
  4880. #if SDCARDDETECT < 1
  4881. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user ////MSG_CNG_SDCARD c=18
  4882. #endif //SDCARDDETECT
  4883. }
  4884. } else {
  4885. bMain=true; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  4886. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu); ////MSG_NO_CARD c=18
  4887. #if SDCARDDETECT < 1
  4888. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface ////MSG_INIT_SDCARD c=18
  4889. #endif //SDCARDDETECT
  4890. }
  4891. #endif //SDSUPPORT
  4892. if(!isPrintPaused && !IS_SD_PRINTING && !usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  4893. if (!farm_mode) {
  4894. const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  4895. const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
  4896. if ((nextSheet >= 0) && (sheet != nextSheet)) { // show menu only if we have 2 or more sheets initialized
  4897. MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet);
  4898. }
  4899. }
  4900. }
  4901. if ( ! ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal) ) ) {
  4902. if (MMU2::mmu2.Enabled()) {
  4903. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), mmu_load_filament_menu);
  4904. MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);////MSG_LOAD_TO_NOZZLE c=18
  4905. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), mmu_unload_filament);
  4906. MENU_ITEM_SUBMENU_P(_T(MSG_EJECT_FILAMENT), mmu_fil_eject_menu);
  4907. #ifdef MMU_HAS_CUTTER
  4908. if (eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED) != 0) {
  4909. MENU_ITEM_SUBMENU_P(_T(MSG_CUT_FILAMENT), mmu_cut_filament_menu);
  4910. }
  4911. #endif //MMU_HAS_CUTTER
  4912. } else {
  4913. #ifdef FILAMENT_SENSOR
  4914. if (fsensor.getAutoLoadEnabled()) {
  4915. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=18
  4916. }
  4917. else
  4918. #endif //FILAMENT_SENSOR
  4919. {
  4920. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  4921. }
  4922. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  4923. }
  4924. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  4925. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_CALIBRATION), lcd_calibration_menu);
  4926. }
  4927. if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  4928. MENU_ITEM_SUBMENU_P(_i("Statistics"), lcd_menu_statistics);////MSG_STATISTICS c=18
  4929. }
  4930. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  4931. MENU_ITEM_SUBMENU_P(_i("Fail stats"), lcd_menu_fails_stats);////MSG_FAIL_STATS c=18
  4932. #endif
  4933. if (MMU2::mmu2.Enabled()) {
  4934. MENU_ITEM_SUBMENU_P(_i("Fail stats MMU"), lcd_menu_fails_stats_mmu);////MSG_MMU_FAIL_STATS c=18
  4935. }
  4936. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=18
  4937. #ifdef LCD_TEST
  4938. MENU_ITEM_SUBMENU_P(_i("XFLASH init"), lcd_test_menu);////MSG_XFLASH c=18
  4939. #endif //LCD_TEST
  4940. MENU_END();
  4941. }
  4942. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4943. bool stepper_timer_overflow_state = false;
  4944. uint16_t stepper_timer_overflow_max = 0;
  4945. uint16_t stepper_timer_overflow_last = 0;
  4946. uint16_t stepper_timer_overflow_cnt = 0;
  4947. void stepper_timer_overflow() {
  4948. char msg[28];
  4949. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  4950. lcd_setstatus(msg);
  4951. stepper_timer_overflow_state = false;
  4952. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  4953. stepper_timer_overflow_max = stepper_timer_overflow_last;
  4954. SERIAL_ECHOPGM("Stepper timer overflow: ");
  4955. MYSERIAL.print(msg);
  4956. SERIAL_ECHOLNPGM("");
  4957. WRITE(BEEPER, LOW);
  4958. }
  4959. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  4960. static void lcd_colorprint_change() {
  4961. enquecommand_P(PSTR("M600"));
  4962. custom_message_type = CustomMsg::FilamentLoading; //just print status message
  4963. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  4964. lcd_return_to_status();
  4965. lcd_draw_update = 3;
  4966. }
  4967. #ifdef LA_LIVE_K
  4968. // @wavexx: looks like there's no generic float editing function in menu.cpp so we
  4969. // redefine our custom handling functions to mimick other tunables
  4970. const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6S";
  4971. static void lcd_advance_draw_K(char chr, float val)
  4972. {
  4973. if (val <= 0)
  4974. lcd_printf_P(menu_fmt_float13off, chr, MSG_ADVANCE_K, _T(MSG_OFF));
  4975. else
  4976. lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val);
  4977. }
  4978. static void lcd_advance_edit_K(void)
  4979. {
  4980. if (lcd_draw_update)
  4981. {
  4982. if (lcd_encoder < 0) lcd_encoder = 0;
  4983. if (lcd_encoder > 999) lcd_encoder = 999;
  4984. lcd_set_cursor(0, 1);
  4985. lcd_advance_draw_K(' ', 0.01 * lcd_encoder);
  4986. }
  4987. if (LCD_CLICKED)
  4988. {
  4989. extruder_advance_K = 0.01 * lcd_encoder;
  4990. menu_back_no_reset();
  4991. }
  4992. }
  4993. static uint8_t lcd_advance_K()
  4994. {
  4995. if (menu_item == menu_line)
  4996. {
  4997. if (lcd_draw_update)
  4998. {
  4999. lcd_set_cursor(0, menu_row);
  5000. lcd_advance_draw_K((lcd_encoder == menu_item)?'>':' ', extruder_advance_K);
  5001. }
  5002. if (menu_clicked && (lcd_encoder == menu_item))
  5003. {
  5004. menu_submenu_no_reset(lcd_advance_edit_K);
  5005. lcd_encoder = 100. * extruder_advance_K;
  5006. return menu_item_ret();
  5007. }
  5008. }
  5009. menu_item++;
  5010. return 0;
  5011. }
  5012. #define MENU_ITEM_EDIT_advance_K() do { if (lcd_advance_K()) return; } while (0)
  5013. #endif
  5014. static void lcd_tune_menu()
  5015. {
  5016. typedef struct
  5017. {
  5018. menu_data_edit_t reserved; //!< reserved for number editing functions
  5019. int8_t status; //!< To recognize, whether the menu has been just initialized.
  5020. //! Backup of extrudemultiply, to recognize, that the value has been changed and
  5021. //! it needs to be applied.
  5022. int16_t extrudemultiply;
  5023. } _menu_data_t;
  5024. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  5025. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  5026. if (_md->status == 0)
  5027. {
  5028. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  5029. _md->status = 1;
  5030. _md->extrudemultiply = extrudemultiply;
  5031. }
  5032. else if (_md->extrudemultiply != extrudemultiply)
  5033. {
  5034. // extrudemultiply has been changed from the child menu. Apply the new value.
  5035. _md->extrudemultiply = extrudemultiply;
  5036. calculate_extruder_multipliers();
  5037. }
  5038. SilentModeMenu = eeprom_read_byte((uint8_t*) EEPROM_SILENT);
  5039. MENU_BEGIN();
  5040. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  5041. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=15
  5042. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  5043. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);
  5044. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  5045. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=15
  5046. #ifdef LA_LIVE_K
  5047. MENU_ITEM_EDIT_advance_K();//7
  5048. #endif
  5049. #ifdef FILAMENTCHANGEENABLE
  5050. if (!farm_mode)
  5051. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  5052. #endif
  5053. #ifdef FILAMENT_SENSOR
  5054. MENU_ITEM_SUBMENU_P(_T(MSG_FSENSOR), lcd_fsensor_settings_menu);
  5055. #endif //FILAMENT_SENSOR
  5056. if (MMU2::mmu2.Enabled())
  5057. {
  5058. SETTINGS_SPOOLJOIN;
  5059. SETTINGS_CUTTER;
  5060. }
  5061. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  5062. #ifdef TMC2130
  5063. if(!farm_mode)
  5064. {
  5065. if (SilentModeMenu == SILENT_MODE_NORMAL) {
  5066. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);
  5067. if (lcd_crash_detect_enabled()) {
  5068. MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);
  5069. } else {
  5070. MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);
  5071. }
  5072. } else {
  5073. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);
  5074. MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);
  5075. }
  5076. }
  5077. #else //TMC2130
  5078. if (!farm_mode) { //dont show in menu if we are in farm mode
  5079. switch (SilentModeMenu) {
  5080. case SILENT_MODE_POWER: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break;
  5081. case SILENT_MODE_SILENT: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set); break;
  5082. case SILENT_MODE_AUTO: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set); break;
  5083. default: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break; // (probably) not needed
  5084. }
  5085. }
  5086. #endif //TMC2130
  5087. SETTINGS_MMU_MODE;
  5088. SETTINGS_SOUND;
  5089. #ifdef LCD_BL_PIN
  5090. if (backlightSupport)
  5091. {
  5092. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  5093. }
  5094. #endif //LCD_BL_PIN
  5095. MENU_END();
  5096. }
  5097. static void mbl_magnets_elimination_toggle() {
  5098. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  5099. magnet_elimination = !magnet_elimination;
  5100. eeprom_update_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, (uint8_t)magnet_elimination);
  5101. }
  5102. static void mbl_mesh_toggle() {
  5103. uint8_t mesh_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  5104. if(mesh_nr == 3) mesh_nr = 7;
  5105. else mesh_nr = 3;
  5106. eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mesh_nr);
  5107. }
  5108. static void mbl_probe_nr_toggle() {
  5109. mbl_z_probe_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR);
  5110. switch (mbl_z_probe_nr) {
  5111. case 1: mbl_z_probe_nr = 3; break;
  5112. case 3: mbl_z_probe_nr = 5; break;
  5113. case 5: mbl_z_probe_nr = 1; break;
  5114. default: mbl_z_probe_nr = 3; break;
  5115. }
  5116. eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, mbl_z_probe_nr);
  5117. }
  5118. static void lcd_mesh_bed_leveling_settings()
  5119. {
  5120. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  5121. uint8_t points_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  5122. char sToggle[4]; //enough for nxn format
  5123. MENU_BEGIN();
  5124. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5125. sToggle[0] = points_nr + '0';
  5126. sToggle[1] = 'x';
  5127. sToggle[2] = points_nr + '0';
  5128. sToggle[3] = 0;
  5129. MENU_ITEM_TOGGLE(_T(MSG_MESH), sToggle, mbl_mesh_toggle);
  5130. sToggle[0] = mbl_z_probe_nr + '0';
  5131. sToggle[1] = 0;
  5132. MENU_ITEM_TOGGLE(_T(MSG_Z_PROBE_NR), sToggle, mbl_probe_nr_toggle);
  5133. MENU_ITEM_TOGGLE_P(_T(MSG_MAGNETS_COMP), (points_nr == 7) ? (magnet_elimination ? _T(MSG_ON): _T(MSG_OFF)) : _T(MSG_NA), mbl_magnets_elimination_toggle);
  5134. MENU_END();
  5135. //SETTINGS_MBL_MODE;
  5136. }
  5137. #ifdef LCD_BL_PIN
  5138. static void backlight_mode_toggle()
  5139. {
  5140. switch (backlightMode)
  5141. {
  5142. case BACKLIGHT_MODE_BRIGHT: backlightMode = BACKLIGHT_MODE_DIM; break;
  5143. case BACKLIGHT_MODE_DIM: backlightMode = BACKLIGHT_MODE_AUTO; break;
  5144. case BACKLIGHT_MODE_AUTO: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  5145. default: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  5146. }
  5147. backlight_save();
  5148. }
  5149. static void lcd_backlight_menu()
  5150. {
  5151. MENU_BEGIN();
  5152. ON_MENU_LEAVE(
  5153. backlight_save();
  5154. );
  5155. MENU_ITEM_BACK_P(_T(MSG_BACK));
  5156. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_HIGH), &backlightLevel_HIGH, backlightLevel_LOW, 255);
  5157. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_LOW), &backlightLevel_LOW, 0, backlightLevel_HIGH);
  5158. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), ((backlightMode==BACKLIGHT_MODE_BRIGHT) ? _T(MSG_BRIGHT) : ((backlightMode==BACKLIGHT_MODE_DIM) ? _T(MSG_DIM) : _T(MSG_AUTO))), backlight_mode_toggle);
  5159. MENU_ITEM_EDIT_int3_P(_T(MSG_TIMEOUT), &backlightTimer_period, 1, 999);
  5160. MENU_END();
  5161. }
  5162. #endif //LCD_BL_PIN
  5163. static void lcd_control_temperature_menu()
  5164. {
  5165. #ifdef PIDTEMP
  5166. // set up temp variables - undo the default scaling
  5167. // raw_Ki = unscalePID_i(Ki);
  5168. // raw_Kd = unscalePID_d(Kd);
  5169. #endif
  5170. MENU_BEGIN();
  5171. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5172. #if TEMP_SENSOR_0 != 0
  5173. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  5174. #endif
  5175. #if TEMP_SENSOR_1 != 0
  5176. MENU_ITEM_EDIT_int3_P(_n("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  5177. #endif
  5178. #if TEMP_SENSOR_2 != 0
  5179. MENU_ITEM_EDIT_int3_P(_n("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  5180. #endif
  5181. #if TEMP_SENSOR_BED != 0
  5182. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  5183. #endif
  5184. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  5185. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  5186. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  5187. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  5188. MENU_ITEM_EDIT(float3, _n(" \xdf Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  5189. MENU_ITEM_EDIT(float3, _n(" \xdf Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  5190. MENU_ITEM_EDIT(float32, _n(" \xdf Fact"), &autotemp_factor, 0.0, 1.0);
  5191. #endif
  5192. MENU_END();
  5193. }
  5194. static void lcd_sd_refresh()
  5195. {
  5196. #if SDCARDDETECT == -1
  5197. card.initsd();
  5198. #else
  5199. card.presort();
  5200. #endif
  5201. menu_top = 0;
  5202. lcd_encoder = 0;
  5203. menu_data_reset(); //Forces reloading of cached variables.
  5204. }
  5205. static void lcd_sd_updir()
  5206. {
  5207. card.updir();
  5208. menu_top = 0;
  5209. lcd_encoder = 0;
  5210. menu_data_reset(); //Forces reloading of cached variables.
  5211. }
  5212. // continue stopping the print from the main loop after lcd_print_stop() is called
  5213. void print_stop()
  5214. {
  5215. // save printing time
  5216. stoptime = _millis();
  5217. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5218. save_statistics(total_filament_used, t);
  5219. // lift Z
  5220. raise_z(10);
  5221. // if axis are homed, move to parking position.
  5222. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) {
  5223. current_position[X_AXIS] = X_CANCEL_POS;
  5224. current_position[Y_AXIS] = Y_CANCEL_POS;
  5225. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5226. }
  5227. st_synchronize();
  5228. // did we come here from a thermal error?
  5229. if(get_temp_error()) {
  5230. // time to stop the error beep
  5231. WRITE(BEEPER, LOW);
  5232. } else {
  5233. // Turn off the print fan
  5234. fanSpeed = 0;
  5235. }
  5236. if (MMU2::mmu2.Enabled())
  5237. {
  5238. if (isPrintPaused)
  5239. {
  5240. // Restore temperature saved in ram after pausing print
  5241. restore_extruder_temperature_from_ram();
  5242. }
  5243. MMU2::mmu2.unload(); //M702 C
  5244. }
  5245. lcd_cooldown(); //turns off heaters and fan; goes to status screen.
  5246. finishAndDisableSteppers(); //M84
  5247. axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative
  5248. }
  5249. void lcd_print_stop()
  5250. {
  5251. // UnconditionalStop() will internally cause planner_abort_hard(), meaning we _cannot_ plan
  5252. // any more move in this call! Any further move must happen inside print_stop(), which is called
  5253. // by the main loop one iteration later.
  5254. UnconditionalStop();
  5255. if (!card.sdprinting) {
  5256. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint
  5257. }
  5258. #ifdef MESH_BED_LEVELING
  5259. mbl.active = false;
  5260. #endif
  5261. // clear any pending paused state immediately
  5262. pause_time = 0;
  5263. isPrintPaused = false;
  5264. // return to status is required to continue processing in the main loop!
  5265. lcd_commands_type = LcdCommands::StopPrint;
  5266. lcd_return_to_status();
  5267. }
  5268. #ifdef TEMP_MODEL
  5269. void lcd_temp_model_cal()
  5270. {
  5271. lcd_commands_type = LcdCommands::TempModel;
  5272. lcd_return_to_status();
  5273. }
  5274. #endif //TEMP_MODEL
  5275. void lcd_sdcard_stop()
  5276. {
  5277. lcd_puts_at_P(0, 0, _T(MSG_STOP_PRINT));
  5278. lcd_puts_at_P(2, 2, _T(MSG_NO));
  5279. lcd_puts_at_P(2, 3, _T(MSG_YES));
  5280. lcd_putc_at(0, 2, ' ');
  5281. lcd_putc_at(0, 3, ' ');
  5282. if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; }
  5283. if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; }
  5284. lcd_putc_at(0, 1 + lcd_encoder, '>');
  5285. if (lcd_clicked())
  5286. {
  5287. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5288. if ((int32_t)lcd_encoder == 1)
  5289. {
  5290. lcd_return_to_status();
  5291. }
  5292. if ((int32_t)lcd_encoder == 2)
  5293. {
  5294. lcd_print_stop();
  5295. }
  5296. }
  5297. }
  5298. void lcd_sdcard_menu()
  5299. {
  5300. enum menuState_t : uint8_t {_uninitialized, _standard, _scrolling};
  5301. typedef struct
  5302. {
  5303. menuState_t menuState = _uninitialized;
  5304. uint8_t offset;
  5305. bool isDir;
  5306. const char* scrollPointer;
  5307. uint16_t selectedFileID;
  5308. uint16_t fileCnt;
  5309. int8_t row;
  5310. uint8_t sdSort;
  5311. ShortTimer lcd_scrollTimer;
  5312. } _menu_data_sdcard_t;
  5313. static_assert(sizeof(menu_data)>= sizeof(_menu_data_sdcard_t),"_menu_data_sdcard_t doesn't fit into menu_data");
  5314. _menu_data_sdcard_t* _md = (_menu_data_sdcard_t*)&(menu_data[0]);
  5315. switch(_md->menuState)
  5316. {
  5317. case _uninitialized: //Initialize menu data
  5318. {
  5319. if (card.presort_flag == true) //used to force resorting if sorting type is changed.
  5320. {
  5321. card.presort_flag = false;
  5322. lcd_update_enabled = false;
  5323. card.presort();
  5324. lcd_update_enabled = true;
  5325. }
  5326. _md->fileCnt = card.getnrfilenames();
  5327. _md->sdSort = farm_mode ? SD_SORT_NONE : eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  5328. _md->menuState = _standard;
  5329. _md->row = -1; // assume that no SD file/dir is currently selected. Once they are rendered, it will be changed to the correct row for the _scrolling state.
  5330. }
  5331. // FALLTHRU
  5332. case _standard: //normal menu structure.
  5333. {
  5334. if (!_md->lcd_scrollTimer.running()) //if the timer is not running, then the menu state was just switched, so redraw the screen.
  5335. {
  5336. _md->lcd_scrollTimer.start();
  5337. lcd_draw_update = 1;
  5338. }
  5339. if ((lcd_draw_update == 0) && _md->lcd_scrollTimer.expired(500) && (_md->row != -1)) //switch to the scrolling state on timeout if a file/dir is selected.
  5340. {
  5341. _md->menuState = _scrolling;
  5342. _md->offset = 0;
  5343. _md->scrollPointer = NULL;
  5344. _md->lcd_scrollTimer.start();
  5345. lcd_draw_update = 1; //forces last load before switching to scrolling.
  5346. }
  5347. if (lcd_draw_update == 0 && !LCD_CLICKED)
  5348. return; // nothing to do (so don't thrash the SD card)
  5349. _md->row = -1; // assume that no SD file/dir is currently selected. Once they are rendered, it will be changed to the correct row for the _scrolling state.
  5350. //if we reached this point it means that the encoder moved or clicked or the state is being switched. Reset the scrollTimer.
  5351. _md->lcd_scrollTimer.start();
  5352. MENU_BEGIN();
  5353. MENU_ITEM_BACK_P(_T(bMain?MSG_MAIN:MSG_BACK)); // i.e. default menu-item / menu-item after card insertion
  5354. card.getWorkDirName();
  5355. if (card.filename[0] == '/')
  5356. {
  5357. #if SDCARDDETECT == -1
  5358. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  5359. #else
  5360. if (card.ToshibaFlashAir_isEnabled())
  5361. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh); //show the refresh option if in flashAir mode.
  5362. #endif
  5363. }
  5364. else
  5365. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); //Show the updir button if in a subdir.
  5366. for (uint16_t i = _md->fileCnt; i-- > 0;) // Every file, from top to bottom.
  5367. {
  5368. if (menu_item == menu_line) //If the file is on the screen.
  5369. {
  5370. //load filename to memory.
  5371. #ifdef SDCARD_SORT_ALPHA
  5372. card.getfilename_sorted(i, _md->sdSort);
  5373. #else
  5374. card.getfilename(i);
  5375. #endif
  5376. if (lcd_encoder == menu_item) //If the file is selected.
  5377. {
  5378. _md->selectedFileID = i;
  5379. _md->isDir = card.filenameIsDir;
  5380. _md->row = menu_row;
  5381. }
  5382. if (card.filenameIsDir)
  5383. MENU_ITEM_SDDIR(card.filename, card.longFilename);
  5384. else
  5385. MENU_ITEM_SDFILE(card.filename, card.longFilename);
  5386. }
  5387. else MENU_ITEM_DUMMY(); //dummy item that just increments the internal menu counters.
  5388. }
  5389. MENU_END();
  5390. } break;
  5391. case _scrolling: //scrolling filename
  5392. {
  5393. const bool rewindFlag = LCD_CLICKED || lcd_draw_update; //flag that says whether the menu should return to _standard state.
  5394. if (_md->scrollPointer == NULL)
  5395. {
  5396. //load filename to memory.
  5397. #ifdef SDCARD_SORT_ALPHA
  5398. card.getfilename_sorted(_md->selectedFileID, _md->sdSort);
  5399. #else
  5400. card.getfilename(_md->selectedFileID);
  5401. #endif
  5402. _md->scrollPointer = (card.longFilename[0] == '\0') ? card.filename : card.longFilename;
  5403. }
  5404. if (rewindFlag == 1)
  5405. _md->offset = 0; //redraw once again from the beginning.
  5406. if (_md->lcd_scrollTimer.expired(300) || rewindFlag)
  5407. {
  5408. uint8_t len = LCD_WIDTH - ((_md->isDir)? 2 : 1);
  5409. lcd_set_cursor(0, _md->row);
  5410. lcd_print('>');
  5411. if (_md->isDir)
  5412. lcd_print(LCD_STR_FOLDER[0]);
  5413. if( lcd_print_pad(&_md->scrollPointer[_md->offset], len) )
  5414. {
  5415. _md->lcd_scrollTimer.start();
  5416. _md->offset++;
  5417. } else {
  5418. // stop at the end of the string
  5419. _md->lcd_scrollTimer.stop();
  5420. }
  5421. }
  5422. if (rewindFlag) //go back to sd_menu.
  5423. {
  5424. _md->lcd_scrollTimer.stop(); //forces redraw in _standard state
  5425. _md->menuState = _standard;
  5426. }
  5427. } break;
  5428. default: _md->menuState = _uninitialized; //shouldn't ever happen. Anyways, initialize the menu.
  5429. }
  5430. }
  5431. #ifdef TMC2130
  5432. static void lcd_belttest_v()
  5433. {
  5434. lcd_belttest();
  5435. menu_back_if_clicked();
  5436. }
  5437. void lcd_belttest()
  5438. {
  5439. lcd_clear();
  5440. // Belttest requires high power mode. Enable it.
  5441. FORCE_HIGH_POWER_START;
  5442. uint16_t X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  5443. uint16_t Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  5444. lcd_printf_P(_T(MSG_CHECKING_X));
  5445. lcd_set_cursor(0,1), lcd_printf_P(PSTR("X: %u -> ..."),X);
  5446. KEEPALIVE_STATE(IN_HANDLER);
  5447. // N.B: it doesn't make sense to handle !lcd_selfcheck...() because selftest_sg throws its own error screen
  5448. // that clobbers ours, with more info than we could provide. So on fail we just fall through to take us back to status.
  5449. if (lcd_selfcheck_axis_sg(X_AXIS)){
  5450. X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  5451. lcd_set_cursor(10,1), lcd_printf_P(PSTR("%u"),X); // Show new X value next to old one.
  5452. lcd_puts_at_P(0,2,_T(MSG_CHECKING_Y));
  5453. lcd_set_cursor(0,3), lcd_printf_P(PSTR("Y: %u -> ..."),Y);
  5454. if (lcd_selfcheck_axis_sg(Y_AXIS))
  5455. {
  5456. Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  5457. lcd_set_cursor(10,3),lcd_printf_P(PSTR("%u"),Y);
  5458. lcd_set_cursor(19, 3);
  5459. lcd_print(LCD_STR_UPLEVEL[0]);
  5460. lcd_wait_for_click_delay(10);
  5461. }
  5462. }
  5463. FORCE_HIGH_POWER_END;
  5464. KEEPALIVE_STATE(NOT_BUSY);
  5465. }
  5466. #endif //TMC2130
  5467. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5468. // called also from marlin_main.cpp
  5469. void printf_IRSensorAnalogBoardChange(){
  5470. printf_P(PSTR("Filament sensor board change detected: revision%S\n"), fsensor.getIRVersionText());
  5471. }
  5472. static bool lcd_selftest_IRsensor(bool bStandalone)
  5473. {
  5474. FSensorBlockRunout fsBlockRunout;
  5475. IR_sensor_analog::SensorRevision oldSensorRevision = fsensor.getSensorRevision();
  5476. IR_sensor_analog::SensorRevision newSensorRevision;
  5477. uint16_t volt_IR_int = fsensor.getVoltRaw();
  5478. newSensorRevision = (volt_IR_int < fsensor.IRsensor_Hopen_TRESHOLD) ? IR_sensor_analog::SensorRevision::_Rev04 : IR_sensor_analog::SensorRevision::_Old;
  5479. printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"), Raw2Voltage(volt_IR_int) );
  5480. if(volt_IR_int < fsensor.IRsensor_Hmin_TRESHOLD){
  5481. if(!bStandalone)
  5482. lcd_selftest_error(TestError::FsensorLevel,"HIGH","");
  5483. return false;
  5484. }
  5485. lcd_show_fullscreen_message_and_wait_P(_i("Insert the filament (do not load it) into the extruder and then press the knob."));////MSG_INSERT_FIL c=20 r=6
  5486. volt_IR_int = fsensor.getVoltRaw();
  5487. printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"), Raw2Voltage(volt_IR_int));
  5488. if(volt_IR_int > (fsensor.IRsensor_Lmax_TRESHOLD)){
  5489. if(!bStandalone)
  5490. lcd_selftest_error(TestError::FsensorLevel,"LOW","");
  5491. return false;
  5492. }
  5493. if(newSensorRevision != oldSensorRevision) {
  5494. fsensor.setSensorRevision(newSensorRevision, true);
  5495. printf_IRSensorAnalogBoardChange();
  5496. }
  5497. return true;
  5498. }
  5499. static void lcd_detect_IRsensor(){
  5500. bool bAction;
  5501. bool loaded;
  5502. /// Check if filament is loaded. If it is loaded stop detection.
  5503. /// @todo Add autodetection with MMU2s
  5504. loaded = fsensor.getFilamentPresent();
  5505. if(loaded){
  5506. lcd_show_fullscreen_message_and_wait_P(_i("Please unload the filament first, then repeat this action."));////MSG_UNLOAD_FILAMENT_REPEAT c=20 r=4
  5507. return;
  5508. } else {
  5509. lcd_show_fullscreen_message_and_wait_P(_i("Please check the IR sensor connection, unload filament if present."));////MSG_CHECK_IR_CONNECTION c=20 r=4
  5510. bAction = lcd_selftest_IRsensor(true);
  5511. }
  5512. if(bAction){
  5513. lcd_show_fullscreen_message_and_wait_P(_i("Sensor verified, remove the filament now."));////MSG_FS_VERIFIED c=20 r=3
  5514. fsensor.init();
  5515. } else {
  5516. lcd_show_fullscreen_message_and_wait_P(_i("Verification failed, remove the filament and try again."));////MSG_FIL_FAILED c=20 r=5
  5517. }
  5518. }
  5519. #endif //IR_SENSOR_ANALOG
  5520. static void lcd_selftest_v()
  5521. {
  5522. (void)lcd_selftest();
  5523. }
  5524. bool lcd_selftest()
  5525. {
  5526. uint8_t _progress = 0;
  5527. bool _result = true;
  5528. bool _swapped_fan = false;
  5529. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5530. //! Check if IR sensor is in unknown state, if so run Fsensor Detection
  5531. //! As the Fsensor Detection isn't yet ready for the mmu2s we set temporarily the IR sensor 0.3 or older for mmu2s
  5532. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  5533. if(fsensor.getSensorRevision() == IR_sensor_analog::SensorRevision::_Undef) {
  5534. if (!MMU2::mmu2.Enabled()) {
  5535. lcd_detect_IRsensor();
  5536. }
  5537. else {
  5538. fsensor.setSensorRevision(IR_sensor_analog::SensorRevision::_Old, true);
  5539. }
  5540. }
  5541. #endif
  5542. lcd_wait_for_cool_down();
  5543. lcd_clear();
  5544. lcd_puts_at_P(0, 0, _i("Self test start"));////MSG_SELFTEST_START c=20
  5545. #ifdef TMC2130
  5546. FORCE_HIGH_POWER_START;
  5547. #endif // TMC2130
  5548. FORCE_BL_ON_START;
  5549. _delay(2000);
  5550. KEEPALIVE_STATE(IN_HANDLER);
  5551. _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000);
  5552. #if (defined(FANCHECK) && defined(TACH_0))
  5553. switch (lcd_selftest_fan_auto(0)){ // check hotend fan
  5554. case FanCheck::SwappedFan:
  5555. _swapped_fan = true; // swapped is merely a hint (checked later)
  5556. // FALLTHRU
  5557. case FanCheck::Success:
  5558. _result = true;
  5559. break;
  5560. default:
  5561. _result = false;
  5562. break;
  5563. }
  5564. #else //defined(TACH_0)
  5565. _result = lcd_selftest_manual_fan_check(0, false);
  5566. #endif //defined(TACH_0)
  5567. if (!_result)
  5568. {
  5569. lcd_selftest_error(TestError::ExtruderFan, "", "");
  5570. }
  5571. if (_result)
  5572. {
  5573. _progress = lcd_selftest_screen(TestScreen::PrintFan, _progress, 3, true, 2000);
  5574. #if (defined(FANCHECK) && defined(TACH_1))
  5575. switch (lcd_selftest_fan_auto(1)){ // check print fan
  5576. case FanCheck::SwappedFan:
  5577. _swapped_fan = true; // swapped is merely a hint (checked later)
  5578. // FALLTHRU
  5579. case FanCheck::Success:
  5580. _result = true;
  5581. break;
  5582. default:
  5583. _result = false;
  5584. break;
  5585. }
  5586. #else //defined(TACH_1)
  5587. _result = lcd_selftest_manual_fan_check(1, false);
  5588. #endif //defined(TACH_1)
  5589. if (!_result)
  5590. {
  5591. lcd_selftest_error(TestError::PrintFan, "", ""); //print fan not spinning
  5592. }
  5593. }
  5594. if (_swapped_fan) {
  5595. //turn on print fan and check that left hotend fan is not spinning
  5596. _result = lcd_selftest_manual_fan_check(1, true);
  5597. if (_result) {
  5598. //print fan is stil turned on; check that it is spinning
  5599. _result = lcd_selftest_manual_fan_check(1, false, true);
  5600. if (!_result){
  5601. lcd_selftest_error(TestError::PrintFan, "", "");
  5602. }
  5603. }
  5604. else {
  5605. // fans are swapped
  5606. lcd_selftest_error(TestError::SwappedFan, "", "");
  5607. }
  5608. }
  5609. if (_result)
  5610. {
  5611. _progress = lcd_selftest_screen(TestScreen::FansOk, _progress, 3, true, 2000);
  5612. _result = lcd_selfcheck_endstops(); //With TMC2130, only the Z probe is tested.
  5613. }
  5614. if (_result)
  5615. {
  5616. //current_position[Z_AXIS] += 15; //move Z axis higher to avoid false triggering of Z end stop in case that we are very low - just above heatbed
  5617. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 2000);
  5618. #ifdef TMC2130
  5619. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5620. #else
  5621. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5622. #endif //TMC2130
  5623. }
  5624. if (_result)
  5625. {
  5626. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 0);
  5627. #ifndef TMC2130
  5628. _result = lcd_selfcheck_pulleys(X_AXIS);
  5629. #endif
  5630. }
  5631. if (_result)
  5632. {
  5633. _progress = lcd_selftest_screen(TestScreen::AxisY, _progress, 3, true, 1500);
  5634. #ifdef TMC2130
  5635. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5636. #else
  5637. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5638. #endif // TMC2130
  5639. }
  5640. if (_result)
  5641. {
  5642. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 0);
  5643. #ifndef TMC2130
  5644. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5645. #endif // TMC2130
  5646. }
  5647. if (_result)
  5648. {
  5649. #ifdef TMC2130
  5650. tmc2130_home_exit();
  5651. enable_endstops(false);
  5652. #endif
  5653. //homeaxis(X_AXIS);
  5654. //homeaxis(Y_AXIS);
  5655. current_position[X_AXIS] = pgm_read_float(bed_ref_points_4);
  5656. current_position[Y_AXIS] = pgm_read_float(bed_ref_points_4+1);
  5657. #ifdef TMC2130
  5658. //current_position[X_AXIS] += 0;
  5659. current_position[Y_AXIS] += 4;
  5660. #endif //TMC2130
  5661. raise_z(10);
  5662. set_destination_to_current();
  5663. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500);
  5664. #ifdef TMC2130
  5665. homeaxis(Z_AXIS); //In case of failure, the code gets stuck in this function.
  5666. #else
  5667. _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS);
  5668. #endif //TMC2130
  5669. //raise Z to not damage the bed during and hotend testing
  5670. raise_z(20);
  5671. }
  5672. #ifdef TMC2130
  5673. if (_result)
  5674. {
  5675. raise_z(10);
  5676. _progress = lcd_selftest_screen(TestScreen::Home, 0, 2, true, 0);
  5677. bool bres = tmc2130_home_calibrate(X_AXIS);
  5678. _progress = lcd_selftest_screen(TestScreen::Home, 1, 2, true, 0);
  5679. bres &= tmc2130_home_calibrate(Y_AXIS);
  5680. _progress = lcd_selftest_screen(TestScreen::Home, 2, 2, true, 0);
  5681. if (bres)
  5682. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5683. _result = bres;
  5684. }
  5685. #endif //TMC2130
  5686. if (_result)
  5687. {
  5688. _progress = lcd_selftest_screen(TestScreen::Bed, _progress, 3, true, 2000);
  5689. _result = lcd_selfcheck_check_heater(true);
  5690. }
  5691. if (_result)
  5692. {
  5693. _progress = lcd_selftest_screen(TestScreen::Hotend, _progress, 3, true, 1000);
  5694. _result = lcd_selfcheck_check_heater(false);
  5695. }
  5696. if (_result)
  5697. {
  5698. _progress = lcd_selftest_screen(TestScreen::HotendOk, _progress, 3, true, 2000); //nozzle ok
  5699. }
  5700. #ifdef FILAMENT_SENSOR
  5701. if (_result)
  5702. {
  5703. #if (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5704. if (MMU2::mmu2.Enabled())
  5705. {
  5706. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  5707. _result = selftest_irsensor();
  5708. if (_result)
  5709. {
  5710. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  5711. }
  5712. } else
  5713. #endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5714. {
  5715. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  5716. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  5717. _result = lcd_selftest_fsensor();
  5718. if (_result)
  5719. {
  5720. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  5721. }
  5722. #endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  5723. #if 0
  5724. // Intentionally disabled - that's why we moved the detection to runtime by just checking the two voltages.
  5725. // The idea is not to force the user to remove and insert the filament on an assembled printer.
  5726. //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5727. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filament sensor
  5728. _result = lcd_selftest_IRsensor();
  5729. if (_result)
  5730. {
  5731. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //filament sensor OK
  5732. }
  5733. #endif //IR_SENSOR_ANALOG
  5734. }
  5735. }
  5736. #endif //FILAMENT_SENSOR
  5737. if (_result)
  5738. {
  5739. _progress = lcd_selftest_screen(TestScreen::AllCorrect, _progress, 3, true, 5000); //all correct
  5740. }
  5741. else
  5742. {
  5743. _progress = lcd_selftest_screen(TestScreen::Failed, _progress, 3, true, 5000);
  5744. }
  5745. lcd_reset_alert_level();
  5746. enquecommand_P(PSTR("M84"));
  5747. lcd_update_enable(true);
  5748. if (_result)
  5749. {
  5750. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=20
  5751. }
  5752. else
  5753. {
  5754. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5755. }
  5756. #ifdef TMC2130
  5757. FORCE_HIGH_POWER_END;
  5758. #endif // TMC2130
  5759. FORCE_BL_ON_END;
  5760. KEEPALIVE_STATE(NOT_BUSY);
  5761. return(_result);
  5762. }
  5763. #ifdef TMC2130
  5764. static void reset_crash_det(uint8_t axis) {
  5765. current_position[axis] += 10;
  5766. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5767. st_synchronize();
  5768. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5769. }
  5770. static bool lcd_selfcheck_axis_sg(uint8_t axis) {
  5771. // each axis length is measured twice
  5772. float axis_length, current_position_init, current_position_final;
  5773. float measured_axis_length[2];
  5774. float margin = 60;
  5775. float max_error_mm = 5;
  5776. switch (axis) {
  5777. case 0: axis_length = X_MAX_POS; break;
  5778. case 1: axis_length = Y_MAX_POS + 8; break;
  5779. default: axis_length = 210; break;
  5780. }
  5781. tmc2130_sg_stop_on_crash = false;
  5782. tmc2130_home_exit();
  5783. enable_endstops(true);
  5784. raise_z_above(MESH_HOME_Z_SEARCH);
  5785. tmc2130_home_enter(1 << axis);
  5786. // first axis length measurement begin
  5787. current_position[axis] -= (axis_length + margin);
  5788. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5789. st_synchronize();
  5790. tmc2130_sg_meassure_start(axis);
  5791. current_position_init = st_get_position_mm(axis);
  5792. current_position[axis] += 2 * margin;
  5793. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5794. st_synchronize();
  5795. current_position[axis] += axis_length;
  5796. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5797. st_synchronize();
  5798. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5799. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5800. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5801. current_position_final = st_get_position_mm(axis);
  5802. measured_axis_length[0] = fabs(current_position_final - current_position_init);
  5803. // first measurement end and second measurement begin
  5804. current_position[axis] -= margin;
  5805. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5806. st_synchronize();
  5807. current_position[axis] -= (axis_length + margin);
  5808. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5809. st_synchronize();
  5810. current_position_init = st_get_position_mm(axis);
  5811. measured_axis_length[1] = fabs(current_position_final - current_position_init);
  5812. tmc2130_home_exit();
  5813. //end of second measurement, now check for possible errors:
  5814. for(uint_least8_t i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5815. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  5816. if (fabs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5817. enable_endstops(false);
  5818. const char *_error_1;
  5819. if (axis == X_AXIS) _error_1 = "X";
  5820. if (axis == Y_AXIS) _error_1 = "Y";
  5821. if (axis == Z_AXIS) _error_1 = "Z";
  5822. lcd_selftest_error(TestError::Axis, _error_1, "");
  5823. current_position[axis] = 0;
  5824. plan_set_position_curposXYZE();
  5825. reset_crash_det(axis);
  5826. enable_endstops(true);
  5827. endstops_hit_on_purpose();
  5828. return false;
  5829. }
  5830. }
  5831. printf_P(_N("Axis length difference:%.3f\n"), fabs(measured_axis_length[0] - measured_axis_length[1]));
  5832. if (fabs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5833. //loose pulleys
  5834. const char *_error_1;
  5835. if (axis == X_AXIS) _error_1 = "X";
  5836. if (axis == Y_AXIS) _error_1 = "Y";
  5837. if (axis == Z_AXIS) _error_1 = "Z";
  5838. lcd_selftest_error(TestError::Pulley, _error_1, "");
  5839. current_position[axis] = 0;
  5840. plan_set_position_curposXYZE();
  5841. reset_crash_det(axis);
  5842. endstops_hit_on_purpose();
  5843. return false;
  5844. }
  5845. current_position[axis] = 0;
  5846. plan_set_position_curposXYZE();
  5847. reset_crash_det(axis);
  5848. endstops_hit_on_purpose();
  5849. return true;
  5850. }
  5851. #endif //TMC2130
  5852. #ifndef TMC2130
  5853. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5854. {
  5855. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  5856. bool _stepdone = false;
  5857. bool _stepresult = false;
  5858. uint8_t _progress = 0;
  5859. int _travel_done = 0;
  5860. int _err_endstop = 0;
  5861. int _lcd_refresh = 0;
  5862. _travel = _travel + (_travel / 10);
  5863. if (_axis == X_AXIS) {
  5864. current_position[Z_AXIS] += 17;
  5865. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5866. }
  5867. do {
  5868. current_position[_axis] = current_position[_axis] - 1;
  5869. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5870. st_synchronize();
  5871. #ifdef TMC2130
  5872. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5873. #else //TMC2130
  5874. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  5875. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  5876. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5877. #endif //TMC2130
  5878. {
  5879. if (_axis == 0)
  5880. {
  5881. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5882. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5883. }
  5884. if (_axis == 1)
  5885. {
  5886. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5887. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5888. }
  5889. if (_axis == 2)
  5890. {
  5891. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5892. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5893. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  5894. /*disable_x();
  5895. disable_y();
  5896. disable_z();*/
  5897. }
  5898. _stepdone = true;
  5899. }
  5900. if (_lcd_refresh < 6)
  5901. {
  5902. _lcd_refresh++;
  5903. }
  5904. else
  5905. {
  5906. _progress = lcd_selftest_screen(static_cast<TestScreen>(static_cast<int>(TestScreen::AxisX) + _axis), _progress, 3, false, 0);
  5907. _lcd_refresh = 0;
  5908. }
  5909. manage_heater();
  5910. manage_inactivity(true);
  5911. //_delay(100);
  5912. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5913. } while (!_stepdone);
  5914. //current_position[_axis] = current_position[_axis] + 15;
  5915. //plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder);
  5916. if (!_stepresult)
  5917. {
  5918. const char *_error_1;
  5919. const char *_error_2;
  5920. if (_axis == X_AXIS) _error_1 = "X";
  5921. if (_axis == Y_AXIS) _error_1 = "Y";
  5922. if (_axis == Z_AXIS) _error_1 = "Z";
  5923. if (_err_endstop == 0) _error_2 = "X";
  5924. if (_err_endstop == 1) _error_2 = "Y";
  5925. if (_err_endstop == 2) _error_2 = "Z";
  5926. if (_travel_done >= _travel)
  5927. {
  5928. lcd_selftest_error(TestError::Endstop, _error_1, _error_2);
  5929. }
  5930. else
  5931. {
  5932. lcd_selftest_error(TestError::Motor, _error_1, _error_2);
  5933. }
  5934. }
  5935. current_position[_axis] = 0; //simulate axis home to avoid negative numbers for axis position, especially Z.
  5936. plan_set_position_curposXYZE();
  5937. return _stepresult;
  5938. }
  5939. static bool lcd_selfcheck_pulleys(int axis)
  5940. {
  5941. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5942. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5943. float current_position_init;
  5944. float move;
  5945. bool endstop_triggered = false;
  5946. int i;
  5947. unsigned long timeout_counter;
  5948. refresh_cmd_timeout();
  5949. manage_inactivity(true);
  5950. if (axis == 0) move = 50; //X_AXIS
  5951. else move = 50; //Y_AXIS
  5952. current_position_init = current_position[axis];
  5953. current_position[axis] += 2;
  5954. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5955. for (i = 0; i < 5; i++) {
  5956. refresh_cmd_timeout();
  5957. current_position[axis] = current_position[axis] + move;
  5958. st_current_set(0, 850); //set motor current higher
  5959. plan_buffer_line_curposXYZE(200);
  5960. st_synchronize();
  5961. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  5962. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  5963. current_position[axis] = current_position[axis] - move;
  5964. plan_buffer_line_curposXYZE(50);
  5965. st_synchronize();
  5966. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5967. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5968. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  5969. return(false);
  5970. }
  5971. }
  5972. timeout_counter = _millis() + 2500;
  5973. endstop_triggered = false;
  5974. manage_inactivity(true);
  5975. while (!endstop_triggered) {
  5976. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5977. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5978. endstop_triggered = true;
  5979. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5980. current_position[axis] += 10;
  5981. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5982. st_synchronize();
  5983. return(true);
  5984. }
  5985. else {
  5986. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  5987. return(false);
  5988. }
  5989. }
  5990. else {
  5991. current_position[axis] -= 1;
  5992. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5993. st_synchronize();
  5994. if (_millis() > timeout_counter) {
  5995. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  5996. return(false);
  5997. }
  5998. }
  5999. }
  6000. return(true);
  6001. }
  6002. #endif //not defined TMC2130
  6003. static bool lcd_selfcheck_endstops()
  6004. {
  6005. bool _result = true;
  6006. if (
  6007. #ifndef TMC2130
  6008. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6009. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6010. #endif //!TMC2130
  6011. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6012. {
  6013. #ifndef TMC2130
  6014. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  6015. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  6016. #endif //!TMC2130
  6017. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  6018. }
  6019. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6020. st_synchronize();
  6021. if (
  6022. #ifndef TMC2130
  6023. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6024. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6025. #endif //!TMC2130
  6026. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6027. {
  6028. _result = false;
  6029. char _error[4] = "";
  6030. #ifndef TMC2130
  6031. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  6032. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  6033. #endif //!TMC2130
  6034. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  6035. lcd_selftest_error(TestError::Endstops, _error, "");
  6036. }
  6037. manage_heater();
  6038. manage_inactivity(true);
  6039. return _result;
  6040. }
  6041. static bool lcd_selfcheck_check_heater(bool _isbed)
  6042. {
  6043. uint8_t _counter = 0;
  6044. uint8_t _progress = 0;
  6045. bool _stepresult = false;
  6046. bool _docycle = true;
  6047. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  6048. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  6049. uint8_t _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  6050. target_temperature[0] = (_isbed) ? 0 : 200;
  6051. target_temperature_bed = (_isbed) ? 100 : 0;
  6052. manage_heater();
  6053. manage_inactivity(true);
  6054. do {
  6055. _counter++;
  6056. _docycle = (_counter < _cycles) ? true : false;
  6057. manage_heater();
  6058. manage_inactivity(true);
  6059. _progress = (_isbed) ? lcd_selftest_screen(TestScreen::Bed, _progress, 2, false, 400) : lcd_selftest_screen(TestScreen::Hotend, _progress, 2, false, 400);
  6060. /*if (_isbed) {
  6061. MYSERIAL.print("Bed temp:");
  6062. MYSERIAL.println(degBed());
  6063. }
  6064. else {
  6065. MYSERIAL.print("Hotend temp:");
  6066. MYSERIAL.println(degHotend(0));
  6067. }*/
  6068. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  6069. } while (_docycle);
  6070. target_temperature[0] = 0;
  6071. target_temperature_bed = 0;
  6072. manage_heater();
  6073. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  6074. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  6075. /*
  6076. MYSERIAL.println("");
  6077. MYSERIAL.print("Checked result:");
  6078. MYSERIAL.println(_checked_result);
  6079. MYSERIAL.print("Opposite result:");
  6080. MYSERIAL.println(_opposite_result);
  6081. */
  6082. if (_opposite_result < ((_isbed) ? 30 : 9))
  6083. {
  6084. if (_checked_result >= ((_isbed) ? 9 : 30))
  6085. {
  6086. _stepresult = true;
  6087. }
  6088. else
  6089. {
  6090. lcd_selftest_error(TestError::Heater, "", "");
  6091. }
  6092. }
  6093. else
  6094. {
  6095. lcd_selftest_error(TestError::Bed, "", "");
  6096. }
  6097. manage_heater();
  6098. manage_inactivity(true);
  6099. return _stepresult;
  6100. }
  6101. static void lcd_selftest_error(TestError testError, const char *_error_1, const char *_error_2)
  6102. {
  6103. lcd_beeper_quick_feedback();
  6104. FORCE_BL_ON_END;
  6105. target_temperature[0] = 0;
  6106. target_temperature_bed = 0;
  6107. manage_heater();
  6108. manage_inactivity();
  6109. lcd_clear();
  6110. lcd_puts_at_P(0, 0, _i("Selftest error!"));////MSG_SELFTEST_ERROR c=20
  6111. lcd_puts_at_P(0, 1, _i("Please check:"));////MSG_SELFTEST_PLEASECHECK c=20
  6112. switch (testError)
  6113. {
  6114. case TestError::Heater:
  6115. lcd_puts_at_P(0, 2, _i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=20
  6116. lcd_puts_at_P(0, 3, _i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=20
  6117. break;
  6118. case TestError::Bed:
  6119. lcd_puts_at_P(0, 2, _i("Bed/Heater"));////MSG_SELFTEST_BEDHEATER c=20
  6120. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6121. break;
  6122. case TestError::Endstops:
  6123. lcd_puts_at_P(0, 2, _i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=20
  6124. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6125. lcd_set_cursor(18, 3);
  6126. lcd_print(_error_1);
  6127. break;
  6128. case TestError::Motor:
  6129. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_MOTOR));
  6130. lcd_set_cursor(18, 2);
  6131. lcd_print(_error_1);
  6132. lcd_puts_at_P(0, 3, _i("Endstop"));////MSG_SELFTEST_ENDSTOP c=16
  6133. lcd_set_cursor(18, 3);
  6134. lcd_print(_error_2);
  6135. break;
  6136. case TestError::Endstop:
  6137. lcd_puts_at_P(0, 2, _i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20
  6138. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  6139. lcd_set_cursor(18, 3);
  6140. lcd_print(_error_1);
  6141. break;
  6142. case TestError::PrintFan:
  6143. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_PART_FAN));
  6144. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6145. lcd_set_cursor(18, 3);
  6146. lcd_print(_error_1);
  6147. break;
  6148. case TestError::ExtruderFan:
  6149. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_HOTEND_FAN));
  6150. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6151. lcd_set_cursor(18, 3);
  6152. lcd_print(_error_1);
  6153. break;
  6154. case TestError::Pulley:
  6155. lcd_puts_at_P(0, 2, _i("Loose pulley"));////MSG_LOOSE_PULLEY c=20
  6156. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  6157. lcd_set_cursor(18, 3);
  6158. lcd_print(_error_1);
  6159. break;
  6160. case TestError::Axis:
  6161. lcd_puts_at_P(0, 2, _i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=20
  6162. lcd_puts_at_P(0, 3, _i("Axis"));////MSG_SELFTEST_AXIS c=16
  6163. lcd_set_cursor(18, 3);
  6164. lcd_print(_error_1);
  6165. break;
  6166. case TestError::SwappedFan:
  6167. lcd_puts_at_P(0, 2, _i("Front/left fans"));////MSG_SELFTEST_FANS c=20
  6168. lcd_puts_at_P(0, 3, _i("Swapped"));////MSG_SELFTEST_SWAPPED c=16
  6169. lcd_set_cursor(18, 3);
  6170. lcd_print(_error_1);
  6171. break;
  6172. case TestError::WiringFsensor:
  6173. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6174. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6175. break;
  6176. case TestError::TriggeringFsensor:
  6177. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6178. lcd_puts_at_P(0, 3, _i("False triggering"));////MSG_FALSE_TRIGGERING c=20
  6179. break;
  6180. case TestError::FsensorLevel:
  6181. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6182. lcd_set_cursor(0, 3);
  6183. lcd_printf_P(_i("%s level expected"),_error_1);////MSG_SELFTEST_FS_LEVEL c=20
  6184. break;
  6185. }
  6186. _delay(1000);
  6187. lcd_beeper_quick_feedback();
  6188. do {
  6189. _delay(100);
  6190. manage_heater();
  6191. manage_inactivity();
  6192. } while (!lcd_clicked());
  6193. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  6194. lcd_return_to_status();
  6195. }
  6196. #ifdef FILAMENT_SENSOR
  6197. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  6198. static bool lcd_selftest_fsensor(void)
  6199. {
  6200. fsensor.init();
  6201. if (fsensor.isError())
  6202. {
  6203. lcd_selftest_error(TestError::WiringFsensor, "", "");
  6204. }
  6205. return (!fsensor.isError());
  6206. }
  6207. #endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  6208. #if (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  6209. //! @brief Self-test of infrared barrier filament sensor mounted on MK3S with MMUv2 printer
  6210. //!
  6211. //! Test whether sensor is not triggering filament presence when extruder idler is moving without filament.
  6212. //!
  6213. //! Steps:
  6214. //! * Backup current active extruder temperature
  6215. //! * Pre-heat to PLA extrude temperature.
  6216. //! * Unload filament possibly present.
  6217. //! * Move extruder idler same way as during filament load
  6218. //! and sample the filament sensor.
  6219. //! * Check that pin doesn't go low.
  6220. //!
  6221. //! @retval true passed
  6222. //! @retval false failed
  6223. static bool selftest_irsensor()
  6224. {
  6225. class TempBackup
  6226. {
  6227. public:
  6228. TempBackup():
  6229. m_temp(degTargetHotend(active_extruder)),
  6230. m_extruder(active_extruder){}
  6231. ~TempBackup(){setTargetHotend(m_temp,m_extruder);}
  6232. private:
  6233. float m_temp;
  6234. uint8_t m_extruder;
  6235. };
  6236. uint8_t progress;
  6237. {
  6238. TempBackup tempBackup;
  6239. setTargetHotend(ABS_PREHEAT_HOTEND_TEMP,active_extruder);
  6240. progress = lcd_selftest_screen(TestScreen::Fsensor, 0, 1, true, 0);
  6241. }
  6242. progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  6243. MMU2::mmu2.unload();
  6244. for(uint_least8_t i = 0; i < 200; ++i)
  6245. {
  6246. if (0 == (i % 32)) progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  6247. //@@TODO mmu_load_step(false);
  6248. while (blocks_queued())
  6249. {
  6250. if (fsensor.getFilamentPresent())
  6251. {
  6252. lcd_selftest_error(TestError::TriggeringFsensor, "", "");
  6253. return false;
  6254. }
  6255. #ifdef TMC2130
  6256. manage_heater();
  6257. // Vojtech: Don't disable motors inside the planner!
  6258. if (!tmc2130_update_sg())
  6259. {
  6260. manage_inactivity(true);
  6261. }
  6262. #else //TMC2130
  6263. manage_heater();
  6264. // Vojtech: Don't disable motors inside the planner!
  6265. manage_inactivity(true);
  6266. #endif //TMC2130
  6267. }
  6268. }
  6269. return true;
  6270. }
  6271. #endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  6272. #endif //FILAMENT_SENSOR
  6273. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  6274. bool _default)
  6275. {
  6276. bool _result = check_opposite;
  6277. lcd_clear();
  6278. lcd_puts_at_P(0, 0, _T(MSG_SELFTEST_FAN));
  6279. switch (_fan)
  6280. {
  6281. case 0:
  6282. // extruder cooling fan
  6283. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_PART_FAN) : _T(MSG_SELFTEST_HOTEND_FAN));
  6284. setExtruderAutoFanState(3);
  6285. break;
  6286. case 1:
  6287. // object cooling fan
  6288. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_HOTEND_FAN) : _T(MSG_SELFTEST_PART_FAN));
  6289. SET_OUTPUT(FAN_PIN);
  6290. #ifdef FAN_SOFT_PWM
  6291. fanSpeedSoftPwm = 255;
  6292. #else //FAN_SOFT_PWM
  6293. analogWrite(FAN_PIN, 255);
  6294. #endif //FAN_SOFT_PWM
  6295. break;
  6296. }
  6297. _delay(500);
  6298. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  6299. lcd_putc_at(0, 3, '>');
  6300. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  6301. int8_t enc_dif = int(_default)*3;
  6302. KEEPALIVE_STATE(PAUSED_FOR_USER);
  6303. lcd_button_pressed = false;
  6304. do
  6305. {
  6306. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  6307. if (enc_dif > lcd_encoder_diff) {
  6308. _result = !check_opposite;
  6309. lcd_putc_at(0, 2, '>');
  6310. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  6311. lcd_putc_at(0, 3, ' ');
  6312. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  6313. }
  6314. if (enc_dif < lcd_encoder_diff) {
  6315. _result = check_opposite;
  6316. lcd_putc_at(0, 2, ' ');
  6317. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  6318. lcd_putc_at(0, 3, '>');
  6319. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  6320. }
  6321. enc_dif = 0;
  6322. lcd_encoder_diff = 0;
  6323. }
  6324. manage_heater();
  6325. _delay(100);
  6326. } while (!lcd_clicked());
  6327. KEEPALIVE_STATE(IN_HANDLER);
  6328. setExtruderAutoFanState(0);
  6329. SET_OUTPUT(FAN_PIN);
  6330. #ifdef FAN_SOFT_PWM
  6331. fanSpeedSoftPwm = 0;
  6332. #else //FAN_SOFT_PWM
  6333. analogWrite(FAN_PIN, 0);
  6334. #endif //FAN_SOFT_PWM
  6335. fanSpeed = 0;
  6336. manage_heater();
  6337. return _result;
  6338. }
  6339. #ifdef FANCHECK
  6340. // Set print fan speed
  6341. static void lcd_selftest_setfan(uint8_t speed) {
  6342. // set the fan speed
  6343. fanSpeed = speed;
  6344. #ifdef FAN_SOFT_PWM
  6345. fanSpeedSoftPwm = speed;
  6346. #endif
  6347. manage_heater();
  6348. }
  6349. // Wait for the specified number of seconds while displaying some single-character indicator on the
  6350. // screen coordinate col/row, then perform fan measurement
  6351. static void lcd_selftest_measure_fans(uint8_t delay, uint8_t col, uint8_t row) {
  6352. // spin-up delay
  6353. static char symbols[] = {'-', '|'};
  6354. static_assert(1000 / sizeof(symbols) * sizeof(symbols) == 1000);
  6355. while(delay--) {
  6356. for(uint8_t i = 0; i != sizeof(symbols); ++i) {
  6357. lcd_putc_at(col, row, symbols[i]);
  6358. delay_keep_alive(1000 / sizeof(symbols));
  6359. }
  6360. }
  6361. #ifdef FANCHECK
  6362. extruder_autofan_last_check = _millis();
  6363. #endif
  6364. fan_measuring = true;
  6365. while(fan_measuring) {
  6366. delay_keep_alive(100);
  6367. }
  6368. gcode_M123();
  6369. }
  6370. static FanCheck lcd_selftest_fan_auto(uint8_t _fan)
  6371. {
  6372. // speed threshold to differentiate between extruder and print fan
  6373. static const int printFanThr = FANCHECK_AUTO_PRINT_FAN_THRS; // >= FANCHECK_AUTO_PRINT_FAN_THRS RPS
  6374. // speed threshold to mark a fan as failed
  6375. static const int failThr = FANCHECK_AUTO_FAIL_THRS; // < FANCHECK_AUTO_FAIL_THRS RPM would mean either a faulty Noctua, Altfan or print fan
  6376. switch (_fan) {
  6377. case 0:
  6378. setExtruderAutoFanState(3); // hotend fan
  6379. lcd_selftest_setfan(0); // print fan off
  6380. lcd_selftest_measure_fans(2, 18, 2);
  6381. setExtruderAutoFanState(0); // hotend fan off
  6382. if (fan_speed[0] < failThr) {
  6383. return FanCheck::ExtruderFan;
  6384. }
  6385. if (fan_speed[0] >= printFanThr ) {
  6386. return FanCheck::SwappedFan;
  6387. }
  6388. break;
  6389. case 1:
  6390. lcd_selftest_setfan(255);
  6391. lcd_selftest_measure_fans(5, 18, 3);
  6392. lcd_selftest_setfan(0);
  6393. if (fan_speed[1] < failThr) {
  6394. return FanCheck::PrintFan;
  6395. }
  6396. if (fan_speed[1] < printFanThr) {
  6397. return FanCheck::SwappedFan;
  6398. }
  6399. }
  6400. return FanCheck::Success;
  6401. }
  6402. #endif //FANCHECK
  6403. static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay)
  6404. {
  6405. lcd_update_enable(false);
  6406. const char *_indicator = (_progress >= _progress_scale) ? "-" : "|";
  6407. if (_clear) lcd_clear();
  6408. lcd_set_cursor(0, 0);
  6409. if (screen == TestScreen::ExtruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6410. if (screen == TestScreen::PrintFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6411. if (screen == TestScreen::FansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6412. if (screen == TestScreen::EndStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20
  6413. if (screen == TestScreen::AxisX) lcd_puts_P(_T(MSG_CHECKING_X));
  6414. if (screen == TestScreen::AxisY) lcd_puts_P(_T(MSG_CHECKING_Y));
  6415. if (screen == TestScreen::AxisZ) lcd_puts_P(_i("Checking Z axis"));////MSG_SELFTEST_CHECK_Z c=20
  6416. if (screen == TestScreen::Bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  6417. if (screen == TestScreen::Hotend
  6418. || screen == TestScreen::HotendOk) lcd_puts_P(_i("Checking hotend"));////MSG_SELFTEST_CHECK_HOTEND c=20
  6419. if (screen == TestScreen::Fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6420. if (screen == TestScreen::FsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6421. if (screen == TestScreen::AllCorrect) lcd_puts_P(_i("All correct"));////MSG_SELFTEST_CHECK_ALLCORRECT c=20
  6422. if (screen == TestScreen::Failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  6423. if (screen == TestScreen::Home) lcd_puts_P(_i("Calibrating home"));////MSG_CALIBRATING_HOME c=20
  6424. lcd_puts_at_P(0, 1, separator);
  6425. if ((screen >= TestScreen::ExtruderFan) && (screen <= TestScreen::FansOk))
  6426. {
  6427. //SERIAL_ECHOLNPGM("Fan test");
  6428. lcd_puts_at_P(0, 2, _T(MSG_HOTEND_FAN_SPEED));
  6429. lcd_set_cursor(18, 2);
  6430. (screen < TestScreen::PrintFan) ? lcd_print(_indicator) : lcd_print("OK");
  6431. lcd_puts_at_P(0, 3, _T(MSG_PRINT_FAN_SPEED));
  6432. lcd_set_cursor(18, 3);
  6433. (screen < TestScreen::FansOk) ? lcd_print(_indicator) : lcd_print("OK");
  6434. }
  6435. else if (screen >= TestScreen::Fsensor && screen <= TestScreen::FsensorOk)
  6436. {
  6437. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6438. lcd_putc(':');
  6439. lcd_set_cursor(18, 2);
  6440. (screen == TestScreen::Fsensor) ? lcd_print(_indicator) : lcd_print("OK");
  6441. }
  6442. else if (screen < TestScreen::Fsensor)
  6443. {
  6444. //SERIAL_ECHOLNPGM("Other tests");
  6445. TestScreen _step_block = TestScreen::AxisX;
  6446. lcd_selftest_screen_step(2, 2, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("X"), _indicator);
  6447. _step_block = TestScreen::AxisY;
  6448. lcd_selftest_screen_step(2, 8, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Y"), _indicator);
  6449. _step_block = TestScreen::AxisZ;
  6450. lcd_selftest_screen_step(2, 14, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Z"), _indicator);
  6451. _step_block = TestScreen::Bed;
  6452. lcd_selftest_screen_step(3, 0, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Bed"), _indicator);
  6453. _step_block = TestScreen::Hotend;
  6454. lcd_selftest_screen_step(3, 9, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Hotend"), _indicator);
  6455. }
  6456. if (_delay > 0) delay_keep_alive(_delay);
  6457. _progress++;
  6458. return (_progress >= _progress_scale * 2) ? 0 : _progress;
  6459. }
  6460. static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name_PROGMEM, const char *_indicator)
  6461. {
  6462. lcd_set_cursor(_col, _row);
  6463. uint8_t strlenNameP = strlen_P(_name_PROGMEM);
  6464. switch (_state)
  6465. {
  6466. case 1:
  6467. lcd_puts_P(_name_PROGMEM);
  6468. lcd_putc_at(_col + strlenNameP, _row, ':');
  6469. lcd_set_cursor(_col + strlenNameP + 1, _row);
  6470. lcd_print(_indicator);
  6471. break;
  6472. case 2:
  6473. lcd_puts_P(_name_PROGMEM);
  6474. lcd_putc_at(_col + strlenNameP, _row, ':');
  6475. lcd_puts_at_P(_col + strlenNameP + 1, _row, PSTR("OK"));
  6476. break;
  6477. default:
  6478. lcd_puts_P(_name_PROGMEM);
  6479. }
  6480. }
  6481. /** End of menus **/
  6482. /** Menu action functions **/
  6483. static bool check_file(const char* filename) {
  6484. if (farm_mode) return true;
  6485. card.openFileReadFilteredGcode(filename, true);
  6486. bool result = false;
  6487. const uint32_t filesize = card.getFileSize();
  6488. uint32_t startPos = 0;
  6489. const uint16_t bytesToCheck = min(END_FILE_SECTION, filesize);
  6490. if (filesize > END_FILE_SECTION) {
  6491. startPos = filesize - END_FILE_SECTION;
  6492. card.setIndex(startPos);
  6493. }
  6494. cmdqueue_reset();
  6495. cmdqueue_serial_disabled = true;
  6496. menu_progressbar_init(bytesToCheck, _i("Checking file"));////MSG_CHECKING_FILE c=17
  6497. while (!card.eof() && !result) {
  6498. menu_progressbar_update(card.get_sdpos() - startPos);
  6499. card.sdprinting = true;
  6500. get_command();
  6501. result = check_commands();
  6502. #ifdef CMDBUFFER_DEBUG
  6503. // Kick watchdog because the file check is very slow
  6504. // with the CMDBUFFER_DEBUG enabled
  6505. manage_heater();
  6506. #endif // CMDBUFFER_DEBUG
  6507. }
  6508. menu_progressbar_finish();
  6509. cmdqueue_serial_disabled = false;
  6510. card.printingHasFinished();
  6511. lcd_setstatuspgm(MSG_WELCOME);
  6512. return result;
  6513. }
  6514. static void menu_action_sdfile(const char* filename)
  6515. {
  6516. loading_flag = false;
  6517. char cmd[30];
  6518. char* c;
  6519. bool result = true;
  6520. sprintf_P(cmd, PSTR("M23 %s"), filename);
  6521. for (c = &cmd[4]; *c; c++)
  6522. *c = tolower(*c);
  6523. const char end[5] = ".gco";
  6524. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  6525. for (uint_least8_t i = 0; i < 8; i++) {
  6526. if (strcmp((cmd + i + 4), end) == 0) {
  6527. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  6528. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  6529. break;
  6530. }
  6531. else {
  6532. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  6533. }
  6534. }
  6535. uint8_t depth = card.getWorkDirDepth();
  6536. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  6537. for (uint_least8_t i = 0; i < depth; i++) {
  6538. for (uint_least8_t j = 0; j < 8; j++) {
  6539. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, card.dir_names[i][j]);
  6540. }
  6541. }
  6542. //filename is just a pointer to card.filename, which changes everytime you try to open a file by filename. So you can't use filename directly
  6543. //to open a file. Instead, the cached filename in cmd is used as that one is static for the whole lifetime of this function.
  6544. if (!check_file(cmd + 4)) {
  6545. result = !lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false);////MSG_FILE_INCOMPLETE c=20 r=3
  6546. lcd_update_enable(true);
  6547. }
  6548. if (result) {
  6549. enquecommand(cmd);
  6550. enquecommand_P(PSTR("M24"));
  6551. }
  6552. lcd_return_to_status();
  6553. }
  6554. void menu_action_sddirectory(const char* filename)
  6555. {
  6556. card.chdir(filename, true);
  6557. lcd_encoder = 0;
  6558. menu_data_reset(); //Forces reloading of cached variables.
  6559. }
  6560. /** LCD API **/
  6561. void ultralcd_init()
  6562. {
  6563. backlight_init();
  6564. lcd_init();
  6565. lcd_refresh();
  6566. lcd_longpress_func = menu_lcd_longpress_func;
  6567. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  6568. menu_menu = lcd_status_screen;
  6569. SET_INPUT(BTN_EN1);
  6570. SET_INPUT(BTN_EN2);
  6571. WRITE(BTN_EN1, HIGH);
  6572. WRITE(BTN_EN2, HIGH);
  6573. #if BTN_ENC > 0
  6574. SET_INPUT(BTN_ENC);
  6575. WRITE(BTN_ENC, HIGH);
  6576. #endif
  6577. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  6578. SET_INPUT(SDCARDDETECT);
  6579. WRITE(SDCARDDETECT, HIGH);
  6580. _delay_ms(1); //wait for the pullups to raise the line
  6581. lcd_oldcardstatus = IS_SD_INSERTED;
  6582. #endif//(SDCARDDETECT > 0)
  6583. lcd_encoder_diff = 0;
  6584. // Initialise status line
  6585. strncpy_P(lcd_status_message, MSG_WELCOME, LCD_WIDTH);
  6586. }
  6587. void lcd_ignore_click(bool b)
  6588. {
  6589. ignore_click = b;
  6590. wait_for_unclick = false;
  6591. }
  6592. static bool lcd_message_check(uint8_t priority)
  6593. {
  6594. // regular priority check
  6595. if (priority >= lcd_status_message_level)
  6596. return true;
  6597. // check if we can override an info message yet
  6598. if (lcd_status_message_level == LCD_STATUS_INFO) {
  6599. return lcd_status_message_timeout.expired_cont(LCD_STATUS_INFO_TIMEOUT);
  6600. }
  6601. return false;
  6602. }
  6603. static void lcd_updatestatus(const char *message, bool progmem = false)
  6604. {
  6605. if (progmem)
  6606. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6607. else
  6608. strncpy(lcd_status_message, message, LCD_WIDTH);
  6609. lcd_status_message[LCD_WIDTH] = 0;
  6610. SERIAL_PROTOCOLLNRPGM(MSG_LCD_STATUS_CHANGED);
  6611. // hack lcd_draw_update to 1, i.e. without clear
  6612. lcd_draw_update = 1;
  6613. }
  6614. void lcd_setstatus(const char* message)
  6615. {
  6616. if (lcd_message_check(LCD_STATUS_NONE))
  6617. lcd_updatestatus(message);
  6618. }
  6619. void lcd_setstatuspgm(const char* message)
  6620. {
  6621. if (lcd_message_check(LCD_STATUS_NONE))
  6622. lcd_updatestatus(message, true);
  6623. }
  6624. void lcd_setstatus_serial(const char* message)
  6625. {
  6626. if (lcd_message_check(LCD_STATUS_NONE))
  6627. lcd_updatestatus(message);
  6628. SERIAL_ECHOLN(message);
  6629. }
  6630. void lcd_setalertstatus_(const char* message, uint8_t severity, bool progmem)
  6631. {
  6632. if (lcd_message_check(severity)) {
  6633. bool same = !(progmem?
  6634. strcmp_P(lcd_status_message, message):
  6635. strcmp(lcd_status_message, message));
  6636. lcd_updatestatus(message, progmem);
  6637. lcd_status_message_timeout.start();
  6638. lcd_status_message_level = severity;
  6639. custom_message_type = CustomMsg::Status;
  6640. custom_message_state = 0;
  6641. if (!same) {
  6642. // do not kick the user out of the menus if the message is unchanged
  6643. lcd_return_to_status();
  6644. }
  6645. }
  6646. }
  6647. void lcd_setalertstatus(const char* message, uint8_t severity)
  6648. {
  6649. lcd_setalertstatus_(message, severity, false);
  6650. }
  6651. void lcd_setalertstatuspgm(const char* message, uint8_t severity)
  6652. {
  6653. lcd_setalertstatus_(message, severity, true);
  6654. }
  6655. void lcd_reset_alert_level()
  6656. {
  6657. lcd_status_message_level = 0;
  6658. }
  6659. uint8_t get_message_level()
  6660. {
  6661. return lcd_status_message_level;
  6662. }
  6663. void menu_lcd_longpress_func(void)
  6664. {
  6665. // Wake up the LCD backlight and,
  6666. // start LCD inactivity timer
  6667. lcd_timeoutToStatus.start();
  6668. backlight_wake();
  6669. if (homing_flag || mesh_bed_leveling_flag || menu_menu == lcd_babystep_z || menu_menu == lcd_move_z || menu_block_mask != MENU_BLOCK_NONE)
  6670. {
  6671. // disable longpress during re-entry, while homing, calibration or if a serious error
  6672. lcd_quick_feedback();
  6673. return;
  6674. }
  6675. if (menu_menu == lcd_hw_setup_menu)
  6676. {
  6677. // only toggle the experimental menu visibility flag
  6678. lcd_quick_feedback();
  6679. eeprom_toggle((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  6680. return;
  6681. }
  6682. // explicitely listed menus which are allowed to rise the move-z or live-adj-z functions
  6683. // The lists are not the same for both functions, so first decide which function is to be performed
  6684. if ( (moves_planned() || IS_SD_PRINTING || usb_timer.running() )){ // long press as live-adj-z
  6685. if (( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height
  6686. && ( menu_menu == lcd_status_screen // and in listed menus...
  6687. || menu_menu == lcd_main_menu
  6688. || menu_menu == lcd_tune_menu
  6689. || menu_menu == lcd_support_menu
  6690. )
  6691. ){
  6692. lcd_clear();
  6693. menu_submenu(lcd_babystep_z);
  6694. } else {
  6695. lcd_quick_feedback();
  6696. }
  6697. } else { // long press as move-z
  6698. if (menu_menu == lcd_status_screen
  6699. || menu_menu == lcd_main_menu
  6700. || menu_menu == lcd_preheat_menu
  6701. || menu_menu == lcd_sdcard_menu
  6702. || menu_menu == lcd_settings_menu
  6703. || menu_menu == lcd_control_temperature_menu
  6704. #if (LANG_MODE != 0)
  6705. || menu_menu == lcd_language
  6706. #endif
  6707. || menu_menu == lcd_support_menu
  6708. ){
  6709. menu_submenu(lcd_move_z);
  6710. } else {
  6711. lcd_quick_feedback();
  6712. }
  6713. }
  6714. }
  6715. static inline bool z_menu_expired()
  6716. {
  6717. return (menu_menu == lcd_babystep_z
  6718. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  6719. }
  6720. static inline bool other_menu_expired()
  6721. {
  6722. return (menu_menu != lcd_status_screen
  6723. && menu_menu != lcd_babystep_z
  6724. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  6725. }
  6726. void menu_lcd_lcdupdate_func(void)
  6727. {
  6728. #if (SDCARDDETECT > 0)
  6729. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  6730. {
  6731. if(menu_menu == lcd_sdcard_menu) {
  6732. // If the user is either inside the submenus
  6733. // 1. 'Print from SD' --> and SD card is removed
  6734. // 2. 'No SD card' --> and SD card is inserted
  6735. //
  6736. // 1. 'Print from SD': We want to back out of this submenu
  6737. // and instead show the submenu title 'No SD card'.
  6738. //
  6739. // 2. 'No SD card': When the user inserts the SD card we want
  6740. // to back out of this submenu. Not only to show
  6741. // 'Print from SD' submenu title but also because the user
  6742. // will be prompted with another menu with the sorted list of files.
  6743. // Without backing out of the menu, the list will appear empty and
  6744. // The user will need to back out of two nested submenus.
  6745. menu_back();
  6746. }
  6747. lcd_draw_update = 2;
  6748. lcd_oldcardstatus = IS_SD_INSERTED;
  6749. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  6750. backlight_wake();
  6751. if (lcd_oldcardstatus)
  6752. {
  6753. if (!card.cardOK)
  6754. {
  6755. card.initsd(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back()
  6756. card.presort_flag = true; //force sorting of the SD menu
  6757. }
  6758. LCD_MESSAGERPGM(MSG_WELCOME);
  6759. bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  6760. menu_submenu(lcd_sdcard_menu);
  6761. lcd_timeoutToStatus.start();
  6762. }
  6763. else
  6764. {
  6765. card.release();
  6766. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=20
  6767. }
  6768. }
  6769. #endif//CARDINSERTED
  6770. backlight_update();
  6771. if (lcd_next_update_millis < _millis())
  6772. {
  6773. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  6774. {
  6775. if (lcd_draw_update == 0)
  6776. lcd_draw_update = 1;
  6777. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  6778. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  6779. lcd_encoder_diff = 0;
  6780. lcd_timeoutToStatus.start();
  6781. backlight_wake();
  6782. }
  6783. if (LCD_CLICKED)
  6784. {
  6785. lcd_timeoutToStatus.start();
  6786. backlight_wake();
  6787. }
  6788. (*menu_menu)();
  6789. if (z_menu_expired() || other_menu_expired())
  6790. {
  6791. // Exiting a menu. Let's call the menu function the last time with menu_leaving flag set to true
  6792. // to give it a chance to save its state.
  6793. // This is useful for example, when the babystep value has to be written into EEPROM.
  6794. if (menu_menu != NULL)
  6795. {
  6796. menu_leaving = 1;
  6797. (*menu_menu)();
  6798. menu_leaving = 0;
  6799. }
  6800. lcd_clear();
  6801. lcd_return_to_status();
  6802. lcd_draw_update = 2;
  6803. }
  6804. if (lcd_draw_update == 2) lcd_clear();
  6805. if (lcd_draw_update) lcd_draw_update--;
  6806. lcd_next_update_millis = _millis() + LCD_UPDATE_INTERVAL;
  6807. }
  6808. prusa_statistics_update_from_lcd_update();
  6809. if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands();
  6810. }
  6811. #ifdef TMC2130
  6812. //! @brief Is crash detection enabled?
  6813. //!
  6814. //! @retval true crash detection enabled
  6815. //! @retval false crash detection disabled
  6816. bool lcd_crash_detect_enabled()
  6817. {
  6818. return eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET);
  6819. }
  6820. void lcd_crash_detect_enable()
  6821. {
  6822. tmc2130_sg_stop_on_crash = true;
  6823. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF);
  6824. }
  6825. void lcd_crash_detect_disable()
  6826. {
  6827. tmc2130_sg_stop_on_crash = false;
  6828. tmc2130_sg_crash = 0;
  6829. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00);
  6830. }
  6831. #endif
  6832. #ifdef TMC2130
  6833. void UserECool_toggle(){
  6834. // this is only called when the experimental menu is visible, thus the first condition for enabling of the ECool mode is met in this place
  6835. // The condition is intentionally inverted as we are toggling the state (i.e. if it was enabled, we are disabling the feature and vice versa)
  6836. bool enable = ! UserECoolEnabled();
  6837. eeprom_update_byte((uint8_t *)EEPROM_ECOOL_ENABLE, enable ? EEPROM_ECOOL_MAGIC_NUMBER : EEPROM_EMPTY_VALUE);
  6838. // @@TODO I don't like this - disabling the experimental menu shall disable ECool mode, but it will not reinit the TMC
  6839. // and I don't want to add more code for this experimental feature ... ideally do not reinit the TMC here at all and let the user reset the printer.
  6840. tmc2130_init(TMCInitParams(enable));
  6841. }
  6842. #endif
  6843. /// Enable experimental support for cooler operation of the extruder motor
  6844. /// Beware - REQUIRES original Prusa MK3/S/+ extruder motor with adequate maximal current
  6845. /// Therefore we don't want to allow general usage of this feature in public as the community likes to
  6846. /// change motors for various reasons and unless the motor is rotating, we cannot verify its properties
  6847. /// (which would be obviously too late for an improperly sized motor)
  6848. /// For farm printing, the cooler E-motor is enabled by default.
  6849. bool UserECoolEnabled(){
  6850. // We enable E-cool mode for non-farm prints IFF the experimental menu is visible AND the EEPROM_ECOOL variable has
  6851. // a value of the universal answer to all problems of the universe
  6852. return ( eeprom_read_byte((uint8_t *)EEPROM_ECOOL_ENABLE) == EEPROM_ECOOL_MAGIC_NUMBER )
  6853. && ( eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY) == 1 );
  6854. }
  6855. bool FarmOrUserECool(){
  6856. return farm_mode || UserECoolEnabled();
  6857. }
  6858. #ifdef PRUSA_SN_SUPPORT
  6859. void WorkaroundPrusaSN() {
  6860. const char *SN = PSTR("CZPXInvalidSerialNr");
  6861. for (uint8_t i = 0; i < 20; i++) {
  6862. eeprom_update_byte((uint8_t*)EEPROM_PRUSA_SN + i, pgm_read_byte(SN++));
  6863. }
  6864. }
  6865. #endif //PRUSA_SN_SUPPORT
  6866. void lcd_experimental_menu()
  6867. {
  6868. MENU_BEGIN();
  6869. MENU_ITEM_BACK_P(_T(MSG_BACK));
  6870. #ifdef EXTRUDER_ALTFAN_DETECT
  6871. MENU_ITEM_TOGGLE_P(_N("ALTFAN det."), altfanOverride_get()?_T(MSG_OFF):_T(MSG_ON), altfanOverride_toggle);////MSG_MENU_ALTFAN c=18
  6872. #endif //EXTRUDER_ALTFAN_DETECT
  6873. #ifdef TMC2130
  6874. MENU_ITEM_TOGGLE_P(_N("E-cool mode"), UserECoolEnabled()?_T(MSG_ON):_T(MSG_OFF), UserECool_toggle);////MSG_MENU_ECOOL c=18
  6875. #endif
  6876. #ifdef DEBUG_PULLUP_CRASH
  6877. MENU_ITEM_FUNCTION_P(_N("Test Pullup Crash"), TestPullupCrash);
  6878. #endif // DEBUG_PULLUP_CRASH
  6879. #ifdef PRUSA_SN_SUPPORT
  6880. MENU_ITEM_FUNCTION_P(_N("Fake serial number"), WorkaroundPrusaSN);////MSG_WORKAROUND_PRUSA_SN c=18
  6881. #endif //PRUSA_SN_SUPPORT
  6882. MENU_END();
  6883. }
  6884. #ifdef PINDA_TEMP_COMP
  6885. void lcd_pinda_temp_compensation_toggle()
  6886. {
  6887. uint8_t pinda_temp_compensation = eeprom_read_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION);
  6888. if (pinda_temp_compensation == EEPROM_EMPTY_VALUE) // On MK2.5/S the EEPROM_EMPTY_VALUE will be set to 0 during eeprom_init.
  6889. pinda_temp_compensation = 1; // But for MK3/S it should be 1 so SuperPINDA is "active"
  6890. else
  6891. pinda_temp_compensation = !pinda_temp_compensation;
  6892. eeprom_update_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION, pinda_temp_compensation);
  6893. SERIAL_ECHOLNPGM("SuperPINDA:");
  6894. SERIAL_ECHOLN(pinda_temp_compensation);
  6895. }
  6896. #endif //PINDA_TEMP_COMP