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

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