ultralcd.cpp 216 KB

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