My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ultralcd.cpp 174KB

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