ultralcd.cpp 202 KB

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