ultralcd.cpp 223 KB

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