ultralcd.cpp 262 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879
  1. //! @file
  2. //! @date Aug 28, 2019
  3. //! @author mkbel
  4. //! @brief LCD
  5. #include "temperature.h"
  6. #include "ultralcd.h"
  7. #include "fsensor.h"
  8. #include "Marlin.h"
  9. #include "language.h"
  10. #include "cardreader.h"
  11. #include "temperature.h"
  12. #include "stepper.h"
  13. #include "ConfigurationStore.h"
  14. #include "printers.h"
  15. #include <string.h>
  16. #include "lcd.h"
  17. #include "menu.h"
  18. #include "backlight.h"
  19. #include "util.h"
  20. #include "mesh_bed_leveling.h"
  21. #include "mesh_bed_calibration.h"
  22. //#include "Configuration.h"
  23. #include "cmdqueue.h"
  24. #include "SdFatUtil.h"
  25. #ifdef FILAMENT_SENSOR
  26. #include "pat9125.h"
  27. #include "fsensor.h"
  28. #endif //FILAMENT_SENSOR
  29. #ifdef TMC2130
  30. #include "tmc2130.h"
  31. #endif //TMC2130
  32. #include "sound.h"
  33. #include "mmu.h"
  34. #include "static_assert.h"
  35. #include "first_lay_cal.h"
  36. #include "fsensor.h"
  37. #include "adc.h"
  38. #include "config.h"
  39. #ifndef LA_NOCOMPAT
  40. #include "la10compat.h"
  41. #endif
  42. static void lcd_sd_updir();
  43. static void lcd_mesh_bed_leveling_settings();
  44. static void lcd_backlight_menu();
  45. int8_t ReInitLCD = 0;
  46. uint8_t scrollstuff = 0;
  47. int8_t SilentModeMenu = SILENT_MODE_OFF;
  48. uint8_t SilentModeMenu_MMU = 1; //activate mmu unit stealth mode
  49. int8_t FSensorStateMenu = 1;
  50. #ifdef IR_SENSOR_ANALOG
  51. bool bMenuFSDetect=false;
  52. #endif //IR_SENSOR_ANALOG
  53. LcdCommands lcd_commands_type = LcdCommands::Idle;
  54. static uint8_t lcd_commands_step = 0;
  55. CustomMsg custom_message_type = CustomMsg::Status;
  56. unsigned int custom_message_state = 0;
  57. bool isPrintPaused = false;
  58. uint8_t farm_mode = 0;
  59. int farm_timer = 8;
  60. uint8_t farm_status = 0;
  61. bool printer_connected = true;
  62. unsigned long display_time; //just timer for showing pid finished message on lcd;
  63. float pid_temp = DEFAULT_PID_TEMP;
  64. static bool forceMenuExpire = false;
  65. static bool lcd_autoDeplete;
  66. static float manual_feedrate[] = MANUAL_FEEDRATE;
  67. /* !Configuration settings */
  68. uint8_t lcd_status_message_level;
  69. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  70. unsigned char firstrun = 1;
  71. static uint8_t lay1cal_filament = 0;
  72. static const char separator[] PROGMEM = "--------------------";
  73. /** forward declarations **/
  74. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines);
  75. // void copy_and_scalePID_i();
  76. // void copy_and_scalePID_d();
  77. /* Different menus */
  78. //static void lcd_status_screen(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  79. #if (LANG_MODE != 0)
  80. static void lcd_language_menu();
  81. #endif
  82. static void lcd_main_menu();
  83. static void lcd_tune_menu();
  84. //static void lcd_move_menu();
  85. static void lcd_settings_menu();
  86. static void lcd_calibration_menu();
  87. static void lcd_control_temperature_menu();
  88. static void lcd_settings_linearity_correction_menu_save();
  89. static void prusa_stat_printerstatus(int _status);
  90. static void prusa_stat_farm_number();
  91. static void prusa_stat_diameter();
  92. static void prusa_stat_temperatures();
  93. static void prusa_stat_printinfo();
  94. static void lcd_menu_xyz_y_min();
  95. static void lcd_menu_xyz_skew();
  96. static void lcd_menu_xyz_offset();
  97. static void lcd_menu_fails_stats_mmu();
  98. static void lcd_menu_fails_stats_mmu_print();
  99. static void lcd_menu_fails_stats_mmu_total();
  100. static void mmu_unload_filament();
  101. static void lcd_v2_calibration();
  102. //static void lcd_menu_show_sensors_state(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  103. static void mmu_fil_eject_menu();
  104. static void mmu_load_to_nozzle_menu();
  105. static void preheat_or_continue();
  106. #ifdef MMU_HAS_CUTTER
  107. static void mmu_cut_filament_menu();
  108. #endif //MMU_HAS_CUTTER
  109. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  110. static void lcd_menu_fails_stats();
  111. #endif //TMC2130 or FILAMENT_SENSOR
  112. #ifdef TMC2130
  113. static void lcd_belttest_v();
  114. #endif //TMC2130
  115. static void lcd_selftest_v();
  116. #ifdef TMC2130
  117. static void reset_crash_det(unsigned char axis);
  118. static bool lcd_selfcheck_axis_sg(unsigned char axis);
  119. static bool lcd_selfcheck_axis(int _axis, int _travel);
  120. #else
  121. static bool lcd_selfcheck_axis(int _axis, int _travel);
  122. static bool lcd_selfcheck_pulleys(int axis);
  123. #endif //TMC2130
  124. static bool lcd_selfcheck_endstops();
  125. static bool lcd_selfcheck_check_heater(bool _isbed);
  126. enum class TestScreen : uint_least8_t
  127. {
  128. ExtruderFan,
  129. PrintFan,
  130. FansOk,
  131. EndStops,
  132. AxisX,
  133. AxisY,
  134. AxisZ,
  135. Bed,
  136. Hotend,
  137. HotendOk,
  138. Fsensor,
  139. FsensorOk,
  140. AllCorrect,
  141. Failed,
  142. Home,
  143. };
  144. enum class TestError : uint_least8_t
  145. {
  146. Heater,
  147. Bed,
  148. Endstops,
  149. Motor,
  150. Endstop,
  151. PrintFan,
  152. ExtruderFan,
  153. Pulley,
  154. Axis,
  155. SwappedFan,
  156. WiringFsensor,
  157. TriggeringFsensor,
  158. FsensorLevel
  159. };
  160. static int lcd_selftest_screen(TestScreen screen, int _progress, int _progress_scale, bool _clear, int _delay);
  161. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator);
  162. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  163. bool _default=false);
  164. #ifdef FANCHECK
  165. /** Enumerate for lcd_selftest_fan_auto function.
  166. */
  167. enum class FanCheck : uint_least8_t {
  168. Success,
  169. PrintFan,
  170. ExtruderFan,
  171. SwappedFan,
  172. };
  173. /**
  174. * Try to check fan working and wiring.
  175. *
  176. * @param _fan i fan number 0 means extruder fan, 1 means print fan.
  177. *
  178. * @returns a TestError noerror, extruderFan, printFan or swappedFan.
  179. */
  180. static FanCheck lcd_selftest_fan_auto(int _fan);
  181. #endif //FANCHECK
  182. #ifdef PAT9125
  183. static bool lcd_selftest_fsensor();
  184. #endif //PAT9125
  185. static bool selftest_irsensor();
  186. #ifdef IR_SENSOR_ANALOG
  187. static bool lcd_selftest_IRsensor(bool bStandalone=false);
  188. static void lcd_detect_IRsensor();
  189. #endif //IR_SENSOR_ANALOG
  190. static void lcd_selftest_error(TestError error, const char *_error_1, const char *_error_2);
  191. static void lcd_colorprint_change();
  192. #ifdef SNMM
  193. static int get_ext_nr();
  194. #endif //SNMM
  195. #if defined (SNMM) || defined(SNMM_V2)
  196. static void fil_load_menu();
  197. static void fil_unload_menu();
  198. #endif // SNMM || SNMM_V2
  199. static void lcd_disable_farm_mode();
  200. static void lcd_set_fan_check();
  201. static void lcd_cutter_enabled();
  202. #ifdef SNMM
  203. static char snmm_stop_print_menu();
  204. #endif //SNMM
  205. #ifdef SDCARD_SORT_ALPHA
  206. static void lcd_sort_type_set();
  207. #endif
  208. static void lcd_babystep_z();
  209. static void lcd_send_status();
  210. #ifdef FARM_CONNECT_MESSAGE
  211. static void lcd_connect_printer();
  212. #endif //FARM_CONNECT_MESSAGE
  213. //! Beware: has side effects - forces lcd_draw_update to 2, which means clear the display
  214. void lcd_finishstatus();
  215. static void lcd_sdcard_menu();
  216. static void lcd_sheet_menu();
  217. #ifdef DELTA_CALIBRATION_MENU
  218. static void lcd_delta_calibrate_menu();
  219. #endif // DELTA_CALIBRATION_MENU
  220. /* Different types of actions that can be used in menu items. */
  221. static void menu_action_sdfile(const char* filename);
  222. static void menu_action_sddirectory(const char* filename);
  223. #define ENCODER_FEEDRATE_DEADZONE 10
  224. #define STATE_NA 255
  225. #define STATE_OFF 0
  226. #define STATE_ON 1
  227. /*
  228. #define MENU_ITEM(type, label, args...) do { \
  229. if (menu_item == menu_line) { \
  230. if (lcd_draw_update) { \
  231. const char* _label_pstr = (label); \
  232. if (lcd_encoder == menu_item) { \
  233. lcd_implementation_drawmenu_ ## type ## _selected (menu_row, _label_pstr , ## args ); \
  234. }else{\
  235. lcd_implementation_drawmenu_ ## type (menu_row, _label_pstr , ## args ); \
  236. }\
  237. }\
  238. if (menu_clicked && (lcd_encoder == menu_item)) {\
  239. lcd_quick_feedback(); \
  240. menu_action_ ## type ( args ); \
  241. return;\
  242. }\
  243. }\
  244. menu_item++;\
  245. } while(0)
  246. */
  247. #if (SDCARDDETECT > 0)
  248. bool lcd_oldcardstatus;
  249. #endif
  250. uint8_t selected_sheet = 0;
  251. bool ignore_click = false;
  252. bool wait_for_unclick;
  253. // place-holders for Ki and Kd edits
  254. #ifdef PIDTEMP
  255. // float raw_Ki, raw_Kd;
  256. #endif
  257. bool bMain; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  258. bool bSettings; // flag (i.e. 'fake parameter') for 'lcd_hw_setup_menu()' function
  259. const char STR_SEPARATOR[] PROGMEM = "------------";
  260. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* longFilename)
  261. {
  262. char c;
  263. uint8_t n = LCD_WIDTH - 1;
  264. lcd_set_cursor(0, row);
  265. lcd_print((lcd_encoder == menu_item)?'>':' ');
  266. while( ((c = *longFilename) != '\0') && (n>0) )
  267. {
  268. lcd_print(c);
  269. longFilename++;
  270. n--;
  271. }
  272. lcd_space(n);
  273. }
  274. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* longFilename)
  275. {
  276. char c;
  277. uint8_t n = LCD_WIDTH - 2;
  278. lcd_set_cursor(0, row);
  279. lcd_print((lcd_encoder == menu_item)?'>':' ');
  280. lcd_print(LCD_STR_FOLDER[0]);
  281. while( ((c = *longFilename) != '\0') && (n>0) )
  282. {
  283. lcd_print(c);
  284. longFilename++;
  285. n--;
  286. }
  287. lcd_space(n);
  288. }
  289. #define MENU_ITEM_SDDIR(str_fn, str_fnl) do { if (menu_item_sddir(str_fn, str_fnl)) return; } while (0)
  290. #define MENU_ITEM_SDFILE(str_fn, str_fnl) do { if (menu_item_sdfile(str_fn, str_fnl)) return; } while (0)
  291. uint8_t menu_item_sddir(const char* str_fn, char* str_fnl)
  292. {
  293. if (menu_item == menu_line)
  294. {
  295. if (lcd_draw_update)
  296. {
  297. lcd_implementation_drawmenu_sddirectory(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl);
  298. }
  299. if (menu_clicked && (lcd_encoder == menu_item))
  300. {
  301. menu_clicked = false;
  302. lcd_update_enabled = 0;
  303. menu_action_sddirectory(str_fn);
  304. lcd_update_enabled = 1;
  305. /* return */ menu_item_ret();
  306. return 1;
  307. }
  308. }
  309. menu_item++;
  310. return 0;
  311. }
  312. static uint8_t menu_item_sdfile(const char* str_fn, char* str_fnl)
  313. {
  314. if (menu_item == menu_line)
  315. {
  316. if (lcd_draw_update)
  317. {
  318. lcd_implementation_drawmenu_sdfile(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl);
  319. }
  320. if (menu_clicked && (lcd_encoder == menu_item))
  321. {
  322. lcd_consume_click();
  323. menu_action_sdfile(str_fn);
  324. /* return */ menu_item_ret();
  325. return 1;
  326. }
  327. }
  328. menu_item++;
  329. return 0;
  330. }
  331. // Print temperature (nozzle/bed) (9 chars total)
  332. void lcdui_print_temp(char type, int val_current, int val_target)
  333. {
  334. int chars = lcd_printf_P(_N("%c%3d/%d%c"), type, val_current, val_target, LCD_STR_DEGREE[0]);
  335. lcd_space(9 - chars);
  336. }
  337. // Print Z-coordinate (8 chars total)
  338. void lcdui_print_Z_coord(void)
  339. {
  340. if (custom_message_type == CustomMsg::MeshBedLeveling)
  341. lcd_puts_P(_N("Z --- "));
  342. else
  343. lcd_printf_P(_N("Z%6.2f%c"), current_position[Z_AXIS], axis_known_position[Z_AXIS]?' ':'?');
  344. }
  345. #ifdef PLANNER_DIAGNOSTICS
  346. // Print planner diagnostics (8 chars total)
  347. void lcdui_print_planner_diag(void)
  348. {
  349. lcd_set_cursor(LCD_WIDTH - 8-2, 1);
  350. lcd_print(LCD_STR_FEEDRATE[0]);
  351. lcd_print(itostr3(feedmultiply));
  352. lcd_puts_P(PSTR("% Q"));
  353. {
  354. uint8_t queue = planner_queue_min();
  355. if (queue < (BLOCK_BUFFER_SIZE >> 1))
  356. lcd_putc('!');
  357. else
  358. {
  359. lcd_putc((char)(queue / 10) + '0');
  360. queue %= 10;
  361. }
  362. lcd_putc((char)queue + '0');
  363. planner_queue_min_reset();
  364. }
  365. }
  366. #endif // PLANNER_DIAGNOSTICS
  367. // Print feedrate (8 chars total)
  368. void lcdui_print_feedrate(void)
  369. {
  370. int chars = lcd_printf_P(_N("%c%3d%%"), LCD_STR_FEEDRATE[0], feedmultiply);
  371. lcd_space(8 - chars);
  372. }
  373. // Print percent done in form "USB---%", " SD---%", " ---%" (7 chars total)
  374. void lcdui_print_percent_done(void)
  375. {
  376. const char* src = is_usb_printing?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" "));
  377. char per[4];
  378. bool num = IS_SD_PRINTING || (PRINTER_ACTIVE && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT));
  379. if (!num || heating_status) // either not printing or heating
  380. {
  381. const int8_t sheetNR = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  382. const int8_t nextSheet = eeprom_next_initialized_sheet(sheetNR);
  383. if ((nextSheet >= 0) && (sheetNR != nextSheet))
  384. {
  385. char sheet[8];
  386. eeprom_read_block(sheet, EEPROM_Sheets_base->s[sheetNR].name, 7);
  387. sheet[7] = '\0';
  388. lcd_printf_P(PSTR("%-7s"),sheet);
  389. return; //do not also print the percentage
  390. }
  391. }
  392. sprintf_P(per, num?_N("%3hhd"):_N("---"), calc_percent_done());
  393. lcd_printf_P(_N("%3S%3s%%"), src, per);
  394. }
  395. // Print extruder status (5 chars total)
  396. void lcdui_print_extruder(void)
  397. {
  398. int chars = 0;
  399. if (mmu_extruder == tmp_extruder) {
  400. if (mmu_extruder == MMU_FILAMENT_UNKNOWN) chars = lcd_printf_P(_N(" F?"));
  401. else chars = lcd_printf_P(_N(" F%u"), mmu_extruder + 1);
  402. }
  403. else
  404. {
  405. if (mmu_extruder == MMU_FILAMENT_UNKNOWN) chars = lcd_printf_P(_N(" ?>%u"), tmp_extruder + 1);
  406. else chars = lcd_printf_P(_N(" %u>%u"), mmu_extruder + 1, tmp_extruder + 1);
  407. }
  408. lcd_space(5 - chars);
  409. }
  410. // Print farm number (5 chars total)
  411. void lcdui_print_farm(void)
  412. {
  413. lcd_printf_P(_N(" FRM "));
  414. }
  415. #ifdef CMD_DIAGNOSTICS
  416. // Print CMD queue diagnostic (8 chars total)
  417. void lcdui_print_cmd_diag(void)
  418. {
  419. lcd_set_cursor(LCD_WIDTH - 8 -1, 2);
  420. lcd_puts_P(PSTR(" C"));
  421. lcd_print(buflen); // number of commands in cmd buffer
  422. if (buflen < 9) lcd_print(' ');
  423. }
  424. #endif //CMD_DIAGNOSTICS
  425. // Print time (8 chars total)
  426. void lcdui_print_time(void)
  427. {
  428. //if remaining print time estimation is available print it else print elapsed time
  429. uint16_t print_t = 0;
  430. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)
  431. print_t = print_time_remaining();
  432. else if(starttime != 0)
  433. print_t = _millis() / 60000 - starttime / 60000;
  434. int chars = 0;
  435. if ((PRINTER_ACTIVE) && ((print_time_remaining_normal != PRINT_TIME_REMAINING_INIT) || (starttime != 0)))
  436. {
  437. char suff = ' ';
  438. char suff_doubt = ' ';
  439. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)
  440. {
  441. suff = 'R';
  442. if (feedmultiply != 100)
  443. suff_doubt = '?';
  444. }
  445. if (print_t < 6000) //time<100h
  446. chars = lcd_printf_P(_N("%c%02u:%02u%c%c"), LCD_STR_CLOCK[0], print_t / 60, print_t % 60, suff, suff_doubt);
  447. else //time>=100h
  448. chars = lcd_printf_P(_N("%c%3uh %c%c"), LCD_STR_CLOCK[0], print_t / 60, suff, suff_doubt);
  449. }
  450. else
  451. chars = lcd_printf_P(_N("%c--:-- "), LCD_STR_CLOCK[0]);
  452. lcd_space(8 - chars);
  453. }
  454. //Print status line on status screen
  455. void lcdui_print_status_line(void)
  456. {
  457. if (heating_status)
  458. { // If heating flag, show progress of heating
  459. heating_status_counter++;
  460. if (heating_status_counter > 13)
  461. {
  462. heating_status_counter = 0;
  463. }
  464. lcd_set_cursor(7, 3);
  465. lcd_space(13);
  466. for (unsigned int dots = 0; dots < heating_status_counter; dots++)
  467. {
  468. lcd_putc_at(7 + dots, 3, '.');
  469. }
  470. switch (heating_status)
  471. {
  472. case 1:
  473. lcd_puts_at_P(0, 3, _T(MSG_HEATING));
  474. break;
  475. case 2:
  476. lcd_puts_at_P(0, 3, _T(MSG_HEATING_COMPLETE));
  477. heating_status = 0;
  478. heating_status_counter = 0;
  479. break;
  480. case 3:
  481. lcd_puts_at_P(0, 3, _T(MSG_BED_HEATING));
  482. break;
  483. case 4:
  484. lcd_puts_at_P(0, 3, _T(MSG_BED_DONE));
  485. heating_status = 0;
  486. heating_status_counter = 0;
  487. break;
  488. default:
  489. break;
  490. }
  491. }
  492. else if ((IS_SD_PRINTING) && (custom_message_type == CustomMsg::Status))
  493. { // If printing from SD, show what we are printing
  494. const char* longFilenameOLD = (card.longFilename[0] ? card.longFilename : card.filename);
  495. if(strlen(longFilenameOLD) > LCD_WIDTH)
  496. {
  497. int inters = 0;
  498. int gh = scrollstuff;
  499. while (((gh - scrollstuff) < LCD_WIDTH) && (inters == 0))
  500. {
  501. if (longFilenameOLD[gh] == '\0')
  502. {
  503. lcd_set_cursor(gh - scrollstuff, 3);
  504. lcd_print(longFilenameOLD[gh - 1]);
  505. scrollstuff = 0;
  506. gh = scrollstuff;
  507. inters = 1;
  508. }
  509. else
  510. {
  511. lcd_set_cursor(gh - scrollstuff, 3);
  512. lcd_print(longFilenameOLD[gh - 1]);
  513. gh++;
  514. }
  515. }
  516. scrollstuff++;
  517. }
  518. else
  519. {
  520. lcd_printf_P(PSTR("%-20s"), longFilenameOLD);
  521. }
  522. }
  523. else
  524. { // Otherwise check for other special events
  525. switch (custom_message_type)
  526. {
  527. case CustomMsg::Status: // Nothing special, print status message normally
  528. lcd_print(lcd_status_message);
  529. break;
  530. case CustomMsg::MeshBedLeveling: // If mesh bed leveling in progress, show the status
  531. if (custom_message_state > 10)
  532. {
  533. lcd_set_cursor(0, 3);
  534. lcd_space(20);
  535. lcd_puts_at_P(0, 3, _T(MSG_CALIBRATE_Z_AUTO));
  536. lcd_puts_P(PSTR(" : "));
  537. lcd_print(custom_message_state-10);
  538. }
  539. else
  540. {
  541. if (custom_message_state == 3)
  542. {
  543. lcd_puts_P(_T(WELCOME_MSG));
  544. lcd_setstatuspgm(_T(WELCOME_MSG));
  545. custom_message_type = CustomMsg::Status;
  546. }
  547. if (custom_message_state > 3 && custom_message_state <= 10 )
  548. {
  549. lcd_set_cursor(0, 3);
  550. lcd_space(19);
  551. lcd_puts_at_P(0, 3, _i("Calibration done"));////MSG_HOMEYZ_DONE
  552. custom_message_state--;
  553. }
  554. }
  555. break;
  556. case CustomMsg::FilamentLoading: // If loading filament, print status
  557. lcd_print(lcd_status_message);
  558. break;
  559. case CustomMsg::PidCal: // PID tuning in progress
  560. lcd_print(lcd_status_message);
  561. if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0)
  562. {
  563. lcd_set_cursor(10, 3);
  564. lcd_print(itostr3(pid_cycle));
  565. lcd_print('/');
  566. lcd_print(itostr3left(pid_number_of_cycles));
  567. }
  568. break;
  569. case CustomMsg::TempCal: // PINDA temp calibration in progress
  570. {
  571. char statusLine[LCD_WIDTH + 1];
  572. sprintf_P(statusLine, PSTR("%-20S"), _T(MSG_TEMP_CALIBRATION));
  573. char progress[4];
  574. sprintf_P(progress, PSTR("%d/6"), custom_message_state);
  575. memcpy(statusLine + 12, progress, sizeof(progress) - 1);
  576. lcd_set_cursor(0, 3);
  577. lcd_print(statusLine);
  578. }
  579. break;
  580. case CustomMsg::TempCompPreheat: // temp compensation preheat
  581. lcd_puts_at_P(0, 3, _i("PINDA Heating"));////MSG_PINDA_PREHEAT c=20 r=1
  582. if (custom_message_state <= PINDA_HEAT_T)
  583. {
  584. lcd_puts_P(PSTR(": "));
  585. lcd_print(custom_message_state); //seconds
  586. lcd_print(' ');
  587. }
  588. break;
  589. }
  590. }
  591. // Fill the rest of line to have nice and clean output
  592. for(int fillspace = 0; fillspace < 20; fillspace++)
  593. if ((lcd_status_message[fillspace] <= 31 ))
  594. lcd_print(' ');
  595. }
  596. //! @brief Show Status Screen
  597. //!
  598. //! @code{.unparsed}
  599. //! |01234567890123456789|
  600. //! |N 000/000D Z000.0 |
  601. //! |B 000/000D F100% |
  602. //! |USB100% T0 t--:-- |
  603. //! |Status line.........|
  604. //! ----------------------
  605. //! N - nozzle temp symbol LCD_STR_THERMOMETER
  606. //! D - Degree sysmbol LCD_STR_DEGREE
  607. //! B - bed temp symbol LCD_STR_BEDTEMP
  608. //! F - feedrate symbol LCD_STR_FEEDRATE
  609. //! t - clock symbol LCD_STR_THERMOMETER
  610. //! @endcode
  611. void lcdui_print_status_screen(void)
  612. {
  613. lcd_set_cursor(0, 0); //line 0
  614. //Print the hotend temperature (9 chars total)
  615. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  616. lcd_space(3); //3 spaces
  617. //Print Z-coordinate (8 chars total)
  618. lcdui_print_Z_coord();
  619. lcd_set_cursor(0, 1); //line 1
  620. //Print the Bed temperature (9 chars total)
  621. lcdui_print_temp(LCD_STR_BEDTEMP[0], (int)(degBed() + 0.5), (int)(degTargetBed() + 0.5));
  622. lcd_space(3); //3 spaces
  623. #ifdef PLANNER_DIAGNOSTICS
  624. //Print planner diagnostics (8 chars)
  625. lcdui_print_planner_diag();
  626. #else // PLANNER_DIAGNOSTICS
  627. //Print Feedrate (8 chars)
  628. lcdui_print_feedrate();
  629. #endif // PLANNER_DIAGNOSTICS
  630. lcd_set_cursor(0, 2); //line 2
  631. //Print SD status (7 chars)
  632. lcdui_print_percent_done();
  633. if (mmu_enabled)
  634. //Print extruder status (5 chars)
  635. lcdui_print_extruder();
  636. else if (farm_mode)
  637. //Print farm number (5 chars)
  638. lcdui_print_farm();
  639. else
  640. lcd_space(5); //5 spaces
  641. #ifdef CMD_DIAGNOSTICS
  642. //Print cmd queue diagnostics (8chars)
  643. lcdui_print_cmd_diag();
  644. #else
  645. //Print time (8chars)
  646. lcdui_print_time();
  647. #endif //CMD_DIAGNOSTICS
  648. lcd_set_cursor(0, 3); //line 3
  649. #ifndef DEBUG_DISABLE_LCD_STATUS_LINE
  650. lcdui_print_status_line();
  651. #endif //DEBUG_DISABLE_LCD_STATUS_LINE
  652. }
  653. // Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent
  654. void lcd_status_screen() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  655. {
  656. if (firstrun == 1)
  657. {
  658. firstrun = 0;
  659. if(lcd_status_message_level == 0)
  660. {
  661. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  662. lcd_finishstatus();
  663. }
  664. if (eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 1) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 2) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 3) == 255)
  665. {
  666. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  667. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  668. }
  669. }
  670. #ifdef ULTIPANEL_FEEDMULTIPLY
  671. // Dead zone at 100% feedrate
  672. if ((feedmultiply < 100 && (feedmultiply + int(lcd_encoder)) > 100) ||
  673. (feedmultiply > 100 && (feedmultiply + int(lcd_encoder)) < 100))
  674. {
  675. lcd_encoder = 0;
  676. feedmultiply = 100;
  677. }
  678. if (feedmultiply == 100 && int(lcd_encoder) > ENCODER_FEEDRATE_DEADZONE)
  679. {
  680. feedmultiply += int(lcd_encoder) - ENCODER_FEEDRATE_DEADZONE;
  681. lcd_encoder = 0;
  682. }
  683. else if (feedmultiply == 100 && int(lcd_encoder) < -ENCODER_FEEDRATE_DEADZONE)
  684. {
  685. feedmultiply += int(lcd_encoder) + ENCODER_FEEDRATE_DEADZONE;
  686. lcd_encoder = 0;
  687. }
  688. else if (feedmultiply != 100)
  689. {
  690. feedmultiply += int(lcd_encoder);
  691. lcd_encoder = 0;
  692. }
  693. #endif //ULTIPANEL_FEEDMULTIPLY
  694. if (feedmultiply < 10)
  695. feedmultiply = 10;
  696. else if (feedmultiply > 999)
  697. feedmultiply = 999;
  698. if (lcd_status_update_delay)
  699. lcd_status_update_delay--;
  700. else
  701. lcd_draw_update = 1;
  702. if (lcd_draw_update)
  703. {
  704. ReInitLCD++;
  705. if (ReInitLCD == 30)
  706. {
  707. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  708. ReInitLCD = 0 ;
  709. }
  710. else
  711. {
  712. if ((ReInitLCD % 10) == 0)
  713. lcd_refresh_noclear(); //to maybe revive the LCD if static electricity killed it.
  714. }
  715. lcdui_print_status_screen();
  716. if (farm_mode)
  717. {
  718. farm_timer--;
  719. if (farm_timer < 1)
  720. {
  721. farm_timer = 10;
  722. prusa_statistics(0);
  723. }
  724. switch (farm_timer)
  725. {
  726. case 8:
  727. prusa_statistics(21);
  728. if(loading_flag)
  729. prusa_statistics(22);
  730. break;
  731. case 5:
  732. if (IS_SD_PRINTING)
  733. prusa_statistics(20);
  734. break;
  735. }
  736. } // end of farm_mode
  737. lcd_status_update_delay = 10; /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */
  738. if (lcd_commands_type != LcdCommands::Idle)
  739. lcd_commands();
  740. } // end of lcd_draw_update
  741. bool current_click = LCD_CLICKED;
  742. if (ignore_click)
  743. {
  744. if (wait_for_unclick)
  745. {
  746. if (!current_click)
  747. ignore_click = wait_for_unclick = false;
  748. else
  749. current_click = false;
  750. }
  751. else if (current_click)
  752. {
  753. lcd_quick_feedback();
  754. wait_for_unclick = true;
  755. current_click = false;
  756. }
  757. }
  758. if (current_click
  759. && ( menu_block_entering_on_serious_errors == SERIOUS_ERR_NONE ) // or a serious error blocks entering the menu
  760. )
  761. {
  762. menu_depth = 0; //redundant, as already done in lcd_return_to_status(), just to be sure
  763. menu_submenu(lcd_main_menu);
  764. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  765. }
  766. }
  767. void lcd_commands()
  768. {
  769. if (lcd_commands_type == LcdCommands::LongPause)
  770. {
  771. if (!blocks_queued() && !homing_flag)
  772. {
  773. lcd_setstatuspgm(_i("Print paused"));////MSG_PRINT_PAUSED c=20 r=1
  774. lcd_commands_type = LcdCommands::Idle;
  775. lcd_commands_step = 0;
  776. long_pause();
  777. }
  778. }
  779. #ifdef SNMM
  780. if (lcd_commands_type == LcdCommands::Layer1Cal)
  781. {
  782. char cmd1[30];
  783. float width = 0.4;
  784. float length = 20 - width;
  785. float extr = count_e(0.2, width, length);
  786. float extr_short_segment = count_e(0.2, width, width);
  787. if (lcd_commands_step>1) lcd_timeoutToStatus.start(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  788. if (lcd_commands_step == 0)
  789. {
  790. lcd_commands_step = 10;
  791. }
  792. if (lcd_commands_step == 10 && !blocks_queued() && cmd_buffer_empty())
  793. {
  794. enquecommand_P(PSTR("M107"));
  795. enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  796. enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  797. enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  798. enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  799. enquecommand_P(PSTR("T0"));
  800. enquecommand_P(_T(MSG_M117_V2_CALIBRATION));
  801. enquecommand_P(PSTR("G87")); //sets calibration status
  802. enquecommand_P(PSTR("G28"));
  803. enquecommand_P(PSTR("G21")); //set units to millimeters
  804. enquecommand_P(PSTR("G90")); //use absolute coordinates
  805. enquecommand_P(PSTR("M83")); //use relative distances for extrusion
  806. enquecommand_P(PSTR("G92 E0"));
  807. enquecommand_P(PSTR("M203 E100"));
  808. enquecommand_P(PSTR("M92 E140"));
  809. lcd_commands_step = 9;
  810. }
  811. if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty())
  812. {
  813. lcd_timeoutToStatus.start();
  814. enquecommand_P(PSTR("G1 Z0.250 F7200.000"));
  815. enquecommand_P(PSTR("G1 X50.0 E80.0 F1000.0"));
  816. enquecommand_P(PSTR("G1 X160.0 E20.0 F1000.0"));
  817. enquecommand_P(PSTR("G1 Z0.200 F7200.000"));
  818. enquecommand_P(PSTR("G1 X220.0 E13 F1000.0"));
  819. enquecommand_P(PSTR("G1 X240.0 E0 F1000.0"));
  820. enquecommand_P(PSTR("G92 E0.0"));
  821. enquecommand_P(PSTR("G21"));
  822. enquecommand_P(PSTR("G90"));
  823. enquecommand_P(PSTR("M83"));
  824. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  825. enquecommand_P(PSTR("G1 Z0.150 F7200.000"));
  826. enquecommand_P(PSTR("M204 S1000"));
  827. enquecommand_P(PSTR("G1 F4000"));
  828. lcd_clear();
  829. menu_goto(lcd_babystep_z, 0, false, true);
  830. lcd_commands_step = 8;
  831. }
  832. if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty()) //draw meander
  833. {
  834. lcd_timeoutToStatus.start();
  835. enquecommand_P(PSTR("G1 X50 Y155"));
  836. enquecommand_P(PSTR("G1 X60 Y155 E4"));
  837. enquecommand_P(PSTR("G1 F1080"));
  838. enquecommand_P(PSTR("G1 X75 Y155 E2.5"));
  839. enquecommand_P(PSTR("G1 X100 Y155 E2"));
  840. enquecommand_P(PSTR("G1 X200 Y155 E2.62773"));
  841. enquecommand_P(PSTR("G1 X200 Y135 E0.66174"));
  842. enquecommand_P(PSTR("G1 X50 Y135 E3.62773"));
  843. enquecommand_P(PSTR("G1 X50 Y115 E0.49386"));
  844. enquecommand_P(PSTR("G1 X200 Y115 E3.62773"));
  845. enquecommand_P(PSTR("G1 X200 Y95 E0.49386"));
  846. enquecommand_P(PSTR("G1 X50 Y95 E3.62773"));
  847. enquecommand_P(PSTR("G1 X50 Y75 E0.49386"));
  848. enquecommand_P(PSTR("G1 X200 Y75 E3.62773"));
  849. enquecommand_P(PSTR("G1 X200 Y55 E0.49386"));
  850. enquecommand_P(PSTR("G1 X50 Y55 E3.62773"));
  851. lcd_commands_step = 7;
  852. }
  853. if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty())
  854. {
  855. lcd_timeoutToStatus.start();
  856. strcpy(cmd1, "G1 X50 Y35 E");
  857. strcat(cmd1, ftostr43(extr));
  858. enquecommand(cmd1);
  859. for (int i = 0; i < 4; i++) {
  860. strcpy(cmd1, "G1 X70 Y");
  861. strcat(cmd1, ftostr32(35 - i*width * 2));
  862. strcat(cmd1, " E");
  863. strcat(cmd1, ftostr43(extr));
  864. enquecommand(cmd1);
  865. strcpy(cmd1, "G1 Y");
  866. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  867. strcat(cmd1, " E");
  868. strcat(cmd1, ftostr43(extr_short_segment));
  869. enquecommand(cmd1);
  870. strcpy(cmd1, "G1 X50 Y");
  871. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  872. strcat(cmd1, " E");
  873. strcat(cmd1, ftostr43(extr));
  874. enquecommand(cmd1);
  875. strcpy(cmd1, "G1 Y");
  876. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  877. strcat(cmd1, " E");
  878. strcat(cmd1, ftostr43(extr_short_segment));
  879. enquecommand(cmd1);
  880. }
  881. lcd_commands_step = 6;
  882. }
  883. if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty())
  884. {
  885. lcd_timeoutToStatus.start();
  886. for (int i = 4; i < 8; i++) {
  887. strcpy(cmd1, "G1 X70 Y");
  888. strcat(cmd1, ftostr32(35 - i*width * 2));
  889. strcat(cmd1, " E");
  890. strcat(cmd1, ftostr43(extr));
  891. enquecommand(cmd1);
  892. strcpy(cmd1, "G1 Y");
  893. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  894. strcat(cmd1, " E");
  895. strcat(cmd1, ftostr43(extr_short_segment));
  896. enquecommand(cmd1);
  897. strcpy(cmd1, "G1 X50 Y");
  898. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  899. strcat(cmd1, " E");
  900. strcat(cmd1, ftostr43(extr));
  901. enquecommand(cmd1);
  902. strcpy(cmd1, "G1 Y");
  903. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  904. strcat(cmd1, " E");
  905. strcat(cmd1, ftostr43(extr_short_segment));
  906. enquecommand(cmd1);
  907. }
  908. lcd_commands_step = 5;
  909. }
  910. if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty())
  911. {
  912. lcd_timeoutToStatus.start();
  913. for (int i = 8; i < 12; i++) {
  914. strcpy(cmd1, "G1 X70 Y");
  915. strcat(cmd1, ftostr32(35 - i*width * 2));
  916. strcat(cmd1, " E");
  917. strcat(cmd1, ftostr43(extr));
  918. enquecommand(cmd1);
  919. strcpy(cmd1, "G1 Y");
  920. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  921. strcat(cmd1, " E");
  922. strcat(cmd1, ftostr43(extr_short_segment));
  923. enquecommand(cmd1);
  924. strcpy(cmd1, "G1 X50 Y");
  925. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  926. strcat(cmd1, " E");
  927. strcat(cmd1, ftostr43(extr));
  928. enquecommand(cmd1);
  929. strcpy(cmd1, "G1 Y");
  930. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  931. strcat(cmd1, " E");
  932. strcat(cmd1, ftostr43(extr_short_segment));
  933. enquecommand(cmd1);
  934. }
  935. lcd_commands_step = 4;
  936. }
  937. if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty())
  938. {
  939. lcd_timeoutToStatus.start();
  940. for (int i = 12; i < 16; i++) {
  941. strcpy(cmd1, "G1 X70 Y");
  942. strcat(cmd1, ftostr32(35 - i*width * 2));
  943. strcat(cmd1, " E");
  944. strcat(cmd1, ftostr43(extr));
  945. enquecommand(cmd1);
  946. strcpy(cmd1, "G1 Y");
  947. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  948. strcat(cmd1, " E");
  949. strcat(cmd1, ftostr43(extr_short_segment));
  950. enquecommand(cmd1);
  951. strcpy(cmd1, "G1 X50 Y");
  952. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  953. strcat(cmd1, " E");
  954. strcat(cmd1, ftostr43(extr));
  955. enquecommand(cmd1);
  956. strcpy(cmd1, "G1 Y");
  957. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  958. strcat(cmd1, " E");
  959. strcat(cmd1, ftostr43(extr_short_segment));
  960. enquecommand(cmd1);
  961. }
  962. lcd_commands_step = 3;
  963. }
  964. if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty())
  965. {
  966. lcd_timeoutToStatus.start();
  967. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000"));
  968. enquecommand_P(PSTR("G4 S0"));
  969. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  970. enquecommand_P(PSTR("G1 Z0.5 F7200.000"));
  971. enquecommand_P(PSTR("G1 X245 Y1"));
  972. enquecommand_P(PSTR("G1 X240 E4"));
  973. enquecommand_P(PSTR("G1 F4000"));
  974. enquecommand_P(PSTR("G1 X190 E2.7"));
  975. enquecommand_P(PSTR("G1 F4600"));
  976. enquecommand_P(PSTR("G1 X110 E2.8"));
  977. enquecommand_P(PSTR("G1 F5200"));
  978. enquecommand_P(PSTR("G1 X40 E3"));
  979. enquecommand_P(PSTR("G1 E-15.0000 F5000"));
  980. enquecommand_P(PSTR("G1 E-50.0000 F5400"));
  981. enquecommand_P(PSTR("G1 E-15.0000 F3000"));
  982. enquecommand_P(PSTR("G1 E-12.0000 F2000"));
  983. enquecommand_P(PSTR("G1 F1600"));
  984. lcd_commands_step = 2;
  985. }
  986. if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty())
  987. {
  988. lcd_timeoutToStatus.start();
  989. enquecommand_P(PSTR("G1 X0 Y1 E3.0000"));
  990. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  991. enquecommand_P(PSTR("G1 F2000"));
  992. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  993. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  994. enquecommand_P(PSTR("G1 F2400"));
  995. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  996. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  997. enquecommand_P(PSTR("G1 F2400"));
  998. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  999. enquecommand_P(PSTR("G1 X50 Y1 E-3.0000"));
  1000. enquecommand_P(PSTR("G4 S0"));
  1001. enquecommand_P(PSTR("M107"));
  1002. enquecommand_P(PSTR("M104 S0"));
  1003. enquecommand_P(PSTR("M140 S0"));
  1004. enquecommand_P(PSTR("G1 X10 Y180 F4000"));
  1005. enquecommand_P(PSTR("G1 Z10 F1300.000"));
  1006. enquecommand_P(PSTR("M84"));
  1007. lcd_commands_step = 1;
  1008. }
  1009. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty())
  1010. {
  1011. lcd_setstatuspgm(_T(WELCOME_MSG));
  1012. lcd_commands_step = 0;
  1013. lcd_commands_type = 0;
  1014. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) {
  1015. lcd_wizard(WizState::RepeatLay1Cal);
  1016. }
  1017. }
  1018. }
  1019. #else //if not SNMM
  1020. if (lcd_commands_type == LcdCommands::Layer1Cal)
  1021. {
  1022. char cmd1[30];
  1023. if(lcd_commands_step>1) lcd_timeoutToStatus.start(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  1024. if (!blocks_queued() && cmd_buffer_empty() && !saved_printing)
  1025. {
  1026. switch(lcd_commands_step)
  1027. {
  1028. case 0:
  1029. lcd_commands_step = 11;
  1030. break;
  1031. case 11:
  1032. lay1cal_wait_preheat();
  1033. lcd_commands_step = 10;
  1034. break;
  1035. case 10:
  1036. lay1cal_load_filament(cmd1, lay1cal_filament);
  1037. lcd_commands_step = 9;
  1038. break;
  1039. case 9:
  1040. lcd_clear();
  1041. menu_depth = 0;
  1042. menu_submenu(lcd_babystep_z);
  1043. lay1cal_intro_line();
  1044. lcd_commands_step = 8;
  1045. break;
  1046. case 8:
  1047. lay1cal_before_meander();
  1048. lcd_commands_step = 7;
  1049. break;
  1050. case 7:
  1051. lay1cal_meander(cmd1);
  1052. lcd_commands_step = 6;
  1053. break;
  1054. case 6:
  1055. for (uint8_t i = 0; i < 4; i++)
  1056. {
  1057. lay1cal_square(cmd1, i);
  1058. }
  1059. lcd_commands_step = 5;
  1060. break;
  1061. case 5:
  1062. for (uint8_t i = 4; i < 8; i++)
  1063. {
  1064. lay1cal_square(cmd1, i);
  1065. }
  1066. lcd_commands_step = 4;
  1067. break;
  1068. case 4:
  1069. for (uint8_t i = 8; i < 12; i++)
  1070. {
  1071. lay1cal_square(cmd1, i);
  1072. }
  1073. lcd_commands_step = 3;
  1074. break;
  1075. case 3:
  1076. for (uint8_t i = 12; i < 16; i++)
  1077. {
  1078. lay1cal_square(cmd1, i);
  1079. }
  1080. lcd_commands_step = 2;
  1081. break;
  1082. case 2:
  1083. enquecommand_P(PSTR("M107")); //turn off printer fan
  1084. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000")); //retract
  1085. enquecommand_P(PSTR("M104 S0")); // turn off temperature
  1086. enquecommand_P(PSTR("M140 S0")); // turn off heatbed
  1087. enquecommand_P(PSTR("G1 Z10 F1300.000")); //lift Z
  1088. enquecommand_P(PSTR("G1 X10 Y180 F4000")); //Go to parking position
  1089. if (mmu_enabled) enquecommand_P(PSTR("M702 C")); //unload from nozzle
  1090. enquecommand_P(PSTR("M84"));// disable motors
  1091. forceMenuExpire = true; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  1092. lcd_commands_step = 1;
  1093. break;
  1094. case 1:
  1095. lcd_setstatuspgm(_T(WELCOME_MSG));
  1096. lcd_commands_step = 0;
  1097. lcd_commands_type = LcdCommands::Idle;
  1098. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1)
  1099. {
  1100. lcd_wizard(WizState::RepeatLay1Cal);
  1101. }
  1102. break;
  1103. }
  1104. }
  1105. }
  1106. #endif // not SNMM
  1107. if (lcd_commands_type == LcdCommands::FarmModeConfirm) /// farm mode confirm
  1108. {
  1109. if (lcd_commands_step == 0) { lcd_commands_step = 6; }
  1110. if (lcd_commands_step == 1 && !blocks_queued())
  1111. {
  1112. lcd_commands_step = 0;
  1113. lcd_commands_type = LcdCommands::Idle;
  1114. }
  1115. if (lcd_commands_step == 2 && !blocks_queued())
  1116. {
  1117. lcd_commands_step = 1;
  1118. }
  1119. if (lcd_commands_step == 3 && !blocks_queued())
  1120. {
  1121. lcd_commands_step = 2;
  1122. }
  1123. if (lcd_commands_step == 4 && !blocks_queued())
  1124. {
  1125. enquecommand_P(PSTR("G90"));
  1126. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  1127. lcd_commands_step = 3;
  1128. }
  1129. if (lcd_commands_step == 5 && !blocks_queued())
  1130. {
  1131. lcd_commands_step = 4;
  1132. }
  1133. if (lcd_commands_step == 6 && !blocks_queued())
  1134. {
  1135. enquecommand_P(PSTR("G91"));
  1136. enquecommand_P(PSTR("G1 Z15 F1500"));
  1137. st_synchronize();
  1138. #ifdef SNMM
  1139. lcd_commands_step = 7;
  1140. #else
  1141. lcd_commands_step = 5;
  1142. #endif
  1143. }
  1144. }
  1145. if (lcd_commands_type == LcdCommands::PidExtruder) {
  1146. char cmd1[30];
  1147. if (lcd_commands_step == 0) {
  1148. custom_message_type = CustomMsg::PidCal;
  1149. custom_message_state = 1;
  1150. lcd_draw_update = 3;
  1151. lcd_commands_step = 3;
  1152. }
  1153. if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
  1154. strcpy(cmd1, "M303 E0 S");
  1155. strcat(cmd1, ftostr3(pid_temp));
  1156. // setting the correct target temperature (for visualization) is done in PID_autotune
  1157. enquecommand(cmd1);
  1158. lcd_setstatuspgm(_i("PID cal. "));////MSG_PID_RUNNING c=20 r=1
  1159. lcd_commands_step = 2;
  1160. }
  1161. if (lcd_commands_step == 2 && pid_tuning_finished) { //saving to eeprom
  1162. pid_tuning_finished = false;
  1163. custom_message_state = 0;
  1164. lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20 r=1
  1165. setAllTargetHotends(0); // reset all hotends temperature including the number displayed on the main screen
  1166. if (_Kp != 0 || _Ki != 0 || _Kd != 0) {
  1167. strcpy(cmd1, "M301 P");
  1168. strcat(cmd1, ftostr32(_Kp));
  1169. strcat(cmd1, " I");
  1170. strcat(cmd1, ftostr32(_Ki));
  1171. strcat(cmd1, " D");
  1172. strcat(cmd1, ftostr32(_Kd));
  1173. enquecommand(cmd1);
  1174. enquecommand_P(PSTR("M500"));
  1175. }
  1176. else {
  1177. SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
  1178. }
  1179. display_time = _millis();
  1180. lcd_commands_step = 1;
  1181. }
  1182. if ((lcd_commands_step == 1) && ((_millis()- display_time)>2000)) { //calibration finished message
  1183. lcd_setstatuspgm(_T(WELCOME_MSG));
  1184. custom_message_type = CustomMsg::Status;
  1185. pid_temp = DEFAULT_PID_TEMP;
  1186. lcd_commands_step = 0;
  1187. lcd_commands_type = LcdCommands::Idle;
  1188. }
  1189. }
  1190. }
  1191. void lcd_return_to_status()
  1192. {
  1193. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  1194. menu_goto(lcd_status_screen, 0, false, true);
  1195. menu_depth = 0;
  1196. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1197. }
  1198. //! @brief Pause print, disable nozzle heater, move to park position
  1199. void lcd_pause_print()
  1200. {
  1201. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); //pause for octoprint
  1202. stop_and_save_print_to_ram(0.0, -default_retraction);
  1203. lcd_return_to_status();
  1204. isPrintPaused = true;
  1205. if (LcdCommands::Idle == lcd_commands_type)
  1206. {
  1207. lcd_commands_type = LcdCommands::LongPause;
  1208. }
  1209. }
  1210. float move_menu_scale;
  1211. static void lcd_move_menu_axis();
  1212. /* Menu implementation */
  1213. static void lcd_cooldown()
  1214. {
  1215. setAllTargetHotends(0);
  1216. setTargetBed(0);
  1217. fanSpeed = 0;
  1218. eFilamentAction = FilamentAction::None;
  1219. lcd_return_to_status();
  1220. }
  1221. //! @brief append text label with a colon and format it into a fixed size output buffer
  1222. //! It would have been much easier if there was a ':' in the labels.
  1223. //! But since the texts like Bed, Nozzle and PINDA are used in other places
  1224. //! it is better to reuse these texts even though it requires some extra formatting code.
  1225. //! @param [in] ipgmLabel pointer to string in PROGMEM
  1226. //! @param [out] pointer to string in RAM which will receive the formatted text. Must be allocated to appropriate size
  1227. //! @param [in] dstSize allocated length of dst
  1228. static void pgmtext_with_colon(const char *ipgmLabel, char *dst, uint8_t dstSize){
  1229. uint8_t i = 0;
  1230. for(; i < dstSize - 2; ++i){ // 2 byte less than buffer, we'd be adding a ':' to the end
  1231. uint8_t b = pgm_read_byte(ipgmLabel + i);
  1232. if( ! b )
  1233. break;
  1234. dst[i] = b;
  1235. }
  1236. dst[i] = ':'; // append the colon
  1237. ++i;
  1238. for(; i < dstSize - 1; ++i) // fill the rest with spaces
  1239. dst[i] = ' ';
  1240. dst[dstSize-1] = '\0'; // terminate the string properly
  1241. }
  1242. //! @brief Show Extruder Info
  1243. //!
  1244. //! @code{.unparsed}
  1245. //! |01234567890123456789|
  1246. //! |Nozzle FAN: 0000 RPM| FAN c=10 r=1 SPEED c=3 r=1
  1247. //! |Print FAN: 0000 RPM| FAN c=10 r=1 SPEED c=3 r=1
  1248. //! |Fil. Xd:000 Yd:000 | Fil. c=4 r=1
  1249. //! |Int: 000 Shut: 000 | Int: c=4 r=1 Shut: c=4 r=1
  1250. //! ----------------------
  1251. //! @endcode
  1252. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1253. void lcd_menu_extruder_info() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  1254. {
  1255. // Display Nozzle fan RPM
  1256. lcd_timeoutToStatus.stop(); //infinite timeout
  1257. lcd_home();
  1258. static const size_t maxChars = 12;
  1259. char nozzle[maxChars], print[maxChars];
  1260. pgmtext_with_colon(_i("Nozzle FAN"), nozzle, maxChars); ////c=10 r=1
  1261. pgmtext_with_colon(_i("Print FAN"), print, maxChars); ////c=10 r=1
  1262. lcd_printf_P(_N("%s %4d RPM\n" "%s %4d RPM\n"), nozzle, 60*fan_speed[0], print, 60*fan_speed[1] );
  1263. #ifdef PAT9125
  1264. // Display X and Y difference from Filament sensor
  1265. // Display Light intensity from Filament sensor
  1266. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  1267. // value ranges from 0(darkest) to 255(brightest).
  1268. // Display LASER shutter time from Filament sensor
  1269. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  1270. // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small.
  1271. // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46.
  1272. if (mmu_enabled == false)
  1273. {
  1274. if (!fsensor_enabled)
  1275. lcd_puts_P(_N("Filament sensor\n" "is disabled."));
  1276. else
  1277. {
  1278. if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal))
  1279. pat9125_update();
  1280. lcd_printf_P(_N(
  1281. "Fil. Xd:%3d Yd:%3d\n" ////c=4 r=1
  1282. "Int: %3d " ////c=4 r=1
  1283. "Shut: %3d" ////c=4 r=1
  1284. ),
  1285. pat9125_x, pat9125_y,
  1286. pat9125_b, pat9125_s
  1287. );
  1288. }
  1289. }
  1290. #endif //PAT9125
  1291. menu_back_if_clicked();
  1292. }
  1293. //! @brief Show Fails Statistics MMU
  1294. //!
  1295. //! @code{.unparsed}
  1296. //! |01234567890123456789|
  1297. //! | Main | c=18 r=1
  1298. //! | Last print | MSG_LAST_PRINT c=18
  1299. //! | Total | MSG_TOTAL c=6
  1300. //! | |
  1301. //! ----------------------
  1302. //! @endcode
  1303. static void lcd_menu_fails_stats_mmu()
  1304. {
  1305. MENU_BEGIN();
  1306. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1307. MENU_ITEM_SUBMENU_P(_T(MSG_LAST_PRINT), lcd_menu_fails_stats_mmu_print);
  1308. MENU_ITEM_SUBMENU_P(_T(MSG_TOTAL), lcd_menu_fails_stats_mmu_total); ////c=18 r=1
  1309. MENU_END();
  1310. }
  1311. //! @brief Show Last Print Failures Statistics MMU
  1312. //!
  1313. //! @code{.unparsed}
  1314. //! |01234567890123456789|
  1315. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1316. //! | MMU fails: 000| MSG_MMU_FAILS c=14
  1317. //! | MMU load fails: 000| MSG_MMU_LOAD_FAILS c=14
  1318. //! | |
  1319. //! ----------------------
  1320. //! @endcode
  1321. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1322. static void lcd_menu_fails_stats_mmu_print()
  1323. {
  1324. lcd_timeoutToStatus.stop(); //infinite timeout
  1325. uint8_t fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL);
  1326. uint16_t load_fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL);
  1327. lcd_home();
  1328. lcd_printf_P(PSTR("%S\n" " %-16.16S%-3d\n" " %-16.16S%-3d"),
  1329. _T(MSG_LAST_PRINT_FAILURES), ////c=20
  1330. _T(MSG_MMU_FAILS), fails, ////c=14
  1331. _T(MSG_MMU_LOAD_FAILS), load_fails); ////c=14
  1332. menu_back_if_clicked_fb();
  1333. }
  1334. //! @brief Show Total Failures Statistics MMU
  1335. //!
  1336. //! @code{.unparsed}
  1337. //! |01234567890123456789|
  1338. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1339. //! | MMU fails: 000| MSG_MMU_FAILS c=14
  1340. //! | MMU load fails: 000| MSG_MMU_LOAD_FAILS c=14
  1341. //! | MMU power fails:000| c=14 r=1
  1342. //! ----------------------
  1343. //! @endcode
  1344. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1345. static void lcd_menu_fails_stats_mmu_total()
  1346. {
  1347. mmu_command(MmuCmd::S3);
  1348. lcd_timeoutToStatus.stop(); //infinite timeout
  1349. uint8_t fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL_TOT);
  1350. uint16_t load_fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL_TOT);
  1351. lcd_home();
  1352. lcd_printf_P(PSTR("%S\n" " %-16.16S%-3d\n" " %-16.16S%-3d\n" " %-16.16S%-3d"),
  1353. _T(MSG_TOTAL_FAILURES), ////c=20
  1354. _T(MSG_MMU_FAILS), fails, ////c=14
  1355. _T(MSG_MMU_LOAD_FAILS), load_fails, ////c=14
  1356. _i("MMU power fails"), mmu_power_failures); ////c=14 r=1
  1357. menu_back_if_clicked_fb();
  1358. }
  1359. #if defined(TMC2130) && defined(FILAMENT_SENSOR)
  1360. static const char failStatsFmt[] PROGMEM = "%S\n" " %-16.16S%-3d\n" " %-16.16S%-3d\n" " %-7.7SX %-3d Y %-3d";
  1361. //! @brief Show Total Failures Statistics MMU
  1362. //!
  1363. //! @code{.unparsed}
  1364. //! |01234567890123456789|
  1365. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1366. //! | Power failures: 000| MSG_POWER_FAILURES c=14
  1367. //! | Fil. runouts : 000| MSG_FIL_RUNOUTS c=14
  1368. //! | Crash X:000 Y:000| MSG_CRASH c=7
  1369. //! ----------------------
  1370. //! @endcode
  1371. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1372. static void lcd_menu_fails_stats_total()
  1373. {
  1374. lcd_timeoutToStatus.stop(); //infinite timeout
  1375. uint16_t power = eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT);
  1376. uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1377. uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT);
  1378. uint16_t crashY = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT);
  1379. lcd_home();
  1380. lcd_printf_P(failStatsFmt,
  1381. _T(MSG_TOTAL_FAILURES), ////c=20
  1382. _T(MSG_POWER_FAILURES), power, ////c=14
  1383. _T(MSG_FIL_RUNOUTS), filam, ////c=14
  1384. _T(MSG_CRASH), crashX, crashY); ////c=7
  1385. menu_back_if_clicked_fb();
  1386. }
  1387. //! @brief Show Last Print Failures Statistics
  1388. //!
  1389. //! @code{.unparsed}
  1390. //! |01234567890123456789|
  1391. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1392. //! | Power failures 000| MSG_POWER_FAILURES c=14
  1393. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=14
  1394. //! | Crash X:000 Y:000| MSG_CRASH c=7
  1395. //! ----------------------
  1396. //! @endcode
  1397. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1398. static void lcd_menu_fails_stats_print()
  1399. {
  1400. lcd_timeoutToStatus.stop(); //infinite timeout
  1401. uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT);
  1402. uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1403. uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
  1404. uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y);
  1405. lcd_home();
  1406. #ifndef PAT9125
  1407. lcd_printf_P(failStatsFmt,
  1408. _T(MSG_LAST_PRINT_FAILURES), ////c=20
  1409. _T(MSG_POWER_FAILURES), power, ////c=14
  1410. _T(MSG_FIL_RUNOUTS), filam, ////c=14
  1411. _T(MSG_CRASH), crashX, crashY); ////c=7
  1412. #else
  1413. // On the MK3 include detailed PAT9125 statistics about soft failures
  1414. lcd_printf_P(PSTR("%S\n"
  1415. " %-16.16S%-3d\n"
  1416. " %-7.7S H %-3d S %-3d\n"
  1417. " %-7.7S X %-3d Y %-3d"),
  1418. _T(MSG_LAST_PRINT_FAILURES), ////c=20
  1419. _T(MSG_POWER_FAILURES), power, ////c=14
  1420. _i("Runouts"), filam, fsensor_softfail, //c=7
  1421. _T(MSG_CRASH), crashX, crashY); ////c=7
  1422. #endif
  1423. menu_back_if_clicked_fb();
  1424. }
  1425. //! @brief Open fail statistics menu
  1426. //!
  1427. //! This version of function is used, when there is filament sensor,
  1428. //! power failure and crash detection.
  1429. //! There are Last print and Total menu items.
  1430. //!
  1431. //! @code{.unparsed}
  1432. //! |01234567890123456789|
  1433. //! | Main | c=18 r=1
  1434. //! | Last print | MSG_LAST_PRINT c=18
  1435. //! | Total | MSG_TOTAL c=6
  1436. //! | |
  1437. //! ----------------------
  1438. //! @endcode
  1439. static void lcd_menu_fails_stats()
  1440. {
  1441. MENU_BEGIN();
  1442. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1443. MENU_ITEM_SUBMENU_P(_T(MSG_LAST_PRINT), lcd_menu_fails_stats_print); ////c=18 r=1
  1444. MENU_ITEM_SUBMENU_P(_T(MSG_TOTAL), lcd_menu_fails_stats_total); ////c=18 r=1
  1445. MENU_END();
  1446. }
  1447. #elif defined(FILAMENT_SENSOR)
  1448. static const char failStatsFmt[] PROGMEM = "%S\n" " %-16.16S%-3d\n" "%S\n" " %-16.16S%-3d\n";
  1449. //!
  1450. //! @brief Print last print and total filament run outs
  1451. //!
  1452. //! This version of function is used, when there is filament sensor,
  1453. //! but no other sensors (e.g. power failure, crash detection).
  1454. //!
  1455. //! Example screen:
  1456. //! @code{.unparsed}
  1457. //! |01234567890123456789|
  1458. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1459. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=14
  1460. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1461. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=14
  1462. //! ----------------------
  1463. //! @endcode
  1464. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1465. static void lcd_menu_fails_stats()
  1466. {
  1467. lcd_timeoutToStatus.stop(); //infinite timeout
  1468. uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1469. uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1470. lcd_home();
  1471. lcd_printf_P(failStatsFmt,
  1472. _T(MSG_LAST_PRINT_FAILURES), ////c=20
  1473. _T(MSG_FIL_RUNOUTS), filamentLast, ////c=14
  1474. _T(MSG_TOTAL_FAILURES), ////c=20
  1475. _T(MSG_FIL_RUNOUTS), filamentTotal); ////c=14
  1476. menu_back_if_clicked();
  1477. }
  1478. #else
  1479. static void lcd_menu_fails_stats()
  1480. {
  1481. lcd_timeoutToStatus.stop(); //infinite timeout
  1482. MENU_BEGIN();
  1483. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1484. MENU_END();
  1485. }
  1486. #endif //TMC2130
  1487. #ifdef DEBUG_BUILD
  1488. #ifdef DEBUG_STACK_MONITOR
  1489. extern uint16_t SP_min;
  1490. extern char* __malloc_heap_start;
  1491. extern char* __malloc_heap_end;
  1492. #endif //DEBUG_STACK_MONITOR
  1493. //! @brief Show Debug Information
  1494. //!
  1495. //! @code{.unparsed}
  1496. //! |01234567890123456789|
  1497. //! |RAM statistics | c=20 r=1
  1498. //! | SP_min: 0000| c=14 r=1
  1499. //! | heap_start: 0000| c=14 r=1
  1500. //! | heap_end: 0000| c=14 r=1
  1501. //! ----------------------
  1502. //! @endcode
  1503. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1504. static void lcd_menu_debug()
  1505. {
  1506. #ifdef DEBUG_STACK_MONITOR
  1507. lcd_home();
  1508. lcd_printf_P(PSTR("RAM statistics\n" ////c=20 r=1
  1509. " SP_min: 0x%04x\n" ////c=14 r=1
  1510. " heap_start: 0x%04x\n" ////c=14 r=1
  1511. " heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end); ////c=14 r=1
  1512. #endif //DEBUG_STACK_MONITOR
  1513. menu_back_if_clicked_fb();
  1514. }
  1515. #endif /* DEBUG_BUILD */
  1516. //! @brief common line print for lcd_menu_temperatures
  1517. //! @param [in] ipgmLabel pointer to string in PROGMEM
  1518. //! @param [in] value to be printed behind the label
  1519. static void lcd_menu_temperatures_line(const char *ipgmLabel, int value){
  1520. static const size_t maxChars = 15;
  1521. char tmp[maxChars];
  1522. pgmtext_with_colon(ipgmLabel, tmp, maxChars);
  1523. lcd_printf_P(PSTR(" %s%3d\x01 \n"), tmp, value); // no need to add -14.14 to string alignment
  1524. }
  1525. //! @brief Show Temperatures
  1526. //!
  1527. //! @code{.unparsed}
  1528. //! |01234567890123456789|
  1529. //! | Nozzle: 000D| c=14 r=1
  1530. //! | Bed: 000D| c=14 r=1
  1531. //! | Ambient: 000D| c=14 r=1
  1532. //! | PINDA: 000D| c=14 r=1
  1533. //! ----------------------
  1534. //! D - Degree sysmbol LCD_STR_DEGREE
  1535. //! @endcode
  1536. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1537. static void lcd_menu_temperatures()
  1538. {
  1539. lcd_timeoutToStatus.stop(); //infinite timeout
  1540. lcd_home();
  1541. lcd_menu_temperatures_line( _T(MSG_NOZZLE), (int)current_temperature[0] ); ////c=14 r=1
  1542. lcd_menu_temperatures_line( _T(MSG_BED), (int)current_temperature_bed ); ////c=14 r=1
  1543. #ifdef AMBIENT_THERMISTOR
  1544. lcd_menu_temperatures_line( _i("Ambient"), (int)current_temperature_ambient ); ////c=14 r=1
  1545. #endif //AMBIENT_THERMISTOR
  1546. #ifdef PINDA_THERMISTOR
  1547. lcd_menu_temperatures_line( _i("PINDA"), (int)current_temperature_pinda ); ////c=14
  1548. #endif //PINDA_THERMISTOR
  1549. menu_back_if_clicked();
  1550. }
  1551. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || defined(IR_SENSOR_ANALOG)
  1552. #define VOLT_DIV_R1 10000
  1553. #define VOLT_DIV_R2 2370
  1554. #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1))
  1555. //! @brief Show Voltages
  1556. //!
  1557. //! @code{.unparsed}
  1558. //! |01234567890123456789|
  1559. //! | |
  1560. //! | PWR: 00.0V | c=12 r=1
  1561. //! | Bed: 00.0V | c=12 r=1
  1562. //! | IR : 00.0V | c=12 r=1 optional
  1563. //! ----------------------
  1564. //! @endcode
  1565. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1566. static void lcd_menu_voltages()
  1567. {
  1568. lcd_timeoutToStatus.stop(); //infinite timeout
  1569. float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1570. float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1571. lcd_home();
  1572. lcd_printf_P(PSTR(" PWR: %4.1fV\n" " BED: %4.1fV"), volt_pwr, volt_bed);
  1573. #ifdef IR_SENSOR_ANALOG
  1574. lcd_printf_P(PSTR("\n IR : %3.1fV"), Raw2Voltage(current_voltage_raw_IR));
  1575. #endif //IR_SENSOR_ANALOG
  1576. menu_back_if_clicked();
  1577. }
  1578. #endif //defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || defined(IR_SENSOR_ANALOG)
  1579. #ifdef TMC2130
  1580. //! @brief Show Belt Status
  1581. //!
  1582. //! @code{.unparsed}
  1583. //! |01234567890123456789|
  1584. //! | Belt status | c=18
  1585. //! | X: 000 |
  1586. //! | Y: 000 |
  1587. //! | |
  1588. //! ----------------------
  1589. //! @endcode
  1590. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1591. static void lcd_menu_belt_status()
  1592. {
  1593. lcd_home();
  1594. lcd_printf_P(PSTR("%S\n" " X %d\n" " Y %d"), _T(MSG_BELT_STATUS), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)));
  1595. menu_back_if_clicked();
  1596. }
  1597. #endif //TMC2130
  1598. #ifdef RESUME_DEBUG
  1599. extern void stop_and_save_print_to_ram(float z_move, float e_move);
  1600. extern void restore_print_from_ram_and_continue(float e_move);
  1601. static void lcd_menu_test_save()
  1602. {
  1603. stop_and_save_print_to_ram(10, -0.8);
  1604. }
  1605. static void lcd_menu_test_restore()
  1606. {
  1607. restore_print_from_ram_and_continue(0.8);
  1608. }
  1609. #endif //RESUME_DEBUG
  1610. //! @brief Show Preheat Menu
  1611. static void lcd_preheat_menu()
  1612. {
  1613. eFilamentAction = FilamentAction::Preheat;
  1614. lcd_generic_preheat_menu();
  1615. }
  1616. //! @brief Show Support Menu
  1617. //!
  1618. //! @code{.unparsed}
  1619. //! |01234567890123456789|
  1620. //! | Main |
  1621. //! | Firmware: | c=18 r=1
  1622. //! | 3.7.2.-2363 | c=16 r=1
  1623. //! | prusa3d.com | MSG_PRUSA3D
  1624. //! | forum.prusa3d.com | MSG_PRUSA3D_FORUM
  1625. //! | howto.prusa3d.com | MSG_PRUSA3D_HOWTO
  1626. //! | -------------- | STR_SEPARATOR
  1627. //! | 1_75mm_MK3 | FILAMENT_SIZE
  1628. //! | howto.prusa3d.com | ELECTRONICS
  1629. //! | howto.prusa3d.com | NOZZLE_TYPE
  1630. //! | -------------- | STR_SEPARATOR
  1631. //! | Date: | c=17 r=1
  1632. //! | MMM DD YYYY | __DATE__
  1633. //! | -------------- | STR_SEPARATOR
  1634. //! @endcode
  1635. //!
  1636. //! If MMU is connected
  1637. //!
  1638. //! @code{.unparsed}
  1639. //! | MMU2 connected | c=18 r=1
  1640. //! | FW: 1.0.6-7064523 |
  1641. //! @endcode
  1642. //!
  1643. //! If MMU is not connected
  1644. //!
  1645. //! @code{.unparsed}
  1646. //! | MMU2 N/A | c=18 r=1
  1647. //! @endcode
  1648. //!
  1649. //! If Flash Air is connected
  1650. //!
  1651. //! @code{.unparsed}
  1652. //! | -------------- | STR_SEPARATOR
  1653. //! | FlashAir IP Addr: | c=18 r=1
  1654. //! | 192.168.1.100 |
  1655. //! @endcode
  1656. //!
  1657. //! @code{.unparsed}
  1658. //! | -------------- | STR_SEPARATOR
  1659. //! | XYZ cal. details | MSG_XYZ_DETAILS c=18
  1660. //! | Extruder info | MSG_INFO_EXTRUDER
  1661. //! | XYZ cal. details | MSG_INFO_SENSORS
  1662. //! @endcode
  1663. //!
  1664. //! If TMC2130 defined
  1665. //!
  1666. //! @code{.unparsed}
  1667. //! | Belt status | MSG_BELT_STATUS
  1668. //! @endcode
  1669. //!
  1670. //! @code{.unparsed}
  1671. //! | Temperatures | MSG_MENU_TEMPERATURES
  1672. //! @endcode
  1673. //!
  1674. //! If Voltage Bed and PWR Pin are defined
  1675. //!
  1676. //! @code{.unparsed}
  1677. //! | Voltages | MSG_MENU_VOLTAGES
  1678. //! @endcode
  1679. //!
  1680. //!
  1681. //! If DEBUG_BUILD is defined
  1682. //!
  1683. //! @code{.unparsed}
  1684. //! | Debug | c=18 r=1
  1685. //! @endcode
  1686. //! ----------------------
  1687. //! @endcode
  1688. static void lcd_support_menu()
  1689. {
  1690. typedef struct
  1691. { // 22bytes total
  1692. int8_t status; // 1byte
  1693. bool is_flash_air; // 1byte
  1694. uint32_t ip; // 4bytes
  1695. char ip_str[IP4_STR_SIZE]; // 16bytes
  1696. } _menu_data_t;
  1697. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1698. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1699. if (_md->status == 0 || lcd_draw_update == 2)
  1700. {
  1701. // Menu was entered or SD card status has changed (plugged in or removed).
  1702. // Initialize its status.
  1703. _md->status = 1;
  1704. _md->is_flash_air = card.ToshibaFlashAir_isEnabled();
  1705. if (_md->is_flash_air) {
  1706. card.ToshibaFlashAir_GetIP((uint8_t*)(&_md->ip)); // ip == 0 if it failed
  1707. }
  1708. } else if (_md->is_flash_air && _md->ip == 0 && ++ _md->status == 16)
  1709. {
  1710. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  1711. _md->status = 0;
  1712. }
  1713. MENU_BEGIN();
  1714. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1715. MENU_ITEM_BACK_P(PSTR("Firmware:"));
  1716. MENU_ITEM_BACK_P(PSTR(" " FW_VERSION_FULL));
  1717. #if (FW_DEV_VERSION != FW_VERSION_GOLD) && (FW_DEV_VERSION != FW_VERSION_RC)
  1718. MENU_ITEM_BACK_P(PSTR(" repo " FW_REPOSITORY));
  1719. #endif
  1720. // Ideally this block would be optimized out by the compiler.
  1721. /* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  1722. if (fw_string_len < 6) {
  1723. MENU_ITEM_BACK_P(PSTR(MSG_FW_VERSION " - " FW_version));
  1724. } else {
  1725. MENU_ITEM_BACK_P(PSTR("FW - " FW_version));
  1726. }*/
  1727. MENU_ITEM_BACK_P(_i("prusa3d.com"));////MSG_PRUSA3D
  1728. MENU_ITEM_BACK_P(_i("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM
  1729. MENU_ITEM_BACK_P(_i("howto.prusa3d.com"));////MSG_PRUSA3D_HOWTO
  1730. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1731. MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE));
  1732. MENU_ITEM_BACK_P(PSTR(ELECTRONICS));
  1733. MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE));
  1734. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1735. MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1
  1736. MENU_ITEM_BACK_P(PSTR(__DATE__));
  1737. #ifdef IR_SENSOR_ANALOG
  1738. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1739. MENU_ITEM_BACK_P(PSTR("Fil. sensor v.:"));
  1740. MENU_ITEM_BACK_P(FsensorIRVersionText());
  1741. #endif // IR_SENSOR_ANALOG
  1742. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1743. if (mmu_enabled)
  1744. {
  1745. MENU_ITEM_BACK_P(_i("MMU2 connected")); ////c=18 r=1
  1746. MENU_ITEM_BACK_P(PSTR(" FW:")); ////c=17 r=1
  1747. if (((menu_item - 1) == menu_line) && lcd_draw_update)
  1748. {
  1749. lcd_set_cursor(6, menu_row);
  1750. if ((mmu_version > 0) && (mmu_buildnr > 0))
  1751. lcd_printf_P(PSTR("%d.%d.%d-%d"), mmu_version/100, mmu_version%100/10, mmu_version%10, mmu_buildnr);
  1752. else
  1753. lcd_puts_P(_i("unknown"));
  1754. }
  1755. }
  1756. else
  1757. MENU_ITEM_BACK_P(PSTR("MMU2 N/A"));
  1758. // Show the FlashAir IP address, if the card is available.
  1759. if (_md->is_flash_air) {
  1760. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1761. MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:")); //c=18 r=1
  1762. MENU_ITEM_BACK_P(PSTR(" "));
  1763. if (((menu_item - 1) == menu_line) && lcd_draw_update) {
  1764. lcd_set_cursor(2, menu_row);
  1765. ip4_to_str(_md->ip_str, (uint8_t*)(&_md->ip));
  1766. lcd_printf_P(PSTR("%s"), _md->ip_str);
  1767. }
  1768. }
  1769. // Show the printer IP address, if it is available.
  1770. if (IP_address) {
  1771. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1772. MENU_ITEM_BACK_P(PSTR("Printer IP Addr:")); //c=18 r=1
  1773. MENU_ITEM_BACK_P(PSTR(" "));
  1774. if (((menu_item - 1) == menu_line) && lcd_draw_update) {
  1775. lcd_set_cursor(2, menu_row);
  1776. ip4_to_str(_md->ip_str, (uint8_t*)(&IP_address));
  1777. lcd_printf_P(PSTR("%s"), _md->ip_str);
  1778. }
  1779. }
  1780. #ifndef MK1BP
  1781. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1782. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=18
  1783. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=18
  1784. MENU_ITEM_SUBMENU_P(_i("Sensor info"), lcd_menu_show_sensors_state);////MSG_INFO_SENSORS c=18 r=1
  1785. #ifdef TMC2130
  1786. MENU_ITEM_SUBMENU_P(_T(MSG_BELT_STATUS), lcd_menu_belt_status);////MSG_BELT_STATUS c=18
  1787. #endif //TMC2130
  1788. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=18 r=1
  1789. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1790. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=18 r=1
  1791. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1792. #ifdef DEBUG_BUILD
  1793. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);////c=18 r=1
  1794. #endif /* DEBUG_BUILD */
  1795. #endif //MK1BP
  1796. MENU_END();
  1797. }
  1798. void lcd_set_fan_check() {
  1799. fans_check_enabled = !fans_check_enabled;
  1800. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1801. #ifdef FANCHECK
  1802. if (fans_check_enabled == false) fan_check_error = EFCE_OK; //reset error if fanCheck is disabled during error. Allows resuming print.
  1803. #endif //FANCHECK
  1804. }
  1805. #ifdef MMU_HAS_CUTTER
  1806. void lcd_cutter_enabled()
  1807. {
  1808. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1809. {
  1810. #ifndef MMU_ALWAYS_CUT
  1811. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1812. }
  1813. #else //MMU_ALWAYS_CUT
  1814. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_always);
  1815. }
  1816. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1817. {
  1818. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1819. }
  1820. #endif //MMU_ALWAYS_CUT
  1821. else
  1822. {
  1823. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_enabled);
  1824. }
  1825. }
  1826. #endif //MMU_HAS_CUTTER
  1827. void lcd_set_filament_autoload() {
  1828. fsensor_autoload_set(!fsensor_autoload_enabled);
  1829. }
  1830. #if defined(FILAMENT_SENSOR) && defined(PAT9125)
  1831. void lcd_set_filament_oq_meass()
  1832. {
  1833. fsensor_oq_meassure_set(!fsensor_oq_meassure_enabled);
  1834. }
  1835. #endif
  1836. FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad'
  1837. bool bFilamentFirstRun;
  1838. bool bFilamentPreheatState;
  1839. bool bFilamentAction=false;
  1840. static bool bFilamentWaitingFlag=false;
  1841. static void mFilamentPrompt()
  1842. {
  1843. uint8_t nLevel;
  1844. lcd_set_cursor(0,0);
  1845. lcdui_print_temp(LCD_STR_THERMOMETER[0],(int)degHotend(0),(int)degTargetHotend(0));
  1846. lcd_puts_at_P(0,1, _i("Press the knob")); ////MSG_ c=20
  1847. lcd_set_cursor(0,2);
  1848. switch(eFilamentAction)
  1849. {
  1850. case FilamentAction::Load:
  1851. case FilamentAction::AutoLoad:
  1852. case FilamentAction::MmuLoad:
  1853. lcd_puts_P(_i("to load filament")); ////MSG_ c=20
  1854. break;
  1855. case FilamentAction::UnLoad:
  1856. case FilamentAction::MmuUnLoad:
  1857. lcd_puts_P(_i("to unload filament")); ////MSG_ c=20
  1858. break;
  1859. case FilamentAction::MmuEject:
  1860. case FilamentAction::MmuCut:
  1861. case FilamentAction::None:
  1862. case FilamentAction::Preheat:
  1863. case FilamentAction::Lay1Cal:
  1864. break;
  1865. }
  1866. if(lcd_clicked())
  1867. {
  1868. nLevel=2;
  1869. if(!bFilamentPreheatState)
  1870. {
  1871. nLevel++;
  1872. // setTargetHotend0(0.0); // uncoment if return to base-state is required
  1873. }
  1874. menu_back(nLevel);
  1875. switch(eFilamentAction)
  1876. {
  1877. case FilamentAction::AutoLoad:
  1878. eFilamentAction=FilamentAction::None; // i.e. non-autoLoad
  1879. // no break
  1880. case FilamentAction::Load:
  1881. loading_flag=true;
  1882. enquecommand_P(PSTR("M701")); // load filament
  1883. break;
  1884. case FilamentAction::UnLoad:
  1885. enquecommand_P(PSTR("M702")); // unload filament
  1886. break;
  1887. case FilamentAction::MmuLoad:
  1888. case FilamentAction::MmuUnLoad:
  1889. case FilamentAction::MmuEject:
  1890. case FilamentAction::MmuCut:
  1891. case FilamentAction::None:
  1892. case FilamentAction::Preheat:
  1893. case FilamentAction::Lay1Cal:
  1894. break;
  1895. }
  1896. }
  1897. }
  1898. void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
  1899. {
  1900. static int nTargetOld;
  1901. static int nTargetBedOld;
  1902. uint8_t nLevel;
  1903. nTargetOld = target_temperature[0];
  1904. nTargetBedOld = target_temperature_bed;
  1905. setTargetHotend0((float )nTemp);
  1906. setTargetBed((float) nTempBed);
  1907. {
  1908. const FilamentAction action = eFilamentAction;
  1909. if (action == FilamentAction::Preheat || action == FilamentAction::Lay1Cal)
  1910. {
  1911. lcd_return_to_status();
  1912. if (action == FilamentAction::Lay1Cal)
  1913. {
  1914. lcd_commands_type = LcdCommands::Layer1Cal;
  1915. }
  1916. else
  1917. {
  1918. raise_z_above(MIN_Z_FOR_PREHEAT);
  1919. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1920. lcd_wizard(WizState::LoadFilHot);
  1921. }
  1922. return;
  1923. }
  1924. }
  1925. lcd_timeoutToStatus.stop();
  1926. if (current_temperature[0] > (target_temperature[0] * 0.95))
  1927. {
  1928. switch (eFilamentAction)
  1929. {
  1930. case FilamentAction::Load:
  1931. case FilamentAction::AutoLoad:
  1932. case FilamentAction::UnLoad:
  1933. if (bFilamentWaitingFlag) menu_submenu(mFilamentPrompt);
  1934. else
  1935. {
  1936. nLevel = bFilamentPreheatState ? 1 : 2;
  1937. menu_back(nLevel);
  1938. if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad))
  1939. {
  1940. loading_flag = true;
  1941. enquecommand_P(PSTR("M701")); // load filament
  1942. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1943. }
  1944. if (eFilamentAction == FilamentAction::UnLoad)
  1945. enquecommand_P(PSTR("M702")); // unload filament
  1946. }
  1947. break;
  1948. case FilamentAction::MmuLoad:
  1949. nLevel = bFilamentPreheatState ? 1 : 2;
  1950. bFilamentAction = true;
  1951. menu_back(nLevel);
  1952. menu_submenu(mmu_load_to_nozzle_menu);
  1953. break;
  1954. case FilamentAction::MmuUnLoad:
  1955. nLevel = bFilamentPreheatState ? 1 : 2;
  1956. bFilamentAction = true;
  1957. menu_back(nLevel);
  1958. extr_unload();
  1959. break;
  1960. case FilamentAction::MmuEject:
  1961. nLevel = bFilamentPreheatState ? 1 : 2;
  1962. bFilamentAction = true;
  1963. menu_back(nLevel);
  1964. menu_submenu(mmu_fil_eject_menu);
  1965. break;
  1966. case FilamentAction::MmuCut:
  1967. #ifdef MMU_HAS_CUTTER
  1968. nLevel=bFilamentPreheatState?1:2;
  1969. bFilamentAction=true;
  1970. menu_back(nLevel);
  1971. menu_submenu(mmu_cut_filament_menu);
  1972. #endif //MMU_HAS_CUTTER
  1973. break;
  1974. case FilamentAction::None:
  1975. case FilamentAction::Preheat:
  1976. case FilamentAction::Lay1Cal:
  1977. // handled earlier
  1978. break;
  1979. }
  1980. if (bFilamentWaitingFlag) Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  1981. bFilamentWaitingFlag = false;
  1982. }
  1983. else
  1984. {
  1985. lcd_set_cursor(0, 0);
  1986. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int) degHotend(0), (int) degTargetHotend(0));
  1987. if (!bFilamentWaitingFlag)
  1988. {
  1989. // First run after the filament preheat selection:
  1990. // setup the fixed LCD parts and raise Z as we wait
  1991. bFilamentWaitingFlag = true;
  1992. lcd_set_cursor(0, 1);
  1993. switch (eFilamentAction)
  1994. {
  1995. case FilamentAction::Load:
  1996. case FilamentAction::AutoLoad:
  1997. case FilamentAction::MmuLoad:
  1998. lcd_puts_P(_i("Preheating to load")); ////MSG_ c=20
  1999. raise_z_above(MIN_Z_FOR_LOAD);
  2000. break;
  2001. case FilamentAction::UnLoad:
  2002. case FilamentAction::MmuUnLoad:
  2003. lcd_puts_P(_i("Preheating to unload")); ////MSG_ c=20
  2004. raise_z_above(MIN_Z_FOR_UNLOAD);
  2005. break;
  2006. case FilamentAction::MmuEject:
  2007. lcd_puts_P(_i("Preheating to eject")); ////MSG_ c=20
  2008. break;
  2009. case FilamentAction::MmuCut:
  2010. lcd_puts_P(_i("Preheating to cut")); ////MSG_ c=20
  2011. break;
  2012. case FilamentAction::None:
  2013. case FilamentAction::Preheat:
  2014. case FilamentAction::Lay1Cal:
  2015. // handled earlier
  2016. break;
  2017. }
  2018. lcd_puts_at_P(0, 3, _i(">Cancel")); ////MSG_ c=20 r=1
  2019. }
  2020. if (lcd_clicked())
  2021. {
  2022. bFilamentWaitingFlag = false;
  2023. if (!bFilamentPreheatState)
  2024. {
  2025. setTargetHotend0(0.0);
  2026. setTargetBed(0.0);
  2027. menu_back();
  2028. }
  2029. else
  2030. {
  2031. setTargetHotend0((float )nTargetOld);
  2032. setTargetBed((float) nTargetBedOld);
  2033. }
  2034. menu_back();
  2035. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  2036. }
  2037. }
  2038. }
  2039. static void mFilamentItem_farm()
  2040. {
  2041. bFilamentPreheatState = false;
  2042. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, FARM_PREHEAT_HPB_TEMP);
  2043. }
  2044. static void mFilamentItem_farm_nozzle()
  2045. {
  2046. bFilamentPreheatState = false;
  2047. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, 0);
  2048. }
  2049. static void mFilamentItem_PLA()
  2050. {
  2051. bFilamentPreheatState = false;
  2052. mFilamentItem(PLA_PREHEAT_HOTEND_TEMP, PLA_PREHEAT_HPB_TEMP);
  2053. }
  2054. static void mFilamentItem_PET()
  2055. {
  2056. bFilamentPreheatState = false;
  2057. mFilamentItem(PET_PREHEAT_HOTEND_TEMP, PET_PREHEAT_HPB_TEMP);
  2058. }
  2059. static void mFilamentItem_ASA()
  2060. {
  2061. bFilamentPreheatState = false;
  2062. mFilamentItem(ASA_PREHEAT_HOTEND_TEMP, ASA_PREHEAT_HPB_TEMP);
  2063. }
  2064. static void mFilamentItem_PC()
  2065. {
  2066. bFilamentPreheatState = false;
  2067. mFilamentItem(PC_PREHEAT_HOTEND_TEMP, PC_PREHEAT_HPB_TEMP);
  2068. }
  2069. static void mFilamentItem_ABS()
  2070. {
  2071. bFilamentPreheatState = false;
  2072. mFilamentItem(ABS_PREHEAT_HOTEND_TEMP, ABS_PREHEAT_HPB_TEMP);
  2073. }
  2074. static void mFilamentItem_HIPS()
  2075. {
  2076. bFilamentPreheatState = false;
  2077. mFilamentItem(HIPS_PREHEAT_HOTEND_TEMP, HIPS_PREHEAT_HPB_TEMP);
  2078. }
  2079. static void mFilamentItem_PP()
  2080. {
  2081. bFilamentPreheatState = false;
  2082. mFilamentItem(PP_PREHEAT_HOTEND_TEMP, PP_PREHEAT_HPB_TEMP);
  2083. }
  2084. static void mFilamentItem_FLEX()
  2085. {
  2086. bFilamentPreheatState = false;
  2087. mFilamentItem(FLEX_PREHEAT_HOTEND_TEMP, FLEX_PREHEAT_HPB_TEMP);
  2088. }
  2089. static void mFilamentItem_PVB()
  2090. {
  2091. bFilamentPreheatState = false;
  2092. mFilamentItem(PVB_PREHEAT_HOTEND_TEMP, PVB_PREHEAT_HPB_TEMP);
  2093. }
  2094. void mFilamentBack()
  2095. {
  2096. menu_back();
  2097. if (eFilamentAction == FilamentAction::AutoLoad ||
  2098. eFilamentAction == FilamentAction::Preheat ||
  2099. eFilamentAction == FilamentAction::Lay1Cal)
  2100. {
  2101. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  2102. }
  2103. }
  2104. void lcd_generic_preheat_menu()
  2105. {
  2106. MENU_BEGIN();
  2107. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  2108. {
  2109. if (eFilamentAction == FilamentAction::Lay1Cal)
  2110. {
  2111. MENU_ITEM_FUNCTION_P(_T(MSG_BACK), mFilamentBack);
  2112. }
  2113. else
  2114. {
  2115. MENU_ITEM_FUNCTION_P(_T(MSG_MAIN), mFilamentBack);
  2116. }
  2117. }
  2118. if (farm_mode)
  2119. {
  2120. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), mFilamentItem_farm);
  2121. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), mFilamentItem_farm_nozzle);
  2122. }
  2123. else
  2124. {
  2125. MENU_ITEM_SUBMENU_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)),mFilamentItem_PLA);
  2126. MENU_ITEM_SUBMENU_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)),mFilamentItem_PET);
  2127. MENU_ITEM_SUBMENU_P(PSTR("ASA - " STRINGIFY(ASA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ASA_PREHEAT_HPB_TEMP)),mFilamentItem_ASA);
  2128. MENU_ITEM_SUBMENU_P(PSTR("PC - " STRINGIFY(PC_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PC_PREHEAT_HPB_TEMP)),mFilamentItem_PC);
  2129. MENU_ITEM_SUBMENU_P(PSTR("PVB - " STRINGIFY(PVB_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PVB_PREHEAT_HPB_TEMP)),mFilamentItem_PVB);
  2130. MENU_ITEM_SUBMENU_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)),mFilamentItem_ABS);
  2131. MENU_ITEM_SUBMENU_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)),mFilamentItem_HIPS);
  2132. MENU_ITEM_SUBMENU_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)),mFilamentItem_PP);
  2133. MENU_ITEM_SUBMENU_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)),mFilamentItem_FLEX);
  2134. }
  2135. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) && eFilamentAction == FilamentAction::Preheat) MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  2136. MENU_END();
  2137. }
  2138. void mFilamentItemForce()
  2139. {
  2140. mFilamentItem(target_temperature[0],target_temperature_bed);
  2141. }
  2142. void lcd_unLoadFilament()
  2143. {
  2144. eFilamentAction=FilamentAction::UnLoad;
  2145. preheat_or_continue();
  2146. }
  2147. static void mmu_unload_filament()
  2148. {
  2149. eFilamentAction = FilamentAction::MmuUnLoad;
  2150. preheat_or_continue();
  2151. }
  2152. void lcd_wait_interact() {
  2153. lcd_clear();
  2154. lcd_set_cursor(0, 1);
  2155. #ifdef SNMM
  2156. lcd_puts_P(_i("Prepare new filament"));////MSG_PREPARE_FILAMENT c=20 r=1
  2157. #else
  2158. lcd_puts_P(_i("Insert filament"));////MSG_INSERT_FILAMENT c=20
  2159. #endif
  2160. if (!fsensor_autoload_enabled) {
  2161. lcd_puts_at_P(0, 2, _i("and press the knob"));////MSG_PRESS c=20 r=2
  2162. }
  2163. }
  2164. void lcd_change_success() {
  2165. lcd_clear();
  2166. lcd_puts_at_P(0, 2, _i("Change success!"));////MSG_CHANGE_SUCCESS
  2167. }
  2168. static void lcd_loading_progress_bar(uint16_t loading_time_ms) {
  2169. for (uint_least8_t i = 0; i < 20; i++) {
  2170. lcd_putc_at(i, 3, '.');
  2171. //loading_time_ms/20 delay
  2172. for (uint_least8_t j = 0; j < 5; j++) {
  2173. delay_keep_alive(loading_time_ms / 100);
  2174. }
  2175. }
  2176. }
  2177. void lcd_loading_color() {
  2178. //we are extruding 25mm with feedrate 200mm/min -> 7.5 seconds for whole action, 0.375 s for one character
  2179. lcd_clear();
  2180. lcd_puts_at_P(0, 0, _i("Loading color"));////MSG_LOADING_COLOR
  2181. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2182. lcd_loading_progress_bar((FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL); //show progress bar during filament loading slow sequence
  2183. }
  2184. void lcd_loading_filament() {
  2185. lcd_clear();
  2186. lcd_puts_at_P(0, 0, _T(MSG_LOADING_FILAMENT));
  2187. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2188. #ifdef SNMM
  2189. for (int i = 0; i < 20; i++) {
  2190. lcd_set_cursor(i, 3);
  2191. lcd_print('.');
  2192. for (int j = 0; j < 10 ; j++) {
  2193. manage_heater();
  2194. manage_inactivity(true);
  2195. _delay(153);
  2196. }
  2197. }
  2198. #else //SNMM
  2199. uint16_t slow_seq_time = (FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL;
  2200. uint16_t fast_seq_time = (FILAMENTCHANGE_FIRSTFEED * 1000ul) / FILAMENTCHANGE_EFEED_FIRST;
  2201. lcd_loading_progress_bar(slow_seq_time + fast_seq_time); //show progress bar for total time of filament loading fast + slow sequence
  2202. #endif //SNMM
  2203. }
  2204. void lcd_alright() {
  2205. int enc_dif = 0;
  2206. int cursor_pos = 1;
  2207. lcd_clear();
  2208. lcd_puts_at_P(0, 0, _i("Changed correctly?"));////MSG_CORRECTLY c=20
  2209. lcd_puts_at_P(1, 1, _T(MSG_YES));
  2210. lcd_puts_at_P(1, 2, _i("Filament not loaded"));////MSG_NOT_LOADED c=19
  2211. lcd_puts_at_P(1, 3, _i("Color not correct"));////MSG_NOT_COLOR
  2212. lcd_putc_at(0, 1, '>');
  2213. enc_dif = lcd_encoder_diff;
  2214. lcd_consume_click();
  2215. while (lcd_change_fil_state == 0) {
  2216. manage_heater();
  2217. manage_inactivity(true);
  2218. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2219. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2220. if (enc_dif > lcd_encoder_diff ) {
  2221. cursor_pos --;
  2222. }
  2223. if (enc_dif < lcd_encoder_diff ) {
  2224. cursor_pos ++;
  2225. }
  2226. if (cursor_pos > 3) {
  2227. cursor_pos = 3;
  2228. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2229. }
  2230. if (cursor_pos < 1) {
  2231. cursor_pos = 1;
  2232. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2233. }
  2234. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  2235. lcd_putc_at(0, cursor_pos, '>');
  2236. enc_dif = lcd_encoder_diff;
  2237. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  2238. _delay(100);
  2239. }
  2240. }
  2241. if (lcd_clicked()) {
  2242. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  2243. lcd_change_fil_state = cursor_pos;
  2244. _delay(500);
  2245. }
  2246. };
  2247. lcd_clear();
  2248. lcd_return_to_status();
  2249. }
  2250. void show_preheat_nozzle_warning()
  2251. {
  2252. lcd_clear();
  2253. lcd_puts_at_P(0, 0, _T(MSG_ERROR));
  2254. lcd_puts_at_P(0, 2, _T(MSG_PREHEAT_NOZZLE));
  2255. _delay(2000);
  2256. lcd_clear();
  2257. }
  2258. void lcd_load_filament_color_check()
  2259. {
  2260. bool clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, true);
  2261. while (!clean) {
  2262. lcd_update_enable(true);
  2263. lcd_update(2);
  2264. load_filament_final_feed();
  2265. st_synchronize();
  2266. clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, true);
  2267. }
  2268. }
  2269. #ifdef FILAMENT_SENSOR
  2270. static void lcd_menu_AutoLoadFilament()
  2271. {
  2272. uint8_t nlines;
  2273. lcd_display_message_fullscreen_nonBlocking_P(_i("Autoloading filament is active, just press the knob and insert filament..."),nlines);////MSG_AUTOLOADING_ENABLED c=20 r=4
  2274. menu_back_if_clicked();
  2275. }
  2276. #endif //FILAMENT_SENSOR
  2277. static void preheat_or_continue()
  2278. {
  2279. bFilamentFirstRun = false;
  2280. if (target_temperature[0] >= EXTRUDE_MINTEMP)
  2281. {
  2282. bFilamentPreheatState = true;
  2283. mFilamentItem(target_temperature[0], target_temperature_bed);
  2284. }
  2285. else lcd_generic_preheat_menu();
  2286. }
  2287. static void lcd_LoadFilament()
  2288. {
  2289. eFilamentAction = FilamentAction::Load;
  2290. preheat_or_continue();
  2291. }
  2292. //! @brief Show filament used a print time
  2293. //!
  2294. //! If printing current print statistics are shown
  2295. //!
  2296. //! @code{.unparsed}
  2297. //! |01234567890123456789|
  2298. //! |Filament used: | c=19
  2299. //! | 0000.00m |
  2300. //! |Print time: | c=19 r=1
  2301. //! | 00h 00m 00s |
  2302. //! ----------------------
  2303. //! @endcode
  2304. //!
  2305. //! If not printing, total statistics are shown
  2306. //!
  2307. //! @code{.unparsed}
  2308. //! |01234567890123456789|
  2309. //! |Total filament: | c=19 r=1
  2310. //! | 0000.00m |
  2311. //! |Total print time: | c=19 r=1
  2312. //! | 00d 00h 00m |
  2313. //! ----------------------
  2314. //! @endcode
  2315. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations. Translations missing for "d"days, "h"ours, "m"inutes", "s"seconds".
  2316. void lcd_menu_statistics()
  2317. {
  2318. lcd_timeoutToStatus.stop(); //infinite timeout
  2319. if (IS_SD_PRINTING)
  2320. {
  2321. const float _met = ((float)total_filament_used) / (100000.f);
  2322. const uint32_t _t = (_millis() - starttime) / 1000ul;
  2323. const uint32_t _h = _t / 3600;
  2324. const uint8_t _m = (_t - (_h * 3600ul)) / 60ul;
  2325. const uint8_t _s = _t - ((_h * 3600ul) + (_m * 60ul));
  2326. lcd_home();
  2327. lcd_printf_P(_N(
  2328. "%S:\n"
  2329. "%18.2fm \n"
  2330. "%S:\n"
  2331. "%10ldh %02hhdm %02hhds"
  2332. ),
  2333. _i("Filament used"), _met, ////c=19
  2334. _i("Print time"), _h, _m, _s); ////c=19 r=1
  2335. menu_back_if_clicked_fb();
  2336. }
  2337. else
  2338. {
  2339. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2340. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2341. uint8_t _hours, _minutes;
  2342. uint32_t _days;
  2343. float _filament_m = (float)_filament/100;
  2344. _days = _time / 1440;
  2345. _hours = (_time - (_days * 1440)) / 60;
  2346. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2347. lcd_home();
  2348. lcd_printf_P(_N(
  2349. "%S:\n"
  2350. "%18.2fm \n"
  2351. "%S:\n"
  2352. "%10ldd %02hhdh %02hhdm"
  2353. ),
  2354. _i("Total filament"), _filament_m, ////c=19 r=1
  2355. _i("Total print time"), _days, _hours, _minutes); ////c=19 r=1
  2356. menu_back_if_clicked_fb();
  2357. }
  2358. }
  2359. static void _lcd_move(const char *name, int axis, int min, int max)
  2360. {
  2361. typedef struct
  2362. { // 2bytes total
  2363. bool initialized; // 1byte
  2364. bool endstopsEnabledPrevious; // 1byte
  2365. } _menu_data_t;
  2366. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2367. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2368. if (!_md->initialized)
  2369. {
  2370. _md->endstopsEnabledPrevious = enable_endstops(false);
  2371. _md->initialized = true;
  2372. }
  2373. if (lcd_encoder != 0)
  2374. {
  2375. refresh_cmd_timeout();
  2376. if (! planner_queue_full())
  2377. {
  2378. current_position[axis] += float((int)lcd_encoder) * move_menu_scale;
  2379. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2380. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2381. lcd_encoder = 0;
  2382. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2383. plan_buffer_line_curposXYZE(manual_feedrate[axis] / 60);
  2384. lcd_draw_update = 1;
  2385. }
  2386. }
  2387. if (lcd_draw_update)
  2388. {
  2389. lcd_set_cursor(0, 1);
  2390. menu_draw_float31(name, current_position[axis]);
  2391. }
  2392. if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious);
  2393. if (LCD_CLICKED) menu_back();
  2394. }
  2395. void lcd_move_e()
  2396. {
  2397. if (degHotend0() > EXTRUDE_MINTEMP)
  2398. {
  2399. if (lcd_encoder != 0)
  2400. {
  2401. refresh_cmd_timeout();
  2402. if (! planner_queue_full())
  2403. {
  2404. current_position[E_AXIS] += float((int)lcd_encoder) * move_menu_scale;
  2405. lcd_encoder = 0;
  2406. plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60);
  2407. lcd_draw_update = 1;
  2408. }
  2409. }
  2410. if (lcd_draw_update)
  2411. {
  2412. lcd_set_cursor(0, 1);
  2413. // Note: the colon behind the text is necessary to greatly shorten
  2414. // the implementation of menu_draw_float31
  2415. menu_draw_float31(PSTR("Extruder:"), current_position[E_AXIS]);
  2416. }
  2417. if (LCD_CLICKED) menu_back();
  2418. }
  2419. else
  2420. {
  2421. show_preheat_nozzle_warning();
  2422. lcd_return_to_status();
  2423. }
  2424. }
  2425. //! @brief Show measured Y distance of front calibration points from Y_MIN_POS
  2426. //! If those points are detected too close to edge of reachable area, their confidence is lowered.
  2427. //! This functionality is applied more often for MK2 printers.
  2428. //! @code{.unparsed}
  2429. //! |01234567890123456789|
  2430. //! |Y distance from min | c=19 r=1
  2431. //! | -------------- | STR_SEPARATOR
  2432. //! |Left: 00.00mm | c=11 r=1
  2433. //! |Right: 00.00mm | c=11 r=1
  2434. //! ----------------------
  2435. //! @endcode
  2436. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2437. static void lcd_menu_xyz_y_min()
  2438. {
  2439. float distanceMin[2];
  2440. count_xyz_details(distanceMin);
  2441. lcd_home();
  2442. lcd_printf_P(_N(
  2443. "%S:\n"
  2444. "%S\n"
  2445. "%S:\n"
  2446. "%S:"
  2447. ),
  2448. _i("Y distance from min"), ////c=19 r=1
  2449. separator,
  2450. _i("Left"), ////c=11 r=1
  2451. _i("Right") ////c=11 r=1
  2452. );
  2453. for (uint8_t i = 0; i < 2; i++)
  2454. {
  2455. lcd_set_cursor(11,2+i);
  2456. if (distanceMin[i] >= 200) lcd_puts_P(_T(MSG_NA)); ////c=3 r=1
  2457. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2458. }
  2459. if (lcd_clicked())
  2460. menu_goto(lcd_menu_xyz_skew, 0, true, true);
  2461. }
  2462. //@brief Show measured axis skewness
  2463. float _deg(float rad)
  2464. {
  2465. return rad * 180 / M_PI;
  2466. }
  2467. //! @brief Show Measured XYZ Skew
  2468. //!
  2469. //! @code{.unparsed}
  2470. //! |01234567890123456789|
  2471. //! |Measured skew: 0.00D| c=13 r=1
  2472. //! | -------------- | STR_SEPARATOR
  2473. //! |Slight skew: 0.12D| c=13 r=1 c=4 r=1
  2474. //! |Severe skew: 0.25D| c=13 r=1 c=4 r=1
  2475. //! ----------------------
  2476. //! D - Degree sysmbol LCD_STR_DEGREE
  2477. //! @endcode
  2478. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2479. static void lcd_menu_xyz_skew()
  2480. {
  2481. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2482. lcd_home();
  2483. lcd_printf_P(_N(
  2484. "%S:\n"
  2485. "%S\n"
  2486. "%-15.15S%3.2f\x01\n"
  2487. "%-15.15S%3.2f\x01"
  2488. ),
  2489. _i("Measured skew"), ////c=13 r=1
  2490. separator,
  2491. _i("Slight skew:"), _deg(bed_skew_angle_mild), ////c=13 r=1 c=4 r=1
  2492. _i("Severe skew:"), _deg(bed_skew_angle_extreme) ////c=13 r=1 c=4 r=1
  2493. );
  2494. if (angleDiff < 100){
  2495. lcd_set_cursor(15,0);
  2496. lcd_printf_P(_N("%3.2f\x01"), _deg(angleDiff));
  2497. }
  2498. else{
  2499. lcd_puts_at_P(15,0, _T(MSG_NA));
  2500. }
  2501. if (lcd_clicked())
  2502. menu_goto(lcd_menu_xyz_offset, 0, true, true);
  2503. }
  2504. //! @brief Show measured bed offset from expected position
  2505. //!
  2506. //! @code{.unparsed}
  2507. //! |01234567890123456789|
  2508. //! |[0;0] point offset | c=20 r=1
  2509. //! | -------------- | STR_SEPARATOR
  2510. //! |X: 000.00mm| c=10 r=1
  2511. //! |Y: 000.00mm| c=10 r=1
  2512. //! ----------------------
  2513. //! @endcode
  2514. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2515. static void lcd_menu_xyz_offset()
  2516. {
  2517. lcd_puts_at_P(0, 0, _i("[0;0] point offset"));////MSG_MEASURED_OFFSET
  2518. lcd_puts_at_P(0, 1, separator);
  2519. lcd_puts_at_P(0, 2, PSTR("X")); ////c=10 r=1
  2520. lcd_puts_at_P(0, 3, PSTR("Y")); ////c=10 r=1
  2521. float vec_x[2];
  2522. float vec_y[2];
  2523. float cntr[2];
  2524. world2machine_read_valid(vec_x, vec_y, cntr);
  2525. for (uint_least8_t i = 0; i < 2; i++)
  2526. {
  2527. lcd_set_cursor((cntr[i] < 0) ? 10 : 11, i+2);
  2528. lcd_print(cntr[i]);
  2529. lcd_puts_at_P(16, i + 2, PSTR("mm"));
  2530. }
  2531. menu_back_if_clicked();
  2532. }
  2533. // Save a single axis babystep value.
  2534. void EEPROM_save_B(int pos, int* value)
  2535. {
  2536. eeprom_update_byte((unsigned char*)pos, (unsigned char)((*value) & 0xff));
  2537. eeprom_update_byte((unsigned char*)pos + 1, (unsigned char)((*value) >> 8));
  2538. }
  2539. // Read a single axis babystep value.
  2540. void EEPROM_read_B(int pos, int* value)
  2541. {
  2542. *value = (int)eeprom_read_byte((unsigned char*)pos) | (int)(eeprom_read_byte((unsigned char*)pos + 1) << 8);
  2543. }
  2544. // Note: the colon behind the text (X, Y, Z) is necessary to greatly shorten
  2545. // the implementation of menu_draw_float31
  2546. static void lcd_move_x() {
  2547. _lcd_move(PSTR("X:"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2548. }
  2549. static void lcd_move_y() {
  2550. _lcd_move(PSTR("Y:"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2551. }
  2552. static void lcd_move_z() {
  2553. _lcd_move(PSTR("Z:"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2554. }
  2555. /**
  2556. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2557. *
  2558. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2559. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2560. * Purpose of this function for other axis then Z is unknown.
  2561. *
  2562. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2563. * other value leads to storing Z_AXIS
  2564. * @param msg text to be displayed
  2565. */
  2566. static void lcd_babystep_z()
  2567. {
  2568. typedef struct
  2569. {
  2570. int8_t status;
  2571. int16_t babystepMemZ;
  2572. float babystepMemMMZ;
  2573. } _menu_data_t;
  2574. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2575. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2576. if (_md->status == 0)
  2577. {
  2578. // Menu was entered.
  2579. // Initialize its status.
  2580. _md->status = 1;
  2581. check_babystep();
  2582. if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){
  2583. _md->babystepMemZ = 0;
  2584. }
  2585. else{
  2586. _md->babystepMemZ = eeprom_read_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->
  2587. s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)));
  2588. }
  2589. // same logic as in babystep_load
  2590. if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST)
  2591. _md->babystepMemZ = 0;
  2592. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2593. lcd_draw_update = 1;
  2594. //SERIAL_ECHO("Z baby step: ");
  2595. //SERIAL_ECHO(_md->babystepMem[2]);
  2596. // Wait 90 seconds before closing the live adjust dialog.
  2597. lcd_timeoutToStatus.start();
  2598. }
  2599. if (lcd_encoder != 0)
  2600. {
  2601. if (homing_flag) lcd_encoder = 0;
  2602. _md->babystepMemZ += (int)lcd_encoder;
  2603. if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2604. else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0
  2605. else
  2606. {
  2607. CRITICAL_SECTION_START
  2608. babystepsTodo[Z_AXIS] += (int)lcd_encoder;
  2609. CRITICAL_SECTION_END
  2610. }
  2611. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2612. _delay(50);
  2613. lcd_encoder = 0;
  2614. lcd_draw_update = 1;
  2615. }
  2616. if (lcd_draw_update)
  2617. {
  2618. SheetFormatBuffer buffer;
  2619. menu_format_sheet_E(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))], buffer);
  2620. lcd_set_cursor(0, 0);
  2621. lcd_print(buffer.c);
  2622. lcd_set_cursor(0, 1);
  2623. menu_draw_float13(_i("Adjusting Z:"), _md->babystepMemMMZ); ////MSG_BABYSTEPPING_Z c=15 Beware: must include the ':' as its last character
  2624. }
  2625. if (LCD_CLICKED || menu_leaving)
  2626. {
  2627. // Only update the EEPROM when leaving the menu.
  2628. uint8_t active_sheet=eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  2629. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[active_sheet].z_offset)),_md->babystepMemZ);
  2630. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].bed_temp),target_temperature_bed);
  2631. #ifdef PINDA_THERMISTOR
  2632. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].pinda_temp),current_temperature_pinda);
  2633. #endif //PINDA_THERMISTOR
  2634. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2635. }
  2636. if (LCD_CLICKED) menu_back();
  2637. }
  2638. typedef struct
  2639. { // 12bytes + 9bytes = 21bytes total
  2640. menu_data_edit_t reserved; //12 bytes reserved for number editing functions
  2641. int8_t status; // 1byte
  2642. int16_t left; // 2byte
  2643. int16_t right; // 2byte
  2644. int16_t front; // 2byte
  2645. int16_t rear; // 2byte
  2646. } _menu_data_adjust_bed_t;
  2647. static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data");
  2648. void lcd_adjust_bed_reset(void)
  2649. {
  2650. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2651. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2652. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2653. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2654. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2655. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2656. _md->status = 0;
  2657. }
  2658. //! @brief Show Bed level correct
  2659. //!
  2660. //! @code{.unparsed}
  2661. //! |01234567890123456789|
  2662. //! |Settings: | MSG_SETTINGS
  2663. //! |Left side [um]: | MSG_BED_CORRECTION_LEFT
  2664. //! |Right side[um]: | MSG_BED_CORRECTION_RIGHT
  2665. //! |Front side[um]: | MSG_BED_CORRECTION_FRONT
  2666. //! |Rear side [um]: | MSG_BED_CORRECTION_REAR
  2667. //! |Reset | MSG_BED_CORRECTION_RESET
  2668. //! ----------------------
  2669. //! @endcode
  2670. void lcd_adjust_bed(void)
  2671. {
  2672. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2673. if (_md->status == 0)
  2674. {
  2675. // Menu was entered.
  2676. _md->left = 0;
  2677. _md->right = 0;
  2678. _md->front = 0;
  2679. _md->rear = 0;
  2680. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1)
  2681. {
  2682. _md->left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2683. _md->right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2684. _md->front = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2685. _md->rear = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2686. }
  2687. _md->status = 1;
  2688. }
  2689. MENU_BEGIN();
  2690. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  2691. ON_MENU_LEAVE(
  2692. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, _md->left);
  2693. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, _md->right);
  2694. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, _md->front);
  2695. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, _md->rear);
  2696. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2697. );
  2698. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  2699. MENU_ITEM_EDIT_int3_P(_i("Left side [um]"), &_md->left, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1
  2700. MENU_ITEM_EDIT_int3_P(_i("Right side[um]"), &_md->right, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_RIGHT c=14 r=1
  2701. MENU_ITEM_EDIT_int3_P(_i("Front side[um]"), &_md->front, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_FRONT c=14 r=1
  2702. MENU_ITEM_EDIT_int3_P(_i("Rear side [um]"), &_md->rear, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_REAR c=14 r=1
  2703. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_adjust_bed_reset);////MSG_RESET c=14
  2704. MENU_END();
  2705. }
  2706. //! @brief Show PID Extruder
  2707. //!
  2708. //! @code{.unparsed}
  2709. //! |01234567890123456789|
  2710. //! | Set temperature: | MSG_SET_TEMPERATURE
  2711. //! | |
  2712. //! | 210 |
  2713. //! | |
  2714. //! ----------------------
  2715. //! @endcode
  2716. void pid_extruder()
  2717. {
  2718. lcd_clear();
  2719. lcd_puts_at_P(1, 0, _i("Set temperature:"));////MSG_SET_TEMPERATURE c=19 r=1
  2720. pid_temp += int(lcd_encoder);
  2721. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2722. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2723. lcd_encoder = 0;
  2724. lcd_set_cursor(1, 2);
  2725. lcd_print(ftostr3(pid_temp));
  2726. if (lcd_clicked()) {
  2727. lcd_commands_type = LcdCommands::PidExtruder;
  2728. lcd_return_to_status();
  2729. lcd_update(2);
  2730. }
  2731. }
  2732. /*
  2733. void lcd_adjust_z() {
  2734. int enc_dif = 0;
  2735. int cursor_pos = 1;
  2736. int fsm = 0;
  2737. lcd_clear();
  2738. lcd_set_cursor(0, 0);
  2739. lcd_puts_P(_i("Auto adjust Z?"));////MSG_ADJUSTZ
  2740. lcd_set_cursor(1, 1);
  2741. lcd_puts_P(_T(MSG_YES));
  2742. lcd_set_cursor(1, 2);
  2743. lcd_puts_P(_T(MSG_NO));
  2744. lcd_set_cursor(0, 1);
  2745. lcd_print('>');
  2746. enc_dif = lcd_encoder_diff;
  2747. while (fsm == 0) {
  2748. manage_heater();
  2749. manage_inactivity(true);
  2750. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2751. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2752. if (enc_dif > lcd_encoder_diff ) {
  2753. cursor_pos --;
  2754. }
  2755. if (enc_dif < lcd_encoder_diff ) {
  2756. cursor_pos ++;
  2757. }
  2758. if (cursor_pos > 2) {
  2759. cursor_pos = 2;
  2760. }
  2761. if (cursor_pos < 1) {
  2762. cursor_pos = 1;
  2763. }
  2764. lcd_set_cursor(0, 1);
  2765. lcd_print(' ');
  2766. lcd_set_cursor(0, 2);
  2767. lcd_print(' ');
  2768. lcd_set_cursor(0, cursor_pos);
  2769. lcd_print('>');
  2770. enc_dif = lcd_encoder_diff;
  2771. _delay(100);
  2772. }
  2773. }
  2774. if (lcd_clicked()) {
  2775. fsm = cursor_pos;
  2776. if (fsm == 1) {
  2777. int babystepLoadZ = 0;
  2778. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  2779. CRITICAL_SECTION_START
  2780. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2781. CRITICAL_SECTION_END
  2782. } else {
  2783. int zero = 0;
  2784. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  2785. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  2786. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  2787. }
  2788. _delay(500);
  2789. }
  2790. };
  2791. lcd_clear();
  2792. lcd_return_to_status();
  2793. }*/
  2794. #ifdef PINDA_THERMISTOR
  2795. bool lcd_wait_for_pinda(float temp) {
  2796. lcd_set_custom_characters_degree();
  2797. setAllTargetHotends(0);
  2798. setTargetBed(0);
  2799. LongTimer pinda_timeout;
  2800. pinda_timeout.start();
  2801. bool target_temp_reached = true;
  2802. while (current_temperature_pinda > temp){
  2803. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2804. lcd_set_cursor(0, 4);
  2805. lcd_print(LCD_STR_THERMOMETER[0]);
  2806. lcd_print(ftostr3(current_temperature_pinda));
  2807. lcd_print('/');
  2808. lcd_print(ftostr3(temp));
  2809. lcd_print(LCD_STR_DEGREE);
  2810. delay_keep_alive(1000);
  2811. serialecho_temperatures();
  2812. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2813. target_temp_reached = false;
  2814. break;
  2815. }
  2816. }
  2817. lcd_set_custom_characters_arrows();
  2818. lcd_update_enable(true);
  2819. return target_temp_reached;
  2820. }
  2821. #endif //PINDA_THERMISTOR
  2822. void lcd_wait_for_heater() {
  2823. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2824. lcd_set_degree();
  2825. lcd_set_cursor(0, 4);
  2826. lcd_print(LCD_STR_THERMOMETER[0]);
  2827. lcd_print(ftostr3(degHotend(active_extruder)));
  2828. lcd_print('/');
  2829. lcd_print(ftostr3(degTargetHotend(active_extruder)));
  2830. lcd_print(LCD_STR_DEGREE);
  2831. }
  2832. void lcd_wait_for_cool_down() {
  2833. lcd_set_custom_characters_degree();
  2834. setAllTargetHotends(0);
  2835. setTargetBed(0);
  2836. int fanSpeedBckp = fanSpeed;
  2837. fanSpeed = 255;
  2838. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2839. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=3
  2840. lcd_set_cursor(0, 4);
  2841. lcd_print(LCD_STR_THERMOMETER[0]);
  2842. lcd_print(ftostr3(degHotend(0)));
  2843. lcd_print("/0");
  2844. lcd_print(LCD_STR_DEGREE);
  2845. lcd_set_cursor(9, 4);
  2846. lcd_print(LCD_STR_BEDTEMP[0]);
  2847. lcd_print(ftostr3(degBed()));
  2848. lcd_print("/0");
  2849. lcd_print(LCD_STR_DEGREE);
  2850. lcd_set_custom_characters();
  2851. delay_keep_alive(1000);
  2852. serialecho_temperatures();
  2853. }
  2854. fanSpeed = fanSpeedBckp;
  2855. lcd_set_custom_characters_arrows();
  2856. lcd_update_enable(true);
  2857. }
  2858. // Lets the user move the Z carriage up to the end stoppers.
  2859. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2860. // Otherwise the Z calibration is not changed and false is returned.
  2861. #ifndef TMC2130
  2862. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2863. {
  2864. // Don't know where we are. Let's claim we are Z=0, so the soft end stops will not be triggered when moving up.
  2865. current_position[Z_AXIS] = 0;
  2866. plan_set_position_curposXYZE();
  2867. // Until confirmed by the confirmation dialog.
  2868. for (;;) {
  2869. const char *msg = only_z ? _i("Calibrating Z. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.") : _i("Calibrating XYZ. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.");////MSG_MOVE_CARRIAGE_TO_THE_TOP c=20 r=8////MSG_MOVE_CARRIAGE_TO_THE_TOP_Z c=20 r=8
  2870. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2871. const bool multi_screen = msg_next != NULL;
  2872. unsigned long previous_millis_msg = _millis();
  2873. // Until the user finishes the z up movement.
  2874. lcd_encoder_diff = 0;
  2875. lcd_encoder = 0;
  2876. for (;;) {
  2877. manage_heater();
  2878. manage_inactivity(true);
  2879. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2880. _delay(50);
  2881. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2882. lcd_encoder_diff = 0;
  2883. if (! planner_queue_full()) {
  2884. // Only move up, whatever direction the user rotates the encoder.
  2885. current_position[Z_AXIS] += fabs(lcd_encoder);
  2886. lcd_encoder = 0;
  2887. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  2888. }
  2889. }
  2890. if (lcd_clicked()) {
  2891. // Abort a move if in progress.
  2892. planner_abort_hard();
  2893. while (lcd_clicked()) ;
  2894. _delay(10);
  2895. while (lcd_clicked()) ;
  2896. break;
  2897. }
  2898. if (multi_screen && _millis() - previous_millis_msg > 5000) {
  2899. if (msg_next == NULL)
  2900. msg_next = msg;
  2901. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2902. previous_millis_msg = _millis();
  2903. }
  2904. }
  2905. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2906. int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Are left and right Z~carriages all up?"), false);////MSG_CONFIRM_CARRIAGE_AT_THE_TOP c=20 r=2
  2907. if (result == -1)
  2908. goto canceled;
  2909. else if (result == 1)
  2910. goto calibrated;
  2911. // otherwise perform another round of the Z up dialog.
  2912. }
  2913. calibrated:
  2914. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2915. // during the search for the induction points.
  2916. if ((PRINTER_TYPE == PRINTER_MK25) || (PRINTER_TYPE == PRINTER_MK2) || (PRINTER_TYPE == PRINTER_MK2_SNMM)) {
  2917. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2918. }
  2919. else {
  2920. current_position[Z_AXIS] = Z_MAX_POS+4.f;
  2921. }
  2922. plan_set_position_curposXYZE();
  2923. return true;
  2924. canceled:
  2925. return false;
  2926. }
  2927. #endif // TMC2130
  2928. static inline bool pgm_is_whitespace(const char *c_addr)
  2929. {
  2930. const char c = pgm_read_byte(c_addr);
  2931. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2932. }
  2933. static inline bool pgm_is_interpunction(const char *c_addr)
  2934. {
  2935. const char c = pgm_read_byte(c_addr);
  2936. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2937. }
  2938. /**
  2939. * @brief show full screen message
  2940. *
  2941. * This function is non-blocking
  2942. * @param msg message to be displayed from PROGMEM
  2943. * @param nlines
  2944. * @return rest of the text (to be displayed on next page)
  2945. */
  2946. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines)
  2947. {
  2948. lcd_set_cursor(0, 0);
  2949. const char *msgend = msg;
  2950. uint8_t row = 0;
  2951. bool multi_screen = false;
  2952. for (; row < 4; ++ row) {
  2953. while (pgm_is_whitespace(msg))
  2954. ++ msg;
  2955. if (pgm_read_byte(msg) == 0)
  2956. // End of the message.
  2957. break;
  2958. lcd_set_cursor(0, row);
  2959. uint8_t linelen = min(strlen_P(msg), 20);
  2960. const char *msgend2 = msg + linelen;
  2961. msgend = msgend2;
  2962. if (row == 3 && linelen == 20) {
  2963. // Last line of the display, full line shall be displayed.
  2964. // Find out, whether this message will be split into multiple screens.
  2965. while (pgm_is_whitespace(msgend))
  2966. ++ msgend;
  2967. multi_screen = pgm_read_byte(msgend) != 0;
  2968. if (multi_screen)
  2969. msgend = (msgend2 -= 2);
  2970. }
  2971. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2972. // Splitting a word. Find the start of the current word.
  2973. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2974. -- msgend;
  2975. if (msgend == msg)
  2976. // Found a single long word, which cannot be split. Just cut it.
  2977. msgend = msgend2;
  2978. }
  2979. for (; msg < msgend; ++ msg) {
  2980. char c = char(pgm_read_byte(msg));
  2981. if (c == '~')
  2982. c = ' ';
  2983. lcd_print(c);
  2984. }
  2985. }
  2986. if (multi_screen) {
  2987. // Display the "next screen" indicator character.
  2988. // lcd_set_custom_characters_arrows();
  2989. lcd_set_custom_characters_nextpage();
  2990. lcd_set_cursor(19, 3);
  2991. // Display the down arrow.
  2992. lcd_print(char(1));
  2993. }
  2994. nlines = row;
  2995. return multi_screen ? msgend : NULL;
  2996. }
  2997. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  2998. {
  2999. // Disable update of the screen by the usual lcd_update(0) routine.
  3000. lcd_update_enable(false);
  3001. lcd_clear();
  3002. // uint8_t nlines;
  3003. return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines);
  3004. }
  3005. const char* lcd_display_message_fullscreen_P(const char *msg)
  3006. {
  3007. uint8_t nlines;
  3008. return lcd_display_message_fullscreen_P(msg, nlines);
  3009. }
  3010. /**
  3011. * @brief show full screen message and wait
  3012. *
  3013. * This function is blocking.
  3014. * @param msg message to be displayed from PROGMEM
  3015. */
  3016. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  3017. {
  3018. LcdUpdateDisabler lcdUpdateDisabler;
  3019. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  3020. bool multi_screen = msg_next != NULL;
  3021. lcd_set_custom_characters_nextpage();
  3022. lcd_consume_click();
  3023. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3024. // Until confirmed by a button click.
  3025. for (;;) {
  3026. if (!multi_screen) {
  3027. lcd_set_cursor(19, 3);
  3028. // Display the confirm char.
  3029. lcd_print(char(2));
  3030. }
  3031. // Wait for 5 seconds before displaying the next text.
  3032. for (uint8_t i = 0; i < 100; ++ i) {
  3033. delay_keep_alive(50);
  3034. if (lcd_clicked()) {
  3035. if (msg_next == NULL) {
  3036. KEEPALIVE_STATE(IN_HANDLER);
  3037. lcd_set_custom_characters();
  3038. lcd_update_enable(true);
  3039. lcd_update(2);
  3040. return;
  3041. }
  3042. else {
  3043. break;
  3044. }
  3045. }
  3046. }
  3047. if (multi_screen) {
  3048. if (msg_next == NULL)
  3049. msg_next = msg;
  3050. msg_next = lcd_display_message_fullscreen_P(msg_next);
  3051. if (msg_next == NULL) {
  3052. lcd_set_cursor(19, 3);
  3053. // Display the confirm char.
  3054. lcd_print(char(2));
  3055. }
  3056. }
  3057. }
  3058. }
  3059. bool lcd_wait_for_click_delay(uint16_t nDelay)
  3060. // nDelay :: timeout [s] (0 ~ no timeout)
  3061. // true ~ clicked, false ~ delayed
  3062. {
  3063. bool bDelayed;
  3064. long nTime0 = _millis()/1000;
  3065. lcd_consume_click();
  3066. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3067. for (;;) {
  3068. manage_heater();
  3069. manage_inactivity(true);
  3070. bDelayed = ((_millis()/1000-nTime0) > nDelay);
  3071. bDelayed = (bDelayed && (nDelay != 0)); // 0 ~ no timeout, always waiting for click
  3072. if (lcd_clicked() || bDelayed) {
  3073. KEEPALIVE_STATE(IN_HANDLER);
  3074. return(!bDelayed);
  3075. }
  3076. }
  3077. }
  3078. void lcd_wait_for_click()
  3079. {
  3080. lcd_wait_for_click_delay(0);
  3081. }
  3082. //! @brief Show multiple screen message with yes and no possible choices and wait with possible timeout
  3083. //! @param msg Message to show
  3084. //! @param allow_timeouting if true, allows time outing of the screen
  3085. //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected
  3086. //! @retval 1 yes choice selected by user
  3087. //! @retval 0 no choice selected by user
  3088. //! @retval -1 screen timed out
  3089. int8_t lcd_show_multiscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes) //currently just max. n*4 + 3 lines supported (set in language header files)
  3090. {
  3091. return lcd_show_multiscreen_message_two_choices_and_wait_P(msg, allow_timeouting, default_yes, _T(MSG_YES), _T(MSG_NO));
  3092. }
  3093. //! @brief Show multiple screen message with two possible choices and wait with possible timeout
  3094. //! @param msg Message to show
  3095. //! @param allow_timeouting if true, allows time outing of the screen
  3096. //! @param default_first if true, fist choice is selected by default, otherwise second choice is preselected
  3097. //! @param first_choice text caption of first possible choice
  3098. //! @param second_choice text caption of second possible choice
  3099. //! @retval 1 first choice selected by user
  3100. //! @retval 0 second choice selected by user
  3101. //! @retval -1 screen timed out
  3102. int8_t lcd_show_multiscreen_message_two_choices_and_wait_P(const char *msg, bool allow_timeouting, bool default_first,
  3103. const char *first_choice, const char *second_choice)
  3104. {
  3105. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  3106. bool multi_screen = msg_next != NULL;
  3107. bool yes = default_first ? true : false;
  3108. // Wait for user confirmation or a timeout.
  3109. unsigned long previous_millis_cmd = _millis();
  3110. int8_t enc_dif = lcd_encoder_diff;
  3111. lcd_consume_click();
  3112. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  3113. for (;;) {
  3114. for (uint8_t i = 0; i < 100; ++i) {
  3115. delay_keep_alive(50);
  3116. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  3117. return -1;
  3118. manage_heater();
  3119. manage_inactivity(true);
  3120. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  3121. if (msg_next == NULL) {
  3122. lcd_set_cursor(0, 3);
  3123. if (enc_dif < lcd_encoder_diff && yes) {
  3124. lcd_print(' ');
  3125. lcd_putc_at(7, 3, '>');
  3126. yes = false;
  3127. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3128. }
  3129. else if (enc_dif > lcd_encoder_diff && !yes) {
  3130. lcd_print('>');
  3131. lcd_putc_at(7, 3, ' ');
  3132. yes = true;
  3133. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3134. }
  3135. enc_dif = lcd_encoder_diff;
  3136. }
  3137. else {
  3138. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  3139. break; //turning knob skips waiting loop
  3140. }
  3141. }
  3142. if (lcd_clicked()) {
  3143. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  3144. if (msg_next == NULL) {
  3145. //KEEPALIVE_STATE(IN_HANDLER);
  3146. lcd_set_custom_characters();
  3147. return yes;
  3148. }
  3149. else break;
  3150. }
  3151. }
  3152. if (multi_screen) {
  3153. if (msg_next == NULL) {
  3154. msg_next = msg;
  3155. }
  3156. msg_next = lcd_display_message_fullscreen_P(msg_next);
  3157. }
  3158. if (msg_next == NULL) {
  3159. lcd_set_cursor(0, 3);
  3160. if (yes) lcd_print('>');
  3161. lcd_puts_at_P(1, 3, first_choice);
  3162. lcd_set_cursor(7, 3);
  3163. if (!yes) lcd_print('>');
  3164. lcd_puts_at_P(8, 3, second_choice);
  3165. }
  3166. }
  3167. }
  3168. //! @brief Show single screen message with yes and no possible choices and wait with possible timeout
  3169. //! @param msg Message to show
  3170. //! @param allow_timeouting if true, allows time outing of the screen
  3171. //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected
  3172. //! @retval 1 yes choice selected by user
  3173. //! @retval 0 no choice selected by user
  3174. //! @retval -1 screen timed out
  3175. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  3176. {
  3177. lcd_display_message_fullscreen_P(msg);
  3178. if (default_yes) {
  3179. lcd_putc_at(0, 2, '>');
  3180. lcd_puts_P(_T(MSG_YES));
  3181. lcd_puts_at_P(1, 3, _T(MSG_NO));
  3182. }
  3183. else {
  3184. lcd_puts_at_P(1, 2, _T(MSG_YES));
  3185. lcd_putc_at(0, 3, '>');
  3186. lcd_puts_P(_T(MSG_NO));
  3187. }
  3188. int8_t retval = default_yes ? true : false;
  3189. // Wait for user confirmation or a timeout.
  3190. unsigned long previous_millis_cmd = _millis();
  3191. int8_t enc_dif = lcd_encoder_diff;
  3192. lcd_consume_click();
  3193. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3194. for (;;) {
  3195. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  3196. {
  3197. retval = -1;
  3198. break;
  3199. }
  3200. manage_heater();
  3201. manage_inactivity(true);
  3202. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  3203. lcd_set_cursor(0, 2);
  3204. if (enc_dif < lcd_encoder_diff && retval) {
  3205. lcd_print(' ');
  3206. lcd_putc_at(0, 3, '>');
  3207. retval = 0;
  3208. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3209. }
  3210. else if (enc_dif > lcd_encoder_diff && !retval) {
  3211. lcd_print('>');
  3212. lcd_putc_at(0, 3, ' ');
  3213. retval = 1;
  3214. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3215. }
  3216. enc_dif = lcd_encoder_diff;
  3217. }
  3218. if (lcd_clicked()) {
  3219. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  3220. KEEPALIVE_STATE(IN_HANDLER);
  3221. break;
  3222. }
  3223. }
  3224. lcd_encoder_diff = 0;
  3225. return retval;
  3226. }
  3227. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  3228. {
  3229. const char *msg = NULL;
  3230. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  3231. lcd_show_fullscreen_message_and_wait_P(_i("XYZ calibration failed. Bed calibration point was not found."));////MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND c=20 r=8
  3232. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  3233. if (point_too_far_mask == 0)
  3234. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3235. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3236. // Only the center point or all the three front points.
  3237. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=8
  3238. else if ((point_too_far_mask & 1) == 0)
  3239. // The right and maybe the center point out of reach.
  3240. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=8
  3241. else
  3242. // The left and maybe the center point out of reach.
  3243. msg = _i("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  3244. lcd_show_fullscreen_message_and_wait_P(msg);
  3245. } else {
  3246. if (point_too_far_mask != 0) {
  3247. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3248. // Only the center point or all the three front points.
  3249. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  3250. else if ((point_too_far_mask & 1) == 0)
  3251. // The right and maybe the center point out of reach.
  3252. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  3253. else
  3254. // The left and maybe the center point out of reach.
  3255. msg = _i("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  3256. lcd_show_fullscreen_message_and_wait_P(msg);
  3257. }
  3258. if (point_too_far_mask == 0 || result > 0) {
  3259. switch (result) {
  3260. default:
  3261. // should not happen
  3262. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3263. break;
  3264. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  3265. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  3266. break;
  3267. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  3268. msg = _i("XYZ calibration all right. X/Y axes are slightly skewed. Good job!");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD c=20 r=8
  3269. break;
  3270. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  3271. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  3272. break;
  3273. }
  3274. lcd_show_fullscreen_message_and_wait_P(msg);
  3275. }
  3276. }
  3277. }
  3278. void lcd_temp_cal_show_result(bool result) {
  3279. custom_message_type = CustomMsg::Status;
  3280. disable_x();
  3281. disable_y();
  3282. disable_z();
  3283. disable_e0();
  3284. disable_e1();
  3285. disable_e2();
  3286. setTargetBed(0); //set bed target temperature back to 0
  3287. if (result == true) {
  3288. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  3289. SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob.");
  3290. lcd_show_fullscreen_message_and_wait_P(_T(MSG_TEMP_CALIBRATION_DONE));
  3291. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  3292. }
  3293. else {
  3294. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  3295. SERIAL_ECHOLNPGM("Temperature calibration failed. Continue with pressing the knob.");
  3296. lcd_show_fullscreen_message_and_wait_P(_i("Temperature calibration failed"));////MSG_TEMP_CAL_FAILED c=20 r=8
  3297. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  3298. }
  3299. lcd_update_enable(true);
  3300. lcd_update(2);
  3301. }
  3302. static void lcd_show_end_stops() {
  3303. lcd_puts_at_P(0, 0, (PSTR("End stops diag")));
  3304. lcd_puts_at_P(0, 1, (READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  3305. lcd_puts_at_P(0, 2, (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  3306. lcd_puts_at_P(0, 3, (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  3307. }
  3308. #ifndef TMC2130
  3309. static void menu_show_end_stops() {
  3310. lcd_show_end_stops();
  3311. if (LCD_CLICKED) menu_back();
  3312. }
  3313. #endif // not defined TMC2130
  3314. // Lets the user move the Z carriage up to the end stoppers.
  3315. // When done, it sets the current Z to Z_MAX_POS and returns true.
  3316. // Otherwise the Z calibration is not changed and false is returned.
  3317. void lcd_diag_show_end_stops()
  3318. {
  3319. lcd_clear();
  3320. lcd_consume_click();
  3321. for (;;) {
  3322. manage_heater();
  3323. manage_inactivity(true);
  3324. lcd_show_end_stops();
  3325. if (lcd_clicked()) {
  3326. break;
  3327. }
  3328. }
  3329. lcd_clear();
  3330. lcd_return_to_status();
  3331. }
  3332. static void lcd_print_state(uint8_t state)
  3333. {
  3334. switch (state) {
  3335. case STATE_ON:
  3336. lcd_puts_P(_N(" 1"));
  3337. break;
  3338. case STATE_OFF:
  3339. lcd_puts_P(_N(" 0"));
  3340. break;
  3341. default:
  3342. lcd_puts_P(_T(MSG_NA));
  3343. break;
  3344. }
  3345. }
  3346. static void lcd_show_sensors_state()
  3347. {
  3348. //0: N/A; 1: OFF; 2: ON
  3349. uint8_t pinda_state = STATE_NA;
  3350. uint8_t finda_state = STATE_NA;
  3351. uint8_t idler_state = STATE_NA;
  3352. pinda_state = READ(Z_MIN_PIN);
  3353. if (mmu_enabled && ((_millis() - mmu_last_finda_response) < 1000ul) )
  3354. {
  3355. finda_state = mmu_finda;
  3356. }
  3357. if (ir_sensor_detected) {
  3358. idler_state = !READ(IR_SENSOR_PIN);
  3359. }
  3360. lcd_puts_at_P(0, 0, _i("Sensor state"));
  3361. lcd_puts_at_P(1, 1, _i("PINDA:"));
  3362. lcd_set_cursor(LCD_WIDTH - 4, 1);
  3363. lcd_print_state(pinda_state);
  3364. lcd_puts_at_P(1, 2, _i("FINDA:"));
  3365. lcd_set_cursor(LCD_WIDTH - 4, 2);
  3366. lcd_print_state(finda_state);
  3367. lcd_puts_at_P(1, 3, _i("IR:"));
  3368. lcd_set_cursor(LCD_WIDTH - 4, 3);
  3369. lcd_print_state(idler_state);
  3370. }
  3371. void lcd_menu_show_sensors_state() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  3372. {
  3373. lcd_timeoutToStatus.stop();
  3374. lcd_show_sensors_state();
  3375. if(LCD_CLICKED)
  3376. {
  3377. lcd_timeoutToStatus.start();
  3378. menu_back();
  3379. }
  3380. }
  3381. void prusa_statistics_err(char c){
  3382. SERIAL_ECHOPGM("{[ERR:");
  3383. SERIAL_ECHO(c);
  3384. SERIAL_ECHO(']');
  3385. prusa_stat_farm_number();
  3386. }
  3387. static void prusa_statistics_case0(uint8_t statnr){
  3388. SERIAL_ECHO('{');
  3389. prusa_stat_printerstatus(statnr);
  3390. prusa_stat_farm_number();
  3391. prusa_stat_printinfo();
  3392. }
  3393. void prusa_statistics(int _message, uint8_t _fil_nr) {
  3394. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  3395. return;
  3396. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  3397. switch (_message)
  3398. {
  3399. case 0: // default message
  3400. if (busy_state == PAUSED_FOR_USER)
  3401. {
  3402. prusa_statistics_case0(15);
  3403. }
  3404. else if (isPrintPaused)
  3405. {
  3406. prusa_statistics_case0(14);
  3407. }
  3408. else if (IS_SD_PRINTING || loading_flag)
  3409. {
  3410. prusa_statistics_case0(4);
  3411. }
  3412. else
  3413. {
  3414. SERIAL_ECHO('{');
  3415. prusa_stat_printerstatus(1);
  3416. prusa_stat_farm_number();
  3417. prusa_stat_diameter();
  3418. status_number = 1;
  3419. }
  3420. break;
  3421. case 1: // 1 heating
  3422. farm_status = 2;
  3423. SERIAL_ECHO('{');
  3424. prusa_stat_printerstatus(2);
  3425. prusa_stat_farm_number();
  3426. status_number = 2;
  3427. farm_timer = 1;
  3428. break;
  3429. case 2: // heating done
  3430. farm_status = 3;
  3431. SERIAL_ECHO('{');
  3432. prusa_stat_printerstatus(3);
  3433. prusa_stat_farm_number();
  3434. SERIAL_ECHOLN('}');
  3435. status_number = 3;
  3436. farm_timer = 1;
  3437. if (IS_SD_PRINTING || loading_flag)
  3438. {
  3439. farm_status = 4;
  3440. SERIAL_ECHO('{');
  3441. prusa_stat_printerstatus(4);
  3442. prusa_stat_farm_number();
  3443. status_number = 4;
  3444. }
  3445. else
  3446. {
  3447. SERIAL_ECHO('{');
  3448. prusa_stat_printerstatus(3);
  3449. prusa_stat_farm_number();
  3450. status_number = 3;
  3451. }
  3452. farm_timer = 1;
  3453. break;
  3454. case 3: // filament change
  3455. // must do a return here to prevent doing SERIAL_ECHOLN("}") at the very end of this function
  3456. // saved a considerable amount of FLASH
  3457. return;
  3458. break;
  3459. case 4: // print succesfull
  3460. SERIAL_ECHOPGM("{[RES:1][FIL:");
  3461. MYSERIAL.print(int(_fil_nr));
  3462. SERIAL_ECHO(']');
  3463. prusa_stat_printerstatus(status_number);
  3464. prusa_stat_farm_number();
  3465. farm_timer = 2;
  3466. break;
  3467. case 5: // print not succesfull
  3468. SERIAL_ECHOPGM("{[RES:0][FIL:");
  3469. MYSERIAL.print(int(_fil_nr));
  3470. SERIAL_ECHO(']');
  3471. prusa_stat_printerstatus(status_number);
  3472. prusa_stat_farm_number();
  3473. farm_timer = 2;
  3474. break;
  3475. case 6: // print done
  3476. SERIAL_ECHOPGM("{[PRN:8]");
  3477. prusa_stat_farm_number();
  3478. status_number = 8;
  3479. farm_timer = 2;
  3480. break;
  3481. case 7: // print done - stopped
  3482. SERIAL_ECHOPGM("{[PRN:9]");
  3483. prusa_stat_farm_number();
  3484. status_number = 9;
  3485. farm_timer = 2;
  3486. break;
  3487. case 8: // printer started
  3488. SERIAL_ECHOPGM("{[PRN:0]");
  3489. prusa_stat_farm_number();
  3490. status_number = 0;
  3491. farm_timer = 2;
  3492. break;
  3493. case 20: // echo farm no
  3494. SERIAL_ECHO('{');
  3495. prusa_stat_printerstatus(status_number);
  3496. prusa_stat_farm_number();
  3497. farm_timer = 4;
  3498. break;
  3499. case 21: // temperatures
  3500. SERIAL_ECHO('{');
  3501. prusa_stat_temperatures();
  3502. prusa_stat_farm_number();
  3503. prusa_stat_printerstatus(status_number);
  3504. break;
  3505. case 22: // waiting for filament change
  3506. SERIAL_ECHOPGM("{[PRN:5]");
  3507. prusa_stat_farm_number();
  3508. status_number = 5;
  3509. break;
  3510. case 90: // Error - Thermal Runaway
  3511. prusa_statistics_err('1');
  3512. break;
  3513. case 91: // Error - Thermal Runaway Preheat
  3514. prusa_statistics_err('2');
  3515. break;
  3516. case 92: // Error - Min temp
  3517. prusa_statistics_err('3');
  3518. break;
  3519. case 93: // Error - Max temp
  3520. prusa_statistics_err('4');
  3521. break;
  3522. case 99: // heartbeat
  3523. SERIAL_ECHOPGM("{[PRN:99]");
  3524. prusa_stat_temperatures();
  3525. prusa_stat_farm_number();
  3526. break;
  3527. }
  3528. SERIAL_ECHOLN('}');
  3529. }
  3530. static void prusa_stat_printerstatus(int _status)
  3531. {
  3532. SERIAL_ECHOPGM("[PRN:");
  3533. SERIAL_ECHO(_status);
  3534. SERIAL_ECHO(']');
  3535. }
  3536. static void prusa_stat_farm_number() {
  3537. SERIAL_ECHOPGM("[PFN:0]");
  3538. }
  3539. static void prusa_stat_diameter() {
  3540. SERIAL_ECHOPGM("[DIA:");
  3541. SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM));
  3542. SERIAL_ECHO(']');
  3543. }
  3544. static void prusa_stat_temperatures()
  3545. {
  3546. SERIAL_ECHOPGM("[ST0:");
  3547. SERIAL_ECHO(target_temperature[0]);
  3548. SERIAL_ECHOPGM("][STB:");
  3549. SERIAL_ECHO(target_temperature_bed);
  3550. SERIAL_ECHOPGM("][AT0:");
  3551. SERIAL_ECHO(current_temperature[0]);
  3552. SERIAL_ECHOPGM("][ATB:");
  3553. SERIAL_ECHO(current_temperature_bed);
  3554. SERIAL_ECHO(']');
  3555. }
  3556. static void prusa_stat_printinfo()
  3557. {
  3558. SERIAL_ECHOPGM("[TFU:");
  3559. SERIAL_ECHO(total_filament_used);
  3560. SERIAL_ECHOPGM("][PCD:");
  3561. SERIAL_ECHO(itostr3(card.percentDone()));
  3562. SERIAL_ECHOPGM("][FEM:");
  3563. SERIAL_ECHO(itostr3(feedmultiply));
  3564. SERIAL_ECHOPGM("][FNM:");
  3565. SERIAL_ECHO(card.longFilename[0] ? card.longFilename : card.filename);
  3566. SERIAL_ECHOPGM("][TIM:");
  3567. if (starttime != 0)
  3568. {
  3569. SERIAL_ECHO(_millis() / 1000 - starttime / 1000);
  3570. }
  3571. else
  3572. {
  3573. SERIAL_ECHO(0);
  3574. }
  3575. SERIAL_ECHOPGM("][FWR:");
  3576. SERIAL_ECHORPGM(FW_VERSION_STR_P());
  3577. SERIAL_ECHO(']');
  3578. prusa_stat_diameter();
  3579. }
  3580. /*
  3581. void lcd_pick_babystep(){
  3582. int enc_dif = 0;
  3583. int cursor_pos = 1;
  3584. int fsm = 0;
  3585. lcd_clear();
  3586. lcd_set_cursor(0, 0);
  3587. lcd_puts_P(_i("Pick print"));////MSG_PICK_Z
  3588. lcd_set_cursor(3, 2);
  3589. lcd_print('1');
  3590. lcd_set_cursor(3, 3);
  3591. lcd_print('2');
  3592. lcd_set_cursor(12, 2);
  3593. lcd_print('3');
  3594. lcd_set_cursor(12, 3);
  3595. lcd_print('4');
  3596. lcd_set_cursor(1, 2);
  3597. lcd_print('>');
  3598. enc_dif = lcd_encoder_diff;
  3599. while (fsm == 0) {
  3600. manage_heater();
  3601. manage_inactivity(true);
  3602. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  3603. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  3604. if (enc_dif > lcd_encoder_diff ) {
  3605. cursor_pos --;
  3606. }
  3607. if (enc_dif < lcd_encoder_diff ) {
  3608. cursor_pos ++;
  3609. }
  3610. if (cursor_pos > 4) {
  3611. cursor_pos = 4;
  3612. }
  3613. if (cursor_pos < 1) {
  3614. cursor_pos = 1;
  3615. }
  3616. lcd_set_cursor(1, 2);
  3617. lcd_print(' ');
  3618. lcd_set_cursor(1, 3);
  3619. lcd_print(' ');
  3620. lcd_set_cursor(10, 2);
  3621. lcd_print(' ');
  3622. lcd_set_cursor(10, 3);
  3623. lcd_print(' ');
  3624. if (cursor_pos < 3) {
  3625. lcd_set_cursor(1, cursor_pos+1);
  3626. lcd_print('>');
  3627. }else{
  3628. lcd_set_cursor(10, cursor_pos-1);
  3629. lcd_print('>');
  3630. }
  3631. enc_dif = lcd_encoder_diff;
  3632. _delay(100);
  3633. }
  3634. }
  3635. if (lcd_clicked()) {
  3636. fsm = cursor_pos;
  3637. int babyStepZ;
  3638. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  3639. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  3640. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  3641. _delay(500);
  3642. }
  3643. };
  3644. lcd_clear();
  3645. lcd_return_to_status();
  3646. }
  3647. */
  3648. void lcd_move_menu_axis()
  3649. {
  3650. MENU_BEGIN();
  3651. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3652. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X
  3653. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y
  3654. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z
  3655. MENU_ITEM_SUBMENU_P(_T(MSG_EXTRUDER), lcd_move_e);////MSG_EXTRUDER
  3656. MENU_END();
  3657. }
  3658. static void lcd_move_menu_1mm()
  3659. {
  3660. move_menu_scale = 1.0;
  3661. lcd_move_menu_axis();
  3662. }
  3663. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  3664. {
  3665. do
  3666. {
  3667. eeprom_write_byte((unsigned char*)pos, *value);
  3668. pos++;
  3669. value++;
  3670. } while (--size);
  3671. }
  3672. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  3673. {
  3674. do
  3675. {
  3676. *value = eeprom_read_byte((unsigned char*)pos);
  3677. pos++;
  3678. value++;
  3679. } while (--size);
  3680. }
  3681. #ifdef SDCARD_SORT_ALPHA
  3682. static void lcd_sort_type_set() {
  3683. uint8_t sdSort;
  3684. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3685. switch (sdSort) {
  3686. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3687. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3688. default: sdSort = SD_SORT_TIME;
  3689. }
  3690. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  3691. card.presort_flag = true;
  3692. }
  3693. #endif //SDCARD_SORT_ALPHA
  3694. #ifdef TMC2130
  3695. static void lcd_crash_mode_info()
  3696. {
  3697. lcd_update_enable(true);
  3698. static uint32_t tim = 0;
  3699. if ((tim + 1000) < _millis())
  3700. {
  3701. lcd_clear();
  3702. fputs_P(_i("Crash detection can\nbe turned on only in\nNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
  3703. tim = _millis();
  3704. }
  3705. menu_back_if_clicked();
  3706. }
  3707. static void lcd_crash_mode_info2()
  3708. {
  3709. lcd_update_enable(true);
  3710. static uint32_t tim = 0;
  3711. if ((tim + 1000) < _millis())
  3712. {
  3713. lcd_clear();
  3714. fputs_P(_i("WARNING:\nCrash detection\ndisabled in\nStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
  3715. tim = _millis();
  3716. }
  3717. menu_back_if_clicked();
  3718. }
  3719. #endif //TMC2130
  3720. #ifdef FILAMENT_SENSOR
  3721. static void lcd_filament_autoload_info()
  3722. {
  3723. uint8_t nlines;
  3724. lcd_update_enable(true);
  3725. static uint32_t tim = 0;
  3726. if ((tim + 1000) < _millis())
  3727. {
  3728. lcd_display_message_fullscreen_nonBlocking_P(_i("Autoloading filament available only when filament sensor is turned on..."), nlines); ////MSG_AUTOLOADING_ONLY_IF_FSENS_ON c=20 r=4
  3729. tim = _millis();
  3730. }
  3731. menu_back_if_clicked();
  3732. }
  3733. static void lcd_fsensor_fail()
  3734. {
  3735. uint8_t nlines;
  3736. lcd_update_enable(true);
  3737. static uint32_t tim = 0;
  3738. if ((tim + 1000) < _millis())
  3739. {
  3740. lcd_display_message_fullscreen_nonBlocking_P(_i("ERROR: Filament sensor is not responding, please check connection."), nlines);////MSG_FSENS_NOT_RESPONDING c=20 r=4
  3741. tim = _millis();
  3742. }
  3743. menu_back_if_clicked();
  3744. }
  3745. #endif //FILAMENT_SENSOR
  3746. //-//
  3747. static void lcd_sound_state_set(void)
  3748. {
  3749. Sound_CycleState();
  3750. }
  3751. #ifndef MMU_FORCE_STEALTH_MODE
  3752. static void lcd_silent_mode_mmu_set() {
  3753. if (SilentModeMenu_MMU == 1) SilentModeMenu_MMU = 0;
  3754. else SilentModeMenu_MMU = 1;
  3755. //saving to eeprom is done in mmu_loop() after mmu actually switches state and confirms with "ok"
  3756. }
  3757. #endif //MMU_FORCE_STEALTH_MODE
  3758. static void lcd_silent_mode_set() {
  3759. switch (SilentModeMenu) {
  3760. #ifdef TMC2130
  3761. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3762. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3763. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3764. #else
  3765. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3766. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3767. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3768. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3769. #endif //TMC2130
  3770. }
  3771. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3772. #ifdef TMC2130
  3773. lcd_display_message_fullscreen_P(_i("Mode change in progress ..."));
  3774. // Wait until the planner queue is drained and the stepper routine achieves
  3775. // an idle state.
  3776. st_synchronize();
  3777. if (tmc2130_wait_standstill_xy(1000)) {}
  3778. // MYSERIAL.print("standstill OK");
  3779. // else
  3780. // MYSERIAL.print("standstill NG!");
  3781. cli();
  3782. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3783. update_mode_profile();
  3784. tmc2130_init();
  3785. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3786. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3787. st_reset_timer();
  3788. sei();
  3789. #endif //TMC2130
  3790. st_current_init();
  3791. #ifdef TMC2130
  3792. if (lcd_crash_detect_enabled() && (SilentModeMenu != SILENT_MODE_NORMAL))
  3793. menu_submenu(lcd_crash_mode_info2);
  3794. lcd_encoder_diff=0; // reset 'encoder buffer'
  3795. #endif //TMC2130
  3796. }
  3797. #ifdef TMC2130
  3798. static void crash_mode_switch()
  3799. {
  3800. if (lcd_crash_detect_enabled())
  3801. {
  3802. lcd_crash_detect_disable();
  3803. }
  3804. else
  3805. {
  3806. lcd_crash_detect_enable();
  3807. }
  3808. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true);
  3809. else menu_goto(lcd_settings_menu, 9, true, true);
  3810. }
  3811. #endif //TMC2130
  3812. #ifdef FILAMENT_SENSOR
  3813. static void lcd_fsensor_state_set()
  3814. {
  3815. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3816. if (!FSensorStateMenu) {
  3817. fsensor_disable();
  3818. if (fsensor_autoload_enabled && !mmu_enabled)
  3819. menu_submenu(lcd_filament_autoload_info);
  3820. }
  3821. else {
  3822. fsensor_enable();
  3823. if (fsensor_not_responding && !mmu_enabled)
  3824. menu_submenu(lcd_fsensor_fail);
  3825. }
  3826. }
  3827. #endif //FILAMENT_SENSOR
  3828. void lcd_set_degree() {
  3829. lcd_set_custom_characters_degree();
  3830. }
  3831. #if (LANG_MODE != 0)
  3832. void menu_setlang(unsigned char lang)
  3833. {
  3834. if (!lang_select(lang))
  3835. {
  3836. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language?"), false, true))
  3837. lang_boot_update_start(lang);
  3838. lcd_update_enable(true);
  3839. lcd_clear();
  3840. menu_goto(lcd_language_menu, 0, true, true);
  3841. lcd_timeoutToStatus.stop(); //infinite timeout
  3842. lcd_draw_update = 2;
  3843. }
  3844. }
  3845. static void lcd_language_menu()
  3846. {
  3847. MENU_BEGIN();
  3848. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3849. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3850. {
  3851. menu_setlang(0);
  3852. return;
  3853. }
  3854. uint8_t cnt = lang_get_count();
  3855. #ifdef W25X20CL
  3856. if (cnt == 2) //display secondary language in case of clear xflash
  3857. {
  3858. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3859. {
  3860. menu_setlang(1);
  3861. return;
  3862. }
  3863. }
  3864. else
  3865. for (int i = 2; i < cnt; i++) //skip seconday language - solved in lang_select (MK3)
  3866. #else //W25X20CL
  3867. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3868. #endif //W25X20CL
  3869. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3870. {
  3871. menu_setlang(i);
  3872. return;
  3873. }
  3874. MENU_END();
  3875. }
  3876. #endif //(LANG_MODE != 0)
  3877. void lcd_mesh_bedleveling()
  3878. {
  3879. mesh_bed_run_from_menu = true;
  3880. enquecommand_P(PSTR("G80"));
  3881. lcd_return_to_status();
  3882. }
  3883. void lcd_mesh_calibration()
  3884. {
  3885. enquecommand_P(PSTR("M45"));
  3886. lcd_return_to_status();
  3887. }
  3888. void lcd_mesh_calibration_z()
  3889. {
  3890. enquecommand_P(PSTR("M45 Z"));
  3891. lcd_return_to_status();
  3892. }
  3893. void lcd_pinda_calibration_menu()
  3894. {
  3895. MENU_BEGIN();
  3896. MENU_ITEM_BACK_P(_T(MSG_MENU_CALIBRATION));
  3897. MENU_ITEM_SUBMENU_P(_i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17 r=1
  3898. MENU_END();
  3899. }
  3900. void lcd_temp_calibration_set() {
  3901. bool temp_cal_active = eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE);
  3902. temp_cal_active = !temp_cal_active;
  3903. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3904. }
  3905. #ifdef HAS_SECOND_SERIAL_PORT
  3906. void lcd_second_serial_set() {
  3907. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3908. else selectedSerialPort = 1;
  3909. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3910. MYSERIAL.begin(BAUDRATE);
  3911. }
  3912. #endif //HAS_SECOND_SERIAL_PORT
  3913. void lcd_calibrate_pinda() {
  3914. enquecommand_P(PSTR("G76"));
  3915. lcd_return_to_status();
  3916. }
  3917. #ifndef SNMM
  3918. /*void lcd_calibrate_extruder() {
  3919. if (degHotend0() > EXTRUDE_MINTEMP)
  3920. {
  3921. current_position[E_AXIS] = 0; //set initial position to zero
  3922. plan_set_e_position(current_position[E_AXIS]);
  3923. //long steps_start = st_get_position(E_AXIS);
  3924. long steps_final;
  3925. float e_steps_per_unit;
  3926. float feedrate = (180 / axis_steps_per_unit[E_AXIS]) * 1; //3 //initial automatic extrusion feedrate (depends on current value of axis_steps_per_unit to avoid too fast extrusion)
  3927. float e_shift_calibration = (axis_steps_per_unit[E_AXIS] > 180 ) ? ((180 / axis_steps_per_unit[E_AXIS]) * 70): 70; //length of initial automatic extrusion sequence
  3928. const char *msg_e_cal_knob = _i("Rotate knob until mark reaches extruder body. Click when done.");////MSG_E_CAL_KNOB c=20 r=8
  3929. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3930. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3931. unsigned long msg_millis;
  3932. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  3933. lcd_clear();
  3934. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  3935. current_position[E_AXIS] += e_shift_calibration;
  3936. plan_buffer_line_curposXYZE(feedrate, active_extruder);
  3937. st_synchronize();
  3938. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3939. msg_millis = _millis();
  3940. while (!LCD_CLICKED) {
  3941. if (multi_screen && _millis() - msg_millis > 5000) {
  3942. if (msg_next_e_cal_knob == NULL)
  3943. msg_next_e_cal_knob = msg_e_cal_knob;
  3944. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3945. msg_millis = _millis();
  3946. }
  3947. //manage_inactivity(true);
  3948. manage_heater();
  3949. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3950. delay_keep_alive(50);
  3951. //previous_millis_cmd = _millis();
  3952. lcd_encoder += (lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  3953. lcd_encoder_diff = 0;
  3954. if (!planner_queue_full()) {
  3955. current_position[E_AXIS] += float(abs((int)lcd_encoder)) * 0.01; //0.05
  3956. lcd_encoder = 0;
  3957. plan_buffer_line_curposXYZE(feedrate, active_extruder);
  3958. }
  3959. }
  3960. }
  3961. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3962. //steps_final = st_get_position(E_AXIS);
  3963. lcd_draw_update = 1;
  3964. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3965. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3966. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3967. lcd_clear();
  3968. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3969. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3970. //lcd_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3971. //delay_keep_alive(2000);
  3972. delay_keep_alive(500);
  3973. lcd_show_fullscreen_message_and_wait_P(_i("E calibration finished. Please clean the nozzle. Click when done."));////MSG_CLEAN_NOZZLE_E c=20 r=8
  3974. lcd_update_enable(true);
  3975. lcd_draw_update = 2;
  3976. }
  3977. else
  3978. {
  3979. show_preheat_nozzle_warning();
  3980. }
  3981. lcd_return_to_status();
  3982. }
  3983. void lcd_extr_cal_reset() {
  3984. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3985. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3986. //extrudemultiply = 100;
  3987. enquecommand_P(PSTR("M500"));
  3988. }*/
  3989. #endif
  3990. void lcd_toshiba_flash_air_compatibility_toggle()
  3991. {
  3992. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3993. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3994. }
  3995. //! @brief Continue first layer calibration with previous value or start from zero?
  3996. //!
  3997. //! @code{.unparsed}
  3998. //! |01234567890123456789|
  3999. //! |Sheet Smooth1 actual| c=a, c=b, a+b = 13
  4000. //! |Z offset: -1.480 mm | c=a, c=b, a+b = 14
  4001. //! |>Continue | c=19
  4002. //! | Start from zero | c=19
  4003. //! ----------------------
  4004. //! @endcode
  4005. void lcd_first_layer_calibration_reset()
  4006. {
  4007. typedef struct
  4008. {
  4009. bool reset;
  4010. } MenuData;
  4011. static_assert(sizeof(menu_data)>= sizeof(MenuData),"_menu_data_t doesn't fit into menu_data");
  4012. MenuData* menuData = (MenuData*)&(menu_data[0]);
  4013. if(LCD_CLICKED || !eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))) ||
  4014. (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST) ||
  4015. (0 == static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>
  4016. (&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))))
  4017. {
  4018. if (menuData->reset)
  4019. {
  4020. eeprom_update_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset), 0xffff);
  4021. }
  4022. menu_goto(lcd_v2_calibration,0,true,true);
  4023. }
  4024. if (lcd_encoder > 0)
  4025. {
  4026. menuData->reset = true;
  4027. lcd_encoder = 1;
  4028. }
  4029. else if (lcd_encoder < 1)
  4030. {
  4031. menuData->reset = false;
  4032. lcd_encoder = 0;
  4033. }
  4034. char sheet_name[sizeof(Sheet::name)];
  4035. eeprom_read_block(sheet_name, &EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].name, sizeof(Sheet::name));
  4036. lcd_set_cursor(0, 0);
  4037. float offset = static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))/cs.axis_steps_per_unit[Z_AXIS];
  4038. lcd_printf_P(_i("Sheet %.7s\nZ offset: %+1.3f mm\n%cContinue\n%cStart from zero"), //// \n denotes line break, %.7s is replaced by 7 character long sheet name, %+1.3f is replaced by 6 character long floating point number, %c is replaced by > or white space (one character) based on whether first or second option is selected. % denoted place holders can not be reordered. r=4
  4039. sheet_name, offset, menuData->reset ? ' ' : '>', menuData->reset ? '>' : ' ');
  4040. }
  4041. void lcd_v2_calibration()
  4042. {
  4043. if (mmu_enabled)
  4044. {
  4045. const uint8_t filament = choose_menu_P(
  4046. _i("Select filament:"), ////c=20 r=1
  4047. _T(MSG_FILAMENT),_i("Cancel")); ////c=19 r=1
  4048. if (filament < 5)
  4049. {
  4050. lay1cal_filament = filament;
  4051. }
  4052. else
  4053. {
  4054. menu_back();
  4055. return;
  4056. }
  4057. }
  4058. else if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  4059. {
  4060. bool loaded = false;
  4061. if (fsensor_enabled && ir_sensor_detected)
  4062. {
  4063. loaded = (digitalRead(IR_SENSOR_PIN) == 0);
  4064. }
  4065. else
  4066. {
  4067. loaded = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), false, true);
  4068. lcd_update_enabled = true;
  4069. }
  4070. if (!loaded)
  4071. {
  4072. lcd_display_message_fullscreen_P(_i("Please load filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  4073. lcd_consume_click();
  4074. for (uint_least8_t i = 0; i < 20; i++) { //wait max. 2s
  4075. delay_keep_alive(100);
  4076. if (lcd_clicked()) {
  4077. break;
  4078. }
  4079. }
  4080. lcd_update_enabled = true;
  4081. menu_back();
  4082. return;
  4083. }
  4084. }
  4085. eFilamentAction = FilamentAction::Lay1Cal;
  4086. menu_goto(lcd_generic_preheat_menu, 0, true, true);
  4087. }
  4088. void lcd_wizard() {
  4089. bool result = true;
  4090. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  4091. result = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Running Wizard will delete current calibration results and start from the beginning. Continue?"), false, false);////MSG_WIZARD_RERUN c=20 r=7
  4092. }
  4093. if (result) {
  4094. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  4095. lcd_wizard(WizState::Run);
  4096. }
  4097. else {
  4098. lcd_return_to_status();
  4099. lcd_update_enable(true);
  4100. lcd_update(2);
  4101. }
  4102. }
  4103. #if (LANG_MODE != 0)
  4104. void lcd_language()
  4105. {
  4106. lcd_update_enable(true);
  4107. lcd_clear();
  4108. menu_goto(lcd_language_menu, 0, true, true);
  4109. lcd_timeoutToStatus.stop(); //infinite timeout
  4110. lcd_draw_update = 2;
  4111. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  4112. {
  4113. _delay(50);
  4114. lcd_update(0);
  4115. manage_heater();
  4116. manage_inactivity(true);
  4117. }
  4118. if (lang_is_selected())
  4119. lcd_return_to_status();
  4120. else
  4121. lang_select(LANG_ID_PRI);
  4122. }
  4123. #endif
  4124. static void wait_preheat()
  4125. {
  4126. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  4127. plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS] / 60);
  4128. delay_keep_alive(2000);
  4129. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  4130. lcd_set_custom_characters();
  4131. while (abs(degHotend(0) - degTargetHotend(0)) > 3) {
  4132. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  4133. lcd_set_cursor(0, 4);
  4134. //Print the hotend temperature (9 chars total)
  4135. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  4136. delay_keep_alive(1000);
  4137. }
  4138. }
  4139. static void lcd_wizard_load()
  4140. {
  4141. if (mmu_enabled)
  4142. {
  4143. lcd_show_fullscreen_message_and_wait_P(_i("Please insert filament into the first tube of the MMU, then press the knob to load it."));////c=20 r=8
  4144. tmp_extruder = 0;
  4145. }
  4146. else
  4147. {
  4148. lcd_show_fullscreen_message_and_wait_P(_i("Please insert filament into the extruder, then press the knob to load it."));////MSG_WIZARD_LOAD_FILAMENT c=20 r=8
  4149. }
  4150. lcd_update_enable(false);
  4151. lcd_clear();
  4152. lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
  4153. #ifdef SNMM
  4154. change_extr(0);
  4155. #endif
  4156. loading_flag = true;
  4157. gcode_M701();
  4158. }
  4159. bool lcd_autoDepleteEnabled()
  4160. {
  4161. return (lcd_autoDeplete && fsensor_enabled);
  4162. }
  4163. static void wizard_lay1cal_message(bool cold)
  4164. {
  4165. lcd_show_fullscreen_message_and_wait_P(
  4166. _i("Now I will calibrate distance between tip of the nozzle and heatbed surface.")); ////MSG_WIZARD_V2_CAL c=20 r=8
  4167. if (mmu_enabled)
  4168. {
  4169. lcd_show_fullscreen_message_and_wait_P(
  4170. _i("Choose a filament for the First Layer Calibration and select it in the on-screen menu."));
  4171. }
  4172. else if (cold)
  4173. {
  4174. lcd_show_fullscreen_message_and_wait_P(
  4175. _i("Select temperature which matches your material."));
  4176. }
  4177. lcd_show_fullscreen_message_and_wait_P(
  4178. _i("The printer will start printing a zig-zag line. Rotate the knob until you reach the optimal height. Check the pictures in the handbook (Calibration chapter).")); ////MSG_WIZARD_V2_CAL_2 c=20 r=12
  4179. }
  4180. //! @brief Printer first run wizard (Selftest and calibration)
  4181. //!
  4182. //!
  4183. //! First layer calibration with MMU state diagram
  4184. //!
  4185. //! @startuml
  4186. //! [*] --> IsFil
  4187. //! IsFil : Is any filament loaded?
  4188. //! LoadFilCold : Push the button to start loading Filament 1
  4189. //!
  4190. //! IsFil --> Lay1CalCold : yes
  4191. //! IsFil --> LoadFilCold : no
  4192. //! LoadFilCold --> Lay1CalCold : click
  4193. //! @enduml
  4194. //!
  4195. //! First layer calibration without MMU state diagram
  4196. //!
  4197. //! @startuml
  4198. //! [*] --> IsFil
  4199. //! IsFil : Is filament loaded?
  4200. //! Preheat : Select nozle temperature which matches your material.
  4201. //! LoadFilHot : Insert filament to extruder and press the knob.
  4202. //!
  4203. //! IsFil --> Lay1CalCold : yes
  4204. //! IsFil --> Preheat : no
  4205. //! Preheat --> LoadFilHot : select
  4206. //! LoadFilHot --> Lay1CalHot : click
  4207. //! @enduml
  4208. //!
  4209. //! @param state Entry point of the wizard
  4210. //!
  4211. //! state | description
  4212. //! ---------------------- | ----------------
  4213. //! WizState::Run | Main entry point
  4214. //! WizState::RepeatLay1Cal | Entry point after passing 1st layer calibration
  4215. //! WizState::LoadFilHot | Entry point after temporarily left for preheat before load filament
  4216. void lcd_wizard(WizState state)
  4217. {
  4218. using S = WizState;
  4219. bool end = false;
  4220. int wizard_event;
  4221. const char *msg = NULL;
  4222. // Make sure EEPROM_WIZARD_ACTIVE is true if entering using different entry point
  4223. // other than WizState::Run - it is useful for debugging wizard.
  4224. if (state != S::Run) eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  4225. FORCE_BL_ON_START;
  4226. while (!end) {
  4227. printf_P(PSTR("Wizard state: %d\n"), state);
  4228. switch (state) {
  4229. case S::Run: //Run wizard?
  4230. // 2019-08-07 brutal hack - solving the "viper" situation.
  4231. // It is caused by the fact, that tmc2130_st_isr makes a crash detection before the printers really starts.
  4232. // And thus it calles stop_and_save_print_to_ram which sets the saved_printing flag.
  4233. // Having this flag set during normal printing is lethal - mesh_plan_buffer_line exist in the middle of planning long travels
  4234. // which results in distorted print.
  4235. // This primarily happens when the printer is new and parked in 0,0
  4236. // So any new printer will fail the first layer calibration unless being reset or the Stop function gets called.
  4237. // We really must find a way to prevent the crash from happening before the printer is started - that would be the correct solution.
  4238. // Btw. the flag may even trigger the viper situation on normal start this way and the user won't be able to find out why.
  4239. saved_printing = false;
  4240. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Hi, I am your Original Prusa i3 printer. Would you like me to guide you through the setup process?"), false, true);////MSG_WIZARD_WELCOME c=20 r=7
  4241. if (wizard_event) {
  4242. state = S::Restore;
  4243. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  4244. }
  4245. else {
  4246. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  4247. end = true;
  4248. }
  4249. break;
  4250. case S::Restore:
  4251. switch (calibration_status()) {
  4252. case CALIBRATION_STATUS_ASSEMBLED: state = S::Selftest; break; //run selftest
  4253. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = S::Xyz; break; //run xyz cal.
  4254. case CALIBRATION_STATUS_Z_CALIBRATION: state = S::Z; break; //run z cal.
  4255. case CALIBRATION_STATUS_LIVE_ADJUST: state = S::IsFil; break; //run live adjust
  4256. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  4257. default: state = S::Selftest; break; //if calibration status is unknown, run wizard from the beginning
  4258. }
  4259. break;
  4260. case S::Selftest:
  4261. lcd_show_fullscreen_message_and_wait_P(_i("First, I will run the selftest to check most common assembly problems."));////MSG_WIZARD_SELFTEST c=20 r=8
  4262. wizard_event = lcd_selftest();
  4263. if (wizard_event) {
  4264. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  4265. state = S::Xyz;
  4266. }
  4267. else end = true;
  4268. break;
  4269. case S::Xyz:
  4270. lcd_show_fullscreen_message_and_wait_P(_i("I will run xyz calibration now. It will take approx. 12 mins."));////MSG_WIZARD_XYZ_CAL c=20 r=8
  4271. wizard_event = gcode_M45(false, 0);
  4272. if (wizard_event) state = S::IsFil;
  4273. else end = true;
  4274. break;
  4275. case S::Z:
  4276. lcd_show_fullscreen_message_and_wait_P(_i("Please remove shipping helpers first."));
  4277. lcd_show_fullscreen_message_and_wait_P(_i("Now remove the test print from steel sheet."));
  4278. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  4279. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  4280. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  4281. wizard_event = gcode_M45(true, 0);
  4282. if (wizard_event) {
  4283. //current filament needs to be unloaded and then new filament should be loaded
  4284. //start to preheat nozzle for unloading remaining PLA filament
  4285. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  4286. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));
  4287. wait_preheat();
  4288. //unload current filament
  4289. unload_filament();
  4290. //load filament
  4291. lcd_wizard_load();
  4292. setTargetHotend(0, 0); //we are finished, cooldown nozzle
  4293. state = S::Finish; //shipped, no need to set first layer, go to final message directly
  4294. }
  4295. else end = true;
  4296. break;
  4297. case S::IsFil:
  4298. //start to preheat nozzle and bed to save some time later
  4299. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  4300. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  4301. if (mmu_enabled)
  4302. {
  4303. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), true);
  4304. } else
  4305. {
  4306. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), true);
  4307. }
  4308. if (wizard_event) state = S::Lay1CalCold;
  4309. else
  4310. {
  4311. if(mmu_enabled) state = S::LoadFilCold;
  4312. else state = S::Preheat;
  4313. }
  4314. break;
  4315. case S::Preheat:
  4316. menu_goto(lcd_preheat_menu,0,false,true);
  4317. lcd_show_fullscreen_message_and_wait_P(_i("Select nozzle preheat temperature which matches your material."));
  4318. end = true; // Leave wizard temporarily for lcd_preheat_menu
  4319. break;
  4320. case S::LoadFilHot:
  4321. wait_preheat();
  4322. lcd_wizard_load();
  4323. state = S::Lay1CalHot;
  4324. break;
  4325. case S::LoadFilCold:
  4326. lcd_wizard_load();
  4327. state = S::Lay1CalCold;
  4328. break;
  4329. case S::Lay1CalCold:
  4330. wizard_lay1cal_message(true);
  4331. menu_goto(lcd_v2_calibration,0,false,true);
  4332. end = true; // Leave wizard temporarily for lcd_v2_calibration
  4333. break;
  4334. case S::Lay1CalHot:
  4335. wizard_lay1cal_message(false);
  4336. lcd_commands_type = LcdCommands::Layer1Cal;
  4337. end = true; // Leave wizard temporarily for lcd_v2_calibration
  4338. break;
  4339. case S::RepeatLay1Cal:
  4340. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Do you want to repeat last step to readjust distance between nozzle and heatbed?"), false);////MSG_WIZARD_REPEAT_V2_CAL c=20 r=7
  4341. if (wizard_event)
  4342. {
  4343. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  4344. state = S::Lay1CalCold;
  4345. }
  4346. else
  4347. {
  4348. lcd_show_fullscreen_message_and_wait_P(_i("If you have additional steel sheets, calibrate their presets in Settings - HW Setup - Steel sheets."));
  4349. state = S::Finish;
  4350. }
  4351. break;
  4352. case S::Finish:
  4353. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  4354. end = true;
  4355. break;
  4356. default: break;
  4357. }
  4358. }
  4359. FORCE_BL_ON_END;
  4360. printf_P(_N("Wizard end state: %d\n"), state);
  4361. switch (state) { //final message
  4362. case S::Restore: //printer was already calibrated
  4363. msg = _T(MSG_WIZARD_DONE);
  4364. break;
  4365. case S::Selftest: //selftest
  4366. case S::Xyz: //xyz cal.
  4367. case S::Z: //z cal.
  4368. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  4369. break;
  4370. case S::Finish: //we are finished
  4371. msg = _T(MSG_WIZARD_DONE);
  4372. lcd_reset_alert_level();
  4373. lcd_setstatuspgm(_T(WELCOME_MSG));
  4374. lcd_return_to_status();
  4375. break;
  4376. default:
  4377. msg = _T(MSG_WIZARD_QUIT);
  4378. break;
  4379. }
  4380. if (!((S::Lay1CalCold == state) || (S::Lay1CalHot == state) || (S::Preheat == state)))
  4381. {
  4382. lcd_show_fullscreen_message_and_wait_P(msg);
  4383. }
  4384. lcd_update_enable(true);
  4385. lcd_update(2);
  4386. }
  4387. #ifdef TMC2130
  4388. void lcd_settings_linearity_correction_menu(void)
  4389. {
  4390. MENU_BEGIN();
  4391. ON_MENU_LEAVE(
  4392. lcd_settings_linearity_correction_menu_save();
  4393. );
  4394. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  4395. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  4396. //tmc2130_wave_fac[X_AXIS]
  4397. MENU_ITEM_EDIT_int3_P(_i("X-correct:"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_X_CORRECTION c=13
  4398. MENU_ITEM_EDIT_int3_P(_i("Y-correct:"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_Y_CORRECTION c=13
  4399. MENU_ITEM_EDIT_int3_P(_i("Z-correct:"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_Z_CORRECTION c=13
  4400. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  4401. MENU_ITEM_EDIT_int3_P(_i("E-correct:"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_EXTRUDER_CORRECTION c=13
  4402. MENU_END();
  4403. }
  4404. #endif // TMC2130
  4405. #ifdef FILAMENT_SENSOR
  4406. #define SETTINGS_FILAMENT_SENSOR \
  4407. do\
  4408. {\
  4409. if (FSensorStateMenu == 0)\
  4410. {\
  4411. if (fsensor_not_responding && (mmu_enabled == false))\
  4412. {\
  4413. /* Filament sensor not working*/\
  4414. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_NA), lcd_fsensor_state_set);/*////MSG_FSENSOR_NA*/\
  4415. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), NULL, lcd_fsensor_fail);\
  4416. }\
  4417. else\
  4418. {\
  4419. /* Filament sensor turned off, working, no problems*/\
  4420. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_OFF), lcd_fsensor_state_set);\
  4421. if (mmu_enabled == false)\
  4422. {\
  4423. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), NULL, lcd_filament_autoload_info);\
  4424. }\
  4425. }\
  4426. }\
  4427. else\
  4428. {\
  4429. /* Filament sensor turned on, working, no problems*/\
  4430. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_ON), lcd_fsensor_state_set);\
  4431. if (mmu_enabled == false)\
  4432. {\
  4433. if (fsensor_autoload_enabled)\
  4434. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_ON), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_ON c=17 r=1*/\
  4435. else\
  4436. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_OFF), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_OFF c=17 r=1*/\
  4437. /*if (fsensor_oq_meassure_enabled)*/\
  4438. /*MENU_ITEM_FUNCTION_P(_i("F. OQ meass. [on]"), lcd_set_filament_oq_meass);*//*////MSG_FSENS_OQMEASS_ON c=17 r=1*/\
  4439. /*else*/\
  4440. /*MENU_ITEM_FUNCTION_P(_i("F. OQ meass.[off]"), lcd_set_filament_oq_meass);*//*////MSG_FSENS_OQMEASS_OFF c=17 r=1*/\
  4441. }\
  4442. }\
  4443. }\
  4444. while(0)
  4445. #else //FILAMENT_SENSOR
  4446. #define SETTINGS_FILAMENT_SENSOR do{}while(0)
  4447. #endif //FILAMENT_SENSOR
  4448. static void auto_deplete_switch()
  4449. {
  4450. lcd_autoDeplete = !lcd_autoDeplete;
  4451. eeprom_update_byte((unsigned char *)EEPROM_AUTO_DEPLETE, lcd_autoDeplete);
  4452. }
  4453. static void settingsAutoDeplete()
  4454. {
  4455. if (mmu_enabled)
  4456. {
  4457. if (!fsensor_enabled)
  4458. {
  4459. MENU_ITEM_TOGGLE_P(_T(MSG_AUTO_DEPLETE), _T(MSG_NA), NULL);
  4460. }
  4461. else if (lcd_autoDeplete)
  4462. {
  4463. MENU_ITEM_TOGGLE_P(_T(MSG_AUTO_DEPLETE), _T(MSG_ON), auto_deplete_switch);
  4464. }
  4465. else
  4466. {
  4467. MENU_ITEM_TOGGLE_P(_T(MSG_AUTO_DEPLETE), _T(MSG_OFF), auto_deplete_switch);
  4468. }
  4469. }
  4470. }
  4471. #define SETTINGS_AUTO_DEPLETE \
  4472. do\
  4473. {\
  4474. settingsAutoDeplete();\
  4475. }\
  4476. while(0)\
  4477. #ifdef MMU_HAS_CUTTER
  4478. static void settingsCutter()
  4479. {
  4480. if (mmu_enabled)
  4481. {
  4482. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  4483. {
  4484. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_ON), lcd_cutter_enabled);
  4485. }
  4486. #ifdef MMU_ALWAYS_CUT
  4487. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  4488. {
  4489. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _i("Always"), lcd_cutter_enabled);
  4490. }
  4491. #endif
  4492. else
  4493. {
  4494. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_OFF), lcd_cutter_enabled);
  4495. }
  4496. }
  4497. }
  4498. #define SETTINGS_CUTTER \
  4499. do\
  4500. {\
  4501. settingsCutter();\
  4502. }\
  4503. while(0)
  4504. #else
  4505. #define SETTINGS_CUTTER
  4506. #endif //MMU_HAS_CUTTER
  4507. #ifdef TMC2130
  4508. #define SETTINGS_SILENT_MODE \
  4509. do\
  4510. {\
  4511. if(!farm_mode)\
  4512. {\
  4513. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4514. {\
  4515. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\
  4516. }\
  4517. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);\
  4518. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4519. {\
  4520. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);\
  4521. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);\
  4522. }\
  4523. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);\
  4524. }\
  4525. }\
  4526. while (0)
  4527. #else //TMC2130
  4528. #define SETTINGS_SILENT_MODE \
  4529. do\
  4530. {\
  4531. if(!farm_mode)\
  4532. {\
  4533. switch (SilentModeMenu)\
  4534. {\
  4535. case SILENT_MODE_POWER:\
  4536. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  4537. break;\
  4538. case SILENT_MODE_SILENT:\
  4539. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set);\
  4540. break;\
  4541. case SILENT_MODE_AUTO:\
  4542. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set);\
  4543. break;\
  4544. default:\
  4545. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  4546. break; /* (probably) not needed*/\
  4547. }\
  4548. }\
  4549. }\
  4550. while (0)
  4551. #endif //TMC2130
  4552. #ifndef MMU_FORCE_STEALTH_MODE
  4553. #define SETTINGS_MMU_MODE \
  4554. do\
  4555. {\
  4556. if (mmu_enabled)\
  4557. {\
  4558. if (SilentModeMenu_MMU == 0) MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_NORMAL), lcd_silent_mode_mmu_set);\
  4559. else MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_STEALTH), lcd_silent_mode_mmu_set);\
  4560. }\
  4561. }\
  4562. while (0)
  4563. #else //MMU_FORCE_STEALTH_MODE
  4564. #define SETTINGS_MMU_MODE
  4565. #endif //MMU_FORCE_STEALTH_MODE
  4566. #ifdef SDCARD_SORT_ALPHA
  4567. #define SETTINGS_SD \
  4568. do\
  4569. {\
  4570. if (card.ToshibaFlashAir_isEnabled())\
  4571. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY), lcd_toshiba_flash_air_compatibility_toggle);\
  4572. else\
  4573. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_NORMAL), lcd_toshiba_flash_air_compatibility_toggle);\
  4574. \
  4575. uint8_t sdSort;\
  4576. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));\
  4577. switch (sdSort)\
  4578. {\
  4579. case SD_SORT_TIME: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_TIME), lcd_sort_type_set); break;\
  4580. case SD_SORT_ALPHA: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_ALPHA), lcd_sort_type_set); break;\
  4581. default: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_NONE), lcd_sort_type_set);\
  4582. }\
  4583. }\
  4584. while (0)
  4585. #else // SDCARD_SORT_ALPHA
  4586. #define SETTINGS_SD \
  4587. do\
  4588. {\
  4589. if (card.ToshibaFlashAir_isEnabled())\
  4590. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY), lcd_toshiba_flash_air_compatibility_toggle);\
  4591. else\
  4592. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_NORMAL), lcd_toshiba_flash_air_compatibility_toggle);\
  4593. }\
  4594. while (0)
  4595. #endif // SDCARD_SORT_ALPHA
  4596. /*
  4597. #define SETTINGS_MBL_MODE \
  4598. do\
  4599. {\
  4600. switch(e_mbl_type)\
  4601. {\
  4602. case e_MBL_FAST:\
  4603. MENU_ITEM_FUNCTION_P(_i("Mode [Fast]"),mbl_mode_set);\
  4604. break; \
  4605. case e_MBL_OPTIMAL:\
  4606. MENU_ITEM_FUNCTION_P(_i("Mode [Optimal]"), mbl_mode_set); \
  4607. break; \
  4608. case e_MBL_PREC:\
  4609. MENU_ITEM_FUNCTION_P(_i("Mode [Precise]"), mbl_mode_set); \
  4610. break; \
  4611. default:\
  4612. MENU_ITEM_FUNCTION_P(_i("Mode [Optimal]"), mbl_mode_set); \
  4613. break; \
  4614. }\
  4615. }\
  4616. while (0)
  4617. */
  4618. #define SETTINGS_SOUND \
  4619. do\
  4620. {\
  4621. switch(eSoundMode)\
  4622. {\
  4623. case e_SOUND_MODE_LOUD:\
  4624. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  4625. break;\
  4626. case e_SOUND_MODE_ONCE:\
  4627. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_ONCE), lcd_sound_state_set);\
  4628. break;\
  4629. case e_SOUND_MODE_SILENT:\
  4630. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SILENT), lcd_sound_state_set);\
  4631. break;\
  4632. case e_SOUND_MODE_BLIND:\
  4633. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_BLIND), lcd_sound_state_set);\
  4634. break;\
  4635. default:\
  4636. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  4637. }\
  4638. }\
  4639. while (0)
  4640. //-//
  4641. static void lcd_check_mode_set(void)
  4642. {
  4643. switch(oCheckMode)
  4644. {
  4645. case ClCheckMode::_None:
  4646. oCheckMode=ClCheckMode::_Warn;
  4647. break;
  4648. case ClCheckMode::_Warn:
  4649. oCheckMode=ClCheckMode::_Strict;
  4650. break;
  4651. case ClCheckMode::_Strict:
  4652. oCheckMode=ClCheckMode::_None;
  4653. break;
  4654. default:
  4655. oCheckMode=ClCheckMode::_None;
  4656. }
  4657. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)oCheckMode);
  4658. }
  4659. #define SETTINGS_MODE \
  4660. do\
  4661. {\
  4662. switch(oCheckMode)\
  4663. {\
  4664. case ClCheckMode::_None:\
  4665. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  4666. break;\
  4667. case ClCheckMode::_Warn:\
  4668. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_WARN), lcd_check_mode_set);\
  4669. break;\
  4670. case ClCheckMode::_Strict:\
  4671. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_STRICT), lcd_check_mode_set);\
  4672. break;\
  4673. default:\
  4674. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  4675. }\
  4676. }\
  4677. while (0)
  4678. static void lcd_nozzle_diameter_cycle(void) {
  4679. uint16_t nDiameter;
  4680. switch(oNozzleDiameter){
  4681. case ClNozzleDiameter::_Diameter_250:
  4682. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4683. nDiameter=400;
  4684. break;
  4685. case ClNozzleDiameter::_Diameter_400:
  4686. oNozzleDiameter=ClNozzleDiameter::_Diameter_600;
  4687. nDiameter=600;
  4688. break;
  4689. case ClNozzleDiameter::_Diameter_600:
  4690. oNozzleDiameter=ClNozzleDiameter::_Diameter_800;
  4691. nDiameter=800;
  4692. break;
  4693. case ClNozzleDiameter::_Diameter_800:
  4694. oNozzleDiameter=ClNozzleDiameter::_Diameter_250;
  4695. nDiameter=250;
  4696. break;
  4697. default:
  4698. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  4699. nDiameter=400;
  4700. }
  4701. eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)oNozzleDiameter);
  4702. eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter);
  4703. }
  4704. #define SETTINGS_NOZZLE \
  4705. do\
  4706. {\
  4707. float fNozzleDiam;\
  4708. switch(oNozzleDiameter)\
  4709. {\
  4710. case ClNozzleDiameter::_Diameter_250: fNozzleDiam = 0.25f; break;\
  4711. case ClNozzleDiameter::_Diameter_400: fNozzleDiam = 0.4f; break;\
  4712. case ClNozzleDiameter::_Diameter_600: fNozzleDiam = 0.6f; break;\
  4713. case ClNozzleDiameter::_Diameter_800: fNozzleDiam = 0.8f; break;\
  4714. default: fNozzleDiam = 0.4f; break;\
  4715. }\
  4716. MENU_ITEM_TOGGLE(_T(MSG_NOZZLE_DIAMETER), ftostr12ns(fNozzleDiam), lcd_nozzle_diameter_cycle);\
  4717. }\
  4718. while (0)
  4719. static void lcd_check_model_set(void)
  4720. {
  4721. switch(oCheckModel)
  4722. {
  4723. case ClCheckModel::_None:
  4724. oCheckModel=ClCheckModel::_Warn;
  4725. break;
  4726. case ClCheckModel::_Warn:
  4727. oCheckModel=ClCheckModel::_Strict;
  4728. break;
  4729. case ClCheckModel::_Strict:
  4730. oCheckModel=ClCheckModel::_None;
  4731. break;
  4732. default:
  4733. oCheckModel=ClCheckModel::_None;
  4734. }
  4735. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODEL,(uint8_t)oCheckModel);
  4736. }
  4737. #define SETTINGS_MODEL \
  4738. do\
  4739. {\
  4740. switch(oCheckModel)\
  4741. {\
  4742. case ClCheckModel::_None:\
  4743. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4744. break;\
  4745. case ClCheckModel::_Warn:\
  4746. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_WARN), lcd_check_model_set);\
  4747. break;\
  4748. case ClCheckModel::_Strict:\
  4749. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_STRICT), lcd_check_model_set);\
  4750. break;\
  4751. default:\
  4752. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4753. }\
  4754. }\
  4755. while (0)
  4756. static void lcd_check_version_set(void)
  4757. {
  4758. switch(oCheckVersion)
  4759. {
  4760. case ClCheckVersion::_None:
  4761. oCheckVersion=ClCheckVersion::_Warn;
  4762. break;
  4763. case ClCheckVersion::_Warn:
  4764. oCheckVersion=ClCheckVersion::_Strict;
  4765. break;
  4766. case ClCheckVersion::_Strict:
  4767. oCheckVersion=ClCheckVersion::_None;
  4768. break;
  4769. default:
  4770. oCheckVersion=ClCheckVersion::_None;
  4771. }
  4772. eeprom_update_byte((uint8_t*)EEPROM_CHECK_VERSION,(uint8_t)oCheckVersion);
  4773. }
  4774. #define SETTINGS_VERSION \
  4775. do\
  4776. {\
  4777. switch(oCheckVersion)\
  4778. {\
  4779. case ClCheckVersion::_None:\
  4780. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_NONE), lcd_check_version_set);\
  4781. break;\
  4782. case ClCheckVersion::_Warn:\
  4783. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_WARN), lcd_check_version_set);\
  4784. break;\
  4785. case ClCheckVersion::_Strict:\
  4786. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_STRICT), lcd_check_version_set);\
  4787. break;\
  4788. default:\
  4789. MENU_ITEM_TOGGLE_P(_T(MSG_FIRMWARE), _T(MSG_NONE), lcd_check_version_set);\
  4790. }\
  4791. }\
  4792. while (0)
  4793. #if 0 // temporarily unused
  4794. static void lcd_check_gcode_set(void)
  4795. {
  4796. switch(oCheckGcode)
  4797. {
  4798. case ClCheckGcode::_None:
  4799. oCheckGcode=ClCheckGcode::_Warn;
  4800. break;
  4801. case ClCheckGcode::_Warn:
  4802. oCheckGcode=ClCheckGcode::_Strict;
  4803. break;
  4804. case ClCheckGcode::_Strict:
  4805. oCheckGcode=ClCheckGcode::_None;
  4806. break;
  4807. default:
  4808. oCheckGcode=ClCheckGcode::_None;
  4809. }
  4810. eeprom_update_byte((uint8_t*)EEPROM_CHECK_GCODE,(uint8_t)oCheckGcode);
  4811. }
  4812. #endif
  4813. #define SETTINGS_GCODE \
  4814. do\
  4815. {\
  4816. switch(oCheckGcode)\
  4817. {\
  4818. case ClCheckGcode::_None:\
  4819. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_NONE), lcd_check_gcode_set);\
  4820. break;\
  4821. case ClCheckGcode::_Warn:\
  4822. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_WARN), lcd_check_gcode_set);\
  4823. break;\
  4824. case ClCheckGcode::_Strict:\
  4825. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_STRICT), lcd_check_gcode_set);\
  4826. break;\
  4827. default:\
  4828. MENU_ITEM_TOGGLE_P(_T(MSG_GCODE), _T(MSG_NONE), lcd_check_gcode_set);\
  4829. }\
  4830. }\
  4831. while (0)
  4832. static void lcd_checking_menu(void)
  4833. {
  4834. MENU_BEGIN();
  4835. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4836. SETTINGS_MODE;
  4837. SETTINGS_MODEL;
  4838. SETTINGS_VERSION;
  4839. //-// temporarily disabled
  4840. //SETTINGS_GCODE;
  4841. MENU_END();
  4842. }
  4843. #ifdef IR_SENSOR_ANALOG
  4844. static void lcd_fsensor_actionNA_set(void)
  4845. {
  4846. switch(oFsensorActionNA)
  4847. {
  4848. case ClFsensorActionNA::_Continue:
  4849. oFsensorActionNA=ClFsensorActionNA::_Pause;
  4850. break;
  4851. case ClFsensorActionNA::_Pause:
  4852. oFsensorActionNA=ClFsensorActionNA::_Continue;
  4853. break;
  4854. default:
  4855. oFsensorActionNA=ClFsensorActionNA::_Continue;
  4856. }
  4857. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_ACTION_NA,(uint8_t)oFsensorActionNA);
  4858. }
  4859. #define FSENSOR_ACTION_NA \
  4860. do\
  4861. {\
  4862. switch(oFsensorActionNA)\
  4863. {\
  4864. case ClFsensorActionNA::_Continue:\
  4865. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_CONTINUE), lcd_fsensor_actionNA_set);\
  4866. break;\
  4867. case ClFsensorActionNA::_Pause:\
  4868. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_PAUSE), lcd_fsensor_actionNA_set);\
  4869. break;\
  4870. default:\
  4871. oFsensorActionNA=ClFsensorActionNA::_Continue;\
  4872. }\
  4873. }\
  4874. while (0)
  4875. #endif //IR_SENSOR_ANALOG
  4876. template <uint8_t number>
  4877. static void select_sheet_menu()
  4878. {
  4879. selected_sheet = number;
  4880. lcd_sheet_menu();
  4881. }
  4882. static void sheets_menu()
  4883. {
  4884. MENU_BEGIN();
  4885. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4886. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[0], select_sheet_menu<0>);
  4887. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[1], select_sheet_menu<1>);
  4888. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[2], select_sheet_menu<2>);
  4889. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[3], select_sheet_menu<3>);
  4890. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[4], select_sheet_menu<4>);
  4891. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[5], select_sheet_menu<5>);
  4892. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[6], select_sheet_menu<6>);
  4893. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[7], select_sheet_menu<7>);
  4894. MENU_END();
  4895. }
  4896. void lcd_hw_setup_menu(void) // can not be "static"
  4897. {
  4898. typedef struct
  4899. {// 2bytes total
  4900. int8_t status;
  4901. uint8_t experimental_menu_visibility;
  4902. } _menu_data_t;
  4903. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  4904. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  4905. if (_md->status == 0 || lcd_draw_update)
  4906. {
  4907. _md->status = 1;
  4908. _md->experimental_menu_visibility = eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  4909. if (_md->experimental_menu_visibility == EEPROM_EMPTY_VALUE)
  4910. {
  4911. _md->experimental_menu_visibility = 0;
  4912. eeprom_update_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, _md->experimental_menu_visibility);
  4913. }
  4914. }
  4915. MENU_BEGIN();
  4916. MENU_ITEM_BACK_P(_T(bSettings?MSG_SETTINGS:MSG_BACK)); // i.e. default menu-item / menu-item after checking mismatch
  4917. MENU_ITEM_SUBMENU_P(_T(MSG_STEEL_SHEETS), sheets_menu);
  4918. SETTINGS_NOZZLE;
  4919. MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu);
  4920. #ifdef IR_SENSOR_ANALOG
  4921. FSENSOR_ACTION_NA;
  4922. //! Fsensor Detection isn't ready for mmu yet it is temporarily disabled.
  4923. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  4924. if(!mmu_enabled) MENU_ITEM_FUNCTION_P(PSTR("Fsensor Detection"), lcd_detect_IRsensor);
  4925. #endif //IR_SENSOR_ANALOG
  4926. if (_md->experimental_menu_visibility)
  4927. {
  4928. MENU_ITEM_SUBMENU_P(PSTR("Experimental"), lcd_experimental_menu);////MSG_MENU_EXPERIMENTAL c=18
  4929. }
  4930. #ifdef PINDA_TEMP_COMP
  4931. //! The SuperPINDA is detected when the PINDA temp is below its defined limit.
  4932. //! This works well on the EINSY board but not on the miniRAMBo board as
  4933. //! as a disconnected SuperPINDA will show higher temps compared to an EINSY board.
  4934. //!
  4935. //! This menu allows the user to en-/disable the SuperPINDA manualy
  4936. MENU_ITEM_TOGGLE_P(_N("SuperPINDA"), eeprom_read_byte((uint8_t *)EEPROM_PINDA_TEMP_COMPENSATION) ? _T(MSG_YES) : _T(MSG_NO), lcd_pinda_temp_compensation_toggle);
  4937. #endif //PINDA_TEMP_COMP
  4938. MENU_END();
  4939. }
  4940. static void lcd_settings_menu()
  4941. {
  4942. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  4943. MENU_BEGIN();
  4944. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4945. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE
  4946. if (!homing_flag)
  4947. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS
  4948. if (!isPrintPaused)
  4949. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS
  4950. SETTINGS_FILAMENT_SENSOR;
  4951. SETTINGS_AUTO_DEPLETE;
  4952. SETTINGS_CUTTER;
  4953. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  4954. SETTINGS_SILENT_MODE;
  4955. if(!farm_mode)
  4956. {
  4957. bSettings=true; // flag ('fake parameter') for 'lcd_hw_setup_menu()' function
  4958. MENU_ITEM_SUBMENU_P(_T(MSG_HW_SETUP), lcd_hw_setup_menu);
  4959. }
  4960. SETTINGS_MMU_MODE;
  4961. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bed_leveling_settings);
  4962. #if defined (TMC2130) && defined (LINEARITY_CORRECTION)
  4963. MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu);
  4964. #endif //LINEARITY_CORRECTION && TMC2130
  4965. if(has_temperature_compensation())
  4966. {
  4967. MENU_ITEM_TOGGLE_P(_T(MSG_TEMP_CALIBRATION), eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE) ? _T(MSG_ON) : _T(MSG_OFF), lcd_temp_calibration_set);
  4968. }
  4969. #ifdef HAS_SECOND_SERIAL_PORT
  4970. MENU_ITEM_TOGGLE_P(_T(MSG_RPI_PORT), (selectedSerialPort == 0) ? _T(MSG_OFF) : _T(MSG_ON), lcd_second_serial_set);
  4971. #endif //HAS_SECOND_SERIAL
  4972. if (!isPrintPaused && !homing_flag)
  4973. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  4974. #if (LANG_MODE != 0)
  4975. MENU_ITEM_SUBMENU_P(_i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT
  4976. #endif //(LANG_MODE != 0)
  4977. SETTINGS_SD;
  4978. SETTINGS_SOUND;
  4979. #ifdef LCD_BL_PIN
  4980. if (backlightSupport)
  4981. {
  4982. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  4983. }
  4984. #endif //LCD_BL_PIN
  4985. if (farm_mode)
  4986. {
  4987. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  4988. }
  4989. MENU_END();
  4990. }
  4991. #ifdef TMC2130
  4992. static void lcd_ustep_linearity_menu_save()
  4993. {
  4994. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  4995. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  4996. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  4997. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  4998. }
  4999. #endif //TMC2130
  5000. #ifdef TMC2130
  5001. static void lcd_settings_linearity_correction_menu_save()
  5002. {
  5003. bool changed = false;
  5004. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  5005. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  5006. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  5007. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  5008. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  5009. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  5010. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  5011. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  5012. lcd_ustep_linearity_menu_save();
  5013. if (changed) tmc2130_init();
  5014. }
  5015. #endif //TMC2130
  5016. static void lcd_calibration_menu()
  5017. {
  5018. MENU_BEGIN();
  5019. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5020. if (!isPrintPaused)
  5021. {
  5022. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17 r=1
  5023. if (lcd_commands_type == LcdCommands::Idle)
  5024. {
  5025. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_first_layer_calibration_reset);////MSG_V2_CALIBRATION c=18
  5026. }
  5027. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  5028. #ifdef TMC2130
  5029. MENU_ITEM_FUNCTION_P(_i("Belt test "), lcd_belttest_v);////MSG_BELTTEST c=17
  5030. #endif //TMC2130
  5031. MENU_ITEM_FUNCTION_P(_i("Selftest "), lcd_selftest_v);////MSG_SELFTEST c=17
  5032. #ifdef MK1BP
  5033. // MK1
  5034. // "Calibrate Z"
  5035. MENU_ITEM_GCODE_P(_T(MSG_HOMEYZ), PSTR("G28 Z"));
  5036. #else //MK1BP
  5037. // MK2
  5038. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED
  5039. // "Calibrate Z" with storing the reference values to EEPROM.
  5040. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  5041. #ifndef SNMM
  5042. //MENU_ITEM_FUNCTION_P(_i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20 r=1
  5043. #endif
  5044. // "Mesh Bed Leveling"
  5045. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bedleveling);
  5046. #endif //MK1BP
  5047. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU
  5048. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17 r=1
  5049. #ifndef TMC2130
  5050. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=18
  5051. #endif
  5052. #ifndef MK1BP
  5053. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET
  5054. #endif //MK1BP
  5055. #ifndef SNMM
  5056. //MENU_ITEM_FUNCTION_P(MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  5057. #endif
  5058. #ifndef MK1BP
  5059. if(has_temperature_compensation())
  5060. {
  5061. MENU_ITEM_SUBMENU_P(_i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17 r=1
  5062. }
  5063. #endif //MK1BP
  5064. }
  5065. MENU_END();
  5066. }
  5067. void bowden_menu() {
  5068. int enc_dif = lcd_encoder_diff;
  5069. int cursor_pos = 0;
  5070. lcd_clear();
  5071. lcd_putc_at(0, 0, '>');
  5072. for (uint_least8_t i = 0; i < 4; i++) {
  5073. lcd_puts_at_P(1, i, PSTR("Extruder "));
  5074. lcd_print(i);
  5075. lcd_print(": ");
  5076. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  5077. lcd_print(bowden_length[i] - 48);
  5078. }
  5079. enc_dif = lcd_encoder_diff;
  5080. lcd_consume_click();
  5081. while (1) {
  5082. manage_heater();
  5083. manage_inactivity(true);
  5084. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5085. if (enc_dif > lcd_encoder_diff) {
  5086. cursor_pos--;
  5087. }
  5088. if (enc_dif < lcd_encoder_diff) {
  5089. cursor_pos++;
  5090. }
  5091. if (cursor_pos > 3) {
  5092. cursor_pos = 3;
  5093. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5094. }
  5095. if (cursor_pos < 0) {
  5096. cursor_pos = 0;
  5097. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5098. }
  5099. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  5100. lcd_putc_at(0, cursor_pos, '>');
  5101. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5102. enc_dif = lcd_encoder_diff;
  5103. _delay(100);
  5104. }
  5105. if (lcd_clicked()) {
  5106. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5107. lcd_clear();
  5108. while (1) {
  5109. manage_heater();
  5110. manage_inactivity(true);
  5111. lcd_puts_at_P(1, 1, PSTR("Extruder "));
  5112. lcd_print(cursor_pos);
  5113. lcd_print(": ");
  5114. lcd_set_cursor(13, 1);
  5115. lcd_print(bowden_length[cursor_pos] - 48);
  5116. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5117. if (enc_dif > lcd_encoder_diff) {
  5118. bowden_length[cursor_pos]--;
  5119. lcd_set_cursor(13, 1);
  5120. lcd_print(bowden_length[cursor_pos] - 48);
  5121. enc_dif = lcd_encoder_diff;
  5122. }
  5123. if (enc_dif < lcd_encoder_diff) {
  5124. bowden_length[cursor_pos]++;
  5125. lcd_set_cursor(13, 1);
  5126. lcd_print(bowden_length[cursor_pos] - 48);
  5127. enc_dif = lcd_encoder_diff;
  5128. }
  5129. }
  5130. _delay(100);
  5131. if (lcd_clicked()) {
  5132. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5133. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  5134. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  5135. lcd_update_enable(true);
  5136. lcd_clear();
  5137. enc_dif = lcd_encoder_diff;
  5138. lcd_putc_at(0, cursor_pos, '>');
  5139. for (uint_least8_t i = 0; i < 4; i++) {
  5140. lcd_puts_at_P(1, i, PSTR("Extruder "));
  5141. lcd_print(i);
  5142. lcd_print(": ");
  5143. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  5144. lcd_print(bowden_length[i] - 48);
  5145. }
  5146. break;
  5147. }
  5148. else return;
  5149. }
  5150. }
  5151. }
  5152. }
  5153. }
  5154. #ifdef SNMM
  5155. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  5156. lcd_clear();
  5157. lcd_puts_at_P(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd_print(':');
  5158. lcd_set_cursor(0, 1); lcd_print('>');
  5159. lcd_puts_at_P(1,2,_i("Used during print"));////MSG_USED c=19 r=1
  5160. lcd_puts_at_P(1,3,_i("Current"));////MSG_CURRENT c=19 r=1
  5161. char cursor_pos = 1;
  5162. int enc_dif = 0;
  5163. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5164. lcd_consume_click();
  5165. while (1) {
  5166. manage_heater();
  5167. manage_inactivity(true);
  5168. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  5169. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  5170. if (enc_dif > lcd_encoder_diff) cursor_pos--;
  5171. if (enc_dif < lcd_encoder_diff) cursor_pos++;
  5172. if (cursor_pos > 3) {
  5173. cursor_pos = 3;
  5174. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5175. }
  5176. if (cursor_pos < 1){
  5177. cursor_pos = 1;
  5178. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5179. }
  5180. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  5181. lcd_set_cursor(0, cursor_pos);
  5182. lcd_print('>');
  5183. enc_dif = lcd_encoder_diff;
  5184. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5185. _delay(100);
  5186. }
  5187. }
  5188. if (lcd_clicked()) {
  5189. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5190. KEEPALIVE_STATE(IN_HANDLER);
  5191. return(cursor_pos - 1);
  5192. }
  5193. }
  5194. }
  5195. #endif //SNMM
  5196. //! @brief Select one of numbered items
  5197. //!
  5198. //! Create list of items with header. Header can not be selected.
  5199. //! Each item has text description passed by function parameter and
  5200. //! number. There are 5 numbered items, if mmu_enabled, 4 otherwise.
  5201. //! Items are numbered from 1 to 4 or 5. But index returned starts at 0.
  5202. //! There can be last item with different text and no number.
  5203. //!
  5204. //! @param header Header text
  5205. //! @param item Item text
  5206. //! @param last_item Last item text, or nullptr if there is no Last item
  5207. //! @return selected item index, first item index is 0
  5208. uint8_t choose_menu_P(const char *header, const char *item, const char *last_item)
  5209. {
  5210. //following code should handle 3 to 127 number of items well
  5211. const int8_t items_no = last_item?(mmu_enabled?6:5):(mmu_enabled?5:4);
  5212. const uint8_t item_len = item?strlen_P(item):0;
  5213. int8_t first = 0;
  5214. int8_t enc_dif = lcd_encoder_diff;
  5215. int8_t cursor_pos = 1;
  5216. lcd_clear();
  5217. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5218. while (1)
  5219. {
  5220. manage_heater();
  5221. manage_inactivity(true);
  5222. if (abs((enc_dif - lcd_encoder_diff)) > 4)
  5223. {
  5224. if (enc_dif > lcd_encoder_diff)
  5225. {
  5226. cursor_pos--;
  5227. }
  5228. if (enc_dif < lcd_encoder_diff)
  5229. {
  5230. cursor_pos++;
  5231. }
  5232. enc_dif = lcd_encoder_diff;
  5233. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5234. }
  5235. if (cursor_pos > 3)
  5236. {
  5237. cursor_pos = 3;
  5238. if (first < items_no - 3)
  5239. {
  5240. first++;
  5241. lcd_clear();
  5242. } else { // here we are at the very end of the list
  5243. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5244. }
  5245. }
  5246. if (cursor_pos < 1)
  5247. {
  5248. cursor_pos = 1;
  5249. if (first > 0)
  5250. {
  5251. first--;
  5252. lcd_clear();
  5253. } else { // here we are at the very end of the list
  5254. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5255. }
  5256. }
  5257. if (header) lcd_puts_at_P(0,0,header);
  5258. const bool last_visible = (first == items_no - 3);
  5259. const uint_least8_t ordinary_items = (last_item&&last_visible)?2:3;
  5260. for (uint_least8_t i = 0; i < ordinary_items; i++)
  5261. {
  5262. if (item) lcd_puts_at_P(1, i + 1, item);
  5263. }
  5264. for (uint_least8_t i = 0; i < ordinary_items; i++)
  5265. {
  5266. lcd_set_cursor(2 + item_len, i+1);
  5267. lcd_print(first + i + 1);
  5268. }
  5269. if (last_item&&last_visible) lcd_puts_at_P(1, 3, last_item);
  5270. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  5271. lcd_putc_at(0, cursor_pos, '>');
  5272. _delay(100);
  5273. if (lcd_clicked())
  5274. {
  5275. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5276. KEEPALIVE_STATE(IN_HANDLER);
  5277. lcd_encoder_diff = 0;
  5278. return(cursor_pos + first - 1);
  5279. }
  5280. }
  5281. }
  5282. char reset_menu() {
  5283. const uint8_t items_no =
  5284. #ifdef SNMM
  5285. 5;
  5286. #else
  5287. 4;
  5288. #endif
  5289. static int8_t first = 0;
  5290. int8_t enc_dif = 0;
  5291. char cursor_pos = 0;
  5292. const char *const item[items_no] PROGMEM = {PSTR("Language"), PSTR("Statistics"), PSTR("Shipping prep"), PSTR("All Data")
  5293. #ifdef SNMM
  5294. , PSTR("Bowden length")
  5295. #endif
  5296. };
  5297. enc_dif = lcd_encoder_diff;
  5298. lcd_clear();
  5299. lcd_set_cursor(0, 0);
  5300. lcd_putc('>');
  5301. lcd_consume_click();
  5302. while (1) {
  5303. for (uint_least8_t i = 0; i < 4; i++) {
  5304. lcd_puts_at_P(1, i, item[first + i]);
  5305. }
  5306. manage_heater();
  5307. manage_inactivity(true);
  5308. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  5309. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  5310. if (enc_dif > lcd_encoder_diff) {
  5311. cursor_pos--;
  5312. }
  5313. if (enc_dif < lcd_encoder_diff) {
  5314. cursor_pos++;
  5315. }
  5316. if (cursor_pos > 3) {
  5317. cursor_pos = 3;
  5318. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5319. if (first < items_no - 4) {
  5320. first++;
  5321. lcd_clear();
  5322. }
  5323. }
  5324. if (cursor_pos < 0) {
  5325. cursor_pos = 0;
  5326. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5327. if (first > 0) {
  5328. first--;
  5329. lcd_clear();
  5330. }
  5331. }
  5332. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  5333. lcd_set_cursor(0, cursor_pos);
  5334. lcd_putc('>');
  5335. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5336. enc_dif = lcd_encoder_diff;
  5337. _delay(100);
  5338. }
  5339. }
  5340. if (lcd_clicked()) {
  5341. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5342. return(cursor_pos + first);
  5343. }
  5344. }
  5345. }
  5346. static void lcd_disable_farm_mode()
  5347. {
  5348. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  5349. if (disable)
  5350. {
  5351. enquecommand_P(PSTR("G99"));
  5352. lcd_return_to_status();
  5353. }
  5354. lcd_update_enable(true);
  5355. lcd_draw_update = 2;
  5356. }
  5357. static void fil_load_menu()
  5358. {
  5359. MENU_BEGIN();
  5360. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5361. MENU_ITEM_FUNCTION_P(_i("Load all"), load_all); ////MSG_LOAD_ALL c=17
  5362. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '1', extr_adj, 0); ////MSG_LOAD_FILAMENT_1 c=16
  5363. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '2', extr_adj, 1); ////MSG_LOAD_FILAMENT_2 c=17
  5364. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '3', extr_adj, 2); ////MSG_LOAD_FILAMENT_3 c=17
  5365. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '4', extr_adj, 3); ////MSG_LOAD_FILAMENT_4 c=17
  5366. if (mmu_enabled)
  5367. {
  5368. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '5', extr_adj, 4);
  5369. }
  5370. MENU_END();
  5371. }
  5372. static void mmu_load_to_nozzle_menu()
  5373. {
  5374. if (bFilamentAction)
  5375. {
  5376. MENU_BEGIN();
  5377. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5378. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '1', lcd_mmu_load_to_nozzle, 0);
  5379. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '2', lcd_mmu_load_to_nozzle, 1);
  5380. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '3', lcd_mmu_load_to_nozzle, 2);
  5381. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '4', lcd_mmu_load_to_nozzle, 3);
  5382. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '5', lcd_mmu_load_to_nozzle, 4);
  5383. MENU_END();
  5384. }
  5385. else
  5386. {
  5387. eFilamentAction = FilamentAction::MmuLoad;
  5388. preheat_or_continue();
  5389. }
  5390. }
  5391. static void mmu_eject_filament(uint8_t filament)
  5392. {
  5393. menu_back();
  5394. mmu_eject_filament(filament, true);
  5395. }
  5396. static void mmu_fil_eject_menu()
  5397. {
  5398. if (bFilamentAction)
  5399. {
  5400. MENU_BEGIN();
  5401. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5402. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '1', mmu_eject_filament, 0);
  5403. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '2', mmu_eject_filament, 1);
  5404. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '3', mmu_eject_filament, 2);
  5405. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '4', mmu_eject_filament, 3);
  5406. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '5', mmu_eject_filament, 4);
  5407. MENU_END();
  5408. }
  5409. else
  5410. {
  5411. eFilamentAction = FilamentAction::MmuEject;
  5412. preheat_or_continue();
  5413. }
  5414. }
  5415. #ifdef MMU_HAS_CUTTER
  5416. static void mmu_cut_filament_menu()
  5417. {
  5418. if(bFilamentAction)
  5419. {
  5420. MENU_BEGIN();
  5421. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5422. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '1', mmu_cut_filament, 0);
  5423. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '2', mmu_cut_filament, 1);
  5424. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '3', mmu_cut_filament, 2);
  5425. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '4', mmu_cut_filament, 3);
  5426. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '5', mmu_cut_filament, 4);
  5427. MENU_END();
  5428. }
  5429. else
  5430. {
  5431. eFilamentAction=FilamentAction::MmuCut;
  5432. bFilamentFirstRun=false;
  5433. if(target_temperature[0]>=EXTRUDE_MINTEMP)
  5434. {
  5435. bFilamentPreheatState=true;
  5436. mFilamentItem(target_temperature[0],target_temperature_bed);
  5437. }
  5438. else lcd_generic_preheat_menu();
  5439. }
  5440. }
  5441. #endif //MMU_HAS_CUTTER
  5442. #ifdef SNMM
  5443. static void fil_unload_menu()
  5444. {
  5445. MENU_BEGIN();
  5446. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5447. MENU_ITEM_FUNCTION_P(_i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=17
  5448. MENU_ITEM_FUNCTION_P(_i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17
  5449. MENU_ITEM_FUNCTION_P(_i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17
  5450. MENU_ITEM_FUNCTION_P(_i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17
  5451. MENU_ITEM_FUNCTION_P(_i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17
  5452. if (mmu_enabled)
  5453. MENU_ITEM_FUNCTION_P(_i("Unload filament 5"), extr_unload_4);////MSG_UNLOAD_FILAMENT_5 c=17
  5454. MENU_END();
  5455. }
  5456. static void change_extr_menu(){
  5457. MENU_BEGIN();
  5458. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5459. MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1
  5460. MENU_ITEM_FUNCTION_P(_i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17 r=1
  5461. MENU_ITEM_FUNCTION_P(_i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17 r=1
  5462. MENU_ITEM_FUNCTION_P(_i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17 r=1
  5463. MENU_END();
  5464. }
  5465. #endif //SNMM
  5466. //unload filament for single material printer (used in M702 gcode)
  5467. void unload_filament()
  5468. {
  5469. custom_message_type = CustomMsg::FilamentLoading;
  5470. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  5471. raise_z_above(MIN_Z_FOR_UNLOAD);
  5472. // extr_unload2();
  5473. current_position[E_AXIS] -= 45;
  5474. plan_buffer_line_curposXYZE(5200 / 60);
  5475. st_synchronize();
  5476. current_position[E_AXIS] -= 15;
  5477. plan_buffer_line_curposXYZE(1000 / 60);
  5478. st_synchronize();
  5479. current_position[E_AXIS] -= 20;
  5480. plan_buffer_line_curposXYZE(1000 / 60);
  5481. st_synchronize();
  5482. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  5483. //disable extruder steppers so filament can be removed
  5484. disable_e0();
  5485. disable_e1();
  5486. disable_e2();
  5487. _delay(100);
  5488. Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  5489. uint8_t counterBeep = 0;
  5490. while (!lcd_clicked() && (counterBeep < 50)) {
  5491. delay_keep_alive(100);
  5492. counterBeep++;
  5493. }
  5494. st_synchronize();
  5495. while (lcd_clicked()) delay_keep_alive(100);
  5496. lcd_update_enable(true);
  5497. lcd_setstatuspgm(_T(WELCOME_MSG));
  5498. custom_message_type = CustomMsg::Status;
  5499. }
  5500. unsigned char lcd_choose_color() {
  5501. //function returns index of currently chosen item
  5502. //following part can be modified from 2 to 255 items:
  5503. //-----------------------------------------------------
  5504. unsigned char items_no = 2;
  5505. const char *item[items_no];
  5506. item[0] = "Orange";
  5507. item[1] = "Black";
  5508. //-----------------------------------------------------
  5509. uint_least8_t active_rows;
  5510. static int first = 0;
  5511. int enc_dif = 0;
  5512. unsigned char cursor_pos = 1;
  5513. enc_dif = lcd_encoder_diff;
  5514. lcd_clear();
  5515. lcd_putc_at(0, 1, '>');
  5516. active_rows = items_no < 3 ? items_no : 3;
  5517. lcd_consume_click();
  5518. while (1) {
  5519. lcd_puts_at_P(0, 0, PSTR("Choose color:"));
  5520. for (uint_least8_t i = 0; i < active_rows; i++) {
  5521. lcd_set_cursor(1, i+1);
  5522. lcd_print(item[first + i]);
  5523. }
  5524. manage_heater();
  5525. manage_inactivity(true);
  5526. proc_commands();
  5527. if (abs((enc_dif - lcd_encoder_diff)) > 12) {
  5528. if (enc_dif > lcd_encoder_diff) {
  5529. cursor_pos--;
  5530. }
  5531. if (enc_dif < lcd_encoder_diff) {
  5532. cursor_pos++;
  5533. }
  5534. if (cursor_pos > active_rows) {
  5535. cursor_pos = active_rows;
  5536. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5537. if (first < items_no - active_rows) {
  5538. first++;
  5539. lcd_clear();
  5540. }
  5541. }
  5542. if (cursor_pos < 1) {
  5543. cursor_pos = 1;
  5544. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5545. if (first > 0) {
  5546. first--;
  5547. lcd_clear();
  5548. }
  5549. }
  5550. lcd_putc_at(0, 1, ' ');
  5551. lcd_putc_at(0, 2, ' ');
  5552. lcd_putc_at(0, 3, ' ');
  5553. lcd_putc_at(0, cursor_pos, '>');
  5554. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5555. enc_dif = lcd_encoder_diff;
  5556. _delay(100);
  5557. }
  5558. if (lcd_clicked()) {
  5559. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5560. switch(cursor_pos + first - 1) {
  5561. case 0: return 1; break;
  5562. case 1: return 0; break;
  5563. default: return 99; break;
  5564. }
  5565. }
  5566. }
  5567. }
  5568. #include "w25x20cl.h"
  5569. #ifdef LCD_TEST
  5570. static void lcd_test_menu()
  5571. {
  5572. W25X20CL_SPI_ENTER();
  5573. w25x20cl_enable_wr();
  5574. w25x20cl_chip_erase();
  5575. w25x20cl_disable_wr();
  5576. }
  5577. #endif //LCD_TEST
  5578. static bool fan_error_selftest()
  5579. {
  5580. #ifdef FANCHECK
  5581. if (!fans_check_enabled) return 0;
  5582. fanSpeed = 255;
  5583. #ifdef FAN_SOFT_PWM
  5584. fanSpeedSoftPwm = 255;
  5585. #endif //FAN_SOFT_PWM
  5586. manage_heater(); //enables print fan
  5587. setExtruderAutoFanState(3); //force enables the extruder fan
  5588. #ifdef FAN_SOFT_PWM
  5589. extruder_autofan_last_check = _millis();
  5590. fan_measuring = true;
  5591. #endif //FAN_SOFT_PWM
  5592. _delay(1000); //delay_keep_alive would turn off extruder fan, because temerature is too low (maybe)
  5593. manage_heater();
  5594. fanSpeed = 0;
  5595. setExtruderAutoFanState(1); //releases lock on the extruder fan
  5596. #ifdef FAN_SOFT_PWM
  5597. fanSpeedSoftPwm = 0;
  5598. #endif //FAN_SOFT_PWM
  5599. manage_heater();
  5600. #ifdef TACH_0
  5601. if (fan_speed[0] <= 20) { //extruder fan error
  5602. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_EXTRUDER);
  5603. return 1;
  5604. }
  5605. #endif
  5606. #ifdef TACH_1
  5607. if (fan_speed[1] <= 20) { //print fan error
  5608. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_PRINT);
  5609. return 1;
  5610. }
  5611. #endif
  5612. #endif //FANCHECK
  5613. return 0;
  5614. }
  5615. //! @brief Resume paused print
  5616. //! @todo It is not good to call restore_print_from_ram_and_continue() from function called by lcd_update(),
  5617. //! as restore_print_from_ram_and_continue() calls lcd_update() internally.
  5618. void lcd_resume_print()
  5619. {
  5620. lcd_return_to_status();
  5621. lcd_reset_alert_level(); //for fan speed error
  5622. if (fan_error_selftest()) return; //abort if error persists
  5623. cmdqueue_serial_disabled = false;
  5624. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5625. st_synchronize();
  5626. lcd_setstatuspgm(_T(MSG_RESUMING_PRINT)); ////MSG_RESUMING_PRINT c=20
  5627. isPrintPaused = false;
  5628. restore_print_from_ram_and_continue(default_retraction);
  5629. pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  5630. refresh_cmd_timeout();
  5631. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUMED); //resume octoprint
  5632. }
  5633. static void change_sheet()
  5634. {
  5635. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  5636. menu_back(3);
  5637. }
  5638. static void lcd_rename_sheet_menu()
  5639. {
  5640. struct MenuData
  5641. {
  5642. bool initialized;
  5643. uint8_t selected;
  5644. char name[sizeof(Sheet::name)];
  5645. };
  5646. static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data");
  5647. MenuData* menuData = (MenuData*)&(menu_data[0]);
  5648. if (!menuData->initialized)
  5649. {
  5650. eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name));
  5651. lcd_encoder = menuData->name[0];
  5652. menuData->initialized = true;
  5653. }
  5654. if (lcd_encoder < '\x20') lcd_encoder = '\x20';
  5655. if (lcd_encoder > '\x7F') lcd_encoder = '\x7F';
  5656. menuData->name[menuData->selected] = lcd_encoder;
  5657. lcd_set_cursor(0,0);
  5658. for (uint_least8_t i = 0; i < sizeof(Sheet::name); ++i)
  5659. {
  5660. lcd_putc(menuData->name[i]);
  5661. }
  5662. lcd_set_cursor(menuData->selected, 1);
  5663. lcd_putc('^');
  5664. if (lcd_clicked())
  5665. {
  5666. if ((menuData->selected + 1u) < sizeof(Sheet::name))
  5667. {
  5668. lcd_encoder = menuData->name[++(menuData->selected)];
  5669. }
  5670. else
  5671. {
  5672. eeprom_update_block(menuData->name,
  5673. EEPROM_Sheets_base->s[selected_sheet].name,
  5674. sizeof(Sheet::name));
  5675. menu_back();
  5676. }
  5677. }
  5678. }
  5679. static void lcd_reset_sheet()
  5680. {
  5681. SheetName sheetName;
  5682. eeprom_default_sheet_name(selected_sheet, sheetName);
  5683. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),EEPROM_EMPTY_VALUE16);
  5684. eeprom_update_block(sheetName.c,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name));
  5685. if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))
  5686. {
  5687. eeprom_switch_to_next_sheet();
  5688. if((-1 == eeprom_next_initialized_sheet(0)) && (CALIBRATION_STATUS_CALIBRATED == calibration_status()))
  5689. {
  5690. calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
  5691. }
  5692. }
  5693. menu_back();
  5694. }
  5695. //! @brief Activate selected_sheet and run first layer calibration
  5696. static void activate_calibrate_sheet()
  5697. {
  5698. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  5699. lcd_first_layer_calibration_reset();
  5700. }
  5701. static void lcd_sheet_menu()
  5702. {
  5703. MENU_BEGIN();
  5704. MENU_ITEM_BACK_P(_T(MSG_STEEL_SHEETS));
  5705. if(eeprom_is_sheet_initialized(selected_sheet)){
  5706. MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); //// c=18
  5707. }
  5708. if (lcd_commands_type == LcdCommands::Idle)
  5709. {
  5710. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), activate_calibrate_sheet);////MSG_V2_CALIBRATION c=18
  5711. }
  5712. MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); //// c=18
  5713. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_reset_sheet); ////MSG_RESET c=14
  5714. MENU_END();
  5715. }
  5716. static void lcd_main_menu()
  5717. {
  5718. MENU_BEGIN();
  5719. // Majkl superawesome menu
  5720. MENU_ITEM_BACK_P(_T(MSG_WATCH));
  5721. #ifdef RESUME_DEBUG
  5722. if (!saved_printing)
  5723. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  5724. else
  5725. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  5726. #endif //RESUME_DEBUG
  5727. #ifdef TMC2130_DEBUG
  5728. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  5729. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  5730. #endif //TMC2130_DEBUG
  5731. if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag)
  5732. {
  5733. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  5734. }
  5735. if (farm_mode)
  5736. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  5737. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal))
  5738. {
  5739. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE
  5740. } else
  5741. {
  5742. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT
  5743. }
  5744. if(isPrintPaused && saved_printing_type == PRINTING_TYPE_USB)
  5745. {
  5746. #ifdef FANCHECK
  5747. if((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK))
  5748. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);////MSG_RESUME_PRINT c=18
  5749. #else
  5750. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);////MSG_RESUME_PRINT c=18
  5751. #endif
  5752. }
  5753. #ifdef SDSUPPORT
  5754. if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal)
  5755. {
  5756. if (card.isFileOpen())
  5757. {
  5758. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  5759. if (card.sdprinting)
  5760. {
  5761. MENU_ITEM_FUNCTION_P(_i("Pause print"), lcd_pause_print);////MSG_PAUSE_PRINT
  5762. }
  5763. else if(isPrintPaused)
  5764. {
  5765. #ifdef FANCHECK
  5766. if((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK))
  5767. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);////MSG_RESUME_PRINT c=18
  5768. #else
  5769. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);////MSG_RESUME_PRINT c=18
  5770. #endif
  5771. }
  5772. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  5773. }
  5774. }
  5775. else if (lcd_commands_type == LcdCommands::Layer1Cal && mesh_bed_leveling_flag == false && homing_flag == false) {
  5776. //MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  5777. }
  5778. else
  5779. {
  5780. if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal))
  5781. {
  5782. //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  5783. /*else*/ {
  5784. bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
  5785. MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  5786. }
  5787. }
  5788. #if SDCARDDETECT < 1
  5789. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD
  5790. #endif
  5791. }
  5792. } else
  5793. {
  5794. bMain=true; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  5795. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD
  5796. #if SDCARDDETECT < 1
  5797. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface////MSG_INIT_SDCARD
  5798. #endif
  5799. }
  5800. #endif
  5801. if(!isPrintPaused && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal))
  5802. {
  5803. if (!farm_mode)
  5804. {
  5805. const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  5806. const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
  5807. if ((nextSheet >= 0) && (sheet != nextSheet)) // show menu only if we have 2 or more sheets initialized
  5808. {
  5809. MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet);
  5810. }
  5811. }
  5812. }
  5813. if ( ! ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal) ) )
  5814. {
  5815. if (mmu_enabled)
  5816. {
  5817. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
  5818. MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);
  5819. //-// MENU_ITEM_FUNCTION_P(_T(MSG_UNLOAD_FILAMENT), extr_unload);
  5820. //bFilamentFirstRun=true;
  5821. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), mmu_unload_filament);
  5822. MENU_ITEM_SUBMENU_P(_T(MSG_EJECT_FILAMENT), mmu_fil_eject_menu);
  5823. #ifdef MMU_HAS_CUTTER
  5824. MENU_ITEM_SUBMENU_P(_T(MSG_CUT_FILAMENT), mmu_cut_filament_menu);
  5825. #endif //MMU_HAS_CUTTER
  5826. }
  5827. else
  5828. {
  5829. #ifdef SNMM
  5830. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  5831. MENU_ITEM_SUBMENU_P(_i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20 r=1
  5832. #endif
  5833. #ifdef FILAMENT_SENSOR
  5834. if ((fsensor_autoload_enabled == true) && (fsensor_enabled == true) && (mmu_enabled == false))
  5835. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=18
  5836. else
  5837. #endif //FILAMENT_SENSOR
  5838. {
  5839. bFilamentFirstRun=true;
  5840. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  5841. }
  5842. bFilamentFirstRun=true;
  5843. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  5844. }
  5845. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  5846. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  5847. }
  5848. if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal))
  5849. {
  5850. MENU_ITEM_SUBMENU_P(_i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS
  5851. }
  5852. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  5853. MENU_ITEM_SUBMENU_P(_i("Fail stats"), lcd_menu_fails_stats);
  5854. #endif
  5855. if (mmu_enabled) {
  5856. MENU_ITEM_SUBMENU_P(_i("Fail stats MMU"), lcd_menu_fails_stats_mmu);
  5857. }
  5858. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT
  5859. #ifdef LCD_TEST
  5860. MENU_ITEM_SUBMENU_P(_i("W25x20CL init"), lcd_test_menu);////MSG_SUPPORT
  5861. #endif //LCD_TEST
  5862. MENU_END();
  5863. }
  5864. void stack_error() {
  5865. Sound_MakeCustom(1000,0,true);
  5866. lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4
  5867. //err_triggered = 1;
  5868. while (1) delay_keep_alive(1000);
  5869. }
  5870. #ifdef DEBUG_STEPPER_TIMER_MISSED
  5871. bool stepper_timer_overflow_state = false;
  5872. uint16_t stepper_timer_overflow_max = 0;
  5873. uint16_t stepper_timer_overflow_last = 0;
  5874. uint16_t stepper_timer_overflow_cnt = 0;
  5875. void stepper_timer_overflow() {
  5876. char msg[28];
  5877. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  5878. lcd_setstatus(msg);
  5879. stepper_timer_overflow_state = false;
  5880. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  5881. stepper_timer_overflow_max = stepper_timer_overflow_last;
  5882. SERIAL_ECHOPGM("Stepper timer overflow: ");
  5883. MYSERIAL.print(msg);
  5884. SERIAL_ECHOLNPGM("");
  5885. WRITE(BEEPER, LOW);
  5886. }
  5887. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5888. static void lcd_colorprint_change() {
  5889. enquecommand_P(PSTR("M600"));
  5890. custom_message_type = CustomMsg::FilamentLoading; //just print status message
  5891. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5892. lcd_return_to_status();
  5893. lcd_draw_update = 3;
  5894. }
  5895. #ifdef LA_LIVE_K
  5896. // @wavexx: looks like there's no generic float editing function in menu.cpp so we
  5897. // redefine our custom handling functions to mimick other tunables
  5898. const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6S";
  5899. static void lcd_advance_draw_K(char chr, float val)
  5900. {
  5901. if (val <= 0)
  5902. lcd_printf_P(menu_fmt_float13off, chr, MSG_ADVANCE_K, _T(MSG_OFF));
  5903. else
  5904. lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val);
  5905. }
  5906. static void lcd_advance_edit_K(void)
  5907. {
  5908. if (lcd_draw_update)
  5909. {
  5910. if (lcd_encoder < 0) lcd_encoder = 0;
  5911. if (lcd_encoder > 999) lcd_encoder = 999;
  5912. lcd_set_cursor(0, 1);
  5913. lcd_advance_draw_K(' ', 0.01 * lcd_encoder);
  5914. }
  5915. if (LCD_CLICKED)
  5916. {
  5917. extruder_advance_K = 0.01 * lcd_encoder;
  5918. menu_back_no_reset();
  5919. }
  5920. }
  5921. static uint8_t lcd_advance_K()
  5922. {
  5923. if (menu_item == menu_line)
  5924. {
  5925. if (lcd_draw_update)
  5926. {
  5927. lcd_set_cursor(0, menu_row);
  5928. lcd_advance_draw_K((lcd_encoder == menu_item)?'>':' ', extruder_advance_K);
  5929. }
  5930. if (menu_clicked && (lcd_encoder == menu_item))
  5931. {
  5932. menu_submenu_no_reset(lcd_advance_edit_K);
  5933. lcd_encoder = 100. * extruder_advance_K;
  5934. return menu_item_ret();
  5935. }
  5936. }
  5937. menu_item++;
  5938. return 0;
  5939. }
  5940. #define MENU_ITEM_EDIT_advance_K() do { if (lcd_advance_K()) return; } while (0)
  5941. #endif
  5942. static void lcd_tune_menu()
  5943. {
  5944. typedef struct
  5945. {
  5946. menu_data_edit_t reserved; //!< reserved for number editing functions
  5947. int8_t status; //!< To recognize, whether the menu has been just initialized.
  5948. //! Backup of extrudemultiply, to recognize, that the value has been changed and
  5949. //! it needs to be applied.
  5950. int16_t extrudemultiply;
  5951. } _menu_data_t;
  5952. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  5953. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  5954. if (_md->status == 0)
  5955. {
  5956. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  5957. _md->status = 1;
  5958. _md->extrudemultiply = extrudemultiply;
  5959. }
  5960. else if (_md->extrudemultiply != extrudemultiply)
  5961. {
  5962. // extrudemultiply has been changed from the child menu. Apply the new value.
  5963. _md->extrudemultiply = extrudemultiply;
  5964. calculate_extruder_multipliers();
  5965. }
  5966. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  5967. MENU_BEGIN();
  5968. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  5969. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED
  5970. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  5971. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  5972. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  5973. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW
  5974. #ifdef LA_LIVE_K
  5975. MENU_ITEM_EDIT_advance_K();//7
  5976. #endif
  5977. #ifdef FILAMENTCHANGEENABLE
  5978. if (!farm_mode)
  5979. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  5980. #endif
  5981. #ifdef FILAMENT_SENSOR
  5982. if (FSensorStateMenu == 0) {
  5983. if (fsensor_not_responding && (mmu_enabled == false)) {
  5984. /* Filament sensor not working*/
  5985. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_NA), lcd_fsensor_state_set);
  5986. }
  5987. else {
  5988. /* Filament sensor turned off, working, no problems*/
  5989. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_OFF), lcd_fsensor_state_set);
  5990. }
  5991. }
  5992. else {
  5993. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_ON), lcd_fsensor_state_set);
  5994. }
  5995. #ifdef IR_SENSOR_ANALOG
  5996. FSENSOR_ACTION_NA;
  5997. #endif //IR_SENSOR_ANALOG
  5998. #endif //FILAMENT_SENSOR
  5999. SETTINGS_AUTO_DEPLETE;
  6000. SETTINGS_CUTTER;
  6001. if(farm_mode)
  6002. {
  6003. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  6004. }
  6005. #ifdef TMC2130
  6006. if(!farm_mode)
  6007. {
  6008. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);
  6009. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);
  6010. if (SilentModeMenu == SILENT_MODE_NORMAL)
  6011. {
  6012. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);
  6013. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);
  6014. }
  6015. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);
  6016. }
  6017. #else //TMC2130
  6018. if (!farm_mode) { //dont show in menu if we are in farm mode
  6019. switch (SilentModeMenu) {
  6020. case SILENT_MODE_POWER: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break;
  6021. case SILENT_MODE_SILENT: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set); break;
  6022. case SILENT_MODE_AUTO: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set); break;
  6023. default: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break; // (probably) not needed
  6024. }
  6025. }
  6026. #endif //TMC2130
  6027. SETTINGS_MMU_MODE;
  6028. SETTINGS_SOUND;
  6029. #ifdef LCD_BL_PIN
  6030. if (backlightSupport)
  6031. {
  6032. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  6033. }
  6034. #endif //LCD_BL_PIN
  6035. MENU_END();
  6036. }
  6037. static void mbl_magnets_elimination_toggle() {
  6038. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  6039. magnet_elimination = !magnet_elimination;
  6040. eeprom_update_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, (uint8_t)magnet_elimination);
  6041. }
  6042. static void mbl_mesh_toggle() {
  6043. uint8_t mesh_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  6044. if(mesh_nr == 3) mesh_nr = 7;
  6045. else mesh_nr = 3;
  6046. eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mesh_nr);
  6047. }
  6048. static void mbl_probe_nr_toggle() {
  6049. mbl_z_probe_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR);
  6050. switch (mbl_z_probe_nr) {
  6051. case 1: mbl_z_probe_nr = 3; break;
  6052. case 3: mbl_z_probe_nr = 5; break;
  6053. case 5: mbl_z_probe_nr = 1; break;
  6054. default: mbl_z_probe_nr = 3; break;
  6055. }
  6056. eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, mbl_z_probe_nr);
  6057. }
  6058. static void lcd_mesh_bed_leveling_settings()
  6059. {
  6060. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  6061. uint8_t points_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  6062. char sToggle[4]; //enough for nxn format
  6063. MENU_BEGIN();
  6064. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  6065. sToggle[0] = points_nr + '0';
  6066. sToggle[1] = 'x';
  6067. sToggle[2] = points_nr + '0';
  6068. sToggle[3] = 0;
  6069. MENU_ITEM_TOGGLE(_T(MSG_MESH), sToggle, mbl_mesh_toggle);
  6070. sToggle[0] = mbl_z_probe_nr + '0';
  6071. sToggle[1] = 0;
  6072. MENU_ITEM_TOGGLE(_T(MSG_Z_PROBE_NR), sToggle, mbl_probe_nr_toggle);
  6073. MENU_ITEM_TOGGLE_P(_T(MSG_MAGNETS_COMP), (points_nr == 7) ? (magnet_elimination ? _T(MSG_ON): _T(MSG_OFF)) : _T(MSG_NA), mbl_magnets_elimination_toggle);
  6074. MENU_END();
  6075. //SETTINGS_MBL_MODE;
  6076. }
  6077. #ifdef LCD_BL_PIN
  6078. static void backlight_mode_toggle()
  6079. {
  6080. switch (backlightMode)
  6081. {
  6082. case BACKLIGHT_MODE_BRIGHT: backlightMode = BACKLIGHT_MODE_DIM; break;
  6083. case BACKLIGHT_MODE_DIM: backlightMode = BACKLIGHT_MODE_AUTO; break;
  6084. case BACKLIGHT_MODE_AUTO: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  6085. default: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  6086. }
  6087. backlight_save();
  6088. }
  6089. static void lcd_backlight_menu()
  6090. {
  6091. MENU_BEGIN();
  6092. ON_MENU_LEAVE(
  6093. backlight_save();
  6094. );
  6095. MENU_ITEM_BACK_P(_T(MSG_BACK));
  6096. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_HIGH), &backlightLevel_HIGH, backlightLevel_LOW, 255);
  6097. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_LOW), &backlightLevel_LOW, 0, backlightLevel_HIGH);
  6098. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), ((backlightMode==BACKLIGHT_MODE_BRIGHT) ? _T(MSG_BRIGHT) : ((backlightMode==BACKLIGHT_MODE_DIM) ? _T(MSG_DIM) : _T(MSG_AUTO))), backlight_mode_toggle);
  6099. MENU_ITEM_EDIT_int3_P(_T(MSG_TIMEOUT), &backlightTimer_period, 1, 999);
  6100. MENU_END();
  6101. }
  6102. #endif //LCD_BL_PIN
  6103. static void lcd_control_temperature_menu()
  6104. {
  6105. #ifdef PIDTEMP
  6106. // set up temp variables - undo the default scaling
  6107. // raw_Ki = unscalePID_i(Ki);
  6108. // raw_Kd = unscalePID_d(Kd);
  6109. #endif
  6110. MENU_BEGIN();
  6111. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  6112. #if TEMP_SENSOR_0 != 0
  6113. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  6114. #endif
  6115. #if TEMP_SENSOR_1 != 0
  6116. MENU_ITEM_EDIT_int3_P(_i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1
  6117. #endif
  6118. #if TEMP_SENSOR_2 != 0
  6119. MENU_ITEM_EDIT_int3_P(_i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2
  6120. #endif
  6121. #if TEMP_SENSOR_BED != 0
  6122. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  6123. #endif
  6124. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  6125. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  6126. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  6127. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  6128. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN
  6129. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX
  6130. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR
  6131. #endif
  6132. MENU_END();
  6133. }
  6134. static void lcd_sd_refresh()
  6135. {
  6136. #if SDCARDDETECT == -1
  6137. card.initsd();
  6138. #else
  6139. card.presort();
  6140. #endif
  6141. menu_top = 0;
  6142. lcd_encoder = 0;
  6143. menu_data_reset(); //Forces reloading of cached variables.
  6144. }
  6145. static void lcd_sd_updir()
  6146. {
  6147. card.updir();
  6148. menu_top = 0;
  6149. lcd_encoder = 0;
  6150. menu_data_reset(); //Forces reloading of cached variables.
  6151. }
  6152. void lcd_print_stop()
  6153. {
  6154. if (!card.sdprinting) {
  6155. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint
  6156. }
  6157. cmdqueue_serial_disabled = false; //for when canceling a print with a fancheck
  6158. CRITICAL_SECTION_START;
  6159. // Clear any saved printing state
  6160. cancel_saved_printing();
  6161. // Abort the planner/queue/sd
  6162. planner_abort_hard();
  6163. cmdqueue_reset();
  6164. card.sdprinting = false;
  6165. card.closefile();
  6166. st_reset_timer();
  6167. CRITICAL_SECTION_END;
  6168. #ifdef MESH_BED_LEVELING
  6169. mbl.active = false; //also prevents undoing the mbl compensation a second time in the second planner_abort_hard()
  6170. #endif
  6171. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  6172. stoptime = _millis();
  6173. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  6174. pause_time = 0;
  6175. save_statistics(total_filament_used, t);
  6176. lcd_commands_step = 0;
  6177. lcd_commands_type = LcdCommands::Idle;
  6178. lcd_cooldown(); //turns off heaters and fan; goes to status screen.
  6179. cancel_heatup = true; //unroll temperature wait loop stack.
  6180. current_position[Z_AXIS] += 10; //lift Z.
  6181. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  6182. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) //if axis are homed, move to parked position.
  6183. {
  6184. current_position[X_AXIS] = X_CANCEL_POS;
  6185. current_position[Y_AXIS] = Y_CANCEL_POS;
  6186. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6187. }
  6188. st_synchronize();
  6189. if (mmu_enabled) extr_unload(); //M702 C
  6190. finishAndDisableSteppers(); //M84
  6191. lcd_setstatuspgm(_T(WELCOME_MSG));
  6192. custom_message_type = CustomMsg::Status;
  6193. planner_abort_hard(); //needs to be done since plan_buffer_line resets waiting_inside_plan_buffer_line_print_aborted to false. Also copies current to destination.
  6194. axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative
  6195. isPrintPaused = false; //clear isPrintPaused flag to allow starting next print after pause->stop scenario.
  6196. }
  6197. void lcd_sdcard_stop()
  6198. {
  6199. lcd_puts_at_P(0, 0, _T(MSG_STOP_PRINT));
  6200. lcd_puts_at_P(2, 2, _T(MSG_NO));
  6201. lcd_puts_at_P(2, 3, _T(MSG_YES));
  6202. lcd_putc_at(0, 2, ' ');
  6203. lcd_putc_at(0, 3, ' ');
  6204. if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; }
  6205. if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; }
  6206. lcd_putc_at(0, 1 + lcd_encoder, '>');
  6207. if (lcd_clicked())
  6208. {
  6209. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  6210. if ((int32_t)lcd_encoder == 1)
  6211. {
  6212. lcd_return_to_status();
  6213. }
  6214. if ((int32_t)lcd_encoder == 2)
  6215. {
  6216. lcd_print_stop();
  6217. }
  6218. }
  6219. }
  6220. void lcd_sdcard_menu()
  6221. {
  6222. enum menuState_t : uint8_t {_uninitialized, _standard, _scrolling};
  6223. typedef struct
  6224. {
  6225. menuState_t menuState = _uninitialized;
  6226. uint8_t offset;
  6227. bool isDir;
  6228. const char* scrollPointer;
  6229. uint16_t selectedFileID;
  6230. uint16_t fileCnt;
  6231. int8_t row;
  6232. uint8_t sdSort;
  6233. ShortTimer lcd_scrollTimer;
  6234. } _menu_data_sdcard_t;
  6235. static_assert(sizeof(menu_data)>= sizeof(_menu_data_sdcard_t),"_menu_data_sdcard_t doesn't fit into menu_data");
  6236. _menu_data_sdcard_t* _md = (_menu_data_sdcard_t*)&(menu_data[0]);
  6237. switch(_md->menuState)
  6238. {
  6239. case _uninitialized: //Initialize menu data
  6240. {
  6241. if (card.presort_flag == true) //used to force resorting if sorting type is changed.
  6242. {
  6243. card.presort_flag = false;
  6244. card.presort();
  6245. }
  6246. _md->fileCnt = card.getnrfilenames();
  6247. _md->sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  6248. _md->menuState = _standard;
  6249. // FALLTHRU
  6250. }
  6251. case _standard: //normal menu structure.
  6252. {
  6253. if (!_md->lcd_scrollTimer.running()) //if the timer is not running, then the menu state was just switched, so redraw the screen.
  6254. {
  6255. _md->lcd_scrollTimer.start();
  6256. lcd_draw_update = 1;
  6257. }
  6258. if (_md->lcd_scrollTimer.expired(500) && (_md->row != -1)) //switch to the scrolling state on timeout if a file/dir is selected.
  6259. {
  6260. _md->menuState = _scrolling;
  6261. _md->offset = 0;
  6262. _md->scrollPointer = NULL;
  6263. _md->lcd_scrollTimer.start();
  6264. lcd_draw_update = 1; //forces last load before switching to scrolling.
  6265. }
  6266. if (lcd_draw_update == 0 && !LCD_CLICKED)
  6267. return; // nothing to do (so don't thrash the SD card)
  6268. _md->row = -1; // assume that no SD file/dir is currently selected. Once they are rendered, it will be changed to the correct row for the _scrolling state.
  6269. //if we reached this point it means that the encoder moved or clicked or the state is being switched. Reset the scrollTimer.
  6270. _md->lcd_scrollTimer.start();
  6271. MENU_BEGIN();
  6272. MENU_ITEM_BACK_P(_T(bMain?MSG_MAIN:MSG_BACK)); // i.e. default menu-item / menu-item after card insertion
  6273. card.getWorkDirName();
  6274. if (card.filename[0] == '/')
  6275. {
  6276. #if SDCARDDETECT == -1
  6277. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  6278. #else
  6279. if (card.ToshibaFlashAir_isEnabled())
  6280. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh); //show the refresh option if in flashAir mode.
  6281. #endif
  6282. }
  6283. else
  6284. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); //Show the updir button if in a subdir.
  6285. for (uint16_t i = _md->fileCnt; i-- > 0;) // Every file, from top to bottom.
  6286. {
  6287. if (menu_item == menu_line) //If the file is on the screen.
  6288. {
  6289. //load filename to memory.
  6290. #ifdef SDCARD_SORT_ALPHA
  6291. if (_md->sdSort == SD_SORT_NONE)
  6292. card.getfilename(i);
  6293. else
  6294. card.getfilename_sorted(i);
  6295. #else
  6296. card.getfilename(i);
  6297. #endif
  6298. if (lcd_encoder == menu_item) //If the file is selected.
  6299. {
  6300. _md->selectedFileID = i;
  6301. _md->isDir = card.filenameIsDir;
  6302. _md->row = menu_row;
  6303. }
  6304. if (card.filenameIsDir)
  6305. MENU_ITEM_SDDIR(card.filename, card.longFilename);
  6306. else
  6307. MENU_ITEM_SDFILE(card.filename, card.longFilename);
  6308. }
  6309. else MENU_ITEM_DUMMY(); //dummy item that just increments the internal menu counters.
  6310. }
  6311. MENU_END();
  6312. } break;
  6313. case _scrolling: //scrolling filename
  6314. {
  6315. const bool rewindFlag = LCD_CLICKED || lcd_draw_update; //flag that says whether the menu should return to _standard state.
  6316. if (_md->scrollPointer == NULL)
  6317. {
  6318. //load filename to memory.
  6319. #ifdef SDCARD_SORT_ALPHA
  6320. if (_md->sdSort == SD_SORT_NONE)
  6321. card.getfilename(_md->selectedFileID);
  6322. else
  6323. card.getfilename_sorted(_md->selectedFileID);
  6324. #else
  6325. card.getfilename(_md->selectedFileID);
  6326. #endif
  6327. _md->scrollPointer = (card.longFilename[0] == '\0') ? card.filename : card.longFilename;
  6328. }
  6329. if (rewindFlag == 1)
  6330. _md->offset = 0; //redraw once again from the beginning.
  6331. if (_md->lcd_scrollTimer.expired(300) || rewindFlag)
  6332. {
  6333. uint8_t i = LCD_WIDTH - ((_md->isDir)?2:1);
  6334. lcd_set_cursor(0, _md->row);
  6335. lcd_print('>');
  6336. if (_md->isDir)
  6337. lcd_print(LCD_STR_FOLDER[0]);
  6338. for (; i != 0; i--)
  6339. {
  6340. const char* c = (_md->scrollPointer + _md->offset + ((LCD_WIDTH - ((_md->isDir)?2:1)) - i));
  6341. lcd_print(c[0]);
  6342. if (c[1])
  6343. _md->lcd_scrollTimer.start();
  6344. else
  6345. {
  6346. _md->lcd_scrollTimer.stop();
  6347. break; //stop at the end of the string
  6348. }
  6349. }
  6350. if (i != 0) //adds spaces if string is incomplete or at the end (instead of null).
  6351. {
  6352. lcd_space(i);
  6353. }
  6354. _md->offset++;
  6355. }
  6356. if (rewindFlag) //go back to sd_menu.
  6357. {
  6358. _md->lcd_scrollTimer.stop(); //forces redraw in _standard state
  6359. _md->menuState = _standard;
  6360. }
  6361. } break;
  6362. default: _md->menuState = _uninitialized; //shouldn't ever happen. Anyways, initialize the menu.
  6363. }
  6364. }
  6365. #ifdef TMC2130
  6366. static void lcd_belttest_v()
  6367. {
  6368. lcd_belttest();
  6369. menu_back_if_clicked();
  6370. }
  6371. void lcd_belttest()
  6372. {
  6373. lcd_clear();
  6374. // Belttest requires high power mode. Enable it.
  6375. FORCE_HIGH_POWER_START;
  6376. uint16_t X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  6377. uint16_t Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  6378. lcd_printf_P(_T(MSG_CHECKING_X));
  6379. lcd_set_cursor(0,1), lcd_printf_P(PSTR("X: %u -> ..."),X);
  6380. KEEPALIVE_STATE(IN_HANDLER);
  6381. // N.B: it doesn't make sense to handle !lcd_selfcheck...() because selftest_sg throws its own error screen
  6382. // that clobbers ours, with more info than we could provide. So on fail we just fall through to take us back to status.
  6383. if (lcd_selfcheck_axis_sg(X_AXIS)){
  6384. X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  6385. lcd_set_cursor(10,1), lcd_printf_P(PSTR("%u"),X); // Show new X value next to old one.
  6386. lcd_puts_at_P(0,2,_T(MSG_CHECKING_Y));
  6387. lcd_set_cursor(0,3), lcd_printf_P(PSTR("Y: %u -> ..."),Y);
  6388. if (lcd_selfcheck_axis_sg(Y_AXIS))
  6389. {
  6390. Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  6391. lcd_set_cursor(10,3),lcd_printf_P(PSTR("%u"),Y);
  6392. lcd_set_cursor(19, 3);
  6393. lcd_print(LCD_STR_UPLEVEL);
  6394. lcd_wait_for_click_delay(10);
  6395. }
  6396. }
  6397. FORCE_HIGH_POWER_END;
  6398. KEEPALIVE_STATE(NOT_BUSY);
  6399. }
  6400. #endif //TMC2130
  6401. #ifdef IR_SENSOR_ANALOG
  6402. // called also from marlin_main.cpp
  6403. void printf_IRSensorAnalogBoardChange(){
  6404. printf_P(PSTR("Filament sensor board change detected: revision%S\n"), FsensorIRVersionText());
  6405. }
  6406. static bool lcd_selftest_IRsensor(bool bStandalone)
  6407. {
  6408. bool bPCBrev04;
  6409. uint16_t volt_IR_int;
  6410. volt_IR_int = current_voltage_raw_IR;
  6411. bPCBrev04=(volt_IR_int < IRsensor_Hopen_TRESHOLD);
  6412. printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"), Raw2Voltage(volt_IR_int) );
  6413. if(volt_IR_int < IRsensor_Hmin_TRESHOLD){
  6414. if(!bStandalone)
  6415. lcd_selftest_error(TestError::FsensorLevel,"HIGH","");
  6416. return(false);
  6417. }
  6418. lcd_show_fullscreen_message_and_wait_P(_i("Insert the filament (do not load it) into the extruder and then press the knob."));////c=20 r=6
  6419. volt_IR_int = current_voltage_raw_IR;
  6420. printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"), Raw2Voltage(volt_IR_int));
  6421. if(volt_IR_int > (IRsensor_Lmax_TRESHOLD)){
  6422. if(!bStandalone)
  6423. lcd_selftest_error(TestError::FsensorLevel,"LOW","");
  6424. return(false);
  6425. }
  6426. if((bPCBrev04 ? 1 : 0) != (uint8_t)oFsensorPCB){ // safer then "(uint8_t)bPCBrev04"
  6427. oFsensorPCB=bPCBrev04 ? ClFsensorPCB::_Rev04 : ClFsensorPCB::_Old;
  6428. printf_IRSensorAnalogBoardChange();
  6429. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB);
  6430. }
  6431. return(true);
  6432. }
  6433. static void lcd_detect_IRsensor(){
  6434. bool bAction;
  6435. bool loaded;
  6436. bMenuFSDetect = true; // inhibits some code inside "manage_inactivity()"
  6437. /// Check if filament is loaded. If it is loaded stop detection.
  6438. /// @todo Add autodetection with MMU2s
  6439. loaded = ! READ(IR_SENSOR_PIN);
  6440. if(loaded ){
  6441. lcd_show_fullscreen_message_and_wait_P(_i("Please unload the filament first, then repeat this action."));
  6442. return;
  6443. } else {
  6444. lcd_show_fullscreen_message_and_wait_P(_i("Please check the IR sensor connection, unload filament if present."));
  6445. bAction = lcd_selftest_IRsensor(true);
  6446. }
  6447. if(bAction){
  6448. lcd_show_fullscreen_message_and_wait_P(_i("Sensor verified, remove the filament now."));////c=20 r=3
  6449. // the fsensor board has been successfully identified, any previous "not responding" may be cleared now
  6450. fsensor_not_responding = false;
  6451. } else {
  6452. lcd_show_fullscreen_message_and_wait_P(_i("Verification failed, remove the filament and try again."));////c=20 r=5
  6453. // here it is unclear what to to with the fsensor_not_responding flag
  6454. }
  6455. bMenuFSDetect=false; // de-inhibits some code inside "manage_inactivity()"
  6456. }
  6457. #endif //IR_SENSOR_ANALOG
  6458. static void lcd_selftest_v()
  6459. {
  6460. (void)lcd_selftest();
  6461. }
  6462. bool lcd_selftest()
  6463. {
  6464. int _progress = 0;
  6465. bool _result = true;
  6466. bool _swapped_fan = false;
  6467. #ifdef IR_SENSOR_ANALOG
  6468. //! Check if IR sensor is in unknown state, if so run Fsensor Detection
  6469. //! As the Fsensor Detection isn't yet ready for the mmu2s we set temporarily the IR sensor 0.3 or older for mmu2s
  6470. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  6471. if( oFsensorPCB == ClFsensorPCB::_Undef) {
  6472. if (!mmu_enabled) {
  6473. lcd_detect_IRsensor();
  6474. }
  6475. else {
  6476. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,0);
  6477. }
  6478. }
  6479. #endif //IR_SENSOR_ANALOG
  6480. lcd_wait_for_cool_down();
  6481. lcd_clear();
  6482. lcd_puts_at_P(0, 0, _i("Self test start "));////MSG_SELFTEST_START c=20
  6483. #ifdef TMC2130
  6484. FORCE_HIGH_POWER_START;
  6485. #endif // TMC2130
  6486. FORCE_BL_ON_START;
  6487. _delay(2000);
  6488. KEEPALIVE_STATE(IN_HANDLER);
  6489. _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000);
  6490. #if (defined(FANCHECK) && defined(TACH_0))
  6491. switch (lcd_selftest_fan_auto(0)){ // check extruder Fan
  6492. case FanCheck::ExtruderFan:
  6493. _result = false;
  6494. break;
  6495. case FanCheck::SwappedFan:
  6496. _swapped_fan = true;
  6497. // no break
  6498. default:
  6499. _result = true;
  6500. break;
  6501. }
  6502. #else //defined(TACH_0)
  6503. _result = lcd_selftest_manual_fan_check(0, false);
  6504. #endif //defined(TACH_0)
  6505. if (!_result)
  6506. {
  6507. lcd_selftest_error(TestError::ExtruderFan, "", "");
  6508. }
  6509. if (_result)
  6510. {
  6511. _progress = lcd_selftest_screen(TestScreen::PrintFan, _progress, 3, true, 2000);
  6512. #if (defined(FANCHECK) && defined(TACH_1))
  6513. switch (lcd_selftest_fan_auto(1)){ // check print fan
  6514. case FanCheck::PrintFan:
  6515. _result = false;
  6516. break;
  6517. case FanCheck::SwappedFan:
  6518. _swapped_fan = true;
  6519. // no break
  6520. default:
  6521. _result = true;
  6522. break;
  6523. }
  6524. #else //defined(TACH_1)
  6525. _result = lcd_selftest_manual_fan_check(1, false);
  6526. #endif //defined(TACH_1)
  6527. if (!_result)
  6528. {
  6529. lcd_selftest_error(TestError::PrintFan, "", ""); //print fan not spinning
  6530. }
  6531. }
  6532. if (_swapped_fan) {
  6533. //turn on print fan and check that left extruder fan is not spinning
  6534. _result = lcd_selftest_manual_fan_check(1, true);
  6535. if (_result) {
  6536. //print fan is stil turned on; check that it is spinning
  6537. _result = lcd_selftest_manual_fan_check(1, false, true);
  6538. if (!_result){
  6539. lcd_selftest_error(TestError::PrintFan, "", "");
  6540. }
  6541. }
  6542. else {
  6543. // fans are swapped
  6544. lcd_selftest_error(TestError::SwappedFan, "", "");
  6545. }
  6546. }
  6547. if (_result)
  6548. {
  6549. _progress = lcd_selftest_screen(TestScreen::FansOk, _progress, 3, true, 2000);
  6550. _result = lcd_selfcheck_endstops(); //With TMC2130, only the Z probe is tested.
  6551. }
  6552. if (_result)
  6553. {
  6554. //current_position[Z_AXIS] += 15; //move Z axis higher to avoid false triggering of Z end stop in case that we are very low - just above heatbed
  6555. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 2000);
  6556. #ifdef TMC2130
  6557. _result = lcd_selfcheck_axis_sg(X_AXIS);
  6558. #else
  6559. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  6560. #endif //TMC2130
  6561. }
  6562. if (_result)
  6563. {
  6564. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 0);
  6565. #ifndef TMC2130
  6566. _result = lcd_selfcheck_pulleys(X_AXIS);
  6567. #endif
  6568. }
  6569. if (_result)
  6570. {
  6571. _progress = lcd_selftest_screen(TestScreen::AxisY, _progress, 3, true, 1500);
  6572. #ifdef TMC2130
  6573. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  6574. #else
  6575. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  6576. #endif // TMC2130
  6577. }
  6578. if (_result)
  6579. {
  6580. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 0);
  6581. #ifndef TMC2130
  6582. _result = lcd_selfcheck_pulleys(Y_AXIS);
  6583. #endif // TMC2130
  6584. }
  6585. if (_result)
  6586. {
  6587. #ifdef TMC2130
  6588. tmc2130_home_exit();
  6589. enable_endstops(false);
  6590. #endif
  6591. //homeaxis(X_AXIS);
  6592. //homeaxis(Y_AXIS);
  6593. current_position[X_AXIS] = pgm_read_float(bed_ref_points_4);
  6594. current_position[Y_AXIS] = pgm_read_float(bed_ref_points_4+1);
  6595. #ifdef TMC2130
  6596. //current_position[X_AXIS] += 0;
  6597. current_position[Y_AXIS] += 4;
  6598. #endif //TMC2130
  6599. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  6600. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6601. st_synchronize();
  6602. set_destination_to_current();
  6603. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500);
  6604. #ifdef TMC2130
  6605. homeaxis(Z_AXIS); //In case of failure, the code gets stuck in this function.
  6606. #else
  6607. _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS);
  6608. #endif //TMC2130
  6609. //raise Z to not damage the bed during and hotend testing
  6610. current_position[Z_AXIS] += 20;
  6611. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6612. st_synchronize();
  6613. }
  6614. #ifdef TMC2130
  6615. if (_result)
  6616. {
  6617. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  6618. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6619. st_synchronize();
  6620. _progress = lcd_selftest_screen(TestScreen::Home, 0, 2, true, 0);
  6621. bool bres = tmc2130_home_calibrate(X_AXIS);
  6622. _progress = lcd_selftest_screen(TestScreen::Home, 1, 2, true, 0);
  6623. bres &= tmc2130_home_calibrate(Y_AXIS);
  6624. _progress = lcd_selftest_screen(TestScreen::Home, 2, 2, true, 0);
  6625. if (bres)
  6626. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  6627. _result = bres;
  6628. }
  6629. #endif //TMC2130
  6630. if (_result)
  6631. {
  6632. _progress = lcd_selftest_screen(TestScreen::Bed, _progress, 3, true, 2000);
  6633. _result = lcd_selfcheck_check_heater(true);
  6634. }
  6635. if (_result)
  6636. {
  6637. _progress = lcd_selftest_screen(TestScreen::Hotend, _progress, 3, true, 1000);
  6638. _result = lcd_selfcheck_check_heater(false);
  6639. }
  6640. if (_result)
  6641. {
  6642. _progress = lcd_selftest_screen(TestScreen::HotendOk, _progress, 3, true, 2000); //nozzle ok
  6643. }
  6644. #ifdef FILAMENT_SENSOR
  6645. if (_result)
  6646. {
  6647. if (mmu_enabled)
  6648. {
  6649. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  6650. _result = selftest_irsensor();
  6651. if (_result)
  6652. {
  6653. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  6654. }
  6655. } else
  6656. {
  6657. #ifdef PAT9125
  6658. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  6659. _result = lcd_selftest_fsensor();
  6660. if (_result)
  6661. {
  6662. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  6663. }
  6664. #endif //PAT9125
  6665. #if 0
  6666. // Intentionally disabled - that's why we moved the detection to runtime by just checking the two voltages.
  6667. // The idea is not to force the user to remove and insert the filament on an assembled printer.
  6668. //def IR_SENSOR_ANALOG
  6669. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filament sensor
  6670. _result = lcd_selftest_IRsensor();
  6671. if (_result)
  6672. {
  6673. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //filament sensor OK
  6674. }
  6675. #endif //IR_SENSOR_ANALOG
  6676. }
  6677. }
  6678. #endif //FILAMENT_SENSOR
  6679. if (_result)
  6680. {
  6681. _progress = lcd_selftest_screen(TestScreen::AllCorrect, _progress, 3, true, 5000); //all correct
  6682. }
  6683. else
  6684. {
  6685. _progress = lcd_selftest_screen(TestScreen::Failed, _progress, 3, true, 5000);
  6686. }
  6687. lcd_reset_alert_level();
  6688. enquecommand_P(PSTR("M84"));
  6689. lcd_update_enable(true);
  6690. if (_result)
  6691. {
  6692. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK
  6693. }
  6694. else
  6695. {
  6696. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  6697. }
  6698. #ifdef TMC2130
  6699. FORCE_HIGH_POWER_END;
  6700. #endif // TMC2130
  6701. FORCE_BL_ON_END;
  6702. KEEPALIVE_STATE(NOT_BUSY);
  6703. return(_result);
  6704. }
  6705. #ifdef TMC2130
  6706. static void reset_crash_det(unsigned char axis) {
  6707. current_position[axis] += 10;
  6708. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6709. st_synchronize();
  6710. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  6711. }
  6712. static bool lcd_selfcheck_axis_sg(unsigned char axis) {
  6713. // each axis length is measured twice
  6714. float axis_length, current_position_init, current_position_final;
  6715. float measured_axis_length[2];
  6716. float margin = 60;
  6717. float max_error_mm = 5;
  6718. switch (axis) {
  6719. case 0: axis_length = X_MAX_POS; break;
  6720. case 1: axis_length = Y_MAX_POS + 8; break;
  6721. default: axis_length = 210; break;
  6722. }
  6723. tmc2130_sg_stop_on_crash = false;
  6724. tmc2130_home_exit();
  6725. enable_endstops(true);
  6726. raise_z_above(MESH_HOME_Z_SEARCH);
  6727. st_synchronize();
  6728. tmc2130_home_enter(1 << axis);
  6729. // first axis length measurement begin
  6730. current_position[axis] -= (axis_length + margin);
  6731. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6732. st_synchronize();
  6733. tmc2130_sg_meassure_start(axis);
  6734. current_position_init = st_get_position_mm(axis);
  6735. current_position[axis] += 2 * margin;
  6736. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6737. st_synchronize();
  6738. current_position[axis] += axis_length;
  6739. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6740. st_synchronize();
  6741. uint16_t sg1 = tmc2130_sg_meassure_stop();
  6742. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  6743. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  6744. current_position_final = st_get_position_mm(axis);
  6745. measured_axis_length[0] = abs(current_position_final - current_position_init);
  6746. // first measurement end and second measurement begin
  6747. current_position[axis] -= margin;
  6748. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6749. st_synchronize();
  6750. current_position[axis] -= (axis_length + margin);
  6751. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6752. st_synchronize();
  6753. current_position_init = st_get_position_mm(axis);
  6754. measured_axis_length[1] = abs(current_position_final - current_position_init);
  6755. tmc2130_home_exit();
  6756. //end of second measurement, now check for possible errors:
  6757. for(uint_least8_t i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  6758. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  6759. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  6760. enable_endstops(false);
  6761. const char *_error_1;
  6762. if (axis == X_AXIS) _error_1 = "X";
  6763. if (axis == Y_AXIS) _error_1 = "Y";
  6764. if (axis == Z_AXIS) _error_1 = "Z";
  6765. lcd_selftest_error(TestError::Axis, _error_1, "");
  6766. current_position[axis] = 0;
  6767. plan_set_position_curposXYZE();
  6768. reset_crash_det(axis);
  6769. enable_endstops(true);
  6770. endstops_hit_on_purpose();
  6771. return false;
  6772. }
  6773. }
  6774. printf_P(_N("Axis length difference:%.3f\n"), abs(measured_axis_length[0] - measured_axis_length[1]));
  6775. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  6776. //loose pulleys
  6777. const char *_error_1;
  6778. if (axis == X_AXIS) _error_1 = "X";
  6779. if (axis == Y_AXIS) _error_1 = "Y";
  6780. if (axis == Z_AXIS) _error_1 = "Z";
  6781. lcd_selftest_error(TestError::Pulley, _error_1, "");
  6782. current_position[axis] = 0;
  6783. plan_set_position_curposXYZE();
  6784. reset_crash_det(axis);
  6785. endstops_hit_on_purpose();
  6786. return false;
  6787. }
  6788. current_position[axis] = 0;
  6789. plan_set_position_curposXYZE();
  6790. reset_crash_det(axis);
  6791. endstops_hit_on_purpose();
  6792. return true;
  6793. }
  6794. #endif //TMC2130
  6795. #ifndef TMC2130
  6796. static bool lcd_selfcheck_axis(int _axis, int _travel)
  6797. {
  6798. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  6799. bool _stepdone = false;
  6800. bool _stepresult = false;
  6801. int _progress = 0;
  6802. int _travel_done = 0;
  6803. int _err_endstop = 0;
  6804. int _lcd_refresh = 0;
  6805. _travel = _travel + (_travel / 10);
  6806. if (_axis == X_AXIS) {
  6807. current_position[Z_AXIS] += 17;
  6808. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6809. }
  6810. do {
  6811. current_position[_axis] = current_position[_axis] - 1;
  6812. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6813. st_synchronize();
  6814. #ifdef TMC2130
  6815. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  6816. #else //TMC2130
  6817. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  6818. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  6819. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  6820. #endif //TMC2130
  6821. {
  6822. if (_axis == 0)
  6823. {
  6824. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6825. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  6826. }
  6827. if (_axis == 1)
  6828. {
  6829. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6830. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  6831. }
  6832. if (_axis == 2)
  6833. {
  6834. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6835. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  6836. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  6837. /*disable_x();
  6838. disable_y();
  6839. disable_z();*/
  6840. }
  6841. _stepdone = true;
  6842. }
  6843. if (_lcd_refresh < 6)
  6844. {
  6845. _lcd_refresh++;
  6846. }
  6847. else
  6848. {
  6849. _progress = lcd_selftest_screen(static_cast<TestScreen>(static_cast<int>(TestScreen::AxisX) + _axis), _progress, 3, false, 0);
  6850. _lcd_refresh = 0;
  6851. }
  6852. manage_heater();
  6853. manage_inactivity(true);
  6854. //_delay(100);
  6855. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  6856. } while (!_stepdone);
  6857. //current_position[_axis] = current_position[_axis] + 15;
  6858. //plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder);
  6859. if (!_stepresult)
  6860. {
  6861. const char *_error_1;
  6862. const char *_error_2;
  6863. if (_axis == X_AXIS) _error_1 = "X";
  6864. if (_axis == Y_AXIS) _error_1 = "Y";
  6865. if (_axis == Z_AXIS) _error_1 = "Z";
  6866. if (_err_endstop == 0) _error_2 = "X";
  6867. if (_err_endstop == 1) _error_2 = "Y";
  6868. if (_err_endstop == 2) _error_2 = "Z";
  6869. if (_travel_done >= _travel)
  6870. {
  6871. lcd_selftest_error(TestError::Endstop, _error_1, _error_2);
  6872. }
  6873. else
  6874. {
  6875. lcd_selftest_error(TestError::Motor, _error_1, _error_2);
  6876. }
  6877. }
  6878. current_position[_axis] = 0; //simulate axis home to avoid negative numbers for axis position, especially Z.
  6879. plan_set_position_curposXYZE();
  6880. return _stepresult;
  6881. }
  6882. static bool lcd_selfcheck_pulleys(int axis)
  6883. {
  6884. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  6885. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  6886. float current_position_init;
  6887. float move;
  6888. bool endstop_triggered = false;
  6889. int i;
  6890. unsigned long timeout_counter;
  6891. refresh_cmd_timeout();
  6892. manage_inactivity(true);
  6893. if (axis == 0) move = 50; //X_AXIS
  6894. else move = 50; //Y_AXIS
  6895. current_position_init = current_position[axis];
  6896. current_position[axis] += 2;
  6897. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6898. for (i = 0; i < 5; i++) {
  6899. refresh_cmd_timeout();
  6900. current_position[axis] = current_position[axis] + move;
  6901. st_current_set(0, 850); //set motor current higher
  6902. plan_buffer_line_curposXYZE(200);
  6903. st_synchronize();
  6904. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  6905. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  6906. current_position[axis] = current_position[axis] - move;
  6907. plan_buffer_line_curposXYZE(50);
  6908. st_synchronize();
  6909. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6910. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6911. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6912. return(false);
  6913. }
  6914. }
  6915. timeout_counter = _millis() + 2500;
  6916. endstop_triggered = false;
  6917. manage_inactivity(true);
  6918. while (!endstop_triggered) {
  6919. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6920. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6921. endstop_triggered = true;
  6922. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  6923. current_position[axis] += 10;
  6924. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6925. st_synchronize();
  6926. return(true);
  6927. }
  6928. else {
  6929. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6930. return(false);
  6931. }
  6932. }
  6933. else {
  6934. current_position[axis] -= 1;
  6935. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6936. st_synchronize();
  6937. if (_millis() > timeout_counter) {
  6938. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6939. return(false);
  6940. }
  6941. }
  6942. }
  6943. return(true);
  6944. }
  6945. #endif //not defined TMC2130
  6946. static bool lcd_selfcheck_endstops()
  6947. {
  6948. bool _result = true;
  6949. if (
  6950. #ifndef TMC2130
  6951. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6952. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6953. #endif //!TMC2130
  6954. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6955. {
  6956. #ifndef TMC2130
  6957. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  6958. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  6959. #endif //!TMC2130
  6960. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  6961. }
  6962. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6963. st_synchronize();
  6964. if (
  6965. #ifndef TMC2130
  6966. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6967. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6968. #endif //!TMC2130
  6969. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6970. {
  6971. _result = false;
  6972. char _error[4] = "";
  6973. #ifndef TMC2130
  6974. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  6975. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  6976. #endif //!TMC2130
  6977. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  6978. lcd_selftest_error(TestError::Endstops, _error, "");
  6979. }
  6980. manage_heater();
  6981. manage_inactivity(true);
  6982. return _result;
  6983. }
  6984. static bool lcd_selfcheck_check_heater(bool _isbed)
  6985. {
  6986. int _counter = 0;
  6987. int _progress = 0;
  6988. bool _stepresult = false;
  6989. bool _docycle = true;
  6990. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  6991. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  6992. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  6993. target_temperature[0] = (_isbed) ? 0 : 200;
  6994. target_temperature_bed = (_isbed) ? 100 : 0;
  6995. manage_heater();
  6996. manage_inactivity(true);
  6997. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  6998. do {
  6999. _counter++;
  7000. _docycle = (_counter < _cycles) ? true : false;
  7001. manage_heater();
  7002. manage_inactivity(true);
  7003. _progress = (_isbed) ? lcd_selftest_screen(TestScreen::Bed, _progress, 2, false, 400) : lcd_selftest_screen(TestScreen::Hotend, _progress, 2, false, 400);
  7004. /*if (_isbed) {
  7005. MYSERIAL.print("Bed temp:");
  7006. MYSERIAL.println(degBed());
  7007. }
  7008. else {
  7009. MYSERIAL.print("Hotend temp:");
  7010. MYSERIAL.println(degHotend(0));
  7011. }*/
  7012. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  7013. } while (_docycle);
  7014. target_temperature[0] = 0;
  7015. target_temperature_bed = 0;
  7016. manage_heater();
  7017. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  7018. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  7019. /*
  7020. MYSERIAL.println("");
  7021. MYSERIAL.print("Checked result:");
  7022. MYSERIAL.println(_checked_result);
  7023. MYSERIAL.print("Opposite result:");
  7024. MYSERIAL.println(_opposite_result);
  7025. */
  7026. if (_opposite_result < ((_isbed) ? 30 : 9))
  7027. {
  7028. if (_checked_result >= ((_isbed) ? 9 : 30))
  7029. {
  7030. _stepresult = true;
  7031. }
  7032. else
  7033. {
  7034. lcd_selftest_error(TestError::Heater, "", "");
  7035. }
  7036. }
  7037. else
  7038. {
  7039. lcd_selftest_error(TestError::Bed, "", "");
  7040. }
  7041. manage_heater();
  7042. manage_inactivity(true);
  7043. KEEPALIVE_STATE(IN_HANDLER);
  7044. return _stepresult;
  7045. }
  7046. static void lcd_selftest_error(TestError testError, const char *_error_1, const char *_error_2)
  7047. {
  7048. lcd_beeper_quick_feedback();
  7049. FORCE_BL_ON_END;
  7050. target_temperature[0] = 0;
  7051. target_temperature_bed = 0;
  7052. manage_heater();
  7053. manage_inactivity();
  7054. lcd_clear();
  7055. lcd_puts_at_P(0, 0, _i("Selftest error !"));////MSG_SELFTEST_ERROR
  7056. lcd_puts_at_P(0, 1, _i("Please check :"));////MSG_SELFTEST_PLEASECHECK
  7057. switch (testError)
  7058. {
  7059. case TestError::Heater:
  7060. lcd_puts_at_P(0, 2, _i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR
  7061. lcd_puts_at_P(0, 3, _i("Not connected"));////MSG_SELFTEST_NOTCONNECTED
  7062. break;
  7063. case TestError::Bed:
  7064. lcd_puts_at_P(0, 2, _i("Bed / Heater"));////MSG_SELFTEST_BEDHEATER
  7065. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7066. break;
  7067. case TestError::Endstops:
  7068. lcd_puts_at_P(0, 2, _i("Endstops"));////MSG_SELFTEST_ENDSTOPS
  7069. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7070. lcd_set_cursor(17, 3);
  7071. lcd_print(_error_1);
  7072. break;
  7073. case TestError::Motor:
  7074. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_MOTOR));
  7075. lcd_set_cursor(18, 2);
  7076. lcd_print(_error_1);
  7077. lcd_puts_at_P(0, 3, _i("Endstop"));////MSG_SELFTEST_ENDSTOP
  7078. lcd_set_cursor(18, 3);
  7079. lcd_print(_error_2);
  7080. break;
  7081. case TestError::Endstop:
  7082. lcd_puts_at_P(0, 2, _i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20
  7083. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  7084. lcd_set_cursor(18, 3);
  7085. lcd_print(_error_1);
  7086. break;
  7087. case TestError::PrintFan:
  7088. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_COOLING_FAN));
  7089. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7090. lcd_set_cursor(18, 3);
  7091. lcd_print(_error_1);
  7092. break;
  7093. case TestError::ExtruderFan:
  7094. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_EXTRUDER_FAN));
  7095. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7096. lcd_set_cursor(18, 3);
  7097. lcd_print(_error_1);
  7098. break;
  7099. case TestError::Pulley:
  7100. lcd_puts_at_P(0, 2, _i("Loose pulley"));////MSG_LOOSE_PULLEY c=20 r=1
  7101. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  7102. lcd_set_cursor(18, 3);
  7103. lcd_print(_error_1);
  7104. break;
  7105. case TestError::Axis:
  7106. lcd_puts_at_P(0, 2, _i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH
  7107. lcd_puts_at_P(0, 3, _i("Axis"));////MSG_SELFTEST_AXIS
  7108. lcd_set_cursor(18, 3);
  7109. lcd_print(_error_1);
  7110. break;
  7111. case TestError::SwappedFan:
  7112. lcd_puts_at_P(0, 2, _i("Front/left fans"));////MSG_SELFTEST_FANS
  7113. lcd_puts_at_P(0, 3, _i("Swapped"));////MSG_SELFTEST_SWAPPED
  7114. lcd_set_cursor(18, 3);
  7115. lcd_print(_error_1);
  7116. break;
  7117. case TestError::WiringFsensor:
  7118. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7119. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7120. break;
  7121. case TestError::TriggeringFsensor:
  7122. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7123. lcd_puts_at_P(0, 3, _i("False triggering"));////c=20
  7124. break;
  7125. case TestError::FsensorLevel:
  7126. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7127. lcd_set_cursor(0, 3);
  7128. lcd_printf_P(_i("%s level expected"),_error_1);////c=20
  7129. break;
  7130. }
  7131. _delay(1000);
  7132. lcd_beeper_quick_feedback();
  7133. do {
  7134. _delay(100);
  7135. manage_heater();
  7136. manage_inactivity();
  7137. } while (!lcd_clicked());
  7138. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  7139. lcd_return_to_status();
  7140. }
  7141. #ifdef FILAMENT_SENSOR
  7142. #ifdef PAT9125
  7143. static bool lcd_selftest_fsensor(void)
  7144. {
  7145. fsensor_init();
  7146. if (fsensor_not_responding)
  7147. {
  7148. lcd_selftest_error(TestError::WiringFsensor, "", "");
  7149. }
  7150. return (!fsensor_not_responding);
  7151. }
  7152. #endif //PAT9125
  7153. //! @brief Self-test of infrared barrier filament sensor mounted on MK3S with MMUv2 printer
  7154. //!
  7155. //! Test whether sensor is not triggering filament presence when extruder idler is moving without filament.
  7156. //!
  7157. //! Steps:
  7158. //! * Backup current active extruder temperature
  7159. //! * Pre-heat to PLA extrude temperature.
  7160. //! * Unload filament possibly present.
  7161. //! * Move extruder idler same way as during filament load
  7162. //! and sample IR_SENSOR_PIN.
  7163. //! * Check that pin doesn't go low.
  7164. //!
  7165. //! @retval true passed
  7166. //! @retval false failed
  7167. static bool selftest_irsensor()
  7168. {
  7169. class TempBackup
  7170. {
  7171. public:
  7172. TempBackup():
  7173. m_temp(degTargetHotend(active_extruder)),
  7174. m_extruder(active_extruder){}
  7175. ~TempBackup(){setTargetHotend(m_temp,m_extruder);}
  7176. private:
  7177. float m_temp;
  7178. uint8_t m_extruder;
  7179. };
  7180. uint8_t progress;
  7181. {
  7182. TempBackup tempBackup;
  7183. setTargetHotend(ABS_PREHEAT_HOTEND_TEMP,active_extruder);
  7184. mmu_wait_for_heater_blocking();
  7185. progress = lcd_selftest_screen(TestScreen::Fsensor, 0, 1, true, 0);
  7186. mmu_filament_ramming();
  7187. }
  7188. progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  7189. mmu_command(MmuCmd::U0);
  7190. manage_response(false, false);
  7191. for(uint_least8_t i = 0; i < 200; ++i)
  7192. {
  7193. if (0 == (i % 32)) progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  7194. mmu_load_step(false);
  7195. while (blocks_queued())
  7196. {
  7197. if (READ(IR_SENSOR_PIN) == 0)
  7198. {
  7199. lcd_selftest_error(TestError::TriggeringFsensor, "", "");
  7200. return false;
  7201. }
  7202. #ifdef TMC2130
  7203. manage_heater();
  7204. // Vojtech: Don't disable motors inside the planner!
  7205. if (!tmc2130_update_sg())
  7206. {
  7207. manage_inactivity(true);
  7208. }
  7209. #else //TMC2130
  7210. manage_heater();
  7211. // Vojtech: Don't disable motors inside the planner!
  7212. manage_inactivity(true);
  7213. #endif //TMC2130
  7214. }
  7215. }
  7216. return true;
  7217. }
  7218. #endif //FILAMENT_SENSOR
  7219. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  7220. bool _default)
  7221. {
  7222. bool _result = check_opposite;
  7223. lcd_clear();
  7224. lcd_puts_at_P(0, 0, _T(MSG_SELFTEST_FAN));
  7225. switch (_fan)
  7226. {
  7227. case 0:
  7228. // extruder cooling fan
  7229. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_COOLING_FAN) : _T(MSG_SELFTEST_EXTRUDER_FAN));
  7230. setExtruderAutoFanState(3);
  7231. break;
  7232. case 1:
  7233. // object cooling fan
  7234. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_EXTRUDER_FAN) : _T(MSG_SELFTEST_COOLING_FAN));
  7235. SET_OUTPUT(FAN_PIN);
  7236. #ifdef FAN_SOFT_PWM
  7237. fanSpeedSoftPwm = 255;
  7238. #else //FAN_SOFT_PWM
  7239. analogWrite(FAN_PIN, 255);
  7240. #endif //FAN_SOFT_PWM
  7241. break;
  7242. }
  7243. _delay(500);
  7244. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7245. lcd_putc_at(0, 3, '>');
  7246. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7247. int8_t enc_dif = int(_default)*3;
  7248. KEEPALIVE_STATE(PAUSED_FOR_USER);
  7249. lcd_button_pressed = false;
  7250. do
  7251. {
  7252. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  7253. if (enc_dif > lcd_encoder_diff) {
  7254. _result = !check_opposite;
  7255. lcd_putc_at(0, 2, '>');
  7256. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7257. lcd_putc_at(0, 3, ' ');
  7258. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7259. }
  7260. if (enc_dif < lcd_encoder_diff) {
  7261. _result = check_opposite;
  7262. lcd_putc_at(0, 2, ' ');
  7263. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7264. lcd_putc_at(0, 3, '>');
  7265. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7266. }
  7267. enc_dif = 0;
  7268. lcd_encoder_diff = 0;
  7269. }
  7270. manage_heater();
  7271. _delay(100);
  7272. } while (!lcd_clicked());
  7273. KEEPALIVE_STATE(IN_HANDLER);
  7274. setExtruderAutoFanState(0);
  7275. SET_OUTPUT(FAN_PIN);
  7276. #ifdef FAN_SOFT_PWM
  7277. fanSpeedSoftPwm = 0;
  7278. #else //FAN_SOFT_PWM
  7279. analogWrite(FAN_PIN, 0);
  7280. #endif //FAN_SOFT_PWM
  7281. fanSpeed = 0;
  7282. manage_heater();
  7283. return _result;
  7284. }
  7285. #ifdef FANCHECK
  7286. static FanCheck lcd_selftest_fan_auto(int _fan)
  7287. {
  7288. switch (_fan) {
  7289. case 0:
  7290. fanSpeed = 0;
  7291. manage_heater(); //turn off fan
  7292. setExtruderAutoFanState(3); //extruder fan
  7293. #ifdef FAN_SOFT_PWM
  7294. extruder_autofan_last_check = _millis();
  7295. fan_measuring = true;
  7296. #endif //FAN_SOFT_PWM
  7297. _delay(2000);
  7298. setExtruderAutoFanState(0); //extruder fan
  7299. manage_heater(); //count average fan speed from 2s delay and turn off fans
  7300. puts_P(PSTR("Test 1:"));
  7301. printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
  7302. printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
  7303. if (fan_speed[0] < 20) { // < 1200 RPM would mean either a faulty Noctua or Altfan
  7304. return FanCheck::ExtruderFan;
  7305. }
  7306. #ifdef FAN_SOFT_PWM
  7307. else if (fan_speed[0] > 50 ) { // printerFan is faster
  7308. return FanCheck::SwappedFan;
  7309. }
  7310. break;
  7311. #endif
  7312. case 1:
  7313. //will it work with Thotend > 50 C ?
  7314. #ifdef FAN_SOFT_PWM
  7315. fanSpeed = 255;
  7316. fanSpeedSoftPwm = 255;
  7317. extruder_autofan_last_check = _millis(); //store time when measurement starts
  7318. fan_measuring = true; //start fan measuring, rest is on manage_heater
  7319. #else //FAN_SOFT_PWM
  7320. fanSpeed = 150; //print fan
  7321. #endif //FAN_SOFT_PWM
  7322. for (uint8_t i = 0; i < 5; i++) {
  7323. delay_keep_alive(1000);
  7324. lcd_putc_at(18, 3, '-');
  7325. delay_keep_alive(1000);
  7326. lcd_putc_at(18, 3, '|');
  7327. }
  7328. fanSpeed = 0;
  7329. #ifdef FAN_SOFT_PWM
  7330. fanSpeedSoftPwm = 0;
  7331. #else //FAN_SOFT_PWM
  7332. manage_heater(); //turn off fan
  7333. manage_inactivity(true); //to turn off print fan
  7334. #endif //FAN_SOFT_PWM
  7335. puts_P(PSTR("Test 2:"));
  7336. printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
  7337. printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
  7338. if (!fan_speed[1]) {
  7339. return FanCheck::PrintFan;
  7340. }
  7341. #ifdef FAN_SOFT_PWM
  7342. fanSpeed = 80;
  7343. fanSpeedSoftPwm = 80;
  7344. for (uint8_t i = 0; i < 5; i++) {
  7345. delay_keep_alive(1000);
  7346. lcd_putc_at(18, 3, '-');
  7347. delay_keep_alive(1000);
  7348. lcd_putc_at(18, 3, '|');
  7349. }
  7350. fanSpeed = 0;
  7351. // noctua speed is between 17 and 24, turbine more then 30
  7352. if (fan_speed[1] < 30) {
  7353. return FanCheck::SwappedFan;
  7354. }
  7355. #else
  7356. // fan is spinning, but measured RPM are too low for print fan, it must
  7357. // be left extruder fan
  7358. else if (fan_speed[1] < 34) {
  7359. return FanCheck::SwappedFan;
  7360. }
  7361. #endif //FAN_SOFT_PWM
  7362. break;
  7363. }
  7364. return FanCheck::Success;
  7365. }
  7366. #endif //FANCHECK
  7367. static int lcd_selftest_screen(TestScreen screen, int _progress, int _progress_scale, bool _clear, int _delay)
  7368. {
  7369. lcd_update_enable(false);
  7370. const char *_indicator = (_progress >= _progress_scale) ? "-" : "|";
  7371. if (_clear) lcd_clear();
  7372. lcd_set_cursor(0, 0);
  7373. if (screen == TestScreen::ExtruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7374. if (screen == TestScreen::PrintFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7375. if (screen == TestScreen::FansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7376. if (screen == TestScreen::EndStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20
  7377. if (screen == TestScreen::AxisX) lcd_puts_P(_T(MSG_CHECKING_X));
  7378. if (screen == TestScreen::AxisY) lcd_puts_P(_T(MSG_CHECKING_Y));
  7379. if (screen == TestScreen::AxisZ) lcd_puts_P(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20
  7380. if (screen == TestScreen::Bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  7381. if (screen == TestScreen::Hotend
  7382. || screen == TestScreen::HotendOk) lcd_puts_P(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20
  7383. if (screen == TestScreen::Fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  7384. if (screen == TestScreen::FsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  7385. if (screen == TestScreen::AllCorrect) lcd_puts_P(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20
  7386. if (screen == TestScreen::Failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  7387. if (screen == TestScreen::Home) lcd_puts_P(_i("Calibrating home"));////c=20 r=1
  7388. lcd_puts_at_P(0, 1, separator);
  7389. if ((screen >= TestScreen::ExtruderFan) && (screen <= TestScreen::FansOk))
  7390. {
  7391. //SERIAL_ECHOLNPGM("Fan test");
  7392. lcd_puts_at_P(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18
  7393. lcd_set_cursor(18, 2);
  7394. (screen < TestScreen::PrintFan) ? lcd_print(_indicator) : lcd_print("OK");
  7395. lcd_puts_at_P(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18
  7396. lcd_set_cursor(18, 3);
  7397. (screen < TestScreen::FansOk) ? lcd_print(_indicator) : lcd_print("OK");
  7398. }
  7399. else if (screen >= TestScreen::Fsensor && screen <= TestScreen::FsensorOk)
  7400. {
  7401. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7402. lcd_putc(':');
  7403. lcd_set_cursor(18, 2);
  7404. (screen == TestScreen::Fsensor) ? lcd_print(_indicator) : lcd_print("OK");
  7405. }
  7406. else if (screen < TestScreen::Fsensor)
  7407. {
  7408. //SERIAL_ECHOLNPGM("Other tests");
  7409. TestScreen _step_block = TestScreen::AxisX;
  7410. lcd_selftest_screen_step(2, 2, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("X"), _indicator);
  7411. _step_block = TestScreen::AxisY;
  7412. lcd_selftest_screen_step(2, 8, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Y"), _indicator);
  7413. _step_block = TestScreen::AxisZ;
  7414. lcd_selftest_screen_step(2, 14, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Z"), _indicator);
  7415. _step_block = TestScreen::Bed;
  7416. lcd_selftest_screen_step(3, 0, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Bed"), _indicator);
  7417. _step_block = TestScreen::Hotend;
  7418. lcd_selftest_screen_step(3, 9, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Hotend"), _indicator);
  7419. }
  7420. if (_delay > 0) delay_keep_alive(_delay);
  7421. _progress++;
  7422. return (_progress >= _progress_scale * 2) ? 0 : _progress;
  7423. }
  7424. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name_PROGMEM, const char *_indicator)
  7425. {
  7426. lcd_set_cursor(_col, _row);
  7427. uint8_t strlenNameP = strlen_P(_name_PROGMEM);
  7428. switch (_state)
  7429. {
  7430. case 1:
  7431. lcd_puts_P(_name_PROGMEM);
  7432. lcd_putc_at(_col + strlenNameP, _row, ':');
  7433. lcd_set_cursor(_col + strlenNameP + 1, _row);
  7434. lcd_print(_indicator);
  7435. break;
  7436. case 2:
  7437. lcd_puts_P(_name_PROGMEM);
  7438. lcd_putc_at(_col + strlenNameP, _row, ':');
  7439. lcd_puts_at_P(_col + strlenNameP + 1, _row, PSTR("OK"));
  7440. break;
  7441. default:
  7442. lcd_puts_P(_name_PROGMEM);
  7443. }
  7444. }
  7445. /** End of menus **/
  7446. /** Menu action functions **/
  7447. static bool check_file(const char* filename) {
  7448. if (farm_mode) return true;
  7449. card.openFileReadFilteredGcode(filename, true);
  7450. bool result = false;
  7451. const uint32_t filesize = card.getFileSize();
  7452. uint32_t startPos = 0;
  7453. const uint16_t bytesToCheck = min(END_FILE_SECTION, filesize);
  7454. uint8_t blocksPrinted = 0;
  7455. if (filesize > END_FILE_SECTION) {
  7456. startPos = filesize - END_FILE_SECTION;
  7457. card.setIndex(startPos);
  7458. }
  7459. cmdqueue_reset();
  7460. cmdqueue_serial_disabled = true;
  7461. lcd_clear();
  7462. lcd_puts_at_P(0, 1, _i("Checking file"));////c=20 r=1
  7463. lcd_set_cursor(0, 2);
  7464. while (!card.eof() && !result) {
  7465. for (; blocksPrinted < (((card.get_sdpos() - startPos) * LCD_WIDTH) / bytesToCheck); blocksPrinted++)
  7466. lcd_print('\xFF'); //simple progress bar
  7467. card.sdprinting = true;
  7468. get_command();
  7469. result = check_commands();
  7470. }
  7471. for (; blocksPrinted < LCD_WIDTH; blocksPrinted++)
  7472. lcd_print('\xFF'); //simple progress bar
  7473. _delay(100); //for the user to see the end of the progress bar.
  7474. cmdqueue_serial_disabled = false;
  7475. card.printingHasFinished();
  7476. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  7477. lcd_finishstatus();
  7478. return result;
  7479. }
  7480. static void menu_action_sdfile(const char* filename)
  7481. {
  7482. loading_flag = false;
  7483. char cmd[30];
  7484. char* c;
  7485. bool result = true;
  7486. sprintf_P(cmd, PSTR("M23 %s"), filename);
  7487. for (c = &cmd[4]; *c; c++)
  7488. *c = tolower(*c);
  7489. const char end[5] = ".gco";
  7490. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  7491. for (uint_least8_t i = 0; i < 8; i++) {
  7492. if (strcmp((cmd + i + 4), end) == 0) {
  7493. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  7494. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  7495. break;
  7496. }
  7497. else {
  7498. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  7499. }
  7500. }
  7501. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  7502. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  7503. for (uint_least8_t i = 0; i < depth; i++) {
  7504. for (uint_least8_t j = 0; j < 8; j++) {
  7505. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, card.dir_names[i][j]);
  7506. }
  7507. }
  7508. if (!check_file(filename)) {
  7509. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=3
  7510. lcd_update_enable(true);
  7511. }
  7512. if (result) {
  7513. enquecommand(cmd);
  7514. enquecommand_P(PSTR("M24"));
  7515. }
  7516. lcd_return_to_status();
  7517. }
  7518. void menu_action_sddirectory(const char* filename)
  7519. {
  7520. card.chdir(filename, true);
  7521. lcd_encoder = 0;
  7522. menu_data_reset(); //Forces reloading of cached variables.
  7523. }
  7524. /** LCD API **/
  7525. void ultralcd_init()
  7526. {
  7527. {
  7528. uint8_t autoDepleteRaw = eeprom_read_byte(reinterpret_cast<uint8_t*>(EEPROM_AUTO_DEPLETE));
  7529. if (0xff == autoDepleteRaw) lcd_autoDeplete = false;
  7530. else lcd_autoDeplete = autoDepleteRaw;
  7531. }
  7532. backlight_init();
  7533. lcd_init();
  7534. lcd_refresh();
  7535. lcd_longpress_func = menu_lcd_longpress_func;
  7536. lcd_charsetup_func = menu_lcd_charsetup_func;
  7537. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  7538. menu_menu = lcd_status_screen;
  7539. menu_lcd_charsetup_func();
  7540. SET_INPUT(BTN_EN1);
  7541. SET_INPUT(BTN_EN2);
  7542. WRITE(BTN_EN1, HIGH);
  7543. WRITE(BTN_EN2, HIGH);
  7544. #if BTN_ENC > 0
  7545. SET_INPUT(BTN_ENC);
  7546. WRITE(BTN_ENC, HIGH);
  7547. #endif
  7548. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  7549. pinMode(SDCARDDETECT, INPUT);
  7550. WRITE(SDCARDDETECT, HIGH);
  7551. lcd_oldcardstatus = IS_SD_INSERTED;
  7552. #endif//(SDCARDDETECT > 0)
  7553. lcd_encoder_diff = 0;
  7554. }
  7555. void lcd_printer_connected() {
  7556. printer_connected = true;
  7557. }
  7558. static void lcd_send_status() {
  7559. if (farm_mode && no_response && ((_millis() - NcTime) > (NC_TIME * 1000))) {
  7560. //send important status messages periodicaly
  7561. prusa_statistics(important_status, saved_filament_type);
  7562. NcTime = _millis();
  7563. #ifdef FARM_CONNECT_MESSAGE
  7564. lcd_connect_printer();
  7565. #endif //FARM_CONNECT_MESSAGE
  7566. }
  7567. }
  7568. #ifdef FARM_CONNECT_MESSAGE
  7569. static void lcd_connect_printer() {
  7570. lcd_update_enable(false);
  7571. lcd_clear();
  7572. int i = 0;
  7573. int t = 0;
  7574. lcd_puts_at_P(0, 0, _i("Connect printer to"));
  7575. lcd_puts_at_P(0, 1, _i("monitoring or hold"));
  7576. lcd_puts_at_P(0, 2, _i("the knob to continue"));
  7577. while (no_response) {
  7578. i++;
  7579. t++;
  7580. delay_keep_alive(100);
  7581. proc_commands();
  7582. if (t == 10) {
  7583. prusa_statistics(important_status, saved_filament_type);
  7584. t = 0;
  7585. }
  7586. if (READ(BTN_ENC)) { //if button is not pressed
  7587. i = 0;
  7588. lcd_puts_at_P(0, 3, PSTR(" "));
  7589. }
  7590. if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\xFF");
  7591. if (i == NC_BUTTON_LONG_PRESS * 10) {
  7592. no_response = false;
  7593. }
  7594. }
  7595. lcd_update_enable(true);
  7596. lcd_update(2);
  7597. }
  7598. #endif //FARM_CONNECT_MESSAGE
  7599. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  7600. if (farm_mode) {
  7601. bool empty = is_buffer_empty();
  7602. if ((_millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  7603. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  7604. //therefore longer period is used
  7605. printer_connected = false;
  7606. }
  7607. else {
  7608. lcd_printer_connected();
  7609. }
  7610. }
  7611. }
  7612. void lcd_ignore_click(bool b)
  7613. {
  7614. ignore_click = b;
  7615. wait_for_unclick = false;
  7616. }
  7617. void lcd_finishstatus() {
  7618. SERIAL_PROTOCOLLNRPGM(MSG_LCD_STATUS_CHANGED);
  7619. int len = strlen(lcd_status_message);
  7620. if (len > 0) {
  7621. while (len < LCD_WIDTH) {
  7622. lcd_status_message[len++] = ' ';
  7623. }
  7624. }
  7625. lcd_status_message[LCD_WIDTH] = '\0';
  7626. lcd_draw_update = 2;
  7627. }
  7628. void lcd_setstatus(const char* message)
  7629. {
  7630. if (lcd_status_message_level > 0)
  7631. return;
  7632. lcd_updatestatus(message);
  7633. }
  7634. void lcd_updatestatuspgm(const char *message){
  7635. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  7636. lcd_status_message[LCD_WIDTH] = 0;
  7637. lcd_finishstatus();
  7638. // hack lcd_draw_update to 1, i.e. without clear
  7639. lcd_draw_update = 1;
  7640. }
  7641. void lcd_setstatuspgm(const char* message)
  7642. {
  7643. if (lcd_status_message_level > 0)
  7644. return;
  7645. lcd_updatestatuspgm(message);
  7646. }
  7647. void lcd_updatestatus(const char *message){
  7648. strncpy(lcd_status_message, message, LCD_WIDTH);
  7649. lcd_status_message[LCD_WIDTH] = 0;
  7650. lcd_finishstatus();
  7651. // hack lcd_draw_update to 1, i.e. without clear
  7652. lcd_draw_update = 1;
  7653. }
  7654. void lcd_setalertstatuspgm(const char* message)
  7655. {
  7656. lcd_setstatuspgm(message);
  7657. lcd_status_message_level = 1;
  7658. lcd_return_to_status();
  7659. }
  7660. void lcd_setalertstatus(const char* message)
  7661. {
  7662. lcd_setstatus(message);
  7663. lcd_status_message_level = 1;
  7664. lcd_return_to_status();
  7665. }
  7666. void lcd_reset_alert_level()
  7667. {
  7668. lcd_status_message_level = 0;
  7669. }
  7670. uint8_t get_message_level()
  7671. {
  7672. return lcd_status_message_level;
  7673. }
  7674. void menu_lcd_longpress_func(void)
  7675. {
  7676. backlight_wake();
  7677. if (homing_flag || mesh_bed_leveling_flag || menu_menu == lcd_babystep_z || menu_menu == lcd_move_z)
  7678. {
  7679. // disable longpress during re-entry, while homing or calibration
  7680. lcd_quick_feedback();
  7681. return;
  7682. }
  7683. if (menu_menu == lcd_hw_setup_menu)
  7684. {
  7685. // only toggle the experimental menu visibility flag
  7686. lcd_quick_feedback();
  7687. lcd_experimental_toggle();
  7688. return;
  7689. }
  7690. // explicitely listed menus which are allowed to rise the move-z or live-adj-z functions
  7691. // The lists are not the same for both functions, so first decide which function is to be performed
  7692. if ( (moves_planned() || IS_SD_PRINTING || is_usb_printing )){ // long press as live-adj-z
  7693. if(( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height
  7694. && ( menu_menu == lcd_status_screen // and in listed menus...
  7695. || menu_menu == lcd_main_menu
  7696. || menu_menu == lcd_tune_menu
  7697. || menu_menu == lcd_support_menu
  7698. )
  7699. ){
  7700. lcd_clear();
  7701. menu_submenu(lcd_babystep_z);
  7702. } else {
  7703. // otherwise consume the long press as normal click
  7704. if( menu_menu != lcd_status_screen )
  7705. menu_back();
  7706. }
  7707. } else { // long press as move-z
  7708. if(menu_menu == lcd_status_screen
  7709. || menu_menu == lcd_main_menu
  7710. || menu_menu == lcd_preheat_menu
  7711. || menu_menu == lcd_sdcard_menu
  7712. || menu_menu == lcd_settings_menu
  7713. || menu_menu == lcd_control_temperature_menu
  7714. #if (LANG_MODE != 0)
  7715. || menu_menu == lcd_language
  7716. #endif
  7717. || menu_menu == lcd_support_menu
  7718. ){
  7719. move_menu_scale = 1.0;
  7720. menu_submenu(lcd_move_z);
  7721. } else {
  7722. // otherwise consume the long press as normal click
  7723. if( menu_menu != lcd_status_screen )
  7724. menu_back();
  7725. }
  7726. }
  7727. }
  7728. void menu_lcd_charsetup_func(void)
  7729. {
  7730. if (menu_menu == lcd_status_screen)
  7731. lcd_set_custom_characters_degree();
  7732. else
  7733. lcd_set_custom_characters_arrows();
  7734. }
  7735. static inline bool z_menu_expired()
  7736. {
  7737. return (menu_menu == lcd_babystep_z
  7738. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  7739. }
  7740. static inline bool other_menu_expired()
  7741. {
  7742. return (menu_menu != lcd_status_screen
  7743. && menu_menu != lcd_babystep_z
  7744. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  7745. }
  7746. static inline bool forced_menu_expire()
  7747. {
  7748. bool retval = (menu_menu != lcd_status_screen
  7749. && forceMenuExpire);
  7750. forceMenuExpire = false;
  7751. return retval;
  7752. }
  7753. void menu_lcd_lcdupdate_func(void)
  7754. {
  7755. #if (SDCARDDETECT > 0)
  7756. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  7757. {
  7758. lcd_draw_update = 2;
  7759. lcd_oldcardstatus = IS_SD_INSERTED;
  7760. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  7761. backlight_wake();
  7762. if (lcd_oldcardstatus)
  7763. {
  7764. card.initsd();
  7765. LCD_MESSAGERPGM(_T(WELCOME_MSG));
  7766. bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  7767. menu_submenu(lcd_sdcard_menu);
  7768. //get_description();
  7769. }
  7770. else
  7771. {
  7772. if(menu_menu==lcd_sdcard_menu)
  7773. menu_back();
  7774. card.release();
  7775. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED
  7776. }
  7777. }
  7778. #endif//CARDINSERTED
  7779. backlight_update();
  7780. if (lcd_next_update_millis < _millis())
  7781. {
  7782. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  7783. {
  7784. if (lcd_draw_update == 0)
  7785. lcd_draw_update = 1;
  7786. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  7787. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  7788. lcd_encoder_diff = 0;
  7789. lcd_timeoutToStatus.start();
  7790. backlight_wake();
  7791. }
  7792. if (LCD_CLICKED)
  7793. {
  7794. lcd_timeoutToStatus.start();
  7795. backlight_wake();
  7796. }
  7797. (*menu_menu)();
  7798. if (z_menu_expired() || other_menu_expired() || forced_menu_expire())
  7799. {
  7800. // Exiting a menu. Let's call the menu function the last time with menu_leaving flag set to true
  7801. // to give it a chance to save its state.
  7802. // This is useful for example, when the babystep value has to be written into EEPROM.
  7803. if (menu_menu != NULL)
  7804. {
  7805. menu_leaving = 1;
  7806. (*menu_menu)();
  7807. menu_leaving = 0;
  7808. }
  7809. lcd_clear();
  7810. lcd_return_to_status();
  7811. lcd_draw_update = 2;
  7812. }
  7813. if (lcd_draw_update == 2) lcd_clear();
  7814. if (lcd_draw_update) lcd_draw_update--;
  7815. lcd_next_update_millis = _millis() + LCD_UPDATE_INTERVAL;
  7816. }
  7817. if (!SdFatUtil::test_stack_integrity()) stack_error();
  7818. lcd_ping(); //check that we have received ping command if we are in farm mode
  7819. lcd_send_status();
  7820. if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands();
  7821. }
  7822. #ifdef TMC2130
  7823. //! @brief Is crash detection enabled?
  7824. //!
  7825. //! @retval true crash detection enabled
  7826. //! @retval false crash detection disabled
  7827. bool lcd_crash_detect_enabled()
  7828. {
  7829. return eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET);
  7830. }
  7831. void lcd_crash_detect_enable()
  7832. {
  7833. tmc2130_sg_stop_on_crash = true;
  7834. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF);
  7835. }
  7836. void lcd_crash_detect_disable()
  7837. {
  7838. tmc2130_sg_stop_on_crash = false;
  7839. tmc2130_sg_crash = 0;
  7840. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00);
  7841. }
  7842. #endif
  7843. void lcd_experimental_toggle()
  7844. {
  7845. uint8_t oldVal = eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  7846. if (oldVal == EEPROM_EMPTY_VALUE)
  7847. oldVal = 0;
  7848. else
  7849. oldVal = !oldVal;
  7850. eeprom_update_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, oldVal);
  7851. }
  7852. void lcd_experimental_menu()
  7853. {
  7854. MENU_BEGIN();
  7855. MENU_ITEM_BACK_P(_T(MSG_BACK));
  7856. #ifdef EXTRUDER_ALTFAN_DETECT
  7857. MENU_ITEM_TOGGLE_P(_N("ALTFAN det."), altfanOverride_get()?_T(MSG_OFF):_T(MSG_ON), altfanOverride_toggle);////MSG_MENU_ALTFAN c=18
  7858. #endif //EXTRUDER_ALTFAN_DETECT
  7859. MENU_END();
  7860. }
  7861. #ifdef PINDA_TEMP_COMP
  7862. void lcd_pinda_temp_compensation_toggle()
  7863. {
  7864. uint8_t pinda_temp_compensation = eeprom_read_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION);
  7865. if (pinda_temp_compensation == EEPROM_EMPTY_VALUE) // On MK2.5/S the EEPROM_EMPTY_VALUE will be set to 0 during eeprom_init.
  7866. pinda_temp_compensation = 1; // But for MK3/S it should be 1 so SuperPINDA is "active"
  7867. else
  7868. pinda_temp_compensation = !pinda_temp_compensation;
  7869. eeprom_update_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION, pinda_temp_compensation);
  7870. SERIAL_ECHOLNPGM("SuperPINDA:");
  7871. SERIAL_ECHOLN(pinda_temp_compensation);
  7872. }
  7873. #endif //PINDA_TEMP_COMP