Exemple #1
0
void svg_write_legend(struct plot *plot)
{
	int legend_line_x = axis_x_off(graph_width) + legend_x_off;
	int legend_line_y = axis_y_off(graph_height) + legend_y_off;
	int i;

	if (plot->legend_index == 0)
		return;

	snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" "
		 "fill=\"white\" filter=\"url(#shadow)\"/>\n",
		 legend_line_x - 15,
		 legend_line_y - 12,
		 legend_width,
		 plot->legend_index * legend_font_size + legend_font_size / 2 + 12);

	write_check(plot->fd, line, strlen(line));
	for (i = 0; i < plot->legend_index; i++) {
		write_check(plot->fd, plot->legend_lines[i],
		      strlen(plot->legend_lines[i]));
		free(plot->legend_lines[i]);
	}
	free(plot->legend_lines);
	plot->legend_lines = NULL;
	plot->legend_index = 0;
}
Exemple #2
0
/* Description: This functions determines whether the camera should send a
                continuous stream of packets or just one packet.
   Parameters:  fd: serial port file descriptor
                on: if on == 1, only one packet is send
                    if on == 0, a continuous stream of packets is send
   Returns:     1: If the command was successfully sent to the camera
                0: Otherwise
*/
int poll_mode(int fd, int on)
{
	if(on)
		return write_check(fd, "PM 1\r", 5);
	else
		return write_check(fd, "PM 0\r", 5);
}
Exemple #3
0
/*
 * create evenly spread out ticks along the y axis.
 * The ticks are labeled as it goes
 */
void set_yticks(struct plot *plot, int num_ticks, int first, int last, char *units)
{
	int pixels_per_tick = graph_height / num_ticks;
	int step = (last - first) / num_ticks;
	int i;
	int tick_y = 0;
	int text_x = axis_x() - 6;
	int tick_x = axis_x();
	char *anchor = "end";

	for (i = 0; i < num_ticks; i++) {
		if (i != 0) {
			snprintf(line, line_len, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" "
				 "style=\"stroke:lightgray;stroke-width:2;stroke-dasharray:9,12;\"/>\n",
				tick_x, axis_y_off(tick_y),
				axis_x_off(graph_width), axis_y_off(tick_y));
			write_check(plot->fd, line, strlen(line));
		}

		snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
			 "fill=\"black\" style=\"text-anchor: %s\">%d%s</text>\n",
			text_x,
			axis_y_off(tick_y - tick_font_size / 2),
			font_family, tick_font_size, anchor, first + step * i, units);
		write_check(plot->fd, line, strlen(line));
		tick_y += pixels_per_tick;
	}
	snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
		 "fill=\"black\" style=\"text-anchor: %s\">%d%s</text>\n",
		 text_x, axis_y_off(graph_height), font_family, tick_font_size, anchor, last, units);
	write_check(plot->fd, line, strlen(line));
}
Exemple #4
0
/*
 * this draws a backing rectangle for the plot and it
 * also creates a new svg element so our offsets can
 * be relative to this one plot.
 */
