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

ultralcd.cpp 166KB

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