ultralcd.cpp 220 KB

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