ultralcd.cpp 181 KB

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