ultralcd.cpp 224 KB

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