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

ultralcd.cpp 100KB

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