ultralcd.cpp 231 KB

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