ultralcd.cpp 177 KB

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