My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ultralcd.pde 63KB

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