Esempio n. 1
0
static int Epdc_init(PyObject *obj, PyObject *args, PyObject *kw)
{
	static char *kwlist[] = { "device", "mode", "config", NULL };
	Epdc *self = (Epdc *)obj;
	char *dev = NULL;
	char *mode = NULL;
	const char *conf_file = NULL;

	if (!PyArg_ParseTupleAndKeywords(args, kw, "|sss", kwlist, &dev,
					 &mode, &conf_file))
		return -1;

	self->plep = plep_init(dev, mode, conf_file);

	if (self->plep == NULL) {
		PyErr_SetString(plsdk_error, "Failed to initialise plep");
		return -1;
	}

	self->refresh = plep_get_wfid(self->plep, PLEP_REFRESH);
	self->delta = plep_get_wfid(self->plep, PLEP_DELTA);
	self->mono = plep_get_wfid(self->plep, PLEP_DELTA"/"PLEP_MONO);

	return 0;
}
Esempio n. 2
0
static PyObject *EpdcObj_get_wfid(Epdc *self, PyObject *args)
{
	char *wfstr;
	int wfid;

	if (!PyArg_ParseTuple(args, "s", &wfstr))
		return NULL;

	wfid = plep_get_wfid(self->plep, wfstr);

	if (wfid < 0)
		Py_RETURN_NONE;

	return Py_BuildValue("i", wfid);
}
Esempio n. 3
0
int test_update(struct pldraw *pldraw, char * const *opts, int opts_n)
{
	struct plep *plep;
	int wfid;

	assert(pldraw != NULL);

	plep = pldraw_get_plep(pldraw);

	if (opts_n > 0) {
		wfid = plep_get_wfid(plep, opts[0]);

		if (wfid < 0) {
			LOG("Invalid waveform: %s", opts[0]);
			return -1;
		}

		LOG("waveform name: %s", opts[0]);
	} else {
		wfid = g_clear_wf;
	}

	return plep_update_screen(plep, wfid);
}
Esempio n. 4
0
int main(int argc, char **argv)
{
	//static const char OPTIONS[] = "hvlpsjPr:g:f::A:Ww:m:d:e:b:T:t:o:a:c:O:i:";
	static const char OPTIONS[] = "A:a:b:c:D:d:E:e:F:f:g:hi:jlm:no:O:Ppr:sT:t:vWw:x:y:";
	__sighandler_t sigint_original;
	char * const *file_names = NULL;
	size_t n_files = 0;
	int dither_mode = 0;
	int keep_power_on = 0;
	const char *waveform_id_str = "2";
	int waveform_id = 2;
	int do_enumerate_waveforms = 0;
	int do_log_info = 0;
	int do_wait_power_off = 0;
	int do_synchro = 0;
	int do_infinite_loop = 0;
	int cfa = -1;
	int display_enable = 0;
	int do_fill = 0;
	int fill_color = 0xFF;
	int do_auto_rotate = 0;
	int rotation_angle = -1;
	int do_partial_update = 0;
	int use_manual_temperature = 0;
	int manual_temperature = 25;
	unsigned long pause_ms = 2000;
	const char *mode = NULL;
	const char *fbdev = NULL;
	const char *epdev = NULL;
	const char *background = NULL;
	struct plep_point offset = { 0, 0 };
	enum epdoc_align_h align_h = EPDOC_ALIGN_H_NONE;
	enum epdoc_align_v align_v = EPDOC_ALIGN_V_NONE;
	struct plep_rect crop = { { 0, 0 }, { INT_MAX, INT_MAX } };
	const char *doc_type = NULL;
	const char *conf_file = NULL;
	struct plep *plep;
	struct pldraw *pldraw;
	int onoff = -1;
	int c;
	int ret;
	int use_alternative_vsource = 0;
	while ((c = getopt(argc, argv, OPTIONS)) != -1) {
		switch (c) {
		case 'A':
			if (!strcmp(optarg, "l")) {
			use_alternative_vsource = 1;
			}else if (!strcmp(optarg, "h")) {
			use_alternative_vsource = 2;
			}else if (!strcmp(optarg, "lh")) {
			use_alternative_vsource = 3;
			}else if (!strcmp(optarg, "hl")) {
			use_alternative_vsource = 3;
			}else{
				LOG("invalid alternative VSOURCE selection");
				print_usage();
				exit(EXIT_FAILURE);
			}
			break;
		case 'h':
			print_usage();
			exit(EXIT_SUCCESS);
			break;

		case 'v':
			printf("%s v%s - %s\n%s\n%s\n", APP_NAME, VERSION,
			       DESCRIPTION, COPYRIGHT, LICENSE);
			exit(EXIT_SUCCESS);
			break;

		case 'l':
			do_log_info = 1;
			break;
		case 'P':
			do_partial_update = 1;
			break;

		case 'p':
			do_wait_power_off = 1;
			break;

		case 's':
			do_synchro = 1;
			break;

		case 'j':
			do_infinite_loop = 1;
			break;

		case 'r':
			if (!strcmp(optarg, "auto")) {
				do_auto_rotate = 1;
			} else {
				unsigned long raw_angle;

				if (str2ul(optarg, &raw_angle) < 0) {
					LOG("failed to parse rotation angle");
					print_usage();
					exit(EXIT_FAILURE);
				}

				if ((raw_angle > 270) || (raw_angle % 90)) {
					LOG("invalid rotation angle");
					print_usage();
					exit(EXIT_FAILURE);
				}

				rotation_angle = raw_angle;
			}
			break;

		case 'g':
			if (str2ul(optarg, &pause_ms) < 0) {
				LOG("failed to parse pause duration");
				print_usage();
				exit(EXIT_FAILURE);
			}
			break;

		case 'f':
			if (optarg == NULL) {
				cfa = PLDRAW_CFA_GR_BW;
			} else {
				cfa = pldraw_get_cfa_id(optarg);

				if (cfa < 0) {
					LOG("Invalid CFA identifier: %s",
					    optarg);
					print_usage();
					exit(EXIT_FAILURE);
				}
			}
			break;
		
		case 'F':{
			char* str = optarg;
			if (optarg == NULL) {
				// set color to white (0xFF)
				do_fill = 1;
			} else {
				do_fill = 1;
				if(!strncmp(optarg, "0x", 2) || !strncmp(optarg, "0X", 2)){
					fill_color = strtoul(optarg, NULL, 16);
				}else{
					fill_color = atoi(optarg);
				}
			}
			break;
		}
		case 'T':
			manual_temperature = atoi(optarg);
			use_manual_temperature = 1;
			break;
		case 'W':
			do_enumerate_waveforms = 1;
			break;
		case 'i':
			waveform_id_str = NULL;
			waveform_id = atoi(optarg);
			break;
		case 'w':
			waveform_id_str = optarg;
			break;

		case 'm':
			mode = optarg;
			break;

		case 'd':
			fbdev = optarg;
			break;

		case 'e':
			epdev = optarg;
			break;

		case 'b':
			background = optarg;
			break;

		case 't':
			doc_type = optarg;
			break;

		case 'o':
			if (parse_offset(&offset, optarg) < 0) {
				print_usage();
				exit(EXIT_FAILURE);
			}
			break;

		case 'a':
			if (parse_alignment(&align_h, &align_v, optarg) < 0) {
				print_usage();
				exit(EXIT_FAILURE);
			}
			break;

		case 'c':
			if (parse_crop(&crop, optarg) < 0) {
				print_usage();
				exit(EXIT_FAILURE);
			}
			break;
		case 'O':
			conf_file = optarg;
			if (access(conf_file, F_OK)) {
				LOG_ERRNO("Configuration file");
				exit(EXIT_FAILURE);
			}
			break;
		case 'x':{
			onoff = atoi(optarg);
			break;
		}	
		case 'E':{
			//Enable Display N
			display_enable = atoi(optarg);
			if(display_enable > 3){
				LOG("Invalid arguments");
				exit(EXIT_FAILURE);
			}
			break;
		}
		case 'D':{
			//disable Display N
			display_enable -= atoi(optarg);
			if(display_enable < -3){
				LOG("Invalid arguments");
				exit(EXIT_FAILURE);
			}
			break;
		}
		case 'y':
			dither_mode = atoi(optarg);
			LOG("dither_mode %i", dither_mode);
			if(display_enable < 0 || display_enable > 3){
				LOG("Invalid arguments");
				exit(EXIT_FAILURE);
			}
			break;
		case 'n':{
			keep_power_on = 1;
			break;
		}	
		case '?':
		default:
			LOG("Invalid arguments");
			print_usage();
			exit(EXIT_FAILURE);
			break;
		}
	}

	if (optind < argc) {
		file_names = &argv[optind];
		n_files = argc - optind;
	}

	LOG("%s v%s", APP_NAME, VERSION);

	plep = plep_init(epdev, mode, conf_file);

	if (plep == NULL) {
		LOG("failed to initialise ePDC");
		goto error_plep;
	}

	pldraw = pldraw_init(fbdev, conf_file);

	if (pldraw == NULL) {
		LOG("failed to initialise pldraw");
		goto error_pldraw;
	}

	pldraw_set_plep(pldraw, plep);
	
	if(waveform_id_str){
		waveform_id = plep_get_wfid(plep, waveform_id_str);

		if (waveform_id < 0) {
			LOG("Invalid waveform path: %s", waveform_id_str);
			goto error_pldraw;
		}
	}
	
	if (cfa >= 0)
		pldraw_set_cfa(pldraw, cfa);
	else
		cfa = pldraw_get_cfa(pldraw);

	if (cfa != PLDRAW_CFA_NONE)
		LOG("CFA: %s", pldraw_cfa_name[cfa]);

	if (rotation_angle < 0)
		rotation_angle = pldraw_get_rotation(pldraw);

	if (rotation_angle)
		LOG("rotation: %d", rotation_angle);

	if (do_log_info)
		pldraw_log_info(pldraw);

	sigint_original = signal(SIGINT, sigint_abort);

	if(onoff != -1){
		LOG("POWER ONOFF:%i\n", onoff);
		if(onoff)
			plep_powerup(plep);
		else
			plep_powerdown(plep);
		exit(EXIT_SUCCESS);
	}
	if(display_enable != 0){
		//LOG("DISPLAY ENABLE:%i\n", display_enable);
		if(display_enable>0){
			plep_enable_display(plep, display_enable);
		}else{
			plep_disable_display(plep, display_enable);
		}
		exit(EXIT_SUCCESS);
	}
	if (do_enumerate_waveforms) {
		ret = enumerate_waveforms(plep);
	} else {
		struct epdoc_opt opt;

		plep_set_opt(plep, PLEP_SYNC_UPDATE, do_synchro);

		if (do_wait_power_off)
			plep_set_opt(plep, PLEP_WAIT_POWER_OFF, 1);

		if(do_partial_update){
			plep_set_opt(plep, PLEP_PARTIAL, 1);
		}
		
		if(use_manual_temperature){
			plep_set_opt(plep, PLEP_TEMPERATURE, 1);
			plep_set_hw_opt(plep, PLEP_TEMPERATURE, manual_temperature);
		}else{
			plep_set_opt(plep, PLEP_TEMPERATURE_AUTO, 1);
		}
		opt.dither_mode = dither_mode;
		opt.keep_power_on = keep_power_on;
		opt.do_auto_rotate = do_auto_rotate;
		opt.rotation_angle = rotation_angle;
		opt.wfid = waveform_id;
		opt.offset.x = offset.x;
		opt.offset.y = offset.y;
		opt.align_h = align_h;
		opt.align_v = align_v;
		memcpy(&opt.crop, &crop, sizeof opt.crop);
		opt.doc_type = doc_type;
		opt.use_alternative_vsource = use_alternative_vsource;
		
		if(do_fill){
			pldraw_fill_rect(pldraw, pldraw_get_grey(pldraw, fill_color), &crop);
			plep_update_screen(plep, opt.wfid);
		}else{
		
			ret = show_contents(pldraw, file_names, n_files, &opt,
				    pause_ms, do_infinite_loop, background);
		}
	}

	signal(SIGINT, sigint_original);
	pldraw_free(pldraw);
	plep_free(plep);

	exit((ret < 0) ? EXIT_FAILURE : EXIT_SUCCESS);

error_pldraw:
	plep_free(plep);
error_plep:
	exit(EXIT_FAILURE);
}
Esempio n. 5
0
int test_highlight(struct pldraw *pldraw, char * const *opts, int opts_n)
{
	struct plep_rect area;
	struct pldraw_pen pen;
	struct plep *plep;
	int xres;
	int yres;
	int wfid;
	int grey;

	assert(pldraw != NULL);

	plep = pldraw_get_plep(pldraw);

	assert(plep != NULL);

	wfid = plep_get_wfid(plep, PLEP_HIGHLIGHT);

	if (wfid < 0) {
		LOG("highlight waveform not available");
		return -1;
	}

	xres = pldraw_get_xres(pldraw);
	yres = pldraw_get_yres(pldraw);

	area.a.x = 0;
	area.b.x = xres;

	for (grey = 0; grey < 4; ++grey) {
		const uint8_t grey4 = pldraw_grey_4[grey];
		const pldraw_color_t col = pldraw_get_grey(pldraw, grey4);

		area.a.y = grey * yres / 4;
		area.b.y = (grey + 1) * yres / 4;
		pldraw_fill_rect(pldraw, col, &area);
	}

	plep_set_opt(plep, PLEP_SYNC_UPDATE, 1);

	if (plep_update_screen(plep, g_clear_wf))
		return -1;

	plep_set_opt(plep, PLEP_SYNC_UPDATE, 0);

	area.a.y = 0;
	area.b.y = pldraw_get_yres(pldraw);

	for (grey = 0; grey < 0x100; ++grey) {
		const pldraw_color_t col = pldraw_get_grey(pldraw, grey);

		area.a.x = grey * xres / 0x100;
		area.b.x = (grey + 1) * xres / 0x100;
		pldraw_fill_rect(pldraw, col, &area);
	}

	plep_set_opt(plep, PLEP_SYNC_UPDATE, 1);

	if (plep_update_screen(plep, wfid))
		return -1;

	pen.font = pldraw_fonts[0];
	pen.foreground = g_black;
	pen.background = g_white;

	for (grey = 0; grey < 16; ++grey) {
		char txt[4];

		area.a.x = 1 + grey * xres / 16;
		area.a.y = yres - 20;
		area.b.x = 1 + (grey + 1) * xres / 16;
		area.b.y = yres;
		snprintf(txt, 4, "%d", (grey * 16));
		pldraw_draw_text(pldraw, &pen, &area.a, txt);

		area.a.x -= 1;
		area.a.y = yres - 50;
		area.b.x = area.a.x;
		pldraw_draw_line(pldraw, g_black, &area);
	}

	area.a.x = 0;
	area.a.y = yres - 50;
	area.b.x = xres;
	area.b.y = yres;
	plep_update(plep, &area, g_clear_wf);

	return 0;
}
Esempio n. 6
0
int test_check(struct pldraw *pldraw, char * const *opts, int opts_n)
{
	const struct plep_point origin = { .x = 0, .y = 0 };
	struct plep *plep = pldraw_get_plep(pldraw);
	pldraw_color_t draw_col;
	unsigned long dim;
	int wfid;
	int n;
	int m;

	assert(pldraw != NULL);
	assert(g_initialised);

	if (opts_n > 0) {
		if (str2ul(&dim, opts[0]) < 0) {
			LOG("Invalid square dimension: %s", opts[0]);
			return -1;
		}
	} else {
		dim = pldraw_get_xres(pldraw) / 40;
	}

	if (opts_n > 1) {
		if (pldraw_str2col(pldraw, &draw_col, opts[1]))
			return -1;
	} else {
		draw_col = g_black;
	}

	if (opts_n > 2) {
		const char *wfid_str = opts[2];

		wfid = plep_get_wfid(plep, wfid_str);

		if (wfid < 0) {
			LOG("Invalid waveform: %s", wfid_str);
			return -1;
		}

		LOG("waveform name: %s", wfid_str);
	} else {
		wfid = g_clear_wf;
	}

	if (dim == 0)
		return -1;

	n = 1 + ((pldraw_get_xres(pldraw) - 1) / dim);
	m = 1 + ((pldraw_get_yres(pldraw) - 1) / dim);

	draw_checkerboard(pldraw, &origin, dim, 0, n, m, draw_col);

	return plep_update_screen(plep, wfid);
}

