ultralcd.cpp 182 KB

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