ultralcd.cpp 258 KB

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