int test_fill(struct pldraw *pldraw, char * const *opts, int opts_n)
{
	struct plep *plep;
	pldraw_color_t col;
	int wfid;

	assert(pldraw != NULL);
	assert(g_initialised);

	plep = pldraw_get_plep(pldraw);

	if (opts_n < 1)
		col = g_white;
	else if (pldraw_str2col(pldraw, &col, opts[0]))
		return -1;

	if (opts_n > 1) {
		const char *wfid_str = opts[1];

		wfid = plep_get_wfid(plep, wfid_str);

		if (wfid < 0) {
			LOG("Invalid waveform: %s", wfid_str);
			return -1;
		}

		LOG("waveform name: %s", wfid_str);
	} else {
		wfid = g_clear_wf;
	}

	pldraw_fill_screen(pldraw, col);

	return plep_update_screen(plep, wfid);
}

int test_sweep(struct pldraw *pldraw, char * const *opts, int opts_n)
{
	struct plep *plep;
	unsigned long sleep_us = 10000;
	int i;

	assert(pldraw != NULL);

	plep = pldraw_get_plep(pldraw);

	if (opts_n >= 1) {
		unsigned long sleep_ms;

		if (str2ul(&sleep_ms, opts[0]) < 0) {
			LOG("Invalid sleep value: %s", opts[0]);
			return -1;
		}

		sleep_us = sleep_ms * 1000;
	}

	for (i = 0; i < 0xFF; ++i) {
		const pldraw_color_t col = pldraw_get_color(pldraw, i, i, i);

		pldraw_fill_screen(pldraw, col);
		plep_update_screen(plep, g_clear_wf);
		usleep(sleep_us);
	}

	return 0;
}

