ultralcd.cpp 127 KB

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