ultralcd.cpp 240 KB

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