int test_none(struct pldraw *pldraw, char * const *opts, int opts_n)
{
	pldraw = NULL;

	LOG("That's all folks!");

	return 0;
}
Esempio n. 7
0
int test_regions(struct pldraw *pldraw, char * const *opts, int opts_n)
{
	struct plep *plep;
	struct plep_rect rect;
	int delta_wf;
	pldraw_color_t col;
	int ret = 0;

	assert(pldraw != NULL);
	assert(g_initialised);

	plep = pldraw_get_plep(pldraw);

	if (plep == NULL) {
		delta_wf = 0;
	} else {
		delta_wf = plep_get_wfid(plep, PLEP_DELTA);

		if (delta_wf < 0)
			delta_wf = g_clear_wf;
	}

	plep_set_opt(plep, PLEP_SYNC_UPDATE, 0);

	LOG("black frame");

	rect.a.x = 50;
	rect.a.y = 350;
	rect.b.x = 100;
	rect.b.y = 550;
	pldraw_fill_rect(pldraw, g_black, &rect);

	if (plep_update(plep, &rect, g_quick_wf) < 0)
		ret = -1;

	rect.a.x += 300;
	rect.b.x += 300;
	pldraw_fill_rect(pldraw, g_black, &rect);

	if (plep_update(plep, &rect, g_quick_wf) < 0)
		ret = -1;

	rect.a.x = 100;
	rect.a.y = 350;
	rect.b.x = 350;
	rect.b.y = 400;
	pldraw_fill_rect(pldraw, g_black, &rect);

	if (plep_update(plep, &rect, g_quick_wf) < 0)
		ret = -1;

	rect.a.y += 150;
	rect.b.y += 150;
	pldraw_fill_rect(pldraw, g_black, &rect);

	if (plep_update(plep, &rect, g_quick_wf) < 0)
		ret = -1;

	LOG("grey rectangles");

	col = pldraw_get_grey(pldraw, 0x80);

	rect.a.x = 50;
	rect.a.y = 50;
	rect.b.x = 200;
	rect.b.y = 100;
	pldraw_fill_rect(pldraw, col, &rect);

	if (plep_update(plep, &rect, delta_wf) < 0)
		ret = -1;

	rect.a.y += 100;
	rect.b.y += 100;
	pldraw_fill_rect(pldraw, col, &rect);

	if (plep_update(plep, &rect, delta_wf) < 0)
		ret = -1;

	rect.a.y += 100;
	rect.b.y += 100;
	pldraw_fill_rect(pldraw, col, &rect);

	if (plep_update(plep, &rect, delta_wf) < 0)
		ret = -1;

	rect.a.x += 200;
	rect.b.x += 200;
	pldraw_fill_rect(pldraw, col, &rect);

	if (plep_update(plep, &rect, delta_wf) < 0)
		ret = -1;

	rect.a.y -= 100;
	rect.b.y -= 100;
	pldraw_fill_rect(pldraw, col, &rect);

	if (plep_update(plep, &rect, delta_wf) < 0)
		ret = -1;

	rect.a.y -= 100;
	rect.b.y -= 100;
	pldraw_fill_rect(pldraw, col, &rect);

	if (plep_update(plep, &rect, delta_wf) < 0)
		ret = -1;

	return ret;
}
Esempio n. 8
0
int test_frame(struct pldraw *pldraw, char * const *opts, int opts_n)
{
	struct plep *plep;
	struct plep_rect rect;
	struct plep_rect outer;
	struct plep_rect inner;
	unsigned long grid = 12;
	pldraw_color_t draw_col = g_black;
	unsigned long gap = 1;
	unsigned long max_gap;
	float x_grid, y_grid;
	int xres, yres;
	int wfid = g_clear_wf;

	assert(pldraw != NULL);
	assert(g_initialised);

	plep = pldraw_get_plep(pldraw);
	xres = pldraw_get_xres(pldraw);
	yres = pldraw_get_yres(pldraw);

	if (opts_n > 0) {
		if (str2ul(&grid, opts[0]) < 0) {
			LOG("Invalid grid value: %s", opts[0]);
			return -1;
		}

		if (grid < 4) {
			LOG("Grid value is too small, minimum is 4");
			return -1;
		}
	}

	if (opts_n > 1) {
		if (pldraw_str2col(pldraw, &draw_col, opts[1]))
			return -1;
	}

	if (opts_n > 2) {
		if (str2ul(&gap, opts[2]) < 0) {
			LOG("Invalid gap value: %s", opts[2]);
			return -1;
		}
	}

	if (opts_n > 3) {
		wfid = plep_get_wfid(plep, opts[3]);

		if (wfid < 0) {
			LOG("Invalid waveform: %s", opts[3]);
			return -1;
		}
	}

	x_grid = xres / (float)grid;
	y_grid = yres / (float)grid;

	LOG("grid: %lu, x: %.3f, y: %.3f", grid, x_grid, y_grid);

	max_gap = (y_grid * ((grid / 2) - 2)) - 1;

	if (gap > max_gap) {
		LOG("Gap is too big, maximum is %lu", max_gap);
		return -1;
	}

	outer.a.x = x_grid;
	outer.a.y = y_grid;
	outer.b.x = x_grid * (grid - 1);
	outer.b.y = y_grid * (grid - 1);

	inner.a.x = x_grid * 2;
	inner.a.y = y_grid * 2;
	inner.b.x = x_grid * (grid - 2);
	inner.b.y = y_grid * (grid - 2);

	rect.a.x = outer.a.x;
	rect.a.y = outer.a.y;
	rect.b.x = outer.b.x;
	rect.b.y = inner.a.y;
	pldraw_fill_rect(pldraw, draw_col, &rect);

	if (plep_update(plep, &rect, wfid) < 0)
		return -1;

	rect.a.y = inner.b.y;
	rect.b.y = outer.b.y;
	pldraw_fill_rect(pldraw, draw_col, &rect);

	if (plep_update(plep, &rect, wfid) < 0)
		return -1;

	rect.a.x = outer.a.x;
	rect.a.y = inner.a.y + gap;
	rect.b.x = inner.a.x;
	rect.b.y = inner.b.y - gap;
	pldraw_fill_rect(pldraw, draw_col, &rect);

	if (plep_update(plep, &rect, wfid) < 0)
		return -1;

	rect.a.x = inner.b.x;
	rect.b.x = outer.b.x;
	pldraw_fill_rect(pldraw, draw_col, &rect);

	if (plep_update(plep, &rect, wfid) < 0)
		return -1;

	return 0;
}
Esempio n. 9
0
int main(int argc, char **argv)
{
	static const char OPTIONS[] = "hvlpsjr:g:f::Ww:m:d:e:b:t:o:a:c:O:";
	__sighandler_t sigint_original;
	char * const *file_names = NULL;
	size_t n_files = 0;
	const char *waveform_id_str = NULL;
	int waveform_id;
	int do_enumerate_waveforms = 0;
	int do_log_info = 0;
	int do_wait_power_off = 0;
	int do_synchro = 0;
	int do_infinite_loop = 0;
	int cfa = -1;
	int do_auto_rotate = 0;
	int rotation_angle = -1;
	unsigned long pause_ms = 2000;
	const char *mode = NULL;
	const char *fbdev = NULL;
	const char *epdev = NULL;
	const char *background = NULL;
	struct plep_point offset = { 0, 0 };
	enum epdoc_align_h align_h = EPDOC_ALIGN_H_NONE;
	enum epdoc_align_v align_v = EPDOC_ALIGN_V_NONE;
	struct plep_rect crop = { { 0, 0 }, { INT_MAX, INT_MAX } };
	const char *doc_type = NULL;
	const char *conf_file = NULL;
	struct plep *plep;
	struct pldraw *pldraw;
	int c;
	int ret;

	while ((c = getopt(argc, argv, OPTIONS)) != -1) {
		switch (c) {
		case 'h':
			print_usage();
			exit(EXIT_SUCCESS);
			break;

		case 'v':
			printf("%s v%s - %s\n%s\n%s\n", APP_NAME, VERSION,
			       DESCRIPTION, COPYRIGHT, LICENSE);
			exit(EXIT_SUCCESS);
			break;

		case 'l':
			do_log_info = 1;
			break;

		case 'p':
			do_wait_power_off = 1;
			break;

		case 's':
			do_synchro = 1;
			break;

		case 'j':
			do_infinite_loop = 1;
			break;

		case 'r':
			if (!strcmp(optarg, "auto")) {
				do_auto_rotate = 1;
			} else {
				unsigned long raw_angle;

				if (str2ul(optarg, &raw_angle) < 0) {
					LOG("failed to parse rotation angle");
					print_usage();
					exit(EXIT_FAILURE);
				}

				if ((raw_angle > 270) || (raw_angle % 90)) {
					LOG("invalid rotation angle");
					print_usage();
					exit(EXIT_FAILURE);
				}

				rotation_angle = raw_angle;
			}
			break;

		case 'g':
			if (str2ul(optarg, &pause_ms) < 0) {
				LOG("failed to parse pause duration");
				print_usage();
				exit(EXIT_FAILURE);
			}
			break;

		case 'f':
			if (optarg == NULL) {
				cfa = PLDRAW_CFA_GR_BW;
			} else {
				cfa = pldraw_get_cfa_id(optarg);

				if (cfa < 0) {
					LOG("Invalid CFA identifier: %s",
					    optarg);
					print_usage();
					exit(EXIT_FAILURE);
				}
			}
			break;

		case 'W':
			do_enumerate_waveforms = 1;
			break;

		case 'w':
			waveform_id_str = optarg;
			break;

		case 'm':
			mode = optarg;
			break;

		case 'd':
			fbdev = optarg;
			break;

		case 'e':
			epdev = optarg;
			break;

		case 'b':
			background = optarg;
			break;

		case 't':
			doc_type = optarg;
			break;

		case 'o':
			if (parse_offset(&offset, optarg) < 0) {
				print_usage();
				exit(EXIT_FAILURE);
			}
			break;

		case 'a':
			if (parse_alignment(&align_h, &align_v, optarg) < 0) {
				print_usage();
				exit(EXIT_FAILURE);
			}
			break;

		case 'c':
			if (parse_crop(&crop, optarg) < 0) {
				print_usage();
				exit(EXIT_FAILURE);
			}
			break;

		case 'O':
			conf_file = optarg;
			if (access(conf_file, F_OK)) {
				LOG_ERRNO("Configuration file");
				exit(EXIT_FAILURE);
			}
			break;

		case '?':
		default:
			LOG("Invalid arguments");
			print_usage();
			exit(EXIT_FAILURE);
			break;
		}
	}

	if (optind < argc) {
		file_names = &argv[optind];
		n_files = argc - optind;
	}

	LOG("%s v%s", APP_NAME, VERSION);

	plep = plep_init(epdev, mode, conf_file);

	if (plep == NULL) {
		LOG("failed to initialise ePDC");
		goto error_plep;
	}

	pldraw = pldraw_init(fbdev, conf_file);

	if (pldraw == NULL) {
		LOG("failed to initialise pldraw");
		goto error_pldraw;
	}

	pldraw_set_plep(pldraw, plep);

	waveform_id = plep_get_wfid(plep, waveform_id_str);

	if (waveform_id < 0) {
		LOG("Invalid waveform path: %s", waveform_id_str);
		goto error_pldraw;
	}

	if (cfa >= 0)
		pldraw_set_cfa(pldraw, cfa);
	else
		cfa = pldraw_get_cfa(pldraw);

	if (cfa != PLDRAW_CFA_NONE)
		LOG("CFA: %s", pldraw_cfa_name[cfa]);

	if (rotation_angle < 0)
		rotation_angle = pldraw_get_rotation(pldraw);

	if (rotation_angle)
		LOG("rotation: %d", rotation_angle);

	if (do_log_info)
		pldraw_log_info(pldraw);

	sigint_original = signal(SIGINT, sigint_abort);

	if (do_enumerate_waveforms) {
		ret = enumerate_waveforms(plep);
	} else {
		struct epdoc_opt opt;

		plep_set_opt(plep, PLEP_SYNC_UPDATE, do_synchro);

		if (do_wait_power_off)
			plep_set_opt(plep, PLEP_WAIT_POWER_OFF, 1);

		opt.do_auto_rotate = do_auto_rotate;
		opt.rotation_angle = rotation_angle;
		opt.wfid = waveform_id;
		opt.offset.x = offset.x;
		opt.offset.y = offset.y;
		opt.align_h = align_h;
		opt.align_v = align_v;
		memcpy(&opt.crop, &crop, sizeof opt.crop);
		opt.doc_type = doc_type;

		ret = show_contents(pldraw, file_names, n_files, &opt,
				    pause_ms, do_infinite_loop, background);
	}

	signal(SIGINT, sigint_original);
	pldraw_free(pldraw);
	plep_free(plep);

	exit((ret < 0) ? EXIT_FAILURE : EXIT_SUCCESS);

error_pldraw:
	plep_free(plep);
error_plep:
	exit(EXIT_FAILURE);
}