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

ultralcd.cpp 100KB

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