ultralcd.cpp 200 KB

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