Exemple #1
0
    def label(self, newtext):
        if self._label and self.group and (self.group[-1] == self._label):
            self.group.pop()

        self._label = None
        if not newtext or (self._label_color is None):  # no new text
            return  # nothing to do!

        if not self._label_font:
            raise RuntimeError("Please provide label font")
        self._label = Label(self._label_font, text=newtext)
        dims = self._label.bounding_box
        if dims[2] >= self.width or dims[3] >= self.height:
            raise RuntimeError("Button not large enough for label")
        self._label.x = self.x + (self.width - dims[2]) // 2
        self._label.y = self.y + self.height // 2
        self._label.color = self._label_color
        self.group.append(self._label)

        if (self.selected_label is None) and (self._label_color is not None):
            self.selected_label = (~self._label_color) & 0xFFFFFF
    def addPlayer(self, name, rssi=None):
        """Add a player to the player list.
           playerListScreen must be called prior to use."""
        if self.disp is None:
            return

        text_color = OPP_NAME_COL_FG if len(
            self.disp_group) else PLAYER_NAME_COL_FG
        pname_dob = Label(self.font, text=name, scale=2, color=text_color)
        pname_dob.x = self.pl_x_pos
        pname_dob.y = self.pl_y_cur_pos
        self.disp_group.append(pname_dob)

        if rssi is not None:
            prssi_dob = Label(self.font,
                              text="{:4d}".format(round(rssi)),
                              scale=2,
                              color=text_color)
            prssi_dob.x = self.plrssi_x_rpos - 4 * 2 * self.font_width
            prssi_dob.y = self.pl_y_cur_pos
            self.disp_group.append(prssi_dob)

        self.pl_y_cur_pos += self.pl_y_off
Exemple #3
0
    def set_text(
        self,
        text: Optional[str],
        color: Optional[str],
        background_color: Optional[int] = None,
    ) -> None:
        """Display the test for a card.

        :param text: the text to display
        :type text: str or None
        :param color: the text color
        :type color: str or None
        :param background_color: the background color of the text
        :type background_color: int or None
        """
        if self._text_group:
            self._text_group.pop()
        if not text or not color:
            return  # nothing to do!
        text_wrap = 37
        if self._display.height < 130:
            text_wrap = 25
        text = self.wrap_nicely(text, text_wrap)
        text = "\n".join(text)
        print("Set text to", text, "with color", hex(color))
        text_x = 8
        text_y = 95
        if self._display.height < 130:
            text_x = 3
            text_y = 38
        elif self._display.height > 250:
            text_y = 50
        if text:
            self._text = Label(self._text_font, text=str(text))
            self._text.x = text_x
            self._text.y = text_y
            self._text.color = color
            if background_color:
                self._text.background_color = background_color
            self._text_group.append(self._text)
Exemple #4
0
    def info(self, value):
        """Place some text on the screen.
           Multiple lines are supported with newline character.
           Font will be 3x standard terminalio font or 2x if that does not fit."""
        if self._displayio_info is not None:
            self._displayio_graph.pop()

        if value is not None and value != "":
            font_scale = 3
            line_spacing = 1.25

            font_w, font_h = self._font.get_bounding_box()
            text_lines = value.split("\n")
            max_word_chars = max([len(word) for word in text_lines])
            # If too large reduce the scale
            if (max_word_chars * font_scale * font_w > self._screen_width
                    or len(text_lines) * font_scale * font_h * line_spacing >
                    self._screen_height):
                font_scale -= 1

            self._displayio_info = Label(self._font,
                                         text=value,
                                         line_spacing=line_spacing,
                                         scale=font_scale,
                                         background_color=None,
                                         color=self.INFO_BG_COLOR)
            self._displayio_info.palette[0] = self.INFO_FG_COLOR
            self._displayio_info.palette.make_opaque(0)
            # centre the (left justified) text
            self._displayio_info.x = (
                self._screen_width - font_scale * font_w * max_word_chars) // 2
            self._displayio_info.y = self._screen_height // 2
            self._displayio_graph.append(self._displayio_info)

        else:
            self._displayio_info = None

        if self._mode == "scroll":
            self._display_refresh()
