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

ultralcd.pde 45KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931
  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_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);beepshort(); ) ;
  433. break;
  434. case ItemP_extrude:
  435. MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E50");beepshort(); ) ;
  436. break;
  437. default:
  438. break;
  439. }
  440. line++;
  441. }
  442. updateActiveLines(ItemP_extrude,encoderpos);
  443. }
  444. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  445. #if (HEATER_BED_PIN > -1)
  446. ItemT_bed,
  447. #endif
  448. ItemT_fan};
  449. void MainMenu::showTune()
  450. {
  451. uint8_t line=0;
  452. clearIfNecessary();
  453. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  454. {
  455. //Serial.println((int)(line-lineoffset));
  456. switch(i)
  457. {
  458. case ItemT_exit:
  459. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  460. break;
  461. case ItemT_speed:
  462. {
  463. if(force_lcd_update)
  464. {
  465. lcd.setCursor(0,line);lcdprintPGM(" Speed:");
  466. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  467. }
  468. if((activeline!=line) )
  469. break;
  470. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  471. {
  472. linechanging=!linechanging;
  473. if(linechanging)
  474. {
  475. encoderpos=feedmultiply;
  476. }
  477. else
  478. {
  479. encoderpos=activeline*lcdslow;
  480. beepshort();
  481. }
  482. BLOCK;
  483. }
  484. if(linechanging)
  485. {
  486. if(encoderpos<1) encoderpos=1;
  487. if(encoderpos>400) encoderpos=400;
  488. feedmultiply = encoderpos;
  489. feedmultiplychanged=true;
  490. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  491. }
  492. }break;
  493. case ItemT_nozzle:
  494. {
  495. if(force_lcd_update)
  496. {
  497. lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:");
  498. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  499. }
  500. if((activeline!=line) )
  501. break;
  502. if(CLICKED)
  503. {
  504. linechanging=!linechanging;
  505. if(linechanging)
  506. {
  507. encoderpos=intround(degTargetHotend0());
  508. }
  509. else
  510. {
  511. setTargetHotend0(encoderpos);
  512. encoderpos=activeline*lcdslow;
  513. beepshort();
  514. }
  515. BLOCK;
  516. }
  517. if(linechanging)
  518. {
  519. if(encoderpos<0) encoderpos=0;
  520. if(encoderpos>260) encoderpos=260;
  521. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  522. }
  523. }break;
  524. #if (HEATER_BED_PIN > -1)
  525. case ItemT_bed:
  526. {
  527. if(force_lcd_update)
  528. {
  529. lcd.setCursor(0,line);lcdprintPGM(" \002Bed:");
  530. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  531. }
  532. if((activeline!=line) )
  533. break;
  534. if(CLICKED)
  535. {
  536. linechanging=!linechanging;
  537. if(linechanging)
  538. {
  539. encoderpos=intround(degTargetBed());
  540. }
  541. else
  542. {
  543. setTargetBed(encoderpos);
  544. encoderpos=activeline*lcdslow;
  545. beepshort();
  546. }
  547. BLOCK;
  548. }
  549. if(linechanging)
  550. {
  551. if(encoderpos<0) encoderpos=0;
  552. if(encoderpos>260) encoderpos=260;
  553. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  554. }
  555. }break;
  556. #endif
  557. case ItemT_fan:
  558. {
  559. if(force_lcd_update)
  560. {
  561. lcd.setCursor(0,line);lcdprintPGM(" Fan speed:");
  562. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  563. }
  564. if((activeline!=line) )
  565. break;
  566. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  567. {
  568. linechanging=!linechanging;
  569. if(linechanging)
  570. {
  571. encoderpos=fanpwm;
  572. }
  573. else
  574. {
  575. encoderpos=activeline*lcdslow;
  576. beepshort();
  577. }
  578. BLOCK;
  579. }
  580. if(linechanging)
  581. {
  582. if(encoderpos<0) encoderpos=0;
  583. if(encoderpos>255) encoderpos=255;
  584. fanpwm=encoderpos;
  585. analogWrite(FAN_PIN, fanpwm);
  586. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  587. }
  588. }break;
  589. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  590. {
  591. if(force_lcd_update)
  592. {
  593. lcd.setCursor(0,line);lcdprintPGM(" Flow:");
  594. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  595. }
  596. if((activeline!=line) )
  597. break;
  598. if(CLICKED)
  599. {
  600. linechanging=!linechanging;
  601. if(linechanging)
  602. {
  603. encoderpos=(int)axis_steps_per_unit[3];
  604. }
  605. else
  606. {
  607. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  608. position[E_AXIS]=lround(position[E_AXIS]*factor);
  609. //current_position[3]*=factor;
  610. axis_steps_per_unit[E_AXIS]= encoderpos;
  611. encoderpos=activeline*lcdslow;
  612. }
  613. BLOCK;
  614. beepshort();
  615. }
  616. if(linechanging)
  617. {
  618. if(encoderpos<5) encoderpos=5;
  619. if(encoderpos>9999) encoderpos=9999;
  620. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  621. }
  622. }break;
  623. default:
  624. break;
  625. }
  626. line++;
  627. }
  628. updateActiveLines(ItemT_fan,encoderpos);
  629. }
  630. //does not work
  631. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  632. // {\
  633. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  634. // if(activeline==line) \
  635. // { \
  636. // if(CLICKED) \
  637. // { \
  638. // linechanging=!linechanging; \
  639. // if(linechanging) {enter_action;} \
  640. // else {accept_action;} \
  641. // } \
  642. // else \
  643. // if(linechanging) {change_action};}\
  644. // }
  645. //
  646. enum {
  647. ItemCT_exit,ItemCT_nozzle,
  648. #ifdef AUTOTEMP
  649. ItemCT_autotempactive,
  650. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  651. #endif
  652. #if (HEATER_BED_PIN > -1)
  653. ItemCT_bed,
  654. #endif
  655. ItemCT_fan,
  656. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C
  657. };
  658. void MainMenu::showControlTemp()
  659. {
  660. uint8_t line=0;
  661. clearIfNecessary();
  662. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  663. {
  664. switch(i)
  665. {
  666. case ItemCT_exit:
  667. MENUITEM( lcdprintPGM(" Control \003") , BLOCK;status=Main_Control;beepshort(); ) ;
  668. break;
  669. case ItemCT_nozzle:
  670. {
  671. if(force_lcd_update)
  672. {
  673. lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:");
  674. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  675. }
  676. if((activeline!=line) )
  677. break;
  678. if(CLICKED)
  679. {
  680. linechanging=!linechanging;
  681. if(linechanging)
  682. {
  683. encoderpos=intround(degTargetHotend0());
  684. }
  685. else
  686. {
  687. setTargetHotend0(encoderpos);
  688. encoderpos=activeline*lcdslow;
  689. beepshort();
  690. }
  691. BLOCK;
  692. }
  693. if(linechanging)
  694. {
  695. if(encoderpos<0) encoderpos=0;
  696. if(encoderpos>260) encoderpos=260;
  697. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  698. }
  699. }break;
  700. #ifdef AUTOTEMP
  701. case ItemCT_autotempmin:
  702. {
  703. if(force_lcd_update)
  704. {
  705. lcd.setCursor(0,line);lcdprintPGM(" \002 Min:");
  706. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  707. }
  708. if((activeline!=line) )
  709. break;
  710. if(CLICKED)
  711. {
  712. linechanging=!linechanging;
  713. if(linechanging)
  714. {
  715. encoderpos=intround(autotemp_min);
  716. }
  717. else
  718. {
  719. autotemp_min=encoderpos;
  720. encoderpos=activeline*lcdslow;
  721. beepshort();
  722. }
  723. BLOCK;
  724. }
  725. if(linechanging)
  726. {
  727. if(encoderpos<0) encoderpos=0;
  728. if(encoderpos>260) encoderpos=260;
  729. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  730. }
  731. }break;
  732. case ItemCT_autotempmax:
  733. {
  734. if(force_lcd_update)
  735. {
  736. lcd.setCursor(0,line);lcdprintPGM(" \002 Max:");
  737. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  738. }
  739. if((activeline!=line) )
  740. break;
  741. if(CLICKED)
  742. {
  743. linechanging=!linechanging;
  744. if(linechanging)
  745. {
  746. encoderpos=intround(autotemp_max);
  747. }
  748. else
  749. {
  750. autotemp_max=encoderpos;
  751. encoderpos=activeline*lcdslow;
  752. beepshort();
  753. }
  754. BLOCK;
  755. }
  756. if(linechanging)
  757. {
  758. if(encoderpos<0) encoderpos=0;
  759. if(encoderpos>260) encoderpos=260;
  760. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  761. }
  762. }break;
  763. case ItemCT_autotempfact:
  764. {
  765. if(force_lcd_update)
  766. {
  767. lcd.setCursor(0,line);lcdprintPGM(" \002 Fact:");
  768. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  769. }
  770. if((activeline!=line) )
  771. break;
  772. if(CLICKED)
  773. {
  774. linechanging=!linechanging;
  775. if(linechanging)
  776. {
  777. encoderpos=intround(autotemp_factor*100);
  778. }
  779. else
  780. {
  781. autotemp_max=encoderpos;
  782. encoderpos=activeline*lcdslow;
  783. beepshort();
  784. }
  785. BLOCK;
  786. }
  787. if(linechanging)
  788. {
  789. if(encoderpos<0) encoderpos=0;
  790. if(encoderpos>99) encoderpos=99;
  791. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  792. }
  793. }break;
  794. case ItemCT_autotempactive:
  795. {
  796. if(force_lcd_update)
  797. {
  798. lcd.setCursor(0,line);lcdprintPGM(" Autotemp:");
  799. lcd.setCursor(13,line);
  800. if(autotemp_enabled)
  801. lcdprintPGM("On");
  802. else
  803. lcdprintPGM("Off");
  804. }
  805. if((activeline!=line) )
  806. break;
  807. if(CLICKED)
  808. {
  809. autotemp_enabled=!autotemp_enabled;
  810. lcd.setCursor(13,line);
  811. if(autotemp_enabled)
  812. lcdprintPGM("On ");
  813. else
  814. lcdprintPGM("Off");
  815. BLOCK;
  816. }
  817. }break;
  818. #endif //autotemp
  819. #if (HEATER_BED_PIN > -1)
  820. case ItemCT_bed:
  821. {
  822. if(force_lcd_update)
  823. {
  824. lcd.setCursor(0,line);lcdprintPGM(" \002Bed:");
  825. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  826. }
  827. if((activeline!=line) )
  828. break;
  829. if(CLICKED)
  830. {
  831. linechanging=!linechanging;
  832. if(linechanging)
  833. {
  834. encoderpos=intround(degTargetBed());
  835. }
  836. else
  837. {
  838. setTargetBed(encoderpos);
  839. encoderpos=activeline*lcdslow;
  840. beepshort();
  841. }
  842. BLOCK;
  843. }
  844. if(linechanging)
  845. {
  846. if(encoderpos<0) encoderpos=0;
  847. if(encoderpos>260) encoderpos=260;
  848. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  849. }
  850. }break;
  851. #endif
  852. case ItemCT_fan:
  853. {
  854. if(force_lcd_update)
  855. {
  856. lcd.setCursor(0,line);lcdprintPGM(" Fan speed:");
  857. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  858. }
  859. if((activeline!=line) )
  860. break;
  861. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  862. {
  863. linechanging=!linechanging;
  864. if(linechanging)
  865. {
  866. encoderpos=fanpwm;
  867. }
  868. else
  869. {
  870. encoderpos=activeline*lcdslow;
  871. beepshort();
  872. }
  873. BLOCK;
  874. }
  875. if(linechanging)
  876. {
  877. if(encoderpos<0) encoderpos=0;
  878. if(encoderpos>255) encoderpos=255;
  879. fanpwm=encoderpos;
  880. analogWrite(FAN_PIN, fanpwm);
  881. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  882. }
  883. }break;
  884. case ItemCT_PID_P:
  885. {
  886. if(force_lcd_update)
  887. {
  888. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  889. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  890. }
  891. if((activeline!=line) )
  892. break;
  893. if(CLICKED)
  894. {
  895. linechanging=!linechanging;
  896. if(linechanging)
  897. {
  898. encoderpos=(int)Kp;
  899. }
  900. else
  901. {
  902. Kp= encoderpos;
  903. encoderpos=activeline*lcdslow;
  904. }
  905. BLOCK;
  906. beepshort();
  907. }
  908. if(linechanging)
  909. {
  910. if(encoderpos<1) encoderpos=1;
  911. if(encoderpos>9990) encoderpos=9990;
  912. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  913. }
  914. }break;
  915. case ItemCT_PID_I:
  916. {
  917. if(force_lcd_update)
  918. {
  919. lcd.setCursor(0,line);lcdprintPGM(" PID-I: ");
  920. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  921. }
  922. if((activeline!=line) )
  923. break;
  924. if(CLICKED)
  925. {
  926. linechanging=!linechanging;
  927. if(linechanging)
  928. {
  929. encoderpos=(int)(Ki*10/PID_dT);
  930. }
  931. else
  932. {
  933. Ki= encoderpos/10.*PID_dT;
  934. encoderpos=activeline*lcdslow;
  935. }
  936. BLOCK;
  937. beepshort();
  938. }
  939. if(linechanging)
  940. {
  941. if(encoderpos<0) encoderpos=0;
  942. if(encoderpos>9990) encoderpos=9990;
  943. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  944. }
  945. }break;
  946. case ItemCT_PID_D:
  947. {
  948. if(force_lcd_update)
  949. {
  950. lcd.setCursor(0,line);lcdprintPGM(" PID-D: ");
  951. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  952. }
  953. if((activeline!=line) )
  954. break;
  955. if(CLICKED)
  956. {
  957. linechanging=!linechanging;
  958. if(linechanging)
  959. {
  960. encoderpos=(int)(Kd/5./PID_dT);
  961. }
  962. else
  963. {
  964. Kd= encoderpos;
  965. encoderpos=activeline*lcdslow;
  966. }
  967. BLOCK;
  968. beepshort();
  969. }
  970. if(linechanging)
  971. {
  972. if(encoderpos<0) encoderpos=0;
  973. if(encoderpos>9990) encoderpos=9990;
  974. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  975. }
  976. }break;
  977. case ItemCT_PID_C:
  978. #ifdef PID_ADD_EXTRUSION_RATE
  979. {
  980. if(force_lcd_update)
  981. {
  982. lcd.setCursor(0,line);lcdprintPGM(" PID-C: ");
  983. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  984. }
  985. if((activeline!=line) )
  986. break;
  987. if(CLICKED)
  988. {
  989. linechanging=!linechanging;
  990. if(linechanging)
  991. {
  992. encoderpos=(int)Kc;
  993. }
  994. else
  995. {
  996. Kc= encoderpos;
  997. encoderpos=activeline*lcdslow;
  998. }
  999. BLOCK;
  1000. beepshort();
  1001. }
  1002. if(linechanging)
  1003. {
  1004. if(encoderpos<0) encoderpos=0;
  1005. if(encoderpos>990) encoderpos=990;
  1006. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1007. }
  1008. }
  1009. #endif
  1010. break;
  1011. default:
  1012. break;
  1013. }
  1014. line++;
  1015. }
  1016. #ifdef PID_ADD_EXTRUSION_RATE
  1017. updateActiveLines(ItemCT_PID_C,encoderpos);
  1018. #else
  1019. updateActiveLines(ItemCT_PID_D,encoderpos);
  1020. #endif
  1021. }
  1022. enum {
  1023. ItemCM_exit,
  1024. ItemCM_acc, ItemCM_xyjerk,
  1025. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1026. ItemCM_vtravmin,ItemCM_vmin,
  1027. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1028. ItemCM_aret,ItemCM_esteps
  1029. };
  1030. void MainMenu::showControlMotion()
  1031. {
  1032. uint8_t line=0;
  1033. clearIfNecessary();
  1034. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1035. {
  1036. switch(i)
  1037. {
  1038. case ItemCM_exit:
  1039. MENUITEM( lcdprintPGM(" Control \003") , BLOCK;status=Main_Control;beepshort(); ) ;
  1040. break;
  1041. case ItemCM_acc:
  1042. {
  1043. if(force_lcd_update)
  1044. {
  1045. lcd.setCursor(0,line);lcdprintPGM(" Acc:");
  1046. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1047. }
  1048. if((activeline!=line) )
  1049. break;
  1050. if(CLICKED)
  1051. {
  1052. linechanging=!linechanging;
  1053. if(linechanging)
  1054. {
  1055. encoderpos=(int)acceleration/100;
  1056. }
  1057. else
  1058. {
  1059. acceleration= encoderpos*100;
  1060. encoderpos=activeline*lcdslow;
  1061. }
  1062. BLOCK;
  1063. beepshort();
  1064. }
  1065. if(linechanging)
  1066. {
  1067. if(encoderpos<5) encoderpos=5;
  1068. if(encoderpos>990) encoderpos=990;
  1069. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1070. }
  1071. }break;
  1072. case ItemCM_xyjerk: //max_xy_jerk
  1073. {
  1074. if(force_lcd_update)
  1075. {
  1076. lcd.setCursor(0,line);lcdprintPGM(" Vxy-jerk: ");
  1077. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1078. }
  1079. if((activeline!=line) )
  1080. break;
  1081. if(CLICKED)
  1082. {
  1083. linechanging=!linechanging;
  1084. if(linechanging)
  1085. {
  1086. encoderpos=(int)max_xy_jerk;
  1087. }
  1088. else
  1089. {
  1090. max_xy_jerk= encoderpos;
  1091. encoderpos=activeline*lcdslow;
  1092. }
  1093. BLOCK;
  1094. beepshort();
  1095. }
  1096. if(linechanging)
  1097. {
  1098. if(encoderpos<1) encoderpos=1;
  1099. if(encoderpos>990) encoderpos=990;
  1100. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1101. }
  1102. }break;
  1103. case ItemCM_vmaxx:
  1104. case ItemCM_vmaxy:
  1105. case ItemCM_vmaxz:
  1106. case ItemCM_vmaxe:
  1107. {
  1108. if(force_lcd_update)
  1109. {
  1110. lcd.setCursor(0,line);lcdprintPGM(" Vmax ");
  1111. if(i==ItemCM_vmaxx)lcdprintPGM("x:");
  1112. if(i==ItemCM_vmaxy)lcdprintPGM("y:");
  1113. if(i==ItemCM_vmaxz)lcdprintPGM("z:");
  1114. if(i==ItemCM_vmaxe)lcdprintPGM("e:");
  1115. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1116. }
  1117. if((activeline!=line) )
  1118. break;
  1119. if(CLICKED)
  1120. {
  1121. linechanging=!linechanging;
  1122. if(linechanging)
  1123. {
  1124. encoderpos=(int)max_feedrate[i-ItemCM_vmaxx];
  1125. }
  1126. else
  1127. {
  1128. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1129. encoderpos=activeline*lcdslow;
  1130. }
  1131. BLOCK;
  1132. beepshort();
  1133. }
  1134. if(linechanging)
  1135. {
  1136. if(encoderpos<1) encoderpos=1;
  1137. if(encoderpos>990) encoderpos=990;
  1138. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1139. }
  1140. }break;
  1141. case ItemCM_vmin:
  1142. {
  1143. if(force_lcd_update)
  1144. {
  1145. lcd.setCursor(0,line);lcdprintPGM(" Vmin:");
  1146. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1147. }
  1148. if((activeline!=line) )
  1149. break;
  1150. if(CLICKED)
  1151. {
  1152. linechanging=!linechanging;
  1153. if(linechanging)
  1154. {
  1155. encoderpos=(int)(minimumfeedrate);
  1156. }
  1157. else
  1158. {
  1159. minimumfeedrate= encoderpos;
  1160. encoderpos=activeline*lcdslow;
  1161. }
  1162. BLOCK;
  1163. beepshort();
  1164. }
  1165. if(linechanging)
  1166. {
  1167. if(encoderpos<0) encoderpos=0;
  1168. if(encoderpos>990) encoderpos=990;
  1169. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1170. }
  1171. }break;
  1172. case ItemCM_vtravmin:
  1173. {
  1174. if(force_lcd_update)
  1175. {
  1176. lcd.setCursor(0,line);lcdprintPGM(" VTrav min:");
  1177. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1178. }
  1179. if((activeline!=line) )
  1180. break;
  1181. if(CLICKED)
  1182. {
  1183. linechanging=!linechanging;
  1184. if(linechanging)
  1185. {
  1186. encoderpos=(int)mintravelfeedrate;
  1187. }
  1188. else
  1189. {
  1190. mintravelfeedrate= encoderpos;
  1191. encoderpos=activeline*lcdslow;
  1192. }
  1193. BLOCK;
  1194. beepshort();
  1195. }
  1196. if(linechanging)
  1197. {
  1198. if(encoderpos<0) encoderpos=0;
  1199. if(encoderpos>990) encoderpos=990;
  1200. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1201. }
  1202. }break;
  1203. case ItemCM_amaxx:
  1204. case ItemCM_amaxy:
  1205. case ItemCM_amaxz:
  1206. case ItemCM_amaxe:
  1207. {
  1208. if(force_lcd_update)
  1209. {
  1210. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1211. if(i==ItemCM_amaxx)lcdprintPGM("x:");
  1212. if(i==ItemCM_amaxy)lcdprintPGM("y:");
  1213. if(i==ItemCM_amaxz)lcdprintPGM("z:");
  1214. if(i==ItemCM_amaxe)lcdprintPGM("e:");
  1215. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1216. }
  1217. if((activeline!=line) )
  1218. break;
  1219. if(CLICKED)
  1220. {
  1221. linechanging=!linechanging;
  1222. if(linechanging)
  1223. {
  1224. encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1225. }
  1226. else
  1227. {
  1228. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1229. encoderpos=activeline*lcdslow;
  1230. }
  1231. BLOCK;
  1232. beepshort();
  1233. }
  1234. if(linechanging)
  1235. {
  1236. if(encoderpos<1) encoderpos=1;
  1237. if(encoderpos>990) encoderpos=990;
  1238. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1239. }
  1240. }break;
  1241. case ItemCM_aret://float retract_acceleration = 7000;
  1242. {
  1243. if(force_lcd_update)
  1244. {
  1245. lcd.setCursor(0,line);lcdprintPGM(" A-retract:");
  1246. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1247. }
  1248. if((activeline!=line) )
  1249. break;
  1250. if(CLICKED)
  1251. {
  1252. linechanging=!linechanging;
  1253. if(linechanging)
  1254. {
  1255. encoderpos=(int)retract_acceleration/100;
  1256. }
  1257. else
  1258. {
  1259. retract_acceleration= encoderpos*100;
  1260. encoderpos=activeline*lcdslow;
  1261. }
  1262. BLOCK;
  1263. beepshort();
  1264. }
  1265. if(linechanging)
  1266. {
  1267. if(encoderpos<10) encoderpos=10;
  1268. if(encoderpos>990) encoderpos=990;
  1269. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1270. }
  1271. }break;
  1272. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1273. {
  1274. if(force_lcd_update)
  1275. {
  1276. lcd.setCursor(0,line);lcdprintPGM(" Esteps/mm:");
  1277. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  1278. }
  1279. if((activeline!=line) )
  1280. break;
  1281. if(CLICKED)
  1282. {
  1283. linechanging=!linechanging;
  1284. if(linechanging)
  1285. {
  1286. encoderpos=(int)axis_steps_per_unit[3];
  1287. }
  1288. else
  1289. {
  1290. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  1291. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1292. //current_position[3]*=factor;
  1293. axis_steps_per_unit[E_AXIS]= encoderpos;
  1294. encoderpos=activeline*lcdslow;
  1295. }
  1296. BLOCK;
  1297. beepshort();
  1298. }
  1299. if(linechanging)
  1300. {
  1301. if(encoderpos<5) encoderpos=5;
  1302. if(encoderpos>9999) encoderpos=9999;
  1303. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1304. }
  1305. }break;
  1306. default:
  1307. break;
  1308. }
  1309. line++;
  1310. }
  1311. updateActiveLines(ItemCM_esteps,encoderpos);
  1312. }
  1313. enum {
  1314. ItemC_exit,ItemC_temp,ItemC_move,
  1315. ItemC_store, ItemC_load,ItemC_failsafe
  1316. };
  1317. void MainMenu::showControl()
  1318. {
  1319. uint8_t line=0;
  1320. clearIfNecessary();
  1321. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1322. {
  1323. switch(i)
  1324. {
  1325. case ItemC_exit:
  1326. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  1327. break;
  1328. case ItemC_temp:
  1329. MENUITEM( lcdprintPGM(" Temperature \x7E") , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1330. break;
  1331. case ItemC_move:
  1332. MENUITEM( lcdprintPGM(" Motion \x7E") , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1333. break;
  1334. case ItemC_store:
  1335. {
  1336. if(force_lcd_update)
  1337. {
  1338. lcd.setCursor(0,line);lcdprintPGM(" Store EPROM");
  1339. }
  1340. if((activeline==line) && CLICKED)
  1341. {
  1342. //enquecommand("M84");
  1343. beepshort();
  1344. BLOCK;
  1345. EEPROM_StoreSettings();
  1346. }
  1347. }break;
  1348. case ItemC_load:
  1349. {
  1350. if(force_lcd_update)
  1351. {
  1352. lcd.setCursor(0,line);lcdprintPGM(" Load EPROM");
  1353. }
  1354. if((activeline==line) && CLICKED)
  1355. {
  1356. //enquecommand("M84");
  1357. beepshort();
  1358. BLOCK;
  1359. EEPROM_RetrieveSettings();
  1360. }
  1361. }break;
  1362. case ItemC_failsafe:
  1363. {
  1364. if(force_lcd_update)
  1365. {
  1366. lcd.setCursor(0,line);lcdprintPGM(" Restore Failsafe");
  1367. }
  1368. if((activeline==line) && CLICKED)
  1369. {
  1370. //enquecommand("M84");
  1371. beepshort();
  1372. BLOCK;
  1373. EEPROM_RetrieveSettings(true);
  1374. }
  1375. }break;
  1376. default:
  1377. break;
  1378. }
  1379. line++;
  1380. }
  1381. updateActiveLines(ItemC_failsafe,encoderpos);
  1382. }
  1383. void MainMenu::showSD()
  1384. {
  1385. #ifdef SDSUPPORT
  1386. uint8_t line=0;
  1387. clearIfNecessary();
  1388. static uint8_t nrfiles=0;
  1389. if(force_lcd_update)
  1390. {
  1391. if(card.cardOK)
  1392. {
  1393. nrfiles=card.getnrfilenames();
  1394. }
  1395. else
  1396. {
  1397. nrfiles=0;
  1398. lineoffset=0;
  1399. }
  1400. }
  1401. bool enforceupdate=false;
  1402. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1403. {
  1404. switch(i)
  1405. {
  1406. case 0:
  1407. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  1408. break;
  1409. // case 1:
  1410. // {
  1411. // if(force_lcd_update)
  1412. // {
  1413. // lcd.setCursor(0,line);
  1414. // #ifdef CARDINSERTED
  1415. // if(CARDINSERTED)
  1416. // #else
  1417. // if(true)
  1418. // #endif
  1419. // {
  1420. // lcdprintPGM(" \004Refresh");
  1421. // }
  1422. // else
  1423. // {
  1424. // lcdprintPGM(" \004Insert Card");
  1425. // }
  1426. //
  1427. // }
  1428. // if((activeline==line) && CLICKED)
  1429. // {
  1430. // BLOCK;
  1431. // beepshort();
  1432. // card.initsd();
  1433. // force_lcd_update=true;
  1434. // nrfiles=card.getnrfilenames();
  1435. // }
  1436. // }break;
  1437. case 1:
  1438. 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(); ) ;
  1439. break;
  1440. default:
  1441. {
  1442. #define FIRSTITEM 2
  1443. if(i-FIRSTITEM<nrfiles)
  1444. {
  1445. if(force_lcd_update)
  1446. {
  1447. card.getfilename(i-FIRSTITEM);
  1448. //Serial.print("Filenr:");Serial.println(i-2);
  1449. lcd.setCursor(0,line);lcdprintPGM(" ");
  1450. if(card.filenameIsDir) lcd.print("\005");
  1451. lcd.print(card.filename);
  1452. }
  1453. if((activeline==line) && CLICKED)
  1454. {
  1455. BLOCK
  1456. card.getfilename(i-FIRSTITEM);
  1457. if(card.filenameIsDir)
  1458. {
  1459. for(int8_t i=0;i<strlen(card.filename);i++)
  1460. card.filename[i]=tolower(card.filename[i]);
  1461. card.chdir(card.filename);
  1462. lineoffset=0;
  1463. enforceupdate=true;
  1464. }
  1465. else
  1466. {
  1467. char cmd[30];
  1468. for(int8_t i=0;i<strlen(card.filename);i++)
  1469. card.filename[i]=tolower(card.filename[i]);
  1470. sprintf(cmd,"M23 %s",card.filename);
  1471. //sprintf(cmd,"M115");
  1472. enquecommand(cmd);
  1473. enquecommand("M24");
  1474. beep();
  1475. status=Main_Status;
  1476. lcd_status(card.filename);
  1477. }
  1478. }
  1479. }
  1480. }
  1481. break;
  1482. }
  1483. line++;
  1484. }
  1485. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  1486. if(enforceupdate)
  1487. {
  1488. force_lcd_update=true;
  1489. enforceupdate=false;
  1490. }
  1491. #endif
  1492. }
  1493. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file };
  1494. void MainMenu::showMainMenu()
  1495. {
  1496. #ifndef ULTIPANEL
  1497. force_lcd_update=false;
  1498. #endif
  1499. if(tune)
  1500. {
  1501. if(!(movesplanned() ||card.sdprinting))
  1502. {
  1503. force_lcd_update=true;
  1504. tune=false;
  1505. }
  1506. }
  1507. else
  1508. {
  1509. if(movesplanned() ||card.sdprinting)
  1510. {
  1511. force_lcd_update=true;
  1512. tune=true;
  1513. }
  1514. }
  1515. clearIfNecessary();
  1516. for(int8_t line=0;line<LCD_HEIGHT;line++)
  1517. {
  1518. switch(line)
  1519. {
  1520. case ItemM_watch:
  1521. MENUITEM( lcdprintPGM(" Watch \003") , BLOCK;status=Main_Status;beepshort(); ) ;
  1522. break;
  1523. case ItemM_prepare:
  1524. MENUITEM( if(!tune) lcdprintPGM(" Prepare \x7E");else lcdprintPGM(" Tune \x7E"); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  1525. break;
  1526. case ItemM_control:
  1527. MENUITEM( lcdprintPGM(" Control \x7E") , BLOCK;status=Main_Control;beepshort(); ) ;
  1528. break;
  1529. #ifdef SDSUPPORT
  1530. case ItemM_file:
  1531. {
  1532. if(force_lcd_update)
  1533. {
  1534. lcd.setCursor(0,line);
  1535. #ifdef CARDINSERTED
  1536. if(CARDINSERTED)
  1537. #else
  1538. if(true)
  1539. #endif
  1540. {
  1541. if(card.sdprinting)
  1542. lcdprintPGM(" Stop Print \x7E");
  1543. else
  1544. lcdprintPGM(" Card Menu \x7E");
  1545. }
  1546. else
  1547. {
  1548. lcdprintPGM(" No Card");
  1549. }
  1550. }
  1551. #ifdef CARDINSERTED
  1552. if(CARDINSERTED)
  1553. #endif
  1554. if((activeline==line)&&CLICKED)
  1555. {
  1556. card.printingHasFinished();
  1557. BLOCK;
  1558. status=Main_SD;
  1559. beepshort();
  1560. }
  1561. }break;
  1562. #else
  1563. case ItemM_file:
  1564. break;
  1565. #endif
  1566. default:
  1567. SERIAL_ERROR_START;
  1568. SERIAL_ERRORLNPGM("Something is wrong in the MenuStructure.");
  1569. break;
  1570. }
  1571. }
  1572. updateActiveLines(3,encoderpos);
  1573. }
  1574. void MainMenu::update()
  1575. {
  1576. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  1577. static long timeoutToStatus=0;
  1578. static bool oldcardstatus=false;
  1579. #ifdef CARDINSERTED
  1580. if((CARDINSERTED != oldcardstatus))
  1581. {
  1582. force_lcd_update=true;
  1583. oldcardstatus=CARDINSERTED;
  1584. //Serial.println("echo: SD CHANGE");
  1585. if(CARDINSERTED)
  1586. {
  1587. card.initsd();
  1588. LCD_MESSAGEPGM("Card inserted");
  1589. }
  1590. else
  1591. {
  1592. card.release();
  1593. LCD_MESSAGEPGM("Card removed");
  1594. }
  1595. }
  1596. #endif
  1597. if(status!=oldstatus)
  1598. {
  1599. force_lcd_update=true;
  1600. encoderpos=0;
  1601. lineoffset=0;
  1602. oldstatus=status;
  1603. }
  1604. if( (encoderpos!=lastencoderpos) || CLICKED)
  1605. timeoutToStatus=millis()+STATUSTIMEOUT;
  1606. switch(status)
  1607. {
  1608. case Main_Status:
  1609. {
  1610. showStatus();
  1611. if(CLICKED)
  1612. {
  1613. linechanging=false;
  1614. BLOCK
  1615. status=Main_Menu;
  1616. timeoutToStatus=millis()+STATUSTIMEOUT;
  1617. }
  1618. }break;
  1619. case Main_Menu:
  1620. {
  1621. showMainMenu();
  1622. linechanging=false;
  1623. }break;
  1624. case Main_Prepare:
  1625. {
  1626. if(tune)
  1627. {
  1628. showTune();
  1629. }
  1630. else
  1631. {
  1632. showPrepare();
  1633. }
  1634. }break;
  1635. case Main_Control:
  1636. {
  1637. showControl();
  1638. }break;
  1639. case Sub_MotionControl:
  1640. {
  1641. showControlMotion();
  1642. }break;
  1643. case Sub_TempControl:
  1644. {
  1645. showControlTemp();
  1646. }break;
  1647. case Main_SD:
  1648. {
  1649. showSD();
  1650. }break;
  1651. }
  1652. if(timeoutToStatus<millis())
  1653. status=Main_Status;
  1654. //force_lcd_update=false;
  1655. lastencoderpos=encoderpos;
  1656. }
  1657. // convert float to string with +123.4 format
  1658. char *ftostr3(const float &x)
  1659. {
  1660. //sprintf(conv,"%5.1f",x);
  1661. int xx=x;
  1662. conv[0]=(xx/100)%10+'0';
  1663. conv[1]=(xx/10)%10+'0';
  1664. conv[2]=(xx)%10+'0';
  1665. conv[3]=0;
  1666. return conv;
  1667. }
  1668. char *itostr2(const uint8_t &x)
  1669. {
  1670. //sprintf(conv,"%5.1f",x);
  1671. int xx=x;
  1672. conv[0]=(xx/10)%10+'0';
  1673. conv[1]=(xx)%10+'0';
  1674. conv[2]=0;
  1675. return conv;
  1676. }
  1677. // convert float to string with +123.4 format
  1678. char *ftostr31(const float &x)
  1679. {
  1680. int xx=x*10;
  1681. conv[0]=(xx>=0)?'+':'-';
  1682. xx=abs(xx);
  1683. conv[1]=(xx/1000)%10+'0';
  1684. conv[2]=(xx/100)%10+'0';
  1685. conv[3]=(xx/10)%10+'0';
  1686. conv[4]='.';
  1687. conv[5]=(xx)%10+'0';
  1688. conv[6]=0;
  1689. return conv;
  1690. }
  1691. char *ftostr32(const float &x)
  1692. {
  1693. int xx=x*100;
  1694. conv[0]=(xx>=0)?'+':'-';
  1695. xx=abs(xx);
  1696. conv[1]=(xx/100)%10+'0';
  1697. conv[2]='.';
  1698. conv[3]=(xx/10)%10+'0';
  1699. conv[4]=(xx)%10+'0';
  1700. conv[6]=0;
  1701. return conv;
  1702. }
  1703. char *itostr31(const int &xx)
  1704. {
  1705. conv[0]=(xx>=0)?'+':'-';
  1706. conv[1]=(xx/1000)%10+'0';
  1707. conv[2]=(xx/100)%10+'0';
  1708. conv[3]=(xx/10)%10+'0';
  1709. conv[4]='.';
  1710. conv[5]=(xx)%10+'0';
  1711. conv[6]=0;
  1712. return conv;
  1713. }
  1714. char *itostr3(const int &xx)
  1715. {
  1716. conv[0]=(xx/100)%10+'0';
  1717. conv[1]=(xx/10)%10+'0';
  1718. conv[2]=(xx)%10+'0';
  1719. conv[3]=0;
  1720. return conv;
  1721. }
  1722. char *itostr4(const int &xx)
  1723. {
  1724. conv[0]=(xx/1000)%10+'0';
  1725. conv[1]=(xx/100)%10+'0';
  1726. conv[2]=(xx/10)%10+'0';
  1727. conv[3]=(xx)%10+'0';
  1728. conv[4]=0;
  1729. return conv;
  1730. }
  1731. // convert float to string with +1234.5 format
  1732. char *ftostr51(const float &x)
  1733. {
  1734. int xx=x*10;
  1735. conv[0]=(xx>=0)?'+':'-';
  1736. xx=abs(xx);
  1737. conv[1]=(xx/10000)%10+'0';
  1738. conv[2]=(xx/1000)%10+'0';
  1739. conv[3]=(xx/100)%10+'0';
  1740. conv[4]=(xx/10)%10+'0';
  1741. conv[5]='.';
  1742. conv[6]=(xx)%10+'0';
  1743. conv[7]=0;
  1744. return conv;
  1745. }
  1746. #endif //ULTRA_LCD