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

ultralcd.cpp 100KB

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