ultralcd.cpp 270 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960
  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. #ifndef MK1BP
  1801. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1802. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=18
  1803. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=18
  1804. MENU_ITEM_SUBMENU_P(_i("Sensor info"), lcd_menu_show_sensors_state);////MSG_INFO_SENSORS c=18
  1805. #ifdef TMC2130
  1806. MENU_ITEM_SUBMENU_P(_T(MSG_BELT_STATUS), lcd_menu_belt_status);////MSG_BELT_STATUS c=18
  1807. #endif //TMC2130
  1808. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=18
  1809. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1810. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=18
  1811. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1812. #ifdef MENU_DUMP
  1813. MENU_ITEM_FUNCTION_P(_i("Dump memory"), lcd_dump_memory);
  1814. #endif //MENU_DUMP
  1815. #ifdef MENU_SERIAL_DUMP
  1816. if (emergency_serial_dump)
  1817. MENU_ITEM_FUNCTION_P(_i("Dump to serial"), lcd_serial_dump);
  1818. #endif
  1819. #ifdef DEBUG_BUILD
  1820. #ifdef EMERGENCY_HANDLERS
  1821. #ifdef WATCHDOG
  1822. MENU_ITEM_FUNCTION_P(PSTR("WDR crash"), lcd_wdr_crash);
  1823. #endif //WATCHDOG
  1824. MENU_ITEM_FUNCTION_P(PSTR("Stack crash"), lcd_stack_crash);
  1825. #endif //EMERGENCY_HANDLERS
  1826. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);////MSG_DEBUG c=18
  1827. #endif /* DEBUG_BUILD */
  1828. #endif //MK1BP
  1829. MENU_END();
  1830. }
  1831. void lcd_set_fan_check() {
  1832. fans_check_enabled = !fans_check_enabled;
  1833. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1834. #ifdef FANCHECK
  1835. if (fans_check_enabled == false) fan_check_error = EFCE_OK; //reset error if fanCheck is disabled during error. Allows resuming print.
  1836. #endif //FANCHECK
  1837. }
  1838. #ifdef MMU_HAS_CUTTER
  1839. void lcd_cutter_enabled()
  1840. {
  1841. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1842. {
  1843. #ifndef MMU_ALWAYS_CUT
  1844. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1845. }
  1846. #else //MMU_ALWAYS_CUT
  1847. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_always);
  1848. }
  1849. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1850. {
  1851. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1852. }
  1853. #endif //MMU_ALWAYS_CUT
  1854. else
  1855. {
  1856. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_enabled);
  1857. }
  1858. }
  1859. #endif //MMU_HAS_CUTTER
  1860. void lcd_set_filament_autoload() {
  1861. fsensor_autoload_set(!fsensor_autoload_enabled);
  1862. }
  1863. #if defined(FILAMENT_SENSOR) && defined(PAT9125)
  1864. void lcd_set_filament_oq_meass()
  1865. {
  1866. fsensor_oq_meassure_set(!fsensor_oq_meassure_enabled);
  1867. }
  1868. #endif
  1869. FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad'
  1870. bool bFilamentFirstRun;
  1871. bool bFilamentPreheatState;
  1872. bool bFilamentAction=false;
  1873. static bool bFilamentWaitingFlag=false;
  1874. static void mFilamentPrompt()
  1875. {
  1876. uint8_t nLevel;
  1877. lcd_set_cursor(0,0);
  1878. lcdui_print_temp(LCD_STR_THERMOMETER[0],(int)degHotend(0),(int)degTargetHotend(0));
  1879. lcd_puts_at_P(0,1, _i("Press the knob")); ////MSG_PRESS_KNOB c=20
  1880. lcd_set_cursor(0,2);
  1881. switch(eFilamentAction)
  1882. {
  1883. case FilamentAction::Load:
  1884. case FilamentAction::AutoLoad:
  1885. case FilamentAction::MmuLoad:
  1886. lcd_puts_P(_i("to load filament")); ////MSG_TO_LOAD_FIL c=20
  1887. break;
  1888. case FilamentAction::UnLoad:
  1889. case FilamentAction::MmuUnLoad:
  1890. lcd_puts_P(_i("to unload filament")); ////MSG_TO_UNLOAD_FIL c=20
  1891. break;
  1892. case FilamentAction::MmuEject:
  1893. case FilamentAction::MmuCut:
  1894. case FilamentAction::None:
  1895. case FilamentAction::Preheat:
  1896. case FilamentAction::Lay1Cal:
  1897. break;
  1898. }
  1899. if(lcd_clicked())
  1900. {
  1901. nLevel=2;
  1902. if(!bFilamentPreheatState)
  1903. {
  1904. nLevel++;
  1905. // setTargetHotend0(0.0); // uncoment if return to base-state is required
  1906. }
  1907. menu_back(nLevel);
  1908. switch(eFilamentAction)
  1909. {
  1910. case FilamentAction::AutoLoad:
  1911. eFilamentAction=FilamentAction::None; // i.e. non-autoLoad
  1912. // FALLTHRU
  1913. case FilamentAction::Load:
  1914. loading_flag=true;
  1915. enquecommand_P(PSTR("M701")); // load filament
  1916. break;
  1917. case FilamentAction::UnLoad:
  1918. enquecommand_P(PSTR("M702")); // unload filament
  1919. break;
  1920. case FilamentAction::MmuLoad:
  1921. case FilamentAction::MmuUnLoad:
  1922. case FilamentAction::MmuEject:
  1923. case FilamentAction::MmuCut:
  1924. case FilamentAction::None:
  1925. case FilamentAction::Preheat:
  1926. case FilamentAction::Lay1Cal:
  1927. break;
  1928. }
  1929. }
  1930. }
  1931. void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
  1932. {
  1933. static int nTargetOld;
  1934. static int nTargetBedOld;
  1935. uint8_t nLevel;
  1936. nTargetOld = target_temperature[0];
  1937. nTargetBedOld = target_temperature_bed;
  1938. setTargetHotend0((float )nTemp);
  1939. setTargetBed((float) nTempBed);
  1940. {
  1941. const FilamentAction action = eFilamentAction;
  1942. if (action == FilamentAction::Preheat || action == FilamentAction::Lay1Cal)
  1943. {
  1944. lcd_return_to_status();
  1945. if (action == FilamentAction::Lay1Cal)
  1946. {
  1947. lcd_commands_type = LcdCommands::Layer1Cal;
  1948. }
  1949. else
  1950. {
  1951. raise_z_above(MIN_Z_FOR_PREHEAT);
  1952. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1953. lcd_wizard(WizState::LoadFilHot);
  1954. }
  1955. return;
  1956. }
  1957. }
  1958. lcd_timeoutToStatus.stop();
  1959. if (current_temperature[0] > (target_temperature[0] * 0.95))
  1960. {
  1961. switch (eFilamentAction)
  1962. {
  1963. case FilamentAction::Load:
  1964. case FilamentAction::AutoLoad:
  1965. case FilamentAction::UnLoad:
  1966. if (bFilamentWaitingFlag) menu_submenu(mFilamentPrompt);
  1967. else
  1968. {
  1969. nLevel = bFilamentPreheatState ? 1 : 2;
  1970. menu_back(nLevel);
  1971. if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad))
  1972. {
  1973. loading_flag = true;
  1974. enquecommand_P(PSTR("M701")); // load filament
  1975. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1976. }
  1977. if (eFilamentAction == FilamentAction::UnLoad)
  1978. enquecommand_P(PSTR("M702")); // unload filament
  1979. }
  1980. break;
  1981. case FilamentAction::MmuLoad:
  1982. nLevel = bFilamentPreheatState ? 1 : 2;
  1983. bFilamentAction = true;
  1984. menu_back(nLevel);
  1985. menu_submenu(mmu_load_to_nozzle_menu);
  1986. break;
  1987. case FilamentAction::MmuUnLoad:
  1988. nLevel = bFilamentPreheatState ? 1 : 2;
  1989. bFilamentAction = true;
  1990. menu_back(nLevel);
  1991. extr_unload();
  1992. break;
  1993. case FilamentAction::MmuEject:
  1994. nLevel = bFilamentPreheatState ? 1 : 2;
  1995. bFilamentAction = true;
  1996. menu_back(nLevel);
  1997. menu_submenu(mmu_fil_eject_menu);
  1998. break;
  1999. case FilamentAction::MmuCut:
  2000. #ifdef MMU_HAS_CUTTER
  2001. nLevel=bFilamentPreheatState?1:2;
  2002. bFilamentAction=true;
  2003. menu_back(nLevel);
  2004. menu_submenu(mmu_cut_filament_menu);
  2005. #endif //MMU_HAS_CUTTER
  2006. break;
  2007. case FilamentAction::None:
  2008. case FilamentAction::Preheat:
  2009. case FilamentAction::Lay1Cal:
  2010. // handled earlier
  2011. break;
  2012. }
  2013. if (bFilamentWaitingFlag) Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  2014. bFilamentWaitingFlag = false;
  2015. }
  2016. else
  2017. {
  2018. if (!bFilamentWaitingFlag || lcd_draw_update)
  2019. {
  2020. // First entry from another menu OR first run after the filament preheat selection. Use
  2021. // bFilamentWaitingFlag to distinguish: this flag is reset exactly once when entering
  2022. // the menu and is used to raise the carriage *once*. In other cases, the LCD has been
  2023. // modified elsewhere and needs to be redrawn in full.
  2024. // reset bFilamentWaitingFlag immediately to avoid re-entry from raise_z_above()!
  2025. bool once = !bFilamentWaitingFlag;
  2026. bFilamentWaitingFlag = true;
  2027. // also force-enable lcd_draw_update (might be 0 when called from outside a menu)
  2028. lcd_draw_update = 1;
  2029. lcd_clear();
  2030. lcd_puts_at_P(0, 3, _T(MSG_CANCEL)); ////MSG_CANCEL
  2031. lcd_set_cursor(0, 1);
  2032. switch (eFilamentAction)
  2033. {
  2034. case FilamentAction::Load:
  2035. case FilamentAction::AutoLoad:
  2036. case FilamentAction::MmuLoad:
  2037. lcd_puts_P(_i("Preheating to load")); ////MSG_PREHEATING_TO_LOAD c=20
  2038. if (once) raise_z_above(MIN_Z_FOR_LOAD);
  2039. break;
  2040. case FilamentAction::UnLoad:
  2041. case FilamentAction::MmuUnLoad:
  2042. lcd_puts_P(_i("Preheating to unload")); ////MSG_PREHEATING_TO_UNLOAD c=20
  2043. if (once) raise_z_above(MIN_Z_FOR_UNLOAD);
  2044. break;
  2045. case FilamentAction::MmuEject:
  2046. lcd_puts_P(_i("Preheating to eject")); ////MSG_PREHEATING_TO_EJECT c=20
  2047. break;
  2048. case FilamentAction::MmuCut:
  2049. lcd_puts_P(_i("Preheating to cut")); ////MSG_PREHEATING_TO_CUT c=20
  2050. break;
  2051. case FilamentAction::None:
  2052. case FilamentAction::Preheat:
  2053. case FilamentAction::Lay1Cal:
  2054. // handled earlier
  2055. break;
  2056. }
  2057. }
  2058. if (bFilamentWaitingFlag) {
  2059. lcd_set_cursor(0, 0);
  2060. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int) degHotend(0), (int) degTargetHotend(0));
  2061. }
  2062. if (lcd_clicked())
  2063. {
  2064. bFilamentWaitingFlag = false;
  2065. if (!bFilamentPreheatState)
  2066. {
  2067. setTargetHotend0(0.0);
  2068. setTargetBed(0.0);
  2069. menu_back();
  2070. }
  2071. else
  2072. {
  2073. setTargetHotend0((float )nTargetOld);
  2074. setTargetBed((float) nTargetBedOld);
  2075. }
  2076. menu_back();
  2077. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  2078. }
  2079. }
  2080. }
  2081. static void mFilamentItem_farm()
  2082. {
  2083. bFilamentPreheatState = false;
  2084. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, FARM_PREHEAT_HPB_TEMP);
  2085. }
  2086. static void mFilamentItem_farm_nozzle()
  2087. {
  2088. bFilamentPreheatState = false;
  2089. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, 0);
  2090. }
  2091. static void mFilamentItem_PLA()
  2092. {
  2093. bFilamentPreheatState = false;
  2094. mFilamentItem(PLA_PREHEAT_HOTEND_TEMP, PLA_PREHEAT_HPB_TEMP);
  2095. }
  2096. static void mFilamentItem_PET()
  2097. {
  2098. bFilamentPreheatState = false;
  2099. mFilamentItem(PET_PREHEAT_HOTEND_TEMP, PET_PREHEAT_HPB_TEMP);
  2100. }
  2101. static void mFilamentItem_ASA()
  2102. {
  2103. bFilamentPreheatState = false;
  2104. mFilamentItem(ASA_PREHEAT_HOTEND_TEMP, ASA_PREHEAT_HPB_TEMP);
  2105. }
  2106. static void mFilamentItem_PC()
  2107. {
  2108. bFilamentPreheatState = false;
  2109. mFilamentItem(PC_PREHEAT_HOTEND_TEMP, PC_PREHEAT_HPB_TEMP);
  2110. }
  2111. static void mFilamentItem_ABS()
  2112. {
  2113. bFilamentPreheatState = false;
  2114. mFilamentItem(ABS_PREHEAT_HOTEND_TEMP, ABS_PREHEAT_HPB_TEMP);
  2115. }
  2116. static void mFilamentItem_HIPS()
  2117. {
  2118. bFilamentPreheatState = false;
  2119. mFilamentItem(HIPS_PREHEAT_HOTEND_TEMP, HIPS_PREHEAT_HPB_TEMP);
  2120. }
  2121. static void mFilamentItem_PP()
  2122. {
  2123. bFilamentPreheatState = false;
  2124. mFilamentItem(PP_PREHEAT_HOTEND_TEMP, PP_PREHEAT_HPB_TEMP);
  2125. }
  2126. static void mFilamentItem_FLEX()
  2127. {
  2128. bFilamentPreheatState = false;
  2129. mFilamentItem(FLEX_PREHEAT_HOTEND_TEMP, FLEX_PREHEAT_HPB_TEMP);
  2130. }
  2131. static void mFilamentItem_PVB()
  2132. {
  2133. bFilamentPreheatState = false;
  2134. mFilamentItem(PVB_PREHEAT_HOTEND_TEMP, PVB_PREHEAT_HPB_TEMP);
  2135. }
  2136. void mFilamentBack()
  2137. {
  2138. if (eFilamentAction == FilamentAction::AutoLoad ||
  2139. eFilamentAction == FilamentAction::Preheat ||
  2140. eFilamentAction == FilamentAction::Lay1Cal)
  2141. {
  2142. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  2143. }
  2144. }
  2145. void lcd_generic_preheat_menu()
  2146. {
  2147. MENU_BEGIN();
  2148. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  2149. {
  2150. ON_MENU_LEAVE(
  2151. mFilamentBack();
  2152. );
  2153. if (eFilamentAction == FilamentAction::Lay1Cal)
  2154. {
  2155. MENU_ITEM_BACK_P(_T(MSG_BACK));
  2156. }
  2157. else
  2158. {
  2159. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  2160. }
  2161. }
  2162. if (farm_mode)
  2163. {
  2164. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), mFilamentItem_farm);
  2165. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), mFilamentItem_farm_nozzle);
  2166. }
  2167. else
  2168. {
  2169. MENU_ITEM_SUBMENU_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)),mFilamentItem_PLA);
  2170. MENU_ITEM_SUBMENU_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)),mFilamentItem_PET);
  2171. MENU_ITEM_SUBMENU_P(PSTR("ASA - " STRINGIFY(ASA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ASA_PREHEAT_HPB_TEMP)),mFilamentItem_ASA);
  2172. MENU_ITEM_SUBMENU_P(PSTR("PC - " STRINGIFY(PC_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PC_PREHEAT_HPB_TEMP)),mFilamentItem_PC);
  2173. MENU_ITEM_SUBMENU_P(PSTR("PVB - " STRINGIFY(PVB_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PVB_PREHEAT_HPB_TEMP)),mFilamentItem_PVB);
  2174. MENU_ITEM_SUBMENU_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)),mFilamentItem_ABS);
  2175. MENU_ITEM_SUBMENU_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)),mFilamentItem_HIPS);
  2176. MENU_ITEM_SUBMENU_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)),mFilamentItem_PP);
  2177. MENU_ITEM_SUBMENU_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)),mFilamentItem_FLEX);
  2178. }
  2179. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) && eFilamentAction == FilamentAction::Preheat) MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  2180. MENU_END();
  2181. }
  2182. void mFilamentItemForce()
  2183. {
  2184. mFilamentItem(target_temperature[0],target_temperature_bed);
  2185. }
  2186. void lcd_unLoadFilament()
  2187. {
  2188. eFilamentAction=FilamentAction::UnLoad;
  2189. preheat_or_continue();
  2190. }
  2191. static void mmu_unload_filament()
  2192. {
  2193. eFilamentAction = FilamentAction::MmuUnLoad;
  2194. preheat_or_continue();
  2195. }
  2196. void lcd_wait_interact() {
  2197. lcd_clear();
  2198. lcd_set_cursor(0, 1);
  2199. #ifdef SNMM
  2200. lcd_puts_P(_i("Prepare new filament"));////MSG_PREPARE_FILAMENT c=20
  2201. #else
  2202. lcd_puts_P(_i("Insert filament"));////MSG_INSERT_FILAMENT c=20
  2203. #endif
  2204. if (!fsensor_autoload_enabled) {
  2205. lcd_puts_at_P(0, 2, _i("and press the knob"));////MSG_PRESS c=20 r=2
  2206. }
  2207. }
  2208. void lcd_change_success() {
  2209. lcd_clear();
  2210. lcd_puts_at_P(0, 2, _i("Change success!"));////MSG_CHANGE_SUCCESS c=20
  2211. }
  2212. static void lcd_loading_progress_bar(uint16_t loading_time_ms) {
  2213. for (uint_least8_t i = 0; i < LCD_WIDTH; i++) {
  2214. lcd_putc_at(i, 3, '.');
  2215. //loading_time_ms/20 delay
  2216. for (uint_least8_t j = 0; j < 5; j++) {
  2217. delay_keep_alive(loading_time_ms / 100);
  2218. }
  2219. }
  2220. }
  2221. void lcd_loading_color() {
  2222. //we are extruding 25mm with feedrate 200mm/min -> 7.5 seconds for whole action, 0.375 s for one character
  2223. lcd_clear();
  2224. lcd_puts_at_P(0, 0, _i("Loading color"));////MSG_LOADING_COLOR c=20
  2225. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2226. lcd_loading_progress_bar((FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL); //show progress bar during filament loading slow sequence
  2227. }
  2228. void lcd_loading_filament() {
  2229. lcd_clear();
  2230. lcd_puts_at_P(0, 0, _T(MSG_LOADING_FILAMENT));
  2231. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2232. #ifdef SNMM
  2233. for (int i = 0; i < 20; i++) {
  2234. lcd_set_cursor(i, 3);
  2235. lcd_print('.');
  2236. for (int j = 0; j < 10 ; j++) {
  2237. manage_heater();
  2238. manage_inactivity(true);
  2239. _delay(153);
  2240. }
  2241. }
  2242. #else //SNMM
  2243. uint16_t slow_seq_time = (FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL;
  2244. uint16_t fast_seq_time = (FILAMENTCHANGE_FIRSTFEED * 1000ul) / FILAMENTCHANGE_EFEED_FIRST;
  2245. lcd_loading_progress_bar(slow_seq_time + fast_seq_time); //show progress bar for total time of filament loading fast + slow sequence
  2246. #endif //SNMM
  2247. }
  2248. void lcd_alright() {
  2249. int enc_dif = 0;
  2250. int cursor_pos = 1;
  2251. lcd_clear();
  2252. lcd_puts_at_P(0, 0, _i("Changed correctly?"));////MSG_CORRECTLY c=20
  2253. lcd_puts_at_P(1, 1, _T(MSG_YES));
  2254. lcd_puts_at_P(1, 2, _i("Filament not loaded"));////MSG_NOT_LOADED c=19
  2255. lcd_puts_at_P(1, 3, _i("Color not correct"));////MSG_NOT_COLOR c=19
  2256. lcd_putc_at(0, 1, '>');
  2257. enc_dif = lcd_encoder_diff;
  2258. lcd_consume_click();
  2259. while (lcd_change_fil_state == 0) {
  2260. manage_heater();
  2261. manage_inactivity(true);
  2262. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2263. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2264. if (enc_dif > lcd_encoder_diff ) {
  2265. cursor_pos --;
  2266. }
  2267. if (enc_dif < lcd_encoder_diff ) {
  2268. cursor_pos ++;
  2269. }
  2270. if (cursor_pos > 3) {
  2271. cursor_pos = 3;
  2272. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2273. }
  2274. if (cursor_pos < 1) {
  2275. cursor_pos = 1;
  2276. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2277. }
  2278. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  2279. lcd_putc_at(0, cursor_pos, '>');
  2280. enc_dif = lcd_encoder_diff;
  2281. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  2282. _delay(100);
  2283. }
  2284. }
  2285. if (lcd_clicked()) {
  2286. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  2287. lcd_change_fil_state = cursor_pos;
  2288. _delay(500);
  2289. }
  2290. };
  2291. lcd_clear();
  2292. lcd_return_to_status();
  2293. }
  2294. void show_preheat_nozzle_warning()
  2295. {
  2296. lcd_clear();
  2297. lcd_puts_at_P(0, 0, _T(MSG_ERROR));
  2298. lcd_puts_at_P(0, 2, _T(MSG_PREHEAT_NOZZLE));
  2299. _delay(2000);
  2300. lcd_clear();
  2301. }
  2302. void lcd_load_filament_color_check()
  2303. {
  2304. bool clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, true);
  2305. while (!clean) {
  2306. lcd_update_enable(true);
  2307. lcd_update(2);
  2308. load_filament_final_feed();
  2309. st_synchronize();
  2310. clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, true);
  2311. }
  2312. }
  2313. #ifdef FILAMENT_SENSOR
  2314. static void lcd_menu_AutoLoadFilament()
  2315. {
  2316. uint8_t nlines;
  2317. 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
  2318. menu_back_if_clicked();
  2319. }
  2320. #endif //FILAMENT_SENSOR
  2321. static void preheat_or_continue()
  2322. {
  2323. bFilamentFirstRun = false;
  2324. if (target_temperature[0] >= EXTRUDE_MINTEMP)
  2325. {
  2326. bFilamentPreheatState = true;
  2327. mFilamentItem(target_temperature[0], target_temperature_bed);
  2328. }
  2329. else lcd_generic_preheat_menu();
  2330. }
  2331. static void lcd_LoadFilament()
  2332. {
  2333. eFilamentAction = FilamentAction::Load;
  2334. preheat_or_continue();
  2335. }
  2336. //! @brief Show filament used a print time
  2337. //!
  2338. //! If printing current print statistics are shown
  2339. //!
  2340. //! @code{.unparsed}
  2341. //! |01234567890123456789|
  2342. //! |Filament used: | MSG_FILAMENT_USED c=19
  2343. //! | 0000.00m |
  2344. //! |Print time: | MSG_PRINT_TIME c=19
  2345. //! | 00h 00m 00s |
  2346. //! ----------------------
  2347. //! @endcode
  2348. //!
  2349. //! If not printing, total statistics are shown
  2350. //!
  2351. //! @code{.unparsed}
  2352. //! |01234567890123456789|
  2353. //! |Total filament: | MSG_TOTAL_FILAMENT c=19
  2354. //! | 0000.00m |
  2355. //! |Total print time: | MSG_TOTAL_PRINT_TIME c=19
  2356. //! | 00d 00h 00m |
  2357. //! ----------------------
  2358. //! @endcode
  2359. //! @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".
  2360. void lcd_menu_statistics()
  2361. {
  2362. lcd_timeoutToStatus.stop(); //infinite timeout
  2363. if (IS_SD_PRINTING)
  2364. {
  2365. const float _met = ((float)total_filament_used) / (100000.f);
  2366. const uint32_t _t = (_millis() - starttime) / 1000ul;
  2367. const uint32_t _h = _t / 3600;
  2368. const uint8_t _m = (_t - (_h * 3600ul)) / 60ul;
  2369. const uint8_t _s = _t - ((_h * 3600ul) + (_m * 60ul));
  2370. lcd_home();
  2371. lcd_printf_P(_N(
  2372. "%S:\n"
  2373. "%18.2fm \n"
  2374. "%S:\n"
  2375. "%10ldh %02dm %02ds"
  2376. ),
  2377. _i("Filament used"), _met, ////MSG_FILAMENT_USED c=19
  2378. _i("Print time"), _h, _m, _s); ////MSG_PRINT_TIME c=19
  2379. menu_back_if_clicked_fb();
  2380. }
  2381. else
  2382. {
  2383. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2384. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2385. uint8_t _hours, _minutes;
  2386. uint32_t _days;
  2387. float _filament_m = (float)_filament/100;
  2388. _days = _time / 1440;
  2389. _hours = (_time - (_days * 1440)) / 60;
  2390. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2391. lcd_home();
  2392. lcd_printf_P(_N(
  2393. "%S:\n"
  2394. "%18.2fm \n"
  2395. "%S:\n"
  2396. "%10ldd %02dh %02dm"
  2397. ),
  2398. _i("Total filament"), _filament_m, ////MSG_TOTAL_FILAMENT c=19
  2399. _i("Total print time"), _days, _hours, _minutes); ////MSG_TOTAL_PRINT_TIME c=19
  2400. menu_back_if_clicked_fb();
  2401. }
  2402. }
  2403. static void _lcd_move(const char *name, uint8_t axis, int min, int max)
  2404. {
  2405. if (homing_flag || mesh_bed_leveling_flag)
  2406. {
  2407. // printer entered a new state where axis move is forbidden
  2408. menu_back();
  2409. return;
  2410. }
  2411. typedef struct
  2412. { // 2bytes total
  2413. bool initialized; // 1byte
  2414. bool endstopsEnabledPrevious; // 1byte
  2415. } _menu_data_t;
  2416. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2417. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2418. if (!_md->initialized)
  2419. {
  2420. _md->endstopsEnabledPrevious = enable_endstops(false);
  2421. _md->initialized = true;
  2422. }
  2423. if (lcd_encoder != 0)
  2424. {
  2425. refresh_cmd_timeout();
  2426. if (! planner_queue_full())
  2427. {
  2428. current_position[axis] += float((int)lcd_encoder);
  2429. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2430. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2431. lcd_encoder = 0;
  2432. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2433. plan_buffer_line_curposXYZE(manual_feedrate[axis] / 60);
  2434. lcd_draw_update = 1;
  2435. }
  2436. }
  2437. if (lcd_draw_update)
  2438. {
  2439. lcd_set_cursor(0, 1);
  2440. menu_draw_float31(name, current_position[axis]);
  2441. }
  2442. if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious);
  2443. if (LCD_CLICKED) menu_back();
  2444. }
  2445. void lcd_move_e()
  2446. {
  2447. if (degHotend0() > EXTRUDE_MINTEMP)
  2448. {
  2449. if (lcd_encoder != 0)
  2450. {
  2451. refresh_cmd_timeout();
  2452. if (! planner_queue_full())
  2453. {
  2454. current_position[E_AXIS] += float((int)lcd_encoder);
  2455. lcd_encoder = 0;
  2456. plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60);
  2457. lcd_draw_update = 1;
  2458. }
  2459. }
  2460. if (lcd_draw_update)
  2461. {
  2462. lcd_set_cursor(0, 1);
  2463. // Note: the colon behind the text is necessary to greatly shorten
  2464. // the implementation of menu_draw_float31
  2465. menu_draw_float31(PSTR("Extruder:"), current_position[E_AXIS]);
  2466. }
  2467. if (LCD_CLICKED) menu_back();
  2468. }
  2469. else
  2470. {
  2471. show_preheat_nozzle_warning();
  2472. lcd_return_to_status();
  2473. }
  2474. }
  2475. //! @brief Show measured Y distance of front calibration points from Y_MIN_POS
  2476. //! If those points are detected too close to edge of reachable area, their confidence is lowered.
  2477. //! This functionality is applied more often for MK2 printers.
  2478. //! @code{.unparsed}
  2479. //! |01234567890123456789|
  2480. //! |Y distance from min | MSG_Y_DIST_FROM_MIN
  2481. //! | -------------- | STR_SEPARATOR
  2482. //! |Left: 00.00mm| MSG_LEFT c=10, c=8
  2483. //! |Right: 00.00mm| MSG_RIGHT c=10, c=8
  2484. //! ----------------------
  2485. //! @endcode
  2486. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2487. static void lcd_menu_xyz_y_min()
  2488. {
  2489. float distanceMin[2];
  2490. count_xyz_details(distanceMin);
  2491. lcd_home();
  2492. lcd_printf_P(_N(
  2493. "%S\n"
  2494. "%S\n"
  2495. "%S:\n"
  2496. "%S:"
  2497. ),
  2498. _i("Y distance from min"), ////MSG_Y_DIST_FROM_MIN c=20
  2499. separator,
  2500. _i("Left"), ////MSG_LEFT c=10
  2501. _i("Right") ////MSG_RIGHT c=10
  2502. );
  2503. for (uint8_t i = 0; i < 2; i++)
  2504. {
  2505. lcd_set_cursor(11,2+i);
  2506. if (distanceMin[i] >= 200) lcd_puts_P(_T(MSG_NA));
  2507. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2508. }
  2509. if (lcd_clicked())
  2510. menu_goto(lcd_menu_xyz_skew, 0, true, true);
  2511. }
  2512. //@brief Show measured axis skewness
  2513. float _deg(float rad)
  2514. {
  2515. return rad * 180 / M_PI;
  2516. }
  2517. //! @brief Show Measured XYZ Skew
  2518. //!
  2519. //! @code{.unparsed}
  2520. //! |01234567890123456789|
  2521. //! |Measured skew :0.00D| MSG_MEASURED_SKEW c=14, c=4
  2522. //! | -------------- | STR_SEPARATOR
  2523. //! |Slight skew :0.12D| MSG_SLIGHT_SKEW c=14, c=4
  2524. //! |Severe skew :0.25D| MSG_SEVERE_SKEW c=14, c=4
  2525. //! ----------------------
  2526. //! D - Degree sysmbol LCD_STR_DEGREE
  2527. //! @endcode
  2528. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2529. static void lcd_menu_xyz_skew()
  2530. {
  2531. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2532. lcd_home();
  2533. lcd_printf_P(_N(
  2534. "%-14.14S:\n"
  2535. "%S\n"
  2536. "%-14.14S:%3.2f\x01\n"
  2537. "%-14.14S:%3.2f\x01"
  2538. ),
  2539. _i("Measured skew"), ////MSG_MEASURED_SKEW c=14
  2540. separator,
  2541. _i("Slight skew"), _deg(bed_skew_angle_mild), ////MSG_SLIGHT_SKEW c=14, c=4
  2542. _i("Severe skew"), _deg(bed_skew_angle_extreme) ////MSG_SEVERE_SKEW c=14, c=4
  2543. );
  2544. if (angleDiff < 100){
  2545. lcd_set_cursor(15,0);
  2546. lcd_printf_P(_N("%3.2f\x01"), _deg(angleDiff));
  2547. }
  2548. else{
  2549. lcd_puts_at_P(15,0, _T(MSG_NA));
  2550. }
  2551. if (lcd_clicked())
  2552. menu_goto(lcd_menu_xyz_offset, 0, true, true);
  2553. }
  2554. //! @brief Show measured bed offset from expected position
  2555. //!
  2556. //! @code{.unparsed}
  2557. //! |01234567890123456789|
  2558. //! |[0;0] point offset | MSG_MEASURED_OFFSET c=20
  2559. //! | -------------- | STR_SEPARATOR
  2560. //! |X 00.00mm| c=10
  2561. //! |Y 00.00mm| c=10
  2562. //! ----------------------
  2563. //! @endcode
  2564. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2565. static void lcd_menu_xyz_offset()
  2566. {
  2567. lcd_puts_at_P(0, 0, _i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=20
  2568. lcd_puts_at_P(0, 1, separator);
  2569. lcd_puts_at_P(0, 2, PSTR("X"));
  2570. lcd_puts_at_P(0, 3, PSTR("Y"));
  2571. float vec_x[2];
  2572. float vec_y[2];
  2573. float cntr[2];
  2574. world2machine_read_valid(vec_x, vec_y, cntr);
  2575. for (uint_least8_t i = 0; i < 2; i++)
  2576. {
  2577. lcd_set_cursor((cntr[i] < 0) ? 13 : 14, i+2);
  2578. lcd_print(cntr[i]);
  2579. lcd_puts_at_P(18, i + 2, PSTR("mm"));
  2580. }
  2581. menu_back_if_clicked();
  2582. }
  2583. // Save a single axis babystep value.
  2584. void EEPROM_save_B(int pos, int* value)
  2585. {
  2586. eeprom_update_byte((unsigned char*)pos, (unsigned char)((*value) & 0xff));
  2587. eeprom_update_byte((unsigned char*)pos + 1, (unsigned char)((*value) >> 8));
  2588. }
  2589. // Read a single axis babystep value.
  2590. void EEPROM_read_B(int pos, int* value)
  2591. {
  2592. *value = (int)eeprom_read_byte((unsigned char*)pos) | (int)(eeprom_read_byte((unsigned char*)pos + 1) << 8);
  2593. }
  2594. // Note: the colon behind the text (X, Y, Z) is necessary to greatly shorten
  2595. // the implementation of menu_draw_float31
  2596. static void lcd_move_x() {
  2597. _lcd_move(PSTR("X:"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2598. }
  2599. static void lcd_move_y() {
  2600. _lcd_move(PSTR("Y:"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2601. }
  2602. static void lcd_move_z() {
  2603. _lcd_move(PSTR("Z:"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2604. }
  2605. /**
  2606. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2607. *
  2608. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2609. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2610. * Purpose of this function for other axis then Z is unknown.
  2611. *
  2612. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2613. * other value leads to storing Z_AXIS
  2614. * @param msg text to be displayed
  2615. */
  2616. static void lcd_babystep_z()
  2617. {
  2618. if (homing_flag || mesh_bed_leveling_flag)
  2619. {
  2620. // printer changed to a new state where live Z is forbidden
  2621. menu_back();
  2622. return;
  2623. }
  2624. typedef struct
  2625. {
  2626. int8_t status;
  2627. int16_t babystepMemZ;
  2628. float babystepMemMMZ;
  2629. } _menu_data_t;
  2630. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2631. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2632. if (_md->status == 0)
  2633. {
  2634. // Menu was entered.
  2635. // Initialize its status.
  2636. _md->status = 1;
  2637. check_babystep();
  2638. if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){
  2639. _md->babystepMemZ = 0;
  2640. }
  2641. else{
  2642. _md->babystepMemZ = eeprom_read_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->
  2643. s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)));
  2644. }
  2645. // same logic as in babystep_load
  2646. if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST)
  2647. _md->babystepMemZ = 0;
  2648. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2649. lcd_draw_update = 1;
  2650. //SERIAL_ECHO("Z baby step: ");
  2651. //SERIAL_ECHO(_md->babystepMem[2]);
  2652. // Wait 90 seconds before closing the live adjust dialog.
  2653. lcd_timeoutToStatus.start();
  2654. }
  2655. if (lcd_encoder != 0)
  2656. {
  2657. _md->babystepMemZ += (int)lcd_encoder;
  2658. if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2659. else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0
  2660. else babystepsTodoZadd(lcd_encoder);
  2661. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2662. _delay(50);
  2663. lcd_encoder = 0;
  2664. lcd_draw_update = 1;
  2665. }
  2666. if (lcd_draw_update)
  2667. {
  2668. SheetFormatBuffer buffer;
  2669. menu_format_sheet_E(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))], buffer);
  2670. lcd_set_cursor(0, 0);
  2671. lcd_print(buffer.c);
  2672. lcd_set_cursor(0, 1);
  2673. menu_draw_float13(_i("Adjusting Z:"), _md->babystepMemMMZ); ////MSG_BABYSTEPPING_Z c=15 Beware: must include the ':' as its last character
  2674. }
  2675. if (LCD_CLICKED || menu_leaving)
  2676. {
  2677. // Only update the EEPROM when leaving the menu.
  2678. uint8_t active_sheet=eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  2679. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[active_sheet].z_offset)),_md->babystepMemZ);
  2680. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].bed_temp),target_temperature_bed);
  2681. #ifdef PINDA_THERMISTOR
  2682. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].pinda_temp),current_temperature_pinda);
  2683. #endif //PINDA_THERMISTOR
  2684. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2685. }
  2686. if (LCD_CLICKED) menu_back();
  2687. }
  2688. typedef struct
  2689. { // 12bytes + 9bytes = 21bytes total
  2690. menu_data_edit_t reserved; //12 bytes reserved for number editing functions
  2691. int8_t status; // 1byte
  2692. int16_t left; // 2byte
  2693. int16_t right; // 2byte
  2694. int16_t front; // 2byte
  2695. int16_t rear; // 2byte
  2696. } _menu_data_adjust_bed_t;
  2697. static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data");
  2698. void lcd_adjust_bed_reset(void)
  2699. {
  2700. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2701. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2702. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2703. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2704. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2705. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2706. _md->status = 0;
  2707. }
  2708. //! @brief Show Bed level correct
  2709. //!
  2710. //! @code{.unparsed}
  2711. //! |01234567890123456789|
  2712. //! |Settings: | MSG_SETTINGS
  2713. //! |Left side [um]: | MSG_BED_CORRECTION_LEFT
  2714. //! |Right side[um]: | MSG_BED_CORRECTION_RIGHT
  2715. //! |Front side[um]: | MSG_BED_CORRECTION_FRONT
  2716. //! |Rear side [um]: | MSG_BED_CORRECTION_REAR
  2717. //! |Reset | MSG_BED_CORRECTION_RESET
  2718. //! ----------------------
  2719. //! @endcode
  2720. void lcd_adjust_bed(void)
  2721. {
  2722. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2723. if (_md->status == 0)
  2724. {
  2725. // Menu was entered.
  2726. _md->left = 0;
  2727. _md->right = 0;
  2728. _md->front = 0;
  2729. _md->rear = 0;
  2730. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1)
  2731. {
  2732. _md->left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2733. _md->right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2734. _md->front = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2735. _md->rear = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2736. }
  2737. _md->status = 1;
  2738. }
  2739. MENU_BEGIN();
  2740. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  2741. ON_MENU_LEAVE(
  2742. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, _md->left);
  2743. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, _md->right);
  2744. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, _md->front);
  2745. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, _md->rear);
  2746. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2747. );
  2748. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  2749. 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
  2750. 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
  2751. 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
  2752. 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
  2753. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_adjust_bed_reset);////MSG_RESET c=14
  2754. MENU_END();
  2755. }
  2756. //! @brief Show PID Extruder
  2757. //!
  2758. //! @code{.unparsed}
  2759. //! |01234567890123456789|
  2760. //! |Set temperature: | MSG_SET_TEMPERATURE c=20
  2761. //! | |
  2762. //! | 210 |
  2763. //! | |
  2764. //! ----------------------
  2765. //! @endcode
  2766. void pid_extruder()
  2767. {
  2768. lcd_clear();
  2769. lcd_puts_at_P(0, 0, _i("Set temperature:"));////MSG_SET_TEMPERATURE
  2770. pid_temp += int(lcd_encoder);
  2771. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2772. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2773. lcd_encoder = 0;
  2774. lcd_set_cursor(1, 2);
  2775. lcd_print(ftostr3(pid_temp));
  2776. if (lcd_clicked()) {
  2777. lcd_commands_type = LcdCommands::PidExtruder;
  2778. lcd_return_to_status();
  2779. lcd_update(2);
  2780. }
  2781. }
  2782. /*
  2783. void lcd_adjust_z() {
  2784. int enc_dif = 0;
  2785. int cursor_pos = 1;
  2786. int fsm = 0;
  2787. lcd_clear();
  2788. lcd_set_cursor(0, 0);
  2789. lcd_puts_P(_i("Auto adjust Z?"));////MSG_ADJUSTZ
  2790. lcd_set_cursor(1, 1);
  2791. lcd_puts_P(_T(MSG_YES));
  2792. lcd_set_cursor(1, 2);
  2793. lcd_puts_P(_T(MSG_NO));
  2794. lcd_set_cursor(0, 1);
  2795. lcd_print('>');
  2796. enc_dif = lcd_encoder_diff;
  2797. while (fsm == 0) {
  2798. manage_heater();
  2799. manage_inactivity(true);
  2800. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2801. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2802. if (enc_dif > lcd_encoder_diff ) {
  2803. cursor_pos --;
  2804. }
  2805. if (enc_dif < lcd_encoder_diff ) {
  2806. cursor_pos ++;
  2807. }
  2808. if (cursor_pos > 2) {
  2809. cursor_pos = 2;
  2810. }
  2811. if (cursor_pos < 1) {
  2812. cursor_pos = 1;
  2813. }
  2814. lcd_set_cursor(0, 1);
  2815. lcd_print(' ');
  2816. lcd_set_cursor(0, 2);
  2817. lcd_print(' ');
  2818. lcd_set_cursor(0, cursor_pos);
  2819. lcd_print('>');
  2820. enc_dif = lcd_encoder_diff;
  2821. _delay(100);
  2822. }
  2823. }
  2824. if (lcd_clicked()) {
  2825. fsm = cursor_pos;
  2826. if (fsm == 1) {
  2827. int babystepLoadZ = 0;
  2828. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  2829. CRITICAL_SECTION_START
  2830. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2831. CRITICAL_SECTION_END
  2832. } else {
  2833. int zero = 0;
  2834. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  2835. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  2836. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  2837. }
  2838. _delay(500);
  2839. }
  2840. };
  2841. lcd_clear();
  2842. lcd_return_to_status();
  2843. }*/
  2844. #ifdef PINDA_THERMISTOR
  2845. bool lcd_wait_for_pinda(float temp) {
  2846. setAllTargetHotends(0);
  2847. setTargetBed(0);
  2848. LongTimer pinda_timeout;
  2849. pinda_timeout.start();
  2850. bool target_temp_reached = true;
  2851. while (current_temperature_pinda > temp){
  2852. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2853. lcd_set_cursor(0, 4);
  2854. lcd_print(LCD_STR_THERMOMETER[0]);
  2855. lcd_print(ftostr3(current_temperature_pinda));
  2856. lcd_print('/');
  2857. lcd_print(ftostr3(temp));
  2858. lcd_print(LCD_STR_DEGREE[0]);
  2859. delay_keep_alive(1000);
  2860. serialecho_temperatures();
  2861. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2862. target_temp_reached = false;
  2863. break;
  2864. }
  2865. }
  2866. lcd_update_enable(true);
  2867. return target_temp_reached;
  2868. }
  2869. #endif //PINDA_THERMISTOR
  2870. void lcd_wait_for_heater() {
  2871. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2872. lcd_set_cursor(0, 4);
  2873. lcd_print(LCD_STR_THERMOMETER[0]);
  2874. lcd_print(ftostr3(degHotend(active_extruder)));
  2875. lcd_print('/');
  2876. lcd_print(ftostr3(degTargetHotend(active_extruder)));
  2877. lcd_print(LCD_STR_DEGREE[0]);
  2878. }
  2879. void lcd_wait_for_cool_down() {
  2880. setAllTargetHotends(0);
  2881. setTargetBed(0);
  2882. int fanSpeedBckp = fanSpeed;
  2883. fanSpeed = 255;
  2884. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2885. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=4
  2886. lcd_set_cursor(0, 4);
  2887. lcd_print(LCD_STR_THERMOMETER[0]);
  2888. lcd_print(ftostr3(degHotend(0)));
  2889. lcd_print("/0");
  2890. lcd_print(LCD_STR_DEGREE[0]);
  2891. lcd_set_cursor(9, 4);
  2892. lcd_print(LCD_STR_BEDTEMP[0]);
  2893. lcd_print(ftostr3(degBed()));
  2894. lcd_print("/0");
  2895. lcd_print(LCD_STR_DEGREE[0]);
  2896. delay_keep_alive(1000);
  2897. serialecho_temperatures();
  2898. }
  2899. fanSpeed = fanSpeedBckp;
  2900. lcd_update_enable(true);
  2901. }
  2902. // Lets the user move the Z carriage up to the end stoppers.
  2903. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2904. // Otherwise the Z calibration is not changed and false is returned.
  2905. #ifndef TMC2130
  2906. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2907. {
  2908. // 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.
  2909. current_position[Z_AXIS] = 0;
  2910. plan_set_position_curposXYZE();
  2911. // Until confirmed by the confirmation dialog.
  2912. for (;;) {
  2913. 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
  2914. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2915. const bool multi_screen = msg_next != NULL;
  2916. unsigned long previous_millis_msg = _millis();
  2917. // Until the user finishes the z up movement.
  2918. lcd_encoder_diff = 0;
  2919. lcd_encoder = 0;
  2920. for (;;) {
  2921. manage_heater();
  2922. manage_inactivity(true);
  2923. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2924. _delay(50);
  2925. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2926. lcd_encoder_diff = 0;
  2927. if (! planner_queue_full()) {
  2928. // Only move up, whatever direction the user rotates the encoder.
  2929. current_position[Z_AXIS] += fabs(lcd_encoder);
  2930. lcd_encoder = 0;
  2931. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  2932. }
  2933. }
  2934. if (lcd_clicked()) {
  2935. // Abort a move if in progress.
  2936. planner_abort_hard();
  2937. while (lcd_clicked()) ;
  2938. _delay(10);
  2939. while (lcd_clicked()) ;
  2940. break;
  2941. }
  2942. if (multi_screen && _millis() - previous_millis_msg > 5000) {
  2943. if (msg_next == NULL)
  2944. msg_next = msg;
  2945. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2946. previous_millis_msg = _millis();
  2947. }
  2948. }
  2949. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2950. 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
  2951. if (result == -1)
  2952. goto canceled;
  2953. else if (result == 1)
  2954. goto calibrated;
  2955. // otherwise perform another round of the Z up dialog.
  2956. }
  2957. calibrated:
  2958. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2959. // during the search for the induction points.
  2960. if ((PRINTER_TYPE == PRINTER_MK25) || (PRINTER_TYPE == PRINTER_MK2) || (PRINTER_TYPE == PRINTER_MK2_SNMM)) {
  2961. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2962. }
  2963. else {
  2964. current_position[Z_AXIS] = Z_MAX_POS+4.f;
  2965. }
  2966. plan_set_position_curposXYZE();
  2967. return true;
  2968. canceled:
  2969. return false;
  2970. }
  2971. #endif // TMC2130
  2972. static inline bool pgm_is_whitespace(const char *c_addr)
  2973. {
  2974. const char c = pgm_read_byte(c_addr);
  2975. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2976. }
  2977. static inline bool pgm_is_interpunction(const char *c_addr)
  2978. {
  2979. const char c = pgm_read_byte(c_addr);
  2980. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2981. }
  2982. /**
  2983. * @brief show full screen message
  2984. *
  2985. * This function is non-blocking
  2986. * @param msg message to be displayed from PROGMEM
  2987. * @param nlines
  2988. * @return rest of the text (to be displayed on next page)
  2989. */
  2990. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines)
  2991. {
  2992. lcd_set_cursor(0, 0);
  2993. const char *msgend = msg;
  2994. uint8_t row = 0;
  2995. bool multi_screen = false;
  2996. for (; row < 4; ++ row) {
  2997. while (pgm_is_whitespace(msg))
  2998. ++ msg;
  2999. if (pgm_read_byte(msg) == 0)
  3000. // End of the message.
  3001. break;
  3002. lcd_set_cursor(0, row);
  3003. uint8_t linelen = min(strlen_P(msg), LCD_WIDTH);
  3004. const char *msgend2 = msg + linelen;
  3005. msgend = msgend2;
  3006. if (row == 3 && linelen == LCD_WIDTH) {
  3007. // Last line of the display, full line shall be displayed.
  3008. // Find out, whether this message will be split into multiple screens.
  3009. while (pgm_is_whitespace(msgend))
  3010. ++ msgend;
  3011. multi_screen = pgm_read_byte(msgend) != 0;
  3012. if (multi_screen)
  3013. msgend = (msgend2 -= 2);
  3014. }
  3015. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  3016. // Splitting a word. Find the start of the current word.
  3017. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  3018. -- msgend;
  3019. if (msgend == msg)
  3020. // Found a single long word, which cannot be split. Just cut it.
  3021. msgend = msgend2;
  3022. }
  3023. for (; msg < msgend; ++ msg) {
  3024. char c = char(pgm_read_byte(msg));
  3025. if (c == '~')
  3026. c = ' ';
  3027. lcd_print(c);
  3028. }
  3029. }
  3030. if (multi_screen) {
  3031. // Display the "next screen" indicator character.
  3032. lcd_set_custom_characters_nextpage();
  3033. lcd_set_cursor(19, 3);
  3034. // Display the double down arrow.
  3035. lcd_print(LCD_STR_ARROW_2_DOWN[0]);
  3036. }
  3037. nlines = row;
  3038. return multi_screen ? msgend : NULL;
  3039. }
  3040. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  3041. {
  3042. // Disable update of the screen by the usual lcd_update(0) routine.
  3043. lcd_update_enable(false);
  3044. lcd_clear();
  3045. // uint8_t nlines;
  3046. return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines);
  3047. }
  3048. const char* lcd_display_message_fullscreen_P(const char *msg)
  3049. {
  3050. uint8_t nlines;
  3051. return lcd_display_message_fullscreen_P(msg, nlines);
  3052. }
  3053. /**
  3054. * @brief show full screen message and wait
  3055. *
  3056. * This function is blocking.
  3057. * @param msg message to be displayed from PROGMEM
  3058. */
  3059. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  3060. {
  3061. LcdUpdateDisabler lcdUpdateDisabler;
  3062. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  3063. bool multi_screen = msg_next != NULL;
  3064. lcd_set_custom_characters_nextpage();
  3065. lcd_consume_click();
  3066. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3067. // Until confirmed by a button click.
  3068. for (;;) {
  3069. if (!multi_screen) {
  3070. lcd_set_cursor(19, 3);
  3071. // Display the confirm char.
  3072. lcd_print(LCD_STR_CONFIRM[0]);
  3073. }
  3074. // Wait for 5 seconds before displaying the next text.
  3075. for (uint8_t i = 0; i < 100; ++ i) {
  3076. delay_keep_alive(50);
  3077. if (lcd_clicked()) {
  3078. if (msg_next == NULL) {
  3079. KEEPALIVE_STATE(IN_HANDLER);
  3080. lcd_set_custom_characters();
  3081. lcd_update_enable(true);
  3082. lcd_update(2);
  3083. return;
  3084. }
  3085. else {
  3086. break;
  3087. }
  3088. }
  3089. }
  3090. if (multi_screen) {
  3091. if (msg_next == NULL)
  3092. msg_next = msg;
  3093. msg_next = lcd_display_message_fullscreen_P(msg_next);
  3094. if (msg_next == NULL) {
  3095. lcd_set_cursor(19, 3);
  3096. // Display the confirm char.
  3097. lcd_print(LCD_STR_CONFIRM[0]);
  3098. }
  3099. }
  3100. }
  3101. }
  3102. bool lcd_wait_for_click_delay(uint16_t nDelay)
  3103. // nDelay :: timeout [s] (0 ~ no timeout)
  3104. // true ~ clicked, false ~ delayed
  3105. {
  3106. bool bDelayed;
  3107. long nTime0 = _millis()/1000;
  3108. lcd_consume_click();
  3109. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3110. for (;;) {
  3111. manage_heater();
  3112. manage_inactivity(true);
  3113. bDelayed = ((_millis()/1000-nTime0) > nDelay);
  3114. bDelayed = (bDelayed && (nDelay != 0)); // 0 ~ no timeout, always waiting for click
  3115. if (lcd_clicked() || bDelayed) {
  3116. KEEPALIVE_STATE(IN_HANDLER);
  3117. return(!bDelayed);
  3118. }
  3119. }
  3120. }
  3121. void lcd_wait_for_click()
  3122. {
  3123. lcd_wait_for_click_delay(0);
  3124. }
  3125. //! @brief Show multiple screen message with yes and no possible choices and wait with possible timeout
  3126. //! @param msg Message to show
  3127. //! @param allow_timeouting if true, allows time outing of the screen
  3128. //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected
  3129. //! @retval 1 yes choice selected by user
  3130. //! @retval 0 no choice selected by user
  3131. //! @retval -1 screen timed out
  3132. 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)
  3133. {
  3134. return lcd_show_multiscreen_message_two_choices_and_wait_P(msg, allow_timeouting, default_yes, _T(MSG_YES), _T(MSG_NO));
  3135. }
  3136. //! @brief Show multiple screen message with two possible choices and wait with possible timeout
  3137. //! @param msg Message to show
  3138. //! @param allow_timeouting if true, allows time outing of the screen
  3139. //! @param default_first if true, fist choice is selected by default, otherwise second choice is preselected
  3140. //! @param first_choice text caption of first possible choice
  3141. //! @param second_choice text caption of second possible choice
  3142. //! @retval 1 first choice selected by user
  3143. //! @retval 0 second choice selected by user
  3144. //! @retval -1 screen timed out
  3145. int8_t lcd_show_multiscreen_message_two_choices_and_wait_P(const char *msg, bool allow_timeouting, bool default_first,
  3146. const char *first_choice, const char *second_choice)
  3147. {
  3148. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  3149. bool multi_screen = msg_next != NULL;
  3150. bool yes = default_first ? true : false;
  3151. // Wait for user confirmation or a timeout.
  3152. unsigned long previous_millis_cmd = _millis();
  3153. int8_t enc_dif = lcd_encoder_diff;
  3154. lcd_consume_click();
  3155. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  3156. for (;;) {
  3157. for (uint8_t i = 0; i < 100; ++i) {
  3158. delay_keep_alive(50);
  3159. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  3160. return -1;
  3161. manage_heater();
  3162. manage_inactivity(true);
  3163. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  3164. if (msg_next == NULL) {
  3165. lcd_set_cursor(0, 3);
  3166. if (enc_dif < lcd_encoder_diff && yes) {
  3167. lcd_print(' ');
  3168. lcd_putc_at(7, 3, '>');
  3169. yes = false;
  3170. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3171. }
  3172. else if (enc_dif > lcd_encoder_diff && !yes) {
  3173. lcd_print('>');
  3174. lcd_putc_at(7, 3, ' ');
  3175. yes = true;
  3176. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3177. }
  3178. enc_dif = lcd_encoder_diff;
  3179. }
  3180. else {
  3181. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  3182. break; //turning knob skips waiting loop
  3183. }
  3184. }
  3185. if (lcd_clicked()) {
  3186. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  3187. if (msg_next == NULL) {
  3188. //KEEPALIVE_STATE(IN_HANDLER);
  3189. lcd_set_custom_characters();
  3190. return yes;
  3191. }
  3192. else break;
  3193. }
  3194. }
  3195. if (multi_screen) {
  3196. if (msg_next == NULL) {
  3197. msg_next = msg;
  3198. }
  3199. msg_next = lcd_display_message_fullscreen_P(msg_next);
  3200. }
  3201. if (msg_next == NULL) {
  3202. lcd_set_cursor(0, 3);
  3203. if (yes) lcd_print('>');
  3204. lcd_puts_at_P(1, 3, first_choice);
  3205. lcd_set_cursor(7, 3);
  3206. if (!yes) lcd_print('>');
  3207. lcd_puts_at_P(8, 3, second_choice);
  3208. }
  3209. }
  3210. }
  3211. //! @brief Show single screen message with yes and no possible choices and wait with possible timeout
  3212. //! @param msg Message to show
  3213. //! @param allow_timeouting if true, allows time outing of the screen
  3214. //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected
  3215. //! @retval 1 yes choice selected by user
  3216. //! @retval 0 no choice selected by user
  3217. //! @retval -1 screen timed out
  3218. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  3219. {
  3220. lcd_display_message_fullscreen_P(msg);
  3221. if (default_yes) {
  3222. lcd_putc_at(0, 2, '>');
  3223. lcd_puts_P(_T(MSG_YES));
  3224. lcd_puts_at_P(1, 3, _T(MSG_NO));
  3225. }
  3226. else {
  3227. lcd_puts_at_P(1, 2, _T(MSG_YES));
  3228. lcd_putc_at(0, 3, '>');
  3229. lcd_puts_P(_T(MSG_NO));
  3230. }
  3231. int8_t retval = default_yes ? true : false;
  3232. // Wait for user confirmation or a timeout.
  3233. unsigned long previous_millis_cmd = _millis();
  3234. int8_t enc_dif = lcd_encoder_diff;
  3235. lcd_consume_click();
  3236. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3237. for (;;) {
  3238. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  3239. {
  3240. retval = -1;
  3241. break;
  3242. }
  3243. manage_heater();
  3244. manage_inactivity(true);
  3245. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  3246. lcd_set_cursor(0, 2);
  3247. if (enc_dif < lcd_encoder_diff && retval) {
  3248. lcd_print(' ');
  3249. lcd_putc_at(0, 3, '>');
  3250. retval = 0;
  3251. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3252. }
  3253. else if (enc_dif > lcd_encoder_diff && !retval) {
  3254. lcd_print('>');
  3255. lcd_putc_at(0, 3, ' ');
  3256. retval = 1;
  3257. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3258. }
  3259. enc_dif = lcd_encoder_diff;
  3260. }
  3261. if (lcd_clicked()) {
  3262. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  3263. KEEPALIVE_STATE(IN_HANDLER);
  3264. break;
  3265. }
  3266. }
  3267. lcd_encoder_diff = 0;
  3268. return retval;
  3269. }
  3270. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  3271. {
  3272. const char *msg = NULL;
  3273. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  3274. 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
  3275. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  3276. if (point_too_far_mask == 0)
  3277. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3278. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3279. // Only the center point or all the three front points.
  3280. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=6
  3281. else if ((point_too_far_mask & 1) == 0)
  3282. // The right and maybe the center point out of reach.
  3283. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=6
  3284. else
  3285. // The left and maybe the center point out of reach.
  3286. msg = _i("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  3287. lcd_show_fullscreen_message_and_wait_P(msg);
  3288. } else {
  3289. if (point_too_far_mask != 0) {
  3290. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3291. // Only the center point or all the three front points.
  3292. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  3293. else if ((point_too_far_mask & 1) == 0)
  3294. // The right and maybe the center point out of reach.
  3295. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  3296. else
  3297. // The left and maybe the center point out of reach.
  3298. msg = _i("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  3299. lcd_show_fullscreen_message_and_wait_P(msg);
  3300. }
  3301. if (point_too_far_mask == 0 || result > 0) {
  3302. switch (result) {
  3303. default:
  3304. // should not happen
  3305. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3306. break;
  3307. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  3308. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  3309. break;
  3310. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  3311. 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
  3312. break;
  3313. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  3314. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  3315. break;
  3316. }
  3317. lcd_show_fullscreen_message_and_wait_P(msg);
  3318. }
  3319. }
  3320. }
  3321. void lcd_temp_cal_show_result(bool result) {
  3322. custom_message_type = CustomMsg::Status;
  3323. disable_x();
  3324. disable_y();
  3325. disable_z();
  3326. disable_e0();
  3327. disable_e1();
  3328. disable_e2();
  3329. setTargetBed(0); //set bed target temperature back to 0
  3330. if (result == true) {
  3331. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  3332. SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob.");
  3333. lcd_show_fullscreen_message_and_wait_P(_T(MSG_TEMP_CALIBRATION_DONE));
  3334. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  3335. }
  3336. else {
  3337. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  3338. SERIAL_ECHOLNPGM("Temperature calibration failed. Continue with pressing the knob.");
  3339. lcd_show_fullscreen_message_and_wait_P(_i("Temperature calibration failed"));////MSG_TEMP_CAL_FAILED c=20 r=8
  3340. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  3341. }
  3342. lcd_update_enable(true);
  3343. lcd_update(2);
  3344. }
  3345. static void lcd_show_end_stops() {
  3346. lcd_puts_at_P(0, 0, (PSTR("End stops diag")));
  3347. lcd_puts_at_P(0, 1, (READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  3348. lcd_puts_at_P(0, 2, (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  3349. lcd_puts_at_P(0, 3, (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  3350. }
  3351. #ifndef TMC2130
  3352. static void menu_show_end_stops() {
  3353. lcd_show_end_stops();
  3354. if (LCD_CLICKED) menu_back();
  3355. }
  3356. #endif // not defined TMC2130
  3357. // Lets the user move the Z carriage up to the end stoppers.
  3358. // When done, it sets the current Z to Z_MAX_POS and returns true.
  3359. // Otherwise the Z calibration is not changed and false is returned.
  3360. void lcd_diag_show_end_stops()
  3361. {
  3362. lcd_clear();
  3363. lcd_consume_click();
  3364. for (;;) {
  3365. manage_heater();
  3366. manage_inactivity(true);
  3367. lcd_show_end_stops();
  3368. if (lcd_clicked()) {
  3369. break;
  3370. }
  3371. }
  3372. lcd_clear();
  3373. lcd_return_to_status();
  3374. }
  3375. static void lcd_print_state(uint8_t state)
  3376. {
  3377. switch (state) {
  3378. case STATE_ON:
  3379. lcd_puts_P(_N(" 1"));
  3380. break;
  3381. case STATE_OFF:
  3382. lcd_puts_P(_N(" 0"));
  3383. break;
  3384. default:
  3385. lcd_puts_P(_T(MSG_NA));
  3386. break;
  3387. }
  3388. }
  3389. //! @brief Show sensor state
  3390. //!
  3391. //! @code{.unparsed}
  3392. //! |01234567890123456789|
  3393. //! |PINDA N/A FINDA N/A| MSG_PINDA c=5 MSG_FINDA c=5
  3394. //! |Fil. sensor N/A| MSG_FSENSOR
  3395. //! |Xd 000 Yd 000| MSG_XD
  3396. //! |Int 000 Shut 000|
  3397. //! ----------------------
  3398. //! @endcode
  3399. static void lcd_show_sensors_state()
  3400. {
  3401. //0: N/A; 1: OFF; 2: ON
  3402. uint8_t pinda_state = STATE_NA;
  3403. uint8_t finda_state = STATE_NA;
  3404. uint8_t idler_state = STATE_NA;
  3405. pinda_state = READ(Z_MIN_PIN);
  3406. if (mmu_enabled && mmu_last_finda_response.expired(1000))
  3407. {
  3408. finda_state = mmu_finda;
  3409. }
  3410. //lcd_puts_at_P(0, 0, _i("Sensor state"));
  3411. lcd_puts_at_P(0, 0, _T(MSG_PINDA));
  3412. lcd_set_cursor(LCD_WIDTH - 14, 0);
  3413. lcd_print_state(pinda_state);
  3414. if (mmu_enabled == true)
  3415. {
  3416. lcd_puts_at_P(10, 0, _n("FINDA"));////MSG_FINDA c=5
  3417. lcd_set_cursor(LCD_WIDTH - 3, 0);
  3418. lcd_print_state(finda_state);
  3419. }
  3420. if (ir_sensor_detected) {
  3421. idler_state = !READ(IR_SENSOR_PIN);
  3422. lcd_puts_at_P(0, 1, _i("Fil. sensor"));
  3423. lcd_set_cursor(LCD_WIDTH - 3, 1);
  3424. lcd_print_state(idler_state);
  3425. }
  3426. #ifdef PAT9125
  3427. // Display X and Y difference from Filament sensor
  3428. // Display Light intensity from Filament sensor
  3429. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  3430. // value ranges from 0(darkest) to 255(brightest).
  3431. // Display LASER shutter time from Filament sensor
  3432. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  3433. // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small.
  3434. // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46.
  3435. if (mmu_enabled == false)
  3436. {
  3437. //if (!fsensor_enabled)
  3438. // lcd_puts_P(_N("Filament sensor\n" "is disabled."));
  3439. //else
  3440. //{
  3441. if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal))
  3442. pat9125_update();
  3443. lcd_set_cursor(0, 2);
  3444. lcd_printf_P(_N(
  3445. "Xd: %3d "
  3446. "Yd: %3d\n" ////c=4
  3447. "Int: %3d " ////c=4
  3448. "Shut: %3d" ////c=4
  3449. ),
  3450. pat9125_x, pat9125_y,
  3451. pat9125_b, pat9125_s
  3452. );
  3453. //}
  3454. }
  3455. #endif //PAT9125
  3456. }
  3457. void lcd_menu_show_sensors_state() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  3458. {
  3459. lcd_timeoutToStatus.stop();
  3460. lcd_show_sensors_state();
  3461. if(LCD_CLICKED)
  3462. {
  3463. lcd_timeoutToStatus.start();
  3464. menu_back();
  3465. }
  3466. }
  3467. void prusa_statistics_err(char c){
  3468. SERIAL_ECHOPGM("{[ERR:");
  3469. SERIAL_ECHO(c);
  3470. SERIAL_ECHO(']');
  3471. prusa_stat_farm_number();
  3472. }
  3473. static void prusa_statistics_case0(uint8_t statnr){
  3474. SERIAL_ECHO('{');
  3475. prusa_stat_printerstatus(statnr);
  3476. prusa_stat_farm_number();
  3477. prusa_stat_printinfo();
  3478. }
  3479. void prusa_statistics(uint8_t _message, uint8_t _fil_nr) {
  3480. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  3481. return;
  3482. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  3483. switch (_message)
  3484. {
  3485. case 0: // default message
  3486. if (busy_state == PAUSED_FOR_USER)
  3487. {
  3488. prusa_statistics_case0(15);
  3489. }
  3490. else if (isPrintPaused)
  3491. {
  3492. prusa_statistics_case0(14);
  3493. }
  3494. else if (IS_SD_PRINTING || loading_flag)
  3495. {
  3496. prusa_statistics_case0(4);
  3497. }
  3498. else
  3499. {
  3500. SERIAL_ECHO('{');
  3501. prusa_stat_printerstatus(1);
  3502. prusa_stat_farm_number();
  3503. prusa_stat_diameter();
  3504. status_number = 1;
  3505. }
  3506. break;
  3507. case 1: // 1 heating
  3508. SERIAL_ECHO('{');
  3509. prusa_stat_printerstatus(2);
  3510. prusa_stat_farm_number();
  3511. status_number = 2;
  3512. farm_timer = 1;
  3513. break;
  3514. case 2: // heating done
  3515. SERIAL_ECHO('{');
  3516. prusa_stat_printerstatus(3);
  3517. prusa_stat_farm_number();
  3518. SERIAL_ECHOLN('}');
  3519. status_number = 3;
  3520. farm_timer = 1;
  3521. if (IS_SD_PRINTING || loading_flag)
  3522. {
  3523. SERIAL_ECHO('{');
  3524. prusa_stat_printerstatus(4);
  3525. prusa_stat_farm_number();
  3526. status_number = 4;
  3527. }
  3528. else
  3529. {
  3530. SERIAL_ECHO('{');
  3531. prusa_stat_printerstatus(3);
  3532. prusa_stat_farm_number();
  3533. status_number = 3;
  3534. }
  3535. farm_timer = 1;
  3536. break;
  3537. case 3: // filament change
  3538. // must do a return here to prevent doing SERIAL_ECHOLN("}") at the very end of this function
  3539. // saved a considerable amount of FLASH
  3540. return;
  3541. break;
  3542. case 4: // print succesfull
  3543. SERIAL_ECHOPGM("{[RES:1][FIL:");
  3544. MYSERIAL.print(int(_fil_nr));
  3545. SERIAL_ECHO(']');
  3546. prusa_stat_printerstatus(status_number);
  3547. prusa_stat_farm_number();
  3548. farm_timer = 2;
  3549. break;
  3550. case 5: // print not succesfull
  3551. SERIAL_ECHOPGM("{[RES:0][FIL:");
  3552. MYSERIAL.print(int(_fil_nr));
  3553. SERIAL_ECHO(']');
  3554. prusa_stat_printerstatus(status_number);
  3555. prusa_stat_farm_number();
  3556. farm_timer = 2;
  3557. break;
  3558. case 6: // print done
  3559. SERIAL_ECHOPGM("{[PRN:8]");
  3560. prusa_stat_farm_number();
  3561. status_number = 8;
  3562. farm_timer = 2;
  3563. break;
  3564. case 7: // print done - stopped
  3565. SERIAL_ECHOPGM("{[PRN:9]");
  3566. prusa_stat_farm_number();
  3567. status_number = 9;
  3568. farm_timer = 2;
  3569. break;
  3570. case 8: // printer started
  3571. SERIAL_ECHOPGM("{[PRN:0]");
  3572. prusa_stat_farm_number();
  3573. status_number = 0;
  3574. farm_timer = 2;
  3575. break;
  3576. case 20: // echo farm no
  3577. SERIAL_ECHO('{');
  3578. prusa_stat_printerstatus(status_number);
  3579. prusa_stat_farm_number();
  3580. farm_timer = 4;
  3581. break;
  3582. case 21: // temperatures
  3583. SERIAL_ECHO('{');
  3584. prusa_stat_temperatures();
  3585. prusa_stat_farm_number();
  3586. prusa_stat_printerstatus(status_number);
  3587. break;
  3588. case 22: // waiting for filament change
  3589. SERIAL_ECHOPGM("{[PRN:5]");
  3590. prusa_stat_farm_number();
  3591. status_number = 5;
  3592. break;
  3593. case 90: // Error - Thermal Runaway
  3594. prusa_statistics_err('1');
  3595. break;
  3596. case 91: // Error - Thermal Runaway Preheat
  3597. prusa_statistics_err('2');
  3598. break;
  3599. case 92: // Error - Min temp
  3600. prusa_statistics_err('3');
  3601. break;
  3602. case 93: // Error - Max temp
  3603. prusa_statistics_err('4');
  3604. break;
  3605. case 99: // heartbeat
  3606. SERIAL_ECHOPGM("{[PRN:99]");
  3607. prusa_stat_temperatures();
  3608. prusa_stat_farm_number();
  3609. break;
  3610. }
  3611. SERIAL_ECHOLN('}');
  3612. }
  3613. static void prusa_stat_printerstatus(uint8_t _status)
  3614. {
  3615. SERIAL_ECHOPGM("[PRN:");
  3616. SERIAL_ECHO(_status);
  3617. SERIAL_ECHO(']');
  3618. }
  3619. static void prusa_stat_farm_number() {
  3620. SERIAL_ECHOPGM("[PFN:0]");
  3621. }
  3622. static void prusa_stat_diameter() {
  3623. SERIAL_ECHOPGM("[DIA:");
  3624. SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM));
  3625. SERIAL_ECHO(']');
  3626. }
  3627. static void prusa_stat_temperatures()
  3628. {
  3629. SERIAL_ECHOPGM("[ST0:");
  3630. SERIAL_ECHO(target_temperature[0]);
  3631. SERIAL_ECHOPGM("][STB:");
  3632. SERIAL_ECHO(target_temperature_bed);
  3633. SERIAL_ECHOPGM("][AT0:");
  3634. SERIAL_ECHO(current_temperature[0]);
  3635. SERIAL_ECHOPGM("][ATB:");
  3636. SERIAL_ECHO(current_temperature_bed);
  3637. SERIAL_ECHO(']');
  3638. }
  3639. static void prusa_stat_printinfo()
  3640. {
  3641. SERIAL_ECHOPGM("[TFU:");
  3642. SERIAL_ECHO(total_filament_used);
  3643. SERIAL_ECHOPGM("][PCD:");
  3644. SERIAL_ECHO(itostr3(card.percentDone()));
  3645. SERIAL_ECHOPGM("][FEM:");
  3646. SERIAL_ECHO(itostr3(feedmultiply));
  3647. SERIAL_ECHOPGM("][FNM:");
  3648. SERIAL_ECHO(card.longFilename[0] ? card.longFilename : card.filename);
  3649. SERIAL_ECHOPGM("][TIM:");
  3650. if (starttime != 0)
  3651. {
  3652. SERIAL_ECHO(_millis() / 1000 - starttime / 1000);
  3653. }
  3654. else
  3655. {
  3656. SERIAL_ECHO(0);
  3657. }
  3658. SERIAL_ECHOPGM("][FWR:");
  3659. SERIAL_ECHORPGM(FW_VERSION_STR_P());
  3660. SERIAL_ECHO(']');
  3661. prusa_stat_diameter();
  3662. }
  3663. /*
  3664. void lcd_pick_babystep(){
  3665. int enc_dif = 0;
  3666. int cursor_pos = 1;
  3667. int fsm = 0;
  3668. lcd_clear();
  3669. lcd_set_cursor(0, 0);
  3670. lcd_puts_P(_i("Pick print"));////MSG_PICK_Z
  3671. lcd_set_cursor(3, 2);
  3672. lcd_print('1');
  3673. lcd_set_cursor(3, 3);
  3674. lcd_print('2');
  3675. lcd_set_cursor(12, 2);
  3676. lcd_print('3');
  3677. lcd_set_cursor(12, 3);
  3678. lcd_print('4');
  3679. lcd_set_cursor(1, 2);
  3680. lcd_print('>');
  3681. enc_dif = lcd_encoder_diff;
  3682. while (fsm == 0) {
  3683. manage_heater();
  3684. manage_inactivity(true);
  3685. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  3686. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  3687. if (enc_dif > lcd_encoder_diff ) {
  3688. cursor_pos --;
  3689. }
  3690. if (enc_dif < lcd_encoder_diff ) {
  3691. cursor_pos ++;
  3692. }
  3693. if (cursor_pos > 4) {
  3694. cursor_pos = 4;
  3695. }
  3696. if (cursor_pos < 1) {
  3697. cursor_pos = 1;
  3698. }
  3699. lcd_set_cursor(1, 2);
  3700. lcd_print(' ');
  3701. lcd_set_cursor(1, 3);
  3702. lcd_print(' ');
  3703. lcd_set_cursor(10, 2);
  3704. lcd_print(' ');
  3705. lcd_set_cursor(10, 3);
  3706. lcd_print(' ');
  3707. if (cursor_pos < 3) {
  3708. lcd_set_cursor(1, cursor_pos+1);
  3709. lcd_print('>');
  3710. }else{
  3711. lcd_set_cursor(10, cursor_pos-1);
  3712. lcd_print('>');
  3713. }
  3714. enc_dif = lcd_encoder_diff;
  3715. _delay(100);
  3716. }
  3717. }
  3718. if (lcd_clicked()) {
  3719. fsm = cursor_pos;
  3720. int babyStepZ;
  3721. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  3722. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  3723. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  3724. _delay(500);
  3725. }
  3726. };
  3727. lcd_clear();
  3728. lcd_return_to_status();
  3729. }
  3730. */
  3731. void lcd_move_menu_axis()
  3732. {
  3733. MENU_BEGIN();
  3734. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3735. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=18
  3736. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=18
  3737. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=18
  3738. MENU_ITEM_SUBMENU_P(_T(MSG_EXTRUDER), lcd_move_e);
  3739. MENU_END();
  3740. }
  3741. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  3742. {
  3743. do
  3744. {
  3745. eeprom_write_byte((unsigned char*)pos, *value);
  3746. pos++;
  3747. value++;
  3748. } while (--size);
  3749. }
  3750. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  3751. {
  3752. do
  3753. {
  3754. *value = eeprom_read_byte((unsigned char*)pos);
  3755. pos++;
  3756. value++;
  3757. } while (--size);
  3758. }
  3759. #ifdef SDCARD_SORT_ALPHA
  3760. static void lcd_sort_type_set() {
  3761. uint8_t sdSort;
  3762. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3763. switch (sdSort) {
  3764. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3765. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3766. default: sdSort = SD_SORT_TIME;
  3767. }
  3768. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  3769. card.presort_flag = true;
  3770. }
  3771. #endif //SDCARD_SORT_ALPHA
  3772. #ifdef TMC2130
  3773. static void lcd_crash_mode_info()
  3774. {
  3775. lcd_update_enable(true);
  3776. static uint32_t tim = 0;
  3777. if ((tim + 1000) < _millis())
  3778. {
  3779. lcd_clear();
  3780. fputs_P(_i("Crash detection can\nbe turned on only in\nNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
  3781. tim = _millis();
  3782. }
  3783. menu_back_if_clicked();
  3784. }
  3785. static void lcd_crash_mode_info2()
  3786. {
  3787. lcd_update_enable(true);
  3788. static uint32_t tim = 0;
  3789. if ((tim + 1000) < _millis())
  3790. {
  3791. lcd_clear();
  3792. fputs_P(_i("WARNING:\nCrash detection\ndisabled in\nStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
  3793. tim = _millis();
  3794. }
  3795. menu_back_if_clicked();
  3796. }
  3797. #endif //TMC2130
  3798. #ifdef FILAMENT_SENSOR
  3799. static void lcd_filament_autoload_info()
  3800. {
  3801. uint8_t nlines;
  3802. lcd_update_enable(true);
  3803. static uint32_t tim = 0;
  3804. if ((tim + 1000) < _millis())
  3805. {
  3806. 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
  3807. tim = _millis();
  3808. }
  3809. menu_back_if_clicked();
  3810. }
  3811. static void lcd_fsensor_fail()
  3812. {
  3813. uint8_t nlines;
  3814. lcd_update_enable(true);
  3815. static uint32_t tim = 0;
  3816. if ((tim + 1000) < _millis())
  3817. {
  3818. 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
  3819. tim = _millis();
  3820. }
  3821. menu_back_if_clicked();
  3822. }
  3823. #endif //FILAMENT_SENSOR
  3824. //-//
  3825. static void lcd_sound_state_set(void)
  3826. {
  3827. Sound_CycleState();
  3828. }
  3829. #ifndef MMU_FORCE_STEALTH_MODE
  3830. static void lcd_silent_mode_mmu_set() {
  3831. if (SilentModeMenu_MMU == 1) SilentModeMenu_MMU = 0;
  3832. else SilentModeMenu_MMU = 1;
  3833. //saving to eeprom is done in mmu_loop() after mmu actually switches state and confirms with "ok"
  3834. }
  3835. #endif //MMU_FORCE_STEALTH_MODE
  3836. static void lcd_silent_mode_set() {
  3837. switch (SilentModeMenu) {
  3838. #ifdef TMC2130
  3839. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3840. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3841. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3842. #else
  3843. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3844. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3845. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3846. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3847. #endif //TMC2130
  3848. }
  3849. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3850. #ifdef TMC2130
  3851. lcd_display_message_fullscreen_P(_i("Mode change in progress..."));////MSG_MODE_CHANGE_IN_PROGRESS c=20 r=3
  3852. // Wait until the planner queue is drained and the stepper routine achieves
  3853. // an idle state.
  3854. st_synchronize();
  3855. if (tmc2130_wait_standstill_xy(1000)) {}
  3856. // MYSERIAL.print("standstill OK");
  3857. // else
  3858. // MYSERIAL.print("standstill NG!");
  3859. cli();
  3860. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3861. update_mode_profile();
  3862. tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  3863. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3864. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3865. st_reset_timer();
  3866. sei();
  3867. #endif //TMC2130
  3868. st_current_init();
  3869. #ifdef TMC2130
  3870. if (lcd_crash_detect_enabled() && (SilentModeMenu != SILENT_MODE_NORMAL))
  3871. menu_submenu(lcd_crash_mode_info2);
  3872. lcd_encoder_diff=0; // reset 'encoder buffer'
  3873. #endif //TMC2130
  3874. }
  3875. #ifdef TMC2130
  3876. static void crash_mode_switch()
  3877. {
  3878. if (lcd_crash_detect_enabled())
  3879. {
  3880. lcd_crash_detect_disable();
  3881. }
  3882. else
  3883. {
  3884. lcd_crash_detect_enable();
  3885. }
  3886. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true);
  3887. else menu_goto(lcd_settings_menu, 9, true, true);
  3888. }
  3889. #endif //TMC2130
  3890. #ifdef FILAMENT_SENSOR
  3891. static void lcd_fsensor_state_set()
  3892. {
  3893. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3894. if (!FSensorStateMenu) {
  3895. fsensor_disable();
  3896. if (fsensor_autoload_enabled && !mmu_enabled)
  3897. menu_submenu(lcd_filament_autoload_info);
  3898. }
  3899. else {
  3900. fsensor_enable();
  3901. if (fsensor_not_responding && !mmu_enabled)
  3902. menu_submenu(lcd_fsensor_fail);
  3903. }
  3904. }
  3905. #endif //FILAMENT_SENSOR
  3906. #if (LANG_MODE != 0)
  3907. void menu_setlang(unsigned char lang)
  3908. {
  3909. if (!lang_select(lang))
  3910. {
  3911. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language?"), false, true))////MSG_COPY_SEL_LANG c=20 r=3
  3912. lang_boot_update_start(lang);
  3913. lcd_update_enable(true);
  3914. lcd_clear();
  3915. menu_goto(lcd_language_menu, 0, true, true);
  3916. lcd_timeoutToStatus.stop(); //infinite timeout
  3917. lcd_draw_update = 2;
  3918. }
  3919. }
  3920. #ifdef COMMUNITY_LANG_SUPPORT
  3921. #ifdef XFLASH
  3922. static void lcd_community_language_menu()
  3923. {
  3924. MENU_BEGIN();
  3925. uint8_t cnt = lang_get_count();
  3926. MENU_ITEM_BACK_P(_i("Select language")); //Back to previous Menu
  3927. for (int i = 8; i < cnt; i++) //all community languages
  3928. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3929. {
  3930. menu_setlang(i);
  3931. return;
  3932. }
  3933. MENU_END();
  3934. }
  3935. #endif //XFLASH
  3936. #endif //COMMUNITY_LANG_SUPPORT && W52X20CL
  3937. static void lcd_language_menu()
  3938. {
  3939. MENU_BEGIN();
  3940. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3941. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3942. {
  3943. menu_setlang(0);
  3944. return;
  3945. }
  3946. uint8_t cnt = lang_get_count();
  3947. #ifdef XFLASH
  3948. if (cnt == 2) //display secondary language in case of clear xflash
  3949. {
  3950. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3951. {
  3952. menu_setlang(1);
  3953. return;
  3954. }
  3955. }
  3956. else
  3957. for (int i = 2; i < 8; i++) //skip seconday language - solved in lang_select (MK3) 'i < 8' for 7 official languages
  3958. #else //XFLASH
  3959. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3960. #endif //XFLASH
  3961. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3962. {
  3963. menu_setlang(i);
  3964. return;
  3965. }
  3966. #ifdef COMMUNITY_LANG_SUPPORT
  3967. #ifdef XFLASH
  3968. MENU_ITEM_SUBMENU_P(_T(MSG_COMMUNITY_MADE), lcd_community_language_menu); ////MSG_COMMUNITY_MADE c=18
  3969. #endif //XFLASH
  3970. #endif //COMMUNITY_LANG_SUPPORT && W52X20CL
  3971. MENU_END();
  3972. }
  3973. #endif //(LANG_MODE != 0)
  3974. void lcd_mesh_bedleveling()
  3975. {
  3976. enquecommand_P(PSTR("G80"));
  3977. lcd_return_to_status();
  3978. }
  3979. void lcd_mesh_calibration()
  3980. {
  3981. enquecommand_P(PSTR("M45"));
  3982. lcd_return_to_status();
  3983. }
  3984. void lcd_mesh_calibration_z()
  3985. {
  3986. enquecommand_P(PSTR("M45 Z"));
  3987. lcd_return_to_status();
  3988. }
  3989. void lcd_pinda_calibration_menu()
  3990. {
  3991. MENU_BEGIN();
  3992. MENU_ITEM_BACK_P(_T(MSG_MENU_CALIBRATION));
  3993. MENU_ITEM_SUBMENU_P(_i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17
  3994. MENU_END();
  3995. }
  3996. void lcd_temp_calibration_set() {
  3997. bool temp_cal_active = eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE);
  3998. temp_cal_active = !temp_cal_active;
  3999. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  4000. }
  4001. #ifdef HAS_SECOND_SERIAL_PORT
  4002. void lcd_second_serial_set() {
  4003. if(selectedSerialPort == 1) selectedSerialPort = 0;
  4004. else selectedSerialPort = 1;
  4005. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  4006. MYSERIAL.begin(BAUDRATE);
  4007. }
  4008. #endif //HAS_SECOND_SERIAL_PORT
  4009. void lcd_calibrate_pinda() {
  4010. enquecommand_P(PSTR("G76"));
  4011. lcd_return_to_status();
  4012. }
  4013. #ifndef SNMM
  4014. /*void lcd_calibrate_extruder() {
  4015. if (degHotend0() > EXTRUDE_MINTEMP)
  4016. {
  4017. current_position[E_AXIS] = 0; //set initial position to zero
  4018. plan_set_e_position(current_position[E_AXIS]);
  4019. //long steps_start = st_get_position(E_AXIS);
  4020. long steps_final;
  4021. float e_steps_per_unit;
  4022. 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)
  4023. 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
  4024. 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
  4025. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  4026. const bool multi_screen = msg_next_e_cal_knob != NULL;
  4027. unsigned long msg_millis;
  4028. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  4029. lcd_clear();
  4030. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  4031. current_position[E_AXIS] += e_shift_calibration;
  4032. plan_buffer_line_curposXYZE(feedrate, active_extruder);
  4033. st_synchronize();
  4034. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  4035. msg_millis = _millis();
  4036. while (!LCD_CLICKED) {
  4037. if (multi_screen && _millis() - msg_millis > 5000) {
  4038. if (msg_next_e_cal_knob == NULL)
  4039. msg_next_e_cal_knob = msg_e_cal_knob;
  4040. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  4041. msg_millis = _millis();
  4042. }
  4043. //manage_inactivity(true);
  4044. manage_heater();
  4045. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  4046. delay_keep_alive(50);
  4047. //previous_millis_cmd = _millis();
  4048. lcd_encoder += (lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  4049. lcd_encoder_diff = 0;
  4050. if (!planner_queue_full()) {
  4051. current_position[E_AXIS] += float(abs((int)lcd_encoder)) * 0.01; //0.05
  4052. lcd_encoder = 0;
  4053. plan_buffer_line_curposXYZE(feedrate, active_extruder);
  4054. }
  4055. }
  4056. }
  4057. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  4058. //steps_final = st_get_position(E_AXIS);
  4059. lcd_draw_update = 1;
  4060. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  4061. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  4062. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  4063. lcd_clear();
  4064. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  4065. enquecommand_P(PSTR("M500")); //store settings to eeprom
  4066. //lcd_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  4067. //delay_keep_alive(2000);
  4068. delay_keep_alive(500);
  4069. 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
  4070. lcd_update_enable(true);
  4071. lcd_draw_update = 2;
  4072. }
  4073. else
  4074. {
  4075. show_preheat_nozzle_warning();
  4076. }
  4077. lcd_return_to_status();
  4078. }
  4079. void lcd_extr_cal_reset() {
  4080. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  4081. axis_steps_per_unit[E_AXIS] = tmp1[3];
  4082. //extrudemultiply = 100;
  4083. enquecommand_P(PSTR("M500"));
  4084. }*/
  4085. #endif
  4086. void lcd_toshiba_flash_air_compatibility_toggle()
  4087. {
  4088. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  4089. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  4090. }
  4091. //! @brief Continue first layer calibration with previous value or start from zero?
  4092. //!
  4093. //! @code{.unparsed}
  4094. //! |01234567890123456789|
  4095. //! |Sheet Smooth1 actual| c=a, c=b, a+b = 13
  4096. //! |Z offset: -1.480 mm | c=a, c=b, a+b = 14
  4097. //! |>Continue | c=19
  4098. //! | Start from zero | c=19
  4099. //! ----------------------
  4100. //! @endcode
  4101. void lcd_first_layer_calibration_reset()
  4102. {
  4103. typedef struct
  4104. {
  4105. bool reset;
  4106. } MenuData;
  4107. static_assert(sizeof(menu_data)>= sizeof(MenuData),"_menu_data_t doesn't fit into menu_data");
  4108. MenuData* menuData = (MenuData*)&(menu_data[0]);
  4109. if(LCD_CLICKED || !eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))) ||
  4110. (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST) ||
  4111. (0 == static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>
  4112. (&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))))
  4113. {
  4114. if (menuData->reset)
  4115. {
  4116. eeprom_update_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset), 0xffff);
  4117. }
  4118. menu_goto(lcd_v2_calibration,0,true,true);
  4119. }
  4120. if (lcd_encoder > 0)
  4121. {
  4122. menuData->reset = true;
  4123. lcd_encoder = 1;
  4124. }
  4125. else if (lcd_encoder < 1)
  4126. {
  4127. menuData->reset = false;
  4128. lcd_encoder = 0;
  4129. }
  4130. char sheet_name[sizeof(Sheet::name)];
  4131. eeprom_read_block(sheet_name, &EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].name, sizeof(Sheet::name));
  4132. lcd_set_cursor(0, 0);
  4133. 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];
  4134. 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
  4135. sheet_name, offset, menuData->reset ? ' ' : '>', menuData->reset ? '>' : ' ');
  4136. }
  4137. void lcd_v2_calibration()
  4138. {
  4139. if (mmu_enabled)
  4140. {
  4141. const uint8_t filament = choose_menu_P(
  4142. _i("Select filament:"), ////MSG_SELECT_FILAMENT c=20
  4143. _T(MSG_FILAMENT),(_T(MSG_CANCEL)+1)); //Hack to reuse MSG but strip 1st char off
  4144. if (filament < 5)
  4145. {
  4146. lay1cal_filament = filament;
  4147. }
  4148. else
  4149. {
  4150. menu_back();
  4151. return;
  4152. }
  4153. }
  4154. else if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  4155. {
  4156. bool loaded = false;
  4157. if (fsensor_enabled && ir_sensor_detected)
  4158. {
  4159. loaded = !READ(IR_SENSOR_PIN);
  4160. }
  4161. else
  4162. {
  4163. loaded = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), false, true);
  4164. lcd_update_enabled = true;
  4165. }
  4166. if (!loaded)
  4167. {
  4168. lcd_display_message_fullscreen_P(_i("Please load filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  4169. lcd_consume_click();
  4170. for (uint_least8_t i = 0; i < 20; i++) { //wait max. 2s
  4171. delay_keep_alive(100);
  4172. if (lcd_clicked()) {
  4173. break;
  4174. }
  4175. }
  4176. lcd_update_enabled = true;
  4177. menu_back();
  4178. return;
  4179. }
  4180. }
  4181. eFilamentAction = FilamentAction::Lay1Cal;
  4182. menu_goto(lcd_generic_preheat_menu, 0, true, true);
  4183. }
  4184. void lcd_wizard() {
  4185. bool result = true;
  4186. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  4187. 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
  4188. }
  4189. if (result) {
  4190. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  4191. lcd_wizard(WizState::Run);
  4192. }
  4193. else {
  4194. lcd_return_to_status();
  4195. lcd_update_enable(true);
  4196. lcd_update(2);
  4197. }
  4198. }
  4199. #if (LANG_MODE != 0)
  4200. void lcd_language()
  4201. {
  4202. lcd_update_enable(true);
  4203. lcd_clear();
  4204. menu_goto(lcd_language_menu, 0, true, true);
  4205. lcd_timeoutToStatus.stop(); //infinite timeout
  4206. lcd_draw_update = 2;
  4207. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  4208. {
  4209. _delay(50);
  4210. lcd_update(0);
  4211. manage_heater();
  4212. manage_inactivity(true);
  4213. }
  4214. if (lang_is_selected())
  4215. lcd_return_to_status();
  4216. else
  4217. lang_select(LANG_ID_PRI);
  4218. }
  4219. #endif
  4220. static void wait_preheat()
  4221. {
  4222. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  4223. plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS] / 60);
  4224. delay_keep_alive(2000);
  4225. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  4226. while (fabs(degHotend(0) - degTargetHotend(0)) > 3) {
  4227. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  4228. lcd_set_cursor(0, 4);
  4229. //Print the hotend temperature (9 chars total)
  4230. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  4231. delay_keep_alive(1000);
  4232. }
  4233. }
  4234. static void lcd_wizard_load()
  4235. {
  4236. if (mmu_enabled)
  4237. {
  4238. 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
  4239. tmp_extruder = 0;
  4240. }
  4241. else
  4242. {
  4243. 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
  4244. }
  4245. lcd_update_enable(false);
  4246. lcd_clear();
  4247. lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
  4248. #ifdef SNMM
  4249. change_extr(0);
  4250. #endif
  4251. loading_flag = true;
  4252. gcode_M701();
  4253. }
  4254. bool lcd_autoDepleteEnabled()
  4255. {
  4256. return (lcd_autoDeplete && fsensor_enabled);
  4257. }
  4258. static void wizard_lay1cal_message(bool cold)
  4259. {
  4260. lcd_show_fullscreen_message_and_wait_P(
  4261. _i("Now I will calibrate distance between tip of the nozzle and heatbed surface.")); ////MSG_WIZARD_V2_CAL c=20 r=8
  4262. if (mmu_enabled)
  4263. {
  4264. lcd_show_fullscreen_message_and_wait_P(
  4265. _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
  4266. }
  4267. else if (cold)
  4268. {
  4269. lcd_show_fullscreen_message_and_wait_P(
  4270. _i("Select temperature which matches your material."));////MSG_SELECT_TEMP_MATCHES_MATERIAL c=20 r=4
  4271. }
  4272. lcd_show_fullscreen_message_and_wait_P(
  4273. _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
  4274. }
  4275. //! @brief Printer first run wizard (Selftest and calibration)
  4276. //!
  4277. //!
  4278. //! First layer calibration with MMU state diagram
  4279. //!
  4280. //! @startuml
  4281. //! [*] --> IsFil
  4282. //! IsFil : Is any filament loaded?
  4283. //! LoadFilCold : Push the button to start loading Filament 1
  4284. //!
  4285. //! IsFil --> Lay1CalCold : yes
  4286. //! IsFil --> LoadFilCold : no
  4287. //! LoadFilCold --> Lay1CalCold : click
  4288. //! @enduml
  4289. //!
  4290. //! First layer calibration without MMU state diagram
  4291. //!
  4292. //! @startuml
  4293. //! [*] --> IsFil
  4294. //! IsFil : Is filament loaded?
  4295. //! Preheat : Select nozle temperature which matches your material.
  4296. //! LoadFilHot : Insert filament to extruder and press the knob.
  4297. //!
  4298. //! IsFil --> Lay1CalCold : yes
  4299. //! IsFil --> Preheat : no
  4300. //! Preheat --> LoadFilHot : select
  4301. //! LoadFilHot --> Lay1CalHot : click
  4302. //! @enduml
  4303. //!
  4304. //! @param state Entry point of the wizard
  4305. //!
  4306. //! state | description
  4307. //! ---------------------- | ----------------
  4308. //! WizState::Run | Main entry point
  4309. //! WizState::RepeatLay1Cal | Entry point after passing 1st layer calibration
  4310. //! WizState::LoadFilHot | Entry point after temporarily left for preheat before load filament
  4311. void lcd_wizard(WizState state)
  4312. {
  4313. using S = WizState;
  4314. bool end = false;
  4315. int8_t wizard_event;
  4316. const char *msg = NULL;
  4317. // Make sure EEPROM_WIZARD_ACTIVE is true if entering using different entry point
  4318. // other than WizState::Run - it is useful for debugging wizard.
  4319. if (state != S::Run) eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  4320. FORCE_BL_ON_START;
  4321. while (!end) {
  4322. printf_P(PSTR("Wizard state: %d\n"), state);
  4323. switch (state) {
  4324. case S::Run: //Run wizard?
  4325. // 2019-08-07 brutal hack - solving the "viper" situation.
  4326. // It is caused by the fact, that tmc2130_st_isr makes a crash detection before the printers really starts.
  4327. // And thus it calles stop_and_save_print_to_ram which sets the saved_printing flag.
  4328. // Having this flag set during normal printing is lethal - mesh_plan_buffer_line exist in the middle of planning long travels
  4329. // which results in distorted print.
  4330. // This primarily happens when the printer is new and parked in 0,0
  4331. // So any new printer will fail the first layer calibration unless being reset or the Stop function gets called.
  4332. // We really must find a way to prevent the crash from happening before the printer is started - that would be the correct solution.
  4333. // 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.
  4334. saved_printing = false;
  4335. if( eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)==2){
  4336. lcd_show_fullscreen_message_and_wait_P(_T(MSG_WIZARD_WELCOME_SHIPPING));
  4337. state = S::Restore;
  4338. } else {
  4339. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_T(MSG_WIZARD_WELCOME), false, true);
  4340. if (wizard_event) {
  4341. state = S::Restore;
  4342. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  4343. } else {
  4344. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  4345. end = true;
  4346. }
  4347. }
  4348. break;
  4349. case S::Restore:
  4350. switch (calibration_status()) {
  4351. case CALIBRATION_STATUS_ASSEMBLED: state = S::Selftest; break; //run selftest
  4352. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = S::Xyz; break; //run xyz cal.
  4353. case CALIBRATION_STATUS_Z_CALIBRATION: state = S::Z; break; //run z cal.
  4354. case CALIBRATION_STATUS_LIVE_ADJUST: state = S::IsFil; break; //run live adjust
  4355. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  4356. default: state = S::Selftest; break; //if calibration status is unknown, run wizard from the beginning
  4357. }
  4358. break;
  4359. case S::Selftest:
  4360. 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
  4361. wizard_event = lcd_selftest();
  4362. if (wizard_event) {
  4363. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  4364. state = S::Xyz;
  4365. }
  4366. else end = true;
  4367. break;
  4368. case S::Xyz:
  4369. 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
  4370. wizard_event = gcode_M45(false, 0);
  4371. if (wizard_event) state = S::IsFil;
  4372. else end = true;
  4373. break;
  4374. case S::Z:
  4375. lcd_show_fullscreen_message_and_wait_P(_i("Please remove shipping helpers first."));////MSG_REMOVE_SHIPPING_HELPERS c=20 r=3
  4376. lcd_show_fullscreen_message_and_wait_P(_i("Now remove the test print from steel sheet."));////MSG_REMOVE_TEST_PRINT c=20 r=4
  4377. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  4378. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  4379. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  4380. wizard_event = gcode_M45(true, 0);
  4381. if (wizard_event) {
  4382. //current filament needs to be unloaded and then new filament should be loaded
  4383. //start to preheat nozzle for unloading remaining PLA filament
  4384. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  4385. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));
  4386. wait_preheat();
  4387. //unload current filament
  4388. unload_filament(true);
  4389. //load filament
  4390. lcd_wizard_load();
  4391. setTargetHotend(0, 0); //we are finished, cooldown nozzle
  4392. state = S::Finish; //shipped, no need to set first layer, go to final message directly
  4393. }
  4394. else end = true;
  4395. break;
  4396. case S::IsFil:
  4397. //start to preheat nozzle and bed to save some time later
  4398. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  4399. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  4400. if (mmu_enabled)
  4401. {
  4402. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), true);
  4403. } else
  4404. {
  4405. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), true);
  4406. }
  4407. if (wizard_event) state = S::Lay1CalCold;
  4408. else
  4409. {
  4410. if(mmu_enabled) state = S::LoadFilCold;
  4411. else state = S::Preheat;
  4412. }
  4413. break;
  4414. case S::Preheat:
  4415. menu_goto(lcd_preheat_menu,0,false,true);
  4416. lcd_show_fullscreen_message_and_wait_P(_i("Select nozzle preheat temperature which matches your material."));////MSG_SEL_PREHEAT_TEMP c=20 r=6
  4417. end = true; // Leave wizard temporarily for lcd_preheat_menu
  4418. break;
  4419. case S::LoadFilHot:
  4420. wait_preheat();
  4421. lcd_wizard_load();
  4422. state = S::Lay1CalHot;
  4423. break;
  4424. case S::LoadFilCold:
  4425. lcd_wizard_load();
  4426. state = S::Lay1CalCold;
  4427. break;
  4428. case S::Lay1CalCold:
  4429. wizard_lay1cal_message(true);
  4430. menu_goto(lcd_v2_calibration,0,false,true);
  4431. end = true; // Leave wizard temporarily for lcd_v2_calibration
  4432. break;
  4433. case S::Lay1CalHot:
  4434. wizard_lay1cal_message(false);
  4435. lcd_commands_type = LcdCommands::Layer1Cal;
  4436. end = true; // Leave wizard temporarily for lcd_v2_calibration
  4437. break;
  4438. case S::RepeatLay1Cal:
  4439. 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
  4440. if (wizard_event)
  4441. {
  4442. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  4443. state = S::Lay1CalCold;
  4444. }
  4445. else
  4446. {
  4447. 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
  4448. state = S::Finish;
  4449. }
  4450. break;
  4451. case S::Finish:
  4452. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  4453. end = true;
  4454. break;
  4455. default: break;
  4456. }
  4457. }
  4458. FORCE_BL_ON_END;
  4459. printf_P(_N("Wizard end state: %d\n"), state);
  4460. switch (state) { //final message
  4461. case S::Restore: //printer was already calibrated
  4462. msg = _T(MSG_WIZARD_DONE);
  4463. break;
  4464. case S::Selftest: //selftest
  4465. case S::Xyz: //xyz cal.
  4466. case S::Z: //z cal.
  4467. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  4468. break;
  4469. case S::Finish: //we are finished
  4470. msg = _T(MSG_WIZARD_DONE);
  4471. lcd_reset_alert_level();
  4472. lcd_setstatuspgm(MSG_WELCOME);
  4473. lcd_return_to_status();
  4474. break;
  4475. default:
  4476. msg = _T(MSG_WIZARD_QUIT);
  4477. break;
  4478. }
  4479. if (!((S::Lay1CalCold == state) || (S::Lay1CalHot == state) || (S::Preheat == state)))
  4480. {
  4481. lcd_show_fullscreen_message_and_wait_P(msg);
  4482. }
  4483. lcd_update_enable(true);
  4484. lcd_update(2);
  4485. }
  4486. #ifdef TMC2130
  4487. void lcd_settings_linearity_correction_menu(void)
  4488. {
  4489. MENU_BEGIN();
  4490. ON_MENU_LEAVE(
  4491. lcd_settings_linearity_correction_menu_save();
  4492. );
  4493. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  4494. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  4495. //tmc2130_wave_fac[X_AXIS]
  4496. 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
  4497. 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
  4498. 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
  4499. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  4500. 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
  4501. MENU_END();
  4502. }
  4503. #endif // TMC2130
  4504. #ifdef FILAMENT_SENSOR
  4505. #define SETTINGS_FILAMENT_SENSOR \
  4506. do\
  4507. {\
  4508. if (FSensorStateMenu == 0)\
  4509. {\
  4510. if (fsensor_not_responding && (mmu_enabled == false))\
  4511. {\
  4512. /* Filament sensor not working*/\
  4513. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_NA), lcd_fsensor_state_set);/*////MSG_FSENSOR_NA*/\
  4514. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), NULL, lcd_fsensor_fail);\
  4515. }\
  4516. else\
  4517. {\
  4518. /* Filament sensor turned off, working, no problems*/\
  4519. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_OFF), lcd_fsensor_state_set);\
  4520. if (mmu_enabled == false)\
  4521. {\
  4522. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), NULL, lcd_filament_autoload_info);\
  4523. }\
  4524. }\
  4525. }\
  4526. else\
  4527. {\
  4528. /* Filament sensor turned on, working, no problems*/\
  4529. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_ON), lcd_fsensor_state_set);\
  4530. if (mmu_enabled == false)\
  4531. {\
  4532. if (fsensor_autoload_enabled)\
  4533. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_ON), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_ON c=17*/\
  4534. else\
  4535. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_OFF), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_OFF c=17*/\
  4536. /*if (fsensor_oq_meassure_enabled)*/\
  4537. /*MENU_ITEM_FUNCTION_P(_i("F. OQ meass. [on]"), lcd_set_filament_oq_meass);*//*////MSG_FSENS_OQMEASS_ON c=17*/\
  4538. /*else*/\
  4539. /*MENU_ITEM_FUNCTION_P(_i("F. OQ meass.[off]"), lcd_set_filament_oq_meass);*//*////MSG_FSENS_OQMEASS_OFF c=17*/\
  4540. }\
  4541. }\
  4542. }\
  4543. while(0)
  4544. #else //FILAMENT_SENSOR
  4545. #define SETTINGS_FILAMENT_SENSOR do{}while(0)
  4546. #endif //FILAMENT_SENSOR
  4547. static void auto_deplete_switch()
  4548. {
  4549. lcd_autoDeplete = !lcd_autoDeplete;
  4550. eeprom_update_byte((unsigned char *)EEPROM_AUTO_DEPLETE, lcd_autoDeplete);
  4551. }
  4552. static void settingsAutoDeplete()
  4553. {
  4554. if (mmu_enabled)
  4555. {
  4556. if (!fsensor_enabled)
  4557. {
  4558. MENU_ITEM_TOGGLE_P(_T(MSG_AUTO_DEPLETE), _T(MSG_NA), NULL);
  4559. }
  4560. else if (lcd_autoDeplete)
  4561. {
  4562. MENU_ITEM_TOGGLE_P(_T(MSG_AUTO_DEPLETE), _T(MSG_ON), auto_deplete_switch);
  4563. }
  4564. else
  4565. {
  4566. MENU_ITEM_TOGGLE_P(_T(MSG_AUTO_DEPLETE), _T(MSG_OFF), auto_deplete_switch);
  4567. }
  4568. }
  4569. }
  4570. #define SETTINGS_AUTO_DEPLETE \
  4571. do\
  4572. {\
  4573. settingsAutoDeplete();\
  4574. }\
  4575. while(0)\
  4576. #ifdef MMU_HAS_CUTTER
  4577. static void settingsCutter()
  4578. {
  4579. if (mmu_enabled)
  4580. {
  4581. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  4582. {
  4583. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_ON), lcd_cutter_enabled);
  4584. }
  4585. #ifdef MMU_ALWAYS_CUT
  4586. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  4587. {
  4588. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _i("Always"), lcd_cutter_enabled);
  4589. }
  4590. #endif
  4591. else
  4592. {
  4593. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_OFF), lcd_cutter_enabled);
  4594. }
  4595. }
  4596. }
  4597. #define SETTINGS_CUTTER \
  4598. do\
  4599. {\
  4600. settingsCutter();\
  4601. }\
  4602. while(0)
  4603. #else
  4604. #define SETTINGS_CUTTER
  4605. #endif //MMU_HAS_CUTTER
  4606. #ifdef TMC2130
  4607. #define SETTINGS_SILENT_MODE \
  4608. do\
  4609. {\
  4610. if(!farm_mode)\
  4611. {\
  4612. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4613. {\
  4614. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\
  4615. }\
  4616. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);\
  4617. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4618. {\
  4619. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);\
  4620. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);\
  4621. }\
  4622. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);\
  4623. }\
  4624. }\
  4625. while (0)
  4626. #else //TMC2130
  4627. #define SETTINGS_SILENT_MODE \
  4628. do\
  4629. {\
  4630. if(!farm_mode)\
  4631. {\
  4632. switch (SilentModeMenu)\
  4633. {\
  4634. case SILENT_MODE_POWER:\
  4635. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  4636. break;\
  4637. case SILENT_MODE_SILENT:\
  4638. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set);\
  4639. break;\
  4640. case SILENT_MODE_AUTO:\
  4641. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set);\
  4642. break;\
  4643. default:\
  4644. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  4645. break; /* (probably) not needed*/\
  4646. }\
  4647. }\
  4648. }\
  4649. while (0)
  4650. #endif //TMC2130
  4651. #ifndef MMU_FORCE_STEALTH_MODE
  4652. #define SETTINGS_MMU_MODE \
  4653. do\
  4654. {\
  4655. if (mmu_enabled)\
  4656. {\
  4657. if (SilentModeMenu_MMU == 0) MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_NORMAL), lcd_silent_mode_mmu_set);\
  4658. else MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_STEALTH), lcd_silent_mode_mmu_set);\
  4659. }\
  4660. }\
  4661. while (0)
  4662. #else //MMU_FORCE_STEALTH_MODE
  4663. #define SETTINGS_MMU_MODE
  4664. #endif //MMU_FORCE_STEALTH_MODE
  4665. #ifdef SDCARD_SORT_ALPHA
  4666. #define SETTINGS_SD \
  4667. do\
  4668. {\
  4669. if (card.ToshibaFlashAir_isEnabled())\
  4670. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY), lcd_toshiba_flash_air_compatibility_toggle);\
  4671. else\
  4672. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_NORMAL), lcd_toshiba_flash_air_compatibility_toggle);\
  4673. \
  4674. uint8_t sdSort;\
  4675. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));\
  4676. switch (sdSort)\
  4677. {\
  4678. case SD_SORT_TIME: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_TIME), lcd_sort_type_set); break;\
  4679. case SD_SORT_ALPHA: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_ALPHA), lcd_sort_type_set); break;\
  4680. default: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_NONE), lcd_sort_type_set);\
  4681. }\
  4682. }\
  4683. while (0)
  4684. #else // SDCARD_SORT_ALPHA
  4685. #define SETTINGS_SD \
  4686. do\
  4687. {\
  4688. if (card.ToshibaFlashAir_isEnabled())\
  4689. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY), lcd_toshiba_flash_air_compatibility_toggle);\
  4690. else\
  4691. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_NORMAL), lcd_toshiba_flash_air_compatibility_toggle);\
  4692. }\
  4693. while (0)
  4694. #endif // SDCARD_SORT_ALPHA
  4695. /*
  4696. #define SETTINGS_MBL_MODE \
  4697. do\
  4698. {\
  4699. switch(e_mbl_type)\
  4700. {\
  4701. case e_MBL_FAST:\
  4702. MENU_ITEM_FUNCTION_P(_i("Mode [Fast]"),mbl_mode_set);\
  4703. break; \
  4704. case e_MBL_OPTIMAL:\
  4705. MENU_ITEM_FUNCTION_P(_i("Mode [Optimal]"), mbl_mode_set); \
  4706. break; \
  4707. case e_MBL_PREC:\
  4708. MENU_ITEM_FUNCTION_P(_i("Mode [Precise]"), mbl_mode_set); \
  4709. break; \
  4710. default:\
  4711. MENU_ITEM_FUNCTION_P(_i("Mode [Optimal]"), mbl_mode_set); \
  4712. break; \
  4713. }\
  4714. }\
  4715. while (0)
  4716. */
  4717. #define SETTINGS_SOUND \
  4718. do\
  4719. {\
  4720. switch(eSoundMode)\
  4721. {\
  4722. case e_SOUND_MODE_LOUD:\
  4723. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  4724. break;\
  4725. case e_SOUND_MODE_ONCE:\
  4726. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_ONCE), lcd_sound_state_set);\
  4727. break;\
  4728. case e_SOUND_MODE_SILENT:\
  4729. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SILENT), lcd_sound_state_set);\
  4730. break;\
  4731. case e_SOUND_MODE_BLIND:\
  4732. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_BLIND), lcd_sound_state_set);\
  4733. break;\
  4734. default:\
  4735. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  4736. }\
  4737. }\
  4738. while (0)
  4739. //-//
  4740. static void lcd_check_mode_set(void)
  4741. {
  4742. switch(oCheckMode)
  4743. {
  4744. case ClCheckMode::_None:
  4745. oCheckMode=ClCheckMode::_Warn;
  4746. break;
  4747. case ClCheckMode::_Warn:
  4748. oCheckMode=ClCheckMode::_Strict;
  4749. break;
  4750. case ClCheckMode::_Strict:
  4751. oCheckMode=ClCheckMode::_None;
  4752. break;
  4753. default:
  4754. oCheckMode=ClCheckMode::_None;
  4755. }
  4756. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)oCheckMode);
  4757. }
  4758. #define SETTINGS_MODE \
  4759. do\
  4760. {\
  4761. switch(oCheckMode)\
  4762. {\
  4763. case ClCheckMode::_None:\
  4764. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  4765. break;\
  4766. case ClCheckMode::_Warn:\
  4767. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_WARN), lcd_check_mode_set);\
  4768. break;\
  4769. case ClCheckMode::_Strict:\
  4770. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_STRICT), lcd_check_mode_set);\
  4771. break;\
  4772. default:\
  4773. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  4774. }\
  4775. }\
  4776. while (0)
  4777. static void lcd_nozzle_diameter_cycle(void) {
  4778. uint16_t nDiameter;
  4779. switch(oNozzleDiameter){
  4780. case ClNozzleDiameter::_Diameter_250:
  4781. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4782. nDiameter=400;
  4783. break;
  4784. case ClNozzleDiameter::_Diameter_400:
  4785. oNozzleDiameter=ClNozzleDiameter::_Diameter_600;
  4786. nDiameter=600;
  4787. break;
  4788. case ClNozzleDiameter::_Diameter_600:
  4789. oNozzleDiameter=ClNozzleDiameter::_Diameter_800;
  4790. nDiameter=800;
  4791. break;
  4792. case ClNozzleDiameter::_Diameter_800:
  4793. oNozzleDiameter=ClNozzleDiameter::_Diameter_250;
  4794. nDiameter=250;
  4795. break;
  4796. default:
  4797. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4798. nDiameter=400;
  4799. }
  4800. eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)oNozzleDiameter);
  4801. eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter);
  4802. }
  4803. #define SETTINGS_NOZZLE \
  4804. do\
  4805. {\
  4806. float fNozzleDiam;\
  4807. switch(oNozzleDiameter)\
  4808. {\
  4809. case ClNozzleDiameter::_Diameter_250: fNozzleDiam = 0.25f; break;\
  4810. case ClNozzleDiameter::_Diameter_400: fNozzleDiam = 0.4f; break;\
  4811. case ClNozzleDiameter::_Diameter_600: fNozzleDiam = 0.6f; break;\
  4812. case ClNozzleDiameter::_Diameter_800: fNozzleDiam = 0.8f; break;\
  4813. default: fNozzleDiam = 0.4f; break;\
  4814. }\
  4815. MENU_ITEM_TOGGLE(_T(MSG_NOZZLE_DIAMETER), ftostr12ns(fNozzleDiam), lcd_nozzle_diameter_cycle);\
  4816. }\
  4817. while (0)
  4818. static void lcd_check_model_set(void)
  4819. {
  4820. switch(oCheckModel)
  4821. {
  4822. case ClCheckModel::_None:
  4823. oCheckModel=ClCheckModel::_Warn;
  4824. break;
  4825. case ClCheckModel::_Warn:
  4826. oCheckModel=ClCheckModel::_Strict;
  4827. break;
  4828. case ClCheckModel::_Strict:
  4829. oCheckModel=ClCheckModel::_None;
  4830. break;
  4831. default:
  4832. oCheckModel=ClCheckModel::_None;
  4833. }
  4834. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODEL,(uint8_t)oCheckModel);
  4835. }
  4836. #define SETTINGS_MODEL \
  4837. do\
  4838. {\
  4839. switch(oCheckModel)\
  4840. {\
  4841. case ClCheckModel::_None:\
  4842. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4843. break;\
  4844. case ClCheckModel::_Warn:\
  4845. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_WARN), lcd_check_model_set);\
  4846. break;\
  4847. case ClCheckModel::_Strict:\
  4848. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_STRICT), lcd_check_model_set);\
  4849. break;\
  4850. default:\
  4851. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4852. }\
  4853. }\
  4854. while (0)
  4855. static void lcd_check_version_set(void)
  4856. {
  4857. switch(oCheckVersion)
  4858. {
  4859. case ClCheckVersion::_None:
  4860. oCheckVersion=ClCheckVersion::_Warn;
  4861. break;
  4862. case ClCheckVersion::_Warn:
  4863. oCheckVersion=ClCheckVersion::_Strict;
  4864. break;
  4865. case ClCheckVersion::_Strict:
  4866. oCheckVersion=ClCheckVersion::_None;
  4867. break;
  4868. default:
  4869. oCheckVersion=ClCheckVersion::_None;
  4870. }
  4871. eeprom_update_byte((uint8_t*)EEPROM_CHECK_VERSION,(uint8_t)oCheckVersion);
  4872. }
  4873. #define SETTINGS_VERSION \
  4874. do\
  4875. {\
  4876. switch(oCheckVersion)\
  4877. {\
  4878. case ClCheckVersion::_None:\
  4879. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_NONE), lcd_check_version_set);\
  4880. break;\
  4881. case ClCheckVersion::_Warn:\
  4882. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_WARN), lcd_check_version_set);\
  4883. break;\
  4884. case ClCheckVersion::_Strict:\
  4885. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_STRICT), lcd_check_version_set);\
  4886. break;\
  4887. default:\
  4888. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_NONE), lcd_check_version_set);\
  4889. }\
  4890. }\
  4891. while (0)
  4892. #if 0 // temporarily unused
  4893. static void lcd_check_gcode_set(void)
  4894. {
  4895. switch(oCheckGcode)
  4896. {
  4897. case ClCheckGcode::_None:
  4898. oCheckGcode=ClCheckGcode::_Warn;
  4899. break;
  4900. case ClCheckGcode::_Warn:
  4901. oCheckGcode=ClCheckGcode::_Strict;
  4902. break;
  4903. case ClCheckGcode::_Strict:
  4904. oCheckGcode=ClCheckGcode::_None;
  4905. break;
  4906. default:
  4907. oCheckGcode=ClCheckGcode::_None;
  4908. }
  4909. eeprom_update_byte((uint8_t*)EEPROM_CHECK_GCODE,(uint8_t)oCheckGcode);
  4910. }
  4911. #endif
  4912. #define SETTINGS_GCODE \
  4913. do\
  4914. {\
  4915. switch(oCheckGcode)\
  4916. {\
  4917. case ClCheckGcode::_None:\
  4918. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_NONE), lcd_check_gcode_set);\
  4919. break;\
  4920. case ClCheckGcode::_Warn:\
  4921. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_WARN), lcd_check_gcode_set);\
  4922. break;\
  4923. case ClCheckGcode::_Strict:\
  4924. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_STRICT), lcd_check_gcode_set);\
  4925. break;\
  4926. default:\
  4927. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_NONE), lcd_check_gcode_set);\
  4928. }\
  4929. }\
  4930. while (0)
  4931. static void lcd_checking_menu(void)
  4932. {
  4933. MENU_BEGIN();
  4934. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4935. SETTINGS_MODE;
  4936. SETTINGS_MODEL;
  4937. SETTINGS_VERSION;
  4938. //-// temporarily disabled
  4939. //SETTINGS_GCODE;
  4940. MENU_END();
  4941. }
  4942. #ifdef IR_SENSOR_ANALOG
  4943. static void lcd_fsensor_actionNA_set(void)
  4944. {
  4945. switch(oFsensorActionNA)
  4946. {
  4947. case ClFsensorActionNA::_Continue:
  4948. oFsensorActionNA=ClFsensorActionNA::_Pause;
  4949. break;
  4950. case ClFsensorActionNA::_Pause:
  4951. oFsensorActionNA=ClFsensorActionNA::_Continue;
  4952. break;
  4953. default:
  4954. oFsensorActionNA=ClFsensorActionNA::_Continue;
  4955. }
  4956. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_ACTION_NA,(uint8_t)oFsensorActionNA);
  4957. }
  4958. #define FSENSOR_ACTION_NA \
  4959. do\
  4960. {\
  4961. switch(oFsensorActionNA)\
  4962. {\
  4963. case ClFsensorActionNA::_Continue:\
  4964. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_CONTINUE), lcd_fsensor_actionNA_set);\
  4965. break;\
  4966. case ClFsensorActionNA::_Pause:\
  4967. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_PAUSE), lcd_fsensor_actionNA_set);\
  4968. break;\
  4969. default:\
  4970. oFsensorActionNA=ClFsensorActionNA::_Continue;\
  4971. }\
  4972. }\
  4973. while (0)
  4974. #endif //IR_SENSOR_ANALOG
  4975. template <uint8_t number>
  4976. static void select_sheet_menu()
  4977. {
  4978. selected_sheet = number;
  4979. lcd_sheet_menu();
  4980. }
  4981. static void sheets_menu()
  4982. {
  4983. MENU_BEGIN();
  4984. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4985. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[0], select_sheet_menu<0>);
  4986. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[1], select_sheet_menu<1>);
  4987. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[2], select_sheet_menu<2>);
  4988. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[3], select_sheet_menu<3>);
  4989. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[4], select_sheet_menu<4>);
  4990. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[5], select_sheet_menu<5>);
  4991. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[6], select_sheet_menu<6>);
  4992. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[7], select_sheet_menu<7>);
  4993. MENU_END();
  4994. }
  4995. void lcd_hw_setup_menu(void) // can not be "static"
  4996. {
  4997. typedef struct
  4998. {// 2bytes total
  4999. int8_t status;
  5000. uint8_t experimental_menu_visibility;
  5001. } _menu_data_t;
  5002. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  5003. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  5004. if (_md->status == 0 || lcd_draw_update)
  5005. {
  5006. _md->status = 1;
  5007. _md->experimental_menu_visibility = eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  5008. if (_md->experimental_menu_visibility == EEPROM_EMPTY_VALUE)
  5009. {
  5010. _md->experimental_menu_visibility = 0;
  5011. eeprom_update_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, _md->experimental_menu_visibility);
  5012. }
  5013. }
  5014. MENU_BEGIN();
  5015. MENU_ITEM_BACK_P(_T(bSettings?MSG_SETTINGS:MSG_BACK)); // i.e. default menu-item / menu-item after checking mismatch
  5016. MENU_ITEM_SUBMENU_P(_T(MSG_STEEL_SHEETS), sheets_menu);
  5017. SETTINGS_NOZZLE;
  5018. MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu); ////MSG_CHECKS c=18
  5019. #ifdef IR_SENSOR_ANALOG
  5020. FSENSOR_ACTION_NA;
  5021. //! Fsensor Detection isn't ready for mmu yet it is temporarily disabled.
  5022. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  5023. if(!mmu_enabled) MENU_ITEM_FUNCTION_P(PSTR("Fsensor Detection"), lcd_detect_IRsensor);
  5024. #endif //IR_SENSOR_ANALOG
  5025. if (_md->experimental_menu_visibility)
  5026. {
  5027. MENU_ITEM_SUBMENU_P(PSTR("Experimental"), lcd_experimental_menu);////MSG_MENU_EXPERIMENTAL c=18
  5028. }
  5029. #ifdef PINDA_TEMP_COMP
  5030. //! The SuperPINDA is detected when the PINDA temp is below its defined limit.
  5031. //! This works well on the EINSY board but not on the miniRAMBo board as
  5032. //! as a disconnected SuperPINDA will show higher temps compared to an EINSY board.
  5033. //!
  5034. //! This menu allows the user to en-/disable the SuperPINDA manualy
  5035. 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);
  5036. #endif //PINDA_TEMP_COMP
  5037. MENU_END();
  5038. }
  5039. static void lcd_settings_menu()
  5040. {
  5041. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  5042. MENU_BEGIN();
  5043. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5044. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=18
  5045. if (!PRINTER_ACTIVE || isPrintPaused)
  5046. {
  5047. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_axis);////MSG_MOVE_AXIS c=18
  5048. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18
  5049. }
  5050. SETTINGS_FILAMENT_SENSOR;
  5051. SETTINGS_AUTO_DEPLETE;
  5052. SETTINGS_CUTTER;
  5053. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  5054. SETTINGS_SILENT_MODE;
  5055. if(!farm_mode)
  5056. {
  5057. bSettings=true; // flag ('fake parameter') for 'lcd_hw_setup_menu()' function
  5058. MENU_ITEM_SUBMENU_P(_T(MSG_HW_SETUP), lcd_hw_setup_menu);
  5059. }
  5060. SETTINGS_MMU_MODE;
  5061. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bed_leveling_settings);
  5062. #if defined (TMC2130) && defined (LINEARITY_CORRECTION)
  5063. MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu);////MSG_LIN_CORRECTION c=18
  5064. #endif //LINEARITY_CORRECTION && TMC2130
  5065. if(has_temperature_compensation())
  5066. {
  5067. 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);
  5068. }
  5069. #ifdef HAS_SECOND_SERIAL_PORT
  5070. MENU_ITEM_TOGGLE_P(_T(MSG_RPI_PORT), (selectedSerialPort == 0) ? _T(MSG_OFF) : _T(MSG_ON), lcd_second_serial_set);
  5071. #endif //HAS_SECOND_SERIAL
  5072. if (!isPrintPaused && !homing_flag && !mesh_bed_leveling_flag)
  5073. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  5074. #if (LANG_MODE != 0)
  5075. MENU_ITEM_SUBMENU_P(_i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=18
  5076. #endif //(LANG_MODE != 0)
  5077. SETTINGS_SD;
  5078. SETTINGS_SOUND;
  5079. #ifdef LCD_BL_PIN
  5080. if (backlightSupport)
  5081. {
  5082. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  5083. }
  5084. #endif //LCD_BL_PIN
  5085. if (farm_mode)
  5086. {
  5087. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  5088. }
  5089. MENU_END();
  5090. }
  5091. #ifdef TMC2130
  5092. static void lcd_ustep_linearity_menu_save()
  5093. {
  5094. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  5095. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  5096. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  5097. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  5098. }
  5099. #endif //TMC2130
  5100. #ifdef TMC2130
  5101. static void lcd_settings_linearity_correction_menu_save()
  5102. {
  5103. bool changed = false;
  5104. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  5105. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  5106. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  5107. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  5108. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  5109. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  5110. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  5111. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  5112. lcd_ustep_linearity_menu_save();
  5113. if (changed) tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  5114. }
  5115. #endif //TMC2130
  5116. static void lcd_calibration_menu()
  5117. {
  5118. MENU_BEGIN();
  5119. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5120. if (!isPrintPaused)
  5121. {
  5122. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17
  5123. if (lcd_commands_type == LcdCommands::Idle)
  5124. {
  5125. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_first_layer_calibration_reset);////MSG_V2_CALIBRATION c=18
  5126. }
  5127. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  5128. #ifdef TMC2130
  5129. MENU_ITEM_FUNCTION_P(_i("Belt test"), lcd_belttest_v);////MSG_BELTTEST c=18
  5130. #endif //TMC2130
  5131. MENU_ITEM_FUNCTION_P(_i("Selftest"), lcd_selftest_v);////MSG_SELFTEST c=18
  5132. #ifdef MK1BP
  5133. // MK1
  5134. // "Calibrate Z"
  5135. MENU_ITEM_GCODE_P(_T(MSG_HOMEYZ), PSTR("G28 Z"));
  5136. #else //MK1BP
  5137. // MK2
  5138. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=18
  5139. // "Calibrate Z" with storing the reference values to EEPROM.
  5140. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  5141. #ifndef SNMM
  5142. //MENU_ITEM_FUNCTION_P(_i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20
  5143. #endif
  5144. // "Mesh Bed Leveling"
  5145. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bedleveling);
  5146. #endif //MK1BP
  5147. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=18
  5148. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17
  5149. #ifndef TMC2130
  5150. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=18
  5151. #endif
  5152. #ifndef MK1BP
  5153. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=18
  5154. #endif //MK1BP
  5155. #ifndef SNMM
  5156. //MENU_ITEM_FUNCTION_P(MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  5157. #endif
  5158. #ifndef MK1BP
  5159. if(has_temperature_compensation())
  5160. {
  5161. MENU_ITEM_SUBMENU_P(_i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17
  5162. }
  5163. #endif //MK1BP
  5164. }
  5165. MENU_END();
  5166. }
  5167. void bowden_menu() {
  5168. int enc_dif = lcd_encoder_diff;
  5169. int cursor_pos = 0;
  5170. lcd_clear();
  5171. lcd_putc_at(0, 0, '>');
  5172. for (uint_least8_t i = 0; i < 4; i++) {
  5173. lcd_puts_at_P(1, i, PSTR("Extruder "));
  5174. lcd_print(i);
  5175. lcd_print(": ");
  5176. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  5177. lcd_print(bowden_length[i] - 48);
  5178. }
  5179. enc_dif = lcd_encoder_diff;
  5180. lcd_consume_click();
  5181. while (1) {
  5182. manage_heater();
  5183. manage_inactivity(true);
  5184. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5185. if (enc_dif > lcd_encoder_diff) {
  5186. cursor_pos--;
  5187. }
  5188. if (enc_dif < lcd_encoder_diff) {
  5189. cursor_pos++;
  5190. }
  5191. if (cursor_pos > 3) {
  5192. cursor_pos = 3;
  5193. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5194. }
  5195. if (cursor_pos < 0) {
  5196. cursor_pos = 0;
  5197. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5198. }
  5199. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  5200. lcd_putc_at(0, cursor_pos, '>');
  5201. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5202. enc_dif = lcd_encoder_diff;
  5203. _delay(100);
  5204. }
  5205. if (lcd_clicked()) {
  5206. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5207. lcd_clear();
  5208. while (1) {
  5209. manage_heater();
  5210. manage_inactivity(true);
  5211. lcd_puts_at_P(1, 1, PSTR("Extruder "));
  5212. lcd_print(cursor_pos);
  5213. lcd_print(": ");
  5214. lcd_set_cursor(13, 1);
  5215. lcd_print(bowden_length[cursor_pos] - 48);
  5216. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5217. if (enc_dif > lcd_encoder_diff) {
  5218. bowden_length[cursor_pos]--;
  5219. lcd_set_cursor(13, 1);
  5220. lcd_print(bowden_length[cursor_pos] - 48);
  5221. enc_dif = lcd_encoder_diff;
  5222. }
  5223. if (enc_dif < lcd_encoder_diff) {
  5224. bowden_length[cursor_pos]++;
  5225. lcd_set_cursor(13, 1);
  5226. lcd_print(bowden_length[cursor_pos] - 48);
  5227. enc_dif = lcd_encoder_diff;
  5228. }
  5229. }
  5230. _delay(100);
  5231. if (lcd_clicked()) {
  5232. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5233. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  5234. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  5235. lcd_update_enable(true);
  5236. lcd_clear();
  5237. enc_dif = lcd_encoder_diff;
  5238. lcd_putc_at(0, cursor_pos, '>');
  5239. for (uint_least8_t i = 0; i < 4; i++) {
  5240. lcd_puts_at_P(1, i, PSTR("Extruder "));
  5241. lcd_print(i);
  5242. lcd_print(": ");
  5243. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  5244. lcd_print(bowden_length[i] - 48);
  5245. }
  5246. break;
  5247. }
  5248. else return;
  5249. }
  5250. }
  5251. }
  5252. }
  5253. }
  5254. #ifdef SNMM
  5255. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  5256. lcd_clear();
  5257. lcd_puts_at_P(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd_print(':');
  5258. lcd_set_cursor(0, 1); lcd_print('>');
  5259. lcd_puts_at_P(1,2,_i("Used during print"));////MSG_USED c=19
  5260. lcd_puts_at_P(1,3,_i("Current"));////MSG_CURRENT c=19
  5261. char cursor_pos = 1;
  5262. int enc_dif = 0;
  5263. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5264. lcd_consume_click();
  5265. while (1) {
  5266. manage_heater();
  5267. manage_inactivity(true);
  5268. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  5269. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  5270. if (enc_dif > lcd_encoder_diff) cursor_pos--;
  5271. if (enc_dif < lcd_encoder_diff) cursor_pos++;
  5272. if (cursor_pos > 3) {
  5273. cursor_pos = 3;
  5274. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5275. }
  5276. if (cursor_pos < 1){
  5277. cursor_pos = 1;
  5278. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5279. }
  5280. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  5281. lcd_set_cursor(0, cursor_pos);
  5282. lcd_print('>');
  5283. enc_dif = lcd_encoder_diff;
  5284. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5285. _delay(100);
  5286. }
  5287. }
  5288. if (lcd_clicked()) {
  5289. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5290. KEEPALIVE_STATE(IN_HANDLER);
  5291. return(cursor_pos - 1);
  5292. }
  5293. }
  5294. }
  5295. #endif //SNMM
  5296. //! @brief Select one of numbered items
  5297. //!
  5298. //! Create list of items with header. Header can not be selected.
  5299. //! Each item has text description passed by function parameter and
  5300. //! number. There are 5 numbered items, if mmu_enabled, 4 otherwise.
  5301. //! Items are numbered from 1 to 4 or 5. But index returned starts at 0.
  5302. //! There can be last item with different text and no number.
  5303. //!
  5304. //! @param header Header text
  5305. //! @param item Item text
  5306. //! @param last_item Last item text, or nullptr if there is no Last item
  5307. //! @return selected item index, first item index is 0
  5308. uint8_t choose_menu_P(const char *header, const char *item, const char *last_item)
  5309. {
  5310. //following code should handle 3 to 127 number of items well
  5311. const int8_t items_no = last_item?(mmu_enabled?6:5):(mmu_enabled?5:4);
  5312. const uint8_t item_len = item?strlen_P(item):0;
  5313. int8_t first = 0;
  5314. int8_t enc_dif = lcd_encoder_diff;
  5315. int8_t cursor_pos = 1;
  5316. lcd_clear();
  5317. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5318. while (1)
  5319. {
  5320. manage_heater();
  5321. manage_inactivity(true);
  5322. if (abs((enc_dif - lcd_encoder_diff)) > 4)
  5323. {
  5324. if (enc_dif > lcd_encoder_diff)
  5325. {
  5326. cursor_pos--;
  5327. }
  5328. if (enc_dif < lcd_encoder_diff)
  5329. {
  5330. cursor_pos++;
  5331. }
  5332. enc_dif = lcd_encoder_diff;
  5333. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5334. }
  5335. if (cursor_pos > 3)
  5336. {
  5337. cursor_pos = 3;
  5338. if (first < items_no - 3)
  5339. {
  5340. first++;
  5341. lcd_clear();
  5342. } else { // here we are at the very end of the list
  5343. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5344. }
  5345. }
  5346. if (cursor_pos < 1)
  5347. {
  5348. cursor_pos = 1;
  5349. if (first > 0)
  5350. {
  5351. first--;
  5352. lcd_clear();
  5353. } else { // here we are at the very end of the list
  5354. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5355. }
  5356. }
  5357. if (header) lcd_puts_at_P(0,0,header);
  5358. const bool last_visible = (first == items_no - 3);
  5359. const uint_least8_t ordinary_items = (last_item&&last_visible)?2:3;
  5360. for (uint_least8_t i = 0; i < ordinary_items; i++)
  5361. {
  5362. if (item) lcd_puts_at_P(1, i + 1, item);
  5363. }
  5364. for (uint_least8_t i = 0; i < ordinary_items; i++)
  5365. {
  5366. lcd_set_cursor(2 + item_len, i+1);
  5367. lcd_print(first + i + 1);
  5368. }
  5369. if (last_item&&last_visible) lcd_puts_at_P(1, 3, last_item);
  5370. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  5371. lcd_putc_at(0, cursor_pos, '>');
  5372. _delay(100);
  5373. if (lcd_clicked())
  5374. {
  5375. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5376. KEEPALIVE_STATE(IN_HANDLER);
  5377. lcd_encoder_diff = 0;
  5378. return(cursor_pos + first - 1);
  5379. }
  5380. }
  5381. }
  5382. char reset_menu() {
  5383. const uint8_t items_no =
  5384. #ifdef SNMM
  5385. 6;
  5386. #else
  5387. 5;
  5388. #endif
  5389. static int8_t first = 0;
  5390. int8_t enc_dif = 0;
  5391. char cursor_pos = 0;
  5392. const char *const item[items_no] = {PSTR("Language"), PSTR("Statistics"), PSTR("Shipping prep"), PSTR("Service prep"), PSTR("All Data")
  5393. #ifdef SNMM
  5394. , PSTR("Bowden length")
  5395. #endif
  5396. };
  5397. enc_dif = lcd_encoder_diff;
  5398. lcd_clear();
  5399. lcd_set_cursor(0, 0);
  5400. lcd_putc('>');
  5401. lcd_consume_click();
  5402. while (1) {
  5403. for (uint_least8_t i = 0; i < 4; i++) {
  5404. lcd_puts_at_P(1, i, item[first + i]);
  5405. }
  5406. manage_heater();
  5407. manage_inactivity(true);
  5408. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  5409. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  5410. if (enc_dif > lcd_encoder_diff) {
  5411. cursor_pos--;
  5412. }
  5413. if (enc_dif < lcd_encoder_diff) {
  5414. cursor_pos++;
  5415. }
  5416. if (cursor_pos > 3) {
  5417. cursor_pos = 3;
  5418. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5419. if (first < items_no - 4) {
  5420. first++;
  5421. lcd_clear();
  5422. }
  5423. }
  5424. if (cursor_pos < 0) {
  5425. cursor_pos = 0;
  5426. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5427. if (first > 0) {
  5428. first--;
  5429. lcd_clear();
  5430. }
  5431. }
  5432. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  5433. lcd_set_cursor(0, cursor_pos);
  5434. lcd_putc('>');
  5435. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5436. enc_dif = lcd_encoder_diff;
  5437. _delay(100);
  5438. }
  5439. }
  5440. if (lcd_clicked()) {
  5441. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5442. return(cursor_pos + first);
  5443. }
  5444. }
  5445. }
  5446. static void lcd_disable_farm_mode()
  5447. {
  5448. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  5449. if (disable)
  5450. {
  5451. enquecommand_P(PSTR("G99"));
  5452. lcd_return_to_status();
  5453. }
  5454. lcd_update_enable(true);
  5455. lcd_draw_update = 2;
  5456. }
  5457. static void fil_load_menu()
  5458. {
  5459. MENU_BEGIN();
  5460. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5461. MENU_ITEM_FUNCTION_P(_i("Load all"), load_all); ////MSG_LOAD_ALL c=17
  5462. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '1', extr_adj, 0); ////MSG_LOAD_FILAMENT_1 c=16
  5463. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '2', extr_adj, 1); ////MSG_LOAD_FILAMENT_2 c=17
  5464. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '3', extr_adj, 2); ////MSG_LOAD_FILAMENT_3 c=17
  5465. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '4', extr_adj, 3); ////MSG_LOAD_FILAMENT_4 c=17
  5466. if (mmu_enabled)
  5467. {
  5468. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '5', extr_adj, 4);
  5469. }
  5470. MENU_END();
  5471. }
  5472. static void mmu_load_to_nozzle_menu()
  5473. {
  5474. if (bFilamentAction)
  5475. {
  5476. MENU_BEGIN();
  5477. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5478. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '1', lcd_mmu_load_to_nozzle, 0);
  5479. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '2', lcd_mmu_load_to_nozzle, 1);
  5480. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '3', lcd_mmu_load_to_nozzle, 2);
  5481. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '4', lcd_mmu_load_to_nozzle, 3);
  5482. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '5', lcd_mmu_load_to_nozzle, 4);
  5483. MENU_END();
  5484. }
  5485. else
  5486. {
  5487. eFilamentAction = FilamentAction::MmuLoad;
  5488. preheat_or_continue();
  5489. }
  5490. }
  5491. static void mmu_eject_filament(uint8_t filament)
  5492. {
  5493. menu_back();
  5494. mmu_eject_filament(filament, true);
  5495. }
  5496. static void mmu_fil_eject_menu()
  5497. {
  5498. if (bFilamentAction)
  5499. {
  5500. MENU_BEGIN();
  5501. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5502. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '1', mmu_eject_filament, 0);
  5503. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '2', mmu_eject_filament, 1);
  5504. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '3', mmu_eject_filament, 2);
  5505. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '4', mmu_eject_filament, 3);
  5506. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '5', mmu_eject_filament, 4);
  5507. MENU_END();
  5508. }
  5509. else
  5510. {
  5511. eFilamentAction = FilamentAction::MmuEject;
  5512. preheat_or_continue();
  5513. }
  5514. }
  5515. #ifdef MMU_HAS_CUTTER
  5516. static void mmu_cut_filament_menu()
  5517. {
  5518. if(bFilamentAction)
  5519. {
  5520. MENU_BEGIN();
  5521. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5522. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '1', mmu_cut_filament, 0);
  5523. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '2', mmu_cut_filament, 1);
  5524. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '3', mmu_cut_filament, 2);
  5525. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '4', mmu_cut_filament, 3);
  5526. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '5', mmu_cut_filament, 4);
  5527. MENU_END();
  5528. }
  5529. else
  5530. {
  5531. eFilamentAction=FilamentAction::MmuCut;
  5532. bFilamentFirstRun=false;
  5533. if(target_temperature[0]>=EXTRUDE_MINTEMP)
  5534. {
  5535. bFilamentPreheatState=true;
  5536. mFilamentItem(target_temperature[0],target_temperature_bed);
  5537. }
  5538. else lcd_generic_preheat_menu();
  5539. }
  5540. }
  5541. #endif //MMU_HAS_CUTTER
  5542. #ifdef SNMM
  5543. static void fil_unload_menu()
  5544. {
  5545. MENU_BEGIN();
  5546. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5547. MENU_ITEM_FUNCTION_P(_i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=17
  5548. MENU_ITEM_FUNCTION_P(_i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17
  5549. MENU_ITEM_FUNCTION_P(_i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17
  5550. MENU_ITEM_FUNCTION_P(_i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17
  5551. MENU_ITEM_FUNCTION_P(_i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17
  5552. if (mmu_enabled)
  5553. MENU_ITEM_FUNCTION_P(_i("Unload filament 5"), extr_unload_4);////MSG_UNLOAD_FILAMENT_5 c=17
  5554. MENU_END();
  5555. }
  5556. static void change_extr_menu(){
  5557. MENU_BEGIN();
  5558. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5559. MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17
  5560. MENU_ITEM_FUNCTION_P(_i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17
  5561. MENU_ITEM_FUNCTION_P(_i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17
  5562. MENU_ITEM_FUNCTION_P(_i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17
  5563. MENU_END();
  5564. }
  5565. #endif //SNMM
  5566. // unload filament for single material printer (used in M702 gcode)
  5567. // @param automatic: If true, unload_filament is part of a unload+load sequence (M600)
  5568. void unload_filament(bool automatic)
  5569. {
  5570. custom_message_type = CustomMsg::FilamentLoading;
  5571. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  5572. raise_z_above(automatic? MIN_Z_FOR_SWAP: MIN_Z_FOR_UNLOAD);
  5573. // extr_unload2();
  5574. current_position[E_AXIS] -= 45;
  5575. plan_buffer_line_curposXYZE(5200 / 60);
  5576. st_synchronize();
  5577. current_position[E_AXIS] -= 15;
  5578. plan_buffer_line_curposXYZE(1000 / 60);
  5579. st_synchronize();
  5580. current_position[E_AXIS] -= 20;
  5581. plan_buffer_line_curposXYZE(1000 / 60);
  5582. st_synchronize();
  5583. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  5584. //disable extruder steppers so filament can be removed
  5585. disable_e0();
  5586. disable_e1();
  5587. disable_e2();
  5588. _delay(100);
  5589. Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  5590. uint8_t counterBeep = 0;
  5591. while (!lcd_clicked() && (counterBeep < 50)) {
  5592. delay_keep_alive(100);
  5593. counterBeep++;
  5594. }
  5595. st_synchronize();
  5596. while (lcd_clicked()) delay_keep_alive(100);
  5597. lcd_update_enable(true);
  5598. lcd_setstatuspgm(MSG_WELCOME);
  5599. custom_message_type = CustomMsg::Status;
  5600. }
  5601. #include "xflash.h"
  5602. #ifdef LCD_TEST
  5603. static void lcd_test_menu()
  5604. {
  5605. XFLASH_SPI_ENTER();
  5606. xflash_enable_wr();
  5607. xflash_chip_erase();
  5608. xflash_disable_wr();
  5609. }
  5610. #endif //LCD_TEST
  5611. static bool fan_error_selftest()
  5612. {
  5613. #ifdef FANCHECK
  5614. if (!fans_check_enabled) return 0;
  5615. fanSpeed = 255;
  5616. #ifdef FAN_SOFT_PWM
  5617. fanSpeedSoftPwm = 255;
  5618. #endif //FAN_SOFT_PWM
  5619. manage_heater(); //enables print fan
  5620. setExtruderAutoFanState(3); //force enables the extruder fan
  5621. #ifdef FAN_SOFT_PWM
  5622. extruder_autofan_last_check = _millis();
  5623. fan_measuring = true;
  5624. #endif //FAN_SOFT_PWM
  5625. _delay(1000); //delay_keep_alive would turn off extruder fan, because temerature is too low (maybe)
  5626. manage_heater();
  5627. fanSpeed = 0;
  5628. setExtruderAutoFanState(1); //releases lock on the extruder fan
  5629. #ifdef FAN_SOFT_PWM
  5630. fanSpeedSoftPwm = 0;
  5631. #endif //FAN_SOFT_PWM
  5632. manage_heater();
  5633. #ifdef TACH_0
  5634. if (fan_speed[0] <= 20) { //extruder fan error
  5635. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_EXTRUDER);
  5636. return 1;
  5637. }
  5638. #endif
  5639. #ifdef TACH_1
  5640. if (fan_speed[1] <= 20) { //print fan error
  5641. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_PRINT);
  5642. return 1;
  5643. }
  5644. #endif
  5645. #endif //FANCHECK
  5646. return 0;
  5647. }
  5648. //! @brief Resume paused print, send host action "resumed"
  5649. //! @todo It is not good to call restore_print_from_ram_and_continue() from function called by lcd_update(),
  5650. //! as restore_print_from_ram_and_continue() calls lcd_update() internally.
  5651. void lcd_resume_print()
  5652. {
  5653. lcd_return_to_status();
  5654. lcd_reset_alert_level(); //for fan speed error
  5655. if (fan_error_selftest()) {
  5656. if (is_usb_printing) SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED);
  5657. return; //abort if error persists
  5658. }
  5659. cmdqueue_serial_disabled = false;
  5660. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5661. st_synchronize();
  5662. custom_message_type = CustomMsg::Resuming;
  5663. isPrintPaused = false;
  5664. restore_print_from_ram_and_continue(default_retraction);
  5665. pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  5666. refresh_cmd_timeout();
  5667. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUMED); //resume octoprint
  5668. custom_message_type = CustomMsg::Status;
  5669. }
  5670. //! @brief Resume paused USB/host print, send host action "resume"
  5671. void lcd_resume_usb_print()
  5672. {
  5673. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUME); //resume octoprint
  5674. }
  5675. static void change_sheet()
  5676. {
  5677. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  5678. menu_back(3);
  5679. }
  5680. static void lcd_rename_sheet_menu()
  5681. {
  5682. struct MenuData
  5683. {
  5684. bool initialized;
  5685. uint8_t selected;
  5686. char name[sizeof(Sheet::name)];
  5687. };
  5688. static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data");
  5689. MenuData* menuData = (MenuData*)&(menu_data[0]);
  5690. if (!menuData->initialized)
  5691. {
  5692. eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name));
  5693. lcd_encoder = menuData->name[0];
  5694. menuData->initialized = true;
  5695. }
  5696. if (lcd_encoder < '\x20') lcd_encoder = '\x20';
  5697. if (lcd_encoder > '\x7F') lcd_encoder = '\x7F';
  5698. menuData->name[menuData->selected] = lcd_encoder;
  5699. lcd_set_cursor(0,0);
  5700. for (uint_least8_t i = 0; i < sizeof(Sheet::name); ++i)
  5701. {
  5702. lcd_putc(menuData->name[i]);
  5703. }
  5704. lcd_set_cursor(menuData->selected, 1);
  5705. lcd_putc('^');
  5706. if (lcd_clicked())
  5707. {
  5708. if ((menuData->selected + 1u) < sizeof(Sheet::name))
  5709. {
  5710. lcd_encoder = menuData->name[++(menuData->selected)];
  5711. }
  5712. else
  5713. {
  5714. eeprom_update_block(menuData->name,
  5715. EEPROM_Sheets_base->s[selected_sheet].name,
  5716. sizeof(Sheet::name));
  5717. menu_back();
  5718. }
  5719. }
  5720. }
  5721. static void lcd_reset_sheet()
  5722. {
  5723. SheetName sheetName;
  5724. eeprom_default_sheet_name(selected_sheet, sheetName);
  5725. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),EEPROM_EMPTY_VALUE16);
  5726. eeprom_update_block(sheetName.c,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name));
  5727. if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))
  5728. {
  5729. eeprom_switch_to_next_sheet();
  5730. if((-1 == eeprom_next_initialized_sheet(0)) && (CALIBRATION_STATUS_CALIBRATED == calibration_status()))
  5731. {
  5732. calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
  5733. }
  5734. }
  5735. menu_back();
  5736. }
  5737. //! @brief Activate selected_sheet and run first layer calibration
  5738. static void activate_calibrate_sheet()
  5739. {
  5740. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  5741. lcd_first_layer_calibration_reset();
  5742. }
  5743. static void lcd_sheet_menu()
  5744. {
  5745. MENU_BEGIN();
  5746. MENU_ITEM_BACK_P(_T(MSG_STEEL_SHEETS));
  5747. if(eeprom_is_sheet_initialized(selected_sheet)){
  5748. MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); ////MSG_SELECT c=18
  5749. }
  5750. if (lcd_commands_type == LcdCommands::Idle)
  5751. {
  5752. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), activate_calibrate_sheet);////MSG_V2_CALIBRATION c=18
  5753. }
  5754. MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); ////MSG_RENAME c=18
  5755. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_reset_sheet); ////MSG_RESET c=14
  5756. MENU_END();
  5757. }
  5758. //! @brief Show Main Menu
  5759. //!
  5760. //! @code{.unparsed}
  5761. //! |01234567890123456789|
  5762. //! | Info screen | allways
  5763. //!
  5764. //! | tst - Save | ifdef RESUME_DEBUG
  5765. //! | tst - Restore | ifdef RESUME_DEBUG
  5766. //!
  5767. //! | recover print | ifdef TMC2130_DEBUG
  5768. //! | power panic | ifdef TMC2130_DEBUG
  5769. //!
  5770. //! | Live adjust Z | printing + Z low
  5771. //!
  5772. //! | Change filament | farm mode
  5773. //!
  5774. //! | Tune | printing + paused
  5775. //! | Pause print | printing + not paused
  5776. //! | Resume print | printing + paused
  5777. //! | Stop print | printing or paused + NOT MBL
  5778. //! | Preheat | not printing + not paused
  5779. //! | Print from SD | not printing or paused
  5780. //!
  5781. //! | Switch sheet | farm mode
  5782. //!
  5783. //! | AutoLoad filament | not printing + not mmu or paused
  5784. //! | Load filament | not printing + mmu or paused
  5785. //! | Load to nozzle | not printing + mmu or paused
  5786. //! | Unload filament | not printing or paused
  5787. //! | Eject filament | not printing + mmu or paused
  5788. //! | Cut filament | not printing + mmu or paused + cut atctive
  5789. //! | Settings | not printing or paused
  5790. //! | Calibration | not printing
  5791. //! | Statistics | not printing
  5792. //! | Fail stats | allways
  5793. //! | Fail stats MMU | mmu
  5794. //! | Support | allways
  5795. //! @endcode
  5796. static void lcd_main_menu()
  5797. {
  5798. MENU_BEGIN();
  5799. // Majkl superawesome menu
  5800. MENU_ITEM_BACK_P(_T(MSG_WATCH));
  5801. #ifdef RESUME_DEBUG
  5802. if (!saved_printing)
  5803. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  5804. else
  5805. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  5806. #endif //RESUME_DEBUG
  5807. #ifdef TMC2130_DEBUG
  5808. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  5809. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  5810. #endif //TMC2130_DEBUG
  5811. 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) {
  5812. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  5813. }
  5814. if (farm_mode)
  5815. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  5816. if ( moves_planned() || PRINTER_ACTIVE ) {
  5817. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=18
  5818. } else {
  5819. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=18
  5820. }
  5821. if (mesh_bed_leveling_flag == false && homing_flag == false && !isPrintPaused) {
  5822. if (is_usb_printing) {
  5823. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_usb_print);////MSG_PAUSE_PRINT c=18
  5824. } else if (IS_SD_PRINTING) {
  5825. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_print);////MSG_PAUSE_PRINT c=18
  5826. }
  5827. }
  5828. if(isPrintPaused)
  5829. {
  5830. #ifdef FANCHECK
  5831. if((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK))
  5832. #endif //FANCHECK
  5833. {
  5834. if (is_usb_printing) {
  5835. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_usb_print);////MSG_RESUME_PRINT c=18
  5836. } else {
  5837. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);////MSG_RESUME_PRINT c=18
  5838. }
  5839. }
  5840. }
  5841. if((IS_SD_PRINTING || is_usb_printing || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling)) {
  5842. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  5843. }
  5844. #ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code
  5845. if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) {
  5846. if (!card.isFileOpen()) {
  5847. if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  5848. //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  5849. /*else*/{
  5850. bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
  5851. MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  5852. }
  5853. }
  5854. #if SDCARDDETECT < 1
  5855. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD
  5856. #endif //SDCARDDETECT
  5857. }
  5858. } else {
  5859. bMain=true; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  5860. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=18
  5861. #if SDCARDDETECT < 1
  5862. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface////MSG_INIT_SDCARD
  5863. #endif //SDCARDDETECT
  5864. }
  5865. #endif //SDSUPPORT
  5866. if(!isPrintPaused && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  5867. if (!farm_mode) {
  5868. const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  5869. const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
  5870. if ((nextSheet >= 0) && (sheet != nextSheet)) { // show menu only if we have 2 or more sheets initialized
  5871. MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet);
  5872. }
  5873. }
  5874. }
  5875. if ( ! ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal) ) ) {
  5876. if (mmu_enabled) {
  5877. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
  5878. MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);////MSG_LOAD_TO_NOZZLE c=18
  5879. //-// MENU_ITEM_FUNCTION_P(_T(MSG_UNLOAD_FILAMENT), extr_unload);
  5880. //bFilamentFirstRun=true;
  5881. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), mmu_unload_filament);
  5882. MENU_ITEM_SUBMENU_P(_T(MSG_EJECT_FILAMENT), mmu_fil_eject_menu);
  5883. #ifdef MMU_HAS_CUTTER
  5884. MENU_ITEM_SUBMENU_P(_T(MSG_CUT_FILAMENT), mmu_cut_filament_menu);
  5885. #endif //MMU_HAS_CUTTER
  5886. } else {
  5887. #ifdef SNMM
  5888. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  5889. MENU_ITEM_SUBMENU_P(_i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20
  5890. #endif
  5891. #ifdef FILAMENT_SENSOR
  5892. if ((fsensor_autoload_enabled == true) && (fsensor_enabled == true) && (mmu_enabled == false))
  5893. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=18
  5894. else
  5895. #endif //FILAMENT_SENSOR
  5896. {
  5897. bFilamentFirstRun=true;
  5898. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  5899. }
  5900. bFilamentFirstRun=true;
  5901. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  5902. }
  5903. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  5904. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  5905. }
  5906. if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  5907. MENU_ITEM_SUBMENU_P(_i("Statistics"), lcd_menu_statistics);////MSG_STATISTICS c=18
  5908. }
  5909. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  5910. MENU_ITEM_SUBMENU_P(_i("Fail stats"), lcd_menu_fails_stats);////MSG_FAIL_STATS c=18
  5911. #endif
  5912. if (mmu_enabled) {
  5913. MENU_ITEM_SUBMENU_P(_i("Fail stats MMU"), lcd_menu_fails_stats_mmu);////MSG_MMU_FAIL_STATS c=18
  5914. }
  5915. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=18
  5916. #ifdef LCD_TEST
  5917. MENU_ITEM_SUBMENU_P(_i("XFLASH init"), lcd_test_menu);////MSG_SUPPORT
  5918. #endif //LCD_TEST
  5919. MENU_END();
  5920. }
  5921. #ifdef DEBUG_STEPPER_TIMER_MISSED
  5922. bool stepper_timer_overflow_state = false;
  5923. uint16_t stepper_timer_overflow_max = 0;
  5924. uint16_t stepper_timer_overflow_last = 0;
  5925. uint16_t stepper_timer_overflow_cnt = 0;
  5926. void stepper_timer_overflow() {
  5927. char msg[28];
  5928. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  5929. lcd_setstatus(msg);
  5930. stepper_timer_overflow_state = false;
  5931. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  5932. stepper_timer_overflow_max = stepper_timer_overflow_last;
  5933. SERIAL_ECHOPGM("Stepper timer overflow: ");
  5934. MYSERIAL.print(msg);
  5935. SERIAL_ECHOLNPGM("");
  5936. WRITE(BEEPER, LOW);
  5937. }
  5938. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5939. static void lcd_colorprint_change() {
  5940. enquecommand_P(PSTR("M600"));
  5941. custom_message_type = CustomMsg::FilamentLoading; //just print status message
  5942. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5943. lcd_return_to_status();
  5944. lcd_draw_update = 3;
  5945. }
  5946. #ifdef LA_LIVE_K
  5947. // @wavexx: looks like there's no generic float editing function in menu.cpp so we
  5948. // redefine our custom handling functions to mimick other tunables
  5949. const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6S";
  5950. static void lcd_advance_draw_K(char chr, float val)
  5951. {
  5952. if (val <= 0)
  5953. lcd_printf_P(menu_fmt_float13off, chr, MSG_ADVANCE_K, _T(MSG_OFF));
  5954. else
  5955. lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val);
  5956. }
  5957. static void lcd_advance_edit_K(void)
  5958. {
  5959. if (lcd_draw_update)
  5960. {
  5961. if (lcd_encoder < 0) lcd_encoder = 0;
  5962. if (lcd_encoder > 999) lcd_encoder = 999;
  5963. lcd_set_cursor(0, 1);
  5964. lcd_advance_draw_K(' ', 0.01 * lcd_encoder);
  5965. }
  5966. if (LCD_CLICKED)
  5967. {
  5968. extruder_advance_K = 0.01 * lcd_encoder;
  5969. menu_back_no_reset();
  5970. }
  5971. }
  5972. static uint8_t lcd_advance_K()
  5973. {
  5974. if (menu_item == menu_line)
  5975. {
  5976. if (lcd_draw_update)
  5977. {
  5978. lcd_set_cursor(0, menu_row);
  5979. lcd_advance_draw_K((lcd_encoder == menu_item)?'>':' ', extruder_advance_K);
  5980. }
  5981. if (menu_clicked && (lcd_encoder == menu_item))
  5982. {
  5983. menu_submenu_no_reset(lcd_advance_edit_K);
  5984. lcd_encoder = 100. * extruder_advance_K;
  5985. return menu_item_ret();
  5986. }
  5987. }
  5988. menu_item++;
  5989. return 0;
  5990. }
  5991. #define MENU_ITEM_EDIT_advance_K() do { if (lcd_advance_K()) return; } while (0)
  5992. #endif
  5993. static void lcd_tune_menu()
  5994. {
  5995. typedef struct
  5996. {
  5997. menu_data_edit_t reserved; //!< reserved for number editing functions
  5998. int8_t status; //!< To recognize, whether the menu has been just initialized.
  5999. //! Backup of extrudemultiply, to recognize, that the value has been changed and
  6000. //! it needs to be applied.
  6001. int16_t extrudemultiply;
  6002. } _menu_data_t;
  6003. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  6004. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  6005. if (_md->status == 0)
  6006. {
  6007. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  6008. _md->status = 1;
  6009. _md->extrudemultiply = extrudemultiply;
  6010. }
  6011. else if (_md->extrudemultiply != extrudemultiply)
  6012. {
  6013. // extrudemultiply has been changed from the child menu. Apply the new value.
  6014. _md->extrudemultiply = extrudemultiply;
  6015. calculate_extruder_multipliers();
  6016. }
  6017. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  6018. MENU_BEGIN();
  6019. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  6020. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=15
  6021. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  6022. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  6023. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  6024. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=15
  6025. #ifdef LA_LIVE_K
  6026. MENU_ITEM_EDIT_advance_K();//7
  6027. #endif
  6028. #ifdef FILAMENTCHANGEENABLE
  6029. if (!farm_mode)
  6030. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  6031. #endif
  6032. #ifdef FILAMENT_SENSOR
  6033. if (FSensorStateMenu == 0) {
  6034. if (fsensor_not_responding && (mmu_enabled == false)) {
  6035. /* Filament sensor not working*/
  6036. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_NA), lcd_fsensor_state_set);
  6037. }
  6038. else {
  6039. /* Filament sensor turned off, working, no problems*/
  6040. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_OFF), lcd_fsensor_state_set);
  6041. }
  6042. }
  6043. else {
  6044. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_ON), lcd_fsensor_state_set);
  6045. }
  6046. #ifdef IR_SENSOR_ANALOG
  6047. FSENSOR_ACTION_NA;
  6048. #endif //IR_SENSOR_ANALOG
  6049. #endif //FILAMENT_SENSOR
  6050. SETTINGS_AUTO_DEPLETE;
  6051. SETTINGS_CUTTER;
  6052. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  6053. #ifdef TMC2130
  6054. if(!farm_mode)
  6055. {
  6056. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);
  6057. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);
  6058. if (SilentModeMenu == SILENT_MODE_NORMAL)
  6059. {
  6060. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);
  6061. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);
  6062. }
  6063. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);
  6064. }
  6065. #else //TMC2130
  6066. if (!farm_mode) { //dont show in menu if we are in farm mode
  6067. switch (SilentModeMenu) {
  6068. case SILENT_MODE_POWER: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break;
  6069. case SILENT_MODE_SILENT: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set); break;
  6070. case SILENT_MODE_AUTO: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set); break;
  6071. default: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break; // (probably) not needed
  6072. }
  6073. }
  6074. #endif //TMC2130
  6075. SETTINGS_MMU_MODE;
  6076. SETTINGS_SOUND;
  6077. #ifdef LCD_BL_PIN
  6078. if (backlightSupport)
  6079. {
  6080. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  6081. }
  6082. #endif //LCD_BL_PIN
  6083. MENU_END();
  6084. }
  6085. static void mbl_magnets_elimination_toggle() {
  6086. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  6087. magnet_elimination = !magnet_elimination;
  6088. eeprom_update_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, (uint8_t)magnet_elimination);
  6089. }
  6090. static void mbl_mesh_toggle() {
  6091. uint8_t mesh_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  6092. if(mesh_nr == 3) mesh_nr = 7;
  6093. else mesh_nr = 3;
  6094. eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mesh_nr);
  6095. }
  6096. static void mbl_probe_nr_toggle() {
  6097. mbl_z_probe_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR);
  6098. switch (mbl_z_probe_nr) {
  6099. case 1: mbl_z_probe_nr = 3; break;
  6100. case 3: mbl_z_probe_nr = 5; break;
  6101. case 5: mbl_z_probe_nr = 1; break;
  6102. default: mbl_z_probe_nr = 3; break;
  6103. }
  6104. eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, mbl_z_probe_nr);
  6105. }
  6106. static void lcd_mesh_bed_leveling_settings()
  6107. {
  6108. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  6109. uint8_t points_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  6110. char sToggle[4]; //enough for nxn format
  6111. MENU_BEGIN();
  6112. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  6113. sToggle[0] = points_nr + '0';
  6114. sToggle[1] = 'x';
  6115. sToggle[2] = points_nr + '0';
  6116. sToggle[3] = 0;
  6117. MENU_ITEM_TOGGLE(_T(MSG_MESH), sToggle, mbl_mesh_toggle);
  6118. sToggle[0] = mbl_z_probe_nr + '0';
  6119. sToggle[1] = 0;
  6120. MENU_ITEM_TOGGLE(_T(MSG_Z_PROBE_NR), sToggle, mbl_probe_nr_toggle);
  6121. 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);
  6122. MENU_END();
  6123. //SETTINGS_MBL_MODE;
  6124. }
  6125. #ifdef LCD_BL_PIN
  6126. static void backlight_mode_toggle()
  6127. {
  6128. switch (backlightMode)
  6129. {
  6130. case BACKLIGHT_MODE_BRIGHT: backlightMode = BACKLIGHT_MODE_DIM; break;
  6131. case BACKLIGHT_MODE_DIM: backlightMode = BACKLIGHT_MODE_AUTO; break;
  6132. case BACKLIGHT_MODE_AUTO: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  6133. default: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  6134. }
  6135. backlight_save();
  6136. }
  6137. static void lcd_backlight_menu()
  6138. {
  6139. MENU_BEGIN();
  6140. ON_MENU_LEAVE(
  6141. backlight_save();
  6142. );
  6143. MENU_ITEM_BACK_P(_T(MSG_BACK));
  6144. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_HIGH), &backlightLevel_HIGH, backlightLevel_LOW, 255);
  6145. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_LOW), &backlightLevel_LOW, 0, backlightLevel_HIGH);
  6146. 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);
  6147. MENU_ITEM_EDIT_int3_P(_T(MSG_TIMEOUT), &backlightTimer_period, 1, 999);
  6148. MENU_END();
  6149. }
  6150. #endif //LCD_BL_PIN
  6151. static void lcd_control_temperature_menu()
  6152. {
  6153. #ifdef PIDTEMP
  6154. // set up temp variables - undo the default scaling
  6155. // raw_Ki = unscalePID_i(Ki);
  6156. // raw_Kd = unscalePID_d(Kd);
  6157. #endif
  6158. MENU_BEGIN();
  6159. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  6160. #if TEMP_SENSOR_0 != 0
  6161. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  6162. #endif
  6163. #if TEMP_SENSOR_1 != 0
  6164. MENU_ITEM_EDIT_int3_P(_i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1
  6165. #endif
  6166. #if TEMP_SENSOR_2 != 0
  6167. MENU_ITEM_EDIT_int3_P(_i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2
  6168. #endif
  6169. #if TEMP_SENSOR_BED != 0
  6170. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  6171. #endif
  6172. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  6173. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  6174. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  6175. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  6176. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN
  6177. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX
  6178. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR
  6179. #endif
  6180. MENU_END();
  6181. }
  6182. static void lcd_sd_refresh()
  6183. {
  6184. #if SDCARDDETECT == -1
  6185. card.initsd();
  6186. #else
  6187. card.presort();
  6188. #endif
  6189. menu_top = 0;
  6190. lcd_encoder = 0;
  6191. menu_data_reset(); //Forces reloading of cached variables.
  6192. }
  6193. static void lcd_sd_updir()
  6194. {
  6195. card.updir();
  6196. menu_top = 0;
  6197. lcd_encoder = 0;
  6198. menu_data_reset(); //Forces reloading of cached variables.
  6199. }
  6200. void lcd_print_stop()
  6201. {
  6202. if (!card.sdprinting) {
  6203. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint
  6204. }
  6205. UnconditionalStop();
  6206. // TODO: all the following should be moved in the main marlin loop!
  6207. #ifdef MESH_BED_LEVELING
  6208. mbl.active = false; //also prevents undoing the mbl compensation a second time in the second planner_abort_hard()
  6209. #endif
  6210. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  6211. stoptime = _millis();
  6212. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  6213. pause_time = 0;
  6214. save_statistics(total_filament_used, t);
  6215. // reset current command
  6216. lcd_commands_step = 0;
  6217. lcd_commands_type = LcdCommands::Idle;
  6218. lcd_cooldown(); //turns off heaters and fan; goes to status screen.
  6219. current_position[Z_AXIS] += 10; //lift Z.
  6220. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  6221. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) //if axis are homed, move to parked position.
  6222. {
  6223. current_position[X_AXIS] = X_CANCEL_POS;
  6224. current_position[Y_AXIS] = Y_CANCEL_POS;
  6225. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6226. }
  6227. st_synchronize();
  6228. if (mmu_enabled) extr_unload(); //M702 C
  6229. finishAndDisableSteppers(); //M84
  6230. lcd_setstatuspgm(MSG_WELCOME);
  6231. custom_message_type = CustomMsg::Status;
  6232. 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.
  6233. axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative
  6234. isPrintPaused = false; //clear isPrintPaused flag to allow starting next print after pause->stop scenario.
  6235. }
  6236. void lcd_sdcard_stop()
  6237. {
  6238. lcd_puts_at_P(0, 0, _T(MSG_STOP_PRINT));
  6239. lcd_puts_at_P(2, 2, _T(MSG_NO));
  6240. lcd_puts_at_P(2, 3, _T(MSG_YES));
  6241. lcd_putc_at(0, 2, ' ');
  6242. lcd_putc_at(0, 3, ' ');
  6243. if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; }
  6244. if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; }
  6245. lcd_putc_at(0, 1 + lcd_encoder, '>');
  6246. if (lcd_clicked())
  6247. {
  6248. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  6249. if ((int32_t)lcd_encoder == 1)
  6250. {
  6251. lcd_return_to_status();
  6252. }
  6253. if ((int32_t)lcd_encoder == 2)
  6254. {
  6255. lcd_print_stop();
  6256. }
  6257. }
  6258. }
  6259. void lcd_sdcard_menu()
  6260. {
  6261. enum menuState_t : uint8_t {_uninitialized, _standard, _scrolling};
  6262. typedef struct
  6263. {
  6264. menuState_t menuState = _uninitialized;
  6265. uint8_t offset;
  6266. bool isDir;
  6267. const char* scrollPointer;
  6268. uint16_t selectedFileID;
  6269. uint16_t fileCnt;
  6270. int8_t row;
  6271. uint8_t sdSort;
  6272. ShortTimer lcd_scrollTimer;
  6273. } _menu_data_sdcard_t;
  6274. static_assert(sizeof(menu_data)>= sizeof(_menu_data_sdcard_t),"_menu_data_sdcard_t doesn't fit into menu_data");
  6275. _menu_data_sdcard_t* _md = (_menu_data_sdcard_t*)&(menu_data[0]);
  6276. switch(_md->menuState)
  6277. {
  6278. case _uninitialized: //Initialize menu data
  6279. {
  6280. if (card.presort_flag == true) //used to force resorting if sorting type is changed.
  6281. {
  6282. card.presort_flag = false;
  6283. card.presort();
  6284. }
  6285. _md->fileCnt = card.getnrfilenames();
  6286. _md->sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  6287. _md->menuState = _standard;
  6288. }
  6289. // FALLTHRU
  6290. case _standard: //normal menu structure.
  6291. {
  6292. if (!_md->lcd_scrollTimer.running()) //if the timer is not running, then the menu state was just switched, so redraw the screen.
  6293. {
  6294. _md->lcd_scrollTimer.start();
  6295. lcd_draw_update = 1;
  6296. }
  6297. if (_md->lcd_scrollTimer.expired(500) && (_md->row != -1)) //switch to the scrolling state on timeout if a file/dir is selected.
  6298. {
  6299. _md->menuState = _scrolling;
  6300. _md->offset = 0;
  6301. _md->scrollPointer = NULL;
  6302. _md->lcd_scrollTimer.start();
  6303. lcd_draw_update = 1; //forces last load before switching to scrolling.
  6304. }
  6305. if (lcd_draw_update == 0 && !LCD_CLICKED)
  6306. return; // nothing to do (so don't thrash the SD card)
  6307. _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.
  6308. //if we reached this point it means that the encoder moved or clicked or the state is being switched. Reset the scrollTimer.
  6309. _md->lcd_scrollTimer.start();
  6310. MENU_BEGIN();
  6311. MENU_ITEM_BACK_P(_T(bMain?MSG_MAIN:MSG_BACK)); // i.e. default menu-item / menu-item after card insertion
  6312. card.getWorkDirName();
  6313. if (card.filename[0] == '/')
  6314. {
  6315. #if SDCARDDETECT == -1
  6316. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  6317. #else
  6318. if (card.ToshibaFlashAir_isEnabled())
  6319. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh); //show the refresh option if in flashAir mode.
  6320. #endif
  6321. }
  6322. else
  6323. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); //Show the updir button if in a subdir.
  6324. for (uint16_t i = _md->fileCnt; i-- > 0;) // Every file, from top to bottom.
  6325. {
  6326. if (menu_item == menu_line) //If the file is on the screen.
  6327. {
  6328. //load filename to memory.
  6329. #ifdef SDCARD_SORT_ALPHA
  6330. if (_md->sdSort == SD_SORT_NONE)
  6331. card.getfilename(i);
  6332. else
  6333. card.getfilename_sorted(i, _md->sdSort);
  6334. #else
  6335. card.getfilename(i);
  6336. #endif
  6337. if (lcd_encoder == menu_item) //If the file is selected.
  6338. {
  6339. _md->selectedFileID = i;
  6340. _md->isDir = card.filenameIsDir;
  6341. _md->row = menu_row;
  6342. }
  6343. if (card.filenameIsDir)
  6344. MENU_ITEM_SDDIR(card.filename, card.longFilename);
  6345. else
  6346. MENU_ITEM_SDFILE(card.filename, card.longFilename);
  6347. }
  6348. else MENU_ITEM_DUMMY(); //dummy item that just increments the internal menu counters.
  6349. }
  6350. MENU_END();
  6351. } break;
  6352. case _scrolling: //scrolling filename
  6353. {
  6354. const bool rewindFlag = LCD_CLICKED || lcd_draw_update; //flag that says whether the menu should return to _standard state.
  6355. if (_md->scrollPointer == NULL)
  6356. {
  6357. //load filename to memory.
  6358. #ifdef SDCARD_SORT_ALPHA
  6359. if (_md->sdSort == SD_SORT_NONE)
  6360. card.getfilename(_md->selectedFileID);
  6361. else
  6362. card.getfilename_sorted(_md->selectedFileID, _md->sdSort);
  6363. #else
  6364. card.getfilename(_md->selectedFileID);
  6365. #endif
  6366. _md->scrollPointer = (card.longFilename[0] == '\0') ? card.filename : card.longFilename;
  6367. }
  6368. if (rewindFlag == 1)
  6369. _md->offset = 0; //redraw once again from the beginning.
  6370. if (_md->lcd_scrollTimer.expired(300) || rewindFlag)
  6371. {
  6372. uint8_t i = LCD_WIDTH - ((_md->isDir)?2:1);
  6373. lcd_set_cursor(0, _md->row);
  6374. lcd_print('>');
  6375. if (_md->isDir)
  6376. lcd_print(LCD_STR_FOLDER[0]);
  6377. for (; i != 0; i--)
  6378. {
  6379. const char* c = (_md->scrollPointer + _md->offset + ((LCD_WIDTH - ((_md->isDir)?2:1)) - i));
  6380. lcd_print(c[0]);
  6381. if (c[1])
  6382. _md->lcd_scrollTimer.start();
  6383. else
  6384. {
  6385. _md->lcd_scrollTimer.stop();
  6386. break; //stop at the end of the string
  6387. }
  6388. }
  6389. if (i != 0) //adds spaces if string is incomplete or at the end (instead of null).
  6390. {
  6391. lcd_space(i);
  6392. }
  6393. _md->offset++;
  6394. }
  6395. if (rewindFlag) //go back to sd_menu.
  6396. {
  6397. _md->lcd_scrollTimer.stop(); //forces redraw in _standard state
  6398. _md->menuState = _standard;
  6399. }
  6400. } break;
  6401. default: _md->menuState = _uninitialized; //shouldn't ever happen. Anyways, initialize the menu.
  6402. }
  6403. }
  6404. #ifdef TMC2130
  6405. static void lcd_belttest_v()
  6406. {
  6407. lcd_belttest();
  6408. menu_back_if_clicked();
  6409. }
  6410. void lcd_belttest()
  6411. {
  6412. lcd_clear();
  6413. // Belttest requires high power mode. Enable it.
  6414. FORCE_HIGH_POWER_START;
  6415. uint16_t X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  6416. uint16_t Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  6417. lcd_printf_P(_T(MSG_CHECKING_X));
  6418. lcd_set_cursor(0,1), lcd_printf_P(PSTR("X: %u -> ..."),X);
  6419. KEEPALIVE_STATE(IN_HANDLER);
  6420. // N.B: it doesn't make sense to handle !lcd_selfcheck...() because selftest_sg throws its own error screen
  6421. // that clobbers ours, with more info than we could provide. So on fail we just fall through to take us back to status.
  6422. if (lcd_selfcheck_axis_sg(X_AXIS)){
  6423. X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  6424. lcd_set_cursor(10,1), lcd_printf_P(PSTR("%u"),X); // Show new X value next to old one.
  6425. lcd_puts_at_P(0,2,_T(MSG_CHECKING_Y));
  6426. lcd_set_cursor(0,3), lcd_printf_P(PSTR("Y: %u -> ..."),Y);
  6427. if (lcd_selfcheck_axis_sg(Y_AXIS))
  6428. {
  6429. Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  6430. lcd_set_cursor(10,3),lcd_printf_P(PSTR("%u"),Y);
  6431. lcd_set_cursor(19, 3);
  6432. lcd_print(LCD_STR_UPLEVEL[0]);
  6433. lcd_wait_for_click_delay(10);
  6434. }
  6435. }
  6436. FORCE_HIGH_POWER_END;
  6437. KEEPALIVE_STATE(NOT_BUSY);
  6438. }
  6439. #endif //TMC2130
  6440. #ifdef IR_SENSOR_ANALOG
  6441. // called also from marlin_main.cpp
  6442. void printf_IRSensorAnalogBoardChange(){
  6443. printf_P(PSTR("Filament sensor board change detected: revision%S\n"), FsensorIRVersionText());
  6444. }
  6445. static bool lcd_selftest_IRsensor(bool bStandalone)
  6446. {
  6447. bool bPCBrev04;
  6448. uint16_t volt_IR_int;
  6449. volt_IR_int = current_voltage_raw_IR;
  6450. bPCBrev04=(volt_IR_int < IRsensor_Hopen_TRESHOLD);
  6451. printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"), Raw2Voltage(volt_IR_int) );
  6452. if(volt_IR_int < IRsensor_Hmin_TRESHOLD){
  6453. if(!bStandalone)
  6454. lcd_selftest_error(TestError::FsensorLevel,"HIGH","");
  6455. return(false);
  6456. }
  6457. 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
  6458. volt_IR_int = current_voltage_raw_IR;
  6459. printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"), Raw2Voltage(volt_IR_int));
  6460. if(volt_IR_int > (IRsensor_Lmax_TRESHOLD)){
  6461. if(!bStandalone)
  6462. lcd_selftest_error(TestError::FsensorLevel,"LOW","");
  6463. return(false);
  6464. }
  6465. if((bPCBrev04 ? 1 : 0) != (uint8_t)oFsensorPCB){ // safer then "(uint8_t)bPCBrev04"
  6466. oFsensorPCB=bPCBrev04 ? ClFsensorPCB::_Rev04 : ClFsensorPCB::_Old;
  6467. printf_IRSensorAnalogBoardChange();
  6468. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB);
  6469. }
  6470. return(true);
  6471. }
  6472. static void lcd_detect_IRsensor(){
  6473. bool bAction;
  6474. bool loaded;
  6475. bMenuFSDetect = true; // inhibits some code inside "manage_inactivity()"
  6476. /// Check if filament is loaded. If it is loaded stop detection.
  6477. /// @todo Add autodetection with MMU2s
  6478. loaded = ! READ(IR_SENSOR_PIN);
  6479. if(loaded ){
  6480. 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
  6481. return;
  6482. } else {
  6483. 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
  6484. bAction = lcd_selftest_IRsensor(true);
  6485. }
  6486. if(bAction){
  6487. lcd_show_fullscreen_message_and_wait_P(_i("Sensor verified, remove the filament now."));////MSG_FS_VERIFIED c=20 r=3
  6488. // the fsensor board has been successfully identified, any previous "not responding" may be cleared now
  6489. fsensor_not_responding = false;
  6490. } else {
  6491. lcd_show_fullscreen_message_and_wait_P(_i("Verification failed, remove the filament and try again."));////MSG_FIL_FAILED c=20 r=5
  6492. // here it is unclear what to to with the fsensor_not_responding flag
  6493. }
  6494. bMenuFSDetect=false; // de-inhibits some code inside "manage_inactivity()"
  6495. }
  6496. #endif //IR_SENSOR_ANALOG
  6497. static void lcd_selftest_v()
  6498. {
  6499. (void)lcd_selftest();
  6500. }
  6501. bool lcd_selftest()
  6502. {
  6503. uint8_t _progress = 0;
  6504. bool _result = true;
  6505. bool _swapped_fan = false;
  6506. #ifdef IR_SENSOR_ANALOG
  6507. //! Check if IR sensor is in unknown state, if so run Fsensor Detection
  6508. //! As the Fsensor Detection isn't yet ready for the mmu2s we set temporarily the IR sensor 0.3 or older for mmu2s
  6509. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  6510. if( oFsensorPCB == ClFsensorPCB::_Undef) {
  6511. if (!mmu_enabled) {
  6512. lcd_detect_IRsensor();
  6513. }
  6514. else {
  6515. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,0);
  6516. }
  6517. }
  6518. #endif //IR_SENSOR_ANALOG
  6519. lcd_wait_for_cool_down();
  6520. lcd_clear();
  6521. lcd_puts_at_P(0, 0, _i("Self test start"));////MSG_SELFTEST_START c=20
  6522. #ifdef TMC2130
  6523. FORCE_HIGH_POWER_START;
  6524. #endif // TMC2130
  6525. FORCE_BL_ON_START;
  6526. _delay(2000);
  6527. KEEPALIVE_STATE(IN_HANDLER);
  6528. _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000);
  6529. #if (defined(FANCHECK) && defined(TACH_0))
  6530. switch (lcd_selftest_fan_auto(0)){ // check extruder Fan
  6531. case FanCheck::ExtruderFan:
  6532. _result = false;
  6533. break;
  6534. case FanCheck::SwappedFan:
  6535. _swapped_fan = true;
  6536. // FALLTHRU
  6537. default:
  6538. _result = true;
  6539. break;
  6540. }
  6541. #else //defined(TACH_0)
  6542. _result = lcd_selftest_manual_fan_check(0, false);
  6543. #endif //defined(TACH_0)
  6544. if (!_result)
  6545. {
  6546. lcd_selftest_error(TestError::ExtruderFan, "", "");
  6547. }
  6548. if (_result)
  6549. {
  6550. _progress = lcd_selftest_screen(TestScreen::PrintFan, _progress, 3, true, 2000);
  6551. #if (defined(FANCHECK) && defined(TACH_1))
  6552. switch (lcd_selftest_fan_auto(1)){ // check print fan
  6553. case FanCheck::PrintFan:
  6554. _result = false;
  6555. break;
  6556. case FanCheck::SwappedFan:
  6557. _swapped_fan = true;
  6558. // FALLTHRU
  6559. default:
  6560. _result = true;
  6561. break;
  6562. }
  6563. #else //defined(TACH_1)
  6564. _result = lcd_selftest_manual_fan_check(1, false);
  6565. #endif //defined(TACH_1)
  6566. if (!_result)
  6567. {
  6568. lcd_selftest_error(TestError::PrintFan, "", ""); //print fan not spinning
  6569. }
  6570. }
  6571. if (_swapped_fan) {
  6572. //turn on print fan and check that left extruder fan is not spinning
  6573. _result = lcd_selftest_manual_fan_check(1, true);
  6574. if (_result) {
  6575. //print fan is stil turned on; check that it is spinning
  6576. _result = lcd_selftest_manual_fan_check(1, false, true);
  6577. if (!_result){
  6578. lcd_selftest_error(TestError::PrintFan, "", "");
  6579. }
  6580. }
  6581. else {
  6582. // fans are swapped
  6583. lcd_selftest_error(TestError::SwappedFan, "", "");
  6584. }
  6585. }
  6586. if (_result)
  6587. {
  6588. _progress = lcd_selftest_screen(TestScreen::FansOk, _progress, 3, true, 2000);
  6589. _result = lcd_selfcheck_endstops(); //With TMC2130, only the Z probe is tested.
  6590. }
  6591. if (_result)
  6592. {
  6593. //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
  6594. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 2000);
  6595. #ifdef TMC2130
  6596. _result = lcd_selfcheck_axis_sg(X_AXIS);
  6597. #else
  6598. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  6599. #endif //TMC2130
  6600. }
  6601. if (_result)
  6602. {
  6603. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 0);
  6604. #ifndef TMC2130
  6605. _result = lcd_selfcheck_pulleys(X_AXIS);
  6606. #endif
  6607. }
  6608. if (_result)
  6609. {
  6610. _progress = lcd_selftest_screen(TestScreen::AxisY, _progress, 3, true, 1500);
  6611. #ifdef TMC2130
  6612. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  6613. #else
  6614. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  6615. #endif // TMC2130
  6616. }
  6617. if (_result)
  6618. {
  6619. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 0);
  6620. #ifndef TMC2130
  6621. _result = lcd_selfcheck_pulleys(Y_AXIS);
  6622. #endif // TMC2130
  6623. }
  6624. if (_result)
  6625. {
  6626. #ifdef TMC2130
  6627. tmc2130_home_exit();
  6628. enable_endstops(false);
  6629. #endif
  6630. //homeaxis(X_AXIS);
  6631. //homeaxis(Y_AXIS);
  6632. current_position[X_AXIS] = pgm_read_float(bed_ref_points_4);
  6633. current_position[Y_AXIS] = pgm_read_float(bed_ref_points_4+1);
  6634. #ifdef TMC2130
  6635. //current_position[X_AXIS] += 0;
  6636. current_position[Y_AXIS] += 4;
  6637. #endif //TMC2130
  6638. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  6639. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6640. st_synchronize();
  6641. set_destination_to_current();
  6642. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500);
  6643. #ifdef TMC2130
  6644. homeaxis(Z_AXIS); //In case of failure, the code gets stuck in this function.
  6645. #else
  6646. _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS);
  6647. #endif //TMC2130
  6648. //raise Z to not damage the bed during and hotend testing
  6649. current_position[Z_AXIS] += 20;
  6650. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6651. st_synchronize();
  6652. }
  6653. #ifdef TMC2130
  6654. if (_result)
  6655. {
  6656. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  6657. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6658. st_synchronize();
  6659. _progress = lcd_selftest_screen(TestScreen::Home, 0, 2, true, 0);
  6660. bool bres = tmc2130_home_calibrate(X_AXIS);
  6661. _progress = lcd_selftest_screen(TestScreen::Home, 1, 2, true, 0);
  6662. bres &= tmc2130_home_calibrate(Y_AXIS);
  6663. _progress = lcd_selftest_screen(TestScreen::Home, 2, 2, true, 0);
  6664. if (bres)
  6665. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  6666. _result = bres;
  6667. }
  6668. #endif //TMC2130
  6669. if (_result)
  6670. {
  6671. _progress = lcd_selftest_screen(TestScreen::Bed, _progress, 3, true, 2000);
  6672. _result = lcd_selfcheck_check_heater(true);
  6673. }
  6674. if (_result)
  6675. {
  6676. _progress = lcd_selftest_screen(TestScreen::Hotend, _progress, 3, true, 1000);
  6677. _result = lcd_selfcheck_check_heater(false);
  6678. }
  6679. if (_result)
  6680. {
  6681. _progress = lcd_selftest_screen(TestScreen::HotendOk, _progress, 3, true, 2000); //nozzle ok
  6682. }
  6683. #ifdef FILAMENT_SENSOR
  6684. if (_result)
  6685. {
  6686. if (mmu_enabled)
  6687. {
  6688. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  6689. _result = selftest_irsensor();
  6690. if (_result)
  6691. {
  6692. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  6693. }
  6694. } else
  6695. {
  6696. #ifdef PAT9125
  6697. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  6698. _result = lcd_selftest_fsensor();
  6699. if (_result)
  6700. {
  6701. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  6702. }
  6703. #endif //PAT9125
  6704. #if 0
  6705. // Intentionally disabled - that's why we moved the detection to runtime by just checking the two voltages.
  6706. // The idea is not to force the user to remove and insert the filament on an assembled printer.
  6707. //def IR_SENSOR_ANALOG
  6708. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filament sensor
  6709. _result = lcd_selftest_IRsensor();
  6710. if (_result)
  6711. {
  6712. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //filament sensor OK
  6713. }
  6714. #endif //IR_SENSOR_ANALOG
  6715. }
  6716. }
  6717. #endif //FILAMENT_SENSOR
  6718. if (_result)
  6719. {
  6720. _progress = lcd_selftest_screen(TestScreen::AllCorrect, _progress, 3, true, 5000); //all correct
  6721. }
  6722. else
  6723. {
  6724. _progress = lcd_selftest_screen(TestScreen::Failed, _progress, 3, true, 5000);
  6725. }
  6726. lcd_reset_alert_level();
  6727. enquecommand_P(PSTR("M84"));
  6728. lcd_update_enable(true);
  6729. if (_result)
  6730. {
  6731. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=20
  6732. }
  6733. else
  6734. {
  6735. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  6736. }
  6737. #ifdef TMC2130
  6738. FORCE_HIGH_POWER_END;
  6739. #endif // TMC2130
  6740. FORCE_BL_ON_END;
  6741. KEEPALIVE_STATE(NOT_BUSY);
  6742. return(_result);
  6743. }
  6744. #ifdef TMC2130
  6745. static void reset_crash_det(uint8_t axis) {
  6746. current_position[axis] += 10;
  6747. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6748. st_synchronize();
  6749. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  6750. }
  6751. static bool lcd_selfcheck_axis_sg(uint8_t axis) {
  6752. // each axis length is measured twice
  6753. float axis_length, current_position_init, current_position_final;
  6754. float measured_axis_length[2];
  6755. float margin = 60;
  6756. float max_error_mm = 5;
  6757. switch (axis) {
  6758. case 0: axis_length = X_MAX_POS; break;
  6759. case 1: axis_length = Y_MAX_POS + 8; break;
  6760. default: axis_length = 210; break;
  6761. }
  6762. tmc2130_sg_stop_on_crash = false;
  6763. tmc2130_home_exit();
  6764. enable_endstops(true);
  6765. raise_z_above(MESH_HOME_Z_SEARCH);
  6766. st_synchronize();
  6767. tmc2130_home_enter(1 << axis);
  6768. // first axis length measurement begin
  6769. current_position[axis] -= (axis_length + margin);
  6770. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6771. st_synchronize();
  6772. tmc2130_sg_meassure_start(axis);
  6773. current_position_init = st_get_position_mm(axis);
  6774. current_position[axis] += 2 * margin;
  6775. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6776. st_synchronize();
  6777. current_position[axis] += axis_length;
  6778. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6779. st_synchronize();
  6780. uint16_t sg1 = tmc2130_sg_meassure_stop();
  6781. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  6782. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  6783. current_position_final = st_get_position_mm(axis);
  6784. measured_axis_length[0] = fabs(current_position_final - current_position_init);
  6785. // first measurement end and second measurement begin
  6786. current_position[axis] -= margin;
  6787. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6788. st_synchronize();
  6789. current_position[axis] -= (axis_length + margin);
  6790. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6791. st_synchronize();
  6792. current_position_init = st_get_position_mm(axis);
  6793. measured_axis_length[1] = fabs(current_position_final - current_position_init);
  6794. tmc2130_home_exit();
  6795. //end of second measurement, now check for possible errors:
  6796. for(uint_least8_t i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  6797. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  6798. if (fabs(measured_axis_length[i] - axis_length) > max_error_mm) {
  6799. enable_endstops(false);
  6800. const char *_error_1;
  6801. if (axis == X_AXIS) _error_1 = "X";
  6802. if (axis == Y_AXIS) _error_1 = "Y";
  6803. if (axis == Z_AXIS) _error_1 = "Z";
  6804. lcd_selftest_error(TestError::Axis, _error_1, "");
  6805. current_position[axis] = 0;
  6806. plan_set_position_curposXYZE();
  6807. reset_crash_det(axis);
  6808. enable_endstops(true);
  6809. endstops_hit_on_purpose();
  6810. return false;
  6811. }
  6812. }
  6813. printf_P(_N("Axis length difference:%.3f\n"), fabs(measured_axis_length[0] - measured_axis_length[1]));
  6814. if (fabs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  6815. //loose pulleys
  6816. const char *_error_1;
  6817. if (axis == X_AXIS) _error_1 = "X";
  6818. if (axis == Y_AXIS) _error_1 = "Y";
  6819. if (axis == Z_AXIS) _error_1 = "Z";
  6820. lcd_selftest_error(TestError::Pulley, _error_1, "");
  6821. current_position[axis] = 0;
  6822. plan_set_position_curposXYZE();
  6823. reset_crash_det(axis);
  6824. endstops_hit_on_purpose();
  6825. return false;
  6826. }
  6827. current_position[axis] = 0;
  6828. plan_set_position_curposXYZE();
  6829. reset_crash_det(axis);
  6830. endstops_hit_on_purpose();
  6831. return true;
  6832. }
  6833. #endif //TMC2130
  6834. #ifndef TMC2130
  6835. static bool lcd_selfcheck_axis(int _axis, int _travel)
  6836. {
  6837. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  6838. bool _stepdone = false;
  6839. bool _stepresult = false;
  6840. uint8_t _progress = 0;
  6841. int _travel_done = 0;
  6842. int _err_endstop = 0;
  6843. int _lcd_refresh = 0;
  6844. _travel = _travel + (_travel / 10);
  6845. if (_axis == X_AXIS) {
  6846. current_position[Z_AXIS] += 17;
  6847. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6848. }
  6849. do {
  6850. current_position[_axis] = current_position[_axis] - 1;
  6851. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6852. st_synchronize();
  6853. #ifdef TMC2130
  6854. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  6855. #else //TMC2130
  6856. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  6857. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  6858. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  6859. #endif //TMC2130
  6860. {
  6861. if (_axis == 0)
  6862. {
  6863. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6864. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  6865. }
  6866. if (_axis == 1)
  6867. {
  6868. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6869. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  6870. }
  6871. if (_axis == 2)
  6872. {
  6873. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6874. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  6875. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  6876. /*disable_x();
  6877. disable_y();
  6878. disable_z();*/
  6879. }
  6880. _stepdone = true;
  6881. }
  6882. if (_lcd_refresh < 6)
  6883. {
  6884. _lcd_refresh++;
  6885. }
  6886. else
  6887. {
  6888. _progress = lcd_selftest_screen(static_cast<TestScreen>(static_cast<int>(TestScreen::AxisX) + _axis), _progress, 3, false, 0);
  6889. _lcd_refresh = 0;
  6890. }
  6891. manage_heater();
  6892. manage_inactivity(true);
  6893. //_delay(100);
  6894. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  6895. } while (!_stepdone);
  6896. //current_position[_axis] = current_position[_axis] + 15;
  6897. //plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder);
  6898. if (!_stepresult)
  6899. {
  6900. const char *_error_1;
  6901. const char *_error_2;
  6902. if (_axis == X_AXIS) _error_1 = "X";
  6903. if (_axis == Y_AXIS) _error_1 = "Y";
  6904. if (_axis == Z_AXIS) _error_1 = "Z";
  6905. if (_err_endstop == 0) _error_2 = "X";
  6906. if (_err_endstop == 1) _error_2 = "Y";
  6907. if (_err_endstop == 2) _error_2 = "Z";
  6908. if (_travel_done >= _travel)
  6909. {
  6910. lcd_selftest_error(TestError::Endstop, _error_1, _error_2);
  6911. }
  6912. else
  6913. {
  6914. lcd_selftest_error(TestError::Motor, _error_1, _error_2);
  6915. }
  6916. }
  6917. current_position[_axis] = 0; //simulate axis home to avoid negative numbers for axis position, especially Z.
  6918. plan_set_position_curposXYZE();
  6919. return _stepresult;
  6920. }
  6921. static bool lcd_selfcheck_pulleys(int axis)
  6922. {
  6923. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  6924. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  6925. float current_position_init;
  6926. float move;
  6927. bool endstop_triggered = false;
  6928. int i;
  6929. unsigned long timeout_counter;
  6930. refresh_cmd_timeout();
  6931. manage_inactivity(true);
  6932. if (axis == 0) move = 50; //X_AXIS
  6933. else move = 50; //Y_AXIS
  6934. current_position_init = current_position[axis];
  6935. current_position[axis] += 2;
  6936. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6937. for (i = 0; i < 5; i++) {
  6938. refresh_cmd_timeout();
  6939. current_position[axis] = current_position[axis] + move;
  6940. st_current_set(0, 850); //set motor current higher
  6941. plan_buffer_line_curposXYZE(200);
  6942. st_synchronize();
  6943. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  6944. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  6945. current_position[axis] = current_position[axis] - move;
  6946. plan_buffer_line_curposXYZE(50);
  6947. st_synchronize();
  6948. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6949. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6950. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6951. return(false);
  6952. }
  6953. }
  6954. timeout_counter = _millis() + 2500;
  6955. endstop_triggered = false;
  6956. manage_inactivity(true);
  6957. while (!endstop_triggered) {
  6958. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6959. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6960. endstop_triggered = true;
  6961. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  6962. current_position[axis] += 10;
  6963. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6964. st_synchronize();
  6965. return(true);
  6966. }
  6967. else {
  6968. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6969. return(false);
  6970. }
  6971. }
  6972. else {
  6973. current_position[axis] -= 1;
  6974. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6975. st_synchronize();
  6976. if (_millis() > timeout_counter) {
  6977. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6978. return(false);
  6979. }
  6980. }
  6981. }
  6982. return(true);
  6983. }
  6984. #endif //not defined TMC2130
  6985. static bool lcd_selfcheck_endstops()
  6986. {
  6987. bool _result = true;
  6988. if (
  6989. #ifndef TMC2130
  6990. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6991. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6992. #endif //!TMC2130
  6993. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6994. {
  6995. #ifndef TMC2130
  6996. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  6997. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  6998. #endif //!TMC2130
  6999. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  7000. }
  7001. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  7002. st_synchronize();
  7003. if (
  7004. #ifndef TMC2130
  7005. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  7006. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  7007. #endif //!TMC2130
  7008. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  7009. {
  7010. _result = false;
  7011. char _error[4] = "";
  7012. #ifndef TMC2130
  7013. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  7014. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  7015. #endif //!TMC2130
  7016. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  7017. lcd_selftest_error(TestError::Endstops, _error, "");
  7018. }
  7019. manage_heater();
  7020. manage_inactivity(true);
  7021. return _result;
  7022. }
  7023. static bool lcd_selfcheck_check_heater(bool _isbed)
  7024. {
  7025. uint8_t _counter = 0;
  7026. uint8_t _progress = 0;
  7027. bool _stepresult = false;
  7028. bool _docycle = true;
  7029. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  7030. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  7031. uint8_t _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  7032. target_temperature[0] = (_isbed) ? 0 : 200;
  7033. target_temperature_bed = (_isbed) ? 100 : 0;
  7034. manage_heater();
  7035. manage_inactivity(true);
  7036. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  7037. do {
  7038. _counter++;
  7039. _docycle = (_counter < _cycles) ? true : false;
  7040. manage_heater();
  7041. manage_inactivity(true);
  7042. _progress = (_isbed) ? lcd_selftest_screen(TestScreen::Bed, _progress, 2, false, 400) : lcd_selftest_screen(TestScreen::Hotend, _progress, 2, false, 400);
  7043. /*if (_isbed) {
  7044. MYSERIAL.print("Bed temp:");
  7045. MYSERIAL.println(degBed());
  7046. }
  7047. else {
  7048. MYSERIAL.print("Hotend temp:");
  7049. MYSERIAL.println(degHotend(0));
  7050. }*/
  7051. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  7052. } while (_docycle);
  7053. target_temperature[0] = 0;
  7054. target_temperature_bed = 0;
  7055. manage_heater();
  7056. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  7057. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  7058. /*
  7059. MYSERIAL.println("");
  7060. MYSERIAL.print("Checked result:");
  7061. MYSERIAL.println(_checked_result);
  7062. MYSERIAL.print("Opposite result:");
  7063. MYSERIAL.println(_opposite_result);
  7064. */
  7065. if (_opposite_result < ((_isbed) ? 30 : 9))
  7066. {
  7067. if (_checked_result >= ((_isbed) ? 9 : 30))
  7068. {
  7069. _stepresult = true;
  7070. }
  7071. else
  7072. {
  7073. lcd_selftest_error(TestError::Heater, "", "");
  7074. }
  7075. }
  7076. else
  7077. {
  7078. lcd_selftest_error(TestError::Bed, "", "");
  7079. }
  7080. manage_heater();
  7081. manage_inactivity(true);
  7082. KEEPALIVE_STATE(IN_HANDLER);
  7083. return _stepresult;
  7084. }
  7085. static void lcd_selftest_error(TestError testError, const char *_error_1, const char *_error_2)
  7086. {
  7087. lcd_beeper_quick_feedback();
  7088. FORCE_BL_ON_END;
  7089. target_temperature[0] = 0;
  7090. target_temperature_bed = 0;
  7091. manage_heater();
  7092. manage_inactivity();
  7093. lcd_clear();
  7094. lcd_puts_at_P(0, 0, _i("Selftest error!"));////MSG_SELFTEST_ERROR c=20
  7095. lcd_puts_at_P(0, 1, _i("Please check:"));////MSG_SELFTEST_PLEASECHECK c=20
  7096. switch (testError)
  7097. {
  7098. case TestError::Heater:
  7099. lcd_puts_at_P(0, 2, _i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=20
  7100. lcd_puts_at_P(0, 3, _i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=20
  7101. break;
  7102. case TestError::Bed:
  7103. lcd_puts_at_P(0, 2, _i("Bed/Heater"));////MSG_SELFTEST_BEDHEATER c=20
  7104. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7105. break;
  7106. case TestError::Endstops:
  7107. lcd_puts_at_P(0, 2, _i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=20
  7108. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7109. lcd_set_cursor(18, 3);
  7110. lcd_print(_error_1);
  7111. break;
  7112. case TestError::Motor:
  7113. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_MOTOR));
  7114. lcd_set_cursor(18, 2);
  7115. lcd_print(_error_1);
  7116. lcd_puts_at_P(0, 3, _i("Endstop"));////MSG_SELFTEST_ENDSTOP c=16
  7117. lcd_set_cursor(18, 3);
  7118. lcd_print(_error_2);
  7119. break;
  7120. case TestError::Endstop:
  7121. lcd_puts_at_P(0, 2, _i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20
  7122. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  7123. lcd_set_cursor(18, 3);
  7124. lcd_print(_error_1);
  7125. break;
  7126. case TestError::PrintFan:
  7127. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_COOLING_FAN));
  7128. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7129. lcd_set_cursor(18, 3);
  7130. lcd_print(_error_1);
  7131. break;
  7132. case TestError::ExtruderFan:
  7133. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_EXTRUDER_FAN));
  7134. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7135. lcd_set_cursor(18, 3);
  7136. lcd_print(_error_1);
  7137. break;
  7138. case TestError::Pulley:
  7139. lcd_puts_at_P(0, 2, _i("Loose pulley"));////MSG_LOOSE_PULLEY c=20
  7140. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  7141. lcd_set_cursor(18, 3);
  7142. lcd_print(_error_1);
  7143. break;
  7144. case TestError::Axis:
  7145. lcd_puts_at_P(0, 2, _i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=20
  7146. lcd_puts_at_P(0, 3, _i("Axis"));////MSG_SELFTEST_AXIS c=16
  7147. lcd_set_cursor(18, 3);
  7148. lcd_print(_error_1);
  7149. break;
  7150. case TestError::SwappedFan:
  7151. lcd_puts_at_P(0, 2, _i("Front/left fans"));////MSG_SELFTEST_FANS c=20
  7152. lcd_puts_at_P(0, 3, _i("Swapped"));////MSG_SELFTEST_SWAPPED c=16
  7153. lcd_set_cursor(18, 3);
  7154. lcd_print(_error_1);
  7155. break;
  7156. case TestError::WiringFsensor:
  7157. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7158. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7159. break;
  7160. case TestError::TriggeringFsensor:
  7161. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7162. lcd_puts_at_P(0, 3, _i("False triggering"));////MSG_FALSE_TRIGGERING c=20
  7163. break;
  7164. case TestError::FsensorLevel:
  7165. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7166. lcd_set_cursor(0, 3);
  7167. lcd_printf_P(_i("%s level expected"),_error_1);////MSG_SELFTEST_FS_LEVEL c=20
  7168. break;
  7169. }
  7170. _delay(1000);
  7171. lcd_beeper_quick_feedback();
  7172. do {
  7173. _delay(100);
  7174. manage_heater();
  7175. manage_inactivity();
  7176. } while (!lcd_clicked());
  7177. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  7178. lcd_return_to_status();
  7179. }
  7180. #ifdef FILAMENT_SENSOR
  7181. #ifdef PAT9125
  7182. static bool lcd_selftest_fsensor(void)
  7183. {
  7184. fsensor_init();
  7185. if (fsensor_not_responding)
  7186. {
  7187. lcd_selftest_error(TestError::WiringFsensor, "", "");
  7188. }
  7189. return (!fsensor_not_responding);
  7190. }
  7191. #endif //PAT9125
  7192. //! @brief Self-test of infrared barrier filament sensor mounted on MK3S with MMUv2 printer
  7193. //!
  7194. //! Test whether sensor is not triggering filament presence when extruder idler is moving without filament.
  7195. //!
  7196. //! Steps:
  7197. //! * Backup current active extruder temperature
  7198. //! * Pre-heat to PLA extrude temperature.
  7199. //! * Unload filament possibly present.
  7200. //! * Move extruder idler same way as during filament load
  7201. //! and sample IR_SENSOR_PIN.
  7202. //! * Check that pin doesn't go low.
  7203. //!
  7204. //! @retval true passed
  7205. //! @retval false failed
  7206. static bool selftest_irsensor()
  7207. {
  7208. class TempBackup
  7209. {
  7210. public:
  7211. TempBackup():
  7212. m_temp(degTargetHotend(active_extruder)),
  7213. m_extruder(active_extruder){}
  7214. ~TempBackup(){setTargetHotend(m_temp,m_extruder);}
  7215. private:
  7216. float m_temp;
  7217. uint8_t m_extruder;
  7218. };
  7219. uint8_t progress;
  7220. {
  7221. TempBackup tempBackup;
  7222. setTargetHotend(ABS_PREHEAT_HOTEND_TEMP,active_extruder);
  7223. mmu_wait_for_heater_blocking();
  7224. progress = lcd_selftest_screen(TestScreen::Fsensor, 0, 1, true, 0);
  7225. mmu_filament_ramming();
  7226. }
  7227. progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  7228. mmu_command(MmuCmd::U0);
  7229. manage_response(false, false);
  7230. for(uint_least8_t i = 0; i < 200; ++i)
  7231. {
  7232. if (0 == (i % 32)) progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  7233. mmu_load_step(false);
  7234. while (blocks_queued())
  7235. {
  7236. if (READ(IR_SENSOR_PIN) == 0)
  7237. {
  7238. lcd_selftest_error(TestError::TriggeringFsensor, "", "");
  7239. return false;
  7240. }
  7241. #ifdef TMC2130
  7242. manage_heater();
  7243. // Vojtech: Don't disable motors inside the planner!
  7244. if (!tmc2130_update_sg())
  7245. {
  7246. manage_inactivity(true);
  7247. }
  7248. #else //TMC2130
  7249. manage_heater();
  7250. // Vojtech: Don't disable motors inside the planner!
  7251. manage_inactivity(true);
  7252. #endif //TMC2130
  7253. }
  7254. }
  7255. return true;
  7256. }
  7257. #endif //FILAMENT_SENSOR
  7258. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  7259. bool _default)
  7260. {
  7261. bool _result = check_opposite;
  7262. lcd_clear();
  7263. lcd_puts_at_P(0, 0, _T(MSG_SELFTEST_FAN));
  7264. switch (_fan)
  7265. {
  7266. case 0:
  7267. // extruder cooling fan
  7268. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_COOLING_FAN) : _T(MSG_SELFTEST_EXTRUDER_FAN));
  7269. setExtruderAutoFanState(3);
  7270. break;
  7271. case 1:
  7272. // object cooling fan
  7273. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_EXTRUDER_FAN) : _T(MSG_SELFTEST_COOLING_FAN));
  7274. SET_OUTPUT(FAN_PIN);
  7275. #ifdef FAN_SOFT_PWM
  7276. fanSpeedSoftPwm = 255;
  7277. #else //FAN_SOFT_PWM
  7278. analogWrite(FAN_PIN, 255);
  7279. #endif //FAN_SOFT_PWM
  7280. break;
  7281. }
  7282. _delay(500);
  7283. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7284. lcd_putc_at(0, 3, '>');
  7285. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7286. int8_t enc_dif = int(_default)*3;
  7287. KEEPALIVE_STATE(PAUSED_FOR_USER);
  7288. lcd_button_pressed = false;
  7289. do
  7290. {
  7291. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  7292. if (enc_dif > lcd_encoder_diff) {
  7293. _result = !check_opposite;
  7294. lcd_putc_at(0, 2, '>');
  7295. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7296. lcd_putc_at(0, 3, ' ');
  7297. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7298. }
  7299. if (enc_dif < lcd_encoder_diff) {
  7300. _result = check_opposite;
  7301. lcd_putc_at(0, 2, ' ');
  7302. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7303. lcd_putc_at(0, 3, '>');
  7304. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7305. }
  7306. enc_dif = 0;
  7307. lcd_encoder_diff = 0;
  7308. }
  7309. manage_heater();
  7310. _delay(100);
  7311. } while (!lcd_clicked());
  7312. KEEPALIVE_STATE(IN_HANDLER);
  7313. setExtruderAutoFanState(0);
  7314. SET_OUTPUT(FAN_PIN);
  7315. #ifdef FAN_SOFT_PWM
  7316. fanSpeedSoftPwm = 0;
  7317. #else //FAN_SOFT_PWM
  7318. analogWrite(FAN_PIN, 0);
  7319. #endif //FAN_SOFT_PWM
  7320. fanSpeed = 0;
  7321. manage_heater();
  7322. return _result;
  7323. }
  7324. #ifdef FANCHECK
  7325. static FanCheck lcd_selftest_fan_auto(int _fan)
  7326. {
  7327. switch (_fan) {
  7328. case 0:
  7329. fanSpeed = 0;
  7330. manage_heater(); //turn off fan
  7331. setExtruderAutoFanState(3); //extruder fan
  7332. #ifdef FAN_SOFT_PWM
  7333. extruder_autofan_last_check = _millis();
  7334. fan_measuring = true;
  7335. #endif //FAN_SOFT_PWM
  7336. _delay(2000);
  7337. setExtruderAutoFanState(0); //extruder fan
  7338. manage_heater(); //count average fan speed from 2s delay and turn off fans
  7339. puts_P(PSTR("Test 1:"));
  7340. printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
  7341. printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
  7342. if (fan_speed[0] < 20) { // < 1200 RPM would mean either a faulty Noctua or Altfan
  7343. return FanCheck::ExtruderFan;
  7344. }
  7345. #ifdef FAN_SOFT_PWM
  7346. else if (fan_speed[0] > 50 ) { // printerFan is faster
  7347. return FanCheck::SwappedFan;
  7348. }
  7349. break;
  7350. #endif
  7351. case 1:
  7352. //will it work with Thotend > 50 C ?
  7353. #ifdef FAN_SOFT_PWM
  7354. fanSpeed = 255;
  7355. fanSpeedSoftPwm = 255;
  7356. extruder_autofan_last_check = _millis(); //store time when measurement starts
  7357. fan_measuring = true; //start fan measuring, rest is on manage_heater
  7358. #else //FAN_SOFT_PWM
  7359. fanSpeed = 150; //print fan
  7360. #endif //FAN_SOFT_PWM
  7361. for (uint8_t i = 0; i < 5; i++) {
  7362. delay_keep_alive(1000);
  7363. lcd_putc_at(18, 3, '-');
  7364. delay_keep_alive(1000);
  7365. lcd_putc_at(18, 3, '|');
  7366. }
  7367. fanSpeed = 0;
  7368. #ifdef FAN_SOFT_PWM
  7369. fanSpeedSoftPwm = 0;
  7370. #else //FAN_SOFT_PWM
  7371. manage_heater(); //turn off fan
  7372. manage_inactivity(true); //to turn off print fan
  7373. #endif //FAN_SOFT_PWM
  7374. puts_P(PSTR("Test 2:"));
  7375. printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
  7376. printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
  7377. if (!fan_speed[1]) {
  7378. return FanCheck::PrintFan;
  7379. }
  7380. #ifdef FAN_SOFT_PWM
  7381. fanSpeed = 80;
  7382. fanSpeedSoftPwm = 80;
  7383. for (uint8_t i = 0; i < 5; i++) {
  7384. delay_keep_alive(1000);
  7385. lcd_putc_at(18, 3, '-');
  7386. delay_keep_alive(1000);
  7387. lcd_putc_at(18, 3, '|');
  7388. }
  7389. fanSpeed = 0;
  7390. // noctua speed is between 17 and 24, turbine more then 30
  7391. if (fan_speed[1] < 30) {
  7392. return FanCheck::SwappedFan;
  7393. }
  7394. #else
  7395. // fan is spinning, but measured RPM are too low for print fan, it must
  7396. // be left extruder fan
  7397. else if (fan_speed[1] < 34) {
  7398. return FanCheck::SwappedFan;
  7399. }
  7400. #endif //FAN_SOFT_PWM
  7401. break;
  7402. }
  7403. return FanCheck::Success;
  7404. }
  7405. #endif //FANCHECK
  7406. static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay)
  7407. {
  7408. lcd_update_enable(false);
  7409. const char *_indicator = (_progress >= _progress_scale) ? "-" : "|";
  7410. if (_clear) lcd_clear();
  7411. lcd_set_cursor(0, 0);
  7412. if (screen == TestScreen::ExtruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7413. if (screen == TestScreen::PrintFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7414. if (screen == TestScreen::FansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7415. if (screen == TestScreen::EndStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20
  7416. if (screen == TestScreen::AxisX) lcd_puts_P(_T(MSG_CHECKING_X));
  7417. if (screen == TestScreen::AxisY) lcd_puts_P(_T(MSG_CHECKING_Y));
  7418. if (screen == TestScreen::AxisZ) lcd_puts_P(_i("Checking Z axis"));////MSG_SELFTEST_CHECK_Z c=20
  7419. if (screen == TestScreen::Bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  7420. if (screen == TestScreen::Hotend
  7421. || screen == TestScreen::HotendOk) lcd_puts_P(_i("Checking hotend"));////MSG_SELFTEST_CHECK_HOTEND c=20
  7422. if (screen == TestScreen::Fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  7423. if (screen == TestScreen::FsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  7424. if (screen == TestScreen::AllCorrect) lcd_puts_P(_i("All correct"));////MSG_SELFTEST_CHECK_ALLCORRECT c=20
  7425. if (screen == TestScreen::Failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  7426. if (screen == TestScreen::Home) lcd_puts_P(_i("Calibrating home"));////MSG_CALIBRATING_HOME c=20
  7427. lcd_puts_at_P(0, 1, separator);
  7428. if ((screen >= TestScreen::ExtruderFan) && (screen <= TestScreen::FansOk))
  7429. {
  7430. //SERIAL_ECHOLNPGM("Fan test");
  7431. lcd_puts_at_P(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18
  7432. lcd_set_cursor(18, 2);
  7433. (screen < TestScreen::PrintFan) ? lcd_print(_indicator) : lcd_print("OK");
  7434. lcd_puts_at_P(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18
  7435. lcd_set_cursor(18, 3);
  7436. (screen < TestScreen::FansOk) ? lcd_print(_indicator) : lcd_print("OK");
  7437. }
  7438. else if (screen >= TestScreen::Fsensor && screen <= TestScreen::FsensorOk)
  7439. {
  7440. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7441. lcd_putc(':');
  7442. lcd_set_cursor(18, 2);
  7443. (screen == TestScreen::Fsensor) ? lcd_print(_indicator) : lcd_print("OK");
  7444. }
  7445. else if (screen < TestScreen::Fsensor)
  7446. {
  7447. //SERIAL_ECHOLNPGM("Other tests");
  7448. TestScreen _step_block = TestScreen::AxisX;
  7449. lcd_selftest_screen_step(2, 2, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("X"), _indicator);
  7450. _step_block = TestScreen::AxisY;
  7451. lcd_selftest_screen_step(2, 8, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Y"), _indicator);
  7452. _step_block = TestScreen::AxisZ;
  7453. lcd_selftest_screen_step(2, 14, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Z"), _indicator);
  7454. _step_block = TestScreen::Bed;
  7455. lcd_selftest_screen_step(3, 0, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Bed"), _indicator);
  7456. _step_block = TestScreen::Hotend;
  7457. lcd_selftest_screen_step(3, 9, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Hotend"), _indicator);
  7458. }
  7459. if (_delay > 0) delay_keep_alive(_delay);
  7460. _progress++;
  7461. return (_progress >= _progress_scale * 2) ? 0 : _progress;
  7462. }
  7463. static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name_PROGMEM, const char *_indicator)
  7464. {
  7465. lcd_set_cursor(_col, _row);
  7466. uint8_t strlenNameP = strlen_P(_name_PROGMEM);
  7467. switch (_state)
  7468. {
  7469. case 1:
  7470. lcd_puts_P(_name_PROGMEM);
  7471. lcd_putc_at(_col + strlenNameP, _row, ':');
  7472. lcd_set_cursor(_col + strlenNameP + 1, _row);
  7473. lcd_print(_indicator);
  7474. break;
  7475. case 2:
  7476. lcd_puts_P(_name_PROGMEM);
  7477. lcd_putc_at(_col + strlenNameP, _row, ':');
  7478. lcd_puts_at_P(_col + strlenNameP + 1, _row, PSTR("OK"));
  7479. break;
  7480. default:
  7481. lcd_puts_P(_name_PROGMEM);
  7482. }
  7483. }
  7484. /** End of menus **/
  7485. /** Menu action functions **/
  7486. static bool check_file(const char* filename) {
  7487. if (farm_mode) return true;
  7488. card.openFileReadFilteredGcode(filename, true);
  7489. bool result = false;
  7490. const uint32_t filesize = card.getFileSize();
  7491. uint32_t startPos = 0;
  7492. const uint16_t bytesToCheck = min(END_FILE_SECTION, filesize);
  7493. if (filesize > END_FILE_SECTION) {
  7494. startPos = filesize - END_FILE_SECTION;
  7495. card.setIndex(startPos);
  7496. }
  7497. cmdqueue_reset();
  7498. cmdqueue_serial_disabled = true;
  7499. menu_progressbar_init(bytesToCheck, _i("Checking file"));////MSG_CHECKING_FILE c=17
  7500. while (!card.eof() && !result) {
  7501. menu_progressbar_update(card.get_sdpos() - startPos);
  7502. card.sdprinting = true;
  7503. get_command();
  7504. result = check_commands();
  7505. }
  7506. menu_progressbar_finish();
  7507. cmdqueue_serial_disabled = false;
  7508. card.printingHasFinished();
  7509. lcd_setstatuspgm(MSG_WELCOME);
  7510. lcd_finishstatus();
  7511. return result;
  7512. }
  7513. static void menu_action_sdfile(const char* filename)
  7514. {
  7515. loading_flag = false;
  7516. char cmd[30];
  7517. char* c;
  7518. bool result = true;
  7519. sprintf_P(cmd, PSTR("M23 %s"), filename);
  7520. for (c = &cmd[4]; *c; c++)
  7521. *c = tolower(*c);
  7522. const char end[5] = ".gco";
  7523. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  7524. for (uint_least8_t i = 0; i < 8; i++) {
  7525. if (strcmp((cmd + i + 4), end) == 0) {
  7526. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  7527. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  7528. break;
  7529. }
  7530. else {
  7531. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  7532. }
  7533. }
  7534. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  7535. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  7536. for (uint_least8_t i = 0; i < depth; i++) {
  7537. for (uint_least8_t j = 0; j < 8; j++) {
  7538. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, card.dir_names[i][j]);
  7539. }
  7540. }
  7541. //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
  7542. //to open a file. Instead, the cached filename in cmd is used as that one is static for the whole lifetime of this function.
  7543. if (!check_file(cmd + 4)) {
  7544. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=3
  7545. lcd_update_enable(true);
  7546. }
  7547. if (result) {
  7548. enquecommand(cmd);
  7549. enquecommand_P(PSTR("M24"));
  7550. }
  7551. lcd_return_to_status();
  7552. }
  7553. void menu_action_sddirectory(const char* filename)
  7554. {
  7555. card.chdir(filename, true);
  7556. lcd_encoder = 0;
  7557. menu_data_reset(); //Forces reloading of cached variables.
  7558. }
  7559. /** LCD API **/
  7560. void ultralcd_init()
  7561. {
  7562. {
  7563. uint8_t autoDepleteRaw = eeprom_read_byte(reinterpret_cast<uint8_t*>(EEPROM_AUTO_DEPLETE));
  7564. if (0xff == autoDepleteRaw) lcd_autoDeplete = false;
  7565. else lcd_autoDeplete = autoDepleteRaw;
  7566. }
  7567. backlight_init();
  7568. lcd_init();
  7569. lcd_refresh();
  7570. lcd_longpress_func = menu_lcd_longpress_func;
  7571. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  7572. menu_menu = lcd_status_screen;
  7573. SET_INPUT(BTN_EN1);
  7574. SET_INPUT(BTN_EN2);
  7575. WRITE(BTN_EN1, HIGH);
  7576. WRITE(BTN_EN2, HIGH);
  7577. #if BTN_ENC > 0
  7578. SET_INPUT(BTN_ENC);
  7579. WRITE(BTN_ENC, HIGH);
  7580. #endif
  7581. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  7582. SET_INPUT(SDCARDDETECT);
  7583. WRITE(SDCARDDETECT, HIGH);
  7584. lcd_oldcardstatus = IS_SD_INSERTED;
  7585. #endif//(SDCARDDETECT > 0)
  7586. lcd_encoder_diff = 0;
  7587. }
  7588. void lcd_printer_connected() {
  7589. printer_connected = true;
  7590. }
  7591. static void lcd_send_status() {
  7592. if (farm_mode && no_response && (NcTime.expired(NC_TIME * 1000))) {
  7593. //send important status messages periodicaly
  7594. prusa_statistics(important_status, saved_filament_type);
  7595. NcTime.start();
  7596. #ifdef FARM_CONNECT_MESSAGE
  7597. lcd_connect_printer();
  7598. #endif //FARM_CONNECT_MESSAGE
  7599. }
  7600. }
  7601. #ifdef FARM_CONNECT_MESSAGE
  7602. static void lcd_connect_printer() {
  7603. lcd_update_enable(false);
  7604. lcd_clear();
  7605. int i = 0;
  7606. int t = 0;
  7607. lcd_puts_at_P(0, 0, _i("Connect printer to"));
  7608. lcd_puts_at_P(0, 1, _i("monitoring or hold"));
  7609. lcd_puts_at_P(0, 2, _i("the knob to continue"));
  7610. while (no_response) {
  7611. i++;
  7612. t++;
  7613. delay_keep_alive(100);
  7614. proc_commands();
  7615. if (t == 10) {
  7616. prusa_statistics(important_status, saved_filament_type);
  7617. t = 0;
  7618. }
  7619. if (READ(BTN_ENC)) { //if button is not pressed
  7620. i = 0;
  7621. lcd_puts_at_P(0, 3, PSTR(" "));
  7622. }
  7623. if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, LCD_STR_SOLID_BLOCK[0]);
  7624. if (i == NC_BUTTON_LONG_PRESS * 10) {
  7625. no_response = false;
  7626. }
  7627. }
  7628. lcd_update_enable(true);
  7629. lcd_update(2);
  7630. }
  7631. #endif //FARM_CONNECT_MESSAGE
  7632. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  7633. if (farm_mode) {
  7634. bool empty = cmd_buffer_empty();
  7635. if ((_millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  7636. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  7637. //therefore longer period is used
  7638. printer_connected = false;
  7639. }
  7640. else {
  7641. lcd_printer_connected();
  7642. }
  7643. }
  7644. }
  7645. void lcd_ignore_click(bool b)
  7646. {
  7647. ignore_click = b;
  7648. wait_for_unclick = false;
  7649. }
  7650. void lcd_finishstatus() {
  7651. SERIAL_PROTOCOLLNRPGM(MSG_LCD_STATUS_CHANGED);
  7652. int len = strlen(lcd_status_message);
  7653. if (len > 0) {
  7654. while (len < LCD_WIDTH) {
  7655. lcd_status_message[len++] = ' ';
  7656. }
  7657. }
  7658. lcd_status_message[LCD_WIDTH] = '\0';
  7659. lcd_draw_update = 2;
  7660. }
  7661. void lcd_setstatus(const char* message)
  7662. {
  7663. if (lcd_status_message_level > 0)
  7664. return;
  7665. lcd_updatestatus(message);
  7666. }
  7667. void lcd_updatestatuspgm(const char *message){
  7668. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  7669. lcd_status_message[LCD_WIDTH] = 0;
  7670. lcd_finishstatus();
  7671. // hack lcd_draw_update to 1, i.e. without clear
  7672. lcd_draw_update = 1;
  7673. }
  7674. void lcd_setstatuspgm(const char* message)
  7675. {
  7676. if (lcd_status_message_level > 0)
  7677. return;
  7678. lcd_updatestatuspgm(message);
  7679. }
  7680. void lcd_updatestatus(const char *message){
  7681. strncpy(lcd_status_message, message, LCD_WIDTH);
  7682. lcd_status_message[LCD_WIDTH] = 0;
  7683. lcd_finishstatus();
  7684. // hack lcd_draw_update to 1, i.e. without clear
  7685. lcd_draw_update = 1;
  7686. }
  7687. void lcd_setalertstatuspgm(const char* message, uint8_t severity)
  7688. {
  7689. if (severity > lcd_status_message_level) {
  7690. lcd_updatestatuspgm(message);
  7691. lcd_status_message_level = severity;
  7692. lcd_return_to_status();
  7693. }
  7694. }
  7695. void lcd_setalertstatus(const char* message, uint8_t severity)
  7696. {
  7697. if (severity > lcd_status_message_level) {
  7698. lcd_updatestatus(message);
  7699. lcd_status_message_level = severity;
  7700. lcd_return_to_status();
  7701. }
  7702. }
  7703. void lcd_reset_alert_level()
  7704. {
  7705. lcd_status_message_level = 0;
  7706. }
  7707. uint8_t get_message_level()
  7708. {
  7709. return lcd_status_message_level;
  7710. }
  7711. void menu_lcd_longpress_func(void)
  7712. {
  7713. backlight_wake();
  7714. if (homing_flag || mesh_bed_leveling_flag || menu_menu == lcd_babystep_z || menu_menu == lcd_move_z)
  7715. {
  7716. // disable longpress during re-entry, while homing or calibration
  7717. lcd_quick_feedback();
  7718. return;
  7719. }
  7720. if (menu_menu == lcd_hw_setup_menu)
  7721. {
  7722. // only toggle the experimental menu visibility flag
  7723. lcd_quick_feedback();
  7724. lcd_experimental_toggle();
  7725. return;
  7726. }
  7727. // explicitely listed menus which are allowed to rise the move-z or live-adj-z functions
  7728. // The lists are not the same for both functions, so first decide which function is to be performed
  7729. if ( (moves_planned() || IS_SD_PRINTING || is_usb_printing )){ // long press as live-adj-z
  7730. if(( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height
  7731. && ( menu_menu == lcd_status_screen // and in listed menus...
  7732. || menu_menu == lcd_main_menu
  7733. || menu_menu == lcd_tune_menu
  7734. || menu_menu == lcd_support_menu
  7735. )
  7736. ){
  7737. lcd_clear();
  7738. menu_submenu(lcd_babystep_z);
  7739. } else {
  7740. // otherwise consume the long press as normal click
  7741. if( menu_menu != lcd_status_screen )
  7742. menu_back();
  7743. }
  7744. } else { // long press as move-z
  7745. if(menu_menu == lcd_status_screen
  7746. || menu_menu == lcd_main_menu
  7747. || menu_menu == lcd_preheat_menu
  7748. || menu_menu == lcd_sdcard_menu
  7749. || menu_menu == lcd_settings_menu
  7750. || menu_menu == lcd_control_temperature_menu
  7751. #if (LANG_MODE != 0)
  7752. || menu_menu == lcd_language
  7753. #endif
  7754. || menu_menu == lcd_support_menu
  7755. ){
  7756. menu_submenu(lcd_move_z);
  7757. } else {
  7758. // otherwise consume the long press as normal click
  7759. if( menu_menu != lcd_status_screen )
  7760. menu_back();
  7761. }
  7762. }
  7763. }
  7764. static inline bool z_menu_expired()
  7765. {
  7766. return (menu_menu == lcd_babystep_z
  7767. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  7768. }
  7769. static inline bool other_menu_expired()
  7770. {
  7771. return (menu_menu != lcd_status_screen
  7772. && menu_menu != lcd_babystep_z
  7773. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  7774. }
  7775. static inline bool forced_menu_expire()
  7776. {
  7777. bool retval = (menu_menu != lcd_status_screen
  7778. && forceMenuExpire);
  7779. forceMenuExpire = false;
  7780. return retval;
  7781. }
  7782. void menu_lcd_lcdupdate_func(void)
  7783. {
  7784. #if (SDCARDDETECT > 0)
  7785. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  7786. {
  7787. if(menu_menu == lcd_sdcard_menu) {
  7788. // If the user is either inside the submenus
  7789. // 1. 'Print from SD' --> and SD card is removed
  7790. // 2. 'No SD card' --> and SD card is inserted
  7791. //
  7792. // 1. 'Print from SD': We want to back out of this submenu
  7793. // and instead show the submenu title 'No SD card'.
  7794. //
  7795. // 2. 'No SD card': When the user inserts the SD card we want
  7796. // to back out of this submenu. Not only to show
  7797. // 'Print from SD' submenu title but also because the user
  7798. // will be prompted with another menu with the sorted list of files.
  7799. // Without backing out of the menu, the list will appear empty and
  7800. // The user will need to back out of two nested submenus.
  7801. menu_back();
  7802. }
  7803. lcd_draw_update = 2;
  7804. lcd_oldcardstatus = IS_SD_INSERTED;
  7805. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  7806. backlight_wake();
  7807. if (lcd_oldcardstatus)
  7808. {
  7809. if (!card.cardOK)
  7810. {
  7811. card.initsd(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back()
  7812. card.presort_flag = true; //force sorting of the SD menu
  7813. }
  7814. LCD_MESSAGERPGM(MSG_WELCOME);
  7815. bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  7816. menu_submenu(lcd_sdcard_menu);
  7817. lcd_timeoutToStatus.start();
  7818. }
  7819. else
  7820. {
  7821. card.release();
  7822. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=20
  7823. }
  7824. }
  7825. #endif//CARDINSERTED
  7826. backlight_update();
  7827. if (lcd_next_update_millis < _millis())
  7828. {
  7829. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  7830. {
  7831. if (lcd_draw_update == 0)
  7832. lcd_draw_update = 1;
  7833. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  7834. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  7835. lcd_encoder_diff = 0;
  7836. lcd_timeoutToStatus.start();
  7837. backlight_wake();
  7838. }
  7839. if (LCD_CLICKED)
  7840. {
  7841. lcd_timeoutToStatus.start();
  7842. backlight_wake();
  7843. }
  7844. (*menu_menu)();
  7845. if (z_menu_expired() || other_menu_expired() || forced_menu_expire())
  7846. {
  7847. // Exiting a menu. Let's call the menu function the last time with menu_leaving flag set to true
  7848. // to give it a chance to save its state.
  7849. // This is useful for example, when the babystep value has to be written into EEPROM.
  7850. if (menu_menu != NULL)
  7851. {
  7852. menu_leaving = 1;
  7853. (*menu_menu)();
  7854. menu_leaving = 0;
  7855. }
  7856. lcd_clear();
  7857. lcd_return_to_status();
  7858. lcd_draw_update = 2;
  7859. }
  7860. if (lcd_draw_update == 2) lcd_clear();
  7861. if (lcd_draw_update) lcd_draw_update--;
  7862. lcd_next_update_millis = _millis() + LCD_UPDATE_INTERVAL;
  7863. }
  7864. lcd_ping(); //check that we have received ping command if we are in farm mode
  7865. lcd_send_status();
  7866. if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands();
  7867. }
  7868. #ifdef TMC2130
  7869. //! @brief Is crash detection enabled?
  7870. //!
  7871. //! @retval true crash detection enabled
  7872. //! @retval false crash detection disabled
  7873. bool lcd_crash_detect_enabled()
  7874. {
  7875. return eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET);
  7876. }
  7877. void lcd_crash_detect_enable()
  7878. {
  7879. tmc2130_sg_stop_on_crash = true;
  7880. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF);
  7881. }
  7882. void lcd_crash_detect_disable()
  7883. {
  7884. tmc2130_sg_stop_on_crash = false;
  7885. tmc2130_sg_crash = 0;
  7886. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00);
  7887. }
  7888. #endif
  7889. void lcd_experimental_toggle()
  7890. {
  7891. uint8_t oldVal = eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  7892. if (oldVal == EEPROM_EMPTY_VALUE)
  7893. oldVal = 0;
  7894. else
  7895. oldVal = !oldVal;
  7896. eeprom_update_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, oldVal);
  7897. }
  7898. #ifdef TMC2130
  7899. void UserECool_toggle(){
  7900. // 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
  7901. // 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)
  7902. bool enable = ! UserECoolEnabled();
  7903. eeprom_update_byte((uint8_t *)EEPROM_ECOOL_ENABLE, enable ? EEPROM_ECOOL_MAGIC_NUMBER : EEPROM_EMPTY_VALUE);
  7904. // @@TODO I don't like this - disabling the experimental menu shall disable ECool mode, but it will not reinit the TMC
  7905. // 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.
  7906. tmc2130_init(TMCInitParams(enable));
  7907. }
  7908. #endif
  7909. /// Enable experimental support for cooler operation of the extruder motor
  7910. /// Beware - REQUIRES original Prusa MK3/S/+ extruder motor with adequate maximal current
  7911. /// Therefore we don't want to allow general usage of this feature in public as the community likes to
  7912. /// change motors for various reasons and unless the motor is rotating, we cannot verify its properties
  7913. /// (which would be obviously too late for an improperly sized motor)
  7914. /// For farm printing, the cooler E-motor is enabled by default.
  7915. bool UserECoolEnabled(){
  7916. // We enable E-cool mode for non-farm prints IFF the experimental menu is visible AND the EEPROM_ECOOL variable has
  7917. // a value of the universal answer to all problems of the universe
  7918. return ( eeprom_read_byte((uint8_t *)EEPROM_ECOOL_ENABLE) == EEPROM_ECOOL_MAGIC_NUMBER )
  7919. && ( eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY) == 1 );
  7920. }
  7921. bool FarmOrUserECool(){
  7922. return farm_mode || UserECoolEnabled();
  7923. }
  7924. void lcd_experimental_menu()
  7925. {
  7926. MENU_BEGIN();
  7927. MENU_ITEM_BACK_P(_T(MSG_BACK));
  7928. #ifdef EXTRUDER_ALTFAN_DETECT
  7929. MENU_ITEM_TOGGLE_P(_N("ALTFAN det."), altfanOverride_get()?_T(MSG_OFF):_T(MSG_ON), altfanOverride_toggle);////MSG_MENU_ALTFAN c=18
  7930. #endif //EXTRUDER_ALTFAN_DETECT
  7931. #ifdef TMC2130
  7932. MENU_ITEM_TOGGLE_P(_N("E-cool mode"), UserECoolEnabled()?_T(MSG_ON):_T(MSG_OFF), UserECool_toggle);////MSG_MENU_ECOOL c=18
  7933. #endif
  7934. MENU_END();
  7935. }
  7936. #ifdef PINDA_TEMP_COMP
  7937. void lcd_pinda_temp_compensation_toggle()
  7938. {
  7939. uint8_t pinda_temp_compensation = eeprom_read_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION);
  7940. if (pinda_temp_compensation == EEPROM_EMPTY_VALUE) // On MK2.5/S the EEPROM_EMPTY_VALUE will be set to 0 during eeprom_init.
  7941. pinda_temp_compensation = 1; // But for MK3/S it should be 1 so SuperPINDA is "active"
  7942. else
  7943. pinda_temp_compensation = !pinda_temp_compensation;
  7944. eeprom_update_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION, pinda_temp_compensation);
  7945. SERIAL_ECHOLNPGM("SuperPINDA:");
  7946. SERIAL_ECHOLN(pinda_temp_compensation);
  7947. }
  7948. #endif //PINDA_TEMP_COMP