ultralcd.cpp 186 KB

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