ultralcd.cpp 186 KB

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