ultralcd.cpp 189 KB

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