ultralcd.cpp 220 KB

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