ultralcd.cpp 146 KB

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