ultralcd.cpp 155 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992
  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. cli();
  2105. tmc2130_mode = SilentModeMenu?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  2106. tmc2130_init();
  2107. sei();
  2108. #endif //TMC2130
  2109. digipot_init();
  2110. lcd_goto_menu(lcd_settings_menu, 7);
  2111. }
  2112. static void lcd_crash_mode_set()
  2113. {
  2114. CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable()
  2115. if (CrashDetectMenu==0) {
  2116. crashdet_disable();
  2117. }else{
  2118. crashdet_enable();
  2119. }
  2120. lcd_goto_menu(lcd_settings_menu, 7);
  2121. }
  2122. static void lcd_set_lang(unsigned char lang) {
  2123. lang_selected = lang;
  2124. firstrun = 1;
  2125. eeprom_update_byte((unsigned char *)EEPROM_LANG, lang);
  2126. /*langsel=0;*/
  2127. if (langsel == LANGSEL_MODAL)
  2128. // From modal mode to an active mode? This forces the menu to return to the setup menu.
  2129. langsel = LANGSEL_ACTIVE;
  2130. }
  2131. static void lcd_fsensor_state_set()
  2132. {
  2133. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  2134. if (FSensorStateMenu==0) {
  2135. fsensor_disable();
  2136. }else{
  2137. fsensor_enable();
  2138. }
  2139. lcd_goto_menu(lcd_settings_menu, 7);
  2140. }
  2141. void lcd_force_language_selection() {
  2142. eeprom_update_byte((unsigned char *)EEPROM_LANG, LANG_ID_FORCE_SELECTION);
  2143. }
  2144. static void lcd_language_menu()
  2145. {
  2146. START_MENU();
  2147. if (langsel == LANGSEL_OFF) {
  2148. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  2149. } else if (langsel == LANGSEL_ACTIVE) {
  2150. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  2151. }
  2152. for (int i=0;i<LANG_NUM;i++){
  2153. MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(i), i);
  2154. }
  2155. END_MENU();
  2156. }
  2157. void lcd_mesh_bedleveling()
  2158. {
  2159. mesh_bed_run_from_menu = true;
  2160. enquecommand_P(PSTR("G80"));
  2161. lcd_return_to_status();
  2162. }
  2163. void lcd_mesh_calibration()
  2164. {
  2165. enquecommand_P(PSTR("M45"));
  2166. lcd_return_to_status();
  2167. }
  2168. void lcd_mesh_calibration_z()
  2169. {
  2170. enquecommand_P(PSTR("M45 Z"));
  2171. lcd_return_to_status();
  2172. }
  2173. void lcd_pinda_calibration_menu()
  2174. {
  2175. START_MENU();
  2176. MENU_ITEM(back, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  2177. MENU_ITEM(submenu, MSG_CALIBRATE_PINDA, lcd_calibrate_pinda);
  2178. if (temp_cal_active == false) {
  2179. MENU_ITEM(function, MSG_TEMP_CALIBRATION_OFF, lcd_temp_calibration_set);
  2180. }
  2181. else {
  2182. MENU_ITEM(function, MSG_TEMP_CALIBRATION_ON, lcd_temp_calibration_set);
  2183. }
  2184. END_MENU();
  2185. }
  2186. void lcd_temp_calibration_set() {
  2187. temp_cal_active = !temp_cal_active;
  2188. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  2189. digipot_init();
  2190. lcd_goto_menu(lcd_pinda_calibration_menu, 2);
  2191. }
  2192. void lcd_calibrate_pinda() {
  2193. enquecommand_P(PSTR("G76"));
  2194. lcd_return_to_status();
  2195. }
  2196. #ifndef SNMM
  2197. /*void lcd_calibrate_extruder() {
  2198. if (degHotend0() > EXTRUDE_MINTEMP)
  2199. {
  2200. current_position[E_AXIS] = 0; //set initial position to zero
  2201. plan_set_e_position(current_position[E_AXIS]);
  2202. //long steps_start = st_get_position(E_AXIS);
  2203. long steps_final;
  2204. float e_steps_per_unit;
  2205. 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)
  2206. 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
  2207. const char *msg_e_cal_knob = MSG_E_CAL_KNOB;
  2208. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  2209. const bool multi_screen = msg_next_e_cal_knob != NULL;
  2210. unsigned long msg_millis;
  2211. lcd_show_fullscreen_message_and_wait_P(MSG_MARK_FIL);
  2212. lcd_implementation_clear();
  2213. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  2214. current_position[E_AXIS] += e_shift_calibration;
  2215. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  2216. st_synchronize();
  2217. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  2218. msg_millis = millis();
  2219. while (!LCD_CLICKED) {
  2220. if (multi_screen && millis() - msg_millis > 5000) {
  2221. if (msg_next_e_cal_knob == NULL)
  2222. msg_next_e_cal_knob = msg_e_cal_knob;
  2223. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  2224. msg_millis = millis();
  2225. }
  2226. //manage_inactivity(true);
  2227. manage_heater();
  2228. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  2229. delay_keep_alive(50);
  2230. //previous_millis_cmd = millis();
  2231. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  2232. encoderDiff = 0;
  2233. if (!planner_queue_full()) {
  2234. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.01; //0.05
  2235. encoderPosition = 0;
  2236. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  2237. }
  2238. }
  2239. }
  2240. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  2241. //steps_final = st_get_position(E_AXIS);
  2242. lcdDrawUpdate = 1;
  2243. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  2244. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  2245. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  2246. lcd_implementation_clear();
  2247. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  2248. enquecommand_P(PSTR("M500")); //store settings to eeprom
  2249. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  2250. //delay_keep_alive(2000);
  2251. delay_keep_alive(500);
  2252. lcd_show_fullscreen_message_and_wait_P(MSG_CLEAN_NOZZLE_E);
  2253. lcd_update_enable(true);
  2254. lcdDrawUpdate = 2;
  2255. }
  2256. else
  2257. {
  2258. lcd_implementation_clear();
  2259. lcd.setCursor(0, 0);
  2260. lcd_printPGM(MSG_ERROR);
  2261. lcd.setCursor(0, 2);
  2262. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2263. delay(2000);
  2264. lcd_implementation_clear();
  2265. }
  2266. lcd_return_to_status();
  2267. }
  2268. void lcd_extr_cal_reset() {
  2269. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  2270. axis_steps_per_unit[E_AXIS] = tmp1[3];
  2271. //extrudemultiply = 100;
  2272. enquecommand_P(PSTR("M500"));
  2273. }*/
  2274. #endif
  2275. void lcd_toshiba_flash_air_compatibility_toggle()
  2276. {
  2277. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  2278. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  2279. }
  2280. static void lcd_crash_menu()
  2281. {
  2282. }
  2283. static void lcd_settings_menu()
  2284. {
  2285. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  2286. START_MENU();
  2287. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2288. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  2289. if (!homing_flag)
  2290. {
  2291. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  2292. }
  2293. if (!isPrintPaused)
  2294. {
  2295. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  2296. }
  2297. if (FSensorStateMenu == 0) {
  2298. MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set);
  2299. } else {
  2300. MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
  2301. }
  2302. if (SilentModeMenu == 0) {
  2303. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  2304. } else {
  2305. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  2306. }
  2307. if (SilentModeMenu == 0) {
  2308. if (CrashDetectMenu == 0) {
  2309. MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
  2310. } else {
  2311. MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
  2312. }
  2313. }
  2314. if (!isPrintPaused && !homing_flag)
  2315. {
  2316. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  2317. }
  2318. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  2319. if (card.ToshibaFlashAir_isEnabled()) {
  2320. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON, lcd_toshiba_flash_air_compatibility_toggle);
  2321. } else {
  2322. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF, lcd_toshiba_flash_air_compatibility_toggle);
  2323. }
  2324. if (farm_mode)
  2325. {
  2326. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  2327. MENU_ITEM(function, PSTR("Disable farm mode"), lcd_disable_farm_mode);
  2328. }
  2329. END_MENU();
  2330. }
  2331. static void lcd_calibration_menu()
  2332. {
  2333. START_MENU();
  2334. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2335. if (!isPrintPaused)
  2336. {
  2337. MENU_ITEM(function, MSG_SELFTEST, lcd_selftest);
  2338. #ifdef MK1BP
  2339. // MK1
  2340. // "Calibrate Z"
  2341. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  2342. #else //MK1BP
  2343. // MK2
  2344. MENU_ITEM(function, MSG_CALIBRATE_BED, lcd_mesh_calibration);
  2345. // "Calibrate Z" with storing the reference values to EEPROM.
  2346. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_calibration_z);
  2347. #ifndef SNMM
  2348. //MENU_ITEM(function, MSG_CALIBRATE_E, lcd_calibrate_extruder);
  2349. #endif
  2350. // "Mesh Bed Leveling"
  2351. MENU_ITEM(submenu, MSG_MESH_BED_LEVELING, lcd_mesh_bedleveling);
  2352. #endif //MK1BP
  2353. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28 W"));
  2354. MENU_ITEM(submenu, MSG_BED_CORRECTION_MENU, lcd_adjust_bed);
  2355. #ifndef MK1BP
  2356. MENU_ITEM(submenu, MSG_CALIBRATION_PINDA_MENU, lcd_pinda_calibration_menu);
  2357. #endif //MK1BP
  2358. MENU_ITEM(submenu, MSG_PID_EXTRUDER, pid_extruder);
  2359. MENU_ITEM(submenu, MSG_SHOW_END_STOPS, menu_show_end_stops);
  2360. #ifndef MK1BP
  2361. MENU_ITEM(gcode, MSG_CALIBRATE_BED_RESET, PSTR("M44"));
  2362. #endif //MK1BP
  2363. #ifndef SNMM
  2364. //MENU_ITEM(function, MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  2365. #endif
  2366. }
  2367. END_MENU();
  2368. }
  2369. /*
  2370. void lcd_mylang_top(int hlaska) {
  2371. lcd.setCursor(0,0);
  2372. lcd.print(" ");
  2373. lcd.setCursor(0,0);
  2374. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  2375. }
  2376. void lcd_mylang_drawmenu(int cursor) {
  2377. int first = 0;
  2378. if (cursor>2) first = cursor-2;
  2379. if (cursor==LANG_NUM) first = LANG_NUM-3;
  2380. lcd.setCursor(0, 1);
  2381. lcd.print(" ");
  2382. lcd.setCursor(1, 1);
  2383. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  2384. lcd.setCursor(0, 2);
  2385. lcd.print(" ");
  2386. lcd.setCursor(1, 2);
  2387. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  2388. lcd.setCursor(0, 3);
  2389. lcd.print(" ");
  2390. lcd.setCursor(1, 3);
  2391. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  2392. if (cursor==1) lcd.setCursor(0, 1);
  2393. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  2394. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  2395. lcd.print(">");
  2396. if (cursor<LANG_NUM-1) {
  2397. lcd.setCursor(19,3);
  2398. lcd.print("\x01");
  2399. }
  2400. if (cursor>2) {
  2401. lcd.setCursor(19,1);
  2402. lcd.print("^");
  2403. }
  2404. }
  2405. */
  2406. void lcd_mylang_drawmenu(int cursor) {
  2407. int first = 0;
  2408. if (cursor>3) first = cursor-3;
  2409. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  2410. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  2411. lcd.setCursor(0, 0);
  2412. lcd.print(" ");
  2413. lcd.setCursor(1, 0);
  2414. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
  2415. lcd.setCursor(0, 1);
  2416. lcd.print(" ");
  2417. lcd.setCursor(1, 1);
  2418. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
  2419. lcd.setCursor(0, 2);
  2420. lcd.print(" ");
  2421. if (LANG_NUM > 2){
  2422. lcd.setCursor(1, 2);
  2423. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
  2424. }
  2425. lcd.setCursor(0, 3);
  2426. lcd.print(" ");
  2427. if (LANG_NUM>3) {
  2428. lcd.setCursor(1, 3);
  2429. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
  2430. }
  2431. if (cursor==1) lcd.setCursor(0, 0);
  2432. if (cursor==2) lcd.setCursor(0, 1);
  2433. if (cursor>2) lcd.setCursor(0, 2);
  2434. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  2435. lcd.print(">");
  2436. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  2437. lcd.setCursor(19,3);
  2438. lcd.print("\x01");
  2439. }
  2440. if (cursor>3 && LANG_NUM>4) {
  2441. lcd.setCursor(19,0);
  2442. lcd.print("^");
  2443. }
  2444. }
  2445. void lcd_mylang_drawcursor(int cursor) {
  2446. if (cursor==1) lcd.setCursor(0, 1);
  2447. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  2448. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  2449. lcd.print(">");
  2450. }
  2451. void lcd_mylang() {
  2452. int enc_dif = 0;
  2453. int cursor_pos = 1;
  2454. lang_selected=255;
  2455. int hlaska=1;
  2456. int counter=0;
  2457. lcd_set_custom_characters_arrows();
  2458. lcd_implementation_clear();
  2459. //lcd_mylang_top(hlaska);
  2460. lcd_mylang_drawmenu(cursor_pos);
  2461. enc_dif = encoderDiff;
  2462. while ( (lang_selected == 255) ) {
  2463. manage_heater();
  2464. manage_inactivity(true);
  2465. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2466. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2467. if (enc_dif > encoderDiff ) {
  2468. cursor_pos --;
  2469. }
  2470. if (enc_dif < encoderDiff ) {
  2471. cursor_pos ++;
  2472. }
  2473. if (cursor_pos > LANG_NUM) {
  2474. cursor_pos = LANG_NUM;
  2475. }
  2476. if (cursor_pos < 1) {
  2477. cursor_pos = 1;
  2478. }
  2479. lcd_mylang_drawmenu(cursor_pos);
  2480. enc_dif = encoderDiff;
  2481. delay(100);
  2482. //}
  2483. } else delay(20);
  2484. if (lcd_clicked()) {
  2485. lcd_set_lang(cursor_pos-1);
  2486. delay(500);
  2487. }
  2488. /*
  2489. if (++counter == 80) {
  2490. hlaska++;
  2491. if(hlaska>LANG_NUM) hlaska=1;
  2492. lcd_mylang_top(hlaska);
  2493. lcd_mylang_drawcursor(cursor_pos);
  2494. counter=0;
  2495. }
  2496. */
  2497. };
  2498. if(MYSERIAL.available() > 1){
  2499. lang_selected = 0;
  2500. firstrun = 0;
  2501. }
  2502. lcd_set_custom_characters_degree();
  2503. lcd_implementation_clear();
  2504. lcd_return_to_status();
  2505. }
  2506. void bowden_menu() {
  2507. int enc_dif = encoderDiff;
  2508. int cursor_pos = 0;
  2509. lcd_implementation_clear();
  2510. lcd.setCursor(0, 0);
  2511. lcd.print(">");
  2512. for (int i = 0; i < 4; i++) {
  2513. lcd.setCursor(1, i);
  2514. lcd.print("Extruder ");
  2515. lcd.print(i);
  2516. lcd.print(": ");
  2517. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  2518. lcd.print(bowden_length[i] - 48);
  2519. }
  2520. enc_dif = encoderDiff;
  2521. while (1) {
  2522. manage_heater();
  2523. manage_inactivity(true);
  2524. if (abs((enc_dif - encoderDiff)) > 2) {
  2525. if (enc_dif > encoderDiff) {
  2526. cursor_pos--;
  2527. }
  2528. if (enc_dif < encoderDiff) {
  2529. cursor_pos++;
  2530. }
  2531. if (cursor_pos > 3) {
  2532. cursor_pos = 3;
  2533. }
  2534. if (cursor_pos < 0) {
  2535. cursor_pos = 0;
  2536. }
  2537. lcd.setCursor(0, 0);
  2538. lcd.print(" ");
  2539. lcd.setCursor(0, 1);
  2540. lcd.print(" ");
  2541. lcd.setCursor(0, 2);
  2542. lcd.print(" ");
  2543. lcd.setCursor(0, 3);
  2544. lcd.print(" ");
  2545. lcd.setCursor(0, cursor_pos);
  2546. lcd.print(">");
  2547. enc_dif = encoderDiff;
  2548. delay(100);
  2549. }
  2550. if (lcd_clicked()) {
  2551. while (lcd_clicked());
  2552. delay(10);
  2553. while (lcd_clicked());
  2554. lcd_implementation_clear();
  2555. while (1) {
  2556. manage_heater();
  2557. manage_inactivity(true);
  2558. lcd.setCursor(1, 1);
  2559. lcd.print("Extruder ");
  2560. lcd.print(cursor_pos);
  2561. lcd.print(": ");
  2562. lcd.setCursor(13, 1);
  2563. lcd.print(bowden_length[cursor_pos] - 48);
  2564. if (abs((enc_dif - encoderDiff)) > 2) {
  2565. if (enc_dif > encoderDiff) {
  2566. bowden_length[cursor_pos]--;
  2567. lcd.setCursor(13, 1);
  2568. lcd.print(bowden_length[cursor_pos] - 48);
  2569. enc_dif = encoderDiff;
  2570. }
  2571. if (enc_dif < encoderDiff) {
  2572. bowden_length[cursor_pos]++;
  2573. lcd.setCursor(13, 1);
  2574. lcd.print(bowden_length[cursor_pos] - 48);
  2575. enc_dif = encoderDiff;
  2576. }
  2577. }
  2578. delay(100);
  2579. if (lcd_clicked()) {
  2580. while (lcd_clicked());
  2581. delay(10);
  2582. while (lcd_clicked());
  2583. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  2584. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  2585. lcd_update_enable(true);
  2586. lcd_implementation_clear();
  2587. enc_dif = encoderDiff;
  2588. lcd.setCursor(0, cursor_pos);
  2589. lcd.print(">");
  2590. for (int i = 0; i < 4; i++) {
  2591. lcd.setCursor(1, i);
  2592. lcd.print("Extruder ");
  2593. lcd.print(i);
  2594. lcd.print(": ");
  2595. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  2596. lcd.print(bowden_length[i] - 48);
  2597. }
  2598. break;
  2599. }
  2600. else return;
  2601. }
  2602. }
  2603. }
  2604. }
  2605. }
  2606. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  2607. lcd_implementation_clear();
  2608. lcd_print_at_PGM(0,0,MSG_UNLOAD_FILAMENT); lcd.print(":");
  2609. lcd.setCursor(0, 1); lcd.print(">");
  2610. lcd_print_at_PGM(1,1,MSG_ALL);
  2611. lcd_print_at_PGM(1,2,MSG_USED);
  2612. lcd_print_at_PGM(1,3,MSG_CURRENT);
  2613. char cursor_pos = 1;
  2614. int enc_dif = 0;
  2615. while (1) {
  2616. manage_heater();
  2617. manage_inactivity(true);
  2618. if (abs((enc_dif - encoderDiff)) > 4) {
  2619. if ((abs(enc_dif - encoderDiff)) > 1) {
  2620. if (enc_dif > encoderDiff) cursor_pos--;
  2621. if (enc_dif < encoderDiff) cursor_pos++;
  2622. if (cursor_pos > 3) cursor_pos = 3;
  2623. if (cursor_pos < 1) cursor_pos = 1;
  2624. lcd.setCursor(0, 1);
  2625. lcd.print(" ");
  2626. lcd.setCursor(0, 2);
  2627. lcd.print(" ");
  2628. lcd.setCursor(0, 3);
  2629. lcd.print(" ");
  2630. lcd.setCursor(0, cursor_pos);
  2631. lcd.print(">");
  2632. enc_dif = encoderDiff;
  2633. delay(100);
  2634. }
  2635. }
  2636. if (lcd_clicked()) {
  2637. while (lcd_clicked());
  2638. delay(10);
  2639. while (lcd_clicked());
  2640. return(cursor_pos - 1);
  2641. }
  2642. }
  2643. }
  2644. char choose_extruder_menu() {
  2645. int items_no = 4;
  2646. int first = 0;
  2647. int enc_dif = 0;
  2648. char cursor_pos = 1;
  2649. enc_dif = encoderDiff;
  2650. lcd_implementation_clear();
  2651. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  2652. lcd.setCursor(0, 1);
  2653. lcd.print(">");
  2654. for (int i = 0; i < 3; i++) {
  2655. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  2656. }
  2657. while (1) {
  2658. for (int i = 0; i < 3; i++) {
  2659. lcd.setCursor(2 + strlen_P(MSG_EXTRUDER), i+1);
  2660. lcd.print(first + i + 1);
  2661. }
  2662. manage_heater();
  2663. manage_inactivity(true);
  2664. if (abs((enc_dif - encoderDiff)) > 4) {
  2665. if ((abs(enc_dif - encoderDiff)) > 1) {
  2666. if (enc_dif > encoderDiff) {
  2667. cursor_pos--;
  2668. }
  2669. if (enc_dif < encoderDiff) {
  2670. cursor_pos++;
  2671. }
  2672. if (cursor_pos > 3) {
  2673. cursor_pos = 3;
  2674. if (first < items_no - 3) {
  2675. first++;
  2676. lcd_implementation_clear();
  2677. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  2678. for (int i = 0; i < 3; i++) {
  2679. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  2680. }
  2681. }
  2682. }
  2683. if (cursor_pos < 1) {
  2684. cursor_pos = 1;
  2685. if (first > 0) {
  2686. first--;
  2687. lcd_implementation_clear();
  2688. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  2689. for (int i = 0; i < 3; i++) {
  2690. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  2691. }
  2692. }
  2693. }
  2694. lcd.setCursor(0, 1);
  2695. lcd.print(" ");
  2696. lcd.setCursor(0, 2);
  2697. lcd.print(" ");
  2698. lcd.setCursor(0, 3);
  2699. lcd.print(" ");
  2700. lcd.setCursor(0, cursor_pos);
  2701. lcd.print(">");
  2702. enc_dif = encoderDiff;
  2703. delay(100);
  2704. }
  2705. }
  2706. if (lcd_clicked()) {
  2707. lcd_update(2);
  2708. while (lcd_clicked());
  2709. delay(10);
  2710. while (lcd_clicked());
  2711. return(cursor_pos + first - 1);
  2712. }
  2713. }
  2714. }
  2715. char reset_menu() {
  2716. #ifdef SNMM
  2717. int items_no = 5;
  2718. #else
  2719. int items_no = 4;
  2720. #endif
  2721. static int first = 0;
  2722. int enc_dif = 0;
  2723. char cursor_pos = 0;
  2724. const char *item [items_no];
  2725. item[0] = "Language";
  2726. item[1] = "Statistics";
  2727. item[2] = "Shipping prep";
  2728. item[3] = "All Data";
  2729. #ifdef SNMM
  2730. item[4] = "Bowden length";
  2731. #endif // SNMM
  2732. enc_dif = encoderDiff;
  2733. lcd_implementation_clear();
  2734. lcd.setCursor(0, 0);
  2735. lcd.print(">");
  2736. while (1) {
  2737. for (int i = 0; i < 4; i++) {
  2738. lcd.setCursor(1, i);
  2739. lcd.print(item[first + i]);
  2740. }
  2741. manage_heater();
  2742. manage_inactivity(true);
  2743. if (abs((enc_dif - encoderDiff)) > 4) {
  2744. if ((abs(enc_dif - encoderDiff)) > 1) {
  2745. if (enc_dif > encoderDiff) {
  2746. cursor_pos--;
  2747. }
  2748. if (enc_dif < encoderDiff) {
  2749. cursor_pos++;
  2750. }
  2751. if (cursor_pos > 3) {
  2752. cursor_pos = 3;
  2753. if (first < items_no - 4) {
  2754. first++;
  2755. lcd_implementation_clear();
  2756. }
  2757. }
  2758. if (cursor_pos < 0) {
  2759. cursor_pos = 0;
  2760. if (first > 0) {
  2761. first--;
  2762. lcd_implementation_clear();
  2763. }
  2764. }
  2765. lcd.setCursor(0, 0);
  2766. lcd.print(" ");
  2767. lcd.setCursor(0, 1);
  2768. lcd.print(" ");
  2769. lcd.setCursor(0, 2);
  2770. lcd.print(" ");
  2771. lcd.setCursor(0, 3);
  2772. lcd.print(" ");
  2773. lcd.setCursor(0, cursor_pos);
  2774. lcd.print(">");
  2775. enc_dif = encoderDiff;
  2776. delay(100);
  2777. }
  2778. }
  2779. if (lcd_clicked()) {
  2780. while (lcd_clicked());
  2781. delay(10);
  2782. while (lcd_clicked());
  2783. return(cursor_pos + first);
  2784. }
  2785. }
  2786. }
  2787. static void lcd_disable_farm_mode() {
  2788. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  2789. if (disable) {
  2790. enquecommand_P(PSTR("G99"));
  2791. lcd_return_to_status();
  2792. }
  2793. else {
  2794. lcd_goto_menu(lcd_settings_menu);
  2795. }
  2796. lcd_update_enable(true);
  2797. lcdDrawUpdate = 2;
  2798. }
  2799. static void lcd_ping_allert() {
  2800. if ((abs(millis() - allert_timer)*0.001) > PING_ALLERT_PERIOD) {
  2801. allert_timer = millis();
  2802. SET_OUTPUT(BEEPER);
  2803. for (int i = 0; i < 2; i++) {
  2804. WRITE(BEEPER, HIGH);
  2805. delay(50);
  2806. WRITE(BEEPER, LOW);
  2807. delay(100);
  2808. }
  2809. }
  2810. };
  2811. #ifdef SNMM
  2812. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  2813. set_extrude_min_temp(.0);
  2814. current_position[E_AXIS] += shift;
  2815. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  2816. set_extrude_min_temp(EXTRUDE_MINTEMP);
  2817. }
  2818. void change_extr(int extr) { //switches multiplexer for extruders
  2819. st_synchronize();
  2820. delay(100);
  2821. disable_e0();
  2822. disable_e1();
  2823. disable_e2();
  2824. #ifdef SNMM
  2825. snmm_extruder = extr;
  2826. #endif
  2827. pinMode(E_MUX0_PIN, OUTPUT);
  2828. pinMode(E_MUX1_PIN, OUTPUT);
  2829. pinMode(E_MUX2_PIN, OUTPUT);
  2830. switch (extr) {
  2831. case 1:
  2832. WRITE(E_MUX0_PIN, HIGH);
  2833. WRITE(E_MUX1_PIN, LOW);
  2834. WRITE(E_MUX2_PIN, LOW);
  2835. break;
  2836. case 2:
  2837. WRITE(E_MUX0_PIN, LOW);
  2838. WRITE(E_MUX1_PIN, HIGH);
  2839. WRITE(E_MUX2_PIN, LOW);
  2840. break;
  2841. case 3:
  2842. WRITE(E_MUX0_PIN, HIGH);
  2843. WRITE(E_MUX1_PIN, HIGH);
  2844. WRITE(E_MUX2_PIN, LOW);
  2845. break;
  2846. default:
  2847. WRITE(E_MUX0_PIN, LOW);
  2848. WRITE(E_MUX1_PIN, LOW);
  2849. WRITE(E_MUX2_PIN, LOW);
  2850. break;
  2851. }
  2852. delay(100);
  2853. }
  2854. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  2855. return(4 * READ(E_MUX2_PIN) + 2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  2856. }
  2857. void display_loading() {
  2858. switch (snmm_extruder) {
  2859. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  2860. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  2861. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  2862. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  2863. }
  2864. }
  2865. static void extr_adj(int extruder) //loading filament for SNMM
  2866. {
  2867. bool correct;
  2868. max_feedrate[E_AXIS] =80;
  2869. //max_feedrate[E_AXIS] = 50;
  2870. START:
  2871. lcd_implementation_clear();
  2872. lcd.setCursor(0, 0);
  2873. switch (extruder) {
  2874. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  2875. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  2876. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  2877. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  2878. }
  2879. do{
  2880. extr_mov(0.001,1000);
  2881. delay_keep_alive(2);
  2882. } while (!lcd_clicked());
  2883. //delay_keep_alive(500);
  2884. st_synchronize();
  2885. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  2886. //if (!correct) goto START;
  2887. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  2888. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  2889. extr_mov(bowden_length[extruder], 500);
  2890. lcd_implementation_clear();
  2891. lcd.setCursor(0, 0); lcd_printPGM(MSG_LOADING_FILAMENT);
  2892. if(strlen(MSG_LOADING_FILAMENT)>18) lcd.setCursor(0, 1);
  2893. else lcd.print(" ");
  2894. lcd.print(snmm_extruder + 1);
  2895. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  2896. st_synchronize();
  2897. max_feedrate[E_AXIS] = 50;
  2898. lcd_update_enable(true);
  2899. lcd_return_to_status();
  2900. lcdDrawUpdate = 2;
  2901. }
  2902. void extr_unload() { //unloads filament
  2903. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  2904. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  2905. int8_t SilentMode;
  2906. if (degHotend0() > EXTRUDE_MINTEMP) {
  2907. lcd_implementation_clear();
  2908. lcd_display_message_fullscreen_P(PSTR(""));
  2909. max_feedrate[E_AXIS] = 50;
  2910. lcd.setCursor(0, 0); lcd_printPGM(MSG_UNLOADING_FILAMENT);
  2911. lcd.print(" ");
  2912. lcd.print(snmm_extruder + 1);
  2913. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  2914. if (current_position[Z_AXIS] < 15) {
  2915. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  2916. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  2917. }
  2918. current_position[E_AXIS] += 10; //extrusion
  2919. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  2920. digipot_current(2, E_MOTOR_HIGH_CURRENT);
  2921. if (current_temperature[0] < 230) { //PLA & all other filaments
  2922. current_position[E_AXIS] += 5.4;
  2923. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  2924. current_position[E_AXIS] += 3.2;
  2925. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  2926. current_position[E_AXIS] += 3;
  2927. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  2928. }
  2929. else { //ABS
  2930. current_position[E_AXIS] += 3.1;
  2931. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  2932. current_position[E_AXIS] += 3.1;
  2933. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  2934. current_position[E_AXIS] += 4;
  2935. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  2936. /*current_position[X_AXIS] += 23; //delay
  2937. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  2938. current_position[X_AXIS] -= 23; //delay
  2939. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  2940. delay_keep_alive(4700);
  2941. }
  2942. max_feedrate[E_AXIS] = 80;
  2943. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  2944. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  2945. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  2946. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  2947. st_synchronize();
  2948. //digipot_init();
  2949. if (SilentMode == 1) digipot_current(2, tmp_motor[2]); //set back to normal operation currents
  2950. else digipot_current(2, tmp_motor_loud[2]);
  2951. lcd_update_enable(true);
  2952. lcd_return_to_status();
  2953. max_feedrate[E_AXIS] = 50;
  2954. }
  2955. else {
  2956. lcd_implementation_clear();
  2957. lcd.setCursor(0, 0);
  2958. lcd_printPGM(MSG_ERROR);
  2959. lcd.setCursor(0, 2);
  2960. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2961. delay(2000);
  2962. lcd_implementation_clear();
  2963. }
  2964. lcd_return_to_status();
  2965. }
  2966. //wrapper functions for loading filament
  2967. static void extr_adj_0(){
  2968. change_extr(0);
  2969. extr_adj(0);
  2970. }
  2971. static void extr_adj_1() {
  2972. change_extr(1);
  2973. extr_adj(1);
  2974. }
  2975. static void extr_adj_2() {
  2976. change_extr(2);
  2977. extr_adj(2);
  2978. }
  2979. static void extr_adj_3() {
  2980. change_extr(3);
  2981. extr_adj(3);
  2982. }
  2983. static void load_all() {
  2984. for (int i = 0; i < 4; i++) {
  2985. change_extr(i);
  2986. extr_adj(i);
  2987. }
  2988. }
  2989. //wrapper functions for changing extruders
  2990. static void extr_change_0() {
  2991. change_extr(0);
  2992. lcd_return_to_status();
  2993. }
  2994. static void extr_change_1() {
  2995. change_extr(1);
  2996. lcd_return_to_status();
  2997. }
  2998. static void extr_change_2() {
  2999. change_extr(2);
  3000. lcd_return_to_status();
  3001. }
  3002. static void extr_change_3() {
  3003. change_extr(3);
  3004. lcd_return_to_status();
  3005. }
  3006. //wrapper functions for unloading filament
  3007. void extr_unload_all() {
  3008. if (degHotend0() > EXTRUDE_MINTEMP) {
  3009. for (int i = 0; i < 4; i++) {
  3010. change_extr(i);
  3011. extr_unload();
  3012. }
  3013. }
  3014. else {
  3015. lcd_implementation_clear();
  3016. lcd.setCursor(0, 0);
  3017. lcd_printPGM(MSG_ERROR);
  3018. lcd.setCursor(0, 2);
  3019. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  3020. delay(2000);
  3021. lcd_implementation_clear();
  3022. lcd_return_to_status();
  3023. }
  3024. }
  3025. //unloading just used filament (for snmm)
  3026. void extr_unload_used() {
  3027. if (degHotend0() > EXTRUDE_MINTEMP) {
  3028. for (int i = 0; i < 4; i++) {
  3029. if (snmm_filaments_used & (1 << i)) {
  3030. change_extr(i);
  3031. extr_unload();
  3032. }
  3033. }
  3034. snmm_filaments_used = 0;
  3035. }
  3036. else {
  3037. lcd_implementation_clear();
  3038. lcd.setCursor(0, 0);
  3039. lcd_printPGM(MSG_ERROR);
  3040. lcd.setCursor(0, 2);
  3041. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  3042. delay(2000);
  3043. lcd_implementation_clear();
  3044. lcd_return_to_status();
  3045. }
  3046. }
  3047. static void extr_unload_0() {
  3048. change_extr(0);
  3049. extr_unload();
  3050. }
  3051. static void extr_unload_1() {
  3052. change_extr(1);
  3053. extr_unload();
  3054. }
  3055. static void extr_unload_2() {
  3056. change_extr(2);
  3057. extr_unload();
  3058. }
  3059. static void extr_unload_3() {
  3060. change_extr(3);
  3061. extr_unload();
  3062. }
  3063. static void fil_load_menu()
  3064. {
  3065. START_MENU();
  3066. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3067. MENU_ITEM(function, MSG_LOAD_ALL, load_all);
  3068. MENU_ITEM(function, MSG_LOAD_FILAMENT_1, extr_adj_0);
  3069. MENU_ITEM(function, MSG_LOAD_FILAMENT_2, extr_adj_1);
  3070. MENU_ITEM(function, MSG_LOAD_FILAMENT_3, extr_adj_2);
  3071. MENU_ITEM(function, MSG_LOAD_FILAMENT_4, extr_adj_3);
  3072. END_MENU();
  3073. }
  3074. static void fil_unload_menu()
  3075. {
  3076. START_MENU();
  3077. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3078. MENU_ITEM(function, MSG_UNLOAD_ALL, extr_unload_all);
  3079. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_1, extr_unload_0);
  3080. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_2, extr_unload_1);
  3081. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_3, extr_unload_2);
  3082. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_4, extr_unload_3);
  3083. END_MENU();
  3084. }
  3085. static void change_extr_menu(){
  3086. START_MENU();
  3087. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3088. MENU_ITEM(function, MSG_EXTRUDER_1, extr_change_0);
  3089. MENU_ITEM(function, MSG_EXTRUDER_2, extr_change_1);
  3090. MENU_ITEM(function, MSG_EXTRUDER_3, extr_change_2);
  3091. MENU_ITEM(function, MSG_EXTRUDER_4, extr_change_3);
  3092. END_MENU();
  3093. }
  3094. #endif
  3095. static void lcd_farm_no()
  3096. {
  3097. char step = 0;
  3098. int enc_dif = 0;
  3099. int _farmno = farm_no;
  3100. int _ret = 0;
  3101. lcd_implementation_clear();
  3102. lcd.setCursor(0, 0);
  3103. lcd.print("Farm no");
  3104. do
  3105. {
  3106. if (abs((enc_dif - encoderDiff)) > 2) {
  3107. if (enc_dif > encoderDiff) {
  3108. switch (step) {
  3109. case(0): if (_farmno >= 100) _farmno -= 100; break;
  3110. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  3111. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  3112. default: break;
  3113. }
  3114. }
  3115. if (enc_dif < encoderDiff) {
  3116. switch (step) {
  3117. case(0): if (_farmno < 900) _farmno += 100; break;
  3118. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  3119. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  3120. default: break;
  3121. }
  3122. }
  3123. enc_dif = 0;
  3124. encoderDiff = 0;
  3125. }
  3126. lcd.setCursor(0, 2);
  3127. if (_farmno < 100) lcd.print("0");
  3128. if (_farmno < 10) lcd.print("0");
  3129. lcd.print(_farmno);
  3130. lcd.print(" ");
  3131. lcd.setCursor(0, 3);
  3132. lcd.print(" ");
  3133. lcd.setCursor(step, 3);
  3134. lcd.print("^");
  3135. delay(100);
  3136. if (lcd_clicked())
  3137. {
  3138. delay(200);
  3139. step++;
  3140. if(step == 3) {
  3141. _ret = 1;
  3142. farm_no = _farmno;
  3143. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  3144. prusa_statistics(20);
  3145. lcd_return_to_status();
  3146. }
  3147. }
  3148. manage_heater();
  3149. } while (_ret == 0);
  3150. }
  3151. void lcd_confirm_print()
  3152. {
  3153. int enc_dif = 0;
  3154. int cursor_pos = 1;
  3155. int _ret = 0;
  3156. int _t = 0;
  3157. lcd_implementation_clear();
  3158. lcd.setCursor(0, 0);
  3159. lcd.print("Print ok ?");
  3160. do
  3161. {
  3162. if (abs((enc_dif - encoderDiff)) > 2) {
  3163. if (enc_dif > encoderDiff) {
  3164. cursor_pos--;
  3165. }
  3166. if (enc_dif < encoderDiff) {
  3167. cursor_pos++;
  3168. }
  3169. }
  3170. if (cursor_pos > 2) { cursor_pos = 2; }
  3171. if (cursor_pos < 1) { cursor_pos = 1; }
  3172. lcd.setCursor(0, 2); lcd.print(" ");
  3173. lcd.setCursor(0, 3); lcd.print(" ");
  3174. lcd.setCursor(2, 2);
  3175. lcd_printPGM(MSG_YES);
  3176. lcd.setCursor(2, 3);
  3177. lcd_printPGM(MSG_NO);
  3178. lcd.setCursor(0, 1 + cursor_pos);
  3179. lcd.print(">");
  3180. delay(100);
  3181. _t = _t + 1;
  3182. if (_t>100)
  3183. {
  3184. prusa_statistics(99);
  3185. _t = 0;
  3186. }
  3187. if (lcd_clicked())
  3188. {
  3189. if (cursor_pos == 1)
  3190. {
  3191. _ret = 1;
  3192. prusa_statistics(20);
  3193. prusa_statistics(4);
  3194. }
  3195. if (cursor_pos == 2)
  3196. {
  3197. _ret = 2;
  3198. prusa_statistics(20);
  3199. prusa_statistics(5);
  3200. }
  3201. }
  3202. manage_heater();
  3203. manage_inactivity();
  3204. } while (_ret == 0);
  3205. }
  3206. extern bool saved_printing;
  3207. static void lcd_main_menu()
  3208. {
  3209. SDscrool = 0;
  3210. START_MENU();
  3211. // Majkl superawesome menu
  3212. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  3213. #ifdef RESUME_DEBUG
  3214. if (!saved_printing)
  3215. MENU_ITEM(function, PSTR("tst - Save"), lcd_menu_test_save);
  3216. else
  3217. MENU_ITEM(function, PSTR("tst - Restore"), lcd_menu_test_restore);
  3218. #endif //RESUME_DEBUG
  3219. #ifdef TMC2130_DEBUG
  3220. MENU_ITEM(function, PSTR("recover print"), recover_print);
  3221. MENU_ITEM(function, PSTR("power panic"), uvlo_);
  3222. #endif //TMC2130_DEBUG
  3223. /* if (farm_mode && !IS_SD_PRINTING )
  3224. {
  3225. int tempScrool = 0;
  3226. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  3227. //delay(100);
  3228. return; // nothing to do (so don't thrash the SD card)
  3229. uint16_t fileCnt = card.getnrfilenames();
  3230. card.getWorkDirName();
  3231. if (card.filename[0] == '/')
  3232. {
  3233. #if SDCARDDETECT == -1
  3234. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  3235. #endif
  3236. } else {
  3237. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  3238. }
  3239. for (uint16_t i = 0; i < fileCnt; i++)
  3240. {
  3241. if (_menuItemNr == _lineNr)
  3242. {
  3243. #ifndef SDCARD_RATHERRECENTFIRST
  3244. card.getfilename(i);
  3245. #else
  3246. card.getfilename(fileCnt - 1 - i);
  3247. #endif
  3248. if (card.filenameIsDir)
  3249. {
  3250. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3251. } else {
  3252. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  3253. }
  3254. } else {
  3255. MENU_ITEM_DUMMY();
  3256. }
  3257. }
  3258. MENU_ITEM(back, PSTR("- - - - - - - - -"), lcd_status_screen);
  3259. }*/
  3260. if ( ( IS_SD_PRINTING || is_usb_printing ) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag)
  3261. {
  3262. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  3263. }
  3264. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing )
  3265. {
  3266. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  3267. } else
  3268. {
  3269. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  3270. }
  3271. #ifdef SDSUPPORT
  3272. if (card.cardOK)
  3273. {
  3274. if (card.isFileOpen())
  3275. {
  3276. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  3277. if (card.sdprinting)
  3278. {
  3279. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  3280. }
  3281. else
  3282. {
  3283. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  3284. }
  3285. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  3286. }
  3287. }
  3288. else
  3289. {
  3290. if (!is_usb_printing)
  3291. {
  3292. //if (farm_mode) MENU_ITEM(submenu, MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  3293. /*else*/ MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  3294. }
  3295. #if SDCARDDETECT < 1
  3296. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  3297. #endif
  3298. }
  3299. } else
  3300. {
  3301. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  3302. #if SDCARDDETECT < 1
  3303. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  3304. #endif
  3305. }
  3306. #endif
  3307. if (IS_SD_PRINTING || is_usb_printing)
  3308. {
  3309. if (farm_mode)
  3310. {
  3311. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  3312. }
  3313. }
  3314. else
  3315. {
  3316. #ifndef SNMM
  3317. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  3318. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  3319. #endif
  3320. #ifdef SNMM
  3321. MENU_ITEM(submenu, MSG_LOAD_FILAMENT, fil_load_menu);
  3322. MENU_ITEM(submenu, MSG_UNLOAD_FILAMENT, fil_unload_menu);
  3323. MENU_ITEM(submenu, MSG_CHANGE_EXTR, change_extr_menu);
  3324. #endif
  3325. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  3326. if(!isPrintPaused) MENU_ITEM(submenu, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  3327. }
  3328. if (!is_usb_printing)
  3329. {
  3330. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  3331. }
  3332. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  3333. END_MENU();
  3334. }
  3335. void stack_error() {
  3336. SET_OUTPUT(BEEPER);
  3337. WRITE(BEEPER, HIGH);
  3338. delay(1000);
  3339. WRITE(BEEPER, LOW);
  3340. lcd_display_message_fullscreen_P(MSG_STACK_ERROR);
  3341. //err_triggered = 1;
  3342. while (1) delay_keep_alive(1000);
  3343. }
  3344. #ifdef SDSUPPORT
  3345. static void lcd_autostart_sd()
  3346. {
  3347. card.lastnr = 0;
  3348. card.setroot();
  3349. card.checkautostart(true);
  3350. }
  3351. #endif
  3352. static void lcd_silent_mode_set_tune() {
  3353. SilentModeMenu = !SilentModeMenu;
  3354. eeprom_update_byte((unsigned char*)EEPROM_SILENT, SilentModeMenu);
  3355. #ifdef TMC2130
  3356. st_synchronize();
  3357. cli();
  3358. tmc2130_mode = SilentModeMenu?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3359. tmc2130_init();
  3360. sei();
  3361. #endif //TMC2130
  3362. digipot_init();
  3363. lcd_goto_menu(lcd_tune_menu, 9);
  3364. }
  3365. static void lcd_colorprint_change() {
  3366. enquecommand_P(PSTR("M600"));
  3367. custom_message = true;
  3368. custom_message_type = 2; //just print status message
  3369. lcd_setstatuspgm(MSG_FINISHING_MOVEMENTS);
  3370. lcd_return_to_status();
  3371. lcdDrawUpdate = 3;
  3372. }
  3373. static void lcd_tune_menu()
  3374. {
  3375. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  3376. START_MENU();
  3377. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  3378. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  3379. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  3380. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  3381. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  3382. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  3383. #ifdef FILAMENTCHANGEENABLE
  3384. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7
  3385. #endif
  3386. if (FSensorStateMenu == 0) {
  3387. MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set);
  3388. } else {
  3389. MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
  3390. }
  3391. if (SilentModeMenu == 0) {
  3392. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  3393. } else {
  3394. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  3395. }
  3396. if (SilentModeMenu == 0) {
  3397. if (CrashDetectMenu == 0) {
  3398. MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
  3399. } else {
  3400. MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
  3401. }
  3402. }
  3403. END_MENU();
  3404. }
  3405. static void lcd_move_menu_01mm()
  3406. {
  3407. move_menu_scale = 0.1;
  3408. lcd_move_menu_axis();
  3409. }
  3410. static void lcd_control_temperature_menu()
  3411. {
  3412. #ifdef PIDTEMP
  3413. // set up temp variables - undo the default scaling
  3414. // raw_Ki = unscalePID_i(Ki);
  3415. // raw_Kd = unscalePID_d(Kd);
  3416. #endif
  3417. START_MENU();
  3418. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  3419. #if TEMP_SENSOR_0 != 0
  3420. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  3421. #endif
  3422. #if TEMP_SENSOR_1 != 0
  3423. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  3424. #endif
  3425. #if TEMP_SENSOR_2 != 0
  3426. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  3427. #endif
  3428. #if TEMP_SENSOR_BED != 0
  3429. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  3430. #endif
  3431. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  3432. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  3433. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  3434. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  3435. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  3436. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  3437. #endif
  3438. END_MENU();
  3439. }
  3440. #if SDCARDDETECT == -1
  3441. static void lcd_sd_refresh()
  3442. {
  3443. card.initsd();
  3444. currentMenuViewOffset = 0;
  3445. }
  3446. #endif
  3447. static void lcd_sd_updir()
  3448. {
  3449. SDscrool = 0;
  3450. card.updir();
  3451. currentMenuViewOffset = 0;
  3452. }
  3453. void lcd_print_stop() {
  3454. cancel_heatup = true;
  3455. #ifdef MESH_BED_LEVELING
  3456. mbl.active = false;
  3457. #endif
  3458. // Stop the stoppers, update the position from the stoppers.
  3459. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  3460. planner_abort_hard();
  3461. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  3462. // Z baystep is no more applied. Reset it.
  3463. babystep_reset();
  3464. }
  3465. // Clean the input command queue.
  3466. cmdqueue_reset();
  3467. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  3468. lcd_update(2);
  3469. card.sdprinting = false;
  3470. card.closefile();
  3471. stoptime = millis();
  3472. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  3473. pause_time = 0;
  3474. save_statistics(total_filament_used, t);
  3475. lcd_return_to_status();
  3476. lcd_ignore_click(true);
  3477. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  3478. // Turn off the print fan
  3479. SET_OUTPUT(FAN_PIN);
  3480. WRITE(FAN_PIN, 0);
  3481. fanSpeed = 0;
  3482. }
  3483. void lcd_sdcard_stop()
  3484. {
  3485. lcd.setCursor(0, 0);
  3486. lcd_printPGM(MSG_STOP_PRINT);
  3487. lcd.setCursor(2, 2);
  3488. lcd_printPGM(MSG_NO);
  3489. lcd.setCursor(2, 3);
  3490. lcd_printPGM(MSG_YES);
  3491. lcd.setCursor(0, 2); lcd.print(" ");
  3492. lcd.setCursor(0, 3); lcd.print(" ");
  3493. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  3494. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  3495. lcd.setCursor(0, 1 + encoderPosition);
  3496. lcd.print(">");
  3497. if (lcd_clicked())
  3498. {
  3499. if ((int32_t)encoderPosition == 1)
  3500. {
  3501. lcd_return_to_status();
  3502. }
  3503. if ((int32_t)encoderPosition == 2)
  3504. {
  3505. lcd_print_stop();
  3506. }
  3507. }
  3508. }
  3509. /*
  3510. void getFileDescription(char *name, char *description) {
  3511. // get file description, ie the REAL filenam, ie the second line
  3512. card.openFile(name, true);
  3513. int i = 0;
  3514. // skip the first line (which is the version line)
  3515. while (true) {
  3516. uint16_t readByte = card.get();
  3517. if (readByte == '\n') {
  3518. break;
  3519. }
  3520. }
  3521. // read the second line (which is the description line)
  3522. while (true) {
  3523. uint16_t readByte = card.get();
  3524. if (i == 0) {
  3525. // skip the first '^'
  3526. readByte = card.get();
  3527. }
  3528. description[i] = readByte;
  3529. i++;
  3530. if (readByte == '\n') {
  3531. break;
  3532. }
  3533. }
  3534. card.closefile();
  3535. description[i-1] = 0;
  3536. }
  3537. */
  3538. void lcd_sdcard_menu()
  3539. {
  3540. int tempScrool = 0;
  3541. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  3542. //delay(100);
  3543. return; // nothing to do (so don't thrash the SD card)
  3544. uint16_t fileCnt = card.getnrfilenames();
  3545. START_MENU();
  3546. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3547. card.getWorkDirName();
  3548. if (card.filename[0] == '/')
  3549. {
  3550. #if SDCARDDETECT == -1
  3551. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  3552. #endif
  3553. } else {
  3554. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  3555. }
  3556. for (uint16_t i = 0; i < fileCnt; i++)
  3557. {
  3558. if (_menuItemNr == _lineNr)
  3559. {
  3560. #ifndef SDCARD_RATHERRECENTFIRST
  3561. card.getfilename(i);
  3562. #else
  3563. card.getfilename(fileCnt - 1 - i);
  3564. #endif
  3565. if (card.filenameIsDir)
  3566. {
  3567. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3568. } else {
  3569. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  3570. }
  3571. } else {
  3572. MENU_ITEM_DUMMY();
  3573. }
  3574. }
  3575. END_MENU();
  3576. }
  3577. //char description [10] [31];
  3578. /*void get_description() {
  3579. uint16_t fileCnt = card.getnrfilenames();
  3580. for (uint16_t i = 0; i < fileCnt; i++)
  3581. {
  3582. card.getfilename(fileCnt - 1 - i);
  3583. getFileDescription(card.filename, description[i]);
  3584. }
  3585. }*/
  3586. /*void lcd_farm_sdcard_menu()
  3587. {
  3588. static int i = 0;
  3589. if (i == 0) {
  3590. get_description();
  3591. i++;
  3592. }
  3593. //int j;
  3594. //char description[31];
  3595. int tempScrool = 0;
  3596. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  3597. //delay(100);
  3598. return; // nothing to do (so don't thrash the SD card)
  3599. uint16_t fileCnt = card.getnrfilenames();
  3600. START_MENU();
  3601. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3602. card.getWorkDirName();
  3603. if (card.filename[0] == '/')
  3604. {
  3605. #if SDCARDDETECT == -1
  3606. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  3607. #endif
  3608. }
  3609. else {
  3610. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  3611. }
  3612. for (uint16_t i = 0; i < fileCnt; i++)
  3613. {
  3614. if (_menuItemNr == _lineNr)
  3615. {
  3616. #ifndef SDCARD_RATHERRECENTFIRST
  3617. card.getfilename(i);
  3618. #else
  3619. card.getfilename(fileCnt - 1 - i);
  3620. #endif
  3621. if (card.filenameIsDir)
  3622. {
  3623. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3624. }
  3625. else {
  3626. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, description[i]);
  3627. }
  3628. }
  3629. else {
  3630. MENU_ITEM_DUMMY();
  3631. }
  3632. }
  3633. END_MENU();
  3634. }*/
  3635. #define menu_edit_type(_type, _name, _strFunc, scale) \
  3636. void menu_edit_ ## _name () \
  3637. { \
  3638. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  3639. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  3640. if (lcdDrawUpdate) \
  3641. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  3642. if (LCD_CLICKED) \
  3643. { \
  3644. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  3645. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  3646. } \
  3647. } \
  3648. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  3649. { \
  3650. menuData.editMenuParentState.prevMenu = currentMenu; \
  3651. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  3652. \
  3653. lcdDrawUpdate = 2; \
  3654. menuData.editMenuParentState.editLabel = pstr; \
  3655. menuData.editMenuParentState.editValue = ptr; \
  3656. menuData.editMenuParentState.minEditValue = minValue * scale; \
  3657. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  3658. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  3659. \
  3660. }\
  3661. /*
  3662. void menu_edit_callback_ ## _name () { \
  3663. menu_edit_ ## _name (); \
  3664. if (LCD_CLICKED) (*callbackFunc)(); \
  3665. } \
  3666. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  3667. { \
  3668. menuData.editMenuParentState.prevMenu = currentMenu; \
  3669. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  3670. \
  3671. lcdDrawUpdate = 2; \
  3672. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  3673. \
  3674. menuData.editMenuParentState.editLabel = pstr; \
  3675. menuData.editMenuParentState.editValue = ptr; \
  3676. menuData.editMenuParentState.minEditValue = minValue * scale; \
  3677. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  3678. callbackFunc = callback;\
  3679. }
  3680. */
  3681. menu_edit_type(int, int3, itostr3, 1)
  3682. menu_edit_type(float, float3, ftostr3, 1)
  3683. menu_edit_type(float, float32, ftostr32, 100)
  3684. menu_edit_type(float, float43, ftostr43, 1000)
  3685. menu_edit_type(float, float5, ftostr5, 0.01)
  3686. menu_edit_type(float, float51, ftostr51, 10)
  3687. menu_edit_type(float, float52, ftostr52, 100)
  3688. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  3689. static void lcd_selftest()
  3690. {
  3691. int _progress = 0;
  3692. bool _result = false;
  3693. lcd_implementation_clear();
  3694. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_START);
  3695. delay(2000);
  3696. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  3697. _result = lcd_selftest_fan_dialog(0);
  3698. if (_result)
  3699. {
  3700. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  3701. _result = lcd_selftest_fan_dialog(1);
  3702. }
  3703. if (_result)
  3704. {
  3705. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  3706. //_progress = lcd_selftest_screen(2, _progress, 3, true, 2000);
  3707. _result = true;// lcd_selfcheck_endstops();
  3708. }
  3709. if (_result)
  3710. {
  3711. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  3712. _result = lcd_selfcheck_check_heater(false);
  3713. }
  3714. if (_result)
  3715. {
  3716. //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
  3717. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  3718. _result = lcd_selfcheck_axis_sg(X_AXIS);//, X_MAX_POS);
  3719. }
  3720. if (_result)
  3721. {
  3722. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  3723. //_result = lcd_selfcheck_pulleys(X_AXIS);
  3724. }
  3725. if (_result)
  3726. {
  3727. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  3728. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  3729. //_result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  3730. }
  3731. if (_result)
  3732. {
  3733. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  3734. //_result = lcd_selfcheck_pulleys(Y_AXIS);
  3735. }
  3736. if (_result)
  3737. {
  3738. #ifdef TMC2130
  3739. tmc2130_home_exit();
  3740. enable_endstops(false);
  3741. #endif
  3742. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  3743. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  3744. //homeaxis(X_AXIS);
  3745. //homeaxis(Y_AXIS);
  3746. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  3747. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3748. st_synchronize();
  3749. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  3750. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  3751. enquecommand_P(PSTR("G28 W"));
  3752. }
  3753. if (_result)
  3754. {
  3755. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000);
  3756. _result = lcd_selfcheck_check_heater(true);
  3757. }
  3758. if (_result)
  3759. {
  3760. _progress = lcd_selftest_screen(8, _progress, 3, true, 5000);
  3761. }
  3762. else
  3763. {
  3764. _progress = lcd_selftest_screen(9, _progress, 3, true, 5000);
  3765. }
  3766. lcd_reset_alert_level();
  3767. enquecommand_P(PSTR("M84"));
  3768. lcd_implementation_clear();
  3769. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  3770. if (_result)
  3771. {
  3772. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  3773. }
  3774. else
  3775. {
  3776. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  3777. }
  3778. }
  3779. static bool lcd_selfcheck_axis_sg(char axis) {
  3780. float axis_length, current_position_init, current_position_final;
  3781. float measured_axis_length[2];
  3782. float margin = 100;
  3783. float max_error_mm = 10;
  3784. switch (axis) {
  3785. case 0: axis_length = X_MAX_POS; break;
  3786. case 1: axis_length = Y_MAX_POS + 8; break;
  3787. default: axis_length = 210; break;
  3788. }
  3789. /*SERIAL_ECHOPGM("Current position 1:");
  3790. MYSERIAL.println(current_position[axis]);*/
  3791. current_position[axis] = 0;
  3792. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  3793. #ifdef TMC2130
  3794. tmc2130_home_exit();
  3795. enable_endstops(true);
  3796. #endif
  3797. for (char i = 0; i < 2; i++) {
  3798. /*SERIAL_ECHOPGM("i = ");
  3799. MYSERIAL.println(int(i));
  3800. SERIAL_ECHOPGM("Current position 2:");
  3801. MYSERIAL.println(current_position[axis]);*/
  3802. #ifdef TMC2130
  3803. tmc2130_home_enter(X_AXIS_MASK << axis);
  3804. #endif
  3805. current_position[axis] -= (axis_length + margin);
  3806. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3807. st_synchronize();
  3808. #ifdef TMC2130
  3809. tmc2130_home_exit();
  3810. #endif
  3811. //current_position[axis] = st_get_position_mm(axis);
  3812. //plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  3813. current_position_init = st_get_position_mm(axis);
  3814. if (i < 1) {
  3815. current_position[axis] += margin;
  3816. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3817. st_synchronize();
  3818. current_position[axis] += axis_length;
  3819. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3820. #ifdef TMC2130
  3821. tmc2130_home_enter(X_AXIS_MASK << axis);
  3822. #endif
  3823. st_synchronize();
  3824. #ifdef TMC2130
  3825. tmc2130_home_exit();
  3826. #endif
  3827. //current_position[axis] = st_get_position_mm(axis);
  3828. //plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  3829. current_position_final = st_get_position_mm(axis);
  3830. }
  3831. measured_axis_length[i] = abs(current_position_final - current_position_init);
  3832. SERIAL_ECHOPGM("Measured axis length:");
  3833. MYSERIAL.println(measured_axis_length[i]);
  3834. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  3835. //axis length
  3836. #ifdef TMC2130
  3837. tmc2130_home_exit();
  3838. enable_endstops(false);
  3839. #endif
  3840. const char *_error_1;
  3841. const char *_error_2;
  3842. if (axis == X_AXIS) _error_1 = "X";
  3843. if (axis == Y_AXIS) _error_1 = "Y";
  3844. if (axis == Z_AXIS) _error_1 = "Z";
  3845. lcd_selftest_error(9, _error_1, _error_2);
  3846. return false;
  3847. }
  3848. }
  3849. SERIAL_ECHOPGM("Axis length difference:");
  3850. MYSERIAL.println(abs(measured_axis_length[0] - measured_axis_length[1]));
  3851. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) {
  3852. //loose pulleys
  3853. const char *_error_1;
  3854. const char *_error_2;
  3855. if (axis == X_AXIS) _error_1 = "X";
  3856. if (axis == Y_AXIS) _error_1 = "Y";
  3857. if (axis == Z_AXIS) _error_1 = "Z";
  3858. lcd_selftest_error(8, _error_1, _error_2);
  3859. return false;
  3860. }
  3861. return true;
  3862. }
  3863. static bool lcd_selfcheck_axis(int _axis, int _travel)
  3864. {
  3865. bool _stepdone = false;
  3866. bool _stepresult = false;
  3867. int _progress = 0;
  3868. int _travel_done = 0;
  3869. int _err_endstop = 0;
  3870. int _lcd_refresh = 0;
  3871. _travel = _travel + (_travel / 10);
  3872. do {
  3873. current_position[_axis] = current_position[_axis] - 1;
  3874. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3875. st_synchronize();
  3876. if (/*x_min_endstop || y_min_endstop || */(READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1))
  3877. {
  3878. if (_axis == 0)
  3879. {
  3880. _stepresult = (x_min_endstop) ? true : false;
  3881. _err_endstop = (y_min_endstop) ? 1 : 2;
  3882. }
  3883. if (_axis == 1)
  3884. {
  3885. _stepresult = (y_min_endstop) ? true : false;
  3886. _err_endstop = (x_min_endstop) ? 0 : 2;
  3887. }
  3888. if (_axis == 2)
  3889. {
  3890. _stepresult = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3891. _err_endstop = (x_min_endstop) ? 0 : 1;
  3892. /*disable_x();
  3893. disable_y();
  3894. disable_z();*/
  3895. }
  3896. _stepdone = true;
  3897. }
  3898. #ifdef TMC2130
  3899. tmc2130_home_exit();
  3900. #endif
  3901. if (_lcd_refresh < 6)
  3902. {
  3903. _lcd_refresh++;
  3904. }
  3905. else
  3906. {
  3907. _progress = lcd_selftest_screen(4 + _axis, _progress, 3, false, 0);
  3908. _lcd_refresh = 0;
  3909. }
  3910. manage_heater();
  3911. manage_inactivity(true);
  3912. //delay(100);
  3913. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  3914. } while (!_stepdone);
  3915. //current_position[_axis] = current_position[_axis] + 15;
  3916. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3917. if (!_stepresult)
  3918. {
  3919. const char *_error_1;
  3920. const char *_error_2;
  3921. if (_axis == X_AXIS) _error_1 = "X";
  3922. if (_axis == Y_AXIS) _error_1 = "Y";
  3923. if (_axis == Z_AXIS) _error_1 = "Z";
  3924. if (_err_endstop == 0) _error_2 = "X";
  3925. if (_err_endstop == 1) _error_2 = "Y";
  3926. if (_err_endstop == 2) _error_2 = "Z";
  3927. if (_travel_done >= _travel)
  3928. {
  3929. lcd_selftest_error(5, _error_1, _error_2);
  3930. }
  3931. else
  3932. {
  3933. lcd_selftest_error(4, _error_1, _error_2);
  3934. }
  3935. }
  3936. return _stepresult;
  3937. }
  3938. static bool lcd_selfcheck_pulleys(int axis)
  3939. {
  3940. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  3941. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  3942. float current_position_init, current_position_final;
  3943. float move;
  3944. bool endstop_triggered = false;
  3945. bool result = true;
  3946. int i;
  3947. unsigned long timeout_counter;
  3948. refresh_cmd_timeout();
  3949. manage_inactivity(true);
  3950. if (axis == 0) move = 50; //X_AXIS
  3951. else move = 50; //Y_AXIS
  3952. //current_position_init = current_position[axis];
  3953. current_position_init = st_get_position_mm(axis);
  3954. current_position[axis] += 5;
  3955. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3956. for (i = 0; i < 5; i++) {
  3957. refresh_cmd_timeout();
  3958. current_position[axis] = current_position[axis] + move;
  3959. //digipot_current(0, 850); //set motor current higher
  3960. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  3961. st_synchronize();
  3962. //if (SilentModeMenu == 1) digipot_current(0, tmp_motor[0]); //set back to normal operation currents
  3963. //else digipot_current(0, tmp_motor_loud[0]); //set motor current back
  3964. current_position[axis] = current_position[axis] - move;
  3965. #ifdef TMC2130
  3966. tmc2130_home_enter(X_AXIS_MASK << axis);
  3967. #endif
  3968. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  3969. st_synchronize();
  3970. if ((x_min_endstop) || (y_min_endstop)) {
  3971. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3972. return(false);
  3973. }
  3974. #ifdef TMC2130
  3975. tmc2130_home_exit();
  3976. #endif
  3977. }
  3978. timeout_counter = millis() + 2500;
  3979. endstop_triggered = false;
  3980. manage_inactivity(true);
  3981. while (!endstop_triggered) {
  3982. if ((x_min_endstop) || (y_min_endstop)) {
  3983. #ifdef TMC2130
  3984. tmc2130_home_exit();
  3985. #endif
  3986. endstop_triggered = true;
  3987. current_position_final = st_get_position_mm(axis);
  3988. SERIAL_ECHOPGM("current_pos_init:");
  3989. MYSERIAL.println(current_position_init);
  3990. SERIAL_ECHOPGM("current_pos:");
  3991. MYSERIAL.println(current_position_final);
  3992. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3993. if (current_position_init - 1 <= current_position_final && current_position_init + 1 >= current_position_final) {
  3994. current_position[axis] += 15;
  3995. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3996. st_synchronize();
  3997. return(true);
  3998. }
  3999. else {
  4000. return(false);
  4001. }
  4002. }
  4003. else {
  4004. #ifdef TMC2130
  4005. tmc2130_home_exit();
  4006. #endif
  4007. //current_position[axis] -= 1;
  4008. current_position[axis] += 50;
  4009. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  4010. current_position[axis] -= 100;
  4011. #ifdef TMC2130
  4012. tmc2130_home_enter(X_AXIS_MASK << axis);
  4013. #endif
  4014. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  4015. st_synchronize();
  4016. if (millis() > timeout_counter) {
  4017. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  4018. return(false);
  4019. }
  4020. }
  4021. }
  4022. }
  4023. static bool lcd_selfcheck_endstops()
  4024. {/*
  4025. bool _result = true;
  4026. if (x_min_endstop || y_min_endstop || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  4027. {
  4028. current_position[0] = (x_min_endstop) ? current_position[0] = current_position[0] + 10 : current_position[0];
  4029. current_position[1] = (y_min_endstop) ? current_position[1] = current_position[1] + 10 : current_position[1];
  4030. current_position[2] = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? current_position[2] = current_position[2] + 10 : current_position[2];
  4031. }
  4032. 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);
  4033. delay(500);
  4034. if (x_min_endstop || y_min_endstop || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  4035. {
  4036. _result = false;
  4037. char _error[4] = "";
  4038. if (x_min_endstop) strcat(_error, "X");
  4039. if (y_min_endstop) strcat(_error, "Y");
  4040. if (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) strcat(_error, "Z");
  4041. lcd_selftest_error(3, _error, "");
  4042. }
  4043. manage_heater();
  4044. manage_inactivity(true);
  4045. return _result;
  4046. */
  4047. }
  4048. static bool lcd_selfcheck_check_heater(bool _isbed)
  4049. {
  4050. int _counter = 0;
  4051. int _progress = 0;
  4052. bool _stepresult = false;
  4053. bool _docycle = true;
  4054. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  4055. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  4056. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  4057. target_temperature[0] = (_isbed) ? 0 : 200;
  4058. target_temperature_bed = (_isbed) ? 100 : 0;
  4059. manage_heater();
  4060. manage_inactivity(true);
  4061. do {
  4062. _counter++;
  4063. _docycle = (_counter < _cycles) ? true : false;
  4064. manage_heater();
  4065. manage_inactivity(true);
  4066. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  4067. /*if (_isbed) {
  4068. MYSERIAL.print("Bed temp:");
  4069. MYSERIAL.println(degBed());
  4070. }
  4071. else {
  4072. MYSERIAL.print("Hotend temp:");
  4073. MYSERIAL.println(degHotend(0));
  4074. }*/
  4075. } while (_docycle);
  4076. target_temperature[0] = 0;
  4077. target_temperature_bed = 0;
  4078. manage_heater();
  4079. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  4080. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  4081. /*
  4082. MYSERIAL.println("");
  4083. MYSERIAL.print("Checked result:");
  4084. MYSERIAL.println(_checked_result);
  4085. MYSERIAL.print("Opposite result:");
  4086. MYSERIAL.println(_opposite_result);
  4087. */
  4088. if (_opposite_result < ((_isbed) ? 10 : 3))
  4089. {
  4090. if (_checked_result >= ((_isbed) ? 3 : 10))
  4091. {
  4092. _stepresult = true;
  4093. }
  4094. else
  4095. {
  4096. lcd_selftest_error(1, "", "");
  4097. }
  4098. }
  4099. else
  4100. {
  4101. lcd_selftest_error(2, "", "");
  4102. }
  4103. manage_heater();
  4104. manage_inactivity(true);
  4105. return _stepresult;
  4106. }
  4107. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  4108. {
  4109. lcd_implementation_quick_feedback();
  4110. target_temperature[0] = 0;
  4111. target_temperature_bed = 0;
  4112. manage_heater();
  4113. manage_inactivity();
  4114. lcd_implementation_clear();
  4115. lcd.setCursor(0, 0);
  4116. lcd_printPGM(MSG_SELFTEST_ERROR);
  4117. lcd.setCursor(0, 1);
  4118. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  4119. switch (_error_no)
  4120. {
  4121. case 1:
  4122. lcd.setCursor(0, 2);
  4123. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  4124. lcd.setCursor(0, 3);
  4125. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  4126. break;
  4127. case 2:
  4128. lcd.setCursor(0, 2);
  4129. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  4130. lcd.setCursor(0, 3);
  4131. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  4132. break;
  4133. case 3:
  4134. lcd.setCursor(0, 2);
  4135. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  4136. lcd.setCursor(0, 3);
  4137. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  4138. lcd.setCursor(17, 3);
  4139. lcd.print(_error_1);
  4140. break;
  4141. case 4:
  4142. lcd.setCursor(0, 2);
  4143. lcd_printPGM(MSG_SELFTEST_MOTOR);
  4144. lcd.setCursor(18, 2);
  4145. lcd.print(_error_1);
  4146. lcd.setCursor(0, 3);
  4147. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  4148. lcd.setCursor(18, 3);
  4149. lcd.print(_error_2);
  4150. break;
  4151. case 5:
  4152. lcd.setCursor(0, 2);
  4153. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  4154. lcd.setCursor(0, 3);
  4155. lcd_printPGM(MSG_SELFTEST_MOTOR);
  4156. lcd.setCursor(18, 3);
  4157. lcd.print(_error_1);
  4158. break;
  4159. case 6:
  4160. lcd.setCursor(0, 2);
  4161. lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  4162. lcd.setCursor(0, 3);
  4163. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  4164. lcd.setCursor(18, 3);
  4165. lcd.print(_error_1);
  4166. break;
  4167. case 7:
  4168. lcd.setCursor(0, 2);
  4169. lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  4170. lcd.setCursor(0, 3);
  4171. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  4172. lcd.setCursor(18, 3);
  4173. lcd.print(_error_1);
  4174. break;
  4175. case 8:
  4176. lcd.setCursor(0, 2);
  4177. lcd_printPGM(MSG_LOOSE_PULLEY);
  4178. lcd.setCursor(0, 3);
  4179. lcd_printPGM(MSG_SELFTEST_MOTOR);
  4180. lcd.setCursor(18, 3);
  4181. lcd.print(_error_1);
  4182. break;
  4183. case 9:
  4184. lcd.setCursor(0, 2);
  4185. lcd_printPGM(MSG_SELFTEST_AXIS_LENGTH);
  4186. lcd.setCursor(0, 3);
  4187. lcd_printPGM(MSG_SELFTEST_AXIS);
  4188. lcd.setCursor(18, 3);
  4189. lcd.print(_error_1);
  4190. break;
  4191. }
  4192. delay(1000);
  4193. lcd_implementation_quick_feedback();
  4194. do {
  4195. delay(100);
  4196. manage_heater();
  4197. manage_inactivity();
  4198. } while (!lcd_clicked());
  4199. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  4200. lcd_return_to_status();
  4201. }
  4202. static bool lcd_selftest_fan_dialog(int _fan)
  4203. {
  4204. bool _result = true;
  4205. int _errno = 6;
  4206. switch (_fan) {
  4207. case 0:
  4208. fanSpeed = 0;
  4209. manage_heater(); //turn off fan
  4210. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  4211. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  4212. manage_heater(); //count average fan speed from 2s delay and turn off fans
  4213. if (!fan_speed[0]) _result = false;
  4214. /*SERIAL_ECHOPGM("Extruder fan speed: ");
  4215. MYSERIAL.println(fan_speed[0]);
  4216. SERIAL_ECHOPGM("Print fan speed: ");
  4217. MYSERIAL.print(fan_speed[1]);*/
  4218. break;
  4219. case 1:
  4220. //will it work with Thotend > 50 C ?
  4221. fanSpeed = 255; //print fan
  4222. delay_keep_alive(2000);
  4223. fanSpeed = 0;
  4224. manage_heater(); //turn off fan
  4225. manage_inactivity(true); //to turn off print fan
  4226. if (!fan_speed[1]) {
  4227. _result = false; _errno = 7;
  4228. }
  4229. /*SERIAL_ECHOPGM("Extruder fan speed: ");
  4230. MYSERIAL.println(fan_speed[0]);
  4231. SERIAL_ECHOPGM("Print fan speed: ");
  4232. MYSERIAL.print(fan_speed[1]);*/
  4233. break;
  4234. }
  4235. if (!_result)
  4236. {
  4237. const char *_err;
  4238. lcd_selftest_error(_errno, _err, _err);
  4239. }
  4240. return _result;
  4241. }
  4242. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  4243. {
  4244. //SERIAL_ECHOPGM("Step:");
  4245. //MYSERIAL.println(_step);
  4246. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  4247. int _step_block = 0;
  4248. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  4249. if (_clear) lcd_implementation_clear();
  4250. lcd.setCursor(0, 0);
  4251. if (_step == -1) lcd_printPGM(MSG_SELFTEST_FAN);
  4252. if (_step == 0) lcd_printPGM(MSG_SELFTEST_FAN);
  4253. if (_step == 1) lcd_printPGM(MSG_SELFTEST_FAN);
  4254. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  4255. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  4256. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  4257. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  4258. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  4259. if (_step == 7) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  4260. if (_step == 8) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  4261. if (_step == 9) lcd_printPGM(MSG_SELFTEST_FAILED);
  4262. lcd.setCursor(0, 1);
  4263. lcd.print("--------------------");
  4264. if ((_step >= -1) && (_step <= 1))
  4265. {
  4266. //SERIAL_ECHOLNPGM("Fan test");
  4267. lcd_print_at_PGM(0, 2, PSTR("Extruder fan:"));
  4268. lcd.setCursor(14, 2);
  4269. (_step < 0) ? lcd.print(_indicator) : lcd.print("OK");
  4270. lcd_print_at_PGM(0, 3, PSTR("Print fan:"));
  4271. lcd.setCursor(14, 3);
  4272. (_step < 1) ? lcd.print(_indicator) : lcd.print("OK");
  4273. }
  4274. else if (_step != 9)
  4275. {
  4276. //SERIAL_ECHOLNPGM("Other tests");
  4277. _step_block = 3;
  4278. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  4279. _step_block = 4;
  4280. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  4281. _step_block = 5;
  4282. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  4283. _step_block = 6;
  4284. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  4285. _step_block = 7;
  4286. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  4287. }
  4288. if (_delay > 0) delay(_delay);
  4289. _progress++;
  4290. return (_progress > _progress_scale * 2) ? 0 : _progress;
  4291. }
  4292. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  4293. {
  4294. lcd.setCursor(_col, _row);
  4295. switch (_state)
  4296. {
  4297. case 1:
  4298. lcd.print(_name);
  4299. lcd.setCursor(_col + strlen(_name), _row);
  4300. lcd.print(":");
  4301. lcd.setCursor(_col + strlen(_name) + 1, _row);
  4302. lcd.print(_indicator);
  4303. break;
  4304. case 2:
  4305. lcd.print(_name);
  4306. lcd.setCursor(_col + strlen(_name), _row);
  4307. lcd.print(":");
  4308. lcd.setCursor(_col + strlen(_name) + 1, _row);
  4309. lcd.print("OK");
  4310. break;
  4311. default:
  4312. lcd.print(_name);
  4313. }
  4314. }
  4315. /** End of menus **/
  4316. static void lcd_quick_feedback()
  4317. {
  4318. lcdDrawUpdate = 2;
  4319. button_pressed = false;
  4320. lcd_implementation_quick_feedback();
  4321. }
  4322. /** Menu action functions **/
  4323. static void menu_action_back(menuFunc_t data) {
  4324. lcd_goto_menu(data);
  4325. }
  4326. static void menu_action_submenu(menuFunc_t data) {
  4327. lcd_goto_menu(data);
  4328. }
  4329. static void menu_action_gcode(const char* pgcode) {
  4330. enquecommand_P(pgcode);
  4331. }
  4332. static void menu_action_setlang(unsigned char lang) {
  4333. lcd_set_lang(lang);
  4334. }
  4335. static void menu_action_function(menuFunc_t data) {
  4336. (*data)();
  4337. }
  4338. static void menu_action_sdfile(const char* filename, char* longFilename)
  4339. {
  4340. loading_flag = false;
  4341. char cmd[30];
  4342. char* c;
  4343. sprintf_P(cmd, PSTR("M23 %s"), filename);
  4344. for (c = &cmd[4]; *c; c++)
  4345. *c = tolower(*c);
  4346. enquecommand(cmd);
  4347. for (int i = 0; i < 8; i++) {
  4348. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, filename[i]);
  4349. }
  4350. enquecommand_P(PSTR("M24"));
  4351. lcd_return_to_status();
  4352. }
  4353. static void menu_action_sddirectory(const char* filename, char* longFilename)
  4354. {
  4355. card.chdir(filename);
  4356. encoderPosition = 0;
  4357. }
  4358. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  4359. {
  4360. *ptr = !(*ptr);
  4361. }
  4362. /*
  4363. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  4364. {
  4365. menu_action_setting_edit_bool(pstr, ptr);
  4366. (*callback)();
  4367. }
  4368. */
  4369. #endif//ULTIPANEL
  4370. /** LCD API **/
  4371. void lcd_init()
  4372. {
  4373. lcd_implementation_init();
  4374. #ifdef NEWPANEL
  4375. SET_INPUT(BTN_EN1);
  4376. SET_INPUT(BTN_EN2);
  4377. WRITE(BTN_EN1, HIGH);
  4378. WRITE(BTN_EN2, HIGH);
  4379. #if BTN_ENC > 0
  4380. SET_INPUT(BTN_ENC);
  4381. WRITE(BTN_ENC, HIGH);
  4382. #endif
  4383. #ifdef REPRAPWORLD_KEYPAD
  4384. pinMode(SHIFT_CLK, OUTPUT);
  4385. pinMode(SHIFT_LD, OUTPUT);
  4386. pinMode(SHIFT_OUT, INPUT);
  4387. WRITE(SHIFT_OUT, HIGH);
  4388. WRITE(SHIFT_LD, HIGH);
  4389. #endif
  4390. #else // Not NEWPANEL
  4391. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  4392. pinMode (SR_DATA_PIN, OUTPUT);
  4393. pinMode (SR_CLK_PIN, OUTPUT);
  4394. #elif defined(SHIFT_CLK)
  4395. pinMode(SHIFT_CLK, OUTPUT);
  4396. pinMode(SHIFT_LD, OUTPUT);
  4397. pinMode(SHIFT_EN, OUTPUT);
  4398. pinMode(SHIFT_OUT, INPUT);
  4399. WRITE(SHIFT_OUT, HIGH);
  4400. WRITE(SHIFT_LD, HIGH);
  4401. WRITE(SHIFT_EN, LOW);
  4402. #else
  4403. #ifdef ULTIPANEL
  4404. #error ULTIPANEL requires an encoder
  4405. #endif
  4406. #endif // SR_LCD_2W_NL
  4407. #endif//!NEWPANEL
  4408. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  4409. pinMode(SDCARDDETECT, INPUT);
  4410. WRITE(SDCARDDETECT, HIGH);
  4411. lcd_oldcardstatus = IS_SD_INSERTED;
  4412. #endif//(SDCARDDETECT > 0)
  4413. #ifdef LCD_HAS_SLOW_BUTTONS
  4414. slow_buttons = 0;
  4415. #endif
  4416. lcd_buttons_update();
  4417. #ifdef ULTIPANEL
  4418. encoderDiff = 0;
  4419. #endif
  4420. }
  4421. //#include <avr/pgmspace.h>
  4422. static volatile bool lcd_update_enabled = true;
  4423. unsigned long lcd_timeoutToStatus = 0;
  4424. void lcd_update_enable(bool enabled)
  4425. {
  4426. if (lcd_update_enabled != enabled) {
  4427. lcd_update_enabled = enabled;
  4428. if (enabled) {
  4429. // Reset encoder position. This is equivalent to re-entering a menu.
  4430. encoderPosition = 0;
  4431. encoderDiff = 0;
  4432. // Enabling the normal LCD update procedure.
  4433. // Reset the timeout interval.
  4434. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4435. // Force the keypad update now.
  4436. lcd_next_update_millis = millis() - 1;
  4437. // Full update.
  4438. lcd_implementation_clear();
  4439. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  4440. lcd_set_custom_characters(currentMenu == lcd_status_screen);
  4441. #else
  4442. if (currentMenu == lcd_status_screen)
  4443. lcd_set_custom_characters_degree();
  4444. else
  4445. lcd_set_custom_characters_arrows();
  4446. #endif
  4447. lcd_update(2);
  4448. } else {
  4449. // Clear the LCD always, or let it to the caller?
  4450. }
  4451. }
  4452. }
  4453. void lcd_update(uint8_t lcdDrawUpdateOverride)
  4454. {
  4455. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  4456. lcdDrawUpdate = lcdDrawUpdateOverride;
  4457. if (!lcd_update_enabled)
  4458. return;
  4459. #ifdef LCD_HAS_SLOW_BUTTONS
  4460. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  4461. #endif
  4462. lcd_buttons_update();
  4463. #if (SDCARDDETECT > 0)
  4464. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  4465. {
  4466. lcdDrawUpdate = 2;
  4467. lcd_oldcardstatus = IS_SD_INSERTED;
  4468. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  4469. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  4470. currentMenu == lcd_status_screen
  4471. #endif
  4472. );
  4473. if (lcd_oldcardstatus)
  4474. {
  4475. card.initsd();
  4476. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  4477. //get_description();
  4478. }
  4479. else
  4480. {
  4481. card.release();
  4482. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  4483. }
  4484. }
  4485. #endif//CARDINSERTED
  4486. if (lcd_next_update_millis < millis())
  4487. {
  4488. #ifdef DEBUG_BLINK_ACTIVE
  4489. static bool active_led = false;
  4490. active_led = !active_led;
  4491. pinMode(LED_PIN, OUTPUT);
  4492. digitalWrite(LED_PIN, active_led?HIGH:LOW);
  4493. #endif //DEBUG_BLINK_ACTIVE
  4494. #ifdef ULTIPANEL
  4495. #ifdef REPRAPWORLD_KEYPAD
  4496. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  4497. reprapworld_keypad_move_z_up();
  4498. }
  4499. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  4500. reprapworld_keypad_move_z_down();
  4501. }
  4502. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  4503. reprapworld_keypad_move_x_left();
  4504. }
  4505. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  4506. reprapworld_keypad_move_x_right();
  4507. }
  4508. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  4509. reprapworld_keypad_move_y_down();
  4510. }
  4511. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  4512. reprapworld_keypad_move_y_up();
  4513. }
  4514. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  4515. reprapworld_keypad_move_home();
  4516. }
  4517. #endif
  4518. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  4519. {
  4520. if (lcdDrawUpdate == 0)
  4521. lcdDrawUpdate = 1;
  4522. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  4523. encoderDiff = 0;
  4524. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4525. }
  4526. if (LCD_CLICKED) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4527. #endif//ULTIPANEL
  4528. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  4529. blink++; // Variable for fan animation and alive dot
  4530. u8g.firstPage();
  4531. do
  4532. {
  4533. u8g.setFont(u8g_font_6x10_marlin);
  4534. u8g.setPrintPos(125, 0);
  4535. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  4536. u8g.drawPixel(127, 63); // draw alive dot
  4537. u8g.setColorIndex(1); // black on white
  4538. (*currentMenu)();
  4539. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  4540. } while (u8g.nextPage());
  4541. #else
  4542. (*currentMenu)();
  4543. #endif
  4544. #ifdef LCD_HAS_STATUS_INDICATORS
  4545. lcd_implementation_update_indicators();
  4546. #endif
  4547. #ifdef ULTIPANEL
  4548. if (lcd_timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  4549. {
  4550. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  4551. // to give it a chance to save its state.
  4552. // This is useful for example, when the babystep value has to be written into EEPROM.
  4553. if (currentMenu != NULL) {
  4554. menuExiting = true;
  4555. (*currentMenu)();
  4556. menuExiting = false;
  4557. }
  4558. lcd_return_to_status();
  4559. lcdDrawUpdate = 2;
  4560. }
  4561. #endif//ULTIPANEL
  4562. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  4563. if (lcdDrawUpdate) lcdDrawUpdate--;
  4564. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  4565. }
  4566. if (!SdFatUtil::test_stack_integrity()) stack_error();
  4567. lcd_ping(); //check that we have received ping command if we are in farm mode
  4568. }
  4569. void lcd_printer_connected() {
  4570. printer_connected = true;
  4571. }
  4572. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  4573. if (farm_mode) {
  4574. bool empty = is_buffer_empty();
  4575. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  4576. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  4577. //therefore longer period is used
  4578. printer_connected = false;
  4579. //lcd_ping_allert(); //acustic signals
  4580. }
  4581. else {
  4582. lcd_printer_connected();
  4583. }
  4584. }
  4585. }
  4586. void lcd_ignore_click(bool b)
  4587. {
  4588. ignore_click = b;
  4589. wait_for_unclick = false;
  4590. }
  4591. void lcd_finishstatus() {
  4592. int len = strlen(lcd_status_message);
  4593. if (len > 0) {
  4594. while (len < LCD_WIDTH) {
  4595. lcd_status_message[len++] = ' ';
  4596. }
  4597. }
  4598. lcd_status_message[LCD_WIDTH] = '\0';
  4599. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  4600. #if PROGRESS_MSG_EXPIRE > 0
  4601. messageTick =
  4602. #endif
  4603. progressBarTick = millis();
  4604. #endif
  4605. lcdDrawUpdate = 2;
  4606. #ifdef FILAMENT_LCD_DISPLAY
  4607. message_millis = millis(); //get status message to show up for a while
  4608. #endif
  4609. }
  4610. void lcd_setstatus(const char* message)
  4611. {
  4612. if (lcd_status_message_level > 0)
  4613. return;
  4614. strncpy(lcd_status_message, message, LCD_WIDTH);
  4615. lcd_finishstatus();
  4616. }
  4617. void lcd_setstatuspgm(const char* message)
  4618. {
  4619. if (lcd_status_message_level > 0)
  4620. return;
  4621. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  4622. lcd_finishstatus();
  4623. }
  4624. void lcd_setalertstatuspgm(const char* message)
  4625. {
  4626. lcd_setstatuspgm(message);
  4627. lcd_status_message_level = 1;
  4628. #ifdef ULTIPANEL
  4629. lcd_return_to_status();
  4630. #endif//ULTIPANEL
  4631. }
  4632. void lcd_reset_alert_level()
  4633. {
  4634. lcd_status_message_level = 0;
  4635. }
  4636. uint8_t get_message_level()
  4637. {
  4638. return lcd_status_message_level;
  4639. }
  4640. #ifdef DOGLCD
  4641. void lcd_setcontrast(uint8_t value)
  4642. {
  4643. lcd_contrast = value & 63;
  4644. u8g.setContrast(lcd_contrast);
  4645. }
  4646. #endif
  4647. #ifdef ULTIPANEL
  4648. /* Warning: This function is called from interrupt context */
  4649. void lcd_buttons_update()
  4650. {
  4651. #ifdef NEWPANEL
  4652. uint8_t newbutton = 0;
  4653. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  4654. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  4655. #if BTN_ENC > 0
  4656. if (lcd_update_enabled == true) { //if we are in non-modal mode, long press can be used and short press triggers with button release
  4657. if (READ(BTN_ENC) == 0) { //button is pressed
  4658. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4659. if (millis() > button_blanking_time) {
  4660. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  4661. if (button_pressed == false && long_press_active == false) {
  4662. if (currentMenu != lcd_move_z) {
  4663. savedMenu = currentMenu;
  4664. savedEncoderPosition = encoderPosition;
  4665. }
  4666. long_press_timer = millis();
  4667. button_pressed = true;
  4668. }
  4669. else {
  4670. if (millis() - long_press_timer > LONG_PRESS_TIME) { //long press activated
  4671. long_press_active = true;
  4672. move_menu_scale = 1.0;
  4673. lcd_goto_menu(lcd_move_z);
  4674. }
  4675. }
  4676. }
  4677. }
  4678. else { //button not pressed
  4679. if (button_pressed) { //button was released
  4680. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  4681. if (long_press_active == false) { //button released before long press gets activated
  4682. if (currentMenu == lcd_move_z) {
  4683. //return to previously active menu and previous encoder position
  4684. lcd_goto_menu(savedMenu, savedEncoderPosition);
  4685. }
  4686. else {
  4687. newbutton |= EN_C;
  4688. }
  4689. }
  4690. else if (currentMenu == lcd_move_z) lcd_quick_feedback();
  4691. //button_pressed is set back to false via lcd_quick_feedback function
  4692. }
  4693. else {
  4694. long_press_active = false;
  4695. }
  4696. }
  4697. }
  4698. else { //we are in modal mode
  4699. if (READ(BTN_ENC) == 0)
  4700. newbutton |= EN_C;
  4701. }
  4702. #endif
  4703. buttons = newbutton;
  4704. #ifdef LCD_HAS_SLOW_BUTTONS
  4705. buttons |= slow_buttons;
  4706. #endif
  4707. #ifdef REPRAPWORLD_KEYPAD
  4708. // for the reprapworld_keypad
  4709. uint8_t newbutton_reprapworld_keypad = 0;
  4710. WRITE(SHIFT_LD, LOW);
  4711. WRITE(SHIFT_LD, HIGH);
  4712. for (int8_t i = 0; i < 8; i++) {
  4713. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  4714. if (READ(SHIFT_OUT))
  4715. newbutton_reprapworld_keypad |= (1 << 7);
  4716. WRITE(SHIFT_CLK, HIGH);
  4717. WRITE(SHIFT_CLK, LOW);
  4718. }
  4719. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  4720. #endif
  4721. #else //read it from the shift register
  4722. uint8_t newbutton = 0;
  4723. WRITE(SHIFT_LD, LOW);
  4724. WRITE(SHIFT_LD, HIGH);
  4725. unsigned char tmp_buttons = 0;
  4726. for (int8_t i = 0; i < 8; i++)
  4727. {
  4728. newbutton = newbutton >> 1;
  4729. if (READ(SHIFT_OUT))
  4730. newbutton |= (1 << 7);
  4731. WRITE(SHIFT_CLK, HIGH);
  4732. WRITE(SHIFT_CLK, LOW);
  4733. }
  4734. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  4735. #endif//!NEWPANEL
  4736. //manage encoder rotation
  4737. uint8_t enc = 0;
  4738. if (buttons & EN_A) enc |= B01;
  4739. if (buttons & EN_B) enc |= B10;
  4740. if (enc != lastEncoderBits)
  4741. {
  4742. switch (enc)
  4743. {
  4744. case encrot0:
  4745. if (lastEncoderBits == encrot3)
  4746. encoderDiff++;
  4747. else if (lastEncoderBits == encrot1)
  4748. encoderDiff--;
  4749. break;
  4750. case encrot1:
  4751. if (lastEncoderBits == encrot0)
  4752. encoderDiff++;
  4753. else if (lastEncoderBits == encrot2)
  4754. encoderDiff--;
  4755. break;
  4756. case encrot2:
  4757. if (lastEncoderBits == encrot1)
  4758. encoderDiff++;
  4759. else if (lastEncoderBits == encrot3)
  4760. encoderDiff--;
  4761. break;
  4762. case encrot3:
  4763. if (lastEncoderBits == encrot2)
  4764. encoderDiff++;
  4765. else if (lastEncoderBits == encrot0)
  4766. encoderDiff--;
  4767. break;
  4768. }
  4769. }
  4770. lastEncoderBits = enc;
  4771. }
  4772. bool lcd_detected(void)
  4773. {
  4774. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  4775. return lcd.LcdDetected() == 1;
  4776. #else
  4777. return true;
  4778. #endif
  4779. }
  4780. void lcd_buzz(long duration, uint16_t freq)
  4781. {
  4782. #ifdef LCD_USE_I2C_BUZZER
  4783. lcd.buzz(duration, freq);
  4784. #endif
  4785. }
  4786. bool lcd_clicked()
  4787. {
  4788. bool clicked = LCD_CLICKED;
  4789. if(clicked) button_pressed = false;
  4790. return clicked;
  4791. }
  4792. #endif//ULTIPANEL
  4793. /********************************/
  4794. /** Float conversion utilities **/
  4795. /********************************/
  4796. // convert float to string with +123.4 format
  4797. char conv[8];
  4798. char *ftostr3(const float &x)
  4799. {
  4800. return itostr3((int)x);
  4801. }
  4802. char *itostr2(const uint8_t &x)
  4803. {
  4804. //sprintf(conv,"%5.1f",x);
  4805. int xx = x;
  4806. conv[0] = (xx / 10) % 10 + '0';
  4807. conv[1] = (xx) % 10 + '0';
  4808. conv[2] = 0;
  4809. return conv;
  4810. }
  4811. // Convert float to string with 123.4 format, dropping sign
  4812. char *ftostr31(const float &x)
  4813. {
  4814. int xx = x * 10;
  4815. conv[0] = (xx >= 0) ? '+' : '-';
  4816. xx = abs(xx);
  4817. conv[1] = (xx / 1000) % 10 + '0';
  4818. conv[2] = (xx / 100) % 10 + '0';
  4819. conv[3] = (xx / 10) % 10 + '0';
  4820. conv[4] = '.';
  4821. conv[5] = (xx) % 10 + '0';
  4822. conv[6] = 0;
  4823. return conv;
  4824. }
  4825. // Convert float to string with 123.4 format
  4826. char *ftostr31ns(const float &x)
  4827. {
  4828. int xx = x * 10;
  4829. //conv[0]=(xx>=0)?'+':'-';
  4830. xx = abs(xx);
  4831. conv[0] = (xx / 1000) % 10 + '0';
  4832. conv[1] = (xx / 100) % 10 + '0';
  4833. conv[2] = (xx / 10) % 10 + '0';
  4834. conv[3] = '.';
  4835. conv[4] = (xx) % 10 + '0';
  4836. conv[5] = 0;
  4837. return conv;
  4838. }
  4839. char *ftostr32(const float &x)
  4840. {
  4841. long xx = x * 100;
  4842. if (xx >= 0)
  4843. conv[0] = (xx / 10000) % 10 + '0';
  4844. else
  4845. conv[0] = '-';
  4846. xx = abs(xx);
  4847. conv[1] = (xx / 1000) % 10 + '0';
  4848. conv[2] = (xx / 100) % 10 + '0';
  4849. conv[3] = '.';
  4850. conv[4] = (xx / 10) % 10 + '0';
  4851. conv[5] = (xx) % 10 + '0';
  4852. conv[6] = 0;
  4853. return conv;
  4854. }
  4855. //// Convert float to rj string with 123.45 format
  4856. char *ftostr32ns(const float &x) {
  4857. long xx = abs(x);
  4858. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  4859. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4860. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  4861. conv[3] = '.';
  4862. conv[4] = (xx / 10) % 10 + '0';
  4863. conv[5] = xx % 10 + '0';
  4864. return conv;
  4865. }
  4866. // Convert float to string with 1.234 format
  4867. char *ftostr43(const float &x)
  4868. {
  4869. long xx = x * 1000;
  4870. if (xx >= 0)
  4871. conv[0] = (xx / 1000) % 10 + '0';
  4872. else
  4873. conv[0] = '-';
  4874. xx = abs(xx);
  4875. conv[1] = '.';
  4876. conv[2] = (xx / 100) % 10 + '0';
  4877. conv[3] = (xx / 10) % 10 + '0';
  4878. conv[4] = (xx) % 10 + '0';
  4879. conv[5] = 0;
  4880. return conv;
  4881. }
  4882. //Float to string with 1.23 format
  4883. char *ftostr12ns(const float &x)
  4884. {
  4885. long xx = x * 100;
  4886. xx = abs(xx);
  4887. conv[0] = (xx / 100) % 10 + '0';
  4888. conv[1] = '.';
  4889. conv[2] = (xx / 10) % 10 + '0';
  4890. conv[3] = (xx) % 10 + '0';
  4891. conv[4] = 0;
  4892. return conv;
  4893. }
  4894. //Float to string with 1.234 format
  4895. char *ftostr13ns(const float &x)
  4896. {
  4897. long xx = x * 1000;
  4898. if (xx >= 0)
  4899. conv[0] = ' ';
  4900. else
  4901. conv[0] = '-';
  4902. xx = abs(xx);
  4903. conv[1] = (xx / 1000) % 10 + '0';
  4904. conv[2] = '.';
  4905. conv[3] = (xx / 100) % 10 + '0';
  4906. conv[4] = (xx / 10) % 10 + '0';
  4907. conv[5] = (xx) % 10 + '0';
  4908. conv[6] = 0;
  4909. return conv;
  4910. }
  4911. // convert float to space-padded string with -_23.4_ format
  4912. char *ftostr32sp(const float &x) {
  4913. long xx = abs(x * 100);
  4914. uint8_t dig;
  4915. if (x < 0) { // negative val = -_0
  4916. conv[0] = '-';
  4917. dig = (xx / 1000) % 10;
  4918. conv[1] = dig ? '0' + dig : ' ';
  4919. }
  4920. else { // positive val = __0
  4921. dig = (xx / 10000) % 10;
  4922. if (dig) {
  4923. conv[0] = '0' + dig;
  4924. conv[1] = '0' + (xx / 1000) % 10;
  4925. }
  4926. else {
  4927. conv[0] = ' ';
  4928. dig = (xx / 1000) % 10;
  4929. conv[1] = dig ? '0' + dig : ' ';
  4930. }
  4931. }
  4932. conv[2] = '0' + (xx / 100) % 10; // lsd always
  4933. dig = xx % 10;
  4934. if (dig) { // 2 decimal places
  4935. conv[5] = '0' + dig;
  4936. conv[4] = '0' + (xx / 10) % 10;
  4937. conv[3] = '.';
  4938. }
  4939. else { // 1 or 0 decimal place
  4940. dig = (xx / 10) % 10;
  4941. if (dig) {
  4942. conv[4] = '0' + dig;
  4943. conv[3] = '.';
  4944. }
  4945. else {
  4946. conv[3] = conv[4] = ' ';
  4947. }
  4948. conv[5] = ' ';
  4949. }
  4950. conv[6] = '\0';
  4951. return conv;
  4952. }
  4953. char *itostr31(const int &xx)
  4954. {
  4955. conv[0] = (xx >= 0) ? '+' : '-';
  4956. conv[1] = (xx / 1000) % 10 + '0';
  4957. conv[2] = (xx / 100) % 10 + '0';
  4958. conv[3] = (xx / 10) % 10 + '0';
  4959. conv[4] = '.';
  4960. conv[5] = (xx) % 10 + '0';
  4961. conv[6] = 0;
  4962. return conv;
  4963. }
  4964. // Convert int to rj string with 123 or -12 format
  4965. char *itostr3(const int &x)
  4966. {
  4967. int xx = x;
  4968. if (xx < 0) {
  4969. conv[0] = '-';
  4970. xx = -xx;
  4971. } else if (xx >= 100)
  4972. conv[0] = (xx / 100) % 10 + '0';
  4973. else
  4974. conv[0] = ' ';
  4975. if (xx >= 10)
  4976. conv[1] = (xx / 10) % 10 + '0';
  4977. else
  4978. conv[1] = ' ';
  4979. conv[2] = (xx) % 10 + '0';
  4980. conv[3] = 0;
  4981. return conv;
  4982. }
  4983. // Convert int to lj string with 123 format
  4984. char *itostr3left(const int &xx)
  4985. {
  4986. if (xx >= 100)
  4987. {
  4988. conv[0] = (xx / 100) % 10 + '0';
  4989. conv[1] = (xx / 10) % 10 + '0';
  4990. conv[2] = (xx) % 10 + '0';
  4991. conv[3] = 0;
  4992. }
  4993. else if (xx >= 10)
  4994. {
  4995. conv[0] = (xx / 10) % 10 + '0';
  4996. conv[1] = (xx) % 10 + '0';
  4997. conv[2] = 0;
  4998. }
  4999. else
  5000. {
  5001. conv[0] = (xx) % 10 + '0';
  5002. conv[1] = 0;
  5003. }
  5004. return conv;
  5005. }
  5006. // Convert int to rj string with 1234 format
  5007. char *itostr4(const int &xx) {
  5008. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  5009. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  5010. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  5011. conv[3] = xx % 10 + '0';
  5012. conv[4] = 0;
  5013. return conv;
  5014. }
  5015. // Convert float to rj string with 12345 format
  5016. char *ftostr5(const float &x) {
  5017. long xx = abs(x);
  5018. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  5019. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  5020. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  5021. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  5022. conv[4] = xx % 10 + '0';
  5023. conv[5] = 0;
  5024. return conv;
  5025. }
  5026. // Convert float to string with +1234.5 format
  5027. char *ftostr51(const float &x)
  5028. {
  5029. long xx = x * 10;
  5030. conv[0] = (xx >= 0) ? '+' : '-';
  5031. xx = abs(xx);
  5032. conv[1] = (xx / 10000) % 10 + '0';
  5033. conv[2] = (xx / 1000) % 10 + '0';
  5034. conv[3] = (xx / 100) % 10 + '0';
  5035. conv[4] = (xx / 10) % 10 + '0';
  5036. conv[5] = '.';
  5037. conv[6] = (xx) % 10 + '0';
  5038. conv[7] = 0;
  5039. return conv;
  5040. }
  5041. // Convert float to string with +123.45 format
  5042. char *ftostr52(const float &x)
  5043. {
  5044. long xx = x * 100;
  5045. conv[0] = (xx >= 0) ? '+' : '-';
  5046. xx = abs(xx);
  5047. conv[1] = (xx / 10000) % 10 + '0';
  5048. conv[2] = (xx / 1000) % 10 + '0';
  5049. conv[3] = (xx / 100) % 10 + '0';
  5050. conv[4] = '.';
  5051. conv[5] = (xx / 10) % 10 + '0';
  5052. conv[6] = (xx) % 10 + '0';
  5053. conv[7] = 0;
  5054. return conv;
  5055. }
  5056. /*
  5057. // Callback for after editing PID i value
  5058. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  5059. void copy_and_scalePID_i()
  5060. {
  5061. #ifdef PIDTEMP
  5062. Ki = scalePID_i(raw_Ki);
  5063. updatePID();
  5064. #endif
  5065. }
  5066. // Callback for after editing PID d value
  5067. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  5068. void copy_and_scalePID_d()
  5069. {
  5070. #ifdef PIDTEMP
  5071. Kd = scalePID_d(raw_Kd);
  5072. updatePID();
  5073. #endif
  5074. }
  5075. */
  5076. #endif //ULTRA_LCD