ultralcd.cpp 241 KB

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