ultralcd.cpp 226 KB

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