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

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