ultralcd.cpp 233 KB

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