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

ultralcd.cpp 156KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640
  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 "planner.h"
  29. #include "stepper.h"
  30. #include "configuration_store.h"
  31. #include "utility.h"
  32. #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
  33. #include "buzzer.h"
  34. #endif
  35. #if ENABLED(PRINTCOUNTER)
  36. #include "printcounter.h"
  37. #include "duration_t.h"
  38. #endif
  39. #if ENABLED(BLTOUCH)
  40. #include "endstops.h"
  41. #endif
  42. #if ENABLED(AUTO_BED_LEVELING_UBL)
  43. #include "ubl.h"
  44. bool ubl_lcd_map_control = false;
  45. #endif
  46. int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  47. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  48. millis_t previous_lcd_status_ms = 0;
  49. #endif
  50. #if ENABLED(BABYSTEPPING)
  51. long babysteps_done = 0;
  52. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  53. static void lcd_babystep_zoffset();
  54. #else
  55. static void lcd_babystep_z();
  56. #endif
  57. #endif
  58. uint8_t lcd_status_message_level;
  59. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  60. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  61. uint8_t status_scroll_pos = 0;
  62. #endif
  63. #if ENABLED(DOGLCD)
  64. #include "ultralcd_impl_DOGM.h"
  65. #include <U8glib.h>
  66. #else
  67. #include "ultralcd_impl_HD44780.h"
  68. #endif
  69. // The main status screen
  70. void lcd_status_screen();
  71. millis_t next_lcd_update_ms;
  72. 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)
  73. uint16_t max_display_update_time = 0;
  74. #if ENABLED(DOGLCD)
  75. bool drawing_screen = false;
  76. #endif
  77. #if ENABLED(DAC_STEPPER_CURRENT)
  78. #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
  79. int16_t driverPercent[XYZE];
  80. #endif
  81. #if ENABLED(ULTIPANEL)
  82. #ifndef TALL_FONT_CORRECTION
  83. #define TALL_FONT_CORRECTION 0
  84. #endif
  85. // Function pointer to menu functions.
  86. typedef void (*screenFunc_t)();
  87. #if HAS_POWER_SWITCH
  88. extern bool powersupply_on;
  89. #endif
  90. ////////////////////////////////////////////
  91. ///////////////// Menu Tree ////////////////
  92. ////////////////////////////////////////////
  93. void lcd_main_menu();
  94. void lcd_tune_menu();
  95. void lcd_prepare_menu();
  96. void lcd_move_menu();
  97. void lcd_control_menu();
  98. void lcd_control_temperature_menu();
  99. void lcd_control_temperature_preheat_material1_settings_menu();
  100. void lcd_control_temperature_preheat_material2_settings_menu();
  101. void lcd_control_motion_menu();
  102. void lcd_control_filament_menu();
  103. #if ENABLED(LCD_INFO_MENU)
  104. #if ENABLED(PRINTCOUNTER)
  105. void lcd_info_stats_menu();
  106. #endif
  107. void lcd_info_thermistors_menu();
  108. void lcd_info_board_menu();
  109. void lcd_info_menu();
  110. #endif // LCD_INFO_MENU
  111. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  112. void lcd_advanced_pause_toocold_menu();
  113. void lcd_advanced_pause_option_menu();
  114. void lcd_advanced_pause_init_message();
  115. void lcd_advanced_pause_unload_message();
  116. void lcd_advanced_pause_insert_message();
  117. void lcd_advanced_pause_load_message();
  118. void lcd_advanced_pause_heat_nozzle();
  119. void lcd_advanced_pause_extrude_message();
  120. void lcd_advanced_pause_resume_message();
  121. #endif
  122. #if ENABLED(DAC_STEPPER_CURRENT)
  123. void dac_driver_commit();
  124. void dac_driver_getValues();
  125. void lcd_dac_menu();
  126. void lcd_dac_write_eeprom();
  127. #endif
  128. #if ENABLED(FWRETRACT)
  129. void lcd_control_retract_menu();
  130. #endif
  131. #if ENABLED(DELTA_CALIBRATION_MENU)
  132. void lcd_delta_calibrate_menu();
  133. #endif
  134. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  135. #include "mesh_bed_leveling.h"
  136. extern void mesh_probing_done();
  137. #endif
  138. ////////////////////////////////////////////
  139. //////////// Menu System Actions ///////////
  140. ////////////////////////////////////////////
  141. #define menu_action_back(dummy) _menu_action_back()
  142. void _menu_action_back();
  143. void menu_action_submenu(screenFunc_t data);
  144. void menu_action_gcode(const char* pgcode);
  145. void menu_action_function(screenFunc_t data);
  146. #define DECLARE_MENU_EDIT_TYPE(_type, _name) \
  147. bool _menu_edit_ ## _name(); \
  148. void menu_edit_ ## _name(); \
  149. void menu_edit_callback_ ## _name(); \
  150. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
  151. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
  152. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
  153. typedef void _name##_void
  154. DECLARE_MENU_EDIT_TYPE(int, int3);
  155. DECLARE_MENU_EDIT_TYPE(float, float3);
  156. DECLARE_MENU_EDIT_TYPE(float, float32);
  157. DECLARE_MENU_EDIT_TYPE(float, float43);
  158. DECLARE_MENU_EDIT_TYPE(float, float5);
  159. DECLARE_MENU_EDIT_TYPE(float, float51);
  160. DECLARE_MENU_EDIT_TYPE(float, float52);
  161. DECLARE_MENU_EDIT_TYPE(float, float62);
  162. DECLARE_MENU_EDIT_TYPE(unsigned long, long5);
  163. void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  164. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
  165. #if ENABLED(SDSUPPORT)
  166. void lcd_sdcard_menu();
  167. void menu_action_sdfile(const char* filename, char* longFilename);
  168. void menu_action_sddirectory(const char* filename, char* longFilename);
  169. #endif
  170. ////////////////////////////////////////////
  171. //////////// Menu System Macros ////////////
  172. ////////////////////////////////////////////
  173. #ifndef ENCODER_FEEDRATE_DEADZONE
  174. #define ENCODER_FEEDRATE_DEADZONE 10
  175. #endif
  176. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  177. #define ENCODER_STEPS_PER_MENU_ITEM 5
  178. #endif
  179. #ifndef ENCODER_PULSES_PER_STEP
  180. #define ENCODER_PULSES_PER_STEP 1
  181. #endif
  182. /**
  183. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  184. *
  185. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  186. * menu_action_[type](arg3...)
  187. *
  188. * Examples:
  189. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  190. * or
  191. * MENU_BACK(MSG_WATCH)
  192. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  193. * menu_action_back()
  194. *
  195. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  196. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  197. * menu_action_function(lcd_sdcard_pause)
  198. *
  199. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  200. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  201. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  202. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  203. *
  204. */
  205. #define _MENU_ITEM_PART_1(TYPE, ...) \
  206. if (_menuLineNr == _thisItemNr) { \
  207. if (lcd_clicked && encoderLine == _thisItemNr) {
  208. #define _MENU_ITEM_PART_2(TYPE, LABEL, ...) \
  209. menu_action_ ## TYPE(__VA_ARGS__); \
  210. if (screen_changed) return; \
  211. } \
  212. if (lcdDrawUpdate) \
  213. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  214. } \
  215. ++_thisItemNr
  216. #define MENU_ITEM(TYPE, LABEL, ...) do { \
  217. _skipStatic = false; \
  218. _MENU_ITEM_PART_1(TYPE, ## __VA_ARGS__); \
  219. _MENU_ITEM_PART_2(TYPE, LABEL, ## __VA_ARGS__); \
  220. }while(0)
  221. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
  222. // Used to print static text with no visible cursor.
  223. // Parameters: label [, bool center [, bool invert [, char *value] ] ]
  224. #define STATIC_ITEM(LABEL, ...) \
  225. if (_menuLineNr == _thisItemNr) { \
  226. if (_skipStatic && encoderLine <= _thisItemNr) { \
  227. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  228. ++encoderLine; \
  229. } \
  230. if (lcdDrawUpdate) \
  231. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  232. } \
  233. ++_thisItemNr
  234. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  235. bool encoderRateMultiplierEnabled;
  236. #define ENCODER_RATE_MULTIPLY(F) (encoderRateMultiplierEnabled = F)
  237. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  238. /**
  239. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  240. */
  241. #define MENU_MULTIPLIER_ITEM(type, label, ...) do { \
  242. _MENU_ITEM_PART_1(type, ## __VA_ARGS__); \
  243. encoderRateMultiplierEnabled = true; \
  244. lastEncoderMovementMillis = 0; \
  245. _MENU_ITEM_PART_2(type, label, ## __VA_ARGS__); \
  246. }while(0)
  247. #else // !ENCODER_RATE_MULTIPLIER
  248. #define ENCODER_RATE_MULTIPLY(F) NOOP
  249. #endif // !ENCODER_RATE_MULTIPLIER
  250. #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
  251. #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  252. #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  253. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  254. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  255. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  256. #else // !ENCODER_RATE_MULTIPLIER
  257. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  258. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  259. #endif // !ENCODER_RATE_MULTIPLIER
  260. /**
  261. * START_SCREEN_OR_MENU generates init code for a screen or menu
  262. *
  263. * encoderLine is the position based on the encoder
  264. * encoderTopLine is the top menu line to display
  265. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  266. * _menuLineNr is the menu item to draw and process
  267. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  268. * _countedItems is the total number of items in the menu (after one call)
  269. */
  270. #define START_SCREEN_OR_MENU(LIMIT) \
  271. ENCODER_DIRECTION_MENUS(); \
  272. ENCODER_RATE_MULTIPLY(false); \
  273. if (encoderPosition > 0x8000) encoderPosition = 0; \
  274. static int8_t _countedItems = 0; \
  275. int8_t encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
  276. if (_countedItems > 0 && encoderLine >= _countedItems - (LIMIT)) { \
  277. encoderLine = max(0, _countedItems - (LIMIT)); \
  278. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  279. }
  280. #define SCREEN_OR_MENU_LOOP() \
  281. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  282. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT - (TALL_FONT_CORRECTION); _lcdLineNr++, _menuLineNr++) { \
  283. _thisItemNr = 0
  284. /**
  285. * START_SCREEN Opening code for a screen having only static items.
  286. * Do simplified scrolling of the entire screen.
  287. *
  288. * START_MENU Opening code for a screen with menu items.
  289. * Scroll as-needed to keep the selected line in view.
  290. */
  291. #define START_SCREEN() \
  292. START_SCREEN_OR_MENU(LCD_HEIGHT - (TALL_FONT_CORRECTION)); \
  293. encoderTopLine = encoderLine; \
  294. bool _skipStatic = false; \
  295. SCREEN_OR_MENU_LOOP()
  296. #define START_MENU() \
  297. START_SCREEN_OR_MENU(1); \
  298. screen_changed = false; \
  299. NOMORE(encoderTopLine, encoderLine); \
  300. if (encoderLine >= encoderTopLine + LCD_HEIGHT - (TALL_FONT_CORRECTION)) { \
  301. encoderTopLine = encoderLine - (LCD_HEIGHT - (TALL_FONT_CORRECTION) - 1); \
  302. } \
  303. bool _skipStatic = true; \
  304. SCREEN_OR_MENU_LOOP()
  305. #define END_SCREEN() \
  306. } \
  307. _countedItems = _thisItemNr
  308. #define END_MENU() \
  309. } \
  310. _countedItems = _thisItemNr; \
  311. UNUSED(_skipStatic)
  312. ////////////////////////////////////////////
  313. ///////////// Global Variables /////////////
  314. ////////////////////////////////////////////
  315. /**
  316. * REVERSE_MENU_DIRECTION
  317. *
  318. * To reverse the menu direction we need a general way to reverse
  319. * the direction of the encoder everywhere. So encoderDirection is
  320. * added to allow the encoder to go the other way.
  321. *
  322. * This behavior is limited to scrolling Menus and SD card listings,
  323. * and is disabled in other contexts.
  324. */
  325. #if ENABLED(REVERSE_MENU_DIRECTION)
  326. int8_t encoderDirection = 1;
  327. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  328. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  329. #else
  330. #define ENCODER_DIRECTION_NORMAL() ;
  331. #define ENCODER_DIRECTION_MENUS() ;
  332. #endif
  333. // Encoder Movement
  334. volatile int8_t encoderDiff; // Updated in lcd_buttons_update, added to encoderPosition every LCD update
  335. uint32_t encoderPosition;
  336. millis_t lastEncoderMovementMillis = 0;
  337. // Button States
  338. bool lcd_clicked, wait_for_unclick;
  339. volatile uint8_t buttons;
  340. millis_t next_button_update_ms;
  341. #if ENABLED(REPRAPWORLD_KEYPAD)
  342. volatile uint8_t buttons_reprapworld_keypad;
  343. #endif
  344. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  345. volatile uint8_t slow_buttons;
  346. #endif
  347. // Menu System Navigation
  348. screenFunc_t currentScreen = lcd_status_screen;
  349. int8_t encoderTopLine;
  350. typedef struct {
  351. screenFunc_t menu_function;
  352. uint32_t encoder_position;
  353. } menuPosition;
  354. menuPosition screen_history[6];
  355. uint8_t screen_history_depth = 0;
  356. bool screen_changed, defer_return_to_status;
  357. // Value Editing
  358. const char *editLabel;
  359. void *editValue;
  360. int32_t minEditValue, maxEditValue;
  361. screenFunc_t callbackFunc;
  362. bool liveEdit;
  363. // Manual Moves
  364. const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
  365. millis_t manual_move_start_time = 0;
  366. int8_t manual_move_axis = (int8_t)NO_AXIS;
  367. #if EXTRUDERS > 1
  368. int8_t manual_move_e_index = 0;
  369. #else
  370. #define manual_move_e_index 0
  371. #endif
  372. #if PIN_EXISTS(SD_DETECT)
  373. uint8_t lcd_sd_status;
  374. #endif
  375. #if ENABLED(PIDTEMP)
  376. float raw_Ki, raw_Kd; // place-holders for Ki and Kd edits
  377. #endif
  378. /**
  379. * General function to go directly to a screen
  380. */
  381. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0) {
  382. if (currentScreen != screen) {
  383. #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
  384. static millis_t doubleclick_expire_ms = 0;
  385. // Going to lcd_main_menu from status screen? Remember first click time.
  386. // Going back to status screen within a very short time? Go to Z babystepping.
  387. if (screen == lcd_main_menu) {
  388. if (currentScreen == lcd_status_screen)
  389. doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
  390. }
  391. else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms))
  392. screen =
  393. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  394. lcd_babystep_zoffset
  395. #else
  396. lcd_babystep_z
  397. #endif
  398. ;
  399. #endif
  400. currentScreen = screen;
  401. encoderPosition = encoder;
  402. if (screen == lcd_status_screen) {
  403. defer_return_to_status = false;
  404. screen_history_depth = 0;
  405. }
  406. lcd_implementation_clear();
  407. #if ENABLED(LCD_PROGRESS_BAR)
  408. // For LCD_PROGRESS_BAR re-initialize custom characters
  409. lcd_set_custom_characters(screen == lcd_status_screen);
  410. #endif
  411. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  412. screen_changed = true;
  413. #if ENABLED(DOGLCD)
  414. drawing_screen = false;
  415. #endif
  416. }
  417. }
  418. /**
  419. * Show "Moving..." till moves are done, then revert to previous display.
  420. */
  421. static const char moving[] PROGMEM = MSG_MOVING;
  422. static const char *sync_message = moving;
  423. //
  424. // Display the synchronize screen until moves are
  425. // finished, and don't return to the caller until
  426. // done. ** This blocks the command queue! **
  427. //
  428. void _lcd_synchronize() {
  429. static bool no_reentry = false;
  430. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
  431. if (no_reentry) return;
  432. // Make this the current handler till all moves are done
  433. no_reentry = true;
  434. screenFunc_t old_screen = currentScreen;
  435. lcd_goto_screen(_lcd_synchronize);
  436. stepper.synchronize();
  437. no_reentry = false;
  438. lcd_goto_screen(old_screen);
  439. }
  440. // Display the synchronize screen with a custom message
  441. // ** This blocks the command queue! **
  442. void lcd_synchronize(const char * const msg=NULL) {
  443. sync_message = msg ? msg : moving;
  444. _lcd_synchronize();
  445. }
  446. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  447. void lcd_save_previous_screen() {
  448. if (screen_history_depth < COUNT(screen_history)) {
  449. screen_history[screen_history_depth].menu_function = currentScreen;
  450. screen_history[screen_history_depth].encoder_position = encoderPosition;
  451. ++screen_history_depth;
  452. }
  453. }
  454. void lcd_goto_previous_menu() {
  455. if (screen_history_depth > 0) {
  456. --screen_history_depth;
  457. lcd_goto_screen(
  458. screen_history[screen_history_depth].menu_function,
  459. screen_history[screen_history_depth].encoder_position
  460. );
  461. }
  462. else
  463. lcd_return_to_status();
  464. }
  465. #endif // ULTIPANEL
  466. /**
  467. *
  468. * "Info Screen"
  469. *
  470. * This is very display-dependent, so the lcd implementation draws this.
  471. */
  472. void lcd_status_screen() {
  473. #if ENABLED(ULTIPANEL)
  474. ENCODER_DIRECTION_NORMAL();
  475. ENCODER_RATE_MULTIPLY(false);
  476. #endif
  477. #if ENABLED(LCD_PROGRESS_BAR)
  478. millis_t ms = millis();
  479. #if DISABLED(PROGRESS_MSG_ONCE)
  480. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
  481. progress_bar_ms = ms;
  482. }
  483. #endif
  484. #if PROGRESS_MSG_EXPIRE > 0
  485. // Handle message expire
  486. if (expire_status_ms > 0) {
  487. #if ENABLED(SDSUPPORT)
  488. if (card.isFileOpen()) {
  489. // Expire the message when printing is active
  490. if (IS_SD_PRINTING) {
  491. if (ELAPSED(ms, expire_status_ms)) {
  492. lcd_status_message[0] = '\0';
  493. expire_status_ms = 0;
  494. }
  495. }
  496. else {
  497. expire_status_ms += LCD_UPDATE_INTERVAL;
  498. }
  499. }
  500. else {
  501. expire_status_ms = 0;
  502. }
  503. #else
  504. expire_status_ms = 0;
  505. #endif // SDSUPPORT
  506. }
  507. #endif
  508. #endif // LCD_PROGRESS_BAR
  509. #if ENABLED(ULTIPANEL)
  510. if (lcd_clicked) {
  511. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  512. previous_lcd_status_ms = millis(); // get status message to show up for a while
  513. #endif
  514. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  515. #if ENABLED(LCD_PROGRESS_BAR)
  516. false
  517. #endif
  518. );
  519. lcd_goto_screen(lcd_main_menu);
  520. return;
  521. }
  522. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  523. const int new_frm = feedrate_percentage + (int32_t)encoderPosition;
  524. // Dead zone at 100% feedrate
  525. if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
  526. feedrate_percentage = 100;
  527. encoderPosition = 0;
  528. }
  529. else if (feedrate_percentage == 100) {
  530. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  531. feedrate_percentage += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  532. encoderPosition = 0;
  533. }
  534. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  535. feedrate_percentage += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  536. encoderPosition = 0;
  537. }
  538. }
  539. else {
  540. feedrate_percentage = new_frm;
  541. encoderPosition = 0;
  542. }
  543. #endif // ULTIPANEL_FEEDMULTIPLY
  544. feedrate_percentage = constrain(feedrate_percentage, 10, 999);
  545. #endif // ULTIPANEL
  546. lcd_implementation_status_screen();
  547. }
  548. void lcd_reset_status() { lcd_setstatusPGM(PSTR(""), -1); }
  549. /**
  550. *
  551. * draw the kill screen
  552. *
  553. */
  554. void kill_screen(const char* lcd_msg) {
  555. lcd_init();
  556. lcd_setalertstatusPGM(lcd_msg);
  557. #if ENABLED(DOGLCD)
  558. u8g.firstPage();
  559. do {
  560. lcd_kill_screen();
  561. } while (u8g.nextPage());
  562. #else
  563. lcd_kill_screen();
  564. #endif
  565. }
  566. #if ENABLED(ULTIPANEL)
  567. /**
  568. *
  569. * Audio feedback for controller clicks
  570. *
  571. */
  572. void lcd_buzz(long duration, uint16_t freq) {
  573. #if ENABLED(LCD_USE_I2C_BUZZER)
  574. lcd.buzz(duration, freq);
  575. #elif PIN_EXISTS(BEEPER)
  576. buzzer.tone(duration, freq);
  577. #else
  578. UNUSED(duration); UNUSED(freq);
  579. #endif
  580. }
  581. void lcd_quick_feedback() {
  582. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  583. buttons = 0;
  584. next_button_update_ms = millis() + 500;
  585. // Buzz and wait. The delay is needed for buttons to settle!
  586. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  587. #if ENABLED(LCD_USE_I2C_BUZZER)
  588. delay(10);
  589. #elif PIN_EXISTS(BEEPER)
  590. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  591. #endif
  592. }
  593. void lcd_completion_feedback(const bool good/*=true*/) {
  594. if (good) {
  595. lcd_buzz(100, 659);
  596. lcd_buzz(100, 698);
  597. }
  598. else lcd_buzz(20, 440);
  599. }
  600. inline void line_to_current_z() {
  601. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[Z_AXIS]), active_extruder);
  602. }
  603. inline void line_to_z(const float &z) {
  604. current_position[Z_AXIS] = z;
  605. line_to_current_z();
  606. }
  607. #if ENABLED(SDSUPPORT)
  608. void lcd_sdcard_pause() {
  609. card.pauseSDPrint();
  610. print_job_timer.pause();
  611. #if ENABLED(PARK_HEAD_ON_PAUSE)
  612. enqueue_and_echo_commands_P(PSTR("M125"));
  613. #endif
  614. lcd_setstatusPGM(PSTR(MSG_PRINT_PAUSED), -1);
  615. }
  616. void lcd_sdcard_resume() {
  617. #if ENABLED(PARK_HEAD_ON_PAUSE)
  618. enqueue_and_echo_commands_P(PSTR("M24"));
  619. #else
  620. card.startFileprint();
  621. print_job_timer.start();
  622. #endif
  623. lcd_reset_status();
  624. }
  625. void lcd_sdcard_stop() {
  626. card.stopSDPrint();
  627. clear_command_queue();
  628. quickstop_stepper();
  629. print_job_timer.stop();
  630. thermalManager.disable_all_heaters();
  631. #if FAN_COUNT > 0
  632. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  633. #endif
  634. wait_for_heatup = false;
  635. lcd_setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1);
  636. lcd_return_to_status();
  637. }
  638. #endif // SDSUPPORT
  639. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  640. extern int case_light_brightness;
  641. extern bool case_light_on;
  642. extern void update_case_light();
  643. void case_light_menu() {
  644. START_MENU();
  645. //
  646. // ^ Main
  647. //
  648. MENU_BACK(MSG_MAIN);
  649. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CASE_LIGHT_BRIGHTNESS, &case_light_brightness, 0, 255, update_case_light, true);
  650. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  651. END_MENU();
  652. }
  653. #endif // MENU_ITEM_CASE_LIGHT
  654. #if ENABLED(BLTOUCH)
  655. /**
  656. *
  657. * "BLTouch" submenu
  658. *
  659. */
  660. static void bltouch_menu() {
  661. START_MENU();
  662. //
  663. // ^ Main
  664. //
  665. MENU_BACK(MSG_MAIN);
  666. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  667. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  668. MENU_ITEM(gcode, MSG_BLTOUCH_DEPLOY, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_DEPLOY)));
  669. MENU_ITEM(gcode, MSG_BLTOUCH_STOW, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_STOW)));
  670. END_MENU();
  671. }
  672. #endif // BLTOUCH
  673. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  674. static void progress_bar_test() {
  675. static int8_t bar_percent = 0;
  676. if (lcd_clicked) {
  677. lcd_goto_previous_menu();
  678. lcd_set_custom_characters(false);
  679. return;
  680. }
  681. bar_percent += (int8_t)encoderPosition;
  682. bar_percent = constrain(bar_percent, 0, 100);
  683. encoderPosition = 0;
  684. lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
  685. lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
  686. lcd.print(itostr3(bar_percent)); lcd.print('%');
  687. lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
  688. }
  689. void _progress_bar_test() {
  690. lcd_goto_screen(progress_bar_test);
  691. lcd_set_custom_characters();
  692. }
  693. #endif // LCD_PROGRESS_BAR_TEST
  694. #if HAS_DEBUG_MENU
  695. void lcd_debug_menu() {
  696. START_MENU();
  697. MENU_BACK(MSG_MAIN); // ^ Main
  698. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  699. MENU_ITEM(submenu, MSG_PROGRESS_BAR_TEST, _progress_bar_test);
  700. #endif
  701. END_MENU();
  702. }
  703. #endif // HAS_DEBUG_MENU
  704. #if ENABLED(CUSTOM_USER_MENUS)
  705. #ifdef USER_SCRIPT_DONE
  706. #define _DONE_SCRIPT "\n" USER_SCRIPT_DONE
  707. #else
  708. #define _DONE_SCRIPT ""
  709. #endif
  710. void _lcd_user_gcode(const char * const cmd) {
  711. lcd_return_to_status();
  712. enqueue_and_echo_commands_P(cmd);
  713. }
  714. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  715. void lcd_user_gcode_1() { _lcd_user_gcode(PSTR(USER_GCODE_1 _DONE_SCRIPT)); }
  716. #endif
  717. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  718. void lcd_user_gcode_2() { _lcd_user_gcode(PSTR(USER_GCODE_2 _DONE_SCRIPT)); }
  719. #endif
  720. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  721. void lcd_user_gcode_3() { _lcd_user_gcode(PSTR(USER_GCODE_3 _DONE_SCRIPT)); }
  722. #endif
  723. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  724. void lcd_user_gcode_4() { _lcd_user_gcode(PSTR(USER_GCODE_4 _DONE_SCRIPT)); }
  725. #endif
  726. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  727. void lcd_user_gcode_5() { _lcd_user_gcode(PSTR(USER_GCODE_5 _DONE_SCRIPT)); }
  728. #endif
  729. void _lcd_user_menu() {
  730. START_MENU();
  731. MENU_BACK(MSG_MAIN);
  732. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  733. MENU_ITEM(function, USER_DESC_1, lcd_user_gcode_1);
  734. #endif
  735. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  736. MENU_ITEM(function, USER_DESC_2, lcd_user_gcode_2);
  737. #endif
  738. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  739. MENU_ITEM(function, USER_DESC_3, lcd_user_gcode_3);
  740. #endif
  741. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  742. MENU_ITEM(function, USER_DESC_4, lcd_user_gcode_4);
  743. #endif
  744. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  745. MENU_ITEM(function, USER_DESC_5, lcd_user_gcode_5);
  746. #endif
  747. END_MENU();
  748. }
  749. #endif
  750. /**
  751. *
  752. * "Main" menu
  753. *
  754. */
  755. void lcd_main_menu() {
  756. START_MENU();
  757. MENU_BACK(MSG_WATCH);
  758. #if ENABLED(CUSTOM_USER_MENUS)
  759. MENU_ITEM(submenu, MSG_USER_MENU, _lcd_user_menu);
  760. #endif
  761. //
  762. // Debug Menu when certain options are enabled
  763. //
  764. #if HAS_DEBUG_MENU
  765. MENU_ITEM(submenu, MSG_DEBUG_MENU, lcd_debug_menu);
  766. #endif
  767. //
  768. // Set Case light on/off/brightness
  769. //
  770. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  771. if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) {
  772. MENU_ITEM(submenu, MSG_CASE_LIGHT, case_light_menu);
  773. }
  774. else
  775. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  776. #endif
  777. if (planner.movesplanned() || IS_SD_PRINTING) {
  778. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  779. }
  780. else {
  781. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  782. #if ENABLED(DELTA_CALIBRATION_MENU)
  783. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  784. #endif
  785. }
  786. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  787. #if ENABLED(SDSUPPORT)
  788. if (card.cardOK) {
  789. if (card.isFileOpen()) {
  790. if (card.sdprinting)
  791. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  792. else
  793. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  794. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  795. }
  796. else {
  797. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  798. #if !PIN_EXISTS(SD_DETECT)
  799. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  800. #endif
  801. }
  802. }
  803. else {
  804. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  805. #if !PIN_EXISTS(SD_DETECT)
  806. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  807. #endif
  808. }
  809. #endif // SDSUPPORT
  810. #if ENABLED(LCD_INFO_MENU)
  811. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  812. #endif
  813. END_MENU();
  814. }
  815. /**
  816. *
  817. * "Tune" submenu items
  818. *
  819. */
  820. #if HAS_M206_COMMAND
  821. /**
  822. * Set the home offset based on the current_position
  823. */
  824. void lcd_set_home_offsets() {
  825. // M428 Command
  826. enqueue_and_echo_commands_P(PSTR("M428"));
  827. lcd_return_to_status();
  828. }
  829. #endif
  830. #if ENABLED(BABYSTEPPING)
  831. void _lcd_babystep(const AxisEnum axis, const char* msg) {
  832. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  833. ENCODER_DIRECTION_NORMAL();
  834. if (encoderPosition) {
  835. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  836. encoderPosition = 0;
  837. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  838. thermalManager.babystep_axis(axis, babystep_increment);
  839. babysteps_done += babystep_increment;
  840. }
  841. if (lcdDrawUpdate)
  842. lcd_implementation_drawedit(msg, ftostr43sign(planner.steps_to_mm[axis] * babysteps_done));
  843. }
  844. #if ENABLED(BABYSTEP_XY)
  845. void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  846. void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  847. void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
  848. void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
  849. #endif
  850. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  851. void lcd_babystep_zoffset() {
  852. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  853. defer_return_to_status = true;
  854. ENCODER_DIRECTION_NORMAL();
  855. if (encoderPosition) {
  856. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  857. encoderPosition = 0;
  858. const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
  859. if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
  860. if (planner.abl_enabled)
  861. thermalManager.babystep_axis(Z_AXIS, babystep_increment);
  862. zprobe_zoffset = new_zoffset;
  863. refresh_zprobe_zoffset(true);
  864. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  865. }
  866. }
  867. if (lcdDrawUpdate)
  868. lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
  869. }
  870. #else // !BABYSTEP_ZPROBE_OFFSET
  871. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  872. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  873. #endif // !BABYSTEP_ZPROBE_OFFSET
  874. #endif // BABYSTEPPING
  875. #if ENABLED(AUTO_BED_LEVELING_UBL)
  876. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  877. // seperate value that doesn't lose precision.
  878. static int ubl_encoderPosition = 0;
  879. static void _lcd_mesh_fine_tune(const char* msg) {
  880. defer_return_to_status = true;
  881. if (ubl.encoder_diff) {
  882. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  883. ubl.encoder_diff = 0;
  884. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
  885. mesh_edit_value = mesh_edit_accumulator;
  886. encoderPosition = 0;
  887. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  888. const int32_t rounded = (int32_t)(mesh_edit_value * 1000.0);
  889. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
  890. }
  891. if (lcdDrawUpdate)
  892. lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
  893. }
  894. void _lcd_mesh_edit_NOP() {
  895. defer_return_to_status = true;
  896. }
  897. float lcd_mesh_edit() {
  898. lcd_goto_screen(_lcd_mesh_edit_NOP);
  899. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  900. _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
  901. return mesh_edit_value;
  902. }
  903. void lcd_mesh_edit_setup(float initial) {
  904. mesh_edit_value = mesh_edit_accumulator = initial;
  905. lcd_goto_screen(_lcd_mesh_edit_NOP);
  906. }
  907. void _lcd_z_offset_edit() {
  908. _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
  909. }
  910. float lcd_z_offset_edit() {
  911. lcd_goto_screen(_lcd_z_offset_edit);
  912. return mesh_edit_value;
  913. }
  914. void lcd_z_offset_edit_setup(float initial) {
  915. mesh_edit_value = mesh_edit_accumulator = initial;
  916. lcd_goto_screen(_lcd_z_offset_edit);
  917. }
  918. #endif // AUTO_BED_LEVELING_UBL
  919. /**
  920. * Watch temperature callbacks
  921. */
  922. #if HAS_TEMP_HOTEND
  923. #if WATCH_HOTENDS
  924. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  925. #else
  926. #define _WATCH_FUNC(N) NOOP
  927. #endif
  928. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  929. #if HOTENDS > 1
  930. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  931. #if HOTENDS > 2
  932. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  933. #if HOTENDS > 3
  934. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  935. #if HOTENDS > 4
  936. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  937. #endif // HOTENDS > 4
  938. #endif // HOTENDS > 3
  939. #endif // HOTENDS > 2
  940. #endif // HOTENDS > 1
  941. #endif // HAS_TEMP_HOTEND
  942. #if WATCH_THE_BED
  943. void watch_temp_callback_bed() { thermalManager.start_watching_bed(); }
  944. #endif
  945. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  946. void lcd_enqueue_filament_change() {
  947. if (!DEBUGGING(DRYRUN) && thermalManager.tooColdToExtrude(active_extruder)) {
  948. lcd_save_previous_screen();
  949. lcd_goto_screen(lcd_advanced_pause_toocold_menu);
  950. return;
  951. }
  952. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INIT);
  953. enqueue_and_echo_commands_P(PSTR("M600 B0"));
  954. }
  955. #endif // ADVANCED_PAUSE_FEATURE
  956. /**
  957. *
  958. * "Tune" submenu
  959. *
  960. */
  961. void lcd_tune_menu() {
  962. START_MENU();
  963. //
  964. // ^ Main
  965. //
  966. MENU_BACK(MSG_MAIN);
  967. //
  968. // Speed:
  969. //
  970. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  971. // Manual bed leveling, Bed Z:
  972. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  973. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  974. #endif
  975. //
  976. // Nozzle:
  977. // Nozzle [1-4]:
  978. //
  979. #if HOTENDS == 1
  980. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  981. #else // HOTENDS > 1
  982. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  983. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  984. #if HOTENDS > 2
  985. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  986. #if HOTENDS > 3
  987. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  988. #if HOTENDS > 4
  989. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  990. #endif // HOTENDS > 4
  991. #endif // HOTENDS > 3
  992. #endif // HOTENDS > 2
  993. #endif // HOTENDS > 1
  994. //
  995. // Bed:
  996. //
  997. #if WATCH_THE_BED
  998. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  999. #endif
  1000. //
  1001. // Fan Speed:
  1002. //
  1003. #if FAN_COUNT > 0
  1004. #if HAS_FAN0
  1005. #if FAN_COUNT > 1
  1006. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1007. #else
  1008. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1009. #endif
  1010. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1011. #endif
  1012. #if HAS_FAN1
  1013. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1014. #endif
  1015. #if HAS_FAN2
  1016. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1017. #endif
  1018. #endif // FAN_COUNT > 0
  1019. //
  1020. // Flow:
  1021. // Flow [1-5]:
  1022. //
  1023. #if EXTRUDERS == 1
  1024. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
  1025. #else // EXTRUDERS > 1
  1026. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
  1027. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
  1028. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &flow_percentage[1], 10, 999);
  1029. #if EXTRUDERS > 2
  1030. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &flow_percentage[2], 10, 999);
  1031. #if EXTRUDERS > 3
  1032. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &flow_percentage[3], 10, 999);
  1033. #if EXTRUDERS > 4
  1034. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &flow_percentage[4], 10, 999);
  1035. #endif // EXTRUDERS > 4
  1036. #endif // EXTRUDERS > 3
  1037. #endif // EXTRUDERS > 2
  1038. #endif // EXTRUDERS > 1
  1039. //
  1040. // Babystep X:
  1041. // Babystep Y:
  1042. // Babystep Z:
  1043. //
  1044. #if ENABLED(BABYSTEPPING)
  1045. #if ENABLED(BABYSTEP_XY)
  1046. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  1047. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  1048. #endif
  1049. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1050. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  1051. #else
  1052. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  1053. #endif
  1054. #endif
  1055. //
  1056. // Change filament
  1057. //
  1058. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1059. if (!thermalManager.tooColdToExtrude(active_extruder))
  1060. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  1061. #endif
  1062. END_MENU();
  1063. }
  1064. /**
  1065. *
  1066. * "Driver current control" submenu items
  1067. *
  1068. */
  1069. #if ENABLED(DAC_STEPPER_CURRENT)
  1070. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  1071. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  1072. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  1073. void lcd_dac_menu() {
  1074. dac_driver_getValues();
  1075. START_MENU();
  1076. MENU_BACK(MSG_CONTROL);
  1077. MENU_ITEM_EDIT_CALLBACK(int3, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  1078. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  1079. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  1080. MENU_ITEM_EDIT_CALLBACK(int3, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  1081. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  1082. END_MENU();
  1083. }
  1084. #endif
  1085. constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  1086. /**
  1087. *
  1088. * "Prepare" submenu items
  1089. *
  1090. */
  1091. void _lcd_preheat(const int endnum, const int16_t temph, const int16_t tempb, const int16_t fan) {
  1092. if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
  1093. #if TEMP_SENSOR_BED != 0
  1094. if (tempb >= 0) thermalManager.setTargetBed(tempb);
  1095. #else
  1096. UNUSED(tempb);
  1097. #endif
  1098. #if FAN_COUNT > 0
  1099. #if FAN_COUNT > 1
  1100. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  1101. #else
  1102. fanSpeeds[0] = fan;
  1103. #endif
  1104. #else
  1105. UNUSED(fan);
  1106. #endif
  1107. lcd_return_to_status();
  1108. }
  1109. #if TEMP_SENSOR_0 != 0
  1110. void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1111. void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1112. #if TEMP_SENSOR_BED != 0
  1113. void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1114. void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1115. #endif
  1116. #endif
  1117. #if HOTENDS > 1
  1118. void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1119. void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1120. #if TEMP_SENSOR_BED != 0
  1121. void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1122. void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1123. #endif
  1124. #if HOTENDS > 2
  1125. void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1126. void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1127. #if TEMP_SENSOR_BED != 0
  1128. void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1129. void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1130. #endif
  1131. #if HOTENDS > 3
  1132. void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1133. void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1134. #if TEMP_SENSOR_BED != 0
  1135. void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1136. void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1137. #endif
  1138. #if HOTENDS > 4
  1139. void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1140. void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1141. #if TEMP_SENSOR_BED != 0
  1142. void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1143. void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1144. #endif
  1145. #endif // HOTENDS > 4
  1146. #endif // HOTENDS > 3
  1147. #endif // HOTENDS > 2
  1148. void lcd_preheat_m1_all() {
  1149. #if HOTENDS > 1
  1150. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  1151. #if HOTENDS > 2
  1152. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  1153. #if HOTENDS > 3
  1154. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  1155. #if HOTENDS > 4
  1156. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 4);
  1157. #endif // HOTENDS > 4
  1158. #endif // HOTENDS > 3
  1159. #endif // HOTENDS > 2
  1160. #endif // HOTENDS > 1
  1161. #if TEMP_SENSOR_BED != 0
  1162. lcd_preheat_m1_e0();
  1163. #else
  1164. lcd_preheat_m1_e0_only();
  1165. #endif
  1166. }
  1167. void lcd_preheat_m2_all() {
  1168. #if HOTENDS > 1
  1169. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  1170. #if HOTENDS > 2
  1171. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  1172. #if HOTENDS > 3
  1173. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  1174. #if HOTENDS > 4
  1175. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 4);
  1176. #endif // HOTENDS > 4
  1177. #endif // HOTENDS > 3
  1178. #endif // HOTENDS > 2
  1179. #endif // HOTENDS > 1
  1180. #if TEMP_SENSOR_BED != 0
  1181. lcd_preheat_m2_e0();
  1182. #else
  1183. lcd_preheat_m2_e0_only();
  1184. #endif
  1185. }
  1186. #endif // HOTENDS > 1
  1187. #if TEMP_SENSOR_BED != 0
  1188. void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1189. void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1190. #endif
  1191. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0)
  1192. void lcd_preheat_m1_menu() {
  1193. START_MENU();
  1194. MENU_BACK(MSG_PREPARE);
  1195. #if HOTENDS == 1
  1196. #if TEMP_SENSOR_BED != 0
  1197. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
  1198. MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
  1199. #else
  1200. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1201. #endif
  1202. #else
  1203. #if TEMP_SENSOR_BED != 0
  1204. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
  1205. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
  1206. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
  1207. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E2, lcd_preheat_m1_e1_only);
  1208. #else
  1209. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0_only);
  1210. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
  1211. #endif
  1212. #if HOTENDS > 2
  1213. #if TEMP_SENSOR_BED != 0
  1214. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
  1215. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
  1216. #else
  1217. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
  1218. #endif
  1219. #if HOTENDS > 3
  1220. #if TEMP_SENSOR_BED != 0
  1221. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
  1222. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
  1223. #else
  1224. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
  1225. #endif
  1226. #if HOTENDS > 4
  1227. #if TEMP_SENSOR_BED != 0
  1228. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
  1229. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
  1230. #else
  1231. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4_only);
  1232. #endif
  1233. #endif // HOTENDS > 4
  1234. #endif // HOTENDS > 3
  1235. #endif // HOTENDS > 2
  1236. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
  1237. #endif // HOTENDS > 1
  1238. #if TEMP_SENSOR_BED != 0
  1239. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
  1240. #endif
  1241. END_MENU();
  1242. }
  1243. void lcd_preheat_m2_menu() {
  1244. START_MENU();
  1245. MENU_BACK(MSG_PREPARE);
  1246. #if HOTENDS == 1
  1247. #if TEMP_SENSOR_BED != 0
  1248. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
  1249. MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
  1250. #else
  1251. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1252. #endif
  1253. #else
  1254. #if TEMP_SENSOR_BED != 0
  1255. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
  1256. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
  1257. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
  1258. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E2, lcd_preheat_m2_e1_only);
  1259. #else
  1260. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0_only);
  1261. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
  1262. #endif
  1263. #if HOTENDS > 2
  1264. #if TEMP_SENSOR_BED != 0
  1265. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
  1266. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
  1267. #else
  1268. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
  1269. #endif
  1270. #if HOTENDS > 3
  1271. #if TEMP_SENSOR_BED != 0
  1272. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
  1273. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
  1274. #else
  1275. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
  1276. #endif
  1277. #if HOTENDS > 4
  1278. #if TEMP_SENSOR_BED != 0
  1279. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
  1280. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
  1281. #else
  1282. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4_only);
  1283. #endif
  1284. #endif // HOTENDS > 4
  1285. #endif // HOTENDS > 3
  1286. #endif // HOTENDS > 2
  1287. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
  1288. #endif // HOTENDS > 1
  1289. #if TEMP_SENSOR_BED != 0
  1290. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
  1291. #endif
  1292. END_MENU();
  1293. }
  1294. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_4 || TEMP_SENSOR_BED)
  1295. void lcd_cooldown() {
  1296. #if FAN_COUNT > 0
  1297. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  1298. #endif
  1299. thermalManager.disable_all_heaters();
  1300. lcd_return_to_status();
  1301. }
  1302. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1303. void lcd_autostart_sd() {
  1304. card.autostart_index = 0;
  1305. card.setroot();
  1306. card.checkautostart(true);
  1307. }
  1308. #endif
  1309. #if ENABLED(EEPROM_SETTINGS)
  1310. static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  1311. static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  1312. #endif
  1313. #if ENABLED(LCD_BED_LEVELING)
  1314. /**
  1315. *
  1316. * "Prepare" > "Level Bed" handlers
  1317. *
  1318. */
  1319. static uint8_t manual_probe_index;
  1320. // LCD probed points are from defaults
  1321. constexpr uint8_t total_probe_points = (
  1322. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  1323. 3
  1324. #elif ABL_GRID || ENABLED(MESH_BED_LEVELING)
  1325. GRID_MAX_POINTS
  1326. #endif
  1327. );
  1328. //
  1329. // Raise Z to the "manual probe height"
  1330. // Don't return until done.
  1331. // ** This blocks the command queue! **
  1332. //
  1333. void _lcd_after_probing() {
  1334. #if MANUAL_PROBE_HEIGHT > 0
  1335. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT);
  1336. #endif
  1337. // Display "Done" screen and wait for moves to complete
  1338. #if MANUAL_PROBE_HEIGHT > 0 || ENABLED(MESH_BED_LEVELING)
  1339. lcd_synchronize(PSTR(MSG_LEVEL_BED_DONE));
  1340. #endif
  1341. lcd_goto_previous_menu();
  1342. lcd_completion_feedback();
  1343. defer_return_to_status = false;
  1344. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  1345. }
  1346. #if ENABLED(MESH_BED_LEVELING)
  1347. // Utility to go to the next mesh point
  1348. inline void _manual_probe_goto_xy(float x, float y) {
  1349. #if MANUAL_PROBE_HEIGHT > 0
  1350. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT);
  1351. #endif
  1352. current_position[X_AXIS] = LOGICAL_X_POSITION(x);
  1353. current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
  1354. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1355. #if MANUAL_PROBE_HEIGHT > 0
  1356. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS));
  1357. #endif
  1358. lcd_synchronize();
  1359. }
  1360. #elif ENABLED(PROBE_MANUALLY)
  1361. bool lcd_wait_for_move;
  1362. //
  1363. // Bed leveling is done. Wait for G29 to complete.
  1364. // A flag is used so that this can release control
  1365. // and allow the command queue to be processed.
  1366. //
  1367. void _lcd_level_bed_done() {
  1368. if (!lcd_wait_for_move) _lcd_after_probing();
  1369. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  1370. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1371. }
  1372. #endif
  1373. void _lcd_level_goto_next_point();
  1374. /**
  1375. * Step 7: Get the Z coordinate, click goes to the next point or exits
  1376. */
  1377. void _lcd_level_bed_get_z() {
  1378. ENCODER_DIRECTION_NORMAL();
  1379. if (lcd_clicked) {
  1380. //
  1381. // Save the current Z position
  1382. //
  1383. #if ENABLED(MESH_BED_LEVELING)
  1384. //
  1385. // MBL records the position but doesn't move to the next one
  1386. //
  1387. mbl.set_zigzag_z(manual_probe_index, current_position[Z_AXIS]);
  1388. #endif
  1389. // If done...
  1390. if (++manual_probe_index >= total_probe_points) {
  1391. #if ENABLED(PROBE_MANUALLY)
  1392. //
  1393. // The last G29 will record and enable but not move.
  1394. //
  1395. lcd_wait_for_move = true;
  1396. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1397. lcd_goto_screen(_lcd_level_bed_done);
  1398. #elif ENABLED(MESH_BED_LEVELING)
  1399. _lcd_after_probing();
  1400. mbl.set_has_mesh(true);
  1401. mesh_probing_done();
  1402. #endif
  1403. }
  1404. else {
  1405. // MESH_BED_LEVELING: Z already stored, just move
  1406. // PROBE_MANUALLY: Send G29 to record Z, then move
  1407. _lcd_level_goto_next_point();
  1408. }
  1409. return;
  1410. }
  1411. //
  1412. // Encoder knob or keypad buttons adjust the Z position
  1413. //
  1414. if (encoderPosition) {
  1415. refresh_cmd_timeout();
  1416. const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP);
  1417. line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5));
  1418. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1419. encoderPosition = 0;
  1420. }
  1421. //
  1422. // Draw on first display, then only on Z change
  1423. //
  1424. if (lcdDrawUpdate) {
  1425. const float v = current_position[Z_AXIS];
  1426. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  1427. }
  1428. }
  1429. /**
  1430. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  1431. */
  1432. void _lcd_level_bed_moving() {
  1433. if (lcdDrawUpdate) {
  1434. char msg[10];
  1435. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  1436. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  1437. }
  1438. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1439. #if ENABLED(PROBE_MANUALLY)
  1440. if (!lcd_wait_for_move) lcd_goto_screen(_lcd_level_bed_get_z);
  1441. #endif
  1442. }
  1443. /**
  1444. * Step 5: Initiate a move to the next point
  1445. */
  1446. void _lcd_level_goto_next_point() {
  1447. // Set the menu to display ahead of blocking call
  1448. lcd_goto_screen(_lcd_level_bed_moving);
  1449. #if ENABLED(MESH_BED_LEVELING)
  1450. int8_t px, py;
  1451. mbl.zigzag(manual_probe_index, px, py);
  1452. // Controls the loop until the move is done
  1453. _manual_probe_goto_xy(
  1454. LOGICAL_X_POSITION(mbl.index_to_xpos[px]),
  1455. LOGICAL_Y_POSITION(mbl.index_to_ypos[py])
  1456. );
  1457. // After the blocking function returns, change menus
  1458. lcd_goto_screen(_lcd_level_bed_get_z);
  1459. #elif ENABLED(PROBE_MANUALLY)
  1460. // G29 Records Z, moves, and signals when it pauses
  1461. lcd_wait_for_move = true;
  1462. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1463. #endif
  1464. }
  1465. /**
  1466. * Step 4: Display "Click to Begin", wait for click
  1467. * Move to the first probe position
  1468. */
  1469. void _lcd_level_bed_homing_done() {
  1470. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1471. if (lcd_clicked) {
  1472. manual_probe_index = 0;
  1473. _lcd_level_goto_next_point();
  1474. }
  1475. }
  1476. /**
  1477. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1478. */
  1479. void _lcd_level_bed_homing() {
  1480. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1481. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1482. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1483. lcd_goto_screen(_lcd_level_bed_homing_done);
  1484. }
  1485. #if ENABLED(PROBE_MANUALLY)
  1486. extern bool g29_in_progress;
  1487. #endif
  1488. /**
  1489. * Step 2: Continue Bed Leveling...
  1490. */
  1491. void _lcd_level_bed_continue() {
  1492. defer_return_to_status = true;
  1493. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1494. lcd_goto_screen(_lcd_level_bed_homing);
  1495. enqueue_and_echo_commands_P(PSTR("G28"));
  1496. }
  1497. static bool _level_state;
  1498. void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(_level_state); }
  1499. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1500. void _lcd_set_z_fade_height() { set_z_fade_height(planner.z_fade_height); }
  1501. #endif
  1502. /**
  1503. * Step 1: Bed Level entry-point
  1504. * - Cancel
  1505. * - Auto Home (if homing needed)
  1506. * - Leveling On/Off (if data exists, and homed)
  1507. * - Level Bed >
  1508. * - Fade Height (Req: ENABLE_LEVELING_FADE_HEIGHT)
  1509. * - Mesh Z Offset (Req: MESH_BED_LEVELING)
  1510. * - Z Probe Offset (Req: HAS_BED_PROBE, Opt: BABYSTEP_ZPROBE_OFFSET)
  1511. * - Load Settings (Req: EEPROM_SETTINGS)
  1512. * - Save Settings (Req: EEPROM_SETTINGS)
  1513. */
  1514. void lcd_bed_leveling() {
  1515. START_MENU();
  1516. MENU_BACK(MSG_PREPARE);
  1517. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
  1518. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1519. else if (leveling_is_valid()) {
  1520. _level_state = leveling_is_active();
  1521. MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
  1522. }
  1523. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1524. set_z_fade_height(planner.z_fade_height);
  1525. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &planner.z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
  1526. #endif
  1527. //
  1528. // MBL Z Offset
  1529. //
  1530. #if ENABLED(MESH_BED_LEVELING)
  1531. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  1532. #endif
  1533. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1534. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  1535. #elif HAS_BED_PROBE
  1536. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  1537. #endif
  1538. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1539. #if ENABLED(EEPROM_SETTINGS)
  1540. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  1541. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  1542. #endif
  1543. END_MENU();
  1544. }
  1545. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1546. void _lcd_ubl_level_bed();
  1547. static int ubl_storage_slot = 0,
  1548. custom_bed_temp = 50,
  1549. custom_hotend_temp = 190,
  1550. side_points = 3,
  1551. ubl_fillin_amount = 5,
  1552. ubl_height_amount = 1,
  1553. n_edit_pts = 1,
  1554. x_plot = 0,
  1555. y_plot = 0;
  1556. /**
  1557. * UBL Build Custom Mesh Command
  1558. */
  1559. void _lcd_ubl_build_custom_mesh() {
  1560. char UBL_LCD_GCODE[20];
  1561. enqueue_and_echo_commands_P(PSTR("G28"));
  1562. #if WATCH_THE_BED
  1563. sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
  1564. enqueue_and_echo_command(UBL_LCD_GCODE);
  1565. #endif
  1566. sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
  1567. enqueue_and_echo_command(UBL_LCD_GCODE);
  1568. enqueue_and_echo_commands_P(PSTR("G29 P1"));
  1569. }
  1570. /**
  1571. * UBL Custom Mesh submenu
  1572. */
  1573. void _lcd_ubl_custom_mesh() {
  1574. START_MENU();
  1575. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1576. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_HOTEND_TEMP, &custom_hotend_temp, EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP - 10));
  1577. #if WATCH_THE_BED
  1578. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_BED_TEMP, &custom_bed_temp, BED_MINTEMP, (BED_MAXTEMP - 5));
  1579. #endif
  1580. MENU_ITEM(function, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
  1581. END_MENU();
  1582. }
  1583. /**
  1584. * UBL Adjust Mesh Height Command
  1585. */
  1586. void _lcd_ubl_adjust_height_cmd() {
  1587. char UBL_LCD_GCODE[16];
  1588. const int ind = ubl_height_amount < 0 ? 6 : 7;
  1589. strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6-"));
  1590. sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
  1591. enqueue_and_echo_command(UBL_LCD_GCODE);
  1592. }
  1593. /**
  1594. * UBL Adjust Mesh Height submenu
  1595. */
  1596. void _lcd_ubl_height_adjust_menu() {
  1597. START_MENU();
  1598. MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
  1599. MENU_ITEM_EDIT(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9);
  1600. MENU_ITEM(function, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_adjust_height_cmd);
  1601. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1602. END_MENU();
  1603. }
  1604. /**
  1605. * UBL Edit Mesh submenu
  1606. */
  1607. void _lcd_ubl_edit_mesh() {
  1608. START_MENU();
  1609. MENU_BACK(MSG_UBL_TOOLS);
  1610. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  1611. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
  1612. MENU_ITEM(submenu, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_height_adjust_menu);
  1613. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1614. END_MENU();
  1615. }
  1616. /**
  1617. * UBL Validate Custom Mesh Command
  1618. */
  1619. void _lcd_ubl_validate_custom_mesh() {
  1620. char UBL_LCD_GCODE[24];
  1621. const int temp =
  1622. #if WATCH_THE_BED
  1623. custom_bed_temp
  1624. #else
  1625. 0
  1626. #endif
  1627. ;
  1628. sprintf_P(UBL_LCD_GCODE, PSTR("G28\nG26 C B%i H%i P"), temp, custom_hotend_temp);
  1629. enqueue_and_echo_command(UBL_LCD_GCODE);
  1630. }
  1631. /**
  1632. * UBL Validate Mesh submenu
  1633. */
  1634. void _lcd_ubl_validate_mesh() {
  1635. START_MENU();
  1636. MENU_BACK(MSG_UBL_TOOLS);
  1637. #if WATCH_THE_BED
  1638. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_1_TEMP_BED) " H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1639. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_2_TEMP_BED) " H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1640. #else
  1641. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1642. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1643. #endif
  1644. MENU_ITEM(function, MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
  1645. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1646. END_MENU();
  1647. }
  1648. /**
  1649. * UBL Grid Leveling Command
  1650. */
  1651. void _lcd_ubl_grid_level_cmd() {
  1652. char UBL_LCD_GCODE[10];
  1653. sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
  1654. enqueue_and_echo_command(UBL_LCD_GCODE);
  1655. }
  1656. /**
  1657. * UBL Grid Leveling submenu
  1658. */
  1659. void _lcd_ubl_grid_level() {
  1660. START_MENU();
  1661. MENU_BACK(MSG_UBL_TOOLS);
  1662. MENU_ITEM_EDIT(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
  1663. MENU_ITEM(function, MSG_UBL_MESH_LEVEL, _lcd_ubl_grid_level_cmd);
  1664. END_MENU();
  1665. }
  1666. /**
  1667. * UBL Mesh Leveling submenu
  1668. */
  1669. void _lcd_ubl_mesh_leveling() {
  1670. START_MENU();
  1671. MENU_BACK(MSG_UBL_TOOLS);
  1672. MENU_ITEM(gcode, MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
  1673. MENU_ITEM(submenu, MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
  1674. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1675. END_MENU();
  1676. }
  1677. /**
  1678. * UBL Fill-in Amount Mesh Command
  1679. */
  1680. void _lcd_ubl_fillin_amount_cmd() {
  1681. char UBL_LCD_GCODE[16];
  1682. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
  1683. enqueue_and_echo_command(UBL_LCD_GCODE);
  1684. }
  1685. /**
  1686. * UBL Smart Fill-in Command
  1687. */
  1688. void _lcd_ubl_smart_fillin_cmd() {
  1689. char UBL_LCD_GCODE[12];
  1690. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 T0"));
  1691. enqueue_and_echo_command(UBL_LCD_GCODE);
  1692. }
  1693. /**
  1694. * UBL Fill-in Mesh submenu
  1695. */
  1696. void _lcd_ubl_fillin_menu() {
  1697. START_MENU();
  1698. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1699. MENU_ITEM_EDIT(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9);
  1700. MENU_ITEM(function, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_amount_cmd);
  1701. MENU_ITEM(function, MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
  1702. MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
  1703. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1704. END_MENU();
  1705. }
  1706. void _lcd_ubl_invalidate() {
  1707. ubl.invalidate();
  1708. SERIAL_PROTOCOLLNPGM("Mesh invalidated.");
  1709. }
  1710. /**
  1711. * UBL Build Mesh submenu
  1712. */
  1713. void _lcd_ubl_build_mesh() {
  1714. START_MENU();
  1715. MENU_BACK(MSG_UBL_TOOLS);
  1716. #if WATCH_THE_BED
  1717. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1718. "G28\n"
  1719. "M190 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\n"
  1720. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1721. "G29 P1\n"
  1722. "M104 S0\n"
  1723. "M140 S0"
  1724. ));
  1725. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1726. "G28\n"
  1727. "M190 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\n"
  1728. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1729. "G29 P1\n"
  1730. "M104 S0\n"
  1731. "M140 S0"
  1732. ));
  1733. #else
  1734. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1735. "G28\n"
  1736. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1737. "G29 P1\n"
  1738. "M104 S0"
  1739. ));
  1740. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1741. "G28\n"
  1742. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1743. "G29 P1\n"
  1744. "M104 S0"
  1745. ));
  1746. #endif
  1747. MENU_ITEM(submenu, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  1748. MENU_ITEM(gcode, MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  1749. MENU_ITEM(submenu, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_menu);
  1750. MENU_ITEM(gcode, MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
  1751. MENU_ITEM(function, MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  1752. MENU_ITEM(gcode, MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
  1753. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1754. END_MENU();
  1755. }
  1756. /**
  1757. * UBL Load Mesh Command
  1758. */
  1759. void _lcd_ubl_load_mesh_cmd() {
  1760. char UBL_LCD_GCODE[8];
  1761. sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
  1762. enqueue_and_echo_command(UBL_LCD_GCODE);
  1763. }
  1764. /**
  1765. * UBL Save Mesh Command
  1766. */
  1767. void _lcd_ubl_save_mesh_cmd() {
  1768. char UBL_LCD_GCODE[8];
  1769. sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
  1770. enqueue_and_echo_command(UBL_LCD_GCODE);
  1771. }
  1772. /**
  1773. * UBL Mesh Storage submenu
  1774. */
  1775. void _lcd_ubl_storage_mesh() {
  1776. START_MENU();
  1777. MENU_BACK(MSG_UBL_LEVEL_BED);
  1778. MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, 9);
  1779. MENU_ITEM(function, MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  1780. MENU_ITEM(function, MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  1781. END_MENU();
  1782. }
  1783. /**
  1784. * UBL LCD "radar" map homing
  1785. */
  1786. void _lcd_ubl_output_map_lcd();
  1787. void _lcd_ubl_map_homing() {
  1788. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1789. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1790. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1791. lcd_goto_screen(_lcd_ubl_output_map_lcd);
  1792. }
  1793. /**
  1794. * UBL LCD "radar" map point editing
  1795. */
  1796. void _lcd_ubl_map_lcd_edit_cmd() {
  1797. char ubl_lcd_gcode [50], str[10], str2[10];
  1798. ubl_lcd_map_control = true; // Used for returning to the map screen
  1799. dtostrf(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]), 0, 2, str);
  1800. dtostrf(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]), 0, 2, str2);
  1801. snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29 P4 X%s Y%s R%i"), str, str2, n_edit_pts);
  1802. enqueue_and_echo_command(ubl_lcd_gcode);
  1803. }
  1804. #if ENABLED(DOGLCD)
  1805. /**
  1806. * UBL LCD "radar" map data
  1807. */
  1808. #define MAP_UPPER_LEFT_CORNER_X 35 // These probably should be moved to the .h file But for now,
  1809. #define MAP_UPPER_LEFT_CORNER_Y 8 // it is easier to play with things having them here
  1810. #define MAP_MAX_PIXELS_X 53
  1811. #define MAP_MAX_PIXELS_Y 49
  1812. void _lcd_ubl_plot_drawing_prep() {
  1813. uint8_t i, j, x_offset, y_offset, x_map_pixels, y_map_pixels,
  1814. pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt, inverted_y;
  1815. /*********************************************************/
  1816. /************ Scale the box pixels appropriately *********/
  1817. /*********************************************************/
  1818. x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / GRID_MAX_POINTS_X) * GRID_MAX_POINTS_X;
  1819. y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / GRID_MAX_POINTS_Y) * GRID_MAX_POINTS_Y;
  1820. pixels_per_X_mesh_pnt = x_map_pixels / GRID_MAX_POINTS_X;
  1821. pixels_per_Y_mesh_pnt = y_map_pixels / GRID_MAX_POINTS_Y;
  1822. x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2;
  1823. y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
  1824. /*********************************************************/
  1825. /************ Clear the Mesh Map Box**********************/
  1826. /*********************************************************/
  1827. u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box
  1828. u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4);
  1829. u8g.setColorIndex(0); // Now actually clear the mesh map box
  1830. u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels);
  1831. /*********************************************************/
  1832. /************ Display Mesh Point Locations ***************/
  1833. /*********************************************************/
  1834. u8g.setColorIndex(1);
  1835. for (i = 0; i < GRID_MAX_POINTS_X; i++) {
  1836. for (j = 0; j < GRID_MAX_POINTS_Y; j++) {
  1837. u8g.drawBox(x_offset + i * pixels_per_X_mesh_pnt + pixels_per_X_mesh_pnt / 2,
  1838. y_offset + j * pixels_per_Y_mesh_pnt + pixels_per_Y_mesh_pnt / 2, 1, 1);
  1839. }
  1840. }
  1841. /*********************************************************/
  1842. /************ Fill in the Specified Mesh Point ***********/
  1843. /*********************************************************/
  1844. inverted_y = GRID_MAX_POINTS_Y - y_plot - 1; // The origin is typically in the lower right corner. We need to
  1845. // invert the Y to get it to plot in the right location.
  1846. u8g.drawBox(x_offset + x_plot * pixels_per_X_mesh_pnt, y_offset + inverted_y * pixels_per_Y_mesh_pnt,
  1847. pixels_per_X_mesh_pnt, pixels_per_Y_mesh_pnt);
  1848. /*********************************************************/
  1849. /************** Put Relevent Text on Display *************/
  1850. /*********************************************************/
  1851. // Show X and Y positions at top of screen
  1852. u8g.setColorIndex(1);
  1853. u8g.setPrintPos(5, 7);
  1854. lcd_print("X:");
  1855. lcd_print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
  1856. u8g.setPrintPos(74, 7);
  1857. lcd_print("Y:");
  1858. lcd_print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
  1859. // Print plot position
  1860. u8g.setPrintPos(5, 64);
  1861. lcd_print('(');
  1862. u8g.print(x_plot);
  1863. lcd_print(',');
  1864. u8g.print(y_plot);
  1865. lcd_print(')');
  1866. // Show the location value
  1867. u8g.setPrintPos(74, 64);
  1868. lcd_print("Z:");
  1869. if (!isnan(ubl.z_values[x_plot][y_plot])) {
  1870. lcd_print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
  1871. }
  1872. else {
  1873. lcd_print(" -----");
  1874. }
  1875. }
  1876. #endif // DOGLCD
  1877. /**
  1878. * UBL LCD Map Movement
  1879. */
  1880. void ubl_map_move_to_xy() {
  1881. current_position[X_AXIS] = LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]));
  1882. current_position[Y_AXIS] = LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]));
  1883. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1884. }
  1885. /**
  1886. * UBL LCD "radar" map
  1887. */
  1888. void set_current_from_steppers_for_axis(const AxisEnum axis);
  1889. void sync_plan_position();
  1890. void _lcd_ubl_output_map_lcd() {
  1891. static int step_scaler=0;
  1892. int32_t signed_enc_pos;
  1893. defer_return_to_status = true;
  1894. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]) {
  1895. if (lcd_clicked) { return _lcd_ubl_map_lcd_edit_cmd(); }
  1896. ENCODER_DIRECTION_NORMAL();
  1897. if (encoderPosition != 0) {
  1898. signed_enc_pos = (int32_t)encoderPosition;
  1899. step_scaler += signed_enc_pos;
  1900. x_plot = (x_plot + step_scaler / ENCODER_STEPS_PER_MENU_ITEM);
  1901. if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM)
  1902. step_scaler = 0;
  1903. refresh_cmd_timeout();
  1904. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1905. }
  1906. encoderPosition = 0;
  1907. // Encoder to the right (++)
  1908. if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
  1909. if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
  1910. // Encoder to the left (--)
  1911. if (x_plot <= GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1)) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
  1912. if (y_plot <= GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1)) y_plot = GRID_MAX_POINTS_Y - 1;
  1913. // Prevent underrun/overrun of plot numbers
  1914. x_plot = constrain(x_plot, GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1), GRID_MAX_POINTS_X + 1);
  1915. y_plot = constrain(y_plot, GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1), GRID_MAX_POINTS_Y + 1);
  1916. // Determine number of points to edit
  1917. #if IS_KINEMATIC
  1918. n_edit_pts = 9; //TODO: Delta accessible edit points
  1919. #else
  1920. if (x_plot < 1 || x_plot >= GRID_MAX_POINTS_X - 1)
  1921. if (y_plot < 1 || y_plot >= GRID_MAX_POINTS_Y - 1) n_edit_pts = 4; // Corners
  1922. else n_edit_pts = 6;
  1923. else if (y_plot < 1 || y_plot >= GRID_MAX_POINTS_Y - 1) n_edit_pts = 6; // Edges
  1924. else n_edit_pts = 9; // Field
  1925. #endif
  1926. if (lcdDrawUpdate) {
  1927. #if ENABLED(DOGLCD)
  1928. _lcd_ubl_plot_drawing_prep();
  1929. #else
  1930. _lcd_ubl_output_char_lcd();
  1931. #endif
  1932. ubl_map_move_to_xy(); // Move to current location
  1933. if (planner.movesplanned()>1) { // if the nozzle is moving, cancel the move. There is a new location
  1934. #define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
  1935. #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
  1936. DISABLE_STEPPER_DRIVER_INTERRUPT();
  1937. while (planner.blocks_queued()) planner.discard_current_block();
  1938. stepper.current_block = NULL;
  1939. planner.clear_block_buffer_runtime();
  1940. ENABLE_STEPPER_DRIVER_INTERRUPT();
  1941. set_current_from_steppers_for_axis(ALL_AXES);
  1942. sync_plan_position();
  1943. ubl_map_move_to_xy(); // Move to new location
  1944. }
  1945. }
  1946. safe_delay(10);
  1947. }
  1948. else lcd_goto_screen(_lcd_ubl_map_homing);
  1949. }
  1950. /**
  1951. * UBL Homing before LCD map
  1952. */
  1953. void _lcd_ubl_output_map_lcd_cmd() {
  1954. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
  1955. enqueue_and_echo_commands_P(PSTR("G28"));
  1956. lcd_goto_screen(_lcd_ubl_map_homing);
  1957. }
  1958. /**
  1959. * UBL Output map submenu
  1960. */
  1961. void _lcd_ubl_output_map() {
  1962. START_MENU();
  1963. MENU_BACK(MSG_UBL_LEVEL_BED);
  1964. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29 T0"));
  1965. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29 T1"));
  1966. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29 S-1"));
  1967. MENU_ITEM(function, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map_lcd_cmd);
  1968. END_MENU();
  1969. }
  1970. /**
  1971. * UBL Tools submenu
  1972. */
  1973. void _lcd_ubl_tools_menu() {
  1974. START_MENU();
  1975. MENU_BACK(MSG_UBL_LEVEL_BED);
  1976. MENU_ITEM(submenu, MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  1977. MENU_ITEM(submenu, MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  1978. MENU_ITEM(submenu, MSG_UBL_EDIT_MESH_MENU, _lcd_ubl_edit_mesh);
  1979. MENU_ITEM(submenu, MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  1980. END_MENU();
  1981. }
  1982. /**
  1983. * UBL System submenu
  1984. *
  1985. * Prepare
  1986. * - Unified Bed Leveling
  1987. * - Manually Build Mesh
  1988. * - Activate UBL
  1989. * - Deactivate UBL
  1990. * - Mesh Storage
  1991. * Memory Slot:
  1992. * Load Bed Mesh
  1993. * Save Bed Mesh
  1994. * - Output Map
  1995. * Topography to Host
  1996. * CSV for Spreadsheet
  1997. * Mesh Output Backup
  1998. * Output to LCD Grid
  1999. * - UBL Tools
  2000. * - Build Mesh
  2001. * Build PLA Mesh
  2002. * Build ABS Mesh
  2003. * - Build Custom Mesh
  2004. * Hotend Temp:
  2005. * Bed Temp:
  2006. * Build Custom Mesh
  2007. * Info Screen
  2008. * - Build Cold Mesh
  2009. * - Fill-in Mesh
  2010. * Fill-in Mesh
  2011. * Smart Fill-in
  2012. * Manual Fill-in
  2013. * Info Screen
  2014. * Continue Bed Mesh
  2015. * Invalidate All
  2016. * Invalidate Closest
  2017. * - Validate Mesh
  2018. * PLA Mesh Validation
  2019. * ABS Mesh Validation
  2020. * - Custom Mesh Validation
  2021. * Hotend Temp:
  2022. * Bed Temp:
  2023. * Validate Mesh
  2024. * Info Screen
  2025. * - Edit Mesh
  2026. * Fine Tune All
  2027. * Fine Tune Closest
  2028. * - Adjust Mesh Height
  2029. * Height Amount:
  2030. * Adjust Mesh Height
  2031. * Info Screen
  2032. * - Mesh Leveling
  2033. * 3-Point Mesh Leveling
  2034. * - Grid Mesh Leveling
  2035. * Side points:
  2036. * Level Mesh
  2037. * Info Screen
  2038. * - Output UBL Info
  2039. */
  2040. void _lcd_ubl_level_bed() {
  2041. START_MENU();
  2042. MENU_BACK(MSG_PREPARE);
  2043. MENU_ITEM(gcode, MSG_UBL_MANUAL_MESH, PSTR("G29 I999\nG29 P2 B T0"));
  2044. MENU_ITEM(gcode, MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
  2045. MENU_ITEM(gcode, MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
  2046. MENU_ITEM(submenu, MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  2047. MENU_ITEM(submenu, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  2048. MENU_ITEM(submenu, MSG_UBL_TOOLS, _lcd_ubl_tools_menu);
  2049. MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
  2050. END_MENU();
  2051. }
  2052. #endif // AUTO_BED_LEVELING_UBL
  2053. /**
  2054. *
  2055. * "Prepare" submenu
  2056. *
  2057. */
  2058. void lcd_prepare_menu() {
  2059. START_MENU();
  2060. //
  2061. // ^ Main
  2062. //
  2063. MENU_BACK(MSG_MAIN);
  2064. //
  2065. // Move Axis
  2066. //
  2067. #if ENABLED(DELTA)
  2068. if (axis_homed[Z_AXIS])
  2069. #endif
  2070. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  2071. //
  2072. // Auto Home
  2073. //
  2074. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2075. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  2076. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  2077. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  2078. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  2079. #endif
  2080. //
  2081. // Level Bed
  2082. //
  2083. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2084. MENU_ITEM(submenu, MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  2085. #elif ENABLED(LCD_BED_LEVELING)
  2086. #if ENABLED(PROBE_MANUALLY)
  2087. if (!g29_in_progress)
  2088. #endif
  2089. MENU_ITEM(submenu, MSG_BED_LEVELING, lcd_bed_leveling);
  2090. #endif
  2091. #if HAS_M206_COMMAND
  2092. //
  2093. // Set Home Offsets
  2094. //
  2095. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  2096. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  2097. #endif
  2098. //
  2099. // Disable Steppers
  2100. //
  2101. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  2102. //
  2103. // Change filament
  2104. //
  2105. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2106. if (!thermalManager.tooColdToExtrude(active_extruder))
  2107. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  2108. #endif
  2109. #if TEMP_SENSOR_0 != 0
  2110. //
  2111. // Cooldown
  2112. //
  2113. bool has_heat = false;
  2114. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  2115. #if HAS_TEMP_BED
  2116. if (thermalManager.target_temperature_bed) has_heat = true;
  2117. #endif
  2118. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  2119. //
  2120. // Preheat for Material 1 and 2
  2121. //
  2122. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0
  2123. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
  2124. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
  2125. #else
  2126. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  2127. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  2128. #endif
  2129. #endif // TEMP_SENSOR_0 != 0
  2130. //
  2131. // BLTouch Self-Test and Reset
  2132. //
  2133. #if ENABLED(BLTOUCH)
  2134. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  2135. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  2136. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  2137. #endif
  2138. //
  2139. // Switch power on/off
  2140. //
  2141. #if HAS_POWER_SWITCH
  2142. if (powersupply_on)
  2143. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  2144. else
  2145. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  2146. #endif
  2147. //
  2148. // Autostart
  2149. //
  2150. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  2151. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  2152. #endif
  2153. END_MENU();
  2154. }
  2155. float move_menu_scale;
  2156. #if ENABLED(DELTA_CALIBRATION_MENU)
  2157. void lcd_move_z();
  2158. void lcd_delta_calibrate_menu();
  2159. void _lcd_calibrate_homing() {
  2160. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  2161. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  2162. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2163. lcd_goto_previous_menu();
  2164. }
  2165. void _lcd_delta_calibrate_home() {
  2166. #if HAS_LEVELING
  2167. reset_bed_level(); // After calibration bed-level data is no longer valid
  2168. #endif
  2169. enqueue_and_echo_commands_P(PSTR("G28"));
  2170. lcd_goto_screen(_lcd_calibrate_homing);
  2171. }
  2172. // Move directly to the tower position with uninterpolated moves
  2173. // If we used interpolated moves it would cause this to become re-entrant
  2174. void _goto_tower_pos(const float &a) {
  2175. #if HAS_LEVELING
  2176. reset_bed_level(); // After calibration bed-level data is no longer valid
  2177. #endif
  2178. line_to_z(max(Z_HOMING_HEIGHT, Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5);
  2179. current_position[X_AXIS] = a < 0 ? LOGICAL_X_POSITION(X_HOME_POS) : cos(RADIANS(a)) * delta_calibration_radius;
  2180. current_position[Y_AXIS] = a < 0 ? LOGICAL_Y_POSITION(Y_HOME_POS) : sin(RADIANS(a)) * delta_calibration_radius;
  2181. line_to_current_z();
  2182. line_to_z(4.0);
  2183. lcd_synchronize();
  2184. move_menu_scale = 0.1;
  2185. lcd_goto_screen(lcd_move_z);
  2186. }
  2187. void _goto_tower_x() { _goto_tower_pos(210); }
  2188. void _goto_tower_y() { _goto_tower_pos(330); }
  2189. void _goto_tower_z() { _goto_tower_pos(90); }
  2190. void _goto_center() { _goto_tower_pos(-1); }
  2191. void lcd_delta_calibrate_menu() {
  2192. START_MENU();
  2193. MENU_BACK(MSG_MAIN);
  2194. #if ENABLED(DELTA_AUTO_CALIBRATION)
  2195. MENU_ITEM(gcode, MSG_DELTA_AUTO_CALIBRATE, PSTR("G33"));
  2196. MENU_ITEM(gcode, MSG_DELTA_HEIGHT_CALIBRATE, PSTR("G33 P1"));
  2197. #endif
  2198. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  2199. if (axis_homed[Z_AXIS]) {
  2200. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  2201. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  2202. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  2203. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  2204. }
  2205. END_MENU();
  2206. }
  2207. #endif // DELTA_CALIBRATION_MENU
  2208. /**
  2209. * If the most recent manual move hasn't been fed to the planner yet,
  2210. * and the planner can accept one, send immediately
  2211. */
  2212. inline void manage_manual_move() {
  2213. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  2214. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  2215. manual_move_axis = (int8_t)NO_AXIS;
  2216. }
  2217. }
  2218. /**
  2219. * Set a flag that lcd_update() should start a move
  2220. * to "current_position" after a short delay.
  2221. */
  2222. inline void manual_move_to_current(AxisEnum axis
  2223. #if E_MANUAL > 1
  2224. , int8_t eindex=-1
  2225. #endif
  2226. ) {
  2227. #if E_MANUAL > 1
  2228. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  2229. #endif
  2230. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  2231. manual_move_axis = (int8_t)axis;
  2232. }
  2233. /**
  2234. *
  2235. * "Prepare" > "Move Axis" submenu
  2236. *
  2237. */
  2238. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  2239. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2240. ENCODER_DIRECTION_NORMAL();
  2241. if (encoderPosition) {
  2242. refresh_cmd_timeout();
  2243. float min = current_position[axis] - 1000,
  2244. max = current_position[axis] + 1000;
  2245. #if HAS_SOFTWARE_ENDSTOPS
  2246. // Limit to software endstops, if enabled
  2247. if (soft_endstops_enabled) {
  2248. #if ENABLED(MIN_SOFTWARE_ENDSTOPS)
  2249. min = soft_endstop_min[axis];
  2250. #endif
  2251. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  2252. max = soft_endstop_max[axis];
  2253. #endif
  2254. }
  2255. #endif
  2256. // Get the new position
  2257. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  2258. // Delta limits XY based on the current offset from center
  2259. // This assumes the center is 0,0
  2260. #if ENABLED(DELTA)
  2261. if (axis != Z_AXIS) {
  2262. max = sqrt(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
  2263. min = -max;
  2264. }
  2265. #endif
  2266. // Limit only when trying to move towards the limit
  2267. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  2268. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  2269. manual_move_to_current(axis);
  2270. encoderPosition = 0;
  2271. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2272. }
  2273. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
  2274. }
  2275. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  2276. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  2277. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  2278. void _lcd_move_e(
  2279. #if E_MANUAL > 1
  2280. int8_t eindex=-1
  2281. #endif
  2282. ) {
  2283. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2284. ENCODER_DIRECTION_NORMAL();
  2285. if (encoderPosition) {
  2286. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  2287. encoderPosition = 0;
  2288. manual_move_to_current(E_AXIS
  2289. #if E_MANUAL > 1
  2290. , eindex
  2291. #endif
  2292. );
  2293. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2294. }
  2295. if (lcdDrawUpdate) {
  2296. PGM_P pos_label;
  2297. #if E_MANUAL == 1
  2298. pos_label = PSTR(MSG_MOVE_E);
  2299. #else
  2300. switch (eindex) {
  2301. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  2302. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  2303. #if E_MANUAL > 2
  2304. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  2305. #if E_MANUAL > 3
  2306. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  2307. #if E_MANUAL > 4
  2308. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  2309. #endif // E_MANUAL > 4
  2310. #endif // E_MANUAL > 3
  2311. #endif // E_MANUAL > 2
  2312. }
  2313. #endif // E_MANUAL > 1
  2314. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  2315. }
  2316. }
  2317. void lcd_move_e() { _lcd_move_e(); }
  2318. #if E_MANUAL > 1
  2319. void lcd_move_e0() { _lcd_move_e(0); }
  2320. void lcd_move_e1() { _lcd_move_e(1); }
  2321. #if E_MANUAL > 2
  2322. void lcd_move_e2() { _lcd_move_e(2); }
  2323. #if E_MANUAL > 3
  2324. void lcd_move_e3() { _lcd_move_e(3); }
  2325. #if E_MANUAL > 4
  2326. void lcd_move_e4() { _lcd_move_e(4); }
  2327. #endif // E_MANUAL > 4
  2328. #endif // E_MANUAL > 3
  2329. #endif // E_MANUAL > 2
  2330. #endif // E_MANUAL > 1
  2331. /**
  2332. *
  2333. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  2334. *
  2335. */
  2336. screenFunc_t _manual_move_func_ptr;
  2337. void lcd_move_menu_10mm() { move_menu_scale = 10.0; lcd_goto_screen(_manual_move_func_ptr); }
  2338. void lcd_move_menu_1mm() { move_menu_scale = 1.0; lcd_goto_screen(_manual_move_func_ptr); }
  2339. void lcd_move_menu_01mm() { move_menu_scale = 0.1; lcd_goto_screen(_manual_move_func_ptr); }
  2340. void _lcd_move_distance_menu(AxisEnum axis, screenFunc_t func) {
  2341. _manual_move_func_ptr = func;
  2342. START_MENU();
  2343. if (LCD_HEIGHT >= 4) {
  2344. switch(axis) {
  2345. case X_AXIS:
  2346. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  2347. case Y_AXIS:
  2348. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  2349. case Z_AXIS:
  2350. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  2351. default:
  2352. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  2353. }
  2354. }
  2355. MENU_BACK(MSG_MOVE_AXIS);
  2356. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  2357. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  2358. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  2359. END_MENU();
  2360. }
  2361. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  2362. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  2363. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  2364. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  2365. #if E_MANUAL > 1
  2366. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  2367. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  2368. #if E_MANUAL > 2
  2369. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  2370. #if E_MANUAL > 3
  2371. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  2372. #if E_MANUAL > 4
  2373. void lcd_move_get_e4_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e4); }
  2374. #endif // E_MANUAL > 4
  2375. #endif // E_MANUAL > 3
  2376. #endif // E_MANUAL > 2
  2377. #endif // E_MANUAL > 1
  2378. /**
  2379. *
  2380. * "Prepare" > "Move Axis" submenu
  2381. *
  2382. */
  2383. #if IS_KINEMATIC
  2384. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2385. #if ENABLED(DELTA)
  2386. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  2387. void lcd_lower_z_to_clip_height() {
  2388. line_to_z(delta_clip_start_height);
  2389. lcd_synchronize();
  2390. }
  2391. #else
  2392. #define _MOVE_XY_ALLOWED true
  2393. #endif
  2394. #else
  2395. #define _MOVE_XYZ_ALLOWED true
  2396. #define _MOVE_XY_ALLOWED true
  2397. #endif
  2398. void lcd_move_menu() {
  2399. START_MENU();
  2400. MENU_BACK(MSG_PREPARE);
  2401. if (_MOVE_XYZ_ALLOWED) {
  2402. if (_MOVE_XY_ALLOWED) {
  2403. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  2404. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  2405. }
  2406. #if ENABLED(DELTA)
  2407. else
  2408. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  2409. #endif
  2410. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  2411. }
  2412. else
  2413. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2414. #if ENABLED(SWITCHING_EXTRUDER)
  2415. if (active_extruder)
  2416. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  2417. else
  2418. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  2419. #endif
  2420. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  2421. #if E_MANUAL > 1
  2422. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  2423. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  2424. #if E_MANUAL > 2
  2425. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  2426. #if E_MANUAL > 3
  2427. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  2428. #if E_MANUAL > 4
  2429. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  2430. #endif // E_MANUAL > 4
  2431. #endif // E_MANUAL > 3
  2432. #endif // E_MANUAL > 2
  2433. #endif // E_MANUAL > 1
  2434. END_MENU();
  2435. }
  2436. /**
  2437. *
  2438. * "Control" submenu
  2439. *
  2440. */
  2441. #if HAS_LCD_CONTRAST
  2442. void lcd_callback_set_contrast() { set_lcd_contrast(lcd_contrast); }
  2443. #endif
  2444. static void lcd_factory_settings() {
  2445. settings.reset();
  2446. lcd_completion_feedback();
  2447. }
  2448. void lcd_control_menu() {
  2449. START_MENU();
  2450. MENU_BACK(MSG_MAIN);
  2451. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  2452. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  2453. MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
  2454. #if HAS_LCD_CONTRAST
  2455. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, (int*)&lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
  2456. #endif
  2457. #if ENABLED(FWRETRACT)
  2458. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  2459. #endif
  2460. #if ENABLED(DAC_STEPPER_CURRENT)
  2461. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  2462. #endif
  2463. #if ENABLED(BLTOUCH)
  2464. MENU_ITEM(submenu, MSG_BLTOUCH, bltouch_menu);
  2465. #endif
  2466. #if ENABLED(EEPROM_SETTINGS)
  2467. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2468. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2469. #endif
  2470. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, lcd_factory_settings);
  2471. #if ENABLED(EEPROM_SETTINGS)
  2472. MENU_ITEM(gcode, MSG_INIT_EEPROM, PSTR("M502\nM500")); // TODO: Add "Are You Sure?" step
  2473. #endif
  2474. END_MENU();
  2475. }
  2476. /**
  2477. *
  2478. * "Temperature" submenu
  2479. *
  2480. */
  2481. #if ENABLED(PID_AUTOTUNE_MENU)
  2482. #if ENABLED(PIDTEMP)
  2483. int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  2484. #endif
  2485. #if ENABLED(PIDTEMPBED)
  2486. int autotune_temp_bed = 70;
  2487. #endif
  2488. void _lcd_autotune(int e) {
  2489. char cmd[30];
  2490. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  2491. #if HAS_PID_FOR_BOTH
  2492. e < 0 ? autotune_temp_bed : autotune_temp[e]
  2493. #elif ENABLED(PIDTEMPBED)
  2494. autotune_temp_bed
  2495. #else
  2496. autotune_temp[e]
  2497. #endif
  2498. );
  2499. enqueue_and_echo_command(cmd);
  2500. }
  2501. #endif // PID_AUTOTUNE_MENU
  2502. #if ENABLED(PIDTEMP)
  2503. // Helpers for editing PID Ki & Kd values
  2504. // grab the PID value out of the temp variable; scale it; then update the PID driver
  2505. void copy_and_scalePID_i(int e) {
  2506. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2507. UNUSED(e);
  2508. #endif
  2509. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  2510. thermalManager.updatePID();
  2511. }
  2512. void copy_and_scalePID_d(int e) {
  2513. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2514. UNUSED(e);
  2515. #endif
  2516. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  2517. thermalManager.updatePID();
  2518. }
  2519. #define _DEFINE_PIDTEMP_BASE_FUNCS(N) \
  2520. void copy_and_scalePID_i_E ## N() { copy_and_scalePID_i(N); } \
  2521. void copy_and_scalePID_d_E ## N() { copy_and_scalePID_d(N); }
  2522. #if ENABLED(PID_AUTOTUNE_MENU)
  2523. #define DEFINE_PIDTEMP_FUNCS(N) \
  2524. _DEFINE_PIDTEMP_BASE_FUNCS(N); \
  2525. void lcd_autotune_callback_E ## N() { _lcd_autotune(N); } typedef void _pid_##N##_void
  2526. #else
  2527. #define DEFINE_PIDTEMP_FUNCS(N) _DEFINE_PIDTEMP_BASE_FUNCS(N) typedef void _pid_##N##_void
  2528. #endif
  2529. DEFINE_PIDTEMP_FUNCS(0);
  2530. #if ENABLED(PID_PARAMS_PER_HOTEND)
  2531. #if HOTENDS > 1
  2532. DEFINE_PIDTEMP_FUNCS(1);
  2533. #if HOTENDS > 2
  2534. DEFINE_PIDTEMP_FUNCS(2);
  2535. #if HOTENDS > 3
  2536. DEFINE_PIDTEMP_FUNCS(3);
  2537. #if HOTENDS > 4
  2538. DEFINE_PIDTEMP_FUNCS(4);
  2539. #endif // HOTENDS > 4
  2540. #endif // HOTENDS > 3
  2541. #endif // HOTENDS > 2
  2542. #endif // HOTENDS > 1
  2543. #endif // PID_PARAMS_PER_HOTEND
  2544. #endif // PIDTEMP
  2545. /**
  2546. *
  2547. * "Control" > "Temperature" submenu
  2548. *
  2549. */
  2550. void lcd_control_temperature_menu() {
  2551. START_MENU();
  2552. //
  2553. // ^ Control
  2554. //
  2555. MENU_BACK(MSG_CONTROL);
  2556. //
  2557. // Nozzle:
  2558. // Nozzle [1-5]:
  2559. //
  2560. #if HOTENDS == 1
  2561. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2562. #else // HOTENDS > 1
  2563. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2564. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  2565. #if HOTENDS > 2
  2566. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  2567. #if HOTENDS > 3
  2568. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  2569. #if HOTENDS > 4
  2570. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  2571. #endif // HOTENDS > 4
  2572. #endif // HOTENDS > 3
  2573. #endif // HOTENDS > 2
  2574. #endif // HOTENDS > 1
  2575. //
  2576. // Bed:
  2577. //
  2578. #if WATCH_THE_BED
  2579. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  2580. #endif
  2581. //
  2582. // Fan Speed:
  2583. //
  2584. #if FAN_COUNT > 0
  2585. #if HAS_FAN0
  2586. #if FAN_COUNT > 1
  2587. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  2588. #else
  2589. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  2590. #endif
  2591. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  2592. #endif
  2593. #if HAS_FAN1
  2594. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  2595. #endif
  2596. #if HAS_FAN2
  2597. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  2598. #endif
  2599. #endif // FAN_COUNT > 0
  2600. //
  2601. // Autotemp, Min, Max, Fact
  2602. //
  2603. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  2604. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  2605. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  2606. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  2607. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  2608. #endif
  2609. //
  2610. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  2611. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  2612. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  2613. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  2614. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  2615. // PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
  2616. //
  2617. #if ENABLED(PIDTEMP)
  2618. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  2619. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  2620. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  2621. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  2622. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  2623. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  2624. #if ENABLED(PID_EXTRUSION_SCALING)
  2625. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  2626. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  2627. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  2628. #else
  2629. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  2630. #endif
  2631. #if ENABLED(PID_AUTOTUNE_MENU)
  2632. #define PID_MENU_ITEMS(ELABEL, eindex) \
  2633. _PID_MENU_ITEMS(ELABEL, eindex); \
  2634. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  2635. #else
  2636. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  2637. #endif
  2638. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  2639. PID_MENU_ITEMS(" " MSG_E1, 0);
  2640. PID_MENU_ITEMS(" " MSG_E2, 1);
  2641. #if HOTENDS > 2
  2642. PID_MENU_ITEMS(" " MSG_E3, 2);
  2643. #if HOTENDS > 3
  2644. PID_MENU_ITEMS(" " MSG_E4, 3);
  2645. #if HOTENDS > 4
  2646. PID_MENU_ITEMS(" " MSG_E5, 4);
  2647. #endif // HOTENDS > 4
  2648. #endif // HOTENDS > 3
  2649. #endif // HOTENDS > 2
  2650. #else // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2651. PID_MENU_ITEMS("", 0);
  2652. #endif // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2653. #endif // PIDTEMP
  2654. //
  2655. // Preheat Material 1 conf
  2656. //
  2657. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  2658. //
  2659. // Preheat Material 2 conf
  2660. //
  2661. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  2662. END_MENU();
  2663. }
  2664. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  2665. #if HOTENDS > 4
  2666. #define MINTEMP_ALL MIN5(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP)
  2667. #define MAXTEMP_ALL MAX5(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP)
  2668. #elif HOTENDS > 3
  2669. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  2670. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  2671. #elif HOTENDS > 2
  2672. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  2673. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  2674. #elif HOTENDS > 1
  2675. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  2676. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  2677. #else
  2678. #define MINTEMP_ALL HEATER_0_MINTEMP
  2679. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  2680. #endif
  2681. START_MENU();
  2682. MENU_BACK(MSG_TEMPERATURE);
  2683. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  2684. #if TEMP_SENSOR_0 != 0
  2685. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  2686. #endif
  2687. #if TEMP_SENSOR_BED != 0
  2688. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  2689. #endif
  2690. #if ENABLED(EEPROM_SETTINGS)
  2691. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2692. #endif
  2693. END_MENU();
  2694. }
  2695. /**
  2696. *
  2697. * "Temperature" > "Preheat Material 1 conf" submenu
  2698. *
  2699. */
  2700. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  2701. /**
  2702. *
  2703. * "Temperature" > "Preheat Material 2 conf" submenu
  2704. *
  2705. */
  2706. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  2707. /**
  2708. *
  2709. * "Control" > "Motion" submenu
  2710. *
  2711. */
  2712. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  2713. #if ENABLED(DISTINCT_E_FACTORS)
  2714. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  2715. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  2716. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  2717. #if E_STEPPERS > 2
  2718. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  2719. #if E_STEPPERS > 3
  2720. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  2721. #if E_STEPPERS > 4
  2722. void _reset_e4_acceleration_rate() { _reset_e_acceleration_rate(4); }
  2723. #endif // E_STEPPERS > 4
  2724. #endif // E_STEPPERS > 3
  2725. #endif // E_STEPPERS > 2
  2726. #endif
  2727. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  2728. #if ENABLED(DISTINCT_E_FACTORS)
  2729. void _planner_refresh_e_positioning(const uint8_t e) {
  2730. if (e == active_extruder)
  2731. _planner_refresh_positioning();
  2732. else
  2733. planner.steps_to_mm[e] = 1.0 / planner.axis_steps_per_mm[e];
  2734. }
  2735. void _planner_refresh_e0_positioning() { _reset_e_acceleration_rate(0); }
  2736. void _planner_refresh_e1_positioning() { _reset_e_acceleration_rate(1); }
  2737. #if E_STEPPERS > 2
  2738. void _planner_refresh_e2_positioning() { _reset_e_acceleration_rate(2); }
  2739. #if E_STEPPERS > 3
  2740. void _planner_refresh_e3_positioning() { _reset_e_acceleration_rate(3); }
  2741. #if E_STEPPERS > 4
  2742. void _planner_refresh_e4_positioning() { _reset_e_acceleration_rate(4); }
  2743. #endif // E_STEPPERS > 4
  2744. #endif // E_STEPPERS > 3
  2745. #endif // E_STEPPERS > 2
  2746. #endif
  2747. #if HAS_BED_PROBE && DISABLED(BABYSTEP_ZPROBE_OFFSET)
  2748. static void lcd_refresh_zprobe_zoffset() { refresh_zprobe_zoffset(); }
  2749. #endif
  2750. // M203 / M205 Velocity options
  2751. void lcd_control_motion_velocity_menu() {
  2752. START_MENU();
  2753. MENU_BACK(MSG_MOTION);
  2754. // M203 Max Feedrate
  2755. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  2756. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  2757. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  2758. #if ENABLED(DISTINCT_E_FACTORS)
  2759. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  2760. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2761. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  2762. #if E_STEPPERS > 2
  2763. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  2764. #if E_STEPPERS > 3
  2765. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  2766. #if E_STEPPERS > 4
  2767. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
  2768. #endif // E_STEPPERS > 4
  2769. #endif // E_STEPPERS > 3
  2770. #endif // E_STEPPERS > 2
  2771. #else
  2772. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2773. #endif
  2774. // M205 S Min Feedrate
  2775. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  2776. // M205 T Min Travel Feedrate
  2777. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  2778. END_MENU();
  2779. }
  2780. // M201 / M204 Accelerations
  2781. void lcd_control_motion_acceleration_menu() {
  2782. START_MENU();
  2783. MENU_BACK(MSG_MOTION);
  2784. // M204 P Acceleration
  2785. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  2786. // M204 R Retract Acceleration
  2787. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  2788. // M204 T Travel Acceleration
  2789. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  2790. // M201 settings
  2791. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  2792. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  2793. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  2794. #if ENABLED(DISTINCT_E_FACTORS)
  2795. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  2796. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  2797. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  2798. #if E_STEPPERS > 2
  2799. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  2800. #if E_STEPPERS > 3
  2801. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  2802. #if E_STEPPERS > 4
  2803. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
  2804. #endif // E_STEPPERS > 4
  2805. #endif // E_STEPPERS > 3
  2806. #endif // E_STEPPERS > 2
  2807. #else
  2808. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  2809. #endif
  2810. END_MENU();
  2811. }
  2812. // M205 Jerk
  2813. void lcd_control_motion_jerk_menu() {
  2814. START_MENU();
  2815. MENU_BACK(MSG_MOTION);
  2816. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  2817. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  2818. #if ENABLED(DELTA)
  2819. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  2820. #else
  2821. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  2822. #endif
  2823. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  2824. END_MENU();
  2825. }
  2826. // M92 Steps-per-mm
  2827. void lcd_control_motion_steps_per_mm_menu() {
  2828. START_MENU();
  2829. MENU_BACK(MSG_MOTION);
  2830. MENU_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  2831. MENU_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  2832. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  2833. #if ENABLED(DISTINCT_E_FACTORS)
  2834. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  2835. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  2836. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  2837. #if E_STEPPERS > 2
  2838. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  2839. #if E_STEPPERS > 3
  2840. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  2841. #if E_STEPPERS > 4
  2842. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E5STEPS, &planner.axis_steps_per_mm[E_AXIS + 4], 5, 9999, _planner_refresh_e4_positioning);
  2843. #endif // E_STEPPERS > 4
  2844. #endif // E_STEPPERS > 3
  2845. #endif // E_STEPPERS > 2
  2846. #else
  2847. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  2848. #endif
  2849. END_MENU();
  2850. }
  2851. void lcd_control_motion_menu() {
  2852. START_MENU();
  2853. MENU_BACK(MSG_CONTROL);
  2854. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  2855. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  2856. #elif HAS_BED_PROBE
  2857. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  2858. #endif
  2859. // M203 / M205 - Feedrate items
  2860. MENU_ITEM(submenu, MSG_VELOCITY, lcd_control_motion_velocity_menu);
  2861. // M201 - Acceleration items
  2862. MENU_ITEM(submenu, MSG_ACCELERATION, lcd_control_motion_acceleration_menu);
  2863. // M205 - Max Jerk
  2864. MENU_ITEM(submenu, MSG_JERK, lcd_control_motion_jerk_menu);
  2865. // M92 - Steps Per mm
  2866. MENU_ITEM(submenu, MSG_STEPS_PER_MM, lcd_control_motion_steps_per_mm_menu);
  2867. // M540 S - Abort on endstop hit when SD printing
  2868. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  2869. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  2870. #endif
  2871. END_MENU();
  2872. }
  2873. /**
  2874. *
  2875. * "Control" > "Filament" submenu
  2876. *
  2877. */
  2878. void lcd_control_filament_menu() {
  2879. START_MENU();
  2880. MENU_BACK(MSG_CONTROL);
  2881. #if ENABLED(LIN_ADVANCE)
  2882. MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
  2883. #endif
  2884. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  2885. if (volumetric_enabled) {
  2886. #if EXTRUDERS == 1
  2887. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2888. #else // EXTRUDERS > 1
  2889. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2890. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  2891. #if EXTRUDERS > 2
  2892. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  2893. #if EXTRUDERS > 3
  2894. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  2895. #if EXTRUDERS > 4
  2896. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
  2897. #endif // EXTRUDERS > 4
  2898. #endif // EXTRUDERS > 3
  2899. #endif // EXTRUDERS > 2
  2900. #endif // EXTRUDERS > 1
  2901. }
  2902. END_MENU();
  2903. }
  2904. /**
  2905. *
  2906. * "Control" > "Retract" submenu
  2907. *
  2908. */
  2909. #if ENABLED(FWRETRACT)
  2910. void lcd_control_retract_menu() {
  2911. START_MENU();
  2912. MENU_BACK(MSG_CONTROL);
  2913. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  2914. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  2915. #if EXTRUDERS > 1
  2916. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  2917. #endif
  2918. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  2919. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  2920. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
  2921. #if EXTRUDERS > 1
  2922. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, -100, 100);
  2923. #endif
  2924. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  2925. END_MENU();
  2926. }
  2927. #endif // FWRETRACT
  2928. #if ENABLED(SDSUPPORT)
  2929. #if !PIN_EXISTS(SD_DETECT)
  2930. void lcd_sd_refresh() {
  2931. card.initsd();
  2932. encoderTopLine = 0;
  2933. }
  2934. #endif
  2935. void lcd_sd_updir() {
  2936. card.updir();
  2937. encoderTopLine = 0;
  2938. screen_changed = true;
  2939. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2940. }
  2941. /**
  2942. *
  2943. * "Print from SD" submenu
  2944. *
  2945. */
  2946. void lcd_sdcard_menu() {
  2947. ENCODER_DIRECTION_MENUS();
  2948. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  2949. const uint16_t fileCnt = card.getnrfilenames();
  2950. START_MENU();
  2951. MENU_BACK(MSG_MAIN);
  2952. card.getWorkDirName();
  2953. if (card.filename[0] == '/') {
  2954. #if !PIN_EXISTS(SD_DETECT)
  2955. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  2956. #endif
  2957. }
  2958. else {
  2959. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  2960. }
  2961. for (uint16_t i = 0; i < fileCnt; i++) {
  2962. if (_menuLineNr == _thisItemNr) {
  2963. const uint16_t nr =
  2964. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  2965. fileCnt - 1 -
  2966. #endif
  2967. i;
  2968. #if ENABLED(SDCARD_SORT_ALPHA)
  2969. card.getfilename_sorted(nr);
  2970. #else
  2971. card.getfilename(nr);
  2972. #endif
  2973. if (card.filenameIsDir)
  2974. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2975. else
  2976. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2977. }
  2978. else {
  2979. MENU_ITEM_DUMMY();
  2980. }
  2981. }
  2982. END_MENU();
  2983. }
  2984. #endif // SDSUPPORT
  2985. #if ENABLED(LCD_INFO_MENU)
  2986. #if ENABLED(PRINTCOUNTER)
  2987. /**
  2988. *
  2989. * About Printer > Statistics submenu
  2990. *
  2991. */
  2992. void lcd_info_stats_menu() {
  2993. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2994. char buffer[21];
  2995. printStatistics stats = print_job_timer.getStats();
  2996. START_SCREEN(); // 12345678901234567890
  2997. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  2998. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  2999. duration_t elapsed = stats.printTime;
  3000. elapsed.toString(buffer);
  3001. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  3002. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3003. elapsed = stats.longestPrint;
  3004. elapsed.toString(buffer);
  3005. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  3006. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3007. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int(stats.filamentUsed / 100) % 10);
  3008. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  3009. STATIC_ITEM("", false, false, buffer); // 125m
  3010. END_SCREEN();
  3011. }
  3012. #endif // PRINTCOUNTER
  3013. /**
  3014. *
  3015. * About Printer > Thermistors
  3016. *
  3017. */
  3018. void lcd_info_thermistors_menu() {
  3019. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3020. START_SCREEN();
  3021. #define THERMISTOR_ID TEMP_SENSOR_0
  3022. #include "thermistornames.h"
  3023. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  3024. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  3025. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  3026. #if TEMP_SENSOR_1 != 0
  3027. #undef THERMISTOR_ID
  3028. #define THERMISTOR_ID TEMP_SENSOR_1
  3029. #include "thermistornames.h"
  3030. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  3031. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  3032. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  3033. #endif
  3034. #if TEMP_SENSOR_2 != 0
  3035. #undef THERMISTOR_ID
  3036. #define THERMISTOR_ID TEMP_SENSOR_2
  3037. #include "thermistornames.h"
  3038. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  3039. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  3040. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  3041. #endif
  3042. #if TEMP_SENSOR_3 != 0
  3043. #undef THERMISTOR_ID
  3044. #define THERMISTOR_ID TEMP_SENSOR_3
  3045. #include "thermistornames.h"
  3046. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  3047. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  3048. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  3049. #endif
  3050. #if TEMP_SENSOR_4 != 0
  3051. #undef THERMISTOR_ID
  3052. #define THERMISTOR_ID TEMP_SENSOR_4
  3053. #include "thermistornames.h"
  3054. STATIC_ITEM("T4: " THERMISTOR_NAME, false, true);
  3055. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_4_MINTEMP), false);
  3056. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_4_MAXTEMP), false);
  3057. #endif
  3058. #if TEMP_SENSOR_BED != 0
  3059. #undef THERMISTOR_ID
  3060. #define THERMISTOR_ID TEMP_SENSOR_BED
  3061. #include "thermistornames.h"
  3062. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  3063. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  3064. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  3065. #endif
  3066. END_SCREEN();
  3067. }
  3068. /**
  3069. *
  3070. * About Printer > Board Info
  3071. *
  3072. */
  3073. void lcd_info_board_menu() {
  3074. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3075. START_SCREEN();
  3076. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  3077. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  3078. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  3079. #if POWER_SUPPLY == 0
  3080. STATIC_ITEM(MSG_INFO_PSU ": Generic", true);
  3081. #elif POWER_SUPPLY == 1
  3082. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  3083. #elif POWER_SUPPLY == 2
  3084. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  3085. #endif
  3086. END_SCREEN();
  3087. }
  3088. /**
  3089. *
  3090. * About Printer > Printer Info
  3091. *
  3092. */
  3093. void lcd_info_printer_menu() {
  3094. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3095. START_SCREEN();
  3096. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  3097. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  3098. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  3099. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  3100. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  3101. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  3102. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  3103. STATIC_ITEM(MSG_3POINT_LEVELING, true); // 3-Point Leveling
  3104. #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
  3105. STATIC_ITEM(MSG_LINEAR_LEVELING, true); // Linear Leveling
  3106. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  3107. STATIC_ITEM(MSG_BILINEAR_LEVELING, true); // Bi-linear Leveling
  3108. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  3109. STATIC_ITEM(MSG_UBL_LEVELING, true); // Unified Bed Leveling
  3110. #elif ENABLED(MESH_BED_LEVELING)
  3111. STATIC_ITEM(MSG_MESH_LEVELING, true); // Mesh Leveling
  3112. #endif
  3113. END_SCREEN();
  3114. }
  3115. /**
  3116. *
  3117. * "About Printer" submenu
  3118. *
  3119. */
  3120. void lcd_info_menu() {
  3121. START_MENU();
  3122. MENU_BACK(MSG_MAIN);
  3123. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  3124. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  3125. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  3126. #if ENABLED(PRINTCOUNTER)
  3127. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  3128. #endif
  3129. END_MENU();
  3130. }
  3131. #endif // LCD_INFO_MENU
  3132. /**
  3133. *
  3134. * Filament Change Feature Screens
  3135. *
  3136. */
  3137. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  3138. // Portions from STATIC_ITEM...
  3139. #define HOTEND_STATUS_ITEM() do { \
  3140. if (_menuLineNr == _thisItemNr) { \
  3141. if (lcdDrawUpdate) { \
  3142. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  3143. lcd_implementation_hotend_status(_lcdLineNr); \
  3144. } \
  3145. if (_skipStatic && encoderLine <= _thisItemNr) { \
  3146. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  3147. ++encoderLine; \
  3148. } \
  3149. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  3150. } \
  3151. ++_thisItemNr; \
  3152. }while(0)
  3153. void lcd_advanced_pause_toocold_menu() {
  3154. START_MENU();
  3155. STATIC_ITEM(MSG_HEATING_FAILED_LCD, true, true);
  3156. STATIC_ITEM(MSG_FILAMENT_CHANGE_MINTEMP STRINGIFY(EXTRUDE_MINTEMP) ".", false, false);
  3157. MENU_BACK(MSG_BACK);
  3158. #if LCD_HEIGHT > 4
  3159. STATIC_ITEM(" ");
  3160. #endif
  3161. HOTEND_STATUS_ITEM();
  3162. END_MENU();
  3163. }
  3164. void lcd_advanced_pause_resume_print() {
  3165. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_RESUME_PRINT;
  3166. }
  3167. void lcd_advanced_pause_extrude_more() {
  3168. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE;
  3169. }
  3170. void lcd_advanced_pause_option_menu() {
  3171. START_MENU();
  3172. #if LCD_HEIGHT > 2
  3173. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  3174. #endif
  3175. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_advanced_pause_resume_print);
  3176. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_advanced_pause_extrude_more);
  3177. END_MENU();
  3178. }
  3179. void lcd_advanced_pause_init_message() {
  3180. START_SCREEN();
  3181. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3182. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  3183. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  3184. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  3185. #define __FC_LINES_A 3
  3186. #else
  3187. #define __FC_LINES_A 2
  3188. #endif
  3189. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  3190. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  3191. #define _FC_LINES_A (__FC_LINES_A + 1)
  3192. #else
  3193. #define _FC_LINES_A __FC_LINES_A
  3194. #endif
  3195. #if LCD_HEIGHT > _FC_LINES_A + 1
  3196. STATIC_ITEM(" ");
  3197. #endif
  3198. HOTEND_STATUS_ITEM();
  3199. END_SCREEN();
  3200. }
  3201. void lcd_advanced_pause_unload_message() {
  3202. START_SCREEN();
  3203. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3204. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  3205. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  3206. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  3207. #define __FC_LINES_B 3
  3208. #else
  3209. #define __FC_LINES_B 2
  3210. #endif
  3211. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  3212. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  3213. #define _FC_LINES_B (__FC_LINES_B + 1)
  3214. #else
  3215. #define _FC_LINES_B __FC_LINES_B
  3216. #endif
  3217. #if LCD_HEIGHT > _FC_LINES_B + 1
  3218. STATIC_ITEM(" ");
  3219. #endif
  3220. HOTEND_STATUS_ITEM();
  3221. END_SCREEN();
  3222. }
  3223. void lcd_advanced_pause_wait_for_nozzles_to_heat() {
  3224. START_SCREEN();
  3225. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3226. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  3227. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  3228. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  3229. #define _FC_LINES_C 3
  3230. #else
  3231. #define _FC_LINES_C 2
  3232. #endif
  3233. #if LCD_HEIGHT > _FC_LINES_C + 1
  3234. STATIC_ITEM(" ");
  3235. #endif
  3236. HOTEND_STATUS_ITEM();
  3237. END_SCREEN();
  3238. }
  3239. void lcd_advanced_pause_heat_nozzle() {
  3240. START_SCREEN();
  3241. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3242. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  3243. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  3244. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  3245. #define _FC_LINES_D 3
  3246. #else
  3247. #define _FC_LINES_D 2
  3248. #endif
  3249. #if LCD_HEIGHT > _FC_LINES_D + 1
  3250. STATIC_ITEM(" ");
  3251. #endif
  3252. HOTEND_STATUS_ITEM();
  3253. END_SCREEN();
  3254. }
  3255. void lcd_advanced_pause_insert_message() {
  3256. START_SCREEN();
  3257. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3258. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  3259. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  3260. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  3261. #define __FC_LINES_E 3
  3262. #else
  3263. #define __FC_LINES_E 2
  3264. #endif
  3265. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  3266. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  3267. #define _FC_LINES_E (__FC_LINES_E + 1)
  3268. #else
  3269. #define _FC_LINES_E __FC_LINES_E
  3270. #endif
  3271. #if LCD_HEIGHT > _FC_LINES_E + 1
  3272. STATIC_ITEM(" ");
  3273. #endif
  3274. HOTEND_STATUS_ITEM();
  3275. END_SCREEN();
  3276. }
  3277. void lcd_advanced_pause_load_message() {
  3278. START_SCREEN();
  3279. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3280. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  3281. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  3282. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  3283. #define __FC_LINES_F 3
  3284. #else
  3285. #define __FC_LINES_F 2
  3286. #endif
  3287. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  3288. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  3289. #define _FC_LINES_F (__FC_LINES_F + 1)
  3290. #else
  3291. #define _FC_LINES_F __FC_LINES_F
  3292. #endif
  3293. #if LCD_HEIGHT > _FC_LINES_F + 1
  3294. STATIC_ITEM(" ");
  3295. #endif
  3296. HOTEND_STATUS_ITEM();
  3297. END_SCREEN();
  3298. }
  3299. void lcd_advanced_pause_extrude_message() {
  3300. START_SCREEN();
  3301. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3302. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  3303. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  3304. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  3305. #define __FC_LINES_G 3
  3306. #else
  3307. #define __FC_LINES_G 2
  3308. #endif
  3309. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  3310. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  3311. #define _FC_LINES_G (__FC_LINES_G + 1)
  3312. #else
  3313. #define _FC_LINES_G __FC_LINES_G
  3314. #endif
  3315. #if LCD_HEIGHT > _FC_LINES_G + 1
  3316. STATIC_ITEM(" ");
  3317. #endif
  3318. HOTEND_STATUS_ITEM();
  3319. END_SCREEN();
  3320. }
  3321. void lcd_advanced_pause_resume_message() {
  3322. START_SCREEN();
  3323. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3324. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  3325. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  3326. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  3327. #endif
  3328. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  3329. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  3330. #endif
  3331. END_SCREEN();
  3332. }
  3333. void lcd_advanced_pause_show_message(const AdvancedPauseMessage message) {
  3334. switch (message) {
  3335. case ADVANCED_PAUSE_MESSAGE_INIT:
  3336. defer_return_to_status = true;
  3337. lcd_goto_screen(lcd_advanced_pause_init_message);
  3338. break;
  3339. case ADVANCED_PAUSE_MESSAGE_UNLOAD:
  3340. defer_return_to_status = true;
  3341. lcd_goto_screen(lcd_advanced_pause_unload_message);
  3342. break;
  3343. case ADVANCED_PAUSE_MESSAGE_INSERT:
  3344. defer_return_to_status = true;
  3345. lcd_goto_screen(lcd_advanced_pause_insert_message);
  3346. break;
  3347. case ADVANCED_PAUSE_MESSAGE_LOAD:
  3348. defer_return_to_status = true;
  3349. lcd_goto_screen(lcd_advanced_pause_load_message);
  3350. break;
  3351. case ADVANCED_PAUSE_MESSAGE_EXTRUDE:
  3352. defer_return_to_status = true;
  3353. lcd_goto_screen(lcd_advanced_pause_extrude_message);
  3354. break;
  3355. case ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE:
  3356. defer_return_to_status = true;
  3357. lcd_goto_screen(lcd_advanced_pause_heat_nozzle);
  3358. break;
  3359. case ADVANCED_PAUSE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT:
  3360. defer_return_to_status = true;
  3361. lcd_goto_screen(lcd_advanced_pause_wait_for_nozzles_to_heat);
  3362. break;
  3363. case ADVANCED_PAUSE_MESSAGE_OPTION:
  3364. defer_return_to_status = true;
  3365. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_WAIT_FOR;
  3366. lcd_goto_screen(lcd_advanced_pause_option_menu);
  3367. break;
  3368. case ADVANCED_PAUSE_MESSAGE_RESUME:
  3369. defer_return_to_status = true;
  3370. lcd_goto_screen(lcd_advanced_pause_resume_message);
  3371. break;
  3372. case ADVANCED_PAUSE_MESSAGE_STATUS:
  3373. lcd_return_to_status();
  3374. break;
  3375. }
  3376. }
  3377. #endif // ADVANCED_PAUSE_FEATURE
  3378. /**
  3379. *
  3380. * Functions for editing single values
  3381. *
  3382. * The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value.
  3383. *
  3384. * For example, DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1) expands into these functions:
  3385. *
  3386. * bool _menu_edit_int3();
  3387. * void menu_edit_int3(); // edit int (interactively)
  3388. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  3389. * void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  3390. * void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  3391. * void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback, const bool live); // edit int with callback
  3392. *
  3393. * You can then use one of the menu macros to present the edit interface:
  3394. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  3395. *
  3396. * This expands into a more primitive menu item:
  3397. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3398. *
  3399. * ...which calls:
  3400. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3401. */
  3402. #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
  3403. bool _menu_edit_ ## _name() { \
  3404. ENCODER_DIRECTION_NORMAL(); \
  3405. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  3406. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  3407. if (lcdDrawUpdate) \
  3408. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
  3409. if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
  3410. _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
  3411. if (editValue != NULL) *((_type*)editValue) = value; \
  3412. if (liveEdit) (*callbackFunc)(); \
  3413. if (lcd_clicked) lcd_goto_previous_menu(); \
  3414. } \
  3415. return lcd_clicked; \
  3416. } \
  3417. void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
  3418. void menu_edit_callback_ ## _name() { if (_menu_edit_ ## _name()) (*callbackFunc)(); } \
  3419. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  3420. lcd_save_previous_screen(); \
  3421. \
  3422. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  3423. \
  3424. editLabel = pstr; \
  3425. editValue = ptr; \
  3426. minEditValue = minValue * _scale; \
  3427. maxEditValue = maxValue * _scale - minEditValue; \
  3428. encoderPosition = (*ptr) * _scale - minEditValue; \
  3429. } \
  3430. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  3431. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3432. currentScreen = menu_edit_ ## _name; \
  3433. } \
  3434. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live) { \
  3435. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3436. currentScreen = menu_edit_callback_ ## _name; \
  3437. callbackFunc = callback; \
  3438. liveEdit = live; \
  3439. } \
  3440. typedef void _name
  3441. DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1);
  3442. DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
  3443. DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0);
  3444. DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000.0);
  3445. DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01);
  3446. DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
  3447. DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
  3448. DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
  3449. DEFINE_MENU_EDIT_TYPE(unsigned long, long5, ftostr5rj, 0.01);
  3450. /**
  3451. *
  3452. * Handlers for RepRap World Keypad input
  3453. *
  3454. */
  3455. #if ENABLED(REPRAPWORLD_KEYPAD)
  3456. void _reprapworld_keypad_move(AxisEnum axis, int dir) {
  3457. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  3458. encoderPosition = dir;
  3459. switch (axis) {
  3460. case X_AXIS: lcd_move_x(); break;
  3461. case Y_AXIS: lcd_move_y(); break;
  3462. case Z_AXIS: lcd_move_z();
  3463. default: break;
  3464. }
  3465. }
  3466. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  3467. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  3468. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  3469. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  3470. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  3471. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  3472. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  3473. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  3474. inline void handle_reprapworld_keypad() {
  3475. static uint8_t keypad_debounce = 0;
  3476. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  3477. if (keypad_debounce > 0) keypad_debounce--;
  3478. }
  3479. else if (!keypad_debounce) {
  3480. keypad_debounce = 2;
  3481. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  3482. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  3483. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3484. #endif
  3485. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  3486. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  3487. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3488. #endif
  3489. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  3490. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  3491. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  3492. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  3493. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  3494. }
  3495. else {
  3496. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  3497. }
  3498. }
  3499. }
  3500. #endif // REPRAPWORLD_KEYPAD
  3501. /**
  3502. *
  3503. * Menu actions
  3504. *
  3505. */
  3506. void _menu_action_back() { lcd_goto_previous_menu(); }
  3507. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  3508. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  3509. void menu_action_function(screenFunc_t func) { (*func)(); }
  3510. #if ENABLED(SDSUPPORT)
  3511. void menu_action_sdfile(const char* filename, char* longFilename) {
  3512. UNUSED(longFilename);
  3513. card.openAndPrintFile(filename);
  3514. lcd_return_to_status();
  3515. }
  3516. void menu_action_sddirectory(const char* filename, char* longFilename) {
  3517. UNUSED(longFilename);
  3518. card.chdir(filename);
  3519. encoderPosition = 0;
  3520. screen_changed = true;
  3521. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3522. }
  3523. #endif // SDSUPPORT
  3524. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
  3525. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  3526. menu_action_setting_edit_bool(pstr, ptr);
  3527. (*callback)();
  3528. }
  3529. #endif // ULTIPANEL
  3530. void lcd_init() {
  3531. lcd_implementation_init(
  3532. #if ENABLED(LCD_PROGRESS_BAR)
  3533. true
  3534. #endif
  3535. );
  3536. #if ENABLED(NEWPANEL)
  3537. #if BUTTON_EXISTS(EN1)
  3538. SET_INPUT_PULLUP(BTN_EN1);
  3539. #endif
  3540. #if BUTTON_EXISTS(EN2)
  3541. SET_INPUT_PULLUP(BTN_EN2);
  3542. #endif
  3543. #if BUTTON_EXISTS(ENC)
  3544. SET_INPUT_PULLUP(BTN_ENC);
  3545. #endif
  3546. #if ENABLED(REPRAPWORLD_KEYPAD)
  3547. SET_OUTPUT(SHIFT_CLK);
  3548. OUT_WRITE(SHIFT_LD, HIGH);
  3549. SET_INPUT_PULLUP(SHIFT_OUT);
  3550. #endif
  3551. #if BUTTON_EXISTS(UP)
  3552. SET_INPUT(BTN_UP);
  3553. #endif
  3554. #if BUTTON_EXISTS(DWN)
  3555. SET_INPUT(BTN_DWN);
  3556. #endif
  3557. #if BUTTON_EXISTS(LFT)
  3558. SET_INPUT(BTN_LFT);
  3559. #endif
  3560. #if BUTTON_EXISTS(RT)
  3561. SET_INPUT(BTN_RT);
  3562. #endif
  3563. #else // !NEWPANEL
  3564. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  3565. SET_OUTPUT(SR_DATA_PIN);
  3566. SET_OUTPUT(SR_CLK_PIN);
  3567. #elif defined(SHIFT_CLK)
  3568. SET_OUTPUT(SHIFT_CLK);
  3569. OUT_WRITE(SHIFT_LD, HIGH);
  3570. OUT_WRITE(SHIFT_EN, LOW);
  3571. SET_INPUT_PULLUP(SHIFT_OUT);
  3572. #endif // SR_LCD_2W_NL
  3573. #endif // !NEWPANEL
  3574. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3575. SET_INPUT_PULLUP(SD_DETECT_PIN);
  3576. lcd_sd_status = 2; // UNKNOWN
  3577. #endif
  3578. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3579. slow_buttons = 0;
  3580. #endif
  3581. lcd_buttons_update();
  3582. #if ENABLED(ULTIPANEL)
  3583. encoderDiff = 0;
  3584. #endif
  3585. }
  3586. int lcd_strlen(const char* s) {
  3587. int i = 0, j = 0;
  3588. while (s[i]) {
  3589. if (PRINTABLE(s[i])) j++;
  3590. i++;
  3591. }
  3592. return j;
  3593. }
  3594. int lcd_strlen_P(const char* s) {
  3595. int j = 0;
  3596. while (pgm_read_byte(s)) {
  3597. if (PRINTABLE(pgm_read_byte(s))) j++;
  3598. s++;
  3599. }
  3600. return j;
  3601. }
  3602. bool lcd_blink() {
  3603. static uint8_t blink = 0;
  3604. static millis_t next_blink_ms = 0;
  3605. millis_t ms = millis();
  3606. if (ELAPSED(ms, next_blink_ms)) {
  3607. blink ^= 0xFF;
  3608. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  3609. }
  3610. return blink != 0;
  3611. }
  3612. /**
  3613. * Update the LCD, read encoder buttons, etc.
  3614. * - Read button states
  3615. * - Check the SD Card slot state
  3616. * - Act on RepRap World keypad input
  3617. * - Update the encoder position
  3618. * - Apply acceleration to the encoder position
  3619. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  3620. * - Reset the Info Screen timeout if there's any input
  3621. * - Update status indicators, if any
  3622. *
  3623. * Run the current LCD menu handler callback function:
  3624. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  3625. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  3626. * - Call the menu handler. Menu handlers should do the following:
  3627. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  3628. * (Encoder events automatically set lcdDrawUpdate for you.)
  3629. * - if (lcdDrawUpdate) { redraw }
  3630. * - Before exiting the handler set lcdDrawUpdate to:
  3631. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  3632. * - LCDVIEW_REDRAW_NOW to draw now (including remaining stripes).
  3633. * - LCDVIEW_CALL_REDRAW_NEXT to draw now and get LCDVIEW_REDRAW_NOW on the next loop.
  3634. * - LCDVIEW_CALL_NO_REDRAW to draw now and get LCDVIEW_NONE on the next loop.
  3635. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  3636. * so don't change lcdDrawUpdate without considering this.
  3637. *
  3638. * After the menu handler callback runs (or not):
  3639. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  3640. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  3641. *
  3642. * No worries. This function is only called from the main thread.
  3643. */
  3644. void lcd_update() {
  3645. #if ENABLED(ULTIPANEL)
  3646. static millis_t return_to_status_ms = 0;
  3647. manage_manual_move();
  3648. lcd_buttons_update();
  3649. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3650. const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
  3651. #else
  3652. constexpr bool UBL_CONDITION = true;
  3653. #endif
  3654. // If the action button is pressed...
  3655. if (UBL_CONDITION && LCD_CLICKED) {
  3656. if (!wait_for_unclick) { // If not waiting for a debounce release:
  3657. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  3658. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  3659. wait_for_user = false; // Any click clears wait for user
  3660. lcd_quick_feedback(); // Always make a click sound
  3661. }
  3662. }
  3663. else wait_for_unclick = false;
  3664. #endif
  3665. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3666. const bool sd_status = IS_SD_INSERTED;
  3667. if (sd_status != lcd_sd_status && lcd_detected()) {
  3668. if (sd_status) {
  3669. card.initsd();
  3670. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  3671. }
  3672. else {
  3673. card.release();
  3674. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  3675. }
  3676. lcd_sd_status = sd_status;
  3677. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3678. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  3679. #if ENABLED(LCD_PROGRESS_BAR)
  3680. currentScreen == lcd_status_screen
  3681. #endif
  3682. );
  3683. }
  3684. #endif // SDSUPPORT && SD_DETECT_PIN
  3685. const millis_t ms = millis();
  3686. if (ELAPSED(ms, next_lcd_update_ms)
  3687. #if ENABLED(DOGLCD)
  3688. || drawing_screen
  3689. #endif
  3690. ) {
  3691. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  3692. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  3693. lcd_implementation_update_indicators();
  3694. #endif
  3695. #if ENABLED(ULTIPANEL)
  3696. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3697. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  3698. #endif
  3699. #if ENABLED(REPRAPWORLD_KEYPAD)
  3700. handle_reprapworld_keypad();
  3701. #endif
  3702. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  3703. if (encoderPastThreshold || lcd_clicked) {
  3704. if (encoderPastThreshold) {
  3705. int32_t encoderMultiplier = 1;
  3706. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  3707. if (encoderRateMultiplierEnabled) {
  3708. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  3709. if (lastEncoderMovementMillis != 0) {
  3710. // Note that the rate is always calculated between two passes through the
  3711. // loop and that the abs of the encoderDiff value is tracked.
  3712. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  3713. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  3714. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  3715. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  3716. SERIAL_ECHO_START();
  3717. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  3718. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  3719. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  3720. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  3721. SERIAL_EOL();
  3722. #endif // ENCODER_RATE_MULTIPLIER_DEBUG
  3723. }
  3724. lastEncoderMovementMillis = ms;
  3725. } // encoderRateMultiplierEnabled
  3726. #endif // ENCODER_RATE_MULTIPLIER
  3727. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  3728. encoderDiff = 0;
  3729. }
  3730. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3731. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3732. }
  3733. #endif // ULTIPANEL
  3734. // We arrive here every ~100ms when idling often enough.
  3735. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  3736. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  3737. if (
  3738. #if ENABLED(ULTIPANEL)
  3739. currentScreen == lcd_status_screen &&
  3740. #endif
  3741. !lcd_status_update_delay--
  3742. ) {
  3743. lcd_status_update_delay = 9
  3744. #if ENABLED(DOGLCD)
  3745. + 3
  3746. #endif
  3747. ;
  3748. max_display_update_time--;
  3749. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3750. }
  3751. // then we want to use 1/2 of the time only.
  3752. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  3753. #if ENABLED(DOGLCD)
  3754. if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
  3755. #else
  3756. if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
  3757. #endif
  3758. {
  3759. #if ENABLED(DOGLCD)
  3760. if (!drawing_screen)
  3761. #endif
  3762. {
  3763. switch (lcdDrawUpdate) {
  3764. case LCDVIEW_CALL_NO_REDRAW:
  3765. lcdDrawUpdate = LCDVIEW_NONE;
  3766. break;
  3767. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  3768. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  3769. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3770. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  3771. case LCDVIEW_NONE:
  3772. break;
  3773. } // switch
  3774. }
  3775. #if ENABLED(ULTIPANEL)
  3776. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  3777. #else
  3778. #define CURRENTSCREEN() lcd_status_screen()
  3779. #endif
  3780. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  3781. if (!drawing_screen) {
  3782. u8g.firstPage();
  3783. drawing_screen = 1;
  3784. }
  3785. lcd_setFont(FONT_MENU);
  3786. u8g.setColorIndex(1);
  3787. CURRENTSCREEN();
  3788. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  3789. NOLESS(max_display_update_time, millis() - ms);
  3790. return;
  3791. }
  3792. #else
  3793. CURRENTSCREEN();
  3794. #endif
  3795. NOLESS(max_display_update_time, millis() - ms);
  3796. }
  3797. #if ENABLED(ULTIPANEL)
  3798. // Return to Status Screen after a timeout
  3799. if (currentScreen == lcd_status_screen || defer_return_to_status)
  3800. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3801. else if (ELAPSED(ms, return_to_status_ms))
  3802. lcd_return_to_status();
  3803. #endif // ULTIPANEL
  3804. #if ENABLED(DOGLCD)
  3805. if (!drawing_screen)
  3806. #endif
  3807. {
  3808. switch (lcdDrawUpdate) {
  3809. case LCDVIEW_CLEAR_CALL_REDRAW:
  3810. lcd_implementation_clear();
  3811. case LCDVIEW_CALL_REDRAW_NEXT:
  3812. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3813. break;
  3814. case LCDVIEW_REDRAW_NOW:
  3815. lcdDrawUpdate = LCDVIEW_NONE;
  3816. break;
  3817. case LCDVIEW_NONE:
  3818. break;
  3819. } // switch
  3820. }
  3821. } // ELAPSED(ms, next_lcd_update_ms)
  3822. }
  3823. void pad_message_string() {
  3824. uint8_t i = 0, j = 0;
  3825. char c;
  3826. while ((c = lcd_status_message[i]) && j < LCD_WIDTH) {
  3827. if (PRINTABLE(c)) j++;
  3828. i++;
  3829. }
  3830. if (true
  3831. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  3832. && j < LCD_WIDTH
  3833. #endif
  3834. ) {
  3835. // pad with spaces to fill up the line
  3836. while (j++ < LCD_WIDTH) lcd_status_message[i++] = ' ';
  3837. // chop off at the edge
  3838. lcd_status_message[--i] = '\0';
  3839. }
  3840. }
  3841. void lcd_finishstatus(bool persist=false) {
  3842. pad_message_string();
  3843. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  3844. UNUSED(persist);
  3845. #endif
  3846. #if ENABLED(LCD_PROGRESS_BAR)
  3847. progress_bar_ms = millis();
  3848. #if PROGRESS_MSG_EXPIRE > 0
  3849. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  3850. #endif
  3851. #endif
  3852. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3853. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  3854. previous_lcd_status_ms = millis(); //get status message to show up for a while
  3855. #endif
  3856. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  3857. status_scroll_pos = 0;
  3858. #endif
  3859. }
  3860. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  3861. void dontExpireStatus() { expire_status_ms = 0; }
  3862. #endif
  3863. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  3864. void lcd_setstatus(const char * const message, const bool persist) {
  3865. if (lcd_status_message_level > 0) return;
  3866. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  3867. lcd_finishstatus(persist);
  3868. }
  3869. void lcd_setstatusPGM(const char * const message, int8_t level) {
  3870. if (level < 0) level = lcd_status_message_level = 0;
  3871. if (level < lcd_status_message_level) return;
  3872. lcd_status_message_level = level;
  3873. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  3874. lcd_finishstatus(level > 0);
  3875. }
  3876. void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
  3877. if (level < lcd_status_message_level) return;
  3878. lcd_status_message_level = level;
  3879. va_list args;
  3880. va_start(args, fmt);
  3881. vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args);
  3882. va_end(args);
  3883. lcd_finishstatus(level > 0);
  3884. }
  3885. void lcd_setalertstatusPGM(const char * const message) {
  3886. lcd_setstatusPGM(message, 1);
  3887. #if ENABLED(ULTIPANEL)
  3888. lcd_return_to_status();
  3889. #endif
  3890. }
  3891. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  3892. #if HAS_LCD_CONTRAST
  3893. void set_lcd_contrast(const uint16_t value) {
  3894. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  3895. u8g.setContrast(lcd_contrast);
  3896. }
  3897. #endif
  3898. #if ENABLED(ULTIPANEL)
  3899. /**
  3900. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  3901. * These values are independent of which pins are used for EN_A and EN_B indications
  3902. * The rotary encoder part is also independent to the chipset used for the LCD
  3903. */
  3904. #if defined(EN_A) && defined(EN_B)
  3905. #define encrot0 0
  3906. #define encrot1 2
  3907. #define encrot2 3
  3908. #define encrot3 1
  3909. #endif
  3910. #define GET_BUTTON_STATES(DST) \
  3911. uint8_t new_##DST = 0; \
  3912. WRITE(SHIFT_LD, LOW); \
  3913. WRITE(SHIFT_LD, HIGH); \
  3914. for (int8_t i = 0; i < 8; i++) { \
  3915. new_##DST >>= 1; \
  3916. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  3917. WRITE(SHIFT_CLK, HIGH); \
  3918. WRITE(SHIFT_CLK, LOW); \
  3919. } \
  3920. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  3921. /**
  3922. * Read encoder buttons from the hardware registers
  3923. * Warning: This function is called from interrupt context!
  3924. */
  3925. void lcd_buttons_update() {
  3926. static uint8_t lastEncoderBits;
  3927. millis_t now = millis();
  3928. if (ELAPSED(now, next_button_update_ms)) {
  3929. #if ENABLED(NEWPANEL)
  3930. uint8_t newbutton = 0;
  3931. #if BUTTON_EXISTS(EN1)
  3932. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  3933. #endif
  3934. #if BUTTON_EXISTS(EN2)
  3935. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  3936. #endif
  3937. #if BUTTON_EXISTS(ENC)
  3938. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  3939. #endif
  3940. #if LCD_HAS_DIRECTIONAL_BUTTONS
  3941. // Manage directional buttons
  3942. #if ENABLED(REVERSE_MENU_DIRECTION)
  3943. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  3944. #else
  3945. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  3946. #endif
  3947. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  3948. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  3949. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  3950. #else
  3951. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  3952. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  3953. #endif
  3954. if (false) {
  3955. // for the else-ifs below
  3956. }
  3957. #if BUTTON_EXISTS(UP)
  3958. else if (BUTTON_PRESSED(UP)) {
  3959. encoderDiff = -(ENCODER_UD_STEPS);
  3960. next_button_update_ms = now + 300;
  3961. }
  3962. #endif
  3963. #if BUTTON_EXISTS(DWN)
  3964. else if (BUTTON_PRESSED(DWN)) {
  3965. encoderDiff = ENCODER_UD_STEPS;
  3966. next_button_update_ms = now + 300;
  3967. }
  3968. #endif
  3969. #if BUTTON_EXISTS(LFT)
  3970. else if (BUTTON_PRESSED(LFT)) {
  3971. encoderDiff = -(ENCODER_LR_PULSES);
  3972. next_button_update_ms = now + 300;
  3973. }
  3974. #endif
  3975. #if BUTTON_EXISTS(RT)
  3976. else if (BUTTON_PRESSED(RT)) {
  3977. encoderDiff = ENCODER_LR_PULSES;
  3978. next_button_update_ms = now + 300;
  3979. }
  3980. #endif
  3981. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  3982. buttons = newbutton;
  3983. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3984. buttons |= slow_buttons;
  3985. #endif
  3986. #if ENABLED(REPRAPWORLD_KEYPAD)
  3987. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  3988. #endif
  3989. #else
  3990. GET_BUTTON_STATES(buttons);
  3991. #endif // !NEWPANEL
  3992. } // next_button_update_ms
  3993. // Manage encoder rotation
  3994. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  3995. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  3996. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  3997. #elif ENABLED(REVERSE_MENU_DIRECTION)
  3998. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  3999. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  4000. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  4001. #define ENCODER_DIFF_CW (encoderDiff--)
  4002. #define ENCODER_DIFF_CCW (encoderDiff++)
  4003. #else
  4004. #define ENCODER_DIFF_CW (encoderDiff++)
  4005. #define ENCODER_DIFF_CCW (encoderDiff--)
  4006. #endif
  4007. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  4008. uint8_t enc = 0;
  4009. if (buttons & EN_A) enc |= B01;
  4010. if (buttons & EN_B) enc |= B10;
  4011. if (enc != lastEncoderBits) {
  4012. switch (enc) {
  4013. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  4014. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  4015. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  4016. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  4017. }
  4018. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4019. if (ubl.has_control_of_lcd_panel) {
  4020. ubl.encoder_diff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
  4021. encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
  4022. // knob has not turned.
  4023. }
  4024. #endif
  4025. lastEncoderBits = enc;
  4026. }
  4027. }
  4028. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  4029. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  4030. #else
  4031. bool lcd_detected() { return true; }
  4032. #endif
  4033. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4034. void chirp_at_user() {
  4035. #if ENABLED(LCD_USE_I2C_BUZZER)
  4036. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4037. #elif PIN_EXISTS(BEEPER)
  4038. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4039. #endif
  4040. }
  4041. bool ubl_lcd_clicked() { return LCD_CLICKED; }
  4042. #endif
  4043. #endif // ULTIPANEL
  4044. #endif // ULTRA_LCD