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.

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