Exemplo n.º 1
0
def show_graph(temp, load):
    segment_pixels_count = output_device.NUM_PIXELS / 4
    temp = temp / 80 * output_device.NUM_PIXELS
    if isinstance(load, list):
        load = [x / 100 * segment_pixels_count for x in load]
    else:
        load = load / 100 * output_device.NUM_PIXELS
    pixels = range(output_device.NUM_PIXELS)
    current = 0
    if direction.lower() == "rtl":
        pixels = reversed(pixels)
    for x in pixels:
        r, g, b = 0, 0, 0
        if temp > 0:
            r = get_value(temp)
            temp -= 1
        if isinstance(load, list):
            segment_index = math.trunc(x / segment_pixels_count)
            if load[segment_index] > 0:
                b = get_value(load[segment_index])
                load[segment_index] -= 1
        else:
            if load > 0:
                b = get_value(load)
                load -= 1

        # show the marker, if it's not the last pixel and if it's the last pixel of the segment.
        if marker and current + 1 != output_device.NUM_PIXELS and (
                current + 1) % segment_pixels_count == 0:
            g = 255
        output_device.set_pixel(x, r, g, b)
        current += 1

    output_device.show()
Exemplo n.º 2
0
def lightShow(jumpVal, jumpPR):
    heightVal = 10 * jumpVal * ledshim.NUM_PIXELS
    prVal = 10 * jumpPR * ledshim.NUM_PIXELS

    # Green lights show your current PR
    r, g, b = 0, 255, 0

    if heightVal < prVal:
        # Additional red lights if you don't beat your PR
        r = 255
    else:
        # Additional blue lights if you beat the PR
        b = 255

    # Set LED colors
    for x in range(ledshim.NUM_PIXELS):
        if heightVal < 0:
            r, b = 0, 0
        if prVal < 0:
            g = 0

        ledshim.set_pixel(x, r, g, b)
        heightVal -= 1
        prVal -= 1

    # Turn on the LEDs
    ledshim.show()
Exemplo n.º 3
0
    def drawAndReset(self):
        for i in range(ledshim.NUM_PIXELS):
            j = ledshim.NUM_PIXELS - i - 1
            ledshim.set_pixel(i, self.array[j][0], self.array[j][1],
                              self.array[j][2])
            self.array[j] = (0, 0, 0)

        ledshim.show()
Exemplo n.º 4
0
 def reset():
     pixelCount = (request.json['pixelCount'])
     delay = 0.1
     for pixel in range(pixelCount - 1, -1, -1):
         ledshim.set_pixel(pixel, 0, 0, 0)
         ledshim.show()
         time.sleep(delay)
     return '200 OK'
Exemplo n.º 5
0
def show_graph(v, r, g, b):
    v *= ledshim.NUM_PIXELS
    for x in range(ledshim.NUM_PIXELS):
        if v < 0:
            r, g, b = 0, 0, 0
        else:
            r, g, b = [int(min(v, 1.0) * c) for c in [r, g, b]]
        ledshim.set_pixel(x, r, g, b)
        v -= 1
    ledshim.show()
Exemplo n.º 6
0
 def set_pixel(pixel, status):
     if status == 'red':
         ledshim.set_pixel(pixel, 255, 0, 0, 0.5)
     elif status == 'amber':
         ledshim.set_pixel(pixel, 255, 140, 0, 0.5)
     elif status == 'green':
         ledshim.set_pixel(pixel, 0, 255, 0, 0.5)
     else:
         ledshim.set_pixel(pixel, 0, 0, 0)
     ledshim.show()
     return
Exemplo n.º 7
0
    def drawAndReset(self):
        for i in range(ledshim.NUM_PIXELS):
            ledshim.set_pixel(
                i, 
                self.array[i][0], 
                self.array[i][1], 
                self.array[i][2]
            )
            self.array[i] = (0,0,0)

        ledshim.show()
Exemplo n.º 8
0
def solid():
    global animateStop
    animateStop = False
    step = 0
    while not animateStop:
        if step == 0: ledshim.set_all(128, 0, 0)
        if step == 1: ledshim.set_all(0, 128, 0)
        if step == 2: ledshim.set_all(0, 0, 128)
        step += 1
        step %= 3
        ledshim.show()
        time.sleep(0.5)
Exemplo n.º 9
0
def show_graph(v, r, g, b, i, c):
    v *= ledshim.NUM_PIXELS / c
    for x in range(int((ledshim.NUM_PIXELS / c) * i),
                   int((ledshim.NUM_PIXELS / c) * (i + 1))):
        if v < 0:
            r, g, b = 0, 0, 0
        else:
            r, g, b = [int(min(v, 1.0) * c) for c in [r, g, b]]
        ledshim.set_pixel(x, r, g, b)
        v -= 1

    ledshim.show()
Exemplo n.º 10
0
def blink_ledshim():
    for i in range(3):
        for j in range(ledshim.NUM_PIXELS):
            ledshim.set_pixel(j, 255, 0, 0)

        ledshim.show()
        time.sleep(0.1)

        for j in range(ledshim.NUM_PIXELS):
            ledshim.set_pixel(j, 0, 0, 0)

        ledshim.show()
        time.sleep(0.2)
