ultralcd.cpp 239 KB

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