ultralcd.cpp 225 KB

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