ultralcd.cpp 101 KB

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