ultralcd.cpp 183 KB

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