ultralcd.cpp 132 KB

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