void setup_axis(struct plot *plot)
{
	int len;
	int fd = plot->fd;
	int bump_height = tick_font_size * 3 + axis_label_font_size;
	int local_legend_width = legend_width;

	if (plot->no_legend)
		local_legend_width = 0;

	plot->total_width = axis_x_off(graph_width) + graph_left_pad / 2 + local_legend_width;
	plot->total_height = axis_y() + tick_label_pad + tick_font_size;

	if (plot->add_xlabel)
		plot->total_height += bump_height;

	/* backing rect */
	snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"%d\" "
		 "height=\"%d\" fill=\"white\" stroke=\"none\"/>",
		 plot->start_x_offset,
		plot->start_y_offset, plot->total_width + 40,
		plot->total_height + 20);
	len = strlen(line);
	write_check(fd, line, len);

	snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"%d\" "
		 "filter=\"url(#shadow)\" "
		 "height=\"%d\" fill=\"white\" stroke=\"none\"/>",
		 plot->start_x_offset + 15,
		plot->start_y_offset, plot->total_width, plot->total_height);
	len = strlen(line);
	write_check(fd, line, len);
	plot->total_height += 20;
	plot->total_width += 20;

	if (plot->total_height + plot->start_y_offset > final_height)
		final_height = plot->total_height + plot->start_y_offset;
	if (plot->start_x_offset + plot->total_width + 40 > final_width)
		final_width = plot->start_x_offset + plot->total_width + 40;

	/* create an svg object for all our coords to be relative against */
	snprintf(line, line_len, "<svg x=\"%d\" y=\"%d\">\n", plot->start_x_offset, plot->start_y_offset);
	write_check(fd, line, strlen(line));

	snprintf(line, 1024, "<path d=\"M%d %d h %d V %d H %d Z\" stroke=\"black\" stroke-width=\"2\" fill=\"none\"/>\n",
		 axis_x(), axis_y(),
		 graph_width + graph_inner_x_margin * 2, axis_y_off(graph_height) - graph_inner_y_margin,
		 axis_x());
	len = strlen(line);
	write_check(fd, line, len);
}
Exemple #5
0
SYSCALL_DEFINE1(orientlock_write, struct orientation_range *, orient)
{
	int got_lock = 0;

	spin_lock(&system_call_lock);
	got_lock = write_check(orient);
	if (!got_lock) {
		spin_unlock(&system_call_lock);
		wait_event_interruptible(write_wait_queue, write_check(orient));
	} else
		spin_unlock(&system_call_lock);

	return got_lock;
}
Exemple #6
0
void svg_write_time_line(struct plot *plot, int col)
{
	snprintf(line, line_len, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" "
				 "style=\"stroke:black;stroke-width:2;\"/>\n",
				 axis_x_off(col), axis_y_off(0),
				 axis_x_off(col), axis_y_off(graph_height));
	write_check(plot->fd, line, strlen(line));
}
Exemple #7
0
static void svg_add_io(int fd, double row, double col, double width, double height, char *color)
{
	float rx = 0;

	snprintf(line, line_len, "<rect x=\"%.2f\" y=\"%.2f\" width=\"%.1f\" height=\"%.1f\" "
		 "rx=\"%.2f\" style=\"stroke:none;fill:%s;stroke-width:0\"/>\n",
		 axis_x_off_double(col), axis_y_off_double(row), width, height, rx, color);
	write_check(fd, line, strlen(line));
}
Exemple #8
0
/*
 * this draws a backing rectangle for the plot and it
 * also creates a new svg element so our offsets can
 * be relative to this one plot.
 */
void setup_axis_spindle(struct plot *plot)
{
	int len;
	int fd = plot->fd;
	int bump_height = tick_font_size * 3 + axis_label_font_size;

	legend_x_off = -60;

	plot->total_width = axis_x_off(graph_width) + legend_width;
	plot->total_height = axis_y() + tick_label_pad + tick_font_size;

	if (plot->add_xlabel)
		plot->total_height += bump_height;

	/* backing rect */
	snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"%d\" "
		 "height=\"%d\" fill=\"white\" stroke=\"none\"/>",
		 plot->start_x_offset,
		plot->start_y_offset, plot->total_width + 10,
		plot->total_height + 20);
	len = strlen(line);
	write_check(fd, line, len);

	snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"%d\" "
		 "filter=\"url(#shadow)\" "
		 "height=\"%d\" fill=\"white\" stroke=\"none\"/>",
		 plot->start_x_offset + 15,
		plot->start_y_offset, plot->total_width - 30,
		plot->total_height);
	len = strlen(line);
	write_check(fd, line, len);
	plot->total_height += 20;

	if (plot->total_height + plot->start_y_offset > final_height)
		final_height = plot->total_height + plot->start_y_offset;
	if (plot->start_x_offset + plot->total_width + 40 > final_width)
		final_width = plot->start_x_offset + plot->total_width + 40;

	/* create an svg object for all our coords to be relative against */
	snprintf(line, line_len, "<svg x=\"%d\" y=\"%d\">\n", plot->start_x_offset, plot->start_y_offset);
	write_check(fd, line, strlen(line));

}
Exemple #9
0
/*
 * call-seq:
 *
 *	io.kgio_syssend(str, flags) -> nil, String or :wait_writable
 *
 * Returns nil if the write was completed in full.
 *
 * Returns a String containing the unwritten portion if EAGAIN
 * was encountered, but some portion was successfully written.
 *
 * Returns :wait_writable if EAGAIN is encountered and nothing
 * was written.
 *
 * This method is only available on Ruby 1.9.3 or later.
 */
