The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Attach::Stuff - Attach stuff to other stuff

SYNOPSIS

use Attach::Stuff;

# You've got a board that's 26x34 mm, with two screw holes with a 
# 2 mm diameter, spaced 3mm from the edge
my $attach = Attach::Stuff->new({
    width                => 26,
    height               => 34,
    stroke_width         => 0.3,
    screw_default_radius => 1.25, # 2mm diameter, plus some wiggle room
    screw_holes          => [
        [ 3,       3 ],
        [ 26 - 3,  3 ],
    ],
});
my $svg = $attach->draw;
print $svg->xmlify;

DESCRIPTION

You've got stuff, like a PCB board, that needs to be attached to other stuff, like a lasercut enclosure. How do you attach the stuff to the other stuff? This is a question we ask a lot when doing homebuilt Internet of Things projects. Perl has the "Internet" half down pat. This module is an attempt to improve the "Things" part.

Lasercutters and other CNC machines often work with SVGs. Or more likely SVGs can be converted into something that are converted into G-code by whatever turd of a software package came with your CNC machine. Whatever the case, you can probably start with an SVG and work your way from there.

Before you can get there, you need measurements of the board and the location of the screw holes. If you're lucky, you can find full schematics for your board that will tell you the sizes exactly. If not, you'll need to get out some callipers and possibly do some guesswork.

Protip: if you had to guess on some of the locations, etch a prototype into cardboard. Then you can lay the board over the cardboard and see if it matches up right.

METHODS

new

Constructor. Has the attributes below. Note that all lengths are measured in millimeters.

  • width

  • height

  • stroke_width - The width of the lines. Defaults to 0.3.

  • screw_default_radius - All screws will be this radius. Currently, there is no way to specify a screw with any other radius. It's recommended to add a little extra to the radius to fit the screws through.

  • screw_holes - Arrayref of arrayrefs of the x/y coords of screw holes

draw

Draw based on the parameters given in the constructor. Returns an SVG object.

mm_to_px

Takes a measurement in millimeters and returns the length in pixels according to the SVG standard. Useful if you need to draw more complex shapes for your board after Attach::Stuff did the basics. See the examples/rpi_camera.pl file in this distribution for an example of this.

SEE ALSO

SVG

LICENSE

Copyright (c) 2015, Timm Murray All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of 
  conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of 
  conditions and the following disclaimer in the documentation and/or other materials 
  provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.