ultralcd.cpp 130 KB

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