static VALUE kgio_syssend(VALUE io, VALUE str, VALUE flags)
{
	struct wr_args a;
	long n;

	a.flags = NUM2INT(flags);
	prepare_write(&a, io, str);
	if (a.flags & MY_MSG_DONTWAIT) {
		do {
			n = (long)send(a.fd, a.ptr, a.len, a.flags);
		} while (write_check(&a, n, "send", 0) != 0);
	} else {
		do {
			n = (long)rb_thread_io_blocking_region(
						nogvl_send, &a, a.fd);
		} while (write_check(&a, n, "send", 0) != 0);
	}
	return a.buf;
}
Exemple #10
0
void vulkan_buffer::write(const compute_queue& cqueue, const void* src,
						  const size_t size_, const size_t offset) {
	if(buffer == nullptr) return;
	
	const size_t write_size = (size_ == 0 ? size : size_);
	if(!write_check(size, write_size, offset, flags)) return;
	
	GUARD(lock);
	write_memory_data(cqueue, src, write_size, offset, 0, "failed to write buffer");
}
Exemple #11
0
int close_plot_file(struct plot *plot)
{
	int ret;
	ret = lseek(plot->fd, 0, SEEK_SET);
	if (ret == (off_t)-1) {
		perror("seek");
		exit(1);
	}
	final_width = ((final_width  + 1) / 2) * 2;
	final_height = ((final_height  + 1) / 2) * 2;
	snprintf(line, line_len, "<svg  xmlns=\"http://www.w3.org/2000/svg\" "
		 "width=\"%d\" height=\"%d\">\n",
		 final_width, final_height);
	write_check(plot->fd, line, strlen(line));
	snprintf(line, line_len, "<rect x=\"0\" y=\"0\" width=\"%d\" "
		 "height=\"%d\" fill=\"white\"/>\n", final_width, final_height);
	write_check(plot->fd, line, strlen(line));
	close(plot->fd);
	plot->fd = 0;
	return 0;
}
Exemple #12
0
void set_plot_label(struct plot *plot, char *label)
{
	int len;
	int fd = plot->fd;

	snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" "
		 "font-size=\"%d\" fill=\"black\" style=\"text-anchor: %s\">%s</text>\n",
		 axis_x() + graph_width / 2,
		 plot_label_height / 2,
		font_family, plot_label_font_size, "middle", label);
	len = strlen(line);
	write_check(fd, line, len);
}
void DTemperature::okBtn_click()
{
    int temp=tempLE->text().toDouble()*10;
    int time=timeLE->text().toInt();
    int temp_low=temp%256;
    int temp_hign=temp/256;
    int time_low=time%256;
    int time_hign=time/256;
    int temp_addr=26+combo->currentIndex()*2;
    int time_addr=27+combo->currentIndex()*2;

    int check_low,check_hign;
    write_check(temp_addr,temp,0x01,&check_low,&check_hign);
    QByteArray array_temp,array_time;
    array_temp.append(0x81);
    array_temp.append(0x81);
    array_temp.append(0x43);
    array_temp.append(temp_addr);
    array_temp.append(temp_low);
    array_temp.append(temp_hign);
    array_temp.append(check_low);
    array_temp.append(check_hign);

    write_check(time_addr,time,0x01,&check_low,&check_hign);
    array_time.append(0x81);
    array_time.append(0x81);
    array_time.append(0x43);
    array_time.append(time_addr);
    array_time.append(time_low);
    array_time.append(time_hign);
    array_time.append(check_low);
    array_time.append(check_hign);

    emit tempAndTime(array_temp);
    QTime dieTime = QTime::currentTime().addMSecs(150);
    while( QTime::currentTime() < dieTime )
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    emit tempAndTime(array_time);
}
Exemple #14
0
/* Description: This functions sets the servo position given the servo number
                and the angle (note: angle = 0 denotes servo position = 128
                in terms of camera's values)
   Parameters:  number[i] = c;fd: serial port file descriptor
                servo_num: the servo which we are setting the position
                I am using 0:pan  1:tilt
   Returns:     1: If the command was successfully sent to the camera
                0: Otherwise
*/
int set_servo_position(int fd, int servo_num, int angle)
{
	// change the angle into camera's format
	int position = ZERO_POSITION + angle;
	// for servo position. I am using angle 0
	char comm[10];
	// corresponding to the default servo pos. 128
	int value[] = {servo_num, position};
	// generate the command using the values
	make_command("SV ", value, sizeof(value)/sizeof(int), comm);
	printf("servo %d new position: %d\n", servo_num, angle);
	return write_check(fd, comm, 5);      // write the command to the camera
}
Exemple #15
0
static VALUE my_write(VALUE io, VALUE str, int io_wait)
{
	struct io_args a;
	long n;

	prepare_write(&a, io, str);
	set_nonblocking(a.fd);
retry:
	n = (long)write(a.fd, a.ptr, a.len);
	if (write_check(&a, n, "write", io_wait) != 0)
		goto retry;
	return a.buf;
}
Exemple #16
0
/* Description: The function enables/disables automatic servoing
   Parameters:  fd: serial port handler, on: determines whethere to enable(on=1)
                    or disable(on=0)
   Returns:    0: if the camera fails to write command  1: otherwise
*/
int auto_servoing(int fd, int on)
{
  // Enabling Auto Servoing Mode for both servos
	if(on)
	{
		if(!write_check(fd, "SM 15\r", 5))
		{
			printf("CMUCAM II ERROR: Enabling auto-servo failed.\n");
			return 0;
		}
		return 1;
	}
	else
	{
		if(!write_check(fd, "SM 0\r", 5))
		{
			printf("CMUCAM II ERROR: Disabling auto-servo faild.\n");
			return 0;
		}
		return 1;
	}
}
Exemple #17
0
/* Description: This functions starts to Track a Color. It takes in the minimum
                and maximum RGB values and outputs a type T packet. This packet
                by default returns the middle mass x and y coordinates, the
                bounding box, the number of pixles tracked, and a confidence
                values.
   cc:          the min & max RGB values of the blob to be tracked.
*/
void track_blob( int fd, color_config cc )
{
	char cmd[28];
	int value[] = {cc.rmin, cc.rmax, cc.gmin, cc.gmax, cc.bmin, cc.bmax};
	range = cc;

	make_command("TC ", value, sizeof(value)/sizeof(int), cmd);
	if(!write_check(fd, cmd, 4))
	{
		printf("ERROR; track color failed.\n");
		return;
	}
}
Exemple #18
0
/* Description: This function gets an image from the camera using the
                specified channel as a filter.
   Parameters:  fd: serial port handler, chan_num: the channel number
   Returns:     the image as an F packet
*/
int read_image (int fd, int chan_num, packet_f *fpacket)
{
	char fpack_chars [F_PACKET_LENGTH];
	switch (chan_num)
	{
		case 0:
		{
			write_check (fd, "SF 0\r", 4);
			break;
		}
		case 1:
		{
			write_check (fd, "SF 1\r", 4);
			break;
		}
		case 2:
		{
			write_check (fd, "SF 2\r", 4);
			break;
		}
		case -1:
		{
			write_check (fd, "SF \r", 4);
			break;
		}
		default:
		{
			printf ("Cmucam2: invalid channel number!\n");
			break;
		}
	}


	if (read_f_packet (fd, fpack_chars) != 0)
		return -1;

	return set_f_packet (fpacket, fpack_chars, chan_num);
}
Exemple #19
0
/* draw a plot title.  This should be done only once,
 * and it bumps the plot width/height numbers by
 * what it draws.
 *
 * Call this before setting up the first axis
 */
