123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593 |
- #include "ultralcd.h"
-
-
- #ifdef ULTRA_LCD
- extern volatile int feedmultiply;
- extern long position[4];
-
- char messagetext[LCD_WIDTH]="";
-
- #include <LiquidCrystal.h>
- 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
-
- unsigned long previous_millis_lcd=0;
-
-
-
- volatile char buttons=0; //the last checked buttons in a bit array.
- int encoderpos=0;
- short lastenc=0;
- #ifdef NEWPANEL
- long blocking=0;
- #else
- long blocking[8]={0,0,0,0,0,0,0,0};
- #endif
- MainMenu menu;
-
- void lcd_status(const char* message)
- {
- strncpy(messagetext,message,LCD_WIDTH);
- }
-
- void clear()
- {
- //lcd.setCursor(0,0);
- lcd.clear();
- //delay(1);
- // lcd.begin(LCD_WIDTH,LCD_HEIGHT);
- //lcd_init();
- }
- long previous_millis_buttons=0;
-
- void lcd_init()
- {
- //beep();
- byte Degree[8] =
- {
- B01100,
- B10010,
- B10010,
- B01100,
- B00000,
- B00000,
- B00000,
- B00000
- };
- byte Thermometer[8] =
- {
- B00100,
- B01010,
- B01010,
- B01010,
- B01010,
- B10001,
- B10001,
- B01110
- };
- byte uplevel[8]={0x04, 0x0e, 0x1f, 0x04, 0x1c, 0x00, 0x00, 0x00};//thanks joris
- byte refresh[8]={0x00, 0x06, 0x19, 0x18, 0x03, 0x13, 0x0c, 0x00}; //thanks joris
- lcd.begin(LCD_WIDTH, LCD_HEIGHT);
- lcd.createChar(1,Degree);
- lcd.createChar(2,Thermometer);
- lcd.createChar(3,uplevel);
- lcd.createChar(4,refresh);
- LCD_MESSAGE(fillto(LCD_WIDTH,"UltiMarlin ready."));
- }
-
-
- void beep()
- {
- //return;
- #ifdef ULTIPANEL
- pinMode(BEEPER,OUTPUT);
- for(int i=0;i<20;i++){
- WRITE(BEEPER,HIGH);
- delay(5);
- WRITE(BEEPER,LOW);
- delay(5);
- }
- #endif
- }
-
- void beepshort()
- {
- //return;
- #ifdef ULTIPANEL
- pinMode(BEEPER,OUTPUT);
- for(int i=0;i<10;i++){
- WRITE(BEEPER,HIGH);
- delay(3);
- WRITE(BEEPER,LOW);
- delay(3);
- }
- #endif
- }
- void lcd_status()
- {
- #ifdef ULTIPANEL
- static uint8_t oldbuttons=0;
- static long previous_millis_buttons=0;
- static long previous_lcdinit=0;
- // buttons_check(); // Done in temperature interrupt
- //previous_millis_buttons=millis();
-
- if((buttons==oldbuttons) && ((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
- return;
- oldbuttons=buttons;
- #else
-
- if(((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
- return;
- #endif
-
- previous_millis_lcd=millis();
- menu.update();
- }
- #ifdef ULTIPANEL
- void buttons_init()
- {
- #ifdef NEWPANEL
- pinMode(BTN_EN1,INPUT);
- pinMode(BTN_EN2,INPUT);
- pinMode(BTN_ENC,INPUT);
- pinMode(SDCARDDETECT,INPUT);
- WRITE(BTN_EN1,HIGH);
- WRITE(BTN_EN2,HIGH);
- WRITE(BTN_ENC,HIGH);
- WRITE(SDCARDDETECT,HIGH);
- #else
- pinMode(SHIFT_CLK,OUTPUT);
- pinMode(SHIFT_LD,OUTPUT);
- pinMode(SHIFT_EN,OUTPUT);
- pinMode(SHIFT_OUT,INPUT);
- WRITE(SHIFT_OUT,HIGH);
- WRITE(SHIFT_LD,HIGH);
- WRITE(SHIFT_EN,LOW);
- #endif
- }
-
-
- void buttons_check()
- {
- // volatile static bool busy=false;
- // if(busy)
- // return;
- // busy=true;
-
- #ifdef NEWPANEL
- uint8_t newbutton=0;
- if(READ(BTN_EN1)==0) newbutton|=EN_A;
- if(READ(BTN_EN2)==0) newbutton|=EN_B;
- if((blocking<millis()) &&(READ(BTN_ENC)==0))
- newbutton|=EN_C;
- buttons=newbutton;
- #else
- //read it from the shift register
- uint8_t newbutton=0;
- WRITE(SHIFT_LD,LOW);
- WRITE(SHIFT_LD,HIGH);
- unsigned char tmp_buttons=0;
- for(unsigned char i=0;i<8;i++)
- {
- newbutton = newbutton>>1;
- if(READ(SHIFT_OUT))
- newbutton|=(1<<7);
- WRITE(SHIFT_CLK,HIGH);
- WRITE(SHIFT_CLK,LOW);
- }
- buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
- #endif
- char enc=0;
- if(buttons&EN_A)
- enc|=(1<<0);
- if(buttons&EN_B)
- enc|=(1<<1);
- if(enc!=lastenc)
- {
- switch(enc)
- {
- case encrot0:
- if(lastenc==encrot3)
- encoderpos++;
- else if(lastenc==encrot1)
- encoderpos--;
- break;
- case encrot1:
- if(lastenc==encrot0)
- encoderpos++;
- else if(lastenc==encrot2)
- encoderpos--;
- break;
- case encrot2:
- if(lastenc==encrot1)
- encoderpos++;
- else if(lastenc==encrot3)
- encoderpos--;
- break;
- case encrot3:
- if(lastenc==encrot2)
- encoderpos++;
- else if(lastenc==encrot0)
- encoderpos--;
- break;
- default:
- ;
- }
- }
- lastenc=enc;
- // busy=false;
- }
-
- #endif
-
- MainMenu::MainMenu()
- {
- status=Main_Status;
- displayStartingRow=0;
- activeline=0;
- force_lcd_update=true;
- #ifdef ULTIPANEL
- buttons_init();
- #endif
- lcd_init();
- linechanging=false;
- }
-
- extern volatile bool feedmultiplychanged;
-
- void MainMenu::showStatus()
- {
- #if LCD_HEIGHT==4
- static int oldcurrentraw=-1;
- static int oldtargetraw=-1;
- //force_lcd_update=true;
- if(force_lcd_update||feedmultiplychanged) //initial display of content
- {
- feedmultiplychanged=false;
- encoderpos=feedmultiply;
- clear();
- lcd.setCursor(0,0);lcd.print("\002123/567\001 ");
- #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
- lcd.setCursor(10,0);lcd.print("B123/567\001 ");
- #endif
- }
-
-
- if((abs(current_raw[TEMPSENSOR_HOTEND_0]-oldcurrentraw)>3)||force_lcd_update)
- {
- lcd.setCursor(1,0);
- lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND_0])));
- oldcurrentraw=current_raw[TEMPSENSOR_HOTEND_0];
- }
- if((target_raw[TEMPSENSOR_HOTEND_0]!=oldtargetraw)||force_lcd_update)
- {
- lcd.setCursor(5,0);
- lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND_0])));
- oldtargetraw=target_raw[TEMPSENSOR_HOTEND_0];
- }
- #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
- static int oldcurrentbedraw=-1;
- static int oldtargetbedraw=-1;
- if((current_bed_raw!=oldcurrentbedraw)||force_lcd_update)
- {
- lcd.setCursor(1,0);
- lcd.print(ftostr3(analog2temp(current_bed_raw)));
- oldcurrentraw=current_raw[TEMPSENSOR_BED];
- }
- if((target_bed_raw!=oldtargebedtraw)||force_lcd_update)
- {
- lcd.setCursor(5,0);
- lcd.print(ftostr3(analog2temp(target_bed_raw)));
- oldtargetraw=target_bed_raw;
- }
- #endif
- //starttime=2;
- static uint16_t oldtime=0;
- if(starttime!=0)
- {
- lcd.setCursor(0,1);
- uint16_t time=millis()/60000-starttime/60000;
-
- if(starttime!=oldtime)
- {
- lcd.print(itostr2(time/60));lcd.print("h ");lcd.print(itostr2(time%60));lcd.print("m");
- oldtime=time;
- }
- }
- static int oldzpos=0;
- int currentz=current_position[2]*10;
- if((currentz!=oldzpos)||force_lcd_update)
- {
- lcd.setCursor(10,1);
- lcd.print("Z:");lcd.print(itostr31(currentz));
- oldzpos=currentz;
- }
- static int oldfeedmultiply=0;
- int curfeedmultiply=feedmultiply;
- if(encoderpos!=curfeedmultiply||force_lcd_update)
- {
- curfeedmultiply=encoderpos;
- if(curfeedmultiply<10)
- curfeedmultiply=10;
- if(curfeedmultiply>999)
- curfeedmultiply=999;
- feedmultiply=curfeedmultiply;
- encoderpos=curfeedmultiply;
- }
- if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update)
- {
- oldfeedmultiply=curfeedmultiply;
- lcd.setCursor(0,2);
- lcd.print(itostr3(curfeedmultiply));lcd.print("% ");
- }
- if(messagetext[0]!='\0')
- {
- lcd.setCursor(0,LCD_HEIGHT-1);
- lcd.print(fillto(LCD_WIDTH,messagetext));
- messagetext[0]='\0';
- }
- #else //smaller LCDS----------------------------------
- static int oldcurrentraw=-1;
- static int oldtargetraw=-1;
- if(force_lcd_update) //initial display of content
- {
- encoderpos=feedmultiply;
- lcd.setCursor(0,0);lcd.print("\002123/567\001 ");
- #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
- lcd.setCursor(10,0);lcd.print("B123/567\001 ");
- #endif
- }
-
-
- if((abs(current_raw[TEMPSENSOR_HOTEND]-oldcurrentraw)>3)||force_lcd_update)
- {
- lcd.setCursor(1,0);
- lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND])));
- oldcurrentraw=current_raw[TEMPSENSOR_HOTEND];
- }
- if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update)
- {
- lcd.setCursor(5,0);
- lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));
- oldtargetraw=target_raw[TEMPSENSOR_HOTEND];
- }
-
- if(messagetext[0]!='\0')
- {
- lcd.setCursor(0,LCD_HEIGHT-1);
- lcd.print(fillto(LCD_WIDTH,messagetext));
- messagetext[0]='\0';
- }
-
- #endif
- }
-
- enum {ItemP_exit, ItemP_home, ItemP_origin, ItemP_preheat, ItemP_extrude, ItemP_disstep};
-
- void MainMenu::showPrepare()
- {
- uint8_t line=0;
- if(lastlineoffset!=lineoffset)
- {
- force_lcd_update=true;
- clear();
- }
- for(uint8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
- {
- //Serial.println((int)(line-lineoffset));
- switch(i)
- {
- case ItemP_exit:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Prepare");
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK
- status=Main_Menu;
- beepshort();
- }
- }break;
- case ItemP_home:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Auto Home");
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK
- enquecommand("G28 X-105 Y-105 Z0");
- beepshort();
- }
- }break;
- case ItemP_origin:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Set Origin");
-
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK
- enquecommand("G92 X0 Y0 Z0");
- beepshort();
- }
- }break;
- case ItemP_preheat:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Preheat");
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK
- target_raw[TEMPSENSOR_HOTEND_0] = temp2analog(170);
- beepshort();
- }
- }break;
- case ItemP_extrude:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Extrude");
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK
- enquecommand("G92 E0");
- enquecommand("G1 F700 E50");
- beepshort();
- }
- }break;
- case ItemP_disstep:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Disable Steppers");
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK
- enquecommand("M84");
- beepshort();
- }
- }break;
- default:
- break;
- }
- line++;
- }
- lastlineoffset=lineoffset;
- if((encoderpos/lcdslow!=lastencoderpos/lcdslow)||force_lcd_update)
- {
-
- lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
-
- if(encoderpos<0)
- {
- lineoffset--;
- if(lineoffset<0)
- lineoffset=0;
- encoderpos=0;
- force_lcd_update=true;
- }
- if(encoderpos/lcdslow>3)
- {
- lineoffset++;
- encoderpos=3*lcdslow;
- if(lineoffset>(ItemP_disstep+1-LCD_HEIGHT))
- lineoffset=ItemP_disstep+1-LCD_HEIGHT;
- force_lcd_update=true;
- }
- //encoderpos=encoderpos%LCD_HEIGHT;
- lastencoderpos=encoderpos;
- activeline=encoderpos/lcdslow;
- lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
- }
- }
- enum {
- ItemC_exit, ItemC_nozzle,
- ItemC_PID_P,ItemC_PID_I,ItemC_PID_D,ItemC_PID_C,
- ItemC_fan,
- ItemC_acc, ItemC_xyjerk,
- ItemC_vmaxx, ItemC_vmaxy, ItemC_vmaxz, ItemC_vmaxe,
- ItemC_vtravmin,ItemC_vmin,
- ItemC_amaxx, ItemC_amaxy, ItemC_amaxz, ItemC_amaxe,
- ItemC_aret,ItemC_esteps, ItemC_store, ItemC_load,ItemC_failsafe
- };
-
- void MainMenu::showControl()
- {
- uint8_t line=0;
- if((lastlineoffset!=lineoffset)||force_lcd_update)
- {
- force_lcd_update=true;
- clear();
- }
- for(uint8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
- {
- switch(i)
- {
- case ItemC_exit:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Control");
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK
- status=Main_Menu;
- beepshort();
- }
- }break;
- case ItemC_nozzle:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" \002Nozzle:");
- lcd.setCursor(13,line);lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND_0])));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);
- }
- else
- {
- target_raw[TEMPSENSOR_HOTEND_0] = temp2analog(encoderpos);
- encoderpos=activeline*lcdslow;
- beepshort();
- }
- BLOCK;
- }
- if(linechanging)
- {
- if(encoderpos<0) encoderpos=0;
- if(encoderpos>260) encoderpos=260;
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
- }
- }
- }break;
-
- case ItemC_fan:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Fan speed:");
- lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
- }
-
- if((activeline==line) )
- {
- if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=fanpwm;
- }
- else
- {
- fanpwm = constrain(encoderpos,0,255);
- encoderpos=fanpwm;
- analogWrite(FAN_PIN, fanpwm);
-
- beepshort();
- }
- BLOCK;
- }
- if(linechanging)
- {
- if(encoderpos<0) encoderpos=0;
- if(encoderpos>255) encoderpos=255;
- fanpwm=encoderpos;
- analogWrite(FAN_PIN, fanpwm);
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
- }
- }
- }break;
- case ItemC_acc:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Acc:");
- lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcd.print("00");
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)acceleration/100;
- }
- else
- {
- acceleration= encoderpos*100;
- encoderpos=activeline*lcdslow;
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<5) encoderpos=5;
- if(encoderpos>990) encoderpos=990;
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcd.print("00");
- }
- }
- }break;
- case ItemC_xyjerk: //max_xy_jerk
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Vxy-jerk: ");
- lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk/60));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)max_xy_jerk/60;
- }
- else
- {
- max_xy_jerk= encoderpos*60;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<1) encoderpos=1;
- if(encoderpos>990) encoderpos=990;
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
- }
- }
- }break;
- case ItemC_PID_P:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" PID-P: ");
- lcd.setCursor(13,line);lcd.print(itostr4(Kp));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)Kp/5;
- }
- else
- {
- Kp= encoderpos*5;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<1) encoderpos=1;
- if(encoderpos>9990/5) encoderpos=9990/5;
- lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
- }
- }
- }break;
- case ItemC_PID_I:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" PID-I: ");
- lcd.setCursor(13,line);lcd.print(ftostr51(Ki));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)(Ki*10);
- }
- else
- {
- Ki= encoderpos/10.;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<0) encoderpos=0;
- if(encoderpos>9990) encoderpos=9990;
- lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
- }
- }
- }break;
- case ItemC_PID_D:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" PID-D: ");
- lcd.setCursor(13,line);lcd.print(itostr4(Kd));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)Kd/5;
- }
- else
- {
- Kd= encoderpos*5;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<0) encoderpos=0;
- if(encoderpos>9990/5) encoderpos=9990/5;
- lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
- }
- }
- }break;
-
-
-
- case ItemC_PID_C:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" PID-C: ");
- lcd.setCursor(13,line);lcd.print(itostr3(Kc));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)Kc;
- }
- else
- {
- Kc= encoderpos;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<0) encoderpos=0;
- if(encoderpos>990) encoderpos=990;
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
- }
- }
- }break;
- case ItemC_vmaxx:
- case ItemC_vmaxy:
- case ItemC_vmaxz:
- case ItemC_vmaxe:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Vmax ");
- if(i==ItemC_vmaxx)lcd.print("x:");
- if(i==ItemC_vmaxy)lcd.print("y:");
- if(i==ItemC_vmaxz)lcd.print("z:");
- if(i==ItemC_vmaxe)lcd.print("e:");
- lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemC_vmaxx]/60));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)max_feedrate[i-ItemC_vmaxx]/60;
- }
- else
- {
- max_feedrate[i-ItemC_vmaxx]= encoderpos*60;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<1) encoderpos=1;
- if(encoderpos>990) encoderpos=990;
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
- }
- }
- }break;
-
- case ItemC_vmin:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Vmin:");
- lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate/60));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)(minimumfeedrate/60.);
- }
- else
- {
- minimumfeedrate= encoderpos*60;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<0) encoderpos=0;
- if(encoderpos>990) encoderpos=990;
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
- }
- }
- }break;
- case ItemC_vtravmin:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" VTrav min:");
- lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate/60));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)mintravelfeedrate/60;
- }
- else
- {
- mintravelfeedrate= encoderpos*60;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<0) encoderpos=0;
- if(encoderpos>990) encoderpos=990;
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
- }
- }
- }break;
-
- case ItemC_amaxx:
- case ItemC_amaxy:
- case ItemC_amaxz:
- case ItemC_amaxe:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Amax ");
- if(i==ItemC_amaxx)lcd.print("x:");
- if(i==ItemC_amaxy)lcd.print("y:");
- if(i==ItemC_amaxz)lcd.print("z:");
- if(i==ItemC_amaxe)lcd.print("e:");
- lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemC_amaxx]/100));lcd.print("00");
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemC_amaxx]/100;
- }
- else
- {
- max_acceleration_units_per_sq_second[i-ItemC_amaxx]= encoderpos*100;
- encoderpos=activeline*lcdslow;
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<1) encoderpos=1;
- if(encoderpos>990) encoderpos=990;
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcd.print("00");
- }
- }
- }break;
- case ItemC_aret://float retract_acceleration = 7000;
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" A-retract:");
- lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcd.print("00");
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)retract_acceleration/100;
- }
- else
- {
- retract_acceleration= encoderpos*100;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<10) encoderpos=10;
- if(encoderpos>990) encoderpos=990;
- lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcd.print("00");
- }
- }
- }break;
- case ItemC_esteps://axis_steps_per_unit[i] = code_value();
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Esteps/mm:");
- lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
- }
-
- if((activeline==line) )
- {
- if(CLICKED)
- {
- linechanging=!linechanging;
- if(linechanging)
- {
- encoderpos=(int)axis_steps_per_unit[3];
- }
- else
- {
- float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
- position[E_AXIS]=lround(position[E_AXIS]*factor);
- //current_position[3]*=factor;
- axis_steps_per_unit[E_AXIS]= encoderpos;
- encoderpos=activeline*lcdslow;
-
- }
- BLOCK;
- beepshort();
- }
- if(linechanging)
- {
- if(encoderpos<5) encoderpos=5;
- if(encoderpos>9999) encoderpos=9999;
- lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
- }
- }
- }break;
- case ItemC_store:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Store EPROM");
- }
- if((activeline==line) && CLICKED)
- {
- //enquecommand("M84");
- beepshort();
- BLOCK;
- StoreSettings();
- }
- }break;
- case ItemC_load:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Load EPROM");
- }
- if((activeline==line) && CLICKED)
- {
- //enquecommand("M84");
- beepshort();
- BLOCK;
- RetrieveSettings();
- }
- }break;
- case ItemC_failsafe:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" Restore Failsafe");
- }
- if((activeline==line) && CLICKED)
- {
- //enquecommand("M84");
- beepshort();
- BLOCK;
- RetrieveSettings(true);
- }
- }break;
- default:
- break;
- }
- line++;
- }
- lastlineoffset=lineoffset;
-
- if(!linechanging && ((encoderpos/lcdslow!=lastencoderpos/lcdslow)||force_lcd_update))
- {
-
- lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
-
- if(encoderpos<0)
- {
- lineoffset--;
- if(lineoffset<0)
- lineoffset=0;
- encoderpos=0;
- force_lcd_update=true;
- }
- if(encoderpos/lcdslow>3)
- {
- lineoffset++;
- encoderpos=3*lcdslow;
- if(lineoffset>(ItemC_failsafe+1-LCD_HEIGHT))
- lineoffset=ItemC_failsafe+1-LCD_HEIGHT;
- force_lcd_update=true;
- }
- //encoderpos=encoderpos%LCD_HEIGHT;
- lastencoderpos=encoderpos;
- activeline=encoderpos/lcdslow;
- if(activeline>3) activeline=3;
- lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
- }
- }
-
- #include "SdFat.h"
-
- void MainMenu::getfilename(const uint8_t nr)
- {
- #ifdef SDSUPPORT
- dir_t p;
- root.rewind();
- uint8_t cnt=0;
- filename[0]='\0';
- while (root.readDir(p) > 0)
- {
- if (p.name[0] == DIR_NAME_FREE) break;
- if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
- if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
- if(p.name[8]!='G') continue;
- if(p.name[9]=='~') continue;
- if(cnt++!=nr) continue;
- //Serial.println((char*)p.name);
- uint8_t writepos=0;
- for (uint8_t i = 0; i < 11; i++)
- {
- if (p.name[i] == ' ') continue;
- if (i == 8) {
- filename[writepos++]='.';
- }
- filename[writepos++]=p.name[i];
- }
- filename[writepos++]=0;
- }
- #endif
- }
-
- uint8_t getnrfilenames()
- {
- #ifdef SDSUPPORT
- dir_t p;
- root.rewind();
- uint8_t cnt=0;
- while (root.readDir(p) > 0)
- {
- if (p.name[0] == DIR_NAME_FREE) break;
- if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
- if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
- if(p.name[8]!='G') continue;
- if(p.name[9]=='~') continue;
- cnt++;
- }
- return cnt;
- #endif
- }
-
- void MainMenu::showSD()
- {
-
- #ifdef SDSUPPORT
- uint8_t line=0;
-
- if(lastlineoffset!=lineoffset)
- {
- force_lcd_update=true;
- }
- static uint8_t nrfiles=0;
- if(force_lcd_update)
- {
- clear();
- if(sdactive)
- {
- nrfiles=getnrfilenames();
- }
- else
- {
- nrfiles=0;
- lineoffset=0;
- }
- //Serial.print("Nr files:"); Serial.println((int)nrfiles);
- }
-
- for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
- {
- switch(i)
- {
- case 0:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);lcd.print(" File");
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK
- status=Main_Menu;
- beepshort();
- }
- }break;
- case 1:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);
- #ifdef CARDINSERTED
- if(CARDINSERTED)
- #else
- if(true)
- #endif
- {
- lcd.print(" \004Refresh");
- }
- else
- {
- lcd.print(" \004Insert Card");
- }
-
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK;
- beepshort();
- initsd();
- force_lcd_update=true;
- nrfiles=getnrfilenames();
- }
- }break;
- default:
- {
- if(i-2<nrfiles)
- {
- if(force_lcd_update)
- {
- getfilename(i-2);
- //Serial.print("Filenr:");Serial.println(i-2);
- lcd.setCursor(0,line);lcd.print(" ");lcd.print(filename);
- }
- if((activeline==line) && CLICKED)
- {
- BLOCK
- getfilename(i-2);
- char cmd[30];
- for(int i=0;i<strlen(filename);i++)
- filename[i]=tolower(filename[i]);
- sprintf(cmd,"M23 %s",filename);
- //sprintf(cmd,"M115");
- enquecommand(cmd);
- enquecommand("M24");
- beep();
- status=Main_Status;
- lcd_status(filename);
- }
- }
-
- }
- break;
- }
- line++;
- }
- lastlineoffset=lineoffset;
- if((encoderpos!=lastencoderpos)||force_lcd_update)
- {
-
- lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
-
- if(encoderpos<0)
- {
- lineoffset--;
- if(lineoffset<0)
- lineoffset=0;
- encoderpos=0;
- force_lcd_update=true;
- }
- if(encoderpos/lcdslow>3)
- {
- lineoffset++;
- encoderpos=3*lcdslow;
- if(lineoffset>(1+nrfiles+1-LCD_HEIGHT))
- lineoffset=1+nrfiles+1-LCD_HEIGHT;
- force_lcd_update=true;
-
- }
- lastencoderpos=encoderpos;
- activeline=encoderpos;
- if(activeline>3)
- {
- activeline=3;
- }
- if(activeline<0)
- {
- activeline=0;
- }
- if(activeline>1+nrfiles) activeline=1+nrfiles;
- if(lineoffset>1+nrfiles) lineoffset=1+nrfiles;
- lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
-
- }
- #endif
- }
-
- enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file };
- void MainMenu::showMainMenu()
- {
- //if(int(encoderpos/lcdslow)!=int(lastencoderpos/lcdslow))
- // force_lcd_update=true;
- #ifndef ULTIPANEL
- force_lcd_update=false;
- #endif
- //Serial.println((int)activeline);
- if(force_lcd_update)
- clear();
- for(short line=0;line<LCD_HEIGHT;line++)
- {
- switch(line)
- {
- case ItemM_watch:
- {
- if(force_lcd_update) {lcd.setCursor(0,line);lcd.print(" Watch \x7E");}
- if((activeline==line)&&CLICKED)
- {
- BLOCK;
- beepshort();
- status=Main_Status;
- }
- } break;
- case ItemM_prepare:
- {
- if(force_lcd_update) {lcd.setCursor(0,line);lcd.print(" Prepare \x7E");}
- if((activeline==line)&&CLICKED)
- {
- BLOCK;
- status=Main_Prepare;
- beepshort();
- }
- } break;
-
- case ItemM_control:
- {
- if(force_lcd_update) {lcd.setCursor(0,line);lcd.print(" Control \x7E");}
- if((activeline==line)&&CLICKED)
- {
- BLOCK;
- status=Main_Control;
- beepshort();
- }
- }break;
- #ifdef SDSUPPORT
- case ItemM_file:
- {
- if(force_lcd_update)
- {
- lcd.setCursor(0,line);
- #ifdef CARDINSERTED
- if(CARDINSERTED)
- #else
- if(true)
- #endif
- {
- if(sdmode)
- lcd.print(" Stop Print \x7E");
- else
- lcd.print(" Card Menu \x7E");
- }
- else
- {
- lcd.print(" No Card");
- }
- }
- #ifdef CARDINSERTED
- if(CARDINSERTED)
- #endif
- if((activeline==line)&&CLICKED)
- {
- sdmode = false;
- BLOCK;
- status=Main_SD;
- beepshort();
- }
- }break;
- #endif
- default:
- Serial.println('NEVER say never');
- break;
- }
- }
- if(activeline<0) activeline=0;
- if(activeline>=LCD_HEIGHT) activeline=LCD_HEIGHT-1;
- if((encoderpos!=lastencoderpos)||force_lcd_update)
- {
- lcd.setCursor(0,activeline);lcd.print(activeline?' ':' ');
- if(encoderpos<0) encoderpos=0;
- if(encoderpos>3*lcdslow) encoderpos=3*lcdslow;
- activeline=abs(encoderpos/lcdslow)%LCD_HEIGHT;
- if(activeline<0) activeline=0;
- if(activeline>=LCD_HEIGHT) activeline=LCD_HEIGHT-1;
- lastencoderpos=encoderpos;
- lcd.setCursor(0,activeline);lcd.print(activeline?'>':'\003');
- }
-
-
-
- }
-
- void MainMenu::update()
- {
- static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
- static long timeoutToStatus=0;
- static bool oldcardstatus=false;
- #ifdef CARDINSERTED
- if((CARDINSERTED != oldcardstatus))
- {
- force_lcd_update=true;
- oldcardstatus=CARDINSERTED;
- //Serial.println("SD CHANGE");
- if(CARDINSERTED)
- {
- initsd();
- lcd_status("Card inserted");
- }
- else
- {
- sdactive=false;
- lcd_status("Card removed");
-
- }
- }
- #endif
-
- if(status!=oldstatus)
- {
- //Serial.println(status);
- //clear();
- force_lcd_update=true;
- encoderpos=0;
- lineoffset=0;
-
- oldstatus=status;
- }
- if( (encoderpos!=lastencoderpos) || CLICKED)
- timeoutToStatus=millis()+STATUSTIMEOUT;
-
- switch(status)
- {
- case Main_Status:
- {
- showStatus();
- if(CLICKED)
- {
- linechanging=false;
- BLOCK
- status=Main_Menu;
- timeoutToStatus=millis()+STATUSTIMEOUT;
- }
- }break;
- case Main_Menu:
- {
- showMainMenu();
- linechanging=false;
- }break;
- case Main_Prepare:
- {
- showPrepare();
- }break;
- case Main_Control:
- {
- showControl();
- }break;
- case Main_SD:
- {
- showSD();
- }break;
- }
-
- if(timeoutToStatus<millis())
- status=Main_Status;
- force_lcd_update=false;
- lastencoderpos=encoderpos;
- }
-
-
-
-
- //return for string conversion routines
- char conv[8];
-
- /// convert float to string with +123.4 format
- char *ftostr3(const float &x)
- {
- //sprintf(conv,"%5.1f",x);
- int xx=x;
- conv[0]=(xx/100)%10+'0';
- conv[1]=(xx/10)%10+'0';
- conv[2]=(xx)%10+'0';
- conv[3]=0;
- return conv;
- }
- char *itostr2(const uint8_t &x)
- {
- //sprintf(conv,"%5.1f",x);
- int xx=x;
- conv[0]=(xx/10)%10+'0';
- conv[1]=(xx)%10+'0';
- conv[2]=0;
- return conv;
- }
- /// convert float to string with +123.4 format
- char *ftostr31(const float &x)
- {
- //sprintf(conv,"%5.1f",x);
- int xx=x*10;
- conv[0]=(xx>=0)?'+':'-';
- xx=abs(xx);
- conv[1]=(xx/1000)%10+'0';
- conv[2]=(xx/100)%10+'0';
- conv[3]=(xx/10)%10+'0';
- conv[4]='.';
- conv[5]=(xx)%10+'0';
- conv[6]=0;
- return conv;
- }
-
- char *itostr31(const int &xx)
- {
- //sprintf(conv,"%5.1f",x);
- conv[0]=(xx>=0)?'+':'-';
- conv[1]=(xx/1000)%10+'0';
- conv[2]=(xx/100)%10+'0';
- conv[3]=(xx/10)%10+'0';
- conv[4]='.';
- conv[5]=(xx)%10+'0';
- conv[6]=0;
- return conv;
- }
- char *itostr3(const int &xx)
- {
- conv[0]=(xx/100)%10+'0';
- conv[1]=(xx/10)%10+'0';
- conv[2]=(xx)%10+'0';
- conv[3]=0;
- return conv;
- }
-
- char *itostr4(const int &xx)
- {
- conv[0]=(xx/1000)%10+'0';
- conv[1]=(xx/100)%10+'0';
- conv[2]=(xx/10)%10+'0';
- conv[3]=(xx)%10+'0';
- conv[4]=0;
- return conv;
- }
-
- /// convert float to string with +1234.5 format
- char *ftostr51(const float &x)
- {
- int xx=x*10;
- conv[0]=(xx>=0)?'+':'-';
- xx=abs(xx);
- conv[1]=(xx/10000)%10+'0';
- conv[2]=(xx/1000)%10+'0';
- conv[3]=(xx/100)%10+'0';
- conv[4]=(xx/10)%10+'0';
- conv[5]='.';
- conv[6]=(xx)%10+'0';
- conv[7]=0;
- return conv;
- }
-
- char *fillto(int8_t n,char *c)
- {
- static char ret[25];
- bool endfound=false;
- for(int8_t i=0;i<n;i++)
- {
- ret[i]=c[i];
- if(c[i]==0)
- {
- endfound=true;
- }
- if(endfound)
- {
- ret[i]=' ';
- }
- }
- ret[n]=0;
- return ret;
-
- }
-
- #else
- inline void lcd_status() {};
- #endif
-
|