ultralcd.cpp 142 KB

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