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

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