Printer::Printer(const char *file,
				 int baudRate,
				 int protocol,
				 float home_x,
				 float home_y,
				 float home_z,
				 float home_e)
	: 
	  fd(serialOpen(file, baudRate)),
	  file(fdopen(fd, "rw")),
	  serialReadNum(0),
	  running(true),
	  started(false),
	  protocol(protocol),
	  x(NAN),
	  y(NAN),
	  z(NAN),
	  e(NAN),
	  f(NAN),
	  lineNumber(-1),
	  confirmedLineNumber(-1)
{
	if(fd == -1) {
		throw "Blah :|";
	}

	std::unique_lock<std::mutex> writeLock(writeMutex);
	serialReadThread = std::thread(&Printer::serialRead, this);
	while(!started) {
		signalNextCommand.wait(writeLock);
	}
	writeLock.unlock();
	serialWriteThread = std::thread(&Printer::serialWrite, this);

	setHome(home_x, home_y, home_z, home_e);
	GCode gc;
	gc.setM(110);
	addCommand(gc);
	gc = GCode();
	gc.setM(111);
	gc.setS(7);
	addCommand(gc);
	gc = GCode();
	gc.setM(114);
	addCommand(gc);
	gc = GCode();
	gc.setM(84);
	addCommand(gc);
}
Esempio n. 2
0
// not used (yet)
string Printlines::GCode(Vector3d &lastpos, double &E, double feedrate, 
			 double minspeed, double maxspeed, double movespeed, 
			 bool relativeE) const
{
  ostringstream o;
  // E is total E so far (if absolute Ecode)
  for (lineCIt lIt = lines.begin(); lIt!=lines.end();++lIt){
    o << GCode(*lIt, lastpos, E, feedrate, minspeed, maxspeed, movespeed, relativeE);
  }
  cerr << "PL gcode " << o.str()<< endl;
  return o.str();
}