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

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