Пример #1
0
def printTitle(caption):
    nowTime = datetime.datetime.now()
    inkyphat.text((0, fontSize * 0),
                  caption + ' @' + nowTime.isoformat()[0:19],
                  inkyphat.RED,
                  font=font)
    inkyphat.line((0, fontSize, inkyphat.WIDTH, fontSize), inkyphat.BLACK, 1)
Пример #2
0
def finish_display():

    if not has_inky:
        return

    inkyphat.line((52, 30, 52, 104), inkyphat.BLACK)
    inkyphat.show()

    return True
Пример #3
0
def _bitsRect(bits, xy=(None, None), height=inkyphat.HEIGHT):
    origX, origY = xy
    if origX == None:
        origX = int((inkyphat.WIDTH - len(bits)) / 2)
    if origY == None:
        origY = int((inkyphat.HEIGHT - height) / 2)

    x = origX
    for bit in bits:
        inkyphat.line((x, origY, x, origY + height), bit)
        x += 1
Пример #4
0
def draw_therm():
    inkyphat.arc((margin_bottom, margin_left, margin_bottom + bulb_width,
                  margin_right + bulb_width), 0, 360, 1)
    inkyphat.arc(
        (margin_bottom - 1, margin_left - 1, margin_bottom + bulb_width + 1,
         margin_right + bulb_width + 1), 0, 360, 1)

    inkyphat.rectangle((tube_x - (bulb_width / 2), tube_y,
                        (fill_max - tube_width), (tube_y + tube_width)), 0, 0)

    inkyphat.line((tubeline_top_x, tubeline_top_y, fill_max - tube_width / 2,
                   tubeline_top_y), 1, 1)
    inkyphat.line(
        (tubeline_top_x, (tubeline_top_y - 1), fill_max - tube_width / 2,
         (tubeline_top_y - 1)), 1, 1)

    inkyphat.line((tubeline_top_x, tubeline_bottom_y,
                   (fill_max - tube_width / 2), tubeline_bottom_y), 1, 1)
    inkyphat.line(
        (tubeline_top_x, (tubeline_bottom_y + 1), fill_max - tube_width / 2,
         (tubeline_bottom_y + 1)), 1, 1)

    inkyphat.arc(
        ((fill_max - tube_width), tubeline_top_y, fill_max, tubeline_bottom_y),
        270, 90, 1)
    inkyphat.arc(((fill_max - tube_width + 1), tubeline_top_y - 1,
                  fill_max + 1, tubeline_bottom_y + 1), 270, 90, 1)
Пример #5
0
    def update(self, temperature, weather):
        if temperature and weather:
            self.temp = temperature
            self.weather = weather
            self.active = True
        else:
            self.active = False
        self.update_colors()
        try:
            inkyphat.set_colour(self.color)
        except ValueError:
            print('Invalid colour "{}" for V{}\n'.format(
                self.color, inkyphat.get_version()))
            if inkyphat.get_version() == 2:
                sys.exit(1)
            print('Defaulting to "red"')

        inkyphat.set_border(inkyphat.BLACK)

        # Load our backdrop image
        inkyphat.set_image("resources/backdrop.png")

        # Let's draw some lines!
        inkyphat.line((69, 36, 69, 81))  # Vertical line
        inkyphat.line((31, 35, 184, 35))  # Horizontal top line
        inkyphat.line((69, 58, 174, 58))  # Horizontal middle line
        inkyphat.line((169, 58, 169, 58), 2)  # Red seaweed pixel :D

        # And now some text

        dt = (datetime.datetime.now() +
              datetime.timedelta(seconds=self.tz)).strftime("%m/%d %H:%M")

        inkyphat.text((36, 12), dt, inkyphat.WHITE, font=font)

        inkyphat.text((72, 34), "T", inkyphat.WHITE, font=font)
        inkyphat.text(
            (92, 34),
            u"{:.2f}°".format(self.temp),
            inkyphat.WHITE if self.temp < WARNING_TEMP else inkyphat.RED,
            font=font)

        inkyphat.text((72, 58),
                      "Active" if self.active else "Disconn",
                      inkyphat.WHITE,
                      font=font)

        # Draw the current weather icon over the backdrop
        if self.weather is not None:
            inkyphat.paste(icons[icon_mapping[self.weather]], (28, 36),
                           masks[icon_mapping[self.weather]])

        else:
            inkyphat.text((28, 36), "?", inkyphat.RED, font=font)

        self.display()
