ultralcd.cpp 202 KB

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