ultralcd.cpp 90 KB

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