ultralcd.cpp 234 KB

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