ultralcd.cpp 236 KB

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