ultralcd.cpp 176 KB

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