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

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