Skip to content

Commit

Permalink
Add traces to reversible pads
Browse files Browse the repository at this point in the history
  • Loading branch information
ceoloide committed Nov 22, 2023
1 parent 8ac9f92 commit c0a3c75
Showing 1 changed file with 50 additions and 6 deletions.
56 changes: 50 additions & 6 deletions ergogen/footprints/jst_battery_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,52 @@ module.exports = {
reversible: false,
BAT_P: { type: 'net', value: 'BAT_P' },
BAT_N: { type: 'net', value: 'GND' },
traces: true,
trace_width: 0.250,
silkscreen: true,
fabrication: true,
courtyard: true,
},
body: p => {

const get_at_coordinates = () => {
const pattern = /\(at (-?[\d\.]*) (-?[\d\.]*) (-?[\d\.]*)\)/;
const matches = p.at.match(pattern);
if (matches && matches.length == 4) {
return [parseFloat(matches[1]), parseFloat(matches[2]), parseFloat(matches[3])];
} else {
return null;
}
}

const adjust_point = (x, y) => {
const at_l = get_at_coordinates();
if(at_l == null) {
throw new Error(
`Could not get x and y coordinates from p.at: ${p.at}`
);
}
const at_x = at_l[0];
const at_y = at_l[1];
const at_angle = at_l[2];
const adj_x = at_x + x;
const adj_y = at_y + y;

const radians = (Math.PI / 180) * at_angle,
cos = Math.cos(radians),
sin = Math.sin(radians),
nx = (cos * (adj_x - at_x)) + (sin * (adj_y - at_y)) + at_x,
ny = (cos * (adj_y - at_y)) - (sin * (adj_x - at_x)) + at_y;

const point_str = `${nx.toFixed(3)} ${ny.toFixed(3)}`;
return point_str;
}

let local_nets = [
p.local_net("1").str,
p.local_net("2").str,
p.local_net("1"),
p.local_net("2"),
];

const standard_opening = `
(module "JST_PH_S2B-PH-K" (layer ${p.side}.Cu) (tedit 6135B927)
${p.at /* parametric position */}
Expand Down Expand Up @@ -91,8 +127,8 @@ module.exports = {
(pad 2 thru_hole oval (at -1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${p.BAT_N.str})
`
const reversible_pads = `
(pad 11 thru_hole oval (at -1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[0]})
(pad 12 thru_hole oval (at 1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[1]})
(pad 11 thru_hole oval (at -1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[0].str})
(pad 12 thru_hole oval (at 1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[1].str})
(pad 21 smd custom (at -1 1.8 ${180 + p.rot}) (size 0.1 0.1) (layers "F.Cu" "F.Mask")
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
Expand Down Expand Up @@ -214,6 +250,13 @@ module.exports = {
)
`

const reversible_traces = `
(segment (start ${ adjust_point(-1, 1.8)}) (end ${ adjust_point(-1,0)}) (width ${p.trace_width}) (layer "F.Cu") (net ${local_nets[0].index}))
(segment (start ${ adjust_point(-1, 1.8)}) (end ${ adjust_point(-1,0)}) (width ${p.trace_width}) (layer "B.Cu") (net ${local_nets[0].index}))
(segment (start ${ adjust_point(1, 1.8)}) (end ${ adjust_point(1,0)}) (width ${p.trace_width}) (layer "F.Cu") (net ${local_nets[1].index}))
(segment (start ${ adjust_point(1, 1.8)}) (end ${ adjust_point(1,0)}) (width ${p.trace_width}) (layer "B.Cu") (net ${local_nets[1].index}))
`

let final = standard_opening;

if(p.side == "F" || p.reversible) {
Expand Down Expand Up @@ -245,9 +288,10 @@ module.exports = {
} else if(p.side == "B") {
final += back_pads;
}

final += standard_closing;

if(p.reversible && p.traces) {
final += reversible_traces;
}
return final;
}
}

0 comments on commit c0a3c75

Please sign in to comment.