ultralcd.cpp 153 KB

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