ultralcd.cpp 236 KB

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