def __init__(self, driver_type, led_layout=None, brightness=DEFAULT_BRIGHTNESS): try: if driver_type == "PiWS281x": driver = PiWS281X(self.NUM_PIXELS) elif driver_type == "WS2801": driver = WS2801(self.NUM_PIXELS, dev='/dev/spidev0.1', spi_interface=SPI_INTERFACES.PERIPHERY, spi_speed=1) elif driver_type == "SimPixel": driver = SimPixel(self.NUM_PIXELS) driver.open_browser() else: raise ValueError( "driver_type {driver_type} unknow.".format(driver_type)) except (ImportError, ValueError) as e: print("Not able to initialize the driver. Error{}".format(e)) print("Use bibliopixel.drivers.dummy_driver") driver = DriverDummy(self.NUM_PIXELS) if led_layout is not None: self.layout = Strip(driver, brightness=brightness, threadedUpdate=True) else: self.layout = Strip(driver, brightness=brightness, threadedUpdate=True) self.layout.cleanup_drivers() self.layout.start() self.animation = None
def __init__(self, driver_type, led_mapping=DEFAULT_LED_MAPPING_FILE, brightness=DEFAULT_BRIGHTNESS): #read led mapping led_mappimng_abs = os.path.join(os.path.dirname(__file__), led_mapping) with open(led_mappimng_abs) as json_file: try: data = json.load(json_file) except Exception as e: print("Json led mapping not a valid JSON.") raise e else: self.MAPPING = data try: num_pixels=self.MAPPING["num_pixels"] except: num_pixels=max(self.MAPPING.values())+1 try: if driver_type == "PiWS281x": driver = PiWS281X(num_pixels) elif driver_type == "WS2801": driver = WS2801(num_pixels, dev='/dev/spidev0.1',spi_interface= SPI_INTERFACES.PERIPHERY,spi_speed=1) elif driver_type == "SimPixel": driver = SimPixel(num_pixels) driver.open_browser() else: raise ValueError("driver_type {driver_type} unknow.".format(driver_type) ) except (ImportError, ValueError) as e: print("Not able to initialize the driver. Error{}".format(e)) print("Use bibliopixel.drivers.dummy_driver") driver = DriverDummy(num_pixels) self.layout = Strip (driver, brightness=brightness,threadedUpdate=True) self.layout.cleanup_drivers() self.layout.start() self.animation = None