ultralcd.cpp 145 KB

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