def list(filter: str = None, exact: bool = True): if filter is None: return [proxy(address) for address in get_list()] elif exact: return [proxy(address) for address in get_list(filter)] else: return [ proxy(address) for address, component_type in get_list().items() if filter in component_type ]
def get(address: str, component_type: str): size = len(address) for addr, compType in get_list(component_type): if addr[:size] == address: return proxy(addr) raise Exception("no such component")
def get_component(component_type): component = PRIMARY_COMPONENTS.get(component_type) if component: return component for address in get_list(component_type): component = Component(address, component_type) set_primary(component) return component return None
def bios(): globals().pop('bios') from ucomputer import crash from ucomponent import invoke, get_list eeproms = get_list("eeprom") if not eeproms: crash("no bios found; install a configured EEPROM with Python") eeprom = eeproms[0] data = invoke(eeprom, 'get') comment = b"--[==[", b"]==]" if data.startswith(comment[0]) and comment[1] in data: data = data[len(comment[0]):].partition(comment[1])[0] context = {'__name__': '__main__', '__path__': eeprom} func = compile(data, "<EEPROM>", "exec") exec(func, context)
def find_components(component_type): return [ Component(address, component_type) for address in get_list(component_type) ]
def setup(): for address, component_type in get_list().items(): if not is_available(component_type): set_primary(component_type, address)