ultralcd.cpp 224 KB

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