ultralcd.cpp 181 KB

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