My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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