My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.pde 65KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706
  1. #include "language.h"
  2. #include "temperature.h"
  3. #include "ultralcd.h"
  4. #ifdef ULTRA_LCD
  5. #include "Marlin.h"
  6. #include "language.h"
  7. #include "temperature.h"
  8. #include "EEPROMwrite.h"
  9. #include <LiquidCrystal.h>
  10. //===========================================================================
  11. //=============================imported variables============================
  12. //===========================================================================
  13. extern volatile int feedmultiply;
  14. extern volatile bool feedmultiplychanged;
  15. extern volatile int extrudemultiply;
  16. extern long position[4];
  17. #ifdef SDSUPPORT
  18. #include "cardreader.h"
  19. extern CardReader card;
  20. #endif
  21. //===========================================================================
  22. //=============================public variables============================
  23. //===========================================================================
  24. volatile char buttons=0; //the last checked buttons in a bit array.
  25. long encoderpos=0;
  26. short lastenc=0;
  27. //===========================================================================
  28. //=============================private variables============================
  29. //===========================================================================
  30. static char messagetext[LCD_WIDTH]="";
  31. //return for string conversion routines
  32. static char conv[8];
  33. LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7
  34. static unsigned long previous_millis_lcd=0;
  35. //static long previous_millis_buttons=0;
  36. #ifdef NEWPANEL
  37. static long blocking=0;
  38. #else
  39. static long blocking[8]={0,0,0,0,0,0,0,0};
  40. #endif
  41. static MainMenu menu;
  42. void lcdProgMemprint(const char *str)
  43. {
  44. char ch=pgm_read_byte(str);
  45. while(ch)
  46. {
  47. lcd.print(ch);
  48. ch=pgm_read_byte(++str);
  49. }
  50. }
  51. #define lcdprintPGM(x) lcdProgMemprint(MYPGM(x))
  52. //===========================================================================
  53. //=============================functions ============================
  54. //===========================================================================
  55. int intround(const float &x){return int(0.5+x);}
  56. void lcd_status(const char* message)
  57. {
  58. strncpy(messagetext,message,LCD_WIDTH);
  59. messagetext[strlen(message)]=0;
  60. }
  61. void lcd_statuspgm(const char* message)
  62. {
  63. char ch=pgm_read_byte(message);
  64. char *target=messagetext;
  65. uint8_t cnt=0;
  66. while(ch &&cnt<LCD_WIDTH)
  67. {
  68. *target=ch;
  69. target++;
  70. cnt++;
  71. ch=pgm_read_byte(++message);
  72. }
  73. *target=0;
  74. }
  75. void lcd_alertstatuspgm(const char* message)
  76. {
  77. lcd_statuspgm(message);
  78. menu.showStatus();
  79. }
  80. FORCE_INLINE void clear()
  81. {
  82. lcd.clear();
  83. }
  84. void lcd_init()
  85. {
  86. //beep();
  87. #ifdef ULTIPANEL
  88. buttons_init();
  89. #endif
  90. byte Degree[8] =
  91. {
  92. B01100,
  93. B10010,
  94. B10010,
  95. B01100,
  96. B00000,
  97. B00000,
  98. B00000,
  99. B00000
  100. };
  101. byte Thermometer[8] =
  102. {
  103. B00100,
  104. B01010,
  105. B01010,
  106. B01010,
  107. B01010,
  108. B10001,
  109. B10001,
  110. B01110
  111. };
  112. byte uplevel[8]={0x04, 0x0e, 0x1f, 0x04, 0x1c, 0x00, 0x00, 0x00};//thanks joris
  113. byte refresh[8]={0x00, 0x06, 0x19, 0x18, 0x03, 0x13, 0x0c, 0x00}; //thanks joris
  114. byte folder [8]={0x00, 0x1c, 0x1f, 0x11, 0x11, 0x1f, 0x00, 0x00}; //thanks joris
  115. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  116. lcd.createChar(1,Degree);
  117. lcd.createChar(2,Thermometer);
  118. lcd.createChar(3,uplevel);
  119. lcd.createChar(4,refresh);
  120. lcd.createChar(5,folder);
  121. LCD_MESSAGEPGM(WELCOME_MSG);
  122. }
  123. void beep()
  124. {
  125. //return;
  126. #ifdef ULTIPANEL
  127. #if (BEEPER > -1)
  128. {
  129. pinMode(BEEPER,OUTPUT);
  130. for(int8_t i=0;i<20;i++){
  131. WRITE(BEEPER,HIGH);
  132. delay(5);
  133. WRITE(BEEPER,LOW);
  134. delay(5);
  135. }
  136. }
  137. #endif
  138. #endif
  139. }
  140. void beepshort()
  141. {
  142. //return;
  143. #ifdef ULTIPANEL
  144. #if (BEEPER > -1)
  145. {
  146. pinMode(BEEPER,OUTPUT);
  147. for(int8_t i=0;i<10;i++){
  148. WRITE(BEEPER,HIGH);
  149. delay(3);
  150. WRITE(BEEPER,LOW);
  151. delay(3);
  152. }
  153. }
  154. #endif
  155. #endif
  156. }
  157. void lcd_status()
  158. {
  159. #ifdef ULTIPANEL
  160. static uint8_t oldbuttons=0;
  161. //static long previous_millis_buttons=0;
  162. //static long previous_lcdinit=0;
  163. // buttons_check(); // Done in temperature interrupt
  164. //previous_millis_buttons=millis();
  165. long ms=millis();
  166. for(int8_t i=0; i<8; i++) {
  167. #ifndef NEWPANEL
  168. if((blocking[i]>ms))
  169. buttons &= ~(1<<i);
  170. #else
  171. if((blocking>ms))
  172. buttons &= ~(1<<i);
  173. #endif
  174. }
  175. if((buttons==oldbuttons) && ((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  176. return;
  177. oldbuttons=buttons;
  178. #else
  179. if(((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  180. return;
  181. #endif
  182. previous_millis_lcd=millis();
  183. menu.update();
  184. }
  185. #ifdef ULTIPANEL
  186. void buttons_init()
  187. {
  188. #ifdef NEWPANEL
  189. pinMode(BTN_EN1,INPUT);
  190. pinMode(BTN_EN2,INPUT);
  191. pinMode(BTN_ENC,INPUT);
  192. pinMode(SDCARDDETECT,INPUT);
  193. WRITE(BTN_EN1,HIGH);
  194. WRITE(BTN_EN2,HIGH);
  195. WRITE(BTN_ENC,HIGH);
  196. #if (SDCARDDETECT > -1)
  197. {
  198. WRITE(SDCARDDETECT,HIGH);
  199. }
  200. #endif
  201. #else
  202. pinMode(SHIFT_CLK,OUTPUT);
  203. pinMode(SHIFT_LD,OUTPUT);
  204. pinMode(SHIFT_EN,OUTPUT);
  205. pinMode(SHIFT_OUT,INPUT);
  206. WRITE(SHIFT_OUT,HIGH);
  207. WRITE(SHIFT_LD,HIGH);
  208. WRITE(SHIFT_EN,LOW);
  209. #endif
  210. }
  211. void buttons_check()
  212. {
  213. #ifdef NEWPANEL
  214. uint8_t newbutton=0;
  215. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  216. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  217. if((blocking<millis()) &&(READ(BTN_ENC)==0))
  218. newbutton|=EN_C;
  219. buttons=newbutton;
  220. #else //read it from the shift register
  221. uint8_t newbutton=0;
  222. WRITE(SHIFT_LD,LOW);
  223. WRITE(SHIFT_LD,HIGH);
  224. unsigned char tmp_buttons=0;
  225. for(int8_t i=0;i<8;i++)
  226. {
  227. newbutton = newbutton>>1;
  228. if(READ(SHIFT_OUT))
  229. newbutton|=(1<<7);
  230. WRITE(SHIFT_CLK,HIGH);
  231. WRITE(SHIFT_CLK,LOW);
  232. }
  233. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  234. #endif
  235. //manage encoder rotation
  236. char enc=0;
  237. if(buttons&EN_A)
  238. enc|=(1<<0);
  239. if(buttons&EN_B)
  240. enc|=(1<<1);
  241. if(enc!=lastenc)
  242. {
  243. switch(enc)
  244. {
  245. case encrot0:
  246. if(lastenc==encrot3)
  247. encoderpos++;
  248. else if(lastenc==encrot1)
  249. encoderpos--;
  250. break;
  251. case encrot1:
  252. if(lastenc==encrot0)
  253. encoderpos++;
  254. else if(lastenc==encrot2)
  255. encoderpos--;
  256. break;
  257. case encrot2:
  258. if(lastenc==encrot1)
  259. encoderpos++;
  260. else if(lastenc==encrot3)
  261. encoderpos--;
  262. break;
  263. case encrot3:
  264. if(lastenc==encrot2)
  265. encoderpos++;
  266. else if(lastenc==encrot0)
  267. encoderpos--;
  268. break;
  269. default:
  270. ;
  271. }
  272. }
  273. lastenc=enc;
  274. }
  275. #endif
  276. MainMenu::MainMenu()
  277. {
  278. status=Main_Status;
  279. displayStartingRow=0;
  280. activeline=0;
  281. force_lcd_update=true;
  282. linechanging=false;
  283. tune=false;
  284. }
  285. void MainMenu::showStatus()
  286. {
  287. #if LCD_HEIGHT==4
  288. static int olddegHotEnd0=-1;
  289. static int oldtargetHotEnd0=-1;
  290. //force_lcd_update=true;
  291. if(force_lcd_update) //initial display of content
  292. {
  293. encoderpos=feedmultiply;
  294. clear();
  295. lcd.setCursor(0,0);lcdprintPGM("\002---/---\001 ");
  296. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  297. lcd.setCursor(10,0);lcdprintPGM("B---/---\001 ");
  298. #elif EXTRUDERS > 1
  299. lcd.setCursor(10,0);lcdprintPGM("\002---/---\001 ");
  300. #endif
  301. }
  302. int tHotEnd0=intround(degHotend0());
  303. if((tHotEnd0!=olddegHotEnd0)||force_lcd_update)
  304. {
  305. lcd.setCursor(1,0);
  306. lcd.print(ftostr3(tHotEnd0));
  307. olddegHotEnd0=tHotEnd0;
  308. }
  309. int ttHotEnd0=intround(degTargetHotend0());
  310. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  311. {
  312. lcd.setCursor(5,0);
  313. lcd.print(ftostr3(ttHotEnd0));
  314. oldtargetHotEnd0=ttHotEnd0;
  315. }
  316. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  317. static int oldtBed=-1;
  318. static int oldtargetBed=-1;
  319. int tBed=intround(degBed());
  320. if((tBed!=oldtBed)||force_lcd_update)
  321. {
  322. lcd.setCursor(11,0);
  323. lcd.print(ftostr3(tBed));
  324. oldtBed=tBed;
  325. }
  326. int targetBed=intround(degTargetBed());
  327. if((targetBed!=oldtargetBed)||force_lcd_update)
  328. {
  329. lcd.setCursor(15,0);
  330. lcd.print(ftostr3(targetBed));
  331. oldtargetBed=targetBed;
  332. }
  333. #elif EXTRUDERS > 1
  334. static int olddegHotEnd1=-1;
  335. static int oldtargetHotEnd1=-1;
  336. int tHotEnd1=intround(degHotend1());
  337. if((tHotEnd1!=olddegHotEnd1)||force_lcd_update)
  338. {
  339. lcd.setCursor(11,0);
  340. lcd.print(ftostr3(tHotEnd1));
  341. olddegHotEnd1=tHotEnd1;
  342. }
  343. int ttHotEnd1=intround(degTargetHotend1());
  344. if((ttHotEnd1!=oldtargetHotEnd1)||force_lcd_update)
  345. {
  346. lcd.setCursor(15,0);
  347. lcd.print(ftostr3(ttHotEnd1));
  348. oldtargetHotEnd1=ttHotEnd1;
  349. }
  350. #endif
  351. //starttime=2;
  352. static uint16_t oldtime=0;
  353. if(starttime!=0)
  354. {
  355. lcd.setCursor(0,1);
  356. uint16_t time=millis()/60000-starttime/60000;
  357. if(starttime!=oldtime)
  358. {
  359. lcd.print(itostr2(time/60));lcdprintPGM("h ");lcd.print(itostr2(time%60));lcdprintPGM("m");
  360. oldtime=time;
  361. }
  362. }
  363. static int oldzpos=0;
  364. int currentz=current_position[2]*100;
  365. if((currentz!=oldzpos)||force_lcd_update)
  366. {
  367. lcd.setCursor(10,1);
  368. lcdprintPGM("Z:");lcd.print(ftostr52(current_position[2]));
  369. oldzpos=currentz;
  370. }
  371. static int oldfeedmultiply=0;
  372. int curfeedmultiply=feedmultiply;
  373. if(feedmultiplychanged == true) {
  374. feedmultiplychanged = false;
  375. encoderpos = curfeedmultiply;
  376. }
  377. if(encoderpos!=curfeedmultiply||force_lcd_update)
  378. {
  379. curfeedmultiply=encoderpos;
  380. if(curfeedmultiply<10)
  381. curfeedmultiply=10;
  382. if(curfeedmultiply>999)
  383. curfeedmultiply=999;
  384. feedmultiply=curfeedmultiply;
  385. encoderpos=curfeedmultiply;
  386. }
  387. if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update)
  388. {
  389. oldfeedmultiply=curfeedmultiply;
  390. lcd.setCursor(0,2);
  391. lcd.print(itostr3(curfeedmultiply));lcdprintPGM("% ");
  392. }
  393. if(messagetext[0]!='\0')
  394. {
  395. lcd.setCursor(0,LCD_HEIGHT-1);
  396. lcd.print(messagetext);
  397. uint8_t n=strlen(messagetext);
  398. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  399. lcd.print(" ");
  400. messagetext[0]='\0';
  401. }
  402. #ifdef SDSUPPORT
  403. static uint8_t oldpercent=101;
  404. uint8_t percent=card.percentDone();
  405. if(oldpercent!=percent ||force_lcd_update)
  406. {
  407. lcd.setCursor(10,2);
  408. lcd.print(itostr3((int)percent));
  409. lcdprintPGM("%SD");
  410. }
  411. #endif
  412. #else //smaller LCDS----------------------------------
  413. static int olddegHotEnd0=-1;
  414. static int oldtargetHotEnd0=-1;
  415. if(force_lcd_update) //initial display of content
  416. {
  417. encoderpos=feedmultiply;
  418. lcd.setCursor(0,0);lcdprintPGM("\002---/---\001 ");
  419. }
  420. int tHotEnd0=intround(degHotend0());
  421. int ttHotEnd0=intround(degTargetHotend0());
  422. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update)
  423. {
  424. lcd.setCursor(1,0);
  425. lcd.print(ftostr3(tHotEnd0));
  426. olddegHotEnd0=tHotEnd0;
  427. }
  428. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  429. {
  430. lcd.setCursor(5,0);
  431. lcd.print(ftostr3(ttHotEnd0));
  432. oldtargetHotEnd0=ttHotEnd0;
  433. }
  434. if(messagetext[0]!='\0')
  435. {
  436. lcd.setCursor(0,LCD_HEIGHT-1);
  437. lcd.print(messagetext);
  438. uint8_t n=strlen(messagetext);
  439. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  440. lcd.print(" ");
  441. messagetext[0]='\0';
  442. }
  443. #endif
  444. force_lcd_update=false;
  445. }
  446. enum {ItemP_exit, ItemP_autostart,ItemP_disstep,ItemP_home, ItemP_origin, ItemP_preheat_pla, ItemP_preheat_abs, ItemP_cooldown,/*ItemP_extrude,*/ItemP_move};
  447. //any action must not contain a ',' character anywhere, or this breaks:
  448. #define MENUITEM(repaint_action, click_action) \
  449. {\
  450. if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  451. if((activeline==line) && CLICKED) {click_action} \
  452. }
  453. void MainMenu::showPrepare()
  454. {
  455. #ifdef ULTIPANEL
  456. uint8_t line=0;
  457. clearIfNecessary();
  458. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  459. {
  460. //Serial.println((int)(line-lineoffset));
  461. switch(i)
  462. {
  463. case ItemP_exit:
  464. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  465. break;
  466. case ItemP_autostart:
  467. MENUITEM( lcdprintPGM(MSG_AUTOSTART) , BLOCK;
  468. #ifdef SDSUPPORT
  469. card.lastnr=0;card.setroot();card.checkautostart(true);
  470. #endif
  471. beepshort(); ) ;
  472. break;
  473. case ItemP_disstep:
  474. MENUITEM( lcdprintPGM(MSG_DISABLE_STEPPERS) , BLOCK;enquecommand("M84");beepshort(); ) ;
  475. break;
  476. case ItemP_home:
  477. MENUITEM( lcdprintPGM(MSG_AUTO_HOME) , BLOCK;enquecommand("G28");beepshort(); ) ;
  478. break;
  479. case ItemP_origin:
  480. MENUITEM( lcdprintPGM(MSG_SET_ORIGIN) , BLOCK;enquecommand("G92 X0 Y0 Z0");beepshort(); ) ;
  481. break;
  482. case ItemP_preheat_pla:
  483. MENUITEM( lcdprintPGM(MSG_PREHEAT_PLA) , BLOCK;setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);setTargetBed(PLA_PREHEAT_HPB_TEMP);
  484. #if FAN_PIN > -1
  485. FanSpeed=PLA_PREHEAT_FAN_SPEED;
  486. analogWrite(FAN_PIN, FanSpeed);
  487. #endif
  488. beepshort(); );
  489. break;
  490. case ItemP_preheat_abs:
  491. MENUITEM( lcdprintPGM(MSG_PREHEAT_ABS) , BLOCK;setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);setTargetBed(ABS_PREHEAT_HPB_TEMP);
  492. #if FAN_PIN > -1
  493. FanSpeed=ABS_PREHEAT_FAN_SPEED;
  494. analogWrite(FAN_PIN, FanSpeed);
  495. #endif
  496. beepshort(); );
  497. break;
  498. case ItemP_cooldown:
  499. MENUITEM( lcdprintPGM(MSG_COOLDOWN) , BLOCK;setTargetHotend0(0);setTargetHotend1(0);setTargetHotend2(0);setTargetBed(0);beepshort(); ) ;
  500. break;
  501. // case ItemP_extrude:
  502. // MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E50");beepshort(); ) ;
  503. // break;
  504. case ItemP_move:
  505. MENUITEM( lcdprintPGM(MSG_MOVE_AXIS) , BLOCK;status=Sub_PrepareMove;beepshort(); );
  506. break;
  507. default:
  508. break;
  509. }
  510. line++;
  511. }
  512. updateActiveLines(ItemP_move,encoderpos);
  513. #endif
  514. }
  515. enum {
  516. ItemAM_exit,
  517. ItemAM_X, ItemAM_Y, ItemAM_Z, ItemAM_E, ItemAM_ERetract
  518. };
  519. void MainMenu::showAxisMove()
  520. {
  521. uint8_t line=0;
  522. int oldencoderpos=0;
  523. clearIfNecessary();
  524. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  525. {
  526. switch(i)
  527. {
  528. case ItemAM_exit:
  529. MENUITEM( lcdprintPGM(MSG_PREPARE_ALT) , BLOCK;status=Main_Prepare;beepshort(); ) ;
  530. break;
  531. case ItemAM_X:
  532. {
  533. //oldencoderpos=0;
  534. if(force_lcd_update)
  535. {
  536. lcd.setCursor(0,line);lcdprintPGM(" X:");
  537. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  538. }
  539. if((activeline!=line) )
  540. break;
  541. if(CLICKED)
  542. {
  543. linechanging=!linechanging;
  544. if(linechanging)
  545. {
  546. enquecommand("G91");
  547. }
  548. else
  549. {
  550. enquecommand("G90");
  551. encoderpos=activeline*lcdslow;
  552. beepshort();
  553. }
  554. BLOCK;
  555. }
  556. if(linechanging)
  557. {
  558. if (encoderpos >0)
  559. {
  560. enquecommand("G1 F700 X0.1");
  561. oldencoderpos=encoderpos;
  562. encoderpos=0;
  563. }
  564. else if (encoderpos < 0)
  565. {
  566. enquecommand("G1 F700 X-0.1");
  567. oldencoderpos=encoderpos;
  568. encoderpos=0;
  569. }
  570. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  571. }
  572. }
  573. break;
  574. case ItemAM_Y:
  575. {
  576. if(force_lcd_update)
  577. {
  578. lcd.setCursor(0,line);lcdprintPGM(" Y:");
  579. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  580. }
  581. if((activeline!=line) )
  582. break;
  583. if(CLICKED)
  584. {
  585. linechanging=!linechanging;
  586. if(linechanging)
  587. {
  588. enquecommand("G91");
  589. }
  590. else
  591. {
  592. enquecommand("G90");
  593. encoderpos=activeline*lcdslow;
  594. beepshort();
  595. }
  596. BLOCK;
  597. }
  598. if(linechanging)
  599. {
  600. if (encoderpos >0)
  601. {
  602. enquecommand("G1 F700 Y0.1");
  603. oldencoderpos=encoderpos;
  604. encoderpos=0;
  605. }
  606. else if (encoderpos < 0)
  607. {
  608. enquecommand("G1 F700 Y-0.1");
  609. oldencoderpos=encoderpos;
  610. encoderpos=0;
  611. }
  612. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  613. }
  614. }
  615. break;
  616. case ItemAM_Z:
  617. {
  618. if(force_lcd_update)
  619. {
  620. lcd.setCursor(0,line);lcdprintPGM(" Z:");
  621. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  622. }
  623. if((activeline!=line) )
  624. break;
  625. if(CLICKED)
  626. {
  627. linechanging=!linechanging;
  628. if(linechanging)
  629. {
  630. enquecommand("G91");
  631. }
  632. else
  633. {
  634. enquecommand("G90");
  635. encoderpos=activeline*lcdslow;
  636. beepshort();
  637. }
  638. BLOCK;
  639. }
  640. if(linechanging)
  641. {
  642. if (encoderpos >0)
  643. {
  644. enquecommand("G1 F70 Z0.1");
  645. oldencoderpos=encoderpos;
  646. encoderpos=0;
  647. }
  648. else if (encoderpos < 0)
  649. {
  650. enquecommand("G1 F70 Z-0.1");
  651. oldencoderpos=encoderpos;
  652. encoderpos=0;
  653. }
  654. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  655. }
  656. }
  657. break;
  658. case ItemAM_E:
  659. // ErikDB: TODO: this length should be changed for volumetric.
  660. MENUITEM( lcdprintPGM(MSG_EXTRUDE) , BLOCK;enquecommand("G92 E0");enquecommand("G1 F70 E1");beepshort(); ) ;
  661. break;
  662. case ItemAM_ERetract:
  663. // ErikDB: TODO: this length should be changed for volumetric.
  664. MENUITEM( lcdprintPGM(MSG_RETRACT) , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E-1");beepshort(); ) ;
  665. break;
  666. default:
  667. break;
  668. }
  669. line++;
  670. }
  671. updateActiveLines(ItemAM_ERetract,encoderpos);
  672. }
  673. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  674. #if (HEATER_BED_PIN > -1)
  675. ItemT_bed,
  676. #endif
  677. ItemT_fan};
  678. void MainMenu::showTune()
  679. {
  680. uint8_t line=0;
  681. clearIfNecessary();
  682. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  683. {
  684. //Serial.println((int)(line-lineoffset));
  685. switch(i)
  686. {
  687. case ItemT_exit:
  688. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  689. break;
  690. case ItemT_speed:
  691. {
  692. if(force_lcd_update)
  693. {
  694. lcd.setCursor(0,line);lcdprintPGM(MSG_SPEED);
  695. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  696. }
  697. if((activeline!=line) )
  698. break;
  699. if(CLICKED) //AnalogWrite(FAN_PIN, fanpwm);
  700. {
  701. linechanging=!linechanging;
  702. if(linechanging)
  703. {
  704. encoderpos=feedmultiply;
  705. }
  706. else
  707. {
  708. encoderpos=activeline*lcdslow;
  709. beepshort();
  710. }
  711. BLOCK;
  712. }
  713. if(linechanging)
  714. {
  715. if(encoderpos<1) encoderpos=1;
  716. if(encoderpos>400) encoderpos=400;
  717. feedmultiply = encoderpos;
  718. feedmultiplychanged=true;
  719. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  720. }
  721. }break;
  722. case ItemT_nozzle:
  723. {
  724. if(force_lcd_update)
  725. {
  726. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  727. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  728. }
  729. if((activeline!=line) )
  730. break;
  731. if(CLICKED)
  732. {
  733. linechanging=!linechanging;
  734. if(linechanging)
  735. {
  736. encoderpos=intround(degTargetHotend0());
  737. }
  738. else
  739. {
  740. setTargetHotend0(encoderpos);
  741. encoderpos=activeline*lcdslow;
  742. beepshort();
  743. }
  744. BLOCK;
  745. }
  746. if(linechanging)
  747. {
  748. if(encoderpos<0) encoderpos=0;
  749. if(encoderpos>260) encoderpos=260;
  750. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  751. }
  752. }break;
  753. #if (HEATER_BED_PIN > -1)
  754. case ItemT_bed:
  755. {
  756. if(force_lcd_update)
  757. {
  758. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  759. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  760. }
  761. if((activeline!=line) )
  762. break;
  763. if(CLICKED)
  764. {
  765. linechanging=!linechanging;
  766. if(linechanging)
  767. {
  768. encoderpos=intround(degTargetBed());
  769. }
  770. else
  771. {
  772. setTargetBed(encoderpos);
  773. encoderpos=activeline*lcdslow;
  774. beepshort();
  775. }
  776. BLOCK;
  777. }
  778. if(linechanging)
  779. {
  780. if(encoderpos<0) encoderpos=0;
  781. if(encoderpos>260) encoderpos=260;
  782. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  783. }
  784. }break;
  785. #endif
  786. case ItemT_fan:
  787. {
  788. if(force_lcd_update)
  789. {
  790. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  791. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  792. }
  793. if((activeline!=line) )
  794. break;
  795. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  796. {
  797. linechanging=!linechanging;
  798. if(linechanging)
  799. {
  800. encoderpos=FanSpeed;
  801. }
  802. else
  803. {
  804. encoderpos=activeline*lcdslow;
  805. beepshort();
  806. }
  807. BLOCK;
  808. }
  809. if(linechanging)
  810. {
  811. if(encoderpos<0) encoderpos=0;
  812. if(encoderpos>255) encoderpos=255;
  813. FanSpeed=encoderpos;
  814. analogWrite(FAN_PIN, FanSpeed);
  815. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  816. }
  817. }break;
  818. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  819. {
  820. if(force_lcd_update)
  821. {
  822. lcd.setCursor(0,line);lcdprintPGM(MSG_FLOW);
  823. lcd.setCursor(13,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
  824. }
  825. if((activeline!=line) )
  826. break;
  827. if(CLICKED)
  828. {
  829. linechanging=!linechanging;
  830. if(linechanging)
  831. {
  832. encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
  833. }
  834. else
  835. {
  836. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
  837. position[E_AXIS]=lround(position[E_AXIS]*factor);
  838. //current_position[E_AXIS]*=factor;
  839. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  840. encoderpos=activeline*lcdslow;
  841. }
  842. BLOCK;
  843. beepshort();
  844. }
  845. if(linechanging)
  846. {
  847. if(encoderpos<5) encoderpos=5;
  848. if(encoderpos>999999) encoderpos=999999;
  849. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.0));
  850. }
  851. }break;
  852. default:
  853. break;
  854. }
  855. line++;
  856. }
  857. updateActiveLines(ItemT_fan,encoderpos);
  858. }
  859. //does not work
  860. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  861. // {\
  862. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  863. // if(activeline==line) \
  864. // { \
  865. // if(CLICKED) \
  866. // { \
  867. // linechanging=!linechanging; \
  868. // if(linechanging) {enter_action;} \
  869. // else {accept_action;} \
  870. // } \
  871. // else \
  872. // if(linechanging) {change_action};}\
  873. // }
  874. //
  875. enum {
  876. ItemCT_exit,ItemCT_nozzle0,
  877. #ifdef AUTOTEMP
  878. ItemCT_autotempactive,
  879. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  880. #endif
  881. #if EXTRUDERS > 1
  882. ItemCT_nozzle1,
  883. #endif
  884. #if EXTRUDERS > 2
  885. ItemCT_nozzle2,
  886. #endif
  887. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  888. ItemCT_bed,
  889. #endif
  890. ItemCT_fan,
  891. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C
  892. };
  893. void MainMenu::showControlTemp()
  894. {
  895. uint8_t line=0;
  896. clearIfNecessary();
  897. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  898. {
  899. switch(i)
  900. {
  901. case ItemCT_exit:
  902. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  903. break;
  904. case ItemCT_nozzle0:
  905. {
  906. if(force_lcd_update)
  907. {
  908. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  909. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  910. }
  911. if((activeline!=line) )
  912. break;
  913. if(CLICKED)
  914. {
  915. linechanging=!linechanging;
  916. if(linechanging)
  917. {
  918. encoderpos=intround(degTargetHotend0());
  919. }
  920. else
  921. {
  922. setTargetHotend0(encoderpos);
  923. encoderpos=activeline*lcdslow;
  924. beepshort();
  925. }
  926. BLOCK;
  927. }
  928. if(linechanging)
  929. {
  930. if(encoderpos<0) encoderpos=0;
  931. if(encoderpos>260) encoderpos=260;
  932. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  933. }
  934. }break;
  935. #if EXTRUDERS > 1
  936. case ItemCT_nozzle1:
  937. {
  938. if(force_lcd_update)
  939. {
  940. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE1);
  941. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend1())));
  942. }
  943. if((activeline!=line) )
  944. break;
  945. if(CLICKED)
  946. {
  947. linechanging=!linechanging;
  948. if(linechanging)
  949. {
  950. encoderpos=intround(degTargetHotend1());
  951. }
  952. else
  953. {
  954. setTargetHotend1(encoderpos);
  955. encoderpos=activeline*lcdslow;
  956. beepshort();
  957. }
  958. BLOCK;
  959. }
  960. if(linechanging)
  961. {
  962. if(encoderpos<0) encoderpos=0;
  963. if(encoderpos>260) encoderpos=260;
  964. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  965. }
  966. }break;
  967. #endif
  968. #if EXTRUDERS > 2
  969. case ItemCT_nozzle2:
  970. {
  971. if(force_lcd_update)
  972. {
  973. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE2);
  974. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend2())));
  975. }
  976. if((activeline!=line) )
  977. break;
  978. if(CLICKED)
  979. {
  980. linechanging=!linechanging;
  981. if(linechanging)
  982. {
  983. encoderpos=intround(degTargetHotend2());
  984. }
  985. else
  986. {
  987. setTargetHotend1(encoderpos);
  988. encoderpos=activeline*lcdslow;
  989. beepshort();
  990. }
  991. BLOCK;
  992. }
  993. if(linechanging)
  994. {
  995. if(encoderpos<0) encoderpos=0;
  996. if(encoderpos>260) encoderpos=260;
  997. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  998. }
  999. }break;
  1000. #endif
  1001. #ifdef AUTOTEMP
  1002. case ItemCT_autotempmin:
  1003. {
  1004. if(force_lcd_update)
  1005. {
  1006. lcd.setCursor(0,line);lcdprintPGM(MSG_MIN);
  1007. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  1008. }
  1009. if((activeline!=line) )
  1010. break;
  1011. if(CLICKED)
  1012. {
  1013. linechanging=!linechanging;
  1014. if(linechanging)
  1015. {
  1016. encoderpos=intround(autotemp_min);
  1017. }
  1018. else
  1019. {
  1020. autotemp_min=encoderpos;
  1021. encoderpos=activeline*lcdslow;
  1022. beepshort();
  1023. }
  1024. BLOCK;
  1025. }
  1026. if(linechanging)
  1027. {
  1028. if(encoderpos<0) encoderpos=0;
  1029. if(encoderpos>260) encoderpos=260;
  1030. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1031. }
  1032. }break;
  1033. case ItemCT_autotempmax:
  1034. {
  1035. if(force_lcd_update)
  1036. {
  1037. lcd.setCursor(0,line);lcdprintPGM(MSG_MAX);
  1038. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  1039. }
  1040. if((activeline!=line) )
  1041. break;
  1042. if(CLICKED)
  1043. {
  1044. linechanging=!linechanging;
  1045. if(linechanging)
  1046. {
  1047. encoderpos=intround(autotemp_max);
  1048. }
  1049. else
  1050. {
  1051. autotemp_max=encoderpos;
  1052. encoderpos=activeline*lcdslow;
  1053. beepshort();
  1054. }
  1055. BLOCK;
  1056. }
  1057. if(linechanging)
  1058. {
  1059. if(encoderpos<0) encoderpos=0;
  1060. if(encoderpos>260) encoderpos=260;
  1061. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1062. }
  1063. }break;
  1064. case ItemCT_autotempfact:
  1065. {
  1066. if(force_lcd_update)
  1067. {
  1068. lcd.setCursor(0,line);lcdprintPGM(MSG_FACTOR);
  1069. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  1070. }
  1071. if((activeline!=line) )
  1072. break;
  1073. if(CLICKED)
  1074. {
  1075. linechanging=!linechanging;
  1076. if(linechanging)
  1077. {
  1078. encoderpos=intround(autotemp_factor*100);
  1079. }
  1080. else
  1081. {
  1082. autotemp_max=encoderpos;
  1083. encoderpos=activeline*lcdslow;
  1084. beepshort();
  1085. }
  1086. BLOCK;
  1087. }
  1088. if(linechanging)
  1089. {
  1090. if(encoderpos<0) encoderpos=0;
  1091. if(encoderpos>99) encoderpos=99;
  1092. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  1093. }
  1094. }break;
  1095. case ItemCT_autotempactive:
  1096. {
  1097. if(force_lcd_update)
  1098. {
  1099. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTOTEMP);
  1100. lcd.setCursor(13,line);
  1101. if(autotemp_enabled)
  1102. lcdprintPGM(MSG_ON);
  1103. else
  1104. lcdprintPGM(MSG_OFF);
  1105. }
  1106. if((activeline!=line) )
  1107. break;
  1108. if(CLICKED)
  1109. {
  1110. autotemp_enabled=!autotemp_enabled;
  1111. lcd.setCursor(13,line);
  1112. if(autotemp_enabled)
  1113. lcdprintPGM(MSG_ON);
  1114. else
  1115. lcdprintPGM(MSG_OFF);
  1116. BLOCK;
  1117. }
  1118. }break;
  1119. #endif //autotemp
  1120. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  1121. case ItemCT_bed:
  1122. {
  1123. if(force_lcd_update)
  1124. {
  1125. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  1126. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  1127. }
  1128. if((activeline!=line) )
  1129. break;
  1130. if(CLICKED)
  1131. {
  1132. linechanging=!linechanging;
  1133. if(linechanging)
  1134. {
  1135. encoderpos=intround(degTargetBed());
  1136. }
  1137. else
  1138. {
  1139. setTargetBed(encoderpos);
  1140. encoderpos=activeline*lcdslow;
  1141. beepshort();
  1142. }
  1143. BLOCK;
  1144. }
  1145. if(linechanging)
  1146. {
  1147. if(encoderpos<0) encoderpos=0;
  1148. if(encoderpos>260) encoderpos=260;
  1149. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1150. }
  1151. }break;
  1152. #endif
  1153. case ItemCT_fan:
  1154. {
  1155. if(force_lcd_update)
  1156. {
  1157. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  1158. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  1159. }
  1160. if((activeline!=line) )
  1161. break;
  1162. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  1163. {
  1164. linechanging=!linechanging;
  1165. if(linechanging)
  1166. {
  1167. encoderpos=FanSpeed;
  1168. }
  1169. else
  1170. {
  1171. encoderpos=activeline*lcdslow;
  1172. beepshort();
  1173. }
  1174. BLOCK;
  1175. }
  1176. if(linechanging)
  1177. {
  1178. if(encoderpos<0) encoderpos=0;
  1179. if(encoderpos>255) encoderpos=255;
  1180. FanSpeed=encoderpos;
  1181. analogWrite(FAN_PIN, FanSpeed);
  1182. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1183. }
  1184. }break;
  1185. #ifdef PIDTEMP
  1186. case ItemCT_PID_P:
  1187. {
  1188. if(force_lcd_update)
  1189. {
  1190. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  1191. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  1192. }
  1193. if((activeline!=line) )
  1194. break;
  1195. if(CLICKED)
  1196. {
  1197. linechanging=!linechanging;
  1198. if(linechanging)
  1199. {
  1200. encoderpos=(long)Kp;
  1201. }
  1202. else
  1203. {
  1204. Kp= encoderpos;
  1205. encoderpos=activeline*lcdslow;
  1206. }
  1207. BLOCK;
  1208. beepshort();
  1209. }
  1210. if(linechanging)
  1211. {
  1212. if(encoderpos<1) encoderpos=1;
  1213. if(encoderpos>9990) encoderpos=9990;
  1214. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1215. }
  1216. }break;
  1217. case ItemCT_PID_I:
  1218. {
  1219. if(force_lcd_update)
  1220. {
  1221. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_I);
  1222. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  1223. }
  1224. if((activeline!=line) )
  1225. break;
  1226. if(CLICKED)
  1227. {
  1228. linechanging=!linechanging;
  1229. if(linechanging)
  1230. {
  1231. encoderpos=(long)(Ki*10/PID_dT);
  1232. }
  1233. else
  1234. {
  1235. Ki= encoderpos/10.*PID_dT;
  1236. encoderpos=activeline*lcdslow;
  1237. }
  1238. BLOCK;
  1239. beepshort();
  1240. }
  1241. if(linechanging)
  1242. {
  1243. if(encoderpos<0) encoderpos=0;
  1244. if(encoderpos>9990) encoderpos=9990;
  1245. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  1246. }
  1247. }break;
  1248. case ItemCT_PID_D:
  1249. {
  1250. if(force_lcd_update)
  1251. {
  1252. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_D);
  1253. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  1254. }
  1255. if((activeline!=line) )
  1256. break;
  1257. if(CLICKED)
  1258. {
  1259. linechanging=!linechanging;
  1260. if(linechanging)
  1261. {
  1262. encoderpos=(long)(Kd/5./PID_dT);
  1263. }
  1264. else
  1265. {
  1266. Kd= encoderpos;
  1267. encoderpos=activeline*lcdslow;
  1268. }
  1269. BLOCK;
  1270. beepshort();
  1271. }
  1272. if(linechanging)
  1273. {
  1274. if(encoderpos<0) encoderpos=0;
  1275. if(encoderpos>9990) encoderpos=9990;
  1276. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1277. }
  1278. }break;
  1279. case ItemCT_PID_C:
  1280. #ifdef PID_ADD_EXTRUSION_RATE
  1281. {
  1282. if(force_lcd_update)
  1283. {
  1284. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_C);
  1285. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  1286. }
  1287. if((activeline!=line) )
  1288. break;
  1289. if(CLICKED)
  1290. {
  1291. linechanging=!linechanging;
  1292. if(linechanging)
  1293. {
  1294. encoderpos=(long)Kc;
  1295. }
  1296. else
  1297. {
  1298. Kc= encoderpos;
  1299. encoderpos=activeline*lcdslow;
  1300. }
  1301. BLOCK;
  1302. beepshort();
  1303. }
  1304. if(linechanging)
  1305. {
  1306. if(encoderpos<0) encoderpos=0;
  1307. if(encoderpos>990) encoderpos=990;
  1308. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1309. }
  1310. }
  1311. #endif
  1312. #endif
  1313. break;
  1314. default:
  1315. break;
  1316. }
  1317. line++;
  1318. }
  1319. #ifdef PID_ADD_EXTRUSION_RATE
  1320. updateActiveLines(ItemCT_PID_C,encoderpos);
  1321. #else
  1322. updateActiveLines(ItemCT_PID_D,encoderpos);
  1323. #endif
  1324. }
  1325. enum {
  1326. ItemCM_exit,
  1327. ItemCM_acc, ItemCM_xyjerk,
  1328. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1329. ItemCM_vtravmin,ItemCM_vmin,
  1330. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1331. ItemCM_aret, ItemCM_xsteps,ItemCM_ysteps, ItemCM_zsteps, ItemCM_esteps
  1332. };
  1333. void MainMenu::showControlMotion()
  1334. {
  1335. uint8_t line=0;
  1336. clearIfNecessary();
  1337. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1338. {
  1339. switch(i)
  1340. {
  1341. case ItemCM_exit:
  1342. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1343. break;
  1344. case ItemCM_acc:
  1345. {
  1346. if(force_lcd_update)
  1347. {
  1348. lcd.setCursor(0,line);lcdprintPGM(MSG_ACC);
  1349. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1350. }
  1351. if((activeline!=line) )
  1352. break;
  1353. if(CLICKED)
  1354. {
  1355. linechanging=!linechanging;
  1356. if(linechanging)
  1357. {
  1358. encoderpos=(long)acceleration/100;
  1359. }
  1360. else
  1361. {
  1362. acceleration= encoderpos*100;
  1363. encoderpos=activeline*lcdslow;
  1364. }
  1365. BLOCK;
  1366. beepshort();
  1367. }
  1368. if(linechanging)
  1369. {
  1370. if(encoderpos<5) encoderpos=5;
  1371. if(encoderpos>990) encoderpos=990;
  1372. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1373. }
  1374. }break;
  1375. case ItemCM_xyjerk: //max_xy_jerk
  1376. {
  1377. if(force_lcd_update)
  1378. {
  1379. lcd.setCursor(0,line);lcdprintPGM(MSG_VXY_JERK);
  1380. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1381. }
  1382. if((activeline!=line) )
  1383. break;
  1384. if(CLICKED)
  1385. {
  1386. linechanging=!linechanging;
  1387. if(linechanging)
  1388. {
  1389. encoderpos=(long)max_xy_jerk;
  1390. }
  1391. else
  1392. {
  1393. max_xy_jerk= encoderpos;
  1394. encoderpos=activeline*lcdslow;
  1395. }
  1396. BLOCK;
  1397. beepshort();
  1398. }
  1399. if(linechanging)
  1400. {
  1401. if(encoderpos<1) encoderpos=1;
  1402. if(encoderpos>990) encoderpos=990;
  1403. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1404. }
  1405. }break;
  1406. case ItemCM_vmaxx:
  1407. case ItemCM_vmaxy:
  1408. case ItemCM_vmaxz:
  1409. case ItemCM_vmaxe:
  1410. {
  1411. if(force_lcd_update)
  1412. {
  1413. lcd.setCursor(0,line);lcdprintPGM(MSG_VMAX);
  1414. if(i==ItemCM_vmaxx)lcdprintPGM(MSG_X);
  1415. if(i==ItemCM_vmaxy)lcdprintPGM(MSG_Y);
  1416. if(i==ItemCM_vmaxz)lcdprintPGM(MSG_Z);
  1417. if(i==ItemCM_vmaxe)lcdprintPGM(MSG_E);
  1418. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1419. }
  1420. if((activeline!=line) )
  1421. break;
  1422. if(CLICKED)
  1423. {
  1424. linechanging=!linechanging;
  1425. if(linechanging)
  1426. {
  1427. encoderpos=(long)max_feedrate[i-ItemCM_vmaxx];
  1428. }
  1429. else
  1430. {
  1431. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1432. encoderpos=activeline*lcdslow;
  1433. }
  1434. BLOCK;
  1435. beepshort();
  1436. }
  1437. if(linechanging)
  1438. {
  1439. if(encoderpos<1) encoderpos=1;
  1440. if(encoderpos>990) encoderpos=990;
  1441. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1442. }
  1443. }break;
  1444. case ItemCM_vmin:
  1445. {
  1446. if(force_lcd_update)
  1447. {
  1448. lcd.setCursor(0,line);lcdprintPGM(MSG_VMIN);
  1449. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1450. }
  1451. if((activeline!=line) )
  1452. break;
  1453. if(CLICKED)
  1454. {
  1455. linechanging=!linechanging;
  1456. if(linechanging)
  1457. {
  1458. encoderpos=(long)(minimumfeedrate);
  1459. }
  1460. else
  1461. {
  1462. minimumfeedrate= encoderpos;
  1463. encoderpos=activeline*lcdslow;
  1464. }
  1465. BLOCK;
  1466. beepshort();
  1467. }
  1468. if(linechanging)
  1469. {
  1470. if(encoderpos<0) encoderpos=0;
  1471. if(encoderpos>990) encoderpos=990;
  1472. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1473. }
  1474. }break;
  1475. case ItemCM_vtravmin:
  1476. {
  1477. if(force_lcd_update)
  1478. {
  1479. lcd.setCursor(0,line);lcdprintPGM(MSG_VTRAV_MIN);
  1480. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1481. }
  1482. if((activeline!=line) )
  1483. break;
  1484. if(CLICKED)
  1485. {
  1486. linechanging=!linechanging;
  1487. if(linechanging)
  1488. {
  1489. encoderpos=(long)mintravelfeedrate;
  1490. }
  1491. else
  1492. {
  1493. mintravelfeedrate= encoderpos;
  1494. encoderpos=activeline*lcdslow;
  1495. }
  1496. BLOCK;
  1497. beepshort();
  1498. }
  1499. if(linechanging)
  1500. {
  1501. if(encoderpos<0) encoderpos=0;
  1502. if(encoderpos>990) encoderpos=990;
  1503. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1504. }
  1505. }break;
  1506. case ItemCM_amaxx:
  1507. case ItemCM_amaxy:
  1508. case ItemCM_amaxz:
  1509. case ItemCM_amaxe:
  1510. {
  1511. if(force_lcd_update)
  1512. {
  1513. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1514. if(i==ItemCM_amaxx)lcdprintPGM(MSG_X);
  1515. if(i==ItemCM_amaxy)lcdprintPGM(MSG_Y);
  1516. if(i==ItemCM_amaxz)lcdprintPGM(MSG_Z);
  1517. if(i==ItemCM_amaxe)lcdprintPGM(MSG_E);
  1518. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1519. }
  1520. if((activeline!=line) )
  1521. break;
  1522. if(CLICKED)
  1523. {
  1524. linechanging=!linechanging;
  1525. if(linechanging)
  1526. {
  1527. encoderpos=(long)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1528. }
  1529. else
  1530. {
  1531. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1532. encoderpos=activeline*lcdslow;
  1533. }
  1534. BLOCK;
  1535. beepshort();
  1536. }
  1537. if(linechanging)
  1538. {
  1539. if(encoderpos<1) encoderpos=1;
  1540. if(encoderpos>990) encoderpos=990;
  1541. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1542. }
  1543. }break;
  1544. case ItemCM_aret://float retract_acceleration = 7000;
  1545. {
  1546. if(force_lcd_update)
  1547. {
  1548. lcd.setCursor(0,line);lcdprintPGM(MSG_A_RETRACT);
  1549. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1550. }
  1551. if((activeline!=line) )
  1552. break;
  1553. if(CLICKED)
  1554. {
  1555. linechanging=!linechanging;
  1556. if(linechanging)
  1557. {
  1558. encoderpos=(long)retract_acceleration/100;
  1559. }
  1560. else
  1561. {
  1562. retract_acceleration= encoderpos*100;
  1563. encoderpos=activeline*lcdslow;
  1564. }
  1565. BLOCK;
  1566. beepshort();
  1567. }
  1568. if(linechanging)
  1569. {
  1570. if(encoderpos<10) encoderpos=10;
  1571. if(encoderpos>990) encoderpos=990;
  1572. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1573. }
  1574. }break;
  1575. case ItemCM_xsteps://axis_steps_per_unit[i] = code_value();
  1576. {
  1577. if(force_lcd_update)
  1578. {
  1579. lcd.setCursor(0,line);lcdprintPGM(MSG_XSTEPS);
  1580. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[X_AXIS]));
  1581. }
  1582. if((activeline!=line) )
  1583. break;
  1584. if(CLICKED)
  1585. {
  1586. linechanging=!linechanging;
  1587. if(linechanging)
  1588. {
  1589. encoderpos=(long)(axis_steps_per_unit[X_AXIS]*100.0);
  1590. }
  1591. else
  1592. {
  1593. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[X_AXIS]);
  1594. position[X_AXIS]=lround(position[X_AXIS]*factor);
  1595. //current_position[X_AXIS]*=factor;
  1596. axis_steps_per_unit[X_AXIS]= encoderpos/100.0;
  1597. encoderpos=activeline*lcdslow;
  1598. }
  1599. BLOCK;
  1600. beepshort();
  1601. }
  1602. if(linechanging)
  1603. {
  1604. if(encoderpos<5) encoderpos=5;
  1605. if(encoderpos>999999) encoderpos=999999;
  1606. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1607. }
  1608. }break;
  1609. case ItemCM_ysteps://axis_steps_per_unit[i] = code_value();
  1610. {
  1611. if(force_lcd_update)
  1612. {
  1613. lcd.setCursor(0,line);lcdprintPGM(MSG_YSTEPS);
  1614. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Y_AXIS]));
  1615. }
  1616. if((activeline!=line) )
  1617. break;
  1618. if(CLICKED)
  1619. {
  1620. linechanging=!linechanging;
  1621. if(linechanging)
  1622. {
  1623. encoderpos=(long)(axis_steps_per_unit[Y_AXIS]*100.0);
  1624. }
  1625. else
  1626. {
  1627. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Y_AXIS]);
  1628. position[Y_AXIS]=lround(position[Y_AXIS]*factor);
  1629. //current_position[Y_AXIS]*=factor;
  1630. axis_steps_per_unit[Y_AXIS]= encoderpos/100.0;
  1631. encoderpos=activeline*lcdslow;
  1632. }
  1633. BLOCK;
  1634. beepshort();
  1635. }
  1636. if(linechanging)
  1637. {
  1638. if(encoderpos<5) encoderpos=5;
  1639. if(encoderpos>999999) encoderpos=999999;
  1640. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1641. }
  1642. }break;
  1643. case ItemCM_zsteps://axis_steps_per_unit[i] = code_value();
  1644. {
  1645. if(force_lcd_update)
  1646. {
  1647. lcd.setCursor(0,line);lcdprintPGM(MSG_ZSTEPS);
  1648. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Z_AXIS]));
  1649. }
  1650. if((activeline!=line) )
  1651. break;
  1652. if(CLICKED)
  1653. {
  1654. linechanging=!linechanging;
  1655. if(linechanging)
  1656. {
  1657. encoderpos=(long)(axis_steps_per_unit[Z_AXIS]*100.0);
  1658. }
  1659. else
  1660. {
  1661. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Z_AXIS]);
  1662. position[Z_AXIS]=lround(position[Z_AXIS]*factor);
  1663. //current_position[Z_AXIS]*=factor;
  1664. axis_steps_per_unit[Z_AXIS]= encoderpos/100.0;
  1665. encoderpos=activeline*lcdslow;
  1666. }
  1667. BLOCK;
  1668. beepshort();
  1669. }
  1670. if(linechanging)
  1671. {
  1672. if(encoderpos<5) encoderpos=5;
  1673. if(encoderpos>999999) encoderpos=999999;
  1674. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1675. }
  1676. }break;
  1677. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1678. {
  1679. if(force_lcd_update)
  1680. {
  1681. lcd.setCursor(0,line);lcdprintPGM(MSG_ESTEPS);
  1682. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
  1683. }
  1684. if((activeline!=line) )
  1685. break;
  1686. if(CLICKED)
  1687. {
  1688. linechanging=!linechanging;
  1689. if(linechanging)
  1690. {
  1691. encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
  1692. }
  1693. else
  1694. {
  1695. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
  1696. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1697. //current_position[E_AXIS]*=factor;
  1698. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  1699. encoderpos=activeline*lcdslow;
  1700. }
  1701. BLOCK;
  1702. beepshort();
  1703. }
  1704. if(linechanging)
  1705. {
  1706. if(encoderpos<5) encoderpos=5;
  1707. if(encoderpos>999999) encoderpos=999999;
  1708. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1709. }
  1710. }break;
  1711. default:
  1712. break;
  1713. }
  1714. line++;
  1715. }
  1716. updateActiveLines(ItemCM_esteps,encoderpos);
  1717. }
  1718. enum {
  1719. ItemR_exit,
  1720. ItemR_autoretract,
  1721. ItemR_retract_length,ItemR_retract_feedrate,ItemR_retract_zlift,
  1722. ItemR_unretract_length,ItemR_unretract_feedrate,
  1723. };
  1724. void MainMenu::showControlRetract()
  1725. {
  1726. #ifdef FWRETRACT
  1727. uint8_t line=0;
  1728. clearIfNecessary();
  1729. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1730. {
  1731. switch(i)
  1732. {
  1733. case ItemR_exit:
  1734. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1735. break;
  1736. //float retract_length=2, retract_feedrate=1200, retract_zlift=0.4;
  1737. //float retract_recover_length=0, retract_recover_feedrate=500;
  1738. case ItemR_autoretract:
  1739. {
  1740. if(force_lcd_update)
  1741. {
  1742. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTORETRACT);
  1743. lcd.setCursor(13,line);
  1744. if(autoretract_enabled)
  1745. lcdprintPGM(MSG_ON);
  1746. else
  1747. lcdprintPGM(MSG_OFF);
  1748. }
  1749. if((activeline!=line) )
  1750. break;
  1751. if(CLICKED)
  1752. {
  1753. autoretract_enabled=!autoretract_enabled;
  1754. lcd.setCursor(13,line);
  1755. if(autoretract_enabled)
  1756. lcdprintPGM(MSG_ON);
  1757. else
  1758. lcdprintPGM(MSG_OFF);
  1759. BLOCK;
  1760. }
  1761. }break;
  1762. case ItemR_retract_length:
  1763. {
  1764. if(force_lcd_update)
  1765. {
  1766. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT);
  1767. lcd.setCursor(13,line);lcd.print(ftostr52(retract_length));
  1768. }
  1769. if((activeline!=line) )
  1770. break;
  1771. if(CLICKED)
  1772. {
  1773. linechanging=!linechanging;
  1774. if(linechanging)
  1775. {
  1776. encoderpos=(long)(retract_length*100);
  1777. }
  1778. else
  1779. {
  1780. retract_length= encoderpos/100.;
  1781. encoderpos=activeline*lcdslow;
  1782. }
  1783. BLOCK;
  1784. beepshort();
  1785. }
  1786. if(linechanging)
  1787. {
  1788. if(encoderpos<1) encoderpos=1;
  1789. if(encoderpos>990) encoderpos=990;
  1790. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
  1791. }
  1792. }break;
  1793. case ItemR_retract_feedrate:
  1794. {
  1795. if(force_lcd_update)
  1796. {
  1797. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACTF);
  1798. lcd.setCursor(13,line);lcd.print(itostr4(retract_feedrate));
  1799. }
  1800. if((activeline!=line) )
  1801. break;
  1802. if(CLICKED)
  1803. {
  1804. linechanging=!linechanging;
  1805. if(linechanging)
  1806. {
  1807. encoderpos=(long)(retract_feedrate/5);
  1808. }
  1809. else
  1810. {
  1811. retract_feedrate= encoderpos*5.;
  1812. encoderpos=activeline*lcdslow;
  1813. }
  1814. BLOCK;
  1815. beepshort();
  1816. }
  1817. if(linechanging)
  1818. {
  1819. if(encoderpos<1) encoderpos=1;
  1820. if(encoderpos>990) encoderpos=990;
  1821. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  1822. }
  1823. }break;
  1824. case ItemR_retract_zlift://float retract_acceleration = 7000;
  1825. {
  1826. if(force_lcd_update)
  1827. {
  1828. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_ZLIFT);
  1829. lcd.setCursor(13,line);lcd.print(ftostr52(retract_zlift));;
  1830. }
  1831. if((activeline!=line) )
  1832. break;
  1833. if(CLICKED)
  1834. {
  1835. linechanging=!linechanging;
  1836. if(linechanging)
  1837. {
  1838. encoderpos=(long)(retract_zlift*10);
  1839. }
  1840. else
  1841. {
  1842. retract_zlift= encoderpos/10.;
  1843. encoderpos=activeline*lcdslow;
  1844. }
  1845. BLOCK;
  1846. beepshort();
  1847. }
  1848. if(linechanging)
  1849. {
  1850. if(encoderpos<0) encoderpos=0;
  1851. if(encoderpos>990) encoderpos=990;
  1852. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/10.));
  1853. }
  1854. }break;
  1855. case ItemR_unretract_length:
  1856. {
  1857. if(force_lcd_update)
  1858. {
  1859. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVER);
  1860. lcd.setCursor(13,line);lcd.print(ftostr52(retract_recover_length));;
  1861. }
  1862. if((activeline!=line) )
  1863. break;
  1864. if(CLICKED)
  1865. {
  1866. linechanging=!linechanging;
  1867. if(linechanging)
  1868. {
  1869. encoderpos=(long)(retract_recover_length*100);
  1870. }
  1871. else
  1872. {
  1873. retract_recover_length= encoderpos/100.;
  1874. encoderpos=activeline*lcdslow;
  1875. }
  1876. BLOCK;
  1877. beepshort();
  1878. }
  1879. if(linechanging)
  1880. {
  1881. if(encoderpos<0) encoderpos=0;
  1882. if(encoderpos>990) encoderpos=990;
  1883. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
  1884. }
  1885. }break;
  1886. case ItemR_unretract_feedrate:
  1887. {
  1888. if(force_lcd_update)
  1889. {
  1890. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVERF);
  1891. lcd.setCursor(13,line);lcd.print(itostr4(retract_recover_feedrate));
  1892. }
  1893. if((activeline!=line) )
  1894. break;
  1895. if(CLICKED)
  1896. {
  1897. linechanging=!linechanging;
  1898. if(linechanging)
  1899. {
  1900. encoderpos=(long)retract_recover_feedrate/5;
  1901. }
  1902. else
  1903. {
  1904. retract_recover_feedrate= encoderpos*5.;
  1905. encoderpos=activeline*lcdslow;
  1906. }
  1907. BLOCK;
  1908. beepshort();
  1909. }
  1910. if(linechanging)
  1911. {
  1912. if(encoderpos<1) encoderpos=1;
  1913. if(encoderpos>990) encoderpos=990;
  1914. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  1915. }
  1916. }break;
  1917. default:
  1918. break;
  1919. }
  1920. line++;
  1921. }
  1922. updateActiveLines(ItemR_unretract_feedrate,encoderpos);
  1923. #endif
  1924. }
  1925. enum {
  1926. ItemC_exit,ItemC_temp,ItemC_move,
  1927. #ifdef FWRETRACT
  1928. ItemC_rectract,
  1929. #endif
  1930. ItemC_store, ItemC_load,ItemC_failsafe
  1931. };
  1932. void MainMenu::showControl()
  1933. {
  1934. uint8_t line=0;
  1935. clearIfNecessary();
  1936. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1937. {
  1938. switch(i)
  1939. {
  1940. case ItemC_exit:
  1941. MENUITEM( lcdprintPGM(MSG_MAIN_WIDE) , BLOCK;status=Main_Menu;beepshort(); ) ;
  1942. break;
  1943. case ItemC_temp:
  1944. MENUITEM( lcdprintPGM(MSG_TEMPERATURE_WIDE) , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1945. break;
  1946. case ItemC_move:
  1947. MENUITEM( lcdprintPGM(MSG_MOTION_WIDE) , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1948. break;
  1949. #ifdef FWRETRACT
  1950. case ItemC_rectract:
  1951. MENUITEM( lcdprintPGM(MSG_RECTRACT_WIDE) , BLOCK;status=Sub_RetractControl;beepshort(); ) ;
  1952. break;
  1953. #endif
  1954. case ItemC_store:
  1955. {
  1956. if(force_lcd_update)
  1957. {
  1958. lcd.setCursor(0,line);lcdprintPGM(MSG_STORE_EPROM);
  1959. }
  1960. if((activeline==line) && CLICKED)
  1961. {
  1962. //enquecommand("M84");
  1963. beepshort();
  1964. BLOCK;
  1965. EEPROM_StoreSettings();
  1966. }
  1967. }break;
  1968. case ItemC_load:
  1969. {
  1970. if(force_lcd_update)
  1971. {
  1972. lcd.setCursor(0,line);lcdprintPGM(MSG_LOAD_EPROM);
  1973. }
  1974. if((activeline==line) && CLICKED)
  1975. {
  1976. //enquecommand("M84");
  1977. beepshort();
  1978. BLOCK;
  1979. EEPROM_RetrieveSettings();
  1980. }
  1981. }break;
  1982. case ItemC_failsafe:
  1983. {
  1984. if(force_lcd_update)
  1985. {
  1986. lcd.setCursor(0,line);lcdprintPGM(MSG_RESTORE_FAILSAFE);
  1987. }
  1988. if((activeline==line) && CLICKED)
  1989. {
  1990. //enquecommand("M84");
  1991. beepshort();
  1992. BLOCK;
  1993. EEPROM_RetrieveSettings(true);
  1994. }
  1995. }break;
  1996. default:
  1997. break;
  1998. }
  1999. line++;
  2000. }
  2001. updateActiveLines(ItemC_failsafe,encoderpos);
  2002. }
  2003. void MainMenu::showSD()
  2004. {
  2005. #ifdef SDSUPPORT
  2006. uint8_t line=0;
  2007. clearIfNecessary();
  2008. static uint8_t nrfiles=0;
  2009. if(force_lcd_update)
  2010. {
  2011. if(card.cardOK)
  2012. {
  2013. nrfiles=card.getnrfilenames();
  2014. }
  2015. else
  2016. {
  2017. nrfiles=0;
  2018. lineoffset=0;
  2019. }
  2020. }
  2021. bool enforceupdate=false;
  2022. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2023. {
  2024. switch(i)
  2025. {
  2026. case 0:
  2027. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  2028. break;
  2029. // case 1:
  2030. // {
  2031. // if(force_lcd_update)
  2032. // {
  2033. // lcd.setCursor(0,line);
  2034. // #ifdef CARDINSERTED
  2035. // if(CARDINSERTED)
  2036. // #else
  2037. // if(true)
  2038. // #endif
  2039. // {
  2040. // lcdprintPGM(" \004Refresh");
  2041. // }
  2042. // else
  2043. // {
  2044. // lcdprintPGM(" \004Insert Card");
  2045. // }
  2046. //
  2047. // }
  2048. // if((activeline==line) && CLICKED)
  2049. // {
  2050. // BLOCK;
  2051. // beepshort();
  2052. // card.initsd();
  2053. // force_lcd_update=true;
  2054. // nrfiles=card.getnrfilenames();
  2055. // }
  2056. // }break;
  2057. case 1:
  2058. MENUITEM( lcd.print(" ");card.getWorkDirName();
  2059. if(card.filename[0]=='/') lcdprintPGM(MSG_REFRESH);
  2060. else {
  2061. lcd.print("\005");
  2062. lcd.print(card.filename);
  2063. lcd.print("/..");
  2064. } ,
  2065. BLOCK;
  2066. if(SDCARDDETECT == -1) card.initsd();
  2067. card.updir();
  2068. enforceupdate=true;
  2069. lineoffset=0;
  2070. beepshort(); ) ;
  2071. break;
  2072. default:
  2073. {
  2074. #define FIRSTITEM 2
  2075. if(i-FIRSTITEM<nrfiles)
  2076. {
  2077. if(force_lcd_update)
  2078. {
  2079. card.getfilename(i-FIRSTITEM);
  2080. //Serial.print("Filenr:");Serial.println(i-2);
  2081. lcd.setCursor(0,line);lcdprintPGM(" ");
  2082. if(card.filenameIsDir) lcd.print("\005");
  2083. lcd.print(card.filename);
  2084. }
  2085. if((activeline==line) && CLICKED)
  2086. {
  2087. BLOCK
  2088. card.getfilename(i-FIRSTITEM);
  2089. if(card.filenameIsDir)
  2090. {
  2091. for(int8_t i=0;i<strlen(card.filename);i++)
  2092. card.filename[i]=tolower(card.filename[i]);
  2093. card.chdir(card.filename);
  2094. lineoffset=0;
  2095. enforceupdate=true;
  2096. }
  2097. else
  2098. {
  2099. char cmd[30];
  2100. for(int8_t i=0;i<strlen(card.filename);i++)
  2101. card.filename[i]=tolower(card.filename[i]);
  2102. sprintf(cmd,"M23 %s",card.filename);
  2103. //sprintf(cmd,"M115");
  2104. enquecommand(cmd);
  2105. enquecommand("M24");
  2106. beep();
  2107. status=Main_Status;
  2108. lcd_status(card.filename);
  2109. }
  2110. }
  2111. }
  2112. }
  2113. break;
  2114. }
  2115. line++;
  2116. }
  2117. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  2118. if(enforceupdate)
  2119. {
  2120. force_lcd_update=true;
  2121. enforceupdate=false;
  2122. }
  2123. #endif
  2124. }
  2125. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file, ItemM_pause};
  2126. void MainMenu::showMainMenu()
  2127. {
  2128. #ifndef ULTIPANEL
  2129. force_lcd_update=false;
  2130. #endif
  2131. if(tune)
  2132. {
  2133. if(!(movesplanned() || IS_SD_PRINTING))
  2134. {
  2135. force_lcd_update=true;
  2136. tune=false;
  2137. }
  2138. }
  2139. else
  2140. {
  2141. if(movesplanned() || IS_SD_PRINTING)
  2142. {
  2143. force_lcd_update=true;
  2144. tune=true;
  2145. }
  2146. }
  2147. clearIfNecessary();
  2148. uint8_t line=0;
  2149. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2150. {
  2151. switch(i)
  2152. {
  2153. case ItemM_watch:
  2154. MENUITEM( lcdprintPGM(MSG_WATCH) , BLOCK;status=Main_Status;beepshort(); ) ;
  2155. break;
  2156. case ItemM_prepare:
  2157. MENUITEM( if(!tune) lcdprintPGM(MSG_PREPARE);else lcdprintPGM(MSG_TUNE); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  2158. break;
  2159. case ItemM_control:
  2160. MENUITEM( lcdprintPGM(MSG_CONTROL_ARROW) , BLOCK;status=Main_Control;beepshort(); ) ;
  2161. break;
  2162. #ifdef SDSUPPORT
  2163. case ItemM_file:
  2164. {
  2165. if(force_lcd_update)
  2166. {
  2167. lcd.setCursor(0,line);
  2168. #ifdef CARDINSERTED
  2169. if(CARDINSERTED)
  2170. #else
  2171. if(true)
  2172. #endif
  2173. {
  2174. if(card.sdprinting)
  2175. lcdprintPGM(MSG_STOP_PRINT);
  2176. else
  2177. lcdprintPGM(MSG_CARD_MENU);
  2178. }
  2179. else
  2180. {
  2181. lcdprintPGM(MSG_NO_CARD);
  2182. }
  2183. }
  2184. #ifdef CARDINSERTED
  2185. if(CARDINSERTED)
  2186. #endif
  2187. if((activeline==line)&&CLICKED)
  2188. {
  2189. card.printingHasFinished();
  2190. BLOCK;
  2191. status=Main_SD;
  2192. beepshort();
  2193. }
  2194. }break;
  2195. case ItemM_pause:
  2196. {
  2197. if(force_lcd_update)
  2198. {
  2199. lcd.setCursor(0,line);
  2200. #ifdef CARDINSERTED
  2201. if(CARDINSERTED)
  2202. #else
  2203. if(true)
  2204. #endif
  2205. {
  2206. if(card.sdprinting)
  2207. lcdprintPGM(MSG_PAUSE_PRINT);
  2208. else
  2209. lcdprintPGM(MSG_RESUME_PRINT);
  2210. }
  2211. else
  2212. {
  2213. //lcdprintPGM(MSG_NO_CARD);
  2214. }
  2215. }
  2216. #ifdef CARDINSERTED
  2217. if(CARDINSERTED)
  2218. #endif
  2219. if((activeline==line) && CLICKED)
  2220. {
  2221. if(card.sdprinting)
  2222. {
  2223. card.pauseSDPrint();
  2224. beepshort();
  2225. status = Main_Status;
  2226. }
  2227. else
  2228. {
  2229. card.startFileprint();
  2230. starttime=millis();
  2231. beepshort();
  2232. status = Main_Status;
  2233. }
  2234. }
  2235. }break;
  2236. #else
  2237. case ItemM_file:
  2238. break;
  2239. case ItemM_pause:
  2240. break;
  2241. #endif
  2242. default:
  2243. SERIAL_ERROR_START;
  2244. SERIAL_ERRORLNPGM(MSG_SERIAL_ERROR_MENU_STRUCTURE);
  2245. break;
  2246. }
  2247. line++;
  2248. }
  2249. uint8_t numberOfLines = 4;
  2250. #ifdef SDSUPPORT
  2251. numberOfLines = 4;
  2252. #else
  2253. numberOfLines = 3;
  2254. #endif
  2255. updateActiveLines(numberOfLines,encoderpos);
  2256. }
  2257. void MainMenu::update()
  2258. {
  2259. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  2260. static long timeoutToStatus=0;
  2261. static bool oldcardstatus=false;
  2262. #ifdef CARDINSERTED
  2263. if((CARDINSERTED != oldcardstatus))
  2264. {
  2265. force_lcd_update=true;
  2266. oldcardstatus=CARDINSERTED;
  2267. lcd_init(); // to maybe revive the lcd if static electricty killed it.
  2268. //Serial.println("echo: SD CHANGE");
  2269. if(CARDINSERTED)
  2270. {
  2271. card.initsd();
  2272. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  2273. }
  2274. else
  2275. {
  2276. card.release();
  2277. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  2278. }
  2279. }
  2280. #endif
  2281. if(status!=oldstatus)
  2282. {
  2283. force_lcd_update=true;
  2284. encoderpos=0;
  2285. lineoffset=0;
  2286. oldstatus=status;
  2287. }
  2288. if( (encoderpos!=lastencoderpos) || CLICKED)
  2289. timeoutToStatus=millis()+STATUSTIMEOUT;
  2290. switch(status)
  2291. {
  2292. case Main_Status:
  2293. {
  2294. showStatus();
  2295. if(CLICKED)
  2296. {
  2297. linechanging=false;
  2298. BLOCK
  2299. status=Main_Menu;
  2300. timeoutToStatus=millis()+STATUSTIMEOUT;
  2301. }
  2302. }break;
  2303. case Main_Menu:
  2304. {
  2305. showMainMenu();
  2306. linechanging=false;
  2307. }break;
  2308. case Main_Prepare:
  2309. {
  2310. if(tune)
  2311. {
  2312. showTune();
  2313. }
  2314. else
  2315. {
  2316. showPrepare();
  2317. }
  2318. }break;
  2319. case Sub_PrepareMove:
  2320. {
  2321. showAxisMove();
  2322. }break;
  2323. case Main_Control:
  2324. {
  2325. showControl();
  2326. }break;
  2327. case Sub_MotionControl:
  2328. {
  2329. showControlMotion();
  2330. }break;
  2331. case Sub_RetractControl:
  2332. {
  2333. showControlRetract();
  2334. }break;
  2335. case Sub_TempControl:
  2336. {
  2337. showControlTemp();
  2338. }break;
  2339. case Main_SD:
  2340. {
  2341. showSD();
  2342. }break;
  2343. }
  2344. if(timeoutToStatus<millis())
  2345. status=Main_Status;
  2346. //force_lcd_update=false;
  2347. lastencoderpos=encoderpos;
  2348. }
  2349. // convert float to string with +123.4 format
  2350. char *ftostr3(const float &x)
  2351. {
  2352. //sprintf(conv,"%5.1f",x);
  2353. int xx=x;
  2354. conv[0]=(xx/100)%10+'0';
  2355. conv[1]=(xx/10)%10+'0';
  2356. conv[2]=(xx)%10+'0';
  2357. conv[3]=0;
  2358. return conv;
  2359. }
  2360. char *itostr2(const uint8_t &x)
  2361. {
  2362. //sprintf(conv,"%5.1f",x);
  2363. int xx=x;
  2364. conv[0]=(xx/10)%10+'0';
  2365. conv[1]=(xx)%10+'0';
  2366. conv[2]=0;
  2367. return conv;
  2368. }
  2369. // convert float to string with +123.4 format
  2370. char *ftostr31(const float &x)
  2371. {
  2372. int xx=x*10;
  2373. conv[0]=(xx>=0)?'+':'-';
  2374. xx=abs(xx);
  2375. conv[1]=(xx/1000)%10+'0';
  2376. conv[2]=(xx/100)%10+'0';
  2377. conv[3]=(xx/10)%10+'0';
  2378. conv[4]='.';
  2379. conv[5]=(xx)%10+'0';
  2380. conv[6]=0;
  2381. return conv;
  2382. }
  2383. char *ftostr32(const float &x)
  2384. {
  2385. long xx=x*100;
  2386. conv[0]=(xx>=0)?'+':'-';
  2387. xx=abs(xx);
  2388. conv[1]=(xx/100)%10+'0';
  2389. conv[2]='.';
  2390. conv[3]=(xx/10)%10+'0';
  2391. conv[4]=(xx)%10+'0';
  2392. conv[6]=0;
  2393. return conv;
  2394. }
  2395. char *itostr31(const int &xx)
  2396. {
  2397. conv[0]=(xx>=0)?'+':'-';
  2398. conv[1]=(xx/1000)%10+'0';
  2399. conv[2]=(xx/100)%10+'0';
  2400. conv[3]=(xx/10)%10+'0';
  2401. conv[4]='.';
  2402. conv[5]=(xx)%10+'0';
  2403. conv[6]=0;
  2404. return conv;
  2405. }
  2406. char *itostr3(const int &xx)
  2407. {
  2408. conv[0]=(xx/100)%10+'0';
  2409. conv[1]=(xx/10)%10+'0';
  2410. conv[2]=(xx)%10+'0';
  2411. conv[3]=0;
  2412. return conv;
  2413. }
  2414. char *itostr4(const int &xx)
  2415. {
  2416. conv[0]=(xx/1000)%10+'0';
  2417. conv[1]=(xx/100)%10+'0';
  2418. conv[2]=(xx/10)%10+'0';
  2419. conv[3]=(xx)%10+'0';
  2420. conv[4]=0;
  2421. return conv;
  2422. }
  2423. // convert float to string with +1234.5 format
  2424. char *ftostr51(const float &x)
  2425. {
  2426. long xx=x*10;
  2427. conv[0]=(xx>=0)?'+':'-';
  2428. xx=abs(xx);
  2429. conv[1]=(xx/10000)%10+'0';
  2430. conv[2]=(xx/1000)%10+'0';
  2431. conv[3]=(xx/100)%10+'0';
  2432. conv[4]=(xx/10)%10+'0';
  2433. conv[5]='.';
  2434. conv[6]=(xx)%10+'0';
  2435. conv[7]=0;
  2436. return conv;
  2437. }
  2438. // convert float to string with +123.45 format
  2439. char *ftostr52(const float &x)
  2440. {
  2441. long xx=x*100;
  2442. conv[0]=(xx>=0)?'+':'-';
  2443. xx=abs(xx);
  2444. conv[1]=(xx/10000)%10+'0';
  2445. conv[2]=(xx/1000)%10+'0';
  2446. conv[3]=(xx/100)%10+'0';
  2447. conv[4]='.';
  2448. conv[5]=(xx/10)%10+'0';
  2449. conv[6]=(xx)%10+'0';
  2450. conv[7]=0;
  2451. return conv;
  2452. }
  2453. #endif //ULTRA_LCD