ultralcd.cpp 89 KB

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