Refactor audio plug module

This commit is contained in:
Roberto Alsina 2023-03-20 13:19:14 -03:00
parent 9904a412a3
commit 9bdabfdd98
5 changed files with 62 additions and 17 deletions

View File

@ -1,7 +1,10 @@
# Hole to expose a USB audio card (YMMV) # Hole to expose a USB audio card (YMMV)
# The hole is for a USB-A plug, y is measured in the hub import cadquery as cq
# (from the bottom face to middle of the hole)
from utils import punch_hole2, extrude_shape2
# The hole is for a random USB sound card.
# Consumers should set proper offsets for the hole # Consumers should set proper offsets for the hole
holes = [ holes = [
@ -9,8 +12,39 @@ holes = [
{ {
"x": 0, "x": 0,
"y": 4, "y": 4,
"height": 6, "shape": cq.Sketch().trapezoid(17, 2, 90, mode="a").fillet(2),
"width": 17,
"fillet": 2,
}, },
] ]
def add(
*,
model,
width,
height,
thickness,
offset_x,
offset_y,
bottom_face,
back_face,
shell_t
):
# Holes
if back_face:
for hole in holes:
model = punch_hole2(
model=model,
face=back_face,
# FIXME: This is weird because it's the RIGHT side,
# So it's height instead of w
# need to work on making these coherent
w=height,
h=thickness,
x_offset=offset_x - 17 / 2,
y_offset=shell_t,
hole=hole,
depth=shell_t,
)
return model

Binary file not shown.

View File

@ -180,17 +180,17 @@ def model():
) )
# Hole for audio in right side # Hole for audio in right side
for hole in audio_plug.holes: model = audio_plug.add(
model = punch_hole( model=model,
model=model, width=width,
face=">X", height=height,
w=height, thickness=thickness,
h=thickness, offset_x=111, # Offset from the front-left corner
x_offset=height - shell_t - 34.5 - audio_plug.holes[0]["width"] / 2, offset_y=0, # Offset from the bottom
y_offset=shell_t, bottom_face=None,
hole=hole, back_face=">X",
depth=shell_t, shell_t=shell_t,
) )
model = cpu_holder.add( model = cpu_holder.add(
model=model, model=model,

Binary file not shown.

View File

@ -26,6 +26,16 @@ def punch_hole(*, model, face, w, h, x_offset, y_offset, hole, depth):
) )
def extrude_shape2(*, model, face, w, h, x_offset, y_offset, hole, depth):
return (
model.faces(face)
.workplane(centerOption="CenterOfBoundBox")
.center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"])
.placeSketch(hole["shape"])
.extrude(-depth)
)
def punch_hole2(*, model, face, w, h, x_offset, y_offset, hole, depth): def punch_hole2(*, model, face, w, h, x_offset, y_offset, hole, depth):
return ( return (
model.faces(face) model.faces(face)
@ -35,6 +45,7 @@ def punch_hole2(*, model, face, w, h, x_offset, y_offset, hole, depth):
.cutBlind(-depth) .cutBlind(-depth)
) )
def hex_vents(*, size, width, height): def hex_vents(*, size, width, height):
vent_positions = [] vent_positions = []
for x in range(1, width // size): for x in range(1, width // size):
@ -53,4 +64,4 @@ def hex_vents(*, size, width, height):
} }
] ]
return vents return vents