ultralcd.cpp 157 KB

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