ultralcd.cpp 205 KB

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