ultralcd.cpp 184 KB

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