ultralcd.cpp 236 KB

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