Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ci/micropython.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export TERM=${TERM:="xterm-256color"}

MICROPYTHON_FLAVOUR="pimoroni"
MICROPYTHON_VERSION="v1.25.0-and-wireless"
MICROPYTHON_VERSION="cyw43-breakout/1.27.0"

PIMORONI_PICO_FLAVOUR="pimoroni"
PIMORONI_PICO_VERSION="v1.25.0"
PIMORONI_PICO_VERSION="main"

PY_DECL_VERSION="v0.0.3"
DIR2UF2_VERSION="v0.0.9"
PY_DECL_VERSION="v0.0.5"
DIR2UF2_VERSION="v0.1.0"


function log_success {
Expand Down Expand Up @@ -132,7 +132,8 @@ function ci_cmake_build {
}

if [ -z ${CI_USE_ENV+x} ] || [ -z ${CI_PROJECT_ROOT+x} ] || [ -z ${CI_BUILD_ROOT+x} ]; then
SCRIPT_PATH="$(dirname $0)"
SCRIPT_PATH=${BASH_SOURCE-$0}
SCRIPT_PATH=$(dirname "$SCRIPT_PATH")
CI_PROJECT_ROOT=$(realpath "$SCRIPT_PATH/..")
CI_BUILD_ROOT=$(pwd)
fi
Expand Down
35 changes: 15 additions & 20 deletions ci/python.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
# F = Pyflakes
# Q = Quotes
# E/W = pycodestyle (Whitespace, Line lengths etc)
# B - flake8-bugbear = Unused loop variables, sloppy code
# COM - flake8-commas
# BLE - flake8-blind-except
# C4 - flake8-comprehensions
# ISC - flake8-implicit-str-concat = Implicit string concat, eg: `"hello" "world"` on one line
# ICN - flake8-import-conventions = Import conventions
# PIE - flake8-pie = Misc silliness, catches range with a 0 start argument
# RET - flake8-return = Enforces straight-forward code around return statements
# SLF - flake8-self
# ARG - flake8-unused-arguments

QA_INCLUDE="F,Q,W,E,B,COM,BLE,C4,ISC,ICN,PIE,RSE,RET,SLF,ARG"
QA_IGNORE="E501,E402,COM812"
QA_SCRIPT_PATH=${BASH_SOURCE-$0}
QA_SCRIPT_PATH=$(dirname "$QA_SCRIPT_PATH")
QA_SCRIPT_PATH=$(realpath "$QA_SCRIPT_PATH")

function qa_prepare_all {
pip install ruff
}

function qa_check {
ruff check --config "$QA_SCRIPT_PATH/ruff.toml" "$1"
}

function qa_fix {
ruff check --config "$QA_SCRIPT_PATH/ruff.toml" --fix "$1"
}

function qa_examples_check {
ruff check --select "$QA_INCLUDE" examples/ --ignore "$QA_IGNORE"
qa_check examples/
}

function qa_examples_fix {
ruff check --select "$QA_INCLUDE" examples/ --ignore "$QA_IGNORE" --fix
qa_fix examples/
}

function qa_modules_check {
ruff check --select "$QA_INCLUDE" modules/ --ignore "$QA_IGNORE"
qa_check modules/
}

function qa_modules_fix {
ruff check --select "$QA_INCLUDE" modules/ --ignore "$QA_IGNORE" --fix
qa_fix modules/
}
47 changes: 47 additions & 0 deletions ci/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
builtins = [
]

# Include:
# F = Pyflakes
# Q = Quotes
# E/W = pycodestyle (Whitespace, Line lengths etc)
# B - flake8-bugbear = Unused loop variables, sloppy code
# COM - flake8-commas
# BLE - flake8-blind-except
# C4 - flake8-comprehensions
# ISC - flake8-implicit-str-concat = Implicit string concat, eg: `"hello" "world"` on one line
# ICN - flake8-import-conventions = Import conventions
# PIE - flake8-pie = Misc silliness, catches range with a 0 start argument
# RET - flake8-return = Enforces straight-forward code around return statements
# SLF - flake8-self
# ARG - flake8-unused-arguments

lint.select = [
"F",
"Q",
"W",
"E",
"B",
"COM",
"BLE",
"C4",
"ISC",
"ICN",
"PIE",
"RSE",
"RET",
"SLF",
"ARG"
]

# Ignore:
# E501 - "line too long". How narrow is your screen!?
# E402 - "module level import not at top of file". Needs must!
# COM812 - "Add trailing comma". These are a little obnoxious and weird.
# ICN001 - "numpy should be imported as np". No. No it should not.

lint.ignore = [
"E501",
"E402",
"COM812"
]
74 changes: 35 additions & 39 deletions examples/sparkles.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,38 @@

period = math.pi * EFFECT_SPEED

try:
while True:
t = time.ticks_ms() / 1000 * period
t *= 0.5

for i in range(NUM_LEDS):
led_offset = i / NUM_LEDS
led_offset *= math.pi
led_offset *= 3
led_offset += t

# A sine with a 2x period, shifted to 0 to 254
# This provides a brightness cycling effect phase-locked to the LEDs
br = (math.sin(t / 2 + led_offset) + 1) * 127

# Calculate slightly out of phase sine waves for the red, green and blue channels
r = (math.sin(led_offset + (period * 0.85)) + 1) / 2
g = (math.sin(led_offset + (period * 0.90)) + 1) / 2
b = (math.sin(led_offset + (period * 0.95)) + 1) / 2

# Convert the slow procession of the sine wave into a brief pulse
# by raising it by a power we've called EFFECT_SHARPNESS
# https://www.wolframalpha.com/input?i=plot+pow%28%28sin%28x%29+%2B+1%29+%2F+2.0%2C+10%29%2C+%28sin%28x%29+%2B+1%29+%2F+2.0
r = min(1, max(0, math.pow(r, EFFECT_SHARPNESS)))
g = min(1, max(0, math.pow(g, EFFECT_SHARPNESS)))
b = min(1, max(0, math.pow(b, EFFECT_SHARPNESS)))

# Tune the output colours and apply brightness
# This is a nice greeny teal
r = 0
g = int(g * br)
b = int(g * 0.6)

led_strip.set_rgb(i, g, r, b)

time.sleep(1.0 / EFFECT_FPS)
finally:
led_strip.clear()
led_strip.stop()
while True:
t = time.ticks_ms() / 1000 * period
t *= 0.5

for i in range(NUM_LEDS):
led_offset = i / NUM_LEDS
led_offset *= math.pi
led_offset *= 3
led_offset += t

# A sine with a 2x period, shifted to 0 to 254
# This provides a brightness cycling effect phase-locked to the LEDs
br = (math.sin(t / 2 + led_offset) + 1) * 127

# Calculate slightly out of phase sine waves for the red, green and blue channels
r = (math.sin(led_offset + (period * 0.85)) + 1) / 2
g = (math.sin(led_offset + (period * 0.90)) + 1) / 2
b = (math.sin(led_offset + (period * 0.95)) + 1) / 2

# Convert the slow procession of the sine wave into a brief pulse
# by raising it by a power we've called EFFECT_SHARPNESS
# https://www.wolframalpha.com/input?i=plot+pow%28%28sin%28x%29+%2B+1%29+%2F+2.0%2C+10%29%2C+%28sin%28x%29+%2B+1%29+%2F+2.0
r = min(1, max(0, math.pow(r, EFFECT_SHARPNESS)))
g = min(1, max(0, math.pow(g, EFFECT_SHARPNESS)))
b = min(1, max(0, math.pow(b, EFFECT_SHARPNESS)))

# Tune the output colours and apply brightness
# This is a nice greeny teal
r = 0
g = int(g * br)
b = int(g * 0.6)

led_strip.set_rgb(i, g, r, b)

time.sleep(1.0 / EFFECT_FPS)
18 changes: 15 additions & 3 deletions modules/wireless/ezwifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def __init__(self, **kwargs):

self._verbose = get("verbose", False)

self._spce = get("spce", False)

self._events = {
"connected": get("connected", None),
"failed": get("failed", None),
Expand All @@ -28,7 +30,14 @@ def __init__(self, **kwargs):
"error": get("error", None)
}

self._if = network.WLAN(network.STA_IF)
if self._spce:
# Use the SP/CE pins for this board
wifi_pins = {"pin_on": 8, "pin_out": 11, "pin_in": 11, "pin_wake": 11, "pin_clock": 10, "pin_cs": 9}
else:
# Try to get custom pins from kwargs
wifi_pins = {key: kwargs[key] for key in kwargs if key.startswith("pin_")}

self._if = network.WLAN(network.STA_IF, **wifi_pins)
self._if.active(True)
# self._if.config(pm=0xa11140) # TODO: ???
self._statuses = {v: k[5:] for (k, v) in network.__dict__.items() if k.startswith("STAT_")}
Expand Down Expand Up @@ -120,5 +129,8 @@ def _secrets(self):
raise ImportError("secrets.py: missing or invalid!") from e


def connect(**kwargs):
return asyncio.get_event_loop().run_until_complete(EzWiFi(**kwargs).connect(retries=kwargs.get("retries", 10)))
def connect(*args, **kwargs):
ssid, password = None, None
if len(args) == 2:
ssid, password = args
return asyncio.get_event_loop().run_until_complete(EzWiFi(**kwargs).connect(ssid, password, retries=kwargs.get("retries", 10)))
6 changes: 6 additions & 0 deletions modules/wireless/lte.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, apn, uart=None, reset_pin=None, netlight_pin=None, netlight_l

# Set PPP timeouts and rxbuf
self._uart.init(
baudrate=DEFAULT_UART_STARTUP_BAUD,
timeout=DEFAULT_UART_TIMEOUT,
timeout_char=DEFAULT_UART_TIMEOUT_CHAR,
rxbuf=DEFAULT_UART_RXBUF)
Expand Down Expand Up @@ -80,6 +81,11 @@ def stop_ppp(self):
self._ppp.disconnect()
self._send_at_command(f"AT+IPR={DEFAULT_UART_STARTUP_BAUD}")
self._flush_uart()
self._uart.init(
baudrate=DEFAULT_UART_STARTUP_BAUD,
timeout=DEFAULT_UART_TIMEOUT,
timeout_char=DEFAULT_UART_TIMEOUT_CHAR,
rxbuf=DEFAULT_UART_RXBUF)

def start_ppp(self, baudrate=DEFAULT_UART_BAUD, connect=True):
self._wait_ready(poll_time=1.0, timeout=30)
Expand Down