ultralcd.cpp 263 KB

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