My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.pde 72KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001
  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(plaPreheatHotendTemp);setTargetBed(plaPreheatHPBTemp);
  479. #if FAN_PIN > -1
  480. FanSpeed = plaPreheatFanSpeed;
  481. analogWrite(FAN_PIN, FanSpeed);
  482. #endif
  483. beepshort(); );
  484. break;
  485. case ItemP_preheat_abs:
  486. MENUITEM( lcdprintPGM(MSG_PREHEAT_ABS) , BLOCK;setTargetHotend0(absPreheatHotendTemp);setTargetBed(absPreheatHPBTemp);
  487. #if FAN_PIN > -1
  488. FanSpeed = absPreheatFanSpeed;
  489. analogWrite(FAN_PIN, FanSpeed);
  490. #endif
  491. beepshort(); );
  492. break;
  493. case ItemP_cooldown:
  494. MENUITEM( lcdprintPGM(MSG_COOLDOWN) , BLOCK;setTargetHotend0(0);setTargetHotend1(0);setTargetHotend2(0);setTargetBed(0);beepshort(); ) ;
  495. break;
  496. // case ItemP_extrude:
  497. // MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E50");beepshort(); ) ;
  498. // break;
  499. case ItemP_move:
  500. MENUITEM( lcdprintPGM(MSG_MOVE_AXIS) , BLOCK;status=Sub_PrepareMove;beepshort(); );
  501. break;
  502. default:
  503. break;
  504. }
  505. line++;
  506. }
  507. updateActiveLines(ItemP_move,encoderpos);
  508. #endif
  509. }
  510. enum {
  511. ItemAM_exit,
  512. ItemAM_X, ItemAM_Y, ItemAM_Z, ItemAM_E, ItemAM_ERetract
  513. };
  514. void MainMenu::showAxisMove()
  515. {
  516. uint8_t line=0;
  517. int oldencoderpos=0;
  518. clearIfNecessary();
  519. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  520. {
  521. switch(i)
  522. {
  523. case ItemAM_exit:
  524. MENUITEM( lcdprintPGM(MSG_PREPARE_ALT) , BLOCK;status=Main_Prepare;beepshort(); ) ;
  525. break;
  526. case ItemAM_X:
  527. {
  528. //oldencoderpos=0;
  529. if(force_lcd_update)
  530. {
  531. lcd.setCursor(0,line);lcdprintPGM(" X:");
  532. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  533. }
  534. if((activeline!=line) )
  535. break;
  536. if(CLICKED)
  537. {
  538. linechanging=!linechanging;
  539. if(linechanging)
  540. {
  541. enquecommand("G91");
  542. }
  543. else
  544. {
  545. enquecommand("G90");
  546. encoderpos=activeline*lcdslow;
  547. beepshort();
  548. }
  549. BLOCK;
  550. }
  551. if(linechanging)
  552. {
  553. if (encoderpos >0)
  554. {
  555. enquecommand("G1 F700 X0.1");
  556. oldencoderpos=encoderpos;
  557. encoderpos=0;
  558. }
  559. else if (encoderpos < 0)
  560. {
  561. enquecommand("G1 F700 X-0.1");
  562. oldencoderpos=encoderpos;
  563. encoderpos=0;
  564. }
  565. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  566. }
  567. }
  568. break;
  569. case ItemAM_Y:
  570. {
  571. if(force_lcd_update)
  572. {
  573. lcd.setCursor(0,line);lcdprintPGM(" Y:");
  574. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  575. }
  576. if((activeline!=line) )
  577. break;
  578. if(CLICKED)
  579. {
  580. linechanging=!linechanging;
  581. if(linechanging)
  582. {
  583. enquecommand("G91");
  584. }
  585. else
  586. {
  587. enquecommand("G90");
  588. encoderpos=activeline*lcdslow;
  589. beepshort();
  590. }
  591. BLOCK;
  592. }
  593. if(linechanging)
  594. {
  595. if (encoderpos >0)
  596. {
  597. enquecommand("G1 F700 Y0.1");
  598. oldencoderpos=encoderpos;
  599. encoderpos=0;
  600. }
  601. else if (encoderpos < 0)
  602. {
  603. enquecommand("G1 F700 Y-0.1");
  604. oldencoderpos=encoderpos;
  605. encoderpos=0;
  606. }
  607. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  608. }
  609. }
  610. break;
  611. case ItemAM_Z:
  612. {
  613. if(force_lcd_update)
  614. {
  615. lcd.setCursor(0,line);lcdprintPGM(" Z:");
  616. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  617. }
  618. if((activeline!=line) )
  619. break;
  620. if(CLICKED)
  621. {
  622. linechanging=!linechanging;
  623. if(linechanging)
  624. {
  625. enquecommand("G91");
  626. }
  627. else
  628. {
  629. enquecommand("G90");
  630. encoderpos=activeline*lcdslow;
  631. beepshort();
  632. }
  633. BLOCK;
  634. }
  635. if(linechanging)
  636. {
  637. if (encoderpos >0)
  638. {
  639. enquecommand("G1 F70 Z0.1");
  640. oldencoderpos=encoderpos;
  641. encoderpos=0;
  642. }
  643. else if (encoderpos < 0)
  644. {
  645. enquecommand("G1 F70 Z-0.1");
  646. oldencoderpos=encoderpos;
  647. encoderpos=0;
  648. }
  649. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  650. }
  651. }
  652. break;
  653. case ItemAM_E:
  654. // ErikDB: TODO: this length should be changed for volumetric.
  655. MENUITEM( lcdprintPGM(MSG_EXTRUDE) , BLOCK;enquecommand("G92 E0");enquecommand("G1 F70 E1");beepshort(); ) ;
  656. break;
  657. case ItemAM_ERetract:
  658. // ErikDB: TODO: this length should be changed for volumetric.
  659. MENUITEM( lcdprintPGM(MSG_RETRACT) , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E-1");beepshort(); ) ;
  660. break;
  661. default:
  662. break;
  663. }
  664. line++;
  665. }
  666. updateActiveLines(ItemAM_ERetract,encoderpos);
  667. }
  668. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  669. #if (HEATER_BED_PIN > -1)
  670. ItemT_bed,
  671. #endif
  672. ItemT_fan};
  673. void MainMenu::showTune()
  674. {
  675. uint8_t line=0;
  676. clearIfNecessary();
  677. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  678. {
  679. //Serial.println((int)(line-lineoffset));
  680. switch(i)
  681. {
  682. case ItemT_exit:
  683. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  684. break;
  685. case ItemT_speed:
  686. {
  687. if(force_lcd_update)
  688. {
  689. lcd.setCursor(0,line);lcdprintPGM(MSG_SPEED);
  690. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  691. }
  692. if((activeline!=line) )
  693. break;
  694. if(CLICKED) //AnalogWrite(FAN_PIN, fanpwm);
  695. {
  696. linechanging=!linechanging;
  697. if(linechanging)
  698. {
  699. encoderpos=feedmultiply;
  700. }
  701. else
  702. {
  703. encoderpos=activeline*lcdslow;
  704. beepshort();
  705. }
  706. BLOCK;
  707. }
  708. if(linechanging)
  709. {
  710. if(encoderpos<1) encoderpos=1;
  711. if(encoderpos>400) encoderpos=400;
  712. feedmultiply = encoderpos;
  713. feedmultiplychanged=true;
  714. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  715. }
  716. }break;
  717. case ItemT_nozzle:
  718. {
  719. if(force_lcd_update)
  720. {
  721. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  722. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  723. }
  724. if((activeline!=line) )
  725. break;
  726. if(CLICKED)
  727. {
  728. linechanging=!linechanging;
  729. if(linechanging)
  730. {
  731. encoderpos=intround(degTargetHotend0());
  732. }
  733. else
  734. {
  735. setTargetHotend0(encoderpos);
  736. encoderpos=activeline*lcdslow;
  737. beepshort();
  738. }
  739. BLOCK;
  740. }
  741. if(linechanging)
  742. {
  743. if(encoderpos<0) encoderpos=0;
  744. if(encoderpos>260) encoderpos=260;
  745. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  746. }
  747. }break;
  748. #if (HEATER_BED_PIN > -1)
  749. case ItemT_bed:
  750. {
  751. if(force_lcd_update)
  752. {
  753. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  754. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  755. }
  756. if((activeline!=line) )
  757. break;
  758. if(CLICKED)
  759. {
  760. linechanging=!linechanging;
  761. if(linechanging)
  762. {
  763. encoderpos=intround(degTargetBed());
  764. }
  765. else
  766. {
  767. setTargetBed(encoderpos);
  768. encoderpos=activeline*lcdslow;
  769. beepshort();
  770. }
  771. BLOCK;
  772. }
  773. if(linechanging)
  774. {
  775. if(encoderpos<0) encoderpos=0;
  776. if(encoderpos>260) encoderpos=260;
  777. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  778. }
  779. }break;
  780. #endif
  781. case ItemT_fan:
  782. {
  783. if(force_lcd_update)
  784. {
  785. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  786. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  787. }
  788. if((activeline!=line) )
  789. break;
  790. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  791. {
  792. linechanging=!linechanging;
  793. if(linechanging)
  794. {
  795. encoderpos=FanSpeed;
  796. }
  797. else
  798. {
  799. encoderpos=activeline*lcdslow;
  800. beepshort();
  801. }
  802. BLOCK;
  803. }
  804. if(linechanging)
  805. {
  806. if(encoderpos<0) encoderpos=0;
  807. if(encoderpos>255) encoderpos=255;
  808. FanSpeed=encoderpos;
  809. analogWrite(FAN_PIN, FanSpeed);
  810. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  811. }
  812. }break;
  813. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  814. {
  815. if(force_lcd_update)
  816. {
  817. lcd.setCursor(0,line);lcdprintPGM(MSG_FLOW);
  818. lcd.setCursor(13,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
  819. }
  820. if((activeline!=line) )
  821. break;
  822. if(CLICKED)
  823. {
  824. linechanging=!linechanging;
  825. if(linechanging)
  826. {
  827. encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
  828. }
  829. else
  830. {
  831. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
  832. position[E_AXIS]=lround(position[E_AXIS]*factor);
  833. //current_position[E_AXIS]*=factor;
  834. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  835. encoderpos=activeline*lcdslow;
  836. }
  837. BLOCK;
  838. beepshort();
  839. }
  840. if(linechanging)
  841. {
  842. if(encoderpos<5) encoderpos=5;
  843. if(encoderpos>999999) encoderpos=999999;
  844. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.0));
  845. }
  846. }break;
  847. default:
  848. break;
  849. }
  850. line++;
  851. }
  852. updateActiveLines(ItemT_fan,encoderpos);
  853. }
  854. //does not work
  855. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  856. // {\
  857. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  858. // if(activeline==line) \
  859. // { \
  860. // if(CLICKED) \
  861. // { \
  862. // linechanging=!linechanging; \
  863. // if(linechanging) {enter_action;} \
  864. // else {accept_action;} \
  865. // } \
  866. // else \
  867. // if(linechanging) {change_action};}\
  868. // }
  869. //
  870. enum {
  871. ItemCT_exit,ItemCT_nozzle0,
  872. #ifdef AUTOTEMP
  873. ItemCT_autotempactive,
  874. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  875. #endif
  876. #if EXTRUDERS > 1
  877. ItemCT_nozzle1,
  878. #endif
  879. #if EXTRUDERS > 2
  880. ItemCT_nozzle2,
  881. #endif
  882. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  883. ItemCT_bed,
  884. #endif
  885. ItemCT_fan,
  886. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C,
  887. ItemCT_PLA_PreHeat_Setting,
  888. ItemCT_ABS_PreHeat_Setting,
  889. };
  890. void MainMenu::showControlTemp()
  891. {
  892. uint8_t line=0;
  893. clearIfNecessary();
  894. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  895. {
  896. switch(i)
  897. {
  898. case ItemCT_exit:
  899. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  900. break;
  901. case ItemCT_nozzle0:
  902. {
  903. if(force_lcd_update)
  904. {
  905. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  906. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  907. }
  908. if((activeline!=line) )
  909. break;
  910. if(CLICKED)
  911. {
  912. linechanging=!linechanging;
  913. if(linechanging)
  914. {
  915. encoderpos=intround(degTargetHotend0());
  916. }
  917. else
  918. {
  919. setTargetHotend0(encoderpos);
  920. encoderpos=activeline*lcdslow;
  921. beepshort();
  922. }
  923. BLOCK;
  924. }
  925. if(linechanging)
  926. {
  927. if(encoderpos<0) encoderpos=0;
  928. if(encoderpos>260) encoderpos=260;
  929. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  930. }
  931. }break;
  932. #if EXTRUDERS > 1
  933. case ItemCT_nozzle1:
  934. {
  935. if(force_lcd_update)
  936. {
  937. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE1);
  938. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend1())));
  939. }
  940. if((activeline!=line) )
  941. break;
  942. if(CLICKED)
  943. {
  944. linechanging=!linechanging;
  945. if(linechanging)
  946. {
  947. encoderpos=intround(degTargetHotend1());
  948. }
  949. else
  950. {
  951. setTargetHotend1(encoderpos);
  952. encoderpos=activeline*lcdslow;
  953. beepshort();
  954. }
  955. BLOCK;
  956. }
  957. if(linechanging)
  958. {
  959. if(encoderpos<0) encoderpos=0;
  960. if(encoderpos>260) encoderpos=260;
  961. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  962. }
  963. }break;
  964. #endif
  965. #if EXTRUDERS > 2
  966. case ItemCT_nozzle2:
  967. {
  968. if(force_lcd_update)
  969. {
  970. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE2);
  971. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend2())));
  972. }
  973. if((activeline!=line) )
  974. break;
  975. if(CLICKED)
  976. {
  977. linechanging=!linechanging;
  978. if(linechanging)
  979. {
  980. encoderpos=intround(degTargetHotend2());
  981. }
  982. else
  983. {
  984. setTargetHotend1(encoderpos);
  985. encoderpos=activeline*lcdslow;
  986. beepshort();
  987. }
  988. BLOCK;
  989. }
  990. if(linechanging)
  991. {
  992. if(encoderpos<0) encoderpos=0;
  993. if(encoderpos>260) encoderpos=260;
  994. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  995. }
  996. }break;
  997. #endif
  998. #ifdef AUTOTEMP
  999. case ItemCT_autotempmin:
  1000. {
  1001. if(force_lcd_update)
  1002. {
  1003. lcd.setCursor(0,line);lcdprintPGM(MSG_MIN);
  1004. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  1005. }
  1006. if((activeline!=line) )
  1007. break;
  1008. if(CLICKED)
  1009. {
  1010. linechanging=!linechanging;
  1011. if(linechanging)
  1012. {
  1013. encoderpos=intround(autotemp_min);
  1014. }
  1015. else
  1016. {
  1017. autotemp_min=encoderpos;
  1018. encoderpos=activeline*lcdslow;
  1019. beepshort();
  1020. }
  1021. BLOCK;
  1022. }
  1023. if(linechanging)
  1024. {
  1025. if(encoderpos<0) encoderpos=0;
  1026. if(encoderpos>260) encoderpos=260;
  1027. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1028. }
  1029. }break;
  1030. case ItemCT_autotempmax:
  1031. {
  1032. if(force_lcd_update)
  1033. {
  1034. lcd.setCursor(0,line);lcdprintPGM(MSG_MAX);
  1035. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  1036. }
  1037. if((activeline!=line) )
  1038. break;
  1039. if(CLICKED)
  1040. {
  1041. linechanging=!linechanging;
  1042. if(linechanging)
  1043. {
  1044. encoderpos=intround(autotemp_max);
  1045. }
  1046. else
  1047. {
  1048. autotemp_max=encoderpos;
  1049. encoderpos=activeline*lcdslow;
  1050. beepshort();
  1051. }
  1052. BLOCK;
  1053. }
  1054. if(linechanging)
  1055. {
  1056. if(encoderpos<0) encoderpos=0;
  1057. if(encoderpos>260) encoderpos=260;
  1058. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1059. }
  1060. }break;
  1061. case ItemCT_autotempfact:
  1062. {
  1063. if(force_lcd_update)
  1064. {
  1065. lcd.setCursor(0,line);lcdprintPGM(MSG_FACTOR);
  1066. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  1067. }
  1068. if((activeline!=line) )
  1069. break;
  1070. if(CLICKED)
  1071. {
  1072. linechanging=!linechanging;
  1073. if(linechanging)
  1074. {
  1075. encoderpos=intround(autotemp_factor*100);
  1076. }
  1077. else
  1078. {
  1079. autotemp_max=encoderpos;
  1080. encoderpos=activeline*lcdslow;
  1081. beepshort();
  1082. }
  1083. BLOCK;
  1084. }
  1085. if(linechanging)
  1086. {
  1087. if(encoderpos<0) encoderpos=0;
  1088. if(encoderpos>99) encoderpos=99;
  1089. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  1090. }
  1091. }break;
  1092. case ItemCT_autotempactive:
  1093. {
  1094. if(force_lcd_update)
  1095. {
  1096. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTOTEMP);
  1097. lcd.setCursor(13,line);
  1098. if(autotemp_enabled)
  1099. lcdprintPGM(MSG_ON);
  1100. else
  1101. lcdprintPGM(MSG_OFF);
  1102. }
  1103. if((activeline!=line) )
  1104. break;
  1105. if(CLICKED)
  1106. {
  1107. autotemp_enabled=!autotemp_enabled;
  1108. lcd.setCursor(13,line);
  1109. if(autotemp_enabled)
  1110. lcdprintPGM(MSG_ON);
  1111. else
  1112. lcdprintPGM(MSG_OFF);
  1113. BLOCK;
  1114. }
  1115. }break;
  1116. #endif //autotemp
  1117. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  1118. case ItemCT_bed:
  1119. {
  1120. if(force_lcd_update)
  1121. {
  1122. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  1123. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  1124. }
  1125. if((activeline!=line) )
  1126. break;
  1127. if(CLICKED)
  1128. {
  1129. linechanging=!linechanging;
  1130. if(linechanging)
  1131. {
  1132. encoderpos=intround(degTargetBed());
  1133. }
  1134. else
  1135. {
  1136. setTargetBed(encoderpos);
  1137. encoderpos=activeline*lcdslow;
  1138. beepshort();
  1139. }
  1140. BLOCK;
  1141. }
  1142. if(linechanging)
  1143. {
  1144. if(encoderpos<0) encoderpos=0;
  1145. if(encoderpos>260) encoderpos=260;
  1146. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1147. }
  1148. }break;
  1149. #endif
  1150. case ItemCT_fan:
  1151. {
  1152. if(force_lcd_update)
  1153. {
  1154. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  1155. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  1156. }
  1157. if((activeline!=line) )
  1158. break;
  1159. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  1160. {
  1161. linechanging=!linechanging;
  1162. if(linechanging)
  1163. {
  1164. encoderpos=FanSpeed;
  1165. }
  1166. else
  1167. {
  1168. encoderpos=activeline*lcdslow;
  1169. beepshort();
  1170. }
  1171. BLOCK;
  1172. }
  1173. if(linechanging)
  1174. {
  1175. if(encoderpos<0) encoderpos=0;
  1176. if(encoderpos>255) encoderpos=255;
  1177. FanSpeed=encoderpos;
  1178. analogWrite(FAN_PIN, FanSpeed);
  1179. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1180. }
  1181. }break;
  1182. #ifdef PIDTEMP
  1183. case ItemCT_PID_P:
  1184. {
  1185. if(force_lcd_update)
  1186. {
  1187. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  1188. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  1189. }
  1190. if((activeline!=line) )
  1191. break;
  1192. if(CLICKED)
  1193. {
  1194. linechanging=!linechanging;
  1195. if(linechanging)
  1196. {
  1197. encoderpos=(long)Kp;
  1198. }
  1199. else
  1200. {
  1201. Kp= encoderpos;
  1202. encoderpos=activeline*lcdslow;
  1203. }
  1204. BLOCK;
  1205. beepshort();
  1206. }
  1207. if(linechanging)
  1208. {
  1209. if(encoderpos<1) encoderpos=1;
  1210. if(encoderpos>9990) encoderpos=9990;
  1211. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1212. }
  1213. }break;
  1214. case ItemCT_PID_I:
  1215. {
  1216. if(force_lcd_update)
  1217. {
  1218. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_I);
  1219. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  1220. }
  1221. if((activeline!=line) )
  1222. break;
  1223. if(CLICKED)
  1224. {
  1225. linechanging=!linechanging;
  1226. if(linechanging)
  1227. {
  1228. encoderpos=(long)(Ki*10/PID_dT);
  1229. }
  1230. else
  1231. {
  1232. Ki= encoderpos/10.*PID_dT;
  1233. encoderpos=activeline*lcdslow;
  1234. }
  1235. BLOCK;
  1236. beepshort();
  1237. }
  1238. if(linechanging)
  1239. {
  1240. if(encoderpos<0) encoderpos=0;
  1241. if(encoderpos>9990) encoderpos=9990;
  1242. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  1243. }
  1244. }break;
  1245. case ItemCT_PID_D:
  1246. {
  1247. if(force_lcd_update)
  1248. {
  1249. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_D);
  1250. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  1251. }
  1252. if((activeline!=line) )
  1253. break;
  1254. if(CLICKED)
  1255. {
  1256. linechanging=!linechanging;
  1257. if(linechanging)
  1258. {
  1259. encoderpos=(long)(Kd/5./PID_dT);
  1260. }
  1261. else
  1262. {
  1263. Kd= encoderpos;
  1264. encoderpos=activeline*lcdslow;
  1265. }
  1266. BLOCK;
  1267. beepshort();
  1268. }
  1269. if(linechanging)
  1270. {
  1271. if(encoderpos<0) encoderpos=0;
  1272. if(encoderpos>9990) encoderpos=9990;
  1273. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1274. }
  1275. }break;
  1276. case ItemCT_PID_C:
  1277. #ifdef PID_ADD_EXTRUSION_RATE
  1278. {
  1279. if(force_lcd_update)
  1280. {
  1281. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_C);
  1282. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  1283. }
  1284. if((activeline!=line) )
  1285. break;
  1286. if(CLICKED)
  1287. {
  1288. linechanging=!linechanging;
  1289. if(linechanging)
  1290. {
  1291. encoderpos=(long)Kc;
  1292. }
  1293. else
  1294. {
  1295. Kc= encoderpos;
  1296. encoderpos=activeline*lcdslow;
  1297. }
  1298. BLOCK;
  1299. beepshort();
  1300. }
  1301. if(linechanging)
  1302. {
  1303. if(encoderpos<0) encoderpos=0;
  1304. if(encoderpos>990) encoderpos=990;
  1305. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1306. }
  1307. }
  1308. #endif
  1309. #endif
  1310. break;
  1311. case ItemCT_PLA_PreHeat_Setting:
  1312. MENUITEM( lcdprintPGM(MSG_PREHEAT_PLA_SETTINGS) , BLOCK;status=Sub_PreheatPLASettings;beepshort(); ) ;
  1313. break;
  1314. case ItemCT_ABS_PreHeat_Setting:
  1315. MENUITEM( lcdprintPGM(MSG_PREHEAT_ABS_SETTINGS) , BLOCK;status=Sub_PreheatABSSettings;beepshort(); ) ;
  1316. break;
  1317. default:
  1318. break;
  1319. }
  1320. line++;
  1321. }
  1322. updateActiveLines(ItemCT_ABS_PreHeat_Setting,encoderpos);
  1323. }
  1324. enum {
  1325. ItemCM_exit,
  1326. ItemCM_acc, ItemCM_xyjerk,
  1327. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1328. ItemCM_vtravmin,ItemCM_vmin,
  1329. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1330. ItemCM_aret, ItemCM_xsteps,ItemCM_ysteps, ItemCM_zsteps, ItemCM_esteps
  1331. };
  1332. void MainMenu::showControlMotion()
  1333. {
  1334. uint8_t line=0;
  1335. clearIfNecessary();
  1336. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1337. {
  1338. switch(i)
  1339. {
  1340. case ItemCM_exit:
  1341. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1342. break;
  1343. case ItemCM_acc:
  1344. {
  1345. if(force_lcd_update)
  1346. {
  1347. lcd.setCursor(0,line);lcdprintPGM(MSG_ACC);
  1348. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1349. }
  1350. if((activeline!=line) )
  1351. break;
  1352. if(CLICKED)
  1353. {
  1354. linechanging=!linechanging;
  1355. if(linechanging)
  1356. {
  1357. encoderpos=(long)acceleration/100;
  1358. }
  1359. else
  1360. {
  1361. acceleration= encoderpos*100;
  1362. encoderpos=activeline*lcdslow;
  1363. }
  1364. BLOCK;
  1365. beepshort();
  1366. }
  1367. if(linechanging)
  1368. {
  1369. if(encoderpos<5) encoderpos=5;
  1370. if(encoderpos>990) encoderpos=990;
  1371. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1372. }
  1373. }break;
  1374. case ItemCM_xyjerk: //max_xy_jerk
  1375. {
  1376. if(force_lcd_update)
  1377. {
  1378. lcd.setCursor(0,line);lcdprintPGM(MSG_VXY_JERK);
  1379. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1380. }
  1381. if((activeline!=line) )
  1382. break;
  1383. if(CLICKED)
  1384. {
  1385. linechanging=!linechanging;
  1386. if(linechanging)
  1387. {
  1388. encoderpos=(long)max_xy_jerk;
  1389. }
  1390. else
  1391. {
  1392. max_xy_jerk= encoderpos;
  1393. encoderpos=activeline*lcdslow;
  1394. }
  1395. BLOCK;
  1396. beepshort();
  1397. }
  1398. if(linechanging)
  1399. {
  1400. if(encoderpos<1) encoderpos=1;
  1401. if(encoderpos>990) encoderpos=990;
  1402. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1403. }
  1404. }break;
  1405. case ItemCM_vmaxx:
  1406. case ItemCM_vmaxy:
  1407. case ItemCM_vmaxz:
  1408. case ItemCM_vmaxe:
  1409. {
  1410. if(force_lcd_update)
  1411. {
  1412. lcd.setCursor(0,line);lcdprintPGM(MSG_VMAX);
  1413. if(i==ItemCM_vmaxx)lcdprintPGM(MSG_X);
  1414. if(i==ItemCM_vmaxy)lcdprintPGM(MSG_Y);
  1415. if(i==ItemCM_vmaxz)lcdprintPGM(MSG_Z);
  1416. if(i==ItemCM_vmaxe)lcdprintPGM(MSG_E);
  1417. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1418. }
  1419. if((activeline!=line) )
  1420. break;
  1421. if(CLICKED)
  1422. {
  1423. linechanging=!linechanging;
  1424. if(linechanging)
  1425. {
  1426. encoderpos=(long)max_feedrate[i-ItemCM_vmaxx];
  1427. }
  1428. else
  1429. {
  1430. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1431. encoderpos=activeline*lcdslow;
  1432. }
  1433. BLOCK;
  1434. beepshort();
  1435. }
  1436. if(linechanging)
  1437. {
  1438. if(encoderpos<1) encoderpos=1;
  1439. if(encoderpos>990) encoderpos=990;
  1440. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1441. }
  1442. }break;
  1443. case ItemCM_vmin:
  1444. {
  1445. if(force_lcd_update)
  1446. {
  1447. lcd.setCursor(0,line);lcdprintPGM(MSG_VMIN);
  1448. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1449. }
  1450. if((activeline!=line) )
  1451. break;
  1452. if(CLICKED)
  1453. {
  1454. linechanging=!linechanging;
  1455. if(linechanging)
  1456. {
  1457. encoderpos=(long)(minimumfeedrate);
  1458. }
  1459. else
  1460. {
  1461. minimumfeedrate= encoderpos;
  1462. encoderpos=activeline*lcdslow;
  1463. }
  1464. BLOCK;
  1465. beepshort();
  1466. }
  1467. if(linechanging)
  1468. {
  1469. if(encoderpos<0) encoderpos=0;
  1470. if(encoderpos>990) encoderpos=990;
  1471. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1472. }
  1473. }break;
  1474. case ItemCM_vtravmin:
  1475. {
  1476. if(force_lcd_update)
  1477. {
  1478. lcd.setCursor(0,line);lcdprintPGM(MSG_VTRAV_MIN);
  1479. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1480. }
  1481. if((activeline!=line) )
  1482. break;
  1483. if(CLICKED)
  1484. {
  1485. linechanging=!linechanging;
  1486. if(linechanging)
  1487. {
  1488. encoderpos=(long)mintravelfeedrate;
  1489. }
  1490. else
  1491. {
  1492. mintravelfeedrate= encoderpos;
  1493. encoderpos=activeline*lcdslow;
  1494. }
  1495. BLOCK;
  1496. beepshort();
  1497. }
  1498. if(linechanging)
  1499. {
  1500. if(encoderpos<0) encoderpos=0;
  1501. if(encoderpos>990) encoderpos=990;
  1502. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1503. }
  1504. }break;
  1505. case ItemCM_amaxx:
  1506. case ItemCM_amaxy:
  1507. case ItemCM_amaxz:
  1508. case ItemCM_amaxe:
  1509. {
  1510. if(force_lcd_update)
  1511. {
  1512. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1513. if(i==ItemCM_amaxx)lcdprintPGM(MSG_X);
  1514. if(i==ItemCM_amaxy)lcdprintPGM(MSG_Y);
  1515. if(i==ItemCM_amaxz)lcdprintPGM(MSG_Z);
  1516. if(i==ItemCM_amaxe)lcdprintPGM(MSG_E);
  1517. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1518. }
  1519. if((activeline!=line) )
  1520. break;
  1521. if(CLICKED)
  1522. {
  1523. linechanging=!linechanging;
  1524. if(linechanging)
  1525. {
  1526. encoderpos=(long)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1527. }
  1528. else
  1529. {
  1530. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1531. encoderpos=activeline*lcdslow;
  1532. }
  1533. BLOCK;
  1534. beepshort();
  1535. }
  1536. if(linechanging)
  1537. {
  1538. if(encoderpos<1) encoderpos=1;
  1539. if(encoderpos>990) encoderpos=990;
  1540. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1541. }
  1542. }break;
  1543. case ItemCM_aret://float retract_acceleration = 7000;
  1544. {
  1545. if(force_lcd_update)
  1546. {
  1547. lcd.setCursor(0,line);lcdprintPGM(MSG_A_RETRACT);
  1548. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1549. }
  1550. if((activeline!=line) )
  1551. break;
  1552. if(CLICKED)
  1553. {
  1554. linechanging=!linechanging;
  1555. if(linechanging)
  1556. {
  1557. encoderpos=(long)retract_acceleration/100;
  1558. }
  1559. else
  1560. {
  1561. retract_acceleration= encoderpos*100;
  1562. encoderpos=activeline*lcdslow;
  1563. }
  1564. BLOCK;
  1565. beepshort();
  1566. }
  1567. if(linechanging)
  1568. {
  1569. if(encoderpos<10) encoderpos=10;
  1570. if(encoderpos>990) encoderpos=990;
  1571. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1572. }
  1573. }break;
  1574. case ItemCM_xsteps://axis_steps_per_unit[i] = code_value();
  1575. {
  1576. if(force_lcd_update)
  1577. {
  1578. lcd.setCursor(0,line);lcdprintPGM(MSG_XSTEPS);
  1579. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[X_AXIS]));
  1580. }
  1581. if((activeline!=line) )
  1582. break;
  1583. if(CLICKED)
  1584. {
  1585. linechanging=!linechanging;
  1586. if(linechanging)
  1587. {
  1588. encoderpos=(long)(axis_steps_per_unit[X_AXIS]*100.0);
  1589. }
  1590. else
  1591. {
  1592. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[X_AXIS]);
  1593. position[X_AXIS]=lround(position[X_AXIS]*factor);
  1594. //current_position[X_AXIS]*=factor;
  1595. axis_steps_per_unit[X_AXIS]= encoderpos/100.0;
  1596. encoderpos=activeline*lcdslow;
  1597. }
  1598. BLOCK;
  1599. beepshort();
  1600. }
  1601. if(linechanging)
  1602. {
  1603. if(encoderpos<5) encoderpos=5;
  1604. if(encoderpos>999999) encoderpos=999999;
  1605. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1606. }
  1607. }break;
  1608. case ItemCM_ysteps://axis_steps_per_unit[i] = code_value();
  1609. {
  1610. if(force_lcd_update)
  1611. {
  1612. lcd.setCursor(0,line);lcdprintPGM(MSG_YSTEPS);
  1613. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Y_AXIS]));
  1614. }
  1615. if((activeline!=line) )
  1616. break;
  1617. if(CLICKED)
  1618. {
  1619. linechanging=!linechanging;
  1620. if(linechanging)
  1621. {
  1622. encoderpos=(long)(axis_steps_per_unit[Y_AXIS]*100.0);
  1623. }
  1624. else
  1625. {
  1626. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Y_AXIS]);
  1627. position[Y_AXIS]=lround(position[Y_AXIS]*factor);
  1628. //current_position[Y_AXIS]*=factor;
  1629. axis_steps_per_unit[Y_AXIS]= encoderpos/100.0;
  1630. encoderpos=activeline*lcdslow;
  1631. }
  1632. BLOCK;
  1633. beepshort();
  1634. }
  1635. if(linechanging)
  1636. {
  1637. if(encoderpos<5) encoderpos=5;
  1638. if(encoderpos>999999) encoderpos=999999;
  1639. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1640. }
  1641. }break;
  1642. case ItemCM_zsteps://axis_steps_per_unit[i] = code_value();
  1643. {
  1644. if(force_lcd_update)
  1645. {
  1646. lcd.setCursor(0,line);lcdprintPGM(MSG_ZSTEPS);
  1647. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Z_AXIS]));
  1648. }
  1649. if((activeline!=line) )
  1650. break;
  1651. if(CLICKED)
  1652. {
  1653. linechanging=!linechanging;
  1654. if(linechanging)
  1655. {
  1656. encoderpos=(long)(axis_steps_per_unit[Z_AXIS]*100.0);
  1657. }
  1658. else
  1659. {
  1660. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Z_AXIS]);
  1661. position[Z_AXIS]=lround(position[Z_AXIS]*factor);
  1662. //current_position[Z_AXIS]*=factor;
  1663. axis_steps_per_unit[Z_AXIS]= encoderpos/100.0;
  1664. encoderpos=activeline*lcdslow;
  1665. }
  1666. BLOCK;
  1667. beepshort();
  1668. }
  1669. if(linechanging)
  1670. {
  1671. if(encoderpos<5) encoderpos=5;
  1672. if(encoderpos>999999) encoderpos=999999;
  1673. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1674. }
  1675. }break;
  1676. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1677. {
  1678. if(force_lcd_update)
  1679. {
  1680. lcd.setCursor(0,line);lcdprintPGM(MSG_ESTEPS);
  1681. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
  1682. }
  1683. if((activeline!=line) )
  1684. break;
  1685. if(CLICKED)
  1686. {
  1687. linechanging=!linechanging;
  1688. if(linechanging)
  1689. {
  1690. encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
  1691. }
  1692. else
  1693. {
  1694. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
  1695. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1696. //current_position[E_AXIS]*=factor;
  1697. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  1698. encoderpos=activeline*lcdslow;
  1699. }
  1700. BLOCK;
  1701. beepshort();
  1702. }
  1703. if(linechanging)
  1704. {
  1705. if(encoderpos<5) encoderpos=5;
  1706. if(encoderpos>999999) encoderpos=999999;
  1707. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1708. }
  1709. }break;
  1710. default:
  1711. break;
  1712. }
  1713. line++;
  1714. }
  1715. updateActiveLines(ItemCM_esteps,encoderpos);
  1716. }
  1717. enum {
  1718. ItemR_exit,
  1719. ItemR_autoretract,
  1720. ItemR_retract_length,ItemR_retract_feedrate,ItemR_retract_zlift,
  1721. ItemR_unretract_length,ItemR_unretract_feedrate,
  1722. };
  1723. void MainMenu::showControlRetract()
  1724. {
  1725. #ifdef FWRETRACT
  1726. uint8_t line=0;
  1727. clearIfNecessary();
  1728. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1729. {
  1730. switch(i)
  1731. {
  1732. case ItemR_exit:
  1733. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1734. break;
  1735. //float retract_length=2, retract_feedrate=1200, retract_zlift=0.4;
  1736. //float retract_recover_length=0, retract_recover_feedrate=500;
  1737. case ItemR_autoretract:
  1738. {
  1739. if(force_lcd_update)
  1740. {
  1741. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTORETRACT);
  1742. lcd.setCursor(13,line);
  1743. if(autoretract_enabled)
  1744. lcdprintPGM(MSG_ON);
  1745. else
  1746. lcdprintPGM(MSG_OFF);
  1747. }
  1748. if((activeline!=line) )
  1749. break;
  1750. if(CLICKED)
  1751. {
  1752. autoretract_enabled=!autoretract_enabled;
  1753. lcd.setCursor(13,line);
  1754. if(autoretract_enabled)
  1755. lcdprintPGM(MSG_ON);
  1756. else
  1757. lcdprintPGM(MSG_OFF);
  1758. BLOCK;
  1759. }
  1760. }break;
  1761. case ItemR_retract_length:
  1762. {
  1763. if(force_lcd_update)
  1764. {
  1765. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT);
  1766. lcd.setCursor(13,line);lcd.print(ftostr52(retract_length));
  1767. }
  1768. if((activeline!=line) )
  1769. break;
  1770. if(CLICKED)
  1771. {
  1772. linechanging=!linechanging;
  1773. if(linechanging)
  1774. {
  1775. encoderpos=(long)(retract_length*100);
  1776. }
  1777. else
  1778. {
  1779. retract_length= encoderpos/100.;
  1780. encoderpos=activeline*lcdslow;
  1781. }
  1782. BLOCK;
  1783. beepshort();
  1784. }
  1785. if(linechanging)
  1786. {
  1787. if(encoderpos<1) encoderpos=1;
  1788. if(encoderpos>990) encoderpos=990;
  1789. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
  1790. }
  1791. }break;
  1792. case ItemR_retract_feedrate:
  1793. {
  1794. if(force_lcd_update)
  1795. {
  1796. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACTF);
  1797. lcd.setCursor(13,line);lcd.print(itostr4(retract_feedrate));
  1798. }
  1799. if((activeline!=line) )
  1800. break;
  1801. if(CLICKED)
  1802. {
  1803. linechanging=!linechanging;
  1804. if(linechanging)
  1805. {
  1806. encoderpos=(long)(retract_feedrate/5);
  1807. }
  1808. else
  1809. {
  1810. retract_feedrate= encoderpos*5.;
  1811. encoderpos=activeline*lcdslow;
  1812. }
  1813. BLOCK;
  1814. beepshort();
  1815. }
  1816. if(linechanging)
  1817. {
  1818. if(encoderpos<1) encoderpos=1;
  1819. if(encoderpos>990) encoderpos=990;
  1820. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  1821. }
  1822. }break;
  1823. case ItemR_retract_zlift://float retract_acceleration = 7000;
  1824. {
  1825. if(force_lcd_update)
  1826. {
  1827. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_ZLIFT);
  1828. lcd.setCursor(13,line);lcd.print(ftostr52(retract_zlift));;
  1829. }
  1830. if((activeline!=line) )
  1831. break;
  1832. if(CLICKED)
  1833. {
  1834. linechanging=!linechanging;
  1835. if(linechanging)
  1836. {
  1837. encoderpos=(long)(retract_zlift*10);
  1838. }
  1839. else
  1840. {
  1841. retract_zlift= encoderpos/10.;
  1842. encoderpos=activeline*lcdslow;
  1843. }
  1844. BLOCK;
  1845. beepshort();
  1846. }
  1847. if(linechanging)
  1848. {
  1849. if(encoderpos<0) encoderpos=0;
  1850. if(encoderpos>990) encoderpos=990;
  1851. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/10.));
  1852. }
  1853. }break;
  1854. case ItemR_unretract_length:
  1855. {
  1856. if(force_lcd_update)
  1857. {
  1858. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVER);
  1859. lcd.setCursor(13,line);lcd.print(ftostr52(retract_recover_length));;
  1860. }
  1861. if((activeline!=line) )
  1862. break;
  1863. if(CLICKED)
  1864. {
  1865. linechanging=!linechanging;
  1866. if(linechanging)
  1867. {
  1868. encoderpos=(long)(retract_recover_length*100);
  1869. }
  1870. else
  1871. {
  1872. retract_recover_length= encoderpos/100.;
  1873. encoderpos=activeline*lcdslow;
  1874. }
  1875. BLOCK;
  1876. beepshort();
  1877. }
  1878. if(linechanging)
  1879. {
  1880. if(encoderpos<0) encoderpos=0;
  1881. if(encoderpos>990) encoderpos=990;
  1882. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
  1883. }
  1884. }break;
  1885. case ItemR_unretract_feedrate:
  1886. {
  1887. if(force_lcd_update)
  1888. {
  1889. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVERF);
  1890. lcd.setCursor(13,line);lcd.print(itostr4(retract_recover_feedrate));
  1891. }
  1892. if((activeline!=line) )
  1893. break;
  1894. if(CLICKED)
  1895. {
  1896. linechanging=!linechanging;
  1897. if(linechanging)
  1898. {
  1899. encoderpos=(long)retract_recover_feedrate/5;
  1900. }
  1901. else
  1902. {
  1903. retract_recover_feedrate= encoderpos*5.;
  1904. encoderpos=activeline*lcdslow;
  1905. }
  1906. BLOCK;
  1907. beepshort();
  1908. }
  1909. if(linechanging)
  1910. {
  1911. if(encoderpos<1) encoderpos=1;
  1912. if(encoderpos>990) encoderpos=990;
  1913. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  1914. }
  1915. }break;
  1916. default:
  1917. break;
  1918. }
  1919. line++;
  1920. }
  1921. updateActiveLines(ItemR_unretract_feedrate,encoderpos);
  1922. #endif
  1923. }
  1924. enum {
  1925. ItemC_exit,ItemC_temp,ItemC_move,
  1926. #ifdef FWRETRACT
  1927. ItemC_rectract,
  1928. #endif
  1929. ItemC_store, ItemC_load,ItemC_failsafe
  1930. };
  1931. void MainMenu::showControl()
  1932. {
  1933. uint8_t line=0;
  1934. clearIfNecessary();
  1935. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1936. {
  1937. switch(i)
  1938. {
  1939. case ItemC_exit:
  1940. MENUITEM( lcdprintPGM(MSG_MAIN_WIDE) , BLOCK;status=Main_Menu;beepshort(); ) ;
  1941. break;
  1942. case ItemC_temp:
  1943. MENUITEM( lcdprintPGM(MSG_TEMPERATURE_WIDE) , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1944. break;
  1945. case ItemC_move:
  1946. MENUITEM( lcdprintPGM(MSG_MOTION_WIDE) , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1947. break;
  1948. #ifdef FWRETRACT
  1949. case ItemC_rectract:
  1950. MENUITEM( lcdprintPGM(MSG_RECTRACT_WIDE) , BLOCK;status=Sub_RetractControl;beepshort(); ) ;
  1951. break;
  1952. #endif
  1953. case ItemC_store:
  1954. {
  1955. if(force_lcd_update)
  1956. {
  1957. lcd.setCursor(0,line);lcdprintPGM(MSG_STORE_EPROM);
  1958. }
  1959. if((activeline==line) && CLICKED)
  1960. {
  1961. //enquecommand("M84");
  1962. beepshort();
  1963. BLOCK;
  1964. EEPROM_StoreSettings();
  1965. }
  1966. }break;
  1967. case ItemC_load:
  1968. {
  1969. if(force_lcd_update)
  1970. {
  1971. lcd.setCursor(0,line);lcdprintPGM(MSG_LOAD_EPROM);
  1972. }
  1973. if((activeline==line) && CLICKED)
  1974. {
  1975. //enquecommand("M84");
  1976. beepshort();
  1977. BLOCK;
  1978. EEPROM_RetrieveSettings();
  1979. }
  1980. }break;
  1981. case ItemC_failsafe:
  1982. {
  1983. if(force_lcd_update)
  1984. {
  1985. lcd.setCursor(0,line);lcdprintPGM(MSG_RESTORE_FAILSAFE);
  1986. }
  1987. if((activeline==line) && CLICKED)
  1988. {
  1989. //enquecommand("M84");
  1990. beepshort();
  1991. BLOCK;
  1992. EEPROM_RetrieveSettings(true);
  1993. }
  1994. }break;
  1995. default:
  1996. break;
  1997. }
  1998. line++;
  1999. }
  2000. updateActiveLines(ItemC_failsafe,encoderpos);
  2001. }
  2002. void MainMenu::showSD()
  2003. {
  2004. #ifdef SDSUPPORT
  2005. uint8_t line=0;
  2006. clearIfNecessary();
  2007. static uint8_t nrfiles=0;
  2008. if(force_lcd_update)
  2009. {
  2010. if(card.cardOK)
  2011. {
  2012. nrfiles=card.getnrfilenames();
  2013. }
  2014. else
  2015. {
  2016. nrfiles=0;
  2017. lineoffset=0;
  2018. }
  2019. }
  2020. bool enforceupdate=false;
  2021. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2022. {
  2023. switch(i)
  2024. {
  2025. case 0:
  2026. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  2027. break;
  2028. // case 1:
  2029. // {
  2030. // if(force_lcd_update)
  2031. // {
  2032. // lcd.setCursor(0,line);
  2033. // #ifdef CARDINSERTED
  2034. // if(CARDINSERTED)
  2035. // #else
  2036. // if(true)
  2037. // #endif
  2038. // {
  2039. // lcdprintPGM(" \004Refresh");
  2040. // }
  2041. // else
  2042. // {
  2043. // lcdprintPGM(" \004Insert Card");
  2044. // }
  2045. //
  2046. // }
  2047. // if((activeline==line) && CLICKED)
  2048. // {
  2049. // BLOCK;
  2050. // beepshort();
  2051. // card.initsd();
  2052. // force_lcd_update=true;
  2053. // nrfiles=card.getnrfilenames();
  2054. // }
  2055. // }break;
  2056. case 1:
  2057. MENUITEM( lcd.print(" ");card.getWorkDirName();
  2058. if(card.filename[0]=='/') lcdprintPGM(MSG_REFRESH);
  2059. else {
  2060. lcd.print("\005");
  2061. lcd.print(card.filename);
  2062. lcd.print("/..");
  2063. } ,
  2064. BLOCK;
  2065. if(SDCARDDETECT == -1) card.initsd();
  2066. card.updir();
  2067. enforceupdate=true;
  2068. lineoffset=0;
  2069. beepshort(); ) ;
  2070. break;
  2071. default:
  2072. {
  2073. #define FIRSTITEM 2
  2074. if(i-FIRSTITEM<nrfiles)
  2075. {
  2076. if(force_lcd_update)
  2077. {
  2078. card.getfilename(i-FIRSTITEM);
  2079. //Serial.print("Filenr:");Serial.println(i-2);
  2080. lcd.setCursor(0,line);lcdprintPGM(" ");
  2081. if(card.filenameIsDir) lcd.print("\005");
  2082. lcd.print(card.filename);
  2083. }
  2084. if((activeline==line) && CLICKED)
  2085. {
  2086. BLOCK
  2087. card.getfilename(i-FIRSTITEM);
  2088. if(card.filenameIsDir)
  2089. {
  2090. for(int8_t i=0;i<strlen(card.filename);i++)
  2091. card.filename[i]=tolower(card.filename[i]);
  2092. card.chdir(card.filename);
  2093. lineoffset=0;
  2094. enforceupdate=true;
  2095. }
  2096. else
  2097. {
  2098. char cmd[30];
  2099. for(int8_t i=0;i<strlen(card.filename);i++)
  2100. card.filename[i]=tolower(card.filename[i]);
  2101. sprintf(cmd,"M23 %s",card.filename);
  2102. //sprintf(cmd,"M115");
  2103. enquecommand(cmd);
  2104. enquecommand("M24");
  2105. beep();
  2106. status=Main_Status;
  2107. lcd_status(card.filename);
  2108. }
  2109. }
  2110. }
  2111. }
  2112. break;
  2113. }
  2114. line++;
  2115. }
  2116. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  2117. if(enforceupdate)
  2118. {
  2119. force_lcd_update=true;
  2120. enforceupdate=false;
  2121. }
  2122. #endif
  2123. }
  2124. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file, ItemM_pause};
  2125. void MainMenu::showMainMenu()
  2126. {
  2127. #ifndef ULTIPANEL
  2128. force_lcd_update=false;
  2129. #endif
  2130. if(tune)
  2131. {
  2132. if(!(movesplanned() || IS_SD_PRINTING))
  2133. {
  2134. force_lcd_update=true;
  2135. tune=false;
  2136. }
  2137. }
  2138. else
  2139. {
  2140. if(movesplanned() || IS_SD_PRINTING)
  2141. {
  2142. force_lcd_update=true;
  2143. tune=true;
  2144. }
  2145. }
  2146. clearIfNecessary();
  2147. uint8_t line=0;
  2148. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2149. {
  2150. switch(i)
  2151. {
  2152. case ItemM_watch:
  2153. MENUITEM( lcdprintPGM(MSG_WATCH) , BLOCK;status=Main_Status;beepshort(); ) ;
  2154. break;
  2155. case ItemM_prepare:
  2156. MENUITEM( if(!tune) lcdprintPGM(MSG_PREPARE);else lcdprintPGM(MSG_TUNE); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  2157. break;
  2158. case ItemM_control:
  2159. MENUITEM( lcdprintPGM(MSG_CONTROL_ARROW) , BLOCK;status=Main_Control;beepshort(); ) ;
  2160. break;
  2161. #ifdef SDSUPPORT
  2162. case ItemM_file:
  2163. {
  2164. if(force_lcd_update)
  2165. {
  2166. lcd.setCursor(0,line);
  2167. #ifdef CARDINSERTED
  2168. if(CARDINSERTED)
  2169. #else
  2170. if(true)
  2171. #endif
  2172. {
  2173. if(card.sdprinting)
  2174. lcdprintPGM(MSG_STOP_PRINT);
  2175. else
  2176. lcdprintPGM(MSG_CARD_MENU);
  2177. }
  2178. else
  2179. {
  2180. lcdprintPGM(MSG_NO_CARD);
  2181. }
  2182. }
  2183. #ifdef CARDINSERTED
  2184. if(CARDINSERTED)
  2185. #endif
  2186. if((activeline==line)&&CLICKED)
  2187. {
  2188. card.printingHasFinished();
  2189. BLOCK;
  2190. status=Main_SD;
  2191. beepshort();
  2192. }
  2193. }break;
  2194. case ItemM_pause:
  2195. {
  2196. if(force_lcd_update)
  2197. {
  2198. lcd.setCursor(0,line);
  2199. #ifdef CARDINSERTED
  2200. if(CARDINSERTED)
  2201. #else
  2202. if(true)
  2203. #endif
  2204. {
  2205. if(card.sdprinting)
  2206. lcdprintPGM(MSG_PAUSE_PRINT);
  2207. else
  2208. lcdprintPGM(MSG_RESUME_PRINT);
  2209. }
  2210. else
  2211. {
  2212. //lcdprintPGM(MSG_NO_CARD);
  2213. }
  2214. }
  2215. #ifdef CARDINSERTED
  2216. if(CARDINSERTED)
  2217. #endif
  2218. if((activeline==line) && CLICKED)
  2219. {
  2220. if(card.sdprinting)
  2221. {
  2222. card.pauseSDPrint();
  2223. beepshort();
  2224. status = Main_Status;
  2225. }
  2226. else
  2227. {
  2228. card.startFileprint();
  2229. starttime=millis();
  2230. beepshort();
  2231. status = Main_Status;
  2232. }
  2233. }
  2234. }break;
  2235. #else
  2236. case ItemM_file:
  2237. break;
  2238. case ItemM_pause:
  2239. break;
  2240. #endif
  2241. default:
  2242. SERIAL_ERROR_START;
  2243. SERIAL_ERRORLNPGM(MSG_SERIAL_ERROR_MENU_STRUCTURE);
  2244. break;
  2245. }
  2246. line++;
  2247. }
  2248. uint8_t numberOfLines = 4;
  2249. #ifdef SDSUPPORT
  2250. numberOfLines = 4;
  2251. #else
  2252. numberOfLines = 3;
  2253. #endif
  2254. updateActiveLines(numberOfLines,encoderpos);
  2255. }
  2256. void MainMenu::update()
  2257. {
  2258. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  2259. static long timeoutToStatus=0;
  2260. static bool oldcardstatus=false;
  2261. #ifdef CARDINSERTED
  2262. if((CARDINSERTED != oldcardstatus))
  2263. {
  2264. force_lcd_update=true;
  2265. oldcardstatus=CARDINSERTED;
  2266. lcd_init(); // to maybe revive the lcd if static electricty killed it.
  2267. //Serial.println("echo: SD CHANGE");
  2268. if(CARDINSERTED)
  2269. {
  2270. card.initsd();
  2271. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  2272. }
  2273. else
  2274. {
  2275. card.release();
  2276. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  2277. }
  2278. }
  2279. #endif
  2280. if(status!=oldstatus)
  2281. {
  2282. force_lcd_update=true;
  2283. encoderpos=0;
  2284. lineoffset=0;
  2285. oldstatus=status;
  2286. }
  2287. if( (encoderpos!=lastencoderpos) || CLICKED)
  2288. timeoutToStatus=millis()+STATUSTIMEOUT;
  2289. switch(status)
  2290. {
  2291. case Main_Status:
  2292. {
  2293. showStatus();
  2294. if(CLICKED)
  2295. {
  2296. linechanging=false;
  2297. BLOCK
  2298. status=Main_Menu;
  2299. timeoutToStatus=millis()+STATUSTIMEOUT;
  2300. }
  2301. }break;
  2302. case Main_Menu:
  2303. {
  2304. showMainMenu();
  2305. linechanging=false;
  2306. }break;
  2307. case Main_Prepare:
  2308. {
  2309. if(tune)
  2310. {
  2311. showTune();
  2312. }
  2313. else
  2314. {
  2315. showPrepare();
  2316. }
  2317. }break;
  2318. case Sub_PrepareMove:
  2319. {
  2320. showAxisMove();
  2321. }break;
  2322. case Main_Control:
  2323. {
  2324. showControl();
  2325. }break;
  2326. case Sub_MotionControl:
  2327. {
  2328. showControlMotion();
  2329. }break;
  2330. case Sub_RetractControl:
  2331. {
  2332. showControlRetract();
  2333. }break;
  2334. case Sub_TempControl:
  2335. {
  2336. showControlTemp();
  2337. }break;
  2338. case Main_SD:
  2339. {
  2340. showSD();
  2341. }break;
  2342. case Sub_PreheatPLASettings:
  2343. {
  2344. showPLAsettings();
  2345. }break;
  2346. case Sub_PreheatABSSettings:
  2347. {
  2348. showABSsettings();
  2349. }break;
  2350. }
  2351. if(timeoutToStatus<millis())
  2352. status=Main_Status;
  2353. //force_lcd_update=false;
  2354. lastencoderpos=encoderpos;
  2355. }
  2356. enum {
  2357. ItemPLAPreHeat_Exit,
  2358. ItemPLAPreHeat_set_PLA_FanSpeed,
  2359. ItemPLAPreHeat_set_nozzle,
  2360. ItemPLAPreHeat_set_HPB,
  2361. ItemPLAPreHeat_Store_Eprom
  2362. };
  2363. void MainMenu::showPLAsettings()
  2364. {
  2365. #ifdef ULTIPANEL
  2366. uint8_t line=0;
  2367. clearIfNecessary();
  2368. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2369. {
  2370. switch(i)
  2371. {
  2372. case ItemPLAPreHeat_Exit:
  2373. MENUITEM( lcdprintPGM(MSG_TEMPERATURE_RTN) , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  2374. break;
  2375. case ItemPLAPreHeat_set_PLA_FanSpeed:
  2376. {
  2377. if(force_lcd_update)
  2378. {
  2379. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  2380. lcd.setCursor(13,line);lcd.print(ftostr3(plaPreheatFanSpeed));
  2381. }
  2382. if((activeline!=line) )
  2383. break;
  2384. if(CLICKED)
  2385. {
  2386. linechanging=!linechanging;
  2387. if(linechanging)
  2388. {
  2389. encoderpos=plaPreheatFanSpeed;
  2390. }
  2391. else
  2392. {
  2393. encoderpos=activeline*lcdslow;
  2394. beepshort();
  2395. }
  2396. BLOCK;
  2397. }
  2398. if(linechanging)
  2399. {
  2400. if(encoderpos<0) encoderpos=0;
  2401. if(encoderpos>255) encoderpos=255;
  2402. plaPreheatFanSpeed=encoderpos;
  2403. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  2404. }
  2405. }break;
  2406. case ItemPLAPreHeat_set_nozzle:
  2407. {
  2408. if(force_lcd_update)
  2409. {
  2410. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  2411. lcd.setCursor(13,line);lcd.print(ftostr3(plaPreheatHotendTemp));
  2412. }
  2413. if((activeline!=line) )
  2414. break;
  2415. if(CLICKED)
  2416. {
  2417. linechanging=!linechanging;
  2418. if(linechanging)
  2419. {
  2420. encoderpos=plaPreheatHotendTemp;
  2421. }
  2422. else
  2423. {
  2424. encoderpos=activeline*lcdslow;
  2425. beepshort();
  2426. }
  2427. BLOCK;
  2428. }
  2429. if(linechanging)
  2430. {
  2431. if(encoderpos<0) encoderpos=0;
  2432. if(encoderpos>260) encoderpos=260;
  2433. plaPreheatHotendTemp = encoderpos;
  2434. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  2435. }
  2436. }break;
  2437. case ItemPLAPreHeat_set_HPB:
  2438. {
  2439. if(force_lcd_update)
  2440. {
  2441. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  2442. lcd.setCursor(13,line);lcd.print(ftostr3(plaPreheatHPBTemp));
  2443. }
  2444. if((activeline!=line) )
  2445. break;
  2446. if(CLICKED)
  2447. {
  2448. linechanging=!linechanging;
  2449. if(linechanging)
  2450. {
  2451. encoderpos=plaPreheatHPBTemp;
  2452. }
  2453. else
  2454. {
  2455. encoderpos=activeline*lcdslow;
  2456. beepshort();
  2457. }
  2458. BLOCK;
  2459. }
  2460. if(linechanging)
  2461. {
  2462. if(encoderpos<0) encoderpos=0;
  2463. if(encoderpos>250) encoderpos=150;
  2464. plaPreheatHPBTemp = encoderpos;
  2465. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  2466. }
  2467. }break;
  2468. case ItemPLAPreHeat_Store_Eprom:
  2469. {
  2470. if(force_lcd_update)
  2471. {
  2472. lcd.setCursor(0,line);lcdprintPGM(MSG_STORE_EPROM);
  2473. }
  2474. if((activeline==line) && CLICKED)
  2475. {
  2476. //enquecommand("M84");
  2477. beepshort();
  2478. BLOCK;
  2479. EEPROM_StoreSettings();
  2480. }
  2481. }break;
  2482. default:
  2483. break;
  2484. }
  2485. line++;
  2486. }
  2487. updateActiveLines(ItemPLAPreHeat_Store_Eprom,encoderpos);
  2488. #endif
  2489. }
  2490. enum {
  2491. ItemABSPreHeat_Exit,
  2492. ItemABSPreHeat_set_FanSpeed,
  2493. ItemABSPreHeat_set_nozzle,
  2494. ItemABSPreHeat_set_HPB,
  2495. ItemABSPreHeat_Store_Eprom
  2496. };
  2497. void MainMenu::showABSsettings()
  2498. {
  2499. #ifdef ULTIPANEL
  2500. uint8_t line=0;
  2501. clearIfNecessary();
  2502. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2503. {
  2504. switch(i)
  2505. {
  2506. case ItemABSPreHeat_Exit:
  2507. MENUITEM( lcdprintPGM(MSG_TEMPERATURE_RTN) , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  2508. break;
  2509. case ItemABSPreHeat_set_FanSpeed:
  2510. {
  2511. if(force_lcd_update)
  2512. {
  2513. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  2514. lcd.setCursor(13,line);lcd.print(ftostr3(absPreheatFanSpeed));
  2515. }
  2516. if((activeline!=line) )
  2517. break;
  2518. if(CLICKED)
  2519. {
  2520. linechanging=!linechanging;
  2521. if(linechanging)
  2522. {
  2523. encoderpos=absPreheatFanSpeed;
  2524. }
  2525. else
  2526. {
  2527. encoderpos=activeline*lcdslow;
  2528. beepshort();
  2529. }
  2530. BLOCK;
  2531. }
  2532. if(linechanging)
  2533. {
  2534. if(encoderpos<0) encoderpos=0;
  2535. if(encoderpos>255) encoderpos=255;
  2536. absPreheatFanSpeed=encoderpos;
  2537. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  2538. }
  2539. }break;
  2540. case ItemABSPreHeat_set_nozzle:
  2541. {
  2542. if(force_lcd_update)
  2543. {
  2544. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  2545. lcd.setCursor(13,line);lcd.print(ftostr3(absPreheatHotendTemp));
  2546. }
  2547. if((activeline!=line) )
  2548. break;
  2549. if(CLICKED)
  2550. {
  2551. linechanging=!linechanging;
  2552. if(linechanging)
  2553. {
  2554. encoderpos=absPreheatHotendTemp;
  2555. }
  2556. else
  2557. {
  2558. encoderpos=activeline*lcdslow;
  2559. beepshort();
  2560. }
  2561. BLOCK;
  2562. }
  2563. if(linechanging)
  2564. {
  2565. if(encoderpos<0) encoderpos=0;
  2566. if(encoderpos>260) encoderpos=260;
  2567. absPreheatHotendTemp = encoderpos;
  2568. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  2569. }
  2570. }break;
  2571. case ItemABSPreHeat_set_HPB:
  2572. {
  2573. if(force_lcd_update)
  2574. {
  2575. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  2576. lcd.setCursor(13,line);lcd.print(ftostr3(absPreheatHPBTemp));
  2577. }
  2578. if((activeline!=line) )
  2579. break;
  2580. if(CLICKED)
  2581. {
  2582. linechanging=!linechanging;
  2583. if(linechanging)
  2584. {
  2585. encoderpos=absPreheatHPBTemp;
  2586. }
  2587. else
  2588. {
  2589. encoderpos=activeline*lcdslow;
  2590. beepshort();
  2591. }
  2592. BLOCK;
  2593. }
  2594. if(linechanging)
  2595. {
  2596. if(encoderpos<0) encoderpos=0;
  2597. if(encoderpos>250) encoderpos=150;
  2598. absPreheatHPBTemp = encoderpos;
  2599. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  2600. }
  2601. }break;
  2602. case ItemABSPreHeat_Store_Eprom:
  2603. {
  2604. if(force_lcd_update)
  2605. {
  2606. lcd.setCursor(0,line);lcdprintPGM(MSG_STORE_EPROM);
  2607. }
  2608. if((activeline==line) && CLICKED)
  2609. {
  2610. //enquecommand("M84");
  2611. beepshort();
  2612. BLOCK;
  2613. EEPROM_StoreSettings();
  2614. }
  2615. }break;
  2616. default:
  2617. break;
  2618. }
  2619. line++;
  2620. }
  2621. updateActiveLines(ItemABSPreHeat_Store_Eprom,encoderpos);
  2622. #endif
  2623. }
  2624. //**********************************************************************************************************
  2625. // convert float to string with +123.4 format
  2626. char *ftostr3(const float &x)
  2627. {
  2628. //sprintf(conv,"%5.1f",x);
  2629. int xx=x;
  2630. conv[0]=(xx/100)%10+'0';
  2631. conv[1]=(xx/10)%10+'0';
  2632. conv[2]=(xx)%10+'0';
  2633. conv[3]=0;
  2634. return conv;
  2635. }
  2636. char *itostr2(const uint8_t &x)
  2637. {
  2638. //sprintf(conv,"%5.1f",x);
  2639. int xx=x;
  2640. conv[0]=(xx/10)%10+'0';
  2641. conv[1]=(xx)%10+'0';
  2642. conv[2]=0;
  2643. return conv;
  2644. }
  2645. // convert float to string with +123.4 format
  2646. char *ftostr31(const float &x)
  2647. {
  2648. int xx=x*10;
  2649. conv[0]=(xx>=0)?'+':'-';
  2650. xx=abs(xx);
  2651. conv[1]=(xx/1000)%10+'0';
  2652. conv[2]=(xx/100)%10+'0';
  2653. conv[3]=(xx/10)%10+'0';
  2654. conv[4]='.';
  2655. conv[5]=(xx)%10+'0';
  2656. conv[6]=0;
  2657. return conv;
  2658. }
  2659. char *ftostr32(const float &x)
  2660. {
  2661. int xx=x*100;
  2662. conv[0]=(xx>=0)?'+':'-';
  2663. xx=abs(xx);
  2664. conv[1]=(xx/100)%10+'0';
  2665. conv[2]='.';
  2666. conv[3]=(xx/10)%10+'0';
  2667. conv[4]=(xx)%10+'0';
  2668. conv[6]=0;
  2669. return conv;
  2670. }
  2671. char *itostr31(const int &xx)
  2672. {
  2673. conv[0]=(xx>=0)?'+':'-';
  2674. conv[1]=(xx/1000)%10+'0';
  2675. conv[2]=(xx/100)%10+'0';
  2676. conv[3]=(xx/10)%10+'0';
  2677. conv[4]='.';
  2678. conv[5]=(xx)%10+'0';
  2679. conv[6]=0;
  2680. return conv;
  2681. }
  2682. char *itostr3(const int &xx)
  2683. {
  2684. conv[0]=(xx/100)%10+'0';
  2685. conv[1]=(xx/10)%10+'0';
  2686. conv[2]=(xx)%10+'0';
  2687. conv[3]=0;
  2688. return conv;
  2689. }
  2690. char *itostr4(const int &xx)
  2691. {
  2692. conv[0]=(xx/1000)%10+'0';
  2693. conv[1]=(xx/100)%10+'0';
  2694. conv[2]=(xx/10)%10+'0';
  2695. conv[3]=(xx)%10+'0';
  2696. conv[4]=0;
  2697. return conv;
  2698. }
  2699. // convert float to string with +1234.5 format
  2700. char *ftostr51(const float &x)
  2701. {
  2702. int xx=x*10;
  2703. conv[0]=(xx>=0)?'+':'-';
  2704. xx=abs(xx);
  2705. conv[1]=(xx/10000)%10+'0';
  2706. conv[2]=(xx/1000)%10+'0';
  2707. conv[3]=(xx/100)%10+'0';
  2708. conv[4]=(xx/10)%10+'0';
  2709. conv[5]='.';
  2710. conv[6]=(xx)%10+'0';
  2711. conv[7]=0;
  2712. return conv;
  2713. }
  2714. // convert float to string with +123.45 format
  2715. char *ftostr52(const float &x)
  2716. {
  2717. int xx=x*100;
  2718. conv[0]=(xx>=0)?'+':'-';
  2719. xx=abs(xx);
  2720. conv[1]=(xx/10000)%10+'0';
  2721. conv[2]=(xx/1000)%10+'0';
  2722. conv[3]=(xx/100)%10+'0';
  2723. conv[4]='.';
  2724. conv[5]=(xx/10)%10+'0';
  2725. conv[6]=(xx)%10+'0';
  2726. conv[7]=0;
  2727. return conv;
  2728. }
  2729. #endif //ULTRA_LCD