def get_type_value(self, value): if self._stype == 'capacitor': capacitance, voltage = electronics.parse_capacitor(value) return self._typeclass(capacitance) if self._stype == 'resistor': resistance, wattage = electronics.parse_resistor(value) return self._typeclass(resistance)
def find_resistor(resistance, footprint, device="RES SMD", wattage=None): # TODO This should return a symbol instead, and usages should be adapted # accordingly to make consistent with find_capacitor if isinstance(resistance, str): try: resistance = Resistance(resistance) except ValueError: raise NoGedaSymbolException(resistance) if isinstance(resistance, Resistance): resistance = resistance._value if footprint[0:3] == "MY-": footprint = footprint[3:] if device == "RES THRU": resistances = iec60063.gen_vals(iec60063.get_series("E24"), iec60063.res_ostrs) if resistance in [parse_resistance(x) for x in resistances]: return construct_resistor(normalize_resistance(resistance), "0.25W") # noqa else: raise NoGedaSymbolException(resistance, device) for symbol in gsymlib: if symbol.device == device and symbol.footprint == footprint: res, watt = parse_resistor(symbol.value) sym_resistance = parse_resistance(res) if resistance == sym_resistance: return symbol.value raise NoGedaSymbolException(resistance)
def _res_smd_sanitycheck(name, device, value, footprint): v = parse_resistor(value, context={ 'device': device, 'footprint': footprint }) if not name.startswith(str(v.resistance)): return False return True
def _res_smd_searchterm(device, value, footprint): v = parse_resistor(value, context={ 'device': device, 'footprint': footprint }) parts = ['RES SMD', v.resistance, v.tolerance, footprint] parts = [str(x) for x in parts if x] return ' '.join(parts)
def find_resistor(device, footprint, resistance, wattage=None, tolerance=None, tc=None): if footprint[0:3] == "MY-": footprint = footprint[3:] if isinstance(resistance, str): try: resistance = Resistance(resistance) except ParseException: tident = ident_transform(device, resistance, footprint) symbol = get_symbol(tident) return symbol tresistor = jb_resistor(resistance, wattage=wattage, tolerance=tolerance, tc=tc) candidates = [] for symbol in gsymlib: # TODO Don't search _everything_ here # TODO Handle special resistors? if symbol.device == device and symbol.footprint == footprint: try: sresistor = parse_resistor(symbol.value) except ParseException: continue symscore = match_resistor(tresistor, sresistor) if symscore: candidates.append((symbol, symscore)) if not len(candidates): raise NoGedaSymbolException(resistance) candidates = sorted(candidates, key=lambda c: c[1], reverse=True) maxscore = candidates[0][1] candidates = [x for x in candidates if x[1] == maxscore] return bestmatch_resistor(tresistor, candidates)
def get_type_value(self, value): if self._stype == 'capacitor': return parse_capacitor(value).capacitance if self._stype == 'resistor': return parse_resistor(value).resistance
def RLIM(self): elem = self.get_elem_by_idx('RLIM') assert elem.data['device'] in ['RES SMD', 'RES THRU'] return Resistance(electronics.parse_resistance(electronics.parse_resistor(elem.data['value'])[0])) # noqa
def R2(self): # TODO switch to series.get_type_value if custom series to be supported elem = self.get_elem_by_idx('R2') assert elem.data['device'] in ['RES SMD', 'RES THRU'] return electronics.parse_resistance(electronics.parse_resistor(elem.data['value'])[0]) # noqa