ultralcd.cpp 79 KB

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