ultralcd.cpp 219 KB

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