ultralcd.cpp 199 KB

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