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

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