ultralcd.cpp 237 KB

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