ultralcd.cpp 221 KB

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