ultralcd.cpp 224 KB

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