ultralcd.cpp 230 KB

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