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

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