ultralcd.cpp 91 KB

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