From c0a3c75e3ae820153e7e082418c781b87d5e2af2 Mon Sep 17 00:00:00 2001 From: Marco Massarelli Date: Wed, 22 Nov 2023 02:53:27 +0000 Subject: [PATCH] Add traces to reversible pads --- ergogen/footprints/jst_battery_connector.js | 56 ++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/ergogen/footprints/jst_battery_connector.js b/ergogen/footprints/jst_battery_connector.js index c628771..0ae6e4c 100644 --- a/ergogen/footprints/jst_battery_connector.js +++ b/ergogen/footprints/jst_battery_connector.js @@ -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 */} @@ -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)) @@ -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) { @@ -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; } } \ No newline at end of file