Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions bom/helpers.zen
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,33 @@ def prop(c, names):


def set_primary_and_alts(c, primary, manufacturer, alts):
"""Set primary MPN and alternatives on component."""
"""Set primary MPN and alternatives on component.

alts can be either:
- A list of MPN strings (uses primary's manufacturer for all)
- A list of {"mpn": ..., "manufacturer": ...} dicts
"""
c.mpn = primary
c.manufacturer = manufacturer
if alts and len(alts) > 0:
c.alternatives = [{"mpn": m, "manufacturer": manufacturer} for m in alts]
if type(alts[0]) == "string":
c.alternatives = [{"mpn": m, "manufacturer": manufacturer} for m in alts]
else:
c.alternatives = alts


def set_from_matches(c, matches):
"""Set primary MPN and alternatives from a list of match dicts.

Each match must have "mpn" and "manufacturer" keys.
First match becomes primary, rest become alternatives.
"""
if not matches:
return
c.mpn = matches[0]["mpn"]
c.manufacturer = matches[0]["manufacturer"]
if len(matches) > 1:
c.alternatives = [{"mpn": p["mpn"], "manufacturer": p["manufacturer"]} for p in matches[1:]]


def find_e_series_match(r, series_tolerance, e_series_types):
Expand Down
18 changes: 5 additions & 13 deletions bom/match_generics.zen
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ load(
"helpers.zen",
"prop",
"set_primary_and_alts",
"set_from_matches",
"find_e_series_match",
"iec60062_3digit",
"iec60062_4digit",
Expand Down Expand Up @@ -612,18 +613,15 @@ def assign_house_led(c, house_leds_by_pkg):
if req_voltage:
if req_voltage.tolerance == 0.0:
# Assume 15% tolerance if not specified
req_voltage = req_voltage.with_tolerance(0.15)
req_voltage = req_voltage.with_tolerance(0.20)
# LED's Vf should be within the specified range
if p["forward_voltage"] not in req_voltage:
continue

matches.append(p)

if matches:
# Use first match as primary, rest as alternatives
manufacturer = matches[0]["manufacturer"]
all_mpns = [p["mpn"] for p in matches]
set_primary_and_alts(c, all_mpns[0], manufacturer, all_mpns[1:])
set_from_matches(c, matches)
c.matcher = "assign_house_led"
return

Expand Down Expand Up @@ -673,10 +671,7 @@ def assign_house_ferrite_bead(c, house_fb_by_pkg):
matches.append(p)

if matches:
# Use first match as primary, rest as alternatives
manufacturer = matches[0]["manufacturer"]
all_mpns = [p["mpn"] for p in matches]
set_primary_and_alts(c, all_mpns[0], manufacturer, all_mpns[1:])
set_from_matches(c, matches)
c.matcher = "assign_house_ferrite_bead"
return

Expand Down Expand Up @@ -750,10 +745,7 @@ def assign_house_tvs(c, house_tvs_by_pkg):
matches.append(p)

if matches:
# Use first match as primary, rest as alternatives
manufacturer = matches[0]["manufacturer"]
all_mpns = [p["mpn"] for p in matches]
set_primary_and_alts(c, all_mpns[0], manufacturer, all_mpns[1:])
set_from_matches(c, matches)
c.matcher = "assign_house_tvs"
return

Expand Down