Exemplo n.º 11
0
def larson():
    global animateStop
    animateStop = False
    REDS = [0] * 56
    SCAN = [1, 2, 4, 8, 16, 32, 64, 128, 255]
    REDS[28 - len(SCAN):28 + len(SCAN)] = SCAN + SCAN[::-1]
    start_time = time.time()
    while not animateStop:
        delta = (time.time() - start_time) * 56
        offset = int(abs((delta % len(REDS)) - 28))
        for i in range(0, 28):
            ledshim.set_pixel(i, REDS[offset + i], 0, 0)
        ledshim.show()
        time.sleep(0.05)
Exemplo n.º 12
0
def show_graph(v, r, g, b):
    v *= ledshim.NUM_PIXELS
    for x in range(ledshim.NUM_PIXELS):
        hue = ((hue_start +
                ((x / float(ledshim.NUM_PIXELS)) * hue_range)) % 360) / 360.0
        r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(hue, 1.0, 1.0)]
        if v < 0:
            brightness = 0
        else:
            brightness = min(v, 1.0) * max_brightness

        ledshim.set_pixel(x, r, g, b, brightness)
        v -= 1

    ledshim.show()
Exemplo n.º 13
0
def breakup():
    stopAnimations()  # stop animation thread
    showTime = 2.0  # show for 2 seconds
    startTime = time.time()
    while time.time() - startTime < showTime:
        pixels = random.sample(range(ledshim.NUM_PIXELS), random.randint(1, 5))
        for i in range(ledshim.NUM_PIXELS):
            if i in pixels:
                ledshim.set_pixel(i, 255, 150, 0)
            else:
                ledshim.set_pixel(i, 0, 0, 0)
        ledshim.show()
        time.sleep(0.05)
    ledshim.clear()  # turn off after showTime
    ledshim.show()
Exemplo n.º 14
0
def update_led_row(event_times):
    global working_hours
    current_time = datetime.datetime.now()

    if start_hour <= current_time.hour < end_hour:
        working_hours = True
        set_indicator_led(current_time_event_overlap_hew, 1)
    else:
        working_hours = False
        set_indicator_led(current_time_hew, 1)

    # Create the time outline
    for x in range(num_leds):
        if x < start_extra:
            set_pixel(x, edge_hew, 1, edge_brightness)
        elif x < (start_extra + leds_for_all_hours):
            set_pixel(x, work_day_hew, 1, work_day_brightness)
        else:
            set_pixel(x, edge_hew, 1, edge_brightness)

    # Colour in events
    # TODO: If event is outside of working day don't include it
    # print("LED Helper: Event times", event_times)
    for event in event_times:
        event_hour = int(event.get('start').split(':')[0])
        event_minute = int(event.get('start').split(':')[1])
        minute_duration = event.get('duration')
        if event_hour < current_time.hour or (
                event_hour == current_time.hour
                and event_minute < current_time.minute):
            highlight_event_time(event_hour, event_minute, minute_duration,
                                 event_hew, event_brightness_past)
        else:
            highlight_event_time(event_hour, event_minute, minute_duration,
                                 event_hew, event_brightness)

    # Colour in the current time marker
    if working_hours:
        highlight_current_time(current_time.hour, current_time.minute)

    ledshim.show()
Exemplo n.º 15
0
def pulse():
    global animateStop
    animateStop = False
    while not animateStop:
        for z in list(range(1, 10)[::-1]) + list(range(1, 10)):
            fwhm = 15.0 / z
            gauss = make_gaussian(fwhm)
            y = 4
            start = time.time()
            for x in range(ledshim.NUM_PIXELS):
                h = 0.5
                s = 1.0
                v = gauss[x, y]
                rgb = colorsys.hsv_to_rgb(h, s, v)
                r, g, b = [int(255.0 * i) for i in rgb]
                ledshim.set_pixel(x, r, g, b)
            ledshim.show()
            end = time.time()
            t = end - start
            if t < 0.04:
                time.sleep(0.04 - t)
Exemplo n.º 16
0
    def on_wait(self, agent, t):
        FALLOFF = 1.9
        SCAN_SPEED = 4

        # ledshim.set_brightness(0.4)

        ledshim.set_clear_on_exit()
        ledshim.clear()
        ledshim.show()

        # Buffering start and end time to avoid hitting associations,
        # deauths, and handshakes since it can bug out the wait cycle
        time.sleep(1)

        start_time = time.time()
        while (time.time() - start_time) < (t - 2):
            delta = (time.time() - start_time)
            offset = (math.sin(delta * SCAN_SPEED) + 1) / 2
            hue = int(round(offset * 360))
            max_val = ledshim.NUM_PIXELS - 1
            offset = int(round(offset * max_val))
            for x in range(ledshim.NUM_PIXELS):
                sat = 1.0
                val = max_val - (abs(offset - x) * FALLOFF)
                val /= float(max_val)  # Convert to 0.0 to 1.0
                val = max(val, 0.0)  # Ditch negative values

                r, g, b = [255, 0, 0]
                ledshim.set_pixel(x, r, g, b, val / 4)

            ledshim.show()
            time.sleep(0.001)

        ledshim.clear()
        ledshim.show()