Пример #6
0
def draw_fahrenheit_scale():
    """Does not work"""
    inkyphat.line((fill_max - 140, 0, fill_max, 0), 1, 1)
    inkyphat.line((fill_max - 140, 1, fill_max, 1), 1, 1)
    i = 0
    while i < 126:
        if i % 10 == 0:
            inkyphat.line((fill_max - i, 2, fill_max - i, 22), 1, 1)
        else:
            inkyphat.line((fill_max - i, 2, fill_max - i, 12), 1, 1)
        i += 2
Пример #7
0
def draw_tube():
    # Upper part of tube
    inkyphat.line((65, 36, 200, 37), 1, 1)
    inkyphat.line((65, 37, 200, 36), 1, 1)

    # Lower part of tube
    inkyphat.line((65, 66, 200, 66), 1, 1)
    inkyphat.line((65, 67, 200, 67), 1, 1)

    # Round top of tube
    inkyphat.arc((187, 37, inkyphat.WIDTH - margin_top, 66), 270, 90, 1)
    inkyphat.arc((186, 37, (inkyphat.WIDTH - margin_top) + 1, 67), 270, 90, 1)
Пример #8
0
def draw_table_border(rect, line_count, col_width):
    left, top, right, bottom = rect
    line_height = int((bottom - top) / line_count)
    bottom = (line_height * line_count) + top
    inkyphat.line((left, top, left, bottom), inkyphat.BLACK)
    inkyphat.line((right, top, right, bottom), inkyphat.BLACK)
    # 横の罫線と上下の縁
    for i in range(line_count+1):
        height = top + i*line_height
        inkyphat.line((left, height, right, height), inkyphat.BLACK)
        # 縦の罫線
    for pos in col_width:
        inkyphat.line((left + pos, top, left + pos, bottom), inkyphat.BLACK)
Пример #9
0
# Load our icon files and generate masks
for icon in glob.glob("resources/icon-*.png"):
    icon_name = icon.split("icon-")[1].replace(".png", "")
    icon_image = Image.open(icon)
    icons[icon_name] = icon_image
    masks[icon_name] = inkyphat.create_mask(icon_image)

# Load the built-in FredokaOne font
font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 20)

# Load our backdrop image
inkyphat.set_image("resources/backdrop.png")


# Let's draw some lines!
inkyphat.line((69, 36, 69, 81)) # Vertical line
inkyphat.line((31, 35, 184, 35)) # Horizontal top line
inkyphat.line((69, 58, 174, 58)) # Horizontal middle line
inkyphat.line((169, 58, 169, 58), 2) # Red seaweed pixel :D

# And now some text

datetime = time.strftime("%d/%b/%Y")

inkyphat.text((36, 12), datetime, inkyphat.WHITE, font=font)

inkyphat.text((72, 34), u"{:.1f}°".format(local_temperature), inkyphat.WHITE if local_temperature < WARNING_TEMP else inkyphat.RED, font=font)
inkyphat.text((122, 34), u"{:.1f}°".format(mean_temperature), inkyphat.WHITE if mean_temperature < WARNING_TEMP else inkyphat.RED, font=font)

inkyphat.text((72, 58), u"{:.1f}°".format(outside_temperature), inkyphat.WHITE, font=font)
Пример #10
0
# and also draw the day names into the table header
for x in range(cols):
    # Figure out the left edge of the column
    o_x = (col_w + 1) * x
    o_x += cal_x

    crop_x = 2 + (16 * x)

    # Crop the relevant day name from our text image
    crop_region = ((crop_x, 0, crop_x + 16, 9))
    day_mask = text_mask.crop(crop_region)
    inkyphat.paste(inkyphat.WHITE, (o_x + 4, cal_y + 2), day_mask)

    # Offset to the right side of the column and draw the vertical line
    o_x += col_w + 1
    inkyphat.line((o_x, cal_y, o_x, cal_h))

# Draw the horizontal lines which separate the rows
for y in range(rows):
    o_y = (col_h + 1) * y
    o_y += cal_y + col_h + 1
    inkyphat.line((cal_x, o_y, cal_w + cal_x - 1, o_y))

