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

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