My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 129KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "ultralcd.h"
  23. #if ENABLED(ULTRA_LCD)
  24. #include "Marlin.h"
  25. #include "language.h"
  26. #include "cardreader.h"
  27. #include "temperature.h"
  28. #include "stepper.h"
  29. #include "configuration_store.h"
  30. #include "utility.h"
  31. #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
  32. #include "buzzer.h"
  33. #endif
  34. #if ENABLED(BLTOUCH)
  35. #include "endstops.h"
  36. #endif
  37. #if ENABLED(PRINTCOUNTER)
  38. #include "printcounter.h"
  39. #include "duration_t.h"
  40. #endif
  41. int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  42. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  43. millis_t previous_lcd_status_ms = 0;
  44. #endif
  45. #if ENABLED(BABYSTEPPING)
  46. long babysteps_done = 0;
  47. static void lcd_babystep_z();
  48. #endif
  49. uint8_t lcd_status_message_level;
  50. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  51. #if ENABLED(DOGLCD)
  52. #include "ultralcd_impl_DOGM.h"
  53. #include <U8glib.h>
  54. #else
  55. #include "ultralcd_impl_HD44780.h"
  56. #endif
  57. // The main status screen
  58. void lcd_status_screen();
  59. millis_t next_lcd_update_ms;
  60. uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
  61. uint16_t max_display_update_time = 0;
  62. #if ENABLED(DOGLCD)
  63. bool drawing_screen = false;
  64. #define LCDVIEW_KEEP_REDRAWING LCDVIEW_CALL_REDRAW_NEXT
  65. #else
  66. #define LCDVIEW_KEEP_REDRAWING LCDVIEW_REDRAW_NOW
  67. #endif
  68. #if ENABLED(DAC_STEPPER_CURRENT)
  69. #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
  70. int16_t driverPercent[XYZE];
  71. #endif
  72. #if ENABLED(ULTIPANEL)
  73. // place-holders for Ki and Kd edits
  74. float raw_Ki, raw_Kd;
  75. /**
  76. * REVERSE_MENU_DIRECTION
  77. *
  78. * To reverse the menu direction we need a general way to reverse
  79. * the direction of the encoder everywhere. So encoderDirection is
  80. * added to allow the encoder to go the other way.
  81. *
  82. * This behavior is limited to scrolling Menus and SD card listings,
  83. * and is disabled in other contexts.
  84. */
  85. #if ENABLED(REVERSE_MENU_DIRECTION)
  86. int8_t encoderDirection = 1;
  87. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  88. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  89. #else
  90. #define ENCODER_DIRECTION_NORMAL() ;
  91. #define ENCODER_DIRECTION_MENUS() ;
  92. #endif
  93. int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update
  94. millis_t manual_move_start_time = 0;
  95. int8_t manual_move_axis = (int8_t)NO_AXIS;
  96. #if EXTRUDERS > 1
  97. int8_t manual_move_e_index = 0;
  98. #else
  99. #define manual_move_e_index 0
  100. #endif
  101. bool encoderRateMultiplierEnabled;
  102. int32_t lastEncoderMovementMillis;
  103. #if ENABLED(AUTO_BED_LEVELING_UBL)
  104. #include "ubl.h"
  105. #endif
  106. #if HAS_POWER_SWITCH
  107. extern bool powersupply;
  108. #endif
  109. const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
  110. void lcd_main_menu();
  111. void lcd_tune_menu();
  112. void lcd_prepare_menu();
  113. void lcd_move_menu();
  114. void lcd_control_menu();
  115. void lcd_control_temperature_menu();
  116. void lcd_control_temperature_preheat_material1_settings_menu();
  117. void lcd_control_temperature_preheat_material2_settings_menu();
  118. void lcd_control_motion_menu();
  119. void lcd_control_volumetric_menu();
  120. #if ENABLED(DAC_STEPPER_CURRENT)
  121. void dac_driver_commit();
  122. void dac_driver_getValues();
  123. void lcd_dac_menu();
  124. void lcd_dac_write_eeprom();
  125. #endif
  126. #if ENABLED(LCD_INFO_MENU)
  127. #if ENABLED(PRINTCOUNTER)
  128. void lcd_info_stats_menu();
  129. #endif
  130. void lcd_info_thermistors_menu();
  131. void lcd_info_board_menu();
  132. void lcd_info_menu();
  133. #endif // LCD_INFO_MENU
  134. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  135. void lcd_filament_change_toocold_menu();
  136. void lcd_filament_change_option_menu();
  137. void lcd_filament_change_init_message();
  138. void lcd_filament_change_unload_message();
  139. void lcd_filament_change_insert_message();
  140. void lcd_filament_change_load_message();
  141. void lcd_filament_change_heat_nozzle();
  142. void lcd_filament_change_extrude_message();
  143. void lcd_filament_change_resume_message();
  144. #endif
  145. #if HAS_LCD_CONTRAST
  146. void lcd_set_contrast();
  147. #endif
  148. #if ENABLED(FWRETRACT)
  149. void lcd_control_retract_menu();
  150. #endif
  151. #if ENABLED(DELTA_CALIBRATION_MENU)
  152. void lcd_delta_calibrate_menu();
  153. #endif
  154. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  155. #include "mesh_bed_leveling.h"
  156. #endif
  157. // Function pointer to menu functions.
  158. typedef void (*screenFunc_t)();
  159. // Different types of actions that can be used in menu items.
  160. #define menu_action_back(dummy) _menu_action_back()
  161. void _menu_action_back();
  162. void menu_action_submenu(screenFunc_t data);
  163. void menu_action_gcode(const char* pgcode);
  164. void menu_action_function(screenFunc_t data);
  165. void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  166. void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  167. void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  168. void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  169. void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  170. void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  171. void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  172. void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  173. void menu_action_setting_edit_float62(const char* pstr, float* ptr, float minValue, float maxValue);
  174. void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  175. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
  176. void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, screenFunc_t callbackFunc);
  177. void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  178. void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  179. void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  180. void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  181. void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  182. void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  183. void menu_action_setting_edit_callback_float62(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  184. void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, screenFunc_t callbackFunc);
  185. #if ENABLED(SDSUPPORT)
  186. void lcd_sdcard_menu();
  187. void menu_action_sdfile(const char* filename, char* longFilename);
  188. void menu_action_sddirectory(const char* filename, char* longFilename);
  189. #endif
  190. /* Helper macros for menus */
  191. #ifndef ENCODER_FEEDRATE_DEADZONE
  192. #define ENCODER_FEEDRATE_DEADZONE 10
  193. #endif
  194. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  195. #define ENCODER_STEPS_PER_MENU_ITEM 5
  196. #endif
  197. #ifndef ENCODER_PULSES_PER_STEP
  198. #define ENCODER_PULSES_PER_STEP 1
  199. #endif
  200. #ifndef TALL_FONT_CORRECTION
  201. #define TALL_FONT_CORRECTION 0
  202. #endif
  203. /**
  204. * START_SCREEN_OR_MENU generates init code for a screen or menu
  205. *
  206. * encoderLine is the position based on the encoder
  207. * encoderTopLine is the top menu line to display
  208. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  209. * _menuLineNr is the menu item to draw and process
  210. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  211. * _countedItems is the total number of items in the menu (after one call)
  212. */
  213. #define START_SCREEN_OR_MENU(LIMIT) \
  214. ENCODER_DIRECTION_MENUS(); \
  215. encoderRateMultiplierEnabled = false; \
  216. if (encoderPosition > 0x8000) encoderPosition = 0; \
  217. static int8_t _countedItems = 0; \
  218. int8_t encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
  219. if (_countedItems > 0 && encoderLine >= _countedItems - (LIMIT)) { \
  220. encoderLine = max(0, _countedItems - (LIMIT)); \
  221. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  222. }
  223. #define SCREEN_OR_MENU_LOOP() \
  224. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  225. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT - (TALL_FONT_CORRECTION); _lcdLineNr++, _menuLineNr++) { \
  226. _thisItemNr = 0
  227. /**
  228. * START_SCREEN Opening code for a screen having only static items.
  229. * Do simplified scrolling of the entire screen.
  230. *
  231. * START_MENU Opening code for a screen with menu items.
  232. * Scroll as-needed to keep the selected line in view.
  233. */
  234. #define START_SCREEN() \
  235. START_SCREEN_OR_MENU(LCD_HEIGHT - (TALL_FONT_CORRECTION)); \
  236. encoderTopLine = encoderLine; \
  237. bool _skipStatic = false; \
  238. SCREEN_OR_MENU_LOOP()
  239. #define START_MENU() \
  240. START_SCREEN_OR_MENU(1); \
  241. screen_changed = false; \
  242. NOMORE(encoderTopLine, encoderLine); \
  243. if (encoderLine >= encoderTopLine + LCD_HEIGHT - (TALL_FONT_CORRECTION)) { \
  244. encoderTopLine = encoderLine - (LCD_HEIGHT - (TALL_FONT_CORRECTION) - 1); \
  245. } \
  246. bool _skipStatic = true; \
  247. SCREEN_OR_MENU_LOOP()
  248. /**
  249. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  250. *
  251. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  252. * menu_action_[type](arg3...)
  253. *
  254. * Examples:
  255. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  256. * or
  257. * MENU_BACK(MSG_WATCH)
  258. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  259. * menu_action_back()
  260. *
  261. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  262. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  263. * menu_action_function(lcd_sdcard_pause)
  264. *
  265. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  266. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  267. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  268. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  269. *
  270. */
  271. #define _MENU_ITEM_PART_1(TYPE, LABEL, ...) \
  272. if (_menuLineNr == _thisItemNr) { \
  273. if (lcdDrawUpdate) \
  274. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  275. if (lcd_clicked && encoderLine == _thisItemNr) {
  276. #define _MENU_ITEM_PART_2(TYPE, ...) \
  277. menu_action_ ## TYPE(__VA_ARGS__); \
  278. if (screen_changed) return; \
  279. } \
  280. } \
  281. ++_thisItemNr
  282. #define MENU_ITEM(TYPE, LABEL, ...) do { \
  283. _skipStatic = false; \
  284. _MENU_ITEM_PART_1(TYPE, LABEL, ## __VA_ARGS__); \
  285. _MENU_ITEM_PART_2(TYPE, ## __VA_ARGS__); \
  286. } while(0)
  287. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
  288. // Used to print static text with no visible cursor.
  289. // Parameters: label [, bool center [, bool invert [, char *value] ] ]
  290. #define STATIC_ITEM(LABEL, ...) \
  291. if (_menuLineNr == _thisItemNr) { \
  292. if (_skipStatic && encoderLine <= _thisItemNr) { \
  293. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  294. ++encoderLine; \
  295. } \
  296. if (lcdDrawUpdate) \
  297. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  298. } \
  299. ++_thisItemNr
  300. #define END_SCREEN() \
  301. } \
  302. _countedItems = _thisItemNr
  303. #define END_MENU() \
  304. } \
  305. _countedItems = _thisItemNr; \
  306. UNUSED(_skipStatic)
  307. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  308. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  309. /**
  310. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  311. */
  312. #define MENU_MULTIPLIER_ITEM(type, label, ...) do { \
  313. _MENU_ITEM_PART_1(type, label, ## __VA_ARGS__); \
  314. encoderRateMultiplierEnabled = true; \
  315. lastEncoderMovementMillis = 0; \
  316. _MENU_ITEM_PART_2(type, ## __VA_ARGS__); \
  317. } while(0)
  318. #endif //ENCODER_RATE_MULTIPLIER
  319. #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0)
  320. #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  321. #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  322. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  323. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  324. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  325. #else //!ENCODER_RATE_MULTIPLIER
  326. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  327. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  328. #endif //!ENCODER_RATE_MULTIPLIER
  329. /** Used variables to keep track of the menu */
  330. volatile uint8_t buttons; //the last checked buttons in a bit array.
  331. #if ENABLED(REPRAPWORLD_KEYPAD)
  332. volatile uint8_t buttons_reprapworld_keypad; // to store the keypad shift register values
  333. #endif
  334. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  335. volatile uint8_t slow_buttons; // Bits of the pressed buttons.
  336. #endif
  337. int8_t encoderTopLine; /* scroll offset in the current menu */
  338. millis_t next_button_update_ms;
  339. uint8_t lastEncoderBits;
  340. uint32_t encoderPosition;
  341. #if PIN_EXISTS(SD_DETECT)
  342. uint8_t lcd_sd_status;
  343. #endif
  344. typedef struct {
  345. screenFunc_t menu_function;
  346. uint32_t encoder_position;
  347. } menuPosition;
  348. screenFunc_t currentScreen = lcd_status_screen; // pointer to the currently active menu handler
  349. menuPosition screen_history[10];
  350. uint8_t screen_history_depth = 0;
  351. bool screen_changed;
  352. // LCD and menu clicks
  353. bool lcd_clicked, wait_for_unclick, defer_return_to_status;
  354. // Variables used when editing values.
  355. const char* editLabel;
  356. void* editValue;
  357. int32_t minEditValue, maxEditValue;
  358. screenFunc_t callbackFunc; // call this after editing
  359. /**
  360. * General function to go directly to a screen
  361. */
  362. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0) {
  363. if (currentScreen != screen) {
  364. #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
  365. static millis_t doubleclick_expire_ms = 0;
  366. // Going to lcd_main_menu from status screen? Remember first click time.
  367. // Going back to status screen within a very short time? Go to Z babystepping.
  368. if (screen == lcd_main_menu) {
  369. if (currentScreen == lcd_status_screen)
  370. doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
  371. }
  372. else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms))
  373. screen = lcd_babystep_z;
  374. #endif
  375. currentScreen = screen;
  376. encoderPosition = encoder;
  377. if (screen == lcd_status_screen) {
  378. defer_return_to_status = false;
  379. screen_history_depth = 0;
  380. }
  381. lcd_implementation_clear();
  382. #if ENABLED(LCD_PROGRESS_BAR)
  383. // For LCD_PROGRESS_BAR re-initialize custom characters
  384. lcd_set_custom_characters(screen == lcd_status_screen);
  385. #endif
  386. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  387. screen_changed = true;
  388. #if ENABLED(DOGLCD)
  389. drawing_screen = false;
  390. #endif
  391. }
  392. }
  393. /**
  394. * Synchronize safely while holding the current screen
  395. * This blocks all further screen or stripe updates once called
  396. */
  397. extern uint8_t commands_in_queue;
  398. inline void lcd_synchronize() {
  399. static bool no_reentry = false;
  400. lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_MOVING));
  401. if (no_reentry) return;
  402. no_reentry = true;
  403. screenFunc_t old_screen = currentScreen;
  404. lcd_goto_screen(lcd_synchronize);
  405. while (commands_in_queue) {
  406. idle();
  407. stepper.synchronize();
  408. }
  409. no_reentry = false;
  410. lcd_goto_screen(old_screen);
  411. }
  412. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  413. void lcd_save_previous_screen() {
  414. if (screen_history_depth < COUNT(screen_history)) {
  415. screen_history[screen_history_depth].menu_function = currentScreen;
  416. screen_history[screen_history_depth].encoder_position = encoderPosition;
  417. ++screen_history_depth;
  418. }
  419. }
  420. void lcd_goto_previous_menu() {
  421. if (screen_history_depth > 0) {
  422. --screen_history_depth;
  423. lcd_goto_screen(
  424. screen_history[screen_history_depth].menu_function,
  425. screen_history[screen_history_depth].encoder_position
  426. );
  427. }
  428. else
  429. lcd_return_to_status();
  430. }
  431. #endif // ULTIPANEL
  432. /**
  433. *
  434. * "Info Screen"
  435. *
  436. * This is very display-dependent, so the lcd implementation draws this.
  437. */
  438. void lcd_status_screen() {
  439. #if ENABLED(ULTIPANEL)
  440. ENCODER_DIRECTION_NORMAL();
  441. encoderRateMultiplierEnabled = false;
  442. #endif
  443. #if ENABLED(LCD_PROGRESS_BAR)
  444. millis_t ms = millis();
  445. #if DISABLED(PROGRESS_MSG_ONCE)
  446. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
  447. progress_bar_ms = ms;
  448. }
  449. #endif
  450. #if PROGRESS_MSG_EXPIRE > 0
  451. // Handle message expire
  452. if (expire_status_ms > 0) {
  453. #if ENABLED(SDSUPPORT)
  454. if (card.isFileOpen()) {
  455. // Expire the message when printing is active
  456. if (IS_SD_PRINTING) {
  457. if (ELAPSED(ms, expire_status_ms)) {
  458. lcd_status_message[0] = '\0';
  459. expire_status_ms = 0;
  460. }
  461. }
  462. else {
  463. expire_status_ms += LCD_UPDATE_INTERVAL;
  464. }
  465. }
  466. else {
  467. expire_status_ms = 0;
  468. }
  469. #else
  470. expire_status_ms = 0;
  471. #endif //SDSUPPORT
  472. }
  473. #endif
  474. #endif //LCD_PROGRESS_BAR
  475. lcd_implementation_status_screen();
  476. #if ENABLED(ULTIPANEL)
  477. if (lcd_clicked) {
  478. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  479. previous_lcd_status_ms = millis(); // get status message to show up for a while
  480. #endif
  481. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  482. #if ENABLED(LCD_PROGRESS_BAR)
  483. false
  484. #endif
  485. );
  486. lcd_goto_screen(lcd_main_menu);
  487. }
  488. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  489. int new_frm = feedrate_percentage + (int32_t)encoderPosition;
  490. // Dead zone at 100% feedrate
  491. if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
  492. feedrate_percentage = 100;
  493. encoderPosition = 0;
  494. }
  495. else if (feedrate_percentage == 100) {
  496. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  497. feedrate_percentage += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  498. encoderPosition = 0;
  499. }
  500. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  501. feedrate_percentage += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  502. encoderPosition = 0;
  503. }
  504. }
  505. else {
  506. feedrate_percentage = new_frm;
  507. encoderPosition = 0;
  508. }
  509. #endif // ULTIPANEL_FEEDMULTIPLY
  510. feedrate_percentage = constrain(feedrate_percentage, 10, 999);
  511. #endif //ULTIPANEL
  512. }
  513. /**
  514. *
  515. * draw the kill screen
  516. *
  517. */
  518. void kill_screen(const char* lcd_msg) {
  519. lcd_init();
  520. lcd_setalertstatuspgm(lcd_msg);
  521. #if ENABLED(DOGLCD)
  522. u8g.firstPage();
  523. do {
  524. lcd_kill_screen();
  525. } while (u8g.nextPage());
  526. #else
  527. lcd_kill_screen();
  528. #endif
  529. }
  530. #if ENABLED(ULTIPANEL)
  531. /**
  532. *
  533. * Audio feedback for controller clicks
  534. *
  535. */
  536. void lcd_buzz(long duration, uint16_t freq) {
  537. #if ENABLED(LCD_USE_I2C_BUZZER)
  538. lcd.buzz(duration, freq);
  539. #elif PIN_EXISTS(BEEPER)
  540. buzzer.tone(duration, freq);
  541. #else
  542. UNUSED(duration); UNUSED(freq);
  543. #endif
  544. }
  545. void lcd_quick_feedback() {
  546. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  547. buttons = 0;
  548. next_button_update_ms = millis() + 500;
  549. // Buzz and wait. The delay is needed for buttons to settle!
  550. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  551. #if ENABLED(LCD_USE_I2C_BUZZER)
  552. delay(10);
  553. #elif PIN_EXISTS(BEEPER)
  554. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  555. #endif
  556. }
  557. void lcd_completion_feedback(const bool good/*=true*/) {
  558. if (good) {
  559. lcd_buzz(100, 659);
  560. lcd_buzz(100, 698);
  561. }
  562. else lcd_buzz(20, 440);
  563. }
  564. inline void line_to_current(AxisEnum axis) {
  565. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[axis]), active_extruder);
  566. }
  567. #if ENABLED(SDSUPPORT)
  568. void lcd_sdcard_pause() {
  569. card.pauseSDPrint();
  570. print_job_timer.pause();
  571. #if ENABLED(PARK_HEAD_ON_PAUSE)
  572. enqueue_and_echo_commands_P(PSTR("M125"));
  573. #endif
  574. }
  575. void lcd_sdcard_resume() {
  576. #if ENABLED(PARK_HEAD_ON_PAUSE)
  577. enqueue_and_echo_commands_P(PSTR("M24"));
  578. #else
  579. card.startFileprint();
  580. print_job_timer.start();
  581. #endif
  582. }
  583. void lcd_sdcard_stop() {
  584. card.stopSDPrint();
  585. clear_command_queue();
  586. quickstop_stepper();
  587. print_job_timer.stop();
  588. #if ENABLED(AUTOTEMP)
  589. thermalManager.autotempShutdown();
  590. #endif
  591. wait_for_heatup = false;
  592. lcd_setstatuspgm(PSTR(MSG_PRINT_ABORTED), true);
  593. }
  594. #endif // SDSUPPORT
  595. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  596. extern bool case_light_on;
  597. extern void update_case_light();
  598. void toggle_case_light() {
  599. case_light_on ^= true;
  600. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  601. update_case_light();
  602. }
  603. #endif // MENU_ITEM_CASE_LIGHT
  604. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  605. static void progress_bar_test() {
  606. static int8_t bar_percent = 0;
  607. if (lcd_clicked) {
  608. lcd_goto_previous_menu();
  609. lcd_set_custom_characters(false);
  610. return;
  611. }
  612. bar_percent += (int8_t)encoderPosition;
  613. bar_percent = constrain(bar_percent, 0, 100);
  614. encoderPosition = 0;
  615. lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
  616. lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
  617. lcd.print(itostr3(bar_percent)); lcd.print('%');
  618. lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
  619. }
  620. void _progress_bar_test() {
  621. lcd_goto_screen(progress_bar_test);
  622. lcd_set_custom_characters();
  623. }
  624. #endif // LCD_PROGRESS_BAR_TEST
  625. #if HAS_DEBUG_MENU
  626. void lcd_debug_menu() {
  627. START_MENU();
  628. MENU_BACK(MSG_MAIN); // ^ Main
  629. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  630. MENU_ITEM(submenu, MSG_PROGRESS_BAR_TEST, _progress_bar_test);
  631. #endif
  632. END_MENU();
  633. }
  634. #endif // HAS_DEBUG_MENU
  635. /**
  636. *
  637. * "Main" menu
  638. *
  639. */
  640. void lcd_main_menu() {
  641. START_MENU();
  642. MENU_BACK(MSG_WATCH);
  643. //
  644. // Debug Menu when certain options are enabled
  645. //
  646. #if HAS_DEBUG_MENU
  647. MENU_ITEM(submenu, MSG_DEBUG_MENU, lcd_debug_menu);
  648. #endif
  649. //
  650. // Switch case light on/off
  651. //
  652. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  653. if (case_light_on)
  654. MENU_ITEM(function, MSG_LIGHTS_OFF, toggle_case_light);
  655. else
  656. MENU_ITEM(function, MSG_LIGHTS_ON, toggle_case_light);
  657. #endif
  658. #if ENABLED(BLTOUCH)
  659. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  660. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  661. #endif
  662. if (planner.movesplanned() || IS_SD_PRINTING) {
  663. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  664. }
  665. else {
  666. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  667. #if ENABLED(DELTA_CALIBRATION_MENU)
  668. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  669. #endif
  670. }
  671. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  672. #if ENABLED(SDSUPPORT)
  673. if (card.cardOK) {
  674. if (card.isFileOpen()) {
  675. if (card.sdprinting)
  676. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  677. else
  678. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  679. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  680. }
  681. else {
  682. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  683. #if !PIN_EXISTS(SD_DETECT)
  684. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  685. #endif
  686. }
  687. }
  688. else {
  689. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  690. #if !PIN_EXISTS(SD_DETECT)
  691. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  692. #endif
  693. }
  694. #endif //SDSUPPORT
  695. #if ENABLED(LCD_INFO_MENU)
  696. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  697. #endif
  698. END_MENU();
  699. }
  700. /**
  701. *
  702. * "Tune" submenu items
  703. *
  704. */
  705. #if DISABLED(NO_WORKSPACE_OFFSETS)
  706. /**
  707. * Set the home offset based on the current_position
  708. */
  709. void lcd_set_home_offsets() {
  710. // M428 Command
  711. enqueue_and_echo_commands_P(PSTR("M428"));
  712. lcd_return_to_status();
  713. }
  714. #endif
  715. #if ENABLED(BABYSTEPPING)
  716. void _lcd_babystep(const AxisEnum axis, const char* msg) {
  717. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  718. ENCODER_DIRECTION_NORMAL();
  719. if (encoderPosition) {
  720. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  721. encoderPosition = 0;
  722. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  723. thermalManager.babystep_axis(axis, babystep_increment);
  724. babysteps_done += babystep_increment;
  725. }
  726. if (lcdDrawUpdate)
  727. lcd_implementation_drawedit(msg, ftostr43sign(planner.steps_to_mm[axis] * babysteps_done));
  728. }
  729. #if ENABLED(BABYSTEP_XY)
  730. void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  731. void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  732. void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
  733. void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
  734. #endif
  735. #if HAS_BED_PROBE
  736. void lcd_babystep_zoffset() {
  737. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  738. defer_return_to_status = true;
  739. ENCODER_DIRECTION_NORMAL();
  740. if (encoderPosition) {
  741. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  742. encoderPosition = 0;
  743. const float new_zoffset = zprobe_zoffset + steps_to_mm[Z_AXIS] * babystep_increment;
  744. if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
  745. if (planner.abl_enabled)
  746. thermalManager.babystep_axis(Z_AXIS, babystep_increment);
  747. zprobe_zoffset = new_zoffset;
  748. refresh_zprobe_zoffset(true);
  749. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  750. }
  751. }
  752. if (lcdDrawUpdate)
  753. lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
  754. }
  755. #else // !HAS_BED_PROBE
  756. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  757. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  758. #endif // HAS_BED_PROBE
  759. #endif //BABYSTEPPING
  760. #if ENABLED(AUTO_BED_LEVELING_UBL)
  761. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  762. // seperate value that doesn't lose precision.
  763. static int ubl_encoderPosition = 0;
  764. static void _lcd_mesh_fine_tune(const char* msg) {
  765. defer_return_to_status = true;
  766. if (ubl.encoder_diff) {
  767. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  768. ubl.encoder_diff = 0;
  769. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
  770. mesh_edit_value = mesh_edit_accumulator;
  771. encoderPosition = 0;
  772. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  773. const int32_t rounded = (int32_t)(mesh_edit_value * 1000.0);
  774. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
  775. }
  776. if (lcdDrawUpdate)
  777. lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
  778. }
  779. void _lcd_mesh_edit_NOP() {
  780. defer_return_to_status = true;
  781. }
  782. void _lcd_mesh_edit() {
  783. _lcd_mesh_fine_tune(PSTR("Mesh Editor: "));
  784. }
  785. float lcd_mesh_edit() {
  786. lcd_goto_screen(_lcd_mesh_edit_NOP);
  787. _lcd_mesh_fine_tune(PSTR("Mesh Editor: "));
  788. return mesh_edit_value;
  789. }
  790. void lcd_mesh_edit_setup(float initial) {
  791. mesh_edit_value = mesh_edit_accumulator = initial;
  792. lcd_goto_screen(_lcd_mesh_edit_NOP);
  793. }
  794. void _lcd_z_offset_edit() {
  795. _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
  796. }
  797. float lcd_z_offset_edit() {
  798. lcd_goto_screen(_lcd_z_offset_edit);
  799. return mesh_edit_value;
  800. }
  801. void lcd_z_offset_edit_setup(float initial) {
  802. mesh_edit_value = mesh_edit_accumulator = initial;
  803. lcd_goto_screen(_lcd_z_offset_edit);
  804. }
  805. #endif // AUTO_BED_LEVELING_UBL
  806. /**
  807. * Watch temperature callbacks
  808. */
  809. #if HAS_TEMP_HOTEND
  810. #if WATCH_HOTENDS
  811. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  812. #else
  813. #define _WATCH_FUNC(N) NOOP
  814. #endif
  815. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  816. #if HOTENDS > 1
  817. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  818. #if HOTENDS > 2
  819. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  820. #if HOTENDS > 3
  821. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  822. #if HOTENDS > 4
  823. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  824. #endif // HOTENDS > 4
  825. #endif // HOTENDS > 3
  826. #endif // HOTENDS > 2
  827. #endif // HOTENDS > 1
  828. #endif // HAS_TEMP_HOTEND
  829. #if WATCH_THE_BED
  830. void watch_temp_callback_bed() { thermalManager.start_watching_bed(); }
  831. #endif
  832. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  833. void lcd_enqueue_filament_change() {
  834. if (!DEBUGGING(DRYRUN) && thermalManager.tooColdToExtrude(active_extruder)) {
  835. lcd_save_previous_screen();
  836. lcd_goto_screen(lcd_filament_change_toocold_menu);
  837. return;
  838. }
  839. lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_INIT);
  840. enqueue_and_echo_commands_P(PSTR("M600"));
  841. }
  842. #endif
  843. /**
  844. *
  845. * "Tune" submenu
  846. *
  847. */
  848. void lcd_tune_menu() {
  849. START_MENU();
  850. //
  851. // ^ Main
  852. //
  853. MENU_BACK(MSG_MAIN);
  854. //
  855. // Speed:
  856. //
  857. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  858. // Manual bed leveling, Bed Z:
  859. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  860. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  861. #endif
  862. //
  863. // Nozzle:
  864. // Nozzle [1-4]:
  865. //
  866. #if HOTENDS == 1
  867. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  868. #else //HOTENDS > 1
  869. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  870. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  871. #if HOTENDS > 2
  872. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  873. #if HOTENDS > 3
  874. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  875. #if HOTENDS > 4
  876. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  877. #endif // HOTENDS > 4
  878. #endif // HOTENDS > 3
  879. #endif // HOTENDS > 2
  880. #endif // HOTENDS > 1
  881. //
  882. // Bed:
  883. //
  884. #if WATCH_THE_BED
  885. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  886. #endif
  887. //
  888. // Fan Speed:
  889. //
  890. #if FAN_COUNT > 0
  891. #if HAS_FAN0
  892. #if FAN_COUNT > 1
  893. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  894. #else
  895. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  896. #endif
  897. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  898. #endif
  899. #if HAS_FAN1
  900. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  901. #endif
  902. #if HAS_FAN2
  903. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  904. #endif
  905. #endif // FAN_COUNT > 0
  906. //
  907. // Flow:
  908. // Flow [1-5]:
  909. //
  910. #if EXTRUDERS == 1
  911. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
  912. #else // EXTRUDERS > 1
  913. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
  914. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
  915. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &flow_percentage[1], 10, 999);
  916. #if EXTRUDERS > 2
  917. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &flow_percentage[2], 10, 999);
  918. #if EXTRUDERS > 3
  919. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &flow_percentage[3], 10, 999);
  920. #if EXTRUDERS > 4
  921. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &flow_percentage[4], 10, 999);
  922. #endif //EXTRUDERS > 4
  923. #endif //EXTRUDERS > 3
  924. #endif //EXTRUDERS > 2
  925. #endif //EXTRUDERS > 1
  926. //
  927. // Babystep X:
  928. // Babystep Y:
  929. // Babystep Z:
  930. //
  931. #if ENABLED(BABYSTEPPING)
  932. #if ENABLED(BABYSTEP_XY)
  933. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  934. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  935. #endif
  936. #if DISABLED(BABYSTEP_ZPROBE_OFFSET)
  937. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  938. #endif
  939. #endif
  940. //
  941. // Change filament
  942. //
  943. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  944. if (!thermalManager.tooColdToExtrude(active_extruder))
  945. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  946. #endif
  947. END_MENU();
  948. }
  949. /**
  950. *
  951. * "Driver current control" submenu items
  952. *
  953. */
  954. #if ENABLED(DAC_STEPPER_CURRENT)
  955. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  956. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  957. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  958. void lcd_dac_menu() {
  959. dac_driver_getValues();
  960. START_MENU();
  961. MENU_BACK(MSG_CONTROL);
  962. MENU_ITEM_EDIT_CALLBACK(int3, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  963. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  964. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  965. MENU_ITEM_EDIT_CALLBACK(int3, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  966. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  967. END_MENU();
  968. }
  969. #endif
  970. constexpr int heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  971. /**
  972. *
  973. * "Prepare" submenu items
  974. *
  975. */
  976. void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
  977. if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
  978. #if TEMP_SENSOR_BED != 0
  979. if (tempb >= 0) thermalManager.setTargetBed(tempb);
  980. #else
  981. UNUSED(tempb);
  982. #endif
  983. #if FAN_COUNT > 0
  984. #if FAN_COUNT > 1
  985. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  986. #else
  987. fanSpeeds[0] = fan;
  988. #endif
  989. #else
  990. UNUSED(fan);
  991. #endif
  992. lcd_return_to_status();
  993. }
  994. #if TEMP_SENSOR_0 != 0
  995. void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  996. void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  997. #if TEMP_SENSOR_BED != 0
  998. void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  999. void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1000. #endif
  1001. #endif
  1002. #if HOTENDS > 1
  1003. void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1004. void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1005. #if TEMP_SENSOR_BED != 0
  1006. void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1007. void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1008. #endif
  1009. #if HOTENDS > 2
  1010. void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1011. void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1012. #if TEMP_SENSOR_BED != 0
  1013. void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1014. void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1015. #endif
  1016. #if HOTENDS > 3
  1017. void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1018. void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1019. #if TEMP_SENSOR_BED != 0
  1020. void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1021. void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1022. #endif
  1023. #if HOTENDS > 4
  1024. void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1025. void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1026. #if TEMP_SENSOR_BED != 0
  1027. void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1028. void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1029. #endif
  1030. #endif // HOTENDS > 4
  1031. #endif // HOTENDS > 3
  1032. #endif // HOTENDS > 2
  1033. void lcd_preheat_m1_all() {
  1034. #if HOTENDS > 1
  1035. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  1036. #if HOTENDS > 2
  1037. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  1038. #if HOTENDS > 3
  1039. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  1040. #if HOTENDS > 4
  1041. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 4);
  1042. #endif // HOTENDS > 4
  1043. #endif // HOTENDS > 3
  1044. #endif // HOTENDS > 2
  1045. #endif // HOTENDS > 1
  1046. #if TEMP_SENSOR_BED != 0
  1047. lcd_preheat_m1_e0();
  1048. #else
  1049. lcd_preheat_m1_e0_only();
  1050. #endif
  1051. }
  1052. void lcd_preheat_m2_all() {
  1053. #if HOTENDS > 1
  1054. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  1055. #if HOTENDS > 2
  1056. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  1057. #if HOTENDS > 3
  1058. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  1059. #if HOTENDS > 4
  1060. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 4);
  1061. #endif // HOTENDS > 4
  1062. #endif // HOTENDS > 3
  1063. #endif // HOTENDS > 2
  1064. #endif // HOTENDS > 1
  1065. #if TEMP_SENSOR_BED != 0
  1066. lcd_preheat_m2_e0();
  1067. #else
  1068. lcd_preheat_m2_e0_only();
  1069. #endif
  1070. }
  1071. #endif // HOTENDS > 1
  1072. #if TEMP_SENSOR_BED != 0
  1073. void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1074. void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1075. #endif
  1076. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0)
  1077. void lcd_preheat_m1_menu() {
  1078. START_MENU();
  1079. MENU_BACK(MSG_PREPARE);
  1080. #if HOTENDS == 1
  1081. #if TEMP_SENSOR_BED != 0
  1082. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
  1083. MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
  1084. #else
  1085. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1086. #endif
  1087. #else
  1088. #if TEMP_SENSOR_BED != 0
  1089. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
  1090. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
  1091. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
  1092. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E2, lcd_preheat_m1_e1_only);
  1093. #else
  1094. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0_only);
  1095. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
  1096. #endif
  1097. #if HOTENDS > 2
  1098. #if TEMP_SENSOR_BED != 0
  1099. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
  1100. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
  1101. #else
  1102. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
  1103. #endif
  1104. #if HOTENDS > 3
  1105. #if TEMP_SENSOR_BED != 0
  1106. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
  1107. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
  1108. #else
  1109. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
  1110. #endif
  1111. #if HOTENDS > 4
  1112. #if TEMP_SENSOR_BED != 0
  1113. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
  1114. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
  1115. #else
  1116. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4_only);
  1117. #endif
  1118. #endif // HOTENDS > 4
  1119. #endif // HOTENDS > 3
  1120. #endif // HOTENDS > 2
  1121. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
  1122. #endif // HOTENDS > 1
  1123. #if TEMP_SENSOR_BED != 0
  1124. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
  1125. #endif
  1126. END_MENU();
  1127. }
  1128. void lcd_preheat_m2_menu() {
  1129. START_MENU();
  1130. MENU_BACK(MSG_PREPARE);
  1131. #if HOTENDS == 1
  1132. #if TEMP_SENSOR_BED != 0
  1133. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
  1134. MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
  1135. #else
  1136. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1137. #endif
  1138. #else
  1139. #if TEMP_SENSOR_BED != 0
  1140. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
  1141. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
  1142. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
  1143. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E2, lcd_preheat_m2_e1_only);
  1144. #else
  1145. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0_only);
  1146. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
  1147. #endif
  1148. #if HOTENDS > 2
  1149. #if TEMP_SENSOR_BED != 0
  1150. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
  1151. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
  1152. #else
  1153. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
  1154. #endif
  1155. #if HOTENDS > 3
  1156. #if TEMP_SENSOR_BED != 0
  1157. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
  1158. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
  1159. #else
  1160. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
  1161. #endif
  1162. #if HOTENDS > 4
  1163. #if TEMP_SENSOR_BED != 0
  1164. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
  1165. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
  1166. #else
  1167. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4_only);
  1168. #endif
  1169. #endif // HOTENDS > 4
  1170. #endif // HOTENDS > 3
  1171. #endif // HOTENDS > 2
  1172. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
  1173. #endif // HOTENDS > 1
  1174. #if TEMP_SENSOR_BED != 0
  1175. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
  1176. #endif
  1177. END_MENU();
  1178. }
  1179. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_BED)
  1180. void lcd_cooldown() {
  1181. #if FAN_COUNT > 0
  1182. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  1183. #endif
  1184. thermalManager.disable_all_heaters();
  1185. lcd_return_to_status();
  1186. }
  1187. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1188. void lcd_autostart_sd() {
  1189. card.autostart_index = 0;
  1190. card.setroot();
  1191. card.checkautostart(true);
  1192. }
  1193. #endif
  1194. #if ENABLED(LCD_BED_LEVELING)
  1195. /**
  1196. *
  1197. * "Prepare" > "Level Bed" handlers
  1198. *
  1199. */
  1200. static uint8_t manual_probe_index;
  1201. #if ENABLED(PROBE_MANUALLY)
  1202. extern bool g29_in_progress;
  1203. #endif
  1204. // LCD probed points are from defaults
  1205. constexpr uint8_t total_probe_points =
  1206. #if ABL_GRID
  1207. (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
  1208. #elif ENABLED(AUTO_BED_LEVELING_3POINT)
  1209. int(3)
  1210. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1211. (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
  1212. #elif ENABLED(MESH_BED_LEVELING)
  1213. (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
  1214. #endif
  1215. ;
  1216. #if ENABLED(MESH_BED_LEVELING)
  1217. // Utility to go to the next mesh point
  1218. inline void _manual_probe_goto_xy(float x, float y) {
  1219. #if MANUAL_PROBE_HEIGHT > 0
  1220. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
  1221. line_to_current(Z_AXIS);
  1222. #endif
  1223. current_position[X_AXIS] = LOGICAL_X_POSITION(x);
  1224. current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
  1225. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1226. #if MANUAL_PROBE_HEIGHT > 0
  1227. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + 0.2;
  1228. line_to_current(Z_AXIS);
  1229. #endif
  1230. lcd_synchronize();
  1231. }
  1232. #endif // MESH_BED_LEVELING
  1233. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  1234. void _lcd_level_goto_next_point();
  1235. #endif
  1236. void _lcd_level_bed_done() {
  1237. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  1238. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1239. }
  1240. /**
  1241. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  1242. */
  1243. void _lcd_level_bed_moving() {
  1244. if (lcdDrawUpdate) {
  1245. char msg[10];
  1246. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  1247. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  1248. }
  1249. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1250. }
  1251. /**
  1252. * Step 7: Get the Z coordinate, click goes to the next point or exits
  1253. */
  1254. void _lcd_level_bed_get_z() {
  1255. ENCODER_DIRECTION_NORMAL();
  1256. // Encoder wheel adjusts the Z position
  1257. if (encoderPosition) {
  1258. refresh_cmd_timeout();
  1259. current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
  1260. NOLESS(current_position[Z_AXIS], -(LCD_PROBE_Z_RANGE) * 0.5);
  1261. NOMORE(current_position[Z_AXIS], (LCD_PROBE_Z_RANGE) * 0.5);
  1262. line_to_current(Z_AXIS);
  1263. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1264. encoderPosition = 0;
  1265. }
  1266. if (lcd_clicked) {
  1267. // Use a hook to set the probe point z
  1268. // (zigzag arranges in XY order)
  1269. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1270. // UBL set-z handling goes here
  1271. #elif ENABLED(PROBE_MANUALLY)
  1272. // G29 helpfully records Z and goes to the next
  1273. // point (or beeps if done)
  1274. enqueue_and_echo_commands_P(PSTR("G29"));
  1275. manual_probe_index++;
  1276. #elif ENABLED(MESH_BED_LEVELING)
  1277. mbl.set_zigzag_z(manual_probe_index++, current_position[Z_AXIS]);
  1278. #endif
  1279. // If done...
  1280. if (manual_probe_index == total_probe_points) {
  1281. // Say "Done!"
  1282. lcd_goto_screen(_lcd_level_bed_done);
  1283. // Raise Z to the "manual probe height"
  1284. #if MANUAL_PROBE_HEIGHT > 0
  1285. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
  1286. line_to_current(Z_AXIS);
  1287. lcd_synchronize();
  1288. #endif
  1289. // Enable leveling, if needed
  1290. #if ENABLED(MESH_BED_LEVELING)
  1291. mbl.set_has_mesh(true);
  1292. mbl.set_reactivate(true);
  1293. enqueue_and_echo_commands_P(PSTR("G28"));
  1294. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1295. // UBL enable goes here
  1296. #elif ENABLED(PROBE_MANUALLY)
  1297. // ABL will be enabled due to "G29".
  1298. #endif
  1299. lcd_return_to_status();
  1300. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  1301. lcd_completion_feedback();
  1302. }
  1303. else {
  1304. // Move to the next probe point, if needed
  1305. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  1306. _lcd_level_goto_next_point();
  1307. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1308. // UBL goto-next-point goes here
  1309. #endif
  1310. }
  1311. }
  1312. // Update on first display, then only on updates to Z position
  1313. // Show message above on clicks instead
  1314. if (lcdDrawUpdate) {
  1315. const float v = current_position[Z_AXIS];
  1316. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  1317. }
  1318. }
  1319. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  1320. /**
  1321. * Step 5: Initiate a move to the next point
  1322. */
  1323. void _lcd_level_goto_next_point() {
  1324. // Set the menu to display ahead of blocking call
  1325. lcd_goto_screen(_lcd_level_bed_moving);
  1326. #if ENABLED(MESH_BED_LEVELING)
  1327. int8_t px, py;
  1328. mbl.zigzag(manual_probe_index, px, py);
  1329. // Controls the loop until the move is done
  1330. _manual_probe_goto_xy(
  1331. LOGICAL_X_POSITION(mbl.index_to_xpos[px]),
  1332. LOGICAL_Y_POSITION(mbl.index_to_ypos[py])
  1333. );
  1334. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1335. // UBL may have its own methodology
  1336. #elif ENABLED(PROBE_MANUALLY)
  1337. // Just wait for the G29 move to complete
  1338. lcd_synchronize();
  1339. #endif
  1340. // After the blocking function returns, change menus
  1341. lcd_goto_screen(_lcd_level_bed_get_z);
  1342. }
  1343. #endif // MESH_BED_LEVELING
  1344. /**
  1345. * Step 4: Display "Click to Begin", wait for click
  1346. * Move to the first probe position
  1347. */
  1348. void _lcd_level_bed_homing_done() {
  1349. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1350. if (lcd_clicked) {
  1351. manual_probe_index = 0;
  1352. #if ENABLED(MESH_BED_LEVELING)
  1353. _lcd_level_goto_next_point();
  1354. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1355. // UBL click handling should go here
  1356. #elif ENABLED(PROBE_MANUALLY)
  1357. enqueue_and_echo_commands_P(PSTR("G29"));
  1358. _lcd_level_goto_next_point();
  1359. #endif
  1360. }
  1361. }
  1362. /**
  1363. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1364. */
  1365. void _lcd_level_bed_homing() {
  1366. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1367. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1368. lcd_goto_screen(_lcd_level_bed_homing_done);
  1369. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1370. }
  1371. /**
  1372. * Step 2: Continue Bed Leveling...
  1373. */
  1374. void _lcd_level_bed_continue() {
  1375. #if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL)
  1376. reset_bed_level();
  1377. #endif
  1378. defer_return_to_status = true;
  1379. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1380. lcd_goto_screen(_lcd_level_bed_homing);
  1381. enqueue_and_echo_commands_P(PSTR("G28"));
  1382. }
  1383. /**
  1384. * Step 1: Bed Level entry-point: "Cancel" or "Level Bed"
  1385. */
  1386. void lcd_level_bed() {
  1387. START_MENU();
  1388. MENU_BACK(MSG_LEVEL_BED_CANCEL);
  1389. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1390. END_MENU();
  1391. }
  1392. #endif // LCD_BED_LEVELING
  1393. /**
  1394. *
  1395. * "Prepare" submenu
  1396. *
  1397. */
  1398. void lcd_prepare_menu() {
  1399. START_MENU();
  1400. //
  1401. // ^ Main
  1402. //
  1403. MENU_BACK(MSG_MAIN);
  1404. //
  1405. // Move Axis
  1406. //
  1407. #if ENABLED(DELTA)
  1408. if (axis_homed[Z_AXIS])
  1409. #endif
  1410. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  1411. //
  1412. // Auto Home
  1413. //
  1414. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1415. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  1416. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  1417. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  1418. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  1419. #endif
  1420. //
  1421. // Level Bed
  1422. //
  1423. #if ENABLED(LCD_BED_LEVELING)
  1424. #if ENABLED(PROBE_MANUALLY)
  1425. if (!g29_in_progress)
  1426. #endif
  1427. MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
  1428. #elif HAS_ABL
  1429. MENU_ITEM(gcode, MSG_LEVEL_BED,
  1430. axis_homed[X_AXIS] && axis_homed[Y_AXIS] ? PSTR("G29") : PSTR("G28\nG29")
  1431. );
  1432. #endif
  1433. #if DISABLED(NO_WORKSPACE_OFFSETS)
  1434. //
  1435. // Set Home Offsets
  1436. //
  1437. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  1438. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  1439. #endif
  1440. //
  1441. // Disable Steppers
  1442. //
  1443. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1444. //
  1445. // Preheat PLA
  1446. // Preheat ABS
  1447. //
  1448. #if TEMP_SENSOR_0 != 0
  1449. //
  1450. // Change filament
  1451. //
  1452. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  1453. if (!thermalManager.tooColdToExtrude(active_extruder))
  1454. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  1455. #endif
  1456. //
  1457. // Cooldown
  1458. //
  1459. bool has_heat = false;
  1460. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  1461. #if HAS_TEMP_BED
  1462. if (thermalManager.target_temperature_bed) has_heat = true;
  1463. #endif
  1464. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  1465. //
  1466. // Preheat for Material 1 and 2
  1467. //
  1468. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
  1469. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
  1470. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
  1471. #else
  1472. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1473. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1474. #endif
  1475. #endif // TEMP_SENSOR_0 != 0
  1476. //
  1477. // BLTouch Self-Test and Reset
  1478. //
  1479. #if ENABLED(BLTOUCH)
  1480. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  1481. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  1482. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  1483. #endif
  1484. //
  1485. // Switch power on/off
  1486. //
  1487. #if HAS_POWER_SWITCH
  1488. if (powersupply)
  1489. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  1490. else
  1491. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  1492. #endif
  1493. //
  1494. // Autostart
  1495. //
  1496. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1497. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  1498. #endif
  1499. END_MENU();
  1500. }
  1501. float move_menu_scale;
  1502. #if ENABLED(DELTA_CALIBRATION_MENU)
  1503. void lcd_move_z();
  1504. void lcd_delta_calibrate_menu();
  1505. void _lcd_calibrate_homing() {
  1506. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  1507. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1508. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1509. lcd_goto_previous_menu();
  1510. }
  1511. void _lcd_delta_calibrate_home() {
  1512. enqueue_and_echo_commands_P(PSTR("G28"));
  1513. lcd_goto_screen(_lcd_calibrate_homing);
  1514. }
  1515. // Move directly to the tower position with uninterpolated moves
  1516. // If we used interpolated moves it would cause this to become re-entrant
  1517. void _goto_tower_pos(const float &a) {
  1518. current_position[Z_AXIS] = max(Z_HOMING_HEIGHT, Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5;
  1519. line_to_current(Z_AXIS);
  1520. current_position[X_AXIS] = a < 0 ? X_HOME_POS : sin(a) * -(DELTA_PRINTABLE_RADIUS);
  1521. current_position[Y_AXIS] = a < 0 ? Y_HOME_POS : cos(a) * (DELTA_PRINTABLE_RADIUS);
  1522. line_to_current(Z_AXIS);
  1523. current_position[Z_AXIS] = 4.0;
  1524. line_to_current(Z_AXIS);
  1525. lcd_synchronize();
  1526. move_menu_scale = 0.1;
  1527. lcd_goto_screen(lcd_move_z);
  1528. }
  1529. void _goto_tower_x() { _goto_tower_pos(RADIANS(120)); }
  1530. void _goto_tower_y() { _goto_tower_pos(RADIANS(240)); }
  1531. void _goto_tower_z() { _goto_tower_pos(0); }
  1532. void _goto_center() { _goto_tower_pos(-1); }
  1533. void lcd_delta_calibrate_menu() {
  1534. START_MENU();
  1535. MENU_BACK(MSG_MAIN);
  1536. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  1537. if (axis_homed[Z_AXIS]) {
  1538. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  1539. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  1540. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  1541. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  1542. }
  1543. END_MENU();
  1544. }
  1545. #endif // DELTA_CALIBRATION_MENU
  1546. /**
  1547. * If the most recent manual move hasn't been fed to the planner yet,
  1548. * and the planner can accept one, send immediately
  1549. */
  1550. inline void manage_manual_move() {
  1551. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  1552. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  1553. manual_move_axis = (int8_t)NO_AXIS;
  1554. }
  1555. }
  1556. /**
  1557. * Set a flag that lcd_update() should start a move
  1558. * to "current_position" after a short delay.
  1559. */
  1560. inline void manual_move_to_current(AxisEnum axis
  1561. #if E_MANUAL > 1
  1562. , int8_t eindex=-1
  1563. #endif
  1564. ) {
  1565. #if E_MANUAL > 1
  1566. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  1567. #endif
  1568. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  1569. manual_move_axis = (int8_t)axis;
  1570. }
  1571. /**
  1572. *
  1573. * "Prepare" > "Move Axis" submenu
  1574. *
  1575. */
  1576. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  1577. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1578. ENCODER_DIRECTION_NORMAL();
  1579. if (encoderPosition) {
  1580. refresh_cmd_timeout();
  1581. float min = current_position[axis] - 1000,
  1582. max = current_position[axis] + 1000;
  1583. #if HAS_SOFTWARE_ENDSTOPS
  1584. // Limit to software endstops, if enabled
  1585. if (soft_endstops_enabled) {
  1586. #if ENABLED(MIN_SOFTWARE_ENDSTOPS)
  1587. min = soft_endstop_min[axis];
  1588. #endif
  1589. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  1590. max = soft_endstop_max[axis];
  1591. #endif
  1592. }
  1593. #endif
  1594. // Get the new position
  1595. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  1596. // Delta limits XY based on the current offset from center
  1597. // This assumes the center is 0,0
  1598. #if ENABLED(DELTA)
  1599. if (axis != Z_AXIS) {
  1600. max = sqrt(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
  1601. min = -max;
  1602. }
  1603. #endif
  1604. // Limit only when trying to move towards the limit
  1605. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  1606. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  1607. manual_move_to_current(axis);
  1608. encoderPosition = 0;
  1609. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1610. }
  1611. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
  1612. }
  1613. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  1614. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  1615. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  1616. void _lcd_move_e(
  1617. #if E_MANUAL > 1
  1618. int8_t eindex=-1
  1619. #endif
  1620. ) {
  1621. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1622. ENCODER_DIRECTION_NORMAL();
  1623. if (encoderPosition) {
  1624. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  1625. encoderPosition = 0;
  1626. manual_move_to_current(E_AXIS
  1627. #if E_MANUAL > 1
  1628. , eindex
  1629. #endif
  1630. );
  1631. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1632. }
  1633. if (lcdDrawUpdate) {
  1634. PGM_P pos_label;
  1635. #if E_MANUAL == 1
  1636. pos_label = PSTR(MSG_MOVE_E);
  1637. #else
  1638. switch (eindex) {
  1639. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  1640. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  1641. #if E_MANUAL > 2
  1642. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  1643. #if E_MANUAL > 3
  1644. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  1645. #if E_MANUAL > 4
  1646. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  1647. #endif // E_MANUAL > 4
  1648. #endif // E_MANUAL > 3
  1649. #endif // E_MANUAL > 2
  1650. }
  1651. #endif // E_MANUAL > 1
  1652. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  1653. }
  1654. }
  1655. void lcd_move_e() { _lcd_move_e(); }
  1656. #if E_MANUAL > 1
  1657. void lcd_move_e0() { _lcd_move_e(0); }
  1658. void lcd_move_e1() { _lcd_move_e(1); }
  1659. #if E_MANUAL > 2
  1660. void lcd_move_e2() { _lcd_move_e(2); }
  1661. #if E_MANUAL > 3
  1662. void lcd_move_e3() { _lcd_move_e(3); }
  1663. #if E_MANUAL > 4
  1664. void lcd_move_e4() { _lcd_move_e(4); }
  1665. #endif // E_MANUAL > 4
  1666. #endif // E_MANUAL > 3
  1667. #endif // E_MANUAL > 2
  1668. #endif // E_MANUAL > 1
  1669. /**
  1670. *
  1671. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  1672. *
  1673. */
  1674. screenFunc_t _manual_move_func_ptr;
  1675. void lcd_move_menu_10mm() { move_menu_scale = 10.0; lcd_goto_screen(_manual_move_func_ptr); }
  1676. void lcd_move_menu_1mm() { move_menu_scale = 1.0; lcd_goto_screen(_manual_move_func_ptr); }
  1677. void lcd_move_menu_01mm() { move_menu_scale = 0.1; lcd_goto_screen(_manual_move_func_ptr); }
  1678. void _lcd_move_distance_menu(AxisEnum axis, screenFunc_t func) {
  1679. _manual_move_func_ptr = func;
  1680. START_MENU();
  1681. if (LCD_HEIGHT >= 4) {
  1682. switch(axis) {
  1683. case X_AXIS:
  1684. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  1685. case Y_AXIS:
  1686. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  1687. case Z_AXIS:
  1688. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  1689. default:
  1690. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  1691. }
  1692. }
  1693. MENU_BACK(MSG_MOVE_AXIS);
  1694. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  1695. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  1696. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  1697. END_MENU();
  1698. }
  1699. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  1700. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  1701. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  1702. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  1703. #if E_MANUAL > 1
  1704. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  1705. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  1706. #if E_MANUAL > 2
  1707. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  1708. #if E_MANUAL > 3
  1709. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  1710. #if E_MANUAL > 4
  1711. void lcd_move_get_e4_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e4); }
  1712. #endif // E_MANUAL > 4
  1713. #endif // E_MANUAL > 3
  1714. #endif // E_MANUAL > 2
  1715. #endif // E_MANUAL > 1
  1716. /**
  1717. *
  1718. * "Prepare" > "Move Axis" submenu
  1719. *
  1720. */
  1721. #if IS_KINEMATIC
  1722. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1723. #if ENABLED(DELTA)
  1724. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  1725. void lcd_lower_z_to_clip_height() {
  1726. current_position[Z_AXIS] = delta_clip_start_height;
  1727. line_to_current(Z_AXIS);
  1728. lcd_synchronize();
  1729. }
  1730. #else
  1731. #define _MOVE_XY_ALLOWED true
  1732. #endif
  1733. #else
  1734. #define _MOVE_XYZ_ALLOWED true
  1735. #define _MOVE_XY_ALLOWED true
  1736. #endif
  1737. void lcd_move_menu() {
  1738. START_MENU();
  1739. MENU_BACK(MSG_PREPARE);
  1740. if (_MOVE_XYZ_ALLOWED) {
  1741. if (_MOVE_XY_ALLOWED) {
  1742. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  1743. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  1744. }
  1745. #if ENABLED(DELTA)
  1746. else
  1747. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  1748. #endif
  1749. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  1750. }
  1751. else
  1752. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1753. #if ENABLED(SWITCHING_EXTRUDER)
  1754. if (active_extruder)
  1755. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  1756. else
  1757. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  1758. #endif
  1759. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  1760. #if E_MANUAL > 1
  1761. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  1762. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  1763. #if E_MANUAL > 2
  1764. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  1765. #if E_MANUAL > 3
  1766. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  1767. #if E_MANUAL > 4
  1768. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  1769. #endif // E_MANUAL > 4
  1770. #endif // E_MANUAL > 3
  1771. #endif // E_MANUAL > 2
  1772. #endif // E_MANUAL > 1
  1773. END_MENU();
  1774. }
  1775. /**
  1776. *
  1777. * "Control" submenu
  1778. *
  1779. */
  1780. #if ENABLED(EEPROM_SETTINGS)
  1781. static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  1782. static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  1783. #endif
  1784. static void lcd_factory_settings() {
  1785. settings.reset();
  1786. lcd_completion_feedback();
  1787. }
  1788. void lcd_control_menu() {
  1789. START_MENU();
  1790. MENU_BACK(MSG_MAIN);
  1791. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1792. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  1793. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  1794. #if HAS_LCD_CONTRAST
  1795. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  1796. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  1797. #endif
  1798. #if ENABLED(FWRETRACT)
  1799. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  1800. #endif
  1801. #if ENABLED(DAC_STEPPER_CURRENT)
  1802. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  1803. #endif
  1804. #if ENABLED(EEPROM_SETTINGS)
  1805. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  1806. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  1807. #endif
  1808. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, lcd_factory_settings);
  1809. END_MENU();
  1810. }
  1811. /**
  1812. *
  1813. * "Temperature" submenu
  1814. *
  1815. */
  1816. #if ENABLED(PID_AUTOTUNE_MENU)
  1817. #if ENABLED(PIDTEMP)
  1818. int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  1819. #endif
  1820. #if ENABLED(PIDTEMPBED)
  1821. int autotune_temp_bed = 70;
  1822. #endif
  1823. void _lcd_autotune(int e) {
  1824. char cmd[30];
  1825. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  1826. #if HAS_PID_FOR_BOTH
  1827. e < 0 ? autotune_temp_bed : autotune_temp[e]
  1828. #elif ENABLED(PIDTEMPBED)
  1829. autotune_temp_bed
  1830. #else
  1831. autotune_temp[e]
  1832. #endif
  1833. );
  1834. enqueue_and_echo_command(cmd);
  1835. }
  1836. #endif //PID_AUTOTUNE_MENU
  1837. #if ENABLED(PIDTEMP)
  1838. // Helpers for editing PID Ki & Kd values
  1839. // grab the PID value out of the temp variable; scale it; then update the PID driver
  1840. void copy_and_scalePID_i(int e) {
  1841. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1842. UNUSED(e);
  1843. #endif
  1844. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  1845. thermalManager.updatePID();
  1846. }
  1847. void copy_and_scalePID_d(int e) {
  1848. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1849. UNUSED(e);
  1850. #endif
  1851. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  1852. thermalManager.updatePID();
  1853. }
  1854. #define _PIDTEMP_BASE_FUNCTIONS(N) \
  1855. void copy_and_scalePID_i_E ## N() { copy_and_scalePID_i(N); } \
  1856. void copy_and_scalePID_d_E ## N() { copy_and_scalePID_d(N); }
  1857. #if ENABLED(PID_AUTOTUNE_MENU)
  1858. #define _PIDTEMP_FUNCTIONS(N) \
  1859. _PIDTEMP_BASE_FUNCTIONS(N); \
  1860. void lcd_autotune_callback_E ## N() { _lcd_autotune(N); }
  1861. #else
  1862. #define _PIDTEMP_FUNCTIONS(N) _PIDTEMP_BASE_FUNCTIONS(N)
  1863. #endif
  1864. _PIDTEMP_FUNCTIONS(0)
  1865. #if ENABLED(PID_PARAMS_PER_HOTEND)
  1866. #if HOTENDS > 1
  1867. _PIDTEMP_FUNCTIONS(1)
  1868. #if HOTENDS > 2
  1869. _PIDTEMP_FUNCTIONS(2)
  1870. #if HOTENDS > 3
  1871. _PIDTEMP_FUNCTIONS(3)
  1872. #if HOTENDS > 4
  1873. _PIDTEMP_FUNCTIONS(4)
  1874. #endif // HOTENDS > 4
  1875. #endif // HOTENDS > 3
  1876. #endif // HOTENDS > 2
  1877. #endif // HOTENDS > 1
  1878. #endif // PID_PARAMS_PER_HOTEND
  1879. #endif // PIDTEMP
  1880. /**
  1881. *
  1882. * "Control" > "Temperature" submenu
  1883. *
  1884. */
  1885. void lcd_control_temperature_menu() {
  1886. START_MENU();
  1887. //
  1888. // ^ Control
  1889. //
  1890. MENU_BACK(MSG_CONTROL);
  1891. //
  1892. // Nozzle:
  1893. // Nozzle [1-5]:
  1894. //
  1895. #if HOTENDS == 1
  1896. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1897. #else // HOTENDS > 1
  1898. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1899. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1900. #if HOTENDS > 2
  1901. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1902. #if HOTENDS > 3
  1903. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1904. #if HOTENDS > 4
  1905. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  1906. #endif // HOTENDS > 4
  1907. #endif // HOTENDS > 3
  1908. #endif // HOTENDS > 2
  1909. #endif // HOTENDS > 1
  1910. //
  1911. // Bed:
  1912. //
  1913. #if WATCH_THE_BED
  1914. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  1915. #endif
  1916. //
  1917. // Fan Speed:
  1918. //
  1919. #if FAN_COUNT > 0
  1920. #if HAS_FAN0
  1921. #if FAN_COUNT > 1
  1922. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1923. #else
  1924. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1925. #endif
  1926. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1927. #endif
  1928. #if HAS_FAN1
  1929. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1930. #endif
  1931. #if HAS_FAN2
  1932. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1933. #endif
  1934. #endif // FAN_COUNT > 0
  1935. //
  1936. // Autotemp, Min, Max, Fact
  1937. //
  1938. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  1939. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  1940. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  1941. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  1942. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  1943. #endif
  1944. //
  1945. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  1946. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  1947. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  1948. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  1949. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  1950. // PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
  1951. //
  1952. #if ENABLED(PIDTEMP)
  1953. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  1954. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  1955. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  1956. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  1957. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  1958. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  1959. #if ENABLED(PID_EXTRUSION_SCALING)
  1960. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  1961. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  1962. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  1963. #else
  1964. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  1965. #endif
  1966. #if ENABLED(PID_AUTOTUNE_MENU)
  1967. #define PID_MENU_ITEMS(ELABEL, eindex) \
  1968. _PID_MENU_ITEMS(ELABEL, eindex); \
  1969. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  1970. #else
  1971. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  1972. #endif
  1973. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  1974. PID_MENU_ITEMS(" " MSG_E1, 0);
  1975. PID_MENU_ITEMS(" " MSG_E2, 1);
  1976. #if HOTENDS > 2
  1977. PID_MENU_ITEMS(" " MSG_E3, 2);
  1978. #if HOTENDS > 3
  1979. PID_MENU_ITEMS(" " MSG_E4, 3);
  1980. #if HOTENDS > 4
  1981. PID_MENU_ITEMS(" " MSG_E5, 4);
  1982. #endif // HOTENDS > 4
  1983. #endif // HOTENDS > 3
  1984. #endif // HOTENDS > 2
  1985. #else // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1986. PID_MENU_ITEMS("", 0);
  1987. #endif // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1988. #endif //PIDTEMP
  1989. //
  1990. // Preheat Material 1 conf
  1991. //
  1992. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  1993. //
  1994. // Preheat Material 2 conf
  1995. //
  1996. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  1997. END_MENU();
  1998. }
  1999. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  2000. #if HOTENDS > 4
  2001. #define MINTEMP_ALL MIN5(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP)
  2002. #define MAXTEMP_ALL MAX5(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP)
  2003. #elif HOTENDS > 3
  2004. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  2005. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  2006. #elif HOTENDS > 2
  2007. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  2008. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  2009. #elif HOTENDS > 1
  2010. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  2011. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  2012. #else
  2013. #define MINTEMP_ALL HEATER_0_MINTEMP
  2014. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  2015. #endif
  2016. START_MENU();
  2017. MENU_BACK(MSG_TEMPERATURE);
  2018. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  2019. #if TEMP_SENSOR_0 != 0
  2020. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  2021. #endif
  2022. #if TEMP_SENSOR_BED != 0
  2023. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  2024. #endif
  2025. #if ENABLED(EEPROM_SETTINGS)
  2026. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2027. #endif
  2028. END_MENU();
  2029. }
  2030. /**
  2031. *
  2032. * "Temperature" > "Preheat Material 1 conf" submenu
  2033. *
  2034. */
  2035. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  2036. /**
  2037. *
  2038. * "Temperature" > "Preheat Material 2 conf" submenu
  2039. *
  2040. */
  2041. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  2042. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  2043. #if ENABLED(DISTINCT_E_FACTORS)
  2044. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  2045. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  2046. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  2047. #if E_STEPPERS > 2
  2048. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  2049. #if E_STEPPERS > 3
  2050. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  2051. #if E_STEPPERS > 4
  2052. void _reset_e4_acceleration_rate() { _reset_e_acceleration_rate(4); }
  2053. #endif // E_STEPPERS > 4
  2054. #endif // E_STEPPERS > 3
  2055. #endif // E_STEPPERS > 2
  2056. #endif
  2057. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  2058. #if ENABLED(DISTINCT_E_FACTORS)
  2059. void _planner_refresh_e_positioning(const uint8_t e) {
  2060. if (e == active_extruder)
  2061. _planner_refresh_positioning();
  2062. else
  2063. planner.steps_to_mm[e] = 1.0 / planner.axis_steps_per_mm[e];
  2064. }
  2065. void _planner_refresh_e0_positioning() { _reset_e_acceleration_rate(0); }
  2066. void _planner_refresh_e1_positioning() { _reset_e_acceleration_rate(1); }
  2067. #if E_STEPPERS > 2
  2068. void _planner_refresh_e2_positioning() { _reset_e_acceleration_rate(2); }
  2069. #if E_STEPPERS > 3
  2070. void _planner_refresh_e3_positioning() { _reset_e_acceleration_rate(3); }
  2071. #if E_STEPPERS > 4
  2072. void _planner_refresh_e4_positioning() { _reset_e_acceleration_rate(4); }
  2073. #endif // E_STEPPERS > 4
  2074. #endif // E_STEPPERS > 3
  2075. #endif // E_STEPPERS > 2
  2076. #endif
  2077. /**
  2078. *
  2079. * "Control" > "Motion" submenu
  2080. *
  2081. */
  2082. void lcd_control_motion_menu() {
  2083. START_MENU();
  2084. MENU_BACK(MSG_CONTROL);
  2085. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  2086. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  2087. #elif HAS_BED_PROBE
  2088. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, refresh_zprobe_zoffset);
  2089. #endif
  2090. // Manual bed leveling, Bed Z:
  2091. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  2092. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  2093. #endif
  2094. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  2095. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  2096. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  2097. #if ENABLED(DELTA)
  2098. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  2099. #else
  2100. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  2101. #endif
  2102. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  2103. //
  2104. // M203 Settings
  2105. //
  2106. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  2107. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  2108. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  2109. #if ENABLED(DISTINCT_E_FACTORS)
  2110. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  2111. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2112. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  2113. #if E_STEPPERS > 2
  2114. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  2115. #if E_STEPPERS > 3
  2116. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  2117. #if E_STEPPERS > 4
  2118. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
  2119. #endif // E_STEPPERS > 4
  2120. #endif // E_STEPPERS > 3
  2121. #endif // E_STEPPERS > 2
  2122. #else
  2123. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2124. #endif
  2125. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  2126. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  2127. //
  2128. // M201 Settings
  2129. //
  2130. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  2131. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  2132. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  2133. #if ENABLED(DISTINCT_E_FACTORS)
  2134. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  2135. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  2136. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  2137. #if E_STEPPERS > 2
  2138. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  2139. #if E_STEPPERS > 3
  2140. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  2141. #if E_STEPPERS > 4
  2142. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
  2143. #endif // E_STEPPERS > 4
  2144. #endif // E_STEPPERS > 3
  2145. #endif // E_STEPPERS > 2
  2146. #else
  2147. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  2148. #endif
  2149. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  2150. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  2151. //
  2152. // M92 Settings
  2153. //
  2154. MENU_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  2155. MENU_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  2156. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  2157. #if ENABLED(DISTINCT_E_FACTORS)
  2158. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  2159. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  2160. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  2161. #if E_STEPPERS > 2
  2162. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  2163. #if E_STEPPERS > 3
  2164. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  2165. #if E_STEPPERS > 4
  2166. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E5STEPS, &planner.axis_steps_per_mm[E_AXIS + 4], 5, 9999, _planner_refresh_e4_positioning);
  2167. #endif // E_STEPPERS > 4
  2168. #endif // E_STEPPERS > 3
  2169. #endif // E_STEPPERS > 2
  2170. #else
  2171. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  2172. #endif
  2173. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  2174. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  2175. #endif
  2176. END_MENU();
  2177. }
  2178. /**
  2179. *
  2180. * "Control" > "Filament" submenu
  2181. *
  2182. */
  2183. void lcd_control_volumetric_menu() {
  2184. START_MENU();
  2185. MENU_BACK(MSG_CONTROL);
  2186. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  2187. if (volumetric_enabled) {
  2188. #if EXTRUDERS == 1
  2189. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2190. #else // EXTRUDERS > 1
  2191. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2192. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  2193. #if EXTRUDERS > 2
  2194. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  2195. #if EXTRUDERS > 3
  2196. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  2197. #if EXTRUDERS > 4
  2198. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
  2199. #endif // EXTRUDERS > 4
  2200. #endif // EXTRUDERS > 3
  2201. #endif // EXTRUDERS > 2
  2202. #endif // EXTRUDERS > 1
  2203. }
  2204. END_MENU();
  2205. }
  2206. /**
  2207. *
  2208. * "Control" > "Contrast" submenu
  2209. *
  2210. */
  2211. #if HAS_LCD_CONTRAST
  2212. void lcd_set_contrast() {
  2213. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2214. ENCODER_DIRECTION_NORMAL();
  2215. if (encoderPosition) {
  2216. set_lcd_contrast(lcd_contrast + encoderPosition);
  2217. encoderPosition = 0;
  2218. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2219. }
  2220. if (lcdDrawUpdate) {
  2221. lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
  2222. #if LCD_CONTRAST_MAX >= 100
  2223. itostr3(lcd_contrast)
  2224. #else
  2225. itostr2(lcd_contrast)
  2226. #endif
  2227. );
  2228. }
  2229. }
  2230. #endif // HAS_LCD_CONTRAST
  2231. /**
  2232. *
  2233. * "Control" > "Retract" submenu
  2234. *
  2235. */
  2236. #if ENABLED(FWRETRACT)
  2237. void lcd_control_retract_menu() {
  2238. START_MENU();
  2239. MENU_BACK(MSG_CONTROL);
  2240. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  2241. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  2242. #if EXTRUDERS > 1
  2243. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  2244. #endif
  2245. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  2246. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  2247. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
  2248. #if EXTRUDERS > 1
  2249. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, -100, 100);
  2250. #endif
  2251. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  2252. END_MENU();
  2253. }
  2254. #endif // FWRETRACT
  2255. #if ENABLED(SDSUPPORT)
  2256. #if !PIN_EXISTS(SD_DETECT)
  2257. void lcd_sd_refresh() {
  2258. card.initsd();
  2259. encoderTopLine = 0;
  2260. }
  2261. #endif
  2262. void lcd_sd_updir() {
  2263. card.updir();
  2264. encoderTopLine = 0;
  2265. screen_changed = true;
  2266. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2267. }
  2268. /**
  2269. *
  2270. * "Print from SD" submenu
  2271. *
  2272. */
  2273. void lcd_sdcard_menu() {
  2274. ENCODER_DIRECTION_MENUS();
  2275. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  2276. uint16_t fileCnt = card.getnrfilenames();
  2277. START_MENU();
  2278. MENU_BACK(MSG_MAIN);
  2279. card.getWorkDirName();
  2280. if (card.filename[0] == '/') {
  2281. #if !PIN_EXISTS(SD_DETECT)
  2282. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  2283. #endif
  2284. }
  2285. else {
  2286. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  2287. }
  2288. for (uint16_t i = 0; i < fileCnt; i++) {
  2289. if (_menuLineNr == _thisItemNr) {
  2290. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  2291. int nr = fileCnt - 1 - i;
  2292. #else
  2293. int nr = i;
  2294. #endif
  2295. #if ENABLED(SDCARD_SORT_ALPHA)
  2296. card.getfilename_sorted(nr);
  2297. #else
  2298. card.getfilename(nr);
  2299. #endif
  2300. if (card.filenameIsDir)
  2301. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2302. else
  2303. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2304. }
  2305. else {
  2306. MENU_ITEM_DUMMY();
  2307. }
  2308. }
  2309. END_MENU();
  2310. }
  2311. #endif //SDSUPPORT
  2312. #if ENABLED(LCD_INFO_MENU)
  2313. #if ENABLED(PRINTCOUNTER)
  2314. /**
  2315. *
  2316. * About Printer > Statistics submenu
  2317. *
  2318. */
  2319. void lcd_info_stats_menu() {
  2320. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2321. char buffer[21];
  2322. printStatistics stats = print_job_timer.getStats();
  2323. START_SCREEN(); // 12345678901234567890
  2324. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  2325. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  2326. duration_t elapsed = stats.printTime;
  2327. elapsed.toString(buffer);
  2328. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  2329. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2330. elapsed = stats.longestPrint;
  2331. elapsed.toString(buffer);
  2332. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  2333. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2334. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int(stats.filamentUsed / 100) % 10);
  2335. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  2336. STATIC_ITEM("", false, false, buffer); // 125m
  2337. END_SCREEN();
  2338. }
  2339. #endif // PRINTCOUNTER
  2340. /**
  2341. *
  2342. * About Printer > Thermistors
  2343. *
  2344. */
  2345. void lcd_info_thermistors_menu() {
  2346. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2347. START_SCREEN();
  2348. #define THERMISTOR_ID TEMP_SENSOR_0
  2349. #include "thermistornames.h"
  2350. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  2351. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  2352. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  2353. #if TEMP_SENSOR_1 != 0
  2354. #undef THERMISTOR_ID
  2355. #define THERMISTOR_ID TEMP_SENSOR_1
  2356. #include "thermistornames.h"
  2357. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  2358. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  2359. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  2360. #endif
  2361. #if TEMP_SENSOR_2 != 0
  2362. #undef THERMISTOR_ID
  2363. #define THERMISTOR_ID TEMP_SENSOR_2
  2364. #include "thermistornames.h"
  2365. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  2366. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  2367. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  2368. #endif
  2369. #if TEMP_SENSOR_3 != 0
  2370. #undef THERMISTOR_ID
  2371. #define THERMISTOR_ID TEMP_SENSOR_3
  2372. #include "thermistornames.h"
  2373. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  2374. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  2375. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  2376. #endif
  2377. #if TEMP_SENSOR_BED != 0
  2378. #undef THERMISTOR_ID
  2379. #define THERMISTOR_ID TEMP_SENSOR_BED
  2380. #include "thermistornames.h"
  2381. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  2382. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  2383. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  2384. #endif
  2385. END_SCREEN();
  2386. }
  2387. /**
  2388. *
  2389. * About Printer > Board Info
  2390. *
  2391. */
  2392. void lcd_info_board_menu() {
  2393. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2394. START_SCREEN();
  2395. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  2396. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  2397. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  2398. #if POWER_SUPPLY == 0
  2399. STATIC_ITEM(MSG_INFO_PSU ": Generic", true);
  2400. #elif POWER_SUPPLY == 1
  2401. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  2402. #elif POWER_SUPPLY == 2
  2403. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  2404. #endif
  2405. END_SCREEN();
  2406. }
  2407. /**
  2408. *
  2409. * About Printer > Printer Info
  2410. *
  2411. */
  2412. void lcd_info_printer_menu() {
  2413. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2414. START_SCREEN();
  2415. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  2416. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  2417. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  2418. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  2419. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  2420. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  2421. END_SCREEN();
  2422. }
  2423. /**
  2424. *
  2425. * "About Printer" submenu
  2426. *
  2427. */
  2428. void lcd_info_menu() {
  2429. START_MENU();
  2430. MENU_BACK(MSG_MAIN);
  2431. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  2432. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  2433. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  2434. #if ENABLED(PRINTCOUNTER)
  2435. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  2436. #endif
  2437. END_MENU();
  2438. }
  2439. #endif // LCD_INFO_MENU
  2440. /**
  2441. *
  2442. * Filament Change Feature Screens
  2443. *
  2444. */
  2445. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  2446. // Portions from STATIC_ITEM...
  2447. #define HOTEND_STATUS_ITEM() do { \
  2448. if (_menuLineNr == _thisItemNr) { \
  2449. if (lcdDrawUpdate) \
  2450. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  2451. lcd_implementation_hotend_status(_lcdLineNr); \
  2452. if (_skipStatic && encoderLine <= _thisItemNr) { \
  2453. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  2454. ++encoderLine; \
  2455. } \
  2456. else \
  2457. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING; \
  2458. } \
  2459. ++_thisItemNr; \
  2460. } while(0)
  2461. void lcd_filament_change_toocold_menu() {
  2462. START_MENU();
  2463. STATIC_ITEM(MSG_HEATING_FAILED_LCD, true, true);
  2464. STATIC_ITEM(MSG_FILAMENT_CHANGE_MINTEMP STRINGIFY(EXTRUDE_MINTEMP) ".", false, false);
  2465. MENU_BACK(MSG_BACK);
  2466. #if LCD_HEIGHT > 4
  2467. STATIC_ITEM(" ");
  2468. #endif
  2469. HOTEND_STATUS_ITEM();
  2470. END_MENU();
  2471. }
  2472. void lcd_filament_change_resume_print() {
  2473. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_RESUME_PRINT;
  2474. }
  2475. void lcd_filament_change_extrude_more() {
  2476. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_EXTRUDE_MORE;
  2477. }
  2478. void lcd_filament_change_option_menu() {
  2479. START_MENU();
  2480. #if LCD_HEIGHT > 2
  2481. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  2482. #endif
  2483. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_filament_change_resume_print);
  2484. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_filament_change_extrude_more);
  2485. END_MENU();
  2486. }
  2487. void lcd_filament_change_init_message() {
  2488. START_SCREEN();
  2489. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2490. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  2491. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  2492. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  2493. #define __FC_LINES_A 3
  2494. #else
  2495. #define __FC_LINES_A 2
  2496. #endif
  2497. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  2498. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  2499. #define _FC_LINES_A (__FC_LINES_A + 1)
  2500. #else
  2501. #define _FC_LINES_A __FC_LINES_A
  2502. #endif
  2503. #if LCD_HEIGHT > _FC_LINES_A + 1
  2504. STATIC_ITEM(" ");
  2505. #endif
  2506. HOTEND_STATUS_ITEM();
  2507. END_SCREEN();
  2508. }
  2509. void lcd_filament_change_unload_message() {
  2510. START_SCREEN();
  2511. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2512. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  2513. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  2514. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  2515. #define __FC_LINES_B 3
  2516. #else
  2517. #define __FC_LINES_B 2
  2518. #endif
  2519. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  2520. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  2521. #define _FC_LINES_B (__FC_LINES_B + 1)
  2522. #else
  2523. #define _FC_LINES_B __FC_LINES_B
  2524. #endif
  2525. #if LCD_HEIGHT > _FC_LINES_B + 1
  2526. STATIC_ITEM(" ");
  2527. #endif
  2528. HOTEND_STATUS_ITEM();
  2529. END_SCREEN();
  2530. }
  2531. void lcd_filament_change_wait_for_nozzles_to_heat() {
  2532. START_SCREEN();
  2533. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2534. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  2535. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  2536. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  2537. #define _FC_LINES_C 3
  2538. #else
  2539. #define _FC_LINES_C 2
  2540. #endif
  2541. #if LCD_HEIGHT > _FC_LINES_C + 1
  2542. STATIC_ITEM(" ");
  2543. #endif
  2544. HOTEND_STATUS_ITEM();
  2545. END_SCREEN();
  2546. }
  2547. void lcd_filament_change_heat_nozzle() {
  2548. START_SCREEN();
  2549. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2550. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  2551. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2552. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  2553. #define _FC_LINES_D 3
  2554. #else
  2555. #define _FC_LINES_D 2
  2556. #endif
  2557. #if LCD_HEIGHT > _FC_LINES_D + 1
  2558. STATIC_ITEM(" ");
  2559. #endif
  2560. HOTEND_STATUS_ITEM();
  2561. END_SCREEN();
  2562. }
  2563. void lcd_filament_change_insert_message() {
  2564. START_SCREEN();
  2565. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2566. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  2567. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2568. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  2569. #define __FC_LINES_E 3
  2570. #else
  2571. #define __FC_LINES_E 2
  2572. #endif
  2573. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  2574. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  2575. #define _FC_LINES_E (__FC_LINES_E + 1)
  2576. #else
  2577. #define _FC_LINES_E __FC_LINES_E
  2578. #endif
  2579. #if LCD_HEIGHT > _FC_LINES_E + 1
  2580. STATIC_ITEM(" ");
  2581. #endif
  2582. HOTEND_STATUS_ITEM();
  2583. END_SCREEN();
  2584. }
  2585. void lcd_filament_change_load_message() {
  2586. START_SCREEN();
  2587. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2588. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  2589. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  2590. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  2591. #define __FC_LINES_F 3
  2592. #else
  2593. #define __FC_LINES_F 2
  2594. #endif
  2595. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  2596. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  2597. #define _FC_LINES_F (__FC_LINES_F + 1)
  2598. #else
  2599. #define _FC_LINES_F __FC_LINES_F
  2600. #endif
  2601. #if LCD_HEIGHT > _FC_LINES_F + 1
  2602. STATIC_ITEM(" ");
  2603. #endif
  2604. HOTEND_STATUS_ITEM();
  2605. END_SCREEN();
  2606. }
  2607. void lcd_filament_change_extrude_message() {
  2608. START_SCREEN();
  2609. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2610. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  2611. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  2612. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  2613. #define __FC_LINES_G 3
  2614. #else
  2615. #define __FC_LINES_G 2
  2616. #endif
  2617. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  2618. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  2619. #define _FC_LINES_G (__FC_LINES_G + 1)
  2620. #else
  2621. #define _FC_LINES_G __FC_LINES_G
  2622. #endif
  2623. #if LCD_HEIGHT > _FC_LINES_G + 1
  2624. STATIC_ITEM(" ");
  2625. #endif
  2626. HOTEND_STATUS_ITEM();
  2627. END_SCREEN();
  2628. }
  2629. void lcd_filament_change_resume_message() {
  2630. START_SCREEN();
  2631. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2632. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  2633. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  2634. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  2635. #endif
  2636. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  2637. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  2638. #endif
  2639. END_SCREEN();
  2640. }
  2641. void lcd_filament_change_show_message(const FilamentChangeMessage message) {
  2642. switch (message) {
  2643. case FILAMENT_CHANGE_MESSAGE_INIT:
  2644. defer_return_to_status = true;
  2645. lcd_goto_screen(lcd_filament_change_init_message);
  2646. break;
  2647. case FILAMENT_CHANGE_MESSAGE_UNLOAD:
  2648. lcd_goto_screen(lcd_filament_change_unload_message);
  2649. break;
  2650. case FILAMENT_CHANGE_MESSAGE_INSERT:
  2651. lcd_goto_screen(lcd_filament_change_insert_message);
  2652. break;
  2653. case FILAMENT_CHANGE_MESSAGE_LOAD:
  2654. lcd_goto_screen(lcd_filament_change_load_message);
  2655. break;
  2656. case FILAMENT_CHANGE_MESSAGE_EXTRUDE:
  2657. lcd_goto_screen(lcd_filament_change_extrude_message);
  2658. break;
  2659. case FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE:
  2660. lcd_goto_screen(lcd_filament_change_heat_nozzle);
  2661. break;
  2662. case FILAMENT_CHANGE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT:
  2663. lcd_goto_screen(lcd_filament_change_wait_for_nozzles_to_heat);
  2664. break;
  2665. case FILAMENT_CHANGE_MESSAGE_OPTION:
  2666. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_WAIT_FOR;
  2667. lcd_goto_screen(lcd_filament_change_option_menu);
  2668. break;
  2669. case FILAMENT_CHANGE_MESSAGE_RESUME:
  2670. lcd_goto_screen(lcd_filament_change_resume_message);
  2671. break;
  2672. case FILAMENT_CHANGE_MESSAGE_STATUS:
  2673. lcd_return_to_status();
  2674. break;
  2675. }
  2676. }
  2677. #endif // FILAMENT_CHANGE_FEATURE
  2678. /**
  2679. *
  2680. * Functions for editing single values
  2681. *
  2682. * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
  2683. *
  2684. * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
  2685. *
  2686. * bool _menu_edit_int3();
  2687. * void menu_edit_int3(); // edit int (interactively)
  2688. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  2689. * void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  2690. * void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  2691. * void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback); // edit int with callback
  2692. *
  2693. * You can then use one of the menu macros to present the edit interface:
  2694. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  2695. *
  2696. * This expands into a more primitive menu item:
  2697. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2698. *
  2699. *
  2700. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  2701. *
  2702. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2703. */
  2704. #define menu_edit_type(_type, _name, _strFunc, _scale) \
  2705. bool _menu_edit_ ## _name () { \
  2706. ENCODER_DIRECTION_NORMAL(); \
  2707. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  2708. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  2709. if (lcdDrawUpdate) \
  2710. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
  2711. if (lcd_clicked) { \
  2712. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
  2713. lcd_goto_previous_menu(); \
  2714. } \
  2715. return lcd_clicked; \
  2716. } \
  2717. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  2718. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  2719. void _menu_action_setting_edit_ ## _name (const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  2720. lcd_save_previous_screen(); \
  2721. \
  2722. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  2723. \
  2724. editLabel = pstr; \
  2725. editValue = ptr; \
  2726. minEditValue = minValue * _scale; \
  2727. maxEditValue = maxValue * _scale - minEditValue; \
  2728. encoderPosition = (*ptr) * _scale - minEditValue; \
  2729. } \
  2730. void menu_action_setting_edit_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  2731. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2732. currentScreen = menu_edit_ ## _name; \
  2733. }\
  2734. void menu_action_setting_edit_callback_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback) { \
  2735. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2736. currentScreen = menu_edit_callback_ ## _name; \
  2737. callbackFunc = callback; \
  2738. } \
  2739. typedef void _name
  2740. menu_edit_type(int, int3, itostr3, 1);
  2741. menu_edit_type(float, float3, ftostr3, 1.0);
  2742. menu_edit_type(float, float32, ftostr32, 100.0);
  2743. menu_edit_type(float, float43, ftostr43sign, 1000.0);
  2744. menu_edit_type(float, float5, ftostr5rj, 0.01);
  2745. menu_edit_type(float, float51, ftostr51sign, 10.0);
  2746. menu_edit_type(float, float52, ftostr52sign, 100.0);
  2747. menu_edit_type(float, float62, ftostr62rj, 100.0);
  2748. menu_edit_type(unsigned long, long5, ftostr5rj, 0.01);
  2749. /**
  2750. *
  2751. * Handlers for RepRap World Keypad input
  2752. *
  2753. */
  2754. #if ENABLED(REPRAPWORLD_KEYPAD)
  2755. void _reprapworld_keypad_move(AxisEnum axis, int dir) {
  2756. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2757. encoderPosition = dir;
  2758. switch (axis) {
  2759. case X_AXIS: lcd_move_x(); break;
  2760. case Y_AXIS: lcd_move_y(); break;
  2761. case Z_AXIS: lcd_move_z();
  2762. default: break;
  2763. }
  2764. }
  2765. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  2766. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  2767. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  2768. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  2769. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  2770. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  2771. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  2772. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  2773. inline void handle_reprapworld_keypad() {
  2774. static uint8_t keypad_debounce = 0;
  2775. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  2776. if (keypad_debounce > 0) keypad_debounce--;
  2777. }
  2778. else if (!keypad_debounce) {
  2779. keypad_debounce = 2;
  2780. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  2781. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  2782. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2783. #endif
  2784. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  2785. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  2786. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2787. #endif
  2788. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  2789. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  2790. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  2791. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  2792. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  2793. }
  2794. else {
  2795. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  2796. }
  2797. }
  2798. }
  2799. #endif // REPRAPWORLD_KEYPAD
  2800. /**
  2801. *
  2802. * Menu actions
  2803. *
  2804. */
  2805. void _menu_action_back() { lcd_goto_previous_menu(); }
  2806. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  2807. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  2808. void menu_action_function(screenFunc_t func) { (*func)(); }
  2809. #if ENABLED(SDSUPPORT)
  2810. void menu_action_sdfile(const char* filename, char* longFilename) {
  2811. UNUSED(longFilename);
  2812. card.openAndPrintFile(filename);
  2813. lcd_return_to_status();
  2814. }
  2815. void menu_action_sddirectory(const char* filename, char* longFilename) {
  2816. UNUSED(longFilename);
  2817. card.chdir(filename);
  2818. encoderPosition = 0;
  2819. screen_changed = true;
  2820. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2821. }
  2822. #endif //SDSUPPORT
  2823. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) {UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
  2824. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  2825. menu_action_setting_edit_bool(pstr, ptr);
  2826. (*callback)();
  2827. }
  2828. #endif // ULTIPANEL
  2829. void lcd_init() {
  2830. lcd_implementation_init(
  2831. #if ENABLED(LCD_PROGRESS_BAR)
  2832. true
  2833. #endif
  2834. );
  2835. #if ENABLED(NEWPANEL)
  2836. #if BUTTON_EXISTS(EN1)
  2837. SET_INPUT_PULLUP(BTN_EN1);
  2838. #endif
  2839. #if BUTTON_EXISTS(EN2)
  2840. SET_INPUT_PULLUP(BTN_EN2);
  2841. #endif
  2842. #if BUTTON_EXISTS(ENC)
  2843. SET_INPUT_PULLUP(BTN_ENC);
  2844. #endif
  2845. #if ENABLED(REPRAPWORLD_KEYPAD)
  2846. SET_OUTPUT(SHIFT_CLK);
  2847. OUT_WRITE(SHIFT_LD, HIGH);
  2848. SET_INPUT_PULLUP(SHIFT_OUT);
  2849. #endif
  2850. #if BUTTON_EXISTS(UP)
  2851. SET_INPUT(BTN_UP);
  2852. #endif
  2853. #if BUTTON_EXISTS(DWN)
  2854. SET_INPUT(BTN_DWN);
  2855. #endif
  2856. #if BUTTON_EXISTS(LFT)
  2857. SET_INPUT(BTN_LFT);
  2858. #endif
  2859. #if BUTTON_EXISTS(RT)
  2860. SET_INPUT(BTN_RT);
  2861. #endif
  2862. #else // !NEWPANEL
  2863. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  2864. SET_OUTPUT(SR_DATA_PIN);
  2865. SET_OUTPUT(SR_CLK_PIN);
  2866. #elif defined(SHIFT_CLK)
  2867. SET_OUTPUT(SHIFT_CLK);
  2868. OUT_WRITE(SHIFT_LD, HIGH);
  2869. OUT_WRITE(SHIFT_EN, LOW);
  2870. SET_INPUT_PULLUP(SHIFT_OUT);
  2871. #endif // SR_LCD_2W_NL
  2872. #endif // !NEWPANEL
  2873. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2874. SET_INPUT_PULLUP(SD_DETECT_PIN);
  2875. lcd_sd_status = 2; // UNKNOWN
  2876. #endif
  2877. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2878. slow_buttons = 0;
  2879. #endif
  2880. lcd_buttons_update();
  2881. #if ENABLED(ULTIPANEL)
  2882. encoderDiff = 0;
  2883. #endif
  2884. }
  2885. int lcd_strlen(const char* s) {
  2886. int i = 0, j = 0;
  2887. while (s[i]) {
  2888. #if ENABLED(MAPPER_NON)
  2889. j++;
  2890. #else
  2891. if ((s[i] & 0xC0u) != 0x80u) j++;
  2892. #endif
  2893. i++;
  2894. }
  2895. return j;
  2896. }
  2897. int lcd_strlen_P(const char* s) {
  2898. int j = 0;
  2899. while (pgm_read_byte(s)) {
  2900. #if ENABLED(MAPPER_NON)
  2901. j++;
  2902. #else
  2903. if ((pgm_read_byte(s) & 0xC0u) != 0x80u) j++;
  2904. #endif
  2905. s++;
  2906. }
  2907. return j;
  2908. }
  2909. bool lcd_blink() {
  2910. static uint8_t blink = 0;
  2911. static millis_t next_blink_ms = 0;
  2912. millis_t ms = millis();
  2913. if (ELAPSED(ms, next_blink_ms)) {
  2914. blink ^= 0xFF;
  2915. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  2916. }
  2917. return blink != 0;
  2918. }
  2919. /**
  2920. * Update the LCD, read encoder buttons, etc.
  2921. * - Read button states
  2922. * - Check the SD Card slot state
  2923. * - Act on RepRap World keypad input
  2924. * - Update the encoder position
  2925. * - Apply acceleration to the encoder position
  2926. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  2927. * - Reset the Info Screen timeout if there's any input
  2928. * - Update status indicators, if any
  2929. *
  2930. * Run the current LCD menu handler callback function:
  2931. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  2932. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  2933. * - Call the menu handler. Menu handlers should do the following:
  2934. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  2935. * (Encoder events automatically set lcdDrawUpdate for you.)
  2936. * - if (lcdDrawUpdate) { redraw }
  2937. * - Before exiting the handler set lcdDrawUpdate to:
  2938. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  2939. * - LCDVIEW_REDRAW_NOW or LCDVIEW_NONE to keep drawing, but only in this loop.
  2940. * - LCDVIEW_CALL_REDRAW_NEXT to keep drawing and draw on the next loop also.
  2941. * - LCDVIEW_CALL_NO_REDRAW to keep drawing (or start drawing) with no redraw on the next loop.
  2942. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  2943. * so don't change lcdDrawUpdate without considering this.
  2944. *
  2945. * After the menu handler callback runs (or not):
  2946. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  2947. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  2948. *
  2949. * No worries. This function is only called from the main thread.
  2950. */
  2951. void lcd_update() {
  2952. #if ENABLED(ULTIPANEL)
  2953. static millis_t return_to_status_ms = 0;
  2954. manage_manual_move();
  2955. lcd_buttons_update();
  2956. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2957. const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
  2958. #else
  2959. constexpr bool UBL_CONDITION = true;
  2960. #endif
  2961. // If the action button is pressed...
  2962. if (UBL_CONDITION && LCD_CLICKED) {
  2963. if (!wait_for_unclick) { // If not waiting for a debounce release:
  2964. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  2965. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  2966. wait_for_user = false; // Any click clears wait for user
  2967. lcd_quick_feedback(); // Always make a click sound
  2968. }
  2969. }
  2970. else wait_for_unclick = false;
  2971. #endif
  2972. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2973. bool sd_status = IS_SD_INSERTED;
  2974. if (sd_status != lcd_sd_status && lcd_detected()) {
  2975. if (sd_status) {
  2976. card.initsd();
  2977. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  2978. }
  2979. else {
  2980. card.release();
  2981. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  2982. }
  2983. lcd_sd_status = sd_status;
  2984. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2985. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  2986. #if ENABLED(LCD_PROGRESS_BAR)
  2987. currentScreen == lcd_status_screen
  2988. #endif
  2989. );
  2990. }
  2991. #endif //SDSUPPORT && SD_DETECT_PIN
  2992. millis_t ms = millis();
  2993. if (ELAPSED(ms, next_lcd_update_ms)
  2994. #if ENABLED(DOGLCD)
  2995. || drawing_screen
  2996. #endif
  2997. ) {
  2998. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  2999. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  3000. lcd_implementation_update_indicators();
  3001. #endif
  3002. #if ENABLED(ULTIPANEL)
  3003. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3004. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  3005. #endif
  3006. #if ENABLED(REPRAPWORLD_KEYPAD)
  3007. handle_reprapworld_keypad();
  3008. #endif
  3009. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  3010. if (encoderPastThreshold || lcd_clicked) {
  3011. if (encoderPastThreshold) {
  3012. int32_t encoderMultiplier = 1;
  3013. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  3014. if (encoderRateMultiplierEnabled) {
  3015. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  3016. if (lastEncoderMovementMillis != 0) {
  3017. // Note that the rate is always calculated between to passes through the
  3018. // loop and that the abs of the encoderDiff value is tracked.
  3019. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  3020. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  3021. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  3022. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  3023. SERIAL_ECHO_START;
  3024. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  3025. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  3026. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  3027. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  3028. SERIAL_EOL;
  3029. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  3030. }
  3031. lastEncoderMovementMillis = ms;
  3032. } // encoderRateMultiplierEnabled
  3033. #endif //ENCODER_RATE_MULTIPLIER
  3034. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  3035. encoderDiff = 0;
  3036. }
  3037. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3038. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  3039. }
  3040. #endif // ULTIPANEL
  3041. // We arrive here every ~100ms when idling often enough.
  3042. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  3043. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  3044. if (
  3045. #if ENABLED(ULTIPANEL)
  3046. currentScreen == lcd_status_screen &&
  3047. #endif
  3048. !lcd_status_update_delay--
  3049. ) {
  3050. lcd_status_update_delay = 9
  3051. #if ENABLED(DOGLCD)
  3052. + 3
  3053. #endif
  3054. ;
  3055. max_display_update_time--;
  3056. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3057. }
  3058. // then we want to use 1/2 of the time only.
  3059. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  3060. #if ENABLED(DOGLCD)
  3061. if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
  3062. #else
  3063. if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
  3064. #endif
  3065. {
  3066. #if ENABLED(DOGLCD)
  3067. if (!drawing_screen)
  3068. #endif
  3069. {
  3070. switch (lcdDrawUpdate) {
  3071. case LCDVIEW_CALL_NO_REDRAW:
  3072. lcdDrawUpdate = LCDVIEW_NONE;
  3073. break;
  3074. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  3075. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  3076. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3077. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  3078. case LCDVIEW_NONE:
  3079. break;
  3080. } // switch
  3081. }
  3082. #if ENABLED(ULTIPANEL)
  3083. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  3084. #else
  3085. #define CURRENTSCREEN() lcd_status_screen()
  3086. #endif
  3087. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  3088. if (!drawing_screen) {
  3089. u8g.firstPage();
  3090. drawing_screen = 1;
  3091. }
  3092. lcd_setFont(FONT_MENU);
  3093. u8g.setColorIndex(1);
  3094. CURRENTSCREEN();
  3095. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  3096. NOLESS(max_display_update_time, millis() - ms);
  3097. return;
  3098. }
  3099. #else
  3100. CURRENTSCREEN();
  3101. #endif
  3102. NOLESS(max_display_update_time, millis() - ms);
  3103. }
  3104. #if ENABLED(ULTIPANEL)
  3105. // Return to Status Screen after a timeout
  3106. if (currentScreen == lcd_status_screen || defer_return_to_status)
  3107. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3108. else if (ELAPSED(ms, return_to_status_ms))
  3109. lcd_return_to_status();
  3110. #endif // ULTIPANEL
  3111. #if ENABLED(DOGLCD)
  3112. if (!drawing_screen)
  3113. #endif
  3114. {
  3115. switch (lcdDrawUpdate) {
  3116. case LCDVIEW_CLEAR_CALL_REDRAW:
  3117. lcd_implementation_clear();
  3118. case LCDVIEW_CALL_REDRAW_NEXT:
  3119. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3120. break;
  3121. case LCDVIEW_REDRAW_NOW:
  3122. lcdDrawUpdate = LCDVIEW_NONE;
  3123. break;
  3124. case LCDVIEW_NONE:
  3125. break;
  3126. } // switch
  3127. }
  3128. } // ELAPSED(ms, next_lcd_update_ms)
  3129. }
  3130. void set_utf_strlen(char* s, uint8_t n) {
  3131. uint8_t i = 0, j = 0;
  3132. while (s[i] && (j < n)) {
  3133. #if ENABLED(MAPPER_NON)
  3134. j++;
  3135. #else
  3136. if ((s[i] & 0xC0u) != 0x80u) j++;
  3137. #endif
  3138. i++;
  3139. }
  3140. while (j++ < n) s[i++] = ' ';
  3141. s[i] = '\0';
  3142. }
  3143. void lcd_finishstatus(bool persist=false) {
  3144. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  3145. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  3146. UNUSED(persist);
  3147. #endif
  3148. #if ENABLED(LCD_PROGRESS_BAR)
  3149. progress_bar_ms = millis();
  3150. #if PROGRESS_MSG_EXPIRE > 0
  3151. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  3152. #endif
  3153. #endif
  3154. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3155. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  3156. previous_lcd_status_ms = millis(); //get status message to show up for a while
  3157. #endif
  3158. }
  3159. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  3160. void dontExpireStatus() { expire_status_ms = 0; }
  3161. #endif
  3162. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  3163. void lcd_setstatus(const char * const message, const bool persist) {
  3164. if (lcd_status_message_level > 0) return;
  3165. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  3166. lcd_finishstatus(persist);
  3167. }
  3168. void lcd_setstatuspgm(const char * const message, const uint8_t level) {
  3169. if (level < lcd_status_message_level) return;
  3170. lcd_status_message_level = level;
  3171. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  3172. lcd_finishstatus(level > 0);
  3173. }
  3174. void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
  3175. if (level < lcd_status_message_level) return;
  3176. lcd_status_message_level = level;
  3177. va_list args;
  3178. va_start(args, fmt);
  3179. vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args);
  3180. va_end(args);
  3181. lcd_finishstatus(level > 0);
  3182. }
  3183. void lcd_setalertstatuspgm(const char * const message) {
  3184. lcd_setstatuspgm(message, 1);
  3185. #if ENABLED(ULTIPANEL)
  3186. lcd_return_to_status();
  3187. #endif
  3188. }
  3189. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  3190. #if HAS_LCD_CONTRAST
  3191. void set_lcd_contrast(const int value) {
  3192. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  3193. u8g.setContrast(lcd_contrast);
  3194. }
  3195. #endif
  3196. #if ENABLED(ULTIPANEL)
  3197. /**
  3198. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  3199. * These values are independent of which pins are used for EN_A and EN_B indications
  3200. * The rotary encoder part is also independent to the chipset used for the LCD
  3201. */
  3202. #if defined(EN_A) && defined(EN_B)
  3203. #define encrot0 0
  3204. #define encrot1 2
  3205. #define encrot2 3
  3206. #define encrot3 1
  3207. #endif
  3208. #define GET_BUTTON_STATES(DST) \
  3209. uint8_t new_##DST = 0; \
  3210. WRITE(SHIFT_LD, LOW); \
  3211. WRITE(SHIFT_LD, HIGH); \
  3212. for (int8_t i = 0; i < 8; i++) { \
  3213. new_##DST >>= 1; \
  3214. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  3215. WRITE(SHIFT_CLK, HIGH); \
  3216. WRITE(SHIFT_CLK, LOW); \
  3217. } \
  3218. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  3219. /**
  3220. * Read encoder buttons from the hardware registers
  3221. * Warning: This function is called from interrupt context!
  3222. */
  3223. void lcd_buttons_update() {
  3224. millis_t now = millis();
  3225. if (ELAPSED(now, next_button_update_ms)) {
  3226. #if ENABLED(NEWPANEL)
  3227. uint8_t newbutton = 0;
  3228. #if BUTTON_EXISTS(EN1)
  3229. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  3230. #endif
  3231. #if BUTTON_EXISTS(EN2)
  3232. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  3233. #endif
  3234. #if BUTTON_EXISTS(ENC)
  3235. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  3236. #endif
  3237. #if LCD_HAS_DIRECTIONAL_BUTTONS
  3238. // Manage directional buttons
  3239. #if ENABLED(REVERSE_MENU_DIRECTION)
  3240. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  3241. #else
  3242. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  3243. #endif
  3244. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  3245. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  3246. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  3247. #else
  3248. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  3249. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  3250. #endif
  3251. if (false) {
  3252. // for the else-ifs below
  3253. }
  3254. #if BUTTON_EXISTS(UP)
  3255. else if (BUTTON_PRESSED(UP)) {
  3256. encoderDiff = -(ENCODER_UD_STEPS);
  3257. next_button_update_ms = now + 300;
  3258. }
  3259. #endif
  3260. #if BUTTON_EXISTS(DWN)
  3261. else if (BUTTON_PRESSED(DWN)) {
  3262. encoderDiff = ENCODER_UD_STEPS;
  3263. next_button_update_ms = now + 300;
  3264. }
  3265. #endif
  3266. #if BUTTON_EXISTS(LFT)
  3267. else if (BUTTON_PRESSED(LFT)) {
  3268. encoderDiff = -(ENCODER_LR_PULSES);
  3269. next_button_update_ms = now + 300;
  3270. }
  3271. #endif
  3272. #if BUTTON_EXISTS(RT)
  3273. else if (BUTTON_PRESSED(RT)) {
  3274. encoderDiff = ENCODER_LR_PULSES;
  3275. next_button_update_ms = now + 300;
  3276. }
  3277. #endif
  3278. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  3279. buttons = newbutton;
  3280. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3281. buttons |= slow_buttons;
  3282. #endif
  3283. #if ENABLED(REPRAPWORLD_KEYPAD)
  3284. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  3285. #endif
  3286. #else
  3287. GET_BUTTON_STATES(buttons);
  3288. #endif //!NEWPANEL
  3289. } // next_button_update_ms
  3290. // Manage encoder rotation
  3291. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  3292. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  3293. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  3294. #elif ENABLED(REVERSE_MENU_DIRECTION)
  3295. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  3296. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  3297. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  3298. #define ENCODER_DIFF_CW (encoderDiff--)
  3299. #define ENCODER_DIFF_CCW (encoderDiff++)
  3300. #else
  3301. #define ENCODER_DIFF_CW (encoderDiff++)
  3302. #define ENCODER_DIFF_CCW (encoderDiff--)
  3303. #endif
  3304. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  3305. uint8_t enc = 0;
  3306. if (buttons & EN_A) enc |= B01;
  3307. if (buttons & EN_B) enc |= B10;
  3308. if (enc != lastEncoderBits) {
  3309. switch (enc) {
  3310. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  3311. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  3312. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  3313. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  3314. }
  3315. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3316. if (ubl.has_control_of_lcd_panel) {
  3317. ubl.encoder_diff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
  3318. encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
  3319. // wheel has not turned.
  3320. }
  3321. #endif
  3322. lastEncoderBits = enc;
  3323. }
  3324. }
  3325. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  3326. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  3327. #else
  3328. bool lcd_detected() { return true; }
  3329. #endif
  3330. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3331. void chirp_at_user() {
  3332. #if ENABLED(LCD_USE_I2C_BUZZER)
  3333. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  3334. #elif PIN_EXISTS(BEEPER)
  3335. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  3336. #endif
  3337. }
  3338. bool ubl_lcd_clicked() { return LCD_CLICKED; }
  3339. #endif
  3340. #endif // ULTIPANEL
  3341. #endif // ULTRA_LCD