ultralcd.cpp 237 KB

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