ultralcd.cpp 200 KB

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