ultralcd.cpp 220 KB

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