Esempio n. 1
0
void CardReader::removeFile(char* name) {
  if (!cardOK) return;

  file.close();
  sdprinting = false;

  SdFile myDir;
  curDir = &root;
  char *fname = name;

  char *dirname_start, *dirname_end;
  if (name[0] == '/') {
    dirname_start = strchr(name, '/') + 1;
    while (dirname_start > 0) {
      dirname_end = strchr(dirname_start, '/');
      //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start - name));
      //SERIAL_ECHO("end  :");SERIAL_ECHOLN((int)(dirname_end - name));
      if (dirname_end > 0 && dirname_end > dirname_start) {
        char subdirname[FILENAME_LENGTH];
        strncpy(subdirname, dirname_start, dirname_end - dirname_start);
        subdirname[dirname_end - dirname_start] = 0;
        SERIAL_ECHOLN(subdirname);
        if (!myDir.open(curDir, subdirname, O_READ)) {
          SERIAL_PROTOCOLPGM("open failed, File: ");
          SERIAL_PROTOCOL(subdirname);
          SERIAL_PROTOCOLCHAR('.');
          return;
        }
        else {
          //SERIAL_ECHOLN("dive ok");
        }

        curDir = &myDir;
        dirname_start = dirname_end + 1;
      }
      else { // the remainder after all /fsa/fdsa/ is the filename
        fname = dirname_start;
        //SERIAL_ECHOLN("remainder");
        //SERIAL_ECHOLN(fname);
        break;
      }
    }
  }
  else { // relative path
    curDir = &workDir;
  }

  if (file.remove(curDir, fname)) {
    SERIAL_PROTOCOLPGM("File deleted:");
    SERIAL_PROTOCOLLN(fname);
    sdpos = 0;
  }
  else {
    SERIAL_PROTOCOLPGM("Deletion failed, File: ");
    SERIAL_PROTOCOL(fname);
    SERIAL_PROTOCOLCHAR('.');
  }
}
Esempio n. 2
0
void MTWLEDUpdate(patterncode pattern, unsigned long timer, int control) // send pattern frame via I2C
{
  byte sout[]={250,pattern.part[0],constrain(pattern.part[1],0,127),constrain(pattern.part[2],0,127),constrain(pattern.part[3],0,127)}; // build frame
  
  if(control==2) { MTWLEDEndstop(true); return; }         // force endstop status display on C2
  if(control==254) { MTWLED_feedback=!MTWLED_feedback; return; }
  if(control==252) { MTWLED_mode ? MTWLED_mode=0 : MTWLED_mode=1; return; }
  if(control>=0) MTWLED_control=control;                  // handle exceptions/collisions/control
  if(pattern.part[0] < 1) return;
  if(pattern.value != MTWLED_lastpattern.value)           // don't sent sequential identical patterns
  {    
    Wire.beginTransmission(21);
     Wire.write(sout,5);                                  // send the 5 byte frame
    Wire.endTransmission();
    MTWLED_lastpattern=pattern;                           // update states
    if(timer) MTWLED_timer=millis()+(timer*1000);
  if(MTWLED_feedback)
    {
    SERIAL_PROTOCOL("LED P:");                           // print feedback to serial
    SERIAL_PROTOCOL((int)pattern.part[0]);
    SERIAL_PROTOCOL(" R:");
    SERIAL_PROTOCOL((int)pattern.part[1]);
    SERIAL_PROTOCOL(" E:");
    SERIAL_PROTOCOL((int)pattern.part[2]);
    SERIAL_PROTOCOL(" B:");
    SERIAL_PROTOCOL((int)pattern.part[3]);
    SERIAL_PROTOCOL(" C:");
    SERIAL_PROTOCOLLN((int)MTWLED_control);
//    SERIAL_PROTOCOL("MTWLED ");
//    SERIAL_PROTOCOLLN((uint32_t)pattern.value);
    }
  }
}
Esempio n. 3
0
void vector_3::debug(char* title)
{
	SERIAL_PROTOCOL(title);
	SERIAL_PROTOCOLPGM(" x: ");
	SERIAL_PROTOCOL(x);
	SERIAL_PROTOCOLPGM(" y: ");
	SERIAL_PROTOCOL(y);
	SERIAL_PROTOCOLPGM(" z: ");
	SERIAL_PROTOCOL(z);
	SERIAL_PROTOCOLPGM("\n");
}
Esempio n. 4
0
void checkHitEndstops()
{
 if( endstop_x_hit || endstop_y_hit || endstop_z_hit || endstop_j_hit) {
   SERIAL_ECHO_START;
   snprintf(json_str,JSONSIZE,"{%s:[",MSG_ENDSTOPS_HIT);
   SERIAL_PROTOCOL(json_str);
   comma = false;
   if(endstop_x_hit) {
     SERIAL_PROTOCOLPGM("\"x\"");
     LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "X");
     comma = true;
   }
   if(endstop_y_hit) {
     if (comma) SERIAL_PROTOCOLPGM(",");
     SERIAL_PROTOCOLPGM("\"y\"");
     LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Y");
     comma = true;
   }
   if(endstop_z_hit) {
     if (comma) SERIAL_PROTOCOLPGM(",");
     SERIAL_PROTOCOLPGM("\"z\"");
     LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Z");
     comma = true;
   }
   if(endstop_j_hit) {
     if (comma) SERIAL_PROTOCOLPGM(",");
     SERIAL_PROTOCOLPGM("\"j\"");
     LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "J");
   }
   SERIAL_PROTOCOL("]}");
   SERIAL_MSG_END;
   endstop_x_hit=false;
   endstop_y_hit=false;
   endstop_z_hit=false;
   endstop_j_hit=false;
#ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
   if (abort_on_endstop_hit)
   {
     card.sdprinting = false;
     card.closefile();
     quickStop();
     setTargetHotend0(0);
     setTargetHotend1(0);
     setTargetHotend2(0);
   }
#endif
 }
}
Esempio n. 5
0
void matrix_3x3::debug(char* title)
{
	SERIAL_PROTOCOL(title);
	SERIAL_PROTOCOL("\n");
	int count = 0;
	for(int i=0; i<3; i++)
	{
		for(int j=0; j<3; j++)
		{
			SERIAL_PROTOCOL(matrix[count]);
			SERIAL_PROTOCOLPGM(" ");
		        count++;
		}

		SERIAL_PROTOCOLPGM("\n");
	}
}
Esempio n. 6
0
void CardReader::getStatus() {
  if (cardOK) {
    SERIAL_PROTOCOLPGM(MSG_SD_PRINTING_BYTE);
    SERIAL_PROTOCOL(sdpos);
    SERIAL_PROTOCOLCHAR('/');
    SERIAL_PROTOCOLLN(filesize);
  } else
    SERIAL_PROTOCOLLNPGM(MSG_SD_NOT_PRINTING);
}
Esempio n. 7
0
 void report_xyze(const float pos[XYZE], const uint8_t n = 4, const uint8_t precision = 3) {
   char str[12];
   for (uint8_t i = 0; i < n; i++) {
     SERIAL_CHAR(' ');
     SERIAL_CHAR(axis_codes[i]);
     SERIAL_CHAR(':');
     SERIAL_PROTOCOL(dtostrf(pos[i], 8, precision, str));
   }
   SERIAL_EOL();
 }
Esempio n. 8
0
void vector_3::debug(const char title[]) {
	SERIAL_PROTOCOL(title);
	SERIAL_PROTOCOLPGM(" x: ");
	SERIAL_PROTOCOL_F(x, 6);
	SERIAL_PROTOCOLPGM(" y: ");
	SERIAL_PROTOCOL_F(y, 6);
	SERIAL_PROTOCOLPGM(" z: ");
	SERIAL_PROTOCOL_F(z, 6);
	SERIAL_EOL;
}
Esempio n. 9
0
  /**
   * Get a long pretty path based on a DOS 8.3 path
   */
  void CardReader::printLongPath(char *path) {
    lsAction = LS_GetFilename;

    int i, pathLen = strlen(path);

    // SERIAL_ECHOPGM("Full Path: "); SERIAL_ECHOLN(path);

    // Zero out slashes to make segments
    for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';

    SdFile diveDir = root; // start from the root for segment 1
    for (i = 0; i < pathLen;) {

      if (path[i] == '\0') i++; // move past a single nul

      char *segment = &path[i]; // The segment after most slashes

      // If a segment is empty (extra-slash) then exit
      if (!*segment) break;

      // Go to the next segment
      while (path[++i]) { }

      // SERIAL_ECHOPGM("Looking for segment: "); SERIAL_ECHOLN(segment);

      // Find the item, setting the long filename
      diveDir.rewind();
      lsDive("", diveDir, segment);

      // Print /LongNamePart to serial output
      SERIAL_PROTOCOLCHAR('/');
      SERIAL_PROTOCOL(longFilename[0] ? longFilename : "???");

      // If the filename was printed then that's it
      if (!filenameIsDir) break;

      // SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment);

      // Open the sub-item as the new dive parent
      SdFile dir;
      if (!dir.open(diveDir, segment, O_READ)) {
        SERIAL_EOL;
        SERIAL_ECHO_START;
        SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
        SERIAL_ECHO(segment);
        break;
      }

      diveDir.close();
      diveDir = dir;

    } // while i<pathLen

    SERIAL_EOL;
  }
