def main(argv): init_host(argv) berry_list = get_berry_list() berries = [berry_factory('yo', berry[0], berry[1]) for berry in berry_list] btn = None led = None for berry in berries: print('name: {}, type: {}, guid: {}'.format(berry.name, berry.berry_type, berry.addr)) if berry.berry_type == 'Button': btn = berry if berry.berry_type == 'RGB': led = berry try: v = 0 i = 0 while True: berries[i].set_status_led(v) i = (i + 1) % len(berries) v = random.randint(0, 1) if btn.state == 1: led.color = [150, 150, 150] else: led.color = [0, 0, 0] sleep(.01) except: print('End')
def sync_project(self): api.init_host(sys.argv) berry_list = api.get_berry_list() self.project_berries.clear() self.project_init = importlib.import_module('{}.{}'.format( self.project_name, '__init__')) self.project_files = self.project_init.berry_files # This is how you get the module from here: # package = '.{}'.format(file) # mod = importlib.import_module(package, self.project_name) # For each berry from the network, see if the guid is present in the project files dict # If not, make a new file with a generic name and add it both to the project files dict # and the persistent project __init__.py field via self._update_project_files_() for berry_inst in berry_list: guid = berry_inst[0] berry_type = berry_inst[1] if guid in self.project_files.keys(): name = self.project_files[guid] else: name = self._make_berry_file(berry_type) self.project_files[guid] = name self._update_project_files_() berry = berry_factory(name, guid, berry_type) self.project_berries[name] = berry
def light_sequence(self): # This function will run through the lights identifying the berries. berry_list = [] init_host(sys.argv) berry_list = get_berry_list() berries = [berry_factory('Name Your Berry', berry[0], berry[1]) for berry in berry_list] btn = None led = None slider = None knob = None for berry in berries: print('name: {}, type: {}, guid: {}'.format(berry.name, berry.berry_type, berry.addr)) #print("did you get here??") Worked for berry in berries: #led.color = [0,0,0] print(berry.berry_type) print("next berry : \n") berry.set_status_led(1) #image_difference = light_seeker() #image_difference sleep(2) berry.set_status_led(0)
def main(argv): init_host(argv) berry_list = get_berry_list() berry_mod_list = {} berries = {} for berry_entry in berry_list: print('{}: {}'.format(berry_entry[1], berry_entry[0])) # Import all berry code files and store module references in dictionary with guid as key # The guid is retrieved as the value in the dictionary with the names of the berry files for name in berry_files: mod = importlib.import_module(name) berry_mod_list[berry_files[name]] = mod print(mod.__name__) # Create berry objects and store in dictionary. Register events for berry_entry in berry_list: berry_guid = berry_entry[0] if berry_guid in berry_mod_list: berry_module = berry_mod_list[berry_guid] berry_type = berry_entry[1] berry_name = berry_module.__name__ berry = berry_factory(berry_name, berry_guid, berry_type) berries[berry.name] = berry # Store berry reference in dictionary # If the berry has events, register the event handlers in the imported file to the events if hasattr(berry, 'events'): for event in berry.events.values(): handler = getattr(berry_module, event) if not empty(handler): getattr(berry, event)(handler) print(dir(berry_mod_list[berries['button1'].addr].__dict__)) # Add all berry object references to the namespaces of all the imported berry files for mod in berry_mod_list.values(): mod.__dict__.update(berries) # Spin while event-driven program runs while True: pass