My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ultralcd.pde 45KB

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