ultralcd.cpp 193 KB

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