ultralcd.cpp 267 KB

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