ultralcd.cpp 78 KB

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