Beispiel #1
0
static int select_trace(int x, int y) {
    int n;
    scope_disp_t *disp = &(ctrl_usr->disp);

    min_dist = hypot(disp->width, disp->height) / 100.;
    if(min_dist < 5) min_dist = 5;
    target = -1;

    DRAWING = 0;
    select_x = x;
    select_y = y;
    for(n=0; n<16; n++) {
        scope_vert_t *vert = &(ctrl_usr->vert);
        draw_baseline(n+1, FALSE);
        if((vert->chan_enabled[n]) && (vert->data_offset[n] >= 0)) {
            draw_waveform(n+1, FALSE);
        }
    }
    draw_triggerline(ctrl_shm->trig_chan, FALSE);
    return target;
}
Beispiel #2
0
int main(int argc, char* argv[])
{
	struct wave* w;
	struct image* img;
	int width, height;
	char* in_file_name;
	char* out_file_name;
	FILE* file;
	int style = DEFAULT_STYLE;
	
	/* Options */
	int c;
	opterr = 0;
	
	print_greeting();
	
	/* Defaults */
	width = 1024;
	height = 256;
	in_file_name = "";
	out_file_name = "";
	
	while ((c = getopt (argc, argv, "W:H:hi:o:s:")) != -1)
		switch (c)
	{
		case 'W':
			width = atoi(optarg);
			DPRINTF("Width set to %d\n", width);
			break;
		case 'H':
			height = atoi(optarg);
			DPRINTF("Height set to %d\n", height);
			break;
		case 'h':
			print_help();
			return 0;
			break;
		case 'i':
			in_file_name = optarg;
			break;
		case 'o':
			out_file_name = optarg;
			break;
		case 's':
			style = MIN(MAX(atoi(optarg), 1), MAX_STYLE);
			printf("Style set to %d\n", style);
			break;
		case '?':
			fprintf (stderr, "Unknown option `-%c'.\n", optopt);
			return 1;
		default:
			abort();
	}
	
	if (argc == 1) {
		print_help();
		return 0;
	}
	
	w = ini_wave(in_file_name);
	assert(w!=NULL);
	
	DPRINTF(PRINT_DIVISION);
	DPRINTF("We seem to have a valid WAVE file!\n");
	
	/* Create image. Note width first.*/
	img = image_alloc(width, height);
	
	draw_waveform(w, img, style);
	
	/* Output where? */
	if (strlen(out_file_name) == 0) {
		asprintf(&out_file_name, "%s.png", in_file_name); /* Small leak; avoiding it would be a bit messy. */
	}
	
	/* Open */
	printf("Writing to file %s\n", out_file_name);
	file = fopen(out_file_name, "w");
	assert(file != NULL);
	
	/* Write */
	write_PNG_image_to_file(file, img);
	
	/* Close */
	image_free(img);
	fclose(file);
	
	cleanup_wave(w);
	free(w);
	
	return 0;
}
Beispiel #3
0
void refresh_display(void)
{
    int n;
    scope_disp_t *disp;
    scope_vert_t *vert;
    scope_horiz_t *horiz;
    int depth;
    double pixels_per_div, pixels_per_sec, overall_record_length;
    double screen_center_time, screen_start_time, screen_end_time;

    /* cancel any pending refresh request */
    ctrl_usr->display_refresh_timer = 0;
    /* set pointers */
    disp = &(ctrl_usr->disp);
    vert = &(ctrl_usr->vert);
    horiz = &(ctrl_usr->horiz);
    /* get window pointer */
    disp->win = disp->drawing->window;
    if (disp->win == NULL) {
	/* window isn't visible yet, do nothing */
	printf("refresh_display(): win = NULL, bailing!\n");
	return;
    }
    /* create drawing context if needed */
    if (disp->context == NULL) {
	disp->context = gdk_gc_new(disp->win);
    }

    /* get window dimensions */
    gdk_window_get_geometry(disp->win, NULL, NULL, &(disp->width),
	&(disp->height), &depth);
    /* calculate horizontal params that depend on width */
    pixels_per_div = disp->width * 0.1;
    pixels_per_sec = pixels_per_div / horiz->disp_scale;
    disp->pixels_per_sample = pixels_per_sec * horiz->sample_period;
    overall_record_length = horiz->sample_period * ctrl_shm->rec_len;
    screen_center_time = overall_record_length * horiz->pos_setting;
    screen_start_time = screen_center_time - (5.0 * horiz->disp_scale);
    disp->horiz_offset = screen_start_time * pixels_per_sec;
    disp->start_sample = screen_start_time / horiz->sample_period;
    if (disp->start_sample < 0) {
	disp->start_sample = 0;
    }
    screen_end_time = screen_center_time + (5.0 * horiz->disp_scale);
    disp->end_sample = (screen_end_time / horiz->sample_period) + 1;
    if (disp->end_sample > ctrl_shm->rec_len - 1) {
	disp->end_sample = ctrl_shm->rec_len - 1;
    }

    {
        GdkRectangle rect = {0, 0, disp->width, disp->height};
        GdkRegion *region = gdk_region_rectangle(&rect);
        gdk_window_begin_paint_region(disp->drawing->window, region);
        gdk_region_destroy(region);
    }

    DRAWING = 1;
    clear_display_window();
    draw_grid();

    /* calculate offsets for AC-offset channels */
    for (n = 0; n < 16; n++) {
        if (vert->chan_enabled[n]) calculate_offset(n);
    }

    /* draw baselines first */
    for (n = 0; n < 16; n++) {
	if ((vert->chan_enabled[n]) && (n + 1 != vert->selected)) {
	    draw_baseline(n + 1, FALSE);
	}
    }
    if (vert->chan_enabled[vert->selected - 1]) {
        draw_baseline(vert->selected, TRUE);
    }

    /* Draw trigger line */
    if (vert->chan_enabled[ctrl_shm->trig_chan - 1]) {
        draw_triggerline(ctrl_shm->trig_chan,
                ctrl_shm->trig_chan == vert->selected);
    }

    conflict_reset(disp->height);

    /* draw non-highlighted waveforms next */
    for (n = 0; n < 16; n++) {
	if ((vert->chan_enabled[n]) && (vert->data_offset[n] >= 0)
	    && (n + 1 != vert->selected)) {
	    draw_waveform(n + 1, FALSE);
	}
    }
    /* draw highlighted waveform last */
    if ((vert->chan_enabled[vert->selected - 1])
	&& (vert->data_offset[vert->selected - 1] >= 0)) {
	draw_waveform(vert->selected, TRUE);
    }

    update_readout();

    gdk_window_end_paint(disp->drawing->window);
}
Beispiel #4
0
static void redraw(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    draw_grid();
    draw_waveform();
    glfwSwapBuffers(main_window);
}