ultralcd.cpp 198 KB

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