ultralcd.cpp 194 KB

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