Skip to content

Instantly share code, notes, and snippets.

@keshuaixu
Created January 8, 2024 06:23
Show Gist options
  • Save keshuaixu/881ba3a5263ca708a8a695c6c1e33869 to your computer and use it in GitHub Desktop.
Save keshuaixu/881ba3a5263ca708a8a695c6c1e33869 to your computer and use it in GitHub Desktop.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
from __future__ import division
import pcbnew
import pcbnew
import FootprintWizardBase
import PadArray as PA
class FFCSegment(FootprintWizardBase.FootprintWizard):
def GetName(self):
return "FFCSegment"
def GetDescription(self):
return "FFC segments"
def GenerateParameterList(self):
self.AddParam("Traces", "n", self.uInteger, 8, multiple=1, min_value=1)
self.AddParam('Traces', 'width', self.uMM, 0.2, designator='W')
self.AddParam('Traces', 'length', self.uMM, 10, designator='L')
self.AddParam('Traces', 'spacing', self.uMM, 0.2, designator='S')
@property
def traces(self):
return self.parameters['Traces']
def CheckParameters(self):
pass
def GetValue(self):
return "Segment-{n}".format(
n = self.traces['n']
)
def BuildThisFootprint(self):
h_pad = PA.PadMaker(self.module).SMDPad( self.traces['width'], self.traces['width'],
shape=pcbnew.PAD_SHAPE_RECT)
pitch = self.traces['spacing'] + self.traces['width']
offset = pcbnew.PutOnGridMM((self.traces['width'] + self.traces['spacing']) * (self.traces['n'] - 1) / 2, 0.0001)
# left
pin1Pos = pcbnew.VECTOR2I(0, 0)
array = PA.PadLineArray(h_pad, self.traces['n'], pitch, True, pin1Pos)
array.SetFirstPadInArray(1)
array.AddPadsToModule(self.draw)
# right
pin1Pos = pcbnew.VECTOR2I(self.traces['length'], 0)
array = PA.PadLineArray(h_pad, self.traces['n'], pitch, True, pin1Pos)
array.SetFirstPadInArray(1)
array.AddPadsToModule(self.draw)
# traces
self.draw.SetLayer(pcbnew.F_Cu)
self.draw.SetLineThickness(self.traces['width'])
for i in range(self.traces['n']):
y = i * pitch - offset
self.draw.Line(0, y, self.traces['length'], y)
# set SMD attribute
self.module.SetAttributes(pcbnew.FP_SMD)
for i in range(self.traces['n']):
self.module.AddNetTiePadGroup(f'{i+1}, {i+1}')
FFCSegment().register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment