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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  1. #include "ultralcd.h"
  2. #ifdef ULTRA_LCD
  3. //===========================================================================
  4. //=============================imported variables============================
  5. //===========================================================================
  6. extern volatile int feedmultiply;
  7. extern volatile bool feedmultiplychanged;
  8. extern long position[4];
  9. extern CardReader card;
  10. //===========================================================================
  11. //=============================public variables============================
  12. //===========================================================================
  13. volatile char buttons=0; //the last checked buttons in a bit array.
  14. int encoderpos=0;
  15. short lastenc=0;
  16. //===========================================================================
  17. //=============================private variables============================
  18. //===========================================================================
  19. static char messagetext[LCD_WIDTH]="";
  20. //return for string conversion routines
  21. static char conv[8];
  22. #include <LiquidCrystal.h>
  23. 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
  24. static unsigned long previous_millis_lcd=0;
  25. static long previous_millis_buttons=0;
  26. #ifdef NEWPANEL
  27. static long blocking=0;
  28. #else
  29. static long blocking[8]={0,0,0,0,0,0,0,0};
  30. #endif
  31. static MainMenu menu;
  32. #include <avr/pgmspace.h>
  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