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_cursor(0, 4);
  2618. lcd_print(LCD_STR_THERMOMETER[0]);
  2619. lcd_print(ftostr3(degHotend(active_extruder)));
  2620. lcd_print("/");
  2621. lcd_print(ftostr3(degTargetHotend(active_extruder)));
  2622. lcd_print(LCD_STR_DEGREE);
  2623. }
  2624. void lcd_wait_for_cool_down() {
  2625. lcd_set_custom_characters_degree();
  2626. setAllTargetHotends(0);
  2627. setTargetBed(0);
  2628. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2629. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=3
  2630. lcd_set_cursor(0, 4);
  2631. lcd_print(LCD_STR_THERMOMETER[0]);
  2632. lcd_print(ftostr3(degHotend(0)));
  2633. lcd_print("/0");
  2634. lcd_print(LCD_STR_DEGREE);
  2635. lcd_set_cursor(9, 4);
  2636. lcd_print(LCD_STR_BEDTEMP[0]);
  2637. lcd_print(ftostr3(degBed()));
  2638. lcd_print("/0");
  2639. lcd_print(LCD_STR_DEGREE);
  2640. lcd_set_custom_characters();
  2641. delay_keep_alive(1000);
  2642. serialecho_temperatures();
  2643. }
  2644. lcd_set_custom_characters_arrows();
  2645. lcd_update_enable(true);
  2646. }
  2647. // Lets the user move the Z carriage up to the end stoppers.
  2648. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2649. // Otherwise the Z calibration is not changed and false is returned.
  2650. #ifndef TMC2130
  2651. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2652. {
  2653. bool clean_nozzle_asked = false;
  2654. // 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.
  2655. current_position[Z_AXIS] = 0;
  2656. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2657. // Until confirmed by the confirmation dialog.
  2658. for (;;) {
  2659. unsigned long previous_millis_cmd = millis();
  2660. 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
  2661. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2662. const bool multi_screen = msg_next != NULL;
  2663. unsigned long previous_millis_msg = millis();
  2664. // Until the user finishes the z up movement.
  2665. lcd_encoder_diff = 0;
  2666. lcd_encoder = 0;
  2667. for (;;) {
  2668. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2669. // goto canceled;
  2670. manage_heater();
  2671. manage_inactivity(true);
  2672. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2673. delay(50);
  2674. previous_millis_cmd = millis();
  2675. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2676. lcd_encoder_diff = 0;
  2677. if (! planner_queue_full()) {
  2678. // Only move up, whatever direction the user rotates the encoder.
  2679. current_position[Z_AXIS] += fabs(lcd_encoder);
  2680. lcd_encoder = 0;
  2681. 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);
  2682. }
  2683. }
  2684. if (lcd_clicked()) {
  2685. // Abort a move if in progress.
  2686. planner_abort_hard();
  2687. while (lcd_clicked()) ;
  2688. delay(10);
  2689. while (lcd_clicked()) ;
  2690. break;
  2691. }
  2692. if (multi_screen && millis() - previous_millis_msg > 5000) {
  2693. if (msg_next == NULL)
  2694. msg_next = msg;
  2695. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2696. previous_millis_msg = millis();
  2697. }
  2698. }
  2699. if (! clean_nozzle_asked) {
  2700. lcd_show_fullscreen_message_and_wait_P(_T(MSG_CONFIRM_NOZZLE_CLEAN));
  2701. clean_nozzle_asked = true;
  2702. }
  2703. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2704. 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
  2705. if (result == -1)
  2706. goto canceled;
  2707. else if (result == 1)
  2708. goto calibrated;
  2709. // otherwise perform another round of the Z up dialog.
  2710. }
  2711. calibrated:
  2712. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2713. // during the search for the induction points.
  2714. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2715. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2716. if(only_z){
  2717. lcd_display_message_fullscreen_P(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1));
  2718. lcd_set_cursor(0, 3);
  2719. lcd_print(1);
  2720. lcd_puts_P(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2));
  2721. }else{
  2722. //lcd_show_fullscreen_message_and_wait_P(_T(MSG_PAPER));
  2723. lcd_display_message_fullscreen_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1));
  2724. lcd_set_cursor(0, 2);
  2725. lcd_print(1);
  2726. lcd_puts_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2));
  2727. }
  2728. return true;
  2729. canceled:
  2730. return false;
  2731. }
  2732. #endif // TMC2130
  2733. static inline bool pgm_is_whitespace(const char *c_addr)
  2734. {
  2735. const char c = pgm_read_byte(c_addr);
  2736. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2737. }
  2738. static inline bool pgm_is_interpunction(const char *c_addr)
  2739. {
  2740. const char c = pgm_read_byte(c_addr);
  2741. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2742. }
  2743. /**
  2744. * @brief show full screen message
  2745. *
  2746. * This function is non-blocking
  2747. * @param msg message to be displayed from PROGMEM
  2748. * @param nlines
  2749. * @return rest of the text (to be displayed on next page)
  2750. */
  2751. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines)
  2752. {
  2753. lcd_set_cursor(0, 0);
  2754. const char *msgend = msg;
  2755. uint8_t row = 0;
  2756. bool multi_screen = false;
  2757. for (; row < 4; ++ row) {
  2758. while (pgm_is_whitespace(msg))
  2759. ++ msg;
  2760. if (pgm_read_byte(msg) == 0)
  2761. // End of the message.
  2762. break;
  2763. lcd_set_cursor(0, row);
  2764. uint8_t linelen = min(strlen_P(msg), 20);
  2765. const char *msgend2 = msg + linelen;
  2766. msgend = msgend2;
  2767. if (row == 3 && linelen == 20) {
  2768. // Last line of the display, full line shall be displayed.
  2769. // Find out, whether this message will be split into multiple screens.
  2770. while (pgm_is_whitespace(msgend))
  2771. ++ msgend;
  2772. multi_screen = pgm_read_byte(msgend) != 0;
  2773. if (multi_screen)
  2774. msgend = (msgend2 -= 2);
  2775. }
  2776. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2777. // Splitting a word. Find the start of the current word.
  2778. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2779. -- msgend;
  2780. if (msgend == msg)
  2781. // Found a single long word, which cannot be split. Just cut it.
  2782. msgend = msgend2;
  2783. }
  2784. for (; msg < msgend; ++ msg) {
  2785. char c = char(pgm_read_byte(msg));
  2786. if (c == '~')
  2787. c = ' ';
  2788. lcd_print(c);
  2789. }
  2790. }
  2791. if (multi_screen) {
  2792. // Display the "next screen" indicator character.
  2793. // lcd_set_custom_characters_arrows();
  2794. lcd_set_custom_characters_nextpage();
  2795. lcd_set_cursor(19, 3);
  2796. // Display the down arrow.
  2797. lcd_print(char(1));
  2798. }
  2799. nlines = row;
  2800. return multi_screen ? msgend : NULL;
  2801. }
  2802. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  2803. {
  2804. // Disable update of the screen by the usual lcd_update(0) routine.
  2805. lcd_update_enable(false);
  2806. lcd_clear();
  2807. // uint8_t nlines;
  2808. return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines);
  2809. }
  2810. const char* lcd_display_message_fullscreen_P(const char *msg)
  2811. {
  2812. uint8_t nlines;
  2813. return lcd_display_message_fullscreen_P(msg, nlines);
  2814. }
  2815. /**
  2816. * @brief show full screen message and wait
  2817. *
  2818. * This function is blocking.
  2819. * @param msg message to be displayed from PROGMEM
  2820. */
  2821. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2822. {
  2823. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2824. bool multi_screen = msg_next != NULL;
  2825. lcd_set_custom_characters_nextpage();
  2826. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2827. // Until confirmed by a button click.
  2828. for (;;) {
  2829. if (!multi_screen) {
  2830. lcd_set_cursor(19, 3);
  2831. // Display the confirm char.
  2832. lcd_print(char(2));
  2833. }
  2834. // Wait for 5 seconds before displaying the next text.
  2835. for (uint8_t i = 0; i < 100; ++ i) {
  2836. delay_keep_alive(50);
  2837. if (lcd_clicked()) {
  2838. while (lcd_clicked()) ;
  2839. delay(10);
  2840. while (lcd_clicked()) ;
  2841. if (msg_next == NULL) {
  2842. KEEPALIVE_STATE(IN_HANDLER);
  2843. lcd_set_custom_characters();
  2844. lcd_update_enable(true);
  2845. lcd_update(2);
  2846. return;
  2847. }
  2848. else {
  2849. break;
  2850. }
  2851. }
  2852. }
  2853. if (multi_screen) {
  2854. if (msg_next == NULL)
  2855. msg_next = msg;
  2856. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2857. if (msg_next == NULL) {
  2858. lcd_set_cursor(19, 3);
  2859. // Display the confirm char.
  2860. lcd_print(char(2));
  2861. }
  2862. }
  2863. }
  2864. }
  2865. void lcd_wait_for_click()
  2866. {
  2867. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2868. for (;;) {
  2869. manage_heater();
  2870. manage_inactivity(true);
  2871. if (lcd_clicked()) {
  2872. while (lcd_clicked()) ;
  2873. delay(10);
  2874. while (lcd_clicked()) ;
  2875. KEEPALIVE_STATE(IN_HANDLER);
  2876. return;
  2877. }
  2878. }
  2879. }
  2880. 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)
  2881. {
  2882. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2883. bool multi_screen = msg_next != NULL;
  2884. bool yes = default_yes ? true : false;
  2885. // Wait for user confirmation or a timeout.
  2886. unsigned long previous_millis_cmd = millis();
  2887. int8_t enc_dif = lcd_encoder_diff;
  2888. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  2889. for (;;) {
  2890. for (uint8_t i = 0; i < 100; ++i) {
  2891. delay_keep_alive(50);
  2892. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2893. return -1;
  2894. manage_heater();
  2895. manage_inactivity(true);
  2896. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  2897. if (msg_next == NULL) {
  2898. lcd_set_cursor(0, 3);
  2899. if (enc_dif < lcd_encoder_diff && yes) {
  2900. lcd_puts_P((PSTR(" ")));
  2901. lcd_set_cursor(7, 3);
  2902. lcd_puts_P((PSTR(">")));
  2903. yes = false;
  2904. }
  2905. else if (enc_dif > lcd_encoder_diff && !yes) {
  2906. lcd_puts_P((PSTR(">")));
  2907. lcd_set_cursor(7, 3);
  2908. lcd_puts_P((PSTR(" ")));
  2909. yes = true;
  2910. }
  2911. enc_dif = lcd_encoder_diff;
  2912. }
  2913. else {
  2914. break; //turning knob skips waiting loop
  2915. }
  2916. }
  2917. if (lcd_clicked()) {
  2918. while (lcd_clicked());
  2919. delay(10);
  2920. while (lcd_clicked());
  2921. if (msg_next == NULL) {
  2922. //KEEPALIVE_STATE(IN_HANDLER);
  2923. lcd_set_custom_characters();
  2924. return yes;
  2925. }
  2926. else break;
  2927. }
  2928. }
  2929. if (multi_screen) {
  2930. if (msg_next == NULL) {
  2931. msg_next = msg;
  2932. }
  2933. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2934. }
  2935. if (msg_next == NULL) {
  2936. lcd_set_cursor(0, 3);
  2937. if (yes) lcd_puts_P(PSTR(">"));
  2938. lcd_set_cursor(1, 3);
  2939. lcd_puts_P(_T(MSG_YES));
  2940. lcd_set_cursor(7, 3);
  2941. if (!yes) lcd_puts_P(PSTR(">"));
  2942. lcd_set_cursor(8, 3);
  2943. lcd_puts_P(_T(MSG_NO));
  2944. }
  2945. }
  2946. }
  2947. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  2948. {
  2949. lcd_display_message_fullscreen_P(msg);
  2950. if (default_yes) {
  2951. lcd_set_cursor(0, 2);
  2952. lcd_puts_P(PSTR(">"));
  2953. lcd_puts_P(_T(MSG_YES));
  2954. lcd_set_cursor(1, 3);
  2955. lcd_puts_P(_T(MSG_NO));
  2956. }
  2957. else {
  2958. lcd_set_cursor(1, 2);
  2959. lcd_puts_P(_T(MSG_YES));
  2960. lcd_set_cursor(0, 3);
  2961. lcd_puts_P(PSTR(">"));
  2962. lcd_puts_P(_T(MSG_NO));
  2963. }
  2964. bool yes = default_yes ? true : false;
  2965. // Wait for user confirmation or a timeout.
  2966. unsigned long previous_millis_cmd = millis();
  2967. int8_t enc_dif = lcd_encoder_diff;
  2968. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2969. for (;;) {
  2970. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2971. return -1;
  2972. manage_heater();
  2973. manage_inactivity(true);
  2974. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  2975. lcd_set_cursor(0, 2);
  2976. if (enc_dif < lcd_encoder_diff && yes) {
  2977. lcd_puts_P((PSTR(" ")));
  2978. lcd_set_cursor(0, 3);
  2979. lcd_puts_P((PSTR(">")));
  2980. yes = false;
  2981. }
  2982. else if (enc_dif > lcd_encoder_diff && !yes) {
  2983. lcd_puts_P((PSTR(">")));
  2984. lcd_set_cursor(0, 3);
  2985. lcd_puts_P((PSTR(" ")));
  2986. yes = true;
  2987. }
  2988. enc_dif = lcd_encoder_diff;
  2989. }
  2990. if (lcd_clicked()) {
  2991. while (lcd_clicked());
  2992. delay(10);
  2993. while (lcd_clicked());
  2994. KEEPALIVE_STATE(IN_HANDLER);
  2995. return yes;
  2996. }
  2997. }
  2998. }
  2999. void lcd_bed_calibration_show_result(uint8_t result, uint8_t point_too_far_mask)
  3000. {
  3001. const char *msg = NULL;
  3002. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  3003. 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
  3004. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  3005. if (point_too_far_mask == 0)
  3006. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3007. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3008. // Only the center point or all the three front points.
  3009. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=8
  3010. else if ((point_too_far_mask & 1) == 0)
  3011. // The right and maybe the center point out of reach.
  3012. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=8
  3013. else
  3014. // The left and maybe the center point out of reach.
  3015. msg = _i("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  3016. lcd_show_fullscreen_message_and_wait_P(msg);
  3017. } else {
  3018. if (point_too_far_mask != 0) {
  3019. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3020. // Only the center point or all the three front points.
  3021. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  3022. else if ((point_too_far_mask & 1) == 0)
  3023. // The right and maybe the center point out of reach.
  3024. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  3025. else
  3026. // The left and maybe the center point out of reach.
  3027. msg = _i("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  3028. lcd_show_fullscreen_message_and_wait_P(msg);
  3029. }
  3030. if (point_too_far_mask == 0 || result > 0) {
  3031. switch (result) {
  3032. default:
  3033. // should not happen
  3034. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3035. break;
  3036. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  3037. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  3038. break;
  3039. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  3040. 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
  3041. break;
  3042. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  3043. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  3044. break;
  3045. }
  3046. lcd_show_fullscreen_message_and_wait_P(msg);
  3047. }
  3048. }
  3049. }
  3050. void lcd_temp_cal_show_result(bool result) {
  3051. custom_message_type = 0;
  3052. custom_message = false;
  3053. disable_x();
  3054. disable_y();
  3055. disable_z();
  3056. disable_e0();
  3057. disable_e1();
  3058. disable_e2();
  3059. setTargetBed(0); //set bed target temperature back to 0
  3060. if (result == true) {
  3061. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  3062. SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob.");
  3063. lcd_show_fullscreen_message_and_wait_P(_T(MSG_TEMP_CALIBRATION_DONE));
  3064. temp_cal_active = true;
  3065. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  3066. }
  3067. else {
  3068. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  3069. SERIAL_ECHOLNPGM("Temperature calibration failed. Continue with pressing the knob.");
  3070. lcd_show_fullscreen_message_and_wait_P(_i("Temperature calibration failed"));////MSG_TEMP_CAL_FAILED c=20 r=8
  3071. temp_cal_active = false;
  3072. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  3073. }
  3074. lcd_update_enable(true);
  3075. lcd_update(2);
  3076. }
  3077. static void lcd_show_end_stops() {
  3078. lcd_set_cursor(0, 0);
  3079. lcd_puts_P((PSTR("End stops diag")));
  3080. lcd_set_cursor(0, 1);
  3081. lcd_puts_P((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  3082. lcd_set_cursor(0, 2);
  3083. lcd_puts_P((READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  3084. lcd_set_cursor(0, 3);
  3085. lcd_puts_P((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  3086. }
  3087. static void menu_show_end_stops() {
  3088. lcd_show_end_stops();
  3089. if (LCD_CLICKED) menu_back();
  3090. }
  3091. // Lets the user move the Z carriage up to the end stoppers.
  3092. // When done, it sets the current Z to Z_MAX_POS and returns true.
  3093. // Otherwise the Z calibration is not changed and false is returned.
  3094. void lcd_diag_show_end_stops()
  3095. {
  3096. int enc_dif = lcd_encoder_diff;
  3097. lcd_clear();
  3098. for (;;) {
  3099. manage_heater();
  3100. manage_inactivity(true);
  3101. lcd_show_end_stops();
  3102. if (lcd_clicked()) {
  3103. while (lcd_clicked()) ;
  3104. delay(10);
  3105. while (lcd_clicked()) ;
  3106. break;
  3107. }
  3108. }
  3109. lcd_clear();
  3110. lcd_return_to_status();
  3111. }
  3112. void prusa_statistics(int _message, uint8_t _fil_nr) {
  3113. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  3114. return;
  3115. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  3116. switch (_message)
  3117. {
  3118. case 0: // default message
  3119. if (IS_SD_PRINTING)
  3120. {
  3121. SERIAL_ECHO("{");
  3122. prusa_stat_printerstatus(4);
  3123. prusa_stat_farm_number();
  3124. prusa_stat_printinfo();
  3125. SERIAL_ECHOLN("}");
  3126. status_number = 4;
  3127. }
  3128. else
  3129. {
  3130. SERIAL_ECHO("{");
  3131. prusa_stat_printerstatus(1);
  3132. prusa_stat_farm_number();
  3133. SERIAL_ECHOLN("}");
  3134. status_number = 1;
  3135. }
  3136. break;
  3137. case 1: // 1 heating
  3138. farm_status = 2;
  3139. SERIAL_ECHO("{");
  3140. prusa_stat_printerstatus(2);
  3141. prusa_stat_farm_number();
  3142. SERIAL_ECHOLN("}");
  3143. status_number = 2;
  3144. farm_timer = 1;
  3145. break;
  3146. case 2: // heating done
  3147. farm_status = 3;
  3148. SERIAL_ECHO("{");
  3149. prusa_stat_printerstatus(3);
  3150. prusa_stat_farm_number();
  3151. SERIAL_ECHOLN("}");
  3152. status_number = 3;
  3153. farm_timer = 1;
  3154. if (IS_SD_PRINTING)
  3155. {
  3156. farm_status = 4;
  3157. SERIAL_ECHO("{");
  3158. prusa_stat_printerstatus(4);
  3159. prusa_stat_farm_number();
  3160. SERIAL_ECHOLN("}");
  3161. status_number = 4;
  3162. }
  3163. else
  3164. {
  3165. SERIAL_ECHO("{");
  3166. prusa_stat_printerstatus(3);
  3167. prusa_stat_farm_number();
  3168. SERIAL_ECHOLN("}");
  3169. status_number = 3;
  3170. }
  3171. farm_timer = 1;
  3172. break;
  3173. case 3: // filament change
  3174. break;
  3175. case 4: // print succesfull
  3176. SERIAL_ECHO("{[RES:1][FIL:");
  3177. MYSERIAL.print(int(_fil_nr));
  3178. SERIAL_ECHO("]");
  3179. prusa_stat_printerstatus(status_number);
  3180. prusa_stat_farm_number();
  3181. SERIAL_ECHOLN("}");
  3182. farm_timer = 2;
  3183. break;
  3184. case 5: // print not succesfull
  3185. SERIAL_ECHO("{[RES:0][FIL:");
  3186. MYSERIAL.print(int(_fil_nr));
  3187. SERIAL_ECHO("]");
  3188. prusa_stat_printerstatus(status_number);
  3189. prusa_stat_farm_number();
  3190. SERIAL_ECHOLN("}");
  3191. farm_timer = 2;
  3192. break;
  3193. case 6: // print done
  3194. SERIAL_ECHO("{[PRN:8]");
  3195. prusa_stat_farm_number();
  3196. SERIAL_ECHOLN("}");
  3197. status_number = 8;
  3198. farm_timer = 2;
  3199. break;
  3200. case 7: // print done - stopped
  3201. SERIAL_ECHO("{[PRN:9]");
  3202. prusa_stat_farm_number();
  3203. SERIAL_ECHOLN("}");
  3204. status_number = 9;
  3205. farm_timer = 2;
  3206. break;
  3207. case 8: // printer started
  3208. SERIAL_ECHO("{[PRN:0][PFN:");
  3209. status_number = 0;
  3210. SERIAL_ECHO(farm_no);
  3211. SERIAL_ECHOLN("]}");
  3212. farm_timer = 2;
  3213. break;
  3214. case 20: // echo farm no
  3215. SERIAL_ECHO("{");
  3216. prusa_stat_printerstatus(status_number);
  3217. prusa_stat_farm_number();
  3218. SERIAL_ECHOLN("}");
  3219. farm_timer = 4;
  3220. break;
  3221. case 21: // temperatures
  3222. SERIAL_ECHO("{");
  3223. prusa_stat_temperatures();
  3224. prusa_stat_farm_number();
  3225. prusa_stat_printerstatus(status_number);
  3226. SERIAL_ECHOLN("}");
  3227. break;
  3228. case 22: // waiting for filament change
  3229. SERIAL_ECHO("{[PRN:5]");
  3230. prusa_stat_farm_number();
  3231. SERIAL_ECHOLN("}");
  3232. status_number = 5;
  3233. break;
  3234. case 90: // Error - Thermal Runaway
  3235. SERIAL_ECHO("{[ERR:1]");
  3236. prusa_stat_farm_number();
  3237. SERIAL_ECHOLN("}");
  3238. break;
  3239. case 91: // Error - Thermal Runaway Preheat
  3240. SERIAL_ECHO("{[ERR:2]");
  3241. prusa_stat_farm_number();
  3242. SERIAL_ECHOLN("}");
  3243. break;
  3244. case 92: // Error - Min temp
  3245. SERIAL_ECHO("{[ERR:3]");
  3246. prusa_stat_farm_number();
  3247. SERIAL_ECHOLN("}");
  3248. break;
  3249. case 93: // Error - Max temp
  3250. SERIAL_ECHO("{[ERR:4]");
  3251. prusa_stat_farm_number();
  3252. SERIAL_ECHOLN("}");
  3253. break;
  3254. case 99: // heartbeat
  3255. SERIAL_ECHO("{[PRN:99]");
  3256. prusa_stat_temperatures();
  3257. SERIAL_ECHO("[PFN:");
  3258. SERIAL_ECHO(farm_no);
  3259. SERIAL_ECHO("]");
  3260. SERIAL_ECHOLN("}");
  3261. break;
  3262. }
  3263. }
  3264. static void prusa_stat_printerstatus(int _status)
  3265. {
  3266. SERIAL_ECHO("[PRN:");
  3267. SERIAL_ECHO(_status);
  3268. SERIAL_ECHO("]");
  3269. }
  3270. static void prusa_stat_farm_number() {
  3271. SERIAL_ECHO("[PFN:");
  3272. SERIAL_ECHO(farm_no);
  3273. SERIAL_ECHO("]");
  3274. }
  3275. static void prusa_stat_temperatures()
  3276. {
  3277. SERIAL_ECHO("[ST0:");
  3278. SERIAL_ECHO(target_temperature[0]);
  3279. SERIAL_ECHO("][STB:");
  3280. SERIAL_ECHO(target_temperature_bed);
  3281. SERIAL_ECHO("][AT0:");
  3282. SERIAL_ECHO(current_temperature[0]);
  3283. SERIAL_ECHO("][ATB:");
  3284. SERIAL_ECHO(current_temperature_bed);
  3285. SERIAL_ECHO("]");
  3286. }
  3287. static void prusa_stat_printinfo()
  3288. {
  3289. SERIAL_ECHO("[TFU:");
  3290. SERIAL_ECHO(total_filament_used);
  3291. SERIAL_ECHO("][PCD:");
  3292. SERIAL_ECHO(itostr3(card.percentDone()));
  3293. SERIAL_ECHO("][FEM:");
  3294. SERIAL_ECHO(itostr3(feedmultiply));
  3295. SERIAL_ECHO("][FNM:");
  3296. SERIAL_ECHO(longFilenameOLD);
  3297. SERIAL_ECHO("][TIM:");
  3298. if (starttime != 0)
  3299. {
  3300. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  3301. }
  3302. else
  3303. {
  3304. SERIAL_ECHO(0);
  3305. }
  3306. SERIAL_ECHO("][FWR:");
  3307. SERIAL_ECHO(FW_VERSION);
  3308. SERIAL_ECHO("]");
  3309. }
  3310. /*
  3311. void lcd_pick_babystep(){
  3312. int enc_dif = 0;
  3313. int cursor_pos = 1;
  3314. int fsm = 0;
  3315. lcd_clear();
  3316. lcd_set_cursor(0, 0);
  3317. lcd_puts_P(_i("Pick print"));////MSG_PICK_Z c=0 r=0
  3318. lcd_set_cursor(3, 2);
  3319. lcd_print("1");
  3320. lcd_set_cursor(3, 3);
  3321. lcd_print("2");
  3322. lcd_set_cursor(12, 2);
  3323. lcd_print("3");
  3324. lcd_set_cursor(12, 3);
  3325. lcd_print("4");
  3326. lcd_set_cursor(1, 2);
  3327. lcd_print(">");
  3328. enc_dif = lcd_encoder_diff;
  3329. while (fsm == 0) {
  3330. manage_heater();
  3331. manage_inactivity(true);
  3332. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  3333. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  3334. if (enc_dif > lcd_encoder_diff ) {
  3335. cursor_pos --;
  3336. }
  3337. if (enc_dif < lcd_encoder_diff ) {
  3338. cursor_pos ++;
  3339. }
  3340. if (cursor_pos > 4) {
  3341. cursor_pos = 4;
  3342. }
  3343. if (cursor_pos < 1) {
  3344. cursor_pos = 1;
  3345. }
  3346. lcd_set_cursor(1, 2);
  3347. lcd_print(" ");
  3348. lcd_set_cursor(1, 3);
  3349. lcd_print(" ");
  3350. lcd_set_cursor(10, 2);
  3351. lcd_print(" ");
  3352. lcd_set_cursor(10, 3);
  3353. lcd_print(" ");
  3354. if (cursor_pos < 3) {
  3355. lcd_set_cursor(1, cursor_pos+1);
  3356. lcd_print(">");
  3357. }else{
  3358. lcd_set_cursor(10, cursor_pos-1);
  3359. lcd_print(">");
  3360. }
  3361. enc_dif = lcd_encoder_diff;
  3362. delay(100);
  3363. }
  3364. }
  3365. if (lcd_clicked()) {
  3366. fsm = cursor_pos;
  3367. int babyStepZ;
  3368. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  3369. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  3370. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  3371. delay(500);
  3372. }
  3373. };
  3374. lcd_clear();
  3375. lcd_return_to_status();
  3376. }
  3377. */
  3378. void lcd_move_menu_axis()
  3379. {
  3380. MENU_BEGIN();
  3381. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3382. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=0 r=0
  3383. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=0 r=0
  3384. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=0 r=0
  3385. MENU_ITEM_SUBMENU_P(_i("Extruder"), lcd_move_e);////MSG_MOVE_E c=0 r=0
  3386. MENU_END();
  3387. }
  3388. static void lcd_move_menu_1mm()
  3389. {
  3390. move_menu_scale = 1.0;
  3391. lcd_move_menu_axis();
  3392. }
  3393. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  3394. {
  3395. do
  3396. {
  3397. eeprom_write_byte((unsigned char*)pos, *value);
  3398. pos++;
  3399. value++;
  3400. } while (--size);
  3401. }
  3402. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  3403. {
  3404. do
  3405. {
  3406. *value = eeprom_read_byte((unsigned char*)pos);
  3407. pos++;
  3408. value++;
  3409. } while (--size);
  3410. }
  3411. #ifdef SDCARD_SORT_ALPHA
  3412. static void lcd_sort_type_set() {
  3413. uint8_t sdSort;
  3414. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3415. switch (sdSort) {
  3416. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3417. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3418. default: sdSort = SD_SORT_TIME;
  3419. }
  3420. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  3421. presort_flag = true;
  3422. }
  3423. #endif //SDCARD_SORT_ALPHA
  3424. #ifdef TMC2130
  3425. static void lcd_crash_mode_info()
  3426. {
  3427. lcd_update_enable(true);
  3428. static uint32_t tim = 0;
  3429. if ((tim + 1000) < millis())
  3430. {
  3431. 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
  3432. tim = millis();
  3433. }
  3434. menu_back_if_clicked();
  3435. }
  3436. static void lcd_crash_mode_info2()
  3437. {
  3438. lcd_update_enable(true);
  3439. static uint32_t tim = 0;
  3440. if ((tim + 1000) < millis())
  3441. {
  3442. 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
  3443. tim = millis();
  3444. }
  3445. menu_back_if_clicked();
  3446. }
  3447. #endif //TMC2130
  3448. #ifdef FILAMENT_SENSOR
  3449. static void lcd_filament_autoload_info()
  3450. {
  3451. uint8_t nlines;
  3452. lcd_update_enable(true);
  3453. static uint32_t tim = 0;
  3454. if ((tim + 1000) < millis())
  3455. {
  3456. 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
  3457. tim = millis();
  3458. }
  3459. menu_back_if_clicked();
  3460. }
  3461. static void lcd_fsensor_fail()
  3462. {
  3463. uint8_t nlines;
  3464. lcd_update_enable(true);
  3465. static uint32_t tim = 0;
  3466. if ((tim + 1000) < millis())
  3467. {
  3468. 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
  3469. tim = millis();
  3470. }
  3471. menu_back_if_clicked();
  3472. }
  3473. #endif //FILAMENT_SENSOR
  3474. //-//
  3475. static void lcd_sound_state_set(void)
  3476. {
  3477. Sound_CycleState();
  3478. }
  3479. static void lcd_silent_mode_set() {
  3480. switch (SilentModeMenu) {
  3481. #ifdef TMC2130
  3482. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3483. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3484. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3485. #else
  3486. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3487. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3488. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3489. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3490. #endif //TMC2130
  3491. }
  3492. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3493. #ifdef TMC2130
  3494. // Wait until the planner queue is drained and the stepper routine achieves
  3495. // an idle state.
  3496. st_synchronize();
  3497. if (tmc2130_wait_standstill_xy(1000)) {}
  3498. // MYSERIAL.print("standstill OK");
  3499. // else
  3500. // MYSERIAL.print("standstill NG!");
  3501. cli();
  3502. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3503. update_mode_profile();
  3504. tmc2130_init();
  3505. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3506. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3507. st_reset_timer();
  3508. sei();
  3509. #endif //TMC2130
  3510. st_current_init();
  3511. #ifdef TMC2130
  3512. if (CrashDetectMenu && (SilentModeMenu != SILENT_MODE_NORMAL))
  3513. menu_submenu(lcd_crash_mode_info2);
  3514. #endif //TMC2130
  3515. }
  3516. #ifdef TMC2130
  3517. static void lcd_crash_mode_set()
  3518. {
  3519. CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable()
  3520. if (CrashDetectMenu==0) {
  3521. crashdet_disable();
  3522. }else{
  3523. crashdet_enable();
  3524. }
  3525. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) menu_goto(lcd_tune_menu, 9, true, true);
  3526. else menu_goto(lcd_settings_menu, 9, true, true);
  3527. }
  3528. #endif //TMC2130
  3529. #ifdef FILAMENT_SENSOR
  3530. static void lcd_fsensor_state_set()
  3531. {
  3532. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3533. if (!FSensorStateMenu) {
  3534. fsensor_disable();
  3535. if (fsensor_autoload_enabled)
  3536. menu_submenu(lcd_filament_autoload_info);
  3537. }else{
  3538. fsensor_enable();
  3539. if (fsensor_not_responding)
  3540. menu_submenu(lcd_fsensor_fail);
  3541. }
  3542. }
  3543. #endif //FILAMENT_SENSOR
  3544. #if !SDSORT_USES_RAM
  3545. void lcd_set_degree() {
  3546. lcd_set_custom_characters_degree();
  3547. }
  3548. void lcd_set_progress() {
  3549. lcd_set_custom_characters_progress();
  3550. }
  3551. #endif
  3552. #if (LANG_MODE != 0)
  3553. void menu_setlang(unsigned char lang)
  3554. {
  3555. if (!lang_select(lang))
  3556. {
  3557. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language from XFLASH?"), false, true))
  3558. lang_boot_update_start(lang);
  3559. lcd_update_enable(true);
  3560. lcd_clear();
  3561. menu_goto(lcd_language_menu, 0, true, true);
  3562. lcd_timeoutToStatus.stop(); //infinite timeout
  3563. lcd_draw_update = 2;
  3564. }
  3565. }
  3566. static void lcd_language_menu()
  3567. {
  3568. MENU_BEGIN();
  3569. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3570. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3571. {
  3572. menu_setlang(0);
  3573. return;
  3574. }
  3575. uint8_t cnt = lang_get_count();
  3576. #ifdef W25X20CL
  3577. if (cnt == 2) //display secondary language in case of clear xflash
  3578. {
  3579. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3580. {
  3581. menu_setlang(1);
  3582. return;
  3583. }
  3584. }
  3585. else
  3586. for (int i = 2; i < cnt; i++) //skip seconday language - solved in lang_select (MK3)
  3587. #else //W25X20CL
  3588. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3589. #endif //W25X20CL
  3590. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3591. {
  3592. menu_setlang(i);
  3593. return;
  3594. }
  3595. MENU_END();
  3596. }
  3597. #endif //(LANG_MODE != 0)
  3598. void lcd_mesh_bedleveling()
  3599. {
  3600. mesh_bed_run_from_menu = true;
  3601. enquecommand_P(PSTR("G80"));
  3602. lcd_return_to_status();
  3603. }
  3604. void lcd_mesh_calibration()
  3605. {
  3606. enquecommand_P(PSTR("M45"));
  3607. lcd_return_to_status();
  3608. }
  3609. void lcd_mesh_calibration_z()
  3610. {
  3611. enquecommand_P(PSTR("M45 Z"));
  3612. lcd_return_to_status();
  3613. }
  3614. void lcd_pinda_calibration_menu()
  3615. {
  3616. MENU_BEGIN();
  3617. MENU_ITEM_BACK_P(_T(MSG_MENU_CALIBRATION));
  3618. MENU_ITEM_SUBMENU_P(_i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17 r=1
  3619. MENU_END();
  3620. }
  3621. void lcd_temp_calibration_set() {
  3622. temp_cal_active = !temp_cal_active;
  3623. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3624. st_current_init();
  3625. }
  3626. #ifdef HAS_SECOND_SERIAL_PORT
  3627. void lcd_second_serial_set() {
  3628. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3629. else selectedSerialPort = 1;
  3630. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3631. MYSERIAL.begin(BAUDRATE);
  3632. }
  3633. #endif //HAS_SECOND_SERIAL_PORT
  3634. void lcd_calibrate_pinda() {
  3635. enquecommand_P(PSTR("G76"));
  3636. lcd_return_to_status();
  3637. }
  3638. #ifndef SNMM
  3639. /*void lcd_calibrate_extruder() {
  3640. if (degHotend0() > EXTRUDE_MINTEMP)
  3641. {
  3642. current_position[E_AXIS] = 0; //set initial position to zero
  3643. plan_set_e_position(current_position[E_AXIS]);
  3644. //long steps_start = st_get_position(E_AXIS);
  3645. long steps_final;
  3646. float e_steps_per_unit;
  3647. 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)
  3648. 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
  3649. 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
  3650. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3651. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3652. unsigned long msg_millis;
  3653. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  3654. lcd_clear();
  3655. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  3656. current_position[E_AXIS] += e_shift_calibration;
  3657. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3658. st_synchronize();
  3659. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3660. msg_millis = millis();
  3661. while (!LCD_CLICKED) {
  3662. if (multi_screen && millis() - msg_millis > 5000) {
  3663. if (msg_next_e_cal_knob == NULL)
  3664. msg_next_e_cal_knob = msg_e_cal_knob;
  3665. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3666. msg_millis = millis();
  3667. }
  3668. //manage_inactivity(true);
  3669. manage_heater();
  3670. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3671. delay_keep_alive(50);
  3672. //previous_millis_cmd = millis();
  3673. lcd_encoder += (lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  3674. lcd_encoder_diff = 0;
  3675. if (!planner_queue_full()) {
  3676. current_position[E_AXIS] += float(abs((int)lcd_encoder)) * 0.01; //0.05
  3677. lcd_encoder = 0;
  3678. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3679. }
  3680. }
  3681. }
  3682. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3683. //steps_final = st_get_position(E_AXIS);
  3684. lcd_draw_update = 1;
  3685. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3686. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3687. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3688. lcd_clear();
  3689. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3690. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3691. //lcd_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3692. //delay_keep_alive(2000);
  3693. delay_keep_alive(500);
  3694. 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
  3695. lcd_update_enable(true);
  3696. lcd_draw_update = 2;
  3697. }
  3698. else
  3699. {
  3700. lcd_clear();
  3701. lcd_set_cursor(0, 0);
  3702. lcd_puts_P(_T(MSG_ERROR));
  3703. lcd_set_cursor(0, 2);
  3704. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  3705. delay(2000);
  3706. lcd_clear();
  3707. }
  3708. lcd_return_to_status();
  3709. }
  3710. void lcd_extr_cal_reset() {
  3711. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3712. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3713. //extrudemultiply = 100;
  3714. enquecommand_P(PSTR("M500"));
  3715. }*/
  3716. #endif
  3717. void lcd_toshiba_flash_air_compatibility_toggle()
  3718. {
  3719. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3720. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3721. }
  3722. void lcd_v2_calibration()
  3723. {
  3724. if (mmu_enabled)
  3725. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3726. else
  3727. {
  3728. 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
  3729. if (loaded) {
  3730. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3731. }
  3732. else {
  3733. lcd_display_message_fullscreen_P(_i("Please load PLA filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3734. for (int i = 0; i < 20; i++) { //wait max. 2s
  3735. delay_keep_alive(100);
  3736. if (lcd_clicked()) {
  3737. while (lcd_clicked());
  3738. delay(10);
  3739. while (lcd_clicked());
  3740. break;
  3741. }
  3742. }
  3743. }
  3744. }
  3745. lcd_return_to_status();
  3746. lcd_update_enable(true);
  3747. }
  3748. void lcd_wizard() {
  3749. bool result = true;
  3750. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3751. 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
  3752. }
  3753. if (result) {
  3754. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3755. lcd_wizard(0);
  3756. }
  3757. else {
  3758. lcd_return_to_status();
  3759. lcd_update_enable(true);
  3760. lcd_update(2);
  3761. }
  3762. }
  3763. void lcd_language()
  3764. {
  3765. lcd_update_enable(true);
  3766. lcd_clear();
  3767. menu_goto(lcd_language_menu, 0, true, true);
  3768. lcd_timeoutToStatus.stop(); //infinite timeout
  3769. lcd_draw_update = 2;
  3770. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  3771. {
  3772. delay(50);
  3773. lcd_update(0);
  3774. manage_heater();
  3775. manage_inactivity(true);
  3776. }
  3777. if (lang_is_selected())
  3778. lcd_return_to_status();
  3779. else
  3780. lang_select(LANG_ID_PRI);
  3781. }
  3782. void lcd_wizard(int state) {
  3783. bool end = false;
  3784. int wizard_event;
  3785. const char *msg = NULL;
  3786. while (!end) {
  3787. switch (state) {
  3788. case 0: // run wizard?
  3789. 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
  3790. if (wizard_event) {
  3791. state = 1;
  3792. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3793. }
  3794. else {
  3795. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3796. end = true;
  3797. }
  3798. break;
  3799. case 1: // restore calibration status
  3800. switch (calibration_status()) {
  3801. case CALIBRATION_STATUS_ASSEMBLED: state = 2; break; //run selftest
  3802. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = 3; break; //run xyz cal.
  3803. case CALIBRATION_STATUS_Z_CALIBRATION: state = 4; break; //run z cal.
  3804. case CALIBRATION_STATUS_LIVE_ADJUST: state = 5; break; //run live adjust
  3805. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3806. default: state = 2; break; //if calibration status is unknown, run wizard from the beginning
  3807. }
  3808. break;
  3809. case 2: //selftest
  3810. 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
  3811. wizard_event = lcd_selftest();
  3812. if (wizard_event) {
  3813. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3814. state = 3;
  3815. }
  3816. else end = true;
  3817. break;
  3818. case 3: //xyz cal.
  3819. 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
  3820. wizard_event = gcode_M45(false, 0);
  3821. if (wizard_event) state = 5;
  3822. else end = true;
  3823. break;
  3824. case 4: //z cal.
  3825. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3826. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  3827. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3828. wizard_event = gcode_M45(true, 0);
  3829. if (wizard_event) state = 11; //shipped, no need to set first layer, go to final message directly
  3830. else end = true;
  3831. break;
  3832. case 5: //is filament loaded?
  3833. //start to preheat nozzle and bed to save some time later
  3834. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3835. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3836. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament loaded?"), false);////MSG_WIZARD_FILAMENT_LOADED c=20 r=2
  3837. if (wizard_event) state = 8;
  3838. else state = 6;
  3839. break;
  3840. case 6: //waiting for preheat nozzle for PLA;
  3841. #ifndef SNMM
  3842. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3843. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3844. 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);
  3845. delay_keep_alive(2000);
  3846. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3847. while (abs(degHotend(0) - PLA_PREHEAT_HOTEND_TEMP) > 3) {
  3848. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3849. lcd_set_cursor(0, 4);
  3850. lcd_print(LCD_STR_THERMOMETER[0]);
  3851. lcd_print(ftostr3(degHotend(0)));
  3852. lcd_print("/");
  3853. lcd_print(PLA_PREHEAT_HOTEND_TEMP);
  3854. lcd_print(LCD_STR_DEGREE);
  3855. lcd_set_custom_characters();
  3856. delay_keep_alive(1000);
  3857. }
  3858. #endif //not SNMM
  3859. state = 7;
  3860. break;
  3861. case 7: //load filament
  3862. 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
  3863. lcd_update_enable(false);
  3864. lcd_clear();
  3865. lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
  3866. #ifdef SNMM
  3867. change_extr(0);
  3868. #endif
  3869. gcode_M701();
  3870. state = 9;
  3871. break;
  3872. case 8:
  3873. 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
  3874. if (wizard_event) state = 9;
  3875. else end = true;
  3876. break;
  3877. case 9:
  3878. 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
  3879. 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
  3880. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3881. end = true;
  3882. break;
  3883. case 10: //repeat first layer cal.?
  3884. 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
  3885. if (wizard_event) {
  3886. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3887. state = 9;
  3888. }
  3889. else {
  3890. state = 11;
  3891. }
  3892. break;
  3893. case 11: //we are finished
  3894. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3895. end = true;
  3896. break;
  3897. default: break;
  3898. }
  3899. }
  3900. printf_P(_N("State: %d\n"), state);
  3901. switch (state) { //final message
  3902. case 0: //user dont want to use wizard
  3903. msg = _T(MSG_WIZARD_QUIT);
  3904. break;
  3905. case 1: //printer was already calibrated
  3906. msg = _T(MSG_WIZARD_DONE);
  3907. break;
  3908. case 2: //selftest
  3909. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3910. break;
  3911. case 3: //xyz cal.
  3912. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3913. break;
  3914. case 4: //z cal.
  3915. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3916. break;
  3917. case 8:
  3918. msg = _i("Please load PLA filament and then resume Wizard by rebooting the printer.");////MSG_WIZARD_INSERT_CORRECT_FILAMENT c=20 r=8
  3919. break;
  3920. case 9: break; //exit wizard for v2 calibration, which is implemted in lcd_commands (we need lcd_update running)
  3921. case 11: //we are finished
  3922. msg = _T(MSG_WIZARD_DONE);
  3923. lcd_reset_alert_level();
  3924. lcd_setstatuspgm(_T(WELCOME_MSG));
  3925. break;
  3926. default:
  3927. msg = _T(MSG_WIZARD_QUIT);
  3928. break;
  3929. }
  3930. if (state != 9) lcd_show_fullscreen_message_and_wait_P(msg);
  3931. lcd_update_enable(true);
  3932. lcd_return_to_status();
  3933. lcd_update(2);
  3934. }
  3935. /*
  3936. void lcd_settings_linearity_correction_menu(void)
  3937. {
  3938. MENU_BEGIN();
  3939. if (menu_item_back_P(_T(MSG_MAIN)))
  3940. {
  3941. lcd_settings_menu_back();
  3942. return;
  3943. }
  3944. // MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3945. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3946. //tmc2130_wave_fac[X_AXIS]
  3947. int corr[4] = {tmc2130_wave_fac[X_AXIS], tmc2130_wave_fac[Y_AXIS], tmc2130_wave_fac[Z_AXIS], tmc2130_wave_fac[E_AXIS]};
  3948. 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
  3949. 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
  3950. 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
  3951. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3952. 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
  3953. MENU_END();
  3954. }
  3955. */
  3956. static void lcd_settings_menu()
  3957. {
  3958. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  3959. MENU_BEGIN();
  3960. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  3961. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=0 r=0
  3962. if (!homing_flag)
  3963. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=0 r=0
  3964. if (!isPrintPaused)
  3965. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=0 r=0
  3966. #ifndef TMC2130
  3967. if (!farm_mode)
  3968. { //dont show in menu if we are in farm mode
  3969. switch (SilentModeMenu)
  3970. {
  3971. case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  3972. case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  3973. case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  3974. default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  3975. }
  3976. }
  3977. #endif //TMC2130
  3978. #ifdef FILAMENT_SENSOR
  3979. if (FSensorStateMenu == 0)
  3980. {
  3981. if (fsensor_not_responding)
  3982. {
  3983. // Filament sensor not working
  3984. MENU_ITEM_FUNCTION_P(_i("Fil. sensor [N/A]"), lcd_fsensor_state_set);////MSG_FSENSOR_NA c=0 r=0
  3985. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_fsensor_fail);
  3986. }
  3987. else
  3988. {
  3989. // Filament sensor turned off, working, no problems
  3990. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  3991. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_filament_autoload_info);
  3992. }
  3993. }
  3994. else
  3995. {
  3996. // Filament sensor turned on, working, no problems
  3997. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  3998. if (fsensor_autoload_enabled)
  3999. MENU_ITEM_FUNCTION_P(_i("F. autoload [on]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_ON c=17 r=1
  4000. else
  4001. MENU_ITEM_FUNCTION_P(_i("F. autoload [off]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_OFF c=17 r=1
  4002. }
  4003. #endif //FILAMENT_SENSOR
  4004. if (fans_check_enabled == true)
  4005. MENU_ITEM_FUNCTION_P(_i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1
  4006. else
  4007. MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1
  4008. #ifdef TMC2130
  4009. if(!farm_mode)
  4010. {
  4011. if (SilentModeMenu == SILENT_MODE_NORMAL) { MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set); }
  4012. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  4013. if (SilentModeMenu == SILENT_MODE_NORMAL)
  4014. {
  4015. if (CrashDetectMenu == 0) { MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set); }
  4016. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  4017. }
  4018. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  4019. }
  4020. // MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu);
  4021. #endif //TMC2130
  4022. if (temp_cal_active == false)
  4023. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [off]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_OFF c=20 r=1
  4024. else
  4025. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [on]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_ON c=20 r=1
  4026. #ifdef HAS_SECOND_SERIAL_PORT
  4027. if (selectedSerialPort == 0)
  4028. MENU_ITEM_FUNCTION_P(_i("RPi port [off]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_OFF c=17 r=1
  4029. else
  4030. MENU_ITEM_FUNCTION_P(_i("RPi port [on]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_ON c=17 r=1
  4031. #endif //HAS_SECOND_SERIAL
  4032. if (!isPrintPaused && !homing_flag)
  4033. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  4034. #if (LANG_MODE != 0)
  4035. MENU_ITEM_SUBMENU_P(_i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=0 r=0
  4036. #endif //(LANG_MODE != 0)
  4037. if (card.ToshibaFlashAir_isEnabled())
  4038. MENU_ITEM_FUNCTION_P(_i("SD card [flshAir]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1
  4039. else
  4040. MENU_ITEM_FUNCTION_P(_i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1
  4041. #ifdef SDCARD_SORT_ALPHA
  4042. if (!farm_mode)
  4043. {
  4044. uint8_t sdSort;
  4045. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  4046. switch (sdSort)
  4047. {
  4048. case SD_SORT_TIME: MENU_ITEM_FUNCTION_P(_i("Sort: [time]"), lcd_sort_type_set); break;////MSG_SORT_TIME c=17 r=1
  4049. case SD_SORT_ALPHA: MENU_ITEM_FUNCTION_P(_i("Sort: [alphabet]"), lcd_sort_type_set); break;////MSG_SORT_ALPHA c=17 r=1
  4050. default: MENU_ITEM_FUNCTION_P(_i("Sort: [none]"), lcd_sort_type_set);////MSG_SORT_NONE c=17 r=1
  4051. }
  4052. }
  4053. #endif // SDCARD_SORT_ALPHA
  4054. //-//
  4055. switch(eSoundMode)
  4056. {
  4057. case e_SOUND_MODE_LOUD:
  4058. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
  4059. break;
  4060. case e_SOUND_MODE_ONCE:
  4061. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_ONCE),lcd_sound_state_set);
  4062. break;
  4063. case e_SOUND_MODE_SILENT:
  4064. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_SILENT),lcd_sound_state_set);
  4065. break;
  4066. case e_SOUND_MODE_MUTE:
  4067. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_MUTE),lcd_sound_state_set);
  4068. break;
  4069. default:
  4070. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
  4071. }
  4072. //-//
  4073. if (farm_mode)
  4074. {
  4075. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  4076. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  4077. }
  4078. MENU_END();
  4079. }
  4080. static void lcd_selftest_()
  4081. {
  4082. lcd_selftest();
  4083. }
  4084. #ifdef TMC2130
  4085. static void lcd_ustep_linearity_menu_save()
  4086. {
  4087. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  4088. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  4089. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  4090. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  4091. }
  4092. #endif //TMC2130
  4093. static void lcd_settings_menu_back()
  4094. {
  4095. #ifdef TMC2130
  4096. bool changed = false;
  4097. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  4098. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  4099. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  4100. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  4101. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  4102. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  4103. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  4104. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  4105. lcd_ustep_linearity_menu_save();
  4106. if (changed) tmc2130_init();
  4107. #endif //TMC2130
  4108. menu_menu = lcd_main_menu;
  4109. // lcd_main_menu();
  4110. }
  4111. static void lcd_calibration_menu()
  4112. {
  4113. MENU_BEGIN();
  4114. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4115. if (!isPrintPaused)
  4116. {
  4117. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17 r=1
  4118. MENU_ITEM_SUBMENU_P(_i("First layer cal."), lcd_v2_calibration);////MSG_V2_CALIBRATION c=17 r=1
  4119. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  4120. MENU_ITEM_FUNCTION_P(_i("Selftest "), lcd_selftest_v);////MSG_SELFTEST c=0 r=0
  4121. #ifdef MK1BP
  4122. // MK1
  4123. // "Calibrate Z"
  4124. MENU_ITEM_GCODE_P(_T(MSG_HOMEYZ), PSTR("G28 Z"));
  4125. #else //MK1BP
  4126. // MK2
  4127. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=0 r=0
  4128. // "Calibrate Z" with storing the reference values to EEPROM.
  4129. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  4130. #ifndef SNMM
  4131. //MENU_ITEM_FUNCTION_P(_i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20 r=1
  4132. #endif
  4133. // "Mesh Bed Leveling"
  4134. MENU_ITEM_SUBMENU_P(_i("Mesh Bed Leveling"), lcd_mesh_bedleveling);////MSG_MESH_BED_LEVELING c=0 r=0
  4135. #endif //MK1BP
  4136. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=0 r=0
  4137. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17 r=1
  4138. #ifndef TMC2130
  4139. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=17 r=1
  4140. #endif
  4141. #ifndef MK1BP
  4142. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=0 r=0
  4143. #endif //MK1BP
  4144. #ifndef SNMM
  4145. //MENU_ITEM_FUNCTION_P(MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  4146. #endif
  4147. #ifndef MK1BP
  4148. MENU_ITEM_SUBMENU_P(_i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17 r=1
  4149. #endif //MK1BP
  4150. }
  4151. MENU_END();
  4152. }
  4153. void bowden_menu() {
  4154. int enc_dif = lcd_encoder_diff;
  4155. int cursor_pos = 0;
  4156. lcd_clear();
  4157. lcd_set_cursor(0, 0);
  4158. lcd_print(">");
  4159. for (int i = 0; i < 4; i++) {
  4160. lcd_set_cursor(1, i);
  4161. lcd_print("Extruder ");
  4162. lcd_print(i);
  4163. lcd_print(": ");
  4164. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4165. lcd_print(bowden_length[i] - 48);
  4166. }
  4167. enc_dif = lcd_encoder_diff;
  4168. while (1) {
  4169. manage_heater();
  4170. manage_inactivity(true);
  4171. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  4172. if (enc_dif > lcd_encoder_diff) {
  4173. cursor_pos--;
  4174. }
  4175. if (enc_dif < lcd_encoder_diff) {
  4176. cursor_pos++;
  4177. }
  4178. if (cursor_pos > 3) {
  4179. cursor_pos = 3;
  4180. }
  4181. if (cursor_pos < 0) {
  4182. cursor_pos = 0;
  4183. }
  4184. lcd_set_cursor(0, 0);
  4185. lcd_print(" ");
  4186. lcd_set_cursor(0, 1);
  4187. lcd_print(" ");
  4188. lcd_set_cursor(0, 2);
  4189. lcd_print(" ");
  4190. lcd_set_cursor(0, 3);
  4191. lcd_print(" ");
  4192. lcd_set_cursor(0, cursor_pos);
  4193. lcd_print(">");
  4194. enc_dif = lcd_encoder_diff;
  4195. delay(100);
  4196. }
  4197. if (lcd_clicked()) {
  4198. while (lcd_clicked());
  4199. delay(10);
  4200. while (lcd_clicked());
  4201. lcd_clear();
  4202. while (1) {
  4203. manage_heater();
  4204. manage_inactivity(true);
  4205. lcd_set_cursor(1, 1);
  4206. lcd_print("Extruder ");
  4207. lcd_print(cursor_pos);
  4208. lcd_print(": ");
  4209. lcd_set_cursor(13, 1);
  4210. lcd_print(bowden_length[cursor_pos] - 48);
  4211. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  4212. if (enc_dif > lcd_encoder_diff) {
  4213. bowden_length[cursor_pos]--;
  4214. lcd_set_cursor(13, 1);
  4215. lcd_print(bowden_length[cursor_pos] - 48);
  4216. enc_dif = lcd_encoder_diff;
  4217. }
  4218. if (enc_dif < lcd_encoder_diff) {
  4219. bowden_length[cursor_pos]++;
  4220. lcd_set_cursor(13, 1);
  4221. lcd_print(bowden_length[cursor_pos] - 48);
  4222. enc_dif = lcd_encoder_diff;
  4223. }
  4224. }
  4225. delay(100);
  4226. if (lcd_clicked()) {
  4227. while (lcd_clicked());
  4228. delay(10);
  4229. while (lcd_clicked());
  4230. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  4231. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  4232. lcd_update_enable(true);
  4233. lcd_clear();
  4234. enc_dif = lcd_encoder_diff;
  4235. lcd_set_cursor(0, cursor_pos);
  4236. lcd_print(">");
  4237. for (int i = 0; i < 4; i++) {
  4238. lcd_set_cursor(1, i);
  4239. lcd_print("Extruder ");
  4240. lcd_print(i);
  4241. lcd_print(": ");
  4242. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4243. lcd_print(bowden_length[i] - 48);
  4244. }
  4245. break;
  4246. }
  4247. else return;
  4248. }
  4249. }
  4250. }
  4251. }
  4252. }
  4253. //#ifdef SNMM
  4254. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  4255. lcd_clear();
  4256. lcd_puts_at_P(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd_print(":");
  4257. lcd_set_cursor(0, 1); lcd_print(">");
  4258. lcd_puts_at_P(1,2,_i("Used during print"));////MSG_USED c=19 r=1
  4259. lcd_puts_at_P(1,3,_i("Current"));////MSG_CURRENT c=19 r=1
  4260. char cursor_pos = 1;
  4261. int enc_dif = 0;
  4262. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4263. while (1) {
  4264. manage_heater();
  4265. manage_inactivity(true);
  4266. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4267. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4268. if (enc_dif > lcd_encoder_diff) cursor_pos--;
  4269. if (enc_dif < lcd_encoder_diff) cursor_pos++;
  4270. if (cursor_pos > 3) cursor_pos = 3;
  4271. if (cursor_pos < 1) cursor_pos = 1;
  4272. lcd_set_cursor(0, 1);
  4273. lcd_print(" ");
  4274. lcd_set_cursor(0, 2);
  4275. lcd_print(" ");
  4276. lcd_set_cursor(0, 3);
  4277. lcd_print(" ");
  4278. lcd_set_cursor(0, cursor_pos);
  4279. lcd_print(">");
  4280. enc_dif = lcd_encoder_diff;
  4281. delay(100);
  4282. }
  4283. }
  4284. if (lcd_clicked()) {
  4285. while (lcd_clicked());
  4286. delay(10);
  4287. while (lcd_clicked());
  4288. KEEPALIVE_STATE(IN_HANDLER);
  4289. return(cursor_pos - 1);
  4290. }
  4291. }
  4292. }
  4293. char choose_extruder_menu()
  4294. {
  4295. int items_no = mmu_enabled?5:4;
  4296. int first = 0;
  4297. int enc_dif = 0;
  4298. char cursor_pos = 1;
  4299. enc_dif = lcd_encoder_diff;
  4300. lcd_clear();
  4301. lcd_puts_P(_T(MSG_CHOOSE_EXTRUDER));
  4302. lcd_set_cursor(0, 1);
  4303. lcd_print(">");
  4304. for (int i = 0; i < 3; i++) {
  4305. lcd_puts_at_P(1, i + 1, _T(MSG_EXTRUDER));
  4306. }
  4307. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4308. while (1) {
  4309. for (int i = 0; i < 3; i++) {
  4310. lcd_set_cursor(2 + strlen_P(_T(MSG_EXTRUDER)), i+1);
  4311. lcd_print(first + i + 1);
  4312. }
  4313. manage_heater();
  4314. manage_inactivity(true);
  4315. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4316. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4317. if (enc_dif > lcd_encoder_diff) {
  4318. cursor_pos--;
  4319. }
  4320. if (enc_dif < lcd_encoder_diff) {
  4321. cursor_pos++;
  4322. }
  4323. if (cursor_pos > 3) {
  4324. cursor_pos = 3;
  4325. if (first < items_no - 3) {
  4326. first++;
  4327. lcd_clear();
  4328. lcd_puts_P(_T(MSG_CHOOSE_EXTRUDER));
  4329. for (int i = 0; i < 3; i++) {
  4330. lcd_puts_at_P(1, i + 1, _T(MSG_EXTRUDER));
  4331. }
  4332. }
  4333. }
  4334. if (cursor_pos < 1) {
  4335. cursor_pos = 1;
  4336. if (first > 0) {
  4337. first--;
  4338. lcd_clear();
  4339. lcd_puts_P(_T(MSG_CHOOSE_EXTRUDER));
  4340. for (int i = 0; i < 3; i++) {
  4341. lcd_puts_at_P(1, i + 1, _T(MSG_EXTRUDER));
  4342. }
  4343. }
  4344. }
  4345. lcd_set_cursor(0, 1);
  4346. lcd_print(" ");
  4347. lcd_set_cursor(0, 2);
  4348. lcd_print(" ");
  4349. lcd_set_cursor(0, 3);
  4350. lcd_print(" ");
  4351. lcd_set_cursor(0, cursor_pos);
  4352. lcd_print(">");
  4353. enc_dif = lcd_encoder_diff;
  4354. delay(100);
  4355. }
  4356. }
  4357. if (lcd_clicked()) {
  4358. lcd_update(2);
  4359. while (lcd_clicked());
  4360. delay(10);
  4361. while (lcd_clicked());
  4362. KEEPALIVE_STATE(IN_HANDLER);
  4363. return(cursor_pos + first - 1);
  4364. }
  4365. }
  4366. }
  4367. //#endif
  4368. char reset_menu() {
  4369. #ifdef SNMM
  4370. int items_no = 5;
  4371. #else
  4372. int items_no = 4;
  4373. #endif
  4374. static int first = 0;
  4375. int enc_dif = 0;
  4376. char cursor_pos = 0;
  4377. const char *item [items_no];
  4378. item[0] = "Language";
  4379. item[1] = "Statistics";
  4380. item[2] = "Shipping prep";
  4381. item[3] = "All Data";
  4382. #ifdef SNMM
  4383. item[4] = "Bowden length";
  4384. #endif // SNMM
  4385. enc_dif = lcd_encoder_diff;
  4386. lcd_clear();
  4387. lcd_set_cursor(0, 0);
  4388. lcd_print(">");
  4389. while (1) {
  4390. for (int i = 0; i < 4; i++) {
  4391. lcd_set_cursor(1, i);
  4392. lcd_print(item[first + i]);
  4393. }
  4394. manage_heater();
  4395. manage_inactivity(true);
  4396. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4397. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4398. if (enc_dif > lcd_encoder_diff) {
  4399. cursor_pos--;
  4400. }
  4401. if (enc_dif < lcd_encoder_diff) {
  4402. cursor_pos++;
  4403. }
  4404. if (cursor_pos > 3) {
  4405. cursor_pos = 3;
  4406. if (first < items_no - 4) {
  4407. first++;
  4408. lcd_clear();
  4409. }
  4410. }
  4411. if (cursor_pos < 0) {
  4412. cursor_pos = 0;
  4413. if (first > 0) {
  4414. first--;
  4415. lcd_clear();
  4416. }
  4417. }
  4418. lcd_set_cursor(0, 0);
  4419. lcd_print(" ");
  4420. lcd_set_cursor(0, 1);
  4421. lcd_print(" ");
  4422. lcd_set_cursor(0, 2);
  4423. lcd_print(" ");
  4424. lcd_set_cursor(0, 3);
  4425. lcd_print(" ");
  4426. lcd_set_cursor(0, cursor_pos);
  4427. lcd_print(">");
  4428. enc_dif = lcd_encoder_diff;
  4429. delay(100);
  4430. }
  4431. }
  4432. if (lcd_clicked()) {
  4433. while (lcd_clicked());
  4434. delay(10);
  4435. while (lcd_clicked());
  4436. return(cursor_pos + first);
  4437. }
  4438. }
  4439. }
  4440. static void lcd_disable_farm_mode()
  4441. {
  4442. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  4443. if (disable)
  4444. {
  4445. enquecommand_P(PSTR("G99"));
  4446. lcd_return_to_status();
  4447. }
  4448. lcd_update_enable(true);
  4449. lcd_draw_update = 2;
  4450. }
  4451. static void fil_load_menu()
  4452. {
  4453. MENU_BEGIN();
  4454. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4455. MENU_ITEM_FUNCTION_P(_i("Load all"), load_all);////MSG_LOAD_ALL c=0 r=0
  4456. MENU_ITEM_FUNCTION_P(_i("Load filament 1"), extr_adj_0);////MSG_LOAD_FILAMENT_1 c=17 r=0
  4457. MENU_ITEM_FUNCTION_P(_i("Load filament 2"), extr_adj_1);////MSG_LOAD_FILAMENT_2 c=17 r=0
  4458. MENU_ITEM_FUNCTION_P(_i("Load filament 3"), extr_adj_2);////MSG_LOAD_FILAMENT_3 c=17 r=0
  4459. MENU_ITEM_FUNCTION_P(_i("Load filament 4"), extr_adj_3);////MSG_LOAD_FILAMENT_4 c=17 r=0
  4460. if (mmu_enabled)
  4461. MENU_ITEM_FUNCTION_P(_i("Load filament 5"), extr_adj_4);
  4462. MENU_END();
  4463. }
  4464. static void fil_unload_menu()
  4465. {
  4466. MENU_BEGIN();
  4467. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4468. MENU_ITEM_FUNCTION_P(_i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=0 r=0
  4469. MENU_ITEM_FUNCTION_P(_i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17 r=0
  4470. MENU_ITEM_FUNCTION_P(_i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17 r=0
  4471. MENU_ITEM_FUNCTION_P(_i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17 r=0
  4472. MENU_ITEM_FUNCTION_P(_i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17 r=0
  4473. if (mmu_enabled)
  4474. MENU_ITEM_FUNCTION_P(_i("Unload filament 5"), extr_unload_4);////MSG_UNLOAD_FILAMENT_4 c=17 r=0
  4475. MENU_END();
  4476. }
  4477. static void change_extr_menu(){
  4478. MENU_BEGIN();
  4479. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4480. MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1
  4481. MENU_ITEM_FUNCTION_P(_i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17 r=1
  4482. MENU_ITEM_FUNCTION_P(_i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17 r=1
  4483. MENU_ITEM_FUNCTION_P(_i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17 r=1
  4484. MENU_END();
  4485. }
  4486. //unload filament for single material printer (used in M702 gcode)
  4487. void unload_filament()
  4488. {
  4489. custom_message = true;
  4490. custom_message_type = 2;
  4491. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  4492. // extr_unload2();
  4493. current_position[E_AXIS] -= 45;
  4494. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 5200 / 60, active_extruder);
  4495. st_synchronize();
  4496. current_position[E_AXIS] -= 15;
  4497. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1000 / 60, active_extruder);
  4498. st_synchronize();
  4499. current_position[E_AXIS] -= 20;
  4500. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1000 / 60, active_extruder);
  4501. st_synchronize();
  4502. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  4503. //disable extruder steppers so filament can be removed
  4504. disable_e0();
  4505. disable_e1();
  4506. disable_e2();
  4507. delay(100);
  4508. Sound_MakeSound(e_SOUND_CLASS_Prompt, e_SOUND_TYPE_StandardPrompt);
  4509. uint8_t counterBeep = 0;
  4510. while (!lcd_clicked() && (counterBeep < 50)) {
  4511. delay_keep_alive(100);
  4512. counterBeep++;
  4513. }
  4514. st_synchronize();
  4515. while (lcd_clicked()) delay_keep_alive(100);
  4516. lcd_update_enable(true);
  4517. lcd_setstatuspgm(_T(WELCOME_MSG));
  4518. custom_message = false;
  4519. custom_message_type = 0;
  4520. }
  4521. static void lcd_farm_no()
  4522. {
  4523. char step = 0;
  4524. int enc_dif = 0;
  4525. int _farmno = farm_no;
  4526. int _ret = 0;
  4527. lcd_clear();
  4528. lcd_set_cursor(0, 0);
  4529. lcd_print("Farm no");
  4530. do
  4531. {
  4532. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  4533. if (enc_dif > lcd_encoder_diff) {
  4534. switch (step) {
  4535. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4536. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4537. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4538. default: break;
  4539. }
  4540. }
  4541. if (enc_dif < lcd_encoder_diff) {
  4542. switch (step) {
  4543. case(0): if (_farmno < 900) _farmno += 100; break;
  4544. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4545. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4546. default: break;
  4547. }
  4548. }
  4549. enc_dif = 0;
  4550. lcd_encoder_diff = 0;
  4551. }
  4552. lcd_set_cursor(0, 2);
  4553. if (_farmno < 100) lcd_print("0");
  4554. if (_farmno < 10) lcd_print("0");
  4555. lcd_print(_farmno);
  4556. lcd_print(" ");
  4557. lcd_set_cursor(0, 3);
  4558. lcd_print(" ");
  4559. lcd_set_cursor(step, 3);
  4560. lcd_print("^");
  4561. delay(100);
  4562. if (lcd_clicked())
  4563. {
  4564. delay(200);
  4565. step++;
  4566. if(step == 3) {
  4567. _ret = 1;
  4568. farm_no = _farmno;
  4569. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4570. prusa_statistics(20);
  4571. lcd_return_to_status();
  4572. }
  4573. }
  4574. manage_heater();
  4575. } while (_ret == 0);
  4576. }
  4577. unsigned char lcd_choose_color() {
  4578. //function returns index of currently chosen item
  4579. //following part can be modified from 2 to 255 items:
  4580. //-----------------------------------------------------
  4581. unsigned char items_no = 2;
  4582. const char *item[items_no];
  4583. item[0] = "Orange";
  4584. item[1] = "Black";
  4585. //-----------------------------------------------------
  4586. unsigned char active_rows;
  4587. static int first = 0;
  4588. int enc_dif = 0;
  4589. unsigned char cursor_pos = 1;
  4590. enc_dif = lcd_encoder_diff;
  4591. lcd_clear();
  4592. lcd_set_cursor(0, 1);
  4593. lcd_print(">");
  4594. active_rows = items_no < 3 ? items_no : 3;
  4595. while (1) {
  4596. lcd_puts_at_P(0, 0, PSTR("Choose color:"));
  4597. for (int i = 0; i < active_rows; i++) {
  4598. lcd_set_cursor(1, i+1);
  4599. lcd_print(item[first + i]);
  4600. }
  4601. manage_heater();
  4602. manage_inactivity(true);
  4603. proc_commands();
  4604. if (abs((enc_dif - lcd_encoder_diff)) > 12) {
  4605. if (enc_dif > lcd_encoder_diff) {
  4606. cursor_pos--;
  4607. }
  4608. if (enc_dif < lcd_encoder_diff) {
  4609. cursor_pos++;
  4610. }
  4611. if (cursor_pos > active_rows) {
  4612. cursor_pos = active_rows;
  4613. if (first < items_no - active_rows) {
  4614. first++;
  4615. lcd_clear();
  4616. }
  4617. }
  4618. if (cursor_pos < 1) {
  4619. cursor_pos = 1;
  4620. if (first > 0) {
  4621. first--;
  4622. lcd_clear();
  4623. }
  4624. }
  4625. lcd_set_cursor(0, 1);
  4626. lcd_print(" ");
  4627. lcd_set_cursor(0, 2);
  4628. lcd_print(" ");
  4629. lcd_set_cursor(0, 3);
  4630. lcd_print(" ");
  4631. lcd_set_cursor(0, cursor_pos);
  4632. lcd_print(">");
  4633. enc_dif = lcd_encoder_diff;
  4634. delay(100);
  4635. }
  4636. if (lcd_clicked()) {
  4637. while (lcd_clicked());
  4638. delay(10);
  4639. while (lcd_clicked());
  4640. switch(cursor_pos + first - 1) {
  4641. case 0: return 1; break;
  4642. case 1: return 0; break;
  4643. default: return 99; break;
  4644. }
  4645. }
  4646. }
  4647. }
  4648. void lcd_confirm_print()
  4649. {
  4650. uint8_t filament_type;
  4651. int enc_dif = 0;
  4652. int cursor_pos = 1;
  4653. int _ret = 0;
  4654. int _t = 0;
  4655. enc_dif = lcd_encoder_diff;
  4656. lcd_clear();
  4657. lcd_set_cursor(0, 0);
  4658. lcd_print("Print ok ?");
  4659. do
  4660. {
  4661. if (abs(enc_dif - lcd_encoder_diff) > 12) {
  4662. if (enc_dif > lcd_encoder_diff) {
  4663. cursor_pos--;
  4664. }
  4665. if (enc_dif < lcd_encoder_diff) {
  4666. cursor_pos++;
  4667. }
  4668. enc_dif = lcd_encoder_diff;
  4669. }
  4670. if (cursor_pos > 2) { cursor_pos = 2; }
  4671. if (cursor_pos < 1) { cursor_pos = 1; }
  4672. lcd_set_cursor(0, 2); lcd_print(" ");
  4673. lcd_set_cursor(0, 3); lcd_print(" ");
  4674. lcd_set_cursor(2, 2);
  4675. lcd_puts_P(_T(MSG_YES));
  4676. lcd_set_cursor(2, 3);
  4677. lcd_puts_P(_T(MSG_NO));
  4678. lcd_set_cursor(0, 1 + cursor_pos);
  4679. lcd_print(">");
  4680. delay(100);
  4681. _t = _t + 1;
  4682. if (_t>100)
  4683. {
  4684. prusa_statistics(99);
  4685. _t = 0;
  4686. }
  4687. if (lcd_clicked())
  4688. {
  4689. if (cursor_pos == 1)
  4690. {
  4691. _ret = 1;
  4692. filament_type = lcd_choose_color();
  4693. prusa_statistics(4, filament_type);
  4694. no_response = true; //we need confirmation by recieving PRUSA thx
  4695. important_status = 4;
  4696. saved_filament_type = filament_type;
  4697. NcTime = millis();
  4698. }
  4699. if (cursor_pos == 2)
  4700. {
  4701. _ret = 2;
  4702. filament_type = lcd_choose_color();
  4703. prusa_statistics(5, filament_type);
  4704. no_response = true; //we need confirmation by recieving PRUSA thx
  4705. important_status = 5;
  4706. saved_filament_type = filament_type;
  4707. NcTime = millis();
  4708. }
  4709. }
  4710. manage_heater();
  4711. manage_inactivity();
  4712. proc_commands();
  4713. } while (_ret == 0);
  4714. }
  4715. #include "w25x20cl.h"
  4716. static void lcd_test_menu()
  4717. {
  4718. W25X20CL_SPI_ENTER();
  4719. w25x20cl_enable_wr();
  4720. w25x20cl_chip_erase();
  4721. w25x20cl_disable_wr();
  4722. }
  4723. static void lcd_main_menu()
  4724. {
  4725. MENU_BEGIN();
  4726. // Majkl superawesome menu
  4727. MENU_ITEM_BACK_P(_T(MSG_WATCH));
  4728. #ifdef RESUME_DEBUG
  4729. if (!saved_printing)
  4730. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  4731. else
  4732. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  4733. #endif //RESUME_DEBUG
  4734. #ifdef TMC2130_DEBUG
  4735. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  4736. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  4737. #endif //TMC2130_DEBUG
  4738. /* if (farm_mode && !IS_SD_PRINTING )
  4739. {
  4740. int tempScrool = 0;
  4741. if (lcd_draw_update == 0 && LCD_CLICKED == 0)
  4742. //delay(100);
  4743. return; // nothing to do (so don't thrash the SD card)
  4744. uint16_t fileCnt = card.getnrfilenames();
  4745. card.getWorkDirName();
  4746. if (card.filename[0] == '/')
  4747. {
  4748. #if SDCARDDETECT == -1
  4749. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  4750. #endif
  4751. } else {
  4752. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4753. }
  4754. for (uint16_t i = 0; i < fileCnt; i++)
  4755. {
  4756. if (menu_item == menu_line)
  4757. {
  4758. #ifndef SDCARD_RATHERRECENTFIRST
  4759. card.getfilename(i);
  4760. #else
  4761. card.getfilename(fileCnt - 1 - i);
  4762. #endif
  4763. if (card.filenameIsDir)
  4764. {
  4765. MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4766. } else {
  4767. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4768. }
  4769. } else {
  4770. MENU_ITEM_DUMMY();
  4771. }
  4772. }
  4773. MENU_ITEM_BACK_P(PSTR("- - - - - - - - -"));
  4774. }*/
  4775. 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)
  4776. {
  4777. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4778. }
  4779. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4780. {
  4781. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=0 r=0
  4782. } else
  4783. {
  4784. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=0 r=0
  4785. }
  4786. #ifdef SDSUPPORT
  4787. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4788. {
  4789. if (card.isFileOpen())
  4790. {
  4791. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4792. if (card.sdprinting)
  4793. {
  4794. MENU_ITEM_FUNCTION_P(_i("Pause print"), lcd_sdcard_pause);////MSG_PAUSE_PRINT c=0 r=0
  4795. }
  4796. else
  4797. {
  4798. MENU_ITEM_FUNCTION_P(_i("Resume print"), lcd_sdcard_resume);////MSG_RESUME_PRINT c=0 r=0
  4799. }
  4800. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4801. }
  4802. }
  4803. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  4804. //MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4805. }
  4806. else
  4807. {
  4808. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4809. {
  4810. //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  4811. /*else*/ MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  4812. }
  4813. #if SDCARDDETECT < 1
  4814. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD c=0 r=0
  4815. #endif
  4816. }
  4817. } else
  4818. {
  4819. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=0 r=0
  4820. #if SDCARDDETECT < 1
  4821. 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
  4822. #endif
  4823. }
  4824. #endif
  4825. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4826. {
  4827. if (farm_mode)
  4828. {
  4829. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  4830. }
  4831. }
  4832. else
  4833. {
  4834. if (mmu_enabled)
  4835. {
  4836. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
  4837. if (mmu_enabled)
  4838. MENU_ITEM_GCODE_P(_T(MSG_UNLOAD_FILAMENT), PSTR("M702 C"));
  4839. else
  4840. {
  4841. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  4842. MENU_ITEM_SUBMENU_P(_i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20 r=1
  4843. }
  4844. }
  4845. else
  4846. {
  4847. #ifdef FILAMENT_SENSOR
  4848. if ( ((fsensor_autoload_enabled == true) && (fsensor_enabled == true)))
  4849. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0
  4850. else
  4851. #endif //FILAMENT_SENSOR
  4852. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  4853. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  4854. }
  4855. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  4856. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  4857. }
  4858. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4859. {
  4860. MENU_ITEM_SUBMENU_P(_i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS c=0 r=0
  4861. }
  4862. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  4863. MENU_ITEM_SUBMENU_P(PSTR("Fail stats"), lcd_menu_fails_stats);
  4864. #endif
  4865. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=0 r=0
  4866. // MENU_ITEM_SUBMENU_P(_i("W25x20CL init"), lcd_test_menu);////MSG_SUPPORT c=0 r=0
  4867. MENU_END();
  4868. }
  4869. void stack_error() {
  4870. SET_OUTPUT(BEEPER);
  4871. if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
  4872. WRITE(BEEPER, HIGH);
  4873. delay(1000);
  4874. WRITE(BEEPER, LOW);
  4875. lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4
  4876. //err_triggered = 1;
  4877. while (1) delay_keep_alive(1000);
  4878. }
  4879. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4880. bool stepper_timer_overflow_state = false;
  4881. uint16_t stepper_timer_overflow_max = 0;
  4882. uint16_t stepper_timer_overflow_last = 0;
  4883. uint16_t stepper_timer_overflow_cnt = 0;
  4884. void stepper_timer_overflow() {
  4885. char msg[28];
  4886. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  4887. lcd_setstatus(msg);
  4888. stepper_timer_overflow_state = false;
  4889. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  4890. stepper_timer_overflow_max = stepper_timer_overflow_last;
  4891. SERIAL_ECHOPGM("Stepper timer overflow: ");
  4892. MYSERIAL.print(msg);
  4893. SERIAL_ECHOLNPGM("");
  4894. WRITE(BEEPER, LOW);
  4895. }
  4896. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  4897. #ifdef SDSUPPORT
  4898. static void lcd_autostart_sd()
  4899. {
  4900. card.lastnr = 0;
  4901. card.setroot();
  4902. card.checkautostart(true);
  4903. }
  4904. #endif
  4905. static void lcd_silent_mode_set_tune() {
  4906. switch (SilentModeMenu) {
  4907. #ifdef TMC2130
  4908. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  4909. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  4910. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  4911. #else
  4912. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  4913. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  4914. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  4915. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  4916. #endif //TMC2130
  4917. }
  4918. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  4919. st_current_init();
  4920. menu_back();
  4921. }
  4922. static void lcd_colorprint_change() {
  4923. enquecommand_P(PSTR("M600"));
  4924. custom_message = true;
  4925. custom_message_type = 2; //just print status message
  4926. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  4927. lcd_return_to_status();
  4928. lcd_draw_update = 3;
  4929. }
  4930. static void lcd_tune_menu()
  4931. {
  4932. if (menuData.tuneMenu.status == 0) {
  4933. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  4934. menuData.tuneMenu.status = 1;
  4935. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  4936. } else if (menuData.tuneMenu.extrudemultiply != extrudemultiply) {
  4937. // extrudemultiply has been changed from the child menu. Apply the new value.
  4938. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  4939. calculate_extruder_multipliers();
  4940. }
  4941. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  4942. MENU_BEGIN();
  4943. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  4944. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=0 r=0
  4945. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  4946. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  4947. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  4948. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=0 r=0
  4949. #ifdef FILAMENTCHANGEENABLE
  4950. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//7
  4951. #endif
  4952. #ifdef FILAMENT_SENSOR
  4953. if (FSensorStateMenu == 0) {
  4954. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  4955. }
  4956. else {
  4957. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  4958. }
  4959. #endif //FILAMENT_SENSOR
  4960. #ifdef TMC2130
  4961. if(!farm_mode)
  4962. {
  4963. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);
  4964. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  4965. if (SilentModeMenu == SILENT_MODE_NORMAL)
  4966. {
  4967. if (CrashDetectMenu == 0) MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);
  4968. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  4969. }
  4970. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  4971. }
  4972. #else //TMC2130
  4973. if (!farm_mode) { //dont show in menu if we are in farm mode
  4974. switch (SilentModeMenu) {
  4975. case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  4976. case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  4977. case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  4978. default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  4979. }
  4980. }
  4981. #endif //TMC2130
  4982. switch(eSoundMode)
  4983. {
  4984. case e_SOUND_MODE_LOUD:
  4985. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
  4986. break;
  4987. case e_SOUND_MODE_ONCE:
  4988. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_ONCE),lcd_sound_state_set);
  4989. break;
  4990. case e_SOUND_MODE_SILENT:
  4991. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_SILENT),lcd_sound_state_set);
  4992. break;
  4993. case e_SOUND_MODE_MUTE:
  4994. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_MUTE),lcd_sound_state_set);
  4995. break;
  4996. default:
  4997. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
  4998. }
  4999. MENU_END();
  5000. }
  5001. static void lcd_move_menu_01mm()
  5002. {
  5003. move_menu_scale = 0.1;
  5004. lcd_move_menu_axis();
  5005. }
  5006. static void lcd_control_temperature_menu()
  5007. {
  5008. #ifdef PIDTEMP
  5009. // set up temp variables - undo the default scaling
  5010. // raw_Ki = unscalePID_i(Ki);
  5011. // raw_Kd = unscalePID_d(Kd);
  5012. #endif
  5013. MENU_BEGIN();
  5014. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5015. #if TEMP_SENSOR_0 != 0
  5016. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  5017. #endif
  5018. #if TEMP_SENSOR_1 != 0
  5019. MENU_ITEM_EDIT_int3_P(_i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1 c=0 r=0
  5020. #endif
  5021. #if TEMP_SENSOR_2 != 0
  5022. MENU_ITEM_EDIT_int3_P(_i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2 c=0 r=0
  5023. #endif
  5024. #if TEMP_SENSOR_BED != 0
  5025. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  5026. #endif
  5027. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  5028. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  5029. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  5030. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  5031. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN c=0 r=0
  5032. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX c=0 r=0
  5033. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR c=0 r=0
  5034. #endif
  5035. MENU_END();
  5036. }
  5037. #if SDCARDDETECT == -1
  5038. static void lcd_sd_refresh()
  5039. {
  5040. card.initsd();
  5041. menu_top = 0;
  5042. }
  5043. #endif
  5044. static void lcd_sd_updir()
  5045. {
  5046. card.updir();
  5047. menu_top = 0;
  5048. }
  5049. void lcd_print_stop()
  5050. {
  5051. cancel_heatup = true;
  5052. #ifdef MESH_BED_LEVELING
  5053. mbl.active = false;
  5054. #endif
  5055. // Stop the stoppers, update the position from the stoppers.
  5056. if (mesh_bed_leveling_flag == false && homing_flag == false)
  5057. {
  5058. planner_abort_hard();
  5059. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  5060. // Z baystep is no more applied. Reset it.
  5061. babystep_reset();
  5062. }
  5063. // Clean the input command queue.
  5064. cmdqueue_reset();
  5065. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  5066. card.sdprinting = false;
  5067. card.closefile();
  5068. stoptime = millis();
  5069. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5070. pause_time = 0;
  5071. save_statistics(total_filament_used, t);
  5072. lcd_return_to_status();
  5073. lcd_ignore_click(true);
  5074. lcd_commands_step = 0;
  5075. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  5076. // Turn off the print fan
  5077. SET_OUTPUT(FAN_PIN);
  5078. WRITE(FAN_PIN, 0);
  5079. fanSpeed = 0;
  5080. }
  5081. void lcd_sdcard_stop()
  5082. {
  5083. lcd_set_cursor(0, 0);
  5084. lcd_puts_P(_T(MSG_STOP_PRINT));
  5085. lcd_set_cursor(2, 2);
  5086. lcd_puts_P(_T(MSG_NO));
  5087. lcd_set_cursor(2, 3);
  5088. lcd_puts_P(_T(MSG_YES));
  5089. lcd_set_cursor(0, 2); lcd_print(" ");
  5090. lcd_set_cursor(0, 3); lcd_print(" ");
  5091. if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; }
  5092. if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; }
  5093. lcd_set_cursor(0, 1 + lcd_encoder);
  5094. lcd_print(">");
  5095. if (lcd_clicked())
  5096. {
  5097. if ((int32_t)lcd_encoder == 1)
  5098. {
  5099. lcd_return_to_status();
  5100. }
  5101. if ((int32_t)lcd_encoder == 2)
  5102. {
  5103. lcd_print_stop();
  5104. }
  5105. }
  5106. }
  5107. void lcd_sdcard_menu()
  5108. {
  5109. uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  5110. int tempScrool = 0;
  5111. if (presort_flag == true) {
  5112. presort_flag = false;
  5113. card.presort();
  5114. }
  5115. if (lcd_draw_update == 0 && LCD_CLICKED == 0)
  5116. //delay(100);
  5117. return; // nothing to do (so don't thrash the SD card)
  5118. uint16_t fileCnt = card.getnrfilenames();
  5119. MENU_BEGIN();
  5120. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5121. card.getWorkDirName();
  5122. if (card.filename[0] == '/')
  5123. {
  5124. #if SDCARDDETECT == -1
  5125. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  5126. #endif
  5127. } else {
  5128. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  5129. }
  5130. for (uint16_t i = 0; i < fileCnt; i++)
  5131. {
  5132. if (menu_item == menu_line)
  5133. {
  5134. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
  5135. /*#ifdef SDCARD_RATHERRECENTFIRST
  5136. #ifndef SDCARD_SORT_ALPHA
  5137. fileCnt - 1 -
  5138. #endif
  5139. #endif
  5140. i;*/
  5141. #ifdef SDCARD_SORT_ALPHA
  5142. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  5143. else card.getfilename_sorted(nr);
  5144. #else
  5145. card.getfilename(nr);
  5146. #endif
  5147. if (card.filenameIsDir)
  5148. MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  5149. else
  5150. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  5151. } else {
  5152. MENU_ITEM_DUMMY();
  5153. }
  5154. }
  5155. MENU_END();
  5156. }
  5157. static void lcd_selftest_v()
  5158. {
  5159. (void)lcd_selftest();
  5160. }
  5161. bool lcd_selftest()
  5162. {
  5163. int _progress = 0;
  5164. bool _result = true;
  5165. lcd_wait_for_cool_down();
  5166. lcd_clear();
  5167. lcd_set_cursor(0, 0); lcd_puts_P(_i("Self test start "));////MSG_SELFTEST_START c=20 r=0
  5168. #ifdef TMC2130
  5169. FORCE_HIGH_POWER_START;
  5170. #endif // TMC2130
  5171. delay(2000);
  5172. KEEPALIVE_STATE(IN_HANDLER);
  5173. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  5174. #if (defined(FANCHECK) && defined(TACH_0))
  5175. _result = lcd_selftest_fan_dialog(0);
  5176. #else //defined(TACH_0)
  5177. _result = lcd_selftest_manual_fan_check(0, false);
  5178. if (!_result)
  5179. {
  5180. const char *_err;
  5181. lcd_selftest_error(7, _err, _err); //extruder fan not spinning
  5182. }
  5183. #endif //defined(TACH_0)
  5184. if (_result)
  5185. {
  5186. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  5187. #if (defined(FANCHECK) && defined(TACH_1))
  5188. _result = lcd_selftest_fan_dialog(1);
  5189. #else //defined(TACH_1)
  5190. _result = lcd_selftest_manual_fan_check(1, false);
  5191. if (!_result)
  5192. {
  5193. const char *_err;
  5194. lcd_selftest_error(6, _err, _err); //print fan not spinning
  5195. }
  5196. #endif //defined(TACH_1)
  5197. }
  5198. if (_result)
  5199. {
  5200. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  5201. #ifndef TMC2130
  5202. _result = lcd_selfcheck_endstops();
  5203. #else
  5204. _result = true;
  5205. #endif
  5206. }
  5207. if (_result)
  5208. {
  5209. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  5210. _result = lcd_selfcheck_check_heater(false);
  5211. }
  5212. if (_result)
  5213. {
  5214. //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
  5215. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  5216. #ifdef TMC2130
  5217. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5218. #else
  5219. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5220. #endif //TMC2130
  5221. }
  5222. if (_result)
  5223. {
  5224. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  5225. #ifndef TMC2130
  5226. _result = lcd_selfcheck_pulleys(X_AXIS);
  5227. #endif
  5228. }
  5229. if (_result)
  5230. {
  5231. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  5232. #ifdef TMC2130
  5233. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5234. #else
  5235. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5236. #endif // TMC2130
  5237. }
  5238. if (_result)
  5239. {
  5240. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  5241. #ifndef TMC2130
  5242. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5243. #endif // TMC2130
  5244. }
  5245. if (_result)
  5246. {
  5247. #ifdef TMC2130
  5248. tmc2130_home_exit();
  5249. enable_endstops(false);
  5250. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  5251. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  5252. #endif
  5253. //homeaxis(X_AXIS);
  5254. //homeaxis(Y_AXIS);
  5255. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5256. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5257. st_synchronize();
  5258. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  5259. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  5260. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) {
  5261. enquecommand_P(PSTR("G28 W"));
  5262. enquecommand_P(PSTR("G1 Z15 F1000"));
  5263. }
  5264. }
  5265. #ifdef TMC2130
  5266. if (_result)
  5267. {
  5268. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5269. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5270. st_synchronize();
  5271. _progress = lcd_selftest_screen(13, 0, 2, true, 0);
  5272. bool bres = tmc2130_home_calibrate(X_AXIS);
  5273. _progress = lcd_selftest_screen(13, 1, 2, true, 0);
  5274. bres &= tmc2130_home_calibrate(Y_AXIS);
  5275. _progress = lcd_selftest_screen(13, 2, 2, true, 0);
  5276. if (bres)
  5277. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5278. _result = bres;
  5279. }
  5280. #endif //TMC2130
  5281. if (_result)
  5282. {
  5283. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000); //check bed
  5284. _result = lcd_selfcheck_check_heater(true);
  5285. }
  5286. if (_result)
  5287. {
  5288. _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok
  5289. #ifdef FILAMENT_SENSOR
  5290. _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor
  5291. _result = lcd_selftest_fsensor();
  5292. #endif // FILAMENT_SENSOR
  5293. }
  5294. if (_result)
  5295. {
  5296. #ifdef FILAMENT_SENSOR
  5297. _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK
  5298. #endif // FILAMENT_SENSOR
  5299. _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct
  5300. }
  5301. else
  5302. {
  5303. _progress = lcd_selftest_screen(12, _progress, 3, true, 5000);
  5304. }
  5305. lcd_reset_alert_level();
  5306. enquecommand_P(PSTR("M84"));
  5307. lcd_update_enable(true);
  5308. if (_result)
  5309. {
  5310. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=0 r=0
  5311. }
  5312. else
  5313. {
  5314. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5315. }
  5316. #ifdef TMC2130
  5317. FORCE_HIGH_POWER_END;
  5318. #endif // TMC2130
  5319. KEEPALIVE_STATE(NOT_BUSY);
  5320. return(_result);
  5321. }
  5322. #ifdef TMC2130
  5323. static void reset_crash_det(char axis) {
  5324. current_position[axis] += 10;
  5325. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5326. st_synchronize();
  5327. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5328. }
  5329. static bool lcd_selfcheck_axis_sg(char axis) {
  5330. // each axis length is measured twice
  5331. float axis_length, current_position_init, current_position_final;
  5332. float measured_axis_length[2];
  5333. float margin = 60;
  5334. float max_error_mm = 5;
  5335. switch (axis) {
  5336. case 0: axis_length = X_MAX_POS; break;
  5337. case 1: axis_length = Y_MAX_POS + 8; break;
  5338. default: axis_length = 210; break;
  5339. }
  5340. tmc2130_sg_stop_on_crash = false;
  5341. tmc2130_home_exit();
  5342. enable_endstops(true);
  5343. if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low
  5344. current_position[Z_AXIS] += 17;
  5345. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5346. tmc2130_home_enter(Z_AXIS_MASK);
  5347. st_synchronize();
  5348. tmc2130_home_exit();
  5349. }
  5350. // first axis length measurement begin
  5351. current_position[axis] -= (axis_length + margin);
  5352. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5353. st_synchronize();
  5354. tmc2130_sg_meassure_start(axis);
  5355. current_position_init = st_get_position_mm(axis);
  5356. current_position[axis] += 2 * margin;
  5357. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5358. st_synchronize();
  5359. current_position[axis] += axis_length;
  5360. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5361. st_synchronize();
  5362. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5363. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5364. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5365. current_position_final = st_get_position_mm(axis);
  5366. measured_axis_length[0] = abs(current_position_final - current_position_init);
  5367. // first measurement end and second measurement begin
  5368. current_position[axis] -= margin;
  5369. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5370. st_synchronize();
  5371. current_position[axis] -= (axis_length + margin);
  5372. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5373. st_synchronize();
  5374. current_position_init = st_get_position_mm(axis);
  5375. measured_axis_length[1] = abs(current_position_final - current_position_init);
  5376. //end of second measurement, now check for possible errors:
  5377. for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5378. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  5379. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5380. enable_endstops(false);
  5381. const char *_error_1;
  5382. if (axis == X_AXIS) _error_1 = "X";
  5383. if (axis == Y_AXIS) _error_1 = "Y";
  5384. if (axis == Z_AXIS) _error_1 = "Z";
  5385. lcd_selftest_error(9, _error_1, NULL);
  5386. current_position[axis] = 0;
  5387. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5388. reset_crash_det(axis);
  5389. return false;
  5390. }
  5391. }
  5392. printf_P(_N("Axis length difference:%.3f\n"), abs(measured_axis_length[0] - measured_axis_length[1]));
  5393. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5394. //loose pulleys
  5395. const char *_error_1;
  5396. if (axis == X_AXIS) _error_1 = "X";
  5397. if (axis == Y_AXIS) _error_1 = "Y";
  5398. if (axis == Z_AXIS) _error_1 = "Z";
  5399. lcd_selftest_error(8, _error_1, NULL);
  5400. current_position[axis] = 0;
  5401. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5402. reset_crash_det(axis);
  5403. return false;
  5404. }
  5405. current_position[axis] = 0;
  5406. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5407. reset_crash_det(axis);
  5408. return true;
  5409. }
  5410. #endif //TMC2130
  5411. //#ifndef TMC2130
  5412. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5413. {
  5414. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  5415. bool _stepdone = false;
  5416. bool _stepresult = false;
  5417. int _progress = 0;
  5418. int _travel_done = 0;
  5419. int _err_endstop = 0;
  5420. int _lcd_refresh = 0;
  5421. _travel = _travel + (_travel / 10);
  5422. if (_axis == X_AXIS) {
  5423. current_position[Z_AXIS] += 17;
  5424. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5425. }
  5426. do {
  5427. current_position[_axis] = current_position[_axis] - 1;
  5428. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5429. st_synchronize();
  5430. #ifdef TMC2130
  5431. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5432. #else //TMC2130
  5433. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  5434. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  5435. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5436. #endif //TMC2130
  5437. {
  5438. if (_axis == 0)
  5439. {
  5440. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5441. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5442. }
  5443. if (_axis == 1)
  5444. {
  5445. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5446. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5447. }
  5448. if (_axis == 2)
  5449. {
  5450. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5451. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5452. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  5453. /*disable_x();
  5454. disable_y();
  5455. disable_z();*/
  5456. }
  5457. _stepdone = true;
  5458. }
  5459. if (_lcd_refresh < 6)
  5460. {
  5461. _lcd_refresh++;
  5462. }
  5463. else
  5464. {
  5465. _progress = lcd_selftest_screen(4 + _axis, _progress, 3, false, 0);
  5466. _lcd_refresh = 0;
  5467. }
  5468. manage_heater();
  5469. manage_inactivity(true);
  5470. //delay(100);
  5471. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5472. } while (!_stepdone);
  5473. //current_position[_axis] = current_position[_axis] + 15;
  5474. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5475. if (!_stepresult)
  5476. {
  5477. const char *_error_1;
  5478. const char *_error_2;
  5479. if (_axis == X_AXIS) _error_1 = "X";
  5480. if (_axis == Y_AXIS) _error_1 = "Y";
  5481. if (_axis == Z_AXIS) _error_1 = "Z";
  5482. if (_err_endstop == 0) _error_2 = "X";
  5483. if (_err_endstop == 1) _error_2 = "Y";
  5484. if (_err_endstop == 2) _error_2 = "Z";
  5485. if (_travel_done >= _travel)
  5486. {
  5487. lcd_selftest_error(5, _error_1, _error_2);
  5488. }
  5489. else
  5490. {
  5491. lcd_selftest_error(4, _error_1, _error_2);
  5492. }
  5493. }
  5494. return _stepresult;
  5495. }
  5496. #ifndef TMC2130
  5497. static bool lcd_selfcheck_pulleys(int axis)
  5498. {
  5499. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5500. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5501. float current_position_init;
  5502. float move;
  5503. bool endstop_triggered = false;
  5504. int i;
  5505. unsigned long timeout_counter;
  5506. refresh_cmd_timeout();
  5507. manage_inactivity(true);
  5508. if (axis == 0) move = 50; //X_AXIS
  5509. else move = 50; //Y_AXIS
  5510. current_position_init = current_position[axis];
  5511. current_position[axis] += 2;
  5512. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5513. for (i = 0; i < 5; i++) {
  5514. refresh_cmd_timeout();
  5515. current_position[axis] = current_position[axis] + move;
  5516. st_current_set(0, 850); //set motor current higher
  5517. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  5518. st_synchronize();
  5519. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  5520. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  5521. current_position[axis] = current_position[axis] - move;
  5522. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  5523. st_synchronize();
  5524. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5525. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5526. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5527. return(false);
  5528. }
  5529. }
  5530. timeout_counter = millis() + 2500;
  5531. endstop_triggered = false;
  5532. manage_inactivity(true);
  5533. while (!endstop_triggered) {
  5534. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5535. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5536. endstop_triggered = true;
  5537. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5538. current_position[axis] += (axis == X_AXIS) ? 13 : 9;
  5539. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5540. st_synchronize();
  5541. return(true);
  5542. }
  5543. else {
  5544. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5545. return(false);
  5546. }
  5547. }
  5548. else {
  5549. current_position[axis] -= 1;
  5550. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5551. st_synchronize();
  5552. if (millis() > timeout_counter) {
  5553. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5554. return(false);
  5555. }
  5556. }
  5557. }
  5558. return(true);
  5559. }
  5560. #endif //TMC2130
  5561. static bool lcd_selfcheck_endstops()
  5562. {
  5563. bool _result = true;
  5564. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5565. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5566. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5567. {
  5568. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  5569. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  5570. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  5571. }
  5572. 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);
  5573. delay(500);
  5574. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5575. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5576. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5577. {
  5578. _result = false;
  5579. char _error[4] = "";
  5580. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  5581. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  5582. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  5583. lcd_selftest_error(3, _error, "");
  5584. }
  5585. manage_heater();
  5586. manage_inactivity(true);
  5587. return _result;
  5588. }
  5589. //#endif //not defined TMC2130
  5590. static bool lcd_selfcheck_check_heater(bool _isbed)
  5591. {
  5592. int _counter = 0;
  5593. int _progress = 0;
  5594. bool _stepresult = false;
  5595. bool _docycle = true;
  5596. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5597. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5598. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5599. target_temperature[0] = (_isbed) ? 0 : 200;
  5600. target_temperature_bed = (_isbed) ? 100 : 0;
  5601. manage_heater();
  5602. manage_inactivity(true);
  5603. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  5604. do {
  5605. _counter++;
  5606. _docycle = (_counter < _cycles) ? true : false;
  5607. manage_heater();
  5608. manage_inactivity(true);
  5609. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  5610. /*if (_isbed) {
  5611. MYSERIAL.print("Bed temp:");
  5612. MYSERIAL.println(degBed());
  5613. }
  5614. else {
  5615. MYSERIAL.print("Hotend temp:");
  5616. MYSERIAL.println(degHotend(0));
  5617. }*/
  5618. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  5619. } while (_docycle);
  5620. target_temperature[0] = 0;
  5621. target_temperature_bed = 0;
  5622. manage_heater();
  5623. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  5624. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  5625. /*
  5626. MYSERIAL.println("");
  5627. MYSERIAL.print("Checked result:");
  5628. MYSERIAL.println(_checked_result);
  5629. MYSERIAL.print("Opposite result:");
  5630. MYSERIAL.println(_opposite_result);
  5631. */
  5632. if (_opposite_result < ((_isbed) ? 10 : 3))
  5633. {
  5634. if (_checked_result >= ((_isbed) ? 3 : 10))
  5635. {
  5636. _stepresult = true;
  5637. }
  5638. else
  5639. {
  5640. lcd_selftest_error(1, "", "");
  5641. }
  5642. }
  5643. else
  5644. {
  5645. lcd_selftest_error(2, "", "");
  5646. }
  5647. manage_heater();
  5648. manage_inactivity(true);
  5649. KEEPALIVE_STATE(IN_HANDLER);
  5650. return _stepresult;
  5651. }
  5652. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  5653. {
  5654. lcd_beeper_quick_feedback();
  5655. target_temperature[0] = 0;
  5656. target_temperature_bed = 0;
  5657. manage_heater();
  5658. manage_inactivity();
  5659. lcd_clear();
  5660. lcd_set_cursor(0, 0);
  5661. lcd_puts_P(_i("Selftest error !"));////MSG_SELFTEST_ERROR c=0 r=0
  5662. lcd_set_cursor(0, 1);
  5663. lcd_puts_P(_i("Please check :"));////MSG_SELFTEST_PLEASECHECK c=0 r=0
  5664. switch (_error_no)
  5665. {
  5666. case 1:
  5667. lcd_set_cursor(0, 2);
  5668. lcd_puts_P(_i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=0 r=0
  5669. lcd_set_cursor(0, 3);
  5670. lcd_puts_P(_i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=0 r=0
  5671. break;
  5672. case 2:
  5673. lcd_set_cursor(0, 2);
  5674. lcd_puts_P(_i("Bed / Heater"));////MSG_SELFTEST_BEDHEATER c=0 r=0
  5675. lcd_set_cursor(0, 3);
  5676. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5677. break;
  5678. case 3:
  5679. lcd_set_cursor(0, 2);
  5680. lcd_puts_P(_i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=0 r=0
  5681. lcd_set_cursor(0, 3);
  5682. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5683. lcd_set_cursor(17, 3);
  5684. lcd_print(_error_1);
  5685. break;
  5686. case 4:
  5687. lcd_set_cursor(0, 2);
  5688. lcd_puts_P(_T(MSG_SELFTEST_MOTOR));
  5689. lcd_set_cursor(18, 2);
  5690. lcd_print(_error_1);
  5691. lcd_set_cursor(0, 3);
  5692. lcd_puts_P(_i("Endstop"));////MSG_SELFTEST_ENDSTOP c=0 r=0
  5693. lcd_set_cursor(18, 3);
  5694. lcd_print(_error_2);
  5695. break;
  5696. case 5:
  5697. lcd_set_cursor(0, 2);
  5698. lcd_puts_P(_i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20 r=1
  5699. lcd_set_cursor(0, 3);
  5700. lcd_puts_P(_T(MSG_SELFTEST_MOTOR));
  5701. lcd_set_cursor(18, 3);
  5702. lcd_print(_error_1);
  5703. break;
  5704. case 6:
  5705. lcd_set_cursor(0, 2);
  5706. lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN));
  5707. lcd_set_cursor(0, 3);
  5708. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5709. lcd_set_cursor(18, 3);
  5710. lcd_print(_error_1);
  5711. break;
  5712. case 7:
  5713. lcd_set_cursor(0, 2);
  5714. lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5715. lcd_set_cursor(0, 3);
  5716. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5717. lcd_set_cursor(18, 3);
  5718. lcd_print(_error_1);
  5719. break;
  5720. case 8:
  5721. lcd_set_cursor(0, 2);
  5722. lcd_puts_P(_i("Loose pulley"));////MSG_LOOSE_PULLEY c=20 r=1
  5723. lcd_set_cursor(0, 3);
  5724. lcd_puts_P(_T(MSG_SELFTEST_MOTOR));
  5725. lcd_set_cursor(18, 3);
  5726. lcd_print(_error_1);
  5727. break;
  5728. case 9:
  5729. lcd_set_cursor(0, 2);
  5730. lcd_puts_P(_i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=0 r=0
  5731. lcd_set_cursor(0, 3);
  5732. lcd_puts_P(_i("Axis"));////MSG_SELFTEST_AXIS c=0 r=0
  5733. lcd_set_cursor(18, 3);
  5734. lcd_print(_error_1);
  5735. break;
  5736. case 10:
  5737. lcd_set_cursor(0, 2);
  5738. lcd_puts_P(_i("Front/left fans"));////MSG_SELFTEST_FANS c=0 r=0
  5739. lcd_set_cursor(0, 3);
  5740. lcd_puts_P(_i("Swapped"));////MSG_SELFTEST_SWAPPED c=0 r=0
  5741. lcd_set_cursor(18, 3);
  5742. lcd_print(_error_1);
  5743. break;
  5744. case 11:
  5745. lcd_set_cursor(0, 2);
  5746. lcd_puts_P(_i("Filament sensor"));////MSG_FILAMENT_SENSOR c=20 r=0
  5747. lcd_set_cursor(0, 3);
  5748. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5749. break;
  5750. }
  5751. delay(1000);
  5752. lcd_beeper_quick_feedback();
  5753. do {
  5754. delay(100);
  5755. manage_heater();
  5756. manage_inactivity();
  5757. } while (!lcd_clicked());
  5758. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5759. lcd_return_to_status();
  5760. }
  5761. #ifdef FILAMENT_SENSOR
  5762. static bool lcd_selftest_fsensor(void)
  5763. {
  5764. fsensor_init();
  5765. if (fsensor_not_responding)
  5766. {
  5767. lcd_selftest_error(11, NULL, NULL);
  5768. }
  5769. return (!fsensor_not_responding);
  5770. }
  5771. #endif //FILAMENT_SENSOR
  5772. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
  5773. {
  5774. bool _result = check_opposite;
  5775. lcd_clear();
  5776. lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_SELFTEST_FAN));
  5777. switch (_fan)
  5778. {
  5779. case 0:
  5780. // extruder cooling fan
  5781. lcd_set_cursor(0, 1);
  5782. if(check_opposite == true) lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN));
  5783. else lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5784. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5785. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5786. break;
  5787. case 1:
  5788. // object cooling fan
  5789. lcd_set_cursor(0, 1);
  5790. if (check_opposite == true) lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5791. else lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN));
  5792. SET_OUTPUT(FAN_PIN);
  5793. analogWrite(FAN_PIN, 255);
  5794. break;
  5795. }
  5796. delay(500);
  5797. lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
  5798. lcd_set_cursor(0, 3); lcd_print(">");
  5799. lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
  5800. int8_t enc_dif = 0;
  5801. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5802. lcd_button_pressed = false;
  5803. do
  5804. {
  5805. switch (_fan)
  5806. {
  5807. case 0:
  5808. // extruder cooling fan
  5809. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5810. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5811. break;
  5812. case 1:
  5813. // object cooling fan
  5814. SET_OUTPUT(FAN_PIN);
  5815. analogWrite(FAN_PIN, 255);
  5816. break;
  5817. }
  5818. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5819. if (enc_dif > lcd_encoder_diff) {
  5820. _result = !check_opposite;
  5821. lcd_set_cursor(0, 2); lcd_print(">");
  5822. lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
  5823. lcd_set_cursor(0, 3); lcd_print(" ");
  5824. lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
  5825. }
  5826. if (enc_dif < lcd_encoder_diff) {
  5827. _result = check_opposite;
  5828. lcd_set_cursor(0, 2); lcd_print(" ");
  5829. lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
  5830. lcd_set_cursor(0, 3); lcd_print(">");
  5831. lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
  5832. }
  5833. enc_dif = 0;
  5834. lcd_encoder_diff = 0;
  5835. }
  5836. manage_heater();
  5837. delay(100);
  5838. } while (!lcd_clicked());
  5839. KEEPALIVE_STATE(IN_HANDLER);
  5840. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5841. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  5842. SET_OUTPUT(FAN_PIN);
  5843. analogWrite(FAN_PIN, 0);
  5844. fanSpeed = 0;
  5845. manage_heater();
  5846. return _result;
  5847. }
  5848. static bool lcd_selftest_fan_dialog(int _fan)
  5849. {
  5850. bool _result = true;
  5851. int _errno = 7;
  5852. switch (_fan) {
  5853. case 0:
  5854. fanSpeed = 0;
  5855. manage_heater(); //turn off fan
  5856. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  5857. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  5858. manage_heater(); //count average fan speed from 2s delay and turn off fans
  5859. if (!fan_speed[0]) _result = false;
  5860. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5861. //MYSERIAL.println(fan_speed[0]);
  5862. //SERIAL_ECHOPGM("Print fan speed: ");
  5863. //MYSERIAL.print(fan_speed[1]);
  5864. break;
  5865. case 1:
  5866. //will it work with Thotend > 50 C ?
  5867. fanSpeed = 150; //print fan
  5868. for (uint8_t i = 0; i < 5; i++) {
  5869. delay_keep_alive(1000);
  5870. lcd_set_cursor(18, 3);
  5871. lcd_print("-");
  5872. delay_keep_alive(1000);
  5873. lcd_set_cursor(18, 3);
  5874. lcd_print("|");
  5875. }
  5876. fanSpeed = 0;
  5877. manage_heater(); //turn off fan
  5878. manage_inactivity(true); //to turn off print fan
  5879. if (!fan_speed[1]) {
  5880. _result = false; _errno = 6; //print fan not spinning
  5881. }
  5882. else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
  5883. //check fans manually
  5884. _result = lcd_selftest_manual_fan_check(1, true); //turn on print fan and check that left extruder fan is not spinning
  5885. if (_result) {
  5886. _result = lcd_selftest_manual_fan_check(1, false); //print fan is stil turned on; check that it is spinning
  5887. if (!_result) _errno = 6; //print fan not spinning
  5888. }
  5889. else {
  5890. _errno = 10; //swapped fans
  5891. }
  5892. }
  5893. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5894. //MYSERIAL.println(fan_speed[0]);
  5895. //SERIAL_ECHOPGM("Print fan speed: ");
  5896. //MYSERIAL.println(fan_speed[1]);
  5897. break;
  5898. }
  5899. if (!_result)
  5900. {
  5901. lcd_selftest_error(_errno, NULL, NULL);
  5902. }
  5903. return _result;
  5904. }
  5905. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  5906. {
  5907. lcd_update_enable(false);
  5908. int _step_block = 0;
  5909. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  5910. if (_clear) lcd_clear();
  5911. lcd_set_cursor(0, 0);
  5912. if (_step == -1) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  5913. if (_step == 0) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  5914. if (_step == 1) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  5915. if (_step == 2) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 r=0
  5916. if (_step == 3) lcd_puts_P(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 r=0
  5917. if (_step == 4) lcd_puts_P(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 r=0
  5918. if (_step == 5) lcd_puts_P(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 r=0
  5919. if (_step == 6) lcd_puts_P(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 r=0
  5920. if (_step == 7) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  5921. if (_step == 8) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  5922. if (_step == 9) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  5923. if (_step == 10) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  5924. if (_step == 11) lcd_puts_P(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 r=0
  5925. if (_step == 12) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  5926. if (_step == 13) lcd_puts_P(PSTR("Calibrating home"));
  5927. lcd_set_cursor(0, 1);
  5928. lcd_puts_P(separator);
  5929. if ((_step >= -1) && (_step <= 1))
  5930. {
  5931. //SERIAL_ECHOLNPGM("Fan test");
  5932. lcd_puts_at_P(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18 r=0
  5933. lcd_set_cursor(18, 2);
  5934. (_step < 0) ? lcd_print(_indicator) : lcd_print("OK");
  5935. lcd_puts_at_P(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18 r=0
  5936. lcd_set_cursor(18, 3);
  5937. (_step < 1) ? lcd_print(_indicator) : lcd_print("OK");
  5938. }
  5939. else if (_step >= 9 && _step <= 10)
  5940. {
  5941. lcd_puts_at_P(0, 2, _i("Filament sensor:"));////MSG_SELFTEST_FILAMENT_SENSOR c=18 r=0
  5942. lcd_set_cursor(18, 2);
  5943. (_step == 9) ? lcd_print(_indicator) : lcd_print("OK");
  5944. }
  5945. else if (_step < 9)
  5946. {
  5947. //SERIAL_ECHOLNPGM("Other tests");
  5948. _step_block = 3;
  5949. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  5950. _step_block = 4;
  5951. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  5952. _step_block = 5;
  5953. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  5954. _step_block = 6;
  5955. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  5956. _step_block = 7;
  5957. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  5958. }
  5959. if (_delay > 0) delay_keep_alive(_delay);
  5960. _progress++;
  5961. return (_progress > _progress_scale * 2) ? 0 : _progress;
  5962. }
  5963. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  5964. {
  5965. lcd_set_cursor(_col, _row);
  5966. switch (_state)
  5967. {
  5968. case 1:
  5969. lcd_print(_name);
  5970. lcd_set_cursor(_col + strlen(_name), _row);
  5971. lcd_print(":");
  5972. lcd_set_cursor(_col + strlen(_name) + 1, _row);
  5973. lcd_print(_indicator);
  5974. break;
  5975. case 2:
  5976. lcd_print(_name);
  5977. lcd_set_cursor(_col + strlen(_name), _row);
  5978. lcd_print(":");
  5979. lcd_set_cursor(_col + strlen(_name) + 1, _row);
  5980. lcd_print("OK");
  5981. break;
  5982. default:
  5983. lcd_print(_name);
  5984. }
  5985. }
  5986. /** End of menus **/
  5987. /** Menu action functions **/
  5988. static bool check_file(const char* filename) {
  5989. if (farm_mode) return true;
  5990. bool result = false;
  5991. uint32_t filesize;
  5992. card.openFile((char*)filename, true);
  5993. filesize = card.getFileSize();
  5994. if (filesize > END_FILE_SECTION) {
  5995. card.setIndex(filesize - END_FILE_SECTION);
  5996. }
  5997. while (!card.eof() && !result) {
  5998. card.sdprinting = true;
  5999. get_command();
  6000. result = check_commands();
  6001. }
  6002. card.printingHasFinished();
  6003. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  6004. lcd_finishstatus();
  6005. return result;
  6006. }
  6007. void menu_action_sdfile(const char* filename, char* longFilename)
  6008. {
  6009. loading_flag = false;
  6010. char cmd[30];
  6011. char* c;
  6012. bool result = true;
  6013. sprintf_P(cmd, PSTR("M23 %s"), filename);
  6014. for (c = &cmd[4]; *c; c++)
  6015. *c = tolower(*c);
  6016. const char end[5] = ".gco";
  6017. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  6018. for (int i = 0; i < 8; i++) {
  6019. if (strcmp((cmd + i + 4), end) == 0) {
  6020. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  6021. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  6022. break;
  6023. }
  6024. else {
  6025. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  6026. }
  6027. }
  6028. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6029. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  6030. for (uint8_t i = 0; i < depth; i++) {
  6031. for (int j = 0; j < 8; j++) {
  6032. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
  6033. }
  6034. }
  6035. if (!check_file(filename)) {
  6036. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=2
  6037. lcd_update_enable(true);
  6038. }
  6039. if (result) {
  6040. enquecommand(cmd);
  6041. enquecommand_P(PSTR("M24"));
  6042. }
  6043. lcd_return_to_status();
  6044. }
  6045. void menu_action_sddirectory(const char* filename, char* longFilename)
  6046. {
  6047. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6048. strcpy(dir_names[depth], filename);
  6049. MYSERIAL.println(dir_names[depth]);
  6050. card.chdir(filename);
  6051. lcd_encoder = 0;
  6052. }
  6053. /** LCD API **/
  6054. void ultralcd_init()
  6055. {
  6056. lcd_init();
  6057. lcd_refresh();
  6058. lcd_longpress_func = menu_lcd_longpress_func;
  6059. lcd_charsetup_func = menu_lcd_charsetup_func;
  6060. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  6061. menu_menu = lcd_status_screen;
  6062. menu_lcd_charsetup_func();
  6063. SET_INPUT(BTN_EN1);
  6064. SET_INPUT(BTN_EN2);
  6065. WRITE(BTN_EN1, HIGH);
  6066. WRITE(BTN_EN2, HIGH);
  6067. #if BTN_ENC > 0
  6068. SET_INPUT(BTN_ENC);
  6069. WRITE(BTN_ENC, HIGH);
  6070. #endif
  6071. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  6072. pinMode(SDCARDDETECT, INPUT);
  6073. WRITE(SDCARDDETECT, HIGH);
  6074. lcd_oldcardstatus = IS_SD_INSERTED;
  6075. #endif//(SDCARDDETECT > 0)
  6076. lcd_buttons_update();
  6077. lcd_encoder_diff = 0;
  6078. }
  6079. void lcd_printer_connected() {
  6080. printer_connected = true;
  6081. }
  6082. static void lcd_send_status() {
  6083. if (farm_mode && no_response && ((millis() - NcTime) > (NC_TIME * 1000))) {
  6084. //send important status messages periodicaly
  6085. prusa_statistics(important_status, saved_filament_type);
  6086. NcTime = millis();
  6087. #ifdef FARM_CONNECT_MESSAGE
  6088. lcd_connect_printer();
  6089. #endif //FARM_CONNECT_MESSAGE
  6090. }
  6091. }
  6092. static void lcd_connect_printer() {
  6093. lcd_update_enable(false);
  6094. lcd_clear();
  6095. bool pressed = false;
  6096. int i = 0;
  6097. int t = 0;
  6098. lcd_set_custom_characters_progress();
  6099. lcd_puts_at_P(0, 0, _i("Connect printer to"));
  6100. lcd_puts_at_P(0, 1, _i("monitoring or hold"));
  6101. lcd_puts_at_P(0, 2, _i("the knob to continue"));
  6102. while (no_response) {
  6103. i++;
  6104. t++;
  6105. delay_keep_alive(100);
  6106. proc_commands();
  6107. if (t == 10) {
  6108. prusa_statistics(important_status, saved_filament_type);
  6109. t = 0;
  6110. }
  6111. if (READ(BTN_ENC)) { //if button is not pressed
  6112. i = 0;
  6113. lcd_puts_at_P(0, 3, PSTR(" "));
  6114. }
  6115. if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\x01");
  6116. if (i == NC_BUTTON_LONG_PRESS * 10) {
  6117. no_response = false;
  6118. }
  6119. }
  6120. lcd_set_custom_characters_degree();
  6121. lcd_update_enable(true);
  6122. lcd_update(2);
  6123. }
  6124. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  6125. if (farm_mode) {
  6126. bool empty = is_buffer_empty();
  6127. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  6128. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  6129. //therefore longer period is used
  6130. printer_connected = false;
  6131. }
  6132. else {
  6133. lcd_printer_connected();
  6134. }
  6135. }
  6136. }
  6137. void lcd_ignore_click(bool b)
  6138. {
  6139. ignore_click = b;
  6140. wait_for_unclick = false;
  6141. }
  6142. void lcd_finishstatus() {
  6143. int len = strlen(lcd_status_message);
  6144. if (len > 0) {
  6145. while (len < LCD_WIDTH) {
  6146. lcd_status_message[len++] = ' ';
  6147. }
  6148. }
  6149. lcd_status_message[LCD_WIDTH] = '\0';
  6150. lcd_draw_update = 2;
  6151. }
  6152. void lcd_setstatus(const char* message)
  6153. {
  6154. if (lcd_status_message_level > 0)
  6155. return;
  6156. strncpy(lcd_status_message, message, LCD_WIDTH);
  6157. lcd_finishstatus();
  6158. }
  6159. void lcd_setstatuspgm(const char* message)
  6160. {
  6161. if (lcd_status_message_level > 0)
  6162. return;
  6163. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6164. lcd_status_message[LCD_WIDTH] = 0;
  6165. lcd_finishstatus();
  6166. }
  6167. void lcd_setalertstatuspgm(const char* message)
  6168. {
  6169. lcd_setstatuspgm(message);
  6170. lcd_status_message_level = 1;
  6171. lcd_return_to_status();
  6172. }
  6173. void lcd_reset_alert_level()
  6174. {
  6175. lcd_status_message_level = 0;
  6176. }
  6177. uint8_t get_message_level()
  6178. {
  6179. return lcd_status_message_level;
  6180. }
  6181. void menu_lcd_longpress_func(void)
  6182. {
  6183. move_menu_scale = 1.0;
  6184. menu_submenu(lcd_move_z);
  6185. }
  6186. void menu_lcd_charsetup_func(void)
  6187. {
  6188. if (menu_menu == lcd_status_screen)
  6189. lcd_set_custom_characters_degree();
  6190. else
  6191. lcd_set_custom_characters_arrows();
  6192. }
  6193. static inline bool z_menu_expired()
  6194. {
  6195. return (menu_menu == lcd_babystep_z
  6196. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  6197. }
  6198. static inline bool other_menu_expired()
  6199. {
  6200. return (menu_menu != lcd_status_screen
  6201. && menu_menu != lcd_babystep_z
  6202. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  6203. }
  6204. static inline bool forced_menu_expire()
  6205. {
  6206. bool retval = (menu_menu != lcd_status_screen
  6207. && forceMenuExpire);
  6208. forceMenuExpire = false;
  6209. return retval;
  6210. }
  6211. void menu_lcd_lcdupdate_func(void)
  6212. {
  6213. #if (SDCARDDETECT > 0)
  6214. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  6215. {
  6216. lcd_draw_update = 2;
  6217. lcd_oldcardstatus = IS_SD_INSERTED;
  6218. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  6219. if (lcd_oldcardstatus)
  6220. {
  6221. card.initsd();
  6222. LCD_MESSAGERPGM(_i("Card inserted"));////MSG_SD_INSERTED c=0 r=0
  6223. //get_description();
  6224. }
  6225. else
  6226. {
  6227. card.release();
  6228. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=0 r=0
  6229. }
  6230. }
  6231. #endif//CARDINSERTED
  6232. if (lcd_next_update_millis < millis())
  6233. {
  6234. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  6235. {
  6236. if (lcd_draw_update == 0)
  6237. lcd_draw_update = 1;
  6238. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  6239. lcd_encoder_diff = 0;
  6240. lcd_timeoutToStatus.start();
  6241. }
  6242. if (LCD_CLICKED) lcd_timeoutToStatus.start();
  6243. (*menu_menu)();
  6244. if (z_menu_expired() || other_menu_expired() || forced_menu_expire())
  6245. {
  6246. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  6247. // to give it a chance to save its state.
  6248. // This is useful for example, when the babystep value has to be written into EEPROM.
  6249. if (menu_menu != NULL)
  6250. {
  6251. menuExiting = true;
  6252. (*menu_menu)();
  6253. menuExiting = false;
  6254. }
  6255. lcd_clear();
  6256. lcd_return_to_status();
  6257. lcd_draw_update = 2;
  6258. }
  6259. if (lcd_draw_update == 2) lcd_clear();
  6260. if (lcd_draw_update) lcd_draw_update--;
  6261. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  6262. }
  6263. if (!SdFatUtil::test_stack_integrity()) stack_error();
  6264. lcd_ping(); //check that we have received ping command if we are in farm mode
  6265. lcd_send_status();
  6266. if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
  6267. }