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 57KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381
  1. #include "ultralcd.h"
  2. #ifdef ULTRA_LCD
  3. #include "Marlin.h"
  4. #include <LiquidCrystal.h>
  5. //===========================================================================
  6. //=============================imported variables============================
  7. //===========================================================================
  8. extern volatile int feedmultiply;
  9. extern volatile bool feedmultiplychanged;
  10. extern volatile int extrudemultiply;
  11. extern long position[4];
  12. #ifdef SDSUPPORT
  13. extern CardReader card;
  14. #endif
  15. //===========================================================================
  16. //=============================public variables============================
  17. //===========================================================================
  18. volatile char buttons=0; //the last checked buttons in a bit array.
  19. int encoderpos=0;
  20. short lastenc=0;
  21. //===========================================================================
  22. //=============================private variables============================
  23. //===========================================================================
  24. static char messagetext[LCD_WIDTH]="";
  25. //return for string conversion routines
  26. static char conv[8];
  27. 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
  28. static unsigned long previous_millis_lcd=0;
  29. //static long previous_millis_buttons=0;
  30. #ifdef NEWPANEL
  31. static long blocking=0;
  32. #else
  33. static long blocking[8]={0,0,0,0,0,0,0,0};
  34. #endif
  35. static MainMenu menu;
  36. void lcdProgMemprint(const char *str)
  37. {
  38. char ch=pgm_read_byte(str);
  39. while(ch)
  40. {
  41. lcd.print(ch);
  42. ch=pgm_read_byte(++str);
  43. }
  44. }
  45. #define lcdprintPGM(x) lcdProgMemprint(MYPGM(x))
  46. //===========================================================================
  47. //=============================functions ============================
  48. //===========================================================================
  49. int intround(const float &x){return int(0.5+x);}
  50. void lcd_status(const char* message)
  51. {
  52. strncpy(messagetext,message,LCD_WIDTH);
  53. messagetext[strlen(message)]=0;
  54. }
  55. void lcd_statuspgm(const char* message)
  56. {
  57. char ch=pgm_read_byte(message);
  58. char *target=messagetext;
  59. uint8_t cnt=0;
  60. while(ch &&cnt<LCD_WIDTH)
  61. {
  62. *target=ch;
  63. target++;
  64. cnt++;
  65. ch=pgm_read_byte(++message);
  66. }
  67. *target=0;
  68. }
  69. FORCE_INLINE void clear()
  70. {
  71. lcd.clear();
  72. }
  73. void lcd_init()
  74. {
  75. //beep();
  76. byte Degree[8] =
  77. {
  78. B01100,
  79. B10010,
  80. B10010,
  81. B01100,
  82. B00000,
  83. B00000,
  84. B00000,
  85. B00000
  86. };
  87. byte Thermometer[8] =
  88. {
  89. B00100,
  90. B01010,
  91. B01010,
  92. B01010,
  93. B01010,
  94. B10001,
  95. B10001,
  96. B01110
  97. };
  98. byte uplevel[8]={0x04, 0x0e, 0x1f, 0x04, 0x1c, 0x00, 0x00, 0x00};//thanks joris
  99. byte refresh[8]={0x00, 0x06, 0x19, 0x18, 0x03, 0x13, 0x0c, 0x00}; //thanks joris
  100. byte folder [8]={0x00, 0x1c, 0x1f, 0x11, 0x11, 0x1f, 0x00, 0x00}; //thanks joris
  101. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  102. lcd.createChar(1,Degree);
  103. lcd.createChar(2,Thermometer);
  104. lcd.createChar(3,uplevel);
  105. lcd.createChar(4,refresh);
  106. lcd.createChar(5,folder);
  107. LCD_MESSAGEPGM(WELCOME_MSG);
  108. }
  109. void beep()
  110. {
  111. //return;
  112. #ifdef ULTIPANEL
  113. #if (BEEPER > -1)
  114. {
  115. pinMode(BEEPER,OUTPUT);
  116. for(int8_t i=0;i<20;i++){
  117. WRITE(BEEPER,HIGH);
  118. delay(5);
  119. WRITE(BEEPER,LOW);
  120. delay(5);
  121. }
  122. }
  123. #endif
  124. #endif
  125. }
  126. void beepshort()
  127. {
  128. //return;
  129. #ifdef ULTIPANEL
  130. #if (BEEPER > -1)
  131. {
  132. pinMode(BEEPER,OUTPUT);
  133. for(int8_t i=0;i<10;i++){
  134. WRITE(BEEPER,HIGH);
  135. delay(3);
  136. WRITE(BEEPER,LOW);
  137. delay(3);
  138. }
  139. }
  140. #endif
  141. #endif
  142. }
  143. void lcd_status()
  144. {
  145. #ifdef ULTIPANEL
  146. static uint8_t oldbuttons=0;
  147. //static long previous_millis_buttons=0;
  148. //static long previous_lcdinit=0;
  149. // buttons_check(); // Done in temperature interrupt
  150. //previous_millis_buttons=millis();
  151. long ms=millis();
  152. for(int8_t i=0; i<8; i++) {
  153. #ifndef NEWPANEL
  154. if((blocking[i]>ms))
  155. buttons &= ~(1<<i);
  156. #else
  157. if((blocking>ms))
  158. buttons &= ~(1<<i);
  159. #endif
  160. }
  161. if((buttons==oldbuttons) && ((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  162. return;
  163. oldbuttons=buttons;
  164. #else
  165. if(((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  166. return;
  167. #endif
  168. previous_millis_lcd=millis();
  169. menu.update();
  170. }
  171. #ifdef ULTIPANEL
  172. void buttons_init()
  173. {
  174. #ifdef NEWPANEL
  175. pinMode(BTN_EN1,INPUT);
  176. pinMode(BTN_EN2,INPUT);
  177. pinMode(BTN_ENC,INPUT);
  178. pinMode(SDCARDDETECT,INPUT);
  179. WRITE(BTN_EN1,HIGH);
  180. WRITE(BTN_EN2,HIGH);
  181. WRITE(BTN_ENC,HIGH);
  182. #if (SDCARDDETECT > -1)
  183. {
  184. WRITE(SDCARDDETECT,HIGH);
  185. }
  186. #endif
  187. #else
  188. pinMode(SHIFT_CLK,OUTPUT);
  189. pinMode(SHIFT_LD,OUTPUT);
  190. pinMode(SHIFT_EN,OUTPUT);
  191. pinMode(SHIFT_OUT,INPUT);
  192. WRITE(SHIFT_OUT,HIGH);
  193. WRITE(SHIFT_LD,HIGH);
  194. WRITE(SHIFT_EN,LOW);
  195. #endif
  196. }
  197. void buttons_check()
  198. {
  199. #ifdef NEWPANEL
  200. uint8_t newbutton=0;
  201. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  202. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  203. if((blocking<millis()) &&(READ(BTN_ENC)==0))
  204. newbutton|=EN_C;
  205. buttons=newbutton;
  206. #else //read it from the shift register
  207. uint8_t newbutton=0;
  208. WRITE(SHIFT_LD,LOW);
  209. WRITE(SHIFT_LD,HIGH);
  210. unsigned char tmp_buttons=0;
  211. for(int8_t i=0;i<8;i++)
  212. {
  213. newbutton = newbutton>>1;
  214. if(READ(SHIFT_OUT))
  215. newbutton|=(1<<7);
  216. WRITE(SHIFT_CLK,HIGH);
  217. WRITE(SHIFT_CLK,LOW);
  218. }
  219. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  220. #endif
  221. //manage encoder rotation
  222. char enc=0;
  223. if(buttons&EN_A)
  224. enc|=(1<<0);
  225. if(buttons&EN_B)
  226. enc|=(1<<1);
  227. if(enc!=lastenc)
  228. {
  229. switch(enc)
  230. {
  231. case encrot0:
  232. if(lastenc==encrot3)
  233. encoderpos++;
  234. else if(lastenc==encrot1)
  235. encoderpos--;
  236. break;
  237. case encrot1:
  238. if(lastenc==encrot0)
  239. encoderpos++;
  240. else if(lastenc==encrot2)
  241. encoderpos--;
  242. break;
  243. case encrot2:
  244. if(lastenc==encrot1)
  245. encoderpos++;
  246. else if(lastenc==encrot3)
  247. encoderpos--;
  248. break;
  249. case encrot3:
  250. if(lastenc==encrot2)
  251. encoderpos++;
  252. else if(lastenc==encrot0)
  253. encoderpos--;
  254. break;
  255. default:
  256. ;
  257. }
  258. }
  259. lastenc=enc;
  260. }
  261. #endif
  262. MainMenu::MainMenu()
  263. {
  264. status=Main_Status;
  265. displayStartingRow=0;
  266. activeline=0;
  267. force_lcd_update=true;
  268. #ifdef ULTIPANEL
  269. buttons_init();
  270. #endif
  271. lcd_init();
  272. linechanging=false;
  273. tune=false;
  274. }
  275. void MainMenu::showStatus()
  276. {
  277. #if LCD_HEIGHT==4
  278. static int olddegHotEnd0=-1;
  279. static int oldtargetHotEnd0=-1;
  280. //force_lcd_update=true;
  281. if(force_lcd_update) //initial display of content
  282. {
  283. encoderpos=feedmultiply;
  284. clear();
  285. lcd.setCursor(0,0);lcdprintPGM("\002---/---\001 ");
  286. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  287. lcd.setCursor(10,0);lcdprintPGM("B---/---\001 ");
  288. #elif EXTRUDERS > 1
  289. lcd.setCursor(10,0);lcdprintPGM("\002---/---\001 ");
  290. #endif
  291. }
  292. int tHotEnd0=intround(degHotend0());
  293. if((tHotEnd0!=olddegHotEnd0)||force_lcd_update)
  294. {
  295. lcd.setCursor(1,0);
  296. lcd.print(ftostr3(tHotEnd0));
  297. olddegHotEnd0=tHotEnd0;
  298. }
  299. int ttHotEnd0=intround(degTargetHotend0());
  300. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  301. {
  302. lcd.setCursor(5,0);
  303. lcd.print(ftostr3(ttHotEnd0));
  304. oldtargetHotEnd0=ttHotEnd0;
  305. }
  306. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  307. static int oldtBed=-1;
  308. static int oldtargetBed=-1;
  309. int tBed=intround(degBed());
  310. if((tBed!=oldtBed)||force_lcd_update)
  311. {
  312. lcd.setCursor(11,0);
  313. lcd.print(ftostr3(tBed));
  314. oldtBed=tBed;
  315. }
  316. int targetBed=intround(degTargetBed());
  317. if((targetBed!=oldtargetBed)||force_lcd_update)
  318. {
  319. lcd.setCursor(15,0);
  320. lcd.print(ftostr3(targetBed));
  321. oldtargetBed=targetBed;
  322. }
  323. #elif EXTRUDERS > 1
  324. static int olddegHotEnd1=-1;
  325. static int oldtargetHotEnd1=-1;
  326. int tHotEnd1=intround(degHotend1());
  327. if((tHotEnd1!=olddegHotEnd1)||force_lcd_update)
  328. {
  329. lcd.setCursor(11,0);
  330. lcd.print(ftostr3(tHotEnd1));
  331. olddegHotEnd1=tHotEnd1;
  332. }
  333. int ttHotEnd1=intround(degTargetHotend1());
  334. if((ttHotEnd1!=oldtargetHotEnd1)||force_lcd_update)
  335. {
  336. lcd.setCursor(15,0);
  337. lcd.print(ftostr3(ttHotEnd1));
  338. oldtargetHotEnd1=ttHotEnd1;
  339. }
  340. #endif
  341. //starttime=2;
  342. static uint16_t oldtime=0;
  343. if(starttime!=0)
  344. {
  345. lcd.setCursor(0,1);
  346. uint16_t time=millis()/60000-starttime/60000;
  347. if(starttime!=oldtime)
  348. {
  349. lcd.print(itostr2(time/60));lcdprintPGM("h ");lcd.print(itostr2(time%60));lcdprintPGM("m");
  350. oldtime=time;
  351. }
  352. }
  353. static int oldzpos=0;
  354. int currentz=current_position[2]*100;
  355. if((currentz!=oldzpos)||force_lcd_update)
  356. {
  357. lcd.setCursor(10,1);
  358. lcdprintPGM("Z:");lcd.print(ftostr52(current_position[2]));
  359. oldzpos=currentz;
  360. }
  361. static int oldfeedmultiply=0;
  362. int curfeedmultiply=feedmultiply;
  363. if(feedmultiplychanged == true) {
  364. feedmultiplychanged = false;
  365. encoderpos = curfeedmultiply;
  366. }
  367. if(encoderpos!=curfeedmultiply||force_lcd_update)
  368. {
  369. curfeedmultiply=encoderpos;
  370. if(curfeedmultiply<10)
  371. curfeedmultiply=10;
  372. if(curfeedmultiply>999)
  373. curfeedmultiply=999;
  374. feedmultiply=curfeedmultiply;
  375. encoderpos=curfeedmultiply;
  376. }
  377. if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update)
  378. {
  379. oldfeedmultiply=curfeedmultiply;
  380. lcd.setCursor(0,2);
  381. lcd.print(itostr3(curfeedmultiply));lcdprintPGM("% ");
  382. }
  383. if(messagetext[0]!='\0')
  384. {
  385. lcd.setCursor(0,LCD_HEIGHT-1);
  386. lcd.print(messagetext);
  387. uint8_t n=strlen(messagetext);
  388. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  389. lcd.print(" ");
  390. messagetext[0]='\0';
  391. }
  392. #ifdef SDSUPPORT
  393. static uint8_t oldpercent=101;
  394. uint8_t percent=card.percentDone();
  395. if(oldpercent!=percent ||force_lcd_update)
  396. {
  397. lcd.setCursor(10,2);
  398. lcd.print(itostr3((int)percent));
  399. lcdprintPGM("%SD");
  400. }
  401. #endif
  402. #else //smaller LCDS----------------------------------
  403. static int olddegHotEnd0=-1;
  404. static int oldtargetHotEnd0=-1;
  405. if(force_lcd_update) //initial display of content
  406. {
  407. encoderpos=feedmultiply;
  408. lcd.setCursor(0,0);lcdprintPGM("\002---/---\001 ");
  409. }
  410. int tHotEnd0=intround(degHotend0());
  411. int ttHotEnd0=intround(degTargetHotend0());
  412. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update)
  413. {
  414. lcd.setCursor(1,0);
  415. lcd.print(ftostr3(tHotEnd0));
  416. olddegHotEnd0=tHotEnd0;
  417. }
  418. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  419. {
  420. lcd.setCursor(5,0);
  421. lcd.print(ftostr3(ttHotEnd0));
  422. oldtargetHotEnd0=ttHotEnd0;
  423. }
  424. if(messagetext[0]!='\0')
  425. {
  426. lcd.setCursor(0,LCD_HEIGHT-1);
  427. lcd.print(messagetext);
  428. uint8_t n=strlen(messagetext);
  429. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  430. lcd.print(" ");
  431. messagetext[0]='\0';
  432. }
  433. #endif
  434. force_lcd_update=false;
  435. }
  436. enum {ItemP_exit, ItemP_autostart,ItemP_disstep,ItemP_home, ItemP_origin, ItemP_preheat_pla, ItemP_preheat_abs, ItemP_cooldown,/*ItemP_extrude,*/ItemP_move};
  437. //any action must not contain a ',' character anywhere, or this breaks:
  438. #define MENUITEM(repaint_action, click_action) \
  439. {\
  440. if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  441. if((activeline==line) && CLICKED) {click_action} \
  442. }
  443. void MainMenu::showPrepare()
  444. {
  445. #ifdef ULTIPANEL
  446. uint8_t line=0;
  447. clearIfNecessary();
  448. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  449. {
  450. //Serial.println((int)(line-lineoffset));
  451. switch(i)
  452. {
  453. case ItemP_exit:
  454. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  455. break;
  456. case ItemP_autostart:
  457. MENUITEM( lcdprintPGM(MSG_AUTOSTART) , BLOCK;
  458. #ifdef SDSUPPORT
  459. card.lastnr=0;card.setroot();card.checkautostart(true);
  460. #endif
  461. beepshort(); ) ;
  462. break;
  463. case ItemP_disstep:
  464. MENUITEM( lcdprintPGM(MSG_DISABLE_STEPPERS) , BLOCK;enquecommand("M84");beepshort(); ) ;
  465. break;
  466. case ItemP_home:
  467. MENUITEM( lcdprintPGM(MSG_AUTO_HOME) , BLOCK;enquecommand("G28");beepshort(); ) ;
  468. break;
  469. case ItemP_origin:
  470. MENUITEM( lcdprintPGM(MSG_SET_ORIGIN) , BLOCK;enquecommand("G92 X0 Y0 Z0");beepshort(); ) ;
  471. break;
  472. case ItemP_preheat_pla:
  473. MENUITEM( lcdprintPGM(MSG_PREHEAT_PLA) , BLOCK;setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);setTargetBed(PLA_PREHEAT_HPB_TEMP);
  474. #if FAN_PIN > -1
  475. analogWrite(FAN_PIN, PLA_PREHEAT_FAN_SPEED);
  476. #endif
  477. beepshort(); );
  478. break;
  479. case ItemP_preheat_abs:
  480. MENUITEM( lcdprintPGM(MSG_PREHEAT_ABS) , BLOCK;setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);setTargetBed(ABS_PREHEAT_HPB_TEMP);
  481. #if FAN_PIN > -1
  482. analogWrite(FAN_PIN, ABS_PREHEAT_FAN_SPEED);
  483. #endif
  484. beepshort(); );
  485. break;
  486. case ItemP_cooldown:
  487. MENUITEM( lcdprintPGM(MSG_COOLDOWN) , BLOCK;setTargetHotend0(0);setTargetHotend1(0);setTargetHotend2(0);setTargetBed(0);beepshort(); ) ;
  488. break;
  489. // case ItemP_extrude:
  490. // MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E50");beepshort(); ) ;
  491. // break;
  492. case ItemP_move:
  493. MENUITEM( lcdprintPGM(MSG_MOVE_AXIS) , BLOCK;status=Sub_PrepareMove;beepshort(); );
  494. break;
  495. default:
  496. break;
  497. }
  498. line++;
  499. }
  500. updateActiveLines(ItemP_move,encoderpos);
  501. #endif
  502. }
  503. enum {
  504. ItemAM_exit,
  505. ItemAM_X, ItemAM_Y, ItemAM_Z, ItemAM_E
  506. };
  507. void MainMenu::showAxisMove()
  508. {
  509. uint8_t line=0;
  510. int oldencoderpos=0;
  511. clearIfNecessary();
  512. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  513. {
  514. switch(i)
  515. {
  516. case ItemAM_exit:
  517. MENUITEM( lcdprintPGM(MSG_PREPARE_ALT) , BLOCK;status=Main_Menu;beepshort(); ) ;
  518. break;
  519. case ItemAM_X:
  520. {
  521. //oldencoderpos=0;
  522. if(force_lcd_update)
  523. {
  524. lcd.setCursor(0,line);lcdprintPGM(" X:");
  525. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  526. }
  527. if((activeline!=line) )
  528. break;
  529. if(CLICKED)
  530. {
  531. linechanging=!linechanging;
  532. if(linechanging)
  533. {
  534. enquecommand("G91");
  535. }
  536. else
  537. {
  538. enquecommand("G90");
  539. encoderpos=activeline*lcdslow;
  540. beepshort();
  541. }
  542. BLOCK;
  543. }
  544. if(linechanging)
  545. {
  546. if (encoderpos >0)
  547. {
  548. enquecommand("G1 F700 X0.1");
  549. oldencoderpos=encoderpos;
  550. encoderpos=0;
  551. }
  552. else if (encoderpos < 0)
  553. {
  554. enquecommand("G1 F700 X-0.1");
  555. oldencoderpos=encoderpos;
  556. encoderpos=0;
  557. }
  558. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  559. }
  560. }
  561. break;
  562. case ItemAM_Y:
  563. {
  564. if(force_lcd_update)
  565. {
  566. lcd.setCursor(0,line);lcdprintPGM(" Y:");
  567. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  568. }
  569. if((activeline!=line) )
  570. break;
  571. if(CLICKED)
  572. {
  573. linechanging=!linechanging;
  574. if(linechanging)
  575. {
  576. enquecommand("G91");
  577. }
  578. else
  579. {
  580. enquecommand("G90");
  581. encoderpos=activeline*lcdslow;
  582. beepshort();
  583. }
  584. BLOCK;
  585. }
  586. if(linechanging)
  587. {
  588. if (encoderpos >0)
  589. {
  590. enquecommand("G1 F700 Y0.1");
  591. oldencoderpos=encoderpos;
  592. encoderpos=0;
  593. }
  594. else if (encoderpos < 0)
  595. {
  596. enquecommand("G1 F700 Y-0.1");
  597. oldencoderpos=encoderpos;
  598. encoderpos=0;
  599. }
  600. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  601. }
  602. }
  603. break;
  604. case ItemAM_Z:
  605. {
  606. if(force_lcd_update)
  607. {
  608. lcd.setCursor(0,line);lcdprintPGM(" Z:");
  609. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  610. }
  611. if((activeline!=line) )
  612. break;
  613. if(CLICKED)
  614. {
  615. linechanging=!linechanging;
  616. if(linechanging)
  617. {
  618. enquecommand("G91");
  619. }
  620. else
  621. {
  622. enquecommand("G90");
  623. encoderpos=activeline*lcdslow;
  624. beepshort();
  625. }
  626. BLOCK;
  627. }
  628. if(linechanging)
  629. {
  630. if (encoderpos >0)
  631. {
  632. enquecommand("G1 F70 Z0.1");
  633. oldencoderpos=encoderpos;
  634. encoderpos=0;
  635. }
  636. else if (encoderpos < 0)
  637. {
  638. enquecommand("G1 F70 Z-0.1");
  639. oldencoderpos=encoderpos;
  640. encoderpos=0;
  641. }
  642. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  643. }
  644. }
  645. break;
  646. case ItemAM_E:
  647. MENUITEM( lcdprintPGM(MSG_EXTRUDE) , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E5");beepshort(); ) ;
  648. break;
  649. default:
  650. break;
  651. }
  652. line++;
  653. }
  654. updateActiveLines(ItemAM_E,encoderpos);
  655. }
  656. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  657. #if (HEATER_BED_PIN > -1)
  658. ItemT_bed,
  659. #endif
  660. ItemT_fan};
  661. void MainMenu::showTune()
  662. {
  663. uint8_t line=0;
  664. clearIfNecessary();
  665. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  666. {
  667. //Serial.println((int)(line-lineoffset));
  668. switch(i)
  669. {
  670. case ItemT_exit:
  671. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  672. break;
  673. case ItemT_speed:
  674. {
  675. if(force_lcd_update)
  676. {
  677. lcd.setCursor(0,line);lcdprintPGM(MSG_SPEED);
  678. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  679. }
  680. if((activeline!=line) )
  681. break;
  682. if(CLICKED) //AnalogWrite(FAN_PIN, fanpwm);
  683. {
  684. linechanging=!linechanging;
  685. if(linechanging)
  686. {
  687. encoderpos=feedmultiply;
  688. }
  689. else
  690. {
  691. encoderpos=activeline*lcdslow;
  692. beepshort();
  693. }
  694. BLOCK;
  695. }
  696. if(linechanging)
  697. {
  698. if(encoderpos<1) encoderpos=1;
  699. if(encoderpos>400) encoderpos=400;
  700. feedmultiply = encoderpos;
  701. feedmultiplychanged=true;
  702. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  703. }
  704. }break;
  705. case ItemT_nozzle:
  706. {
  707. if(force_lcd_update)
  708. {
  709. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  710. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  711. }
  712. if((activeline!=line) )
  713. break;
  714. if(CLICKED)
  715. {
  716. linechanging=!linechanging;
  717. if(linechanging)
  718. {
  719. encoderpos=intround(degTargetHotend0());
  720. }
  721. else
  722. {
  723. setTargetHotend0(encoderpos);
  724. encoderpos=activeline*lcdslow;
  725. beepshort();
  726. }
  727. BLOCK;
  728. }
  729. if(linechanging)
  730. {
  731. if(encoderpos<0) encoderpos=0;
  732. if(encoderpos>260) encoderpos=260;
  733. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  734. }
  735. }break;
  736. #if (HEATER_BED_PIN > -1)
  737. case ItemT_bed:
  738. {
  739. if(force_lcd_update)
  740. {
  741. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  742. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  743. }
  744. if((activeline!=line) )
  745. break;
  746. if(CLICKED)
  747. {
  748. linechanging=!linechanging;
  749. if(linechanging)
  750. {
  751. encoderpos=intround(degTargetBed());
  752. }
  753. else
  754. {
  755. setTargetBed(encoderpos);
  756. encoderpos=activeline*lcdslow;
  757. beepshort();
  758. }
  759. BLOCK;
  760. }
  761. if(linechanging)
  762. {
  763. if(encoderpos<0) encoderpos=0;
  764. if(encoderpos>260) encoderpos=260;
  765. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  766. }
  767. }break;
  768. #endif
  769. case ItemT_fan:
  770. {
  771. if(force_lcd_update)
  772. {
  773. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  774. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  775. }
  776. if((activeline!=line) )
  777. break;
  778. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  779. {
  780. linechanging=!linechanging;
  781. if(linechanging)
  782. {
  783. encoderpos=FanSpeed;
  784. }
  785. else
  786. {
  787. encoderpos=activeline*lcdslow;
  788. beepshort();
  789. }
  790. BLOCK;
  791. }
  792. if(linechanging)
  793. {
  794. if(encoderpos<0) encoderpos=0;
  795. if(encoderpos>255) encoderpos=255;
  796. FanSpeed=encoderpos;
  797. analogWrite(FAN_PIN, FanSpeed);
  798. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  799. }
  800. }break;
  801. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  802. {
  803. if(force_lcd_update)
  804. {
  805. lcd.setCursor(0,line);lcdprintPGM(MSG_FLOW);
  806. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  807. }
  808. if((activeline!=line) )
  809. break;
  810. if(CLICKED)
  811. {
  812. linechanging=!linechanging;
  813. if(linechanging)
  814. {
  815. encoderpos=(int)axis_steps_per_unit[3];
  816. }
  817. else
  818. {
  819. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  820. position[E_AXIS]=lround(position[E_AXIS]*factor);
  821. //current_position[3]*=factor;
  822. axis_steps_per_unit[E_AXIS]= encoderpos;
  823. encoderpos=activeline*lcdslow;
  824. }
  825. BLOCK;
  826. beepshort();
  827. }
  828. if(linechanging)
  829. {
  830. if(encoderpos<5) encoderpos=5;
  831. if(encoderpos>9999) encoderpos=9999;
  832. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  833. }
  834. }break;
  835. default:
  836. break;
  837. }
  838. line++;
  839. }
  840. updateActiveLines(ItemT_fan,encoderpos);
  841. }
  842. //does not work
  843. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  844. // {\
  845. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  846. // if(activeline==line) \
  847. // { \
  848. // if(CLICKED) \
  849. // { \
  850. // linechanging=!linechanging; \
  851. // if(linechanging) {enter_action;} \
  852. // else {accept_action;} \
  853. // } \
  854. // else \
  855. // if(linechanging) {change_action};}\
  856. // }
  857. //
  858. enum {
  859. ItemCT_exit,ItemCT_nozzle0,
  860. #ifdef AUTOTEMP
  861. ItemCT_autotempactive,
  862. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  863. #endif
  864. #if EXTRUDERS > 1
  865. ItemCT_nozzle1,
  866. #endif
  867. #if EXTRUDERS > 2
  868. ItemCT_nozzle2,
  869. #endif
  870. #if defined BED_USES_THERMISTOR || BED_USES_AD595
  871. ItemCT_bed,
  872. #endif
  873. ItemCT_fan,
  874. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C
  875. };
  876. void MainMenu::showControlTemp()
  877. {
  878. uint8_t line=0;
  879. clearIfNecessary();
  880. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  881. {
  882. switch(i)
  883. {
  884. case ItemCT_exit:
  885. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  886. break;
  887. case ItemCT_nozzle0:
  888. {
  889. if(force_lcd_update)
  890. {
  891. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  892. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  893. }
  894. if((activeline!=line) )
  895. break;
  896. if(CLICKED)
  897. {
  898. linechanging=!linechanging;
  899. if(linechanging)
  900. {
  901. encoderpos=intround(degTargetHotend0());
  902. }
  903. else
  904. {
  905. setTargetHotend0(encoderpos);
  906. encoderpos=activeline*lcdslow;
  907. beepshort();
  908. }
  909. BLOCK;
  910. }
  911. if(linechanging)
  912. {
  913. if(encoderpos<0) encoderpos=0;
  914. if(encoderpos>260) encoderpos=260;
  915. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  916. }
  917. }break;
  918. #if EXTRUDERS > 1
  919. case ItemCT_nozzle1:
  920. {
  921. if(force_lcd_update)
  922. {
  923. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE1);
  924. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend1())));
  925. }
  926. if((activeline!=line) )
  927. break;
  928. if(CLICKED)
  929. {
  930. linechanging=!linechanging;
  931. if(linechanging)
  932. {
  933. encoderpos=intround(degTargetHotend1());
  934. }
  935. else
  936. {
  937. setTargetHotend1(encoderpos);
  938. encoderpos=activeline*lcdslow;
  939. beepshort();
  940. }
  941. BLOCK;
  942. }
  943. if(linechanging)
  944. {
  945. if(encoderpos<0) encoderpos=0;
  946. if(encoderpos>260) encoderpos=260;
  947. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  948. }
  949. }break;
  950. #endif
  951. #if EXTRUDERS > 2
  952. case ItemCT_nozzle2:
  953. {
  954. if(force_lcd_update)
  955. {
  956. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE2);
  957. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend2())));
  958. }
  959. if((activeline!=line) )
  960. break;
  961. if(CLICKED)
  962. {
  963. linechanging=!linechanging;
  964. if(linechanging)
  965. {
  966. encoderpos=intround(degTargetHotend2());
  967. }
  968. else
  969. {
  970. setTargetHotend1(encoderpos);
  971. encoderpos=activeline*lcdslow;
  972. beepshort();
  973. }
  974. BLOCK;
  975. }
  976. if(linechanging)
  977. {
  978. if(encoderpos<0) encoderpos=0;
  979. if(encoderpos>260) encoderpos=260;
  980. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  981. }
  982. }break;
  983. #endif
  984. #ifdef AUTOTEMP
  985. case ItemCT_autotempmin:
  986. {
  987. if(force_lcd_update)
  988. {
  989. lcd.setCursor(0,line);lcdprintPGM(MSG_MIN);
  990. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  991. }
  992. if((activeline!=line) )
  993. break;
  994. if(CLICKED)
  995. {
  996. linechanging=!linechanging;
  997. if(linechanging)
  998. {
  999. encoderpos=intround(autotemp_min);
  1000. }
  1001. else
  1002. {
  1003. autotemp_min=encoderpos;
  1004. encoderpos=activeline*lcdslow;
  1005. beepshort();
  1006. }
  1007. BLOCK;
  1008. }
  1009. if(linechanging)
  1010. {
  1011. if(encoderpos<0) encoderpos=0;
  1012. if(encoderpos>260) encoderpos=260;
  1013. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1014. }
  1015. }break;
  1016. case ItemCT_autotempmax:
  1017. {
  1018. if(force_lcd_update)
  1019. {
  1020. lcd.setCursor(0,line);lcdprintPGM(MSG_MAX);
  1021. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  1022. }
  1023. if((activeline!=line) )
  1024. break;
  1025. if(CLICKED)
  1026. {
  1027. linechanging=!linechanging;
  1028. if(linechanging)
  1029. {
  1030. encoderpos=intround(autotemp_max);
  1031. }
  1032. else
  1033. {
  1034. autotemp_max=encoderpos;
  1035. encoderpos=activeline*lcdslow;
  1036. beepshort();
  1037. }
  1038. BLOCK;
  1039. }
  1040. if(linechanging)
  1041. {
  1042. if(encoderpos<0) encoderpos=0;
  1043. if(encoderpos>260) encoderpos=260;
  1044. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1045. }
  1046. }break;
  1047. case ItemCT_autotempfact:
  1048. {
  1049. if(force_lcd_update)
  1050. {
  1051. lcd.setCursor(0,line);lcdprintPGM(MSG_FACTOR);
  1052. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  1053. }
  1054. if((activeline!=line) )
  1055. break;
  1056. if(CLICKED)
  1057. {
  1058. linechanging=!linechanging;
  1059. if(linechanging)
  1060. {
  1061. encoderpos=intround(autotemp_factor*100);
  1062. }
  1063. else
  1064. {
  1065. autotemp_max=encoderpos;
  1066. encoderpos=activeline*lcdslow;
  1067. beepshort();
  1068. }
  1069. BLOCK;
  1070. }
  1071. if(linechanging)
  1072. {
  1073. if(encoderpos<0) encoderpos=0;
  1074. if(encoderpos>99) encoderpos=99;
  1075. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  1076. }
  1077. }break;
  1078. case ItemCT_autotempactive:
  1079. {
  1080. if(force_lcd_update)
  1081. {
  1082. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTOTEMP);
  1083. lcd.setCursor(13,line);
  1084. if(autotemp_enabled)
  1085. lcdprintPGM(MSG_ON);
  1086. else
  1087. lcdprintPGM(MSG_OFF);
  1088. }
  1089. if((activeline!=line) )
  1090. break;
  1091. if(CLICKED)
  1092. {
  1093. autotemp_enabled=!autotemp_enabled;
  1094. lcd.setCursor(13,line);
  1095. if(autotemp_enabled)
  1096. lcdprintPGM(MSG_ON);
  1097. else
  1098. lcdprintPGM(MSG_OFF);
  1099. BLOCK;
  1100. }
  1101. }break;
  1102. #endif //autotemp
  1103. #if defined BED_USES_THERMISTOR || BED_USES_AD595
  1104. case ItemCT_bed:
  1105. {
  1106. if(force_lcd_update)
  1107. {
  1108. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  1109. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  1110. }
  1111. if((activeline!=line) )
  1112. break;
  1113. if(CLICKED)
  1114. {
  1115. linechanging=!linechanging;
  1116. if(linechanging)
  1117. {
  1118. encoderpos=intround(degTargetBed());
  1119. }
  1120. else
  1121. {
  1122. setTargetBed(encoderpos);
  1123. encoderpos=activeline*lcdslow;
  1124. beepshort();
  1125. }
  1126. BLOCK;
  1127. }
  1128. if(linechanging)
  1129. {
  1130. if(encoderpos<0) encoderpos=0;
  1131. if(encoderpos>260) encoderpos=260;
  1132. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1133. }
  1134. }break;
  1135. #endif
  1136. case ItemCT_fan:
  1137. {
  1138. if(force_lcd_update)
  1139. {
  1140. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  1141. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  1142. }
  1143. if((activeline!=line) )
  1144. break;
  1145. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  1146. {
  1147. linechanging=!linechanging;
  1148. if(linechanging)
  1149. {
  1150. encoderpos=FanSpeed;
  1151. }
  1152. else
  1153. {
  1154. encoderpos=activeline*lcdslow;
  1155. beepshort();
  1156. }
  1157. BLOCK;
  1158. }
  1159. if(linechanging)
  1160. {
  1161. if(encoderpos<0) encoderpos=0;
  1162. if(encoderpos>255) encoderpos=255;
  1163. FanSpeed=encoderpos;
  1164. analogWrite(FAN_PIN, FanSpeed);
  1165. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1166. }
  1167. }break;
  1168. #ifdef PIDTEMP
  1169. case ItemCT_PID_P:
  1170. {
  1171. if(force_lcd_update)
  1172. {
  1173. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  1174. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  1175. }
  1176. if((activeline!=line) )
  1177. break;
  1178. if(CLICKED)
  1179. {
  1180. linechanging=!linechanging;
  1181. if(linechanging)
  1182. {
  1183. encoderpos=(int)Kp;
  1184. }
  1185. else
  1186. {
  1187. Kp= encoderpos;
  1188. encoderpos=activeline*lcdslow;
  1189. }
  1190. BLOCK;
  1191. beepshort();
  1192. }
  1193. if(linechanging)
  1194. {
  1195. if(encoderpos<1) encoderpos=1;
  1196. if(encoderpos>9990) encoderpos=9990;
  1197. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1198. }
  1199. }break;
  1200. case ItemCT_PID_I:
  1201. {
  1202. if(force_lcd_update)
  1203. {
  1204. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_I);
  1205. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  1206. }
  1207. if((activeline!=line) )
  1208. break;
  1209. if(CLICKED)
  1210. {
  1211. linechanging=!linechanging;
  1212. if(linechanging)
  1213. {
  1214. encoderpos=(int)(Ki*10/PID_dT);
  1215. }
  1216. else
  1217. {
  1218. Ki= encoderpos/10.*PID_dT;
  1219. encoderpos=activeline*lcdslow;
  1220. }
  1221. BLOCK;
  1222. beepshort();
  1223. }
  1224. if(linechanging)
  1225. {
  1226. if(encoderpos<0) encoderpos=0;
  1227. if(encoderpos>9990) encoderpos=9990;
  1228. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  1229. }
  1230. }break;
  1231. case ItemCT_PID_D:
  1232. {
  1233. if(force_lcd_update)
  1234. {
  1235. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_D);
  1236. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  1237. }
  1238. if((activeline!=line) )
  1239. break;
  1240. if(CLICKED)
  1241. {
  1242. linechanging=!linechanging;
  1243. if(linechanging)
  1244. {
  1245. encoderpos=(int)(Kd/5./PID_dT);
  1246. }
  1247. else
  1248. {
  1249. Kd= encoderpos;
  1250. encoderpos=activeline*lcdslow;
  1251. }
  1252. BLOCK;
  1253. beepshort();
  1254. }
  1255. if(linechanging)
  1256. {
  1257. if(encoderpos<0) encoderpos=0;
  1258. if(encoderpos>9990) encoderpos=9990;
  1259. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1260. }
  1261. }break;
  1262. case ItemCT_PID_C:
  1263. #ifdef PID_ADD_EXTRUSION_RATE
  1264. {
  1265. if(force_lcd_update)
  1266. {
  1267. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_C);
  1268. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  1269. }
  1270. if((activeline!=line) )
  1271. break;
  1272. if(CLICKED)
  1273. {
  1274. linechanging=!linechanging;
  1275. if(linechanging)
  1276. {
  1277. encoderpos=(int)Kc;
  1278. }
  1279. else
  1280. {
  1281. Kc= encoderpos;
  1282. encoderpos=activeline*lcdslow;
  1283. }
  1284. BLOCK;
  1285. beepshort();
  1286. }
  1287. if(linechanging)
  1288. {
  1289. if(encoderpos<0) encoderpos=0;
  1290. if(encoderpos>990) encoderpos=990;
  1291. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1292. }
  1293. }
  1294. #endif
  1295. #endif
  1296. break;
  1297. default:
  1298. break;
  1299. }
  1300. line++;
  1301. }
  1302. #ifdef PID_ADD_EXTRUSION_RATE
  1303. updateActiveLines(ItemCT_PID_C,encoderpos);
  1304. #else
  1305. updateActiveLines(ItemCT_PID_D,encoderpos);
  1306. #endif
  1307. }
  1308. enum {
  1309. ItemCM_exit,
  1310. ItemCM_acc, ItemCM_xyjerk,
  1311. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1312. ItemCM_vtravmin,ItemCM_vmin,
  1313. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1314. ItemCM_aret, ItemCM_xsteps,ItemCM_ysteps, ItemCM_zsteps, ItemCM_esteps
  1315. };
  1316. void MainMenu::showControlMotion()
  1317. {
  1318. uint8_t line=0;
  1319. clearIfNecessary();
  1320. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1321. {
  1322. switch(i)
  1323. {
  1324. case ItemCM_exit:
  1325. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1326. break;
  1327. case ItemCM_acc:
  1328. {
  1329. if(force_lcd_update)
  1330. {
  1331. lcd.setCursor(0,line);lcdprintPGM(MSG_ACC);
  1332. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1333. }
  1334. if((activeline!=line) )
  1335. break;
  1336. if(CLICKED)
  1337. {
  1338. linechanging=!linechanging;
  1339. if(linechanging)
  1340. {
  1341. encoderpos=(int)acceleration/100;
  1342. }
  1343. else
  1344. {
  1345. acceleration= encoderpos*100;
  1346. encoderpos=activeline*lcdslow;
  1347. }
  1348. BLOCK;
  1349. beepshort();
  1350. }
  1351. if(linechanging)
  1352. {
  1353. if(encoderpos<5) encoderpos=5;
  1354. if(encoderpos>990) encoderpos=990;
  1355. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1356. }
  1357. }break;
  1358. case ItemCM_xyjerk: //max_xy_jerk
  1359. {
  1360. if(force_lcd_update)
  1361. {
  1362. lcd.setCursor(0,line);lcdprintPGM(MSG_VXY_JERK);
  1363. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1364. }
  1365. if((activeline!=line) )
  1366. break;
  1367. if(CLICKED)
  1368. {
  1369. linechanging=!linechanging;
  1370. if(linechanging)
  1371. {
  1372. encoderpos=(int)max_xy_jerk;
  1373. }
  1374. else
  1375. {
  1376. max_xy_jerk= encoderpos;
  1377. encoderpos=activeline*lcdslow;
  1378. }
  1379. BLOCK;
  1380. beepshort();
  1381. }
  1382. if(linechanging)
  1383. {
  1384. if(encoderpos<1) encoderpos=1;
  1385. if(encoderpos>990) encoderpos=990;
  1386. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1387. }
  1388. }break;
  1389. case ItemCM_vmaxx:
  1390. case ItemCM_vmaxy:
  1391. case ItemCM_vmaxz:
  1392. case ItemCM_vmaxe:
  1393. {
  1394. if(force_lcd_update)
  1395. {
  1396. lcd.setCursor(0,line);lcdprintPGM(MSG_VMAX);
  1397. if(i==ItemCM_vmaxx)lcdprintPGM(MSG_X);
  1398. if(i==ItemCM_vmaxy)lcdprintPGM(MSG_Y);
  1399. if(i==ItemCM_vmaxz)lcdprintPGM(MSG_Z);
  1400. if(i==ItemCM_vmaxe)lcdprintPGM(MSG_E);
  1401. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1402. }
  1403. if((activeline!=line) )
  1404. break;
  1405. if(CLICKED)
  1406. {
  1407. linechanging=!linechanging;
  1408. if(linechanging)
  1409. {
  1410. encoderpos=(int)max_feedrate[i-ItemCM_vmaxx];
  1411. }
  1412. else
  1413. {
  1414. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1415. encoderpos=activeline*lcdslow;
  1416. }
  1417. BLOCK;
  1418. beepshort();
  1419. }
  1420. if(linechanging)
  1421. {
  1422. if(encoderpos<1) encoderpos=1;
  1423. if(encoderpos>990) encoderpos=990;
  1424. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1425. }
  1426. }break;
  1427. case ItemCM_vmin:
  1428. {
  1429. if(force_lcd_update)
  1430. {
  1431. lcd.setCursor(0,line);lcdprintPGM(MSG_VMIN);
  1432. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1433. }
  1434. if((activeline!=line) )
  1435. break;
  1436. if(CLICKED)
  1437. {
  1438. linechanging=!linechanging;
  1439. if(linechanging)
  1440. {
  1441. encoderpos=(int)(minimumfeedrate);
  1442. }
  1443. else
  1444. {
  1445. minimumfeedrate= encoderpos;
  1446. encoderpos=activeline*lcdslow;
  1447. }
  1448. BLOCK;
  1449. beepshort();
  1450. }
  1451. if(linechanging)
  1452. {
  1453. if(encoderpos<0) encoderpos=0;
  1454. if(encoderpos>990) encoderpos=990;
  1455. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1456. }
  1457. }break;
  1458. case ItemCM_vtravmin:
  1459. {
  1460. if(force_lcd_update)
  1461. {
  1462. lcd.setCursor(0,line);lcdprintPGM(MSG_VTRAV_MIN);
  1463. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1464. }
  1465. if((activeline!=line) )
  1466. break;
  1467. if(CLICKED)
  1468. {
  1469. linechanging=!linechanging;
  1470. if(linechanging)
  1471. {
  1472. encoderpos=(int)mintravelfeedrate;
  1473. }
  1474. else
  1475. {
  1476. mintravelfeedrate= encoderpos;
  1477. encoderpos=activeline*lcdslow;
  1478. }
  1479. BLOCK;
  1480. beepshort();
  1481. }
  1482. if(linechanging)
  1483. {
  1484. if(encoderpos<0) encoderpos=0;
  1485. if(encoderpos>990) encoderpos=990;
  1486. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1487. }
  1488. }break;
  1489. case ItemCM_amaxx:
  1490. case ItemCM_amaxy:
  1491. case ItemCM_amaxz:
  1492. case ItemCM_amaxe:
  1493. {
  1494. if(force_lcd_update)
  1495. {
  1496. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1497. if(i==ItemCM_amaxx)lcdprintPGM(MSG_X);
  1498. if(i==ItemCM_amaxy)lcdprintPGM(MSG_Y);
  1499. if(i==ItemCM_amaxz)lcdprintPGM(MSG_Z);
  1500. if(i==ItemCM_amaxe)lcdprintPGM(MSG_E);
  1501. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1502. }
  1503. if((activeline!=line) )
  1504. break;
  1505. if(CLICKED)
  1506. {
  1507. linechanging=!linechanging;
  1508. if(linechanging)
  1509. {
  1510. encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1511. }
  1512. else
  1513. {
  1514. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1515. encoderpos=activeline*lcdslow;
  1516. }
  1517. BLOCK;
  1518. beepshort();
  1519. }
  1520. if(linechanging)
  1521. {
  1522. if(encoderpos<1) encoderpos=1;
  1523. if(encoderpos>990) encoderpos=990;
  1524. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1525. }
  1526. }break;
  1527. case ItemCM_aret://float retract_acceleration = 7000;
  1528. {
  1529. if(force_lcd_update)
  1530. {
  1531. lcd.setCursor(0,line);lcdprintPGM(MSG_A_RETRACT);
  1532. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1533. }
  1534. if((activeline!=line) )
  1535. break;
  1536. if(CLICKED)
  1537. {
  1538. linechanging=!linechanging;
  1539. if(linechanging)
  1540. {
  1541. encoderpos=(int)retract_acceleration/100;
  1542. }
  1543. else
  1544. {
  1545. retract_acceleration= encoderpos*100;
  1546. encoderpos=activeline*lcdslow;
  1547. }
  1548. BLOCK;
  1549. beepshort();
  1550. }
  1551. if(linechanging)
  1552. {
  1553. if(encoderpos<10) encoderpos=10;
  1554. if(encoderpos>990) encoderpos=990;
  1555. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1556. }
  1557. }break;
  1558. case ItemCM_xsteps://axis_steps_per_unit[i] = code_value();
  1559. {
  1560. if(force_lcd_update)
  1561. {
  1562. lcd.setCursor(0,line);lcdprintPGM(MSG_XSTEPS);
  1563. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[0]));
  1564. }
  1565. if((activeline!=line) )
  1566. break;
  1567. if(CLICKED)
  1568. {
  1569. linechanging=!linechanging;
  1570. if(linechanging)
  1571. {
  1572. encoderpos=(int)(axis_steps_per_unit[0]*100.0);
  1573. }
  1574. else
  1575. {
  1576. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[0]);
  1577. position[X_AXIS]=lround(position[X_AXIS]*factor);
  1578. //current_position[3]*=factor;
  1579. axis_steps_per_unit[X_AXIS]= encoderpos/100.0;
  1580. encoderpos=activeline*lcdslow;
  1581. }
  1582. BLOCK;
  1583. beepshort();
  1584. }
  1585. if(linechanging)
  1586. {
  1587. if(encoderpos<5) encoderpos=5;
  1588. if(encoderpos>32000) encoderpos=32000;//TODO: This is a problem, encoderpos is 16bit, but steps_per_unit for e can be wel over 800
  1589. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1590. }
  1591. }break;
  1592. case ItemCM_ysteps://axis_steps_per_unit[i] = code_value();
  1593. {
  1594. if(force_lcd_update)
  1595. {
  1596. lcd.setCursor(0,line);lcdprintPGM(MSG_YSTEPS);
  1597. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[1]));
  1598. }
  1599. if((activeline!=line) )
  1600. break;
  1601. if(CLICKED)
  1602. {
  1603. linechanging=!linechanging;
  1604. if(linechanging)
  1605. {
  1606. encoderpos=(int)(axis_steps_per_unit[1]*100.0);
  1607. }
  1608. else
  1609. {
  1610. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[1]);
  1611. position[Y_AXIS]=lround(position[Y_AXIS]*factor);
  1612. //current_position[3]*=factor;
  1613. axis_steps_per_unit[Y_AXIS]= encoderpos/100.0;
  1614. encoderpos=activeline*lcdslow;
  1615. }
  1616. BLOCK;
  1617. beepshort();
  1618. }
  1619. if(linechanging)
  1620. {
  1621. if(encoderpos<5) encoderpos=5;
  1622. if(encoderpos>9999) encoderpos=9999;
  1623. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1624. }
  1625. }break;
  1626. case ItemCM_zsteps://axis_steps_per_unit[i] = code_value();
  1627. {
  1628. if(force_lcd_update)
  1629. {
  1630. lcd.setCursor(0,line);lcdprintPGM(MSG_ZSTEPS);
  1631. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[2]));
  1632. }
  1633. if((activeline!=line) )
  1634. break;
  1635. if(CLICKED)
  1636. {
  1637. linechanging=!linechanging;
  1638. if(linechanging)
  1639. {
  1640. encoderpos=(int)(axis_steps_per_unit[2]*100.0);
  1641. }
  1642. else
  1643. {
  1644. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[2]);
  1645. position[Z_AXIS]=lround(position[Z_AXIS]*factor);
  1646. //current_position[3]*=factor;
  1647. axis_steps_per_unit[Z_AXIS]= encoderpos/100.0;
  1648. encoderpos=activeline*lcdslow;
  1649. }
  1650. BLOCK;
  1651. beepshort();
  1652. }
  1653. if(linechanging)
  1654. {
  1655. if(encoderpos<5) encoderpos=5;
  1656. if(encoderpos>9999) encoderpos=9999;
  1657. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1658. }
  1659. }break;
  1660. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1661. {
  1662. if(force_lcd_update)
  1663. {
  1664. lcd.setCursor(0,line);lcdprintPGM(MSG_ESTEPS);
  1665. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[3]));
  1666. }
  1667. if((activeline!=line) )
  1668. break;
  1669. if(CLICKED)
  1670. {
  1671. linechanging=!linechanging;
  1672. if(linechanging)
  1673. {
  1674. encoderpos=(int)(axis_steps_per_unit[3]*100.0);
  1675. }
  1676. else
  1677. {
  1678. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[3]);
  1679. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1680. //current_position[3]*=factor;
  1681. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  1682. encoderpos=activeline*lcdslow;
  1683. }
  1684. BLOCK;
  1685. beepshort();
  1686. }
  1687. if(linechanging)
  1688. {
  1689. if(encoderpos<5) encoderpos=5;
  1690. if(encoderpos>9999) encoderpos=9999;
  1691. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1692. }
  1693. }break;
  1694. default:
  1695. break;
  1696. }
  1697. line++;
  1698. }
  1699. updateActiveLines(ItemCM_esteps,encoderpos);
  1700. }
  1701. enum {
  1702. ItemC_exit,ItemC_temp,ItemC_move,
  1703. ItemC_store, ItemC_load,ItemC_failsafe
  1704. };
  1705. void MainMenu::showControl()
  1706. {
  1707. uint8_t line=0;
  1708. clearIfNecessary();
  1709. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1710. {
  1711. switch(i)
  1712. {
  1713. case ItemC_exit:
  1714. MENUITEM( lcdprintPGM(MSG_MAIN_WIDE) , BLOCK;status=Main_Menu;beepshort(); ) ;
  1715. break;
  1716. case ItemC_temp:
  1717. MENUITEM( lcdprintPGM(MSG_TEMPERATURE_WIDE) , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1718. break;
  1719. case ItemC_move:
  1720. MENUITEM( lcdprintPGM(MSG_MOTION_WIDE) , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1721. break;
  1722. case ItemC_store:
  1723. {
  1724. if(force_lcd_update)
  1725. {
  1726. lcd.setCursor(0,line);lcdprintPGM(MSG_STORE_EPROM);
  1727. }
  1728. if((activeline==line) && CLICKED)
  1729. {
  1730. //enquecommand("M84");
  1731. beepshort();
  1732. BLOCK;
  1733. EEPROM_StoreSettings();
  1734. }
  1735. }break;
  1736. case ItemC_load:
  1737. {
  1738. if(force_lcd_update)
  1739. {
  1740. lcd.setCursor(0,line);lcdprintPGM(MSG_LOAD_EPROM);
  1741. }
  1742. if((activeline==line) && CLICKED)
  1743. {
  1744. //enquecommand("M84");
  1745. beepshort();
  1746. BLOCK;
  1747. EEPROM_RetrieveSettings();
  1748. }
  1749. }break;
  1750. case ItemC_failsafe:
  1751. {
  1752. if(force_lcd_update)
  1753. {
  1754. lcd.setCursor(0,line);lcdprintPGM(MSG_RESTORE_FAILSAFE);
  1755. }
  1756. if((activeline==line) && CLICKED)
  1757. {
  1758. //enquecommand("M84");
  1759. beepshort();
  1760. BLOCK;
  1761. EEPROM_RetrieveSettings(true);
  1762. }
  1763. }break;
  1764. default:
  1765. break;
  1766. }
  1767. line++;
  1768. }
  1769. updateActiveLines(ItemC_failsafe,encoderpos);
  1770. }
  1771. void MainMenu::showSD()
  1772. {
  1773. #ifdef SDSUPPORT
  1774. uint8_t line=0;
  1775. clearIfNecessary();
  1776. static uint8_t nrfiles=0;
  1777. if(force_lcd_update)
  1778. {
  1779. if(card.cardOK)
  1780. {
  1781. nrfiles=card.getnrfilenames();
  1782. }
  1783. else
  1784. {
  1785. nrfiles=0;
  1786. lineoffset=0;
  1787. }
  1788. }
  1789. bool enforceupdate=false;
  1790. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1791. {
  1792. switch(i)
  1793. {
  1794. case 0:
  1795. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  1796. break;
  1797. // case 1:
  1798. // {
  1799. // if(force_lcd_update)
  1800. // {
  1801. // lcd.setCursor(0,line);
  1802. // #ifdef CARDINSERTED
  1803. // if(CARDINSERTED)
  1804. // #else
  1805. // if(true)
  1806. // #endif
  1807. // {
  1808. // lcdprintPGM(" \004Refresh");
  1809. // }
  1810. // else
  1811. // {
  1812. // lcdprintPGM(" \004Insert Card");
  1813. // }
  1814. //
  1815. // }
  1816. // if((activeline==line) && CLICKED)
  1817. // {
  1818. // BLOCK;
  1819. // beepshort();
  1820. // card.initsd();
  1821. // force_lcd_update=true;
  1822. // nrfiles=card.getnrfilenames();
  1823. // }
  1824. // }break;
  1825. case 1:
  1826. MENUITEM( lcd.print(" ");card.getWorkDirName();
  1827. if(card.filename[0]=='/') lcdprintPGM(MSG_REFRESH);
  1828. else {
  1829. lcd.print("\005");
  1830. lcd.print(card.filename);
  1831. lcd.print("/..");
  1832. } ,
  1833. BLOCK;
  1834. if(SDCARDDETECT == -1) card.initsd();
  1835. card.updir();
  1836. enforceupdate=true;
  1837. lineoffset=0;
  1838. beepshort(); ) ;
  1839. break;
  1840. default:
  1841. {
  1842. #define FIRSTITEM 2
  1843. if(i-FIRSTITEM<nrfiles)
  1844. {
  1845. if(force_lcd_update)
  1846. {
  1847. card.getfilename(i-FIRSTITEM);
  1848. //Serial.print("Filenr:");Serial.println(i-2);
  1849. lcd.setCursor(0,line);lcdprintPGM(" ");
  1850. if(card.filenameIsDir) lcd.print("\005");
  1851. lcd.print(card.filename);
  1852. }
  1853. if((activeline==line) && CLICKED)
  1854. {
  1855. BLOCK
  1856. card.getfilename(i-FIRSTITEM);
  1857. if(card.filenameIsDir)
  1858. {
  1859. for(int8_t i=0;i<strlen(card.filename);i++)
  1860. card.filename[i]=tolower(card.filename[i]);
  1861. card.chdir(card.filename);
  1862. lineoffset=0;
  1863. enforceupdate=true;
  1864. }
  1865. else
  1866. {
  1867. char cmd[30];
  1868. for(int8_t i=0;i<strlen(card.filename);i++)
  1869. card.filename[i]=tolower(card.filename[i]);
  1870. sprintf(cmd,"M23 %s",card.filename);
  1871. //sprintf(cmd,"M115");
  1872. enquecommand(cmd);
  1873. enquecommand("M24");
  1874. beep();
  1875. status=Main_Status;
  1876. lcd_status(card.filename);
  1877. }
  1878. }
  1879. }
  1880. }
  1881. break;
  1882. }
  1883. line++;
  1884. }
  1885. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  1886. if(enforceupdate)
  1887. {
  1888. force_lcd_update=true;
  1889. enforceupdate=false;
  1890. }
  1891. #endif
  1892. }
  1893. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file };
  1894. void MainMenu::showMainMenu()
  1895. {
  1896. #ifndef ULTIPANEL
  1897. force_lcd_update=false;
  1898. #endif
  1899. if(tune)
  1900. {
  1901. if(!(movesplanned() || IS_SD_PRINTING))
  1902. {
  1903. force_lcd_update=true;
  1904. tune=false;
  1905. }
  1906. }
  1907. else
  1908. {
  1909. if(movesplanned() || IS_SD_PRINTING)
  1910. {
  1911. force_lcd_update=true;
  1912. tune=true;
  1913. }
  1914. }
  1915. clearIfNecessary();
  1916. for(int8_t line=0;line<LCD_HEIGHT;line++)
  1917. {
  1918. switch(line)
  1919. {
  1920. case ItemM_watch:
  1921. MENUITEM( lcdprintPGM(MSG_WATCH) , BLOCK;status=Main_Status;beepshort(); ) ;
  1922. break;
  1923. case ItemM_prepare:
  1924. MENUITEM( if(!tune) lcdprintPGM(MSG_PREPARE);else lcdprintPGM(MSG_TUNE); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  1925. break;
  1926. case ItemM_control:
  1927. MENUITEM( lcdprintPGM(MSG_CONTROL_ARROW) , BLOCK;status=Main_Control;beepshort(); ) ;
  1928. break;
  1929. #ifdef SDSUPPORT
  1930. case ItemM_file:
  1931. {
  1932. if(force_lcd_update)
  1933. {
  1934. lcd.setCursor(0,line);
  1935. #ifdef CARDINSERTED
  1936. if(CARDINSERTED)
  1937. #else
  1938. if(true)
  1939. #endif
  1940. {
  1941. if(card.sdprinting)
  1942. lcdprintPGM(MSG_STOP_PRINT);
  1943. else
  1944. lcdprintPGM(MSG_CARD_MENU);
  1945. }
  1946. else
  1947. {
  1948. lcdprintPGM(MSG_NO_CARD);
  1949. }
  1950. }
  1951. #ifdef CARDINSERTED
  1952. if(CARDINSERTED)
  1953. #endif
  1954. if((activeline==line)&&CLICKED)
  1955. {
  1956. card.printingHasFinished();
  1957. BLOCK;
  1958. status=Main_SD;
  1959. beepshort();
  1960. }
  1961. }break;
  1962. #else
  1963. case ItemM_file:
  1964. break;
  1965. #endif
  1966. default:
  1967. SERIAL_ERROR_START;
  1968. SERIAL_ERRORLNPGM(MSG_SERIAL_ERROR_MENU_STRUCTURE);
  1969. break;
  1970. }
  1971. }
  1972. updateActiveLines(3,encoderpos);
  1973. }
  1974. void MainMenu::update()
  1975. {
  1976. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  1977. static long timeoutToStatus=0;
  1978. static bool oldcardstatus=false;
  1979. #ifdef CARDINSERTED
  1980. if((CARDINSERTED != oldcardstatus))
  1981. {
  1982. force_lcd_update=true;
  1983. oldcardstatus=CARDINSERTED;
  1984. lcd_init(); // to maybe revive the lcd if static electricty killed it.
  1985. //Serial.println("echo: SD CHANGE");
  1986. if(CARDINSERTED)
  1987. {
  1988. card.initsd();
  1989. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  1990. }
  1991. else
  1992. {
  1993. card.release();
  1994. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  1995. }
  1996. }
  1997. #endif
  1998. if(status!=oldstatus)
  1999. {
  2000. force_lcd_update=true;
  2001. encoderpos=0;
  2002. lineoffset=0;
  2003. oldstatus=status;
  2004. }
  2005. if( (encoderpos!=lastencoderpos) || CLICKED)
  2006. timeoutToStatus=millis()+STATUSTIMEOUT;
  2007. switch(status)
  2008. {
  2009. case Main_Status:
  2010. {
  2011. showStatus();
  2012. if(CLICKED)
  2013. {
  2014. linechanging=false;
  2015. BLOCK
  2016. status=Main_Menu;
  2017. timeoutToStatus=millis()+STATUSTIMEOUT;
  2018. }
  2019. }break;
  2020. case Main_Menu:
  2021. {
  2022. showMainMenu();
  2023. linechanging=false;
  2024. }break;
  2025. case Main_Prepare:
  2026. {
  2027. if(tune)
  2028. {
  2029. showTune();
  2030. }
  2031. else
  2032. {
  2033. showPrepare();
  2034. }
  2035. }break;
  2036. case Sub_PrepareMove:
  2037. {
  2038. showAxisMove();
  2039. }break;
  2040. case Main_Control:
  2041. {
  2042. showControl();
  2043. }break;
  2044. case Sub_MotionControl:
  2045. {
  2046. showControlMotion();
  2047. }break;
  2048. case Sub_TempControl:
  2049. {
  2050. showControlTemp();
  2051. }break;
  2052. case Main_SD:
  2053. {
  2054. showSD();
  2055. }break;
  2056. }
  2057. if(timeoutToStatus<millis())
  2058. status=Main_Status;
  2059. //force_lcd_update=false;
  2060. lastencoderpos=encoderpos;
  2061. }
  2062. // convert float to string with +123.4 format
  2063. char *ftostr3(const float &x)
  2064. {
  2065. //sprintf(conv,"%5.1f",x);
  2066. int xx=x;
  2067. conv[0]=(xx/100)%10+'0';
  2068. conv[1]=(xx/10)%10+'0';
  2069. conv[2]=(xx)%10+'0';
  2070. conv[3]=0;
  2071. return conv;
  2072. }
  2073. char *itostr2(const uint8_t &x)
  2074. {
  2075. //sprintf(conv,"%5.1f",x);
  2076. int xx=x;
  2077. conv[0]=(xx/10)%10+'0';
  2078. conv[1]=(xx)%10+'0';
  2079. conv[2]=0;
  2080. return conv;
  2081. }
  2082. // convert float to string with +123.4 format
  2083. char *ftostr31(const float &x)
  2084. {
  2085. int xx=x*10;
  2086. conv[0]=(xx>=0)?'+':'-';
  2087. xx=abs(xx);
  2088. conv[1]=(xx/1000)%10+'0';
  2089. conv[2]=(xx/100)%10+'0';
  2090. conv[3]=(xx/10)%10+'0';
  2091. conv[4]='.';
  2092. conv[5]=(xx)%10+'0';
  2093. conv[6]=0;
  2094. return conv;
  2095. }
  2096. char *ftostr32(const float &x)
  2097. {
  2098. int xx=x*100;
  2099. conv[0]=(xx>=0)?'+':'-';
  2100. xx=abs(xx);
  2101. conv[1]=(xx/100)%10+'0';
  2102. conv[2]='.';
  2103. conv[3]=(xx/10)%10+'0';
  2104. conv[4]=(xx)%10+'0';
  2105. conv[6]=0;
  2106. return conv;
  2107. }
  2108. char *itostr31(const int &xx)
  2109. {
  2110. conv[0]=(xx>=0)?'+':'-';
  2111. conv[1]=(xx/1000)%10+'0';
  2112. conv[2]=(xx/100)%10+'0';
  2113. conv[3]=(xx/10)%10+'0';
  2114. conv[4]='.';
  2115. conv[5]=(xx)%10+'0';
  2116. conv[6]=0;
  2117. return conv;
  2118. }
  2119. char *itostr3(const int &xx)
  2120. {
  2121. conv[0]=(xx/100)%10+'0';
  2122. conv[1]=(xx/10)%10+'0';
  2123. conv[2]=(xx)%10+'0';
  2124. conv[3]=0;
  2125. return conv;
  2126. }
  2127. char *itostr4(const int &xx)
  2128. {
  2129. conv[0]=(xx/1000)%10+'0';
  2130. conv[1]=(xx/100)%10+'0';
  2131. conv[2]=(xx/10)%10+'0';
  2132. conv[3]=(xx)%10+'0';
  2133. conv[4]=0;
  2134. return conv;
  2135. }
  2136. // convert float to string with +1234.5 format
  2137. char *ftostr51(const float &x)
  2138. {
  2139. int xx=x*10;
  2140. conv[0]=(xx>=0)?'+':'-';
  2141. xx=abs(xx);
  2142. conv[1]=(xx/10000)%10+'0';
  2143. conv[2]=(xx/1000)%10+'0';
  2144. conv[3]=(xx/100)%10+'0';
  2145. conv[4]=(xx/10)%10+'0';
  2146. conv[5]='.';
  2147. conv[6]=(xx)%10+'0';
  2148. conv[7]=0;
  2149. return conv;
  2150. }
  2151. // convert float to string with +123.45 format
  2152. char *ftostr52(const float &x)
  2153. {
  2154. int xx=x*100;
  2155. conv[0]=(xx>=0)?'+':'-';
  2156. xx=abs(xx);
  2157. conv[1]=(xx/10000)%10+'0';
  2158. conv[2]=(xx/1000)%10+'0';
  2159. conv[3]=(xx/100)%10+'0';
  2160. conv[4]='.';
  2161. conv[5]=(xx/10)%10+'0';
  2162. conv[6]=(xx)%10+'0';
  2163. conv[7]=0;
  2164. return conv;
  2165. }
  2166. #endif //ULTRA_LCD