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

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