Esempio n. 10
0
/* ??? Check se serve */
void MemReader::getStatus()
{
  if(isprinting){
    SERIAL_PROTOCOLPGM(MSG_SD_PRINTING_BYTE);
    SERIAL_PROTOCOL(pos);
    SERIAL_PROTOCOLPGM("/");
    SERIAL_PROTOCOLLN(ScriptLength[program]);
  }
  else{
    SERIAL_PROTOCOLLNPGM(MSG_SD_NOT_PRINTING);
  }
}
Esempio n. 11
0
void CardReader::getStatus()
{
  if(cardOK){
    SERIAL_PROTOCOLPGM(MSG_SD_PRINTING_BYTE);
    SERIAL_PROTOCOL(sdpos);
    SERIAL_PROTOCOLPGM("/");
    SERIAL_PROTOCOLLN(filesize);
  }
  else{
    SERIAL_PROTOCOLLNPGM(MSG_SD_NOT_PRINTING);
  }
  if (card.errorCode())
  {
    SERIAL_PROTOCOLPGM("Card error:");
    SERIAL_PROTOCOLLN(card.errorCode());
  }
}
Esempio n. 12
0
//===========================================================================
void Hysteresis::ReportToSerial()
{
  SERIAL_PROTOCOLPGM("H=X");
  SERIAL_PROTOCOL(m_hysteresis_mm[X_AXIS]);
  SERIAL_PROTOCOLPGM(" Y");
  SERIAL_PROTOCOL(m_hysteresis_mm[Y_AXIS]);
  SERIAL_PROTOCOLPGM(" Z");
  SERIAL_PROTOCOL(m_hysteresis_mm[Z_AXIS]);
  SERIAL_PROTOCOLPGM(" E");      
  SERIAL_PROTOCOL(m_hysteresis_mm[E_AXIS]);
  SERIAL_PROTOCOLPGM(" SHIFTS:x=");      
  SERIAL_PROTOCOL(axis_shift[X_AXIS]);
  SERIAL_PROTOCOLPGM(" y=");      
  SERIAL_PROTOCOL(axis_shift[Y_AXIS]);
  SERIAL_PROTOCOLPGM(" z=");      
  SERIAL_PROTOCOL(axis_shift[Z_AXIS]);
  SERIAL_PROTOCOLPGM(" e=");      
  SERIAL_PROTOCOL(axis_shift[E_AXIS]);
  
  SERIAL_PROTOCOLLN("");
}
Esempio n. 13
0
void  CardReader::lsDive(const char *prepend,SdFile parent)
{
    dir_t p;
    uint8_t cnt=0;

    while (parent.readDir(p, longFilename) > 0)
    {
        if( DIR_IS_SUBDIR(&p) && lsAction!=LS_Count && lsAction!=LS_GetFilename) // hence LS_SerialPrint
        {

            char path[13*2];
            char lfilename[13];
            createFilename(lfilename,p);

            path[0]=0;
            if(strlen(prepend)==0) //avoid leading / if already in prepend
            {
                strcat(path,"/");
            }
            strcat(path,prepend);
            strcat(path,lfilename);
            strcat(path,"/");

            //Serial.print(path);

            SdFile dir;
            if(!dir.open(parent,lfilename, O_READ))
            {
                if(lsAction==LS_SerialPrint)
                {
                    SERIAL_ECHO_START;
                    SERIAL_ECHOLN(MSG_SD_CANT_OPEN_SUBDIR);
                    SERIAL_ECHOLN(lfilename);
                }
            }
            lsDive(path,dir);
            //close done automatically by destructor of SdFile


        }
        else
        {
            if (p.name[0] == DIR_NAME_FREE) break;
            if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
            if ( p.name[0] == '.')
            {
                if ( p.name[1] != '.')
                    continue;
            }

            if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
            filenameIsDir=DIR_IS_SUBDIR(&p);


            if(!filenameIsDir)
            {
                if(p.name[8]!='G') continue;
                if(p.name[9]=='~') continue;
            }
            //if(cnt++!=nr) continue;
            createFilename(filename,p);
            if(lsAction==LS_SerialPrint)
            {
                SERIAL_PROTOCOL(prepend);
                SERIAL_PROTOCOLLN(filename);
            }
            else if(lsAction==LS_Count)
            {
                nrFiles++;
            }
            else if(lsAction==LS_GetFilename)
            {
                if(cnt==nrFiles)
                    return;
                cnt++;

            }
        }
    }
}
Esempio n. 14
0
void CardReader::openFile(char* name,bool read)
{
    if(!cardOK)
        return;
    file.close();
    sdprinting = false;


    SdFile myDir;
    curDir=&root;
    char *fname=name;

    char *dirname_start,*dirname_end;
    if(name[0]=='/')
    {
        dirname_start=strchr(name,'/')+1;
        while(dirname_start>0)
        {
            dirname_end=strchr(dirname_start,'/');
            //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start-name));
            //SERIAL_ECHO("end  :");SERIAL_ECHOLN((int)(dirname_end-name));
            if(dirname_end>0 && dirname_end>dirname_start)
            {
                char subdirname[13];
                strncpy(subdirname, dirname_start, dirname_end-dirname_start);
                subdirname[dirname_end-dirname_start]=0;
                SERIAL_ECHOLN(subdirname);
                if(!myDir.open(curDir,subdirname,O_READ))
                {
                    SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
                    SERIAL_PROTOCOL(subdirname);
                    SERIAL_PROTOCOLLNPGM(".");
                    return;
                }
                else
                {
                    //SERIAL_ECHOLN("dive ok");
                }

                curDir=&myDir;
                dirname_start=dirname_end+1;
            }
            else // the reminder after all /fsa/fdsa/ is the filename
            {
                fname=dirname_start;
                //SERIAL_ECHOLN("remaider");
                //SERIAL_ECHOLN(fname);
                break;
            }

        }
    }
    else //relative path
    {
        curDir=&workDir;
    }
    if(read)
    {
        if (file.open(curDir, fname, O_READ))
        {
            filesize = file.fileSize();
            SERIAL_PROTOCOLPGM(MSG_SD_FILE_OPENED);
            SERIAL_PROTOCOL(fname);
            SERIAL_PROTOCOLPGM(MSG_SD_SIZE);
            SERIAL_PROTOCOLLN(filesize);
            sdpos = 0;

            SERIAL_PROTOCOLLNPGM(MSG_SD_FILE_SELECTED);
            LCD_MESSAGE(fname);
        }
        else
        {
            SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
            SERIAL_PROTOCOL(fname);
            SERIAL_PROTOCOLLNPGM(".");
        }
    }
    else
    {   //write
        if (!file.open(curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
        {
            SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
            SERIAL_PROTOCOL(fname);
            SERIAL_PROTOCOLLNPGM(".");
        }
        else
        {
            saving = true;
            SERIAL_PROTOCOLPGM(MSG_SD_WRITE_TO_FILE);
            SERIAL_PROTOCOLLN(name);
            LCD_MESSAGE(fname);
        }
    }

}
Esempio n. 15
0
void Config_PrintSettings()
{  // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown

    //SERIAL_ECHO_START;
    SERIAL_ECHOLNPGM("FABtotum TOTUMDUINO");
    SERIAL_ECHOPAIR(" Batch Number: ", (unsigned long)fab_batch_number);
    SERIAL_ECHOLN("");

    SERIAL_ECHOLNPGM("FABlin");
    SERIAL_ECHOLNPGM(" Version: " STRING_BUILD_VERSION);
    SERIAL_ECHOPAIR(" Baudrate: ", (unsigned long)BAUDRATE);
    SERIAL_ECHOLN("");

    SERIAL_ECHOLNPGM("Steps per unit:");
    //SERIAL_ECHO_START;
    SERIAL_ECHOPAIR("  M92 X",axis_steps_per_unit[0]);
    SERIAL_ECHOPAIR_P(PMSG_WS_Y,axis_steps_per_unit[1]);
    SERIAL_ECHOPAIR_P(PMSG_WS_Z,axis_steps_per_unit[2]);
    SERIAL_ECHOPAIR_P(PMSG_WS_E,axis_steps_per_unit[3]);
    SERIAL_ECHOLN("");

    //SERIAL_ECHO_START;
    SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
    //SERIAL_ECHO_START;
    SERIAL_ECHOPAIR("  M203 X",max_feedrate[0]);
    SERIAL_ECHOPAIR_P(PMSG_WS_Y,max_feedrate[1] );
    SERIAL_ECHOPAIR_P(PMSG_WS_Z, max_feedrate[2] );
    SERIAL_ECHOPAIR_P(PMSG_WS_E, max_feedrate[3]);
    SERIAL_ECHOLN("");

    //SERIAL_ECHO_START;
    SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
    //SERIAL_ECHO_START;
    SERIAL_ECHOPAIR("  M201 X" ,max_acceleration_units_per_sq_second[0] );
    SERIAL_ECHOPAIR_P(PMSG_WS_Y , max_acceleration_units_per_sq_second[1] );
    SERIAL_ECHOPAIR_P(PMSG_WS_Z ,max_acceleration_units_per_sq_second[2] );
    SERIAL_ECHOPAIR_P(PMSG_WS_E ,max_acceleration_units_per_sq_second[3]);
    SERIAL_ECHOLN("");
    //SERIAL_ECHO_START;
    SERIAL_ECHOLNPGM("Acceleration: S=acceleration, T=retract acceleration");
    //SERIAL_ECHO_START;
    SERIAL_ECHOPAIR("  M204 S",acceleration );
    SERIAL_ECHOPAIR_P(PMSG_WS_T, retract_acceleration);
    SERIAL_ECHOLN("");

    //SERIAL_ECHO_START;
    SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s),  Z=maximum Z jerk (mm/s),  E=maximum E jerk (mm/s)");
    //SERIAL_ECHO_START;
    SERIAL_ECHOPAIR("  M205 S",minimumfeedrate );
    SERIAL_ECHOPAIR_P(PMSG_WS_T, mintravelfeedrate );
    SERIAL_ECHOPAIR(" B" ,minsegmenttime );
    SERIAL_ECHOPAIR_P(PMSG_WS_X, max_xy_jerk );
    SERIAL_ECHOPAIR_P(PMSG_WS_Z, max_z_jerk);
    SERIAL_ECHOPAIR_P(PMSG_WS_E, max_e_jerk);
    SERIAL_ECHOLN("");

    //SERIAL_ECHO_START;
    SERIAL_ECHOLNPGM("Home offset (mm):");
    //SERIAL_ECHO_START;
    SERIAL_ECHOPAIR("  M206 X",add_homeing[0] );
    SERIAL_ECHOPAIR_P(PMSG_WS_Y, add_homeing[1] );
    SERIAL_ECHOPAIR_P(PMSG_WS_Z, add_homeing[2] );
    SERIAL_ECHOLN("");
#ifdef DELTA
    //SERIAL_ECHO_START;
    SERIAL_ECHOLNPGM("Endstop adjustement (mm):");
    //SERIAL_ECHO_START;
    SERIAL_ECHOPAIR("  M666 X",endstop_adj[0] );
    SERIAL_ECHOPAIR_P(PMSG_WS_Y, endstop_adj[1] );
    SERIAL_ECHOPAIR_P(PMSG_WS_Z, endstop_adj[2] );
	SERIAL_ECHOLN("");
	//SERIAL_ECHO_START;
	SERIAL_ECHOLNPGM("Delta settings: L=delta_diagonal_rod, R=delta_radius, S=delta_segments_per_second");
	//SERIAL_ECHO_START;
	SERIAL_ECHOPAIR("  M665 L",delta_diagonal_rod );
	SERIAL_ECHOPAIR(" R" ,delta_radius );
	SERIAL_ECHOPAIR(" S" ,delta_segments_per_second );
	SERIAL_ECHOLN("");
#endif

#ifdef PIDTEMP
    //SERIAL_ECHO_START;
    SERIAL_ECHOLNPGM("PID settings:");
    //SERIAL_ECHO_START;
    SERIAL_ECHOPAIR("   M301 P",Kp);
    SERIAL_ECHOPAIR(" I" ,unscalePID_i(Ki));
    SERIAL_ECHOPAIR(" D" ,unscalePID_d(Kd));
    SERIAL_ECHOLN("");
#endif

    //SERIAL_ECHO_START;
    SERIAL_ECHOPGM("Servo Endstop settings:");
    SERIAL_PROTOCOL(" R: ");
    SERIAL_PROTOCOL(servo_endstop_angles[5]);
    SERIAL_PROTOCOL(" E: ");
    SERIAL_PROTOCOL(servo_endstop_angles[4]);
    SERIAL_PROTOCOLLN("");

    //SERIAL_ECHO_START;
    SERIAL_ECHOPGM("Z Probe Length: ");
    SERIAL_PROTOCOL_F(-zprobe_zoffset,2);
    SERIAL_PROTOCOLLN("");

    SERIAL_ECHOLNPGM("Installed head ID:");
    SERIAL_ECHOPAIR(" M793 S", (unsigned long)installed_head_id);
    SERIAL_ECHOLN("");
}
Esempio n. 16
0
void CardReader::openFile(char* name, bool read, bool replace_current/*=true*/) {
  if (!cardOK) return;
  if (file.isOpen()) { //replacing current file by new file, or subfile call
    if (!replace_current) {
     if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) {
       SERIAL_ERROR_START;
       SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:");
       SERIAL_ERRORLN(SD_PROCEDURE_DEPTH);
       kill();
       return;
     }

     SERIAL_ECHO_START;
     SERIAL_ECHOPGM("SUBROUTINE CALL target:\"");
     SERIAL_ECHO(name);
     SERIAL_ECHOPGM("\" parent:\"");

     //store current filename and position
     getAbsFilename(filenames[file_subcall_ctr]);

     SERIAL_ECHO(filenames[file_subcall_ctr]);
     SERIAL_ECHOPGM("\" pos");
     SERIAL_ECHOLN(sdpos);
     filespos[file_subcall_ctr] = sdpos;
     file_subcall_ctr++;
    }
    else {
     SERIAL_ECHO_START;
     SERIAL_ECHOPGM("Now doing file: ");
     SERIAL_ECHOLN(name);
    }
    file.close();
  }
  else { //opening fresh file
    file_subcall_ctr = 0; //resetting procedure depth in case user cancels print while in procedure
    SERIAL_ECHO_START;
    SERIAL_ECHOPGM("Now fresh file: ");
    SERIAL_ECHOLN(name);
  }
  sdprinting = false;

  SdFile myDir;
  curDir = &root;
  char *fname = name;

  char *dirname_start, *dirname_end;
  if (name[0] == '/') {
    dirname_start = &name[1];
    while(dirname_start > 0) {
      dirname_end = strchr(dirname_start, '/');
      //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start - name));
      //SERIAL_ECHO("end  :");SERIAL_ECHOLN((int)(dirname_end - name));
      if (dirname_end > 0 && dirname_end > dirname_start) {
        char subdirname[FILENAME_LENGTH];
        strncpy(subdirname, dirname_start, dirname_end - dirname_start);
        subdirname[dirname_end - dirname_start] = 0;
        SERIAL_ECHOLN(subdirname);
        if (!myDir.open(curDir, subdirname, O_READ)) {
          SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
          SERIAL_PROTOCOL(subdirname);
          SERIAL_PROTOCOLCHAR('.');
          return;
        }
        else {
          //SERIAL_ECHOLN("dive ok");
        }

        curDir = &myDir;
        dirname_start = dirname_end + 1;
      }
      else { // the remainder after all /fsa/fdsa/ is the filename
        fname = dirname_start;
        //SERIAL_ECHOLN("remainder");
        //SERIAL_ECHOLN(fname);
        break;
      }
    }
  }
  else { //relative path
    curDir = &workDir;
  }

  if (read) {
    if (file.open(curDir, fname, O_READ)) {
      filesize = file.fileSize();
      SERIAL_PROTOCOLPGM(MSG_SD_FILE_OPENED);
      SERIAL_PROTOCOL(fname);
      SERIAL_PROTOCOLPGM(MSG_SD_SIZE);
      SERIAL_PROTOCOLLN(filesize);
      sdpos = 0;

      SERIAL_PROTOCOLLNPGM(MSG_SD_FILE_SELECTED);
      getfilename(0, fname);
      lcd_setstatus(longFilename[0] ? longFilename : fname);
    }
    else {
      SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
      SERIAL_PROTOCOL(fname);
      SERIAL_PROTOCOLCHAR('.');
    }
  }
  else { //write
    if (!file.open(curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) {
      SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
      SERIAL_PROTOCOL(fname);
      SERIAL_PROTOCOLCHAR('.');
    }
    else {
      saving = true;
      SERIAL_PROTOCOLPGM(MSG_SD_WRITE_TO_FILE);
      SERIAL_PROTOCOLLN(name);
      lcd_setstatus(fname);
    }
  }
}
Esempio n. 17
0
void PID_autotune(float temp, int extruder, int ncycles)
{
  float input = 0.0;
  int cycles = 0;
  bool heating = true;

  millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms;
  long t_high = 0, t_low = 0;

  long bias, d;
  float Ku, Tu;
  float Kp, Ki, Kd;
  float max = 0, min = 10000;

  #if HAS_AUTO_FAN
    millis_t next_auto_fan_check_ms = temp_ms + 2500;
  #endif

  if (extruder >= EXTRUDERS
    #if !HAS_TEMP_BED
       || extruder < 0
    #endif
  ) {
    SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM);
    return;
  }
  
  SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);

  disable_heater(); // switch off all heaters.

  if (extruder < 0)
    soft_pwm_bed = bias = d = MAX_BED_POWER / 2;
  else
    soft_pwm[extruder] = bias = d = PID_MAX / 2;

  // PID Tuning loop
  for (;;) {

    millis_t ms = millis();

    if (temp_meas_ready) { // temp sample ready
      updateTemperaturesFromRawValues();

      input = (extruder<0)?current_temperature_bed:current_temperature[extruder];

      max = max(max, input);
      min = min(min, input);

      #if HAS_AUTO_FAN
        if (ms > next_auto_fan_check_ms) {
          checkExtruderAutoFans();
          next_auto_fan_check_ms = ms + 2500;
        }
      #endif

      if (heating == true && input > temp) {
        if (ms - t2 > 5000) {
          heating = false;
          if (extruder < 0)
            soft_pwm_bed = (bias - d) >> 1;
          else
            soft_pwm[extruder] = (bias - d) >> 1;
          t1 = ms;
          t_high = t1 - t2;
          max = temp;
        }
      }
      if (heating == false && input < temp) {
        if (ms - t1 > 5000) {
          heating = true;
          t2 = ms;
          t_low = t2 - t1;
          if (cycles > 0) {
            long max_pow = extruder < 0 ? MAX_BED_POWER : PID_MAX;
            bias += (d*(t_high - t_low))/(t_low + t_high);
            bias = constrain(bias, 20, max_pow - 20);
            d = (bias > max_pow / 2) ? max_pow - 1 - bias : bias;

            SERIAL_PROTOCOLPGM(MSG_BIAS); SERIAL_PROTOCOL(bias);
            SERIAL_PROTOCOLPGM(MSG_D);    SERIAL_PROTOCOL(d);
            SERIAL_PROTOCOLPGM(MSG_T_MIN);  SERIAL_PROTOCOL(min);
            SERIAL_PROTOCOLPGM(MSG_T_MAX);  SERIAL_PROTOCOLLN(max);
            if (cycles > 2) {
              Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0);
              Tu = ((float)(t_low + t_high) / 1000.0);
              SERIAL_PROTOCOLPGM(MSG_KU); SERIAL_PROTOCOL(Ku);
              SERIAL_PROTOCOLPGM(MSG_TU); SERIAL_PROTOCOLLN(Tu);
              Kp = 0.6 * Ku;
              Ki = 2 * Kp / Tu;
              Kd = Kp * Tu / 8;
              SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID);
              SERIAL_PROTOCOLPGM(MSG_KP); SERIAL_PROTOCOLLN(Kp);
              SERIAL_PROTOCOLPGM(MSG_KI); SERIAL_PROTOCOLLN(Ki);
              SERIAL_PROTOCOLPGM(MSG_KD); SERIAL_PROTOCOLLN(Kd);
              /*
              Kp = 0.33*Ku;
              Ki = Kp/Tu;
              Kd = Kp*Tu/3;
              SERIAL_PROTOCOLLNPGM(" Some overshoot ");
              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
              Kp = 0.2*Ku;
              Ki = 2*Kp/Tu;
              Kd = Kp*Tu/3;
              SERIAL_PROTOCOLLNPGM(" No overshoot ");
              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
              */
            }
          }
          if (extruder < 0)
            soft_pwm_bed = (bias + d) >> 1;
          else
            soft_pwm[extruder] = (bias + d) >> 1;
          cycles++;
          min = temp;
        }
Esempio n. 18
0
void PID_autotune(float temp)
{
  float input;
  int cycles=0;
  bool heating = true;

  unsigned long temp_millis = millis();
  unsigned long t1=temp_millis;
  unsigned long t2=temp_millis;
  long t_high;
  long t_low;

  long bias=127;
  long d = 127;
  float Ku, Tu;
  float Kp, Ki, Kd;
  float max, min;
  
  SERIAL_ECHOLN("PID Autotune start");
  
  disable_heater(); // switch off all heaters.
  
  soft_pwm[0] = 255>>1;
    
  for(;;) {

    if(temp_meas_ready == true) { // temp sample ready
      CRITICAL_SECTION_START;
      temp_meas_ready = false;
      CRITICAL_SECTION_END;
      input = analog2temp(current_raw[0], 0);
      
      max=max(max,input);
      min=min(min,input);
      if(heating == true && input > temp) {
        if(millis() - t2 > 5000) { 
          heating=false;
          soft_pwm[0] = (bias - d) >> 1;
          t1=millis();
          t_high=t1 - t2;
          max=temp;
        }
      }
      if(heating == false && input < temp) {
        if(millis() - t1 > 5000) {
          heating=true;
          t2=millis();
          t_low=t2 - t1;
          if(cycles > 0) {
            bias += (d*(t_high - t_low))/(t_low + t_high);
            bias = constrain(bias, 20 ,235);
            if(bias > 127) d = 254 - bias;
            else d = bias;

            SERIAL_PROTOCOLPGM(" bias: "); SERIAL_PROTOCOL(bias);
            SERIAL_PROTOCOLPGM(" d: "); SERIAL_PROTOCOL(d);
            SERIAL_PROTOCOLPGM(" min: "); SERIAL_PROTOCOL(min);
            SERIAL_PROTOCOLPGM(" max: "); SERIAL_PROTOCOLLN(max);
            if(cycles > 2) {
              Ku = (4.0*d)/(3.14159*(max-min)/2.0);
              Tu = ((float)(t_low + t_high)/1000.0);
              SERIAL_PROTOCOLPGM(" Ku: "); SERIAL_PROTOCOL(Ku);
              SERIAL_PROTOCOLPGM(" Tu: "); SERIAL_PROTOCOLLN(Tu);
              Kp = 0.6*Ku;
              Ki = 2*Kp/Tu;
              Kd = Kp*Tu/8;
              SERIAL_PROTOCOLLNPGM(" Clasic PID ")
              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
              /*
              Kp = 0.33*Ku;
              Ki = Kp/Tu;
              Kd = Kp*Tu/3;
              SERIAL_PROTOCOLLNPGM(" Some overshoot ")
              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
              Kp = 0.2*Ku;
              Ki = 2*Kp/Tu;
              Kd = Kp*Tu/3;
              SERIAL_PROTOCOLLNPGM(" No overshoot ")
              SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp);
              SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki);
              SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd);
              */
            }
          }
          soft_pwm[0] = (bias + d) >> 1;
          cycles++;
          min=temp;
        }
      } 
Esempio n. 19
0
/**
 * Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
 *   LS_Count       - Add +1 to nrFiles for every file within the parent
 *   LS_GetFilename - Get the filename of the file indexed by nrFiles
 *   LS_SerialPrint - Print the full path of each file to serial output
 */
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
  dir_t p;
  uint8_t cnt = 0;

  // Read the next entry from a directory
  while (parent.readDir(p, longFilename) > 0) {

    // If the entry is a directory and the action is LS_SerialPrint
    if (DIR_IS_SUBDIR(&p) && lsAction != LS_Count && lsAction != LS_GetFilename) {

      // Get the short name for the item, which we know is a folder
      char lfilename[FILENAME_LENGTH];
      createFilename(lfilename, p);

      // Allocate enough stack space for the full path to a folder, trailing slash, and nul
      boolean prepend_is_empty = (prepend[0] == '\0');
      int len = (prepend_is_empty ? 1 : strlen(prepend)) + strlen(lfilename) + 1 + 1;
      char path[len];

      // Append the FOLDERNAME12/ to the passed string.
      // It contains the full path to the "parent" argument.
      // We now have the full path to the item in this folder.
      strcpy(path, prepend_is_empty ? "/" : prepend); // root slash if prepend is empty
      strcat(path, lfilename); // FILENAME_LENGTH-1 characters maximum
      strcat(path, "/");       // 1 character

      // Serial.print(path);

      // Get a new directory object using the full path
      // and dive recursively into it.
      SdFile dir;
      if (!dir.open(parent, lfilename, O_READ)) {
        if (lsAction == LS_SerialPrint) {
          SERIAL_ECHO_START;
          SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
          SERIAL_ECHOLN(lfilename);
        }
      }
      lsDive(path, dir);
      // close() is done automatically by destructor of SdFile
    }
    else {
      uint8_t pn0 = p.name[0];
      if (pn0 == DIR_NAME_FREE) break;
      if (pn0 == DIR_NAME_DELETED || pn0 == '.') continue;
      if (longFilename[0] == '.') continue;

      if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;

      filenameIsDir = DIR_IS_SUBDIR(&p);

      if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;

      switch (lsAction) {
        case LS_Count:
          nrFiles++;
          break;
        case LS_SerialPrint:
          createFilename(filename, p);
          SERIAL_PROTOCOL(prepend);
          SERIAL_PROTOCOLLN(filename);
          break;
        case LS_GetFilename:
          createFilename(filename, p);
          if (match != NULL) {
            if (strcasecmp(match, filename) == 0) return;
          }
          else if (cnt == nrFiles) return;
          cnt++;
          break;
      }

    }
  } // while readDir
}