My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ultralcd.pde 45KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939
  1. #include "ultralcd.h"
  2. #ifdef ULTRA_LCD
  3. #include "Marlin.h"
  4. #include <LiquidCrystal.h>
  5. //===========================================================================
  6. //=============================imported variables============================
  7. //===========================================================================
  8. extern volatile int feedmultiply;
  9. extern volatile bool feedmultiplychanged;
  10. extern long position[4];
  11. extern CardReader card;
  12. //===========================================================================
  13. //=============================public variables============================
  14. //===========================================================================
  15. volatile char buttons=0; //the last checked buttons in a bit array.
  16. int encoderpos=0;
  17. short lastenc=0;
  18. //===========================================================================
  19. //=============================private variables============================
  20. //===========================================================================
  21. static char messagetext[LCD_WIDTH]="";
  22. //return for string conversion routines
  23. static char conv[8];
  24. 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
  25. static unsigned long previous_millis_lcd=0;
  26. //static long previous_millis_buttons=0;
  27. #ifdef NEWPANEL
  28. static long blocking=0;
  29. #else
  30. static long blocking[8]={0,0,0,0,0,0,0,0};
  31. #endif
  32. static MainMenu menu;
  33. void lcdProgMemprint(const char *str)
  34. {
  35. char ch=pgm_read_byte(str);
  36. while(ch)
  37. {
  38. lcd.print(ch);
  39. ch=pgm_read_byte(++str);
  40. }
  41. }
  42. #define lcdprintPGM(x) lcdProgMemprint(MYPGM(x))
  43. //===========================================================================
  44. //=============================functions ============================
  45. //===========================================================================
  46. FORCE_INLINE int intround(const float &x){return int(0.5+x);}
  47. void lcd_status(const char* message)
  48. {
  49. strncpy(messagetext,message,LCD_WIDTH);
  50. messagetext[strlen(message)]=0;
  51. }
  52. void lcd_statuspgm(const char* message)
  53. {
  54. char ch=pgm_read_byte(message);
  55. char *target=messagetext;
  56. uint8_t cnt=0;
  57. while(ch &&cnt<LCD_WIDTH)
  58. {
  59. *target=ch;
  60. target++;
  61. cnt++;
  62. ch=pgm_read_byte(++message);
  63. }
  64. *target=0;
  65. }
  66. FORCE_INLINE void clear()
  67. {
  68. lcd.clear();
  69. }
  70. void lcd_init()
  71. {
  72. //beep();
  73. byte Degree[8] =
  74. {
  75. B01100,
  76. B10010,
  77. B10010,
  78. B01100,
  79. B00000,
  80. B00000,
  81. B00000,
  82. B00000
  83. };
  84. byte Thermometer[8] =
  85. {
  86. B00100,
  87. B01010,
  88. B01010,
  89. B01010,
  90. B01010,
  91. B10001,
  92. B10001,
  93. B01110
  94. };
  95. byte uplevel[8]={0x04, 0x0e, 0x1f, 0x04, 0x1c, 0x00, 0x00, 0x00};//thanks joris
  96. byte refresh[8]={0x00, 0x06, 0x19, 0x18, 0x03, 0x13, 0x0c, 0x00}; //thanks joris
  97. byte folder [8]={0x00, 0x1c, 0x1f, 0x11, 0x11, 0x1f, 0x00, 0x00}; //thanks joris
  98. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  99. lcd.createChar(1,Degree);
  100. lcd.createChar(2,Thermometer);
  101. lcd.createChar(3,uplevel);
  102. lcd.createChar(4,refresh);
  103. lcd.createChar(5,folder);
  104. LCD_MESSAGEPGM("UltiMarlin ready.");
  105. }
  106. void beep()
  107. {
  108. //return;
  109. #ifdef ULTIPANEL
  110. if (BEEPER > -1)
  111. {
  112. pinMode(BEEPER,OUTPUT);
  113. for(int8_t i=0;i<20;i++){
  114. WRITE(BEEPER,HIGH);
  115. delay(5);
  116. WRITE(BEEPER,LOW);
  117. delay(5);
  118. }
  119. }
  120. #endif
  121. }
  122. void beepshort()
  123. {
  124. //return;
  125. #ifdef ULTIPANEL
  126. if (BEEPER > -1)
  127. {
  128. pinMode(BEEPER,OUTPUT);
  129. for(int8_t i=0;i<10;i++){
  130. WRITE(BEEPER,HIGH);
  131. delay(3);
  132. WRITE(BEEPER,LOW);
  133. delay(3);
  134. }
  135. }
  136. #endif
  137. }
  138. void lcd_status()
  139. {
  140. #ifdef ULTIPANEL
  141. static uint8_t oldbuttons=0;
  142. //static long previous_millis_buttons=0;
  143. //static long previous_lcdinit=0;
  144. // buttons_check(); // Done in temperature interrupt
  145. //previous_millis_buttons=millis();
  146. long ms=millis();
  147. for(int8_t i=0; i<8; i++) {
  148. #ifndef NEWPANEL
  149. if((blocking[i]>ms))
  150. buttons &= ~(1<<i);
  151. #else
  152. if((blocking>ms))
  153. buttons &= ~(1<<i);
  154. #endif
  155. }
  156. if((buttons==oldbuttons) && ((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  157. return;
  158. oldbuttons=buttons;
  159. #else
  160. if(((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  161. return;
  162. #endif
  163. previous_millis_lcd=millis();
  164. menu.update();
  165. }
  166. #ifdef ULTIPANEL
  167. void buttons_init()
  168. {
  169. #ifdef NEWPANEL
  170. pinMode(BTN_EN1,INPUT);
  171. pinMode(BTN_EN2,INPUT);
  172. pinMode(BTN_ENC,INPUT);
  173. pinMode(SDCARDDETECT,INPUT);
  174. WRITE(BTN_EN1,HIGH);
  175. WRITE(BTN_EN2,HIGH);
  176. WRITE(BTN_ENC,HIGH);
  177. WRITE(SDCARDDETECT,HIGH);
  178. #else
  179. pinMode(SHIFT_CLK,OUTPUT);
  180. pinMode(SHIFT_LD,OUTPUT);
  181. pinMode(SHIFT_EN,OUTPUT);
  182. pinMode(SHIFT_OUT,INPUT);
  183. WRITE(SHIFT_OUT,HIGH);
  184. WRITE(SHIFT_LD,HIGH);
  185. WRITE(SHIFT_EN,LOW);
  186. #endif
  187. }
  188. void buttons_check()
  189. {
  190. #ifdef NEWPANEL
  191. uint8_t newbutton=0;
  192. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  193. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  194. if((blocking<millis()) &&(READ(BTN_ENC)==0))
  195. newbutton|=EN_C;
  196. buttons=newbutton;
  197. #else //read it from the shift register
  198. uint8_t newbutton=0;
  199. WRITE(SHIFT_LD,LOW);
  200. WRITE(SHIFT_LD,HIGH);
  201. unsigned char tmp_buttons=0;
  202. for(int8_t i=0;i<8;i++)
  203. {
  204. newbutton = newbutton>>1;
  205. if(READ(SHIFT_OUT))
  206. newbutton|=(1<<7);
  207. WRITE(SHIFT_CLK,HIGH);
  208. WRITE(SHIFT_CLK,LOW);
  209. }
  210. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  211. #endif
  212. //manage encoder rotation
  213. char enc=0;
  214. if(buttons&EN_A)
  215. enc|=(1<<0);
  216. if(buttons&EN_B)
  217. enc|=(1<<1);
  218. if(enc!=lastenc)
  219. {
  220. switch(enc)
  221. {
  222. case encrot0:
  223. if(lastenc==encrot3)
  224. encoderpos++;
  225. else if(lastenc==encrot1)
  226. encoderpos--;
  227. break;
  228. case encrot1:
  229. if(lastenc==encrot0)
  230. encoderpos++;
  231. else if(lastenc==encrot2)
  232. encoderpos--;
  233. break;
  234. case encrot2:
  235. if(lastenc==encrot1)
  236. encoderpos++;
  237. else if(lastenc==encrot3)
  238. encoderpos--;
  239. break;
  240. case encrot3:
  241. if(lastenc==encrot2)
  242. encoderpos++;
  243. else if(lastenc==encrot0)
  244. encoderpos--;
  245. break;
  246. default:
  247. ;
  248. }
  249. }
  250. lastenc=enc;
  251. }
  252. #endif
  253. MainMenu::MainMenu()
  254. {
  255. status=Main_Status;
  256. displayStartingRow=0;
  257. activeline=0;
  258. force_lcd_update=true;
  259. #ifdef ULTIPANEL
  260. buttons_init();
  261. #endif
  262. lcd_init();
  263. linechanging=false;
  264. tune=false;
  265. }
  266. void MainMenu::showStatus()
  267. {
  268. #if LCD_HEIGHT==4
  269. static int olddegHotEnd0=-1;
  270. static int oldtargetHotEnd0=-1;
  271. //force_lcd_update=true;
  272. if(force_lcd_update||feedmultiplychanged) //initial display of content
  273. {
  274. feedmultiplychanged=false;
  275. encoderpos=feedmultiply;
  276. clear();
  277. lcd.setCursor(0,0);lcdprintPGM("\002123/567\001 ");
  278. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  279. lcd.setCursor(10,0);lcdprintPGM("B123/567\001 ");
  280. #endif
  281. }
  282. int tHotEnd0=intround(degHotend0());
  283. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update) //>1 because otherwise the lcd is refreshed to often.
  284. {
  285. lcd.setCursor(1,0);
  286. lcd.print(ftostr3(tHotEnd0));
  287. olddegHotEnd0=tHotEnd0;
  288. }
  289. int ttHotEnd0=intround(degTargetHotend0());
  290. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  291. {
  292. lcd.setCursor(5,0);
  293. lcd.print(ftostr3(ttHotEnd0));
  294. oldtargetHotEnd0=ttHotEnd0;
  295. }
  296. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  297. static int oldtBed=-1;
  298. static int oldtargetBed=-1;
  299. int tBed=intround(degBed());
  300. if((tBed!=oldtBed)||force_lcd_update)
  301. {
  302. lcd.setCursor(11,0);
  303. lcd.print(ftostr3(tBed));
  304. oldtBed=tBed;
  305. }
  306. int targetBed=intround(degTargetBed());
  307. if((targetBed!=oldtargetBed)||force_lcd_update)
  308. {
  309. lcd.setCursor(15,0);
  310. lcd.print(ftostr3(targetBed));
  311. oldtargetBed=targetBed;
  312. }
  313. #endif
  314. //starttime=2;
  315. static uint16_t oldtime=0;
  316. if(starttime!=0)
  317. {
  318. lcd.setCursor(0,1);
  319. uint16_t time=millis()/60000-starttime/60000;
  320. if(starttime!=oldtime)
  321. {
  322. lcd.print(itostr2(time/60));lcdprintPGM("h ");lcd.print(itostr2(time%60));lcdprintPGM("m");
  323. oldtime=time;
  324. }
  325. }
  326. static int oldzpos=0;
  327. int currentz=current_position[2]*100;
  328. if((currentz!=oldzpos)||force_lcd_update)
  329. {
  330. lcd.setCursor(10,1);
  331. lcdprintPGM("Z:");lcd.print(ftostr32(current_position[2]));
  332. oldzpos=currentz;
  333. }
  334. static int oldfeedmultiply=0;
  335. int curfeedmultiply=feedmultiply;
  336. if(encoderpos!=curfeedmultiply||force_lcd_update)
  337. {
  338. curfeedmultiply=encoderpos;
  339. if(curfeedmultiply<10)
  340. curfeedmultiply=10;
  341. if(curfeedmultiply>999)
  342. curfeedmultiply=999;
  343. feedmultiply=curfeedmultiply;
  344. encoderpos=curfeedmultiply;
  345. }
  346. if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update)
  347. {
  348. oldfeedmultiply=curfeedmultiply;
  349. lcd.setCursor(0,2);
  350. lcd.print(itostr3(curfeedmultiply));lcdprintPGM("% ");
  351. }
  352. if(messagetext[0]!='\0')
  353. {
  354. lcd.setCursor(0,LCD_HEIGHT-1);
  355. lcd.print(messagetext);
  356. uint8_t n=strlen(messagetext);
  357. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  358. lcd.print(" ");
  359. messagetext[0]='\0';
  360. }
  361. static uint8_t oldpercent=101;
  362. uint8_t percent=card.percentDone();
  363. if(oldpercent!=percent ||force_lcd_update)
  364. {
  365. lcd.setCursor(7,2);
  366. lcd.print(itostr3((int)percent));
  367. lcdprintPGM("%SD");
  368. }
  369. #else //smaller LCDS----------------------------------
  370. static int olddegHotEnd0=-1;
  371. static int oldtargetHotEnd0=-1;
  372. if(force_lcd_update) //initial display of content
  373. {
  374. encoderpos=feedmultiply;
  375. lcd.setCursor(0,0);lcdprintPGM("\002123/567\001 ");
  376. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  377. lcd.setCursor(10,0);lcdprintPGM("B123/567\001 ");
  378. #endif
  379. }
  380. int tHotEnd0=intround(degHotend0());
  381. int ttHotEnd0=intround(degTargetHotend0());
  382. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update)
  383. {
  384. lcd.setCursor(1,0);
  385. lcd.print(ftostr3(tHotEnd0));
  386. olddegHotEnd0=tHotEnd0;
  387. }
  388. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  389. {
  390. lcd.setCursor(5,0);
  391. lcd.print(ftostr3(ttHotEnd0));
  392. oldtargetHotEnd0=ttHotEnd0;
  393. }
  394. if(messagetext[0]!='\0')
  395. {
  396. lcd.setCursor(0,LCD_HEIGHT-1);
  397. lcd.print(messagetext);
  398. uint8_t n=strlen(messagetext);
  399. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  400. lcd.print(" ");
  401. messagetext[0]='\0';
  402. }
  403. #endif
  404. force_lcd_update=false;
  405. }
  406. enum {ItemP_exit, ItemP_autostart,ItemP_disstep,ItemP_home, ItemP_origin, ItemP_preheat, ItemP_cooldown,ItemP_extrude};
  407. //any action must not contain a ',' character anywhere, or this breaks:
  408. #define MENUITEM(repaint_action, click_action) \
  409. {\
  410. if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  411. if((activeline==line) && CLICKED) {click_action} \
  412. }
  413. void MainMenu::showPrepare()
  414. {
  415. uint8_t line=0;
  416. clearIfNecessary();
  417. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  418. {
  419. //Serial.println((int)(line-lineoffset));
  420. switch(i)
  421. {
  422. case ItemP_exit:
  423. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  424. break;
  425. case ItemP_autostart:
  426. MENUITEM( lcdprintPGM(" Autostart") , BLOCK;card.lastnr=0;card.setroot();card.checkautostart(true);beepshort(); ) ;
  427. break;
  428. case ItemP_disstep:
  429. MENUITEM( lcdprintPGM(" Disable Steppers") , BLOCK;enquecommand("M84");beepshort(); ) ;
  430. break;
  431. case ItemP_home:
  432. MENUITEM( lcdprintPGM(" Auto Home") , BLOCK;enquecommand("G28 X-105 Y-105 Z0");beepshort(); ) ;
  433. break;
  434. case ItemP_origin:
  435. MENUITEM( lcdprintPGM(" Set Origin") , BLOCK;enquecommand("G92 X0 Y0 Z0");beepshort(); ) ;
  436. break;
  437. case ItemP_preheat:
  438. MENUITEM( lcdprintPGM(" Preheat") , BLOCK;setTargetHotend0(170);setTargetBed(70);beepshort(); ) ;
  439. break;
  440. case ItemP_cooldown:
  441. MENUITEM( lcdprintPGM(" Cooldown") , BLOCK;setTargetHotend0(0);setTargetBed(0);beepshort(); ) ;
  442. break;
  443. case ItemP_extrude:
  444. MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E50");beepshort(); ) ;
  445. break;
  446. default:
  447. break;
  448. }
  449. line++;
  450. }
  451. updateActiveLines(ItemP_extrude,encoderpos);
  452. }
  453. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  454. #if (HEATER_BED_PIN > -1)
  455. ItemT_bed,
  456. #endif
  457. ItemT_fan};
  458. void MainMenu::showTune()
  459. {
  460. uint8_t line=0;
  461. clearIfNecessary();
  462. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  463. {
  464. //Serial.println((int)(line-lineoffset));
  465. switch(i)
  466. {
  467. case ItemT_exit:
  468. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  469. break;
  470. case ItemT_speed:
  471. {
  472. if(force_lcd_update)
  473. {
  474. lcd.setCursor(0,line);lcdprintPGM(" Speed:");
  475. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  476. }
  477. if((activeline!=line) )
  478. break;
  479. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  480. {
  481. linechanging=!linechanging;
  482. if(linechanging)
  483. {
  484. encoderpos=feedmultiply;
  485. }
  486. else
  487. {
  488. encoderpos=activeline*lcdslow;
  489. beepshort();
  490. }
  491. BLOCK;
  492. }
  493. if(linechanging)
  494. {
  495. if(encoderpos<1) encoderpos=1;
  496. if(encoderpos>400) encoderpos=400;
  497. feedmultiply = encoderpos;
  498. feedmultiplychanged=true;
  499. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  500. }
  501. }break;
  502. case ItemT_nozzle:
  503. {
  504. if(force_lcd_update)
  505. {
  506. lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:");
  507. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  508. }
  509. if((activeline!=line) )
  510. break;
  511. if(CLICKED)
  512. {
  513. linechanging=!linechanging;
  514. if(linechanging)
  515. {
  516. encoderpos=intround(degTargetHotend0());
  517. }
  518. else
  519. {
  520. setTargetHotend0(encoderpos);
  521. encoderpos=activeline*lcdslow;
  522. beepshort();
  523. }
  524. BLOCK;
  525. }
  526. if(linechanging)
  527. {
  528. if(encoderpos<0) encoderpos=0;
  529. if(encoderpos>260) encoderpos=260;
  530. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  531. }
  532. }break;
  533. #if (HEATER_BED_PIN > -1)
  534. case ItemT_bed:
  535. {
  536. if(force_lcd_update)
  537. {
  538. lcd.setCursor(0,line);lcdprintPGM(" \002Bed:");
  539. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  540. }
  541. if((activeline!=line) )
  542. break;
  543. if(CLICKED)
  544. {
  545. linechanging=!linechanging;
  546. if(linechanging)
  547. {
  548. encoderpos=intround(degTargetBed());
  549. }
  550. else
  551. {
  552. setTargetBed(encoderpos);
  553. encoderpos=activeline*lcdslow;
  554. beepshort();
  555. }
  556. BLOCK;
  557. }
  558. if(linechanging)
  559. {
  560. if(encoderpos<0) encoderpos=0;
  561. if(encoderpos>260) encoderpos=260;
  562. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  563. }
  564. }break;
  565. #endif
  566. case ItemT_fan:
  567. {
  568. if(force_lcd_update)
  569. {
  570. lcd.setCursor(0,line);lcdprintPGM(" Fan speed:");
  571. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  572. }
  573. if((activeline!=line) )
  574. break;
  575. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  576. {
  577. linechanging=!linechanging;
  578. if(linechanging)
  579. {
  580. encoderpos=fanpwm;
  581. }
  582. else
  583. {
  584. encoderpos=activeline*lcdslow;
  585. beepshort();
  586. }
  587. BLOCK;
  588. }
  589. if(linechanging)
  590. {
  591. if(encoderpos<0) encoderpos=0;
  592. if(encoderpos>255) encoderpos=255;
  593. fanpwm=encoderpos;
  594. analogWrite(FAN_PIN, fanpwm);
  595. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  596. }
  597. }break;
  598. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  599. {
  600. if(force_lcd_update)
  601. {
  602. lcd.setCursor(0,line);lcdprintPGM(" Flow:");
  603. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  604. }
  605. if((activeline!=line) )
  606. break;
  607. if(CLICKED)
  608. {
  609. linechanging=!linechanging;
  610. if(linechanging)
  611. {
  612. encoderpos=(int)axis_steps_per_unit[3];
  613. }
  614. else
  615. {
  616. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  617. position[E_AXIS]=lround(position[E_AXIS]*factor);
  618. //current_position[3]*=factor;
  619. axis_steps_per_unit[E_AXIS]= encoderpos;
  620. encoderpos=activeline*lcdslow;
  621. }
  622. BLOCK;
  623. beepshort();
  624. }
  625. if(linechanging)
  626. {
  627. if(encoderpos<5) encoderpos=5;
  628. if(encoderpos>9999) encoderpos=9999;
  629. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  630. }
  631. }break;
  632. default:
  633. break;
  634. }
  635. line++;
  636. }
  637. updateActiveLines(ItemT_fan,encoderpos);
  638. }
  639. //does not work
  640. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  641. // {\
  642. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  643. // if(activeline==line) \
  644. // { \
  645. // if(CLICKED) \
  646. // { \
  647. // linechanging=!linechanging; \
  648. // if(linechanging) {enter_action;} \
  649. // else {accept_action;} \
  650. // } \
  651. // else \
  652. // if(linechanging) {change_action};}\
  653. // }
  654. //
  655. enum {
  656. ItemCT_exit,ItemCT_nozzle,
  657. #ifdef AUTOTEMP
  658. ItemCT_autotempactive,
  659. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  660. #endif
  661. #if (HEATER_BED_PIN > -1)
  662. ItemCT_bed,
  663. #endif
  664. ItemCT_fan,
  665. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C
  666. };
  667. void MainMenu::showControlTemp()
  668. {
  669. uint8_t line=0;
  670. clearIfNecessary();
  671. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  672. {
  673. switch(i)
  674. {
  675. case ItemCT_exit:
  676. MENUITEM( lcdprintPGM(" Control \003") , BLOCK;status=Main_Control;beepshort(); ) ;
  677. break;
  678. case ItemCT_nozzle:
  679. {
  680. if(force_lcd_update)
  681. {
  682. lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:");
  683. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  684. }
  685. if((activeline!=line) )
  686. break;
  687. if(CLICKED)
  688. {
  689. linechanging=!linechanging;
  690. if(linechanging)
  691. {
  692. encoderpos=intround(degTargetHotend0());
  693. }
  694. else
  695. {
  696. setTargetHotend0(encoderpos);
  697. encoderpos=activeline*lcdslow;
  698. beepshort();
  699. }
  700. BLOCK;
  701. }
  702. if(linechanging)
  703. {
  704. if(encoderpos<0) encoderpos=0;
  705. if(encoderpos>260) encoderpos=260;
  706. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  707. }
  708. }break;
  709. #ifdef AUTOTEMP
  710. case ItemCT_autotempmin:
  711. {
  712. if(force_lcd_update)
  713. {
  714. lcd.setCursor(0,line);lcdprintPGM(" \002 Min:");
  715. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  716. }
  717. if((activeline!=line) )
  718. break;
  719. if(CLICKED)
  720. {
  721. linechanging=!linechanging;
  722. if(linechanging)
  723. {
  724. encoderpos=intround(autotemp_min);
  725. }
  726. else
  727. {
  728. autotemp_min=encoderpos;
  729. encoderpos=activeline*lcdslow;
  730. beepshort();
  731. }
  732. BLOCK;
  733. }
  734. if(linechanging)
  735. {
  736. if(encoderpos<0) encoderpos=0;
  737. if(encoderpos>260) encoderpos=260;
  738. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  739. }
  740. }break;
  741. case ItemCT_autotempmax:
  742. {
  743. if(force_lcd_update)
  744. {
  745. lcd.setCursor(0,line);lcdprintPGM(" \002 Max:");
  746. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  747. }
  748. if((activeline!=line) )
  749. break;
  750. if(CLICKED)
  751. {
  752. linechanging=!linechanging;
  753. if(linechanging)
  754. {
  755. encoderpos=intround(autotemp_max);
  756. }
  757. else
  758. {
  759. autotemp_max=encoderpos;
  760. encoderpos=activeline*lcdslow;
  761. beepshort();
  762. }
  763. BLOCK;
  764. }
  765. if(linechanging)
  766. {
  767. if(encoderpos<0) encoderpos=0;
  768. if(encoderpos>260) encoderpos=260;
  769. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  770. }
  771. }break;
  772. case ItemCT_autotempfact:
  773. {
  774. if(force_lcd_update)
  775. {
  776. lcd.setCursor(0,line);lcdprintPGM(" \002 Fact:");
  777. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  778. }
  779. if((activeline!=line) )
  780. break;
  781. if(CLICKED)
  782. {
  783. linechanging=!linechanging;
  784. if(linechanging)
  785. {
  786. encoderpos=intround(autotemp_factor*100);
  787. }
  788. else
  789. {
  790. autotemp_max=encoderpos;
  791. encoderpos=activeline*lcdslow;
  792. beepshort();
  793. }
  794. BLOCK;
  795. }
  796. if(linechanging)
  797. {
  798. if(encoderpos<0) encoderpos=0;
  799. if(encoderpos>99) encoderpos=99;
  800. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  801. }
  802. }break;
  803. case ItemCT_autotempactive:
  804. {
  805. if(force_lcd_update)
  806. {
  807. lcd.setCursor(0,line);lcdprintPGM(" Autotemp:");
  808. lcd.setCursor(13,line);
  809. if(autotemp_enabled)
  810. lcdprintPGM("On");
  811. else
  812. lcdprintPGM("Off");
  813. }
  814. if((activeline!=line) )
  815. break;
  816. if(CLICKED)
  817. {
  818. autotemp_enabled=!autotemp_enabled;
  819. lcd.setCursor(13,line);
  820. if(autotemp_enabled)
  821. lcdprintPGM("On ");
  822. else
  823. lcdprintPGM("Off");
  824. BLOCK;
  825. }
  826. }break;
  827. #endif //autotemp
  828. #if (HEATER_BED_PIN > -1)
  829. case ItemCT_bed:
  830. {
  831. if(force_lcd_update)
  832. {
  833. lcd.setCursor(0,line);lcdprintPGM(" \002Bed:");
  834. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  835. }
  836. if((activeline!=line) )
  837. break;
  838. if(CLICKED)
  839. {
  840. linechanging=!linechanging;
  841. if(linechanging)
  842. {
  843. encoderpos=intround(degTargetBed());
  844. }
  845. else
  846. {
  847. setTargetBed(encoderpos);
  848. encoderpos=activeline*lcdslow;
  849. beepshort();
  850. }
  851. BLOCK;
  852. }
  853. if(linechanging)
  854. {
  855. if(encoderpos<0) encoderpos=0;
  856. if(encoderpos>260) encoderpos=260;
  857. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  858. }
  859. }break;
  860. #endif
  861. case ItemCT_fan:
  862. {
  863. if(force_lcd_update)
  864. {
  865. lcd.setCursor(0,line);lcdprintPGM(" Fan speed:");
  866. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  867. }
  868. if((activeline!=line) )
  869. break;
  870. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  871. {
  872. linechanging=!linechanging;
  873. if(linechanging)
  874. {
  875. encoderpos=fanpwm;
  876. }
  877. else
  878. {
  879. encoderpos=activeline*lcdslow;
  880. beepshort();
  881. }
  882. BLOCK;
  883. }
  884. if(linechanging)
  885. {
  886. if(encoderpos<0) encoderpos=0;
  887. if(encoderpos>255) encoderpos=255;
  888. fanpwm=encoderpos;
  889. analogWrite(FAN_PIN, fanpwm);
  890. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  891. }
  892. }break;
  893. case ItemCT_PID_P:
  894. {
  895. if(force_lcd_update)
  896. {
  897. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  898. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  899. }
  900. if((activeline!=line) )
  901. break;
  902. if(CLICKED)
  903. {
  904. linechanging=!linechanging;
  905. if(linechanging)
  906. {
  907. encoderpos=(int)Kp;
  908. }
  909. else
  910. {
  911. Kp= encoderpos;
  912. encoderpos=activeline*lcdslow;
  913. }
  914. BLOCK;
  915. beepshort();
  916. }
  917. if(linechanging)
  918. {
  919. if(encoderpos<1) encoderpos=1;
  920. if(encoderpos>9990) encoderpos=9990;
  921. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  922. }
  923. }break;
  924. case ItemCT_PID_I:
  925. {
  926. if(force_lcd_update)
  927. {
  928. lcd.setCursor(0,line);lcdprintPGM(" PID-I: ");
  929. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  930. }
  931. if((activeline!=line) )
  932. break;
  933. if(CLICKED)
  934. {
  935. linechanging=!linechanging;
  936. if(linechanging)
  937. {
  938. encoderpos=(int)(Ki*10/PID_dT);
  939. }
  940. else
  941. {
  942. Ki= encoderpos/10.*PID_dT;
  943. encoderpos=activeline*lcdslow;
  944. }
  945. BLOCK;
  946. beepshort();
  947. }
  948. if(linechanging)
  949. {
  950. if(encoderpos<0) encoderpos=0;
  951. if(encoderpos>9990) encoderpos=9990;
  952. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  953. }
  954. }break;
  955. case ItemCT_PID_D:
  956. {
  957. if(force_lcd_update)
  958. {
  959. lcd.setCursor(0,line);lcdprintPGM(" PID-D: ");
  960. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  961. }
  962. if((activeline!=line) )
  963. break;
  964. if(CLICKED)
  965. {
  966. linechanging=!linechanging;
  967. if(linechanging)
  968. {
  969. encoderpos=(int)(Kd/5./PID_dT);
  970. }
  971. else
  972. {
  973. Kd= encoderpos;
  974. encoderpos=activeline*lcdslow;
  975. }
  976. BLOCK;
  977. beepshort();
  978. }
  979. if(linechanging)
  980. {
  981. if(encoderpos<0) encoderpos=0;
  982. if(encoderpos>9990) encoderpos=9990;
  983. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  984. }
  985. }break;
  986. case ItemCT_PID_C:
  987. #ifdef PID_ADD_EXTRUSION_RATE
  988. {
  989. if(force_lcd_update)
  990. {
  991. lcd.setCursor(0,line);lcdprintPGM(" PID-C: ");
  992. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  993. }
  994. if((activeline!=line) )
  995. break;
  996. if(CLICKED)
  997. {
  998. linechanging=!linechanging;
  999. if(linechanging)
  1000. {
  1001. encoderpos=(int)Kc;
  1002. }
  1003. else
  1004. {
  1005. Kc= encoderpos;
  1006. encoderpos=activeline*lcdslow;
  1007. }
  1008. BLOCK;
  1009. beepshort();
  1010. }
  1011. if(linechanging)
  1012. {
  1013. if(encoderpos<0) encoderpos=0;
  1014. if(encoderpos>990) encoderpos=990;
  1015. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1016. }
  1017. }
  1018. #endif
  1019. break;
  1020. default:
  1021. break;
  1022. }
  1023. line++;
  1024. }
  1025. #ifdef PID_ADD_EXTRUSION_RATE
  1026. updateActiveLines(ItemCT_PID_C,encoderpos);
  1027. #else
  1028. updateActiveLines(ItemCT_PID_D,encoderpos);
  1029. #endif
  1030. }
  1031. enum {
  1032. ItemCM_exit,
  1033. ItemCM_acc, ItemCM_xyjerk,
  1034. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1035. ItemCM_vtravmin,ItemCM_vmin,
  1036. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1037. ItemCM_aret,ItemCM_esteps
  1038. };
  1039. void MainMenu::showControlMotion()
  1040. {
  1041. uint8_t line=0;
  1042. clearIfNecessary();
  1043. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1044. {
  1045. switch(i)
  1046. {
  1047. case ItemCM_exit:
  1048. MENUITEM( lcdprintPGM(" Control \003") , BLOCK;status=Main_Control;beepshort(); ) ;
  1049. break;
  1050. case ItemCM_acc:
  1051. {
  1052. if(force_lcd_update)
  1053. {
  1054. lcd.setCursor(0,line);lcdprintPGM(" Acc:");
  1055. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1056. }
  1057. if((activeline!=line) )
  1058. break;
  1059. if(CLICKED)
  1060. {
  1061. linechanging=!linechanging;
  1062. if(linechanging)
  1063. {
  1064. encoderpos=(int)acceleration/100;
  1065. }
  1066. else
  1067. {
  1068. acceleration= encoderpos*100;
  1069. encoderpos=activeline*lcdslow;
  1070. }
  1071. BLOCK;
  1072. beepshort();
  1073. }
  1074. if(linechanging)
  1075. {
  1076. if(encoderpos<5) encoderpos=5;
  1077. if(encoderpos>990) encoderpos=990;
  1078. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1079. }
  1080. }break;
  1081. case ItemCM_xyjerk: //max_xy_jerk
  1082. {
  1083. if(force_lcd_update)
  1084. {
  1085. lcd.setCursor(0,line);lcdprintPGM(" Vxy-jerk: ");
  1086. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1087. }
  1088. if((activeline!=line) )
  1089. break;
  1090. if(CLICKED)
  1091. {
  1092. linechanging=!linechanging;
  1093. if(linechanging)
  1094. {
  1095. encoderpos=(int)max_xy_jerk;
  1096. }
  1097. else
  1098. {
  1099. max_xy_jerk= encoderpos;
  1100. encoderpos=activeline*lcdslow;
  1101. }
  1102. BLOCK;
  1103. beepshort();
  1104. }
  1105. if(linechanging)
  1106. {
  1107. if(encoderpos<1) encoderpos=1;
  1108. if(encoderpos>990) encoderpos=990;
  1109. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1110. }
  1111. }break;
  1112. case ItemCM_vmaxx:
  1113. case ItemCM_vmaxy:
  1114. case ItemCM_vmaxz:
  1115. case ItemCM_vmaxe:
  1116. {
  1117. if(force_lcd_update)
  1118. {
  1119. lcd.setCursor(0,line);lcdprintPGM(" Vmax ");
  1120. if(i==ItemCM_vmaxx)lcdprintPGM("x:");
  1121. if(i==ItemCM_vmaxy)lcdprintPGM("y:");
  1122. if(i==ItemCM_vmaxz)lcdprintPGM("z:");
  1123. if(i==ItemCM_vmaxe)lcdprintPGM("e:");
  1124. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1125. }
  1126. if((activeline!=line) )
  1127. break;
  1128. if(CLICKED)
  1129. {
  1130. linechanging=!linechanging;
  1131. if(linechanging)
  1132. {
  1133. encoderpos=(int)max_feedrate[i-ItemCM_vmaxx];
  1134. }
  1135. else
  1136. {
  1137. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1138. encoderpos=activeline*lcdslow;
  1139. }
  1140. BLOCK;
  1141. beepshort();
  1142. }
  1143. if(linechanging)
  1144. {
  1145. if(encoderpos<1) encoderpos=1;
  1146. if(encoderpos>990) encoderpos=990;
  1147. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1148. }
  1149. }break;
  1150. case ItemCM_vmin:
  1151. {
  1152. if(force_lcd_update)
  1153. {
  1154. lcd.setCursor(0,line);lcdprintPGM(" Vmin:");
  1155. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1156. }
  1157. if((activeline!=line) )
  1158. break;
  1159. if(CLICKED)
  1160. {
  1161. linechanging=!linechanging;
  1162. if(linechanging)
  1163. {
  1164. encoderpos=(int)(minimumfeedrate);
  1165. }
  1166. else
  1167. {
  1168. minimumfeedrate= encoderpos;
  1169. encoderpos=activeline*lcdslow;
  1170. }
  1171. BLOCK;
  1172. beepshort();
  1173. }
  1174. if(linechanging)
  1175. {
  1176. if(encoderpos<0) encoderpos=0;
  1177. if(encoderpos>990) encoderpos=990;
  1178. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1179. }
  1180. }break;
  1181. case ItemCM_vtravmin:
  1182. {
  1183. if(force_lcd_update)
  1184. {
  1185. lcd.setCursor(0,line);lcdprintPGM(" VTrav min:");
  1186. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1187. }
  1188. if((activeline!=line) )
  1189. break;
  1190. if(CLICKED)
  1191. {
  1192. linechanging=!linechanging;
  1193. if(linechanging)
  1194. {
  1195. encoderpos=(int)mintravelfeedrate;
  1196. }
  1197. else
  1198. {
  1199. mintravelfeedrate= encoderpos;
  1200. encoderpos=activeline*lcdslow;
  1201. }
  1202. BLOCK;
  1203. beepshort();
  1204. }
  1205. if(linechanging)
  1206. {
  1207. if(encoderpos<0) encoderpos=0;
  1208. if(encoderpos>990) encoderpos=990;
  1209. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1210. }
  1211. }break;
  1212. case ItemCM_amaxx:
  1213. case ItemCM_amaxy:
  1214. case ItemCM_amaxz:
  1215. case ItemCM_amaxe:
  1216. {
  1217. if(force_lcd_update)
  1218. {
  1219. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1220. if(i==ItemCM_amaxx)lcdprintPGM("x:");
  1221. if(i==ItemCM_amaxy)lcdprintPGM("y:");
  1222. if(i==ItemCM_amaxz)lcdprintPGM("z:");
  1223. if(i==ItemCM_amaxe)lcdprintPGM("e:");
  1224. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1225. }
  1226. if((activeline!=line) )
  1227. break;
  1228. if(CLICKED)
  1229. {
  1230. linechanging=!linechanging;
  1231. if(linechanging)
  1232. {
  1233. encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1234. }
  1235. else
  1236. {
  1237. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1238. encoderpos=activeline*lcdslow;
  1239. }
  1240. BLOCK;
  1241. beepshort();
  1242. }
  1243. if(linechanging)
  1244. {
  1245. if(encoderpos<1) encoderpos=1;
  1246. if(encoderpos>990) encoderpos=990;
  1247. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1248. }
  1249. }break;
  1250. case ItemCM_aret://float retract_acceleration = 7000;
  1251. {
  1252. if(force_lcd_update)
  1253. {
  1254. lcd.setCursor(0,line);lcdprintPGM(" A-retract:");
  1255. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1256. }
  1257. if((activeline!=line) )
  1258. break;
  1259. if(CLICKED)
  1260. {
  1261. linechanging=!linechanging;
  1262. if(linechanging)
  1263. {
  1264. encoderpos=(int)retract_acceleration/100;
  1265. }
  1266. else
  1267. {
  1268. retract_acceleration= encoderpos*100;
  1269. encoderpos=activeline*lcdslow;
  1270. }
  1271. BLOCK;
  1272. beepshort();
  1273. }
  1274. if(linechanging)
  1275. {
  1276. if(encoderpos<10) encoderpos=10;
  1277. if(encoderpos>990) encoderpos=990;
  1278. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1279. }
  1280. }break;
  1281. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1282. {
  1283. if(force_lcd_update)
  1284. {
  1285. lcd.setCursor(0,line);lcdprintPGM(" Esteps/mm:");
  1286. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  1287. }
  1288. if((activeline!=line) )
  1289. break;
  1290. if(CLICKED)
  1291. {
  1292. linechanging=!linechanging;
  1293. if(linechanging)
  1294. {
  1295. encoderpos=(int)axis_steps_per_unit[3];
  1296. }
  1297. else
  1298. {
  1299. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  1300. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1301. //current_position[3]*=factor;
  1302. axis_steps_per_unit[E_AXIS]= encoderpos;
  1303. encoderpos=activeline*lcdslow;
  1304. }
  1305. BLOCK;
  1306. beepshort();
  1307. }
  1308. if(linechanging)
  1309. {
  1310. if(encoderpos<5) encoderpos=5;
  1311. if(encoderpos>9999) encoderpos=9999;
  1312. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1313. }
  1314. }break;
  1315. default:
  1316. break;
  1317. }
  1318. line++;
  1319. }
  1320. updateActiveLines(ItemCM_esteps,encoderpos);
  1321. }
  1322. enum {
  1323. ItemC_exit,ItemC_temp,ItemC_move,
  1324. ItemC_store, ItemC_load,ItemC_failsafe
  1325. };
  1326. void MainMenu::showControl()
  1327. {
  1328. uint8_t line=0;
  1329. clearIfNecessary();
  1330. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1331. {
  1332. switch(i)
  1333. {
  1334. case ItemC_exit:
  1335. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  1336. break;
  1337. case ItemC_temp:
  1338. MENUITEM( lcdprintPGM(" Temperature \x7E") , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1339. break;
  1340. case ItemC_move:
  1341. MENUITEM( lcdprintPGM(" Motion \x7E") , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1342. break;
  1343. case ItemC_store:
  1344. {
  1345. if(force_lcd_update)
  1346. {
  1347. lcd.setCursor(0,line);lcdprintPGM(" Store EPROM");
  1348. }
  1349. if((activeline==line) && CLICKED)
  1350. {
  1351. //enquecommand("M84");
  1352. beepshort();
  1353. BLOCK;
  1354. EEPROM_StoreSettings();
  1355. }
  1356. }break;
  1357. case ItemC_load:
  1358. {
  1359. if(force_lcd_update)
  1360. {
  1361. lcd.setCursor(0,line);lcdprintPGM(" Load EPROM");
  1362. }
  1363. if((activeline==line) && CLICKED)
  1364. {
  1365. //enquecommand("M84");
  1366. beepshort();
  1367. BLOCK;
  1368. EEPROM_RetrieveSettings();
  1369. }
  1370. }break;
  1371. case ItemC_failsafe:
  1372. {
  1373. if(force_lcd_update)
  1374. {
  1375. lcd.setCursor(0,line);lcdprintPGM(" Restore Failsafe");
  1376. }
  1377. if((activeline==line) && CLICKED)
  1378. {
  1379. //enquecommand("M84");
  1380. beepshort();
  1381. BLOCK;
  1382. EEPROM_RetrieveSettings(true);
  1383. }
  1384. }break;
  1385. default:
  1386. break;
  1387. }
  1388. line++;
  1389. }
  1390. updateActiveLines(ItemC_failsafe,encoderpos);
  1391. }
  1392. void MainMenu::showSD()
  1393. {
  1394. #ifdef SDSUPPORT
  1395. uint8_t line=0;
  1396. clearIfNecessary();
  1397. static uint8_t nrfiles=0;
  1398. if(force_lcd_update)
  1399. {
  1400. if(card.cardOK)
  1401. {
  1402. nrfiles=card.getnrfilenames();
  1403. }
  1404. else
  1405. {
  1406. nrfiles=0;
  1407. lineoffset=0;
  1408. }
  1409. }
  1410. bool enforceupdate=false;
  1411. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1412. {
  1413. switch(i)
  1414. {
  1415. case 0:
  1416. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  1417. break;
  1418. // case 1:
  1419. // {
  1420. // if(force_lcd_update)
  1421. // {
  1422. // lcd.setCursor(0,line);
  1423. // #ifdef CARDINSERTED
  1424. // if(CARDINSERTED)
  1425. // #else
  1426. // if(true)
  1427. // #endif
  1428. // {
  1429. // lcdprintPGM(" \004Refresh");
  1430. // }
  1431. // else
  1432. // {
  1433. // lcdprintPGM(" \004Insert Card");
  1434. // }
  1435. //
  1436. // }
  1437. // if((activeline==line) && CLICKED)
  1438. // {
  1439. // BLOCK;
  1440. // beepshort();
  1441. // card.initsd();
  1442. // force_lcd_update=true;
  1443. // nrfiles=card.getnrfilenames();
  1444. // }
  1445. // }break;
  1446. case 1:
  1447. MENUITEM( lcd.print(" ");card.getWorkDirName();if(card.filename[0]=='/') lcdprintPGM("\004Refresh");else {lcd.print("\005");lcd.print(card.filename);lcd.print("/..");} , BLOCK;card.updir();enforceupdate=true;lineoffset=0;beepshort(); ) ;
  1448. break;
  1449. default:
  1450. {
  1451. #define FIRSTITEM 2
  1452. if(i-FIRSTITEM<nrfiles)
  1453. {
  1454. if(force_lcd_update)
  1455. {
  1456. card.getfilename(i-FIRSTITEM);
  1457. //Serial.print("Filenr:");Serial.println(i-2);
  1458. lcd.setCursor(0,line);lcdprintPGM(" ");
  1459. if(card.filenameIsDir) lcd.print("\005");
  1460. lcd.print(card.filename);
  1461. }
  1462. if((activeline==line) && CLICKED)
  1463. {
  1464. BLOCK
  1465. card.getfilename(i-FIRSTITEM);
  1466. if(card.filenameIsDir)
  1467. {
  1468. for(int8_t i=0;i<strlen(card.filename);i++)
  1469. card.filename[i]=tolower(card.filename[i]);
  1470. card.chdir(card.filename);
  1471. lineoffset=0;
  1472. enforceupdate=true;
  1473. }
  1474. else
  1475. {
  1476. char cmd[30];
  1477. for(int8_t i=0;i<strlen(card.filename);i++)
  1478. card.filename[i]=tolower(card.filename[i]);
  1479. sprintf(cmd,"M23 %s",card.filename);
  1480. //sprintf(cmd,"M115");
  1481. enquecommand(cmd);
  1482. enquecommand("M24");
  1483. beep();
  1484. status=Main_Status;
  1485. lcd_status(card.filename);
  1486. }
  1487. }
  1488. }
  1489. }
  1490. break;
  1491. }
  1492. line++;
  1493. }
  1494. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  1495. if(enforceupdate)
  1496. {
  1497. force_lcd_update=true;
  1498. enforceupdate=false;
  1499. }
  1500. #endif
  1501. }
  1502. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file };
  1503. void MainMenu::showMainMenu()
  1504. {
  1505. #ifndef ULTIPANEL
  1506. force_lcd_update=false;
  1507. #endif
  1508. if(tune)
  1509. {
  1510. if(!(movesplanned() ||card.sdprinting))
  1511. {
  1512. force_lcd_update=true;
  1513. tune=false;
  1514. }
  1515. }
  1516. else
  1517. {
  1518. if(movesplanned() ||card.sdprinting)
  1519. {
  1520. force_lcd_update=true;
  1521. tune=true;
  1522. }
  1523. }
  1524. clearIfNecessary();
  1525. for(int8_t line=0;line<LCD_HEIGHT;line++)
  1526. {
  1527. switch(line)
  1528. {
  1529. case ItemM_watch:
  1530. MENUITEM( lcdprintPGM(" Watch \003") , BLOCK;status=Main_Status;beepshort(); ) ;
  1531. break;
  1532. case ItemM_prepare:
  1533. MENUITEM( if(!tune) lcdprintPGM(" Prepare \x7E");else lcdprintPGM(" Tune \x7E"); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  1534. break;
  1535. case ItemM_control:
  1536. MENUITEM( lcdprintPGM(" Control \x7E") , BLOCK;status=Main_Control;beepshort(); ) ;
  1537. break;
  1538. #ifdef SDSUPPORT
  1539. case ItemM_file:
  1540. {
  1541. if(force_lcd_update)
  1542. {
  1543. lcd.setCursor(0,line);
  1544. #ifdef CARDINSERTED
  1545. if(CARDINSERTED)
  1546. #else
  1547. if(true)
  1548. #endif
  1549. {
  1550. if(card.sdprinting)
  1551. lcdprintPGM(" Stop Print \x7E");
  1552. else
  1553. lcdprintPGM(" Card Menu \x7E");
  1554. }
  1555. else
  1556. {
  1557. lcdprintPGM(" No Card");
  1558. }
  1559. }
  1560. #ifdef CARDINSERTED
  1561. if(CARDINSERTED)
  1562. #endif
  1563. if((activeline==line)&&CLICKED)
  1564. {
  1565. card.printingHasFinished();
  1566. BLOCK;
  1567. status=Main_SD;
  1568. beepshort();
  1569. }
  1570. }break;
  1571. #else
  1572. case ItemM_file:
  1573. break;
  1574. #endif
  1575. default:
  1576. SERIAL_ERROR_START;
  1577. SERIAL_ERRORLNPGM("Something is wrong in the MenuStructure.");
  1578. break;
  1579. }
  1580. }
  1581. updateActiveLines(3,encoderpos);
  1582. }
  1583. void MainMenu::update()
  1584. {
  1585. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  1586. static long timeoutToStatus=0;
  1587. static bool oldcardstatus=false;
  1588. #ifdef CARDINSERTED
  1589. if((CARDINSERTED != oldcardstatus))
  1590. {
  1591. force_lcd_update=true;
  1592. oldcardstatus=CARDINSERTED;
  1593. //Serial.println("echo: SD CHANGE");
  1594. if(CARDINSERTED)
  1595. {
  1596. card.initsd();
  1597. LCD_MESSAGEPGM("Card inserted");
  1598. }
  1599. else
  1600. {
  1601. card.release();
  1602. LCD_MESSAGEPGM("Card removed");
  1603. }
  1604. }
  1605. #endif
  1606. if(status!=oldstatus)
  1607. {
  1608. force_lcd_update=true;
  1609. encoderpos=0;
  1610. lineoffset=0;
  1611. oldstatus=status;
  1612. }
  1613. if( (encoderpos!=lastencoderpos) || CLICKED)
  1614. timeoutToStatus=millis()+STATUSTIMEOUT;
  1615. switch(status)
  1616. {
  1617. case Main_Status:
  1618. {
  1619. showStatus();
  1620. if(CLICKED)
  1621. {
  1622. linechanging=false;
  1623. BLOCK
  1624. status=Main_Menu;
  1625. timeoutToStatus=millis()+STATUSTIMEOUT;
  1626. }
  1627. }break;
  1628. case Main_Menu:
  1629. {
  1630. showMainMenu();
  1631. linechanging=false;
  1632. }break;
  1633. case Main_Prepare:
  1634. {
  1635. if(tune)
  1636. {
  1637. showTune();
  1638. }
  1639. else
  1640. {
  1641. showPrepare();
  1642. }
  1643. }break;
  1644. case Main_Control:
  1645. {
  1646. showControl();
  1647. }break;
  1648. case Sub_MotionControl:
  1649. {
  1650. showControlMotion();
  1651. }break;
  1652. case Sub_TempControl:
  1653. {
  1654. showControlTemp();
  1655. }break;
  1656. case Main_SD:
  1657. {
  1658. showSD();
  1659. }break;
  1660. }
  1661. if(timeoutToStatus<millis())
  1662. status=Main_Status;
  1663. //force_lcd_update=false;
  1664. lastencoderpos=encoderpos;
  1665. }
  1666. // convert float to string with +123.4 format
  1667. char *ftostr3(const float &x)
  1668. {
  1669. //sprintf(conv,"%5.1f",x);
  1670. int xx=x;
  1671. conv[0]=(xx/100)%10+'0';
  1672. conv[1]=(xx/10)%10+'0';
  1673. conv[2]=(xx)%10+'0';
  1674. conv[3]=0;
  1675. return conv;
  1676. }
  1677. char *itostr2(const uint8_t &x)
  1678. {
  1679. //sprintf(conv,"%5.1f",x);
  1680. int xx=x;
  1681. conv[0]=(xx/10)%10+'0';
  1682. conv[1]=(xx)%10+'0';
  1683. conv[2]=0;
  1684. return conv;
  1685. }
  1686. // convert float to string with +123.4 format
  1687. char *ftostr31(const float &x)
  1688. {
  1689. int xx=x*10;
  1690. conv[0]=(xx>=0)?'+':'-';
  1691. xx=abs(xx);
  1692. conv[1]=(xx/1000)%10+'0';
  1693. conv[2]=(xx/100)%10+'0';
  1694. conv[3]=(xx/10)%10+'0';
  1695. conv[4]='.';
  1696. conv[5]=(xx)%10+'0';
  1697. conv[6]=0;
  1698. return conv;
  1699. }
  1700. char *ftostr32(const float &x)
  1701. {
  1702. int xx=x*100;
  1703. conv[0]=(xx>=0)?'+':'-';
  1704. xx=abs(xx);
  1705. conv[1]=(xx/100)%10+'0';
  1706. conv[2]='.';
  1707. conv[3]=(xx/10)%10+'0';
  1708. conv[4]=(xx)%10+'0';
  1709. conv[6]=0;
  1710. return conv;
  1711. }
  1712. char *itostr31(const int &xx)
  1713. {
  1714. conv[0]=(xx>=0)?'+':'-';
  1715. conv[1]=(xx/1000)%10+'0';
  1716. conv[2]=(xx/100)%10+'0';
  1717. conv[3]=(xx/10)%10+'0';
  1718. conv[4]='.';
  1719. conv[5]=(xx)%10+'0';
  1720. conv[6]=0;
  1721. return conv;
  1722. }
  1723. char *itostr3(const int &xx)
  1724. {
  1725. conv[0]=(xx/100)%10+'0';
  1726. conv[1]=(xx/10)%10+'0';
  1727. conv[2]=(xx)%10+'0';
  1728. conv[3]=0;
  1729. return conv;
  1730. }
  1731. char *itostr4(const int &xx)
  1732. {
  1733. conv[0]=(xx/1000)%10+'0';
  1734. conv[1]=(xx/100)%10+'0';
  1735. conv[2]=(xx/10)%10+'0';
  1736. conv[3]=(xx)%10+'0';
  1737. conv[4]=0;
  1738. return conv;
  1739. }
  1740. // convert float to string with +1234.5 format
  1741. char *ftostr51(const float &x)
  1742. {
  1743. int xx=x*10;
  1744. conv[0]=(xx>=0)?'+':'-';
  1745. xx=abs(xx);
  1746. conv[1]=(xx/10000)%10+'0';
  1747. conv[2]=(xx/1000)%10+'0';
  1748. conv[3]=(xx/100)%10+'0';
  1749. conv[4]=(xx/10)%10+'0';
  1750. conv[5]='.';
  1751. conv[6]=(xx)%10+'0';
  1752. conv[7]=0;
  1753. return conv;
  1754. }
  1755. #endif //ULTRA_LCD