def update_lights(matrix, mean, std): """Update the state of all the lights Update the state of all the lights based upon the current frequency response matrix :param matrix: row of data from cache matrix :type matrix: list :param mean: standard mean of fft values :type mean: list :param std: standard deviation of fft values :type std: list """ global decay brightness = matrix - mean + (std * cm.lightshow.SD_low ) # MATRIX WILL BE hc.freq_bins long brightness = (brightness / (std * (cm.lightshow.SD_low + cm.lightshow.SD_high))) * ( 1.0 - (cm.lightshow.attenuate_pct / 100.0)) # insure that the brightness levels are in the correct range brightness = np.clip(brightness, 0.0, 1.0) # brightness needs to be hc.GPIOLEN long brightness = np.round(brightness, decimals=3) # calculate light decay rate if used if decay_factor > 0: decay = np.where(decay <= brightness, brightness, decay) brightness = np.where(decay - decay_factor > 0, decay - decay_factor, brightness) decay = np.where(decay - decay_factor > 0, decay - decay_factor, decay) # broadcast to clients if in server mode if server: network.broadcast(brightness) if terminal.config.enabled: terminal.curses_render(brightness) else: for blevel, pin in zip(brightness, range(hc.GPIOLEN)): hc.set_light(pin, True, blevel)
def network_client(): """Network client support If in client mode, ignore everything else and just read data from the network and blink the lights """ log.info("Network client mode starting") print "Network client mode starting..." print "press CTRL<C> to end" hc.initialize() print try: channels = network.channels channel_keys = channels.keys() while True: data = network.receive() if isinstance(data[0], int): pin = data[0] if pin in channel_keys: hc.set_light(channels[pin], True, float(data[1])) continue elif isinstance(data[0], np.ndarray): blevels = data[0] else: continue for pin in channel_keys: hc.set_light(channels[pin], True, blevels[pin]) except KeyboardInterrupt: log.info("CTRL<C> pressed, stopping") print "stopping" network.close_connection() hc.clean_up()
def update_lights(matrix, mean, std): """Update the state of all the lights Update the state of all the lights based upon the current frequency response matrix :param matrix: row of data from cache matrix :type matrix: list :param mean: standard mean of fft values :type mean: list :param std: standard deviation of fft values :type std: list """ global decay brightness = matrix - mean + (std * 0.5) brightness = brightness / (std * 1.25) # insure that the brightness levels are in the correct range brightness = np.clip(brightness, 0.0, 1.0) brightness = np.round(brightness, decimals=3) # calculate light decay rate if used if decay_factor > 0: decay = np.where(decay <= brightness, brightness, decay) brightness = np.where(decay - decay_factor > 0, decay - decay_factor, brightness) decay = np.where(decay - decay_factor > 0, decay - decay_factor, decay) # broadcast to clients if in server mode if server: network.broadcast(brightness) for blevel, pin in zip(brightness, range(hc.GPIOLEN)): hc.set_light(pin, True, blevel)