ultralcd.cpp 129 KB

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