ultralcd.cpp 210 KB

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