My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ultralcd.pde 44KB

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