ultralcd.cpp 225 KB

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