ultralcd.cpp 127 KB

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