Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into moat
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfix committed Oct 2, 2024
2 parents 6d91982 + 394cbfc commit ffcd35a
Show file tree
Hide file tree
Showing 198 changed files with 4,298 additions and 537 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/package_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Package tests

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Setup environment
run: source tools/ci.sh && ci_package_tests_setup_micropython
- name: Setup libraries
run: source tools/ci.sh && ci_package_tests_setup_lib
- name: Run tests
run: source tools/ci.sh && ci_package_tests_run
13 changes: 9 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,20 @@ Pages](https://docs.github.com/en/pages):
"truthy" value).
5. The settings for GitHub Actions and GitHub Pages features should not need to
be changed from the repository defaults, unless you've explicitly disabled
them.
Actions or Pages in your fork.

The next time you push commits to a branch in your fork, GitHub Actions will run
an additional step in the "Build All Packages" workflow named "Publish Packages
for branch".
for branch". This step runs in *your fork*, but if you open a pull request then
this workflow is not shown in the Pull Request's "Checks". These run in the
upstream repository. Navigate to your fork's Actions tab in order to see
the additional "Publish Packages for branch" step.

Anyone can then install these packages as described under [Installing packages
from forks](README.md#installing-packages-from-forks). The exact commands are also
quoted in the GitHub Actions log for the "Publish Packages for branch" step.
from forks](README.md#installing-packages-from-forks).

The exact command is also quoted in the GitHub Actions log in your fork's
Actions for the "Publish Packages for branch" step of "Build All Packages".

#### Opting Back Out

Expand Down
4 changes: 2 additions & 2 deletions micropython/aioespnow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A supplementary module which extends the micropython `espnow` module to provide
`asyncio` support.

- Asyncio support is available on all ESP32 targets as well as those ESP8266
boards which include the `uasyncio` module (ie. ESP8266 devices with at least
boards which include the `asyncio` module (ie. ESP8266 devices with at least
2MB flash storage).

## API reference
Expand Down Expand Up @@ -52,7 +52,7 @@ A small async server example::
```python
import network
import aioespnow
import uasyncio as asyncio
import asyncio

# A WLAN interface must be active to send()/recv()
network.WLAN(network.STA_IF).active(True)
Expand Down
6 changes: 3 additions & 3 deletions micropython/aioespnow/aioespnow.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# aioespnow module for MicroPython on ESP32 and ESP8266
# MIT license; Copyright (c) 2022 Glenn Moloney @glenn20

import uasyncio as asyncio
import asyncio
import espnow


# Modelled on the uasyncio.Stream class (extmod/stream/stream.py)
# NOTE: Relies on internal implementation of uasyncio.core (_io_queue)
# Modelled on the asyncio.Stream class (extmod/asyncio/stream.py)
# NOTE: Relies on internal implementation of asyncio.core (_io_queue)
class AIOESPNow(espnow.ESPNow):
# Read one ESPNow message
async def arecv(self):
Expand Down
2 changes: 1 addition & 1 deletion micropython/aiorepl/aiorepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def execute(code, g, s):
code = "return {}".format(code)

code = """
import uasyncio as asyncio
import asyncio
async def __code():
{}
Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble-central/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata(version="0.2.1")
metadata(version="0.2.2")

require("aioble-core")

Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble-core/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata(version="0.2.0")
metadata(version="0.3.0")

package(
"aioble",
Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble-peripheral/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata(version="0.2.0")
metadata(version="0.2.1")

require("aioble-core")

Expand Down
16 changes: 9 additions & 7 deletions micropython/bluetooth/aioble/aioble/central.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import bluetooth
import struct

import uasyncio as asyncio
import asyncio

from .core import (
ensure_active,
Expand Down Expand Up @@ -195,12 +195,14 @@ def name(self):

# Generator that enumerates the service UUIDs that are advertised.
def services(self):
for u in self._decode_field(_ADV_TYPE_UUID16_INCOMPLETE, _ADV_TYPE_UUID16_COMPLETE):
yield bluetooth.UUID(struct.unpack("<H", u)[0])
for u in self._decode_field(_ADV_TYPE_UUID32_INCOMPLETE, _ADV_TYPE_UUID32_COMPLETE):
yield bluetooth.UUID(struct.unpack("<I", u)[0])
for u in self._decode_field(_ADV_TYPE_UUID128_INCOMPLETE, _ADV_TYPE_UUID128_COMPLETE):
yield bluetooth.UUID(u)
for uuid_len, codes in (
(2, (_ADV_TYPE_UUID16_INCOMPLETE, _ADV_TYPE_UUID16_COMPLETE)),
(4, (_ADV_TYPE_UUID32_INCOMPLETE, _ADV_TYPE_UUID32_COMPLETE)),
(16, (_ADV_TYPE_UUID128_INCOMPLETE, _ADV_TYPE_UUID128_COMPLETE)),
):
for u in self._decode_field(*codes):
for i in range(0, len(u), uuid_len):
yield bluetooth.UUID(u[i : i + uuid_len])

# Generator that returns (manufacturer_id, data) tuples.
def manufacturer(self, filter=None):
Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble/aioble/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from micropython import const
from collections import deque
import uasyncio as asyncio
import asyncio
import struct

import bluetooth
Expand Down
9 changes: 3 additions & 6 deletions micropython/bluetooth/aioble/aioble/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from micropython import const

import uasyncio as asyncio
import asyncio
import binascii

from .core import ble, register_irq_handler, log_error
Expand Down Expand Up @@ -164,7 +164,7 @@ def __init__(self, device):

# This event is fired by the IRQ both for connection and disconnection
# and controls the device_task.
self._event = None
self._event = asyncio.ThreadSafeFlag()

# If we're waiting for a pending MTU exchange.
self._mtu_event = None
Expand Down Expand Up @@ -207,15 +207,12 @@ async def device_task(self):
t._task.cancel()

def _run_task(self):
# Event will be already created this if we initiated connection.
self._event = self._event or asyncio.ThreadSafeFlag()

self._task = asyncio.create_task(self.device_task())

async def disconnect(self, timeout_ms=2000):
await self.disconnected(timeout_ms, disconnect=True)

async def disconnected(self, timeout_ms=60000, disconnect=False):
async def disconnected(self, timeout_ms=None, disconnect=False):
if not self.is_connected():
return

Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble/aioble/l2cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from micropython import const

import uasyncio as asyncio
import asyncio

from .core import ble, log_error, register_irq_handler
from .device import DeviceConnection
Expand Down
17 changes: 8 additions & 9 deletions micropython/bluetooth/aioble/aioble/peripheral.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import bluetooth
import struct

import uasyncio as asyncio
import asyncio

from .core import (
ensure_active,
Expand Down Expand Up @@ -129,14 +129,13 @@ async def advertise(
# Services are prioritised to go in the advertising data because iOS supports
# filtering scan results by service only, so services must come first.
if services:
for uuid in services:
b = bytes(uuid)
if len(b) == 2:
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID16_COMPLETE, b)
elif len(b) == 4:
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID32_COMPLETE, b)
elif len(b) == 16:
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID128_COMPLETE, b)
for uuid_len, code in (
(2, _ADV_TYPE_UUID16_COMPLETE),
(4, _ADV_TYPE_UUID32_COMPLETE),
(16, _ADV_TYPE_UUID128_COMPLETE),
):
if uuids := [bytes(uuid) for uuid in services if len(bytes(uuid)) == uuid_len]:
resp_data = _append(adv_data, resp_data, code, b"".join(uuids))

if name:
resp_data = _append(adv_data, resp_data, _ADV_TYPE_NAME, name)
Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble/aioble/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# MIT license; Copyright (c) 2021 Jim Mussared

from micropython import const, schedule
import uasyncio as asyncio
import asyncio
import binascii
import json

Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble/aioble/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from micropython import const
from collections import deque
import bluetooth
import uasyncio as asyncio
import asyncio

from .core import (
ensure_active,
Expand Down
7 changes: 4 additions & 3 deletions micropython/bluetooth/aioble/examples/l2cap_file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

import sys

# ruff: noqa: E402
sys.path.append("")

from micropython import const

import uasyncio as asyncio
import asyncio
import aioble
import bluetooth

Expand Down Expand Up @@ -85,7 +86,7 @@ async def size(self, path):
async def download(self, path, dest):
size = await self.size(path)

send_seq = await self._command(_COMMAND_SEND, path.encode())
await self._command(_COMMAND_SEND, path.encode())

with open(dest, "wb") as f: # noqa: ASYNC101
total = 0
Expand All @@ -97,7 +98,7 @@ async def download(self, path, dest):
total += n

async def list(self, path):
send_seq = await self._command(_COMMAND_LIST, path.encode())
await self._command(_COMMAND_LIST, path.encode())
results = bytearray()
buf = bytearray(self._channel.our_mtu)
mv = memoryview(buf)
Expand Down
8 changes: 3 additions & 5 deletions micropython/bluetooth/aioble/examples/l2cap_file_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

import sys

# ruff: noqa: E402
sys.path.append("")

from micropython import const

import uasyncio as asyncio
import asyncio
import aioble
import bluetooth

Expand Down Expand Up @@ -132,23 +133,20 @@ async def control_task(connection):
file = msg[2:].decode()

if command == _COMMAND_SEND:
op_seq = seq
send_file = file
l2cap_event.set()
elif command == _COMMAND_RECV:
op_seq = seq
recv_file = file
l2cap_event.set()
elif command == _COMMAND_LIST:
op_seq = seq
list_path = file
l2cap_event.set()
elif command == _COMMAND_SIZE:
try:
stat = os.stat(file)
size = stat[6]
status = 0
except OSError as e:
except OSError:
size = 0
status = _STATUS_NOT_FOUND
control_characteristic.notify(
Expand Down
5 changes: 3 additions & 2 deletions micropython/bluetooth/aioble/examples/temp_client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import sys

# ruff: noqa: E402
sys.path.append("")

from micropython import const

import uasyncio as asyncio
import asyncio
import aioble
import bluetooth

Expand Down Expand Up @@ -54,7 +55,7 @@ async def main():
print("Timeout discovering services/characteristics")
return

while True:
while connection.is_connected():
temp_deg_c = _decode_temperature(await temp_characteristic.read())
print("Temperature: {:.2f}".format(temp_deg_c))
await asyncio.sleep_ms(1000)
Expand Down
7 changes: 4 additions & 3 deletions micropython/bluetooth/aioble/examples/temp_sensor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import sys

# ruff: noqa: E402
sys.path.append("")

from micropython import const

import uasyncio as asyncio
import asyncio
import aioble
import bluetooth

Expand Down Expand Up @@ -39,7 +40,7 @@ def _encode_temperature(temp_deg_c):
async def sensor_task():
t = 24.5
while True:
temp_characteristic.write(_encode_temperature(t))
temp_characteristic.write(_encode_temperature(t), send_update=True)
t += random.uniform(-0.5, 0.5)
await asyncio.sleep_ms(1000)

Expand All @@ -55,7 +56,7 @@ async def peripheral_task():
appearance=_ADV_APPEARANCE_GENERIC_THERMOMETER,
) as connection:
print("Connection from", connection.device)
await connection.disconnected()
await connection.disconnected(timeout_ms=None)


# Run both tasks.
Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# code. This allows (for development purposes) all the files to live in the
# one directory.

metadata(version="0.4.1")
metadata(version="0.5.2")

# Default installation gives you everything. Install the individual
# components (or a combination of them) if you want a more minimal install.
Expand Down
Loading

0 comments on commit ffcd35a

Please sign in to comment.