ultralcd.cpp 222 KB

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