ultralcd.cpp 236 KB

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