void set_plot_title(struct plot *plot, char *title)
{
	int len;
	int fd = plot->fd;

	plot->total_height = plot_title_height;
	plot->total_width = axis_x_off(graph_width) + graph_left_pad / 2 + legend_width;

	/* backing rect */
	snprintf(line, line_len, "<rect x=\"0\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"white\" stroke=\"none\"/>",
		plot->start_y_offset, plot->total_width + 40, plot_title_height + 20);
	len = strlen(line);
	write_check(fd, line, len);

	snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
		 "font-weight=\"bold\" fill=\"black\" style=\"text-anchor: %s\">%s</text>\n",
		 axis_x_off(graph_width / 2),
		plot->start_y_offset + plot_title_height / 2,
		font_family, plot_title_font_size, "middle", title);
	plot->start_y_offset += plot_title_height;
	len = strlen(line);
	write_check(fd, line, len);
}
Exemple #20
0
/*
 * This method behaves like Kgio::PipeMethods#kgio_write, except
 * it will use send(2) with the MSG_DONTWAIT flag on sockets to
 * avoid unnecessary calls to fcntl(2).
 */
static VALUE my_send(VALUE io, VALUE str, int io_wait)
{
	struct io_args a;
	long n;

	prepare_write(&a, io, str);
retry:
	n = (long)send(a.fd, a.ptr, a.len, MSG_DONTWAIT);
	if (write_check(&a, n, "send", io_wait) != 0)
		goto retry;
	if (TYPE(a.buf) != T_SYMBOL)
		kgio_autopush_send(io);
	return a.buf;
}
Exemple #21
0
/* Description: This function gets the position of the specified servo.
   Parameters:  fd: serial port handler, servo_num: the servo number whose size
                    is required
   Returns:     the position of the servo
*/
int get_servo_position(int fd, int servo_num)
{
	int servo_position;
	int i;
	char number[3];
	char c = 0;

	if(servo_num)               // set position of servo 1
		write_check(fd, "GS 1\r", 4);
	else		               // set position of servo 0
		write_check(fd, "GS 0\r", 4);

	for(i = 0; 1; i++)
	{
		read(fd, &c, 1);
		if(c == '\r')
			break;
		number[i] = c;
	}
	read(fd, &c, 1);           // read the : at the end
	servo_position = atoi(number);
	return servo_position - ZERO_POSITION;
}
void DTemperature::stop_click()
{
    int check_low,check_hign;
    write_check(0x15,0x0C,0x01,&check_low,&check_hign);
    int sz=0;
    QByteArray array_temp;
    array_temp.append(0x81);
    array_temp.append(0x81);
    array_temp.append(0x43);
    array_temp.append(0x15);
    array_temp.append(0x0C);
    array_temp.append(sz);
    array_temp.append(check_low);
    array_temp.append(check_hign);
    emit tempAndTime(array_temp);
}
Exemple #23
0
void set_ylabel(struct plot *plot, char *label)
{
	int len;
	int fd = plot->fd;

	snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" "
		 "transform=\"rotate(-90 %d %d)\" font-weight=\"bold\" "
		 "font-size=\"%d\" fill=\"black\" style=\"text-anchor: %s\">%s</text>\n",
		 graph_left_pad / 2 - axis_label_font_size,
		 axis_y_off(graph_height / 2),
		 font_family,
		 graph_left_pad / 2 - axis_label_font_size,
		 (int)axis_y_off(graph_height / 2),
		 axis_label_font_size, "middle", label);
	len = strlen(line);
	write_check(fd, line, len);
}
Exemple #24
0
void write_svg_header(int fd)
{
	char *spaces = "                                                    \n";
	char *header = "<svg  xmlns=\"http://www.w3.org/2000/svg\">\n";
	char *filter1 ="<filter id=\"shadow\">\n "
		"<feOffset result=\"offOut\" in=\"SourceAlpha\" dx=\"4\" dy=\"4\" />\n "
		"<feGaussianBlur result=\"blurOut\" in=\"offOut\" stdDeviation=\"2\" />\n "
		"<feBlend in=\"SourceGraphic\" in2=\"blurOut\" mode=\"normal\" />\n "
		"</filter>\n";
	char *filter2 ="<filter id=\"textshadow\" x=\"0\" y=\"0\" width=\"200%\" height=\"200%\">\n "
		"<feOffset result=\"offOut\" in=\"SourceAlpha\" dx=\"1\" dy=\"1\" />\n "
		"<feGaussianBlur result=\"blurOut\" in=\"offOut\" stdDeviation=\"1.5\" />\n "
		"<feBlend in=\"SourceGraphic\" in2=\"blurOut\" mode=\"normal\" />\n "
		"</filter>\n";
	char *filter3 ="<filter id=\"labelshadow\" x=\"0\" y=\"0\" width=\"200%\" height=\"200%\">\n "
		"<feOffset result=\"offOut\" in=\"SourceGraphic\" dx=\"3\" dy=\"3\" />\n "
		"<feColorMatrix result=\"matrixOut\" in=\"offOut\" type=\"matrix\" "
		"values=\"0.2 0 0 0 0 0 0.2 0 0 0 0 0 0.2 0 0 0 0 0 1 0\" /> "
		"<feGaussianBlur result=\"blurOut\" in=\"offOut\" stdDeviation=\"2\" />\n "
		"<feBlend in=\"SourceGraphic\" in2=\"blurOut\" mode=\"normal\" />\n "
		"</filter>\n";
	char *defs_start = "<defs>\n";
	char *defs_close = "</defs>\n";
	final_width = 0;
	final_height = 0;

	write_check(fd, header, strlen(header));
	/* write a bunch of spaces so we can stuff in the width and height later */
	write_check(fd, spaces, strlen(spaces));
	write_check(fd, spaces, strlen(spaces));
	write_check(fd, spaces, strlen(spaces));

	write_check(fd, defs_start, strlen(defs_start));
	write_check(fd, filter1, strlen(filter1));
	write_check(fd, filter2, strlen(filter2));
	write_check(fd, filter3, strlen(filter3));
	write_check(fd, defs_close, strlen(defs_close));
}
Exemple #25
0
int set_imager_config(int fd, imager_config ic)
{
   int value[8], size = 0;                 // The numbers used in the command:
   char command[26];                       // ex. CR 5 255 19 33
   if(ic.contrast != -1)                   // If ther is a change set the values
   {
	   value[size++] = CONTRAST;
	   value[size++] = ic.contrast;
   }
   if(ic.brightness != -1)
   {
	   value[size++] = BRIGHTNESS;
	   value[size++] = ic.brightness;
   }
   if(ic.colormode != -1)
   {
	   value[size++] = COLORMODE;
	   if(ic.colormode == 0)
		   value[size++] = RGB_AWT_OFF;
	   if(ic.colormode == 1)
		   value[size++] = RGB_AWT_ON;
	   if(ic.colormode == 2)
		   value[size++] = YCRCB_AWT_OFF;
	   if(ic.colormode == 3)
		   value[size++] = YCRCB_AWT_ON;
   }
   if(ic.autogain != -1)
   {
	   value[size++] = AUTOGAIN;
	   if(ic.autogain == 0)
		   value[size++] = AUTOGAIN_OFF;
	   if(ic.autogain == 1)
		   value[size++] = AUTOGAIN_ON;
   }
   // Put the values into camera's command format:
   // ex. CR 6 105 18 44
   make_command("CR ", value, size, command);
   return write_check(fd, command, 5);         // send the command to the camera
}
Exemple #26
0
int svg_io_graph_movie_array_spindle(struct plot *plot, struct pid_plot_history *pph)
{
	double cell_index;
	int i;
	int num_circles = 0;
	double cells_per_circle;
	double circle_num;
	double degrees_per_cell;
	double rot;
	double center_x;
	double center_y;
	double graph_width_extra = graph_width + graph_circle_extra;
	double graph_height_extra = graph_height + graph_circle_extra;
	double radius;;

	if (graph_width_extra > graph_height_extra)
		graph_width_extra = graph_height_extra;

	if (graph_width_extra < graph_height_extra)
		graph_height_extra = graph_width_extra;

	radius = graph_width_extra;

	center_x = axis_x_off_double(graph_width_extra / 2);
	center_y = axis_y_off_double(graph_height_extra / 2);

	snprintf(line, line_len, "<g transform=\"rotate(%.4f, %.2f, %.2f)\"> "
		 "<circle cx=\"%.2f\" cy=\"%.2f\" "
		 "stroke=\"black\" stroke-width=\"6\" "
		 "r=\"%.2f\" fill=\"none\"/>\n",
		 spindle_steps * 1.2, center_x, center_y, center_x, center_y, graph_width_extra / 2);
	write_check(plot->fd, line, strlen(line));
	snprintf(line, line_len, "<circle cx=\"%.2f\" cy=\"%.2f\" "
		"stroke=\"none\" fill=\"red\" r=\"%.2f\"/>\n</g>\n",
		axis_x_off_double(graph_width_extra), center_y, 4.5);
	write_check(plot->fd, line, strlen(line));
	spindle_steps += 0.01;

	radius = floor(radius / 2);
	num_circles = radius / 4 - 3;
	cells_per_circle = pph->history_max / num_circles;
	degrees_per_cell = 360 / cells_per_circle;

	for (i = 0; i < pph->num_used; i++) {
		cell_index = pph->history[i];
		circle_num = floor(cell_index / cells_per_circle);
		rot = cell_index - circle_num * cells_per_circle;
		circle_num = num_circles - circle_num;
		radius = circle_num * 4;

		rot = rot * degrees_per_cell;
		rot -= spindle_steps;
		snprintf(line, line_len, "<path transform=\"rotate(%.4f, %.2f, %.2f)\" "
			 "d=\"M %.2f %.2f a %.2f %.2f 0 0 1 0 5\" "
			 "stroke=\"%s\" stroke-width=\"4\"/>\n",
			 -rot, center_x, center_y,
			 axis_x_off_double(graph_width_extra / 2 + radius) + 8, center_y,
			 radius, radius, pph->color);

		write_check(plot->fd, line, strlen(line));
	}
	return 0;
}
Exemple #27
0
int power(int fd, int on)
{
	if(on)
		return write_check(fd, "CP 1\r", 5);
	return write_check(fd, "CP 0\r", 5);
}
Exemple #28
0
int svg_line_graph(struct plot *plot, struct graph_line_data *gld, char *color, int thresh1, int thresh2)
{
	unsigned int i;
	double val;
	double avg;
	int rolling;
	int fd = plot->fd;
	char *start = "<path d=\"";
	double yscale = ((double)gld->max) / graph_height;
	double xscale = (double)(gld->max_seconds - gld->min_seconds - 1) / graph_width;
	char c = 'M';
	double x;
	int printed_header = 0;
	int printed_lines = 0;

	if (thresh1 && thresh2)
		rolling = 0;
	else if (rolling_avg_secs)
		rolling = rolling_avg_secs;
	else
		rolling = (gld->stop_seconds - gld->min_seconds) / 25;

	for (i = gld->min_seconds; i < gld->stop_seconds; i++) {
		avg = rolling_avg(gld->data, i, rolling);
		if (yscale == 0)
			val = 0;
		else
			val = avg / yscale;

		if (val > graph_height)
			val = graph_height;
		if (val < 0)
			val = 0;

		x = (double)(i - gld->min_seconds) / xscale;
		if (!thresh1 && !thresh2) {

			if (!printed_header) {
				write_check(fd, start, strlen(start));
				printed_header = 1;
			}

			/* in full line mode, everything in the graph is connected */
			snprintf(line, line_len, "%c %d %d ", c, axis_x_off(x), axis_y_off(val));
			c = 'L';
			write_check(fd, line, strlen(line));
			printed_lines = 1;
		} else if (avg > thresh1 || avg > thresh2) {
			int len = 10;
			if (!printed_header) {
				write_check(fd, start, strlen(start));
				printed_header = 1;
			}

			/* otherwise, we just print a bar up there to show this one data point */
			if (i >= gld->stop_seconds - 2)
				len = -10;

			/*
			 * we don't use the rolling averages here to show high
			 * points in the data
			 */
			snprintf(line, line_len, "M %d %d h %d ", axis_x_off(x),
				 axis_y_off(val), len);
			write_check(fd, line, strlen(line));
			printed_lines = 1;
		}

	}
	if (printed_lines) {
		snprintf(line, line_len, "\" fill=\"none\" stroke=\"%s\" stroke-width=\"2\"/>\n", color);
		write_check(fd, line, strlen(line));
	}
	if (plot->timeline)
		svg_write_time_line(plot, plot->timeline);

	return 0;
}
Exemple #29
0
/*
 * create evenly spread out ticks along the xaxis.  if tick only is set
 * this just makes the ticks, otherwise it labels each tick as it goes
 */
