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

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