ultralcd.cpp 238 KB

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