ultralcd.cpp 246 KB

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