My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ultralcd.cpp 167KB

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