ultralcd.cpp 157 KB

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