Exemplo n.º 17
0
def on_message(client, userdata, msg):

    data = msg.payload.split(',')
    command = data.pop(0)

    if command == 'clr' and len(data) == 0:
        ledshim.clear()
        ledshim.show()
        return

    if command == 'rgb' and len(data) == 4:
        try:
            pixel = data.pop(0)

            if pixel == '*':
                pixel = None
            else:
                pixel = int(pixel)
                if pixel > 7:
                    print('Pixel out of range: ' + str(pixel))
                    return

            r, g, b = [int(x) & 0xff for x in data]

            print(command, pixel, r, g, b)

        except ValueError:
            print('Malformed command: ' + str(msg.payload))
            return

        if pixel is None:
            for x in range(ledshim.NUM_PIXELS):
                ledshim.set_pixel(x, r, g, b)
        else:
            ledshim.set_pixel(pixel, r, g, b)

        ledshim.show()
        return
Exemplo n.º 18
0
    def on_deauthentication(self, agent, access_point, client_station):

        ledshim.set_clear_on_exit()
        ledshim.clear()
        ledshim.show()

        num = 5

        while num >= 0:
            pixels = random.sample(range(ledshim.NUM_PIXELS),
                                   random.randint(1, 5))
            for i in range(ledshim.NUM_PIXELS):
                if i in pixels:
                    ledshim.set_pixel(i, 255, 0, 0)
                else:
                    ledshim.set_pixel(i, 0, 0, 0)
            ledshim.show()
            num -= 1
            time.sleep(0.02)

        ledshim.clear()
        ledshim.show()
Exemplo n.º 19
0
    def on_handshake(self, agent, filename, access_point, client_station):

        ledshim.set_clear_on_exit()
        ledshim.clear()
        ledshim.show()

        num = 20

        while num >= 0:
            pixels = random.sample(range(ledshim.NUM_PIXELS),
                                   random.randint(1, 5))
            for i in range(ledshim.NUM_PIXELS):
                if i in pixels:
                    ledshim.set_pixel(i, random.randint(0, 255),
                                      random.randint(0, 255),
                                      random.randint(0, 255))
                else:
                    ledshim.set_pixel(i, 0, 0, 0)
            ledshim.show()
            num -= 1
            time.sleep(0.001)

        ledshim.clear()
        ledshim.show()
Exemplo n.º 20
0
ledshim.set_clear_on_exit()


def make_gaussian(fwhm):
    x = np.arange(0, ledshim.NUM_PIXELS, 1, float)
    y = x[:, np.newaxis]
    x0, y0 = 3.5, (ledshim.NUM_PIXELS / 2) - 0.5
    fwhm = fwhm
    gauss = np.exp(-4 * np.log(2) * ((x - x0)**2 + (y - y0)**2) / fwhm**2)
    return gauss


while True:
    for z in list(range(1, 10)[::-1]) + list(range(1, 10)):
        fwhm = 15.0 / z
        gauss = make_gaussian(fwhm)
        start = time.time()
        y = 4
        for x in range(ledshim.NUM_PIXELS):
            h = 0.5
            s = 1.0
            v = gauss[x, y]
            rgb = colorsys.hsv_to_rgb(h, s, v)
            r, g, b = [int(255.0 * i) for i in rgb]
            ledshim.set_pixel(x, r, g, b)
        ledshim.show()
        end = time.time()
        t = end - start
        if t < 0.04:
            time.sleep(0.04 - t)
Exemplo n.º 21
0
 def show(self):
     ledshim.show()
Exemplo n.º 22
0
 def on_loaded(self):
     logging.info("Fireworks locked and loaded")
     ledshim.clear()
     ledshim.show()
Exemplo n.º 23
0
def test_setup():
    sys.modules['smbus'] = mock.Mock()
    import ledshim
    ledshim.show()
Exemplo n.º 24
0
def update():
    for i in range(ledshim.NUM_PIXELS):
        ledshim.set_pixel(i, grid[i][0], grid[i][1], grid[i][2])
    ledshim.show()
Exemplo n.º 25
0
    max_value = 255
    if smooth and value <= 1:
        return max_value * value
    else:
        return max_value


def show_info():
    temp = 0
    load = 0
    if mode in ['mixed', 'temp']:
        temp = get_cpu_temperature()
    if mode in ['mixed', 'load']:
        if segmented:
            load = psutil.cpu_percent(percpu=segmented)
        else:
            load = psutil.cpu_percent()
    show_graph(temp, load)


if __name__ == '__main__':
    while True:
        if running:
            show_info()
            time.sleep(interval)
        else:
            break
    # shut off pixels and exit
    output_device.clear()
    output_device.show()
Exemplo n.º 26
0
 def hide():
     for line in get_lines():
         ledshim.set_pixel(line, 0, 0, 0)
     ledshim.show()
Exemplo n.º 27
0
def show_all(state):
    for i in range(ledshim.NUM_PIXELS):
        val = state * 255
        ledshim.set_pixel(i, val, val, val)
    ledshim.show()