ultralcd.cpp 153 KB

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