ultralcd.cpp 221 KB

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