def main():
    # Make the display context
    splash = displayio.Group(max_size=20)
    board.DISPLAY.show(splash)

    # Make a background color fill
    color_bitmap = displayio.Bitmap(320, 240, 1)
    color_palette = displayio.Palette(1)
    color_palette[0] = 0xFFFFFF
    bg_sprite = displayio.TileGrid(color_bitmap,
                                   x=0,
                                   y=0,
                                   pixel_shader=color_palette)
    splash.append(bg_sprite)
    ##########################################################################

    splash.append(Line(220, 130, 270, 210, 0xFF0000))
    splash.append(Line(270, 210, 220, 210, 0xFF0000))
    splash.append(Line(220, 210, 270, 130, 0xFF0000))
    splash.append(Line(270, 130, 220, 130, 0xFF0000))

    #Draw a blue star
    polygon = Polygon([(255, 40), (262, 62), (285, 62), (265, 76), (275, 100),
                       (255, 84), (235, 100), (245, 76), (225, 62), (248, 62)],
                      outline=0x0000FF)
    splash.append(polygon)

    triangle = Triangle(170,
                        50,
                        120,
                        140,
                        210,
                        160,
                        fill=0x00FF00,
                        outline=0xFF00FF)
    splash.append(triangle)

    rect = Rect(80, 20, 41, 41, fill=0x0)
    splash.append(rect)

    circle = Circle(100, 100, 20, fill=0x00FF00, outline=0xFF00FF)
    splash.append(circle)

    rect2 = Rect(50, 100, 61, 81, outline=0x0, stroke=3)
    splash.append(rect2)

    roundrect = RoundRect(10,
                          10,
                          61,
                          81,
                          10,
                          fill=0x0,
                          outline=0xFF00FF,
                          stroke=6)
    splash.append(roundrect)

    sleep(4)
    running = False
    def test_shapes(self):

        expected_images = []
        for i in range(5):
            img = Image.open(
                os.path.join(
                    self.abs_path,
                    CONSTANTS.IMG_DIR_NAME,
                    f"test_image_shapes_{i+1}.bmp",
                ))

            img.putalpha(255)
            expected_images.append(img.load())

        # TAKEN FROM ADAFRUIT'S DISPLAY SHAPES LIBRARY
        # https://github.com/ladyada/Adafruit_CircuitPython_Display_Shapes/blob/master/examples/display_shapes_simpletest.py
        splash = displayio.Group(max_size=10)
        splash._Group__show = self.__send_helper
        board.DISPLAY.show(splash)
        color_bitmap = displayio.Bitmap(320, 240, 1)
        color_palette = displayio.Palette(1)
        color_palette[0] = 0xFFFFFF
        bg_sprite = displayio.TileGrid(color_bitmap,
                                       x=0,
                                       y=0,
                                       pixel_shader=color_palette)
        splash.append(bg_sprite)
        helper._Helper__test_image_equality(self.main_img.load(),
                                            expected_images[0])

        rect = Rect(80, 20, 41, 41, fill=0x00FF00)
        splash.append(rect)
        helper._Helper__test_image_equality(self.main_img.load(),
                                            expected_images[1])
        circle = Circle(100, 100, 20, fill=0x00FF00, outline=0xFF00FF)
        splash.append(circle)

        helper._Helper__test_image_equality(self.main_img.load(),
                                            expected_images[2])

        rect2 = Rect(50, 100, 61, 81, outline=0x0, stroke=3)
        splash.append(rect2)

        helper._Helper__test_image_equality(self.main_img.load(),
                                            expected_images[3])

        roundrect = RoundRect(10,
                              10,
                              61,
                              81,
                              10,
                              fill=0x0,
                              outline=0xFF00FF,
                              stroke=6)
        splash.append(roundrect)

        helper._Helper__test_image_equality(self.main_img.load(),
                                            expected_images[4])
