ultralcd.cpp 189 KB

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