Ejemplo n.º 1
0
std::string
GCodeWriter::unretract(const bool first_layer)
{
    std::ostringstream gcode;
    
    if (FLAVOR_IS(gcfMakerWare))
        gcode << "M101 ; extruder on\n";
    
    double dE = this->_extruder->unretract();
    if (dE != 0) {
        if (this->config.use_firmware_retraction) {
            if (FLAVOR_IS(gcfMachinekit))
                 gcode << "G23 ; unretract\n";
            else
                 gcode << "G11 ; unretract\n";
            gcode << this->reset_e();
        } else {
            // use G1 instead of G0 because G0 will blend the restart with the previous travel move
            if (first_layer) {
                gcode << "G1 " << this->_extrusion_axis << E_NUM(this->_extruder->E) + 0.2
                           << " F" << 300;
                this->_extruder->extrude(0.2);
            } else {
                gcode << "G1 " << this->_extrusion_axis << E_NUM(this->_extruder->E)
                           << " F" << this->_extruder->retract_speed_mm_min;
            }
            if (this->config.gcode_comments) gcode << " ; unretract";
            gcode << "\n";
        }
    }
    
    return gcode.str();
}
Ejemplo n.º 2
0
std::string
GCodeWriter::_retract(double length, double restart_extra, const std::string &comment)
{
    std::ostringstream gcode;
    
    /*  If firmware retraction is enabled, we use a fake value of 1
        since we ignore the actual configured retract_length which 
        might be 0, in which case the retraction logic gets skipped. */
    if (this->config.use_firmware_retraction) length = 1;
    
    // If we use volumetric E values we turn lengths into volumes */
    if (this->config.use_volumetric_e) {
        double d = this->_extruder->filament_diameter();
        double area = d * d * PI/4;
        length = length * area;
        restart_extra = restart_extra * area;
    }
    
    double dE = this->_extruder->retract(length, restart_extra);
    if (dE != 0) {
        if (this->config.use_firmware_retraction) {
            gcode << "G10 ; retract\n";
        } else {
            gcode << "G1 " << this->_extrusion_axis << E_NUM(this->_extruder->E)
                           << " F" << this->_extruder->retract_speed_mm_min;
            COMMENT(comment);
            gcode << "\n";
        }
    }
    
    if (FLAVOR_IS(gcfMakerWare))
        gcode << "M103 ; extruder off\n";
    
    return gcode.str();
}
Ejemplo n.º 3
0
std::string
GCodeWriter::extrude_to_xy(const Pointf &point, double dE, const std::string &comment)
{
    this->_pos.x = point.x;
    this->_pos.y = point.y;
    this->_extruder->extrude(dE);
    
    std::ostringstream gcode;
    gcode << "G1 X" << XYZF_NUM(point.x)
          <<   " Y" << XYZF_NUM(point.y)
          <<    " " << this->_extrusion_axis << E_NUM(this->_extruder->E);
    COMMENT(comment);
    gcode << "\n";
    return gcode.str();
}
Ejemplo n.º 4
0
// doc: The sqlite3_bind_*() routines must be called after sqlite3_prepare() or sqlite3_reset() and before sqlite3_step().
//      Bindings are not cleared by the sqlite3_reset() routine. Unbound parameters are interpreted as NULL.
bool SqliteSetupBindings(JSContext *cx, sqlite3_stmt *pStmt, JS::HandleObject argObj, JS::HandleObject curObj) {

	JS::RootedValue val(cx);
	int anonParamIndex = 0;
	const char *name;

	int count = sqlite3_bind_parameter_count(pStmt);
	for ( int param = 1; param <= count; param++ ) { // The first host parameter has an index of 1, not 0.

		// doc: Parameters of the form "?" have no name. ... If the value n is out of range or if the n-th parameter is nameless, then NULL is returned.
		name = sqlite3_bind_parameter_name(pStmt, param);

		// doc: name is UTF-8 encoding

		if ( name == NULL ) {

			JL_CHKM(argObj, E_PARAM, E_NUM(anonParamIndex), E_DEFINED);
			JL_CHK( JL_GetElement(cx, argObj, anonParamIndex, &val) ); // works with {0:2,1:2,2:2,length:3} and [2,2,2]
			anonParamIndex++;
		} else
		if ( name[0] == '@' ) {

			JL_CHKM(argObj, E_PARAM, E_NAME(name), E_DEFINED);
			JL_CHK( JS_GetProperty(cx, argObj, name+1, &val) );
		} else
		if ( name[0] == ':' ) {
			
			JL_CHKM(curObj, E_PARAM, E_NAME(name), E_DEFINED);
			JL_CHK( JS_GetProperty(cx, curObj, name+1, &val) );
		} else {

			JL_ERR(E_PARAM, E_NOTSUPPORTED);
		}
		
		JL_CHK( jsvalToSqlite( cx, SqliteTargetBind( pStmt, param ), val ) );
	}
	return true;
	JL_BAD;
}
Ejemplo n.º 5
0
/**doc
$TOC_MEMBER $INAME
 $INAME( [type = Socket.TCP] )
  Type can be Socket.TCP or Socket.UDP.
**/
DEFINE_CONSTRUCTOR() {

	PRFileDesc *fd = NULL;

	JL_DEFINE_ARGS;
	JL_ASSERT_CONSTRUCTING();

	{
	JL_DEFINE_CONSTRUCTOR_OBJ;

	int descType;
	if ( JL_ARG_ISDEF(1) )
		JL_CHK( jl::getValue(cx, JL_ARG(1), &descType) );
	else
		descType = PR_DESC_SOCKET_TCP; // default

	if ( descType == PR_DESC_SOCKET_TCP )
		fd = PR_NewTCPSocket();
	else if ( descType == PR_DESC_SOCKET_UDP )
		fd = PR_NewUDPSocket();
	else
		JL_ERR( E_ARG, E_NUM(1), E_INVALID );

	if ( fd == NULL )
		return ThrowIoError(cx);

	JL_CHK( jl::reserveStreamReadInterface(cx, JL_OBJ) );

	JL_SetPrivate(JL_OBJ, fd);

	}

	return true;

bad:
	if ( fd )
		PR_Close(fd);
	return false;
}
Ejemplo n.º 6
0
/**doc
$TOC_MEMBER $INAME
 $INAME( cipherName, hashName [, prngObject] [, PKCSVersion = 1_OAEP] )
  Creates a new Asymmetric Cipher object.
  $H arguments
   $ARG $STR cipherName: is a string that contains the name of the Asymmetric Cipher algorithm:
    * rsa
    * ecc
    * dsa
    * katja
   $ARG $STR hashName: is the hash that will be used to create the PSS (Probabilistic Signature Scheme) encoding. It should be the same as the hash used to hash the message being signed. See Hash class for available names.
   $ARG $OBJ prngObject: is an instantiated Prng object. Its current state will be used for key creation, data encryption/decryption, data signature/signature check. This argument can be ommited if you aim to decrypt data only.
   $ARG $STR PKCSVersion: is a string that contains the padding version used by RSA to encrypt/decrypd data:
    * 1_V1_5 (for PKCS#1 v1.5 padding)
    * 1_OAEP (for PKCS#1 v2.0 encryption padding)
    If omitted, the default value is 1_OAEP.
	 Only RSA use this argument.
    $H note
    When performing v1.5 encryption, the hash and lparam parameters are totally ignored.
**/
DEFINE_CONSTRUCTOR() { // ( cipherName [, hashName] [, prngObject] [, PKCSVersion] )

	JL_DEFINE_ARGS;

	AsymmetricCipherPrivate *pv = NULL;

	JL_ASSERT_ARGC_MIN( 3 );
	JL_ASSERT_CONSTRUCTING();
	JL_DEFINE_CONSTRUCTOR_OBJ;


	AsymmetricCipherType asymmetricCipher;

	{

		jl::StrData asymmetricCipherName(cx);
		JL_CHK( jl::getValue(cx, JL_ARG(1), &asymmetricCipherName) );

		if ( asymmetricCipherName.equals("RSA") )
			asymmetricCipher = rsa;
		else
		if ( asymmetricCipherName.equals("DSA") )
			asymmetricCipher = dsa;
		else
		if ( asymmetricCipherName.equals("ECC") )
			asymmetricCipher = ecc;
	#ifdef MKAT
		else
		if ( asymmetricCipherName.equals("KATJA") )
			asymmetricCipher = katja;
	#endif
		else
			JL_ERR( E_ARG, E_NUM(1), E_INVALID, E_SEP, E_NAME(asymmetricCipherName), E_NOTSUPPORTED );

	}

	pv = (AsymmetricCipherPrivate *)jl_malloc(sizeof(AsymmetricCipherPrivate));
	JL_CHK( pv );

	pv->cipher = asymmetricCipher;

	if ( JL_ARG_ISDEF(2) ) {
		
		jl::StrData hashName(cx);
		JL_CHK( jl::getValue(cx, JL_ARG(2), &hashName) );
		pv->hashIndex = find_hash(hashName);
	} else {

		pv->hashIndex = -1;
	}

	if ( argc >= 3 ) {

		JL_ASSERT_ARG_IS_OBJECT(3);
		JS::RootedObject prngObj(cx, &JL_ARG(3).toObject());
		JL_ASSERT_INSTANCE( prngObj, JL_CLASS(Prng) );
		JL_CHK( JL_SetReservedSlot( JL_OBJ, ASYMMETRIC_CIPHER_PRNG_SLOT, JL_ARG(3)) );
	} else {

		JL_CHK( JL_SetReservedSlot(JL_OBJ, ASYMMETRIC_CIPHER_PRNG_SLOT, JL_UNDEFINED) );
	}

	if ( asymmetricCipher == rsa ) {

		if ( JL_ARGC >= 4 && !JL_ARG(4).isUndefined() ) {

			jl::StrData paddingName(cx);
			JL_CHK( jl::getValue(cx, JL_ARG(4), &paddingName) );

			if ( paddingName.equals("1_OAEP") ) {
				pv->padding = LTC_LTC_PKCS_1_OAEP;
			} else
			if ( paddingName.equals("1_V1_5") ) {
				pv->padding = LTC_LTC_PKCS_1_V1_5;
			} else
				JL_ERR( E_ARG, E_NUM(4), E_INVALID, E_SEP, E_NAME(paddingName), E_NOTSUPPORTED );
		} else {

			pv->padding = LTC_LTC_PKCS_1_OAEP; // default
		}
	} else {

		JL_ASSERT_ARGC_MAX( 3 );
	}

	pv->hasKey = false;

	JL_SetPrivate(JL_OBJ, pv);
	return true;

bad:
	jl_free(pv);
	return false;
}
Ejemplo n.º 7
0
/**doc
$TOC_MEMBER $INAME
 $INAME( [init] )
  Creates a new Transformation object.
  If no argument is given, the transformation is not initialized.
  If _init_ is $NULL, the transformation is initialized to identity.
  If _init_ is a matrix, the transormation is initialized with the matrix.
**/
DEFINE_CONSTRUCTOR() {

	TransformationPrivate *pv = NULL;

	JL_DEFINE_ARGS;

	JL_DEFINE_CONSTRUCTOR_OBJ;
	JL_ASSERT_ARGC_RANGE(0, 16);
//	JL_ASSERT_CONSTRUCTING();

	pv = (TransformationPrivate *)JS_malloc(cx, sizeof(TransformationPrivate));
	JL_CHK(pv);
	pv->mat = NULL; // see bad:

	pv->mat = PoolIsEmpty(&matrixPool) ? Matrix44Alloc() : (Matrix44*)jl::PoolPop(&matrixPool);
	JL_ASSERT_ALLOC(pv->mat);

	if ( JL_ARGC >= 1 ) {
			
		if ( JL_ARG(1).isObject() ) {

			JL_ASSERT_ARGC(1);
			Matrix44 *m = pv->mat;
			JL_CHK( GetMatrixHelper(cx, JL_ARG(1), (float**)&m) );
			if ( m != pv->mat ) // check if the pointer has been modified
				Matrix44Load(pv->mat, m);
			pv->isIdentity = false;
		} else
/*
		if ( JSVAL_IS_NULL(JL_ARG(1)) ) {

			Matrix44Identity(pv->mat);
			pv->isIdentity = true;
		} else
*/
		if ( JL_ARGC == 16 ) {
			
			float *tmp = (float*)&pv->mat->raw;
			for ( int i = 0; i < 16; ++i )
				JL_CHK( jl::getValue(cx, JL_ARG(i+1), (tmp++)) );
			// see JL_CHK( jl::getVector(cx, *JL_ARGV, tmp, 16, &len) );
			pv->isIdentity = false;
		} else {

			JL_ERR( E_ARGC, E_EQUALS, E_NUM(16) );
		}
	}
	// else uninitialized matrix

	JL_CHK( jl::setMatrix44GetInterface(cx, JL_OBJ, GetMatrix) );

	JL_SetPrivate(JL_OBJ, pv);
	return true;

bad:
	if ( pv ) {
		
		if ( pv->mat )
			Matrix44Free(pv->mat);
		JS_free(cx, pv);
	}
	return false;
}
Ejemplo n.º 8
0
/**doc
$TOC_MEMBER $INAME
 $Image $INAME( deviceId, [idealWidth], [idealHeight], [idealFPS], [flipImageY = true], [flipImageRedBlue = true] )
**/
DEFINE_CONSTRUCTOR() {

	JL_DEFINE_ARGS;

	Private *pv = NULL;

	JL_ASSERT_CONSTRUCTING();
	JL_DEFINE_CONSTRUCTOR_OBJ;
	JL_ASSERT_ARGC_RANGE(1,5);

	pv = new Private( jl::Host::getJLHost(cx)->moduleManager().modulePrivateT<videoInput*>( moduleId() ) );
	JL_ASSERT_ALLOC( pv );
	pv->deviceID = -1; // invalid device

	int numDevices = videoInput::listDevices(true);

	if ( !JL_ARG(1).isString() ) {
		
		JL_CHK( jl::getValue(cx, JL_ARG(1), &pv->deviceID) );
		JL_ASSERT_ARG_VAL_RANGE( pv->deviceID, 0, numDevices-1, 1 );
	} else {
	
		jl::StrData requiredDeviceName(cx);
		JL_CHK( jl::getValue(cx, JL_ARG(1), &requiredDeviceName) );
		for ( int i = 0; i < numDevices; i++ ) {

			if ( strstr(videoInput::getDeviceName(i), requiredDeviceName) != NULL ) {
				
				pv->deviceID = i;
				break;
			}
		}
		JL_CHKM( pv->deviceID != -1, E_ARG, E_NUM(1), E_NOTFOUND );
	}

	if ( JL_ARG_ISDEF(4) ) {

		int fps;
		JL_CHK( jl::getValue(cx, JL_ARG(4), &fps) );
		pv->vi->setIdealFramerate( pv->deviceID, fps ); // vi->VDList[deviceId]->requestedFrameTime;
	}
	
	if ( JL_ARG_ISDEF(2) && JL_ARG_ISDEF(3) ) {
		
		int width, height;
		JL_CHK( jl::getValue(cx, JL_ARG(2), &width) );
		JL_CHK( jl::getValue(cx, JL_ARG(3), &height) );
		pv->vi->setupDevice( pv->deviceID, width, height );
	} else {
	
		pv->vi->setupDevice( pv->deviceID ); // use default size
	}

	if ( JL_ARG_ISDEF(5) )
		JL_CHK( jl::getValue(cx, JL_ARG(1), &pv->flipImageY) );
	else
		pv->flipImageY = true;

	if ( JL_ARG_ISDEF(6) )
		JL_CHK( jl::getValue(cx, JL_ARG(1), &pv->flipImageRedBlue) );
	else
		pv->flipImageRedBlue = true;


	//	vi->setVideoSettingCameraPct(deviceId, vi->propBrightness, 100);
	// vi->setFormat(deviceId, VI_NTSC_M);

	JL_SetPrivate(JL_OBJ, pv);
	return true;

bad:
	if ( pv ) {
		
		ASSERT( pv->vi );

		if ( pv->deviceID != -1 )
			pv->vi->stopDevice( pv->deviceID );
		delete pv;
	}
	return false;
}