ultralcd.cpp 210 KB

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