Skip to content

Commit

Permalink
Merge pull request #11 from jake1164/feature/cp9-support
Browse files Browse the repository at this point in the history
Updated code to work with CircuitPython 9
  • Loading branch information
jake1164 authored Apr 12, 2024
2 parents ca18ef9 + 1bc98ff commit 2c6406b
Show file tree
Hide file tree
Showing 36 changed files with 243 additions and 51 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# tempest-led-weather-clock
LED Matrix Clock with weather running on a Raspberry Pico W and a WaveShare [Pico-RGB-Matrix-P3-64x32](https://www.waveshare.com/wiki/Pico-RGB-Matrix-P3-64x32)

## Transition
This project will eventually work from the weatherflow api and not require an Open Weather Map account.
## NOTE: THIS PROJECT HAS BEEN UPDATED AND REQUIRES CircuitPython 9.0.0 or later
This project requires that you use [circuitpython 9.x.x](https://circuitpython.org/board/raspberry_pi_pico_w/).
If you still wish to use 8.x you will need to use an older [release](https://github.com/jake1164/tempest-led-weather-clock/releases/tag/v0.2.1)

## Weather APIs
A subscription to Open Weather Map (OWM) is required to display the current conditions and the current condition icon. Tempest api is optional, if provided it will pull all information except the above two items from OWM.
Expand Down Expand Up @@ -53,8 +54,8 @@ Settings:
## Board
This project requires the use of a [Raspberry Pico W](https://www.raspberrypi.com/products/raspberry-pi-pico/) to use the WIFI for getting information for displaying on the screen such as updated time, and eventually local weather. (api to be defined soon)

## Circuitpython 8.0.0
This project requires that you use [circuitpython 8.x.x](https://circuitpython.org/board/raspberry_pi_pico_w/).
## Circuitpython 9.0.0
This project requires that you use [circuitpython 9.x.x](https://circuitpython.org/board/raspberry_pi_pico_w/).

## Libraries
Circuit libraries are included in the ./lib/src folder, just copy the ./src folder to the Pico. Most of the libraries are located on the
Expand Down Expand Up @@ -91,4 +92,4 @@ to your .vscode.json config file.
```

# KNOWN ISSUES
Does not work with CircuitPython 8.1.0 (or 8.2.0_beta)
Memory is on the ragged edge of the Pico W limits and as such many api requests fail do to memory allocation issues.
39 changes: 21 additions & 18 deletions src/code.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
# UPDATE the settings.toml file before starting!

# Following are imported from circuitpython 8.x
import os
import gc
gc.collect()
print('free memory', gc.mem_free(), gc.mem_alloc())
import os
import board
import displayio
import time
import framebufferio
from rgbmatrix import RGBMatrix

# project classes
from splash_display import SplashDisplay
from settings_display import SETTINGS, SettingsDisplay
from date_utils import DateTimeProcessing
from key_processing import KeyProcessing
from light_sensor import LightSensor
from network import WifiNetwork
from weather.weather_factory import Factory
from weather.weather_display import WeatherDisplay
from persistent_settings import Settings
from buzzer import Buzzer
from version import Version

gc.collect()
icon_spritesheet = "/images/weather-icons.bmp"
time_format_flag = 0 # 12 or 24 (0 or 1) hour display.
bit_depth_value = 1
Expand All @@ -34,11 +22,10 @@

width_value = base_width * chain_across
height_value = base_height * tile_down

from version import Version
version = Version()
# read the version if it exists.
print(f'Version: {version.get_version_string()}')
icons = displayio.OnDiskBitmap(open(icon_spritesheet, "rb"))

# release displays before creating a new one.
displayio.release_displays()
Expand All @@ -58,12 +45,28 @@
doublebuffer=True,
)

# project classes
from splash_display import SplashDisplay
# Associate the RGB matrix with a Display so that we can use displayio features
display = framebufferio.FramebufferDisplay(matrix, auto_refresh=True)

#display a splash screen to hide the random text that appears.
icons = displayio.OnDiskBitmap(open(icon_spritesheet, "rb"))
splash = SplashDisplay(icons, version)
display.root_group = splash
print('free memory', gc.mem_free(), gc.mem_alloc())

from settings_display import SETTINGS, SettingsDisplay
from date_utils import DateTimeProcessing
from key_processing import KeyProcessing
from light_sensor import LightSensor
from network import WifiNetwork
from weather.weather_factory import Factory
from weather.weather_display import WeatherDisplay
from persistent_settings import Settings
from buzzer import Buzzer



try:
network = WifiNetwork() # TODO: catch exception and do something meaninful with it.
Expand Down Expand Up @@ -106,7 +109,7 @@

# remove splash from memory
#del bg, splash
del splash
del version, splash
gc.collect()

print('free memory', gc.mem_free())
Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_bitmap_font/bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from fontio import Glyph
from .glyph_cache import GlyphCache

__version__ = "2.0.2"
__version__ = "2.1.1"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font.git"


Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_bitmap_font/bitmap_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
except ImportError:
pass

__version__ = "2.0.2"
__version__ = "2.1.1"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font.git"


Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_bitmap_font/glyph_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import gc

__version__ = "2.0.2"
__version__ = "2.1.1"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font.git"


Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_bus_device/i2c_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pass


__version__ = "5.2.7"
__version__ = "5.2.8"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git"


Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_bus_device/spi_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
pass


__version__ = "5.2.7"
__version__ = "5.2.8"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git"


Expand Down
Binary file added src/lib/adafruit_connection_manager.mpy
Binary file not shown.
2 changes: 1 addition & 1 deletion src/lib/adafruit_display_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
=======================
"""

__version__ = "3.0.4"
__version__ = "3.1.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

from displayio import Group, Palette
Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_display_text/bitmap_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

__version__ = "3.0.4"
__version__ = "3.1.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

import displayio
Expand Down
2 changes: 1 addition & 1 deletion src/lib/adafruit_display_text/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

__version__ = "3.0.4"
__version__ = "3.1.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"


Expand Down
188 changes: 188 additions & 0 deletions src/lib/adafruit_display_text/outlined_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# SPDX-FileCopyrightText: 2023 Tim C
#
# SPDX-License-Identifier: MIT

"""
`adafruit_display_text.outlined_label`
====================================================
Subclass of BitmapLabel that adds outline color and stroke size
functionalities.
* Author(s): Tim Cocks
Implementation Notes
--------------------
**Hardware:**
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads
"""
__version__ = "3.1.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

import bitmaptools
from displayio import Palette, Bitmap
from adafruit_display_text import bitmap_label

try:
from typing import Optional, Tuple, Union
from fontio import FontProtocol
except ImportError:
pass


class OutlinedLabel(bitmap_label.Label):
"""
OutlinedLabel - A BitmapLabel subclass that includes arguments and properties for specifying
outline_size and outline_color to get drawn as a stroke around the text.
:param Union[Tuple, int] outline_color: The color of the outline stroke as RGB tuple, or hex.
:param int outline_size: The size in pixels of the outline stroke.
"""

# pylint: disable=too-many-arguments
def __init__(
self,
font,
outline_color: Union[int, Tuple] = 0x999999,
outline_size: int = 1,
padding_top: Optional[int] = None,
padding_bottom: Optional[int] = None,
padding_left: Optional[int] = None,
padding_right: Optional[int] = None,
**kwargs
):
if padding_top is None:
padding_top = outline_size + 0
if padding_bottom is None:
padding_bottom = outline_size + 2
if padding_left is None:
padding_left = outline_size + 0
if padding_right is None:
padding_right = outline_size + 0

super().__init__(
font,
padding_top=padding_top,
padding_bottom=padding_bottom,
padding_left=padding_left,
padding_right=padding_right,
**kwargs
)

_background_color = self._palette[0]
_foreground_color = self._palette[1]
_background_is_transparent = self._palette.is_transparent(0)
self._palette = Palette(3)
self._palette[0] = _background_color
self._palette[1] = _foreground_color
self._palette[2] = outline_color
if _background_is_transparent:
self._palette.make_transparent(0)

self._outline_size = outline_size
self._stamp_source = Bitmap((outline_size * 2) + 1, (outline_size * 2) + 1, 3)
self._stamp_source.fill(2)

self._bitmap = None

self._reset_text(
font=font,
text=self._text,
line_spacing=self._line_spacing,
scale=self.scale,
)

def _add_outline(self):
"""
Blit the outline into the labels Bitmap. We will stamp self._stamp_source for each
pixel of the foreground color but skip the foreground color when we blit.
:return: None
"""
if hasattr(self, "_stamp_source"):
for y in range(self.bitmap.height):
for x in range(self.bitmap.width):
if self.bitmap[x, y] == 1:
try:
bitmaptools.blit(
self.bitmap,
self._stamp_source,
x - self._outline_size,
y - self._outline_size,
skip_dest_index=1,
)
except ValueError as value_error:
raise ValueError(
"Padding must be big enough to fit outline_size "
"all the way around the text. "
"Try using either larger padding sizes, or smaller outline_size."
) from value_error

def _place_text(
self,
bitmap: Bitmap,
text: str,
font: FontProtocol,
xposition: int,
yposition: int,
skip_index: int = 0, # set to None to write all pixels, other wise skip this palette index
# when copying glyph bitmaps (this is important for slanted text
# where rectangular glyph boxes overlap)
) -> Tuple[int, int, int, int]:
"""
Copy the glpyphs that represent the value of the string into the labels Bitmap.
:param bitmap: The bitmap to place text into
:param text: The text to render
:param font: The font to render the text in
:param xposition: x location of the starting point within the bitmap
:param yposition: y location of the starting point within the bitmap
:param skip_index: Color index to skip during rendering instead of covering up
:return Tuple bounding_box: tuple with x, y, width, height values of the bitmap
"""
parent_result = super()._place_text(
bitmap, text, font, xposition, yposition, skip_index=skip_index
)

self._add_outline()

return parent_result

@property
def outline_color(self):
"""Color of the outline to draw around the text."""
return self._palette[2]

@outline_color.setter
def outline_color(self, new_outline_color):
self._palette[2] = new_outline_color

@property
def outline_size(self):
"""Stroke size of the outline to draw around the text."""
return self._outline_size

@outline_size.setter
def outline_size(self, new_outline_size):
self._outline_size = new_outline_size

self._padding_top = new_outline_size + 0
self._padding_bottom = new_outline_size + 2
self._padding_left = new_outline_size + 0
self._padding_right = new_outline_size + 0

self._stamp_source = Bitmap(
(new_outline_size * 2) + 1, (new_outline_size * 2) + 1, 3
)
self._stamp_source.fill(2)
self._reset_text(
font=self._font,
text=self._text,
line_spacing=self._line_spacing,
scale=self.scale,
)
2 changes: 1 addition & 1 deletion src/lib/adafruit_display_text/scrolling_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

__version__ = "3.0.4"
__version__ = "3.1.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

import time
Expand Down
Binary file modified src/lib/adafruit_ds3231.mpy
Binary file not shown.
2 changes: 1 addition & 1 deletion src/lib/adafruit_imageload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
except ImportError:
pass

__version__ = "1.20.0"
__version__ = "1.20.2"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad.git"


Expand Down
Loading

0 comments on commit 2c6406b

Please sign in to comment.