ultralcd.cpp 235 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #include "fsensor.h"
  4. #ifdef ULTRA_LCD
  5. #include "MenuStack.h"
  6. #include "Marlin.h"
  7. #include "language.h"
  8. #include "cardreader.h"
  9. #include "temperature.h"
  10. #include "stepper.h"
  11. #include "ConfigurationStore.h"
  12. #include <string.h>
  13. #include "Timer.h"
  14. #include "util.h"
  15. #include "mesh_bed_leveling.h"
  16. //#include "Configuration.h"
  17. #include "cmdqueue.h"
  18. #include "SdFatUtil.h"
  19. #ifdef PAT9125
  20. #include "pat9125.h"
  21. #endif //PAT9125
  22. #ifdef TMC2130
  23. #include "tmc2130.h"
  24. #endif //TMC2130
  25. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  26. extern int lcd_change_fil_state;
  27. extern bool fans_check_enabled;
  28. extern bool filament_autoload_enabled;
  29. #ifdef PAT9125
  30. extern bool fsensor_not_responding;
  31. extern bool fsensor_enabled;
  32. #endif //PAT9125
  33. //Function pointer to menu functions.
  34. static void lcd_sd_updir();
  35. struct EditMenuParentState
  36. {
  37. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  38. menuFunc_t prevMenu;
  39. uint16_t prevEncoderPosition;
  40. //Variables used when editing values.
  41. const char* editLabel;
  42. void* editValue;
  43. int32_t minEditValue, maxEditValue;
  44. // menuFunc_t callbackFunc;
  45. };
  46. union MenuData
  47. {
  48. struct BabyStep
  49. {
  50. // 29B total
  51. int8_t status;
  52. int babystepMem[3];
  53. float babystepMemMM[3];
  54. } babyStep;
  55. struct SupportMenu
  56. {
  57. // 6B+16B=22B total
  58. int8_t status;
  59. bool is_flash_air;
  60. uint8_t ip[4];
  61. char ip_str[3*4+3+1];
  62. } supportMenu;
  63. struct AdjustBed
  64. {
  65. // 6+13+16=35B
  66. // editMenuParentState is used when an edit menu is entered, so it knows
  67. // the return menu and encoder state.
  68. struct EditMenuParentState editMenuParentState;
  69. int8_t status;
  70. int8_t left;
  71. int8_t right;
  72. int8_t front;
  73. int8_t rear;
  74. int left2;
  75. int right2;
  76. int front2;
  77. int rear2;
  78. } adjustBed;
  79. struct TuneMenu
  80. {
  81. // editMenuParentState is used when an edit menu is entered, so it knows
  82. // the return menu and encoder state.
  83. struct EditMenuParentState editMenuParentState;
  84. // To recognize, whether the menu has been just initialized.
  85. int8_t status;
  86. // Backup of extrudemultiply, to recognize, that the value has been changed and
  87. // it needs to be applied.
  88. int16_t extrudemultiply;
  89. } tuneMenu;
  90. // editMenuParentState is used when an edit menu is entered, so it knows
  91. // the return menu and encoder state.
  92. struct EditMenuParentState editMenuParentState;
  93. struct AutoLoadFilamentMenu
  94. {
  95. //ShortTimer timer;
  96. char dummy;
  97. } autoLoadFilamentMenu;
  98. struct _Lcd_moveMenu
  99. {
  100. bool initialized;
  101. bool endstopsEnabledPrevious;
  102. } _lcd_moveMenu;
  103. struct sdcard_menu_t
  104. {
  105. uint8_t viewState;
  106. } sdcard_menu;
  107. };
  108. // State of the currently active menu.
  109. // C Union manages sharing of the static memory by all the menus.
  110. union MenuData menuData = { 0 };
  111. union Data
  112. {
  113. byte b[2];
  114. int value;
  115. };
  116. static MenuStack menuStack;
  117. int8_t ReInitLCD = 0;
  118. int8_t SDscrool = 0;
  119. int8_t SilentModeMenu = SILENT_MODE_OFF;
  120. int8_t FSensorStateMenu = 1;
  121. int8_t CrashDetectMenu = 1;
  122. extern void fsensor_block();
  123. extern void fsensor_unblock();
  124. extern bool fsensor_enable();
  125. extern void fsensor_disable();
  126. #ifdef TMC2130
  127. extern void crashdet_enable();
  128. extern void crashdet_disable();
  129. #endif //TMC2130
  130. #ifdef SNMM
  131. uint8_t snmm_extruder = 0;
  132. #endif
  133. #ifdef SDCARD_SORT_ALPHA
  134. bool presort_flag = false;
  135. #endif
  136. int lcd_commands_type=LCD_COMMAND_IDLE;
  137. int lcd_commands_step=0;
  138. bool isPrintPaused = false;
  139. uint8_t farm_mode = 0;
  140. int farm_no = 0;
  141. int farm_timer = 8;
  142. int farm_status = 0;
  143. bool printer_connected = true;
  144. unsigned long display_time; //just timer for showing pid finished message on lcd;
  145. float pid_temp = DEFAULT_PID_TEMP;
  146. bool long_press_active = false;
  147. static ShortTimer longPressTimer;
  148. unsigned long button_blanking_time = millis();
  149. bool button_pressed = false;
  150. bool menuExiting = false;
  151. #ifdef FILAMENT_LCD_DISPLAY
  152. unsigned long message_millis = 0;
  153. #endif
  154. #ifdef ULTIPANEL
  155. static float manual_feedrate[] = MANUAL_FEEDRATE;
  156. #endif // ULTIPANEL
  157. /* !Configuration settings */
  158. uint8_t lcd_status_message_level;
  159. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  160. unsigned char firstrun = 1;
  161. #include "ultralcd_implementation_hitachi_HD44780.h"
  162. static const char separator[] PROGMEM = "--------------------";
  163. /** forward declarations **/
  164. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines);
  165. // void copy_and_scalePID_i();
  166. // void copy_and_scalePID_d();
  167. /* Different menus */
  168. static void lcd_status_screen();
  169. #ifdef ULTIPANEL
  170. extern bool powersupply;
  171. static void lcd_main_menu();
  172. static void lcd_tune_menu();
  173. static void lcd_prepare_menu();
  174. //static void lcd_move_menu();
  175. static void lcd_settings_menu();
  176. static void lcd_calibration_menu();
  177. static void lcd_control_temperature_menu();
  178. static void lcd_control_temperature_preheat_pla_settings_menu();
  179. static void lcd_control_temperature_preheat_abs_settings_menu();
  180. static void lcd_control_motion_menu();
  181. static void lcd_control_volumetric_menu();
  182. static void lcd_settings_menu_back();
  183. static void prusa_stat_printerstatus(int _status);
  184. static void prusa_stat_farm_number();
  185. static void prusa_stat_temperatures();
  186. static void prusa_stat_printinfo();
  187. static void lcd_farm_no();
  188. static void lcd_menu_extruder_info();
  189. static void lcd_menu_xyz_y_min();
  190. static void lcd_menu_xyz_skew();
  191. static void lcd_menu_xyz_offset();
  192. #if defined(TMC2130) || defined(PAT9125)
  193. static void lcd_menu_fails_stats();
  194. #endif //TMC2130 or PAT9125
  195. void lcd_finishstatus();
  196. #ifdef DOGLCD
  197. static void lcd_set_contrast();
  198. #endif
  199. static void lcd_control_retract_menu();
  200. static void lcd_sdcard_menu();
  201. #ifdef DELTA_CALIBRATION_MENU
  202. static void lcd_delta_calibrate_menu();
  203. #endif // DELTA_CALIBRATION_MENU
  204. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  205. /* Different types of actions that can be used in menu items. */
  206. static void menu_action_sdfile(const char* filename, char* longFilename);
  207. static void menu_action_sddirectory(const char* filename, char* longFilename);
  208. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  209. static void menu_action_setting_edit_wfac(const char* pstr, uint8_t* ptr, uint8_t minValue, uint8_t maxValue);
  210. static void menu_action_setting_edit_mres(const char* pstr, uint8_t* ptr, uint8_t minValue, uint8_t maxValue);
  211. static void menu_action_setting_edit_byte3(const char* pstr, uint8_t* ptr, uint8_t minValue, uint8_t maxValue);
  212. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  213. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  214. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  215. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  216. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  217. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  218. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  219. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  220. /*
  221. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  222. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  223. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  224. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  225. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  226. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  227. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  228. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  229. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  230. */
  231. #define ENCODER_FEEDRATE_DEADZONE 10
  232. #if !defined(LCD_I2C_VIKI)
  233. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  234. #define ENCODER_STEPS_PER_MENU_ITEM 5
  235. #endif
  236. #ifndef ENCODER_PULSES_PER_STEP
  237. #define ENCODER_PULSES_PER_STEP 1
  238. #endif
  239. #else
  240. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  241. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  242. #endif
  243. #ifndef ENCODER_PULSES_PER_STEP
  244. #define ENCODER_PULSES_PER_STEP 1
  245. #endif
  246. #endif
  247. uint8_t _lineNr = 0;
  248. uint8_t _menuItemNr = 0;
  249. uint8_t _drawLineNr = 0;
  250. bool wasClicked = false;
  251. #define MENU_ITEM(type, label, args...) do { \
  252. if (_menuItemNr == _lineNr) { \
  253. if (lcdDrawUpdate) { \
  254. const char* _label_pstr = (label); \
  255. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  256. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  257. }else{\
  258. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  259. }\
  260. }\
  261. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  262. lcd_quick_feedback(); \
  263. menu_action_ ## type ( args ); \
  264. return;\
  265. }\
  266. }\
  267. _menuItemNr++;\
  268. } while(0)
  269. //#define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  270. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, (label) , ## args )
  271. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, (label) , ## args )
  272. /** Used variables to keep track of the menu */
  273. #ifndef REPRAPWORLD_KEYPAD
  274. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  275. #else
  276. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  277. #endif
  278. #ifdef LCD_HAS_SLOW_BUTTONS
  279. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  280. #endif
  281. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  282. uint8_t lastEncoderBits;
  283. uint32_t encoderPosition;
  284. #if (SDCARDDETECT > 0)
  285. bool lcd_oldcardstatus;
  286. #endif
  287. #endif //ULTIPANEL
  288. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  289. uint32_t lcd_next_update_millis;
  290. uint8_t lcd_status_update_delay;
  291. bool ignore_click = false;
  292. bool wait_for_unclick;
  293. 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) */
  294. // place-holders for Ki and Kd edits
  295. #ifdef PIDTEMP
  296. // float raw_Ki, raw_Kd;
  297. #endif
  298. /**
  299. * @brief Go to menu
  300. *
  301. * In MENU_ITEM_SUBMENU_P(str, func) use MENU_ITEM_BACK_P(str) or
  302. * menu_back() and menu_submenu() instead, otherwise menuStack will be broken.
  303. *
  304. * It is acceptable to call lcd_goto_menu(menu) directly from MENU_ITEM(function,...), if destination menu
  305. * is the same, from which function was called.
  306. *
  307. * @param menu target menu
  308. * @param encoder position in target menu
  309. * @param feedback
  310. * * true sound feedback (click)
  311. * * false no feedback
  312. * @param reset_menu_state
  313. * * true reset menu state global union
  314. * * false do not reset menu state global union
  315. */
  316. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder = 0, const bool feedback = true, bool reset_menu_state = true)
  317. {
  318. asm("cli");
  319. if (currentMenu != menu)
  320. {
  321. currentMenu = menu;
  322. encoderPosition = encoder;
  323. asm("sei");
  324. if (reset_menu_state)
  325. {
  326. // Resets the global shared C union.
  327. // This ensures, that the menu entered will find out, that it shall initialize itself.
  328. memset(&menuData, 0, sizeof(menuData));
  329. }
  330. if (feedback) lcd_quick_feedback();
  331. // For LCD_PROGRESS_BAR re-initialize the custom characters
  332. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  333. lcd_set_custom_characters(menu == lcd_status_screen);
  334. #endif
  335. }
  336. else
  337. asm("sei");
  338. }
  339. ////////////////////////////////////////////////////////////////////////////////
  340. // New Menu implementation
  341. #include <stdarg.h>
  342. int lcd_puts_P(const char* str)
  343. {
  344. return fputs_P(str, lcdout);
  345. }
  346. int lcd_putc(int c)
  347. {
  348. return fputc(c, lcdout);
  349. }
  350. int lcd_printf_P(const char* format, ...)
  351. {
  352. va_list args;
  353. va_start(args, format);
  354. int ret = vfprintf_P(lcdout, format, args);
  355. va_end(args);
  356. return ret;
  357. }
  358. #define MENU_BEGIN() menu_start(); for(_drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { _menuItemNr = 0;
  359. void menu_start(void)
  360. {
  361. if (encoderPosition > 0x8000) encoderPosition = 0;
  362. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset)
  363. currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;
  364. _lineNr = currentMenuViewOffset;
  365. wasClicked = LCD_CLICKED;
  366. }
  367. #define MENU_END() menu_end(); }
  368. void menu_end(void)
  369. {
  370. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr)
  371. encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1;
  372. if ((uint8_t)(encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) >= currentMenuViewOffset + LCD_HEIGHT)
  373. {
  374. currentMenuViewOffset = (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) - LCD_HEIGHT + 1;
  375. lcdDrawUpdate = 1;
  376. _lineNr = currentMenuViewOffset - 1;
  377. _drawLineNr = -1;
  378. }
  379. }
  380. void menu_back(void)
  381. {
  382. MenuStack::Record record = menuStack.pop();
  383. lcd_goto_menu(record.menu);
  384. encoderPosition = record.position;
  385. }
  386. void menu_back_if_clicked(void)
  387. {
  388. if (lcd_clicked())
  389. menu_back();
  390. }
  391. void menu_back_if_clicked_fb(void)
  392. {
  393. if (lcd_clicked())
  394. {
  395. lcd_quick_feedback();
  396. menu_back();
  397. }
  398. }
  399. void menu_submenu(menuFunc_t submenu)
  400. {
  401. menuStack.push(currentMenu, encoderPosition);
  402. lcd_goto_menu(submenu);
  403. }
  404. uint8_t menu_item_ret(void)
  405. {
  406. lcd_implementation_quick_feedback();
  407. lcdDrawUpdate = 2;
  408. button_pressed = false;
  409. return 1;
  410. }
  411. uint8_t menu_enc_is_at_item(void)
  412. {
  413. return ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr);
  414. }
  415. /*
  416. int menu_item_printf_P(char type_char, const char* format, ...)
  417. {
  418. va_list args;
  419. va_start(args, format);
  420. int ret = 0;
  421. lcd.setCursor(0, _drawLineNr);
  422. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr)
  423. lcd.print('>');
  424. else
  425. lcd.print(' ');
  426. int cnt = vfprintf_P(lcdout, format, args);
  427. for (int i = cnt; i < 18; i++)
  428. lcd.print(' ');
  429. lcd.print(type_char);
  430. va_end(args);
  431. return ret;
  432. }
  433. */
  434. int menu_draw_item_puts_P(char type_char, const char* str)
  435. {
  436. lcd.setCursor(0, _drawLineNr);
  437. int cnt = lcd_printf_P(_N("%c%-18S%c"), menu_enc_is_at_item()?'>':' ', str, type_char);
  438. return cnt;
  439. }
  440. #define MENU_ITEM_DUMMY() menu_item_dummy()
  441. inline void menu_item_dummy(void)
  442. {
  443. _menuItemNr++;
  444. }
  445. #define MENU_ITEM_TEXT_P(str) do { if (menu_item_text_P(str)) return; } while (0)
  446. uint8_t menu_item_text_P(const char* str)
  447. {
  448. if (_menuItemNr == _lineNr)
  449. {
  450. if (lcdDrawUpdate) menu_draw_item_puts_P(' ', str);
  451. if (wasClicked && menu_enc_is_at_item())
  452. return menu_item_ret();
  453. }
  454. _menuItemNr++;
  455. return 0;
  456. }
  457. #define MENU_ITEM_SUBMENU_P(str, submenu) do { if (menu_item_submenu_P(str, submenu)) return; } while (0)
  458. uint8_t menu_item_submenu_P(const char* str, menuFunc_t submenu)
  459. {
  460. if (_menuItemNr == _lineNr)
  461. {
  462. if (lcdDrawUpdate) menu_draw_item_puts_P(LCD_STR_ARROW_RIGHT[0], str);
  463. if (wasClicked && menu_enc_is_at_item())
  464. {
  465. menuStack.push(currentMenu, encoderPosition);
  466. lcd_goto_menu(submenu, 0, false, true);
  467. return menu_item_ret();
  468. }
  469. }
  470. _menuItemNr++;
  471. return 0;
  472. }
  473. #define MENU_ITEM_BACK_P(str) do { if (menu_item_back_P(str)) return; } while (0)
  474. uint8_t menu_item_back_P(const char* str)
  475. {
  476. if (_menuItemNr == _lineNr)
  477. {
  478. if (lcdDrawUpdate) menu_draw_item_puts_P(LCD_STR_UPLEVEL[0], str);
  479. if (wasClicked && menu_enc_is_at_item())
  480. {
  481. MenuStack::Record record = menuStack.pop();
  482. lcd_goto_menu(record.menu, false, true);
  483. encoderPosition = record.position;
  484. return menu_item_ret();
  485. }
  486. }
  487. _menuItemNr++;
  488. return 0;
  489. }
  490. #define MENU_ITEM_FUNCTION_P(str, func) do { if (menu_item_function_P(str, func)) return; } while (0)
  491. uint8_t menu_item_function_P(const char* str, menuFunc_t func)
  492. {
  493. if (_menuItemNr == _lineNr)
  494. {
  495. if (lcdDrawUpdate) menu_draw_item_puts_P(' ', str);
  496. if (wasClicked && menu_enc_is_at_item())
  497. {
  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. fautoload_set(!filament_autoload_enabled);
  1802. }
  1803. void lcd_unLoadFilament()
  1804. {
  1805. if (degHotend0() > EXTRUDE_MINTEMP) {
  1806. enquecommand_P(PSTR("M702")); //unload filament
  1807. } else {
  1808. lcd_implementation_clear();
  1809. lcd.setCursor(0, 0);
  1810. lcd_printPGM(_T(MSG_ERROR));
  1811. lcd.setCursor(0, 2);
  1812. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  1813. delay(2000);
  1814. lcd_implementation_clear();
  1815. }
  1816. menu_back();
  1817. }
  1818. void lcd_change_filament() {
  1819. lcd_implementation_clear();
  1820. lcd.setCursor(0, 1);
  1821. lcd_printPGM(_i("Changing filament!"));////MSG_CHANGING_FILAMENT c=20 r=0
  1822. }
  1823. void lcd_wait_interact() {
  1824. lcd_implementation_clear();
  1825. lcd.setCursor(0, 1);
  1826. #ifdef SNMM
  1827. lcd_printPGM(_i("Prepare new filament"));////MSG_PREPARE_FILAMENT c=20 r=1
  1828. #else
  1829. lcd_printPGM(_i("Insert filament"));////MSG_INSERT_FILAMENT c=20 r=0
  1830. #endif
  1831. lcd.setCursor(0, 2);
  1832. lcd_printPGM(_i("and press the knob"));////MSG_PRESS c=20 r=0
  1833. }
  1834. void lcd_change_success() {
  1835. lcd_implementation_clear();
  1836. lcd.setCursor(0, 2);
  1837. lcd_printPGM(_i("Change success!"));////MSG_CHANGE_SUCCESS c=0 r=0
  1838. }
  1839. void lcd_loading_color() {
  1840. lcd_implementation_clear();
  1841. lcd.setCursor(0, 0);
  1842. lcd_printPGM(_i("Loading color"));////MSG_LOADING_COLOR c=0 r=0
  1843. lcd.setCursor(0, 2);
  1844. lcd_printPGM(_T(MSG_PLEASE_WAIT));
  1845. for (int i = 0; i < 20; i++) {
  1846. lcd.setCursor(i, 3);
  1847. lcd.print(".");
  1848. for (int j = 0; j < 10 ; j++) {
  1849. manage_heater();
  1850. manage_inactivity(true);
  1851. delay(85);
  1852. }
  1853. }
  1854. }
  1855. void lcd_loading_filament() {
  1856. lcd_implementation_clear();
  1857. lcd.setCursor(0, 0);
  1858. lcd_printPGM(_T(MSG_LOADING_FILAMENT));
  1859. lcd.setCursor(0, 2);
  1860. lcd_printPGM(_T(MSG_PLEASE_WAIT));
  1861. for (int i = 0; i < 20; i++) {
  1862. lcd.setCursor(i, 3);
  1863. lcd.print(".");
  1864. for (int j = 0; j < 10 ; j++) {
  1865. manage_heater();
  1866. manage_inactivity(true);
  1867. #ifdef SNMM
  1868. delay(153);
  1869. #else
  1870. delay(137);
  1871. #endif
  1872. }
  1873. }
  1874. }
  1875. void lcd_alright() {
  1876. int enc_dif = 0;
  1877. int cursor_pos = 1;
  1878. lcd_implementation_clear();
  1879. lcd.setCursor(0, 0);
  1880. lcd_printPGM(_i("Changed correctly?"));////MSG_CORRECTLY c=20 r=0
  1881. lcd.setCursor(1, 1);
  1882. lcd_printPGM(_T(MSG_YES));
  1883. lcd.setCursor(1, 2);
  1884. lcd_printPGM(_i("Filament not loaded"));////MSG_NOT_LOADED c=19 r=0
  1885. lcd.setCursor(1, 3);
  1886. lcd_printPGM(_i("Color not correct"));////MSG_NOT_COLOR c=0 r=0
  1887. lcd.setCursor(0, 1);
  1888. lcd.print(">");
  1889. enc_dif = encoderDiff;
  1890. while (lcd_change_fil_state == 0) {
  1891. manage_heater();
  1892. manage_inactivity(true);
  1893. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1894. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1895. if (enc_dif > encoderDiff ) {
  1896. cursor_pos --;
  1897. }
  1898. if (enc_dif < encoderDiff ) {
  1899. cursor_pos ++;
  1900. }
  1901. if (cursor_pos > 3) {
  1902. cursor_pos = 3;
  1903. }
  1904. if (cursor_pos < 1) {
  1905. cursor_pos = 1;
  1906. }
  1907. lcd.setCursor(0, 1);
  1908. lcd.print(" ");
  1909. lcd.setCursor(0, 2);
  1910. lcd.print(" ");
  1911. lcd.setCursor(0, 3);
  1912. lcd.print(" ");
  1913. lcd.setCursor(0, cursor_pos);
  1914. lcd.print(">");
  1915. enc_dif = encoderDiff;
  1916. delay(100);
  1917. }
  1918. }
  1919. if (lcd_clicked()) {
  1920. lcd_change_fil_state = cursor_pos;
  1921. delay(500);
  1922. }
  1923. };
  1924. lcd_implementation_clear();
  1925. lcd_return_to_status();
  1926. }
  1927. #ifdef PAT9125
  1928. static void lcd_menu_AutoLoadFilament()
  1929. {
  1930. if (degHotend0() > EXTRUDE_MINTEMP)
  1931. {
  1932. uint8_t nlines;
  1933. 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
  1934. }
  1935. else
  1936. {
  1937. ShortTimer* ptimer = (ShortTimer*)&(menuData.autoLoadFilamentMenu.dummy);
  1938. if (!ptimer->running()) ptimer->start();
  1939. lcd.setCursor(0, 0);
  1940. lcd_printPGM(_T(MSG_ERROR));
  1941. lcd.setCursor(0, 2);
  1942. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  1943. if (ptimer->expired(2000ul)) menu_back();
  1944. }
  1945. menu_back_if_clicked();
  1946. }
  1947. #endif //PAT9125
  1948. static void lcd_LoadFilament()
  1949. {
  1950. if (degHotend0() > EXTRUDE_MINTEMP)
  1951. {
  1952. custom_message = true;
  1953. loading_flag = true;
  1954. enquecommand_P(PSTR("M701")); //load filament
  1955. SERIAL_ECHOLN("Loading filament");
  1956. lcd_return_to_status();
  1957. }
  1958. else
  1959. {
  1960. lcd_implementation_clear();
  1961. lcd.setCursor(0, 0);
  1962. lcd_printPGM(_T(MSG_ERROR));
  1963. lcd.setCursor(0, 2);
  1964. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  1965. delay(2000);
  1966. lcd_implementation_clear();
  1967. }
  1968. }
  1969. void lcd_menu_statistics()
  1970. {
  1971. if (IS_SD_PRINTING)
  1972. {
  1973. int _met = total_filament_used / 100000;
  1974. int _cm = (total_filament_used - (_met * 100000)) / 10;
  1975. int _t = (millis() - starttime) / 1000;
  1976. int _h = _t / 3600;
  1977. int _m = (_t - (_h * 3600)) / 60;
  1978. int _s = _t - ((_h * 3600) + (_m * 60));
  1979. //|01234567890123456789|
  1980. //|Filament used: |
  1981. //| 000m 00.000cm |
  1982. //|Print time: |
  1983. //| 00h 00m 00s |
  1984. //----------------------
  1985. lcd_printf_P(_N(
  1986. ESC_2J
  1987. "%S:"
  1988. ESC_H(6,1) "%8.2f m\n"
  1989. "%S :"
  1990. ESC_H(8,3) "%2dh %02dm %02d"
  1991. ),
  1992. _i("Filament used"),
  1993. _met, _cm,
  1994. _i("Print time"),
  1995. _h, _m, _s
  1996. );
  1997. menu_back_if_clicked_fb();
  1998. }
  1999. else
  2000. {
  2001. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2002. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2003. uint8_t _hours, _minutes;
  2004. uint32_t _days;
  2005. float _filament_m = (float)_filament/100;
  2006. // int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  2007. // if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  2008. _days = _time / 1440;
  2009. _hours = (_time - (_days * 1440)) / 60;
  2010. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2011. //|01234567890123456789|
  2012. //|Total filament : |
  2013. //| 000.00 m |
  2014. //|Total print time : |
  2015. //| 00d :00h :00 m |
  2016. //----------------------
  2017. lcd_printf_P(_N(
  2018. ESC_2J
  2019. "%S :"
  2020. ESC_H(9,1) "%8.2f m\n"
  2021. "%S :\n"
  2022. "%7ldd :%2hhdh :%02hhd m"
  2023. ),
  2024. _i("Total filament"),
  2025. _filament_m,
  2026. _i("Total print time"),
  2027. _days, _hours, _minutes
  2028. );
  2029. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2030. while (!lcd_clicked())
  2031. {
  2032. manage_heater();
  2033. manage_inactivity(true);
  2034. delay(100);
  2035. }
  2036. KEEPALIVE_STATE(NOT_BUSY);
  2037. lcd_quick_feedback();
  2038. menu_back();
  2039. }
  2040. }
  2041. static void _lcd_move(const char *name, int axis, int min, int max) {
  2042. if (!menuData._lcd_moveMenu.initialized)
  2043. {
  2044. menuData._lcd_moveMenu.endstopsEnabledPrevious = enable_endstops(false);
  2045. menuData._lcd_moveMenu.initialized = true;
  2046. }
  2047. if (encoderPosition != 0) {
  2048. refresh_cmd_timeout();
  2049. if (! planner_queue_full()) {
  2050. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  2051. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2052. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2053. encoderPosition = 0;
  2054. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2055. 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);
  2056. lcdDrawUpdate = 1;
  2057. }
  2058. }
  2059. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  2060. if (menuExiting || LCD_CLICKED) (void)enable_endstops(menuData._lcd_moveMenu.endstopsEnabledPrevious);
  2061. if (LCD_CLICKED) menu_back();
  2062. }
  2063. static void lcd_move_e()
  2064. {
  2065. if (degHotend0() > EXTRUDE_MINTEMP) {
  2066. if (encoderPosition != 0)
  2067. {
  2068. refresh_cmd_timeout();
  2069. if (! planner_queue_full()) {
  2070. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  2071. encoderPosition = 0;
  2072. 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);
  2073. lcdDrawUpdate = 1;
  2074. }
  2075. }
  2076. if (lcdDrawUpdate)
  2077. {
  2078. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  2079. }
  2080. if (LCD_CLICKED) menu_back();
  2081. }
  2082. else {
  2083. lcd_implementation_clear();
  2084. lcd.setCursor(0, 0);
  2085. lcd_printPGM(_T(MSG_ERROR));
  2086. lcd.setCursor(0, 2);
  2087. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  2088. delay(2000);
  2089. lcd_return_to_status();
  2090. }
  2091. }
  2092. /**
  2093. * @brief Show measured Y distance of front calibration points from Y_MIN_POS
  2094. *
  2095. * If those points are detected too close to edge of reachable area, their confidence is lowered.
  2096. * This functionality is applied more often for MK2 printers.
  2097. */
  2098. static void lcd_menu_xyz_y_min()
  2099. {
  2100. //|01234567890123456789|
  2101. //|Y distance from min:|
  2102. //|--------------------|
  2103. //|Left: N/A |
  2104. //|Right: N/A |
  2105. //----------------------
  2106. float distanceMin[2];
  2107. count_xyz_details(distanceMin);
  2108. lcd_printf_P(_N(
  2109. ESC_H(0,0)
  2110. "%S:\n"
  2111. "%S\n"
  2112. "%S:\n"
  2113. "%S:"
  2114. ),
  2115. _i("Y distance from min"),
  2116. separator,
  2117. _i("Left"),
  2118. _i("Right")
  2119. );
  2120. for (uint8_t i = 0; i < 2; i++)
  2121. {
  2122. lcd.setCursor(11,2+i);
  2123. if (distanceMin[i] >= 200) lcd_puts_P(_N("N/A"));
  2124. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2125. }
  2126. if (lcd_clicked())
  2127. lcd_goto_menu(lcd_menu_xyz_skew);
  2128. }
  2129. /**
  2130. * @brief Show measured axis skewness
  2131. */
  2132. float _deg(float rad)
  2133. {
  2134. return rad * 180 / M_PI;
  2135. }
  2136. static void lcd_menu_xyz_skew()
  2137. {
  2138. //|01234567890123456789|
  2139. //|Measured skew: N/A |
  2140. //|--------------------|
  2141. //|Slight skew: 0.12°|
  2142. //|Severe skew: 0.25°|
  2143. //----------------------
  2144. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2145. lcd_printf_P(_N(
  2146. ESC_H(0,0)
  2147. "%S:\n"
  2148. "%S\n"
  2149. "%S: %5.2f\x01\n"
  2150. "%S: %5.2f\x01"
  2151. ),
  2152. _i("Measured skew"),
  2153. separator,
  2154. _i("Slight skew"), _deg(bed_skew_angle_mild),
  2155. _i("Severe skew"), _deg(bed_skew_angle_extreme)
  2156. );
  2157. if (angleDiff < 100)
  2158. lcd_printf_P(_N(ESC_H(15,0)"%4.2f\x01"), _deg(angleDiff));
  2159. else
  2160. lcd_puts_P(_N(ESC_H(15,0)"N/A"));
  2161. if (lcd_clicked())
  2162. lcd_goto_menu(lcd_menu_xyz_offset);
  2163. }
  2164. /**
  2165. * @brief Show measured bed offset from expected position
  2166. */
  2167. static void lcd_menu_xyz_offset()
  2168. {
  2169. lcd.setCursor(0,0);
  2170. lcd_printPGM(_i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=0 r=0
  2171. lcd_print_at_PGM(0, 1, separator);
  2172. lcd_print_at_PGM(0, 2, PSTR("X"));
  2173. lcd_print_at_PGM(0, 3, PSTR("Y"));
  2174. float vec_x[2];
  2175. float vec_y[2];
  2176. float cntr[2];
  2177. world2machine_read_valid(vec_x, vec_y, cntr);
  2178. for (int i = 0; i < 2; i++)
  2179. {
  2180. lcd_print_at_PGM(11, i + 2, PSTR(""));
  2181. lcd.print(cntr[i]);
  2182. lcd_print_at_PGM((cntr[i] < 0) ? 17 : 16, i + 2, PSTR("mm"));
  2183. }
  2184. menu_back_if_clicked();
  2185. }
  2186. // Save a single axis babystep value.
  2187. void EEPROM_save_B(int pos, int* value)
  2188. {
  2189. union Data data;
  2190. data.value = *value;
  2191. eeprom_update_byte((unsigned char*)pos, data.b[0]);
  2192. eeprom_update_byte((unsigned char*)pos + 1, data.b[1]);
  2193. }
  2194. // Read a single axis babystep value.
  2195. void EEPROM_read_B(int pos, int* value)
  2196. {
  2197. union Data data;
  2198. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  2199. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  2200. *value = data.value;
  2201. }
  2202. static void lcd_move_x() {
  2203. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2204. }
  2205. static void lcd_move_y() {
  2206. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2207. }
  2208. static void lcd_move_z() {
  2209. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2210. }
  2211. /**
  2212. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2213. *
  2214. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2215. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2216. * Purpose of this function for other axis then Z is unknown.
  2217. *
  2218. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2219. * other value leads to storing Z_AXIS
  2220. * @param msg text to be displayed
  2221. */
  2222. static void _lcd_babystep(int axis, const char *msg)
  2223. {
  2224. if (menuData.babyStep.status == 0) {
  2225. // Menu was entered.
  2226. // Initialize its status.
  2227. menuData.babyStep.status = 1;
  2228. check_babystep();
  2229. EEPROM_read_B(EEPROM_BABYSTEP_X, &menuData.babyStep.babystepMem[0]);
  2230. EEPROM_read_B(EEPROM_BABYSTEP_Y, &menuData.babyStep.babystepMem[1]);
  2231. EEPROM_read_B(EEPROM_BABYSTEP_Z, &menuData.babyStep.babystepMem[2]);
  2232. menuData.babyStep.babystepMemMM[0] = menuData.babyStep.babystepMem[0]/axis_steps_per_unit[X_AXIS];
  2233. menuData.babyStep.babystepMemMM[1] = menuData.babyStep.babystepMem[1]/axis_steps_per_unit[Y_AXIS];
  2234. menuData.babyStep.babystepMemMM[2] = menuData.babyStep.babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  2235. lcdDrawUpdate = 1;
  2236. //SERIAL_ECHO("Z baby step: ");
  2237. //SERIAL_ECHO(menuData.babyStep.babystepMem[2]);
  2238. // Wait 90 seconds before closing the live adjust dialog.
  2239. lcd_timeoutToStatus = millis() + 90000;
  2240. }
  2241. if (encoderPosition != 0)
  2242. {
  2243. if (homing_flag) encoderPosition = 0;
  2244. menuData.babyStep.babystepMem[axis] += (int)encoderPosition;
  2245. if (axis == 2) {
  2246. if (menuData.babyStep.babystepMem[axis] < Z_BABYSTEP_MIN) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2247. else if (menuData.babyStep.babystepMem[axis] > Z_BABYSTEP_MAX) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MAX; //0
  2248. else {
  2249. CRITICAL_SECTION_START
  2250. babystepsTodo[axis] += (int)encoderPosition;
  2251. CRITICAL_SECTION_END
  2252. }
  2253. }
  2254. menuData.babyStep.babystepMemMM[axis] = menuData.babyStep.babystepMem[axis]/axis_steps_per_unit[axis];
  2255. delay(50);
  2256. encoderPosition = 0;
  2257. lcdDrawUpdate = 1;
  2258. }
  2259. if (lcdDrawUpdate)
  2260. lcd_implementation_drawedit_2(msg, ftostr13ns(menuData.babyStep.babystepMemMM[axis]));
  2261. if (LCD_CLICKED || menuExiting) {
  2262. // Only update the EEPROM when leaving the menu.
  2263. EEPROM_save_B(
  2264. (axis == X_AXIS) ? EEPROM_BABYSTEP_X : ((axis == Y_AXIS) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  2265. &menuData.babyStep.babystepMem[axis]);
  2266. if(Z_AXIS == axis) calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2267. }
  2268. if (LCD_CLICKED) menu_back();
  2269. }
  2270. static void lcd_babystep_x() {
  2271. _lcd_babystep(X_AXIS, (_i("Babystepping X")));////MSG_BABYSTEPPING_X c=0 r=0
  2272. }
  2273. static void lcd_babystep_y() {
  2274. _lcd_babystep(Y_AXIS, (_i("Babystepping Y")));////MSG_BABYSTEPPING_Y c=0 r=0
  2275. }
  2276. static void lcd_babystep_z() {
  2277. _lcd_babystep(Z_AXIS, (_i("Adjusting Z")));////MSG_BABYSTEPPING_Z c=20 r=0
  2278. }
  2279. static void lcd_adjust_bed();
  2280. /**
  2281. * @brief adjust bed reset menu item function
  2282. *
  2283. * To be used as MENU_ITEM(function,...) inside lcd_adjust_bed submenu. In such case lcd_goto_menu usage
  2284. * is correct and doesn't break menuStack.
  2285. * Because we did not leave the menu, the menuData did not reset.
  2286. * Force refresh of the bed leveling data.
  2287. */
  2288. static void lcd_adjust_bed_reset()
  2289. {
  2290. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2291. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2292. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2293. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2294. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2295. lcd_goto_menu(lcd_adjust_bed, 0, false); //doesn't break menuStack
  2296. menuData.adjustBed.status = 0;
  2297. }
  2298. void adjust_bed_reset() {
  2299. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2300. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0);
  2301. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2302. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2303. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0);
  2304. menuData.adjustBed.left = menuData.adjustBed.left2 = 0;
  2305. menuData.adjustBed.right = menuData.adjustBed.right2 = 0;
  2306. menuData.adjustBed.front = menuData.adjustBed.front2 = 0;
  2307. menuData.adjustBed.rear = menuData.adjustBed.rear2 = 0;
  2308. }
  2309. #define BED_ADJUSTMENT_UM_MAX 50
  2310. static void lcd_adjust_bed()
  2311. {
  2312. if (menuData.adjustBed.status == 0) {
  2313. // Menu was entered.
  2314. // Initialize its status.
  2315. menuData.adjustBed.status = 1;
  2316. bool valid = false;
  2317. menuData.adjustBed.left = menuData.adjustBed.left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2318. menuData.adjustBed.right = menuData.adjustBed.right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2319. menuData.adjustBed.front = menuData.adjustBed.front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2320. menuData.adjustBed.rear = menuData.adjustBed.rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2321. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1 &&
  2322. menuData.adjustBed.left >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.left <= BED_ADJUSTMENT_UM_MAX &&
  2323. menuData.adjustBed.right >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.right <= BED_ADJUSTMENT_UM_MAX &&
  2324. menuData.adjustBed.front >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.front <= BED_ADJUSTMENT_UM_MAX &&
  2325. menuData.adjustBed.rear >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.rear <= BED_ADJUSTMENT_UM_MAX)
  2326. valid = true;
  2327. if (! valid) {
  2328. // Reset the values: simulate an edit.
  2329. menuData.adjustBed.left2 = 0;
  2330. menuData.adjustBed.right2 = 0;
  2331. menuData.adjustBed.front2 = 0;
  2332. menuData.adjustBed.rear2 = 0;
  2333. }
  2334. lcdDrawUpdate = 1;
  2335. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2336. }
  2337. if (menuData.adjustBed.left != menuData.adjustBed.left2)
  2338. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, menuData.adjustBed.left = menuData.adjustBed.left2);
  2339. if (menuData.adjustBed.right != menuData.adjustBed.right2)
  2340. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, menuData.adjustBed.right = menuData.adjustBed.right2);
  2341. if (menuData.adjustBed.front != menuData.adjustBed.front2)
  2342. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, menuData.adjustBed.front = menuData.adjustBed.front2);
  2343. if (menuData.adjustBed.rear != menuData.adjustBed.rear2)
  2344. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, menuData.adjustBed.rear = menuData.adjustBed.rear2);
  2345. MENU_BEGIN();
  2346. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  2347. 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
  2348. 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
  2349. 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
  2350. 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
  2351. MENU_ITEM_FUNCTION_P(_i("Reset"), lcd_adjust_bed_reset);////MSG_BED_CORRECTION_RESET c=0 r=0
  2352. MENU_END();
  2353. }
  2354. void pid_extruder() {
  2355. lcd_implementation_clear();
  2356. lcd.setCursor(1, 0);
  2357. lcd_printPGM(_i("Set temperature:"));////MSG_SET_TEMPERATURE c=19 r=1
  2358. pid_temp += int(encoderPosition);
  2359. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2360. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2361. encoderPosition = 0;
  2362. lcd.setCursor(1, 2);
  2363. lcd.print(ftostr3(pid_temp));
  2364. if (lcd_clicked()) {
  2365. lcd_commands_type = LCD_COMMAND_PID_EXTRUDER;
  2366. lcd_return_to_status();
  2367. lcd_update(2);
  2368. }
  2369. }
  2370. void lcd_adjust_z() {
  2371. int enc_dif = 0;
  2372. int cursor_pos = 1;
  2373. int fsm = 0;
  2374. lcd_implementation_clear();
  2375. lcd.setCursor(0, 0);
  2376. lcd_printPGM(_i("Auto adjust Z?"));////MSG_ADJUSTZ c=0 r=0
  2377. lcd.setCursor(1, 1);
  2378. lcd_printPGM(_T(MSG_YES));
  2379. lcd.setCursor(1, 2);
  2380. lcd_printPGM(_T(MSG_NO));
  2381. lcd.setCursor(0, 1);
  2382. lcd.print(">");
  2383. enc_dif = encoderDiff;
  2384. while (fsm == 0) {
  2385. manage_heater();
  2386. manage_inactivity(true);
  2387. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2388. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2389. if (enc_dif > encoderDiff ) {
  2390. cursor_pos --;
  2391. }
  2392. if (enc_dif < encoderDiff ) {
  2393. cursor_pos ++;
  2394. }
  2395. if (cursor_pos > 2) {
  2396. cursor_pos = 2;
  2397. }
  2398. if (cursor_pos < 1) {
  2399. cursor_pos = 1;
  2400. }
  2401. lcd.setCursor(0, 1);
  2402. lcd.print(" ");
  2403. lcd.setCursor(0, 2);
  2404. lcd.print(" ");
  2405. lcd.setCursor(0, cursor_pos);
  2406. lcd.print(">");
  2407. enc_dif = encoderDiff;
  2408. delay(100);
  2409. }
  2410. }
  2411. if (lcd_clicked()) {
  2412. fsm = cursor_pos;
  2413. if (fsm == 1) {
  2414. int babystepLoadZ = 0;
  2415. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  2416. CRITICAL_SECTION_START
  2417. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2418. CRITICAL_SECTION_END
  2419. } else {
  2420. int zero = 0;
  2421. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  2422. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  2423. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  2424. }
  2425. delay(500);
  2426. }
  2427. };
  2428. lcd_implementation_clear();
  2429. lcd_return_to_status();
  2430. }
  2431. bool lcd_wait_for_pinda(float temp) {
  2432. lcd_set_custom_characters_degree();
  2433. setTargetHotend(0, 0);
  2434. setTargetBed(0);
  2435. LongTimer pinda_timeout;
  2436. pinda_timeout.start();
  2437. bool target_temp_reached = true;
  2438. while (current_temperature_pinda > temp){
  2439. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2440. lcd.setCursor(0, 4);
  2441. lcd.print(LCD_STR_THERMOMETER[0]);
  2442. lcd.print(ftostr3(current_temperature_pinda));
  2443. lcd.print("/");
  2444. lcd.print(ftostr3(temp));
  2445. lcd.print(LCD_STR_DEGREE);
  2446. delay_keep_alive(1000);
  2447. serialecho_temperatures();
  2448. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2449. target_temp_reached = false;
  2450. break;
  2451. }
  2452. }
  2453. lcd_set_custom_characters_arrows();
  2454. lcd_update_enable(true);
  2455. return(target_temp_reached);
  2456. }
  2457. void lcd_wait_for_heater() {
  2458. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2459. lcd.setCursor(0, 4);
  2460. lcd.print(LCD_STR_THERMOMETER[0]);
  2461. lcd.print(ftostr3(degHotend(active_extruder)));
  2462. lcd.print("/");
  2463. lcd.print(ftostr3(degTargetHotend(active_extruder)));
  2464. lcd.print(LCD_STR_DEGREE);
  2465. }
  2466. void lcd_wait_for_cool_down() {
  2467. lcd_set_custom_characters_degree();
  2468. setTargetHotend(0,0);
  2469. setTargetBed(0);
  2470. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2471. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=3
  2472. lcd.setCursor(0, 4);
  2473. lcd.print(LCD_STR_THERMOMETER[0]);
  2474. lcd.print(ftostr3(degHotend(0)));
  2475. lcd.print("/0");
  2476. lcd.print(LCD_STR_DEGREE);
  2477. lcd.setCursor(9, 4);
  2478. lcd.print(LCD_STR_BEDTEMP[0]);
  2479. lcd.print(ftostr3(degBed()));
  2480. lcd.print("/0");
  2481. lcd.print(LCD_STR_DEGREE);
  2482. lcd_set_custom_characters();
  2483. delay_keep_alive(1000);
  2484. serialecho_temperatures();
  2485. }
  2486. lcd_set_custom_characters_arrows();
  2487. lcd_update_enable(true);
  2488. }
  2489. // Lets the user move the Z carriage up to the end stoppers.
  2490. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2491. // Otherwise the Z calibration is not changed and false is returned.
  2492. #ifndef TMC2130
  2493. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2494. {
  2495. bool clean_nozzle_asked = false;
  2496. // 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.
  2497. current_position[Z_AXIS] = 0;
  2498. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2499. // Until confirmed by the confirmation dialog.
  2500. for (;;) {
  2501. unsigned long previous_millis_cmd = millis();
  2502. 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
  2503. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2504. const bool multi_screen = msg_next != NULL;
  2505. unsigned long previous_millis_msg = millis();
  2506. // Until the user finishes the z up movement.
  2507. encoderDiff = 0;
  2508. encoderPosition = 0;
  2509. for (;;) {
  2510. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2511. // goto canceled;
  2512. manage_heater();
  2513. manage_inactivity(true);
  2514. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  2515. delay(50);
  2516. previous_millis_cmd = millis();
  2517. encoderPosition += abs(encoderDiff / ENCODER_PULSES_PER_STEP);
  2518. encoderDiff = 0;
  2519. if (! planner_queue_full()) {
  2520. // Only move up, whatever direction the user rotates the encoder.
  2521. current_position[Z_AXIS] += fabs(encoderPosition);
  2522. encoderPosition = 0;
  2523. 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);
  2524. }
  2525. }
  2526. if (lcd_clicked()) {
  2527. // Abort a move if in progress.
  2528. planner_abort_hard();
  2529. while (lcd_clicked()) ;
  2530. delay(10);
  2531. while (lcd_clicked()) ;
  2532. break;
  2533. }
  2534. if (multi_screen && millis() - previous_millis_msg > 5000) {
  2535. if (msg_next == NULL)
  2536. msg_next = msg;
  2537. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2538. previous_millis_msg = millis();
  2539. }
  2540. }
  2541. if (! clean_nozzle_asked) {
  2542. lcd_show_fullscreen_message_and_wait_P(_T(MSG_CONFIRM_NOZZLE_CLEAN));
  2543. clean_nozzle_asked = true;
  2544. }
  2545. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2546. 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
  2547. if (result == -1)
  2548. goto canceled;
  2549. else if (result == 1)
  2550. goto calibrated;
  2551. // otherwise perform another round of the Z up dialog.
  2552. }
  2553. calibrated:
  2554. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2555. // during the search for the induction points.
  2556. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2557. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2558. if(only_z){
  2559. lcd_display_message_fullscreen_P(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1));
  2560. lcd_implementation_print_at(0, 3, 1);
  2561. lcd_printPGM(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2));
  2562. }else{
  2563. //lcd_show_fullscreen_message_and_wait_P(_T(MSG_PAPER));
  2564. lcd_display_message_fullscreen_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1));
  2565. lcd_implementation_print_at(0, 2, 1);
  2566. lcd_printPGM(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2));
  2567. }
  2568. return true;
  2569. canceled:
  2570. return false;
  2571. }
  2572. #endif // TMC2130
  2573. static inline bool pgm_is_whitespace(const char *c_addr)
  2574. {
  2575. const char c = pgm_read_byte(c_addr);
  2576. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2577. }
  2578. static inline bool pgm_is_interpunction(const char *c_addr)
  2579. {
  2580. const char c = pgm_read_byte(c_addr);
  2581. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2582. }
  2583. /**
  2584. * @brief show full screen message
  2585. *
  2586. * This function is non-blocking
  2587. * @param msg message to be displayed from PROGMEM
  2588. * @param nlines
  2589. * @return rest of the text (to be displayed on next page)
  2590. */
  2591. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines)
  2592. {
  2593. lcd.setCursor(0, 0);
  2594. const char *msgend = msg;
  2595. uint8_t row = 0;
  2596. bool multi_screen = false;
  2597. for (; row < 4; ++ row) {
  2598. while (pgm_is_whitespace(msg))
  2599. ++ msg;
  2600. if (pgm_read_byte(msg) == 0)
  2601. // End of the message.
  2602. break;
  2603. lcd.setCursor(0, row);
  2604. uint8_t linelen = min(strlen_P(msg), 20);
  2605. const char *msgend2 = msg + linelen;
  2606. msgend = msgend2;
  2607. if (row == 3 && linelen == 20) {
  2608. // Last line of the display, full line shall be displayed.
  2609. // Find out, whether this message will be split into multiple screens.
  2610. while (pgm_is_whitespace(msgend))
  2611. ++ msgend;
  2612. multi_screen = pgm_read_byte(msgend) != 0;
  2613. if (multi_screen)
  2614. msgend = (msgend2 -= 2);
  2615. }
  2616. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2617. // Splitting a word. Find the start of the current word.
  2618. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2619. -- msgend;
  2620. if (msgend == msg)
  2621. // Found a single long word, which cannot be split. Just cut it.
  2622. msgend = msgend2;
  2623. }
  2624. for (; msg < msgend; ++ msg) {
  2625. char c = char(pgm_read_byte(msg));
  2626. if (c == '~')
  2627. c = ' ';
  2628. lcd.print(c);
  2629. }
  2630. }
  2631. if (multi_screen) {
  2632. // Display the "next screen" indicator character.
  2633. // lcd_set_custom_characters_arrows();
  2634. lcd_set_custom_characters_nextpage();
  2635. lcd.setCursor(19, 3);
  2636. // Display the down arrow.
  2637. lcd.print(char(1));
  2638. }
  2639. nlines = row;
  2640. return multi_screen ? msgend : NULL;
  2641. }
  2642. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  2643. {
  2644. // Disable update of the screen by the usual lcd_update() routine.
  2645. lcd_update_enable(false);
  2646. lcd_implementation_clear();
  2647. return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines);
  2648. }
  2649. /**
  2650. * @brief show full screen message and wait
  2651. *
  2652. * This function is blocking.
  2653. * @param msg message to be displayed from PROGMEM
  2654. */
  2655. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2656. {
  2657. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2658. bool multi_screen = msg_next != NULL;
  2659. lcd_set_custom_characters_nextpage();
  2660. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2661. // Until confirmed by a button click.
  2662. for (;;) {
  2663. if (!multi_screen) {
  2664. lcd.setCursor(19, 3);
  2665. // Display the confirm char.
  2666. lcd.print(char(2));
  2667. }
  2668. // Wait for 5 seconds before displaying the next text.
  2669. for (uint8_t i = 0; i < 100; ++ i) {
  2670. delay_keep_alive(50);
  2671. if (lcd_clicked()) {
  2672. while (lcd_clicked()) ;
  2673. delay(10);
  2674. while (lcd_clicked()) ;
  2675. if (msg_next == NULL) {
  2676. KEEPALIVE_STATE(IN_HANDLER);
  2677. lcd_set_custom_characters();
  2678. lcd_update_enable(true);
  2679. lcd_update(2);
  2680. return;
  2681. }
  2682. else {
  2683. break;
  2684. }
  2685. }
  2686. }
  2687. if (multi_screen) {
  2688. if (msg_next == NULL)
  2689. msg_next = msg;
  2690. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2691. if (msg_next == NULL) {
  2692. lcd.setCursor(19, 3);
  2693. // Display the confirm char.
  2694. lcd.print(char(2));
  2695. }
  2696. }
  2697. }
  2698. }
  2699. void lcd_wait_for_click()
  2700. {
  2701. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2702. for (;;) {
  2703. manage_heater();
  2704. manage_inactivity(true);
  2705. if (lcd_clicked()) {
  2706. while (lcd_clicked()) ;
  2707. delay(10);
  2708. while (lcd_clicked()) ;
  2709. KEEPALIVE_STATE(IN_HANDLER);
  2710. return;
  2711. }
  2712. }
  2713. }
  2714. 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)
  2715. {
  2716. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2717. bool multi_screen = msg_next != NULL;
  2718. bool yes = default_yes ? true : false;
  2719. // Wait for user confirmation or a timeout.
  2720. unsigned long previous_millis_cmd = millis();
  2721. int8_t enc_dif = encoderDiff;
  2722. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  2723. for (;;) {
  2724. for (uint8_t i = 0; i < 100; ++i) {
  2725. delay_keep_alive(50);
  2726. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2727. return -1;
  2728. manage_heater();
  2729. manage_inactivity(true);
  2730. if (abs(enc_dif - encoderDiff) > 4) {
  2731. if (msg_next == NULL) {
  2732. lcd.setCursor(0, 3);
  2733. if (enc_dif < encoderDiff && yes) {
  2734. lcd_printPGM((PSTR(" ")));
  2735. lcd.setCursor(7, 3);
  2736. lcd_printPGM((PSTR(">")));
  2737. yes = false;
  2738. }
  2739. else if (enc_dif > encoderDiff && !yes) {
  2740. lcd_printPGM((PSTR(">")));
  2741. lcd.setCursor(7, 3);
  2742. lcd_printPGM((PSTR(" ")));
  2743. yes = true;
  2744. }
  2745. enc_dif = encoderDiff;
  2746. }
  2747. else {
  2748. break; //turning knob skips waiting loop
  2749. }
  2750. }
  2751. if (lcd_clicked()) {
  2752. while (lcd_clicked());
  2753. delay(10);
  2754. while (lcd_clicked());
  2755. if (msg_next == NULL) {
  2756. //KEEPALIVE_STATE(IN_HANDLER);
  2757. lcd_set_custom_characters();
  2758. return yes;
  2759. }
  2760. else break;
  2761. }
  2762. }
  2763. if (multi_screen) {
  2764. if (msg_next == NULL) {
  2765. msg_next = msg;
  2766. }
  2767. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2768. }
  2769. if (msg_next == NULL) {
  2770. lcd.setCursor(0, 3);
  2771. if (yes) lcd_printPGM(PSTR(">"));
  2772. lcd.setCursor(1, 3);
  2773. lcd_printPGM(_T(MSG_YES));
  2774. lcd.setCursor(7, 3);
  2775. if (!yes) lcd_printPGM(PSTR(">"));
  2776. lcd.setCursor(8, 3);
  2777. lcd_printPGM(_T(MSG_NO));
  2778. }
  2779. }
  2780. }
  2781. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  2782. {
  2783. lcd_display_message_fullscreen_P(msg);
  2784. if (default_yes) {
  2785. lcd.setCursor(0, 2);
  2786. lcd_printPGM(PSTR(">"));
  2787. lcd_printPGM(_T(MSG_YES));
  2788. lcd.setCursor(1, 3);
  2789. lcd_printPGM(_T(MSG_NO));
  2790. }
  2791. else {
  2792. lcd.setCursor(1, 2);
  2793. lcd_printPGM(_T(MSG_YES));
  2794. lcd.setCursor(0, 3);
  2795. lcd_printPGM(PSTR(">"));
  2796. lcd_printPGM(_T(MSG_NO));
  2797. }
  2798. bool yes = default_yes ? true : false;
  2799. // Wait for user confirmation or a timeout.
  2800. unsigned long previous_millis_cmd = millis();
  2801. int8_t enc_dif = encoderDiff;
  2802. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2803. for (;;) {
  2804. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2805. return -1;
  2806. manage_heater();
  2807. manage_inactivity(true);
  2808. if (abs(enc_dif - encoderDiff) > 4) {
  2809. lcd.setCursor(0, 2);
  2810. if (enc_dif < encoderDiff && yes) {
  2811. lcd_printPGM((PSTR(" ")));
  2812. lcd.setCursor(0, 3);
  2813. lcd_printPGM((PSTR(">")));
  2814. yes = false;
  2815. }
  2816. else if (enc_dif > encoderDiff && !yes) {
  2817. lcd_printPGM((PSTR(">")));
  2818. lcd.setCursor(0, 3);
  2819. lcd_printPGM((PSTR(" ")));
  2820. yes = true;
  2821. }
  2822. enc_dif = encoderDiff;
  2823. }
  2824. if (lcd_clicked()) {
  2825. while (lcd_clicked());
  2826. delay(10);
  2827. while (lcd_clicked());
  2828. KEEPALIVE_STATE(IN_HANDLER);
  2829. return yes;
  2830. }
  2831. }
  2832. }
  2833. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  2834. {
  2835. const char *msg = NULL;
  2836. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  2837. 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
  2838. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  2839. if (point_too_far_mask == 0)
  2840. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2841. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2842. // Only the center point or all the three front points.
  2843. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=8
  2844. else if (point_too_far_mask & 1 == 0)
  2845. // The right and maybe the center point out of reach.
  2846. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=8
  2847. else
  2848. // The left and maybe the center point out of reach.
  2849. msg = _i("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  2850. lcd_show_fullscreen_message_and_wait_P(msg);
  2851. } else {
  2852. if (point_too_far_mask != 0) {
  2853. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2854. // Only the center point or all the three front points.
  2855. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  2856. else if (point_too_far_mask & 1 == 0)
  2857. // The right and maybe the center point out of reach.
  2858. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  2859. else
  2860. // The left and maybe the center point out of reach.
  2861. msg = _i("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  2862. lcd_show_fullscreen_message_and_wait_P(msg);
  2863. }
  2864. if (point_too_far_mask == 0 || result > 0) {
  2865. switch (result) {
  2866. default:
  2867. // should not happen
  2868. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2869. break;
  2870. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  2871. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  2872. break;
  2873. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  2874. 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
  2875. break;
  2876. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  2877. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  2878. break;
  2879. }
  2880. lcd_show_fullscreen_message_and_wait_P(msg);
  2881. }
  2882. }
  2883. }
  2884. void lcd_temp_cal_show_result(bool result) {
  2885. custom_message_type = 0;
  2886. custom_message = false;
  2887. disable_x();
  2888. disable_y();
  2889. disable_z();
  2890. disable_e0();
  2891. disable_e1();
  2892. disable_e2();
  2893. setTargetBed(0); //set bed target temperature back to 0
  2894. if (result == true) {
  2895. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  2896. SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob.");
  2897. lcd_show_fullscreen_message_and_wait_P(_T(MSG_TEMP_CALIBRATION_DONE));
  2898. temp_cal_active = true;
  2899. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  2900. }
  2901. else {
  2902. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  2903. SERIAL_ECHOLNPGM("Temperature calibration failed. Continue with pressing the knob.");
  2904. lcd_show_fullscreen_message_and_wait_P(_i("Temperature calibration failed"));////MSG_TEMP_CAL_FAILED c=20 r=8
  2905. temp_cal_active = false;
  2906. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  2907. }
  2908. lcd_update_enable(true);
  2909. lcd_update(2);
  2910. }
  2911. static void lcd_show_end_stops() {
  2912. lcd.setCursor(0, 0);
  2913. lcd_printPGM((PSTR("End stops diag")));
  2914. lcd.setCursor(0, 1);
  2915. lcd_printPGM((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
  2916. lcd.setCursor(0, 2);
  2917. lcd_printPGM((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
  2918. lcd.setCursor(0, 3);
  2919. lcd_printPGM((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
  2920. }
  2921. static void menu_show_end_stops() {
  2922. lcd_show_end_stops();
  2923. if (LCD_CLICKED) menu_back();
  2924. }
  2925. // Lets the user move the Z carriage up to the end stoppers.
  2926. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2927. // Otherwise the Z calibration is not changed and false is returned.
  2928. void lcd_diag_show_end_stops()
  2929. {
  2930. int enc_dif = encoderDiff;
  2931. lcd_implementation_clear();
  2932. for (;;) {
  2933. manage_heater();
  2934. manage_inactivity(true);
  2935. lcd_show_end_stops();
  2936. if (lcd_clicked()) {
  2937. while (lcd_clicked()) ;
  2938. delay(10);
  2939. while (lcd_clicked()) ;
  2940. break;
  2941. }
  2942. }
  2943. lcd_implementation_clear();
  2944. lcd_return_to_status();
  2945. }
  2946. void prusa_statistics(int _message, uint8_t _fil_nr) {
  2947. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  2948. return;
  2949. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  2950. switch (_message)
  2951. {
  2952. case 0: // default message
  2953. if (IS_SD_PRINTING)
  2954. {
  2955. SERIAL_ECHO("{");
  2956. prusa_stat_printerstatus(4);
  2957. prusa_stat_farm_number();
  2958. prusa_stat_printinfo();
  2959. SERIAL_ECHOLN("}");
  2960. status_number = 4;
  2961. }
  2962. else
  2963. {
  2964. SERIAL_ECHO("{");
  2965. prusa_stat_printerstatus(1);
  2966. prusa_stat_farm_number();
  2967. SERIAL_ECHOLN("}");
  2968. status_number = 1;
  2969. }
  2970. break;
  2971. case 1: // 1 heating
  2972. farm_status = 2;
  2973. SERIAL_ECHO("{");
  2974. prusa_stat_printerstatus(2);
  2975. prusa_stat_farm_number();
  2976. SERIAL_ECHOLN("}");
  2977. status_number = 2;
  2978. farm_timer = 1;
  2979. break;
  2980. case 2: // heating done
  2981. farm_status = 3;
  2982. SERIAL_ECHO("{");
  2983. prusa_stat_printerstatus(3);
  2984. prusa_stat_farm_number();
  2985. SERIAL_ECHOLN("}");
  2986. status_number = 3;
  2987. farm_timer = 1;
  2988. if (IS_SD_PRINTING)
  2989. {
  2990. farm_status = 4;
  2991. SERIAL_ECHO("{");
  2992. prusa_stat_printerstatus(4);
  2993. prusa_stat_farm_number();
  2994. SERIAL_ECHOLN("}");
  2995. status_number = 4;
  2996. }
  2997. else
  2998. {
  2999. SERIAL_ECHO("{");
  3000. prusa_stat_printerstatus(3);
  3001. prusa_stat_farm_number();
  3002. SERIAL_ECHOLN("}");
  3003. status_number = 3;
  3004. }
  3005. farm_timer = 1;
  3006. break;
  3007. case 3: // filament change
  3008. break;
  3009. case 4: // print succesfull
  3010. SERIAL_ECHO("{[RES:1][FIL:");
  3011. MYSERIAL.print(int(_fil_nr));
  3012. SERIAL_ECHO("]");
  3013. prusa_stat_printerstatus(status_number);
  3014. prusa_stat_farm_number();
  3015. SERIAL_ECHOLN("}");
  3016. farm_timer = 2;
  3017. break;
  3018. case 5: // print not succesfull
  3019. SERIAL_ECHO("{[RES:0][FIL:");
  3020. MYSERIAL.print(int(_fil_nr));
  3021. SERIAL_ECHO("]");
  3022. prusa_stat_printerstatus(status_number);
  3023. prusa_stat_farm_number();
  3024. SERIAL_ECHOLN("}");
  3025. farm_timer = 2;
  3026. break;
  3027. case 6: // print done
  3028. SERIAL_ECHO("{[PRN:8]");
  3029. prusa_stat_farm_number();
  3030. SERIAL_ECHOLN("}");
  3031. status_number = 8;
  3032. farm_timer = 2;
  3033. break;
  3034. case 7: // print done - stopped
  3035. SERIAL_ECHO("{[PRN:9]");
  3036. prusa_stat_farm_number();
  3037. SERIAL_ECHOLN("}");
  3038. status_number = 9;
  3039. farm_timer = 2;
  3040. break;
  3041. case 8: // printer started
  3042. SERIAL_ECHO("{[PRN:0][PFN:");
  3043. status_number = 0;
  3044. SERIAL_ECHO(farm_no);
  3045. SERIAL_ECHOLN("]}");
  3046. farm_timer = 2;
  3047. break;
  3048. case 20: // echo farm no
  3049. SERIAL_ECHO("{");
  3050. prusa_stat_printerstatus(status_number);
  3051. prusa_stat_farm_number();
  3052. SERIAL_ECHOLN("}");
  3053. farm_timer = 4;
  3054. break;
  3055. case 21: // temperatures
  3056. SERIAL_ECHO("{");
  3057. prusa_stat_temperatures();
  3058. prusa_stat_farm_number();
  3059. prusa_stat_printerstatus(status_number);
  3060. SERIAL_ECHOLN("}");
  3061. break;
  3062. case 22: // waiting for filament change
  3063. SERIAL_ECHO("{[PRN:5]");
  3064. prusa_stat_farm_number();
  3065. SERIAL_ECHOLN("}");
  3066. status_number = 5;
  3067. break;
  3068. case 90: // Error - Thermal Runaway
  3069. SERIAL_ECHO("{[ERR:1]");
  3070. prusa_stat_farm_number();
  3071. SERIAL_ECHOLN("}");
  3072. break;
  3073. case 91: // Error - Thermal Runaway Preheat
  3074. SERIAL_ECHO("{[ERR:2]");
  3075. prusa_stat_farm_number();
  3076. SERIAL_ECHOLN("}");
  3077. break;
  3078. case 92: // Error - Min temp
  3079. SERIAL_ECHO("{[ERR:3]");
  3080. prusa_stat_farm_number();
  3081. SERIAL_ECHOLN("}");
  3082. break;
  3083. case 93: // Error - Max temp
  3084. SERIAL_ECHO("{[ERR:4]");
  3085. prusa_stat_farm_number();
  3086. SERIAL_ECHOLN("}");
  3087. break;
  3088. case 99: // heartbeat
  3089. SERIAL_ECHO("{[PRN:99]");
  3090. prusa_stat_temperatures();
  3091. SERIAL_ECHO("[PFN:");
  3092. SERIAL_ECHO(farm_no);
  3093. SERIAL_ECHO("]");
  3094. SERIAL_ECHOLN("}");
  3095. break;
  3096. }
  3097. }
  3098. static void prusa_stat_printerstatus(int _status)
  3099. {
  3100. SERIAL_ECHO("[PRN:");
  3101. SERIAL_ECHO(_status);
  3102. SERIAL_ECHO("]");
  3103. }
  3104. static void prusa_stat_farm_number() {
  3105. SERIAL_ECHO("[PFN:");
  3106. SERIAL_ECHO(farm_no);
  3107. SERIAL_ECHO("]");
  3108. }
  3109. static void prusa_stat_temperatures()
  3110. {
  3111. SERIAL_ECHO("[ST0:");
  3112. SERIAL_ECHO(target_temperature[0]);
  3113. SERIAL_ECHO("][STB:");
  3114. SERIAL_ECHO(target_temperature_bed);
  3115. SERIAL_ECHO("][AT0:");
  3116. SERIAL_ECHO(current_temperature[0]);
  3117. SERIAL_ECHO("][ATB:");
  3118. SERIAL_ECHO(current_temperature_bed);
  3119. SERIAL_ECHO("]");
  3120. }
  3121. static void prusa_stat_printinfo()
  3122. {
  3123. SERIAL_ECHO("[TFU:");
  3124. SERIAL_ECHO(total_filament_used);
  3125. SERIAL_ECHO("][PCD:");
  3126. SERIAL_ECHO(itostr3(card.percentDone()));
  3127. SERIAL_ECHO("][FEM:");
  3128. SERIAL_ECHO(itostr3(feedmultiply));
  3129. SERIAL_ECHO("][FNM:");
  3130. SERIAL_ECHO(longFilenameOLD);
  3131. SERIAL_ECHO("][TIM:");
  3132. if (starttime != 0)
  3133. {
  3134. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  3135. }
  3136. else
  3137. {
  3138. SERIAL_ECHO(0);
  3139. }
  3140. SERIAL_ECHO("][FWR:");
  3141. SERIAL_ECHO(FW_VERSION);
  3142. SERIAL_ECHO("]");
  3143. }
  3144. /*
  3145. void lcd_pick_babystep(){
  3146. int enc_dif = 0;
  3147. int cursor_pos = 1;
  3148. int fsm = 0;
  3149. lcd_implementation_clear();
  3150. lcd.setCursor(0, 0);
  3151. lcd_printPGM(_i("Pick print"));////MSG_PICK_Z c=0 r=0
  3152. lcd.setCursor(3, 2);
  3153. lcd.print("1");
  3154. lcd.setCursor(3, 3);
  3155. lcd.print("2");
  3156. lcd.setCursor(12, 2);
  3157. lcd.print("3");
  3158. lcd.setCursor(12, 3);
  3159. lcd.print("4");
  3160. lcd.setCursor(1, 2);
  3161. lcd.print(">");
  3162. enc_dif = encoderDiff;
  3163. while (fsm == 0) {
  3164. manage_heater();
  3165. manage_inactivity(true);
  3166. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  3167. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  3168. if (enc_dif > encoderDiff ) {
  3169. cursor_pos --;
  3170. }
  3171. if (enc_dif < encoderDiff ) {
  3172. cursor_pos ++;
  3173. }
  3174. if (cursor_pos > 4) {
  3175. cursor_pos = 4;
  3176. }
  3177. if (cursor_pos < 1) {
  3178. cursor_pos = 1;
  3179. }
  3180. lcd.setCursor(1, 2);
  3181. lcd.print(" ");
  3182. lcd.setCursor(1, 3);
  3183. lcd.print(" ");
  3184. lcd.setCursor(10, 2);
  3185. lcd.print(" ");
  3186. lcd.setCursor(10, 3);
  3187. lcd.print(" ");
  3188. if (cursor_pos < 3) {
  3189. lcd.setCursor(1, cursor_pos+1);
  3190. lcd.print(">");
  3191. }else{
  3192. lcd.setCursor(10, cursor_pos-1);
  3193. lcd.print(">");
  3194. }
  3195. enc_dif = encoderDiff;
  3196. delay(100);
  3197. }
  3198. }
  3199. if (lcd_clicked()) {
  3200. fsm = cursor_pos;
  3201. int babyStepZ;
  3202. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  3203. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  3204. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  3205. delay(500);
  3206. }
  3207. };
  3208. lcd_implementation_clear();
  3209. lcd_return_to_status();
  3210. }
  3211. */
  3212. void lcd_move_menu_axis()
  3213. {
  3214. MENU_BEGIN();
  3215. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3216. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=0 r=0
  3217. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=0 r=0
  3218. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=0 r=0
  3219. MENU_ITEM_SUBMENU_P(_i("Extruder"), lcd_move_e);////MSG_MOVE_E c=0 r=0
  3220. MENU_END();
  3221. }
  3222. static void lcd_move_menu_1mm()
  3223. {
  3224. move_menu_scale = 1.0;
  3225. lcd_move_menu_axis();
  3226. }
  3227. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  3228. {
  3229. do
  3230. {
  3231. eeprom_write_byte((unsigned char*)pos, *value);
  3232. pos++;
  3233. value++;
  3234. } while (--size);
  3235. }
  3236. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  3237. {
  3238. do
  3239. {
  3240. *value = eeprom_read_byte((unsigned char*)pos);
  3241. pos++;
  3242. value++;
  3243. } while (--size);
  3244. }
  3245. #ifdef SDCARD_SORT_ALPHA
  3246. static void lcd_sort_type_set() {
  3247. uint8_t sdSort;
  3248. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3249. switch (sdSort) {
  3250. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3251. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3252. default: sdSort = SD_SORT_TIME;
  3253. }
  3254. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  3255. presort_flag = true;
  3256. lcd_goto_menu(lcd_settings_menu); //doesn't break menuStack
  3257. }
  3258. #endif //SDCARD_SORT_ALPHA
  3259. #ifdef TMC2130
  3260. static void lcd_crash_mode_info()
  3261. {
  3262. lcd_update_enable(true);
  3263. static uint32_t tim = 0;
  3264. if ((tim + 1000) < millis())
  3265. {
  3266. 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
  3267. tim = millis();
  3268. }
  3269. menu_back_if_clicked();
  3270. }
  3271. static void lcd_crash_mode_info2()
  3272. {
  3273. lcd_update_enable(true);
  3274. static uint32_t tim = 0;
  3275. if ((tim + 1000) < millis())
  3276. {
  3277. 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
  3278. tim = millis();
  3279. }
  3280. menu_back_if_clicked();
  3281. }
  3282. #endif //TMC2130
  3283. #ifdef PAT9125
  3284. static void lcd_filament_autoload_info()
  3285. {
  3286. uint8_t nlines;
  3287. lcd_update_enable(true);
  3288. static uint32_t tim = 0;
  3289. if ((tim + 1000) < millis())
  3290. {
  3291. 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
  3292. tim = millis();
  3293. }
  3294. menu_back_if_clicked();
  3295. }
  3296. static void lcd_fsensor_fail()
  3297. {
  3298. uint8_t nlines;
  3299. lcd_update_enable(true);
  3300. static uint32_t tim = 0;
  3301. if ((tim + 1000) < millis())
  3302. {
  3303. 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
  3304. tim = millis();
  3305. }
  3306. menu_back_if_clicked();
  3307. }
  3308. #endif //PAT9125
  3309. static void lcd_silent_mode_set() {
  3310. switch (SilentModeMenu) {
  3311. #ifdef TMC2130
  3312. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3313. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3314. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3315. #else
  3316. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3317. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3318. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3319. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3320. #endif //TMC2130
  3321. }
  3322. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3323. #ifdef TMC2130
  3324. // Wait until the planner queue is drained and the stepper routine achieves
  3325. // an idle state.
  3326. st_synchronize();
  3327. if (tmc2130_wait_standstill_xy(1000)) {}
  3328. // MYSERIAL.print("standstill OK");
  3329. // else
  3330. // MYSERIAL.print("standstill NG!");
  3331. cli();
  3332. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3333. tmc2130_init();
  3334. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3335. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3336. st_reset_timer();
  3337. sei();
  3338. #endif //TMC2130
  3339. st_current_init();
  3340. #ifdef TMC2130
  3341. if (CrashDetectMenu && (SilentModeMenu != SILENT_MODE_NORMAL))
  3342. menu_submenu(lcd_crash_mode_info2);
  3343. #endif //TMC2130
  3344. }
  3345. #ifdef TMC2130
  3346. static void lcd_crash_mode_set()
  3347. {
  3348. CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable()
  3349. if (CrashDetectMenu==0) {
  3350. crashdet_disable();
  3351. }else{
  3352. crashdet_enable();
  3353. }
  3354. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 9);
  3355. else lcd_goto_menu(lcd_settings_menu, 9);
  3356. }
  3357. #endif //TMC2130
  3358. #ifdef PAT9125
  3359. static void lcd_fsensor_state_set()
  3360. {
  3361. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3362. if (!FSensorStateMenu) {
  3363. fsensor_disable();
  3364. if (filament_autoload_enabled)
  3365. menu_submenu(lcd_filament_autoload_info);
  3366. }else{
  3367. fsensor_enable();
  3368. if (fsensor_not_responding)
  3369. menu_submenu(lcd_fsensor_fail);
  3370. }
  3371. }
  3372. #endif //PAT9125
  3373. #if !SDSORT_USES_RAM
  3374. void lcd_set_degree() {
  3375. lcd_set_custom_characters_degree();
  3376. }
  3377. void lcd_set_progress() {
  3378. lcd_set_custom_characters_progress();
  3379. }
  3380. #endif
  3381. #if (LANG_MODE != 0)
  3382. void menu_setlang(unsigned char lang)
  3383. {
  3384. if (!lang_select(lang))
  3385. {
  3386. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language from XFLASH?"), false, true))
  3387. lang_boot_update_start(lang);
  3388. lcd_update_enable(true);
  3389. lcd_implementation_clear();
  3390. lcd_goto_menu(lcd_language_menu);
  3391. lcd_timeoutToStatus = -1; //infinite timeout
  3392. lcdDrawUpdate = 2;
  3393. }
  3394. }
  3395. static void lcd_language_menu()
  3396. {
  3397. MENU_BEGIN();
  3398. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3399. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3400. {
  3401. menu_setlang(0);
  3402. return;
  3403. }
  3404. uint8_t cnt = lang_get_count();
  3405. #ifdef W25X20CL
  3406. if (cnt == 2) //display secondary language in case of clear xflash
  3407. {
  3408. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3409. {
  3410. menu_setlang(1);
  3411. return;
  3412. }
  3413. }
  3414. else
  3415. for (int i = 2; i < cnt; i++) //skip seconday language - solved in lang_select (MK3)
  3416. #else //W25X20CL
  3417. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3418. #endif //W25X20CL
  3419. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3420. {
  3421. menu_setlang(i);
  3422. return;
  3423. }
  3424. MENU_END();
  3425. }
  3426. #endif //(LANG_MODE != 0)
  3427. void lcd_mesh_bedleveling()
  3428. {
  3429. mesh_bed_run_from_menu = true;
  3430. enquecommand_P(PSTR("G80"));
  3431. lcd_return_to_status();
  3432. }
  3433. void lcd_mesh_calibration()
  3434. {
  3435. enquecommand_P(PSTR("M45"));
  3436. lcd_return_to_status();
  3437. }
  3438. void lcd_mesh_calibration_z()
  3439. {
  3440. enquecommand_P(PSTR("M45 Z"));
  3441. lcd_return_to_status();
  3442. }
  3443. void lcd_pinda_calibration_menu()
  3444. {
  3445. MENU_BEGIN();
  3446. MENU_ITEM_BACK_P(_T(MSG_MENU_CALIBRATION));
  3447. MENU_ITEM_SUBMENU_P(_i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17 r=1
  3448. MENU_END();
  3449. }
  3450. void lcd_temp_calibration_set() {
  3451. temp_cal_active = !temp_cal_active;
  3452. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3453. st_current_init();
  3454. lcd_goto_menu(lcd_settings_menu); //doesn't break menuStack
  3455. }
  3456. #ifdef HAS_SECOND_SERIAL_PORT
  3457. void lcd_second_serial_set() {
  3458. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3459. else selectedSerialPort = 1;
  3460. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3461. MYSERIAL.begin(BAUDRATE);
  3462. lcd_goto_menu(lcd_settings_menu);//doesn't break menuStack
  3463. }
  3464. #endif //HAS_SECOND_SERIAL_PORT
  3465. void lcd_calibrate_pinda() {
  3466. enquecommand_P(PSTR("G76"));
  3467. lcd_return_to_status();
  3468. }
  3469. #ifndef SNMM
  3470. /*void lcd_calibrate_extruder() {
  3471. if (degHotend0() > EXTRUDE_MINTEMP)
  3472. {
  3473. current_position[E_AXIS] = 0; //set initial position to zero
  3474. plan_set_e_position(current_position[E_AXIS]);
  3475. //long steps_start = st_get_position(E_AXIS);
  3476. long steps_final;
  3477. float e_steps_per_unit;
  3478. 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)
  3479. 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
  3480. 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
  3481. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3482. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3483. unsigned long msg_millis;
  3484. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  3485. lcd_implementation_clear();
  3486. lcd.setCursor(0, 1); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  3487. current_position[E_AXIS] += e_shift_calibration;
  3488. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3489. st_synchronize();
  3490. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3491. msg_millis = millis();
  3492. while (!LCD_CLICKED) {
  3493. if (multi_screen && millis() - msg_millis > 5000) {
  3494. if (msg_next_e_cal_knob == NULL)
  3495. msg_next_e_cal_knob = msg_e_cal_knob;
  3496. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3497. msg_millis = millis();
  3498. }
  3499. //manage_inactivity(true);
  3500. manage_heater();
  3501. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3502. delay_keep_alive(50);
  3503. //previous_millis_cmd = millis();
  3504. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  3505. encoderDiff = 0;
  3506. if (!planner_queue_full()) {
  3507. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.01; //0.05
  3508. encoderPosition = 0;
  3509. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3510. }
  3511. }
  3512. }
  3513. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3514. //steps_final = st_get_position(E_AXIS);
  3515. lcdDrawUpdate = 1;
  3516. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3517. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3518. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3519. lcd_implementation_clear();
  3520. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3521. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3522. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3523. //delay_keep_alive(2000);
  3524. delay_keep_alive(500);
  3525. 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
  3526. lcd_update_enable(true);
  3527. lcdDrawUpdate = 2;
  3528. }
  3529. else
  3530. {
  3531. lcd_implementation_clear();
  3532. lcd.setCursor(0, 0);
  3533. lcd_printPGM(_T(MSG_ERROR));
  3534. lcd.setCursor(0, 2);
  3535. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  3536. delay(2000);
  3537. lcd_implementation_clear();
  3538. }
  3539. lcd_return_to_status();
  3540. }
  3541. void lcd_extr_cal_reset() {
  3542. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3543. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3544. //extrudemultiply = 100;
  3545. enquecommand_P(PSTR("M500"));
  3546. }*/
  3547. #endif
  3548. void lcd_toshiba_flash_air_compatibility_toggle()
  3549. {
  3550. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3551. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3552. }
  3553. void lcd_v2_calibration() {
  3554. 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
  3555. if (loaded) {
  3556. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3557. }
  3558. else {
  3559. lcd_display_message_fullscreen_P(_i("Please load PLA filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3560. for (int i = 0; i < 20; i++) { //wait max. 2s
  3561. delay_keep_alive(100);
  3562. if (lcd_clicked()) {
  3563. while (lcd_clicked());
  3564. delay(10);
  3565. while (lcd_clicked());
  3566. break;
  3567. }
  3568. }
  3569. }
  3570. lcd_return_to_status();
  3571. lcd_update_enable(true);
  3572. }
  3573. void lcd_wizard() {
  3574. bool result = true;
  3575. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3576. 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
  3577. }
  3578. if (result) {
  3579. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3580. lcd_wizard(0);
  3581. }
  3582. else {
  3583. lcd_return_to_status();
  3584. lcd_update_enable(true);
  3585. lcd_update(2);
  3586. }
  3587. }
  3588. void lcd_language()
  3589. {
  3590. lcd_update_enable(true);
  3591. lcd_implementation_clear();
  3592. lcd_goto_menu(lcd_language_menu);
  3593. lcd_timeoutToStatus = -1; //infinite timeout
  3594. lcdDrawUpdate = 2;
  3595. while ((currentMenu != lcd_status_screen) && (!lang_is_selected()))
  3596. {
  3597. delay(50);
  3598. lcd_update();
  3599. manage_heater();
  3600. manage_inactivity(true);
  3601. }
  3602. if (lang_is_selected())
  3603. lcd_return_to_status();
  3604. else
  3605. lang_select(LANG_ID_PRI);
  3606. }
  3607. void lcd_wizard(int state) {
  3608. bool end = false;
  3609. int wizard_event;
  3610. const char *msg = NULL;
  3611. while (!end) {
  3612. switch (state) {
  3613. case 0: // run wizard?
  3614. 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
  3615. if (wizard_event) {
  3616. state = 1;
  3617. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3618. }
  3619. else {
  3620. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3621. end = true;
  3622. }
  3623. break;
  3624. case 1: // restore calibration status
  3625. switch (calibration_status()) {
  3626. case CALIBRATION_STATUS_ASSEMBLED: state = 2; break; //run selftest
  3627. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = 3; break; //run xyz cal.
  3628. case CALIBRATION_STATUS_Z_CALIBRATION: state = 4; break; //run z cal.
  3629. case CALIBRATION_STATUS_LIVE_ADJUST: state = 5; break; //run live adjust
  3630. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3631. default: state = 2; break; //if calibration status is unknown, run wizard from the beginning
  3632. }
  3633. break;
  3634. case 2: //selftest
  3635. 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
  3636. wizard_event = lcd_selftest();
  3637. if (wizard_event) {
  3638. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3639. state = 3;
  3640. }
  3641. else end = true;
  3642. break;
  3643. case 3: //xyz cal.
  3644. 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
  3645. wizard_event = gcode_M45(false, 0);
  3646. if (wizard_event) state = 5;
  3647. else end = true;
  3648. break;
  3649. case 4: //z cal.
  3650. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3651. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  3652. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3653. wizard_event = gcode_M45(true, 0);
  3654. if (wizard_event) state = 11; //shipped, no need to set first layer, go to final message directly
  3655. else end = true;
  3656. break;
  3657. case 5: //is filament loaded?
  3658. //start to preheat nozzle and bed to save some time later
  3659. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3660. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3661. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament loaded?"), false);////MSG_WIZARD_FILAMENT_LOADED c=20 r=2
  3662. if (wizard_event) state = 8;
  3663. else state = 6;
  3664. break;
  3665. case 6: //waiting for preheat nozzle for PLA;
  3666. #ifndef SNMM
  3667. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3668. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3669. 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);
  3670. delay_keep_alive(2000);
  3671. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3672. while (abs(degHotend(0) - PLA_PREHEAT_HOTEND_TEMP) > 3) {
  3673. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3674. lcd.setCursor(0, 4);
  3675. lcd.print(LCD_STR_THERMOMETER[0]);
  3676. lcd.print(ftostr3(degHotend(0)));
  3677. lcd.print("/");
  3678. lcd.print(PLA_PREHEAT_HOTEND_TEMP);
  3679. lcd.print(LCD_STR_DEGREE);
  3680. lcd_set_custom_characters();
  3681. delay_keep_alive(1000);
  3682. }
  3683. #endif //not SNMM
  3684. state = 7;
  3685. break;
  3686. case 7: //load filament
  3687. #ifdef PAT9125
  3688. fsensor_block();
  3689. #endif //PAT9125
  3690. 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
  3691. lcd_update_enable(false);
  3692. lcd_implementation_clear();
  3693. lcd_print_at_PGM(0, 2, _T(MSG_LOADING_FILAMENT));
  3694. #ifdef SNMM
  3695. change_extr(0);
  3696. #endif
  3697. gcode_M701();
  3698. #ifdef PAT9125
  3699. fsensor_unblock();
  3700. #endif //PAT9125
  3701. state = 9;
  3702. break;
  3703. case 8:
  3704. 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
  3705. if (wizard_event) state = 9;
  3706. else end = true;
  3707. break;
  3708. case 9:
  3709. 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
  3710. 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
  3711. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3712. end = true;
  3713. break;
  3714. case 10: //repeat first layer cal.?
  3715. 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
  3716. if (wizard_event) {
  3717. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3718. state = 9;
  3719. }
  3720. else {
  3721. state = 11;
  3722. }
  3723. break;
  3724. case 11: //we are finished
  3725. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3726. end = true;
  3727. break;
  3728. default: break;
  3729. }
  3730. }
  3731. printf_P(_N("State: %d\n"), state);
  3732. switch (state) { //final message
  3733. case 0: //user dont want to use wizard
  3734. msg = _T(MSG_WIZARD_QUIT);
  3735. break;
  3736. case 1: //printer was already calibrated
  3737. msg = _T(MSG_WIZARD_DONE);
  3738. break;
  3739. case 2: //selftest
  3740. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3741. break;
  3742. case 3: //xyz cal.
  3743. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3744. break;
  3745. case 4: //z cal.
  3746. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3747. break;
  3748. case 8:
  3749. msg = _i("Please load PLA filament and then resume Wizard by rebooting the printer.");////MSG_WIZARD_INSERT_CORRECT_FILAMENT c=20 r=8
  3750. break;
  3751. case 9: break; //exit wizard for v2 calibration, which is implemted in lcd_commands (we need lcd_update running)
  3752. case 11: //we are finished
  3753. msg = _T(MSG_WIZARD_DONE);
  3754. lcd_reset_alert_level();
  3755. lcd_setstatuspgm(_T(WELCOME_MSG));
  3756. break;
  3757. default:
  3758. msg = _T(MSG_WIZARD_QUIT);
  3759. break;
  3760. }
  3761. if (state != 9) lcd_show_fullscreen_message_and_wait_P(msg);
  3762. lcd_update_enable(true);
  3763. lcd_return_to_status();
  3764. lcd_update(2);
  3765. }
  3766. static void lcd_settings_menu()
  3767. {
  3768. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  3769. MENU_BEGIN();
  3770. if (menu_item_back_P(_T(MSG_MAIN)))
  3771. {
  3772. lcd_settings_menu_back();
  3773. return;
  3774. }
  3775. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=0 r=0
  3776. if (!homing_flag)
  3777. {
  3778. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=0 r=0
  3779. }
  3780. if (!isPrintPaused)
  3781. {
  3782. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=0 r=0
  3783. }
  3784. #ifndef TMC2130
  3785. if (!farm_mode) { //dont show in menu if we are in farm mode
  3786. switch (SilentModeMenu) {
  3787. case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  3788. case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  3789. case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  3790. default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  3791. }
  3792. }
  3793. #endif //TMC2130
  3794. #ifdef PAT9125
  3795. #ifndef DEBUG_DISABLE_FSENSORCHECK
  3796. if (FSensorStateMenu == 0) {
  3797. if (fsensor_not_responding){
  3798. // Filament sensor not working
  3799. MENU_ITEM_FUNCTION_P(_i("Fil. sensor [N/A]"), lcd_fsensor_state_set);////MSG_FSENSOR_NA c=0 r=0
  3800. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_fsensor_fail);
  3801. }
  3802. else{
  3803. // Filament sensor turned off, working, no problems
  3804. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  3805. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_filament_autoload_info);
  3806. }
  3807. } else {
  3808. // Filament sensor turned on, working, no problems
  3809. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  3810. if (filament_autoload_enabled) {
  3811. MENU_ITEM_FUNCTION_P(_i("F. autoload [on]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_ON c=17 r=1
  3812. }
  3813. else {
  3814. MENU_ITEM_FUNCTION_P(_i("F. autoload [off]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_OFF c=17 r=1
  3815. }
  3816. }
  3817. #endif //DEBUG_DISABLE_FSENSORCHECK
  3818. #endif //PAT9125
  3819. if (fans_check_enabled == true) {
  3820. MENU_ITEM_FUNCTION_P(_i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1
  3821. }
  3822. else {
  3823. MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1
  3824. }
  3825. #ifdef TMC2130
  3826. if(!farm_mode)
  3827. {
  3828. if (SilentModeMenu == SILENT_MODE_NORMAL) { MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set); }
  3829. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  3830. if (SilentModeMenu == SILENT_MODE_NORMAL)
  3831. {
  3832. if (CrashDetectMenu == 0) { MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set); }
  3833. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  3834. }
  3835. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  3836. }
  3837. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3838. 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
  3839. 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
  3840. 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
  3841. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3842. 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
  3843. #endif //TMC2130
  3844. if (temp_cal_active == false) {
  3845. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [off]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_OFF c=20 r=1
  3846. }
  3847. else {
  3848. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [on]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_ON c=20 r=1
  3849. }
  3850. #ifdef HAS_SECOND_SERIAL_PORT
  3851. if (selectedSerialPort == 0) {
  3852. MENU_ITEM_FUNCTION_P(_i("RPi port [off]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_OFF c=17 r=1
  3853. }
  3854. else {
  3855. MENU_ITEM_FUNCTION_P(_i("RPi port [on]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_ON c=17 r=1
  3856. }
  3857. #endif //HAS_SECOND_SERIAL
  3858. if (!isPrintPaused && !homing_flag)
  3859. {
  3860. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  3861. }
  3862. #if (LANG_MODE != 0)
  3863. MENU_ITEM_SUBMENU_P(_i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=0 r=0
  3864. #endif //(LANG_MODE != 0)
  3865. if (card.ToshibaFlashAir_isEnabled()) {
  3866. MENU_ITEM_FUNCTION_P(_i("SD card [FlshAir]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1
  3867. } else {
  3868. MENU_ITEM_FUNCTION_P(_i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1
  3869. }
  3870. #ifdef SDCARD_SORT_ALPHA
  3871. if (!farm_mode) {
  3872. uint8_t sdSort;
  3873. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3874. switch (sdSort) {
  3875. case SD_SORT_TIME: MENU_ITEM_FUNCTION_P(_i("Sort: [Time]"), lcd_sort_type_set); break;////MSG_SORT_TIME c=17 r=1
  3876. case SD_SORT_ALPHA: MENU_ITEM_FUNCTION_P(_i("Sort: [Alphabet]"), lcd_sort_type_set); break;////MSG_SORT_ALPHA c=17 r=1
  3877. default: MENU_ITEM_FUNCTION_P(_i("Sort: [None]"), lcd_sort_type_set);////MSG_SORT_NONE c=17 r=1
  3878. }
  3879. }
  3880. #endif // SDCARD_SORT_ALPHA
  3881. if (farm_mode)
  3882. {
  3883. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  3884. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  3885. }
  3886. MENU_END();
  3887. }
  3888. static void lcd_selftest_()
  3889. {
  3890. lcd_selftest();
  3891. }
  3892. #ifdef TMC2130
  3893. static void lcd_ustep_linearity_menu_save()
  3894. {
  3895. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  3896. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  3897. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  3898. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  3899. }
  3900. #endif //TMC2130
  3901. static void lcd_settings_menu_back()
  3902. {
  3903. #ifdef TMC2130
  3904. bool changed = false;
  3905. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  3906. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  3907. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  3908. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  3909. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  3910. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  3911. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  3912. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  3913. lcd_ustep_linearity_menu_save();
  3914. if (changed) tmc2130_init();
  3915. #endif //TMC2130
  3916. currentMenu = lcd_main_menu;
  3917. // lcd_main_menu();
  3918. }
  3919. #ifdef EXPERIMENTAL_FEATURES
  3920. static void lcd_experimantal_menu();
  3921. static void lcd_homing_accuracy_menu();
  3922. static void lcd_accurate_home_set()
  3923. {
  3924. tmc2130_home_enabled = tmc2130_home_enabled?0:1;
  3925. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, tmc2130_home_enabled);
  3926. }
  3927. static void lcd_homing_accuracy_menu_advanced_reset()
  3928. {
  3929. tmc2130_home_bsteps[X_AXIS] = 48;
  3930. tmc2130_home_fsteps[X_AXIS] = 48;
  3931. tmc2130_home_bsteps[Y_AXIS] = 48;
  3932. tmc2130_home_fsteps[Y_AXIS] = 48;
  3933. }
  3934. static void lcd_homing_accuracy_menu_advanced_save()
  3935. {
  3936. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_ORIGIN, tmc2130_home_origin[X_AXIS]);
  3937. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_BSTEPS, tmc2130_home_bsteps[X_AXIS]);
  3938. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_FSTEPS, tmc2130_home_fsteps[X_AXIS]);
  3939. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_ORIGIN, tmc2130_home_origin[Y_AXIS]);
  3940. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_BSTEPS, tmc2130_home_bsteps[Y_AXIS]);
  3941. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_FSTEPS, tmc2130_home_fsteps[Y_AXIS]);
  3942. }
  3943. static void lcd_homing_accuracy_menu_advanced_back()
  3944. {
  3945. lcd_homing_accuracy_menu_advanced_save();
  3946. currentMenu = lcd_homing_accuracy_menu;
  3947. lcd_homing_accuracy_menu();
  3948. }
  3949. static void lcd_homing_accuracy_menu_advanced()
  3950. {
  3951. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3952. MENU_BEGIN();
  3953. ///! MENU_ITEM_BACK_P(PSTR("Homing accuracy"), lcd_homing_accuracy_menu_advanced_back);
  3954. MENU_ITEM_FUNCTION_P(PSTR("Reset def. steps"), lcd_homing_accuracy_menu_advanced_reset);
  3955. MENU_ITEM_EDIT(byte3, PSTR("X-origin"), &tmc2130_home_origin[X_AXIS], 0, 63);
  3956. MENU_ITEM_EDIT(byte3, PSTR("Y-origin"), &tmc2130_home_origin[Y_AXIS], 0, 63);
  3957. MENU_ITEM_EDIT(byte3, PSTR("X-bsteps"), &tmc2130_home_bsteps[X_AXIS], 0, 128);
  3958. MENU_ITEM_EDIT(byte3, PSTR("Y-bsteps"), &tmc2130_home_bsteps[Y_AXIS], 0, 128);
  3959. MENU_ITEM_EDIT(byte3, PSTR("X-fsteps"), &tmc2130_home_fsteps[X_AXIS], 0, 128);
  3960. MENU_ITEM_EDIT(byte3, PSTR("Y-fsteps"), &tmc2130_home_fsteps[Y_AXIS], 0, 128);
  3961. MENU_END();
  3962. }
  3963. static void lcd_homing_accuracy_menu()
  3964. {
  3965. MENU_BEGIN();
  3966. MENU_ITEM_BACK_P(PSTR("Experimental"));
  3967. MENU_ITEM_FUNCTION_P(tmc2130_home_enabled?PSTR("Accur. homing On"):PSTR("Accur. homing Off"), lcd_accurate_home_set);
  3968. MENU_ITEM_GCODE_P(PSTR("Calibrate X"), PSTR("G28XC"));
  3969. MENU_ITEM_GCODE_P(PSTR("Calibrate Y"), PSTR("G28YC"));
  3970. MENU_ITEM_SUBMENU_P(PSTR("Advanced"), lcd_homing_accuracy_menu_advanced);
  3971. MENU_END();
  3972. }
  3973. static void lcd_ustep_resolution_menu_save()
  3974. {
  3975. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_X_MRES, tmc2130_mres[X_AXIS]);
  3976. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Y_MRES, tmc2130_mres[Y_AXIS]);
  3977. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Z_MRES, tmc2130_mres[Z_AXIS]);
  3978. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_E_MRES, tmc2130_mres[E_AXIS]);
  3979. }
  3980. static void lcd_ustep_resolution_menu_back()
  3981. {
  3982. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  3983. bool changed = false;
  3984. if (tmc2130_mres[X_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_X_MRES))
  3985. {
  3986. axis_steps_per_unit[X_AXIS] = tmp1[X_AXIS] * tmc2130_mres2usteps(tmc2130_mres[X_AXIS]) / TMC2130_USTEPS_XY;
  3987. changed = true;
  3988. }
  3989. if (tmc2130_mres[Y_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Y_MRES))
  3990. {
  3991. axis_steps_per_unit[Y_AXIS] = tmp1[Y_AXIS] * tmc2130_mres2usteps(tmc2130_mres[Y_AXIS]) / TMC2130_USTEPS_XY;
  3992. changed = true;
  3993. }
  3994. if (tmc2130_mres[Z_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Z_MRES))
  3995. {
  3996. axis_steps_per_unit[Z_AXIS] = tmp1[Z_AXIS] * tmc2130_mres2usteps(tmc2130_mres[Z_AXIS]) / TMC2130_USTEPS_Z;
  3997. changed = true;
  3998. }
  3999. if (tmc2130_mres[E_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_E_MRES))
  4000. {
  4001. axis_steps_per_unit[E_AXIS] = tmp1[E_AXIS] * tmc2130_mres2usteps(tmc2130_mres[E_AXIS]) / TMC2130_USTEPS_E;
  4002. changed = true;
  4003. }
  4004. if (changed)
  4005. {
  4006. lcd_ustep_resolution_menu_save();
  4007. Config_StoreSettings(EEPROM_OFFSET);
  4008. tmc2130_init();
  4009. }
  4010. currentMenu = lcd_experimantal_menu;
  4011. lcd_experimantal_menu();
  4012. }
  4013. static void lcd_ustep_resolution_reset_def_xyze()
  4014. {
  4015. tmc2130_mres[X_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY);
  4016. tmc2130_mres[Y_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY);
  4017. tmc2130_mres[Z_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_Z);
  4018. tmc2130_mres[E_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_E);
  4019. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  4020. axis_steps_per_unit[X_AXIS] = tmp1[X_AXIS];
  4021. axis_steps_per_unit[Y_AXIS] = tmp1[Y_AXIS];
  4022. axis_steps_per_unit[Z_AXIS] = tmp1[Z_AXIS];
  4023. axis_steps_per_unit[E_AXIS] = tmp1[E_AXIS];
  4024. }
  4025. static void lcd_ustep_resolution_menu()
  4026. {
  4027. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4028. MENU_BEGIN();
  4029. ///! MENU_ITEM_BACK_P(PSTR("Experimental"), lcd_ustep_resolution_menu_back);
  4030. MENU_ITEM_FUNCTION_P(PSTR("Reset defaults"), lcd_ustep_resolution_reset_def_xyze);
  4031. MENU_ITEM_EDIT(mres, PSTR("X-resolution"), &tmc2130_mres[X_AXIS], 4, 4);
  4032. MENU_ITEM_EDIT(mres, PSTR("Y-resolution"), &tmc2130_mres[Y_AXIS], 4, 4);
  4033. MENU_ITEM_EDIT(mres, PSTR("Z-resolution"), &tmc2130_mres[Z_AXIS], 4, 4);
  4034. MENU_ITEM_EDIT(mres, PSTR("E-resolution"), &tmc2130_mres[E_AXIS], 2, 5);
  4035. MENU_END();
  4036. }
  4037. static void lcd_ustep_linearity_menu_back()
  4038. {
  4039. bool changed = false;
  4040. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  4041. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  4042. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  4043. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  4044. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  4045. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  4046. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  4047. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  4048. lcd_ustep_linearity_menu_save();
  4049. if (changed) tmc2130_init();
  4050. currentMenu = lcd_experimantal_menu;
  4051. lcd_experimantal_menu();
  4052. }
  4053. static void lcd_ustep_linearity_menu_recomended()
  4054. {
  4055. tmc2130_wave_fac[X_AXIS] = 220;
  4056. tmc2130_wave_fac[Y_AXIS] = 220;
  4057. tmc2130_wave_fac[Z_AXIS] = 220;
  4058. tmc2130_wave_fac[E_AXIS] = 220;
  4059. }
  4060. static void lcd_ustep_linearity_menu_reset()
  4061. {
  4062. tmc2130_wave_fac[X_AXIS] = 0;
  4063. tmc2130_wave_fac[Y_AXIS] = 0;
  4064. tmc2130_wave_fac[Z_AXIS] = 0;
  4065. tmc2130_wave_fac[E_AXIS] = 0;
  4066. }
  4067. static void lcd_ustep_linearity_menu()
  4068. {
  4069. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4070. MENU_BEGIN();
  4071. ///! MENU_ITEM_BACK_P(PSTR("Experimental"), lcd_ustep_linearity_menu_back);
  4072. MENU_ITEM_FUNCTION_P(PSTR("Reset correction"), lcd_ustep_linearity_menu_reset);
  4073. MENU_ITEM_FUNCTION_P(PSTR("Recomended config"), lcd_ustep_linearity_menu_recomended);
  4074. MENU_ITEM_EDIT(wfac, PSTR("X-correction"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  4075. MENU_ITEM_EDIT(wfac, PSTR("Y-correction"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  4076. MENU_ITEM_EDIT(wfac, PSTR("Z-correction"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  4077. MENU_ITEM_EDIT(wfac, PSTR("E-correction"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  4078. MENU_END();
  4079. }
  4080. static void lcd_experimantal_menu_save_all()
  4081. {
  4082. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, tmc2130_home_enabled);
  4083. lcd_ustep_resolution_menu_save();
  4084. lcd_ustep_linearity_menu_save();
  4085. Config_StoreSettings(EEPROM_OFFSET);
  4086. }
  4087. static void lcd_experimantal_menu_disable_all()
  4088. {
  4089. tmc2130_home_enabled = 0;
  4090. lcd_ustep_resolution_reset_def_xyze();
  4091. lcd_ustep_linearity_menu_reset();
  4092. lcd_experimantal_menu_save_all();
  4093. tmc2130_init();
  4094. }
  4095. static void lcd_experimantal_menu()
  4096. {
  4097. MENU_BEGIN();
  4098. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4099. MENU_ITEM_FUNCTION_P(PSTR("All Xfeatures off"), lcd_experimantal_menu_disable_all);
  4100. MENU_ITEM_SUBMENU_P(PSTR("Homing accuracy"), lcd_homing_accuracy_menu);
  4101. MENU_ITEM_SUBMENU_P(PSTR("uStep resolution"), lcd_ustep_resolution_menu);
  4102. MENU_ITEM_SUBMENU_P(PSTR("uStep linearity"), lcd_ustep_linearity_menu);
  4103. MENU_END();
  4104. }
  4105. #endif //EXPERIMENTAL_FEATURES
  4106. static void lcd_calibration_menu()
  4107. {
  4108. MENU_BEGIN();
  4109. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4110. if (!isPrintPaused)
  4111. {
  4112. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17 r=1
  4113. MENU_ITEM_SUBMENU_P(_i("First layer cal."), lcd_v2_calibration);////MSG_V2_CALIBRATION c=17 r=1
  4114. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  4115. MENU_ITEM_FUNCTION_P(_i("Selftest "), lcd_selftest_v);////MSG_SELFTEST c=0 r=0
  4116. #ifdef MK1BP
  4117. // MK1
  4118. // "Calibrate Z"
  4119. MENU_ITEM_GCODE_P(_T(MSG_HOMEYZ), PSTR("G28 Z"));
  4120. #else //MK1BP
  4121. // MK2
  4122. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=0 r=0
  4123. // "Calibrate Z" with storing the reference values to EEPROM.
  4124. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  4125. #ifndef SNMM
  4126. //MENU_ITEM_FUNCTION_P(_i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20 r=1
  4127. #endif
  4128. // "Mesh Bed Leveling"
  4129. MENU_ITEM_SUBMENU_P(_i("Mesh Bed Leveling"), lcd_mesh_bedleveling);////MSG_MESH_BED_LEVELING c=0 r=0
  4130. #endif //MK1BP
  4131. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=0 r=0
  4132. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17 r=1
  4133. #ifndef TMC2130
  4134. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=17 r=1
  4135. #endif
  4136. #ifndef MK1BP
  4137. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=0 r=0
  4138. #endif //MK1BP
  4139. #ifndef SNMM
  4140. //MENU_ITEM_FUNCTION_P(MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  4141. #endif
  4142. #ifndef MK1BP
  4143. MENU_ITEM_SUBMENU_P(_i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17 r=1
  4144. #endif //MK1BP
  4145. }
  4146. MENU_END();
  4147. }
  4148. void bowden_menu() {
  4149. int enc_dif = encoderDiff;
  4150. int cursor_pos = 0;
  4151. lcd_implementation_clear();
  4152. lcd.setCursor(0, 0);
  4153. lcd.print(">");
  4154. for (int i = 0; i < 4; i++) {
  4155. lcd.setCursor(1, i);
  4156. lcd.print("Extruder ");
  4157. lcd.print(i);
  4158. lcd.print(": ");
  4159. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4160. lcd.print(bowden_length[i] - 48);
  4161. }
  4162. enc_dif = encoderDiff;
  4163. while (1) {
  4164. manage_heater();
  4165. manage_inactivity(true);
  4166. if (abs((enc_dif - encoderDiff)) > 2) {
  4167. if (enc_dif > encoderDiff) {
  4168. cursor_pos--;
  4169. }
  4170. if (enc_dif < encoderDiff) {
  4171. cursor_pos++;
  4172. }
  4173. if (cursor_pos > 3) {
  4174. cursor_pos = 3;
  4175. }
  4176. if (cursor_pos < 0) {
  4177. cursor_pos = 0;
  4178. }
  4179. lcd.setCursor(0, 0);
  4180. lcd.print(" ");
  4181. lcd.setCursor(0, 1);
  4182. lcd.print(" ");
  4183. lcd.setCursor(0, 2);
  4184. lcd.print(" ");
  4185. lcd.setCursor(0, 3);
  4186. lcd.print(" ");
  4187. lcd.setCursor(0, cursor_pos);
  4188. lcd.print(">");
  4189. enc_dif = encoderDiff;
  4190. delay(100);
  4191. }
  4192. if (lcd_clicked()) {
  4193. while (lcd_clicked());
  4194. delay(10);
  4195. while (lcd_clicked());
  4196. lcd_implementation_clear();
  4197. while (1) {
  4198. manage_heater();
  4199. manage_inactivity(true);
  4200. lcd.setCursor(1, 1);
  4201. lcd.print("Extruder ");
  4202. lcd.print(cursor_pos);
  4203. lcd.print(": ");
  4204. lcd.setCursor(13, 1);
  4205. lcd.print(bowden_length[cursor_pos] - 48);
  4206. if (abs((enc_dif - encoderDiff)) > 2) {
  4207. if (enc_dif > encoderDiff) {
  4208. bowden_length[cursor_pos]--;
  4209. lcd.setCursor(13, 1);
  4210. lcd.print(bowden_length[cursor_pos] - 48);
  4211. enc_dif = encoderDiff;
  4212. }
  4213. if (enc_dif < encoderDiff) {
  4214. bowden_length[cursor_pos]++;
  4215. lcd.setCursor(13, 1);
  4216. lcd.print(bowden_length[cursor_pos] - 48);
  4217. enc_dif = encoderDiff;
  4218. }
  4219. }
  4220. delay(100);
  4221. if (lcd_clicked()) {
  4222. while (lcd_clicked());
  4223. delay(10);
  4224. while (lcd_clicked());
  4225. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  4226. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  4227. lcd_update_enable(true);
  4228. lcd_implementation_clear();
  4229. enc_dif = encoderDiff;
  4230. lcd.setCursor(0, cursor_pos);
  4231. lcd.print(">");
  4232. for (int i = 0; i < 4; i++) {
  4233. lcd.setCursor(1, i);
  4234. lcd.print("Extruder ");
  4235. lcd.print(i);
  4236. lcd.print(": ");
  4237. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4238. lcd.print(bowden_length[i] - 48);
  4239. }
  4240. break;
  4241. }
  4242. else return;
  4243. }
  4244. }
  4245. }
  4246. }
  4247. }
  4248. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  4249. lcd_implementation_clear();
  4250. lcd_print_at_PGM(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd.print(":");
  4251. lcd.setCursor(0, 1); lcd.print(">");
  4252. lcd_print_at_PGM(1,2,_i("Used during print"));////MSG_USED c=19 r=1
  4253. lcd_print_at_PGM(1,3,_i("Current"));////MSG_CURRENT c=19 r=1
  4254. char cursor_pos = 1;
  4255. int enc_dif = 0;
  4256. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4257. while (1) {
  4258. manage_heater();
  4259. manage_inactivity(true);
  4260. if (abs((enc_dif - encoderDiff)) > 4) {
  4261. if ((abs(enc_dif - encoderDiff)) > 1) {
  4262. if (enc_dif > encoderDiff) cursor_pos--;
  4263. if (enc_dif < encoderDiff) cursor_pos++;
  4264. if (cursor_pos > 3) cursor_pos = 3;
  4265. if (cursor_pos < 1) cursor_pos = 1;
  4266. lcd.setCursor(0, 1);
  4267. lcd.print(" ");
  4268. lcd.setCursor(0, 2);
  4269. lcd.print(" ");
  4270. lcd.setCursor(0, 3);
  4271. lcd.print(" ");
  4272. lcd.setCursor(0, cursor_pos);
  4273. lcd.print(">");
  4274. enc_dif = encoderDiff;
  4275. delay(100);
  4276. }
  4277. }
  4278. if (lcd_clicked()) {
  4279. while (lcd_clicked());
  4280. delay(10);
  4281. while (lcd_clicked());
  4282. KEEPALIVE_STATE(IN_HANDLER);
  4283. return(cursor_pos - 1);
  4284. }
  4285. }
  4286. }
  4287. char choose_extruder_menu() {
  4288. int items_no = 4;
  4289. int first = 0;
  4290. int enc_dif = 0;
  4291. char cursor_pos = 1;
  4292. enc_dif = encoderDiff;
  4293. lcd_implementation_clear();
  4294. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4295. lcd.setCursor(0, 1);
  4296. lcd.print(">");
  4297. for (int i = 0; i < 3; i++) {
  4298. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4299. }
  4300. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4301. while (1) {
  4302. for (int i = 0; i < 3; i++) {
  4303. lcd.setCursor(2 + strlen_P(_T(MSG_EXTRUDER)), i+1);
  4304. lcd.print(first + i + 1);
  4305. }
  4306. manage_heater();
  4307. manage_inactivity(true);
  4308. if (abs((enc_dif - encoderDiff)) > 4) {
  4309. if ((abs(enc_dif - encoderDiff)) > 1) {
  4310. if (enc_dif > encoderDiff) {
  4311. cursor_pos--;
  4312. }
  4313. if (enc_dif < encoderDiff) {
  4314. cursor_pos++;
  4315. }
  4316. if (cursor_pos > 3) {
  4317. cursor_pos = 3;
  4318. if (first < items_no - 3) {
  4319. first++;
  4320. lcd_implementation_clear();
  4321. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4322. for (int i = 0; i < 3; i++) {
  4323. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4324. }
  4325. }
  4326. }
  4327. if (cursor_pos < 1) {
  4328. cursor_pos = 1;
  4329. if (first > 0) {
  4330. first--;
  4331. lcd_implementation_clear();
  4332. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4333. for (int i = 0; i < 3; i++) {
  4334. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4335. }
  4336. }
  4337. }
  4338. lcd.setCursor(0, 1);
  4339. lcd.print(" ");
  4340. lcd.setCursor(0, 2);
  4341. lcd.print(" ");
  4342. lcd.setCursor(0, 3);
  4343. lcd.print(" ");
  4344. lcd.setCursor(0, cursor_pos);
  4345. lcd.print(">");
  4346. enc_dif = encoderDiff;
  4347. delay(100);
  4348. }
  4349. }
  4350. if (lcd_clicked()) {
  4351. lcd_update(2);
  4352. while (lcd_clicked());
  4353. delay(10);
  4354. while (lcd_clicked());
  4355. KEEPALIVE_STATE(IN_HANDLER);
  4356. return(cursor_pos + first - 1);
  4357. }
  4358. }
  4359. }
  4360. char reset_menu() {
  4361. #ifdef SNMM
  4362. int items_no = 5;
  4363. #else
  4364. int items_no = 4;
  4365. #endif
  4366. static int first = 0;
  4367. int enc_dif = 0;
  4368. char cursor_pos = 0;
  4369. const char *item [items_no];
  4370. item[0] = "Language";
  4371. item[1] = "Statistics";
  4372. item[2] = "Shipping prep";
  4373. item[3] = "All Data";
  4374. #ifdef SNMM
  4375. item[4] = "Bowden length";
  4376. #endif // SNMM
  4377. enc_dif = encoderDiff;
  4378. lcd_implementation_clear();
  4379. lcd.setCursor(0, 0);
  4380. lcd.print(">");
  4381. while (1) {
  4382. for (int i = 0; i < 4; i++) {
  4383. lcd.setCursor(1, i);
  4384. lcd.print(item[first + i]);
  4385. }
  4386. manage_heater();
  4387. manage_inactivity(true);
  4388. if (abs((enc_dif - encoderDiff)) > 4) {
  4389. if ((abs(enc_dif - encoderDiff)) > 1) {
  4390. if (enc_dif > encoderDiff) {
  4391. cursor_pos--;
  4392. }
  4393. if (enc_dif < encoderDiff) {
  4394. cursor_pos++;
  4395. }
  4396. if (cursor_pos > 3) {
  4397. cursor_pos = 3;
  4398. if (first < items_no - 4) {
  4399. first++;
  4400. lcd_implementation_clear();
  4401. }
  4402. }
  4403. if (cursor_pos < 0) {
  4404. cursor_pos = 0;
  4405. if (first > 0) {
  4406. first--;
  4407. lcd_implementation_clear();
  4408. }
  4409. }
  4410. lcd.setCursor(0, 0);
  4411. lcd.print(" ");
  4412. lcd.setCursor(0, 1);
  4413. lcd.print(" ");
  4414. lcd.setCursor(0, 2);
  4415. lcd.print(" ");
  4416. lcd.setCursor(0, 3);
  4417. lcd.print(" ");
  4418. lcd.setCursor(0, cursor_pos);
  4419. lcd.print(">");
  4420. enc_dif = encoderDiff;
  4421. delay(100);
  4422. }
  4423. }
  4424. if (lcd_clicked()) {
  4425. while (lcd_clicked());
  4426. delay(10);
  4427. while (lcd_clicked());
  4428. return(cursor_pos + first);
  4429. }
  4430. }
  4431. }
  4432. static void lcd_disable_farm_mode() {
  4433. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  4434. if (disable) {
  4435. enquecommand_P(PSTR("G99"));
  4436. lcd_return_to_status();
  4437. }
  4438. else {
  4439. lcd_goto_menu(lcd_settings_menu); //doesn't break menuStack
  4440. }
  4441. lcd_update_enable(true);
  4442. lcdDrawUpdate = 2;
  4443. }
  4444. #ifdef SNMM
  4445. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  4446. set_extrude_min_temp(.0);
  4447. current_position[E_AXIS] += shift;
  4448. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  4449. set_extrude_min_temp(EXTRUDE_MINTEMP);
  4450. }
  4451. void change_extr(int extr) { //switches multiplexer for extruders
  4452. st_synchronize();
  4453. delay(100);
  4454. disable_e0();
  4455. disable_e1();
  4456. disable_e2();
  4457. snmm_extruder = extr;
  4458. pinMode(E_MUX0_PIN, OUTPUT);
  4459. pinMode(E_MUX1_PIN, OUTPUT);
  4460. switch (extr) {
  4461. case 1:
  4462. WRITE(E_MUX0_PIN, HIGH);
  4463. WRITE(E_MUX1_PIN, LOW);
  4464. break;
  4465. case 2:
  4466. WRITE(E_MUX0_PIN, LOW);
  4467. WRITE(E_MUX1_PIN, HIGH);
  4468. break;
  4469. case 3:
  4470. WRITE(E_MUX0_PIN, HIGH);
  4471. WRITE(E_MUX1_PIN, HIGH);
  4472. break;
  4473. default:
  4474. WRITE(E_MUX0_PIN, LOW);
  4475. WRITE(E_MUX1_PIN, LOW);
  4476. break;
  4477. }
  4478. delay(100);
  4479. }
  4480. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  4481. return(2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  4482. }
  4483. void display_loading() {
  4484. switch (snmm_extruder) {
  4485. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  4486. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  4487. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  4488. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  4489. }
  4490. }
  4491. void extr_adj(int extruder) //loading filament for SNMM
  4492. {
  4493. bool correct;
  4494. max_feedrate[E_AXIS] =80;
  4495. //max_feedrate[E_AXIS] = 50;
  4496. START:
  4497. lcd_implementation_clear();
  4498. lcd.setCursor(0, 0);
  4499. switch (extruder) {
  4500. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  4501. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  4502. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  4503. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  4504. }
  4505. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4506. do{
  4507. extr_mov(0.001,1000);
  4508. delay_keep_alive(2);
  4509. } while (!lcd_clicked());
  4510. //delay_keep_alive(500);
  4511. KEEPALIVE_STATE(IN_HANDLER);
  4512. st_synchronize();
  4513. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  4514. //if (!correct) goto START;
  4515. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  4516. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  4517. extr_mov(bowden_length[extruder], 500);
  4518. lcd_implementation_clear();
  4519. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_LOADING_FILAMENT));
  4520. if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd.setCursor(0, 1);
  4521. else lcd.print(" ");
  4522. lcd.print(snmm_extruder + 1);
  4523. lcd.setCursor(0, 2); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  4524. st_synchronize();
  4525. max_feedrate[E_AXIS] = 50;
  4526. lcd_update_enable(true);
  4527. lcd_return_to_status();
  4528. lcdDrawUpdate = 2;
  4529. }
  4530. void extr_unload() { //unloads filament
  4531. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  4532. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  4533. uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
  4534. if (degHotend0() > EXTRUDE_MINTEMP) {
  4535. lcd_implementation_clear();
  4536. lcd_display_message_fullscreen_P(PSTR(""));
  4537. max_feedrate[E_AXIS] = 50;
  4538. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_UNLOADING_FILAMENT));
  4539. lcd.print(" ");
  4540. lcd.print(snmm_extruder + 1);
  4541. lcd.setCursor(0, 2); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  4542. if (current_position[Z_AXIS] < 15) {
  4543. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  4544. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  4545. }
  4546. current_position[E_AXIS] += 10; //extrusion
  4547. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  4548. st_current_set(2, E_MOTOR_HIGH_CURRENT);
  4549. if (current_temperature[0] < 230) { //PLA & all other filaments
  4550. current_position[E_AXIS] += 5.4;
  4551. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  4552. current_position[E_AXIS] += 3.2;
  4553. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4554. current_position[E_AXIS] += 3;
  4555. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  4556. }
  4557. else { //ABS
  4558. current_position[E_AXIS] += 3.1;
  4559. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  4560. current_position[E_AXIS] += 3.1;
  4561. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  4562. current_position[E_AXIS] += 4;
  4563. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4564. /*current_position[X_AXIS] += 23; //delay
  4565. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  4566. current_position[X_AXIS] -= 23; //delay
  4567. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  4568. delay_keep_alive(4700);
  4569. }
  4570. max_feedrate[E_AXIS] = 80;
  4571. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4572. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4573. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4574. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4575. st_synchronize();
  4576. //st_current_init();
  4577. if (SilentMode != SILENT_MODE_OFF) st_current_set(2, tmp_motor[2]); //set back to normal operation currents
  4578. else st_current_set(2, tmp_motor_loud[2]);
  4579. lcd_update_enable(true);
  4580. lcd_return_to_status();
  4581. max_feedrate[E_AXIS] = 50;
  4582. }
  4583. else {
  4584. lcd_implementation_clear();
  4585. lcd.setCursor(0, 0);
  4586. lcd_printPGM(_T(MSG_ERROR));
  4587. lcd.setCursor(0, 2);
  4588. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4589. delay(2000);
  4590. lcd_implementation_clear();
  4591. }
  4592. lcd_return_to_status();
  4593. }
  4594. //wrapper functions for loading filament
  4595. static void extr_adj_0(){
  4596. change_extr(0);
  4597. extr_adj(0);
  4598. }
  4599. static void extr_adj_1() {
  4600. change_extr(1);
  4601. extr_adj(1);
  4602. }
  4603. static void extr_adj_2() {
  4604. change_extr(2);
  4605. extr_adj(2);
  4606. }
  4607. static void extr_adj_3() {
  4608. change_extr(3);
  4609. extr_adj(3);
  4610. }
  4611. static void load_all() {
  4612. for (int i = 0; i < 4; i++) {
  4613. change_extr(i);
  4614. extr_adj(i);
  4615. }
  4616. }
  4617. //wrapper functions for changing extruders
  4618. static void extr_change_0() {
  4619. change_extr(0);
  4620. lcd_return_to_status();
  4621. }
  4622. static void extr_change_1() {
  4623. change_extr(1);
  4624. lcd_return_to_status();
  4625. }
  4626. static void extr_change_2() {
  4627. change_extr(2);
  4628. lcd_return_to_status();
  4629. }
  4630. static void extr_change_3() {
  4631. change_extr(3);
  4632. lcd_return_to_status();
  4633. }
  4634. //wrapper functions for unloading filament
  4635. void extr_unload_all() {
  4636. if (degHotend0() > EXTRUDE_MINTEMP) {
  4637. for (int i = 0; i < 4; i++) {
  4638. change_extr(i);
  4639. extr_unload();
  4640. }
  4641. }
  4642. else {
  4643. lcd_implementation_clear();
  4644. lcd.setCursor(0, 0);
  4645. lcd_printPGM(_T(MSG_ERROR));
  4646. lcd.setCursor(0, 2);
  4647. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4648. delay(2000);
  4649. lcd_implementation_clear();
  4650. lcd_return_to_status();
  4651. }
  4652. }
  4653. //unloading just used filament (for snmm)
  4654. void extr_unload_used() {
  4655. if (degHotend0() > EXTRUDE_MINTEMP) {
  4656. for (int i = 0; i < 4; i++) {
  4657. if (snmm_filaments_used & (1 << i)) {
  4658. change_extr(i);
  4659. extr_unload();
  4660. }
  4661. }
  4662. snmm_filaments_used = 0;
  4663. }
  4664. else {
  4665. lcd_implementation_clear();
  4666. lcd.setCursor(0, 0);
  4667. lcd_printPGM(_T(MSG_ERROR));
  4668. lcd.setCursor(0, 2);
  4669. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4670. delay(2000);
  4671. lcd_implementation_clear();
  4672. lcd_return_to_status();
  4673. }
  4674. }
  4675. static void extr_unload_0() {
  4676. change_extr(0);
  4677. extr_unload();
  4678. }
  4679. static void extr_unload_1() {
  4680. change_extr(1);
  4681. extr_unload();
  4682. }
  4683. static void extr_unload_2() {
  4684. change_extr(2);
  4685. extr_unload();
  4686. }
  4687. static void extr_unload_3() {
  4688. change_extr(3);
  4689. extr_unload();
  4690. }
  4691. static void fil_load_menu()
  4692. {
  4693. MENU_BEGIN();
  4694. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4695. MENU_ITEM_FUNCTION_P(_i("Load all"), load_all);////MSG_LOAD_ALL c=0 r=0
  4696. MENU_ITEM_FUNCTION_P(_i("Load filament 1"), extr_adj_0);////MSG_LOAD_FILAMENT_1 c=17 r=0
  4697. MENU_ITEM_FUNCTION_P(_i("Load filament 2"), extr_adj_1);////MSG_LOAD_FILAMENT_2 c=17 r=0
  4698. MENU_ITEM_FUNCTION_P(_i("Load filament 3"), extr_adj_2);////MSG_LOAD_FILAMENT_3 c=17 r=0
  4699. MENU_ITEM_FUNCTION_P(_i("Load filament 4"), extr_adj_3);////MSG_LOAD_FILAMENT_4 c=17 r=0
  4700. MENU_END();
  4701. }
  4702. static void fil_unload_menu()
  4703. {
  4704. MENU_BEGIN();
  4705. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4706. MENU_ITEM_FUNCTION_P(_i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=0 r=0
  4707. MENU_ITEM_FUNCTION_P(_i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17 r=0
  4708. MENU_ITEM_FUNCTION_P(_i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17 r=0
  4709. MENU_ITEM_FUNCTION_P(_i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17 r=0
  4710. MENU_ITEM_FUNCTION_P(_i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17 r=0
  4711. MENU_END();
  4712. }
  4713. static void change_extr_menu(){
  4714. MENU_BEGIN();
  4715. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4716. MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1
  4717. MENU_ITEM_FUNCTION_P(_i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17 r=1
  4718. MENU_ITEM_FUNCTION_P(_i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17 r=1
  4719. MENU_ITEM_FUNCTION_P(_i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17 r=1
  4720. MENU_END();
  4721. }
  4722. #endif
  4723. static void lcd_farm_no()
  4724. {
  4725. char step = 0;
  4726. int enc_dif = 0;
  4727. int _farmno = farm_no;
  4728. int _ret = 0;
  4729. lcd_implementation_clear();
  4730. lcd.setCursor(0, 0);
  4731. lcd.print("Farm no");
  4732. do
  4733. {
  4734. if (abs((enc_dif - encoderDiff)) > 2) {
  4735. if (enc_dif > encoderDiff) {
  4736. switch (step) {
  4737. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4738. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4739. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4740. default: break;
  4741. }
  4742. }
  4743. if (enc_dif < encoderDiff) {
  4744. switch (step) {
  4745. case(0): if (_farmno < 900) _farmno += 100; break;
  4746. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4747. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4748. default: break;
  4749. }
  4750. }
  4751. enc_dif = 0;
  4752. encoderDiff = 0;
  4753. }
  4754. lcd.setCursor(0, 2);
  4755. if (_farmno < 100) lcd.print("0");
  4756. if (_farmno < 10) lcd.print("0");
  4757. lcd.print(_farmno);
  4758. lcd.print(" ");
  4759. lcd.setCursor(0, 3);
  4760. lcd.print(" ");
  4761. lcd.setCursor(step, 3);
  4762. lcd.print("^");
  4763. delay(100);
  4764. if (lcd_clicked())
  4765. {
  4766. delay(200);
  4767. step++;
  4768. if(step == 3) {
  4769. _ret = 1;
  4770. farm_no = _farmno;
  4771. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4772. prusa_statistics(20);
  4773. lcd_return_to_status();
  4774. }
  4775. }
  4776. manage_heater();
  4777. } while (_ret == 0);
  4778. }
  4779. unsigned char lcd_choose_color() {
  4780. //function returns index of currently chosen item
  4781. //following part can be modified from 2 to 255 items:
  4782. //-----------------------------------------------------
  4783. unsigned char items_no = 2;
  4784. const char *item[items_no];
  4785. item[0] = "Orange";
  4786. item[1] = "Black";
  4787. //-----------------------------------------------------
  4788. unsigned char active_rows;
  4789. static int first = 0;
  4790. int enc_dif = 0;
  4791. unsigned char cursor_pos = 1;
  4792. enc_dif = encoderDiff;
  4793. lcd_implementation_clear();
  4794. lcd.setCursor(0, 1);
  4795. lcd.print(">");
  4796. active_rows = items_no < 3 ? items_no : 3;
  4797. while (1) {
  4798. lcd_print_at_PGM(0, 0, PSTR("Choose color:"));
  4799. for (int i = 0; i < active_rows; i++) {
  4800. lcd.setCursor(1, i+1);
  4801. lcd.print(item[first + i]);
  4802. }
  4803. manage_heater();
  4804. manage_inactivity(true);
  4805. proc_commands();
  4806. if (abs((enc_dif - encoderDiff)) > 12) {
  4807. if (enc_dif > encoderDiff) {
  4808. cursor_pos--;
  4809. }
  4810. if (enc_dif < encoderDiff) {
  4811. cursor_pos++;
  4812. }
  4813. if (cursor_pos > active_rows) {
  4814. cursor_pos = active_rows;
  4815. if (first < items_no - active_rows) {
  4816. first++;
  4817. lcd_implementation_clear();
  4818. }
  4819. }
  4820. if (cursor_pos < 1) {
  4821. cursor_pos = 1;
  4822. if (first > 0) {
  4823. first--;
  4824. lcd_implementation_clear();
  4825. }
  4826. }
  4827. lcd.setCursor(0, 1);
  4828. lcd.print(" ");
  4829. lcd.setCursor(0, 2);
  4830. lcd.print(" ");
  4831. lcd.setCursor(0, 3);
  4832. lcd.print(" ");
  4833. lcd.setCursor(0, cursor_pos);
  4834. lcd.print(">");
  4835. enc_dif = encoderDiff;
  4836. delay(100);
  4837. }
  4838. if (lcd_clicked()) {
  4839. while (lcd_clicked());
  4840. delay(10);
  4841. while (lcd_clicked());
  4842. switch(cursor_pos + first - 1) {
  4843. case 0: return 1; break;
  4844. case 1: return 0; break;
  4845. default: return 99; break;
  4846. }
  4847. }
  4848. }
  4849. }
  4850. void lcd_confirm_print()
  4851. {
  4852. uint8_t filament_type;
  4853. int enc_dif = 0;
  4854. int cursor_pos = 1;
  4855. int _ret = 0;
  4856. int _t = 0;
  4857. enc_dif = encoderDiff;
  4858. lcd_implementation_clear();
  4859. lcd.setCursor(0, 0);
  4860. lcd.print("Print ok ?");
  4861. do
  4862. {
  4863. if (abs(enc_dif - encoderDiff) > 12) {
  4864. if (enc_dif > encoderDiff) {
  4865. cursor_pos--;
  4866. }
  4867. if (enc_dif < encoderDiff) {
  4868. cursor_pos++;
  4869. }
  4870. enc_dif = encoderDiff;
  4871. }
  4872. if (cursor_pos > 2) { cursor_pos = 2; }
  4873. if (cursor_pos < 1) { cursor_pos = 1; }
  4874. lcd.setCursor(0, 2); lcd.print(" ");
  4875. lcd.setCursor(0, 3); lcd.print(" ");
  4876. lcd.setCursor(2, 2);
  4877. lcd_printPGM(_T(MSG_YES));
  4878. lcd.setCursor(2, 3);
  4879. lcd_printPGM(_T(MSG_NO));
  4880. lcd.setCursor(0, 1 + cursor_pos);
  4881. lcd.print(">");
  4882. delay(100);
  4883. _t = _t + 1;
  4884. if (_t>100)
  4885. {
  4886. prusa_statistics(99);
  4887. _t = 0;
  4888. }
  4889. if (lcd_clicked())
  4890. {
  4891. if (cursor_pos == 1)
  4892. {
  4893. _ret = 1;
  4894. filament_type = lcd_choose_color();
  4895. prusa_statistics(4, filament_type);
  4896. no_response = true; //we need confirmation by recieving PRUSA thx
  4897. important_status = 4;
  4898. saved_filament_type = filament_type;
  4899. NcTime = millis();
  4900. }
  4901. if (cursor_pos == 2)
  4902. {
  4903. _ret = 2;
  4904. filament_type = lcd_choose_color();
  4905. prusa_statistics(5, filament_type);
  4906. no_response = true; //we need confirmation by recieving PRUSA thx
  4907. important_status = 5;
  4908. saved_filament_type = filament_type;
  4909. NcTime = millis();
  4910. }
  4911. }
  4912. manage_heater();
  4913. manage_inactivity();
  4914. proc_commands();
  4915. } while (_ret == 0);
  4916. }
  4917. #include "w25x20cl.h"
  4918. static void lcd_test_menu()
  4919. {
  4920. W25X20CL_SPI_ENTER();
  4921. w25x20cl_enable_wr();
  4922. w25x20cl_chip_erase();
  4923. w25x20cl_disable_wr();
  4924. }
  4925. static void lcd_main_menu()
  4926. {
  4927. SDscrool = 0;
  4928. MENU_BEGIN();
  4929. // Majkl superawesome menu
  4930. MENU_ITEM_BACK_P(_T(MSG_WATCH));
  4931. #ifdef RESUME_DEBUG
  4932. if (!saved_printing)
  4933. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  4934. else
  4935. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  4936. #endif //RESUME_DEBUG
  4937. #ifdef TMC2130_DEBUG
  4938. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  4939. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  4940. #endif //TMC2130_DEBUG
  4941. /* if (farm_mode && !IS_SD_PRINTING )
  4942. {
  4943. int tempScrool = 0;
  4944. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4945. //delay(100);
  4946. return; // nothing to do (so don't thrash the SD card)
  4947. uint16_t fileCnt = card.getnrfilenames();
  4948. card.getWorkDirName();
  4949. if (card.filename[0] == '/')
  4950. {
  4951. #if SDCARDDETECT == -1
  4952. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  4953. #endif
  4954. } else {
  4955. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4956. }
  4957. for (uint16_t i = 0; i < fileCnt; i++)
  4958. {
  4959. if (_menuItemNr == _lineNr)
  4960. {
  4961. #ifndef SDCARD_RATHERRECENTFIRST
  4962. card.getfilename(i);
  4963. #else
  4964. card.getfilename(fileCnt - 1 - i);
  4965. #endif
  4966. if (card.filenameIsDir)
  4967. {
  4968. MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4969. } else {
  4970. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4971. }
  4972. } else {
  4973. MENU_ITEM_DUMMY();
  4974. }
  4975. }
  4976. MENU_ITEM_BACK_P(PSTR("- - - - - - - - -"));
  4977. }*/
  4978. 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)
  4979. {
  4980. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4981. }
  4982. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4983. {
  4984. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=0 r=0
  4985. } else
  4986. {
  4987. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=0 r=0
  4988. }
  4989. #ifdef SDSUPPORT
  4990. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4991. {
  4992. if (card.isFileOpen())
  4993. {
  4994. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4995. if (card.sdprinting)
  4996. {
  4997. MENU_ITEM_FUNCTION_P(_i("Pause print"), lcd_sdcard_pause);////MSG_PAUSE_PRINT c=0 r=0
  4998. }
  4999. else
  5000. {
  5001. MENU_ITEM_FUNCTION_P(_i("Resume print"), lcd_sdcard_resume);////MSG_RESUME_PRINT c=0 r=0
  5002. }
  5003. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  5004. }
  5005. }
  5006. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  5007. //MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  5008. }
  5009. else
  5010. {
  5011. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  5012. {
  5013. //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  5014. /*else*/ MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  5015. }
  5016. #if SDCARDDETECT < 1
  5017. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD c=0 r=0
  5018. #endif
  5019. }
  5020. } else
  5021. {
  5022. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=0 r=0
  5023. #if SDCARDDETECT < 1
  5024. 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
  5025. #endif
  5026. }
  5027. #endif
  5028. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  5029. {
  5030. if (farm_mode)
  5031. {
  5032. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  5033. }
  5034. }
  5035. else
  5036. {
  5037. #ifndef SNMM
  5038. #ifdef PAT9125
  5039. if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true)))
  5040. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0
  5041. else
  5042. #endif //PAT9125
  5043. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  5044. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  5045. #endif
  5046. #ifdef SNMM
  5047. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
  5048. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  5049. MENU_ITEM_SUBMENU_P(_i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20 r=1
  5050. #endif
  5051. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  5052. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  5053. #ifdef EXPERIMENTAL_FEATURES
  5054. MENU_ITEM_SUBMENU_P(PSTR("Experimantal"), lcd_experimantal_menu);
  5055. #endif //EXPERIMENTAL_FEATURES
  5056. }
  5057. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  5058. {
  5059. MENU_ITEM_SUBMENU_P(_i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS c=0 r=0
  5060. }
  5061. #if defined(TMC2130) || defined(PAT9125)
  5062. MENU_ITEM_SUBMENU_P(PSTR("Fail stats"), lcd_menu_fails_stats);
  5063. #endif
  5064. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=0 r=0
  5065. MENU_ITEM_SUBMENU_P(_i("W25x20CL init"), lcd_test_menu);////MSG_SUPPORT c=0 r=0
  5066. MENU_END();
  5067. }
  5068. void stack_error() {
  5069. SET_OUTPUT(BEEPER);
  5070. WRITE(BEEPER, HIGH);
  5071. delay(1000);
  5072. WRITE(BEEPER, LOW);
  5073. lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4
  5074. //err_triggered = 1;
  5075. while (1) delay_keep_alive(1000);
  5076. }
  5077. #ifdef DEBUG_STEPPER_TIMER_MISSED
  5078. bool stepper_timer_overflow_state = false;
  5079. uint16_t stepper_timer_overflow_max = 0;
  5080. uint16_t stepper_timer_overflow_last = 0;
  5081. uint16_t stepper_timer_overflow_cnt = 0;
  5082. void stepper_timer_overflow() {
  5083. char msg[28];
  5084. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  5085. lcd_setstatus(msg);
  5086. stepper_timer_overflow_state = false;
  5087. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  5088. stepper_timer_overflow_max = stepper_timer_overflow_last;
  5089. SERIAL_ECHOPGM("Stepper timer overflow: ");
  5090. MYSERIAL.print(msg);
  5091. SERIAL_ECHOLNPGM("");
  5092. WRITE(BEEPER, LOW);
  5093. }
  5094. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5095. #ifdef SDSUPPORT
  5096. static void lcd_autostart_sd()
  5097. {
  5098. card.lastnr = 0;
  5099. card.setroot();
  5100. card.checkautostart(true);
  5101. }
  5102. #endif
  5103. static void lcd_silent_mode_set_tune() {
  5104. switch (SilentModeMenu) {
  5105. #ifdef TMC2130
  5106. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  5107. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  5108. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  5109. #else
  5110. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  5111. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  5112. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  5113. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  5114. #endif //TMC2130
  5115. }
  5116. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  5117. st_current_init();
  5118. menu_back();
  5119. }
  5120. static void lcd_colorprint_change() {
  5121. enquecommand_P(PSTR("M600"));
  5122. custom_message = true;
  5123. custom_message_type = 2; //just print status message
  5124. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5125. lcd_return_to_status();
  5126. lcdDrawUpdate = 3;
  5127. }
  5128. static void lcd_tune_menu()
  5129. {
  5130. if (menuData.tuneMenu.status == 0) {
  5131. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  5132. menuData.tuneMenu.status = 1;
  5133. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  5134. } else if (menuData.tuneMenu.extrudemultiply != extrudemultiply) {
  5135. // extrudemultiply has been changed from the child menu. Apply the new value.
  5136. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  5137. calculate_extruder_multipliers();
  5138. }
  5139. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  5140. MENU_BEGIN();
  5141. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  5142. MENU_ITEM_EDIT(int3, _i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=0 r=0
  5143. MENU_ITEM_EDIT(int3, _T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  5144. MENU_ITEM_EDIT(int3, _T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  5145. MENU_ITEM_EDIT(int3, _T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  5146. MENU_ITEM_EDIT(int3, _i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=0 r=0
  5147. #ifdef FILAMENTCHANGEENABLE
  5148. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//7
  5149. #endif
  5150. #ifndef DEBUG_DISABLE_FSENSORCHECK
  5151. #ifdef PAT9125
  5152. if (FSensorStateMenu == 0) {
  5153. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  5154. }
  5155. else {
  5156. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  5157. }
  5158. #endif //PAT9125
  5159. #endif //DEBUG_DISABLE_FSENSORCHECK
  5160. #ifdef TMC2130
  5161. if(!farm_mode)
  5162. {
  5163. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);
  5164. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  5165. if (SilentModeMenu == SILENT_MODE_NORMAL)
  5166. {
  5167. if (CrashDetectMenu == 0) MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);
  5168. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  5169. }
  5170. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  5171. }
  5172. #else //TMC2130
  5173. if (!farm_mode) { //dont show in menu if we are in farm mode
  5174. switch (SilentModeMenu) {
  5175. case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  5176. case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  5177. case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  5178. default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  5179. }
  5180. }
  5181. #endif //TMC2130
  5182. MENU_END();
  5183. }
  5184. static void lcd_move_menu_01mm()
  5185. {
  5186. move_menu_scale = 0.1;
  5187. lcd_move_menu_axis();
  5188. }
  5189. static void lcd_control_temperature_menu()
  5190. {
  5191. #ifdef PIDTEMP
  5192. // set up temp variables - undo the default scaling
  5193. // raw_Ki = unscalePID_i(Ki);
  5194. // raw_Kd = unscalePID_d(Kd);
  5195. #endif
  5196. MENU_BEGIN();
  5197. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5198. #if TEMP_SENSOR_0 != 0
  5199. MENU_ITEM_EDIT(int3, _T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  5200. #endif
  5201. #if TEMP_SENSOR_1 != 0
  5202. MENU_ITEM_EDIT(int3, _i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1 c=0 r=0
  5203. #endif
  5204. #if TEMP_SENSOR_2 != 0
  5205. MENU_ITEM_EDIT(int3, _i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2 c=0 r=0
  5206. #endif
  5207. #if TEMP_SENSOR_BED != 0
  5208. MENU_ITEM_EDIT(int3, _T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  5209. #endif
  5210. MENU_ITEM_EDIT(int3, _T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  5211. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  5212. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  5213. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN c=0 r=0
  5214. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX c=0 r=0
  5215. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR c=0 r=0
  5216. #endif
  5217. MENU_END();
  5218. }
  5219. #if SDCARDDETECT == -1
  5220. static void lcd_sd_refresh()
  5221. {
  5222. card.initsd();
  5223. currentMenuViewOffset = 0;
  5224. }
  5225. #endif
  5226. static void lcd_sd_updir()
  5227. {
  5228. SDscrool = 0;
  5229. card.updir();
  5230. currentMenuViewOffset = 0;
  5231. }
  5232. void lcd_print_stop() {
  5233. cancel_heatup = true;
  5234. #ifdef MESH_BED_LEVELING
  5235. mbl.active = false;
  5236. #endif
  5237. // Stop the stoppers, update the position from the stoppers.
  5238. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  5239. planner_abort_hard();
  5240. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  5241. // Z baystep is no more applied. Reset it.
  5242. babystep_reset();
  5243. }
  5244. // Clean the input command queue.
  5245. cmdqueue_reset();
  5246. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  5247. lcd_update(2);
  5248. card.sdprinting = false;
  5249. card.closefile();
  5250. stoptime = millis();
  5251. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5252. pause_time = 0;
  5253. save_statistics(total_filament_used, t);
  5254. lcd_return_to_status();
  5255. lcd_ignore_click(true);
  5256. lcd_commands_step = 0;
  5257. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  5258. // Turn off the print fan
  5259. SET_OUTPUT(FAN_PIN);
  5260. WRITE(FAN_PIN, 0);
  5261. fanSpeed = 0;
  5262. }
  5263. void lcd_sdcard_stop()
  5264. {
  5265. lcd.setCursor(0, 0);
  5266. lcd_printPGM(_T(MSG_STOP_PRINT));
  5267. lcd.setCursor(2, 2);
  5268. lcd_printPGM(_T(MSG_NO));
  5269. lcd.setCursor(2, 3);
  5270. lcd_printPGM(_T(MSG_YES));
  5271. lcd.setCursor(0, 2); lcd.print(" ");
  5272. lcd.setCursor(0, 3); lcd.print(" ");
  5273. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  5274. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  5275. lcd.setCursor(0, 1 + encoderPosition);
  5276. lcd.print(">");
  5277. if (lcd_clicked())
  5278. {
  5279. if ((int32_t)encoderPosition == 1)
  5280. {
  5281. lcd_return_to_status();
  5282. }
  5283. if ((int32_t)encoderPosition == 2)
  5284. {
  5285. lcd_print_stop();
  5286. }
  5287. }
  5288. }
  5289. /*
  5290. void getFileDescription(char *name, char *description) {
  5291. // get file description, ie the REAL filenam, ie the second line
  5292. card.openFile(name, true);
  5293. int i = 0;
  5294. // skip the first line (which is the version line)
  5295. while (true) {
  5296. uint16_t readByte = card.get();
  5297. if (readByte == '\n') {
  5298. break;
  5299. }
  5300. }
  5301. // read the second line (which is the description line)
  5302. while (true) {
  5303. uint16_t readByte = card.get();
  5304. if (i == 0) {
  5305. // skip the first '^'
  5306. readByte = card.get();
  5307. }
  5308. description[i] = readByte;
  5309. i++;
  5310. if (readByte == '\n') {
  5311. break;
  5312. }
  5313. }
  5314. card.closefile();
  5315. description[i-1] = 0;
  5316. }
  5317. */
  5318. void lcd_sdcard_menu()
  5319. {
  5320. printf_P(_N("menu sd\n"));
  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