Ejemplo n.º 1
0
def rssiGraph(args):
    if 'strip' in args:
        strip = args['strip']
    else:
        return False

    if 'INTERFACE' in args:
        INTERFACE = args['INTERFACE']
    else:
        return False

    if len(INTERFACE.nodes) < 1:
        return False

    height = args['ledRows']
    width = strip.numPixels() // height
    im = Image.new('RGB', [width, height])
    draw = ImageDraw.Draw(im)

    if width < len(INTERFACE.nodes):
        barWidth = 1
    else:
        barWidth = width // len(INTERFACE.nodes)

    loop = range(args['iterations']) if 'iterations' in args else repeat(True)
    for _ in loop:
        draw.rectangle((0, 0, width, height), fill=(0, 0, 0))

        for node in INTERFACE.nodes:
            rssi_min = node.node_nadir_rssi
            rssi_max = node.node_peak_rssi
            rssi_val = node.current_rssi

            color = convertColor(args['manager'].getDisplayColor(node.index))

            rssi_range = rssi_max - rssi_min

            if rssi_range:
                point = (rssi_max - rssi_val) / float(rssi_range) * height

                draw.rectangle(
                    (barWidth * node.index, point,
                     (barWidth * node.index) + barWidth - 1, height),
                    fill=color)

        img = im.rotate(90 * args['panelRotate'])
        setPixels(strip, img, args['invertedPanelRows'])
        strip.show()

        gevent.idle()
Ejemplo n.º 2
0
def showBitmap(args):
    if 'strip' in args:
        strip = args['strip']
    else:
        return False

    bitmaps = args['bitmaps']
    if bitmaps and bitmaps is not None:
        for bitmap in bitmaps:
            img = Image.open(bitmap['image'])
            delay = bitmap['delay']

            img = img.rotate(90 * args['panelRotate'])
            img = img.resize(
                (strip.numPixels() // args['ledRows'], args['ledRows']))

            setPixels(strip, img, args['invertedPanelRows'])
            strip.show()
            gevent.sleep(delay / 1000.0)
Ejemplo n.º 3
0
def printCharacter(args):
    if 'strip' in args:
        strip = args['strip']
    else:
        return False

    if 'text' in args:
        text = str(args['text'])
    else:
        return False

    if 'color' in args:
        color = convertColor(args['color'])
    else:
        color = convertColor(ColorVal.WHITE)

    height = args['ledRows']
    width = strip.numPixels() // height
    im = Image.new('RGB', [width, height])
    draw = ImageDraw.Draw(im)

    use_small_flag = True
    if height >= 16:
        font = ImageFont.truetype(FONT_PATH + "/RotorHazardPanel16.ttf", 16)
        w, h = font.getsize(text)
        if w <= width - 1:
            use_small_flag = False
            h = 16

    if use_small_flag:
        font = ImageFont.truetype(FONT_PATH + "/RotorHazardPanel8.ttf", 8)
        w, h = font.getsize(text)
        h = 8

    draw.text((int((width - w) / 2) + 1, int((height - h) / 2)),
              text,
              font=font,
              fill=(color))

    img = im.rotate(90 * args['panelRotate'])

    setPixels(strip, img, args['invertedPanelRows'])
    strip.show()
Ejemplo n.º 4
0
def scrollText(args):
    if 'strip' in args:
        strip = args['strip']
    else:
        return False

    if args['data'] == 'message':
        text = str(args['message'])
    elif args['data'] == 'lap_time':
        text = str(args['lap']['lap_time_formatted'])
    else:
        return False

    if 'color' in args:
        color = convertColor(args['color'])
    else:
        color = convertColor(ColorVal.WHITE)

    height = args['ledRows']
    width = strip.numPixels() // height
    im = Image.new('RGB', [width, height])
    draw = ImageDraw.Draw(im)

    if height >= 16:
        font = ImageFont.truetype(FONT_PATH + "/RotorHazardPanel16.ttf", 16)
        w, h = font.getsize(text)
        h = 16
    else:
        font = ImageFont.truetype(FONT_PATH + "/RotorHazardPanel8.ttf", 8)
        w, h = font.getsize(text)
        h = 8

    draw_y = int((height - h) / 2)

    for i in range(-width, w + width):
        draw.rectangle((0, 0, width, height), fill=(0, 0, 0))
        draw.text((-i, draw_y), text, font=font, fill=(color))
        img = im.rotate(90 * args['panelRotate'])
        setPixels(strip, img, args['invertedPanelRows'])
        strip.show()
        gevent.sleep(10 / 1000.0)
Ejemplo n.º 5
0
def multiLapGrid(args):
    if 'strip' in args:
        strip = args['strip']
    else:
        return False

    if 'RACE' in args:
        RACE = args['RACE']
    else:
        return False

    if args['RACE'].results and 'by_race_time' in args['RACE'].results:
        leaderboard = args['RACE'].results['by_race_time']
    else:
        return False

    height = args['ledRows']
    width = strip.numPixels() // height
    im = Image.new('RGB', [width, height])
    draw = ImageDraw.Draw(im)
    if height < 16:
        return False

    half_height = height / 2
    half_width = width / 2

    if height >= 32:
        font = ImageFont.truetype(FONT_PATH + "/RotorHazardPanel16.ttf", 16)
        font_h = 16
    else:
        font = ImageFont.truetype(FONT_PATH + "/RotorHazardPanel8.ttf", 8)
        font_h = 8

    active_nodes = []
    for line in leaderboard:
        active_nodes.append(line['node'])

    active_nodes.sort()

    for line in leaderboard:
        if line['node'] < 4:
            if line['laps']:
                if line['laps'] <= 19:
                    text = str(line['laps'])
                else:
                    text = '+'
            else:
                if RACE.race_status == RaceStatus.DONE:
                    text = str(line['laps'])
                else:
                    # first callsign character
                    text = line['callsign'][0]

            w, h = font.getsize(text)
            h = font_h
            color = convertColor(args['manager'].getDisplayColor(
                line['node'], from_result=True))

            # draw positions
            if active_nodes.index(line['node']) == 0:
                pos_x = int((half_width - w) / 2)
                pos_y = int(((half_height) - h) / 2)
            elif active_nodes.index(line['node']) == 1:
                pos_x = int(((half_width - w) / 2) + half_width)
                pos_y = int(((half_height) - h) / 2)
            elif active_nodes.index(line['node']) == 2:
                pos_x = int((half_width - w) / 2)
                pos_y = int((((half_height) - h) / 2) + half_height)
            elif active_nodes.index(line['node']) == 3:
                pos_x = int(((half_width - w) / 2) + half_width)
                pos_y = int((((half_height) - h) / 2) + half_height)

            draw.text((pos_x + 1, pos_y), text, font=font, fill=color)

    img = im.rotate(90 * args['panelRotate'])
    setPixels(strip, img, args['invertedPanelRows'])
    strip.show()