void set_xticks(struct plot *plot, int num_ticks, int first, int last)
{
	int pixels_per_tick;
	double step;
	int i;
	int tick_y = axis_y_off(graph_tick_len) + graph_inner_y_margin;
	int tick_x = axis_x();
	int tick_only = plot->add_xlabel == 0;

	int text_y = axis_y() + tick_label_pad;

	char *middle = "middle";
	char *start = "start";

	step = find_step(first, last, num_ticks);
	/*
	 * We don't want last two ticks to be too close together so subtract
	 * 20% of the step from the interval
	 */
	num_ticks = (double)(last - first - step) / step + 1;
	pixels_per_tick = graph_width * step / (double)(last - first);

	for (i = 0; i < num_ticks; i++) {
		char *anchor;
		if (i != 0) {
			snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"2\" height=\"%d\" style=\"stroke:none;fill:black;\"/>\n",
				tick_x, tick_y, graph_tick_len);
			write_check(plot->fd, line, strlen(line));
			anchor = middle;
		} else {
			anchor = start;
		}

		if (!tick_only) {
			if (step >= 1)
				snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
					"fill=\"black\" style=\"text-anchor: %s\">%d</text>\n",
					tick_x, text_y, font_family, tick_font_size, anchor,
					(int)(first + step * i));
			else
				snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
					"fill=\"black\" style=\"text-anchor: %s\">%.2f</text>\n",
					tick_x, text_y, font_family, tick_font_size, anchor,
					first + step * i);
			write_check(plot->fd, line, strlen(line));
		}
		tick_x += pixels_per_tick;
	}

	if (!tick_only) {
		if (step >= 1)
			snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
				"fill=\"black\" style=\"text-anchor: middle\">%d</text>\n",
				axis_x_off(graph_width - 2),
				text_y, font_family, tick_font_size, last);
		else
			snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
				"fill=\"black\" style=\"text-anchor: middle\">%.2f</text>\n",
				axis_x_off(graph_width - 2),
				text_y, font_family, tick_font_size, (double)last);
		write_check(plot->fd, line, strlen(line));
	}
}
Exemple #30
0
static void close_svg(int fd)
{
	char *close_line = "</svg>\n";

	write_check(fd, close_line, strlen(close_line));
}