ultralcd.cpp 252 KB

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