ultralcd.cpp 155 KB

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