ultralcd.cpp 183 KB

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