ultralcd.cpp 211 KB

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