ultralcd.cpp 262 KB

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