ultralcd.cpp 197 KB

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