ultralcd.cpp 132 KB

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