ultralcd.cpp 156 KB

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