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

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