ultralcd.cpp 231 KB

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