ultralcd.cpp 182 KB

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