# Step through each week
for row, week in enumerate(dates):
    y = (col_h + 1) * (row + 1)
    y += cal_y + 1

    # And each day in the week
    for col, day in enumerate(week):
        x = (col_w + 1) * col
Пример #11
0
    forecast_font = ImageFont.truetype(inkyphat.fonts.PressStart2P, 14)
    for i in range(3):
        inkyphat.text((0, i * inkyphat.HEIGHT / 3 + 10), weather_forecasts[i],
                      inkyphat.BLACK, forecast_font)

    weather_forecast_counter += 1
    return


# start main loop, will never end...
while True:
    try:
        # write up some graphics
        inkyphat.line([(inkyphat.WIDTH / 2, 0),
                       (inkyphat.WIDTH / 2, inkyphat.HEIGHT)],
                      width=2,
                      fill=inkyphat.RED)
        inkyphat.line([(inkyphat.WIDTH / 2, 79), (inkyphat.WIDTH, 79)],
                      width=2,
                      fill=inkyphat.RED)
        # write up data
        write_time(inkyphat)
        write_temperature(inkyphat)
        write_weather_forecast(inkyphat)
        # draw screen
        inkyphat.show()
        # wait one minute
        time.sleep(60)
        # clear screen
        inkyphat.clear()
    except Exception:
Пример #12
0
# Load our icon files and generate masks
for icon in glob.glob("resources/icon-*.png"):
    icon_name = icon.split("icon-")[1].replace(".png", "")
    icon_image = Image.open(icon)
    icons[icon_name] = icon_image
    masks[icon_name] = inkyphat.create_mask(icon_image)

# Load the built-in FredokaOne font
font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 22)

# Load our backdrop image
inkyphat.set_image("resources/backdrop.png")

# Let's draw some lines!
inkyphat.line((69, 36, 69, 81))  # Vertical line
inkyphat.line((31, 35, 184, 35))  # Horizontal top line
inkyphat.line((69, 58, 174, 58))  # Horizontal middle line
inkyphat.line((169, 58, 169, 58), 2)  # Red seaweed pixel :D

# And now some text

datetime = time.strftime("%d/%m %H:%M")

inkyphat.text((36, 12), datetime, inkyphat.WHITE, font=font)

inkyphat.text((72, 34), "T", inkyphat.WHITE, font=font)
inkyphat.text((92, 34),
              u"{:.2f}°".format(temperature),
              inkyphat.WHITE if temperature < WARNING_TEMP else inkyphat.RED,
              font=font)
Пример #13
0
def draw_celsius_scale():
    # inkyphat.line((fill_max - 140, 102, fill_max, 102), 1, 1)
    # inkyphat.line((fill_max - 140, 103, fill_max, 103), 1, 1)
    i = 0
    while i < 141:
        if i == 100:
            inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i,
                           tubeline_top_y - 5 - 33), 1, 1)
            inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i,
                           tubeline_bottom_y + 5 + 33), 1, 1)
        elif i % 20 == 0:
            inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i,
                           tubeline_top_y - 5 - 18), 1, 1)
            inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i,
                           tubeline_bottom_y + 5 + 18), 1, 1)
            # inkyphat.line((fmax - i, 103, fmax - i, 85), 1, 1)
        elif i % 10 == 0:
            inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i,
                           tubeline_top_y - 5 - 12), 1, 1)
            inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i,
                           tubeline_bottom_y + 5 + 12), 1, 1)
            # inkyphat.line((fmax - i, 103, fmax - i, 91), 1, 1)
        elif i % 2 == 0:
            inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i,
                           tubeline_top_y - 5 - 8), 1, 1)
            inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i,
                           tubeline_bottom_y + 5 + 8), 1, 1)
            # inkyphat.line((fmax - i, 103, fmax - i, 95), 1, 1)
        else:
            inkyphat.line((fmax - i, tubeline_top_y - 5, fmax - i,
                           tubeline_top_y - 5 - 8), 0, 0)
            inkyphat.line((fmax - i, tubeline_bottom_y + 5, fmax - i,
                           tubeline_bottom_y + 5 + 8), 0, 0)
            # inkyphat.line((fmax - i, 103, fmax - i, 95), 0, 0)
        i += 1
