ultralcd.cpp 220 KB

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