ultralcd.cpp 181 KB

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