static void load(Space *s, uint8_t old_type, int32_t &addr) {
	if (!s->setup_nums(3, 3)) {
		debug("Failed to set up delta axes");
		s->cancel_update();
		return;
	}
	for (uint8_t a = 0; a < 3; ++a) {
		APEX(s, a).axis_min = read_float(addr);
		APEX(s, a).axis_max = read_float(addr);
		APEX(s, a).rodlength = read_float(addr);
		APEX(s, a).radius = read_float(addr);
	}
	PRIVATE(s).angle = read_float(addr);
	if (isinf(PRIVATE(s).angle) || isnan(PRIVATE(s).angle))
		PRIVATE(s).angle = 0;
#define sin210 -.5
#define cos210 -0.8660254037844386	// .5*sqrt(3)
#define sin330 -.5
#define cos330 0.8660254037844386	// .5*sqrt(3)
#define sin90 1
	// Coordinates of axes (at angles 210, 330, 90; each with its own radius).
	double x[3], y[3];
	x[0] = APEX(s, 0).radius * cos210;
	y[0] = APEX(s, 0).radius * sin210;
	x[1] = APEX(s, 1).radius * cos330;
	y[1] = APEX(s, 1).radius * sin330;
	x[2] = 0;
	y[2] = APEX(s, 2).radius * sin90;
	for (uint8_t a = 0; a < 3; ++a) {
		APEX(s, a).x = x[a] * cos(PRIVATE(s).angle) - y[a] * sin(PRIVATE(s).angle);
		APEX(s, a).y = y[a] * cos(PRIVATE(s).angle) + x[a] * sin(PRIVATE(s).angle);
		APEX(s, a).z = sqrt(APEX(s, a).rodlength * APEX(s, a).rodlength - APEX(s, a).radius * APEX(s, a).radius);
	}
}
Example #2
0
// Parameter lines are on the form '$4=374.3' or '$' to dump current settings
uint8_t settings_execute_line(char *line) {
  uint8_t char_counter = 1;
  float parameter, value;

  if(line[0] != '$') { 
    return (STATUS_UNSUPPORTED_STATEMENT);
  }
  if(!line[char_counter]) {
    settings_dump();
    return (STATUS_OK);
  }
  if(!read_float(line, &char_counter, &parameter)) {
    return(STATUS_BAD_NUMBER_FORMAT);
  };
  if(line[char_counter++] != '=') { 
    return (STATUS_UNSUPPORTED_STATEMENT);
  }
  if(!read_float(line, &char_counter, &value)) {
    return(STATUS_BAD_NUMBER_FORMAT);
  }
  if(line[char_counter] != 0) { 
    return (STATUS_UNSUPPORTED_STATEMENT);
  }
  settings_store_setting(parameter, value);
  return (STATUS_OK);
}
Example #3
0
void Space::load_axis(uint8_t a, int32_t &addr) { // {{{
	loaddebug("loading axis %d", a);
	axis[a]->park = read_float(addr);
	axis[a]->park_order = read_8(addr);
	axis[a]->min_pos = read_float(addr);
	axis[a]->max_pos = read_float(addr);
} // }}}
Example #4
0
int main(int argc, char *argv[])
{
    float curr;
    float full;

    for(int i = 0; i < argc; i++)
    {/* Arguments passed to the
    program will be parsed here. */
        if(strcmp(argv[i], "-n") == 0)
        {/* Set the newline boolean. */
            newline = false;
            continue;
        }
        if(strcmp(argv[i], "-b") == 0)
        {/* Set the colour boolean. */
            colour = false;
            continue;
        }
    }

    read_float(PATH "charge_now", &curr);
    read_float(PATH "charge_full", &full);

    print_percentage(
        calculate_percentage(curr, full));

    return EXIT_SUCCESS;
}
Example #5
0
void Space::load_motor(int m, int32_t &addr) { // {{{
	loaddebug("loading motor %d", m);
	uint16_t enable = motor[m]->enable_pin.write();
	double old_home_pos = motor[m]->home_pos;
	double old_steps_per_unit = motor[m]->steps_per_unit;
	motor[m]->step_pin.read(read_16(addr));
	motor[m]->dir_pin.read(read_16(addr));
	motor[m]->enable_pin.read(read_16(addr));
	motor[m]->limit_min_pin.read(read_16(addr));
	motor[m]->limit_max_pin.read(read_16(addr));
	motor[m]->steps_per_unit = read_float(addr);
	motor[m]->home_pos = read_float(addr);
	motor[m]->limit_v = read_float(addr);
	motor[m]->limit_a = read_float(addr);
	motor[m]->home_order = read_8(addr);
	arch_motors_change();
	SET_OUTPUT(motor[m]->enable_pin);
	if (enable != motor[m]->enable_pin.write()) {
		if (motors_busy)
			SET(motor[m]->enable_pin);
		else {
			RESET(motor[m]->enable_pin);
		}
	}
	RESET(motor[m]->step_pin);
	SET_INPUT(motor[m]->limit_min_pin);
	SET_INPUT(motor[m]->limit_max_pin);
	bool must_move = false;
	if (!isnan(motor[m]->home_pos)) {
		// Axes with a limit switch.
		if (motors_busy && (old_home_pos != motor[m]->home_pos || old_steps_per_unit != motor[m]->steps_per_unit) && !isnan(old_home_pos)) {
			double ohp = old_home_pos * old_steps_per_unit;
			double hp = motor[m]->home_pos * motor[m]->steps_per_unit;
			double diff = hp - ohp;
			motor[m]->settings.current_pos += diff;
			//debug("load motor %d %d new home %f add %f", id, m, motor[m]->home_pos, diff);
			arch_addpos(id, m, diff);
			must_move = true;
		}
	}
	else {
		// Axes without a limit switch, including extruders.
		if (motors_busy && old_steps_per_unit != motor[m]->steps_per_unit) {
			debug("load motor %d %d new steps no home", id, m);
			double oldpos = motor[m]->settings.current_pos;
			double pos = oldpos / old_steps_per_unit;
			motor[m]->settings.current_pos = pos * motor[m]->steps_per_unit;
			arch_addpos(id, m, motor[m]->settings.current_pos - oldpos);
			// Adjust current_pos in all history.
			for (int h = 0; h < FRAGMENTS_PER_BUFFER; ++h) {
				oldpos = motor[m]->history[h].current_pos;
				pos = oldpos / old_steps_per_unit;
				motor[m]->history[h].current_pos = pos * motor[m]->steps_per_unit;
			}
		}
	}
	if (must_move)
		move_to_current();
} // }}}
Example #6
0
		size_t PerspectiveMessage::deserialize(unsigned char *const read_buffer) {
			size_t len = getSize();
			read_float(read_buffer, 12, &_perspective._fov);
			read_float(read_buffer, 16, &_perspective._aspect);
			read_float(read_buffer, 20, &_perspective._near);
			read_float(read_buffer, 24, &_perspective._far);
			return len;
		}
