ultralcd.cpp 78 KB

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