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.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/demo/thirdparty/olinuxino/py/olinuxino.py b/demo/thirdparty/olinuxino/py/olinuxino.py
new file mode 100644
index 0000000..cc33a81
--- /dev/null
+++ b/demo/thirdparty/olinuxino/py/olinuxino.py
@@ -0,0 +1,57 @@
+import re
+
+from ee.kicad import Component
+from ee.kicad.make_bom import MakeBomStrategy
+from ee.xml import bomFile
+from ee.xml.bom_file_utils import facts
+
+
+class OlinuxinoMakeBomStrategy(MakeBomStrategy):
+ def process_part(self, component: Component, part: bomFile.Part):
+ print(component.ref)
+ print(" value={}".format(component.value))
+ print(" footprint={}".format(component.footprint))
+
+ if component.ref_type == "C":
+ v = component.value
+
+ if v == "NA":
+ print(" NA".format())
+ return part
+
+ na = v.startswith("NA(") and v.endswith(")")
+ v = v[3:-1] if na else v
+
+ r = re.compile("([0-9]+\\.?[0-9]*[pnum]F)/([0-9]+\\.?[0-9]*[k]?V)/([0-9]+%)(?:/([A-Z][0-9][A-Z]))?")
+
+ m = r.match(v)
+
+ if m:
+ capacitance = m.group(1) + " F"
+ voltage = m.group(2) + " V"
+ tolerance = m.group(3) + "%"
+ derating = m.group(4)
+
+ print(" capacitance {}".format(capacitance))
+ print(" voltage {}".format(voltage))
+ print(" tolerance {}".format(tolerance))
+ if derating:
+ print(" derating {}".format(derating))
+ if na:
+ print(" NA".format())
+
+ fs = facts(part, create=True)
+ fs.add_fact(bomFile.Fact(key="capacitance", value=capacitance))
+ fs.add_fact(bomFile.Fact(key="max_voltage", value=voltage))
+ fs.add_fact(bomFile.Fact(key="tolerance", value=tolerance))
+ if derating:
+ fs.add_fact(bomFile.Fact(key="derating", value=derating))
+
+ else:
+ print("FAIL")
+
+ return part
+
+
+def make_bom_strategy():
+ return OlinuxinoMakeBomStrategy()