My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 170KB

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