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

ultralcd.pde 45KB

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