aboutsummaryrefslogtreecommitdiff
path: root/demo/thirdparty/olinuxino/py/olinuxino.py
diff options
context:
space:
mode:
Diffstat (limited to 'demo/thirdparty/olinuxino/py/olinuxino.py')
-rw-r--r--demo/thirdparty/olinuxino/py/olinuxino.py110
1 files changed, 82 insertions, 28 deletions
diff --git a/demo/thirdparty/olinuxino/py/olinuxino.py b/demo/thirdparty/olinuxino/py/olinuxino.py
index 2153613..0b6fd1e 100644
--- a/demo/thirdparty/olinuxino/py/olinuxino.py
+++ b/demo/thirdparty/olinuxino/py/olinuxino.py
@@ -1,55 +1,109 @@
import re
+from ee import EeException, EeVal
from ee.kicad import Component
from ee.kicad.make_bom import MakeBomStrategy
-from ee.xml import types
+from ee.xml import types, bom_file_utils
+from ee.part import fact_keys
from ee.xml.bom_file_utils import facts
+c_value_re = re.compile("([0-9]+\\.?[0-9]*[mupn]F)/([0-9]+\\.?[0-9]*[k]?V)/([0-9]+)%(?:/([A-Z][0-9][A-Z]))?")
+r_value_re = re.compile(r"([^/]+)(?:/([^/]+)(?:/([^/]+))?)?")
+
class OlinuxinoMakeBomStrategy(MakeBomStrategy):
+
+ @staticmethod
+ def set_default(fs, fact_key: str, value):
+ fact = bom_file_utils.find_fact(fs, fact_key)
+ if fact:
+ return
+
+ fs.add_fact(types.Fact(key=fact_key, value=value))
+
def process_part(self, component: Component, part: types.Part):
+ debug = False
+
print(component.ref)
print(" value={}".format(component.value))
print(" footprint={}".format(component.footprint))
- if component.ref_type == "C":
- v = component.value
+ v = component.value
- if v == "NA":
- print(" NA".format())
- return part
+ fp_lib, fp_part = None, None
+ if component.footprint:
+ s = component.footprint.split(":")
+ fp_lib, fp_part = s[0], s[1]
+
+ fs = facts(part, create=True)
- na = v.startswith("NA(") and v.endswith(")")
- v = v[3:-1] if na else v
+ na = v.startswith("NA(") and v.endswith(")") or v == "NA"
+ if na:
+ v = v[3:-1]
- r = re.compile("([0-9]+\\.?[0-9]*[pnum]F)/([0-9]+\\.?[0-9]*[k]?V)/([0-9]+%)(?:/([A-Z][0-9][A-Z]))?")
+ if v == "":
+ pass
+ elif component.ref_type == "C":
+ m = c_value_re.match(v)
- m = r.match(v)
+ if not m:
+ raise EeException("Bad value: {}".format(v))
- if m:
- capacitance = m.group(1) + " F"
- voltage = m.group(2) + " V"
- tolerance = m.group(3) + "%"
- derating = m.group(4)
+ capacitance = m.group(1)
+ voltage = m.group(2)
+ tolerance = str(int(m.group(3))) + "%"
+ rs_198_class_2 = m.group(4)
- print(" capacitance {}".format(capacitance))
- print(" voltage {}".format(voltage))
- print(" tolerance {}".format(tolerance))
- if derating:
- print(" derating {}".format(derating))
+ if debug:
+ print(" capacitance {}".format(capacitance))
+ print(" voltage {}".format(voltage))
+ print(" tolerance {}".format(tolerance))
+ if rs_198_class_2:
+ print(" rs_198_class_2 {}".format(rs_198_class_2))
if na:
print(" NA".format())
- fs = facts(part, create=True)
- fs.add_fact(types.Fact(key="capacitance", value=capacitance))
- fs.add_fact(types.Fact(key="max_voltage", value=voltage))
- fs.add_fact(types.Fact(key="tolerance", value=tolerance))
- if derating:
- fs.add_fact(types.Fact(key="derating", value=derating))
+ fs.add_fact(types.Fact(key=fact_keys.capacitance, value=capacitance))
+ fs.add_fact(types.Fact(key=fact_keys.max_voltage, value=voltage))
+ fs.add_fact(types.Fact(key=fact_keys.value_tolerance, value=tolerance))
+ if rs_198_class_2:
+ fs.add_fact(types.Fact(key=fact_keys.rs_198_class_2, value=rs_198_class_2))
+
+ elif component.ref_type == "R":
+ # NA
+ # NA(510R)
+ # NA(243R/1%)
+ # 4.7k
+ # 8.25k/1%
+ # 120R
+ # 0R(Board_Mounted)
+ # 0.01R/1%/1206
+
+ match = r_value_re.match(v)
+ if not match:
+ return part
+
+ resistance, tolerance, size = match.groups()
+ if resistance.endswith("R"):
+ resistance = resistance[:-1]
+
+ resistance = str(EeVal.parse(resistance))
+
+ fs.add_fact(types.Fact(key=fact_keys.resistance, value=resistance))
+ if tolerance:
+ fs.add_fact(types.Fact(key=fact_keys.value_tolerance, value=tolerance))
+ if size:
+ fs.add_fact(types.Fact(key=fact_keys.imperial_footprint_size, value=size))
+
+ self.set_default(fs, fact_keys.value_tolerance, "10%")
+ else:
+ fs.add_fact(types.Fact(key=fact_keys.value, value=v))
- else:
- print("FAIL")
+ if na:
+ fs.add_fact(types.Fact(key=fact_keys.place_part, value="no"))
+ # raise EeException("Unknown component kind: ref={}, ref type:{}, value={}, fp_lib={}, fp_part={}".
+ # format(component.ref, component.ref_type, v, fp_lib, fp_part))
return part