Example #7
0
		size_t TouchEventMessage::deserialize(unsigned char *const read_buffer) {
			size_t len = getSize(); 
			read_uchar(read_buffer, 12, &_touch_event._event_type);
			read_float(read_buffer, 13, &_touch_event._x1);
			read_float(read_buffer, 17, &_touch_event._y1);
			read_float(read_buffer, 21, &_touch_event._x2);
			read_float(read_buffer, 25, &_touch_event._y2);
			return len;
		}
Example #8
0
void Space::load_motor(uint8_t m, int32_t &addr) { // {{{
	loaddebug("loading motor %d", m);
	uint16_t enable = motor[m]->enable_pin.write();
	double old_home_pos = motor[m]->home_pos;
	double old_steps_per_unit = motor[m]->steps_per_unit;
	motor[m]->step_pin.read(read_16(addr));
	motor[m]->dir_pin.read(read_16(addr));
	motor[m]->enable_pin.read(read_16(addr));
	motor[m]->limit_min_pin.read(read_16(addr));
	motor[m]->limit_max_pin.read(read_16(addr));
	motor[m]->sense_pin.read(read_16(addr));
	motor[m]->steps_per_unit = read_float(addr);
	motor[m]->max_steps = read_8(addr);
	motor[m]->home_pos = read_float(addr);
	motor[m]->limit_v = read_float(addr);
	motor[m]->limit_a = read_float(addr);
	motor[m]->home_order = read_8(addr);
	arch_motors_change();
	SET_OUTPUT(motor[m]->enable_pin);
	if (enable != motor[m]->enable_pin.write()) {
		if (motors_busy)
			SET(motor[m]->enable_pin);
		else {
			RESET(motor[m]->enable_pin);
		}
	}
	RESET(motor[m]->step_pin);
	SET_INPUT(motor[m]->limit_min_pin);
	SET_INPUT(motor[m]->limit_max_pin);
	SET_INPUT(motor[m]->sense_pin);
	bool must_move = false;
	if (!isnan(motor[m]->home_pos)) {
		// Axes with a limit switch.
		if (motors_busy && (old_home_pos != motor[m]->home_pos || old_steps_per_unit != motor[m]->steps_per_unit) && !isnan(old_home_pos)) {
			int32_t hp = motor[m]->home_pos * motor[m]->steps_per_unit + (motor[m]->home_pos > 0 ? .49 : -.49);
			int32_t ohp = old_home_pos * old_steps_per_unit + (old_home_pos > 0 ? .49 : -.49);
			int32_t diff = hp - ohp;
			motor[m]->settings.current_pos += diff;
			cpdebug(id, m, "load motor new home add %d", diff);
			arch_addpos(id, m, diff);
			must_move = true;
		}
	}
	else {
		// Axes without a limit switch, including extruders.
		if (motors_busy && old_steps_per_unit != motor[m]->steps_per_unit) {
			int32_t cp = motor[m]->settings.current_pos;
			double pos = cp / old_steps_per_unit;
			cpdebug(id, m, "load motor new steps no home");
			motor[m]->settings.current_pos = pos * motor[m]->steps_per_unit;
			int diff = motor[m]->settings.current_pos - cp;
			arch_addpos(id, m, diff);
		}
	}
	if (must_move)
		move_to_current();
} // }}}
Example #9
0
//---------------------------------------------------------------------------------------------
Vec3 BitMessage::read_vec3() const
{
	Vec3 v;
	
	v.x = read_float();
	v.y = read_float();
	v.z = read_float();
	
	return v;
}
Example #10
0
void gain_menu_branch(uint8_t com_type){
	
	switch(com_type){
		case DISPLAY:
			uart0_printf("P: %f, I: %f, D: %f\r\n", c_gain->p_gain, c_gain->i_gain, c_gain->d_gain);
			break;
		
		case SET_P:
			uart0_printf("P Gain is %f, input new value.\r\n", c_gain->p_gain);
			c_gain->p_gain = uart0_get_float_input();
			break;
		
		case SET_I:
			uart0_printf("I Gain is %f, input new value.\r\n", c_gain->i_gain);
			c_gain->i_gain = uart0_get_float_input();
			break;
		
		case SET_D:
			uart0_printf("D Gain is %f, input new value.\r\n", c_gain->d_gain);
			c_gain->d_gain = uart0_get_float_input();
			break;
		
		case SET_Q_TH:
			uart0_printf("OF quality threshold is %d, input new value. (range: 0~255)\r\n", c_flow->qual_th);
			c_flow->qual_th = (uint16_t)uart0_get_float_input();
			if(c_flow->qual_th > 255) c_flow->qual_th = 255;
			break;
		
		case SAVE:
			write_float(P_ADD, c_gain->p_gain);
			write_float(I_ADD, c_gain->i_gain);
			write_float(D_ADD, c_gain->d_gain);
			write_uint16(Q_TH_ADD, c_flow->qual_th);
			uart0_printf("Saved!\r\n");
			break;
		
		case RESTORE:
			c_gain->p_gain = read_float(P_ADD);
			c_gain->i_gain = read_float(I_ADD);
			c_gain->d_gain = read_float(D_ADD);
			uart0_printf("Restore Parameters.\r\n");
			break;
		
		case EXIT:
			menu_flg = 0;
			input_detect = 0;
			top_menu();
			break;
		
		default:
			uart0_printf("invalid command\r\n");
			input_detect = 0;
			break;
	}
}
Example #11
0
static void read_pnts(FILE *f, int nbytes, lwObject *lwo)
{
  int i;
  lwo->vertex_cnt = nbytes / 12;
  lwo->vertex = (float*) calloc(sizeof(GLfloat)*lwo->vertex_cnt*3, 1);
  for (i=0; i<lwo->vertex_cnt; i++) {
    lwo->vertex[i*3+0] = read_float(f);
    lwo->vertex[i*3+1] = read_float(f);
    lwo->vertex[i*3+2] = read_float(f);
  }
}
Example #12
0
static int load_ambdec_speakers(AmbDecConf *conf, FILE *f, char **buffer, size_t *maxlen, char **saveptr)
{
    ALuint cur = 0;
    while(cur < conf->NumSpeakers)
    {
        const char *cmd = my_strtok_r(NULL, " \t", saveptr);
        if(!cmd)
        {
            char *line = read_clipped_line(f, buffer, maxlen);
            if(!line)
            {
                ERR("Unexpected end of file\n");
                return 0;
            }
            cmd = my_strtok_r(line, " \t", saveptr);
        }

        if(strcmp(cmd, "add_spkr") == 0)
        {
            const char *name = my_strtok_r(NULL, " \t", saveptr);
            const char *dist = my_strtok_r(NULL, " \t", saveptr);
            const char *az = my_strtok_r(NULL, " \t", saveptr);
            const char *elev = my_strtok_r(NULL, " \t", saveptr);
            const char *conn = my_strtok_r(NULL, " \t", saveptr);

            if(!name) WARN("Name not specified for speaker %u\n", cur+1);
            else al_string_copy_cstr(&conf->Speakers[cur].Name, name);
            if(!dist) WARN("Distance not specified for speaker %u\n", cur+1);
            else read_float(&conf->Speakers[cur].Distance, dist);
            if(!az) WARN("Azimuth not specified for speaker %u\n", cur+1);
            else read_float(&conf->Speakers[cur].Azimuth, az);
            if(!elev) WARN("Elevation not specified for speaker %u\n", cur+1);
            else read_float(&conf->Speakers[cur].Elevation, elev);
            if(!conn) TRACE("Connection not specified for speaker %u\n", cur+1);
            else al_string_copy_cstr(&conf->Speakers[cur].Connection, conn);

            cur++;
        }
        else
        {
            ERR("Unexpected speakers command: %s\n", cmd);
            return 0;
        }

        cmd = my_strtok_r(NULL, " \t", saveptr);
        if(cmd)
        {
            ERR("Unexpected junk on line: %s\n", cmd);
            return 0;
        }
    }

    return 1;
}
Example #13
0
void set_line_style_by_UL()
{
	SCHAR index, pos_index, neg_index, count, i;
	double factor, percentage;
	float tmp;

	if (read_float(&tmp)) {
		set_line_style_defaults();	/* reset to defaults */
		return;
	} else {
		index = (int) tmp;
	}

	pos_index = index - LT_MIN;
	neg_index = (index * -1) - LT_MIN;

	for (count = 0, percentage = 0; (read_float(&tmp) == 0); count++) {	/* while there is an argument */
		lt[pos_index][count] = (double) tmp;
		percentage += (int) tmp;
	}

	lt[pos_index][count] = -1;

	if (fabs(percentage - 100.) > 0.5) {
		factor = 100.0 / percentage;
		for (count = 0; count < LT_ELEMENTS; count++) {
			if (lt[pos_index][count] < 0) {
				break;
			} else {
				lt[pos_index][count] *= factor;
			}
		}
	}
	/* now derive the adaptive version */

	count--;

	if (count % 2) {	/* last value denotes a gap */
		lt[neg_index][0] = lt[pos_index][0] / 2;
		for (i = 1; i <= count; i++)
			lt[neg_index][i] = lt[pos_index][i];
		lt[neg_index][count + 1] = lt[pos_index][0] / 2;
		lt[neg_index][count + 2] = -1;
	} else {		/* last value denotes a line */
		lt[neg_index][0] =
		    (lt[pos_index][0] + lt[pos_index][count]) / 2;
		for (i = 1; i < count; i++)
			lt[neg_index][i] = lt[pos_index][i];
		lt[neg_index][count] = lt[neg_index][0];
		lt[neg_index][count + 1] = -1;
	}

}
Example #14
0
void set_line_attr(FILE * hd)
{
	float ftmp1;
	float ftmp2;

/*   LineEnds itmp;*/
	int itmp;

	if (read_float(&ftmp1, hd)) {	/* No kind found        */
		set_line_attr_defaults();
		return;
	}

	for (;;) {

		if (read_float(&ftmp2, hd)) {	/* No value found       */
			/* do_error */
			return;
		}
		itmp = (int) ftmp2;

		PlotCmd_to_tmpfile(DEF_LA);

		switch ((int) ftmp1) {
		case 1:
			if ((itmp >= LAE_butt) && (itmp <= LAE_round)) {
				Line_Attr_to_tmpfile(LineAttrEnd, itmp);
			} else {
				Line_Attr_to_tmpfile(LineAttrEnd,
						     LAE_butt);
			}
			break;
		case 2:
			if ((itmp >= LAJ_plain_miter)
			    && (itmp <= LAJ_nojoin)) {
				Line_Attr_to_tmpfile(LineAttrJoin, itmp);
			} else {
				Line_Attr_to_tmpfile(LineAttrJoin,
						     LAJ_plain_miter);
			}
			break;
		case 3:
			Line_Attr_to_tmpfile(LineAttrLimit, itmp);
			break;
		}
		if (read_float(&ftmp1, hd)) {	/* No kind found        */
			return;
		}
	}
	return;
}
Example #15
0
Volume* load_volume(tinyxml2::XMLElement *elem, VolumeCache &cache, const std::string &scene_file){
	if (!elem->Attribute("name")){
		std::cout << "Scene error: Volumes require a name" << std::endl;
		return nullptr;
	}
	if (!elem->Attribute("type")){
		std::cout << "Scene error: Volumes require a type" << std::endl;
		return nullptr;
	}

	std::string name = elem->Attribute("name");
	std::string type = elem->Attribute("type");

	Volume *vol = cache.get(name);
	if (vol){
		return vol;
	}
	Colorf sig_a, sig_s, emit;
	float phase_asym;
	read_color(elem->FirstChildElement("absorption"), sig_a);
	read_color(elem->FirstChildElement("scattering"), sig_s);
	read_color(elem->FirstChildElement("emission"), emit);
	read_float(elem->FirstChildElement("phase_asymmetry"), phase_asym);

	if (type == "homogeneous"){
		Point min, max;
		read_point(elem->FirstChildElement("min"), min);
		read_point(elem->FirstChildElement("max"), max);
		return cache.add(name, std::make_unique<HomogeneousVolume>(sig_a, sig_s, emit, phase_asym, BBox{min, max}));
	}
	if (type == "exponential"){
		float a = 0, b = 0;
		Vector up;
		Point min, max;
		read_float(elem->FirstChildElement("a"), a);
		read_float(elem->FirstChildElement("b"), b);
		read_vector(elem->FirstChildElement("up"), up);
		read_point(elem->FirstChildElement("min"), min);
		read_point(elem->FirstChildElement("max"), max);
		return cache.add(name, std::make_unique<ExponentialVolume>(sig_a, sig_s, emit, phase_asym, BBox{min, max}, a, b, up));
	}
	if (type == "vol"){
		std::string file = scene_file.substr(0, scene_file.rfind(PATH_SEP) + 1) + elem->Attribute("file");
		float density_scale = 1;
		read_float(elem->FirstChildElement("density_scale"), density_scale);
		return cache.add(name, std::make_unique<GridVolume>(sig_a, sig_s, emit, phase_asym, file, density_scale));
	}
	std::cout << "Scene error: Unrecognized volume type " << type << std::endl;
	return nullptr;
}
Example #16
0
static struct value *
read_value(struct _field *f, struct atom * a, uint8_t *buffer) {
	struct value * v;

	switch (f->type) {
	case PTYPE_DOUBLE:
		v = malloc(SIZE_VAR);
		v->v.var->real = read_double(a);
		break;
	case PTYPE_FLOAT:
		v = malloc(SIZE_VAR);
		v->v.var->real = (double) read_float(a);
		break;
	case PTYPE_ENUM:
		v = malloc(SIZE_VAR);
		v->v.var->e.id = a->v.i.low;
		v->v.var->e.name = _pbcM_ip_query(f->type_name.e->id , a->v.i.low);
		break;
	case PTYPE_INT64:
	case PTYPE_UINT64:
	case PTYPE_INT32:
	case PTYPE_UINT32:
	case PTYPE_FIXED32:
	case PTYPE_FIXED64:
	case PTYPE_SFIXED32:
	case PTYPE_SFIXED64:
	case PTYPE_BOOL:
		v = malloc(SIZE_VAR);
		v->v.var->integer = a->v.i;
		break;
	case PTYPE_SINT32: 
		v = malloc(SIZE_VAR);
		v->v.var->integer = a->v.i;
		varint_dezigzag32(&(v->v.var->integer));
		break;
	case PTYPE_SINT64:
		v = malloc(SIZE_VAR);
		v->v.var->integer = a->v.i;
		varint_dezigzag64(&(v->v.var->integer));
		break;
	case PTYPE_STRING:
		v = read_string(a,f,buffer);
		break;
	case PTYPE_BYTES:
		v = malloc(SIZE_VAR);
		v->v.var->s.str = (const char *)(buffer + a->v.s.start);
		v->v.var->s.len = a->v.s.end - a->v.s.start;
		break;
	case PTYPE_MESSAGE:
		v = malloc(SIZE_MESSAGE);
		_pbc_rmessage_new(&(v->v.message), f->type_name.m , 
			buffer + a->v.s.start , 
			a->v.s.end - a->v.s.start);
		break;
	default:
		return NULL;
	}
	v->type = f;
	return v;
}
Example #17
0
static int
unpack_field(int ctype, int ptype, char * buffer, struct atom * a, void *out) {
	if (ctype == CTYPE_ARRAY) {
		return unpack_array(ptype, buffer, a , out);
	}
	if (ctype == CTYPE_PACKED) {
		pbc_ctx packed;
		struct context * ctx = (struct context *)packed;

		int n = _pbcC_open_packed(packed , ptype, 
			(uint8_t *)buffer + a->v.s.start, a->v.s.end - a->v.s.start);
		if (n<=0)
			return -1;
		int i;
		int r =0;
		for (i=0;i<n;i++) {
			r |= unpack_array(ptype , buffer , &(ctx->a[i]) , out);
		}
		if (r)
			return -1;
		return 0;
	}
	switch(ptype) {
	case PTYPE_DOUBLE:
		return write_real(ctype, read_double(a), out);
	case PTYPE_FLOAT:
		return write_real(ctype, read_float(a), out);
	case PTYPE_INT64:
	case PTYPE_UINT64:
	case PTYPE_INT32:
	case PTYPE_UINT32:
	case PTYPE_FIXED32:
	case PTYPE_FIXED64:
	case PTYPE_SFIXED32:
	case PTYPE_SFIXED64:
	case PTYPE_ENUM:	// enum must be integer type in pattern mode
	case PTYPE_BOOL:
		return write_integer(ctype, a , out);
	case PTYPE_SINT32: {
		struct longlong temp = a->v.i;
		varint_dezigzag32(&temp);
		return write_longlong(ctype, &temp , out);
	}
	case PTYPE_SINT64: {
		struct longlong temp = a->v.i;
		varint_dezigzag64(&temp);
		return write_longlong(ctype, &temp , out);
	}
	case PTYPE_MESSAGE: 
		((union _pbc_var *)out)->m.buffer = buffer + a->v.s.start;
		((union _pbc_var *)out)->m.len = a->v.s.end - a->v.s.start;
		return 0;
	case PTYPE_STRING:
		((union _pbc_var *)out)->s.str = buffer + a->v.s.start;
		((union _pbc_var *)out)->s.len = a->v.s.end - a->v.s.start;
		return 0;
	}
	return -1;
}
Example #18
0
static void load(Space *s, uint8_t old_type, int32_t &addr) {
	if (!s->setup_nums(3, 3)) {
		debug("Failed to set up polar axes");
		s->cancel_update();
		return;
	}
	PRIVATE(s).max_r = read_float(addr);
}
Example #19
0
static void
push_value_array(pbc_array array, struct _field *f, struct atom * a, uint8_t *buffer) {
	pbc_var v;

	switch (f->type) {
	case PTYPE_DOUBLE:
		v->real = read_double(a);
		break;
	case PTYPE_FLOAT:
		v->real = (double) read_float(a);
		break;
	case PTYPE_ENUM:
		v->e.id = a->v.i.low;
		v->e.name = _pbcM_ip_query(f->type_name.e->id , a->v.i.low);
		break;
	case PTYPE_INT64:
	case PTYPE_UINT64:
	case PTYPE_INT32:
	case PTYPE_UINT32:
	case PTYPE_FIXED32:
	case PTYPE_FIXED64:
	case PTYPE_SFIXED32:
	case PTYPE_SFIXED64:
	case PTYPE_BOOL:
		v->integer = a->v.i;
		break;
	case PTYPE_SINT32: 
		v->integer = a->v.i;
		varint_dezigzag32(&(v->integer));
		break;
	case PTYPE_SINT64:
		v->integer = a->v.i;
		varint_dezigzag64(&(v->integer));
		break;
	case PTYPE_STRING:
		read_string_var(v,a,f,buffer);
		break;
	case PTYPE_BYTES:
		v->s.str = (const char *)(buffer + a->v.s.start);
		v->s.len = a->v.s.end - a->v.s.start;
		break;
	case PTYPE_MESSAGE: {
		struct pbc_rmessage message;
		_pbc_rmessage_new(&message, f->type_name.m , 
			buffer + a->v.s.start , 
			a->v.s.end - a->v.s.start);
		if (message.msg == NULL)
			return;
		v->p[0] = message.msg;
		v->p[1] = message.index;
		break;
	}
	default:
		return;
	}

	_pbcA_push(array,v);
}
Example #20
0
		size_t CameraMessage::deserialize(unsigned char *const read_buffer) {
			size_t len = getSize();
			read_float(read_buffer, 12, &_camera._eyex);
			read_float(read_buffer, 16, &_camera._eyey);
			read_float(read_buffer, 20, &_camera._eyez);

			read_float(read_buffer, 24, &_camera._centerx);
			read_float(read_buffer, 28, &_camera._centery);
			read_float(read_buffer, 32, &_camera._centerz);

			read_float(read_buffer, 36, &_camera._upx);
			read_float(read_buffer, 40, &_camera._upy);
			read_float(read_buffer, 44, &_camera._upz);
			return len;
		}
