Source code for jitxexamples.generative_rectangles.cap_touch

from math import floor
from jitx import (
    Circle,
    Circuit,
    Component,
    Copper,
    Landpattern,
    Pad,
    PadMapping,
    Pin,
    Port,
    Pour,
    Symbol,
    SymbolMapping,
    landpattern,
    rectangle,
)
from jitx.anchor import Anchor
from jitx.shapes.primitive import Text
from jitx.symbol import Direction


[docs] class Launch(Pad): shape = rectangle(0.5, 0.5, anchor=Anchor.W)
[docs] class Electrodelp(Landpattern): def __init__(self, width=10.0, length=30.0): self.p = {1: Launch().at(0.0, length / 2), 2: Launch().at(0.0, -length / 2)}
# self.B1 = Copper(rectangle(width=width, height=0.5, anchor=Anchor.W), 0)
[docs] class CapSymbol(Symbol): pin_name_size = 0.7874 pad_name_size = 0.7874 A = Pin((-5, 2), 2, Direction.Left) B = Pin((-5, 0), 2, Direction.Left) draws = [ Text(">VALUE", 0.55559, Anchor.C).at((0, 4.08741)), Text(">REF", 0.55559, Anchor.C).at((0, 4.87481)), # Main body rectangle rectangle(10.00002, 8.00002), # Interdigital finger patterns - representing the sensor electrodes # Top electrode fingers (connected to pin A) rectangle(0.3, 2.5).at(-3.5, 1.5), rectangle(0.3, 2.5).at(-2.5, 1.5), rectangle(0.3, 2.5).at(-1.5, 1.5), rectangle(0.3, 2.5).at(-0.5, 1.5), rectangle(0.3, 2.5).at(0.5, 1.5), rectangle(0.3, 2.5).at(1.5, 1.5), rectangle(0.3, 2.5).at(2.5, 1.5), rectangle(0.3, 2.5).at(3.5, 1.5), # Bottom electrode fingers (connected to pin B) rectangle(0.3, 2.5).at(-3.0, -1.5), rectangle(0.3, 2.5).at(-2.0, -1.5), rectangle(0.3, 2.5).at(-1.0, -1.5), rectangle(0.3, 2.5).at(0.0, -1.5), rectangle(0.3, 2.5).at(1.0, -1.5), rectangle(0.3, 2.5).at(2.0, -1.5), rectangle(0.3, 2.5).at(3.0, -1.5), # Capacitive field indication circles Circle(radius=0.15).at(-3.0, 0.5), Circle(radius=0.15).at(-2.0, 0.5), Circle(radius=0.15).at(-1.0, 0.5), Circle(radius=0.15).at(0.0, 0.5), Circle(radius=0.15).at(1.0, 0.5), Circle(radius=0.15).at(2.0, 0.5), Circle(radius=0.15).at(3.0, 0.5), Circle(radius=0.15).at(-2.5, -0.5), Circle(radius=0.15).at(-1.5, -0.5), Circle(radius=0.15).at(-0.5, -0.5), Circle(radius=0.15).at(0.5, -0.5), Circle(radius=0.15).at(1.5, -0.5), Circle(radius=0.15).at(2.5, -0.5), # Connection indicators Circle(radius=0.3).at(-4.00001, 2.00001), # Pin A indicator Circle(radius=0.3).at(-4.00001, 0.00001), # Pin B indicator # Decorative corner elements Circle(radius=0.2).at(-4.5, 3.5), Circle(radius=0.2).at(4.5, 3.5), Circle(radius=0.2).at(-4.5, -3.5), Circle(radius=0.2).at(4.5, -3.5), # Touch indication symbol in top right Text("⚡", 0.8, Anchor.C).at((3.5, 3.0)), ]
[docs] class Electrode(Component): symbol = CapSymbol() A = Port() B = Port() def __init__(self, width=10.0, length=30.0): self.landpattern = Electrodelp(width, length) self.mappings = [ SymbolMapping( { self.A: self.symbol.A, self.B: self.symbol.B, } ), PadMapping( { self.A: self.landpattern.p[1], self.B: self.landpattern.p[2], } ), ]
[docs] class CapTouch(Circuit): A = Port() B = Port() def __init__(self, width=10.0, length=30.0, pitch=0.1, bar_width=0.5): self.e = Electrode(width=width, length=length).at(0.0, 0.0) self.nets = [ self.A + self.e.A + Copper( rectangle(width=width, height=bar_width, anchor=Anchor.W).at( 0.0, length / 2 ), 0, ), self.B + self.e.B + Copper( rectangle(width=width, height=bar_width, anchor=Anchor.W).at( 0.0, -length / 2 ), 0, ), ] num_fingies = floor(width / (pitch * 4)) offset = pitch * 2 + bar_width self.fingies = [ self.A + Copper( rectangle(pitch, length - offset).at(pitch * (idx * 4 + 1), pitch), 0 ) for idx in range(num_fingies) ] self.fingoos = [ self.B + Copper( rectangle(pitch, length - offset).at(pitch * (idx * 4 + 3), -pitch), 0 ) for idx in range(num_fingies) ]