My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ultralcd.cpp 124KB

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