ultralcd.cpp 233 KB

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