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

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