Beispiel #3
0
 def _create_body(self):
     if (self.outline_color is not None) or (self.fill_color is not None):
         if self.style == Button.RECT:
             self.body = Rect(
                 0,
                 0,
                 self.width,
                 self.height,
                 fill=self._fill_color,
                 outline=self._outline_color,
             )
         elif self.style == Button.ROUNDRECT:
             self.body = RoundRect(
                 0,
                 0,
                 self.width,
                 self.height,
                 r=10,
                 fill=self._fill_color,
                 outline=self._outline_color,
             )
         elif self.style == Button.SHADOWRECT:
             self.shadow = Rect(2,
                                2,
                                self.width - 2,
                                self.height - 2,
                                fill=self.outline_color)
             self.body = Rect(
                 0,
                 0,
                 self.width - 2,
                 self.height - 2,
                 fill=self._fill_color,
                 outline=self._outline_color,
             )
         elif self.style == Button.SHADOWROUNDRECT:
             self.shadow = RoundRect(
                 2,
                 2,
                 self.width - 2,
                 self.height - 2,
                 r=10,
                 fill=self._outline_color,
             )
             self.body = RoundRect(
                 0,
                 0,
                 self.width - 2,
                 self.height - 2,
                 r=10,
                 fill=self._fill_color,
                 outline=self._outline_color,
             )
         if self.shadow:
             self.append(self.shadow)
Beispiel #4
0
    def __init__(self, *, x, y, width, height, name=None, style=RECT,
                 fill_color=0xFFFFFF, outline_color=0x0,
                 label=None, label_font=None, label_color=0x0,
                 selected_fill=None, selected_outline=None,
                 selected_label=None, icon=None):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self._font = label_font
        self._selected = False
        self.group = displayio.Group()
        self.name = name
        self._label = label
        self._icon = icon
        self.body = self.fill = self.shadow = None

        self.fill_color = _check_color(fill_color)
        self.outline_color = _check_color(outline_color)
        self._label_color = label_color
        self._label_font = label_font
        # Selecting inverts the button colors!
        self.selected_fill = _check_color(selected_fill)
        self.selected_outline = _check_color(selected_outline)
        self.selected_label = _check_color(selected_label)

        if self.selected_fill is None and fill_color is not None:
            self.selected_fill = (~self.fill_color) & 0xFFFFFF
        if self.selected_outline is None and outline_color is not None:
            self.selected_outline = (~self.outline_color) & 0xFFFFFF

        if outline_color or fill_color:
            if style == Button.RECT:
                self.body = Rect(x, y, width, height,
                                 fill=self.fill_color, outline=self.outline_color)
            elif style == Button.ROUNDRECT:
                self.body = RoundRect(x, y, width, height, r=10,
                                      fill=self.fill_color, outline=self.outline_color)
            elif style == Button.SHADOWRECT:
                self.shadow = Rect(x + 2, y + 2, width - 2, height - 2,
                                   fill=outline_color)
                self.body = Rect(x, y, width - 2, height - 2,
                                 fill=self.fill_color, outline=self.outline_color)
            elif style == Button.SHADOWROUNDRECT:
                self.shadow = RoundRect(x + 2, y + 2, width - 2, height - 2, r=10,
                                        fill=self.outline_color)
                self.body = RoundRect(x, y, width - 2, height - 2, r=10,
                                      fill=self.fill_color, outline=self.outline_color)
            if self.shadow:
                self.group.append(self.shadow)
            self.group.append(self.body)

        self.icon = icon
        self.label = label
Beispiel #5
0
def cc_init(cc_state):
    fontL = cc_state['fonts']['helvB12']
    fontS = cc_state['fonts']['helvR10']
    #
    grp_clock = displayio.Group(max_size=6)
    #
    grp_clock.append(Rect(0,0, 32,32, fill=0x000020, outline=0x202020))
    grp_clock.append(Rect(1,10, 30,11, fill=0x080030))
    #
    lbl_time = label.Label(fontL, color=0x808080, text='00:00', x=4, y=16)
    grp_clock.append(lbl_time)
    #
    lbl_month = label.Label(fontS, color=0x804000, text='Jan', x=1, y=25)
    grp_clock.append(lbl_month)
    #
    lbl_day_num = label.Label(fontS, color=0x804000, text='33', x=17, y=26)
    grp_clock.append(lbl_day_num)
    #
    lbl_day_wk = label.Label(fontS, color=0x804000, text='Fri', x=8, y=6)
    grp_clock.append(lbl_day_wk)
    #
    # LATITUDE, LONGITUDE, TIMEZONE are set up once, constant over app lifetime
    # Fetch latitude/longitude from secrets.py. If not present, use
    # IP geolocation. This only needs to be done once, at startup!
    lat = None ; lon = None ; tz = None
    net = cc_state['network']
    try:
        lat = cc_state['secrets']['latitude']
        lon = cc_state['secrets']['longitude']
        print('Using stored geolocation: ', lat, lon)
        CC_blockData['lat'] = lat ; CC_blockData['lon'] = lon
    except KeyError:
        pass
    #
    # Load time zone string from secrets.py, else IP geolocation for this too
    # (http://worldtimeapi.org/api/timezone for list).
    try:
        tz = cc_state['secrets']['timezone'] # e.g. 'America/New_York'
        CC_blockData['tz'] = tz
    except KeyError:
        pass
    #
    try:
        utc_offset = cc_state['secrets']['utc_offset']
        CC_blockData['utc_offset'] = utc_offset
    except KeyError:
        CC_blockData['utc_offset'] = 0
    #
    #
    # Set initial last_sync time to update time right away in cc_update
    CC_blockData['last_sync'] = time.time() - SYNC_TIME
    #
    return grp_clock
