My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.pde 45KB

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