Example #21
0
/*
 *  read_cd()
 *
 *  Read in from the keyboard the details of one CD
 */
void read_cd(cd_t *cd)
{
	read_string("Title? ", cd->title, sizeof cd->title);
#ifndef NOARTIST
	read_string("Artist? ", cd->artist, sizeof cd->artist);
#endif
	cd->tracks = read_int("Number of tracks? ");
	cd->album = yesno("Is the CD an Album");
	cd->price = read_float("Retail price (e.g. 4.65)? ");
}
Example #22
0
static void read_field(FILE *f, const save_field_t *field, void *base)
{
    void *p = (byte *)base + field->ofs;
    int i;

    switch (field->type) {
    case F_BYTE:
        read_data(p, field->size, f);
        break;
    case F_SHORT:
        for (i = 0; i < field->size; i++) {
            ((short *)p)[i] = read_short(f);
        }
        break;
    case F_INT:
        for (i = 0; i < field->size; i++) {
            ((int *)p)[i] = read_int(f);
        }
        break;
    case F_FLOAT:
        for (i = 0; i < field->size; i++) {
            ((float *)p)[i] = read_float(f);
        }
        break;
    case F_VECTOR:
        read_vector(f, (vec_t *)p);
        break;

    case F_LSTRING:
        *(char **)p = read_string(f);
        break;
    case F_ZSTRING:
        read_zstring(f, (char *)p, field->size);
        break;

    case F_EDICT:
        *(edict_t **)p = read_index(f, sizeof(edict_t), g_edicts, game.maxentities - 1);
        break;
    case F_CLIENT:
        *(gclient_t **)p = read_index(f, sizeof(gclient_t), game.clients, game.maxclients - 1);
        break;
    case F_ITEM:
        *(gitem_t **)p = read_index(f, sizeof(gitem_t), itemlist, game.num_items - 1);
        break;

    case F_POINTER:
        *(void **)p = read_pointer(f, field->size);
        break;

    default:
        gi.error("%s: unknown field type", __func__);
    }
}
Example #23
0
/* returns false if a option was missing */
bool Profile::load_profile(const char *section) {
  int ires, *tvar;
  float fres, *fvar;
  bool tres, res = true;
  struct stat st;
  
  if(!cfg) return(false); /* no setup() called */
  if(stat(profile_path, &st) == -1) return(false); /* file not there */

  for(int i=0;cfg[i].name;i++) {
    
    switch(cfg[i].type) {

    case cfgINT:
      tvar = (int*)cfg[i].var;
      ires = read_int(section,cfg[i].name);
      *tvar = (ires<0) ? atoi(cfg[i].defval) : ires;
      func("load_profile(%s) parsed %s value %i",
	   section, cfg[i].name, *(int*)cfg[i].var);
      res &= (ires>=0);
      break;

    case cfgSTR:
      tres = read_str(section,cfg[i].name,(char*)cfg[i].var);
      if(!tres) {
	snprintf((char*)cfg[i].var,MAX_VALUE_SIZE,"%s",cfg[i].defval);
	res = false;
      }
      func("load_profile(%s) parsed %s value %s",
	   section, cfg[i].name,(char*)cfg[i].var);
      break;

    case cfgFLOAT:
      fvar = (float*)cfg[i].var;
      fres = read_float(section,cfg[i].name);
      if(fres==-1.0f) {
	sscanf(cfg[i].defval,"%f",fvar);
	res = false; }
      else *fvar = fres;
      func("load_profile(%s) parsed %s value %.4f",
	   section, cfg[i].name, *(float*)cfg[i].var);
      break;

    case cfgNULL: break;

    }
  }
  return(res);
}
Example #24
0
int32_t main(void){
	gain g = { 0.0, 0.0, 0.0};
	
	uint32_t index = 0;
	
	int32_t size;
	uint8_t data_rx[64];
	uint8_t data_tx = 0x00;
	uint32_t start, end;
	
	//初期化開始
	conio_init(57600UL);
	
	Init_timer();
	InitLED();
	rcin_enable(0);
	
	Init_i2c();
	Init_fram();
	Init_DT();
	
	printf("Initialize OK.\r\n");
	//初期化終了
	
	i2c->Cfg.SlaveAddr = 0x42;
	i2c->Cfg.BaudRate = 400000;
	
	g.p_gain = read_float(0);
	g.i_gain = read_float(4);
	g.d_gain = read_float(8);
	
	printf("%f, %f, %f\r\n", g.p_gain, g.i_gain, g.d_gain);
	
	while(1){
	} 
}
Example #25
0
void ask_numbers(void)
{
        int i;
        float real[5] = {0.f},
              rounded[5] = {0.f};

        for (i = 0; i < 5; ++i) {
                read_float("Syötä reaaliluku: ", &real[i]);
                rounded[i] = floor(real[i] + 0.5f);
        }
        printf("Luku\tAlkuperäinen\t\tPyöristetty\n");
        for (i = 0; i < 5; ++i) {
                printf("%i\t%.6f\t\t%.1f\n", i+1, real[i], rounded[i]);
        }
}
static void eload(Space *s, uint8_t old_type, int32_t &addr) {
	uint8_t num = read_8(addr);
	if (!s->setup_nums(num, num)) {
		debug("Failed to set up extruder axes");
		uint8_t n = min(s->num_axes, s->num_motors);
		if (!s->setup_nums(n, n)) {
			debug("Trouble!  Failed to abort.  Cancelling.");
			s->cancel_update();
		}
	}
	for (int a = EDATA(s).num_axes; a < s->num_axes; ++a) {
		s->axis[a]->type_data = new ExtruderAxisData;
		for (int i = 0; i < 3; ++i)
			EADATA(s, a).offset[i] = 0;
	}
	EDATA(s).num_axes = s->num_axes;
	bool move = false;
	if (motors_busy && !computing_move && settings.queue_start == settings.queue_end && !settings.queue_full) {
		move = true;
		queue[settings.queue_end].probe = false;
		queue[settings.queue_end].cb = false;
		queue[settings.queue_end].f[0] = INFINITY;
		queue[settings.queue_end].f[1] = INFINITY;
		for (int i = 0; i < spaces[0].num_axes; ++i) {
			queue[settings.queue_end].data[i] = spaces[0].axis[i]->settings.current;
			for (int ss = 0; ss < 2; ++ss)
				queue[settings.queue_end].data[i] = space_types[spaces[ss].type].unchange0(&spaces[ss], i, queue[settings.queue_end].data[i]);
			if (i == 2)
				queue[settings.queue_end].data[i] -= zoffset;
		}
		for (int i = spaces[0].num_axes; i < QUEUE_LENGTH; ++i) {
			queue[settings.queue_end].data[i] = NAN;
		}
		cpdebug(0, 0, "eload end");
		settings.queue_end = (settings.queue_end + 1) % QUEUE_LENGTH;
		// This shouldn't happen and causes communication problems, but if you have a 1-item buffer it is correct.
		if (settings.queue_end == settings.queue_start)
			settings.queue_full = true;
	}
	for (int a = 0; a < s->num_axes; ++a) {
		for (int o = 0; o < 3; ++o)
			EADATA(s, a).offset[o] = read_float(addr);
	}
	if (move) {
		next_move();
		buffer_refill();
	}
}
Example #27
0
int crf1mm_get_feature(crf1mm_t* model, int fid, crf1mm_feature_t* f)
{
    uint8_t *p = NULL;
    uint32_t val = 0;
    uint32_t offset = model->header->off_features + CHUNK_SIZE;
    offset += FEATURE_SIZE * fid;
    p = model->buffer + offset;
    p += read_uint32(p, &val);
    f->type = val;
    p += read_uint32(p, &val);
    f->src = val;
    p += read_uint32(p, &val);
    f->dst = val;
    p += read_float(p, &f->weight);
    return 0;
}
Example #28
0
// Parses the next statement and leaves the counter on the first character following
// the statement. Returns 1 if there was a statements, 0 if end of string was reached
// or there was an error (check state.status_code).
static bool next_statement(char *letter, float *float_ptr, char *line, uint8_t *char_counter) {
  if(!line[*char_counter]) return false; // No more statements
  
  *letter = line[*char_counter];
  if((*letter < 'A') || (*letter > 'Z')) {
    FAIL(STATUS_EXPECTED_COMMAND_LETTER);
    return false;
  }
  (*char_counter)++;
  if(!read_float(line, char_counter, float_ptr)) {
    FAIL(STATUS_BAD_NUMBER_FORMAT); 
    return false;
  }

  return true;
}
Example #29
0
VALUE read_any_raw(unsigned char **pData) {
  switch(peek_1(pData)) {
    case ERL_SMALL_INT:
      return read_small_int(pData);
      break;
    case ERL_INT:
      return read_int(pData);
      break;
    case ERL_FLOAT:
      return read_float(pData);
      break;
    case ERL_ATOM:
      return read_atom(pData);
      break;
    case ERL_PID:
      return read_pid(pData);
      break;
    case ERL_SMALL_TUPLE:
      return read_small_tuple(pData);
      break;
    case ERL_LARGE_TUPLE:
      return read_large_tuple(pData);
      break;
    case ERL_NIL:
      return read_nil(pData);
      break;
    case ERL_STRING:
      return read_string(pData);
      break;
    case ERL_LIST:
      return read_list(pData);
      break;
    case ERL_BIN:
      return read_bin(pData);
      break;
    case ERL_SMALL_BIGNUM:
      return read_small_bignum(pData);
      break;
    case ERL_LARGE_BIGNUM:
      return read_large_bignum(pData);
      break;
    case ERL_NEW_REF:
      return read_new_reference(pData);
      break;
  }
  return Qnil;
}
Example #30
0
File: gcode.c Project: ikrase/grbl
// Parses the next statement and leaves the counter on the first character following
// the statement. Returns 1 if there was a statements, 0 if end of string was reached
// or there was an error (check state.status_code).
static int next_statement(char *letter, float *float_ptr, char *line, uint8_t *char_counter) 
{
  if (line[*char_counter] == 0) {
    return(0); // No more statements
  }
  
  *letter = line[*char_counter];
  if((*letter < 'A') || (*letter > 'Z')) {
    FAIL(STATUS_EXPECTED_COMMAND_LETTER);
    return(0);
  }
  (*char_counter)++;
  if (!read_float(line, char_counter, float_ptr)) {
    FAIL(STATUS_BAD_NUMBER_FORMAT); 
    return(0);
  };
  return(1);
}