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

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