My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ultralcd.cpp 175KB

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