ultralcd.cpp 230 KB

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