-
Notifications
You must be signed in to change notification settings - Fork 1
API
Complete set of functions.
PlotterController has following architecture:
+---+--------------------+
| 5 | Client program |
+---+------+------+------+
| 4 | Text | HPGL | |
+---+------+------+ |
| 3 | Graph |
+---+--------------------+
| 2 | Printer |
+---+---------+------+---+
| 1 | Parport | GPIO |...|
+---+---------+------+---+
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.
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 Pi, Pi Zero, Pi Zero W and Compute Module
pr_create_printer(GPIO, "1")
- In RPi Pi 2, Pi 3 and Compute Module 3
pr_create_printer(GPIO, "2")
At the end of work you should release and close printer.
void pr_close_printer(PRINTER *p)
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)
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;
If you need to find current position you can call pr_get_current_position.
POSITION pr_get_current_position(PRINTER *p)
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)
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)
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)
To learn current drawing buffer you can call pr_get_moving_buffer function.
POSITION pr_get_moving_buffer(PRINTER *p)
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)
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;
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)
Graphics layer supports basic drawing commands. Prototypes can be found in
graph.h
file.
Move pen to x, y position (absolute to origin).
void xy_ma(PRINTER *p, int x, int y)
Move pen to x, y position (relative to current position).
void xy_mr(PRINTER *p, int x, int y)
Draw line from current position to x, y position (absolute to origin).
void xy_va(PRINTER *p, int x, int y)
Draw line from current position to x, y position (relative to current position).
void xy_vr(PRINTER *p, int x, int y)
Draw point at x, y position (absolute to origin).
void xy_pa(PRINTER *p, int x, int y)
Draw point at x, y position (relative to current position).
void xy_pr(PRINTER *p, int x, int y)
Set working origin [0,0] to x, y of physical origin.
void xy_og(PRINTER *p, int x, int y)
Draw circle with center at current position and with r radius.
void xy_cr(PRINTER *p, int r)
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)
Move pen to home [0,0].
void xy_hm(PRINTER *p)
Set velocity of drawing. Values can be from 0 to 9. Default value is 8.
void xy_vs(PRINTER *p, int v)
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;
Text layer supports basic text drawing commands. Prototypes can be found in
text.h
file.
Set font size.
void xy_set_font_size(int i)
Set text drawing angle. Given angle is in radians.
void xy_set_text_angle(double angle)
Write given text starting from current position.
void xy_write(PRINTER *p, char *text)
PlotterController also supports basic HPGL commands. Prototypes can be found in
hpgl.h
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.