ultralcd.cpp 269 KB

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