Skip to content

Commit

Permalink
Migrate BadgerOS to use png.
Browse files Browse the repository at this point in the history
Update all app icons to (smaller) 1bit png files.

Prefer png but fallback to jpg for app icons, so users don't have to convert their icons.

Update image to support both jpg and png.

Replace jpg icons for Weather with (smaller) png ones.
  • Loading branch information
Gadgetoid committed Mar 27, 2024
1 parent c257bf7 commit a429602
Show file tree
Hide file tree
Showing 37 changed files with 31 additions and 17 deletions.
Binary file removed badger_os/examples/icon-badge.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-clock.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-ebook.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-ebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-fonts.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-fonts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-help.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-image.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-info.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-list.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-net-info.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-net-info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-news.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-news.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-qrgen.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-qrgen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed badger_os/examples/icon-weather.jpg
Binary file not shown.
Binary file added badger_os/examples/icon-weather.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 14 additions & 6 deletions badger_os/examples/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from badger2040 import HEIGHT, WIDTH
import badger_os
import jpegdec
import pngdec


TOTAL_IMAGES = 0
Expand All @@ -14,11 +15,12 @@
display.set_update_speed(badger2040.UPDATE_NORMAL)

jpeg = jpegdec.JPEG(display.display)
png = pngdec.PNG(display.display)


# Load images
try:
IMAGES = [f for f in os.listdir("/images") if f.endswith(".jpg")]
IMAGES = [f for f in os.listdir("/images") if f.endswith(".jpg") or f.endswith(".png")]
TOTAL_IMAGES = len(IMAGES)
except OSError:
pass
Expand All @@ -32,18 +34,24 @@

def show_image(n):
file = IMAGES[n]
name = file.split(".")[0]
jpeg.open_file("/images/{}".format(file))
jpeg.decode()
name, ext = file.split(".")

try:
png.open_file("/images/{}".format(file))
png.decode()
except (OSError, RuntimeError):
jpeg.open_file("/images/{}".format(file))
jpeg.decode()

if state["show_info"]:
name_length = display.measure_text(name, 0.5)
label = f"{name} ({ext})"
name_length = display.measure_text(label, 0.5)
display.set_pen(0)
display.rectangle(0, HEIGHT - 21, name_length + 11, 21)
display.set_pen(15)
display.rectangle(0, HEIGHT - 20, name_length + 10, 20)
display.set_pen(0)
display.text(name, 5, HEIGHT - 10, WIDTH, 0.5)
display.text(label, 5, HEIGHT - 10, WIDTH, 0.5)

for i in range(TOTAL_IMAGES):
x = 286
Expand Down
16 changes: 8 additions & 8 deletions badger_os/examples/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import badger2040
from badger2040 import WIDTH
import urequests
import jpegdec
import pngdec

# Set your latitude/longitude here (find yours by right clicking in Google Maps!)
LAT = 53.38609085276884
Expand All @@ -18,7 +18,7 @@
display.led(128)
display.set_update_speed(2)

jpeg = jpegdec.JPEG(display.display)
png = pngdec.PNG(display.display)

# Connects to the wireless network. Ensure you have entered your details in WIFI_CONFIG.py :).
display.connect()
Expand Down Expand Up @@ -72,16 +72,16 @@ def draw_page():
# Weather codes from https://open-meteo.com/en/docs
# Weather icons from https://fontawesome.com/
if weathercode in [71, 73, 75, 77, 85, 86]: # codes for snow
jpeg.open_file("/icons/icon-snow.jpg")
png.open_file("/icons/icon-snow.png")
elif weathercode in [51, 53, 55, 56, 57, 61, 63, 65, 66, 67, 80, 81, 82]: # codes for rain
jpeg.open_file("/icons/icon-rain.jpg")
png.open_file("/icons/icon-rain.png")
elif weathercode in [1, 2, 3, 45, 48]: # codes for cloud
jpeg.open_file("/icons/icon-cloud.jpg")
png.open_file("/icons/icon-cloud.png")
elif weathercode in [0]: # codes for sun
jpeg.open_file("/icons/icon-sun.jpg")
png.open_file("/icons/icon-sun.png")
elif weathercode in [95, 96, 99]: # codes for storm
jpeg.open_file("/icons/icon-storm.jpg")
jpeg.decode(13, 40, jpegdec.JPEG_SCALE_FULL)
png.open_file("/icons/icon-storm.png")
png.decode(13, 40)
display.set_pen(0)
display.text(f"Temperature: {temperature}°C", int(WIDTH / 3), 28, WIDTH - 105, 2)
display.text(f"Wind Speed: {windspeed}kmph", int(WIDTH / 3), 48, WIDTH - 105, 2)
Expand Down
Binary file removed badger_os/icons/icon-cloud.jpg
Binary file not shown.
Binary file added badger_os/icons/icon-cloud.png
Binary file removed badger_os/icons/icon-rain.jpg
Diff not rendered.
Binary file added badger_os/icons/icon-rain.png
Binary file removed badger_os/icons/icon-snow.jpg
Diff not rendered.
Binary file added badger_os/icons/icon-snow.png
Binary file removed badger_os/icons/icon-storm.jpg
Diff not rendered.
Binary file added badger_os/icons/icon-storm.png
Binary file removed badger_os/icons/icon-sun.jpg
Diff not rendered.
Binary file added badger_os/icons/icon-sun.png
12 changes: 9 additions & 3 deletions badger_os/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import math
import badger2040
import badger_os
import pngdec
import jpegdec

APP_DIR = "/examples"
Expand All @@ -26,6 +27,7 @@
display.set_font("bitmap8")
display.led(128)

png = pngdec.PNG(display.display)
jpeg = jpegdec.JPEG(display.display)

state = {
Expand Down Expand Up @@ -90,10 +92,14 @@ def render():
x = centers[i]
label = examples[i + (state["page"] * 3)]
icon_label = label.replace("_", "-")
icon = f"{APP_DIR}/icon-{icon_label}.jpg"
icon = f"{APP_DIR}/icon-{icon_label}"
label = label.replace("_", " ")
jpeg.open_file(icon)
jpeg.decode(x - 26, 30)
try:
png.open_file(f"{icon}.png")
png.decode(x - 26, 30)
except (OSError, RuntimeError):
jpeg.open_file(f"{icon}.jpg")
jpeg.decode(x - 26, 30)
display.set_pen(0)
w = display.measure_text(label, FONT_SIZE)
display.text(label, int(x - (w / 2)), 16 + 80, WIDTH, FONT_SIZE)
Expand Down

0 comments on commit a429602

Please sign in to comment.