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

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