ultralcd.cpp 138 KB

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