- Notifications
You must be signed in to change notification settings - Fork 1
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_ti, 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.
voidpr_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.
voidpr_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.
POSITIONpr_get_max_position(PRINTER*p)This function returns max x and y drawing size in POSITION structure.
typedefstruct {
intx;
inty;
} POSITION;If you need to find current position you can call pr_get_current_position.
POSITIONpr_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.
voidpr_set_origin_position(PRINTER*p, intx, inty)If you will need to learn where origin position is currently placed then you will call pr_get_origin_position.
POSITIONpr_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.
voidpr_set_moving_buffer(PRINTER*p, intx, inty)To learn current drawing buffer you can call pr_get_moving_buffer function.
POSITIONpr_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.
voidpr_set_velocity(PRINTER*p, intv)To move pen down and up you can call pr_pen function.
voidpr_pen(PRINTER*p, value_pen_tvalue)Value is UP or DOWN.
typedefenum {
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.
voidpr_move(PRINTER*p, value_xy_txy, value_direction_tdirection, intrepeat)Graphics layer supports basic drawing commands. Prototypes can be found in
graph.h file.
Move pen to x, y position (absolute to origin).
voidxy_ma(PRINTER*p, intx, inty)Move pen to x, y position (relative to current position).
voidxy_mr(PRINTER*p, intx, inty)Draw line from current position to x, y position (absolute to origin).
voidxy_va(PRINTER*p, intx, inty)Draw line from current position to x, y position (relative to current position).
voidxy_vr(PRINTER*p, intx, inty)Draw point at x, y position (absolute to origin).
voidxy_pa(PRINTER*p, intx, inty)Draw point at x, y position (relative to current position).
voidxy_pr(PRINTER*p, intx, inty)Set working origin [0,0] to x, y of physical origin.
voidxy_og(PRINTER*p, intx, inty)Draw circle with center at current position and with r radius.
voidxy_cr(PRINTER*p, intr)Draw arcus with center at current position and with r radius. Start and end of arcus are in radians.
voidxy_ar(PRINTER*p, intr, doublestart_arc, doubleend_arc)Move pen to home [0,0].
voidxy_hm(PRINTER*p)Set velocity of drawing. Values can be from 0 to 9. Default value is 8.
voidxy_vs(PRINTER*p, intv)Transforms position with center at current position about givend angle in radians.
D_POSITION_transform_position(doublex, doubley, doubleangle)Returns new position:
typedefstruct {
doublex;
doubley;
} D_POSITION;Text layer supports basic text drawing commands. Prototypes can be found in
text.h file.
Set font size.
voidxy_set_font_size(inti)Set text drawing angle. Given angle is in radians.
voidxy_set_text_angle(doubleangle)Write given text starting from current position.
voidxy_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.
voidhpgl_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.