ultralcd.cpp 147 KB

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