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

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