ultralcd.cpp 146 KB

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