Beispiel #6
0
    def render(self):
        display = badge.display
        screen = displayio.Group()

        screen.append(
            Rect(0, 32, display.width, display.height - 32, fill=0xffffff))

        app_label = bitmap_label.Label(terminalio.FONT,
                                       text="Keyboard Test",
                                       color=0xffffff,
                                       save_text=True)
        app_label_group = displayio.Group(scale=2, x=40, y=14)
        app_label_group.append(app_label)
        screen.append(app_label_group)

        if self.keyboard:
            key_label = bitmap_label.Label(terminalio.FONT,
                                           text=self.text,
                                           color=0x0,
                                           scale=3,
                                           anchor_point=(0.5, 0.5),
                                           anchored_position=(display.width //
                                                              2, 70))
        else:
            key_label = bitmap_label.Label(
                terminalio.FONT,
                text="Keyboard not connected\n         :-(",
                color=0x0,
                scale=2,
                anchor_point=(0.5, 0.5),
                anchored_position=(display.width // 2, 70))
        screen.append(key_label)

        display.show(screen)
        self.update_screen = False
Beispiel #7
0
    def __init__(self,
                 width,
                 height,
                 start_x,
                 start_y,
                 badger,
                 up_btn_str,
                 down_btn_str,
                 debug=False):
        self.badger = badger

        # Store local variables in our object to access later in other functions
        self.height = height
        self.width = width
        self.x = start_x
        self.y = start_y

        # will store previous update y position to determine if paddle is in motion
        self.prev_y = self.y

        # will store the int values of the buttons we are interested in for this update frame
        self.up_btn = 0
        self.down_btn = 0

        # stores the string representation of the buttons we care about
        self.up_btn_str = up_btn_str
        self.down_btn_str = down_btn_str

        # create a rect object
        self.rect = Rect(self.x, self.y, self.width, self.height, fill=0x0)

        # screen height needed so it knows when to stop moving
        self.SCREEN_HEIGHT = 128
Beispiel #8
0
    def show_splash(self):
        """
        Shows the loading screen
        """
        if self.debug:
            return

        blinka_bitmap = "blinka-pyloton.bmp"

        # Compatible with CircuitPython 6 & 7
        with open(blinka_bitmap, 'rb') as bitmap_file:
            bitmap1 = displayio.OnDiskBitmap(bitmap_file)
            tile_grid = displayio.TileGrid(bitmap1,
                                           pixel_shader=getattr(
                                               bitmap1, 'pixel_shader',
                                               displayio.ColorConverter()))
            self.loading_group.append(tile_grid)
            self.display.show(self.loading_group)
            status_heading = label.Label(font=self.arial16,
                                         x=80,
                                         y=175,
                                         text="Status",
                                         color=self.YELLOW)
            rect = Rect(0, 165, 240, 75, fill=self.PURPLE)
            self.loading_group.append(rect)
            self.loading_group.append(status_heading)
    def background(self):
        # PLEASE NOTE
        # This needs to be run before calling render

        # Define the group for the thermal display
        self.image_group = displayio.Group(max_size=77)

        # Create a black background color fill layer; image_group[0]
        color_bitmap = displayio.Bitmap(self.WIDTH, self.HEIGHT, 1)
        color_palette = displayio.Palette(1)
        color_palette[0] = self.colours.BLACK
        background = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
        self.image_group.append(background)

        # Define the foundational thermal image element layers; image_group[1:64]
        #   image_group[#]=(row * 8) + column
        for row in range(0, 8):
            for col in range(0, 8):
                pos_x, pos_y = self.element_grid(col, row)
                # outline is normally None and stroke is 0
                element = Rect(x=pos_x, y=pos_y, width=self.ELEMENT_SIZE, height=self.ELEMENT_SIZE,
                    fill=None, outline=None, stroke=0
                )
                self.image_group.append(element)

        self.display.show(self.image_group)
 def make_ui_group(self, main_config, config_label, rect_val=None):
     """
     Generates and displays a displayio group containing several elements
     that all config screens have in common (or nearly in common).
     Arguments:
         main_config (boolean) : If true, function generates the main
                                 config screen elements, else makes
                                 elements for other config screens.
         config_label (string) : Text to appear at center(ish) of screen.
         rect_val (float)      : If specified, a Rect object is created
                                 whose width represents the value.
                                 0.0 = min, 1.0 = full display width.
     Returns: displayio group
     """
     group = displayio.Group()
     group.append(centered_label('TAP L/R to', 3, 2))
     group.append(centered_label('select item' if main_config else
                                 'select image' if self.config_mode is 0
                                 else 'change', 16, 2))
     group.append(centered_label('HOLD L: item config' if main_config else
                                 'HOLD L: back', 100, 2))
     group.append(centered_label('HOLD R: paint', 113, 2))
     if rect_val:
         self.rect = Rect(int(board.DISPLAY.width * (rect_val - 1.0)),
                          120, board.DISPLAY.width, 40, fill=0x00B000)
         group.append(self.rect)
     # Config label always appears as last item in group
     # so calling func can pop() and replace it if need be.
     group.append(centered_label(config_label, 30 if rect_val else 40, 3))
     board.DISPLAY.show(group)
     return group
Beispiel #11
0
    def __init__(self, parent_group, index):
        y = (int)(config['character_height'] +
                  config['text_padding']) * (index + 1)

        self.line_rect = Rect(0,
                              y,
                              config['train_line_width'],
                              config['train_line_height'],
                              fill=config['loading_line_color'])

        self.destination_label = Label(
            config['font'],
            max_glyphs=config['destination_max_characters'],
            anchor_point=(0, 0))
        self.destination_label.x = config['train_line_width'] + 2
        self.destination_label.y = y
        self.destination_label.color = config['text_color']
        self.destination_label.text = config[
            'loading_destination_text'][:config['destination_max_characters']]

        self.min_label = Label(config['font'],
                               max_glyphs=config['min_label_characters'],
                               anchor_point=(0, 0))
        self.min_label.x = config['matrix_width'] - (
            config['min_label_characters'] * config['character_width']) + 1
        self.min_label.y = y
        self.min_label.color = config['text_color']
        self.min_label.text = config['loading_min_text']

        self.group = displayio.Group(max_size=3)
        self.group.append(self.line_rect)
        self.group.append(self.destination_label)
        self.group.append(self.min_label)

        parent_group.append(self.group)
    def _badge_background(
        self,
        background_color=(255, 0, 0),
        rectangle_color=(255, 255, 255),
        rectangle_drop=0.4,
        rectangle_height=0.5,
    ):
        """Populate the background color with a rectangle color block over it as the background for
         a name badge."""
        background_group = displayio.Group(max_size=30)
        color_bitmap = displayio.Bitmap(self.display.width, self.display.height, 1)
        color_palette = displayio.Palette(1)
        color_palette[0] = background_color

        bg_sprite = displayio.TileGrid(
            color_bitmap, pixel_shader=color_palette, x=0, y=0
        )
        background_group.append(bg_sprite)

        rectangle = Rect(
            0,
            (int(self.display.height * rectangle_drop)),
            self.display.width,
            (int(self.display.height * rectangle_height)),
            fill=rectangle_color,
        )
        background_group.append(rectangle)
        return background_group
    def _badge_background(
        self,
        background_color: Tuple[int, int, int] = RED,
        rectangle_color: Tuple[int, int, int] = WHITE,
        rectangle_drop: float = 0.4,
        rectangle_height: float = 0.5,
    ) -> displayio.Group:
        """Populate the background color with a rectangle color block over it as the background for
        a name badge."""
        background_group = displayio.Group()
        color_bitmap = displayio.Bitmap(self.display.width, self.display.height, 1)
        color_palette = displayio.Palette(1)
        color_palette[0] = background_color

        bg_sprite = displayio.TileGrid(
            color_bitmap, pixel_shader=color_palette, x=0, y=0
        )
        background_group.append(bg_sprite)

        rectangle = Rect(
            0,
            (int(self.display.height * rectangle_drop)),
            self.display.width,
            (int(self.display.height * rectangle_height)),
            fill=rectangle_color,
        )
        background_group.append(rectangle)
        return background_group
Beispiel #14
0
def voltage_bar_set(volt_diff):
    """Draw a bar based on positive or negative values.
       Width of 60 is performance compromise as more pixels take longer."""
    global voltage_sep_dob, voltage_barpos_dob, voltage_barneg_dob
    global last_negbar_len, last_posbar_len

    if voltage_sep_dob is None:
        voltage_sep_dob = Rect(160,
                               VOLTAGE_BAR_HEIGHT,
                               VOLTAGE_BAR_WIDTH,
                               VOLTAGE_BAR_SEP_HEIGHT,
                               fill=WHITE75)
        screen_group.append(voltage_sep_dob)

    if volt_diff < 0:
        negbar_len = max(min(-round(volt_diff * 5e3), VOLTAGE_BAR_HEIGHT), 1)
        posbar_len = 1
    else:
        negbar_len = 1
        posbar_len = max(min(round(volt_diff * 5e3), VOLTAGE_BAR_HEIGHT), 1)

    if posbar_len == last_posbar_len and negbar_len == last_negbar_len:
        return

    if voltage_barpos_dob is not None:
        screen_group.remove(voltage_barpos_dob)
    if posbar_len > 0:
        voltage_barpos_dob = Rect(160,
                                  VOLTAGE_BAR_HEIGHT - posbar_len,
                                  VOLTAGE_BAR_WIDTH,
                                  posbar_len,
                                  fill=GREEN75)
        screen_group.append(voltage_barpos_dob)
        last_posbar_len = posbar_len

    if voltage_barneg_dob is not None:
        screen_group.remove(voltage_barneg_dob)
    if negbar_len > 0:
        voltage_barneg_dob = Rect(160,
                                  VOLTAGE_BAR_HEIGHT + VOLTAGE_BAR_SEP_HEIGHT,
                                  VOLTAGE_BAR_WIDTH,
                                  negbar_len,
                                  fill=RED)
        screen_group.append(voltage_barneg_dob)
        last_negbar_len = negbar_len
Beispiel #15
0
 def new_frame(self):
     self._frame = displayio.Group(max_size=10)
     rect = Rect(0,
                 0,
                 self.DISPLAY_WIDTH,
                 self.DISPLAY_HEIGHT,
                 fill=self.BACKGROUND_COLOR)
     self._frame.append(rect)
     return self._frame
Beispiel #16
0
    def render(self):
        display = badge.display
        font = terminalio.FONT
        apps_per_screen = 3

        screen = displayio.Group(max_size=3 + apps_per_screen)
        screen.append(Rect(0, 0, display.width, display.height, fill=0xffffff))
        
        banner_image = displayio.OnDiskBitmap(open("/assets/banner.bmp", "rb"))
        banner = displayio.TileGrid(banner_image, pixel_shader=displayio.ColorConverter())
        screen.append(banner)

        first_app = (self.selection // apps_per_screen) * apps_per_screen

        # List of apps
        for index, app in enumerate(self.apps[first_app:first_app + apps_per_screen]):
            title = app['menu_item']
            y = 5 + (index % apps_per_screen) * 40
            app_group = displayio.Group(x=38, y=y)
            fill = 0
            palette = displayio.Palette(1)
            if first_app + index == self.selection:
                app_group.append(Rect(-5, -4, display.width - 32, 40, fill=0))
                fill = 0xffffff
                palette[0] = 0xffffff
            try:
                app_icon_file = app.get('icon', "{}/icon.bmp".format(app.get('path', '')))
                app_icon = displayio.OnDiskBitmap(open(app_icon_file, "rb"))
                app_group.append(displayio.TileGrid(app_icon, pixel_shader=palette))
            except:
                pass
            app_label = label.Label(font, text=title, color=fill)
            app_label_group = displayio.Group(scale=2, x=38, y=13)
            app_label_group.append(app_label)
            app_group.append(app_label_group)
            screen.append(app_group)

        if first_app + apps_per_screen < len(self.apps):
            # we have more app, display a down arrow
            more_icon = displayio.OnDiskBitmap(open("{}/arrow_down.bmp".format(MENU_ROOT), "rb"))
            screen.append(displayio.TileGrid(more_icon, pixel_shader=displayio.ColorConverter(), x=display.width - 16, y=display.height - 7))
        
        # Show it
        display.show(screen)
Beispiel #17
0
    def render(self):
        display = badge.display
        screen = displayio.Group()

        screen.append(
            Rect(0, 32, display.width, display.height - 32, fill=0xffffff))
        banner_image = displayio.OnDiskBitmap(
            open("{}/icon.bmp".format(APP_ROOT), "rb"))
        palette = displayio.Palette(1)
        palette[0] = 0xffffff
        banner = displayio.TileGrid(banner_image,
                                    pixel_shader=palette,
                                    x=4,
                                    y=0)
        screen.append(banner)

        app_label = bitmap_label.Label(terminalio.FONT,
                                       text="Conference Agenda",
                                       color=0xffffff,
                                       save_text=True)
        app_label_group = displayio.Group(scale=2, x=40, y=14)
        app_label_group.append(app_label)
        screen.append(app_label_group)

        lines_group = displayio.Group(x=8, y=48)
        lines = self.agenda[self.current_agenda][self.screen *
                                                 SCREEN_SIZE:(self.screen +
                                                              1) * SCREEN_SIZE]
        for (index, line) in enumerate(lines):
            lines_group.append(
                bitmap_label.Label(terminalio.FONT,
                                   text=line[0:40],
                                   color=0x0,
                                   y=index * 12,
                                   save_text=True))
        screen.append(lines_group)

        # Display up/down arrows as needed
        if self.screen > 0:
            more_icon = displayio.OnDiskBitmap(
                open("{}/arrow_up.bmp".format(APP_ROOT), "rb"))
            screen.append(
                displayio.TileGrid(more_icon,
                                   pixel_shader=displayio.ColorConverter(),
                                   x=display.width - 20,
                                   y=40))
        if self.screen + 1 < self.screen_count[self.current_agenda]:
            more_icon = displayio.OnDiskBitmap(
                open("{}/arrow_down.bmp".format(APP_ROOT), "rb"))
            screen.append(
                displayio.TileGrid(more_icon,
                                   pixel_shader=displayio.ColorConverter(),
                                   x=display.width - 20,
                                   y=display.height - 16))

        display.show(screen)
Beispiel #18
0
 def _status_bar(self, fill_color, outline_color):
     # Shapes
     frame = RoundRect(3,
                       96,
                       154,
                       28,
                       5,
                       fill=fill_color,
                       outline=outline_color,
                       stroke=1)
     self.main_group.append(frame)
     line = Rect(8, 110, 144, 1, fill=0x0)
     self.main_group.append(line)
     # Free resources
     self.sys_stat_label = label.Label(self.font_mini,
                                       text='Wait for status ...',
                                       color=outline_color)
     self.sys_stat_label.x = 92
     self.sys_stat_label.y = 116
     self.main_group.append(self.sys_stat_label)
     # Coordinates
     self.lat_label = label.Label(self.font_mini,
                                  text='LAT: wait            ',
                                  color=outline_color)
     self.lat_label.x = 7
     self.lat_label.y = 103
     self.main_group.append(self.lat_label)
     self.lon_label = label.Label(self.font_mini,
                                  text='LON: wait            ',
                                  color=outline_color)
     self.lon_label.x = 7
     self.lon_label.y = 115
     self.main_group.append(self.lon_label)
     # Satellites
     self.sat_label = label.Label(self.font_mini,
                                  text='SAT:0',
                                  color=fill_color)
     self.sat_label.x = 122
     self.sat_label.y = 25
     self.main_group.append(self.sat_label)
     # Fix Quality
     self.fq_label = label.Label(self.font_mini,
                                 text='FQU:0',
                                 color=fill_color)
     self.fq_label.x = 122
     self.fq_label.y = 35
     self.main_group.append(self.fq_label)
     # Altitude
     self.alt_label = label.Label(self.font_mini,
                                  text='ALT:0      ',
                                  color=outline_color)
     self.alt_label.x = 92
     self.alt_label.y = 103
     self.main_group.append(self.alt_label)
Beispiel #19
0
 def rect(self, x, y, w, h, fill=None, outline=None, stroke=1, index=None):
   """ Draw a rectangle
   """
   fl = self._pal[fill] if fill else None
   ol = self._pal[outline] if outline else None
   r = Rect(x, y, w, h, fill=fl, outline=ol, stroke=stroke)
   if index:
     self._group.insert(index, r)
     print(len(self._group), index)
   else:
     self._group.append(r)
   return r
Beispiel #20
0
def cc_init(cc_state):
    grp_meminfo = displayio.Group(max_size=3)
    rect = Rect(0, 0, 32, 32, fill=0x000020, outline=0x444444)
    grp_meminfo.append(rect)
    #
    grp_mem = cc_util.layout_group(MEM)
    grp_meminfo.append(grp_mem)
    #
    grp_free = cc_util.layout_group(FREE, -1, 14)
    grp_meminfo.append(grp_free)
    #
    return grp_meminfo
Beispiel #21
0
def cc_init(cc_state):
    conf = cc_state['config']['blocks'][CC_blockID]
    #
    grp_msg = displayio.Group(max_size=len(conf['lines']) + 1)
    rect = Rect(0, 0, 64, 32, fill=conf['bg'], outline=conf['ol'])
    grp_msg.append(rect)
    #
    for li in conf['lines']:
        font = cc_state['fonts'][li[3]]
        lbl = label.Label(font, text=li[0], x=li[1], y=li[2], color=li[4])
        grp_msg.append(lbl)
    #
    return grp_msg
Beispiel #22
0
    def run(self):
        display = badge.display
        self.running = True

        while self.running:
            group = displayio.Group()
            group.append(
                Rect(0, 0, display.width, display.height, fill=0xffffff))
            group.append(self.draw_time(self.rtc.datetime, 48, 40))
            display.show(group)
            while display.time_to_refresh > 0:
                pass
            if not self.process_input():
                display.refresh()
Beispiel #23
0
def cc_init(cc_state):
    grp_ccmp = displayio.Group(max_size=4)
    rect = Rect(0,0,32,32,fill=0x000020, outline=0x444444)
    grp_ccmp.append(rect)
    #
    grp_compu = cc_util.layout_group(COMPU)
    grp_ccmp.append(grp_compu)
    #
    grp_canvas = cc_util.layout_group(CANVAS, 0, 10)
    grp_ccmp.append(grp_canvas)
    #
    grp_mp = cc_util.layout_group(MP, 0, 20, 6, 0)
    grp_ccmp.append(grp_mp)
    #
    return grp_ccmp
Beispiel #24
0
    def __init__(self, width, height, start_x, start_y, debug=False):
        # Store local variables in our object to access later in other functions
        self.height = height
        self.width = width
        self.x = start_x
        self.y = start_y

        # create a rect object
        self.rect = Rect(self.x, self.y, self.width, self.height, fill=0x0)

        # default to moving up
        self.going_up = True

        # screen height needed so it knows when to change direction
        self.SCREEN_HEIGHT = 128
Beispiel #25
0
def init(cc_state):
    CCMP_model = cc_state['config']['CCMP_model']
    width = 32
    height = 32
    if CCMP_model == '64x':
        width = 64
        height = 64
        cc_state['width'] = 64
        cc_state['height'] = 64
    elif CCMP_model == '64h':
        width = 64
        height = 32
        cc_state['width'] = 64
        cc_state['height'] = 32
    elif CCMP_model == '64v':
        width = 64
        height = 32
        cc_state['width'] = 32
        cc_state['height'] = 64
    else:
        cc_state['width'] = 32
        cc_state['height'] = 32
    #
    matrix = Matrix(width=width, height=height, bit_depth=6)
    cc_state['matrix'] = matrix
    matrix.display.rotation = cc_state['config']['rotation']
    #
    root_group = displayio.Group(max_size=12)
    root_group.append(
        Rect(0,
             0,
             cc_state['width'],
             cc_state['height'],
             fill=0x001020,
             outline=0x444444))
    cc_state['groups']['ROOT'] = root_group
    #
    cc_state['fonts']['terminal'] = terminalio.FONT
    cc_state['fonts']['helvB12'] = bitmap_font.load_font('/fonts/helvB12.bdf')
    cc_state['fonts']['helvR10'] = bitmap_font.load_font('/fonts/helvR10.bdf')
    #
    cc_state['buttons']['up'] = digitalio.DigitalInOut(board.BUTTON_UP)
    cc_state['buttons']['up'].switch_to_input(digitalio.Pull.UP)
    cc_state['buttons']['down'] = digitalio.DigitalInOut(board.BUTTON_DOWN)
    cc_state['buttons']['down'].switch_to_input(digitalio.Pull.UP)
    cc_state['buttons']['counter'] = 0
    #
    matrix.display.show(root_group)
Beispiel #26
0
def cc_init(cc_state):
    grp_wifi = displayio.Group(max_size=2)
    rect = Rect(0, 0, 32, 32, fill=0x000020, outline=0x444444)
    grp_wifi.append(rect)
    #
    font = cc_state['fonts']['helvB12']
    lbl = label.Label(font, max_glyphs=4, color=0x800000)
    lbl.text = "WiFi"
    lbl.x = 4
    lbl.y = 14
    grp_wifi.append(lbl)
    #
    net = Network(status_neopixel=board.NEOPIXEL, debug=True)
    cc_state['network'] = net
    net.connect()
    #
    return grp_wifi
Beispiel #27
0
def PointRect(p1, p2, fill=WHITE, outline=YELLOW, stroke=2):
    ''' A wrapper function to create a rectangle from two points '''
    width = p2.x - p1.x
    height = p2.y - p1.y

    # Set minimum height and width to stroke thickness to avoid error
    if width < stroke:
        width = stroke
    if height < stroke:
        height = stroke

    return Rect(p1.x,
                p1.y,
                width,
                height,
                fill=fill,
                outline=outline,
                stroke=stroke)
Beispiel #28
0
def cc_init(cc_state):
    net = Network(status_neopixel=board.NEOPIXEL, debug=True)
    cc_state['network'] = net
    cc_state['network_IP'] = "0.0.0.0"
    net.connect()
    #
    grp_ipaddr = displayio.Group(max_size=3)
    rect = Rect(0, 0, 32, 32, fill=0x000020, outline=0x444444)
    grp_ipaddr.append(rect)
    #
    grp_addr = cc_util.layout_group(IP_ADDR)
    grp_ipaddr.append(grp_addr)
    #
    grp_trip = cc_util.layout_group(IP_TRIPLETS, 0, 10, 15, 3)
    grp_ipaddr.append(grp_trip)
    #
    del IP_ADDR[:]
    del IP_TRIPLETS[:]
    #
    return grp_ipaddr
Beispiel #29
0
    def render(self):
        screen = displayio.Group()

        screen.append(Rect(0, 0, badge.display.width, 32, fill=0xffffff))
        banner_image = displayio.OnDiskBitmap(
            open("/apps/radio/icon.bmp", "rb"))
        banner = displayio.TileGrid(banner_image,
                                    pixel_shader=displayio.ColorConverter(),
                                    x=4,
                                    y=-2)
        screen.append(banner)

        app_label = label.Label(terminalio.FONT, text="Radio", color=0x0)
        app_label_group = displayio.Group(scale=2, x=40, y=14)
        app_label_group.append(app_label)
        screen.append(app_label_group)

        controls_group = displayio.Group(scale=2, x=8, y=48)

        if self.fm is not None:
            volume_label = label.Label(terminalio.FONT,
                                       text="Volume: {}".format(
                                           self.fm.volume),
                                       color=0xffffff)
            channel_label = label.Label(terminalio.FONT,
                                        text="Station: {} FM".format(
                                            self.fm.channel),
                                        color=0xffffff,
                                        y=16)
            controls_group.append(volume_label)
            controls_group.append(channel_label)
        else:
            missing_module_label = label.Label(
                terminalio.FONT,
                text="FM module missing\n or not working",
                color=0xffffff)
            controls_group.append(missing_module_label)

        screen.append(controls_group)

        badge.display.show(screen)
Beispiel #30
0
 def draw_time(self, dt, x, y):
     timestr = '%02d:%02d' % (dt.tm_hour, dt.tm_min)
     group = displayio.Group(max_size=len(timestr) + 1, x=x, y=y)
     xpos = 0
     digit = self.selected_digit
     if digit >= 2:
         # Skip the colon
         digit += 1
     for index, ch in enumerate(timestr):
         shader = displayio.ColorConverter()
         if index == digit:
             rect = Rect(xpos - 4, -8, 48, 64, fill=0x0)
             group.append(rect)
             shader = displayio.Palette(2)
             shader[0] = 0xffffff
         sprite = displayio.TileGrid(self.assets[ch],
                                     x=xpos,
                                     pixel_shader=shader)
         group.append(sprite)
         xpos += self.assets[ch].width + 8
     return group