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

ultralcd.cpp 99KB

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