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 169KB

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