Jaroslav Beran edited this page Nov 20, 2017 · 6 revisions

PlotterController API Documentation

Complete set of functions.

1 Table of contents

  1. Table of contents
  2. Layers
  3. Printer
  4. Graph
  5. Text
  6. HPGL

2 Layers

PlotterController has following architecture:

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

3 Printer

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

3.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")

3.2 Close printer instance

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

void pr_close_printer(PRINTER *p)

3.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.

Also you have to call this function each time you load new paper into your plotter.

void pr_init(PRINTER *p)

3.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;

3.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)

3.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)

3.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)

3.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)

3.9 Return moving buffer

To learn current drawing buffer you can call pr_get_moving_buffer function.

POSITION pr_get_moving_buffer(PRINTER *p)

3.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)

3.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;

3.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)

4 Graph

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

4.1 Move Absolute

Move pen to x, y position (absolute to origin).

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

4.2 Move Relative

Move pen to x, y position (relative to current position).

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

4.3 Vector Absolute

Draw line from current position to x, y position (absolute to origin).

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

4.4 Vector Relative

Draw line from current position to x, y position (relative to current position).

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

4.5 Point Absolute

Draw point at x, y position (absolute to origin).

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

4.6 Point Relative

Draw point at x, y position (relative to current position).

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

4.7 Origin

Set working origin [0,0] to x, y of physical origin.

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

4.8 Circle

Draw circle with center at current position and with r radius.

void xy_cr(PRINTER *p, int r)

4.9 Arcus

Draw arcus with center at current position and with r radius. Start and end of arcus are in radians.

void xy_ar(PRINTER *p, int r, double start_arc, double end_arc)

4.10 Home

Move pen to home [0,0].

void xy_hm(PRINTER *p)

4.11 Set Velocity

Set velocity of drawing. Values can be from 0 to 9. Default value is 8.

void xy_vs(PRINTER *p, int v)

4.12 Transforms position

Transforms position with center at current position about givend angle in radians.

D_POSITION _transform_position(double x, double y, double angle)

Returns new position:

typedef struct {
	double x;
	double y;
} D_POSITION;

5 Text

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

5.1 Set font size

Set font size.

void xy_set_font_size(int i)

5.2 Set text angle (in radians)

Set text drawing angle. Given angle is in radians.

void xy_set_text_angle(double angle)

5.3 Write text

Write given text starting from current position.

void xy_write(PRINTER *p, char *text)

6 HPGL

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

6.1 Draw hpgl file

Reads and draw hpgl commands from given file.

void hpgl_draw_from_file(PRINTER *p, char *file_name)

Currently supported HPGL commands are:

  • PA - Plot Absolute
  • PR - Plot Relative
  • CI - Circle
  • PD - Pen Down
  • PU - Pen Up

If you need to implement another ones see hpgl.c file.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.