My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ultralcd.cpp 115KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462
  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. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
  1198. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_material1_menu);
  1199. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_material2_menu);
  1200. #else
  1201. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_material1_hotend0);
  1202. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_material2_hotend0);
  1203. #endif
  1204. //
  1205. // Change filament
  1206. //
  1207. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  1208. if (!thermalManager.tooColdToExtrude(active_extruder))
  1209. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  1210. #endif
  1211. #endif // TEMP_SENSOR_0 != 0
  1212. //
  1213. // Cooldown
  1214. //
  1215. bool has_heat = false;
  1216. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  1217. #if HAS_TEMP_BED
  1218. if (thermalManager.target_temperature_bed) has_heat = true;
  1219. #endif
  1220. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  1221. //
  1222. // BLTouch Self-Test and Reset
  1223. //
  1224. #if ENABLED(BLTOUCH)
  1225. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  1226. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  1227. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  1228. #endif
  1229. //
  1230. // Switch power on/off
  1231. //
  1232. #if HAS_POWER_SWITCH
  1233. if (powersupply)
  1234. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  1235. else
  1236. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  1237. #endif
  1238. //
  1239. // Autostart
  1240. //
  1241. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1242. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  1243. #endif
  1244. END_MENU();
  1245. }
  1246. float move_menu_scale;
  1247. #if ENABLED(DELTA_CALIBRATION_MENU)
  1248. void lcd_move_z();
  1249. void lcd_delta_calibrate_menu();
  1250. void _lcd_calibrate_homing() {
  1251. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  1252. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1253. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1254. lcd_goto_previous_menu();
  1255. }
  1256. void _lcd_delta_calibrate_home() {
  1257. enqueue_and_echo_commands_P(PSTR("G28"));
  1258. lcd_goto_screen(_lcd_calibrate_homing);
  1259. }
  1260. // Move directly to the tower position with uninterpolated moves
  1261. // If we used interpolated moves it would cause this to become re-entrant
  1262. void _goto_tower_pos(const float &a) {
  1263. if (no_reentrance) return;
  1264. current_position[Z_AXIS] = max(Z_HOMING_HEIGHT, Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5;
  1265. line_to_current(Z_AXIS);
  1266. current_position[X_AXIS] = a < 0 ? X_HOME_POS : sin(a) * -(DELTA_PRINTABLE_RADIUS);
  1267. current_position[Y_AXIS] = a < 0 ? Y_HOME_POS : cos(a) * (DELTA_PRINTABLE_RADIUS);
  1268. line_to_current(Z_AXIS);
  1269. current_position[Z_AXIS] = 4.0;
  1270. line_to_current(Z_AXIS);
  1271. lcd_synchronize();
  1272. move_menu_scale = 0.1;
  1273. lcd_goto_screen(lcd_move_z);
  1274. }
  1275. void _goto_tower_x() { _goto_tower_pos(RADIANS(120)); }
  1276. void _goto_tower_y() { _goto_tower_pos(RADIANS(240)); }
  1277. void _goto_tower_z() { _goto_tower_pos(0); }
  1278. void _goto_center() { _goto_tower_pos(-1); }
  1279. void lcd_delta_calibrate_menu() {
  1280. START_MENU();
  1281. MENU_BACK(MSG_MAIN);
  1282. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  1283. if (axis_homed[Z_AXIS]) {
  1284. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  1285. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  1286. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  1287. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  1288. }
  1289. END_MENU();
  1290. }
  1291. #endif // DELTA_CALIBRATION_MENU
  1292. /**
  1293. * If the most recent manual move hasn't been fed to the planner yet,
  1294. * and the planner can accept one, send immediately
  1295. */
  1296. inline void manage_manual_move() {
  1297. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  1298. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  1299. manual_move_axis = (int8_t)NO_AXIS;
  1300. }
  1301. }
  1302. /**
  1303. * Set a flag that lcd_update() should start a move
  1304. * to "current_position" after a short delay.
  1305. */
  1306. inline void manual_move_to_current(AxisEnum axis
  1307. #if E_MANUAL > 1
  1308. , int8_t eindex=-1
  1309. #endif
  1310. ) {
  1311. #if E_MANUAL > 1
  1312. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  1313. #endif
  1314. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  1315. manual_move_axis = (int8_t)axis;
  1316. }
  1317. /**
  1318. *
  1319. * "Prepare" > "Move Axis" submenu
  1320. *
  1321. */
  1322. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  1323. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1324. ENCODER_DIRECTION_NORMAL();
  1325. if (encoderPosition) {
  1326. refresh_cmd_timeout();
  1327. // Limit to software endstops, if enabled
  1328. float min = (soft_endstops_enabled && min_software_endstops) ? soft_endstop_min[axis] : current_position[axis] - 1000,
  1329. max = (soft_endstops_enabled && max_software_endstops) ? soft_endstop_max[axis] : current_position[axis] + 1000;
  1330. // Get the new position
  1331. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  1332. // Delta limits XY based on the current offset from center
  1333. // This assumes the center is 0,0
  1334. #if ENABLED(DELTA)
  1335. if (axis != Z_AXIS) {
  1336. max = sqrt(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
  1337. min = -max;
  1338. }
  1339. #endif
  1340. // Limit only when trying to move towards the limit
  1341. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  1342. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  1343. manual_move_to_current(axis);
  1344. encoderPosition = 0;
  1345. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1346. }
  1347. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
  1348. }
  1349. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  1350. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  1351. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  1352. void _lcd_move_e(
  1353. #if E_MANUAL > 1
  1354. int8_t eindex=-1
  1355. #endif
  1356. ) {
  1357. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1358. ENCODER_DIRECTION_NORMAL();
  1359. if (encoderPosition) {
  1360. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  1361. encoderPosition = 0;
  1362. manual_move_to_current(E_AXIS
  1363. #if E_MANUAL > 1
  1364. , eindex
  1365. #endif
  1366. );
  1367. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1368. }
  1369. if (lcdDrawUpdate) {
  1370. PGM_P pos_label;
  1371. #if E_MANUAL == 1
  1372. pos_label = PSTR(MSG_MOVE_E);
  1373. #else
  1374. switch (eindex) {
  1375. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  1376. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  1377. #if E_MANUAL > 2
  1378. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  1379. #if E_MANUAL > 3
  1380. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  1381. #endif
  1382. #endif
  1383. }
  1384. #endif
  1385. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  1386. }
  1387. }
  1388. void lcd_move_e() { _lcd_move_e(); }
  1389. #if E_MANUAL > 1
  1390. void lcd_move_e0() { _lcd_move_e(0); }
  1391. void lcd_move_e1() { _lcd_move_e(1); }
  1392. #if E_MANUAL > 2
  1393. void lcd_move_e2() { _lcd_move_e(2); }
  1394. #if E_MANUAL > 3
  1395. void lcd_move_e3() { _lcd_move_e(3); }
  1396. #endif
  1397. #endif
  1398. #endif
  1399. /**
  1400. *
  1401. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  1402. *
  1403. */
  1404. screenFunc_t _manual_move_func_ptr;
  1405. void lcd_move_menu_10mm() { move_menu_scale = 10.0; lcd_goto_screen(_manual_move_func_ptr); }
  1406. void lcd_move_menu_1mm() { move_menu_scale = 1.0; lcd_goto_screen(_manual_move_func_ptr); }
  1407. void lcd_move_menu_01mm() { move_menu_scale = 0.1; lcd_goto_screen(_manual_move_func_ptr); }
  1408. void _lcd_move_distance_menu(AxisEnum axis, screenFunc_t func) {
  1409. _manual_move_func_ptr = func;
  1410. START_MENU();
  1411. if (LCD_HEIGHT >= 4) {
  1412. switch(axis) {
  1413. case X_AXIS:
  1414. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  1415. case Y_AXIS:
  1416. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  1417. case Z_AXIS:
  1418. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  1419. default:
  1420. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  1421. }
  1422. }
  1423. MENU_BACK(MSG_MOVE_AXIS);
  1424. if (axis == X_AXIS || axis == Y_AXIS)
  1425. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  1426. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  1427. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  1428. END_MENU();
  1429. }
  1430. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  1431. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  1432. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  1433. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  1434. #if E_MANUAL > 1
  1435. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  1436. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  1437. #if E_MANUAL > 2
  1438. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  1439. #if E_MANUAL > 3
  1440. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  1441. #endif
  1442. #endif
  1443. #endif
  1444. /**
  1445. *
  1446. * "Prepare" > "Move Axis" submenu
  1447. *
  1448. */
  1449. #if IS_KINEMATIC
  1450. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1451. #if ENABLED(DELTA)
  1452. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  1453. void lcd_lower_z_to_clip_height() {
  1454. if (!no_reentrance) {
  1455. current_position[Z_AXIS] = delta_clip_start_height;
  1456. line_to_current(Z_AXIS);
  1457. lcd_synchronize();
  1458. }
  1459. }
  1460. #else
  1461. #define _MOVE_XY_ALLOWED true
  1462. #endif
  1463. #else
  1464. #define _MOVE_XYZ_ALLOWED true
  1465. #define _MOVE_XY_ALLOWED true
  1466. #endif
  1467. void lcd_move_menu() {
  1468. START_MENU();
  1469. MENU_BACK(MSG_PREPARE);
  1470. if (_MOVE_XYZ_ALLOWED) {
  1471. if (_MOVE_XY_ALLOWED) {
  1472. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  1473. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  1474. }
  1475. #if ENABLED(DELTA)
  1476. else
  1477. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  1478. #endif
  1479. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  1480. }
  1481. else
  1482. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1483. #if ENABLED(SWITCHING_EXTRUDER)
  1484. if (active_extruder)
  1485. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  1486. else
  1487. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  1488. #endif
  1489. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  1490. #if E_MANUAL > 1
  1491. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  1492. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  1493. #if E_MANUAL > 2
  1494. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  1495. #if E_MANUAL > 3
  1496. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  1497. #endif
  1498. #endif
  1499. #endif
  1500. END_MENU();
  1501. }
  1502. /**
  1503. *
  1504. * "Control" submenu
  1505. *
  1506. */
  1507. void lcd_control_menu() {
  1508. START_MENU();
  1509. MENU_BACK(MSG_MAIN);
  1510. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1511. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  1512. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  1513. #if HAS_LCD_CONTRAST
  1514. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  1515. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  1516. #endif
  1517. #if ENABLED(FWRETRACT)
  1518. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  1519. #endif
  1520. #if ENABLED(DAC_STEPPER_CURRENT)
  1521. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  1522. #endif
  1523. #if ENABLED(EEPROM_SETTINGS)
  1524. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1525. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  1526. #endif
  1527. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  1528. END_MENU();
  1529. }
  1530. /**
  1531. *
  1532. * "Temperature" submenu
  1533. *
  1534. */
  1535. #if ENABLED(PID_AUTOTUNE_MENU)
  1536. #if ENABLED(PIDTEMP)
  1537. int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  1538. #endif
  1539. #if ENABLED(PIDTEMPBED)
  1540. int autotune_temp_bed = 70;
  1541. #endif
  1542. void _lcd_autotune(int e) {
  1543. char cmd[30];
  1544. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  1545. #if HAS_PID_FOR_BOTH
  1546. e < 0 ? autotune_temp_bed : autotune_temp[e]
  1547. #elif ENABLED(PIDTEMPBED)
  1548. autotune_temp_bed
  1549. #else
  1550. autotune_temp[e]
  1551. #endif
  1552. );
  1553. enqueue_and_echo_command(cmd);
  1554. }
  1555. #endif //PID_AUTOTUNE_MENU
  1556. #if ENABLED(PIDTEMP)
  1557. // Helpers for editing PID Ki & Kd values
  1558. // grab the PID value out of the temp variable; scale it; then update the PID driver
  1559. void copy_and_scalePID_i(int e) {
  1560. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1561. UNUSED(e);
  1562. #endif
  1563. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  1564. thermalManager.updatePID();
  1565. }
  1566. void copy_and_scalePID_d(int e) {
  1567. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1568. UNUSED(e);
  1569. #endif
  1570. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  1571. thermalManager.updatePID();
  1572. }
  1573. #define _PIDTEMP_BASE_FUNCTIONS(eindex) \
  1574. void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
  1575. void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); }
  1576. #if ENABLED(PID_AUTOTUNE_MENU)
  1577. #define _PIDTEMP_FUNCTIONS(eindex) \
  1578. _PIDTEMP_BASE_FUNCTIONS(eindex); \
  1579. void lcd_autotune_callback_E ## eindex() { _lcd_autotune(eindex); }
  1580. #else
  1581. #define _PIDTEMP_FUNCTIONS(eindex) _PIDTEMP_BASE_FUNCTIONS(eindex)
  1582. #endif
  1583. _PIDTEMP_FUNCTIONS(0)
  1584. #if ENABLED(PID_PARAMS_PER_HOTEND)
  1585. #if HOTENDS > 1
  1586. _PIDTEMP_FUNCTIONS(1)
  1587. #if HOTENDS > 2
  1588. _PIDTEMP_FUNCTIONS(2)
  1589. #if HOTENDS > 3
  1590. _PIDTEMP_FUNCTIONS(3)
  1591. #endif //HOTENDS > 3
  1592. #endif //HOTENDS > 2
  1593. #endif //HOTENDS > 1
  1594. #endif //PID_PARAMS_PER_HOTEND
  1595. #endif //PIDTEMP
  1596. /**
  1597. *
  1598. * "Control" > "Temperature" submenu
  1599. *
  1600. */
  1601. void lcd_control_temperature_menu() {
  1602. START_MENU();
  1603. //
  1604. // ^ Control
  1605. //
  1606. MENU_BACK(MSG_CONTROL);
  1607. //
  1608. // Nozzle:
  1609. // Nozzle [1-4]:
  1610. //
  1611. #if HOTENDS == 1
  1612. #if TEMP_SENSOR_0 != 0
  1613. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1614. #endif
  1615. #else //HOTENDS > 1
  1616. #if TEMP_SENSOR_0 != 0
  1617. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1618. #endif
  1619. #if TEMP_SENSOR_1 != 0
  1620. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1621. #endif
  1622. #if HOTENDS > 2
  1623. #if TEMP_SENSOR_2 != 0
  1624. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1625. #endif
  1626. #if HOTENDS > 3
  1627. #if TEMP_SENSOR_3 != 0
  1628. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1629. #endif
  1630. #endif // HOTENDS > 3
  1631. #endif // HOTENDS > 2
  1632. #endif // HOTENDS > 1
  1633. //
  1634. // Bed:
  1635. //
  1636. #if TEMP_SENSOR_BED != 0
  1637. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  1638. #endif
  1639. //
  1640. // Fan Speed:
  1641. //
  1642. #if FAN_COUNT > 0
  1643. #if HAS_FAN0
  1644. #if FAN_COUNT > 1
  1645. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1646. #else
  1647. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1648. #endif
  1649. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1650. #endif
  1651. #if HAS_FAN1
  1652. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1653. #endif
  1654. #if HAS_FAN2
  1655. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1656. #endif
  1657. #endif // FAN_COUNT > 0
  1658. //
  1659. // Autotemp, Min, Max, Fact
  1660. //
  1661. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  1662. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  1663. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  1664. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  1665. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  1666. #endif
  1667. //
  1668. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  1669. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  1670. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  1671. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  1672. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  1673. //
  1674. #if ENABLED(PIDTEMP)
  1675. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  1676. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  1677. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  1678. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  1679. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  1680. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  1681. #if ENABLED(PID_EXTRUSION_SCALING)
  1682. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  1683. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  1684. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  1685. #else
  1686. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  1687. #endif
  1688. #if ENABLED(PID_AUTOTUNE_MENU)
  1689. #define PID_MENU_ITEMS(ELABEL, eindex) \
  1690. _PID_MENU_ITEMS(ELABEL, eindex); \
  1691. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  1692. #else
  1693. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  1694. #endif
  1695. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  1696. PID_MENU_ITEMS(" " MSG_E1, 0);
  1697. PID_MENU_ITEMS(" " MSG_E2, 1);
  1698. #if HOTENDS > 2
  1699. PID_MENU_ITEMS(" " MSG_E3, 2);
  1700. #if HOTENDS > 3
  1701. PID_MENU_ITEMS(" " MSG_E4, 3);
  1702. #endif //HOTENDS > 3
  1703. #endif //HOTENDS > 2
  1704. #else //!PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1705. PID_MENU_ITEMS("", 0);
  1706. #endif //!PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1707. #endif //PIDTEMP
  1708. //
  1709. // Preheat Material 1 conf
  1710. //
  1711. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  1712. //
  1713. // Preheat Material 2 conf
  1714. //
  1715. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  1716. END_MENU();
  1717. }
  1718. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  1719. #if HOTENDS > 3
  1720. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  1721. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  1722. #elif HOTENDS > 2
  1723. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  1724. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  1725. #elif HOTENDS > 1
  1726. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  1727. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  1728. #else
  1729. #define MINTEMP_ALL HEATER_0_MINTEMP
  1730. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  1731. #endif
  1732. START_MENU();
  1733. MENU_BACK(MSG_TEMPERATURE);
  1734. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  1735. #if TEMP_SENSOR_0 != 0
  1736. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  1737. #endif
  1738. #if TEMP_SENSOR_BED != 0
  1739. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  1740. #endif
  1741. #if ENABLED(EEPROM_SETTINGS)
  1742. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1743. #endif
  1744. END_MENU();
  1745. }
  1746. /**
  1747. *
  1748. * "Temperature" > "Preheat Material 1 conf" submenu
  1749. *
  1750. */
  1751. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  1752. /**
  1753. *
  1754. * "Temperature" > "Preheat Material 2 conf" submenu
  1755. *
  1756. */
  1757. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  1758. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  1759. #if ENABLED(DISTINCT_E_FACTORS)
  1760. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  1761. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  1762. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  1763. #if E_STEPPERS > 2
  1764. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  1765. #if E_STEPPERS > 3
  1766. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  1767. #endif
  1768. #endif
  1769. #endif
  1770. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  1771. #if ENABLED(DISTINCT_E_FACTORS)
  1772. void _planner_refresh_e_positioning(const uint8_t e) {
  1773. if (e == active_extruder)
  1774. _planner_refresh_positioning();
  1775. else
  1776. planner.steps_to_mm[e] = 1.0 / planner.axis_steps_per_mm[e];
  1777. }
  1778. void _planner_refresh_e0_positioning() { _reset_e_acceleration_rate(0); }
  1779. void _planner_refresh_e1_positioning() { _reset_e_acceleration_rate(1); }
  1780. #if E_STEPPERS > 2
  1781. void _planner_refresh_e2_positioning() { _reset_e_acceleration_rate(2); }
  1782. #if E_STEPPERS > 3
  1783. void _planner_refresh_e3_positioning() { _reset_e_acceleration_rate(3); }
  1784. #endif
  1785. #endif
  1786. #endif
  1787. /**
  1788. *
  1789. * "Control" > "Motion" submenu
  1790. *
  1791. */
  1792. void lcd_control_motion_menu() {
  1793. START_MENU();
  1794. MENU_BACK(MSG_CONTROL);
  1795. #if HAS_BED_PROBE
  1796. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  1797. #endif
  1798. // Manual bed leveling, Bed Z:
  1799. #if ENABLED(MANUAL_BED_LEVELING)
  1800. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  1801. #endif
  1802. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  1803. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  1804. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  1805. #if ENABLED(DELTA)
  1806. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  1807. #else
  1808. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  1809. #endif
  1810. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  1811. //
  1812. // M203 Settings
  1813. //
  1814. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  1815. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  1816. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  1817. #if ENABLED(DISTINCT_E_FACTORS)
  1818. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  1819. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  1820. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  1821. #if E_STEPPERS > 2
  1822. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  1823. #if E_STEPPERS > 3
  1824. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  1825. #endif
  1826. #endif
  1827. #else
  1828. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  1829. #endif
  1830. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  1831. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  1832. //
  1833. // M201 Settings
  1834. //
  1835. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  1836. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  1837. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  1838. #if ENABLED(DISTINCT_E_FACTORS)
  1839. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  1840. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  1841. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  1842. #if E_STEPPERS > 2
  1843. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  1844. #if E_STEPPERS > 3
  1845. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  1846. #endif
  1847. #endif
  1848. #else
  1849. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  1850. #endif
  1851. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  1852. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  1853. //
  1854. // M92 Settings
  1855. //
  1856. MENU_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  1857. MENU_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  1858. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  1859. #if ENABLED(DISTINCT_E_FACTORS)
  1860. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  1861. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  1862. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  1863. #if E_STEPPERS > 2
  1864. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  1865. #if E_STEPPERS > 3
  1866. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  1867. #endif
  1868. #endif
  1869. #else
  1870. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  1871. #endif
  1872. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  1873. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  1874. #endif
  1875. END_MENU();
  1876. }
  1877. /**
  1878. *
  1879. * "Control" > "Filament" submenu
  1880. *
  1881. */
  1882. void lcd_control_volumetric_menu() {
  1883. START_MENU();
  1884. MENU_BACK(MSG_CONTROL);
  1885. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  1886. if (volumetric_enabled) {
  1887. #if EXTRUDERS == 1
  1888. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1889. #else //EXTRUDERS > 1
  1890. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1891. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  1892. #if EXTRUDERS > 2
  1893. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  1894. #if EXTRUDERS > 3
  1895. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  1896. #endif //EXTRUDERS > 3
  1897. #endif //EXTRUDERS > 2
  1898. #endif //EXTRUDERS > 1
  1899. }
  1900. END_MENU();
  1901. }
  1902. /**
  1903. *
  1904. * "Control" > "Contrast" submenu
  1905. *
  1906. */
  1907. #if HAS_LCD_CONTRAST
  1908. void lcd_set_contrast() {
  1909. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1910. ENCODER_DIRECTION_NORMAL();
  1911. if (encoderPosition) {
  1912. set_lcd_contrast(lcd_contrast + encoderPosition);
  1913. encoderPosition = 0;
  1914. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1915. }
  1916. if (lcdDrawUpdate) {
  1917. lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
  1918. #if LCD_CONTRAST_MAX >= 100
  1919. itostr3(lcd_contrast)
  1920. #else
  1921. itostr2(lcd_contrast)
  1922. #endif
  1923. );
  1924. }
  1925. }
  1926. #endif // HAS_LCD_CONTRAST
  1927. /**
  1928. *
  1929. * "Control" > "Retract" submenu
  1930. *
  1931. */
  1932. #if ENABLED(FWRETRACT)
  1933. void lcd_control_retract_menu() {
  1934. START_MENU();
  1935. MENU_BACK(MSG_CONTROL);
  1936. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  1937. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  1938. #if EXTRUDERS > 1
  1939. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  1940. #endif
  1941. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  1942. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  1943. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
  1944. #if EXTRUDERS > 1
  1945. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, -100, 100);
  1946. #endif
  1947. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  1948. END_MENU();
  1949. }
  1950. #endif // FWRETRACT
  1951. #if ENABLED(SDSUPPORT)
  1952. #if !PIN_EXISTS(SD_DETECT)
  1953. void lcd_sd_refresh() {
  1954. card.initsd();
  1955. encoderTopLine = 0;
  1956. }
  1957. #endif
  1958. void lcd_sd_updir() {
  1959. card.updir();
  1960. encoderTopLine = 0;
  1961. screen_changed = true;
  1962. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  1963. }
  1964. /**
  1965. *
  1966. * "Print from SD" submenu
  1967. *
  1968. */
  1969. void lcd_sdcard_menu() {
  1970. ENCODER_DIRECTION_MENUS();
  1971. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  1972. uint16_t fileCnt = card.getnrfilenames();
  1973. START_MENU();
  1974. MENU_BACK(MSG_MAIN);
  1975. card.getWorkDirName();
  1976. if (card.filename[0] == '/') {
  1977. #if !PIN_EXISTS(SD_DETECT)
  1978. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1979. #endif
  1980. }
  1981. else {
  1982. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1983. }
  1984. for (uint16_t i = 0; i < fileCnt; i++) {
  1985. if (_menuLineNr == _thisItemNr) {
  1986. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  1987. int nr = fileCnt - 1 - i;
  1988. #else
  1989. int nr = i;
  1990. #endif
  1991. #if ENABLED(SDCARD_SORT_ALPHA)
  1992. card.getfilename_sorted(nr);
  1993. #else
  1994. card.getfilename(nr);
  1995. #endif
  1996. if (card.filenameIsDir)
  1997. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1998. else
  1999. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2000. }
  2001. else {
  2002. MENU_ITEM_DUMMY();
  2003. }
  2004. }
  2005. END_MENU();
  2006. }
  2007. #endif //SDSUPPORT
  2008. #if ENABLED(LCD_INFO_MENU)
  2009. #if ENABLED(PRINTCOUNTER)
  2010. /**
  2011. *
  2012. * About Printer > Statistics submenu
  2013. *
  2014. */
  2015. void lcd_info_stats_menu() {
  2016. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2017. char buffer[21];
  2018. printStatistics stats = print_job_timer.getStats();
  2019. START_SCREEN(); // 12345678901234567890
  2020. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  2021. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  2022. duration_t elapsed = stats.printTime;
  2023. elapsed.toString(buffer);
  2024. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  2025. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2026. elapsed = stats.longestPrint;
  2027. elapsed.toString(buffer);
  2028. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  2029. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2030. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int(stats.filamentUsed / 100) % 10);
  2031. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  2032. STATIC_ITEM("", false, false, buffer); // 125m
  2033. END_SCREEN();
  2034. }
  2035. #endif // PRINTCOUNTER
  2036. /**
  2037. *
  2038. * About Printer > Thermistors
  2039. *
  2040. */
  2041. void lcd_info_thermistors_menu() {
  2042. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2043. START_SCREEN();
  2044. #define THERMISTOR_ID TEMP_SENSOR_0
  2045. #include "thermistornames.h"
  2046. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  2047. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  2048. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  2049. #if TEMP_SENSOR_1 != 0
  2050. #undef THERMISTOR_ID
  2051. #define THERMISTOR_ID TEMP_SENSOR_1
  2052. #include "thermistornames.h"
  2053. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  2054. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  2055. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  2056. #endif
  2057. #if TEMP_SENSOR_2 != 0
  2058. #undef THERMISTOR_ID
  2059. #define THERMISTOR_ID TEMP_SENSOR_2
  2060. #include "thermistornames.h"
  2061. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  2062. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  2063. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  2064. #endif
  2065. #if TEMP_SENSOR_3 != 0
  2066. #undef THERMISTOR_ID
  2067. #define THERMISTOR_ID TEMP_SENSOR_3
  2068. #include "thermistornames.h"
  2069. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  2070. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  2071. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  2072. #endif
  2073. #if TEMP_SENSOR_BED != 0
  2074. #undef THERMISTOR_ID
  2075. #define THERMISTOR_ID TEMP_SENSOR_BED
  2076. #include "thermistornames.h"
  2077. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  2078. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  2079. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  2080. #endif
  2081. END_SCREEN();
  2082. }
  2083. /**
  2084. *
  2085. * About Printer > Board Info
  2086. *
  2087. */
  2088. void lcd_info_board_menu() {
  2089. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2090. START_SCREEN();
  2091. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  2092. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  2093. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  2094. #ifdef POWER_SUPPLY
  2095. #if (POWER_SUPPLY == 1)
  2096. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  2097. #elif (POWER_SUPPLY == 2)
  2098. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  2099. #endif
  2100. #endif // POWER_SUPPLY
  2101. END_SCREEN();
  2102. }
  2103. /**
  2104. *
  2105. * About Printer > Printer Info
  2106. *
  2107. */
  2108. void lcd_info_printer_menu() {
  2109. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2110. START_SCREEN();
  2111. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  2112. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  2113. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  2114. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  2115. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  2116. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  2117. END_SCREEN();
  2118. }
  2119. /**
  2120. *
  2121. * "About Printer" submenu
  2122. *
  2123. */
  2124. void lcd_info_menu() {
  2125. START_MENU();
  2126. MENU_BACK(MSG_MAIN);
  2127. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  2128. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  2129. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  2130. #if ENABLED(PRINTCOUNTER)
  2131. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  2132. #endif
  2133. END_MENU();
  2134. }
  2135. #endif // LCD_INFO_MENU
  2136. /**
  2137. *
  2138. * Filament Change Feature Screens
  2139. *
  2140. */
  2141. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  2142. // Portions from STATIC_ITEM...
  2143. #define HOTEND_STATUS_ITEM() do { \
  2144. if (_menuLineNr == _thisItemNr) { \
  2145. if (lcdDrawUpdate) \
  2146. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  2147. lcd_implementation_hotend_status(_lcdLineNr); \
  2148. if (_skipStatic && encoderLine <= _thisItemNr) { \
  2149. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  2150. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  2151. } \
  2152. else \
  2153. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW; \
  2154. } \
  2155. ++_thisItemNr; \
  2156. } while(0)
  2157. void lcd_filament_change_toocold_menu() {
  2158. START_MENU();
  2159. STATIC_ITEM(MSG_HEATING_FAILED_LCD, true, true);
  2160. STATIC_ITEM(MSG_FILAMENT_CHANGE_MINTEMP STRINGIFY(EXTRUDE_MINTEMP) ".", false, false);
  2161. MENU_BACK(MSG_BACK);
  2162. #if LCD_HEIGHT > 4
  2163. STATIC_ITEM(" ");
  2164. #endif
  2165. HOTEND_STATUS_ITEM();
  2166. END_MENU();
  2167. }
  2168. void lcd_filament_change_resume_print() {
  2169. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_RESUME_PRINT;
  2170. }
  2171. void lcd_filament_change_extrude_more() {
  2172. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_EXTRUDE_MORE;
  2173. }
  2174. void lcd_filament_change_option_menu() {
  2175. START_MENU();
  2176. #if LCD_HEIGHT > 2
  2177. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  2178. #endif
  2179. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_filament_change_resume_print);
  2180. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_filament_change_extrude_more);
  2181. END_MENU();
  2182. }
  2183. void lcd_filament_change_init_message() {
  2184. START_SCREEN();
  2185. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2186. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  2187. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  2188. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  2189. #define __FC_LINES_A 3
  2190. #else
  2191. #define __FC_LINES_A 2
  2192. #endif
  2193. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  2194. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  2195. #define _FC_LINES_A (__FC_LINES_A + 1)
  2196. #else
  2197. #define _FC_LINES_A __FC_LINES_A
  2198. #endif
  2199. #if LCD_HEIGHT > _FC_LINES_A + 1
  2200. STATIC_ITEM(" ");
  2201. #endif
  2202. HOTEND_STATUS_ITEM();
  2203. END_SCREEN();
  2204. }
  2205. void lcd_filament_change_unload_message() {
  2206. START_SCREEN();
  2207. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2208. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  2209. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  2210. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  2211. #define __FC_LINES_B 3
  2212. #else
  2213. #define __FC_LINES_B 2
  2214. #endif
  2215. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  2216. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  2217. #define _FC_LINES_B (__FC_LINES_B + 1)
  2218. #else
  2219. #define _FC_LINES_B __FC_LINES_B
  2220. #endif
  2221. #if LCD_HEIGHT > _FC_LINES_B + 1
  2222. STATIC_ITEM(" ");
  2223. #endif
  2224. HOTEND_STATUS_ITEM();
  2225. END_SCREEN();
  2226. }
  2227. void lcd_filament_change_wait_for_nozzles_to_heat() {
  2228. START_SCREEN();
  2229. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2230. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  2231. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  2232. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  2233. #define _FC_LINES_C 3
  2234. #else
  2235. #define _FC_LINES_C 2
  2236. #endif
  2237. #if LCD_HEIGHT > _FC_LINES_C + 1
  2238. STATIC_ITEM(" ");
  2239. #endif
  2240. HOTEND_STATUS_ITEM();
  2241. END_SCREEN();
  2242. }
  2243. void lcd_filament_change_heat_nozzle() {
  2244. START_SCREEN();
  2245. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2246. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  2247. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2248. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  2249. #define _FC_LINES_D 3
  2250. #else
  2251. #define _FC_LINES_D 2
  2252. #endif
  2253. #if LCD_HEIGHT > _FC_LINES_D + 1
  2254. STATIC_ITEM(" ");
  2255. #endif
  2256. HOTEND_STATUS_ITEM();
  2257. END_SCREEN();
  2258. }
  2259. void lcd_filament_change_insert_message() {
  2260. START_SCREEN();
  2261. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2262. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  2263. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2264. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  2265. #define __FC_LINES_E 3
  2266. #else
  2267. #define __FC_LINES_E 2
  2268. #endif
  2269. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  2270. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  2271. #define _FC_LINES_E (__FC_LINES_E + 1)
  2272. #else
  2273. #define _FC_LINES_E __FC_LINES_E
  2274. #endif
  2275. #if LCD_HEIGHT > _FC_LINES_E + 1
  2276. STATIC_ITEM(" ");
  2277. #endif
  2278. HOTEND_STATUS_ITEM();
  2279. END_SCREEN();
  2280. }
  2281. void lcd_filament_change_load_message() {
  2282. START_SCREEN();
  2283. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2284. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  2285. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  2286. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  2287. #define __FC_LINES_F 3
  2288. #else
  2289. #define __FC_LINES_F 2
  2290. #endif
  2291. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  2292. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  2293. #define _FC_LINES_F (__FC_LINES_F + 1)
  2294. #else
  2295. #define _FC_LINES_F __FC_LINES_F
  2296. #endif
  2297. #if LCD_HEIGHT > _FC_LINES_F + 1
  2298. STATIC_ITEM(" ");
  2299. #endif
  2300. HOTEND_STATUS_ITEM();
  2301. END_SCREEN();
  2302. }
  2303. void lcd_filament_change_extrude_message() {
  2304. START_SCREEN();
  2305. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2306. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  2307. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  2308. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  2309. #define __FC_LINES_G 3
  2310. #else
  2311. #define __FC_LINES_G 2
  2312. #endif
  2313. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  2314. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  2315. #define _FC_LINES_G (__FC_LINES_G + 1)
  2316. #else
  2317. #define _FC_LINES_G __FC_LINES_G
  2318. #endif
  2319. #if LCD_HEIGHT > _FC_LINES_G + 1
  2320. STATIC_ITEM(" ");
  2321. #endif
  2322. HOTEND_STATUS_ITEM();
  2323. END_SCREEN();
  2324. }
  2325. void lcd_filament_change_resume_message() {
  2326. START_SCREEN();
  2327. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2328. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  2329. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  2330. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  2331. #endif
  2332. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  2333. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  2334. #endif
  2335. END_SCREEN();
  2336. }
  2337. void lcd_filament_change_show_message(const FilamentChangeMessage message) {
  2338. switch (message) {
  2339. case FILAMENT_CHANGE_MESSAGE_INIT:
  2340. defer_return_to_status = true;
  2341. lcd_goto_screen(lcd_filament_change_init_message);
  2342. break;
  2343. case FILAMENT_CHANGE_MESSAGE_UNLOAD:
  2344. lcd_goto_screen(lcd_filament_change_unload_message);
  2345. break;
  2346. case FILAMENT_CHANGE_MESSAGE_INSERT:
  2347. lcd_goto_screen(lcd_filament_change_insert_message);
  2348. break;
  2349. case FILAMENT_CHANGE_MESSAGE_LOAD:
  2350. lcd_goto_screen(lcd_filament_change_load_message);
  2351. break;
  2352. case FILAMENT_CHANGE_MESSAGE_EXTRUDE:
  2353. lcd_goto_screen(lcd_filament_change_extrude_message);
  2354. break;
  2355. case FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE:
  2356. lcd_goto_screen(lcd_filament_change_heat_nozzle);
  2357. break;
  2358. case FILAMENT_CHANGE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT:
  2359. lcd_goto_screen(lcd_filament_change_wait_for_nozzles_to_heat);
  2360. break;
  2361. case FILAMENT_CHANGE_MESSAGE_OPTION:
  2362. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_WAIT_FOR;
  2363. lcd_goto_screen(lcd_filament_change_option_menu);
  2364. break;
  2365. case FILAMENT_CHANGE_MESSAGE_RESUME:
  2366. lcd_goto_screen(lcd_filament_change_resume_message);
  2367. break;
  2368. case FILAMENT_CHANGE_MESSAGE_STATUS:
  2369. lcd_return_to_status();
  2370. break;
  2371. }
  2372. }
  2373. #endif // FILAMENT_CHANGE_FEATURE
  2374. /**
  2375. *
  2376. * Functions for editing single values
  2377. *
  2378. * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
  2379. *
  2380. * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
  2381. *
  2382. * bool _menu_edit_int3();
  2383. * void menu_edit_int3(); // edit int (interactively)
  2384. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  2385. * void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  2386. * void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  2387. * 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
  2388. *
  2389. * You can then use one of the menu macros to present the edit interface:
  2390. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  2391. *
  2392. * This expands into a more primitive menu item:
  2393. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2394. *
  2395. *
  2396. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  2397. *
  2398. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2399. */
  2400. #define menu_edit_type(_type, _name, _strFunc, _scale) \
  2401. bool _menu_edit_ ## _name () { \
  2402. ENCODER_DIRECTION_NORMAL(); \
  2403. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  2404. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  2405. if (lcdDrawUpdate) \
  2406. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
  2407. if (lcd_clicked) { \
  2408. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
  2409. lcd_goto_previous_menu(); \
  2410. } \
  2411. return lcd_clicked; \
  2412. } \
  2413. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  2414. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  2415. void _menu_action_setting_edit_ ## _name (const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  2416. lcd_save_previous_screen(); \
  2417. \
  2418. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  2419. \
  2420. editLabel = pstr; \
  2421. editValue = ptr; \
  2422. minEditValue = minValue * _scale; \
  2423. maxEditValue = maxValue * _scale - minEditValue; \
  2424. encoderPosition = (*ptr) * _scale - minEditValue; \
  2425. } \
  2426. void menu_action_setting_edit_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  2427. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2428. currentScreen = menu_edit_ ## _name; \
  2429. }\
  2430. void menu_action_setting_edit_callback_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback) { \
  2431. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2432. currentScreen = menu_edit_callback_ ## _name; \
  2433. callbackFunc = callback; \
  2434. } \
  2435. typedef void _name
  2436. menu_edit_type(int, int3, itostr3, 1);
  2437. menu_edit_type(float, float3, ftostr3, 1.0);
  2438. menu_edit_type(float, float32, ftostr32, 100.0);
  2439. menu_edit_type(float, float43, ftostr43sign, 1000.0);
  2440. menu_edit_type(float, float5, ftostr5rj, 0.01);
  2441. menu_edit_type(float, float51, ftostr51sign, 10.0);
  2442. menu_edit_type(float, float52, ftostr52sign, 100.0);
  2443. menu_edit_type(float, float62, ftostr62rj, 100.0);
  2444. menu_edit_type(unsigned long, long5, ftostr5rj, 0.01);
  2445. /**
  2446. *
  2447. * Handlers for RepRap World Keypad input
  2448. *
  2449. */
  2450. #if ENABLED(REPRAPWORLD_KEYPAD)
  2451. void _reprapworld_keypad_move(AxisEnum axis, int dir) {
  2452. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2453. encoderPosition = dir;
  2454. switch (axis) {
  2455. case X_AXIS: lcd_move_x(); break;
  2456. case Y_AXIS: lcd_move_y(); break;
  2457. case Z_AXIS: lcd_move_z();
  2458. default: break;
  2459. }
  2460. }
  2461. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  2462. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  2463. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  2464. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  2465. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  2466. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  2467. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  2468. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  2469. inline void handle_reprapworld_keypad() {
  2470. static uint8_t keypad_debounce = 0;
  2471. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  2472. if (keypad_debounce > 0) keypad_debounce--;
  2473. }
  2474. else if (!keypad_debounce) {
  2475. keypad_debounce = 2;
  2476. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  2477. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  2478. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2479. #endif
  2480. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  2481. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  2482. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2483. #endif
  2484. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  2485. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  2486. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  2487. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  2488. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  2489. }
  2490. else {
  2491. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  2492. }
  2493. }
  2494. }
  2495. #endif // REPRAPWORLD_KEYPAD
  2496. /**
  2497. *
  2498. * Audio feedback for controller clicks
  2499. *
  2500. */
  2501. void lcd_buzz(long duration, uint16_t freq) {
  2502. #if ENABLED(LCD_USE_I2C_BUZZER)
  2503. lcd.buzz(duration, freq);
  2504. #elif PIN_EXISTS(BEEPER)
  2505. buzzer.tone(duration, freq);
  2506. #else
  2507. UNUSED(duration); UNUSED(freq);
  2508. #endif
  2509. }
  2510. void lcd_quick_feedback() {
  2511. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2512. buttons = 0;
  2513. next_button_update_ms = millis() + 500;
  2514. // Buzz and wait. The delay is needed for buttons to settle!
  2515. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  2516. #if ENABLED(LCD_USE_I2C_BUZZER)
  2517. delay(10);
  2518. #elif PIN_EXISTS(BEEPER)
  2519. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  2520. #endif
  2521. }
  2522. /**
  2523. *
  2524. * Menu actions
  2525. *
  2526. */
  2527. void _menu_action_back() { lcd_goto_previous_menu(); }
  2528. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  2529. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  2530. void menu_action_function(screenFunc_t func) { (*func)(); }
  2531. #if ENABLED(SDSUPPORT)
  2532. void menu_action_sdfile(const char* filename, char* longFilename) {
  2533. UNUSED(longFilename);
  2534. card.openAndPrintFile(filename);
  2535. lcd_return_to_status();
  2536. }
  2537. void menu_action_sddirectory(const char* filename, char* longFilename) {
  2538. UNUSED(longFilename);
  2539. card.chdir(filename);
  2540. encoderPosition = 0;
  2541. screen_changed = true;
  2542. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2543. }
  2544. #endif //SDSUPPORT
  2545. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) {UNUSED(pstr); *ptr = !(*ptr); lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
  2546. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  2547. menu_action_setting_edit_bool(pstr, ptr);
  2548. (*callback)();
  2549. }
  2550. #endif // ULTIPANEL
  2551. void lcd_init() {
  2552. lcd_implementation_init(
  2553. #if ENABLED(LCD_PROGRESS_BAR)
  2554. true
  2555. #endif
  2556. );
  2557. #if ENABLED(NEWPANEL)
  2558. #if BUTTON_EXISTS(EN1)
  2559. SET_INPUT(BTN_EN1);
  2560. WRITE(BTN_EN1, HIGH);
  2561. #endif
  2562. #if BUTTON_EXISTS(EN2)
  2563. SET_INPUT(BTN_EN2);
  2564. WRITE(BTN_EN2, HIGH);
  2565. #endif
  2566. #if BUTTON_EXISTS(ENC)
  2567. SET_INPUT(BTN_ENC);
  2568. WRITE(BTN_ENC, HIGH);
  2569. #endif
  2570. #if ENABLED(REPRAPWORLD_KEYPAD)
  2571. SET_OUTPUT(SHIFT_CLK);
  2572. OUT_WRITE(SHIFT_LD, HIGH);
  2573. SET_INPUT_PULLUP(SHIFT_OUT);
  2574. #endif
  2575. #if BUTTON_EXISTS(UP)
  2576. SET_INPUT(BTN_UP);
  2577. #endif
  2578. #if BUTTON_EXISTS(DWN)
  2579. SET_INPUT(BTN_DWN);
  2580. #endif
  2581. #if BUTTON_EXISTS(LFT)
  2582. SET_INPUT(BTN_LFT);
  2583. #endif
  2584. #if BUTTON_EXISTS(RT)
  2585. SET_INPUT(BTN_RT);
  2586. #endif
  2587. #else // !NEWPANEL
  2588. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  2589. SET_OUTPUT(SR_DATA_PIN);
  2590. SET_OUTPUT(SR_CLK_PIN);
  2591. #elif defined(SHIFT_CLK)
  2592. SET_OUTPUT(SHIFT_CLK);
  2593. OUT_WRITE(SHIFT_LD, HIGH);
  2594. OUT_WRITE(SHIFT_EN, LOW);
  2595. SET_INPUT_PULLUP(SHIFT_OUT);
  2596. #endif // SR_LCD_2W_NL
  2597. #endif // !NEWPANEL
  2598. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2599. SET_INPUT(SD_DETECT_PIN);
  2600. WRITE(SD_DETECT_PIN, HIGH);
  2601. lcd_sd_status = 2; // UNKNOWN
  2602. #endif
  2603. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2604. slow_buttons = 0;
  2605. #endif
  2606. lcd_buttons_update();
  2607. #if ENABLED(ULTIPANEL)
  2608. encoderDiff = 0;
  2609. #endif
  2610. }
  2611. int lcd_strlen(const char* s) {
  2612. int i = 0, j = 0;
  2613. while (s[i]) {
  2614. #if ENABLED(MAPPER_NON)
  2615. j++;
  2616. #else
  2617. if ((s[i] & 0xC0u) != 0x80u) j++;
  2618. #endif
  2619. i++;
  2620. }
  2621. return j;
  2622. }
  2623. int lcd_strlen_P(const char* s) {
  2624. int j = 0;
  2625. while (pgm_read_byte(s)) {
  2626. #if ENABLED(MAPPER_NON)
  2627. j++;
  2628. #else
  2629. if ((pgm_read_byte(s) & 0xC0u) != 0x80u) j++;
  2630. #endif
  2631. s++;
  2632. }
  2633. return j;
  2634. }
  2635. bool lcd_blink() {
  2636. static uint8_t blink = 0;
  2637. static millis_t next_blink_ms = 0;
  2638. millis_t ms = millis();
  2639. if (ELAPSED(ms, next_blink_ms)) {
  2640. blink ^= 0xFF;
  2641. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  2642. }
  2643. return blink != 0;
  2644. }
  2645. /**
  2646. * Update the LCD, read encoder buttons, etc.
  2647. * - Read button states
  2648. * - Check the SD Card slot state
  2649. * - Act on RepRap World keypad input
  2650. * - Update the encoder position
  2651. * - Apply acceleration to the encoder position
  2652. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  2653. * - Reset the Info Screen timeout if there's any input
  2654. * - Update status indicators, if any
  2655. *
  2656. * Run the current LCD menu handler callback function:
  2657. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  2658. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  2659. * - Call the menu handler. Menu handlers should do the following:
  2660. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  2661. * (Encoder events automatically set lcdDrawUpdate for you.)
  2662. * - if (lcdDrawUpdate) { redraw }
  2663. * - Before exiting the handler set lcdDrawUpdate to:
  2664. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  2665. * - LCDVIEW_REDRAW_NOW or LCDVIEW_NONE to keep drawing, but only in this loop.
  2666. * - LCDVIEW_CALL_REDRAW_NEXT to keep drawing and draw on the next loop also.
  2667. * - LCDVIEW_CALL_NO_REDRAW to keep drawing (or start drawing) with no redraw on the next loop.
  2668. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  2669. * so don't change lcdDrawUpdate without considering this.
  2670. *
  2671. * After the menu handler callback runs (or not):
  2672. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  2673. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  2674. *
  2675. * No worries. This function is only called from the main thread.
  2676. */
  2677. void lcd_update() {
  2678. #if ENABLED(ULTIPANEL)
  2679. static millis_t return_to_status_ms = 0;
  2680. manage_manual_move();
  2681. lcd_buttons_update();
  2682. // If the action button is pressed...
  2683. if (LCD_CLICKED) {
  2684. if (!wait_for_unclick) { // If not waiting for a debounce release:
  2685. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  2686. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  2687. wait_for_user = false; // Any click clears wait for user
  2688. lcd_quick_feedback(); // Always make a click sound
  2689. }
  2690. }
  2691. else wait_for_unclick = false;
  2692. #endif
  2693. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2694. bool sd_status = IS_SD_INSERTED;
  2695. if (sd_status != lcd_sd_status && lcd_detected()) {
  2696. if (sd_status) {
  2697. card.initsd();
  2698. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  2699. }
  2700. else {
  2701. card.release();
  2702. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  2703. }
  2704. lcd_sd_status = sd_status;
  2705. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2706. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  2707. #if ENABLED(LCD_PROGRESS_BAR)
  2708. currentScreen == lcd_status_screen
  2709. #endif
  2710. );
  2711. }
  2712. #endif //SDSUPPORT && SD_DETECT_PIN
  2713. millis_t ms = millis();
  2714. if (ELAPSED(ms, next_lcd_update_ms)
  2715. #if ENABLED(DOGLCD)
  2716. || drawing_screen
  2717. #endif
  2718. ) {
  2719. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  2720. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  2721. lcd_implementation_update_indicators();
  2722. #endif
  2723. #if ENABLED(ULTIPANEL)
  2724. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2725. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  2726. #endif
  2727. #if ENABLED(REPRAPWORLD_KEYPAD)
  2728. handle_reprapworld_keypad();
  2729. #endif
  2730. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  2731. if (encoderPastThreshold || lcd_clicked) {
  2732. if (encoderPastThreshold) {
  2733. int32_t encoderMultiplier = 1;
  2734. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  2735. if (encoderRateMultiplierEnabled) {
  2736. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  2737. if (lastEncoderMovementMillis != 0) {
  2738. // Note that the rate is always calculated between to passes through the
  2739. // loop and that the abs of the encoderDiff value is tracked.
  2740. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  2741. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  2742. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  2743. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  2744. SERIAL_ECHO_START;
  2745. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  2746. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  2747. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  2748. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  2749. SERIAL_EOL;
  2750. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  2751. }
  2752. lastEncoderMovementMillis = ms;
  2753. } // encoderRateMultiplierEnabled
  2754. #endif //ENCODER_RATE_MULTIPLIER
  2755. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  2756. encoderDiff = 0;
  2757. }
  2758. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  2759. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  2760. }
  2761. #endif // ULTIPANEL
  2762. // We arrive here every ~100ms when idling often enough.
  2763. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  2764. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  2765. if (
  2766. #if ENABLED(ULTIPANEL)
  2767. currentScreen == lcd_status_screen &&
  2768. #endif
  2769. !lcd_status_update_delay--
  2770. ) {
  2771. lcd_status_update_delay = 9
  2772. #if ENABLED(DOGLCD)
  2773. + 3
  2774. #endif
  2775. ;
  2776. max_display_update_time--;
  2777. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2778. }
  2779. // then we want to use 1/2 of the time only.
  2780. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  2781. #if ENABLED(DOGLCD)
  2782. if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
  2783. #else
  2784. if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
  2785. #endif
  2786. {
  2787. #if ENABLED(DOGLCD)
  2788. if (!drawing_screen)
  2789. #endif
  2790. {
  2791. switch (lcdDrawUpdate) {
  2792. case LCDVIEW_CALL_NO_REDRAW:
  2793. lcdDrawUpdate = LCDVIEW_NONE;
  2794. break;
  2795. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  2796. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  2797. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2798. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  2799. case LCDVIEW_NONE:
  2800. break;
  2801. } // switch
  2802. }
  2803. #if ENABLED(ULTIPANEL)
  2804. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  2805. #else
  2806. #define CURRENTSCREEN() lcd_status_screen()
  2807. #endif
  2808. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  2809. if (!drawing_screen) {
  2810. u8g.firstPage();
  2811. drawing_screen = 1;
  2812. }
  2813. lcd_setFont(FONT_MENU);
  2814. u8g.setColorIndex(1);
  2815. CURRENTSCREEN();
  2816. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  2817. NOLESS(max_display_update_time, millis() - ms);
  2818. return;
  2819. }
  2820. #else
  2821. CURRENTSCREEN();
  2822. #endif
  2823. NOLESS(max_display_update_time, millis() - ms);
  2824. }
  2825. #if ENABLED(ULTIPANEL)
  2826. // Return to Status Screen after a timeout
  2827. if (currentScreen == lcd_status_screen || defer_return_to_status)
  2828. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  2829. else if (ELAPSED(ms, return_to_status_ms))
  2830. lcd_return_to_status();
  2831. #endif // ULTIPANEL
  2832. #if ENABLED(DOGLCD)
  2833. if (!drawing_screen)
  2834. #endif
  2835. {
  2836. switch (lcdDrawUpdate) {
  2837. case LCDVIEW_CLEAR_CALL_REDRAW:
  2838. lcd_implementation_clear();
  2839. case LCDVIEW_CALL_REDRAW_NEXT:
  2840. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2841. break;
  2842. case LCDVIEW_REDRAW_NOW:
  2843. lcdDrawUpdate = LCDVIEW_NONE;
  2844. break;
  2845. case LCDVIEW_NONE:
  2846. break;
  2847. } // switch
  2848. }
  2849. } // ELAPSED(ms, next_lcd_update_ms)
  2850. }
  2851. void set_utf_strlen(char* s, uint8_t n) {
  2852. uint8_t i = 0, j = 0;
  2853. while (s[i] && (j < n)) {
  2854. #if ENABLED(MAPPER_NON)
  2855. j++;
  2856. #else
  2857. if ((s[i] & 0xC0u) != 0x80u) j++;
  2858. #endif
  2859. i++;
  2860. }
  2861. while (j++ < n) s[i++] = ' ';
  2862. s[i] = '\0';
  2863. }
  2864. void lcd_finishstatus(bool persist=false) {
  2865. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  2866. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  2867. UNUSED(persist);
  2868. #endif
  2869. #if ENABLED(LCD_PROGRESS_BAR)
  2870. progress_bar_ms = millis();
  2871. #if PROGRESS_MSG_EXPIRE > 0
  2872. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  2873. #endif
  2874. #endif
  2875. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2876. #if ENABLED(FILAMENT_LCD_DISPLAY)
  2877. previous_lcd_status_ms = millis(); //get status message to show up for a while
  2878. #endif
  2879. }
  2880. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  2881. void dontExpireStatus() { expire_status_ms = 0; }
  2882. #endif
  2883. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  2884. void lcd_setstatus(const char* const message, bool persist) {
  2885. if (lcd_status_message_level > 0) return;
  2886. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  2887. lcd_finishstatus(persist);
  2888. }
  2889. void lcd_setstatuspgm(const char* const message, uint8_t level) {
  2890. if (level < lcd_status_message_level) return;
  2891. lcd_status_message_level = level;
  2892. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  2893. lcd_finishstatus(level > 0);
  2894. }
  2895. void status_printf(uint8_t level, const char *status, ...) {
  2896. if (level < lcd_status_message_level) return;
  2897. lcd_status_message_level = level;
  2898. va_list args;
  2899. va_start(args, status);
  2900. vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), status, args);
  2901. va_end(args);
  2902. lcd_finishstatus(level > 0);
  2903. }
  2904. void lcd_setalertstatuspgm(const char* const message) {
  2905. lcd_setstatuspgm(message, 1);
  2906. #if ENABLED(ULTIPANEL)
  2907. lcd_return_to_status();
  2908. #endif
  2909. }
  2910. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  2911. #if HAS_LCD_CONTRAST
  2912. void set_lcd_contrast(const int value) {
  2913. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  2914. u8g.setContrast(lcd_contrast);
  2915. }
  2916. #endif
  2917. #if ENABLED(ULTIPANEL)
  2918. /**
  2919. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  2920. * These values are independent of which pins are used for EN_A and EN_B indications
  2921. * The rotary encoder part is also independent to the chipset used for the LCD
  2922. */
  2923. #if defined(EN_A) && defined(EN_B)
  2924. #define encrot0 0
  2925. #define encrot1 2
  2926. #define encrot2 3
  2927. #define encrot3 1
  2928. #endif
  2929. #define GET_BUTTON_STATES(DST) \
  2930. uint8_t new_##DST = 0; \
  2931. WRITE(SHIFT_LD, LOW); \
  2932. WRITE(SHIFT_LD, HIGH); \
  2933. for (int8_t i = 0; i < 8; i++) { \
  2934. new_##DST >>= 1; \
  2935. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  2936. WRITE(SHIFT_CLK, HIGH); \
  2937. WRITE(SHIFT_CLK, LOW); \
  2938. } \
  2939. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  2940. /**
  2941. * Read encoder buttons from the hardware registers
  2942. * Warning: This function is called from interrupt context!
  2943. */
  2944. void lcd_buttons_update() {
  2945. millis_t now = millis();
  2946. if (ELAPSED(now, next_button_update_ms)) {
  2947. #if ENABLED(NEWPANEL)
  2948. uint8_t newbutton = 0;
  2949. #if BUTTON_EXISTS(EN1)
  2950. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  2951. #endif
  2952. #if BUTTON_EXISTS(EN2)
  2953. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  2954. #endif
  2955. #if BUTTON_EXISTS(ENC)
  2956. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  2957. #endif
  2958. #if LCD_HAS_DIRECTIONAL_BUTTONS
  2959. // Manage directional buttons
  2960. #if ENABLED(REVERSE_MENU_DIRECTION)
  2961. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  2962. #else
  2963. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  2964. #endif
  2965. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  2966. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  2967. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  2968. #else
  2969. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  2970. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  2971. #endif
  2972. if (false) {
  2973. // for the else-ifs below
  2974. }
  2975. #if BUTTON_EXISTS(UP)
  2976. else if (BUTTON_PRESSED(UP)) {
  2977. encoderDiff = -(ENCODER_UD_STEPS);
  2978. next_button_update_ms = now + 300;
  2979. }
  2980. #endif
  2981. #if BUTTON_EXISTS(DWN)
  2982. else if (BUTTON_PRESSED(DWN)) {
  2983. encoderDiff = ENCODER_UD_STEPS;
  2984. next_button_update_ms = now + 300;
  2985. }
  2986. #endif
  2987. #if BUTTON_EXISTS(LFT)
  2988. else if (BUTTON_PRESSED(LFT)) {
  2989. encoderDiff = -(ENCODER_LR_PULSES);
  2990. next_button_update_ms = now + 300;
  2991. }
  2992. #endif
  2993. #if BUTTON_EXISTS(RT)
  2994. else if (BUTTON_PRESSED(RT)) {
  2995. encoderDiff = ENCODER_LR_PULSES;
  2996. next_button_update_ms = now + 300;
  2997. }
  2998. #endif
  2999. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  3000. buttons = newbutton;
  3001. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3002. buttons |= slow_buttons;
  3003. #endif
  3004. #if ENABLED(REPRAPWORLD_KEYPAD)
  3005. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  3006. #endif
  3007. #else
  3008. GET_BUTTON_STATES(buttons);
  3009. #endif //!NEWPANEL
  3010. } // next_button_update_ms
  3011. // Manage encoder rotation
  3012. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  3013. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  3014. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  3015. #elif ENABLED(REVERSE_MENU_DIRECTION)
  3016. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  3017. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  3018. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  3019. #define ENCODER_DIFF_CW (encoderDiff--)
  3020. #define ENCODER_DIFF_CCW (encoderDiff++)
  3021. #else
  3022. #define ENCODER_DIFF_CW (encoderDiff++)
  3023. #define ENCODER_DIFF_CCW (encoderDiff--)
  3024. #endif
  3025. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  3026. uint8_t enc = 0;
  3027. if (buttons & EN_A) enc |= B01;
  3028. if (buttons & EN_B) enc |= B10;
  3029. if (enc != lastEncoderBits) {
  3030. switch (enc) {
  3031. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  3032. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  3033. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  3034. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  3035. }
  3036. }
  3037. lastEncoderBits = enc;
  3038. }
  3039. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  3040. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  3041. #else
  3042. bool lcd_detected() { return true; }
  3043. #endif
  3044. #endif // ULTIPANEL
  3045. #endif // ULTRA_LCD