ultralcd.cpp 154 KB

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