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

ultralcd.cpp 130KB

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