ultralcd.cpp 130 KB

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