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

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