ultralcd.cpp 136 KB

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