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 128KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795
  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. 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. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  736. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  737. #endif //BABYSTEPPING
  738. #if ENABLED(AUTO_BED_LEVELING_UBL)
  739. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  740. // seperate value that doesn't lose precision.
  741. static int ubl_encoderPosition = 0;
  742. static void _lcd_mesh_fine_tune(const char* msg) {
  743. defer_return_to_status = true;
  744. if (ubl.encoder_diff) {
  745. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  746. ubl.encoder_diff = 0;
  747. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
  748. mesh_edit_value = mesh_edit_accumulator;
  749. encoderPosition = 0;
  750. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  751. const int32_t rounded = (int32_t)(mesh_edit_value * 1000.0);
  752. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
  753. }
  754. if (lcdDrawUpdate)
  755. lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
  756. }
  757. void _lcd_mesh_edit_NOP() {
  758. defer_return_to_status = true;
  759. }
  760. void _lcd_mesh_edit() {
  761. _lcd_mesh_fine_tune(PSTR("Mesh Editor: "));
  762. }
  763. float lcd_mesh_edit() {
  764. lcd_goto_screen(_lcd_mesh_edit_NOP);
  765. _lcd_mesh_fine_tune(PSTR("Mesh Editor: "));
  766. return mesh_edit_value;
  767. }
  768. void lcd_mesh_edit_setup(float initial) {
  769. mesh_edit_value = mesh_edit_accumulator = initial;
  770. lcd_goto_screen(_lcd_mesh_edit_NOP);
  771. }
  772. void _lcd_z_offset_edit() {
  773. _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
  774. }
  775. float lcd_z_offset_edit() {
  776. lcd_goto_screen(_lcd_z_offset_edit);
  777. return mesh_edit_value;
  778. }
  779. void lcd_z_offset_edit_setup(float initial) {
  780. mesh_edit_value = mesh_edit_accumulator = initial;
  781. lcd_goto_screen(_lcd_z_offset_edit);
  782. }
  783. #endif // AUTO_BED_LEVELING_UBL
  784. /**
  785. * Watch temperature callbacks
  786. */
  787. #if HAS_TEMP_HOTEND
  788. #if WATCH_HOTENDS
  789. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  790. #else
  791. #define _WATCH_FUNC(N) NOOP
  792. #endif
  793. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  794. #if HOTENDS > 1
  795. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  796. #if HOTENDS > 2
  797. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  798. #if HOTENDS > 3
  799. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  800. #if HOTENDS > 4
  801. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  802. #endif // HOTENDS > 4
  803. #endif // HOTENDS > 3
  804. #endif // HOTENDS > 2
  805. #endif // HOTENDS > 1
  806. #endif // HAS_TEMP_HOTEND
  807. #if WATCH_THE_BED
  808. void watch_temp_callback_bed() { thermalManager.start_watching_bed(); }
  809. #endif
  810. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  811. void lcd_enqueue_filament_change() {
  812. if (!DEBUGGING(DRYRUN) && thermalManager.tooColdToExtrude(active_extruder)) {
  813. lcd_save_previous_screen();
  814. lcd_goto_screen(lcd_filament_change_toocold_menu);
  815. return;
  816. }
  817. lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_INIT);
  818. enqueue_and_echo_commands_P(PSTR("M600"));
  819. }
  820. #endif
  821. /**
  822. *
  823. * "Tune" submenu
  824. *
  825. */
  826. void lcd_tune_menu() {
  827. START_MENU();
  828. //
  829. // ^ Main
  830. //
  831. MENU_BACK(MSG_MAIN);
  832. //
  833. // Speed:
  834. //
  835. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  836. // Manual bed leveling, Bed Z:
  837. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  838. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  839. #endif
  840. //
  841. // Nozzle:
  842. // Nozzle [1-4]:
  843. //
  844. #if HOTENDS == 1
  845. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  846. #else //HOTENDS > 1
  847. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  848. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  849. #if HOTENDS > 2
  850. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  851. #if HOTENDS > 3
  852. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  853. #if HOTENDS > 4
  854. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  855. #endif // HOTENDS > 4
  856. #endif // HOTENDS > 3
  857. #endif // HOTENDS > 2
  858. #endif // HOTENDS > 1
  859. //
  860. // Bed:
  861. //
  862. #if WATCH_THE_BED
  863. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  864. #endif
  865. //
  866. // Fan Speed:
  867. //
  868. #if FAN_COUNT > 0
  869. #if HAS_FAN0
  870. #if FAN_COUNT > 1
  871. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  872. #else
  873. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  874. #endif
  875. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  876. #endif
  877. #if HAS_FAN1
  878. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  879. #endif
  880. #if HAS_FAN2
  881. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  882. #endif
  883. #endif // FAN_COUNT > 0
  884. //
  885. // Flow:
  886. // Flow [1-5]:
  887. //
  888. #if EXTRUDERS == 1
  889. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
  890. #else // EXTRUDERS > 1
  891. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
  892. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
  893. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &flow_percentage[1], 10, 999);
  894. #if EXTRUDERS > 2
  895. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &flow_percentage[2], 10, 999);
  896. #if EXTRUDERS > 3
  897. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &flow_percentage[3], 10, 999);
  898. #if EXTRUDERS > 4
  899. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &flow_percentage[4], 10, 999);
  900. #endif //EXTRUDERS > 4
  901. #endif //EXTRUDERS > 3
  902. #endif //EXTRUDERS > 2
  903. #endif //EXTRUDERS > 1
  904. //
  905. // Babystep X:
  906. // Babystep Y:
  907. // Babystep Z:
  908. //
  909. #if ENABLED(BABYSTEPPING)
  910. #if ENABLED(BABYSTEP_XY)
  911. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  912. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  913. #endif //BABYSTEP_XY
  914. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  915. #endif
  916. //
  917. // Change filament
  918. //
  919. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  920. if (!thermalManager.tooColdToExtrude(active_extruder))
  921. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  922. #endif
  923. END_MENU();
  924. }
  925. /**
  926. *
  927. * "Driver current control" submenu items
  928. *
  929. */
  930. #if ENABLED(DAC_STEPPER_CURRENT)
  931. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  932. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  933. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  934. void lcd_dac_menu() {
  935. dac_driver_getValues();
  936. START_MENU();
  937. MENU_BACK(MSG_CONTROL);
  938. MENU_ITEM_EDIT_CALLBACK(int3, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  939. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  940. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  941. MENU_ITEM_EDIT_CALLBACK(int3, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  942. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  943. END_MENU();
  944. }
  945. #endif
  946. constexpr int heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  947. /**
  948. *
  949. * "Prepare" submenu items
  950. *
  951. */
  952. void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
  953. if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
  954. #if TEMP_SENSOR_BED != 0
  955. if (tempb >= 0) thermalManager.setTargetBed(tempb);
  956. #else
  957. UNUSED(tempb);
  958. #endif
  959. #if FAN_COUNT > 0
  960. #if FAN_COUNT > 1
  961. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  962. #else
  963. fanSpeeds[0] = fan;
  964. #endif
  965. #else
  966. UNUSED(fan);
  967. #endif
  968. lcd_return_to_status();
  969. }
  970. #if TEMP_SENSOR_0 != 0
  971. void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  972. void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  973. #if TEMP_SENSOR_BED != 0
  974. void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  975. void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  976. #endif
  977. #endif
  978. #if HOTENDS > 1
  979. void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  980. void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  981. #if TEMP_SENSOR_BED != 0
  982. void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  983. void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  984. #endif
  985. #if HOTENDS > 2
  986. void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  987. void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  988. #if TEMP_SENSOR_BED != 0
  989. void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  990. void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  991. #endif
  992. #if HOTENDS > 3
  993. void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  994. void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  995. #if TEMP_SENSOR_BED != 0
  996. void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  997. void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  998. #endif
  999. #if HOTENDS > 4
  1000. void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1001. void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1002. #if TEMP_SENSOR_BED != 0
  1003. void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1004. void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1005. #endif
  1006. #endif // HOTENDS > 4
  1007. #endif // HOTENDS > 3
  1008. #endif // HOTENDS > 2
  1009. void lcd_preheat_m1_all() {
  1010. #if HOTENDS > 1
  1011. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  1012. #if HOTENDS > 2
  1013. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  1014. #if HOTENDS > 3
  1015. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  1016. #if HOTENDS > 4
  1017. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 4);
  1018. #endif // HOTENDS > 4
  1019. #endif // HOTENDS > 3
  1020. #endif // HOTENDS > 2
  1021. #endif // HOTENDS > 1
  1022. #if TEMP_SENSOR_BED != 0
  1023. lcd_preheat_m1_e0();
  1024. #else
  1025. lcd_preheat_m1_e0_only();
  1026. #endif
  1027. }
  1028. void lcd_preheat_m2_all() {
  1029. #if HOTENDS > 1
  1030. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  1031. #if HOTENDS > 2
  1032. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  1033. #if HOTENDS > 3
  1034. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  1035. #if HOTENDS > 4
  1036. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 4);
  1037. #endif // HOTENDS > 4
  1038. #endif // HOTENDS > 3
  1039. #endif // HOTENDS > 2
  1040. #endif // HOTENDS > 1
  1041. #if TEMP_SENSOR_BED != 0
  1042. lcd_preheat_m2_e0();
  1043. #else
  1044. lcd_preheat_m2_e0_only();
  1045. #endif
  1046. }
  1047. #endif // HOTENDS > 1
  1048. #if TEMP_SENSOR_BED != 0
  1049. void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1050. void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1051. #endif
  1052. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0)
  1053. void lcd_preheat_m1_menu() {
  1054. START_MENU();
  1055. MENU_BACK(MSG_PREPARE);
  1056. #if HOTENDS == 1
  1057. #if TEMP_SENSOR_BED != 0
  1058. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
  1059. MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
  1060. #else
  1061. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1062. #endif
  1063. #else
  1064. #if TEMP_SENSOR_BED != 0
  1065. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
  1066. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
  1067. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
  1068. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E2, lcd_preheat_m1_e1_only);
  1069. #else
  1070. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0_only);
  1071. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
  1072. #endif
  1073. #if HOTENDS > 2
  1074. #if TEMP_SENSOR_BED != 0
  1075. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
  1076. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
  1077. #else
  1078. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
  1079. #endif
  1080. #if HOTENDS > 3
  1081. #if TEMP_SENSOR_BED != 0
  1082. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
  1083. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
  1084. #else
  1085. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
  1086. #endif
  1087. #if HOTENDS > 4
  1088. #if TEMP_SENSOR_BED != 0
  1089. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
  1090. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
  1091. #else
  1092. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4_only);
  1093. #endif
  1094. #endif // HOTENDS > 4
  1095. #endif // HOTENDS > 3
  1096. #endif // HOTENDS > 2
  1097. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
  1098. #endif // HOTENDS > 1
  1099. #if TEMP_SENSOR_BED != 0
  1100. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
  1101. #endif
  1102. END_MENU();
  1103. }
  1104. void lcd_preheat_m2_menu() {
  1105. START_MENU();
  1106. MENU_BACK(MSG_PREPARE);
  1107. #if HOTENDS == 1
  1108. #if TEMP_SENSOR_BED != 0
  1109. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
  1110. MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
  1111. #else
  1112. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1113. #endif
  1114. #else
  1115. #if TEMP_SENSOR_BED != 0
  1116. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
  1117. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
  1118. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
  1119. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E2, lcd_preheat_m2_e1_only);
  1120. #else
  1121. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0_only);
  1122. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
  1123. #endif
  1124. #if HOTENDS > 2
  1125. #if TEMP_SENSOR_BED != 0
  1126. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
  1127. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
  1128. #else
  1129. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
  1130. #endif
  1131. #if HOTENDS > 3
  1132. #if TEMP_SENSOR_BED != 0
  1133. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
  1134. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
  1135. #else
  1136. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
  1137. #endif
  1138. #if HOTENDS > 4
  1139. #if TEMP_SENSOR_BED != 0
  1140. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
  1141. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
  1142. #else
  1143. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4_only);
  1144. #endif
  1145. #endif // HOTENDS > 4
  1146. #endif // HOTENDS > 3
  1147. #endif // HOTENDS > 2
  1148. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
  1149. #endif // HOTENDS > 1
  1150. #if TEMP_SENSOR_BED != 0
  1151. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
  1152. #endif
  1153. END_MENU();
  1154. }
  1155. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_BED)
  1156. void lcd_cooldown() {
  1157. #if FAN_COUNT > 0
  1158. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  1159. #endif
  1160. thermalManager.disable_all_heaters();
  1161. lcd_return_to_status();
  1162. }
  1163. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1164. void lcd_autostart_sd() {
  1165. card.autostart_index = 0;
  1166. card.setroot();
  1167. card.checkautostart(true);
  1168. }
  1169. #endif
  1170. #if ENABLED(LCD_BED_LEVELING)
  1171. /**
  1172. *
  1173. * "Prepare" > "Level Bed" handlers
  1174. *
  1175. */
  1176. static uint8_t manual_probe_index;
  1177. #if ENABLED(PROBE_MANUALLY)
  1178. extern bool g29_in_progress;
  1179. #endif
  1180. // LCD probed points are from defaults
  1181. constexpr uint8_t total_probe_points =
  1182. #if ABL_GRID
  1183. (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
  1184. #elif ENABLED(AUTO_BED_LEVELING_3POINT)
  1185. int(3)
  1186. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1187. (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
  1188. #elif ENABLED(MESH_BED_LEVELING)
  1189. (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
  1190. #endif
  1191. ;
  1192. #if ENABLED(MESH_BED_LEVELING)
  1193. // Utility to go to the next mesh point
  1194. inline void _manual_probe_goto_xy(float x, float y) {
  1195. #if MANUAL_PROBE_HEIGHT > 0
  1196. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
  1197. line_to_current(Z_AXIS);
  1198. #endif
  1199. current_position[X_AXIS] = LOGICAL_X_POSITION(x);
  1200. current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
  1201. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1202. #if MANUAL_PROBE_HEIGHT > 0
  1203. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + 0.2;
  1204. line_to_current(Z_AXIS);
  1205. #endif
  1206. lcd_synchronize();
  1207. }
  1208. #endif // MESH_BED_LEVELING
  1209. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  1210. void _lcd_level_goto_next_point();
  1211. #endif
  1212. void _lcd_level_bed_done() {
  1213. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  1214. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1215. }
  1216. /**
  1217. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  1218. */
  1219. void _lcd_level_bed_moving() {
  1220. if (lcdDrawUpdate) {
  1221. char msg[10];
  1222. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  1223. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  1224. }
  1225. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1226. }
  1227. /**
  1228. * Step 7: Get the Z coordinate, click goes to the next point or exits
  1229. */
  1230. void _lcd_level_bed_get_z() {
  1231. ENCODER_DIRECTION_NORMAL();
  1232. // Encoder wheel adjusts the Z position
  1233. if (encoderPosition) {
  1234. refresh_cmd_timeout();
  1235. current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
  1236. NOLESS(current_position[Z_AXIS], -(LCD_PROBE_Z_RANGE) * 0.5);
  1237. NOMORE(current_position[Z_AXIS], (LCD_PROBE_Z_RANGE) * 0.5);
  1238. line_to_current(Z_AXIS);
  1239. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1240. encoderPosition = 0;
  1241. }
  1242. if (lcd_clicked) {
  1243. // Use a hook to set the probe point z
  1244. // (zigzag arranges in XY order)
  1245. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1246. // UBL set-z handling goes here
  1247. #elif ENABLED(PROBE_MANUALLY)
  1248. // G29 helpfully records Z and goes to the next
  1249. // point (or beeps if done)
  1250. enqueue_and_echo_commands_P(PSTR("G29"));
  1251. manual_probe_index++;
  1252. #elif ENABLED(MESH_BED_LEVELING)
  1253. mbl.set_zigzag_z(manual_probe_index++, current_position[Z_AXIS]);
  1254. #endif
  1255. // If done...
  1256. if (manual_probe_index == total_probe_points) {
  1257. // Say "Done!"
  1258. lcd_goto_screen(_lcd_level_bed_done);
  1259. // Raise Z to the "manual probe height"
  1260. #if MANUAL_PROBE_HEIGHT > 0
  1261. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
  1262. line_to_current(Z_AXIS);
  1263. lcd_synchronize();
  1264. #endif
  1265. // Enable leveling, if needed
  1266. #if ENABLED(MESH_BED_LEVELING)
  1267. mbl.set_has_mesh(true);
  1268. mbl.set_reactivate(true);
  1269. enqueue_and_echo_commands_P(PSTR("G28"));
  1270. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1271. // UBL enable goes here
  1272. #elif ENABLED(PROBE_MANUALLY)
  1273. // ABL will be enabled due to "G29".
  1274. #endif
  1275. lcd_return_to_status();
  1276. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  1277. lcd_completion_feedback();
  1278. }
  1279. else {
  1280. // Move to the next probe point, if needed
  1281. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  1282. _lcd_level_goto_next_point();
  1283. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1284. // UBL goto-next-point goes here
  1285. #endif
  1286. }
  1287. }
  1288. // Update on first display, then only on updates to Z position
  1289. // Show message above on clicks instead
  1290. if (lcdDrawUpdate) {
  1291. const float v = current_position[Z_AXIS];
  1292. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  1293. }
  1294. }
  1295. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  1296. /**
  1297. * Step 5: Initiate a move to the next point
  1298. */
  1299. void _lcd_level_goto_next_point() {
  1300. // Set the menu to display ahead of blocking call
  1301. lcd_goto_screen(_lcd_level_bed_moving);
  1302. #if ENABLED(MESH_BED_LEVELING)
  1303. int8_t px, py;
  1304. mbl.zigzag(manual_probe_index, px, py);
  1305. // Controls the loop until the move is done
  1306. _manual_probe_goto_xy(
  1307. LOGICAL_X_POSITION(mbl.index_to_xpos[px]),
  1308. LOGICAL_Y_POSITION(mbl.index_to_ypos[py])
  1309. );
  1310. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1311. // UBL may have its own methodology
  1312. #elif ENABLED(PROBE_MANUALLY)
  1313. // Just wait for the G29 move to complete
  1314. lcd_synchronize();
  1315. #endif
  1316. // After the blocking function returns, change menus
  1317. lcd_goto_screen(_lcd_level_bed_get_z);
  1318. }
  1319. #endif // MESH_BED_LEVELING
  1320. /**
  1321. * Step 4: Display "Click to Begin", wait for click
  1322. * Move to the first probe position
  1323. */
  1324. void _lcd_level_bed_homing_done() {
  1325. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1326. if (lcd_clicked) {
  1327. manual_probe_index = 0;
  1328. #if ENABLED(MESH_BED_LEVELING)
  1329. _lcd_level_goto_next_point();
  1330. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1331. // UBL click handling should go here
  1332. #elif ENABLED(PROBE_MANUALLY)
  1333. enqueue_and_echo_commands_P(PSTR("G29"));
  1334. _lcd_level_goto_next_point();
  1335. #endif
  1336. }
  1337. }
  1338. /**
  1339. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1340. */
  1341. void _lcd_level_bed_homing() {
  1342. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1343. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1344. lcd_goto_screen(_lcd_level_bed_homing_done);
  1345. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1346. }
  1347. /**
  1348. * Step 2: Continue Bed Leveling...
  1349. */
  1350. void _lcd_level_bed_continue() {
  1351. #if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL)
  1352. reset_bed_level();
  1353. #endif
  1354. defer_return_to_status = true;
  1355. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1356. lcd_goto_screen(_lcd_level_bed_homing);
  1357. enqueue_and_echo_commands_P(PSTR("G28"));
  1358. }
  1359. /**
  1360. * Step 1: Bed Level entry-point: "Cancel" or "Level Bed"
  1361. */
  1362. void lcd_level_bed() {
  1363. START_MENU();
  1364. MENU_BACK(MSG_LEVEL_BED_CANCEL);
  1365. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1366. END_MENU();
  1367. }
  1368. #endif // LCD_BED_LEVELING
  1369. /**
  1370. *
  1371. * "Prepare" submenu
  1372. *
  1373. */
  1374. void lcd_prepare_menu() {
  1375. START_MENU();
  1376. //
  1377. // ^ Main
  1378. //
  1379. MENU_BACK(MSG_MAIN);
  1380. //
  1381. // Move Axis
  1382. //
  1383. #if ENABLED(DELTA)
  1384. if (axis_homed[Z_AXIS])
  1385. #endif
  1386. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  1387. //
  1388. // Auto Home
  1389. //
  1390. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1391. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  1392. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  1393. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  1394. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  1395. #endif
  1396. //
  1397. // Level Bed
  1398. //
  1399. #if ENABLED(LCD_BED_LEVELING)
  1400. #if ENABLED(PROBE_MANUALLY)
  1401. if (!g29_in_progress)
  1402. #endif
  1403. MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
  1404. #elif HAS_ABL
  1405. MENU_ITEM(gcode, MSG_LEVEL_BED,
  1406. axis_homed[X_AXIS] && axis_homed[Y_AXIS] ? PSTR("G29") : PSTR("G28\nG29")
  1407. );
  1408. #endif
  1409. #if DISABLED(NO_WORKSPACE_OFFSETS)
  1410. //
  1411. // Set Home Offsets
  1412. //
  1413. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  1414. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  1415. #endif
  1416. //
  1417. // Disable Steppers
  1418. //
  1419. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1420. //
  1421. // Preheat PLA
  1422. // Preheat ABS
  1423. //
  1424. #if TEMP_SENSOR_0 != 0
  1425. //
  1426. // Change filament
  1427. //
  1428. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  1429. if (!thermalManager.tooColdToExtrude(active_extruder))
  1430. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  1431. #endif
  1432. //
  1433. // Cooldown
  1434. //
  1435. bool has_heat = false;
  1436. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  1437. #if HAS_TEMP_BED
  1438. if (thermalManager.target_temperature_bed) has_heat = true;
  1439. #endif
  1440. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  1441. //
  1442. // Preheat for Material 1 and 2
  1443. //
  1444. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
  1445. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
  1446. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
  1447. #else
  1448. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1449. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1450. #endif
  1451. #endif // TEMP_SENSOR_0 != 0
  1452. //
  1453. // BLTouch Self-Test and Reset
  1454. //
  1455. #if ENABLED(BLTOUCH)
  1456. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  1457. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  1458. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  1459. #endif
  1460. //
  1461. // Switch power on/off
  1462. //
  1463. #if HAS_POWER_SWITCH
  1464. if (powersupply)
  1465. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  1466. else
  1467. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  1468. #endif
  1469. //
  1470. // Autostart
  1471. //
  1472. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1473. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  1474. #endif
  1475. END_MENU();
  1476. }
  1477. float move_menu_scale;
  1478. #if ENABLED(DELTA_CALIBRATION_MENU)
  1479. void lcd_move_z();
  1480. void lcd_delta_calibrate_menu();
  1481. void _lcd_calibrate_homing() {
  1482. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  1483. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1484. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1485. lcd_goto_previous_menu();
  1486. }
  1487. void _lcd_delta_calibrate_home() {
  1488. enqueue_and_echo_commands_P(PSTR("G28"));
  1489. lcd_goto_screen(_lcd_calibrate_homing);
  1490. }
  1491. // Move directly to the tower position with uninterpolated moves
  1492. // If we used interpolated moves it would cause this to become re-entrant
  1493. void _goto_tower_pos(const float &a) {
  1494. current_position[Z_AXIS] = max(Z_HOMING_HEIGHT, Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5;
  1495. line_to_current(Z_AXIS);
  1496. current_position[X_AXIS] = a < 0 ? X_HOME_POS : sin(a) * -(DELTA_PRINTABLE_RADIUS);
  1497. current_position[Y_AXIS] = a < 0 ? Y_HOME_POS : cos(a) * (DELTA_PRINTABLE_RADIUS);
  1498. line_to_current(Z_AXIS);
  1499. current_position[Z_AXIS] = 4.0;
  1500. line_to_current(Z_AXIS);
  1501. lcd_synchronize();
  1502. move_menu_scale = 0.1;
  1503. lcd_goto_screen(lcd_move_z);
  1504. }
  1505. void _goto_tower_x() { _goto_tower_pos(RADIANS(120)); }
  1506. void _goto_tower_y() { _goto_tower_pos(RADIANS(240)); }
  1507. void _goto_tower_z() { _goto_tower_pos(0); }
  1508. void _goto_center() { _goto_tower_pos(-1); }
  1509. void lcd_delta_calibrate_menu() {
  1510. START_MENU();
  1511. MENU_BACK(MSG_MAIN);
  1512. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  1513. if (axis_homed[Z_AXIS]) {
  1514. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  1515. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  1516. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  1517. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  1518. }
  1519. END_MENU();
  1520. }
  1521. #endif // DELTA_CALIBRATION_MENU
  1522. /**
  1523. * If the most recent manual move hasn't been fed to the planner yet,
  1524. * and the planner can accept one, send immediately
  1525. */
  1526. inline void manage_manual_move() {
  1527. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  1528. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  1529. manual_move_axis = (int8_t)NO_AXIS;
  1530. }
  1531. }
  1532. /**
  1533. * Set a flag that lcd_update() should start a move
  1534. * to "current_position" after a short delay.
  1535. */
  1536. inline void manual_move_to_current(AxisEnum axis
  1537. #if E_MANUAL > 1
  1538. , int8_t eindex=-1
  1539. #endif
  1540. ) {
  1541. #if E_MANUAL > 1
  1542. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  1543. #endif
  1544. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  1545. manual_move_axis = (int8_t)axis;
  1546. }
  1547. /**
  1548. *
  1549. * "Prepare" > "Move Axis" submenu
  1550. *
  1551. */
  1552. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  1553. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1554. ENCODER_DIRECTION_NORMAL();
  1555. if (encoderPosition) {
  1556. refresh_cmd_timeout();
  1557. float min = current_position[axis] - 1000,
  1558. max = current_position[axis] + 1000;
  1559. #if HAS_SOFTWARE_ENDSTOPS
  1560. // Limit to software endstops, if enabled
  1561. if (soft_endstops_enabled) {
  1562. #if ENABLED(MIN_SOFTWARE_ENDSTOPS)
  1563. min = soft_endstop_min[axis];
  1564. #endif
  1565. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  1566. max = soft_endstop_max[axis];
  1567. #endif
  1568. }
  1569. #endif
  1570. // Get the new position
  1571. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  1572. // Delta limits XY based on the current offset from center
  1573. // This assumes the center is 0,0
  1574. #if ENABLED(DELTA)
  1575. if (axis != Z_AXIS) {
  1576. max = sqrt(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
  1577. min = -max;
  1578. }
  1579. #endif
  1580. // Limit only when trying to move towards the limit
  1581. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  1582. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  1583. manual_move_to_current(axis);
  1584. encoderPosition = 0;
  1585. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1586. }
  1587. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
  1588. }
  1589. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  1590. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  1591. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  1592. void _lcd_move_e(
  1593. #if E_MANUAL > 1
  1594. int8_t eindex=-1
  1595. #endif
  1596. ) {
  1597. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1598. ENCODER_DIRECTION_NORMAL();
  1599. if (encoderPosition) {
  1600. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  1601. encoderPosition = 0;
  1602. manual_move_to_current(E_AXIS
  1603. #if E_MANUAL > 1
  1604. , eindex
  1605. #endif
  1606. );
  1607. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1608. }
  1609. if (lcdDrawUpdate) {
  1610. PGM_P pos_label;
  1611. #if E_MANUAL == 1
  1612. pos_label = PSTR(MSG_MOVE_E);
  1613. #else
  1614. switch (eindex) {
  1615. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  1616. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  1617. #if E_MANUAL > 2
  1618. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  1619. #if E_MANUAL > 3
  1620. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  1621. #if E_MANUAL > 4
  1622. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  1623. #endif // E_MANUAL > 4
  1624. #endif // E_MANUAL > 3
  1625. #endif // E_MANUAL > 2
  1626. }
  1627. #endif // E_MANUAL > 1
  1628. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  1629. }
  1630. }
  1631. void lcd_move_e() { _lcd_move_e(); }
  1632. #if E_MANUAL > 1
  1633. void lcd_move_e0() { _lcd_move_e(0); }
  1634. void lcd_move_e1() { _lcd_move_e(1); }
  1635. #if E_MANUAL > 2
  1636. void lcd_move_e2() { _lcd_move_e(2); }
  1637. #if E_MANUAL > 3
  1638. void lcd_move_e3() { _lcd_move_e(3); }
  1639. #if E_MANUAL > 4
  1640. void lcd_move_e4() { _lcd_move_e(4); }
  1641. #endif // E_MANUAL > 4
  1642. #endif // E_MANUAL > 3
  1643. #endif // E_MANUAL > 2
  1644. #endif // E_MANUAL > 1
  1645. /**
  1646. *
  1647. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  1648. *
  1649. */
  1650. screenFunc_t _manual_move_func_ptr;
  1651. void lcd_move_menu_10mm() { move_menu_scale = 10.0; lcd_goto_screen(_manual_move_func_ptr); }
  1652. void lcd_move_menu_1mm() { move_menu_scale = 1.0; lcd_goto_screen(_manual_move_func_ptr); }
  1653. void lcd_move_menu_01mm() { move_menu_scale = 0.1; lcd_goto_screen(_manual_move_func_ptr); }
  1654. void _lcd_move_distance_menu(AxisEnum axis, screenFunc_t func) {
  1655. _manual_move_func_ptr = func;
  1656. START_MENU();
  1657. if (LCD_HEIGHT >= 4) {
  1658. switch(axis) {
  1659. case X_AXIS:
  1660. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  1661. case Y_AXIS:
  1662. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  1663. case Z_AXIS:
  1664. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  1665. default:
  1666. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  1667. }
  1668. }
  1669. MENU_BACK(MSG_MOVE_AXIS);
  1670. if (axis == X_AXIS || axis == Y_AXIS)
  1671. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  1672. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  1673. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  1674. END_MENU();
  1675. }
  1676. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  1677. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  1678. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  1679. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  1680. #if E_MANUAL > 1
  1681. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  1682. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  1683. #if E_MANUAL > 2
  1684. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  1685. #if E_MANUAL > 3
  1686. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  1687. #if E_MANUAL > 4
  1688. void lcd_move_get_e4_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e4); }
  1689. #endif // E_MANUAL > 4
  1690. #endif // E_MANUAL > 3
  1691. #endif // E_MANUAL > 2
  1692. #endif // E_MANUAL > 1
  1693. /**
  1694. *
  1695. * "Prepare" > "Move Axis" submenu
  1696. *
  1697. */
  1698. #if IS_KINEMATIC
  1699. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1700. #if ENABLED(DELTA)
  1701. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  1702. void lcd_lower_z_to_clip_height() {
  1703. current_position[Z_AXIS] = delta_clip_start_height;
  1704. line_to_current(Z_AXIS);
  1705. lcd_synchronize();
  1706. }
  1707. #else
  1708. #define _MOVE_XY_ALLOWED true
  1709. #endif
  1710. #else
  1711. #define _MOVE_XYZ_ALLOWED true
  1712. #define _MOVE_XY_ALLOWED true
  1713. #endif
  1714. void lcd_move_menu() {
  1715. START_MENU();
  1716. MENU_BACK(MSG_PREPARE);
  1717. if (_MOVE_XYZ_ALLOWED) {
  1718. if (_MOVE_XY_ALLOWED) {
  1719. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  1720. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  1721. }
  1722. #if ENABLED(DELTA)
  1723. else
  1724. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  1725. #endif
  1726. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  1727. }
  1728. else
  1729. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1730. #if ENABLED(SWITCHING_EXTRUDER)
  1731. if (active_extruder)
  1732. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  1733. else
  1734. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  1735. #endif
  1736. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  1737. #if E_MANUAL > 1
  1738. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  1739. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  1740. #if E_MANUAL > 2
  1741. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  1742. #if E_MANUAL > 3
  1743. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  1744. #if E_MANUAL > 4
  1745. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  1746. #endif // E_MANUAL > 4
  1747. #endif // E_MANUAL > 3
  1748. #endif // E_MANUAL > 2
  1749. #endif // E_MANUAL > 1
  1750. END_MENU();
  1751. }
  1752. /**
  1753. *
  1754. * "Control" submenu
  1755. *
  1756. */
  1757. #if ENABLED(EEPROM_SETTINGS)
  1758. static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  1759. static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  1760. #endif
  1761. static void lcd_factory_settings() {
  1762. settings.reset();
  1763. lcd_completion_feedback();
  1764. }
  1765. void lcd_control_menu() {
  1766. START_MENU();
  1767. MENU_BACK(MSG_MAIN);
  1768. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1769. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  1770. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  1771. #if HAS_LCD_CONTRAST
  1772. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  1773. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  1774. #endif
  1775. #if ENABLED(FWRETRACT)
  1776. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  1777. #endif
  1778. #if ENABLED(DAC_STEPPER_CURRENT)
  1779. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  1780. #endif
  1781. #if ENABLED(EEPROM_SETTINGS)
  1782. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  1783. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  1784. #endif
  1785. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, lcd_factory_settings);
  1786. END_MENU();
  1787. }
  1788. /**
  1789. *
  1790. * "Temperature" submenu
  1791. *
  1792. */
  1793. #if ENABLED(PID_AUTOTUNE_MENU)
  1794. #if ENABLED(PIDTEMP)
  1795. int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  1796. #endif
  1797. #if ENABLED(PIDTEMPBED)
  1798. int autotune_temp_bed = 70;
  1799. #endif
  1800. void _lcd_autotune(int e) {
  1801. char cmd[30];
  1802. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  1803. #if HAS_PID_FOR_BOTH
  1804. e < 0 ? autotune_temp_bed : autotune_temp[e]
  1805. #elif ENABLED(PIDTEMPBED)
  1806. autotune_temp_bed
  1807. #else
  1808. autotune_temp[e]
  1809. #endif
  1810. );
  1811. enqueue_and_echo_command(cmd);
  1812. }
  1813. #endif //PID_AUTOTUNE_MENU
  1814. #if ENABLED(PIDTEMP)
  1815. // Helpers for editing PID Ki & Kd values
  1816. // grab the PID value out of the temp variable; scale it; then update the PID driver
  1817. void copy_and_scalePID_i(int e) {
  1818. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1819. UNUSED(e);
  1820. #endif
  1821. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  1822. thermalManager.updatePID();
  1823. }
  1824. void copy_and_scalePID_d(int e) {
  1825. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1826. UNUSED(e);
  1827. #endif
  1828. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  1829. thermalManager.updatePID();
  1830. }
  1831. #define _PIDTEMP_BASE_FUNCTIONS(N) \
  1832. void copy_and_scalePID_i_E ## N() { copy_and_scalePID_i(N); } \
  1833. void copy_and_scalePID_d_E ## N() { copy_and_scalePID_d(N); }
  1834. #if ENABLED(PID_AUTOTUNE_MENU)
  1835. #define _PIDTEMP_FUNCTIONS(N) \
  1836. _PIDTEMP_BASE_FUNCTIONS(N); \
  1837. void lcd_autotune_callback_E ## N() { _lcd_autotune(N); }
  1838. #else
  1839. #define _PIDTEMP_FUNCTIONS(N) _PIDTEMP_BASE_FUNCTIONS(N)
  1840. #endif
  1841. _PIDTEMP_FUNCTIONS(0)
  1842. #if ENABLED(PID_PARAMS_PER_HOTEND)
  1843. #if HOTENDS > 1
  1844. _PIDTEMP_FUNCTIONS(1)
  1845. #if HOTENDS > 2
  1846. _PIDTEMP_FUNCTIONS(2)
  1847. #if HOTENDS > 3
  1848. _PIDTEMP_FUNCTIONS(3)
  1849. #if HOTENDS > 4
  1850. _PIDTEMP_FUNCTIONS(4)
  1851. #endif // HOTENDS > 4
  1852. #endif // HOTENDS > 3
  1853. #endif // HOTENDS > 2
  1854. #endif // HOTENDS > 1
  1855. #endif // PID_PARAMS_PER_HOTEND
  1856. #endif // PIDTEMP
  1857. /**
  1858. *
  1859. * "Control" > "Temperature" submenu
  1860. *
  1861. */
  1862. void lcd_control_temperature_menu() {
  1863. START_MENU();
  1864. //
  1865. // ^ Control
  1866. //
  1867. MENU_BACK(MSG_CONTROL);
  1868. //
  1869. // Nozzle:
  1870. // Nozzle [1-5]:
  1871. //
  1872. #if HOTENDS == 1
  1873. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1874. #else // HOTENDS > 1
  1875. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1876. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1877. #if HOTENDS > 2
  1878. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1879. #if HOTENDS > 3
  1880. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1881. #if HOTENDS > 4
  1882. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  1883. #endif // HOTENDS > 4
  1884. #endif // HOTENDS > 3
  1885. #endif // HOTENDS > 2
  1886. #endif // HOTENDS > 1
  1887. //
  1888. // Bed:
  1889. //
  1890. #if WATCH_THE_BED
  1891. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  1892. #endif
  1893. //
  1894. // Fan Speed:
  1895. //
  1896. #if FAN_COUNT > 0
  1897. #if HAS_FAN0
  1898. #if FAN_COUNT > 1
  1899. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1900. #else
  1901. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1902. #endif
  1903. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1904. #endif
  1905. #if HAS_FAN1
  1906. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1907. #endif
  1908. #if HAS_FAN2
  1909. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1910. #endif
  1911. #endif // FAN_COUNT > 0
  1912. //
  1913. // Autotemp, Min, Max, Fact
  1914. //
  1915. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  1916. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  1917. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  1918. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  1919. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  1920. #endif
  1921. //
  1922. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  1923. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  1924. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  1925. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  1926. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  1927. // PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
  1928. //
  1929. #if ENABLED(PIDTEMP)
  1930. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  1931. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  1932. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  1933. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  1934. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  1935. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  1936. #if ENABLED(PID_EXTRUSION_SCALING)
  1937. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  1938. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  1939. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  1940. #else
  1941. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  1942. #endif
  1943. #if ENABLED(PID_AUTOTUNE_MENU)
  1944. #define PID_MENU_ITEMS(ELABEL, eindex) \
  1945. _PID_MENU_ITEMS(ELABEL, eindex); \
  1946. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  1947. #else
  1948. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  1949. #endif
  1950. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  1951. PID_MENU_ITEMS(" " MSG_E1, 0);
  1952. PID_MENU_ITEMS(" " MSG_E2, 1);
  1953. #if HOTENDS > 2
  1954. PID_MENU_ITEMS(" " MSG_E3, 2);
  1955. #if HOTENDS > 3
  1956. PID_MENU_ITEMS(" " MSG_E4, 3);
  1957. #if HOTENDS > 4
  1958. PID_MENU_ITEMS(" " MSG_E5, 4);
  1959. #endif // HOTENDS > 4
  1960. #endif // HOTENDS > 3
  1961. #endif // HOTENDS > 2
  1962. #else // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1963. PID_MENU_ITEMS("", 0);
  1964. #endif // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1965. #endif //PIDTEMP
  1966. //
  1967. // Preheat Material 1 conf
  1968. //
  1969. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  1970. //
  1971. // Preheat Material 2 conf
  1972. //
  1973. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  1974. END_MENU();
  1975. }
  1976. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  1977. #if HOTENDS > 4
  1978. #define MINTEMP_ALL MIN5(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP)
  1979. #define MAXTEMP_ALL MAX5(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP)
  1980. #elif HOTENDS > 3
  1981. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  1982. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  1983. #elif HOTENDS > 2
  1984. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  1985. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  1986. #elif HOTENDS > 1
  1987. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  1988. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  1989. #else
  1990. #define MINTEMP_ALL HEATER_0_MINTEMP
  1991. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  1992. #endif
  1993. START_MENU();
  1994. MENU_BACK(MSG_TEMPERATURE);
  1995. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  1996. #if TEMP_SENSOR_0 != 0
  1997. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  1998. #endif
  1999. #if TEMP_SENSOR_BED != 0
  2000. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  2001. #endif
  2002. #if ENABLED(EEPROM_SETTINGS)
  2003. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2004. #endif
  2005. END_MENU();
  2006. }
  2007. /**
  2008. *
  2009. * "Temperature" > "Preheat Material 1 conf" submenu
  2010. *
  2011. */
  2012. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  2013. /**
  2014. *
  2015. * "Temperature" > "Preheat Material 2 conf" submenu
  2016. *
  2017. */
  2018. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  2019. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  2020. #if ENABLED(DISTINCT_E_FACTORS)
  2021. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  2022. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  2023. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  2024. #if E_STEPPERS > 2
  2025. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  2026. #if E_STEPPERS > 3
  2027. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  2028. #if E_STEPPERS > 4
  2029. void _reset_e4_acceleration_rate() { _reset_e_acceleration_rate(4); }
  2030. #endif // E_STEPPERS > 4
  2031. #endif // E_STEPPERS > 3
  2032. #endif // E_STEPPERS > 2
  2033. #endif
  2034. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  2035. #if ENABLED(DISTINCT_E_FACTORS)
  2036. void _planner_refresh_e_positioning(const uint8_t e) {
  2037. if (e == active_extruder)
  2038. _planner_refresh_positioning();
  2039. else
  2040. planner.steps_to_mm[e] = 1.0 / planner.axis_steps_per_mm[e];
  2041. }
  2042. void _planner_refresh_e0_positioning() { _reset_e_acceleration_rate(0); }
  2043. void _planner_refresh_e1_positioning() { _reset_e_acceleration_rate(1); }
  2044. #if E_STEPPERS > 2
  2045. void _planner_refresh_e2_positioning() { _reset_e_acceleration_rate(2); }
  2046. #if E_STEPPERS > 3
  2047. void _planner_refresh_e3_positioning() { _reset_e_acceleration_rate(3); }
  2048. #if E_STEPPERS > 4
  2049. void _planner_refresh_e4_positioning() { _reset_e_acceleration_rate(4); }
  2050. #endif // E_STEPPERS > 4
  2051. #endif // E_STEPPERS > 3
  2052. #endif // E_STEPPERS > 2
  2053. #endif
  2054. /**
  2055. *
  2056. * "Control" > "Motion" submenu
  2057. *
  2058. */
  2059. void lcd_control_motion_menu() {
  2060. START_MENU();
  2061. MENU_BACK(MSG_CONTROL);
  2062. #if HAS_BED_PROBE
  2063. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  2064. #endif
  2065. // Manual bed leveling, Bed Z:
  2066. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  2067. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  2068. #endif
  2069. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  2070. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  2071. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  2072. #if ENABLED(DELTA)
  2073. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  2074. #else
  2075. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  2076. #endif
  2077. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  2078. //
  2079. // M203 Settings
  2080. //
  2081. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  2082. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  2083. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  2084. #if ENABLED(DISTINCT_E_FACTORS)
  2085. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  2086. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2087. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  2088. #if E_STEPPERS > 2
  2089. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  2090. #if E_STEPPERS > 3
  2091. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  2092. #if E_STEPPERS > 4
  2093. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
  2094. #endif // E_STEPPERS > 4
  2095. #endif // E_STEPPERS > 3
  2096. #endif // E_STEPPERS > 2
  2097. #else
  2098. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2099. #endif
  2100. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  2101. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  2102. //
  2103. // M201 Settings
  2104. //
  2105. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  2106. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  2107. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  2108. #if ENABLED(DISTINCT_E_FACTORS)
  2109. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  2110. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  2111. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  2112. #if E_STEPPERS > 2
  2113. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  2114. #if E_STEPPERS > 3
  2115. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  2116. #if E_STEPPERS > 4
  2117. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
  2118. #endif // E_STEPPERS > 4
  2119. #endif // E_STEPPERS > 3
  2120. #endif // E_STEPPERS > 2
  2121. #else
  2122. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  2123. #endif
  2124. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  2125. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  2126. //
  2127. // M92 Settings
  2128. //
  2129. MENU_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  2130. MENU_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  2131. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  2132. #if ENABLED(DISTINCT_E_FACTORS)
  2133. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  2134. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  2135. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  2136. #if E_STEPPERS > 2
  2137. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  2138. #if E_STEPPERS > 3
  2139. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  2140. #if E_STEPPERS > 4
  2141. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E5STEPS, &planner.axis_steps_per_mm[E_AXIS + 4], 5, 9999, _planner_refresh_e4_positioning);
  2142. #endif // E_STEPPERS > 4
  2143. #endif // E_STEPPERS > 3
  2144. #endif // E_STEPPERS > 2
  2145. #else
  2146. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  2147. #endif
  2148. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  2149. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  2150. #endif
  2151. END_MENU();
  2152. }
  2153. /**
  2154. *
  2155. * "Control" > "Filament" submenu
  2156. *
  2157. */
  2158. void lcd_control_volumetric_menu() {
  2159. START_MENU();
  2160. MENU_BACK(MSG_CONTROL);
  2161. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  2162. if (volumetric_enabled) {
  2163. #if EXTRUDERS == 1
  2164. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2165. #else // EXTRUDERS > 1
  2166. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2167. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  2168. #if EXTRUDERS > 2
  2169. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  2170. #if EXTRUDERS > 3
  2171. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  2172. #if EXTRUDERS > 4
  2173. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
  2174. #endif // EXTRUDERS > 4
  2175. #endif // EXTRUDERS > 3
  2176. #endif // EXTRUDERS > 2
  2177. #endif // EXTRUDERS > 1
  2178. }
  2179. END_MENU();
  2180. }
  2181. /**
  2182. *
  2183. * "Control" > "Contrast" submenu
  2184. *
  2185. */
  2186. #if HAS_LCD_CONTRAST
  2187. void lcd_set_contrast() {
  2188. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2189. ENCODER_DIRECTION_NORMAL();
  2190. if (encoderPosition) {
  2191. set_lcd_contrast(lcd_contrast + encoderPosition);
  2192. encoderPosition = 0;
  2193. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2194. }
  2195. if (lcdDrawUpdate) {
  2196. lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
  2197. #if LCD_CONTRAST_MAX >= 100
  2198. itostr3(lcd_contrast)
  2199. #else
  2200. itostr2(lcd_contrast)
  2201. #endif
  2202. );
  2203. }
  2204. }
  2205. #endif // HAS_LCD_CONTRAST
  2206. /**
  2207. *
  2208. * "Control" > "Retract" submenu
  2209. *
  2210. */
  2211. #if ENABLED(FWRETRACT)
  2212. void lcd_control_retract_menu() {
  2213. START_MENU();
  2214. MENU_BACK(MSG_CONTROL);
  2215. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  2216. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  2217. #if EXTRUDERS > 1
  2218. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  2219. #endif
  2220. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  2221. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  2222. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
  2223. #if EXTRUDERS > 1
  2224. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, -100, 100);
  2225. #endif
  2226. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  2227. END_MENU();
  2228. }
  2229. #endif // FWRETRACT
  2230. #if ENABLED(SDSUPPORT)
  2231. #if !PIN_EXISTS(SD_DETECT)
  2232. void lcd_sd_refresh() {
  2233. card.initsd();
  2234. encoderTopLine = 0;
  2235. }
  2236. #endif
  2237. void lcd_sd_updir() {
  2238. card.updir();
  2239. encoderTopLine = 0;
  2240. screen_changed = true;
  2241. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2242. }
  2243. /**
  2244. *
  2245. * "Print from SD" submenu
  2246. *
  2247. */
  2248. void lcd_sdcard_menu() {
  2249. ENCODER_DIRECTION_MENUS();
  2250. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  2251. uint16_t fileCnt = card.getnrfilenames();
  2252. START_MENU();
  2253. MENU_BACK(MSG_MAIN);
  2254. card.getWorkDirName();
  2255. if (card.filename[0] == '/') {
  2256. #if !PIN_EXISTS(SD_DETECT)
  2257. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  2258. #endif
  2259. }
  2260. else {
  2261. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  2262. }
  2263. for (uint16_t i = 0; i < fileCnt; i++) {
  2264. if (_menuLineNr == _thisItemNr) {
  2265. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  2266. int nr = fileCnt - 1 - i;
  2267. #else
  2268. int nr = i;
  2269. #endif
  2270. #if ENABLED(SDCARD_SORT_ALPHA)
  2271. card.getfilename_sorted(nr);
  2272. #else
  2273. card.getfilename(nr);
  2274. #endif
  2275. if (card.filenameIsDir)
  2276. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2277. else
  2278. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2279. }
  2280. else {
  2281. MENU_ITEM_DUMMY();
  2282. }
  2283. }
  2284. END_MENU();
  2285. }
  2286. #endif //SDSUPPORT
  2287. #if ENABLED(LCD_INFO_MENU)
  2288. #if ENABLED(PRINTCOUNTER)
  2289. /**
  2290. *
  2291. * About Printer > Statistics submenu
  2292. *
  2293. */
  2294. void lcd_info_stats_menu() {
  2295. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2296. char buffer[21];
  2297. printStatistics stats = print_job_timer.getStats();
  2298. START_SCREEN(); // 12345678901234567890
  2299. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  2300. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  2301. duration_t elapsed = stats.printTime;
  2302. elapsed.toString(buffer);
  2303. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  2304. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2305. elapsed = stats.longestPrint;
  2306. elapsed.toString(buffer);
  2307. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  2308. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2309. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int(stats.filamentUsed / 100) % 10);
  2310. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  2311. STATIC_ITEM("", false, false, buffer); // 125m
  2312. END_SCREEN();
  2313. }
  2314. #endif // PRINTCOUNTER
  2315. /**
  2316. *
  2317. * About Printer > Thermistors
  2318. *
  2319. */
  2320. void lcd_info_thermistors_menu() {
  2321. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2322. START_SCREEN();
  2323. #define THERMISTOR_ID TEMP_SENSOR_0
  2324. #include "thermistornames.h"
  2325. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  2326. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  2327. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  2328. #if TEMP_SENSOR_1 != 0
  2329. #undef THERMISTOR_ID
  2330. #define THERMISTOR_ID TEMP_SENSOR_1
  2331. #include "thermistornames.h"
  2332. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  2333. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  2334. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  2335. #endif
  2336. #if TEMP_SENSOR_2 != 0
  2337. #undef THERMISTOR_ID
  2338. #define THERMISTOR_ID TEMP_SENSOR_2
  2339. #include "thermistornames.h"
  2340. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  2341. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  2342. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  2343. #endif
  2344. #if TEMP_SENSOR_3 != 0
  2345. #undef THERMISTOR_ID
  2346. #define THERMISTOR_ID TEMP_SENSOR_3
  2347. #include "thermistornames.h"
  2348. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  2349. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  2350. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  2351. #endif
  2352. #if TEMP_SENSOR_BED != 0
  2353. #undef THERMISTOR_ID
  2354. #define THERMISTOR_ID TEMP_SENSOR_BED
  2355. #include "thermistornames.h"
  2356. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  2357. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  2358. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  2359. #endif
  2360. END_SCREEN();
  2361. }
  2362. /**
  2363. *
  2364. * About Printer > Board Info
  2365. *
  2366. */
  2367. void lcd_info_board_menu() {
  2368. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2369. START_SCREEN();
  2370. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  2371. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  2372. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  2373. #if POWER_SUPPLY == 0
  2374. STATIC_ITEM(MSG_INFO_PSU ": Generic", true);
  2375. #elif POWER_SUPPLY == 1
  2376. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  2377. #elif POWER_SUPPLY == 2
  2378. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  2379. #endif
  2380. END_SCREEN();
  2381. }
  2382. /**
  2383. *
  2384. * About Printer > Printer Info
  2385. *
  2386. */
  2387. void lcd_info_printer_menu() {
  2388. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2389. START_SCREEN();
  2390. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  2391. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  2392. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  2393. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  2394. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  2395. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  2396. END_SCREEN();
  2397. }
  2398. /**
  2399. *
  2400. * "About Printer" submenu
  2401. *
  2402. */
  2403. void lcd_info_menu() {
  2404. START_MENU();
  2405. MENU_BACK(MSG_MAIN);
  2406. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  2407. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  2408. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  2409. #if ENABLED(PRINTCOUNTER)
  2410. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  2411. #endif
  2412. END_MENU();
  2413. }
  2414. #endif // LCD_INFO_MENU
  2415. /**
  2416. *
  2417. * Filament Change Feature Screens
  2418. *
  2419. */
  2420. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  2421. // Portions from STATIC_ITEM...
  2422. #define HOTEND_STATUS_ITEM() do { \
  2423. if (_menuLineNr == _thisItemNr) { \
  2424. if (lcdDrawUpdate) \
  2425. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  2426. lcd_implementation_hotend_status(_lcdLineNr); \
  2427. if (_skipStatic && encoderLine <= _thisItemNr) { \
  2428. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  2429. ++encoderLine; \
  2430. } \
  2431. else \
  2432. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING; \
  2433. } \
  2434. ++_thisItemNr; \
  2435. } while(0)
  2436. void lcd_filament_change_toocold_menu() {
  2437. START_MENU();
  2438. STATIC_ITEM(MSG_HEATING_FAILED_LCD, true, true);
  2439. STATIC_ITEM(MSG_FILAMENT_CHANGE_MINTEMP STRINGIFY(EXTRUDE_MINTEMP) ".", false, false);
  2440. MENU_BACK(MSG_BACK);
  2441. #if LCD_HEIGHT > 4
  2442. STATIC_ITEM(" ");
  2443. #endif
  2444. HOTEND_STATUS_ITEM();
  2445. END_MENU();
  2446. }
  2447. void lcd_filament_change_resume_print() {
  2448. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_RESUME_PRINT;
  2449. }
  2450. void lcd_filament_change_extrude_more() {
  2451. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_EXTRUDE_MORE;
  2452. }
  2453. void lcd_filament_change_option_menu() {
  2454. START_MENU();
  2455. #if LCD_HEIGHT > 2
  2456. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  2457. #endif
  2458. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_filament_change_resume_print);
  2459. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_filament_change_extrude_more);
  2460. END_MENU();
  2461. }
  2462. void lcd_filament_change_init_message() {
  2463. START_SCREEN();
  2464. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2465. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  2466. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  2467. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  2468. #define __FC_LINES_A 3
  2469. #else
  2470. #define __FC_LINES_A 2
  2471. #endif
  2472. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  2473. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  2474. #define _FC_LINES_A (__FC_LINES_A + 1)
  2475. #else
  2476. #define _FC_LINES_A __FC_LINES_A
  2477. #endif
  2478. #if LCD_HEIGHT > _FC_LINES_A + 1
  2479. STATIC_ITEM(" ");
  2480. #endif
  2481. HOTEND_STATUS_ITEM();
  2482. END_SCREEN();
  2483. }
  2484. void lcd_filament_change_unload_message() {
  2485. START_SCREEN();
  2486. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2487. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  2488. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  2489. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  2490. #define __FC_LINES_B 3
  2491. #else
  2492. #define __FC_LINES_B 2
  2493. #endif
  2494. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  2495. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  2496. #define _FC_LINES_B (__FC_LINES_B + 1)
  2497. #else
  2498. #define _FC_LINES_B __FC_LINES_B
  2499. #endif
  2500. #if LCD_HEIGHT > _FC_LINES_B + 1
  2501. STATIC_ITEM(" ");
  2502. #endif
  2503. HOTEND_STATUS_ITEM();
  2504. END_SCREEN();
  2505. }
  2506. void lcd_filament_change_wait_for_nozzles_to_heat() {
  2507. START_SCREEN();
  2508. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2509. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  2510. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  2511. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  2512. #define _FC_LINES_C 3
  2513. #else
  2514. #define _FC_LINES_C 2
  2515. #endif
  2516. #if LCD_HEIGHT > _FC_LINES_C + 1
  2517. STATIC_ITEM(" ");
  2518. #endif
  2519. HOTEND_STATUS_ITEM();
  2520. END_SCREEN();
  2521. }
  2522. void lcd_filament_change_heat_nozzle() {
  2523. START_SCREEN();
  2524. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2525. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  2526. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2527. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  2528. #define _FC_LINES_D 3
  2529. #else
  2530. #define _FC_LINES_D 2
  2531. #endif
  2532. #if LCD_HEIGHT > _FC_LINES_D + 1
  2533. STATIC_ITEM(" ");
  2534. #endif
  2535. HOTEND_STATUS_ITEM();
  2536. END_SCREEN();
  2537. }
  2538. void lcd_filament_change_insert_message() {
  2539. START_SCREEN();
  2540. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2541. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  2542. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2543. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  2544. #define __FC_LINES_E 3
  2545. #else
  2546. #define __FC_LINES_E 2
  2547. #endif
  2548. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  2549. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  2550. #define _FC_LINES_E (__FC_LINES_E + 1)
  2551. #else
  2552. #define _FC_LINES_E __FC_LINES_E
  2553. #endif
  2554. #if LCD_HEIGHT > _FC_LINES_E + 1
  2555. STATIC_ITEM(" ");
  2556. #endif
  2557. HOTEND_STATUS_ITEM();
  2558. END_SCREEN();
  2559. }
  2560. void lcd_filament_change_load_message() {
  2561. START_SCREEN();
  2562. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2563. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  2564. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  2565. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  2566. #define __FC_LINES_F 3
  2567. #else
  2568. #define __FC_LINES_F 2
  2569. #endif
  2570. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  2571. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  2572. #define _FC_LINES_F (__FC_LINES_F + 1)
  2573. #else
  2574. #define _FC_LINES_F __FC_LINES_F
  2575. #endif
  2576. #if LCD_HEIGHT > _FC_LINES_F + 1
  2577. STATIC_ITEM(" ");
  2578. #endif
  2579. HOTEND_STATUS_ITEM();
  2580. END_SCREEN();
  2581. }
  2582. void lcd_filament_change_extrude_message() {
  2583. START_SCREEN();
  2584. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2585. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  2586. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  2587. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  2588. #define __FC_LINES_G 3
  2589. #else
  2590. #define __FC_LINES_G 2
  2591. #endif
  2592. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  2593. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  2594. #define _FC_LINES_G (__FC_LINES_G + 1)
  2595. #else
  2596. #define _FC_LINES_G __FC_LINES_G
  2597. #endif
  2598. #if LCD_HEIGHT > _FC_LINES_G + 1
  2599. STATIC_ITEM(" ");
  2600. #endif
  2601. HOTEND_STATUS_ITEM();
  2602. END_SCREEN();
  2603. }
  2604. void lcd_filament_change_resume_message() {
  2605. START_SCREEN();
  2606. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2607. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  2608. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  2609. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  2610. #endif
  2611. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  2612. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  2613. #endif
  2614. END_SCREEN();
  2615. }
  2616. void lcd_filament_change_show_message(const FilamentChangeMessage message) {
  2617. switch (message) {
  2618. case FILAMENT_CHANGE_MESSAGE_INIT:
  2619. defer_return_to_status = true;
  2620. lcd_goto_screen(lcd_filament_change_init_message);
  2621. break;
  2622. case FILAMENT_CHANGE_MESSAGE_UNLOAD:
  2623. lcd_goto_screen(lcd_filament_change_unload_message);
  2624. break;
  2625. case FILAMENT_CHANGE_MESSAGE_INSERT:
  2626. lcd_goto_screen(lcd_filament_change_insert_message);
  2627. break;
  2628. case FILAMENT_CHANGE_MESSAGE_LOAD:
  2629. lcd_goto_screen(lcd_filament_change_load_message);
  2630. break;
  2631. case FILAMENT_CHANGE_MESSAGE_EXTRUDE:
  2632. lcd_goto_screen(lcd_filament_change_extrude_message);
  2633. break;
  2634. case FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE:
  2635. lcd_goto_screen(lcd_filament_change_heat_nozzle);
  2636. break;
  2637. case FILAMENT_CHANGE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT:
  2638. lcd_goto_screen(lcd_filament_change_wait_for_nozzles_to_heat);
  2639. break;
  2640. case FILAMENT_CHANGE_MESSAGE_OPTION:
  2641. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_WAIT_FOR;
  2642. lcd_goto_screen(lcd_filament_change_option_menu);
  2643. break;
  2644. case FILAMENT_CHANGE_MESSAGE_RESUME:
  2645. lcd_goto_screen(lcd_filament_change_resume_message);
  2646. break;
  2647. case FILAMENT_CHANGE_MESSAGE_STATUS:
  2648. lcd_return_to_status();
  2649. break;
  2650. }
  2651. }
  2652. #endif // FILAMENT_CHANGE_FEATURE
  2653. /**
  2654. *
  2655. * Functions for editing single values
  2656. *
  2657. * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
  2658. *
  2659. * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
  2660. *
  2661. * bool _menu_edit_int3();
  2662. * void menu_edit_int3(); // edit int (interactively)
  2663. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  2664. * void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  2665. * void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  2666. * 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
  2667. *
  2668. * You can then use one of the menu macros to present the edit interface:
  2669. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  2670. *
  2671. * This expands into a more primitive menu item:
  2672. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2673. *
  2674. *
  2675. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  2676. *
  2677. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2678. */
  2679. #define menu_edit_type(_type, _name, _strFunc, _scale) \
  2680. bool _menu_edit_ ## _name () { \
  2681. ENCODER_DIRECTION_NORMAL(); \
  2682. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  2683. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  2684. if (lcdDrawUpdate) \
  2685. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
  2686. if (lcd_clicked) { \
  2687. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
  2688. lcd_goto_previous_menu(); \
  2689. } \
  2690. return lcd_clicked; \
  2691. } \
  2692. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  2693. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  2694. void _menu_action_setting_edit_ ## _name (const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  2695. lcd_save_previous_screen(); \
  2696. \
  2697. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  2698. \
  2699. editLabel = pstr; \
  2700. editValue = ptr; \
  2701. minEditValue = minValue * _scale; \
  2702. maxEditValue = maxValue * _scale - minEditValue; \
  2703. encoderPosition = (*ptr) * _scale - minEditValue; \
  2704. } \
  2705. void menu_action_setting_edit_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  2706. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2707. currentScreen = menu_edit_ ## _name; \
  2708. }\
  2709. void menu_action_setting_edit_callback_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback) { \
  2710. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2711. currentScreen = menu_edit_callback_ ## _name; \
  2712. callbackFunc = callback; \
  2713. } \
  2714. typedef void _name
  2715. menu_edit_type(int, int3, itostr3, 1);
  2716. menu_edit_type(float, float3, ftostr3, 1.0);
  2717. menu_edit_type(float, float32, ftostr32, 100.0);
  2718. menu_edit_type(float, float43, ftostr43sign, 1000.0);
  2719. menu_edit_type(float, float5, ftostr5rj, 0.01);
  2720. menu_edit_type(float, float51, ftostr51sign, 10.0);
  2721. menu_edit_type(float, float52, ftostr52sign, 100.0);
  2722. menu_edit_type(float, float62, ftostr62rj, 100.0);
  2723. menu_edit_type(unsigned long, long5, ftostr5rj, 0.01);
  2724. /**
  2725. *
  2726. * Handlers for RepRap World Keypad input
  2727. *
  2728. */
  2729. #if ENABLED(REPRAPWORLD_KEYPAD)
  2730. void _reprapworld_keypad_move(AxisEnum axis, int dir) {
  2731. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2732. encoderPosition = dir;
  2733. switch (axis) {
  2734. case X_AXIS: lcd_move_x(); break;
  2735. case Y_AXIS: lcd_move_y(); break;
  2736. case Z_AXIS: lcd_move_z();
  2737. default: break;
  2738. }
  2739. }
  2740. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  2741. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  2742. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  2743. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  2744. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  2745. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  2746. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  2747. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  2748. inline void handle_reprapworld_keypad() {
  2749. static uint8_t keypad_debounce = 0;
  2750. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  2751. if (keypad_debounce > 0) keypad_debounce--;
  2752. }
  2753. else if (!keypad_debounce) {
  2754. keypad_debounce = 2;
  2755. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  2756. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  2757. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2758. #endif
  2759. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  2760. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  2761. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2762. #endif
  2763. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  2764. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  2765. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  2766. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  2767. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  2768. }
  2769. else {
  2770. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  2771. }
  2772. }
  2773. }
  2774. #endif // REPRAPWORLD_KEYPAD
  2775. /**
  2776. *
  2777. * Menu actions
  2778. *
  2779. */
  2780. void _menu_action_back() { lcd_goto_previous_menu(); }
  2781. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  2782. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  2783. void menu_action_function(screenFunc_t func) { (*func)(); }
  2784. #if ENABLED(SDSUPPORT)
  2785. void menu_action_sdfile(const char* filename, char* longFilename) {
  2786. UNUSED(longFilename);
  2787. card.openAndPrintFile(filename);
  2788. lcd_return_to_status();
  2789. }
  2790. void menu_action_sddirectory(const char* filename, char* longFilename) {
  2791. UNUSED(longFilename);
  2792. card.chdir(filename);
  2793. encoderPosition = 0;
  2794. screen_changed = true;
  2795. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2796. }
  2797. #endif //SDSUPPORT
  2798. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) {UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
  2799. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  2800. menu_action_setting_edit_bool(pstr, ptr);
  2801. (*callback)();
  2802. }
  2803. #endif // ULTIPANEL
  2804. void lcd_init() {
  2805. lcd_implementation_init(
  2806. #if ENABLED(LCD_PROGRESS_BAR)
  2807. true
  2808. #endif
  2809. );
  2810. #if ENABLED(NEWPANEL)
  2811. #if BUTTON_EXISTS(EN1)
  2812. SET_INPUT_PULLUP(BTN_EN1);
  2813. #endif
  2814. #if BUTTON_EXISTS(EN2)
  2815. SET_INPUT_PULLUP(BTN_EN2);
  2816. #endif
  2817. #if BUTTON_EXISTS(ENC)
  2818. SET_INPUT_PULLUP(BTN_ENC);
  2819. #endif
  2820. #if ENABLED(REPRAPWORLD_KEYPAD)
  2821. SET_OUTPUT(SHIFT_CLK);
  2822. OUT_WRITE(SHIFT_LD, HIGH);
  2823. SET_INPUT_PULLUP(SHIFT_OUT);
  2824. #endif
  2825. #if BUTTON_EXISTS(UP)
  2826. SET_INPUT(BTN_UP);
  2827. #endif
  2828. #if BUTTON_EXISTS(DWN)
  2829. SET_INPUT(BTN_DWN);
  2830. #endif
  2831. #if BUTTON_EXISTS(LFT)
  2832. SET_INPUT(BTN_LFT);
  2833. #endif
  2834. #if BUTTON_EXISTS(RT)
  2835. SET_INPUT(BTN_RT);
  2836. #endif
  2837. #else // !NEWPANEL
  2838. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  2839. SET_OUTPUT(SR_DATA_PIN);
  2840. SET_OUTPUT(SR_CLK_PIN);
  2841. #elif defined(SHIFT_CLK)
  2842. SET_OUTPUT(SHIFT_CLK);
  2843. OUT_WRITE(SHIFT_LD, HIGH);
  2844. OUT_WRITE(SHIFT_EN, LOW);
  2845. SET_INPUT_PULLUP(SHIFT_OUT);
  2846. #endif // SR_LCD_2W_NL
  2847. #endif // !NEWPANEL
  2848. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2849. SET_INPUT_PULLUP(SD_DETECT_PIN);
  2850. lcd_sd_status = 2; // UNKNOWN
  2851. #endif
  2852. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2853. slow_buttons = 0;
  2854. #endif
  2855. lcd_buttons_update();
  2856. #if ENABLED(ULTIPANEL)
  2857. encoderDiff = 0;
  2858. #endif
  2859. }
  2860. int lcd_strlen(const char* s) {
  2861. int i = 0, j = 0;
  2862. while (s[i]) {
  2863. #if ENABLED(MAPPER_NON)
  2864. j++;
  2865. #else
  2866. if ((s[i] & 0xC0u) != 0x80u) j++;
  2867. #endif
  2868. i++;
  2869. }
  2870. return j;
  2871. }
  2872. int lcd_strlen_P(const char* s) {
  2873. int j = 0;
  2874. while (pgm_read_byte(s)) {
  2875. #if ENABLED(MAPPER_NON)
  2876. j++;
  2877. #else
  2878. if ((pgm_read_byte(s) & 0xC0u) != 0x80u) j++;
  2879. #endif
  2880. s++;
  2881. }
  2882. return j;
  2883. }
  2884. bool lcd_blink() {
  2885. static uint8_t blink = 0;
  2886. static millis_t next_blink_ms = 0;
  2887. millis_t ms = millis();
  2888. if (ELAPSED(ms, next_blink_ms)) {
  2889. blink ^= 0xFF;
  2890. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  2891. }
  2892. return blink != 0;
  2893. }
  2894. /**
  2895. * Update the LCD, read encoder buttons, etc.
  2896. * - Read button states
  2897. * - Check the SD Card slot state
  2898. * - Act on RepRap World keypad input
  2899. * - Update the encoder position
  2900. * - Apply acceleration to the encoder position
  2901. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  2902. * - Reset the Info Screen timeout if there's any input
  2903. * - Update status indicators, if any
  2904. *
  2905. * Run the current LCD menu handler callback function:
  2906. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  2907. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  2908. * - Call the menu handler. Menu handlers should do the following:
  2909. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  2910. * (Encoder events automatically set lcdDrawUpdate for you.)
  2911. * - if (lcdDrawUpdate) { redraw }
  2912. * - Before exiting the handler set lcdDrawUpdate to:
  2913. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  2914. * - LCDVIEW_REDRAW_NOW or LCDVIEW_NONE to keep drawing, but only in this loop.
  2915. * - LCDVIEW_CALL_REDRAW_NEXT to keep drawing and draw on the next loop also.
  2916. * - LCDVIEW_CALL_NO_REDRAW to keep drawing (or start drawing) with no redraw on the next loop.
  2917. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  2918. * so don't change lcdDrawUpdate without considering this.
  2919. *
  2920. * After the menu handler callback runs (or not):
  2921. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  2922. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  2923. *
  2924. * No worries. This function is only called from the main thread.
  2925. */
  2926. void lcd_update() {
  2927. #if ENABLED(ULTIPANEL)
  2928. static millis_t return_to_status_ms = 0;
  2929. manage_manual_move();
  2930. lcd_buttons_update();
  2931. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2932. const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
  2933. #else
  2934. constexpr bool UBL_CONDITION = true;
  2935. #endif
  2936. // If the action button is pressed...
  2937. if (UBL_CONDITION && LCD_CLICKED) {
  2938. if (!wait_for_unclick) { // If not waiting for a debounce release:
  2939. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  2940. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  2941. wait_for_user = false; // Any click clears wait for user
  2942. lcd_quick_feedback(); // Always make a click sound
  2943. }
  2944. }
  2945. else wait_for_unclick = false;
  2946. #endif
  2947. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2948. bool sd_status = IS_SD_INSERTED;
  2949. if (sd_status != lcd_sd_status && lcd_detected()) {
  2950. if (sd_status) {
  2951. card.initsd();
  2952. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  2953. }
  2954. else {
  2955. card.release();
  2956. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  2957. }
  2958. lcd_sd_status = sd_status;
  2959. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2960. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  2961. #if ENABLED(LCD_PROGRESS_BAR)
  2962. currentScreen == lcd_status_screen
  2963. #endif
  2964. );
  2965. }
  2966. #endif //SDSUPPORT && SD_DETECT_PIN
  2967. millis_t ms = millis();
  2968. if (ELAPSED(ms, next_lcd_update_ms)
  2969. #if ENABLED(DOGLCD)
  2970. || drawing_screen
  2971. #endif
  2972. ) {
  2973. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  2974. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  2975. lcd_implementation_update_indicators();
  2976. #endif
  2977. #if ENABLED(ULTIPANEL)
  2978. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2979. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  2980. #endif
  2981. #if ENABLED(REPRAPWORLD_KEYPAD)
  2982. handle_reprapworld_keypad();
  2983. #endif
  2984. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  2985. if (encoderPastThreshold || lcd_clicked) {
  2986. if (encoderPastThreshold) {
  2987. int32_t encoderMultiplier = 1;
  2988. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  2989. if (encoderRateMultiplierEnabled) {
  2990. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  2991. if (lastEncoderMovementMillis != 0) {
  2992. // Note that the rate is always calculated between to passes through the
  2993. // loop and that the abs of the encoderDiff value is tracked.
  2994. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  2995. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  2996. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  2997. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  2998. SERIAL_ECHO_START;
  2999. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  3000. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  3001. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  3002. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  3003. SERIAL_EOL;
  3004. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  3005. }
  3006. lastEncoderMovementMillis = ms;
  3007. } // encoderRateMultiplierEnabled
  3008. #endif //ENCODER_RATE_MULTIPLIER
  3009. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  3010. encoderDiff = 0;
  3011. }
  3012. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3013. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  3014. }
  3015. #endif // ULTIPANEL
  3016. // We arrive here every ~100ms when idling often enough.
  3017. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  3018. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  3019. if (
  3020. #if ENABLED(ULTIPANEL)
  3021. currentScreen == lcd_status_screen &&
  3022. #endif
  3023. !lcd_status_update_delay--
  3024. ) {
  3025. lcd_status_update_delay = 9
  3026. #if ENABLED(DOGLCD)
  3027. + 3
  3028. #endif
  3029. ;
  3030. max_display_update_time--;
  3031. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3032. }
  3033. // then we want to use 1/2 of the time only.
  3034. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  3035. #if ENABLED(DOGLCD)
  3036. if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
  3037. #else
  3038. if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
  3039. #endif
  3040. {
  3041. #if ENABLED(DOGLCD)
  3042. if (!drawing_screen)
  3043. #endif
  3044. {
  3045. switch (lcdDrawUpdate) {
  3046. case LCDVIEW_CALL_NO_REDRAW:
  3047. lcdDrawUpdate = LCDVIEW_NONE;
  3048. break;
  3049. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  3050. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  3051. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3052. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  3053. case LCDVIEW_NONE:
  3054. break;
  3055. } // switch
  3056. }
  3057. #if ENABLED(ULTIPANEL)
  3058. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  3059. #else
  3060. #define CURRENTSCREEN() lcd_status_screen()
  3061. #endif
  3062. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  3063. if (!drawing_screen) {
  3064. u8g.firstPage();
  3065. drawing_screen = 1;
  3066. }
  3067. lcd_setFont(FONT_MENU);
  3068. u8g.setColorIndex(1);
  3069. CURRENTSCREEN();
  3070. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  3071. NOLESS(max_display_update_time, millis() - ms);
  3072. return;
  3073. }
  3074. #else
  3075. CURRENTSCREEN();
  3076. #endif
  3077. NOLESS(max_display_update_time, millis() - ms);
  3078. }
  3079. #if ENABLED(ULTIPANEL)
  3080. // Return to Status Screen after a timeout
  3081. if (currentScreen == lcd_status_screen || defer_return_to_status)
  3082. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3083. else if (ELAPSED(ms, return_to_status_ms))
  3084. lcd_return_to_status();
  3085. #endif // ULTIPANEL
  3086. #if ENABLED(DOGLCD)
  3087. if (!drawing_screen)
  3088. #endif
  3089. {
  3090. switch (lcdDrawUpdate) {
  3091. case LCDVIEW_CLEAR_CALL_REDRAW:
  3092. lcd_implementation_clear();
  3093. case LCDVIEW_CALL_REDRAW_NEXT:
  3094. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3095. break;
  3096. case LCDVIEW_REDRAW_NOW:
  3097. lcdDrawUpdate = LCDVIEW_NONE;
  3098. break;
  3099. case LCDVIEW_NONE:
  3100. break;
  3101. } // switch
  3102. }
  3103. } // ELAPSED(ms, next_lcd_update_ms)
  3104. }
  3105. void set_utf_strlen(char* s, uint8_t n) {
  3106. uint8_t i = 0, j = 0;
  3107. while (s[i] && (j < n)) {
  3108. #if ENABLED(MAPPER_NON)
  3109. j++;
  3110. #else
  3111. if ((s[i] & 0xC0u) != 0x80u) j++;
  3112. #endif
  3113. i++;
  3114. }
  3115. while (j++ < n) s[i++] = ' ';
  3116. s[i] = '\0';
  3117. }
  3118. void lcd_finishstatus(bool persist=false) {
  3119. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  3120. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  3121. UNUSED(persist);
  3122. #endif
  3123. #if ENABLED(LCD_PROGRESS_BAR)
  3124. progress_bar_ms = millis();
  3125. #if PROGRESS_MSG_EXPIRE > 0
  3126. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  3127. #endif
  3128. #endif
  3129. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3130. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  3131. previous_lcd_status_ms = millis(); //get status message to show up for a while
  3132. #endif
  3133. }
  3134. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  3135. void dontExpireStatus() { expire_status_ms = 0; }
  3136. #endif
  3137. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  3138. void lcd_setstatus(const char * const message, const bool persist) {
  3139. if (lcd_status_message_level > 0) return;
  3140. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  3141. lcd_finishstatus(persist);
  3142. }
  3143. void lcd_setstatuspgm(const char * const message, const uint8_t level) {
  3144. if (level < lcd_status_message_level) return;
  3145. lcd_status_message_level = level;
  3146. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  3147. lcd_finishstatus(level > 0);
  3148. }
  3149. void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
  3150. if (level < lcd_status_message_level) return;
  3151. lcd_status_message_level = level;
  3152. va_list args;
  3153. va_start(args, fmt);
  3154. vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args);
  3155. va_end(args);
  3156. lcd_finishstatus(level > 0);
  3157. }
  3158. void lcd_setalertstatuspgm(const char * const message) {
  3159. lcd_setstatuspgm(message, 1);
  3160. #if ENABLED(ULTIPANEL)
  3161. lcd_return_to_status();
  3162. #endif
  3163. }
  3164. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  3165. #if HAS_LCD_CONTRAST
  3166. void set_lcd_contrast(const int value) {
  3167. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  3168. u8g.setContrast(lcd_contrast);
  3169. }
  3170. #endif
  3171. #if ENABLED(ULTIPANEL)
  3172. /**
  3173. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  3174. * These values are independent of which pins are used for EN_A and EN_B indications
  3175. * The rotary encoder part is also independent to the chipset used for the LCD
  3176. */
  3177. #if defined(EN_A) && defined(EN_B)
  3178. #define encrot0 0
  3179. #define encrot1 2
  3180. #define encrot2 3
  3181. #define encrot3 1
  3182. #endif
  3183. #define GET_BUTTON_STATES(DST) \
  3184. uint8_t new_##DST = 0; \
  3185. WRITE(SHIFT_LD, LOW); \
  3186. WRITE(SHIFT_LD, HIGH); \
  3187. for (int8_t i = 0; i < 8; i++) { \
  3188. new_##DST >>= 1; \
  3189. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  3190. WRITE(SHIFT_CLK, HIGH); \
  3191. WRITE(SHIFT_CLK, LOW); \
  3192. } \
  3193. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  3194. /**
  3195. * Read encoder buttons from the hardware registers
  3196. * Warning: This function is called from interrupt context!
  3197. */
  3198. void lcd_buttons_update() {
  3199. millis_t now = millis();
  3200. if (ELAPSED(now, next_button_update_ms)) {
  3201. #if ENABLED(NEWPANEL)
  3202. uint8_t newbutton = 0;
  3203. #if BUTTON_EXISTS(EN1)
  3204. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  3205. #endif
  3206. #if BUTTON_EXISTS(EN2)
  3207. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  3208. #endif
  3209. #if BUTTON_EXISTS(ENC)
  3210. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  3211. #endif
  3212. #if LCD_HAS_DIRECTIONAL_BUTTONS
  3213. // Manage directional buttons
  3214. #if ENABLED(REVERSE_MENU_DIRECTION)
  3215. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  3216. #else
  3217. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  3218. #endif
  3219. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  3220. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  3221. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  3222. #else
  3223. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  3224. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  3225. #endif
  3226. if (false) {
  3227. // for the else-ifs below
  3228. }
  3229. #if BUTTON_EXISTS(UP)
  3230. else if (BUTTON_PRESSED(UP)) {
  3231. encoderDiff = -(ENCODER_UD_STEPS);
  3232. next_button_update_ms = now + 300;
  3233. }
  3234. #endif
  3235. #if BUTTON_EXISTS(DWN)
  3236. else if (BUTTON_PRESSED(DWN)) {
  3237. encoderDiff = ENCODER_UD_STEPS;
  3238. next_button_update_ms = now + 300;
  3239. }
  3240. #endif
  3241. #if BUTTON_EXISTS(LFT)
  3242. else if (BUTTON_PRESSED(LFT)) {
  3243. encoderDiff = -(ENCODER_LR_PULSES);
  3244. next_button_update_ms = now + 300;
  3245. }
  3246. #endif
  3247. #if BUTTON_EXISTS(RT)
  3248. else if (BUTTON_PRESSED(RT)) {
  3249. encoderDiff = ENCODER_LR_PULSES;
  3250. next_button_update_ms = now + 300;
  3251. }
  3252. #endif
  3253. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  3254. buttons = newbutton;
  3255. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3256. buttons |= slow_buttons;
  3257. #endif
  3258. #if ENABLED(REPRAPWORLD_KEYPAD)
  3259. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  3260. #endif
  3261. #else
  3262. GET_BUTTON_STATES(buttons);
  3263. #endif //!NEWPANEL
  3264. } // next_button_update_ms
  3265. // Manage encoder rotation
  3266. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  3267. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  3268. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  3269. #elif ENABLED(REVERSE_MENU_DIRECTION)
  3270. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  3271. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  3272. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  3273. #define ENCODER_DIFF_CW (encoderDiff--)
  3274. #define ENCODER_DIFF_CCW (encoderDiff++)
  3275. #else
  3276. #define ENCODER_DIFF_CW (encoderDiff++)
  3277. #define ENCODER_DIFF_CCW (encoderDiff--)
  3278. #endif
  3279. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  3280. uint8_t enc = 0;
  3281. if (buttons & EN_A) enc |= B01;
  3282. if (buttons & EN_B) enc |= B10;
  3283. if (enc != lastEncoderBits) {
  3284. switch (enc) {
  3285. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  3286. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  3287. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  3288. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  3289. }
  3290. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3291. if (ubl.has_control_of_lcd_panel) {
  3292. ubl.encoder_diff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
  3293. encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
  3294. // wheel has not turned.
  3295. }
  3296. #endif
  3297. lastEncoderBits = enc;
  3298. }
  3299. }
  3300. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  3301. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  3302. #else
  3303. bool lcd_detected() { return true; }
  3304. #endif
  3305. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3306. void chirp_at_user() {
  3307. #if ENABLED(LCD_USE_I2C_BUZZER)
  3308. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  3309. #elif PIN_EXISTS(BEEPER)
  3310. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  3311. #endif
  3312. }
  3313. bool ubl_lcd_clicked() { return LCD_CLICKED; }
  3314. #endif
  3315. #endif // ULTIPANEL
  3316. #endif // ULTRA_LCD