ultralcd.cpp 199 KB

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