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

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