ultralcd.cpp 236 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241
  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. if (!lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language from XFLASH?"), false, true))
  3195. {
  3196. lcd_return_to_status();
  3197. lcd_update_enable(true);
  3198. return;
  3199. }
  3200. lang_select(lang);
  3201. /*
  3202. lang_selected = lang;
  3203. firstrun = 1;
  3204. eeprom_update_byte((unsigned char *)EEPROM_LANG, lang);
  3205. // langsel=0;
  3206. if (langsel == LANGSEL_MODAL)
  3207. // From modal mode to an active mode? This forces the menu to return to the setup menu.
  3208. langsel = LANGSEL_ACTIVE;
  3209. */
  3210. }
  3211. #ifdef PAT9125
  3212. static void lcd_fsensor_state_set()
  3213. {
  3214. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3215. if (!FSensorStateMenu) {
  3216. fsensor_disable();
  3217. if (filament_autoload_enabled)
  3218. menu_action_submenu(lcd_filament_autoload_info);
  3219. }else{
  3220. fsensor_enable();
  3221. if (fsensor_not_responding)
  3222. menu_action_submenu(lcd_fsensor_fail);
  3223. }
  3224. }
  3225. #endif //PAT9125
  3226. #if !SDSORT_USES_RAM
  3227. void lcd_set_degree() {
  3228. lcd_set_custom_characters_degree();
  3229. }
  3230. void lcd_set_progress() {
  3231. lcd_set_custom_characters_progress();
  3232. }
  3233. #endif
  3234. void lcd_force_language_selection() {
  3235. eeprom_update_byte((unsigned char *)EEPROM_LANG, LANG_ID_FORCE_SELECTION);
  3236. }
  3237. #if (LANG_MODE != 0)
  3238. static void lcd_language_menu()
  3239. {
  3240. START_MENU();
  3241. if (langsel == LANGSEL_OFF)
  3242. MENU_ITEM(back, _T(MSG_SETTINGS), 0);
  3243. else if (langsel == LANGSEL_ACTIVE)
  3244. MENU_ITEM(back, _T(MSG_WATCH), 0);
  3245. MENU_ITEM(setlang, lang_get_name_by_code(lang_get_code(0)), 0);
  3246. // MENU_ITEM(setlang, lang_get_name_by_code(lang_get_code(1)), 1);
  3247. for (int i = 2; i < lang_get_count(); i++) //skip seconday language - solved in menu_action_setlang
  3248. MENU_ITEM(setlang, lang_get_name_by_code(lang_get_code(i)), i);
  3249. END_MENU();
  3250. }
  3251. #endif //(LANG_MODE != 0)
  3252. void lcd_mesh_bedleveling()
  3253. {
  3254. mesh_bed_run_from_menu = true;
  3255. enquecommand_P(PSTR("G80"));
  3256. lcd_return_to_status();
  3257. }
  3258. void lcd_mesh_calibration()
  3259. {
  3260. enquecommand_P(PSTR("M45"));
  3261. lcd_return_to_status();
  3262. }
  3263. void lcd_mesh_calibration_z()
  3264. {
  3265. enquecommand_P(PSTR("M45 Z"));
  3266. lcd_return_to_status();
  3267. }
  3268. void lcd_pinda_calibration_menu()
  3269. {
  3270. START_MENU();
  3271. MENU_ITEM(back, _T(MSG_MENU_CALIBRATION), 0);
  3272. MENU_ITEM(submenu, _i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17 r=1
  3273. END_MENU();
  3274. }
  3275. void lcd_temp_calibration_set() {
  3276. temp_cal_active = !temp_cal_active;
  3277. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3278. st_current_init();
  3279. lcd_goto_menu(lcd_settings_menu); //doesn't break menuStack
  3280. }
  3281. #ifdef HAS_SECOND_SERIAL_PORT
  3282. void lcd_second_serial_set() {
  3283. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3284. else selectedSerialPort = 1;
  3285. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3286. MYSERIAL.begin(BAUDRATE);
  3287. lcd_goto_menu(lcd_settings_menu);//doesn't break menuStack
  3288. }
  3289. #endif //HAS_SECOND_SERIAL_PORT
  3290. void lcd_calibrate_pinda() {
  3291. enquecommand_P(PSTR("G76"));
  3292. lcd_return_to_status();
  3293. }
  3294. #ifndef SNMM
  3295. /*void lcd_calibrate_extruder() {
  3296. if (degHotend0() > EXTRUDE_MINTEMP)
  3297. {
  3298. current_position[E_AXIS] = 0; //set initial position to zero
  3299. plan_set_e_position(current_position[E_AXIS]);
  3300. //long steps_start = st_get_position(E_AXIS);
  3301. long steps_final;
  3302. float e_steps_per_unit;
  3303. 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)
  3304. 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
  3305. 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
  3306. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3307. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3308. unsigned long msg_millis;
  3309. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  3310. lcd_implementation_clear();
  3311. lcd.setCursor(0, 1); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  3312. current_position[E_AXIS] += e_shift_calibration;
  3313. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3314. st_synchronize();
  3315. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3316. msg_millis = millis();
  3317. while (!LCD_CLICKED) {
  3318. if (multi_screen && millis() - msg_millis > 5000) {
  3319. if (msg_next_e_cal_knob == NULL)
  3320. msg_next_e_cal_knob = msg_e_cal_knob;
  3321. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3322. msg_millis = millis();
  3323. }
  3324. //manage_inactivity(true);
  3325. manage_heater();
  3326. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3327. delay_keep_alive(50);
  3328. //previous_millis_cmd = millis();
  3329. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  3330. encoderDiff = 0;
  3331. if (!planner_queue_full()) {
  3332. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.01; //0.05
  3333. encoderPosition = 0;
  3334. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3335. }
  3336. }
  3337. }
  3338. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3339. //steps_final = st_get_position(E_AXIS);
  3340. lcdDrawUpdate = 1;
  3341. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3342. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3343. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3344. lcd_implementation_clear();
  3345. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3346. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3347. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3348. //delay_keep_alive(2000);
  3349. delay_keep_alive(500);
  3350. 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
  3351. lcd_update_enable(true);
  3352. lcdDrawUpdate = 2;
  3353. }
  3354. else
  3355. {
  3356. lcd_implementation_clear();
  3357. lcd.setCursor(0, 0);
  3358. lcd_printPGM(_T(MSG_ERROR));
  3359. lcd.setCursor(0, 2);
  3360. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  3361. delay(2000);
  3362. lcd_implementation_clear();
  3363. }
  3364. lcd_return_to_status();
  3365. }
  3366. void lcd_extr_cal_reset() {
  3367. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3368. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3369. //extrudemultiply = 100;
  3370. enquecommand_P(PSTR("M500"));
  3371. }*/
  3372. #endif
  3373. void lcd_toshiba_flash_air_compatibility_toggle()
  3374. {
  3375. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3376. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3377. }
  3378. void lcd_v2_calibration() {
  3379. 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
  3380. if (loaded) {
  3381. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3382. }
  3383. else {
  3384. lcd_display_message_fullscreen_P(_i("Please load PLA filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3385. for (int i = 0; i < 20; i++) { //wait max. 2s
  3386. delay_keep_alive(100);
  3387. if (lcd_clicked()) {
  3388. while (lcd_clicked());
  3389. delay(10);
  3390. while (lcd_clicked());
  3391. break;
  3392. }
  3393. }
  3394. }
  3395. lcd_return_to_status();
  3396. lcd_update_enable(true);
  3397. }
  3398. void lcd_wizard() {
  3399. bool result = true;
  3400. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3401. 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
  3402. }
  3403. if (result) {
  3404. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3405. lcd_wizard(0);
  3406. }
  3407. else {
  3408. lcd_return_to_status();
  3409. lcd_update_enable(true);
  3410. lcd_update(2);
  3411. }
  3412. }
  3413. void lcd_wizard(int state) {
  3414. bool end = false;
  3415. int wizard_event;
  3416. const char *msg = NULL;
  3417. while (!end) {
  3418. switch (state) {
  3419. case 0: // run wizard?
  3420. 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
  3421. if (wizard_event) {
  3422. state = 1;
  3423. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3424. }
  3425. else {
  3426. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3427. end = true;
  3428. }
  3429. break;
  3430. case 1: // restore calibration status
  3431. switch (calibration_status()) {
  3432. case CALIBRATION_STATUS_ASSEMBLED: state = 2; break; //run selftest
  3433. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = 3; break; //run xyz cal.
  3434. case CALIBRATION_STATUS_Z_CALIBRATION: state = 4; break; //run z cal.
  3435. case CALIBRATION_STATUS_LIVE_ADJUST: state = 5; break; //run live adjust
  3436. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3437. default: state = 2; break; //if calibration status is unknown, run wizard from the beginning
  3438. }
  3439. break;
  3440. case 2: //selftest
  3441. 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
  3442. wizard_event = lcd_selftest();
  3443. if (wizard_event) {
  3444. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3445. state = 3;
  3446. }
  3447. else end = true;
  3448. break;
  3449. case 3: //xyz cal.
  3450. 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
  3451. wizard_event = gcode_M45(false, 0);
  3452. if (wizard_event) state = 5;
  3453. else end = true;
  3454. break;
  3455. case 4: //z cal.
  3456. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3457. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  3458. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3459. wizard_event = gcode_M45(true, 0);
  3460. if (wizard_event) state = 11; //shipped, no need to set first layer, go to final message directly
  3461. else end = true;
  3462. break;
  3463. case 5: //is filament loaded?
  3464. //start to preheat nozzle and bed to save some time later
  3465. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3466. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3467. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament loaded?"), false);////MSG_WIZARD_FILAMENT_LOADED c=20 r=2
  3468. if (wizard_event) state = 8;
  3469. else state = 6;
  3470. break;
  3471. case 6: //waiting for preheat nozzle for PLA;
  3472. #ifndef SNMM
  3473. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3474. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3475. 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);
  3476. delay_keep_alive(2000);
  3477. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3478. while (abs(degHotend(0) - PLA_PREHEAT_HOTEND_TEMP) > 3) {
  3479. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3480. lcd.setCursor(0, 4);
  3481. lcd.print(LCD_STR_THERMOMETER[0]);
  3482. lcd.print(ftostr3(degHotend(0)));
  3483. lcd.print("/");
  3484. lcd.print(PLA_PREHEAT_HOTEND_TEMP);
  3485. lcd.print(LCD_STR_DEGREE);
  3486. lcd_set_custom_characters();
  3487. delay_keep_alive(1000);
  3488. }
  3489. #endif //not SNMM
  3490. state = 7;
  3491. break;
  3492. case 7: //load filament
  3493. #ifdef PAT9125
  3494. fsensor_block();
  3495. #endif //PAT9125
  3496. 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
  3497. lcd_update_enable(false);
  3498. lcd_implementation_clear();
  3499. lcd_print_at_PGM(0, 2, _T(MSG_LOADING_FILAMENT));
  3500. #ifdef SNMM
  3501. change_extr(0);
  3502. #endif
  3503. gcode_M701();
  3504. #ifdef PAT9125
  3505. fsensor_unblock();
  3506. #endif //PAT9125
  3507. state = 9;
  3508. break;
  3509. case 8:
  3510. 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
  3511. if (wizard_event) state = 9;
  3512. else end = true;
  3513. break;
  3514. case 9:
  3515. 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
  3516. 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
  3517. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3518. end = true;
  3519. break;
  3520. case 10: //repeat first layer cal.?
  3521. 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
  3522. if (wizard_event) {
  3523. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3524. state = 9;
  3525. }
  3526. else {
  3527. state = 11;
  3528. }
  3529. break;
  3530. case 11: //we are finished
  3531. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3532. end = true;
  3533. break;
  3534. default: break;
  3535. }
  3536. }
  3537. SERIAL_ECHOPGM("State: ");
  3538. MYSERIAL.println(state);
  3539. switch (state) { //final message
  3540. case 0: //user dont want to use wizard
  3541. msg = _T(MSG_WIZARD_QUIT);
  3542. break;
  3543. case 1: //printer was already calibrated
  3544. msg = _T(MSG_WIZARD_DONE);
  3545. break;
  3546. case 2: //selftest
  3547. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3548. break;
  3549. case 3: //xyz cal.
  3550. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3551. break;
  3552. case 4: //z cal.
  3553. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3554. break;
  3555. case 8:
  3556. msg = _i("Please load PLA filament and then resume Wizard by rebooting the printer.");////MSG_WIZARD_INSERT_CORRECT_FILAMENT c=20 r=8
  3557. break;
  3558. case 9: break; //exit wizard for v2 calibration, which is implemted in lcd_commands (we need lcd_update running)
  3559. case 11: //we are finished
  3560. msg = _T(MSG_WIZARD_DONE);
  3561. lcd_reset_alert_level();
  3562. lcd_setstatuspgm(_T(WELCOME_MSG));
  3563. break;
  3564. default:
  3565. msg = _T(MSG_WIZARD_QUIT);
  3566. break;
  3567. }
  3568. if (state != 9) lcd_show_fullscreen_message_and_wait_P(msg);
  3569. lcd_update_enable(true);
  3570. lcd_return_to_status();
  3571. lcd_update(2);
  3572. }
  3573. static void lcd_settings_menu()
  3574. {
  3575. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  3576. START_MENU();
  3577. MENU_ITEM(back, _T(MSG_MAIN), lcd_settings_menu_back);
  3578. MENU_ITEM(submenu, _i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=0 r=0
  3579. if (!homing_flag)
  3580. {
  3581. MENU_ITEM(submenu, _i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=0 r=0
  3582. }
  3583. if (!isPrintPaused)
  3584. {
  3585. MENU_ITEM(gcode, _i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=0 r=0
  3586. }
  3587. #ifndef TMC2130
  3588. if (!farm_mode) { //dont show in menu if we are in farm mode
  3589. switch (SilentModeMenu) {
  3590. case SILENT_MODE_POWER: MENU_ITEM(function, _T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  3591. case SILENT_MODE_SILENT: MENU_ITEM(function, _T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  3592. case SILENT_MODE_AUTO: MENU_ITEM(function, _T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  3593. default: MENU_ITEM(function, _T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  3594. }
  3595. }
  3596. #endif //TMC2130
  3597. #ifdef PAT9125
  3598. #ifndef DEBUG_DISABLE_FSENSORCHECK
  3599. if (FSensorStateMenu == 0) {
  3600. if (fsensor_not_responding){
  3601. // Filament sensor not working
  3602. MENU_ITEM(function, _i("Fil. sensor [N/A]"), lcd_fsensor_state_set);////MSG_FSENSOR_NA c=0 r=0
  3603. MENU_ITEM(submenu, _T(MSG_FSENS_AUTOLOAD_NA), lcd_fsensor_fail);
  3604. }
  3605. else{
  3606. // Filament sensor turned off, working, no problems
  3607. MENU_ITEM(function, _T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  3608. MENU_ITEM(submenu,_T(MSG_FSENS_AUTOLOAD_NA), lcd_filament_autoload_info);
  3609. }
  3610. } else {
  3611. // Filament sensor turned on, working, no problems
  3612. MENU_ITEM(function, _T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  3613. if (filament_autoload_enabled) {
  3614. MENU_ITEM(function, _i("F. autoload [on]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_ON c=17 r=1
  3615. }
  3616. else {
  3617. MENU_ITEM(function, _i("F. autoload [off]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_OFF c=17 r=1
  3618. }
  3619. }
  3620. #endif //DEBUG_DISABLE_FSENSORCHECK
  3621. #endif //PAT9125
  3622. if (fans_check_enabled == true) {
  3623. MENU_ITEM(function, _i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1
  3624. }
  3625. else {
  3626. MENU_ITEM(function, _i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1
  3627. }
  3628. #ifdef TMC2130
  3629. if(!farm_mode)
  3630. {
  3631. //*** MaR::180416_01a
  3632. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM(function, _T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);
  3633. else MENU_ITEM(function, _T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  3634. if (SilentModeMenu == SILENT_MODE_NORMAL)
  3635. {
  3636. if (CrashDetectMenu == 0) MENU_ITEM(function, _T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);
  3637. else MENU_ITEM(function, _T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  3638. }
  3639. else MENU_ITEM(submenu, _T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  3640. }
  3641. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3642. 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
  3643. 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
  3644. 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
  3645. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3646. 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
  3647. #endif //TMC2130
  3648. if (temp_cal_active == false) {
  3649. MENU_ITEM(function, _i("Temp. cal. [off]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_OFF c=20 r=1
  3650. }
  3651. else {
  3652. MENU_ITEM(function, _i("Temp. cal. [on]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_ON c=20 r=1
  3653. }
  3654. #ifdef HAS_SECOND_SERIAL_PORT
  3655. if (selectedSerialPort == 0) {
  3656. MENU_ITEM(function, _i("RPi port [off]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_OFF c=17 r=1
  3657. }
  3658. else {
  3659. MENU_ITEM(function, _i("RPi port [on]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_ON c=17 r=1
  3660. }
  3661. #endif //HAS_SECOND_SERIAL
  3662. if (!isPrintPaused && !homing_flag)
  3663. {
  3664. MENU_ITEM(submenu, _T(MSG_BABYSTEP_Z), lcd_babystep_z);
  3665. }
  3666. #if (LANG_MODE != 0)
  3667. MENU_ITEM(submenu, _i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=0 r=0
  3668. #endif //(LANG_MODE != 0)
  3669. if (card.ToshibaFlashAir_isEnabled()) {
  3670. MENU_ITEM(function, _i("SD card [FlshAir]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1
  3671. } else {
  3672. MENU_ITEM(function, _i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1
  3673. }
  3674. #ifdef SDCARD_SORT_ALPHA
  3675. if (!farm_mode) {
  3676. uint8_t sdSort;
  3677. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3678. switch (sdSort) {
  3679. case SD_SORT_TIME: MENU_ITEM(function, _i("Sort: [Time]"), lcd_sort_type_set); break;////MSG_SORT_TIME c=17 r=1
  3680. case SD_SORT_ALPHA: MENU_ITEM(function, _i("Sort: [Alphabet]"), lcd_sort_type_set); break;////MSG_SORT_ALPHA c=17 r=1
  3681. default: MENU_ITEM(function, _i("Sort: [None]"), lcd_sort_type_set);////MSG_SORT_NONE c=17 r=1
  3682. }
  3683. }
  3684. #endif // SDCARD_SORT_ALPHA
  3685. if (farm_mode)
  3686. {
  3687. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  3688. MENU_ITEM(function, PSTR("Disable farm mode"), lcd_disable_farm_mode);
  3689. }
  3690. END_MENU();
  3691. }
  3692. static void lcd_selftest_()
  3693. {
  3694. lcd_selftest();
  3695. }
  3696. #ifdef TMC2130
  3697. static void lcd_ustep_linearity_menu_save()
  3698. {
  3699. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  3700. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  3701. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  3702. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  3703. }
  3704. #endif //TMC2130
  3705. static void lcd_settings_menu_back()
  3706. {
  3707. #ifdef TMC2130
  3708. bool changed = false;
  3709. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  3710. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  3711. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  3712. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  3713. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  3714. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  3715. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  3716. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  3717. lcd_ustep_linearity_menu_save();
  3718. if (changed) tmc2130_init();
  3719. #endif //TMC2130
  3720. currentMenu = lcd_main_menu;
  3721. lcd_main_menu();
  3722. }
  3723. #ifdef EXPERIMENTAL_FEATURES
  3724. static void lcd_experimantal_menu();
  3725. static void lcd_homing_accuracy_menu();
  3726. static void lcd_accurate_home_set()
  3727. {
  3728. tmc2130_home_enabled = tmc2130_home_enabled?0:1;
  3729. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, tmc2130_home_enabled);
  3730. }
  3731. static void lcd_homing_accuracy_menu_advanced_reset()
  3732. {
  3733. tmc2130_home_bsteps[X_AXIS] = 48;
  3734. tmc2130_home_fsteps[X_AXIS] = 48;
  3735. tmc2130_home_bsteps[Y_AXIS] = 48;
  3736. tmc2130_home_fsteps[Y_AXIS] = 48;
  3737. }
  3738. static void lcd_homing_accuracy_menu_advanced_save()
  3739. {
  3740. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_ORIGIN, tmc2130_home_origin[X_AXIS]);
  3741. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_BSTEPS, tmc2130_home_bsteps[X_AXIS]);
  3742. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_FSTEPS, tmc2130_home_fsteps[X_AXIS]);
  3743. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_ORIGIN, tmc2130_home_origin[Y_AXIS]);
  3744. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_BSTEPS, tmc2130_home_bsteps[Y_AXIS]);
  3745. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_FSTEPS, tmc2130_home_fsteps[Y_AXIS]);
  3746. }
  3747. static void lcd_homing_accuracy_menu_advanced_back()
  3748. {
  3749. lcd_homing_accuracy_menu_advanced_save();
  3750. currentMenu = lcd_homing_accuracy_menu;
  3751. lcd_homing_accuracy_menu();
  3752. }
  3753. static void lcd_homing_accuracy_menu_advanced()
  3754. {
  3755. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3756. START_MENU();
  3757. MENU_ITEM(back, PSTR("Homing accuracy"), lcd_homing_accuracy_menu_advanced_back);
  3758. MENU_ITEM(function, PSTR("Reset def. steps"), lcd_homing_accuracy_menu_advanced_reset);
  3759. MENU_ITEM_EDIT(byte3, PSTR("X-origin"), &tmc2130_home_origin[X_AXIS], 0, 63);
  3760. MENU_ITEM_EDIT(byte3, PSTR("Y-origin"), &tmc2130_home_origin[Y_AXIS], 0, 63);
  3761. MENU_ITEM_EDIT(byte3, PSTR("X-bsteps"), &tmc2130_home_bsteps[X_AXIS], 0, 128);
  3762. MENU_ITEM_EDIT(byte3, PSTR("Y-bsteps"), &tmc2130_home_bsteps[Y_AXIS], 0, 128);
  3763. MENU_ITEM_EDIT(byte3, PSTR("X-fsteps"), &tmc2130_home_fsteps[X_AXIS], 0, 128);
  3764. MENU_ITEM_EDIT(byte3, PSTR("Y-fsteps"), &tmc2130_home_fsteps[Y_AXIS], 0, 128);
  3765. END_MENU();
  3766. }
  3767. static void lcd_homing_accuracy_menu()
  3768. {
  3769. START_MENU();
  3770. MENU_ITEM(back, PSTR("Experimental"), 0);
  3771. MENU_ITEM(function, tmc2130_home_enabled?PSTR("Accur. homing On"):PSTR("Accur. homing Off"), lcd_accurate_home_set);
  3772. MENU_ITEM(gcode, PSTR("Calibrate X"), PSTR("G28XC"));
  3773. MENU_ITEM(gcode, PSTR("Calibrate Y"), PSTR("G28YC"));
  3774. MENU_ITEM(submenu, PSTR("Advanced"), lcd_homing_accuracy_menu_advanced);
  3775. END_MENU();
  3776. }
  3777. static void lcd_ustep_resolution_menu_save()
  3778. {
  3779. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_X_MRES, tmc2130_mres[X_AXIS]);
  3780. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Y_MRES, tmc2130_mres[Y_AXIS]);
  3781. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Z_MRES, tmc2130_mres[Z_AXIS]);
  3782. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_E_MRES, tmc2130_mres[E_AXIS]);
  3783. }
  3784. static void lcd_ustep_resolution_menu_back()
  3785. {
  3786. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  3787. bool changed = false;
  3788. if (tmc2130_mres[X_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_X_MRES))
  3789. {
  3790. axis_steps_per_unit[X_AXIS] = tmp1[X_AXIS] * tmc2130_mres2usteps(tmc2130_mres[X_AXIS]) / TMC2130_USTEPS_XY;
  3791. changed = true;
  3792. }
  3793. if (tmc2130_mres[Y_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Y_MRES))
  3794. {
  3795. axis_steps_per_unit[Y_AXIS] = tmp1[Y_AXIS] * tmc2130_mres2usteps(tmc2130_mres[Y_AXIS]) / TMC2130_USTEPS_XY;
  3796. changed = true;
  3797. }
  3798. if (tmc2130_mres[Z_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Z_MRES))
  3799. {
  3800. axis_steps_per_unit[Z_AXIS] = tmp1[Z_AXIS] * tmc2130_mres2usteps(tmc2130_mres[Z_AXIS]) / TMC2130_USTEPS_Z;
  3801. changed = true;
  3802. }
  3803. if (tmc2130_mres[E_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_E_MRES))
  3804. {
  3805. axis_steps_per_unit[E_AXIS] = tmp1[E_AXIS] * tmc2130_mres2usteps(tmc2130_mres[E_AXIS]) / TMC2130_USTEPS_E;
  3806. changed = true;
  3807. }
  3808. if (changed)
  3809. {
  3810. lcd_ustep_resolution_menu_save();
  3811. Config_StoreSettings(EEPROM_OFFSET);
  3812. tmc2130_init();
  3813. }
  3814. currentMenu = lcd_experimantal_menu;
  3815. lcd_experimantal_menu();
  3816. }
  3817. static void lcd_ustep_resolution_reset_def_xyze()
  3818. {
  3819. tmc2130_mres[X_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY);
  3820. tmc2130_mres[Y_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY);
  3821. tmc2130_mres[Z_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_Z);
  3822. tmc2130_mres[E_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_E);
  3823. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  3824. axis_steps_per_unit[X_AXIS] = tmp1[X_AXIS];
  3825. axis_steps_per_unit[Y_AXIS] = tmp1[Y_AXIS];
  3826. axis_steps_per_unit[Z_AXIS] = tmp1[Z_AXIS];
  3827. axis_steps_per_unit[E_AXIS] = tmp1[E_AXIS];
  3828. }
  3829. static void lcd_ustep_resolution_menu()
  3830. {
  3831. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3832. START_MENU();
  3833. MENU_ITEM(back, PSTR("Experimental"), lcd_ustep_resolution_menu_back);
  3834. MENU_ITEM(function, PSTR("Reset defaults"), lcd_ustep_resolution_reset_def_xyze);
  3835. MENU_ITEM_EDIT(mres, PSTR("X-resolution"), &tmc2130_mres[X_AXIS], 4, 4);
  3836. MENU_ITEM_EDIT(mres, PSTR("Y-resolution"), &tmc2130_mres[Y_AXIS], 4, 4);
  3837. MENU_ITEM_EDIT(mres, PSTR("Z-resolution"), &tmc2130_mres[Z_AXIS], 4, 4);
  3838. MENU_ITEM_EDIT(mres, PSTR("E-resolution"), &tmc2130_mres[E_AXIS], 2, 5);
  3839. END_MENU();
  3840. }
  3841. static void lcd_ustep_linearity_menu_back()
  3842. {
  3843. bool changed = false;
  3844. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  3845. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  3846. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  3847. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  3848. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  3849. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  3850. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  3851. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  3852. lcd_ustep_linearity_menu_save();
  3853. if (changed) tmc2130_init();
  3854. currentMenu = lcd_experimantal_menu;
  3855. lcd_experimantal_menu();
  3856. }
  3857. static void lcd_ustep_linearity_menu_recomended()
  3858. {
  3859. tmc2130_wave_fac[X_AXIS] = 220;
  3860. tmc2130_wave_fac[Y_AXIS] = 220;
  3861. tmc2130_wave_fac[Z_AXIS] = 220;
  3862. tmc2130_wave_fac[E_AXIS] = 220;
  3863. }
  3864. static void lcd_ustep_linearity_menu_reset()
  3865. {
  3866. tmc2130_wave_fac[X_AXIS] = 0;
  3867. tmc2130_wave_fac[Y_AXIS] = 0;
  3868. tmc2130_wave_fac[Z_AXIS] = 0;
  3869. tmc2130_wave_fac[E_AXIS] = 0;
  3870. }
  3871. static void lcd_ustep_linearity_menu()
  3872. {
  3873. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3874. START_MENU();
  3875. MENU_ITEM(back, PSTR("Experimental"), lcd_ustep_linearity_menu_back);
  3876. MENU_ITEM(function, PSTR("Reset correction"), lcd_ustep_linearity_menu_reset);
  3877. MENU_ITEM(function, PSTR("Recomended config"), lcd_ustep_linearity_menu_recomended);
  3878. MENU_ITEM_EDIT(wfac, PSTR("X-correction"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  3879. MENU_ITEM_EDIT(wfac, PSTR("Y-correction"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  3880. MENU_ITEM_EDIT(wfac, PSTR("Z-correction"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  3881. MENU_ITEM_EDIT(wfac, PSTR("E-correction"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  3882. END_MENU();
  3883. }
  3884. static void lcd_experimantal_menu_save_all()
  3885. {
  3886. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, tmc2130_home_enabled);
  3887. lcd_ustep_resolution_menu_save();
  3888. lcd_ustep_linearity_menu_save();
  3889. Config_StoreSettings(EEPROM_OFFSET);
  3890. }
  3891. static void lcd_experimantal_menu_disable_all()
  3892. {
  3893. tmc2130_home_enabled = 0;
  3894. lcd_ustep_resolution_reset_def_xyze();
  3895. lcd_ustep_linearity_menu_reset();
  3896. lcd_experimantal_menu_save_all();
  3897. tmc2130_init();
  3898. }
  3899. static void lcd_experimantal_menu()
  3900. {
  3901. START_MENU();
  3902. MENU_ITEM(back, _T(MSG_MAIN), 0);
  3903. MENU_ITEM(function, PSTR("All Xfeatures off"), lcd_experimantal_menu_disable_all);
  3904. MENU_ITEM(submenu, PSTR("Homing accuracy"), lcd_homing_accuracy_menu);
  3905. MENU_ITEM(submenu, PSTR("uStep resolution"), lcd_ustep_resolution_menu);
  3906. MENU_ITEM(submenu, PSTR("uStep linearity"), lcd_ustep_linearity_menu);
  3907. END_MENU();
  3908. }
  3909. #endif //EXPERIMENTAL_FEATURES
  3910. static void lcd_calibration_menu()
  3911. {
  3912. START_MENU();
  3913. MENU_ITEM(back, _T(MSG_MAIN), 0);
  3914. if (!isPrintPaused)
  3915. {
  3916. MENU_ITEM(function, _i("Wizard"), lcd_wizard);////MSG_WIZARD c=17 r=1
  3917. MENU_ITEM(submenu, _i("First layer cal."), lcd_v2_calibration);////MSG_V2_CALIBRATION c=17 r=1
  3918. MENU_ITEM(gcode, _T(MSG_AUTO_HOME), PSTR("G28 W"));
  3919. MENU_ITEM(function, _i("Selftest "), lcd_selftest_v);////MSG_SELFTEST c=0 r=0
  3920. #ifdef MK1BP
  3921. // MK1
  3922. // "Calibrate Z"
  3923. MENU_ITEM(gcode, _T(MSG_HOMEYZ), PSTR("G28 Z"));
  3924. #else //MK1BP
  3925. // MK2
  3926. MENU_ITEM(function, _i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=0 r=0
  3927. // "Calibrate Z" with storing the reference values to EEPROM.
  3928. MENU_ITEM(submenu, _T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  3929. #ifndef SNMM
  3930. //MENU_ITEM(function, _i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20 r=1
  3931. #endif
  3932. // "Mesh Bed Leveling"
  3933. MENU_ITEM(submenu, _i("Mesh Bed Leveling"), lcd_mesh_bedleveling);////MSG_MESH_BED_LEVELING c=0 r=0
  3934. #endif //MK1BP
  3935. MENU_ITEM(submenu, _i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=0 r=0
  3936. MENU_ITEM(submenu, _i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17 r=1
  3937. #ifndef TMC2130
  3938. MENU_ITEM(submenu, _i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=17 r=1
  3939. #endif
  3940. #ifndef MK1BP
  3941. MENU_ITEM(gcode, _i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=0 r=0
  3942. #endif //MK1BP
  3943. #ifndef SNMM
  3944. //MENU_ITEM(function, MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  3945. #endif
  3946. #ifndef MK1BP
  3947. MENU_ITEM(submenu, _i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17 r=1
  3948. #endif //MK1BP
  3949. }
  3950. END_MENU();
  3951. }
  3952. /*
  3953. void lcd_mylang_top(int hlaska) {
  3954. lcd.setCursor(0,0);
  3955. lcd.print(" ");
  3956. lcd.setCursor(0,0);
  3957. lcd_printPGM(_T(MSG_ALL)[hlaska-1][LANGUAGE_SELECT]);
  3958. }
  3959. void lcd_mylang_drawmenu(int cursor) {
  3960. int first = 0;
  3961. if (cursor>2) first = cursor-2;
  3962. if (cursor==LANG_NUM) first = LANG_NUM-3;
  3963. lcd.setCursor(0, 1);
  3964. lcd.print(" ");
  3965. lcd.setCursor(1, 1);
  3966. lcd_printPGM(_T(MSG_ALL)[first][LANGUAGE_NAME]);
  3967. lcd.setCursor(0, 2);
  3968. lcd.print(" ");
  3969. lcd.setCursor(1, 2);
  3970. lcd_printPGM(_T(MSG_ALL)[first+1][LANGUAGE_NAME]);
  3971. lcd.setCursor(0, 3);
  3972. lcd.print(" ");
  3973. lcd.setCursor(1, 3);
  3974. lcd_printPGM(_T(MSG_ALL)[first+2][LANGUAGE_NAME]);
  3975. if (cursor==1) lcd.setCursor(0, 1);
  3976. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  3977. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  3978. lcd.print(">");
  3979. if (cursor<LANG_NUM-1) {
  3980. lcd.setCursor(19,3);
  3981. lcd.print("\x01");
  3982. }
  3983. if (cursor>2) {
  3984. lcd.setCursor(19,1);
  3985. lcd.print("^");
  3986. }
  3987. }
  3988. */
  3989. /*
  3990. void lcd_mylang_drawmenu(int cursor)
  3991. {
  3992. unsigned char lang_cnt = lang_get_count();
  3993. int first = 0;
  3994. if (cursor>3) first = cursor-3;
  3995. if (cursor==lang_cnt && lang_cnt>4) first = lang_cnt-4;
  3996. if (cursor==lang_cnt && lang_cnt==4) first = lang_cnt-4;
  3997. lcd.setCursor(0, 0);
  3998. lcd.print(" ");
  3999. lcd.setCursor(1, 0);
  4000. lcd_printPGM(lang_get_name(first+0));
  4001. lcd.setCursor(0, 1);
  4002. lcd.print(" ");
  4003. lcd.setCursor(1, 1);
  4004. lcd_printPGM(lang_get_name(first+1));
  4005. lcd.setCursor(0, 2);
  4006. lcd.print(" ");
  4007. if (lang_cnt > 2){
  4008. lcd.setCursor(1, 2);
  4009. lcd_printPGM(lang_get_name(first+2));
  4010. }
  4011. lcd.setCursor(0, 3);
  4012. lcd.print(" ");
  4013. if (lang_cnt>3) {
  4014. lcd.setCursor(1, 3);
  4015. lcd_printPGM(lang_get_name(first+3));
  4016. }
  4017. if (cursor==1) lcd.setCursor(0, 0);
  4018. if (cursor==2) lcd.setCursor(0, 1);
  4019. if (cursor>2) lcd.setCursor(0, 2);
  4020. if (cursor==lang_cnt && lang_cnt>3) lcd.setCursor(0, 3);
  4021. lcd.print(">");
  4022. if (cursor<lang_cnt-1 && lang_cnt>4) {
  4023. lcd.setCursor(19,3);
  4024. lcd.print("\x01");
  4025. }
  4026. if (cursor>3 && lang_cnt>4) {
  4027. lcd.setCursor(19,0);
  4028. lcd.print("^");
  4029. }
  4030. }
  4031. */
  4032. /*
  4033. void lcd_mylang_drawcursor(int cursor) {
  4034. unsigned char lang_cnt = lang_get_count();
  4035. if (cursor==1) lcd.setCursor(0, 1);
  4036. if (cursor>1 && cursor<lang_cnt) lcd.setCursor(0, 2);
  4037. if (cursor==lang_cnt) lcd.setCursor(0, 3);
  4038. lcd.print(">");
  4039. }
  4040. */
  4041. /*
  4042. void lcd_mylang()
  4043. {
  4044. int enc_dif = 0;
  4045. int cursor_pos = 1;
  4046. lang_selected=255;
  4047. int hlaska=1;
  4048. int counter=0;
  4049. unsigned char lang_cnt = lang_get_count();
  4050. lcd_set_custom_characters_arrows();
  4051. lcd_implementation_clear();
  4052. //lcd_mylang_top(hlaska);
  4053. lcd_mylang_drawmenu(cursor_pos);
  4054. enc_dif = encoderDiff;
  4055. while ( (lang_selected == 255) ) {
  4056. manage_heater();
  4057. manage_inactivity(true);
  4058. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  4059. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  4060. if (enc_dif > encoderDiff ) {
  4061. cursor_pos --;
  4062. }
  4063. if (enc_dif < encoderDiff ) {
  4064. cursor_pos ++;
  4065. }
  4066. if (cursor_pos > lang_cnt) {
  4067. cursor_pos = lang_cnt;
  4068. }
  4069. if (cursor_pos < 1) {
  4070. cursor_pos = 1;
  4071. }
  4072. lcd_mylang_drawmenu(cursor_pos);
  4073. enc_dif = encoderDiff;
  4074. delay(100);
  4075. //}
  4076. } else delay(20);
  4077. if (lcd_clicked()) {
  4078. lcd_set_lang(cursor_pos-1);
  4079. delay(500);
  4080. }
  4081. // if (++counter == 80) {
  4082. // hlaska++;
  4083. // if(hlaska>LANG_NUM) hlaska=1;
  4084. // lcd_mylang_top(hlaska);
  4085. // lcd_mylang_drawcursor(cursor_pos);
  4086. // counter=0;
  4087. // }
  4088. };
  4089. if(MYSERIAL.available() > 1){
  4090. lang_selected = 0;
  4091. firstrun = 0;
  4092. }
  4093. lcd_set_custom_characters_degree();
  4094. lcd_implementation_clear();
  4095. lcd_return_to_status();
  4096. }
  4097. */
  4098. void bowden_menu() {
  4099. int enc_dif = encoderDiff;
  4100. int cursor_pos = 0;
  4101. lcd_implementation_clear();
  4102. lcd.setCursor(0, 0);
  4103. lcd.print(">");
  4104. for (int i = 0; i < 4; i++) {
  4105. lcd.setCursor(1, i);
  4106. lcd.print("Extruder ");
  4107. lcd.print(i);
  4108. lcd.print(": ");
  4109. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4110. lcd.print(bowden_length[i] - 48);
  4111. }
  4112. enc_dif = encoderDiff;
  4113. while (1) {
  4114. manage_heater();
  4115. manage_inactivity(true);
  4116. if (abs((enc_dif - encoderDiff)) > 2) {
  4117. if (enc_dif > encoderDiff) {
  4118. cursor_pos--;
  4119. }
  4120. if (enc_dif < encoderDiff) {
  4121. cursor_pos++;
  4122. }
  4123. if (cursor_pos > 3) {
  4124. cursor_pos = 3;
  4125. }
  4126. if (cursor_pos < 0) {
  4127. cursor_pos = 0;
  4128. }
  4129. lcd.setCursor(0, 0);
  4130. lcd.print(" ");
  4131. lcd.setCursor(0, 1);
  4132. lcd.print(" ");
  4133. lcd.setCursor(0, 2);
  4134. lcd.print(" ");
  4135. lcd.setCursor(0, 3);
  4136. lcd.print(" ");
  4137. lcd.setCursor(0, cursor_pos);
  4138. lcd.print(">");
  4139. enc_dif = encoderDiff;
  4140. delay(100);
  4141. }
  4142. if (lcd_clicked()) {
  4143. while (lcd_clicked());
  4144. delay(10);
  4145. while (lcd_clicked());
  4146. lcd_implementation_clear();
  4147. while (1) {
  4148. manage_heater();
  4149. manage_inactivity(true);
  4150. lcd.setCursor(1, 1);
  4151. lcd.print("Extruder ");
  4152. lcd.print(cursor_pos);
  4153. lcd.print(": ");
  4154. lcd.setCursor(13, 1);
  4155. lcd.print(bowden_length[cursor_pos] - 48);
  4156. if (abs((enc_dif - encoderDiff)) > 2) {
  4157. if (enc_dif > encoderDiff) {
  4158. bowden_length[cursor_pos]--;
  4159. lcd.setCursor(13, 1);
  4160. lcd.print(bowden_length[cursor_pos] - 48);
  4161. enc_dif = encoderDiff;
  4162. }
  4163. if (enc_dif < encoderDiff) {
  4164. bowden_length[cursor_pos]++;
  4165. lcd.setCursor(13, 1);
  4166. lcd.print(bowden_length[cursor_pos] - 48);
  4167. enc_dif = encoderDiff;
  4168. }
  4169. }
  4170. delay(100);
  4171. if (lcd_clicked()) {
  4172. while (lcd_clicked());
  4173. delay(10);
  4174. while (lcd_clicked());
  4175. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  4176. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  4177. lcd_update_enable(true);
  4178. lcd_implementation_clear();
  4179. enc_dif = encoderDiff;
  4180. lcd.setCursor(0, cursor_pos);
  4181. lcd.print(">");
  4182. for (int i = 0; i < 4; i++) {
  4183. lcd.setCursor(1, i);
  4184. lcd.print("Extruder ");
  4185. lcd.print(i);
  4186. lcd.print(": ");
  4187. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4188. lcd.print(bowden_length[i] - 48);
  4189. }
  4190. break;
  4191. }
  4192. else return;
  4193. }
  4194. }
  4195. }
  4196. }
  4197. }
  4198. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  4199. lcd_implementation_clear();
  4200. lcd_print_at_PGM(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd.print(":");
  4201. lcd.setCursor(0, 1); lcd.print(">");
  4202. lcd_print_at_PGM(1,1,_T(MSG_ALL));
  4203. lcd_print_at_PGM(1,2,_i("Used during print"));////MSG_USED c=19 r=1
  4204. lcd_print_at_PGM(1,3,_i("Current"));////MSG_CURRENT c=19 r=1
  4205. char cursor_pos = 1;
  4206. int enc_dif = 0;
  4207. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4208. while (1) {
  4209. manage_heater();
  4210. manage_inactivity(true);
  4211. if (abs((enc_dif - encoderDiff)) > 4) {
  4212. if ((abs(enc_dif - encoderDiff)) > 1) {
  4213. if (enc_dif > encoderDiff) cursor_pos--;
  4214. if (enc_dif < encoderDiff) cursor_pos++;
  4215. if (cursor_pos > 3) cursor_pos = 3;
  4216. if (cursor_pos < 1) cursor_pos = 1;
  4217. lcd.setCursor(0, 1);
  4218. lcd.print(" ");
  4219. lcd.setCursor(0, 2);
  4220. lcd.print(" ");
  4221. lcd.setCursor(0, 3);
  4222. lcd.print(" ");
  4223. lcd.setCursor(0, cursor_pos);
  4224. lcd.print(">");
  4225. enc_dif = encoderDiff;
  4226. delay(100);
  4227. }
  4228. }
  4229. if (lcd_clicked()) {
  4230. while (lcd_clicked());
  4231. delay(10);
  4232. while (lcd_clicked());
  4233. KEEPALIVE_STATE(IN_HANDLER);
  4234. return(cursor_pos - 1);
  4235. }
  4236. }
  4237. }
  4238. char choose_extruder_menu() {
  4239. int items_no = 4;
  4240. int first = 0;
  4241. int enc_dif = 0;
  4242. char cursor_pos = 1;
  4243. enc_dif = encoderDiff;
  4244. lcd_implementation_clear();
  4245. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4246. lcd.setCursor(0, 1);
  4247. lcd.print(">");
  4248. for (int i = 0; i < 3; i++) {
  4249. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4250. }
  4251. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4252. while (1) {
  4253. for (int i = 0; i < 3; i++) {
  4254. lcd.setCursor(2 + strlen_P(_T(MSG_EXTRUDER)), i+1);
  4255. lcd.print(first + i + 1);
  4256. }
  4257. manage_heater();
  4258. manage_inactivity(true);
  4259. if (abs((enc_dif - encoderDiff)) > 4) {
  4260. if ((abs(enc_dif - encoderDiff)) > 1) {
  4261. if (enc_dif > encoderDiff) {
  4262. cursor_pos--;
  4263. }
  4264. if (enc_dif < encoderDiff) {
  4265. cursor_pos++;
  4266. }
  4267. if (cursor_pos > 3) {
  4268. cursor_pos = 3;
  4269. if (first < items_no - 3) {
  4270. first++;
  4271. lcd_implementation_clear();
  4272. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4273. for (int i = 0; i < 3; i++) {
  4274. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4275. }
  4276. }
  4277. }
  4278. if (cursor_pos < 1) {
  4279. cursor_pos = 1;
  4280. if (first > 0) {
  4281. first--;
  4282. lcd_implementation_clear();
  4283. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4284. for (int i = 0; i < 3; i++) {
  4285. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4286. }
  4287. }
  4288. }
  4289. lcd.setCursor(0, 1);
  4290. lcd.print(" ");
  4291. lcd.setCursor(0, 2);
  4292. lcd.print(" ");
  4293. lcd.setCursor(0, 3);
  4294. lcd.print(" ");
  4295. lcd.setCursor(0, cursor_pos);
  4296. lcd.print(">");
  4297. enc_dif = encoderDiff;
  4298. delay(100);
  4299. }
  4300. }
  4301. if (lcd_clicked()) {
  4302. lcd_update(2);
  4303. while (lcd_clicked());
  4304. delay(10);
  4305. while (lcd_clicked());
  4306. KEEPALIVE_STATE(IN_HANDLER);
  4307. return(cursor_pos + first - 1);
  4308. }
  4309. }
  4310. }
  4311. char reset_menu() {
  4312. #ifdef SNMM
  4313. int items_no = 5;
  4314. #else
  4315. int items_no = 4;
  4316. #endif
  4317. static int first = 0;
  4318. int enc_dif = 0;
  4319. char cursor_pos = 0;
  4320. const char *item [items_no];
  4321. item[0] = "Language";
  4322. item[1] = "Statistics";
  4323. item[2] = "Shipping prep";
  4324. item[3] = "All Data";
  4325. #ifdef SNMM
  4326. item[4] = "Bowden length";
  4327. #endif // SNMM
  4328. enc_dif = encoderDiff;
  4329. lcd_implementation_clear();
  4330. lcd.setCursor(0, 0);
  4331. lcd.print(">");
  4332. while (1) {
  4333. for (int i = 0; i < 4; i++) {
  4334. lcd.setCursor(1, i);
  4335. lcd.print(item[first + i]);
  4336. }
  4337. manage_heater();
  4338. manage_inactivity(true);
  4339. if (abs((enc_dif - encoderDiff)) > 4) {
  4340. if ((abs(enc_dif - encoderDiff)) > 1) {
  4341. if (enc_dif > encoderDiff) {
  4342. cursor_pos--;
  4343. }
  4344. if (enc_dif < encoderDiff) {
  4345. cursor_pos++;
  4346. }
  4347. if (cursor_pos > 3) {
  4348. cursor_pos = 3;
  4349. if (first < items_no - 4) {
  4350. first++;
  4351. lcd_implementation_clear();
  4352. }
  4353. }
  4354. if (cursor_pos < 0) {
  4355. cursor_pos = 0;
  4356. if (first > 0) {
  4357. first--;
  4358. lcd_implementation_clear();
  4359. }
  4360. }
  4361. lcd.setCursor(0, 0);
  4362. lcd.print(" ");
  4363. lcd.setCursor(0, 1);
  4364. lcd.print(" ");
  4365. lcd.setCursor(0, 2);
  4366. lcd.print(" ");
  4367. lcd.setCursor(0, 3);
  4368. lcd.print(" ");
  4369. lcd.setCursor(0, cursor_pos);
  4370. lcd.print(">");
  4371. enc_dif = encoderDiff;
  4372. delay(100);
  4373. }
  4374. }
  4375. if (lcd_clicked()) {
  4376. while (lcd_clicked());
  4377. delay(10);
  4378. while (lcd_clicked());
  4379. return(cursor_pos + first);
  4380. }
  4381. }
  4382. }
  4383. static void lcd_disable_farm_mode() {
  4384. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  4385. if (disable) {
  4386. enquecommand_P(PSTR("G99"));
  4387. lcd_return_to_status();
  4388. }
  4389. else {
  4390. lcd_goto_menu(lcd_settings_menu); //doesn't break menuStack
  4391. }
  4392. lcd_update_enable(true);
  4393. lcdDrawUpdate = 2;
  4394. }
  4395. #ifdef SNMM
  4396. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  4397. set_extrude_min_temp(.0);
  4398. current_position[E_AXIS] += shift;
  4399. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  4400. set_extrude_min_temp(EXTRUDE_MINTEMP);
  4401. }
  4402. void change_extr(int extr) { //switches multiplexer for extruders
  4403. st_synchronize();
  4404. delay(100);
  4405. disable_e0();
  4406. disable_e1();
  4407. disable_e2();
  4408. snmm_extruder = extr;
  4409. pinMode(E_MUX0_PIN, OUTPUT);
  4410. pinMode(E_MUX1_PIN, OUTPUT);
  4411. switch (extr) {
  4412. case 1:
  4413. WRITE(E_MUX0_PIN, HIGH);
  4414. WRITE(E_MUX1_PIN, LOW);
  4415. break;
  4416. case 2:
  4417. WRITE(E_MUX0_PIN, LOW);
  4418. WRITE(E_MUX1_PIN, HIGH);
  4419. break;
  4420. case 3:
  4421. WRITE(E_MUX0_PIN, HIGH);
  4422. WRITE(E_MUX1_PIN, HIGH);
  4423. break;
  4424. default:
  4425. WRITE(E_MUX0_PIN, LOW);
  4426. WRITE(E_MUX1_PIN, LOW);
  4427. break;
  4428. }
  4429. delay(100);
  4430. }
  4431. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  4432. return(2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  4433. }
  4434. void display_loading() {
  4435. switch (snmm_extruder) {
  4436. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  4437. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  4438. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  4439. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  4440. }
  4441. }
  4442. void extr_adj(int extruder) //loading filament for SNMM
  4443. {
  4444. bool correct;
  4445. max_feedrate[E_AXIS] =80;
  4446. //max_feedrate[E_AXIS] = 50;
  4447. START:
  4448. lcd_implementation_clear();
  4449. lcd.setCursor(0, 0);
  4450. switch (extruder) {
  4451. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  4452. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  4453. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  4454. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  4455. }
  4456. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4457. do{
  4458. extr_mov(0.001,1000);
  4459. delay_keep_alive(2);
  4460. } while (!lcd_clicked());
  4461. //delay_keep_alive(500);
  4462. KEEPALIVE_STATE(IN_HANDLER);
  4463. st_synchronize();
  4464. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  4465. //if (!correct) goto START;
  4466. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  4467. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  4468. extr_mov(bowden_length[extruder], 500);
  4469. lcd_implementation_clear();
  4470. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_LOADING_FILAMENT));
  4471. if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd.setCursor(0, 1);
  4472. else lcd.print(" ");
  4473. lcd.print(snmm_extruder + 1);
  4474. lcd.setCursor(0, 2); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  4475. st_synchronize();
  4476. max_feedrate[E_AXIS] = 50;
  4477. lcd_update_enable(true);
  4478. lcd_return_to_status();
  4479. lcdDrawUpdate = 2;
  4480. }
  4481. void extr_unload() { //unloads filament
  4482. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  4483. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  4484. uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
  4485. if (degHotend0() > EXTRUDE_MINTEMP) {
  4486. lcd_implementation_clear();
  4487. lcd_display_message_fullscreen_P(PSTR(""));
  4488. max_feedrate[E_AXIS] = 50;
  4489. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_UNLOADING_FILAMENT));
  4490. lcd.print(" ");
  4491. lcd.print(snmm_extruder + 1);
  4492. lcd.setCursor(0, 2); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  4493. if (current_position[Z_AXIS] < 15) {
  4494. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  4495. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  4496. }
  4497. current_position[E_AXIS] += 10; //extrusion
  4498. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  4499. st_current_set(2, E_MOTOR_HIGH_CURRENT);
  4500. if (current_temperature[0] < 230) { //PLA & all other filaments
  4501. current_position[E_AXIS] += 5.4;
  4502. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  4503. current_position[E_AXIS] += 3.2;
  4504. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4505. current_position[E_AXIS] += 3;
  4506. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  4507. }
  4508. else { //ABS
  4509. current_position[E_AXIS] += 3.1;
  4510. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  4511. current_position[E_AXIS] += 3.1;
  4512. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  4513. current_position[E_AXIS] += 4;
  4514. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4515. /*current_position[X_AXIS] += 23; //delay
  4516. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  4517. current_position[X_AXIS] -= 23; //delay
  4518. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  4519. delay_keep_alive(4700);
  4520. }
  4521. max_feedrate[E_AXIS] = 80;
  4522. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4523. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4524. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4525. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4526. st_synchronize();
  4527. //st_current_init();
  4528. if (SilentMode != SILENT_MODE_OFF) st_current_set(2, tmp_motor[2]); //set back to normal operation currents
  4529. else st_current_set(2, tmp_motor_loud[2]);
  4530. lcd_update_enable(true);
  4531. lcd_return_to_status();
  4532. max_feedrate[E_AXIS] = 50;
  4533. }
  4534. else {
  4535. lcd_implementation_clear();
  4536. lcd.setCursor(0, 0);
  4537. lcd_printPGM(_T(MSG_ERROR));
  4538. lcd.setCursor(0, 2);
  4539. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4540. delay(2000);
  4541. lcd_implementation_clear();
  4542. }
  4543. lcd_return_to_status();
  4544. }
  4545. //wrapper functions for loading filament
  4546. static void extr_adj_0(){
  4547. change_extr(0);
  4548. extr_adj(0);
  4549. }
  4550. static void extr_adj_1() {
  4551. change_extr(1);
  4552. extr_adj(1);
  4553. }
  4554. static void extr_adj_2() {
  4555. change_extr(2);
  4556. extr_adj(2);
  4557. }
  4558. static void extr_adj_3() {
  4559. change_extr(3);
  4560. extr_adj(3);
  4561. }
  4562. static void load_all() {
  4563. for (int i = 0; i < 4; i++) {
  4564. change_extr(i);
  4565. extr_adj(i);
  4566. }
  4567. }
  4568. //wrapper functions for changing extruders
  4569. static void extr_change_0() {
  4570. change_extr(0);
  4571. lcd_return_to_status();
  4572. }
  4573. static void extr_change_1() {
  4574. change_extr(1);
  4575. lcd_return_to_status();
  4576. }
  4577. static void extr_change_2() {
  4578. change_extr(2);
  4579. lcd_return_to_status();
  4580. }
  4581. static void extr_change_3() {
  4582. change_extr(3);
  4583. lcd_return_to_status();
  4584. }
  4585. //wrapper functions for unloading filament
  4586. void extr_unload_all() {
  4587. if (degHotend0() > EXTRUDE_MINTEMP) {
  4588. for (int i = 0; i < 4; i++) {
  4589. change_extr(i);
  4590. extr_unload();
  4591. }
  4592. }
  4593. else {
  4594. lcd_implementation_clear();
  4595. lcd.setCursor(0, 0);
  4596. lcd_printPGM(_T(MSG_ERROR));
  4597. lcd.setCursor(0, 2);
  4598. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4599. delay(2000);
  4600. lcd_implementation_clear();
  4601. lcd_return_to_status();
  4602. }
  4603. }
  4604. //unloading just used filament (for snmm)
  4605. void extr_unload_used() {
  4606. if (degHotend0() > EXTRUDE_MINTEMP) {
  4607. for (int i = 0; i < 4; i++) {
  4608. if (snmm_filaments_used & (1 << i)) {
  4609. change_extr(i);
  4610. extr_unload();
  4611. }
  4612. }
  4613. snmm_filaments_used = 0;
  4614. }
  4615. else {
  4616. lcd_implementation_clear();
  4617. lcd.setCursor(0, 0);
  4618. lcd_printPGM(_T(MSG_ERROR));
  4619. lcd.setCursor(0, 2);
  4620. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4621. delay(2000);
  4622. lcd_implementation_clear();
  4623. lcd_return_to_status();
  4624. }
  4625. }
  4626. static void extr_unload_0() {
  4627. change_extr(0);
  4628. extr_unload();
  4629. }
  4630. static void extr_unload_1() {
  4631. change_extr(1);
  4632. extr_unload();
  4633. }
  4634. static void extr_unload_2() {
  4635. change_extr(2);
  4636. extr_unload();
  4637. }
  4638. static void extr_unload_3() {
  4639. change_extr(3);
  4640. extr_unload();
  4641. }
  4642. static void fil_load_menu()
  4643. {
  4644. START_MENU();
  4645. MENU_ITEM(back, _T(MSG_MAIN), 0);
  4646. MENU_ITEM(function, _i("Load all"), load_all);////MSG_LOAD_ALL c=0 r=0
  4647. MENU_ITEM(function, _i("Load filament 1"), extr_adj_0);////MSG_LOAD_FILAMENT_1 c=17 r=0
  4648. MENU_ITEM(function, _i("Load filament 2"), extr_adj_1);////MSG_LOAD_FILAMENT_2 c=17 r=0
  4649. MENU_ITEM(function, _i("Load filament 3"), extr_adj_2);////MSG_LOAD_FILAMENT_3 c=17 r=0
  4650. MENU_ITEM(function, _i("Load filament 4"), extr_adj_3);////MSG_LOAD_FILAMENT_4 c=17 r=0
  4651. END_MENU();
  4652. }
  4653. static void fil_unload_menu()
  4654. {
  4655. START_MENU();
  4656. MENU_ITEM(back, _T(MSG_MAIN), 0);
  4657. MENU_ITEM(function, _i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=0 r=0
  4658. MENU_ITEM(function, _i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17 r=0
  4659. MENU_ITEM(function, _i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17 r=0
  4660. MENU_ITEM(function, _i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17 r=0
  4661. MENU_ITEM(function, _i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17 r=0
  4662. END_MENU();
  4663. }
  4664. static void change_extr_menu(){
  4665. START_MENU();
  4666. MENU_ITEM(back, _T(MSG_MAIN), 0);
  4667. MENU_ITEM(function, _i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1
  4668. MENU_ITEM(function, _i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17 r=1
  4669. MENU_ITEM(function, _i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17 r=1
  4670. MENU_ITEM(function, _i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17 r=1
  4671. END_MENU();
  4672. }
  4673. #endif
  4674. static void lcd_farm_no()
  4675. {
  4676. char step = 0;
  4677. int enc_dif = 0;
  4678. int _farmno = farm_no;
  4679. int _ret = 0;
  4680. lcd_implementation_clear();
  4681. lcd.setCursor(0, 0);
  4682. lcd.print("Farm no");
  4683. do
  4684. {
  4685. if (abs((enc_dif - encoderDiff)) > 2) {
  4686. if (enc_dif > encoderDiff) {
  4687. switch (step) {
  4688. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4689. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4690. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4691. default: break;
  4692. }
  4693. }
  4694. if (enc_dif < encoderDiff) {
  4695. switch (step) {
  4696. case(0): if (_farmno < 900) _farmno += 100; break;
  4697. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4698. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4699. default: break;
  4700. }
  4701. }
  4702. enc_dif = 0;
  4703. encoderDiff = 0;
  4704. }
  4705. lcd.setCursor(0, 2);
  4706. if (_farmno < 100) lcd.print("0");
  4707. if (_farmno < 10) lcd.print("0");
  4708. lcd.print(_farmno);
  4709. lcd.print(" ");
  4710. lcd.setCursor(0, 3);
  4711. lcd.print(" ");
  4712. lcd.setCursor(step, 3);
  4713. lcd.print("^");
  4714. delay(100);
  4715. if (lcd_clicked())
  4716. {
  4717. delay(200);
  4718. step++;
  4719. if(step == 3) {
  4720. _ret = 1;
  4721. farm_no = _farmno;
  4722. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4723. prusa_statistics(20);
  4724. lcd_return_to_status();
  4725. }
  4726. }
  4727. manage_heater();
  4728. } while (_ret == 0);
  4729. }
  4730. unsigned char lcd_choose_color() {
  4731. //function returns index of currently chosen item
  4732. //following part can be modified from 2 to 255 items:
  4733. //-----------------------------------------------------
  4734. unsigned char items_no = 2;
  4735. const char *item[items_no];
  4736. item[0] = "Orange";
  4737. item[1] = "Black";
  4738. //-----------------------------------------------------
  4739. unsigned char active_rows;
  4740. static int first = 0;
  4741. int enc_dif = 0;
  4742. unsigned char cursor_pos = 1;
  4743. enc_dif = encoderDiff;
  4744. lcd_implementation_clear();
  4745. lcd.setCursor(0, 1);
  4746. lcd.print(">");
  4747. active_rows = items_no < 3 ? items_no : 3;
  4748. while (1) {
  4749. lcd_print_at_PGM(0, 0, PSTR("Choose color:"));
  4750. for (int i = 0; i < active_rows; i++) {
  4751. lcd.setCursor(1, i+1);
  4752. lcd.print(item[first + i]);
  4753. }
  4754. manage_heater();
  4755. manage_inactivity(true);
  4756. proc_commands();
  4757. if (abs((enc_dif - encoderDiff)) > 12) {
  4758. if (enc_dif > encoderDiff) {
  4759. cursor_pos--;
  4760. }
  4761. if (enc_dif < encoderDiff) {
  4762. cursor_pos++;
  4763. }
  4764. if (cursor_pos > active_rows) {
  4765. cursor_pos = active_rows;
  4766. if (first < items_no - active_rows) {
  4767. first++;
  4768. lcd_implementation_clear();
  4769. }
  4770. }
  4771. if (cursor_pos < 1) {
  4772. cursor_pos = 1;
  4773. if (first > 0) {
  4774. first--;
  4775. lcd_implementation_clear();
  4776. }
  4777. }
  4778. lcd.setCursor(0, 1);
  4779. lcd.print(" ");
  4780. lcd.setCursor(0, 2);
  4781. lcd.print(" ");
  4782. lcd.setCursor(0, 3);
  4783. lcd.print(" ");
  4784. lcd.setCursor(0, cursor_pos);
  4785. lcd.print(">");
  4786. enc_dif = encoderDiff;
  4787. delay(100);
  4788. }
  4789. if (lcd_clicked()) {
  4790. while (lcd_clicked());
  4791. delay(10);
  4792. while (lcd_clicked());
  4793. switch(cursor_pos + first - 1) {
  4794. case 0: return 1; break;
  4795. case 1: return 0; break;
  4796. default: return 99; break;
  4797. }
  4798. }
  4799. }
  4800. }
  4801. void lcd_confirm_print()
  4802. {
  4803. uint8_t filament_type;
  4804. int enc_dif = 0;
  4805. int cursor_pos = 1;
  4806. int _ret = 0;
  4807. int _t = 0;
  4808. enc_dif = encoderDiff;
  4809. lcd_implementation_clear();
  4810. lcd.setCursor(0, 0);
  4811. lcd.print("Print ok ?");
  4812. do
  4813. {
  4814. if (abs(enc_dif - encoderDiff) > 12) {
  4815. if (enc_dif > encoderDiff) {
  4816. cursor_pos--;
  4817. }
  4818. if (enc_dif < encoderDiff) {
  4819. cursor_pos++;
  4820. }
  4821. enc_dif = encoderDiff;
  4822. }
  4823. if (cursor_pos > 2) { cursor_pos = 2; }
  4824. if (cursor_pos < 1) { cursor_pos = 1; }
  4825. lcd.setCursor(0, 2); lcd.print(" ");
  4826. lcd.setCursor(0, 3); lcd.print(" ");
  4827. lcd.setCursor(2, 2);
  4828. lcd_printPGM(_T(MSG_YES));
  4829. lcd.setCursor(2, 3);
  4830. lcd_printPGM(_T(MSG_NO));
  4831. lcd.setCursor(0, 1 + cursor_pos);
  4832. lcd.print(">");
  4833. delay(100);
  4834. _t = _t + 1;
  4835. if (_t>100)
  4836. {
  4837. prusa_statistics(99);
  4838. _t = 0;
  4839. }
  4840. if (lcd_clicked())
  4841. {
  4842. if (cursor_pos == 1)
  4843. {
  4844. _ret = 1;
  4845. filament_type = lcd_choose_color();
  4846. prusa_statistics(4, filament_type);
  4847. no_response = true; //we need confirmation by recieving PRUSA thx
  4848. important_status = 4;
  4849. saved_filament_type = filament_type;
  4850. NcTime = millis();
  4851. }
  4852. if (cursor_pos == 2)
  4853. {
  4854. _ret = 2;
  4855. filament_type = lcd_choose_color();
  4856. prusa_statistics(5, filament_type);
  4857. no_response = true; //we need confirmation by recieving PRUSA thx
  4858. important_status = 5;
  4859. saved_filament_type = filament_type;
  4860. NcTime = millis();
  4861. }
  4862. }
  4863. manage_heater();
  4864. manage_inactivity();
  4865. proc_commands();
  4866. } while (_ret == 0);
  4867. }
  4868. extern void __test();
  4869. static void lcd_test_menu()
  4870. {
  4871. __test();
  4872. }
  4873. static void lcd_main_menu()
  4874. {
  4875. SDscrool = 0;
  4876. START_MENU();
  4877. // Majkl superawesome menu
  4878. MENU_ITEM(back, _T(MSG_WATCH), 0);
  4879. #ifdef RESUME_DEBUG
  4880. if (!saved_printing)
  4881. MENU_ITEM(function, PSTR("tst - Save"), lcd_menu_test_save);
  4882. else
  4883. MENU_ITEM(function, PSTR("tst - Restore"), lcd_menu_test_restore);
  4884. #endif //RESUME_DEBUG
  4885. #ifdef TMC2130_DEBUG
  4886. MENU_ITEM(function, PSTR("recover print"), recover_print);
  4887. MENU_ITEM(function, PSTR("power panic"), uvlo_);
  4888. #endif //TMC2130_DEBUG
  4889. /* if (farm_mode && !IS_SD_PRINTING )
  4890. {
  4891. int tempScrool = 0;
  4892. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4893. //delay(100);
  4894. return; // nothing to do (so don't thrash the SD card)
  4895. uint16_t fileCnt = card.getnrfilenames();
  4896. card.getWorkDirName();
  4897. if (card.filename[0] == '/')
  4898. {
  4899. #if SDCARDDETECT == -1
  4900. MENU_ITEM(function, _T(MSG_REFRESH), lcd_sd_refresh);
  4901. #endif
  4902. } else {
  4903. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4904. }
  4905. for (uint16_t i = 0; i < fileCnt; i++)
  4906. {
  4907. if (_menuItemNr == _lineNr)
  4908. {
  4909. #ifndef SDCARD_RATHERRECENTFIRST
  4910. card.getfilename(i);
  4911. #else
  4912. card.getfilename(fileCnt - 1 - i);
  4913. #endif
  4914. if (card.filenameIsDir)
  4915. {
  4916. MENU_ITEM(sddirectory, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  4917. } else {
  4918. MENU_ITEM(sdfile, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  4919. }
  4920. } else {
  4921. MENU_ITEM_DUMMY();
  4922. }
  4923. }
  4924. MENU_ITEM(back, PSTR("- - - - - - - - -"), 0);
  4925. }*/
  4926. 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)
  4927. {
  4928. MENU_ITEM(submenu, _T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4929. }
  4930. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4931. {
  4932. MENU_ITEM(submenu, _i("Tune"), lcd_tune_menu);////MSG_TUNE c=0 r=0
  4933. } else
  4934. {
  4935. MENU_ITEM(submenu, _i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=0 r=0
  4936. }
  4937. #ifdef SDSUPPORT
  4938. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4939. {
  4940. if (card.isFileOpen())
  4941. {
  4942. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4943. if (card.sdprinting)
  4944. {
  4945. MENU_ITEM(function, _i("Pause print"), lcd_sdcard_pause);////MSG_PAUSE_PRINT c=0 r=0
  4946. }
  4947. else
  4948. {
  4949. MENU_ITEM(function, _i("Resume print"), lcd_sdcard_resume);////MSG_RESUME_PRINT c=0 r=0
  4950. }
  4951. MENU_ITEM(submenu, _T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4952. }
  4953. }
  4954. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  4955. //MENU_ITEM(submenu, _T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4956. }
  4957. else
  4958. {
  4959. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4960. {
  4961. //if (farm_mode) MENU_ITEM(submenu, MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  4962. /*else*/ MENU_ITEM(submenu, _T(MSG_CARD_MENU), lcd_sdcard_menu);
  4963. }
  4964. #if SDCARDDETECT < 1
  4965. MENU_ITEM(gcode, _i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD c=0 r=0
  4966. #endif
  4967. }
  4968. } else
  4969. {
  4970. MENU_ITEM(submenu, _i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=0 r=0
  4971. #if SDCARDDETECT < 1
  4972. MENU_ITEM(gcode, _i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface////MSG_INIT_SDCARD c=0 r=0
  4973. #endif
  4974. }
  4975. #endif
  4976. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4977. {
  4978. if (farm_mode)
  4979. {
  4980. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  4981. }
  4982. }
  4983. else
  4984. {
  4985. #ifndef SNMM
  4986. #ifdef PAT9125
  4987. if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true)))
  4988. MENU_ITEM(submenu, _i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0
  4989. else
  4990. #endif //PAT9125
  4991. MENU_ITEM(function, _T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  4992. MENU_ITEM(submenu, _T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  4993. #endif
  4994. #ifdef SNMM
  4995. MENU_ITEM(submenu, _T(MSG_LOAD_FILAMENT), fil_load_menu);
  4996. MENU_ITEM(submenu, _T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  4997. MENU_ITEM(submenu, _i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20 r=1
  4998. #endif
  4999. MENU_ITEM(submenu, _T(MSG_SETTINGS), lcd_settings_menu);
  5000. if(!isPrintPaused) MENU_ITEM(submenu, _T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  5001. #ifdef EXPERIMENTAL_FEATURES
  5002. MENU_ITEM(submenu, PSTR("Experimantal"), lcd_experimantal_menu);
  5003. #endif //EXPERIMENTAL_FEATURES
  5004. }
  5005. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  5006. {
  5007. MENU_ITEM(submenu, _i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS c=0 r=0
  5008. }
  5009. #if defined(TMC2130) || defined(PAT9125)
  5010. MENU_ITEM(submenu, PSTR("Fail stats"), lcd_menu_fails_stats);
  5011. #endif
  5012. MENU_ITEM(submenu, _i("Support"), lcd_support_menu);////MSG_SUPPORT c=0 r=0
  5013. // MENU_ITEM(submenu, _i("Test"), lcd_test_menu);////MSG_SUPPORT c=0 r=0
  5014. END_MENU();
  5015. }
  5016. void stack_error() {
  5017. SET_OUTPUT(BEEPER);
  5018. WRITE(BEEPER, HIGH);
  5019. delay(1000);
  5020. WRITE(BEEPER, LOW);
  5021. lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4
  5022. //err_triggered = 1;
  5023. while (1) delay_keep_alive(1000);
  5024. }
  5025. #ifdef DEBUG_STEPPER_TIMER_MISSED
  5026. bool stepper_timer_overflow_state = false;
  5027. uint16_t stepper_timer_overflow_max = 0;
  5028. uint16_t stepper_timer_overflow_last = 0;
  5029. uint16_t stepper_timer_overflow_cnt = 0;
  5030. void stepper_timer_overflow() {
  5031. char msg[28];
  5032. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  5033. lcd_setstatus(msg);
  5034. stepper_timer_overflow_state = false;
  5035. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  5036. stepper_timer_overflow_max = stepper_timer_overflow_last;
  5037. SERIAL_ECHOPGM("Stepper timer overflow: ");
  5038. MYSERIAL.print(msg);
  5039. SERIAL_ECHOLNPGM("");
  5040. WRITE(BEEPER, LOW);
  5041. }
  5042. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5043. #ifdef SDSUPPORT
  5044. static void lcd_autostart_sd()
  5045. {
  5046. card.lastnr = 0;
  5047. card.setroot();
  5048. card.checkautostart(true);
  5049. }
  5050. #endif
  5051. static void lcd_silent_mode_set_tune() {
  5052. switch (SilentModeMenu) {
  5053. #ifdef TMC2130
  5054. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  5055. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  5056. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  5057. #else
  5058. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  5059. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  5060. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  5061. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  5062. #endif //TMC2130
  5063. }
  5064. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  5065. st_current_init();
  5066. menu_action_back();
  5067. }
  5068. static void lcd_colorprint_change() {
  5069. enquecommand_P(PSTR("M600"));
  5070. custom_message = true;
  5071. custom_message_type = 2; //just print status message
  5072. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5073. lcd_return_to_status();
  5074. lcdDrawUpdate = 3;
  5075. }
  5076. static void lcd_tune_menu()
  5077. {
  5078. if (menuData.tuneMenu.status == 0) {
  5079. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  5080. menuData.tuneMenu.status = 1;
  5081. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  5082. } else if (menuData.tuneMenu.extrudemultiply != extrudemultiply) {
  5083. // extrudemultiply has been changed from the child menu. Apply the new value.
  5084. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  5085. calculate_extruder_multipliers();
  5086. }
  5087. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  5088. START_MENU();
  5089. MENU_ITEM(back, _T(MSG_MAIN), 0); //1
  5090. MENU_ITEM_EDIT(int3, _i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=0 r=0
  5091. MENU_ITEM_EDIT(int3, _T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  5092. MENU_ITEM_EDIT(int3, _T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  5093. MENU_ITEM_EDIT(int3, _T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  5094. MENU_ITEM_EDIT(int3, _i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=0 r=0
  5095. #ifdef FILAMENTCHANGEENABLE
  5096. MENU_ITEM(function, _T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//7
  5097. #endif
  5098. #ifndef DEBUG_DISABLE_FSENSORCHECK
  5099. #ifdef PAT9125
  5100. if (FSensorStateMenu == 0) {
  5101. MENU_ITEM(function, _T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  5102. }
  5103. else {
  5104. MENU_ITEM(function, _T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  5105. }
  5106. #endif //PAT9125
  5107. #endif //DEBUG_DISABLE_FSENSORCHECK
  5108. #ifdef TMC2130
  5109. if(!farm_mode)
  5110. {
  5111. //*** MaR::180416_01b
  5112. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM(function, _T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);
  5113. else MENU_ITEM(function, _T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  5114. if (SilentModeMenu == SILENT_MODE_NORMAL)
  5115. {
  5116. if (CrashDetectMenu == 0) MENU_ITEM(function, _T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);
  5117. else MENU_ITEM(function, _T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  5118. }
  5119. else MENU_ITEM(submenu, _T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  5120. }
  5121. #else //TMC2130
  5122. if (!farm_mode) { //dont show in menu if we are in farm mode
  5123. switch (SilentModeMenu) {
  5124. case SILENT_MODE_POWER: MENU_ITEM(function, _T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  5125. case SILENT_MODE_SILENT: MENU_ITEM(function, _T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  5126. case SILENT_MODE_AUTO: MENU_ITEM(function, _T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  5127. default: MENU_ITEM(function, _T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  5128. }
  5129. }
  5130. #endif //TMC2130
  5131. END_MENU();
  5132. }
  5133. static void lcd_move_menu_01mm()
  5134. {
  5135. move_menu_scale = 0.1;
  5136. lcd_move_menu_axis();
  5137. }
  5138. static void lcd_control_temperature_menu()
  5139. {
  5140. #ifdef PIDTEMP
  5141. // set up temp variables - undo the default scaling
  5142. // raw_Ki = unscalePID_i(Ki);
  5143. // raw_Kd = unscalePID_d(Kd);
  5144. #endif
  5145. START_MENU();
  5146. MENU_ITEM(back, _T(MSG_SETTINGS), 0);
  5147. #if TEMP_SENSOR_0 != 0
  5148. MENU_ITEM_EDIT(int3, _T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  5149. #endif
  5150. #if TEMP_SENSOR_1 != 0
  5151. MENU_ITEM_EDIT(int3, _i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1 c=0 r=0
  5152. #endif
  5153. #if TEMP_SENSOR_2 != 0
  5154. MENU_ITEM_EDIT(int3, _i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2 c=0 r=0
  5155. #endif
  5156. #if TEMP_SENSOR_BED != 0
  5157. MENU_ITEM_EDIT(int3, _T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  5158. #endif
  5159. MENU_ITEM_EDIT(int3, _T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  5160. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  5161. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  5162. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN c=0 r=0
  5163. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX c=0 r=0
  5164. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR c=0 r=0
  5165. #endif
  5166. END_MENU();
  5167. }
  5168. #if SDCARDDETECT == -1
  5169. static void lcd_sd_refresh()
  5170. {
  5171. card.initsd();
  5172. currentMenuViewOffset = 0;
  5173. }
  5174. #endif
  5175. static void lcd_sd_updir()
  5176. {
  5177. SDscrool = 0;
  5178. card.updir();
  5179. currentMenuViewOffset = 0;
  5180. }
  5181. void lcd_print_stop() {
  5182. cancel_heatup = true;
  5183. #ifdef MESH_BED_LEVELING
  5184. mbl.active = false;
  5185. #endif
  5186. // Stop the stoppers, update the position from the stoppers.
  5187. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  5188. planner_abort_hard();
  5189. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  5190. // Z baystep is no more applied. Reset it.
  5191. babystep_reset();
  5192. }
  5193. // Clean the input command queue.
  5194. cmdqueue_reset();
  5195. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  5196. lcd_update(2);
  5197. card.sdprinting = false;
  5198. card.closefile();
  5199. stoptime = millis();
  5200. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5201. pause_time = 0;
  5202. save_statistics(total_filament_used, t);
  5203. lcd_return_to_status();
  5204. lcd_ignore_click(true);
  5205. lcd_commands_step = 0;
  5206. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  5207. // Turn off the print fan
  5208. SET_OUTPUT(FAN_PIN);
  5209. WRITE(FAN_PIN, 0);
  5210. fanSpeed = 0;
  5211. }
  5212. void lcd_sdcard_stop()
  5213. {
  5214. lcd.setCursor(0, 0);
  5215. lcd_printPGM(_T(MSG_STOP_PRINT));
  5216. lcd.setCursor(2, 2);
  5217. lcd_printPGM(_T(MSG_NO));
  5218. lcd.setCursor(2, 3);
  5219. lcd_printPGM(_T(MSG_YES));
  5220. lcd.setCursor(0, 2); lcd.print(" ");
  5221. lcd.setCursor(0, 3); lcd.print(" ");
  5222. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  5223. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  5224. lcd.setCursor(0, 1 + encoderPosition);
  5225. lcd.print(">");
  5226. if (lcd_clicked())
  5227. {
  5228. if ((int32_t)encoderPosition == 1)
  5229. {
  5230. lcd_return_to_status();
  5231. }
  5232. if ((int32_t)encoderPosition == 2)
  5233. {
  5234. lcd_print_stop();
  5235. }
  5236. }
  5237. }
  5238. /*
  5239. void getFileDescription(char *name, char *description) {
  5240. // get file description, ie the REAL filenam, ie the second line
  5241. card.openFile(name, true);
  5242. int i = 0;
  5243. // skip the first line (which is the version line)
  5244. while (true) {
  5245. uint16_t readByte = card.get();
  5246. if (readByte == '\n') {
  5247. break;
  5248. }
  5249. }
  5250. // read the second line (which is the description line)
  5251. while (true) {
  5252. uint16_t readByte = card.get();
  5253. if (i == 0) {
  5254. // skip the first '^'
  5255. readByte = card.get();
  5256. }
  5257. description[i] = readByte;
  5258. i++;
  5259. if (readByte == '\n') {
  5260. break;
  5261. }
  5262. }
  5263. card.closefile();
  5264. description[i-1] = 0;
  5265. }
  5266. */
  5267. void lcd_sdcard_menu()
  5268. {
  5269. uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  5270. int tempScrool = 0;
  5271. if (presort_flag == true) {
  5272. presort_flag = false;
  5273. card.presort();
  5274. }
  5275. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  5276. //delay(100);
  5277. return; // nothing to do (so don't thrash the SD card)
  5278. uint16_t fileCnt = card.getnrfilenames();
  5279. START_MENU();
  5280. MENU_ITEM(back, _T(MSG_MAIN), 0);
  5281. card.getWorkDirName();
  5282. if (card.filename[0] == '/')
  5283. {
  5284. #if SDCARDDETECT == -1
  5285. MENU_ITEM(function, _T(MSG_REFRESH), lcd_sd_refresh);
  5286. #endif
  5287. } else {
  5288. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  5289. }
  5290. for (uint16_t i = 0; i < fileCnt; i++)
  5291. {
  5292. if (_menuItemNr == _lineNr)
  5293. {
  5294. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
  5295. /*#ifdef SDCARD_RATHERRECENTFIRST
  5296. #ifndef SDCARD_SORT_ALPHA
  5297. fileCnt - 1 -
  5298. #endif
  5299. #endif
  5300. i;*/
  5301. #ifdef SDCARD_SORT_ALPHA
  5302. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  5303. else card.getfilename_sorted(nr);
  5304. #else
  5305. card.getfilename(nr);
  5306. #endif
  5307. if (card.filenameIsDir)
  5308. MENU_ITEM(sddirectory, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  5309. else
  5310. MENU_ITEM(sdfile, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  5311. } else {
  5312. MENU_ITEM_DUMMY();
  5313. }
  5314. }
  5315. END_MENU();
  5316. }
  5317. //char description [10] [31];
  5318. /*void get_description() {
  5319. uint16_t fileCnt = card.getnrfilenames();
  5320. for (uint16_t i = 0; i < fileCnt; i++)
  5321. {
  5322. card.getfilename(fileCnt - 1 - i);
  5323. getFileDescription(card.filename, description[i]);
  5324. }
  5325. }*/
  5326. /*void lcd_farm_sdcard_menu()
  5327. {
  5328. static int i = 0;
  5329. if (i == 0) {
  5330. get_description();
  5331. i++;
  5332. }
  5333. //int j;
  5334. //char description[31];
  5335. int tempScrool = 0;
  5336. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  5337. //delay(100);
  5338. return; // nothing to do (so don't thrash the SD card)
  5339. uint16_t fileCnt = card.getnrfilenames();
  5340. START_MENU();
  5341. MENU_ITEM(back, _T(MSG_MAIN), 0);
  5342. card.getWorkDirName();
  5343. if (card.filename[0] == '/')
  5344. {
  5345. #if SDCARDDETECT == -1
  5346. MENU_ITEM(function, _T(MSG_REFRESH), lcd_sd_refresh);
  5347. #endif
  5348. }
  5349. else {
  5350. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  5351. }
  5352. for (uint16_t i = 0; i < fileCnt; i++)
  5353. {
  5354. if (_menuItemNr == _lineNr)
  5355. {
  5356. #ifndef SDCARD_RATHERRECENTFIRST
  5357. card.getfilename(i);
  5358. #else
  5359. card.getfilename(fileCnt - 1 - i);
  5360. #endif
  5361. if (card.filenameIsDir)
  5362. {
  5363. MENU_ITEM(sddirectory, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  5364. }
  5365. else {
  5366. MENU_ITEM(sdfile, _T(MSG_CARD_MENU), card.filename, description[i]);
  5367. }
  5368. }
  5369. else {
  5370. MENU_ITEM_DUMMY();
  5371. }
  5372. }
  5373. END_MENU();
  5374. }*/
  5375. #define menu_edit_type(_type, _name, _strFunc, scale) \
  5376. void menu_edit_ ## _name () \
  5377. { \
  5378. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  5379. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  5380. if (lcdDrawUpdate) \
  5381. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  5382. if (LCD_CLICKED) \
  5383. { \
  5384. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  5385. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  5386. } \
  5387. } \
  5388. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  5389. { \
  5390. asm("cli"); \
  5391. menuData.editMenuParentState.prevMenu = currentMenu; \
  5392. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  5393. asm("sei"); \
  5394. \
  5395. lcdDrawUpdate = 2; \
  5396. menuData.editMenuParentState.editLabel = pstr; \
  5397. menuData.editMenuParentState.editValue = ptr; \
  5398. menuData.editMenuParentState.minEditValue = minValue * scale; \
  5399. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  5400. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  5401. \
  5402. }\
  5403. /*
  5404. void menu_edit_callback_ ## _name () { \
  5405. menu_edit_ ## _name (); \
  5406. if (LCD_CLICKED) (*callbackFunc)(); \
  5407. } \
  5408. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  5409. { \
  5410. menuData.editMenuParentState.prevMenu = currentMenu; \
  5411. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  5412. \
  5413. lcdDrawUpdate = 2; \
  5414. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  5415. \
  5416. menuData.editMenuParentState.editLabel = pstr; \
  5417. menuData.editMenuParentState.editValue = ptr; \
  5418. menuData.editMenuParentState.minEditValue = minValue * scale; \
  5419. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  5420. callbackFunc = callback;\
  5421. }
  5422. */
  5423. #ifdef TMC2130
  5424. extern char conv[8];
  5425. // Convert tmc2130 mres to string
  5426. char *mres_to_str3(const uint8_t &x)
  5427. {
  5428. return itostr3(256 >> x);
  5429. }
  5430. menu_edit_type(uint8_t, mres, mres_to_str3, 1)
  5431. // Convert tmc2130 wfac to string
  5432. char *wfac_to_str5(const uint8_t &x)
  5433. {
  5434. if (x >= TMC2130_WAVE_FAC1000_MIN)
  5435. {
  5436. conv[0] = '[';
  5437. ftostr43(((float)((uint16_t)x + 1000) / 1000), 1);
  5438. }
  5439. else strcpy_P(conv, _i(" [off"));////MSG_EXTRUDER_CORRECTION_OFF c=6 r=0
  5440. conv[6] = ']';
  5441. conv[7] = ' ';
  5442. conv[8] = 0;
  5443. return conv;
  5444. }
  5445. menu_edit_type(uint8_t, wfac, wfac_to_str5, 1)
  5446. #endif //TMC2130
  5447. menu_edit_type(uint8_t, byte3, itostr3, 1)
  5448. menu_edit_type(int, int3, itostr3, 1)
  5449. menu_edit_type(float, float3, ftostr3, 1)
  5450. menu_edit_type(float, float32, ftostr32, 100)
  5451. menu_edit_type(float, float43, ftostr43, 1000)
  5452. menu_edit_type(float, float5, ftostr5, 0.01)
  5453. menu_edit_type(float, float51, ftostr51, 10)
  5454. menu_edit_type(float, float52, ftostr52, 100)
  5455. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  5456. static void lcd_selftest_v()
  5457. {
  5458. (void)lcd_selftest();
  5459. }
  5460. bool lcd_selftest()
  5461. {
  5462. int _progress = 0;
  5463. bool _result = true;
  5464. lcd_wait_for_cool_down();
  5465. lcd_implementation_clear();
  5466. lcd.setCursor(0, 0); lcd_printPGM(_i("Self test start "));////MSG_SELFTEST_START c=20 r=0
  5467. #ifdef TMC2130
  5468. FORCE_HIGH_POWER_START;
  5469. #endif // TMC2130
  5470. delay(2000);
  5471. KEEPALIVE_STATE(IN_HANDLER);
  5472. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  5473. #if (defined(FANCHECK) && defined(TACH_0))
  5474. _result = lcd_selftest_fan_dialog(0);
  5475. #else //defined(TACH_0)
  5476. _result = lcd_selftest_manual_fan_check(0, false);
  5477. if (!_result)
  5478. {
  5479. const char *_err;
  5480. lcd_selftest_error(7, _err, _err); //extruder fan not spinning
  5481. }
  5482. #endif //defined(TACH_0)
  5483. if (_result)
  5484. {
  5485. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  5486. #if (defined(FANCHECK) && defined(TACH_1))
  5487. _result = lcd_selftest_fan_dialog(1);
  5488. #else //defined(TACH_1)
  5489. _result = lcd_selftest_manual_fan_check(1, false);
  5490. if (!_result)
  5491. {
  5492. const char *_err;
  5493. lcd_selftest_error(6, _err, _err); //print fan not spinning
  5494. }
  5495. #endif //defined(TACH_1)
  5496. }
  5497. if (_result)
  5498. {
  5499. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  5500. #ifndef TMC2130
  5501. _result = lcd_selfcheck_endstops();
  5502. #else
  5503. _result = true;
  5504. #endif
  5505. }
  5506. if (_result)
  5507. {
  5508. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  5509. _result = lcd_selfcheck_check_heater(false);
  5510. }
  5511. if (_result)
  5512. {
  5513. //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
  5514. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  5515. #ifdef TMC2130
  5516. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5517. #else
  5518. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5519. #endif //TMC2130
  5520. }
  5521. if (_result)
  5522. {
  5523. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  5524. #ifndef TMC2130
  5525. _result = lcd_selfcheck_pulleys(X_AXIS);
  5526. #endif
  5527. }
  5528. if (_result)
  5529. {
  5530. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  5531. #ifdef TMC2130
  5532. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5533. #else
  5534. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5535. #endif // TMC2130
  5536. }
  5537. if (_result)
  5538. {
  5539. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  5540. #ifndef TMC2130
  5541. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5542. #endif // TMC2130
  5543. }
  5544. if (_result)
  5545. {
  5546. #ifdef TMC2130
  5547. tmc2130_home_exit();
  5548. enable_endstops(false);
  5549. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  5550. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  5551. #endif
  5552. //homeaxis(X_AXIS);
  5553. //homeaxis(Y_AXIS);
  5554. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5555. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5556. st_synchronize();
  5557. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  5558. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  5559. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) {
  5560. enquecommand_P(PSTR("G28 W"));
  5561. enquecommand_P(PSTR("G1 Z15 F1000"));
  5562. }
  5563. }
  5564. #ifdef TMC2130
  5565. if (_result)
  5566. {
  5567. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5568. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5569. st_synchronize();
  5570. _progress = lcd_selftest_screen(13, 0, 2, true, 0);
  5571. bool bres = tmc2130_home_calibrate(X_AXIS);
  5572. _progress = lcd_selftest_screen(13, 1, 2, true, 0);
  5573. bres &= tmc2130_home_calibrate(Y_AXIS);
  5574. _progress = lcd_selftest_screen(13, 2, 2, true, 0);
  5575. if (bres)
  5576. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5577. _result = bres;
  5578. }
  5579. #endif //TMC2130
  5580. if (_result)
  5581. {
  5582. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000); //check bed
  5583. _result = lcd_selfcheck_check_heater(true);
  5584. }
  5585. if (_result)
  5586. {
  5587. _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok
  5588. #ifdef PAT9125
  5589. _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor
  5590. _result = lcd_selftest_fsensor();
  5591. #endif // PAT9125
  5592. }
  5593. if (_result)
  5594. {
  5595. #ifdef PAT9125
  5596. _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK
  5597. #endif // PAT9125
  5598. _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct
  5599. }
  5600. else
  5601. {
  5602. _progress = lcd_selftest_screen(12, _progress, 3, true, 5000);
  5603. }
  5604. lcd_reset_alert_level();
  5605. enquecommand_P(PSTR("M84"));
  5606. lcd_implementation_clear();
  5607. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  5608. if (_result)
  5609. {
  5610. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=0 r=0
  5611. }
  5612. else
  5613. {
  5614. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5615. }
  5616. #ifdef TMC2130
  5617. FORCE_HIGH_POWER_END;
  5618. #endif // TMC2130
  5619. KEEPALIVE_STATE(NOT_BUSY);
  5620. return(_result);
  5621. }
  5622. #ifdef TMC2130
  5623. static void reset_crash_det(char axis) {
  5624. current_position[axis] += 10;
  5625. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5626. st_synchronize();
  5627. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5628. }
  5629. static bool lcd_selfcheck_axis_sg(char axis) {
  5630. // each axis length is measured twice
  5631. float axis_length, current_position_init, current_position_final;
  5632. float measured_axis_length[2];
  5633. float margin = 60;
  5634. float max_error_mm = 5;
  5635. switch (axis) {
  5636. case 0: axis_length = X_MAX_POS; break;
  5637. case 1: axis_length = Y_MAX_POS + 8; break;
  5638. default: axis_length = 210; break;
  5639. }
  5640. tmc2130_sg_stop_on_crash = false;
  5641. tmc2130_home_exit();
  5642. enable_endstops(true);
  5643. if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low
  5644. current_position[Z_AXIS] += 17;
  5645. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5646. tmc2130_home_enter(Z_AXIS_MASK);
  5647. st_synchronize();
  5648. tmc2130_home_exit();
  5649. }
  5650. // first axis length measurement begin
  5651. current_position[axis] -= (axis_length + margin);
  5652. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5653. st_synchronize();
  5654. tmc2130_sg_meassure_start(axis);
  5655. current_position_init = st_get_position_mm(axis);
  5656. current_position[axis] += 2 * margin;
  5657. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5658. st_synchronize();
  5659. current_position[axis] += axis_length;
  5660. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5661. st_synchronize();
  5662. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5663. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5664. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5665. current_position_final = st_get_position_mm(axis);
  5666. measured_axis_length[0] = abs(current_position_final - current_position_init);
  5667. // first measurement end and second measurement begin
  5668. current_position[axis] -= margin;
  5669. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5670. st_synchronize();
  5671. current_position[axis] -= (axis_length + margin);
  5672. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5673. st_synchronize();
  5674. current_position_init = st_get_position_mm(axis);
  5675. measured_axis_length[1] = abs(current_position_final - current_position_init);
  5676. //end of second measurement, now check for possible errors:
  5677. for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5678. SERIAL_ECHOPGM("Measured axis length:");
  5679. MYSERIAL.println(measured_axis_length[i]);
  5680. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5681. enable_endstops(false);
  5682. const char *_error_1;
  5683. const char *_error_2;
  5684. if (axis == X_AXIS) _error_1 = "X";
  5685. if (axis == Y_AXIS) _error_1 = "Y";
  5686. if (axis == Z_AXIS) _error_1 = "Z";
  5687. lcd_selftest_error(9, _error_1, _error_2);
  5688. current_position[axis] = 0;
  5689. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5690. reset_crash_det(axis);
  5691. return false;
  5692. }
  5693. }
  5694. SERIAL_ECHOPGM("Axis length difference:");
  5695. MYSERIAL.println(abs(measured_axis_length[0] - measured_axis_length[1]));
  5696. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5697. //loose pulleys
  5698. const char *_error_1;
  5699. const char *_error_2;
  5700. if (axis == X_AXIS) _error_1 = "X";
  5701. if (axis == Y_AXIS) _error_1 = "Y";
  5702. if (axis == Z_AXIS) _error_1 = "Z";
  5703. lcd_selftest_error(8, _error_1, _error_2);
  5704. current_position[axis] = 0;
  5705. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5706. reset_crash_det(axis);
  5707. return false;
  5708. }
  5709. current_position[axis] = 0;
  5710. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5711. reset_crash_det(axis);
  5712. return true;
  5713. }
  5714. #endif //TMC2130
  5715. //#ifndef TMC2130
  5716. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5717. {
  5718. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  5719. bool _stepdone = false;
  5720. bool _stepresult = false;
  5721. int _progress = 0;
  5722. int _travel_done = 0;
  5723. int _err_endstop = 0;
  5724. int _lcd_refresh = 0;
  5725. _travel = _travel + (_travel / 10);
  5726. if (_axis == X_AXIS) {
  5727. current_position[Z_AXIS] += 17;
  5728. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5729. }
  5730. do {
  5731. current_position[_axis] = current_position[_axis] - 1;
  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. st_synchronize();
  5734. #ifdef TMC2130
  5735. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1))
  5736. #else //TMC2130
  5737. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5738. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5739. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5740. #endif //TMC2130
  5741. {
  5742. if (_axis == 0)
  5743. {
  5744. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5745. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5746. }
  5747. if (_axis == 1)
  5748. {
  5749. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5750. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5751. }
  5752. if (_axis == 2)
  5753. {
  5754. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5755. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5756. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  5757. /*disable_x();
  5758. disable_y();
  5759. disable_z();*/
  5760. }
  5761. _stepdone = true;
  5762. }
  5763. if (_lcd_refresh < 6)
  5764. {
  5765. _lcd_refresh++;
  5766. }
  5767. else
  5768. {
  5769. _progress = lcd_selftest_screen(4 + _axis, _progress, 3, false, 0);
  5770. _lcd_refresh = 0;
  5771. }
  5772. manage_heater();
  5773. manage_inactivity(true);
  5774. //delay(100);
  5775. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5776. } while (!_stepdone);
  5777. //current_position[_axis] = current_position[_axis] + 15;
  5778. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5779. if (!_stepresult)
  5780. {
  5781. const char *_error_1;
  5782. const char *_error_2;
  5783. if (_axis == X_AXIS) _error_1 = "X";
  5784. if (_axis == Y_AXIS) _error_1 = "Y";
  5785. if (_axis == Z_AXIS) _error_1 = "Z";
  5786. if (_err_endstop == 0) _error_2 = "X";
  5787. if (_err_endstop == 1) _error_2 = "Y";
  5788. if (_err_endstop == 2) _error_2 = "Z";
  5789. if (_travel_done >= _travel)
  5790. {
  5791. lcd_selftest_error(5, _error_1, _error_2);
  5792. }
  5793. else
  5794. {
  5795. lcd_selftest_error(4, _error_1, _error_2);
  5796. }
  5797. }
  5798. return _stepresult;
  5799. }
  5800. #ifndef TMC2130
  5801. static bool lcd_selfcheck_pulleys(int axis)
  5802. {
  5803. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5804. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5805. float current_position_init;
  5806. float move;
  5807. bool endstop_triggered = false;
  5808. int i;
  5809. unsigned long timeout_counter;
  5810. refresh_cmd_timeout();
  5811. manage_inactivity(true);
  5812. if (axis == 0) move = 50; //X_AXIS
  5813. else move = 50; //Y_AXIS
  5814. current_position_init = current_position[axis];
  5815. current_position[axis] += 2;
  5816. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5817. for (i = 0; i < 5; i++) {
  5818. refresh_cmd_timeout();
  5819. current_position[axis] = current_position[axis] + move;
  5820. st_current_set(0, 850); //set motor current higher
  5821. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  5822. st_synchronize();
  5823. //*** MaR::180416_02
  5824. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  5825. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  5826. current_position[axis] = current_position[axis] - move;
  5827. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  5828. st_synchronize();
  5829. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5830. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5831. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5832. return(false);
  5833. }
  5834. }
  5835. timeout_counter = millis() + 2500;
  5836. endstop_triggered = false;
  5837. manage_inactivity(true);
  5838. while (!endstop_triggered) {
  5839. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5840. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5841. endstop_triggered = true;
  5842. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5843. current_position[axis] += (axis == X_AXIS) ? 13 : 9;
  5844. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5845. st_synchronize();
  5846. return(true);
  5847. }
  5848. else {
  5849. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5850. return(false);
  5851. }
  5852. }
  5853. else {
  5854. current_position[axis] -= 1;
  5855. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5856. st_synchronize();
  5857. if (millis() > timeout_counter) {
  5858. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5859. return(false);
  5860. }
  5861. }
  5862. }
  5863. return(true);
  5864. }
  5865. #endif //TMC2130
  5866. static bool lcd_selfcheck_endstops()
  5867. {
  5868. bool _result = true;
  5869. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5870. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5871. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5872. {
  5873. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  5874. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  5875. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  5876. }
  5877. 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);
  5878. delay(500);
  5879. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5880. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5881. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5882. {
  5883. _result = false;
  5884. char _error[4] = "";
  5885. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  5886. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  5887. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  5888. lcd_selftest_error(3, _error, "");
  5889. }
  5890. manage_heater();
  5891. manage_inactivity(true);
  5892. return _result;
  5893. }
  5894. //#endif //not defined TMC2130
  5895. static bool lcd_selfcheck_check_heater(bool _isbed)
  5896. {
  5897. int _counter = 0;
  5898. int _progress = 0;
  5899. bool _stepresult = false;
  5900. bool _docycle = true;
  5901. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5902. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5903. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5904. target_temperature[0] = (_isbed) ? 0 : 200;
  5905. target_temperature_bed = (_isbed) ? 100 : 0;
  5906. manage_heater();
  5907. manage_inactivity(true);
  5908. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  5909. do {
  5910. _counter++;
  5911. _docycle = (_counter < _cycles) ? true : false;
  5912. manage_heater();
  5913. manage_inactivity(true);
  5914. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  5915. /*if (_isbed) {
  5916. MYSERIAL.print("Bed temp:");
  5917. MYSERIAL.println(degBed());
  5918. }
  5919. else {
  5920. MYSERIAL.print("Hotend temp:");
  5921. MYSERIAL.println(degHotend(0));
  5922. }*/
  5923. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  5924. } while (_docycle);
  5925. target_temperature[0] = 0;
  5926. target_temperature_bed = 0;
  5927. manage_heater();
  5928. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  5929. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  5930. /*
  5931. MYSERIAL.println("");
  5932. MYSERIAL.print("Checked result:");
  5933. MYSERIAL.println(_checked_result);
  5934. MYSERIAL.print("Opposite result:");
  5935. MYSERIAL.println(_opposite_result);
  5936. */
  5937. if (_opposite_result < ((_isbed) ? 10 : 3))
  5938. {
  5939. if (_checked_result >= ((_isbed) ? 3 : 10))
  5940. {
  5941. _stepresult = true;
  5942. }
  5943. else
  5944. {
  5945. lcd_selftest_error(1, "", "");
  5946. }
  5947. }
  5948. else
  5949. {
  5950. lcd_selftest_error(2, "", "");
  5951. }
  5952. manage_heater();
  5953. manage_inactivity(true);
  5954. KEEPALIVE_STATE(IN_HANDLER);
  5955. return _stepresult;
  5956. }
  5957. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  5958. {
  5959. lcd_implementation_quick_feedback();
  5960. target_temperature[0] = 0;
  5961. target_temperature_bed = 0;
  5962. manage_heater();
  5963. manage_inactivity();
  5964. lcd_implementation_clear();
  5965. lcd.setCursor(0, 0);
  5966. lcd_printPGM(_i("Selftest error !"));////MSG_SELFTEST_ERROR c=0 r=0
  5967. lcd.setCursor(0, 1);
  5968. lcd_printPGM(_i("Please check :"));////MSG_SELFTEST_PLEASECHECK c=0 r=0
  5969. switch (_error_no)
  5970. {
  5971. case 1:
  5972. lcd.setCursor(0, 2);
  5973. lcd_printPGM(_i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=0 r=0
  5974. lcd.setCursor(0, 3);
  5975. lcd_printPGM(_i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=0 r=0
  5976. break;
  5977. case 2:
  5978. lcd.setCursor(0, 2);
  5979. lcd_printPGM(_i("Bed / Heater"));////MSG_SELFTEST_BEDHEATER c=0 r=0
  5980. lcd.setCursor(0, 3);
  5981. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5982. break;
  5983. case 3:
  5984. lcd.setCursor(0, 2);
  5985. lcd_printPGM(_i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=0 r=0
  5986. lcd.setCursor(0, 3);
  5987. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5988. lcd.setCursor(17, 3);
  5989. lcd.print(_error_1);
  5990. break;
  5991. case 4:
  5992. lcd.setCursor(0, 2);
  5993. lcd_printPGM(_T(MSG_SELFTEST_MOTOR));
  5994. lcd.setCursor(18, 2);
  5995. lcd.print(_error_1);
  5996. lcd.setCursor(0, 3);
  5997. lcd_printPGM(_i("Endstop"));////MSG_SELFTEST_ENDSTOP c=0 r=0
  5998. lcd.setCursor(18, 3);
  5999. lcd.print(_error_2);
  6000. break;
  6001. case 5:
  6002. lcd.setCursor(0, 2);
  6003. lcd_printPGM(_i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20 r=1
  6004. lcd.setCursor(0, 3);
  6005. lcd_printPGM(_T(MSG_SELFTEST_MOTOR));
  6006. lcd.setCursor(18, 3);
  6007. lcd.print(_error_1);
  6008. break;
  6009. case 6:
  6010. lcd.setCursor(0, 2);
  6011. lcd_printPGM(_T(MSG_SELFTEST_COOLING_FAN));
  6012. lcd.setCursor(0, 3);
  6013. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  6014. lcd.setCursor(18, 3);
  6015. lcd.print(_error_1);
  6016. break;
  6017. case 7:
  6018. lcd.setCursor(0, 2);
  6019. lcd_printPGM(_T(MSG_SELFTEST_EXTRUDER_FAN));
  6020. lcd.setCursor(0, 3);
  6021. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  6022. lcd.setCursor(18, 3);
  6023. lcd.print(_error_1);
  6024. break;
  6025. case 8:
  6026. lcd.setCursor(0, 2);
  6027. lcd_printPGM(_i("Loose pulley"));////MSG_LOOSE_PULLEY c=20 r=1
  6028. lcd.setCursor(0, 3);
  6029. lcd_printPGM(_T(MSG_SELFTEST_MOTOR));
  6030. lcd.setCursor(18, 3);
  6031. lcd.print(_error_1);
  6032. break;
  6033. case 9:
  6034. lcd.setCursor(0, 2);
  6035. lcd_printPGM(_i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=0 r=0
  6036. lcd.setCursor(0, 3);
  6037. lcd_printPGM(_i("Axis"));////MSG_SELFTEST_AXIS c=0 r=0
  6038. lcd.setCursor(18, 3);
  6039. lcd.print(_error_1);
  6040. break;
  6041. case 10:
  6042. lcd.setCursor(0, 2);
  6043. lcd_printPGM(_i("Front/left fans"));////MSG_SELFTEST_FANS c=0 r=0
  6044. lcd.setCursor(0, 3);
  6045. lcd_printPGM(_i("Swapped"));////MSG_SELFTEST_SWAPPED c=0 r=0
  6046. lcd.setCursor(18, 3);
  6047. lcd.print(_error_1);
  6048. break;
  6049. case 11:
  6050. lcd.setCursor(0, 2);
  6051. lcd_printPGM(_i("Filament sensor"));////MSG_FILAMENT_SENSOR c=20 r=0
  6052. lcd.setCursor(0, 3);
  6053. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  6054. break;
  6055. }
  6056. delay(1000);
  6057. lcd_implementation_quick_feedback();
  6058. do {
  6059. delay(100);
  6060. manage_heater();
  6061. manage_inactivity();
  6062. } while (!lcd_clicked());
  6063. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  6064. lcd_return_to_status();
  6065. }
  6066. #ifdef PAT9125
  6067. static bool lcd_selftest_fsensor() {
  6068. fsensor_init();
  6069. if (fsensor_not_responding)
  6070. {
  6071. const char *_err;
  6072. lcd_selftest_error(11, _err, _err);
  6073. }
  6074. return(!fsensor_not_responding);
  6075. }
  6076. #endif //PAT9125
  6077. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
  6078. {
  6079. bool _result = check_opposite;
  6080. lcd_implementation_clear();
  6081. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6082. switch (_fan)
  6083. {
  6084. case 0:
  6085. // extruder cooling fan
  6086. lcd.setCursor(0, 1);
  6087. if(check_opposite == true) lcd_printPGM(_T(MSG_SELFTEST_COOLING_FAN));
  6088. else lcd_printPGM(_T(MSG_SELFTEST_EXTRUDER_FAN));
  6089. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  6090. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  6091. break;
  6092. case 1:
  6093. // object cooling fan
  6094. lcd.setCursor(0, 1);
  6095. if (check_opposite == true) lcd_printPGM(_T(MSG_SELFTEST_EXTRUDER_FAN));
  6096. else lcd_printPGM(_T(MSG_SELFTEST_COOLING_FAN));
  6097. SET_OUTPUT(FAN_PIN);
  6098. analogWrite(FAN_PIN, 255);
  6099. break;
  6100. }
  6101. delay(500);
  6102. lcd.setCursor(1, 2); lcd_printPGM(_T(MSG_SELFTEST_FAN_YES));
  6103. lcd.setCursor(0, 3); lcd.print(">");
  6104. lcd.setCursor(1, 3); lcd_printPGM(_T(MSG_SELFTEST_FAN_NO));
  6105. int8_t enc_dif = 0;
  6106. KEEPALIVE_STATE(PAUSED_FOR_USER);
  6107. button_pressed = false;
  6108. do
  6109. {
  6110. switch (_fan)
  6111. {
  6112. case 0:
  6113. // extruder cooling fan
  6114. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  6115. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  6116. break;
  6117. case 1:
  6118. // object cooling fan
  6119. SET_OUTPUT(FAN_PIN);
  6120. analogWrite(FAN_PIN, 255);
  6121. break;
  6122. }
  6123. if (abs((enc_dif - encoderDiff)) > 2) {
  6124. if (enc_dif > encoderDiff) {
  6125. _result = !check_opposite;
  6126. lcd.setCursor(0, 2); lcd.print(">");
  6127. lcd.setCursor(1, 2); lcd_printPGM(_T(MSG_SELFTEST_FAN_YES));
  6128. lcd.setCursor(0, 3); lcd.print(" ");
  6129. lcd.setCursor(1, 3); lcd_printPGM(_T(MSG_SELFTEST_FAN_NO));
  6130. }
  6131. if (enc_dif < encoderDiff) {
  6132. _result = check_opposite;
  6133. lcd.setCursor(0, 2); lcd.print(" ");
  6134. lcd.setCursor(1, 2); lcd_printPGM(_T(MSG_SELFTEST_FAN_YES));
  6135. lcd.setCursor(0, 3); lcd.print(">");
  6136. lcd.setCursor(1, 3); lcd_printPGM(_T(MSG_SELFTEST_FAN_NO));
  6137. }
  6138. enc_dif = 0;
  6139. encoderDiff = 0;
  6140. }
  6141. manage_heater();
  6142. delay(100);
  6143. } while (!lcd_clicked());
  6144. KEEPALIVE_STATE(IN_HANDLER);
  6145. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  6146. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  6147. SET_OUTPUT(FAN_PIN);
  6148. analogWrite(FAN_PIN, 0);
  6149. fanSpeed = 0;
  6150. manage_heater();
  6151. return _result;
  6152. }
  6153. static bool lcd_selftest_fan_dialog(int _fan)
  6154. {
  6155. bool _result = true;
  6156. int _errno = 7;
  6157. switch (_fan) {
  6158. case 0:
  6159. fanSpeed = 0;
  6160. manage_heater(); //turn off fan
  6161. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  6162. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  6163. manage_heater(); //count average fan speed from 2s delay and turn off fans
  6164. if (!fan_speed[0]) _result = false;
  6165. //SERIAL_ECHOPGM("Extruder fan speed: ");
  6166. //MYSERIAL.println(fan_speed[0]);
  6167. //SERIAL_ECHOPGM("Print fan speed: ");
  6168. //MYSERIAL.print(fan_speed[1]);
  6169. break;
  6170. case 1:
  6171. //will it work with Thotend > 50 C ?
  6172. fanSpeed = 150; //print fan
  6173. for (uint8_t i = 0; i < 5; i++) {
  6174. delay_keep_alive(1000);
  6175. lcd.setCursor(18, 3);
  6176. lcd.print("-");
  6177. delay_keep_alive(1000);
  6178. lcd.setCursor(18, 3);
  6179. lcd.print("|");
  6180. }
  6181. fanSpeed = 0;
  6182. manage_heater(); //turn off fan
  6183. manage_inactivity(true); //to turn off print fan
  6184. if (!fan_speed[1]) {
  6185. _result = false; _errno = 6; //print fan not spinning
  6186. }
  6187. else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
  6188. //check fans manually
  6189. _result = lcd_selftest_manual_fan_check(1, true); //turn on print fan and check that left extruder fan is not spinning
  6190. if (_result) {
  6191. _result = lcd_selftest_manual_fan_check(1, false); //print fan is stil turned on; check that it is spinning
  6192. if (!_result) _errno = 6; //print fan not spinning
  6193. }
  6194. else {
  6195. _errno = 10; //swapped fans
  6196. }
  6197. }
  6198. //SERIAL_ECHOPGM("Extruder fan speed: ");
  6199. //MYSERIAL.println(fan_speed[0]);
  6200. //SERIAL_ECHOPGM("Print fan speed: ");
  6201. //MYSERIAL.println(fan_speed[1]);
  6202. break;
  6203. }
  6204. if (!_result)
  6205. {
  6206. const char *_err;
  6207. lcd_selftest_error(_errno, _err, _err);
  6208. }
  6209. return _result;
  6210. }
  6211. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  6212. {
  6213. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  6214. int _step_block = 0;
  6215. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  6216. if (_clear) lcd_implementation_clear();
  6217. lcd.setCursor(0, 0);
  6218. if (_step == -1) lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6219. if (_step == 0) lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6220. if (_step == 1) lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6221. if (_step == 2) lcd_printPGM(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 r=0
  6222. if (_step == 3) lcd_printPGM(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 r=0
  6223. if (_step == 4) lcd_printPGM(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 r=0
  6224. if (_step == 5) lcd_printPGM(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 r=0
  6225. if (_step == 6) lcd_printPGM(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 r=0
  6226. if (_step == 7) lcd_printPGM(_T(MSG_SELFTEST_CHECK_BED));
  6227. if (_step == 8) lcd_printPGM(_T(MSG_SELFTEST_CHECK_BED));
  6228. if (_step == 9) lcd_printPGM(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6229. if (_step == 10) lcd_printPGM(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6230. if (_step == 11) lcd_printPGM(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 r=0
  6231. if (_step == 12) lcd_printPGM(_T(MSG_SELFTEST_FAILED));
  6232. if (_step == 13) lcd_printPGM(PSTR("Calibrating home"));
  6233. lcd.setCursor(0, 1);
  6234. lcd_printPGM(separator);
  6235. if ((_step >= -1) && (_step <= 1))
  6236. {
  6237. //SERIAL_ECHOLNPGM("Fan test");
  6238. lcd_print_at_PGM(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18 r=0
  6239. lcd.setCursor(18, 2);
  6240. (_step < 0) ? lcd.print(_indicator) : lcd.print("OK");
  6241. lcd_print_at_PGM(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18 r=0
  6242. lcd.setCursor(18, 3);
  6243. (_step < 1) ? lcd.print(_indicator) : lcd.print("OK");
  6244. }
  6245. else if (_step >= 9 && _step <= 10)
  6246. {
  6247. lcd_print_at_PGM(0, 2, _i("Filament sensor:"));////MSG_SELFTEST_FILAMENT_SENSOR c=18 r=0
  6248. lcd.setCursor(18, 2);
  6249. (_step == 9) ? lcd.print(_indicator) : lcd.print("OK");
  6250. }
  6251. else if (_step < 9)
  6252. {
  6253. //SERIAL_ECHOLNPGM("Other tests");
  6254. _step_block = 3;
  6255. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  6256. _step_block = 4;
  6257. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  6258. _step_block = 5;
  6259. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  6260. _step_block = 6;
  6261. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  6262. _step_block = 7;
  6263. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  6264. }
  6265. if (_delay > 0) delay_keep_alive(_delay);
  6266. _progress++;
  6267. return (_progress > _progress_scale * 2) ? 0 : _progress;
  6268. }
  6269. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  6270. {
  6271. lcd.setCursor(_col, _row);
  6272. switch (_state)
  6273. {
  6274. case 1:
  6275. lcd.print(_name);
  6276. lcd.setCursor(_col + strlen(_name), _row);
  6277. lcd.print(":");
  6278. lcd.setCursor(_col + strlen(_name) + 1, _row);
  6279. lcd.print(_indicator);
  6280. break;
  6281. case 2:
  6282. lcd.print(_name);
  6283. lcd.setCursor(_col + strlen(_name), _row);
  6284. lcd.print(":");
  6285. lcd.setCursor(_col + strlen(_name) + 1, _row);
  6286. lcd.print("OK");
  6287. break;
  6288. default:
  6289. lcd.print(_name);
  6290. }
  6291. }
  6292. /** End of menus **/
  6293. static void lcd_quick_feedback()
  6294. {
  6295. lcdDrawUpdate = 2;
  6296. button_pressed = false;
  6297. lcd_implementation_quick_feedback();
  6298. }
  6299. /** Menu action functions **/
  6300. /**
  6301. * @brief Go up in menu structure
  6302. * @param data one time action to be done before leaving menu e.g. saving data or 0
  6303. */
  6304. static void menu_action_back(menuFunc_t data)
  6305. {
  6306. if (data) data();
  6307. MenuStack::Record record = menuStack.pop();
  6308. lcd_goto_menu(record.menu);
  6309. encoderPosition = record.position;
  6310. }
  6311. /**
  6312. * @brief Go deeper into menu structure
  6313. * @param data nested menu
  6314. */
  6315. static void menu_action_submenu(menuFunc_t data) {
  6316. menuStack.push(currentMenu, encoderPosition);
  6317. lcd_goto_menu(data);
  6318. }
  6319. static void menu_action_gcode(const char* pgcode) {
  6320. enquecommand_P(pgcode);
  6321. }
  6322. static void menu_action_setlang(unsigned char lang)
  6323. {
  6324. if (lang <= LANG_ID_SEC)
  6325. {
  6326. lcd_set_lang(lang);
  6327. return;
  6328. }
  6329. uint16_t code = lang_get_code(lang);
  6330. if (code == lang_get_code(1))
  6331. {
  6332. lcd_set_lang(1);
  6333. return;
  6334. }
  6335. lcd_set_lang(lang);
  6336. }
  6337. static void menu_action_function(menuFunc_t data) {
  6338. (*data)();
  6339. }
  6340. static bool check_file(const char* filename) {
  6341. if (farm_mode) return true;
  6342. bool result = false;
  6343. uint32_t filesize;
  6344. card.openFile((char*)filename, true);
  6345. filesize = card.getFileSize();
  6346. if (filesize > END_FILE_SECTION) {
  6347. card.setIndex(filesize - END_FILE_SECTION);
  6348. }
  6349. while (!card.eof() && !result) {
  6350. card.sdprinting = true;
  6351. get_command();
  6352. result = check_commands();
  6353. }
  6354. card.printingHasFinished();
  6355. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  6356. lcd_finishstatus();
  6357. return result;
  6358. }
  6359. static void menu_action_sdfile(const char* filename, char* longFilename)
  6360. {
  6361. loading_flag = false;
  6362. char cmd[30];
  6363. char* c;
  6364. bool result = true;
  6365. sprintf_P(cmd, PSTR("M23 %s"), filename);
  6366. for (c = &cmd[4]; *c; c++)
  6367. *c = tolower(*c);
  6368. for (int i = 0; i < 8; i++) {
  6369. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, filename[i]);
  6370. }
  6371. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6372. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  6373. for (uint8_t i = 0; i < depth; i++) {
  6374. for (int j = 0; j < 8; j++) {
  6375. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
  6376. }
  6377. }
  6378. if (!check_file(filename)) {
  6379. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=2
  6380. lcd_update_enable(true);
  6381. }
  6382. if (result) {
  6383. enquecommand(cmd);
  6384. enquecommand_P(PSTR("M24"));
  6385. }
  6386. lcd_return_to_status();
  6387. }
  6388. static void menu_action_sddirectory(const char* filename, char* longFilename)
  6389. {
  6390. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6391. strcpy(dir_names[depth], filename);
  6392. MYSERIAL.println(dir_names[depth]);
  6393. card.chdir(filename);
  6394. encoderPosition = 0;
  6395. }
  6396. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  6397. {
  6398. *ptr = !(*ptr);
  6399. }
  6400. /*
  6401. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  6402. {
  6403. menu_action_setting_edit_bool(pstr, ptr);
  6404. (*callback)();
  6405. }
  6406. */
  6407. #endif//ULTIPANEL
  6408. /** LCD API **/
  6409. void lcd_init()
  6410. {
  6411. lcd_implementation_init();
  6412. #ifdef NEWPANEL
  6413. SET_INPUT(BTN_EN1);
  6414. SET_INPUT(BTN_EN2);
  6415. WRITE(BTN_EN1, HIGH);
  6416. WRITE(BTN_EN2, HIGH);
  6417. #if BTN_ENC > 0
  6418. SET_INPUT(BTN_ENC);
  6419. WRITE(BTN_ENC, HIGH);
  6420. #endif
  6421. #ifdef REPRAPWORLD_KEYPAD
  6422. pinMode(SHIFT_CLK, OUTPUT);
  6423. pinMode(SHIFT_LD, OUTPUT);
  6424. pinMode(SHIFT_OUT, INPUT);
  6425. WRITE(SHIFT_OUT, HIGH);
  6426. WRITE(SHIFT_LD, HIGH);
  6427. #endif
  6428. #else // Not NEWPANEL
  6429. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  6430. pinMode (SR_DATA_PIN, OUTPUT);
  6431. pinMode (SR_CLK_PIN, OUTPUT);
  6432. #elif defined(SHIFT_CLK)
  6433. pinMode(SHIFT_CLK, OUTPUT);
  6434. pinMode(SHIFT_LD, OUTPUT);
  6435. pinMode(SHIFT_EN, OUTPUT);
  6436. pinMode(SHIFT_OUT, INPUT);
  6437. WRITE(SHIFT_OUT, HIGH);
  6438. WRITE(SHIFT_LD, HIGH);
  6439. WRITE(SHIFT_EN, LOW);
  6440. #else
  6441. #ifdef ULTIPANEL
  6442. #error ULTIPANEL requires an encoder
  6443. #endif
  6444. #endif // SR_LCD_2W_NL
  6445. #endif//!NEWPANEL
  6446. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  6447. pinMode(SDCARDDETECT, INPUT);
  6448. WRITE(SDCARDDETECT, HIGH);
  6449. lcd_oldcardstatus = IS_SD_INSERTED;
  6450. #endif//(SDCARDDETECT > 0)
  6451. #ifdef LCD_HAS_SLOW_BUTTONS
  6452. slow_buttons = 0;
  6453. #endif
  6454. lcd_buttons_update();
  6455. #ifdef ULTIPANEL
  6456. encoderDiff = 0;
  6457. #endif
  6458. }
  6459. //#include <avr/pgmspace.h>
  6460. static volatile bool lcd_update_enabled = true;
  6461. unsigned long lcd_timeoutToStatus = 0;
  6462. void lcd_update_enable(bool enabled)
  6463. {
  6464. if (lcd_update_enabled != enabled) {
  6465. lcd_update_enabled = enabled;
  6466. if (enabled) {
  6467. // Reset encoder position. This is equivalent to re-entering a menu.
  6468. encoderPosition = 0;
  6469. encoderDiff = 0;
  6470. // Enabling the normal LCD update procedure.
  6471. // Reset the timeout interval.
  6472. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6473. // Force the keypad update now.
  6474. lcd_next_update_millis = millis() - 1;
  6475. // Full update.
  6476. lcd_implementation_clear();
  6477. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6478. lcd_set_custom_characters(currentMenu == lcd_status_screen);
  6479. #else
  6480. if (currentMenu == lcd_status_screen)
  6481. lcd_set_custom_characters_degree();
  6482. else
  6483. lcd_set_custom_characters_arrows();
  6484. #endif
  6485. lcd_update(2);
  6486. } else {
  6487. // Clear the LCD always, or let it to the caller?
  6488. }
  6489. }
  6490. }
  6491. void lcd_update(uint8_t lcdDrawUpdateOverride)
  6492. {
  6493. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  6494. lcdDrawUpdate = lcdDrawUpdateOverride;
  6495. if (!lcd_update_enabled)
  6496. return;
  6497. #ifdef LCD_HAS_SLOW_BUTTONS
  6498. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  6499. #endif
  6500. lcd_buttons_update();
  6501. #if (SDCARDDETECT > 0)
  6502. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  6503. {
  6504. lcdDrawUpdate = 2;
  6505. lcd_oldcardstatus = IS_SD_INSERTED;
  6506. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  6507. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6508. currentMenu == lcd_status_screen
  6509. #endif
  6510. );
  6511. if (lcd_oldcardstatus)
  6512. {
  6513. card.initsd();
  6514. LCD_MESSAGERPGM(_i("Card inserted"));////MSG_SD_INSERTED c=0 r=0
  6515. //get_description();
  6516. }
  6517. else
  6518. {
  6519. card.release();
  6520. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=0 r=0
  6521. }
  6522. }
  6523. #endif//CARDINSERTED
  6524. if (lcd_next_update_millis < millis())
  6525. {
  6526. #ifdef DEBUG_BLINK_ACTIVE
  6527. static bool active_led = false;
  6528. active_led = !active_led;
  6529. pinMode(LED_PIN, OUTPUT);
  6530. digitalWrite(LED_PIN, active_led?HIGH:LOW);
  6531. #endif //DEBUG_BLINK_ACTIVE
  6532. #ifdef ULTIPANEL
  6533. #ifdef REPRAPWORLD_KEYPAD
  6534. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  6535. reprapworld_keypad_move_z_up();
  6536. }
  6537. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  6538. reprapworld_keypad_move_z_down();
  6539. }
  6540. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  6541. reprapworld_keypad_move_x_left();
  6542. }
  6543. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  6544. reprapworld_keypad_move_x_right();
  6545. }
  6546. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  6547. reprapworld_keypad_move_y_down();
  6548. }
  6549. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  6550. reprapworld_keypad_move_y_up();
  6551. }
  6552. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  6553. reprapworld_keypad_move_home();
  6554. }
  6555. #endif
  6556. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  6557. {
  6558. if (lcdDrawUpdate == 0)
  6559. lcdDrawUpdate = 1;
  6560. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  6561. encoderDiff = 0;
  6562. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6563. }
  6564. if (LCD_CLICKED) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6565. #endif//ULTIPANEL
  6566. (*currentMenu)();
  6567. #ifdef LCD_HAS_STATUS_INDICATORS
  6568. lcd_implementation_update_indicators();
  6569. #endif
  6570. #ifdef ULTIPANEL
  6571. if (lcd_timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  6572. {
  6573. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  6574. // to give it a chance to save its state.
  6575. // This is useful for example, when the babystep value has to be written into EEPROM.
  6576. if (currentMenu != NULL) {
  6577. menuExiting = true;
  6578. (*currentMenu)();
  6579. menuExiting = false;
  6580. }
  6581. lcd_implementation_clear();
  6582. lcd_return_to_status();
  6583. lcdDrawUpdate = 2;
  6584. }
  6585. #endif//ULTIPANEL
  6586. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  6587. if (lcdDrawUpdate) lcdDrawUpdate--;
  6588. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  6589. }
  6590. if (!SdFatUtil::test_stack_integrity()) stack_error();
  6591. #ifdef DEBUG_STEPPER_TIMER_MISSED
  6592. if (stepper_timer_overflow_state) stepper_timer_overflow();
  6593. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  6594. lcd_ping(); //check that we have received ping command if we are in farm mode
  6595. lcd_send_status();
  6596. if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
  6597. }
  6598. void lcd_printer_connected() {
  6599. printer_connected = true;
  6600. }
  6601. static void lcd_send_status() {
  6602. if (farm_mode && no_response && ((millis() - NcTime) > (NC_TIME * 1000))) {
  6603. //send important status messages periodicaly
  6604. prusa_statistics(important_status, saved_filament_type);
  6605. NcTime = millis();
  6606. lcd_connect_printer();
  6607. }
  6608. }
  6609. static void lcd_connect_printer() {
  6610. lcd_update_enable(false);
  6611. lcd_implementation_clear();
  6612. bool pressed = false;
  6613. int i = 0;
  6614. int t = 0;
  6615. lcd_set_custom_characters_progress();
  6616. lcd_implementation_print_at(0, 0, "Connect printer to");
  6617. lcd_implementation_print_at(0, 1, "monitoring or hold");
  6618. lcd_implementation_print_at(0, 2, "the knob to continue");
  6619. while (no_response) {
  6620. i++;
  6621. t++;
  6622. delay_keep_alive(100);
  6623. proc_commands();
  6624. if (t == 10) {
  6625. prusa_statistics(important_status, saved_filament_type);
  6626. t = 0;
  6627. }
  6628. if (READ(BTN_ENC)) { //if button is not pressed
  6629. i = 0;
  6630. lcd_implementation_print_at(0, 3, " ");
  6631. }
  6632. if (i!=0) lcd_implementation_print_at((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\x01");
  6633. if (i == NC_BUTTON_LONG_PRESS * 10) {
  6634. no_response = false;
  6635. }
  6636. }
  6637. lcd_set_custom_characters_degree();
  6638. lcd_update_enable(true);
  6639. lcd_update(2);
  6640. }
  6641. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  6642. if (farm_mode) {
  6643. bool empty = is_buffer_empty();
  6644. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  6645. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  6646. //therefore longer period is used
  6647. printer_connected = false;
  6648. }
  6649. else {
  6650. lcd_printer_connected();
  6651. }
  6652. }
  6653. }
  6654. void lcd_ignore_click(bool b)
  6655. {
  6656. ignore_click = b;
  6657. wait_for_unclick = false;
  6658. }
  6659. void lcd_finishstatus() {
  6660. int len = strlen(lcd_status_message);
  6661. if (len > 0) {
  6662. while (len < LCD_WIDTH) {
  6663. lcd_status_message[len++] = ' ';
  6664. }
  6665. }
  6666. lcd_status_message[LCD_WIDTH] = '\0';
  6667. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6668. #if PROGRESS_MSG_EXPIRE > 0
  6669. messageTick =
  6670. #endif
  6671. progressBarTick = millis();
  6672. #endif
  6673. lcdDrawUpdate = 2;
  6674. #ifdef FILAMENT_LCD_DISPLAY
  6675. message_millis = millis(); //get status message to show up for a while
  6676. #endif
  6677. }
  6678. void lcd_setstatus(const char* message)
  6679. {
  6680. if (lcd_status_message_level > 0)
  6681. return;
  6682. strncpy(lcd_status_message, message, LCD_WIDTH);
  6683. lcd_finishstatus();
  6684. }
  6685. void lcd_setstatuspgm(const char* message)
  6686. {
  6687. if (lcd_status_message_level > 0)
  6688. return;
  6689. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6690. lcd_status_message[LCD_WIDTH] = 0;
  6691. lcd_finishstatus();
  6692. }
  6693. void lcd_setalertstatuspgm(const char* message)
  6694. {
  6695. lcd_setstatuspgm(message);
  6696. lcd_status_message_level = 1;
  6697. #ifdef ULTIPANEL
  6698. lcd_return_to_status();
  6699. #endif//ULTIPANEL
  6700. }
  6701. void lcd_reset_alert_level()
  6702. {
  6703. lcd_status_message_level = 0;
  6704. }
  6705. uint8_t get_message_level()
  6706. {
  6707. return lcd_status_message_level;
  6708. }
  6709. #ifdef DOGLCD
  6710. void lcd_setcontrast(uint8_t value)
  6711. {
  6712. lcd_contrast = value & 63;
  6713. u8g.setContrast(lcd_contrast);
  6714. }
  6715. #endif
  6716. #ifdef ULTIPANEL
  6717. /* Warning: This function is called from interrupt context */
  6718. void lcd_buttons_update()
  6719. {
  6720. static bool _lock = false;
  6721. if (_lock) return;
  6722. _lock = true;
  6723. #ifdef NEWPANEL
  6724. uint8_t newbutton = 0;
  6725. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  6726. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  6727. #if BTN_ENC > 0
  6728. if (lcd_update_enabled == true) { //if we are in non-modal mode, long press can be used and short press triggers with button release
  6729. if (READ(BTN_ENC) == 0) { //button is pressed
  6730. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6731. if (millis() > button_blanking_time) {
  6732. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6733. if (button_pressed == false && long_press_active == false) {
  6734. longPressTimer.start();
  6735. button_pressed = true;
  6736. }
  6737. else {
  6738. if (longPressTimer.expired(LONG_PRESS_TIME)) {
  6739. long_press_active = true;
  6740. move_menu_scale = 1.0;
  6741. menu_action_submenu(lcd_move_z);
  6742. }
  6743. }
  6744. }
  6745. }
  6746. else { //button not pressed
  6747. if (button_pressed) { //button was released
  6748. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6749. if (long_press_active == false) { //button released before long press gets activated
  6750. newbutton |= EN_C;
  6751. }
  6752. else if (currentMenu == lcd_move_z) lcd_quick_feedback();
  6753. //button_pressed is set back to false via lcd_quick_feedback function
  6754. }
  6755. else {
  6756. long_press_active = false;
  6757. }
  6758. }
  6759. }
  6760. else { //we are in modal mode
  6761. if (READ(BTN_ENC) == 0)
  6762. newbutton |= EN_C;
  6763. }
  6764. #endif
  6765. buttons = newbutton;
  6766. #ifdef LCD_HAS_SLOW_BUTTONS
  6767. buttons |= slow_buttons;
  6768. #endif
  6769. #ifdef REPRAPWORLD_KEYPAD
  6770. // for the reprapworld_keypad
  6771. uint8_t newbutton_reprapworld_keypad = 0;
  6772. WRITE(SHIFT_LD, LOW);
  6773. WRITE(SHIFT_LD, HIGH);
  6774. for (int8_t i = 0; i < 8; i++) {
  6775. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  6776. if (READ(SHIFT_OUT))
  6777. newbutton_reprapworld_keypad |= (1 << 7);
  6778. WRITE(SHIFT_CLK, HIGH);
  6779. WRITE(SHIFT_CLK, LOW);
  6780. }
  6781. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  6782. #endif
  6783. #else //read it from the shift register
  6784. uint8_t newbutton = 0;
  6785. WRITE(SHIFT_LD, LOW);
  6786. WRITE(SHIFT_LD, HIGH);
  6787. unsigned char tmp_buttons = 0;
  6788. for (int8_t i = 0; i < 8; i++)
  6789. {
  6790. newbutton = newbutton >> 1;
  6791. if (READ(SHIFT_OUT))
  6792. newbutton |= (1 << 7);
  6793. WRITE(SHIFT_CLK, HIGH);
  6794. WRITE(SHIFT_CLK, LOW);
  6795. }
  6796. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  6797. #endif//!NEWPANEL
  6798. //manage encoder rotation
  6799. uint8_t enc = 0;
  6800. if (buttons & EN_A) enc |= B01;
  6801. if (buttons & EN_B) enc |= B10;
  6802. if (enc != lastEncoderBits)
  6803. {
  6804. switch (enc)
  6805. {
  6806. case encrot0:
  6807. if (lastEncoderBits == encrot3)
  6808. encoderDiff++;
  6809. else if (lastEncoderBits == encrot1)
  6810. encoderDiff--;
  6811. break;
  6812. case encrot1:
  6813. if (lastEncoderBits == encrot0)
  6814. encoderDiff++;
  6815. else if (lastEncoderBits == encrot2)
  6816. encoderDiff--;
  6817. break;
  6818. case encrot2:
  6819. if (lastEncoderBits == encrot1)
  6820. encoderDiff++;
  6821. else if (lastEncoderBits == encrot3)
  6822. encoderDiff--;
  6823. break;
  6824. case encrot3:
  6825. if (lastEncoderBits == encrot2)
  6826. encoderDiff++;
  6827. else if (lastEncoderBits == encrot0)
  6828. encoderDiff--;
  6829. break;
  6830. }
  6831. }
  6832. lastEncoderBits = enc;
  6833. _lock = false;
  6834. }
  6835. bool lcd_detected(void)
  6836. {
  6837. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  6838. return lcd.LcdDetected() == 1;
  6839. #else
  6840. return true;
  6841. #endif
  6842. }
  6843. void lcd_buzz(long duration, uint16_t freq)
  6844. {
  6845. #ifdef LCD_USE_I2C_BUZZER
  6846. lcd.buzz(duration, freq);
  6847. #endif
  6848. }
  6849. bool lcd_clicked()
  6850. {
  6851. bool clicked = LCD_CLICKED;
  6852. if(clicked) button_pressed = false;
  6853. return clicked;
  6854. }
  6855. #endif//ULTIPANEL
  6856. /********************************/
  6857. /** Float conversion utilities **/
  6858. /********************************/
  6859. // convert float to string with +123.4 format
  6860. char conv[8];
  6861. char *ftostr3(const float &x)
  6862. {
  6863. return itostr3((int)x);
  6864. }
  6865. char *itostr2(const uint8_t &x)
  6866. {
  6867. //sprintf(conv,"%5.1f",x);
  6868. int xx = x;
  6869. conv[0] = (xx / 10) % 10 + '0';
  6870. conv[1] = (xx) % 10 + '0';
  6871. conv[2] = 0;
  6872. return conv;
  6873. }
  6874. // Convert float to string with 123.4 format, dropping sign
  6875. char *ftostr31(const float &x)
  6876. {
  6877. int xx = x * 10;
  6878. conv[0] = (xx >= 0) ? '+' : '-';
  6879. xx = abs(xx);
  6880. conv[1] = (xx / 1000) % 10 + '0';
  6881. conv[2] = (xx / 100) % 10 + '0';
  6882. conv[3] = (xx / 10) % 10 + '0';
  6883. conv[4] = '.';
  6884. conv[5] = (xx) % 10 + '0';
  6885. conv[6] = 0;
  6886. return conv;
  6887. }
  6888. // Convert float to string with 123.4 format
  6889. char *ftostr31ns(const float &x)
  6890. {
  6891. int xx = x * 10;
  6892. //conv[0]=(xx>=0)?'+':'-';
  6893. xx = abs(xx);
  6894. conv[0] = (xx / 1000) % 10 + '0';
  6895. conv[1] = (xx / 100) % 10 + '0';
  6896. conv[2] = (xx / 10) % 10 + '0';
  6897. conv[3] = '.';
  6898. conv[4] = (xx) % 10 + '0';
  6899. conv[5] = 0;
  6900. return conv;
  6901. }
  6902. char *ftostr32(const float &x)
  6903. {
  6904. long xx = x * 100;
  6905. if (xx >= 0)
  6906. conv[0] = (xx / 10000) % 10 + '0';
  6907. else
  6908. conv[0] = '-';
  6909. xx = abs(xx);
  6910. conv[1] = (xx / 1000) % 10 + '0';
  6911. conv[2] = (xx / 100) % 10 + '0';
  6912. conv[3] = '.';
  6913. conv[4] = (xx / 10) % 10 + '0';
  6914. conv[5] = (xx) % 10 + '0';
  6915. conv[6] = 0;
  6916. return conv;
  6917. }
  6918. //// Convert float to rj string with 123.45 format
  6919. char *ftostr32ns(const float &x) {
  6920. long xx = abs(x);
  6921. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6922. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6923. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  6924. conv[3] = '.';
  6925. conv[4] = (xx / 10) % 10 + '0';
  6926. conv[5] = xx % 10 + '0';
  6927. return conv;
  6928. }
  6929. // Convert float to string with 1.234 format
  6930. char *ftostr43(const float &x, uint8_t offset)
  6931. {
  6932. const size_t maxOffset = sizeof(conv)/sizeof(conv[0]) - 6;
  6933. if (offset>maxOffset) offset = maxOffset;
  6934. long xx = x * 1000;
  6935. if (xx >= 0)
  6936. conv[offset] = (xx / 1000) % 10 + '0';
  6937. else
  6938. conv[offset] = '-';
  6939. xx = abs(xx);
  6940. conv[offset + 1] = '.';
  6941. conv[offset + 2] = (xx / 100) % 10 + '0';
  6942. conv[offset + 3] = (xx / 10) % 10 + '0';
  6943. conv[offset + 4] = (xx) % 10 + '0';
  6944. conv[offset + 5] = 0;
  6945. return conv;
  6946. }
  6947. //Float to string with 1.23 format
  6948. char *ftostr12ns(const float &x)
  6949. {
  6950. long xx = x * 100;
  6951. xx = abs(xx);
  6952. conv[0] = (xx / 100) % 10 + '0';
  6953. conv[1] = '.';
  6954. conv[2] = (xx / 10) % 10 + '0';
  6955. conv[3] = (xx) % 10 + '0';
  6956. conv[4] = 0;
  6957. return conv;
  6958. }
  6959. //Float to string with 1.234 format
  6960. char *ftostr13ns(const float &x)
  6961. {
  6962. long xx = x * 1000;
  6963. if (xx >= 0)
  6964. conv[0] = ' ';
  6965. else
  6966. conv[0] = '-';
  6967. xx = abs(xx);
  6968. conv[1] = (xx / 1000) % 10 + '0';
  6969. conv[2] = '.';
  6970. conv[3] = (xx / 100) % 10 + '0';
  6971. conv[4] = (xx / 10) % 10 + '0';
  6972. conv[5] = (xx) % 10 + '0';
  6973. conv[6] = 0;
  6974. return conv;
  6975. }
  6976. // convert float to space-padded string with -_23.4_ format
  6977. char *ftostr32sp(const float &x) {
  6978. long xx = abs(x * 100);
  6979. uint8_t dig;
  6980. if (x < 0) { // negative val = -_0
  6981. conv[0] = '-';
  6982. dig = (xx / 1000) % 10;
  6983. conv[1] = dig ? '0' + dig : ' ';
  6984. }
  6985. else { // positive val = __0
  6986. dig = (xx / 10000) % 10;
  6987. if (dig) {
  6988. conv[0] = '0' + dig;
  6989. conv[1] = '0' + (xx / 1000) % 10;
  6990. }
  6991. else {
  6992. conv[0] = ' ';
  6993. dig = (xx / 1000) % 10;
  6994. conv[1] = dig ? '0' + dig : ' ';
  6995. }
  6996. }
  6997. conv[2] = '0' + (xx / 100) % 10; // lsd always
  6998. dig = xx % 10;
  6999. if (dig) { // 2 decimal places
  7000. conv[5] = '0' + dig;
  7001. conv[4] = '0' + (xx / 10) % 10;
  7002. conv[3] = '.';
  7003. }
  7004. else { // 1 or 0 decimal place
  7005. dig = (xx / 10) % 10;
  7006. if (dig) {
  7007. conv[4] = '0' + dig;
  7008. conv[3] = '.';
  7009. }
  7010. else {
  7011. conv[3] = conv[4] = ' ';
  7012. }
  7013. conv[5] = ' ';
  7014. }
  7015. conv[6] = '\0';
  7016. return conv;
  7017. }
  7018. char *itostr31(const int &xx)
  7019. {
  7020. conv[0] = (xx >= 0) ? '+' : '-';
  7021. conv[1] = (xx / 1000) % 10 + '0';
  7022. conv[2] = (xx / 100) % 10 + '0';
  7023. conv[3] = (xx / 10) % 10 + '0';
  7024. conv[4] = '.';
  7025. conv[5] = (xx) % 10 + '0';
  7026. conv[6] = 0;
  7027. return conv;
  7028. }
  7029. // Convert int to rj string with 123 or -12 format
  7030. char *itostr3(const int &x)
  7031. {
  7032. int xx = x;
  7033. if (xx < 0) {
  7034. conv[0] = '-';
  7035. xx = -xx;
  7036. } else if (xx >= 100)
  7037. conv[0] = (xx / 100) % 10 + '0';
  7038. else
  7039. conv[0] = ' ';
  7040. if (xx >= 10)
  7041. conv[1] = (xx / 10) % 10 + '0';
  7042. else
  7043. conv[1] = ' ';
  7044. conv[2] = (xx) % 10 + '0';
  7045. conv[3] = 0;
  7046. return conv;
  7047. }
  7048. // Convert int to lj string with 123 format
  7049. char *itostr3left(const int &xx)
  7050. {
  7051. if (xx >= 100)
  7052. {
  7053. conv[0] = (xx / 100) % 10 + '0';
  7054. conv[1] = (xx / 10) % 10 + '0';
  7055. conv[2] = (xx) % 10 + '0';
  7056. conv[3] = 0;
  7057. }
  7058. else if (xx >= 10)
  7059. {
  7060. conv[0] = (xx / 10) % 10 + '0';
  7061. conv[1] = (xx) % 10 + '0';
  7062. conv[2] = 0;
  7063. }
  7064. else
  7065. {
  7066. conv[0] = (xx) % 10 + '0';
  7067. conv[1] = 0;
  7068. }
  7069. return conv;
  7070. }
  7071. // Convert int to rj string with 1234 format
  7072. char *itostr4(const int &xx) {
  7073. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  7074. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  7075. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  7076. conv[3] = xx % 10 + '0';
  7077. conv[4] = 0;
  7078. return conv;
  7079. }
  7080. // Convert float to rj string with 12345 format
  7081. char *ftostr5(const float &x) {
  7082. long xx = abs(x);
  7083. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  7084. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  7085. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  7086. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  7087. conv[4] = xx % 10 + '0';
  7088. conv[5] = 0;
  7089. return conv;
  7090. }
  7091. // Convert float to string with +1234.5 format
  7092. char *ftostr51(const float &x)
  7093. {
  7094. long xx = x * 10;
  7095. conv[0] = (xx >= 0) ? '+' : '-';
  7096. xx = abs(xx);
  7097. conv[1] = (xx / 10000) % 10 + '0';
  7098. conv[2] = (xx / 1000) % 10 + '0';
  7099. conv[3] = (xx / 100) % 10 + '0';
  7100. conv[4] = (xx / 10) % 10 + '0';
  7101. conv[5] = '.';
  7102. conv[6] = (xx) % 10 + '0';
  7103. conv[7] = 0;
  7104. return conv;
  7105. }
  7106. // Convert float to string with +123.45 format
  7107. char *ftostr52(const float &x)
  7108. {
  7109. long xx = x * 100;
  7110. conv[0] = (xx >= 0) ? '+' : '-';
  7111. xx = abs(xx);
  7112. conv[1] = (xx / 10000) % 10 + '0';
  7113. conv[2] = (xx / 1000) % 10 + '0';
  7114. conv[3] = (xx / 100) % 10 + '0';
  7115. conv[4] = '.';
  7116. conv[5] = (xx / 10) % 10 + '0';
  7117. conv[6] = (xx) % 10 + '0';
  7118. conv[7] = 0;
  7119. return conv;
  7120. }
  7121. /*
  7122. // Callback for after editing PID i value
  7123. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  7124. void copy_and_scalePID_i()
  7125. {
  7126. #ifdef PIDTEMP
  7127. Ki = scalePID_i(raw_Ki);
  7128. updatePID();
  7129. #endif
  7130. }
  7131. // Callback for after editing PID d value
  7132. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  7133. void copy_and_scalePID_d()
  7134. {
  7135. #ifdef PIDTEMP
  7136. Kd = scalePID_d(raw_Kd);
  7137. updatePID();
  7138. #endif
  7139. }
  7140. */
  7141. #endif //ULTRA_LCD