ultralcd.cpp 236 KB

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