ultralcd.cpp 200 KB

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