My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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