ultralcd.cpp 146 KB

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