Skip to content
Jaroslav Beran edited this page Nov 19, 2017 · 7 revisions

API

PlotterController has following architecture:

+---+--------------------+
| 5 | Client program     |
+---+------+------+------+
| 4 | Text | HPGL |      |
+---+------+------+      |
| 3 | Graph              |
+---+--------------------+
| 2 | Printer            |
+---+---------+------+---+
| 1 | Parport | GPIO |...|
+---+---------+------+---+

API is split between following four parts:

  • Printer
  • Graph
  • Text
  • HPGL

1 Printer

Printer layer supports basic commands related to particular plotter like printer initalization, information about curent pen location and so on. Prototypes can be found in printer.h file.

1.1 Create printer instance

For printer instance creation use follofing function. Function pr_create_printer returns PRINTER handle.

PRINTER *pr_create_printer(interface_t i, char *param)

Examples of usage in different systems:

  • In Linux pr_create_printer(PARPORT, "/dev/parport0")
  • In FreeBSD pr_create_printer(PARPORT, "/dev/ppi0")
  • In DOS pr_create_printer(PARPORT, "0x378")
  • In RPi v1 pr_create_printer(GPIO, "1")
  • In RPi v2 pr_create_printer(GPIO, "2")

1.2 Close printer instance

At the end of work you should release and close printer.

void pr_close_printer(PRINTER *p);

1.3 Initialize printer

The first operation you should call after you get printer handle is to call printer initialization. It will look for paper origin and setup all internal values.

void pr_init(PRINTER *p);

1.4 Return max. position

Sometime you can need to know maximal supporting size of drawing area. In this case you can call pr_get_max_position.

POSITION pr_get_max_position(PRINTER *p)

This function returns max x and y drawing size in POSITION structure.

typedef struct {
	int    x;
	int    y;
} POSITION;

1.5 Return current position

If you need to find current position you can call pr_get_current_position.

POSITION pr_get_current_position(PRINTER *p)

1.6 Set origin position

Sometime you can need to move origin position [0,0] to somewhere inside drawing area. In this case you will use pr_set_origin_position.

void pr_set_origin_position(PRINTER *p, int x, int y)

1.7 Return origin position

If you will need to learn where origin position is currently placed then you will call pr_get_origin_position.

POSITION pr_get_origin_position(PRINTER *p)

1.8 Set moving buffer

To set pen position you can call pr_set_moving_buffer. This function set moving buffer, but pen will not move physicaly until you don't call some drawing function.

void pr_set_moving_buffer(PRINTER *p, int x, int y)

1.9 Return moving buffer

To learn current drawing buffer you can call pr_get_moving_buffer function.

POSITION pr_get_moving_buffer(PRINTER *p)

1.10 Set velocity

To set drawing velocity you can call pr_set_velocity function. Velocity can be from 0 to 9. Default value is 8.

void pr_set_velocity(PRINTER *p, int v)

1.11 Set pen

To move pen down and up you can call pr_pen function.

void pr_pen(PRINTER *p, value_pen_t value);

Value is UP or DOWN.

typedef enum {
        UP   = 0,
        DOWN = 1
} value_pen_t;

1.12 Move

To move you can call pr_move function but this is very low-level function and you should prefer drawing functions from graph, text or hpgl section.

void pr_move(PRINTER *p, value_xy_t xy, value_direction_t direction, int repeat);

2 Graph

Graphics layer supports basic drawing commands. Prototypes can be found in graph.h file.

3 Text

Text layer supports basic text drawing commands. Prototypes can be found in text.h file.

4 HPGL

PlotterController also supports basic HPGL commands. Prototypes can be found in hpgl.h file.

Clone this wiki locally