ultralcd.cpp 200 KB

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