ultralcd.cpp 153 KB

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