ultralcd.cpp 176 KB

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