Exemple #5
0
def build(
    widget: Button,
    *,
    radius: int,
    size: float | int,
    fit_to_text: bool,
) -> tuple[Native, tuple[int, int]]:
    """
    Creates the native element for the std tg-gui widget based on the _fixed_style_attrs_.
    Those _fixed_style_attrs_ are passed as kwargs to this function.
    :param widget: the tg-gui widget instance to build the native for
    :param **style_attrs: the fixed style attributes that are set at build time
    :return: a tuple of the native widget and suggested size
    """
    native = Group()

    label = Label(font=FONT, x=0, y=0, text=widget.text, scale=size)
    native.append(label)

    _, _, w, h = label.bounding_box
    w *= size
    h = int(1.15 * h * size)
    r = (
        min(radius, w // 2 - 1, h // 2 - 1)
        if isinstance(radius, int)
        else min(w // 2, h // 2) - 1
    )
    padding = round(1.25 * r)

    widget._impl_cache_ = dict(radius=radius, label_width=w)
    return (
        native,
        (
            w + padding + widget._margin_ * 2,
            int(h * 1.2) + widget._margin_ * 2,
        ),
    )
    def label(self, newtext):
        if self._label and (self.group[-1] == self._label):
            self.group.pop()

        self._label = None
        if not newtext or (self._label_color is None):  # no new text
            return     # nothing to do!

        if not self._label_font:
            raise RuntimeError("Please provide label font")
        self._label = Label(self._label_font, text=newtext)
        dims = self._label.bounding_box
        if dims[2] >= self.width or dims[3] >= self.height:
            raise RuntimeError("Button not large enough for label")

        # PaddedButton
        # Set an x,y location for the label
        if self._label_x > -1:
            x_loc = self.x + self._label_x
        else: 
            x_loc = self.x + (self.width - dims[2]) // 2
        if self._label_y > -1: 
            y_loc = self.y + self._label_y
        else:
            y_loc = self.y + self.height // 2
            
        self._label.x = x_loc
        self._label.y = y_loc

        # self._label.x = self.x + (self.width - dims[2]) // 2
        # self._label.y = self.y + self.height // 2

        self._label.color = self._label_color
        self.group.append(self._label)

        if (self.selected_label is None) and (self._label_color is not None):
            self.selected_label = (~self._label_color) & 0xFFFFFF
    def display_weather(self, weather):
        # set the icon
        self.set_icon(weather["weather"][0]["icon"])

        city_name = weather["name"] + ", " + weather["sys"]["country"]
        print(city_name)
        if not self.city_text:
            self.city_text = Label(self.small_font, text=city_name)
            self.city_text.color = CITY_COLOR
            self._scrolling_texts.append(self.city_text)

        temperature = weather["main"]["temp"]
        print(temperature)
        if self.celsius:
            self.temp_text.text = "%d°C" % temperature
        else:
            self.temp_text.text = "%d°F" % temperature

        description = weather["weather"][0]["description"]
        description = description[0].upper() + description[1:]
        print(description)
        self.description_text.text = description
        # "thunderstorm with heavy drizzle"

        humidity = weather["main"]["humidity"]
        print(humidity)
        self.humidity_text.text = "%d%% humidity" % humidity

        wind = weather["wind"]["speed"]
        print(wind)
        if self.meters_speed:
            self.wind_text.text = "%d m/s" % wind
        else:
            self.wind_text.text = "%d mph" % wind

        self.display.show(self.root_group)
Exemple #8
0
 def update_date(self):
     date_now = time.localtime()
     year = date_now[0]
     mon = date_now[1]
     date = date_now[2]
     day = date_now[6]
     today = weekday[day]
     month = month_name[mon - 1]
     date_format_str = " %d, %d"
     shortened_date_format_str = " %d"
     date_str = today+", "+month+date_format_str % (date, year)
     holiday_date_str = month+shortened_date_format_str % (date)
     print(date_str)
     self.date_text.text = date_str
     for i in holiday_checks:
         h = holiday_checks.index(i)
         if holiday_date_str == holiday_checks[h]:
             if not self.holiday_text:
                 self.holiday_text = Label(self.medium_font)
                 self.holiday_text.x = 10
                 self.holiday_text.y = 45
                 self.holiday_text.color = 0xf2f89d
                 self._text_group.append(self.holiday_text)
             self.holiday_text.text = holiday_greetings[h]
def update_display():
    counters = [{
        'font': large_font2,
        'max_glyphs': 3,
        'text': "%d" % HEALTH,
        'pos': (30, 60),
        'color': 0xFFFFFF
    }, {
        'font': large_font2,
        'max_glyphs': 3,
        'text': "%d" % PLAYER_COUNTER,
        'pos': (190, 60),
        'color': 0xFFFFFF
    }]
    for counter in counters:
        texty = Label(counter['font'],
                      max_glyphs=counter['max_glyphs'],
                      x=counter['pos'][0],
                      y=counter['pos'][1],
                      color=counter['color'],
                      text=counter['text'])
        texts.append(texty)
        if len(texts) > 2:
            texts.pop(0)
def st_graphics(medium_font, large_font, small_font, st):
    """Take input JSON pulled from the Shower Thoughts subreddit API, extract the title field,
    and format for display. Inputs are medium, large, and small fonts and the JSON input from
    the API
    """
    text_group = displayio.Group(max_size=6)
    st = json.loads(st)
    thought = st['data']['children'][0]['data']['title']
    print(thought)
    # Split into multiple lines (based on pyportal's wrap_nicely method)
    # Use smaller font if needed to fit
    print("length: ", len(thought))
    if len(thought) > 140:
        max_chars = 38
        font = small_font
        max_glyphs = 38
        print("using small font")
    else:
        max_chars = 28
        font = medium_font
        max_glyphs = 28
        print("using medium font")
    words = thought.split(' ')
    the_lines = []
    the_line = ""
    for w in words:
        if len(the_line + ' ' + w) <= max_chars:
            the_line += ' ' + w
        else:
            the_lines.append(the_line)
            the_line = '' + w
    if the_line:  # last line remaining
        the_lines.append(the_line)
    # remove first space from first line:
    the_lines[0] = the_lines[0][1:]
    for idx, line in enumerate(the_lines):
        thought_text = Label(font, line_spacing=1.2, max_glyphs=max_glyphs)
        thought_text.x = 15
        thought_text.color = 0xFFFFFF
        thought_text.y = 110 + (idx * 24)
        thought_text.text = line
        text_group.append(thought_text)
    return (text_group)
Exemple #11
0
# Create a TileGrid using the Bitmap and Palette
tile_grid = displayio.TileGrid(bitmap, pixel_shader=color)
group.append(tile_grid)  # Add the TileGrid to the Group
display.show(group)

if not DEBUG:
    # font = bitmap_font.load_font("fonts/IBMPlexMono-Medium-24_jep.bdf")
    font = bitmap_font.load_font("fonts/Arial-14.bdf")
    font2 = bitmap_font.load_font("fonts/Arial-12.bdf")
    small_font = bitmap_font.load_font("fonts/helvR10.bdf")
else:
    font = terminalio.FONT
    font2 = terminalio.FONT
    small_font = terminalio.FONT

clock_label = Label(font, max_glyphs=8)
clock_label.color_idx = 1
clock_label.color = color[clock_label.color_idx]
clock_label.text = 'Matrix'
clock_label.x = 0
clock_label.y = display.height // 4
clock_label.normal = True
event_label = Label(font2, max_glyphs=32)
event_label.color_idx = 2
event_label.color = color[event_label.color_idx]
event_label.text = 'Clock'
event_label.x = 0
event_label.y = display.height // 4 * 3

DATA_LOCATION = []
Exemple #12
0
# A quick template and troubleshooting help App
# for the Adafruit Mini Color TFT with Joystick FeatherWing
# Included is the DisplayIO library to modify the screen output
# If you connected everything correctly this code should work

import time
import displayio
import terminalio
from adafruit_display_text.label import Label
from adafruit_featherwing import minitft_featherwing

minitft = minitft_featherwing.MiniTFTFeatherWing()

uiGroup = displayio.Group(max_size=20)

text_area = Label(terminalio.FONT, text=' ', max_glyphs=20)
text_area.x = 40
text_area.y = 32

uiGroup.append(text_area)
minitft.display.show(uiGroup)

while True:
    buttons = minitft.buttons

    if buttons.right:
        text_area.text = "Button RIGHT!"

    if buttons.down:
        text_area.text = "Button DOWN!"
color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF
bg_sprite = displayio.TileGrid(color_bitmap,
                               pixel_shader=color_palette,
                               x=0,
                               y=0)
splash.append(bg_sprite)

# Load the font
font = bitmap_font.load_font(THE_FONT)
font.load_glyphs(DISPLAY_STRING.encode('utf-8'))

print(DISPLAY_STRING)

text = Label(font, text=DISPLAY_STRING)
text.x = 20
text.y = 100
text.color = 0x0

# Make a background color fill
dims = text.bounding_box
print(dims)
textbg_bitmap = displayio.Bitmap(dims[2], dims[3], 1)
textbg_palette = displayio.Palette(1)
textbg_palette[0] = 0xFF0000
textbg_sprite = displayio.TileGrid(textbg_bitmap,
                                   pixel_shader=textbg_palette,
                                   x=text.x + dims[0],
                                   y=text.y + dims[1])
splash.append(textbg_sprite)
Exemple #14
0
    board.DISPLAY.brightness = b / 100
    time.sleep(0.01)  # default (0.01)

demos = [
    "CircuitPython = Code + Community", "accents - üàêùéáçãÍóí",
    "others - αψ◌"
]

splash = displayio.Group(max_size=len(fonts) * len(demos))
board.DISPLAY.show(splash)
max_y = 0
y = 2
for demo_text in demos:
    for font in fonts:
        print("Font load {}".format(font.name))
        area = Label(font, text=demo_text)
        area.y = y
        splash.append(area)

        y += area.height

        # Wait for the image to load.
        board.DISPLAY.wait_for_frame()

# Wait for 10 minutes (600 seconds)
time.sleep(600)

# Fade down the backlight
for b in range(100, -1, -1):
    board.DISPLAY.brightness = b / 100
    time.sleep(0.01)  # default (0.01)
image_group.append(image_tile)

scale_bitmap = displayio.Bitmap( number_of_colors, 1, number_of_colors )

# Create a Group Scale must be 128 divided by number_of_colors
scale_group = displayio.Group(scale=2)
scale_tile = displayio.TileGrid(scale_bitmap, pixel_shader=palette, x = 0, y = 60)
scale_group.append(scale_tile)

for i in range(number_of_colors):
    scale_bitmap[i, 0] = i            # Fill the scale with the palette gradian

# Create the super Group
group = displayio.Group(max_size = 8)

min_label = Label(terminalio.FONT, max_glyphs=10, color=palette[0], x = 0, y = 110)
center_label = Label(terminalio.FONT, max_glyphs=10, color=palette[int(number_of_colors/2)], x = 48, y = 110)
max_label = Label(terminalio.FONT, max_glyphs=10, color=palette[last_color], x = 80, y = 110)

# Indicator for the minimum and maximum location
o_label = Label(terminalio.FONT, max_glyphs = 1, text = "o", color = 0xFFFFFF, x = 0, y = 0)
x_label = Label(terminalio.FONT, max_glyphs = 1, text = "x", color = 0xFFFFFF, x = 0, y = 0)

# Add all the sub-group to the SuperGroup
group.append(image_group)
group.append(scale_group)
group.append(min_label)
group.append(center_label)
group.append(max_label)
group.append(o_label)
group.append(x_label)
Exemple #16
0
    'background_13.bmp', 'background_14.bmp', 'background_15.bmp',
    'background_16.bmp', 'background_17.bmp'
]

event_background = cwd + "/happy_halloween.bmp"

# Initialize the pyportal object and let us know what data to fetch and where
# to display it
pyportal = PyPortal(status_neopixel=board.NEOPIXEL,
                    default_bg=cwd + backgrounds[0],
                    caption_text='DAYS  REMAINING',
                    caption_font=cwd + '/fonts/Terror-31.bdf',
                    caption_position=(24, 218),
                    caption_color=0x000000)

countdown_text = Label(big_font, max_glyphs=3)
countdown_text.x = 25
countdown_text.y = 120
countdown_text.color = 0x7942a0
pyportal.splash.append(countdown_text)

refresh_time = None

while True:
    # only query the online time once per hour (and on first run)
    if (not refresh_time) or (time.monotonic() - refresh_time) > 3600:
        try:
            print("Getting time from internet!")
            pyportal.get_local_time(location=secrets['timezone'])
            refresh_time = time.monotonic()
        except RuntimeError as e:
Exemple #17
0
image_group = displayio.Group(scale=4)
image_group.append(image_tile)

scale_bitmap = displayio.Bitmap(number_of_colors, 1, number_of_colors)
# Create a Group Scale must be 128 divided by number_of_colors
scale_group = displayio.Group(scale=2)
scale_tile = displayio.TileGrid(scale_bitmap, pixel_shader=palette, x=0, y=60)
scale_group.append(scale_tile)

for i in range(number_of_colors):
    scale_bitmap[i, 0] = i  # Fill the scale with the palette gradian

# Create the super Group
group = displayio.Group()

min_label = Label(terminalio.FONT, max_glyphs=10, color=palette[0], x=0, y=110)
max_label = Label(terminalio.FONT,
                  max_glyphs=10,
                  color=palette[last_color],
                  x=80,
                  y=110)

# Add all the sub-group to the SuperGroup
group.append(image_group)
group.append(scale_group)
group.append(min_label)
group.append(max_label)

# Add the SuperGroup to the Display
board.DISPLAY.show(group)
# the current working directory (where this file is)
cwd = ("/" + __file__).rsplit('/', 1)[0]
large_font = cwd + "/fonts/Helvetica-Bold-36.bdf"
small_font = cwd + "/fonts/Helvetica-Bold-16.bdf"

root_group = displayio.Group()
print('loading fonts...')
weight_font = bitmap_font.load_font(large_font)
weight_font.load_glyphs(b'0123456789.goz-SCALEROIO ')

text_font = bitmap_font.load_font(small_font)
text_font.load_glyphs(b'sendig!t.')

print('making labels...')
weight_label = Label(weight_font)
weight_label.x = 75
weight_label.y = 120
root_group.append(weight_label)
weight_label.text = "---"

title_label = Label(weight_font)
title_label.x = 65
title_label.y = 20
root_group.append(title_label)
title_label.text = "IO SCALE"

text_label = Label(text_font)
text_label.x = 100
text_label.y = 200
text_label.color = 0xFFFFFF
Exemple #19
0
    def __init__(self,
                 min_val,
                 max_val,
                 width,
                 height,
                 base_size=8,
                 colour=0x0000FF,
                 outline_colour=0x0000FF,
                 outline=True,
                 bg_colour=0000000,
                 display_value=True,
                 value_label="",
                 arc_colour=0xFF0000,
                 colour_fade=False):
        super().__init__(max_size=20)
        self.pivot1 = [(width // 2) - (base_size // 2), 0]
        self.pivot2 = [(width // 2) + (base_size // 2), 0]
        self.mid = width // 2
        self.min_val = min_val
        self.max_val = max_val
        self.colour = colour
        self.height = height
        self.value_label = value_label
        self.outline_colour = outline_colour
        self.outline = outline

        self.length = int(1.4 * (width / 2))
        if outline:
            self.arrow = Triangle(self.pivot1[0],
                                  self.length,
                                  self.pivot2[0],
                                  self.length,
                                  self.mid,
                                  0,
                                  fill=self.colour,
                                  outline=self.outline_colour)
        else:
            self.arrow = Triangle(self.pivot1[0],
                                  self.length,
                                  self.pivot2[0],
                                  self.length,
                                  self.mid,
                                  0,
                                  fill=self.colour)

        self.data = Label(terminalio.FONT,
                          text="0.0",
                          color=0xFFFFFF,
                          max_glyphs=10)
        self.data.x = width // 2
        self.data.y = (height - self.length) // 2
        if display_value: super().append(self.data)

        arc = draw_arc(width // 2,
                       self.height,
                       self.length,
                       0,
                       width,
                       10,
                       arc_colour,
                       height,
                       colour_fade=colour_fade)
        for tri in arc:
            super().append(tri)
        super().append(self.arrow)
Exemple #20
0
    width=BUTTON_WIDTH,
    height=BUTTON_HEIGHT,
    label="Button 2",
    label_font=font,
    style=Button.SHADOWROUNDRECT,
    label_color=0x505050,
    fill_color=0x9E9E9E,
    outline_color=0x464646,
)
buttons.append(button_2)

for b in buttons:
    splash.append(b.group)

# Text Label Objects
temperature_label = Label(font, text="temperature", color=0xE300D2)
temperature_label.x = 130
temperature_label.y = 20
splash.append(temperature_label)

light_label = Label(font, text="lux", color=0xE300D2)
light_label.x = 130
light_label.y = 40
splash.append(light_label)

motion_label = Label(font, text="motion", color=0xE300D2)
motion_label.x = 130
motion_label.y = 60
splash.append(motion_label)

feed1_label = Label(font, text="MQTT feed1", color=0xE39300)
Exemple #21
0
# to display it
pyportal = PyPortal(status_neopixel=board.NEOPIXEL,
                    default_bg=cwd + "/countup_background.bmp")

big_font = bitmap_font.load_font(cwd + "/fonts/Helvetica-Bold-24.bdf")
big_font.load_glyphs(b'0123456789')  # pre-load glyphs for fast printing

years_position = (126, 15)
days_position = (13, 41)
hours_position = (118, 41)
minutes_position = (25, 68)
text_color = 0xFF0000

text_areas = []
for pos in (years_position, days_position, hours_position, minutes_position):
    textarea = Label(big_font, text='  ')
    textarea.x = pos[0]
    textarea.y = pos[1]
    textarea.color = text_color
    pyportal.splash.append(textarea)
    text_areas.append(textarea)
refresh_time = None

while True:
    # only query the online time once per hour (and on first run)
    if (not refresh_time) or (time.monotonic() - refresh_time) > 3600:
        try:
            print("Getting time from internet!")
            pyportal.get_local_time()
            refresh_time = time.monotonic()
        except RuntimeError as e:
Exemple #22
0
pyportal = PyPortal(status_neopixel=board.NEOPIXEL,
                    default_bg=cwd + "/countdown_background.bmp")

big_font = bitmap_font.load_font(cwd + "/fonts/Helvetica-Bold-36.bdf")
big_font.load_glyphs(b'0123456789')  # pre-load glyphs for fast printing
on_air_background = cwd + "/on_air_background.bmp"
its_over_background = cwd + "/its_over_background.bmp"

days_position = (8, 115)
hours_position = (100, 115)
minutes_position = (210, 115)
text_color = 0xFFFFFF

text_areas = []
for pos in (days_position, hours_position, minutes_position):
    textarea = Label(big_font, max_glyphs=3)
    textarea.x = pos[0]
    textarea.y = pos[1]
    textarea.color = text_color
    pyportal.splash.append(textarea)
    text_areas.append(textarea)
refresh_time = None

while True:
    # only query the online time once per hour (and on first run)
    if (not refresh_time) or (time.monotonic() - refresh_time) > 3600:
        try:
            print("Getting time from internet!")
            pyportal.get_local_time()
            refresh_time = time.monotonic()
        except RuntimeError as e:
# splash.append(view2)
# splash.append(view3)

text = "hello hello"
color = 0x0000FF
font = terminalio.FONT
color = 0x03AD31

# Set the font and preload letters
font = bitmap_font.load_font("/fonts/Junction-regular-24.bdf")
# font = bitmap_font.load_font("/fonts/Arial-ItalicMT-17.bdf")
# font = bitmap_font.load_font("/fonts/LeagueSpartan-Bold-16.bdf")
font.load_glyphs(
    b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()')
# Used to calculate vertical text height for Top Alignment
text_hight = Label(font, text="M", color=0x03AD31, max_glyphs=10)

# Create the text label
text_area = Label(font, text=text, color=color, max_glyphs=200)

# Set the location
text_area.x = 100
text_area.y = 180

# Show it
cntr = 0
while True:
    # text = str(cntr)
    cntr = cntr + 1

    received_data = io.receive_data(temperature_feed["key"])
Exemple #24
0
    "others - αψ◌"
]

splash = displayio.Group()
board.DISPLAY.show(splash)
max_y = 0
y = 0
for demo_text in demos:
    for font in fonts:
        if y >= board.DISPLAY.height:
            y = 0
            while len(splash):
                splash.pop()
        print("Font load {}".format(font.name))
        area = Label(font,
                     text=demo_text,
                     anchor_point=(0, 0),
                     anchored_position=(0, y))
        splash.append(area)

        y += area.height

        # Wait for the image to load.
        try:
            board.DISPLAY.refresh(target_frames_per_second=60)
        except AttributeError:
            board.DISPLAY.wait_for_frame()

# Wait for 1 minute (60 seconds)
time.sleep(60)

# Fade down the backlight
print('loading fonts...')
# Fonts within /fonts/ folder
font = cwd+"/fonts/GothamBlack-50.bdf"
font_small = cwd+"/fonts/GothamBlack-25.bdf"

# pylint: disable=syntax-error
data_glyphs = b'0123456789FC-* '
font = bitmap_font.load_font(font)
font.load_glyphs(data_glyphs)

font_small = bitmap_font.load_font(font_small)
full_glyphs = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.: '
font_small.load_glyphs(full_glyphs)

# Label to display Adafruit IO status
label_status = Label(font_small, max_glyphs=20)
label_status.x = 305
label_status.y = 10
splash.append(label_status)

# Create a label to display the temperature
label_temp = Label(font, max_glyphs=4)
label_temp.x = 35
label_temp.y = 300
splash.append(label_temp)

# Create a label to display the water level
label_level = Label(font, max_glyphs=4)
label_level.x = display.width - 130
label_level.y = 300
splash.append(label_level)
Exemple #26
0
FONT_WIDTH, FONT_HEIGHT = terminalio.FONT.get_bounding_box()
screen_group = Group(max_size=len(choices) * 2 + 1 + 1)

### The position of the two players RPS Label objects inside screen_group
rps_dob_idx = []

### Create the simple arrow cursors
left_col = 20
right_col = display.width // 2 + left_col
for x_pos in (left_col, right_col):
    y_pos = top_y_pos
    rps_dob_idx.append(len(screen_group))
    for label_text in choices:
        rps_dob = Label(terminalio.FONT,
                        text=label_text,
                        scale=2,
                        color=DEFAULT_TXT_COL_FG,
                        background_color=DEFAULT_TXT_COL_BG)
        rps_dob.x = x_pos
        rps_dob.y = y_pos
        y_pos += 60
        screen_group.append(rps_dob)

cursor_dob = Label(terminalio.FONT, text=">", scale=3, color=CURSOR_COL_FG)
cursor_dob.x = left_col - 20
setCursor(my_choice_idx, "mine")
cursor_dob.y = top_y_pos
screen_group.append(cursor_dob)

### Initially set to a space to not show it
opp_cursor_dob = Label(terminalio.FONT,
submit = touchio.TouchIn(board.CAP8)

# Check for secrets.py. Note: for this project, your secrets.py needs an adafruit io api key as
# well as the wifi information
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

# Make the rgb group for setting rgb hex values for NeoPixels
rgb_group = displayio.Group()
R_label = Label(
    terminalio.FONT,
    text="   +\nR:\n   -",
    color=0xFFFFFF,
    anchor_point=(0, 0.5),
    anchored_position=(5, 120),
    scale=2,
)
G_label = Label(
    terminalio.FONT,
    text="   +\nG:\n   -",
    color=0xFFFFFF,
    anchor_point=(0, 0.5),
    anchored_position=(90, 120),
    scale=2,
)
B_label = Label(
    terminalio.FONT,
    text="   +\nB:\n   -",
    color=0xFFFFFF,
Exemple #28
0
    def __init__(self, is_celsius):
        """Creates an Azure_GFX object.
        :param bool is_celsius: Temperature displayed in Celsius.
        """
        # root displayio group
        root_group = displayio.Group()
        board.DISPLAY.show(root_group)
        super().__init__()

        # temperature display option
        self._is_celsius = is_celsius

        # create background icon group
        self._icon_group = displayio.Group()
        board.DISPLAY.show(self._icon_group)
        # create text object group
        self._text_group = displayio.Group()

        self._icon_sprite = None
        self._icon_file = None
        self._cwd = cwd
        self.set_icon(self._cwd + "/images/azure_splash.bmp")

        print("loading fonts...")
        glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.: "
        data_glyphs = b"012345678-,.:/FC"
        self.main_font = bitmap_font.load_font(main_font)
        self.main_font.load_glyphs(glyphs)
        self.data_font = bitmap_font.load_font(data_font)
        self.data_font.load_glyphs(data_glyphs)
        self.data_font.load_glyphs(("°", ))  # extra glyph for temperature font

        print("setting up labels...")
        self.title_text = Label(self.main_font, text="Azure Plant Monitor")
        self.title_text.x = 35
        self.title_text.y = 25
        self._text_group.append(self.title_text)

        self.temp_label = Label(self.main_font, text="Temperature")
        self.temp_label.x = 0
        self.temp_label.y = 65
        self._text_group.append(self.temp_label)

        self.temp_text = Label(self.data_font)
        self.temp_text.x = 200
        self.temp_text.y = 85
        self._text_group.append(self.temp_text)

        self.moisture_label = Label(self.main_font, text="Moisture Level")
        self.moisture_label.x = 0
        self.moisture_label.y = 135
        self._text_group.append(self.moisture_label)

        self.moisture_text = Label(self.data_font)
        self.moisture_text.x = 200
        self.moisture_text.y = 175
        self._text_group.append(self.moisture_text)

        self.azure_status_text = Label(self.main_font)
        self.azure_status_text.x = 65
        self.azure_status_text.y = 225
        self._text_group.append(self.azure_status_text)
# Initialize a requests object with a socket and esp32spi interface
socket.set_interface(esp)
requests.set_socket(socket, esp)

# DisplayIO Setup
# Set up fonts
font_small = bitmap_font.load_font("/fonts/Arial-12.pcf")
font_large = bitmap_font.load_font("/fonts/Arial-14.pcf")
# preload fonts
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.: "
font_small.load_glyphs(glyphs)
font_large.load_glyphs(glyphs)

group_verification = displayio.Group(max_size=25)
label_overview_text = Label(font_large,
                            x=0,
                            y=45,
                            text="To authorize this device with Google:")
group_verification.append(label_overview_text)

label_verification_url = Label(font_small,
                               x=0,
                               y=100,
                               line_spacing=1,
                               max_glyphs=90)
group_verification.append(label_verification_url)

label_user_code = Label(font_small, x=0, y=150, max_glyphs=50)
group_verification.append(label_user_code)

label_qr_code = Label(font_small, x=0, y=190, text="Or scan the QR code:")
group_verification.append(label_qr_code)
Exemple #30
0
def sample_sum(pin, num):
    """Sample the analogue value from pin num times and return the sum
       of the values."""
    global samples  ### Not strictly needed - indicative of r/w use
    samples[:] = [pin.value for _ in range(num)]
    return sum(samples)


### Initialise detector display
### The units are created as separate text objects as they are static
### and this reduces the amount of redrawing for the dynamic numbers
FONT_SCALE = 3

if magnetometer is not None:
    magnet_value_dob = Label(font=terminalio.FONT,
                             text="----.-",
                             scale=FONT_SCALE,
                             color=0xc0c000)
    magnet_value_dob.y = 90

    magnet_units_dob = Label(font=terminalio.FONT,
                             text="uT",
                             scale=FONT_SCALE,
                             color=0xc0c000)
    magnet_units_dob.x = len(magnet_value_dob.text) * FONT_WIDTH * FONT_SCALE
    magnet_units_dob.y = magnet_value_dob.y

voltage_value_dob = Label(font=terminalio.FONT,
                          text="----.-",
                          scale=FONT_SCALE,
                          color=0x00c0c0)
voltage_value_dob.y = 30