Пример #14
0
    font=font)
inkyphat.text((6, 41),
              'mb- '.join(map(str, get_ram())) + 'mb+',
              inkyphat.BLACK,
              font=font)
# Bottom Row
inkyphat.text((6, 87), get_ip_address("wlan0"), inkyphat.WHITE, font=font)
# Right
inkyphat.text((108, 7),
              u"{:.1f}c".format(temperature) + " {}mb ".format(pressure),
              inkyphat.WHITE if temperature < WARNING_TEMP else inkyphat.RED,
              font=font)
inkyphat.text((108, 17), pressurestatestr, inkyphat.WHITE, font=font)
inkyphat.text((108, 27),
              str(windspeed) + "mph " + str(winddir),
              inkyphat.WHITE,
              font=font)
inkyphat.text((108, 37),
              "feels " + u"{:.1f}c ".format(windchill),
              inkyphat.WHITE,
              font=font)

inkyphat.line((108, 47, 200, 47), 2)  # Red line

inkyphat.text((108, 49), shorten(weathertext0, 14), inkyphat.WHITE, font=font)
inkyphat.text((108, 59), shorten(weathertext1, 14), inkyphat.WHITE, font=font)
inkyphat.text((108, 69), shorten(weathertext2, 14), inkyphat.WHITE, font=font)

inkyphat.show()
print("Display updated")
Пример #15
0
def decorate():
    # Reflection
    inkyphat.pieslice((40, 52, 52, 64), 0, 360, 0, 0)
    # Scale
    inkyphat.line((202, 20, 202, 36), 1, 1)
Пример #16
0
# FONTS
font10 = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Regular.ttf', 10)
font10b = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 10)
font22 = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 22)
font28 = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 28)

# TOP infos
Rdatew, Rdateh = font10.getsize(Rdate)
inkyphat.text((3, -2), str(Rhour), inkyphat.RED, font22)
inkyphat.text((inkyphat.WIDTH - Rdatew - 6, 6), str(Rdate + ' '),
              inkyphat.BLACK, font10)
inkyphat.line((3, 23, inkyphat.WIDTH - 3, 23),
              inkyphat.BLACK)  # Horizontal separator

# INSIDE readings
insideT = str(d["inside"]["temp"])
insideH = str(d["inside"]["humi"])
inkyphat.text((6, 30), "IN: ", inkyphat.RED, font10)
inkyphat.text((35, 25), insideT + degSign, inkyphat.RED, font28)
inkyphat.text((35, 50), insideH + '%', inkyphat.BLACK, font22)

# OUTSUDE readings
outsideT = str(d["outside"]["temp"])
outsideP = str(d["outside"]["press"])
outsideD = str(d["outside"]["timestamp"])
OUTpressw, OUTpressh = font22.getsize(outsideP)
inkyphat.text((6, 80), "OUT: ", inkyphat.RED, font10)
inkyphat.text((35, 75), outsideT + degSign, inkyphat.BLACK, font22)
Пример #17
0
fontMid = ImageFont.truetype(inkyphat.fonts.FredokaOne, 12)
fontSmall = ImageFont.truetype("/home/pi/Pimoroni/inkyphat/examples/04B.ttf",
                               8)

#define weekday text
weekday = date.today()
day = date.strftime(weekday, '%A')

weekday2 = datetime.date.today() + datetime.timedelta(days=1)
day2 = date.strftime(weekday2, '%A')

weekday3 = datetime.date.today() + datetime.timedelta(days=2)
day3 = date.strftime(weekday3, '%A')

#draw some lines
inkyphat.line((118, 20, 118, 90), 2)  # Vertical line

### now draw the text##

#format today's name to center over left side
dayName = day
w, h = fontBig.getsize(day)
x = (inkyphat.WIDTH / 4) - (w / 2)
y = (inkyphat.HEIGHT / 4) - (h / 2)

#format the summary text for today
summaryFormatted = textwrap.fill(summary, 20)

#draw the suff on the left side of the screen
inkyphat.text((20, 5), day, inkyphat.BLACK, font=fontBig)
inkyphat.text((60, 29), highTempToday, inkyphat.BLACK, font=fontMid)