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
Understanding Magtag Weather Display Project - displayio
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- edallatore
- Posts: 1
- Joined: Sat May 04, 2019 1:50 pm
- dastels
- Posts: 15831
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Understanding Magtag Weather Display Project - displayio
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:
The sprite displayed in that tile is updated based on the weather and the mapping table:
The spritemap:
is 9 70x70 sprites in a 3x3 spritemap. It's loaded by:
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
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,
)
Code: Select all
today_icon[0] = ICON_MAP.index(data["weather"][0]["icon"][:2])
Code: Select all
icons_large_bmp, icons_large_pal = adafruit_imageload.load(ICONS_LARGE_FILE)
See https://learn.adafruit.com/circuitpytho ... -displayio for more detail on displayio.
I hope that helps a bit.
Dave
Please be positive and constructive with your questions and comments.