Commits

Jaroslav Beran  committed 9ff1816

Text font completion

  • Participants
  • Parent commits 7dd5345

Comments (0)

Files changed (7)

 	xy_flush_moving_buffer(p);
 }
 
+/* Set Velocity (0 - 9) */
+xy_vs(PRINTER *p, int v) {
+	xy_flush_moving_buffer(p);
+	pr_set_velocity(p, v);
+}
+
 /* Transforms position */
 D_POSITION _transform_position(double x, double y, double angle) {
 	D_POSITION result;
 /* Home */
 extern void xy_hm(PRINTER *p);
 
+/* Set Velocity (0 - 9) */
+extern xy_vs(PRINTER *p, int v);
+
 /* Transforms position  */
 extern D_POSITION _transform_position(double x, double y, double angle);
 
 
 
 static int show_menu(PRINTER *prn);
+static void test_page(PRINTER *prn);
 static void cone_demo(PRINTER *prn);
 static void circles_demo(PRINTER *prn);
 static void text_demo(PRINTER *prn);
 
 static int show_menu(PRINTER *prn) {
 	printf("PlotterController\n");
-	printf("Build 20140209\n");
+	printf("Build 20140216\n");
 	printf("---------------------------\n\n");
 
-	printf("1) Cone demo\n");
-	printf("2) Circles demo\n");
-	printf("3) Text demo\n");
-	printf("4) Triangle demo\n");
-	printf("5) HPGL demo\n");
+	printf("1) Test page\n");
+	printf("2) Cone demo\n");
+	printf("3) Circles demo\n");
+	printf("4) Text demo\n");
+	printf("5) Triangle demo\n");
+	printf("6) HPGL demo\n");
 	printf("0) Exit\n");
 
 	printf("\n");
 	while (getchar() != '\n');
 
 	switch (c) {
-		case '1' :	cone_demo(prn);
+		case '1' :	test_page(prn);
 				break;
-		case '2' :	circles_demo(prn);
+		case '2' :	cone_demo(prn);
 				break;
-		case '3' :	text_demo(prn);
+		case '3' :	circles_demo(prn);
 				break;
-		case '4' :	triangle_demo(prn);
+		case '4' :	text_demo(prn);
 				break;
-		case '5' :	hpgl_demo(prn);
+		case '5' :	triangle_demo(prn);
+				break;
+		case '6' :	hpgl_demo(prn);
 				break;
 	}
 
 	return c;
 }
 
+static void test_page(PRINTER *prn) {
+	pr_init(prn);
+	POSITION paper = pr_get_max_position(prn);
+	
+	xy_va(prn, paper.x, 0);
+	xy_va(prn, paper.x, paper.y);
+	xy_va(prn, 0, paper.y);
+	xy_va(prn, 0, 0);
+
+	xy_vs(prn, 7);
+	xy_set_font_size(10);
+	xy_set_text_angle(M_PI_2);
+	xy_ma(prn, 200, paper.y / 2 - 300);
+	xy_write(prn, "TEST PAGE");
+
+	xy_vs(prn, 8);
+	int x = paper.x / 2;
+	int y = paper.y / 2;
+	int r = 800;
+	int n = 12;
+
+	int i;
+	int dir = 0;
+	for (i = 0; i < n; i ++) {
+		int x1 = x + r * sin(M_PI / (double) n * (double) i); 
+		int y1 = y + r * cos(M_PI / (double) n * (double) i);
+		int x2 = x - r * sin(M_PI / (double) n * (double) i);
+		int y2 = y - r * cos(M_PI / (double) n * (double) i);
+		if (dir == 0) {
+			xy_ma(prn, x1, y1);
+			xy_va(prn, x2, y2);
+			dir = 1;
+		} else {
+			xy_ma(prn, x2, y2);
+			xy_va(prn, x1, y1);
+			dir = 0;
+		}
+	}
+
+	xy_vs(prn, 7);
+	xy_set_font_size(8);
+	xy_set_text_angle(M_PI_2);
+	xy_ma(prn, paper.x - 370, 100);
+	xy_write(prn, "0123456789");
+	xy_ma(prn, paper.x - 280, 100);
+	xy_write(prn, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+	xy_ma(prn, paper.x - 190, 100);
+	xy_write(prn, "abcdefghijklmnopqrstuvwxyz");
+	xy_ma(prn, paper.x - 100, 100);
+	xy_write(prn, "!\"#$%&'()*+,-./:;<=>?@[\\]^_�{|}~");
+
+	xy_vs(prn, 8);
+	xy_hm(prn);
+}
+
 static void cone_demo(PRINTER *prn) {
 	pr_init(prn);
 	POSITION paper = pr_get_max_position(prn);
 
 	xy_set_font_size(10);
 	xy_ma(prn, paper.x / 2 - 350, paper.y / 2 + r * 2 + dist);
+	xy_vs(prn, 7);
 	xy_write(prn, "OLYMPIC GAMES");
+	xy_vs(prn, 8);
 	xy_ma(prn, paper.x / 2 - 450, paper.y / 2 - r * 2 - dist);
+	xy_vs(prn, 7);
 	xy_write(prn, "SOCHI RUSSIA 2014");
-
+	xy_vs(prn, 8);
 	xy_hm(prn);
 }
 
 	POSITION paper = pr_get_max_position(prn);
 
 	xy_set_font_size(5);
+	xy_vs(prn, 7);
 
 	int i;
 	for (i = 0; i < 16; i++) {
 		xy_write(prn, "    XY4150.WEBSTONES.CZ");
 	}
 
+	xy_vs(prn, 8);
 	xy_hm(prn);
 }
 
 	scanf("%99s", file_name);
 	while (getchar() != '\n');
 	hpgl_draw_from_file(prn, file_name);
-}
+}
+

