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

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