ultralcd.cpp 90 KB

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