File src/printer.c

 #define DIRECTION_BIT 0	/* L = TO LEFT (FORWARD), H = TO RIGHT (BACK) */
 #define READY_BIT 4		/* L = READY, H = NOT READY */
 
-#define SLEEP_INTERVAL 		1000	/* in ms */
-#define SLEEP_INTERVAL_LOW	10000
-
 #define MAX_X 2600
 #define MAX_Y 1850
 
 #define check_bit(var,pos) ((var) & (1<<(pos)))
 
+/* 
+ *	Speed value is sleep interval in ms
+ *	There are 10 values (0 the slowes 9 the fasts)
+ */
+static speed[] = {2600,2400,2200,2000,1800,1600,1400,1200,1000,800};
+
 static int is_ready(PRINTER *p);
 static void step(PRINTER *p, int repeat);
 static void dirty_step(PRINTER *p);
 	result->moving_buffer.x = 0;
 	result->moving_buffer.y = 0;
 	result->data = 0;
+	result->velocity = 8;
 
 	return result;
 }
 	set_bit(&(p->data), READY_BIT, 1);
 	set_bit(&(p->data), STEP_BIT, 1);
 	write_data(p->parport_fd, p->data);
-	USLEEP(SLEEP_INTERVAL_LOW);
+	USLEEP(speed[p->velocity]);
 
 	switch_direction(p, 0);
 
 }
 
 /*
+*	Set velocity (0-9)
+*/
+void pr_set_velocity(PRINTER *p, int v) {
+	if ((v >= 0) && (v < 10)) {
+		p->velocity = v;
+	}
+}
+
+/*
 *	Set pen
 */
 void pr_pen(PRINTER *p, int value) {
 	set_bit(&(p->data), PEN_BIT, value);
 	write_data(p->parport_fd, p->data);
-	USLEEP(SLEEP_INTERVAL);
+	USLEEP(speed[p->velocity] * 10);
 }
 
 /*
 static int is_ready(PRINTER *p) {
 	set_bit(&(p->data), READY_BIT, 0);
 	write_data(p->parport_fd, p->data);
-	USLEEP(SLEEP_INTERVAL);
+	USLEEP(speed[p->velocity]);
 
 	set_bit(&(p->data), READY_BIT, 1);
 	write_data(p->parport_fd, p->data);
-	USLEEP(SLEEP_INTERVAL);
+	USLEEP(speed[p->velocity]);
 
 	DATA data;
 	read_data(p->parport_fd, &data);
 static void dirty_step(PRINTER *p) {
 	set_bit(&(p->data), STEP_BIT, 0);
 	write_data(p->parport_fd, p->data);
-	USLEEP(SLEEP_INTERVAL);
+	USLEEP(speed[p->velocity]);
 	set_bit(&(p->data), STEP_BIT, 1);
 	write_data(p->parport_fd, p->data);
-	USLEEP(SLEEP_INTERVAL);
+	USLEEP(speed[p->velocity]);
 }
 
 

File src/printer.h

 	POSITION	origin_position;
 	POSITION	moving_buffer;
 	DATA		data;
+	int		velocity;
 } PRINTER;
 
 /*
 extern void pr_set_moving_buffer(PRINTER *p, int x, int y);
 
 /*
+*	Set velocity (0-9)
+*/
+extern void pr_set_velocity(PRINTER *p, int v);
+
+/*
 *	Set pen
 *	0 = UP, 1 = DOWN
 */
 					break;
 			case 'v' :      xy_vr(p, pos.x, pos.y);
 					break;
-			//case 'c' :      xy_ar(p, cmd[1] * char_size, cmd[2] * char_size, cmd[3] * char_size);
-			//		break;
+			case 'p' :      xy_pr(p, pos.x, pos.y);
+					break;
 		 }
 	}
 
-	pos = _transform_position(char_h_dist * 10, 0, text_angle);
+	pos = _transform_position(char_h_dist * char_size, 0, text_angle);
 	xy_mr(p, pos.x, pos.y);
 }
 

File var/font1.fnt

 # Possible commands:
 # move		m,x,y
 # vector	v,x,y
-# arcus		a,r,start,stop
+# point		p,x,y
 #
 
 32;m,5,0;
-33
-34
-35
-36
-37
-38
-39
-40
-41
-42
-43
-44
-45
-46;v,0,0;
-47
+33;m,0,7;v,0,-5;p,0,-2;
+34;m,0,7;v,0,-2;m,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