ultralcd.cpp 144 KB

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