ultralcd.cpp 235 KB

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