Understanding Magtag Weather Display Project - displayio

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
edallatore
 
Posts: 1
Joined: Sat May 04, 2019 1:50 pm

Understanding Magtag Weather Display Project - displayio

Post by edallatore »

Hello,

I'm running the weather display project on my magtag, and I'd like to add a battery icon to the display.
I'm having trouble understanding how the software picks the correct weather icon from the bmps to display.
I think it's something to do with this line: today_icon[0] = ICON_MAP.index(data["weather"][0]["icon"][:2])
Does anyone have any insight on how this works?

Thanks!

~ E

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: Understanding Magtag Weather Display Project - displayio

Post by dastels »

This uses the displayio module to manage the display and UI elements including, of interest here, TileMap.

The weather icons are in a spritemap. Based on the weather data (i.e. data["weather"][0]["icon"][:2] we map to a sprite by indexing into ICON_MAP. That sprite number gets placed in the (only) tile in today_icon. That causes the tile to update by displaying the sprite that was set.

The tilemap is created, with one 70x70 tile, using icons_large_bmp as its spritemap:

Code: Select all

today_icon = displayio.TileGrid(
    icons_large_bmp,
    pixel_shader=icons_small_pal,
    x=10,
    y=40,
    width=1,
    height=1,
    tile_width=70,
    tile_height=70,
)
The sprite displayed in that tile is updated based on the weather and the mapping table:

Code: Select all

today_icon[0] = ICON_MAP.index(data["weather"][0]["icon"][:2])
The spritemap:

[The extension bmp has been deactivated and can no longer be displayed.]

is 9 70x70 sprites in a 3x3 spritemap. It's loaded by:

Code: Select all

icons_large_bmp, icons_large_pal = adafruit_imageload.load(ICONS_LARGE_FILE)
The tile knows how to extract selected sprites.

See https://learn.adafruit.com/circuitpytho ... -displayio for more detail on displayio.

I hope that helps a bit.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”