Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boards #18

Merged
merged 59 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d03dee8
Add test code
danielbloy Aug 27, 2024
c7fbd43
minor update
danielbloy Aug 27, 2024
7fa4d0e
minor update
danielbloy Aug 27, 2024
c3eca2b
Added RAM test results
danielbloy Aug 27, 2024
e8663d2
Add some comments.
danielbloy Aug 28, 2024
a25139a
Add some comments.
danielbloy Aug 28, 2024
25082e3
Add some comments.
danielbloy Aug 28, 2024
f92be3f
Minor work
danielbloy Aug 29, 2024
89731c0
More work.
danielbloy-fs Aug 29, 2024
1fb9b07
Minor work
danielbloy Aug 29, 2024
c954ca5
Minor work
danielbloy Aug 30, 2024
a9316cd
Minor work
danielbloy Sep 2, 2024
7c02357
More work.
danielbloy-fs Sep 2, 2024
af2d0a9
Added some tests.
danielbloy-fs Sep 3, 2024
6eebd16
Added some tests.
danielbloy-fs Sep 3, 2024
997390d
Added some tests.
danielbloy-fs Sep 3, 2024
c140352
Minor work
danielbloy Sep 3, 2024
26c427e
Some initial tests for networking.
danielbloy Sep 5, 2024
ba5397b
Some initial tests for networking.
danielbloy Sep 5, 2024
6bdb777
Minor work
danielbloy-fs Sep 5, 2024
9dde9ba
Some initial tests for networking.
danielbloy Sep 5, 2024
c5223b1
Some initial tests for networking.
danielbloy Sep 5, 2024
7ee16a6
Some initial tests for networking.
danielbloy Sep 6, 2024
865f51f
Some initial tests for networking.
danielbloy Sep 6, 2024
25d9441
Added some tests.
danielbloy-fs Sep 6, 2024
03a457e
Add placeholders for network tests.
danielbloy Sep 9, 2024
7ab1d23
Add placeholders for network tests.
danielbloy Sep 9, 2024
2ee54f2
Add placeholders for network tests.
danielbloy Sep 9, 2024
84d234f
Added some tests.
danielbloy-fs Sep 9, 2024
25ad4cf
Added some tests.
danielbloy-fs Sep 9, 2024
1343097
Added some tests.
danielbloy-fs Sep 9, 2024
6259553
Add placeholders for network tests.
danielbloy Sep 9, 2024
66ccc15
Add placeholders for network tests.
danielbloy Sep 9, 2024
ee39b53
Add placeholders for network tests.
danielbloy Sep 9, 2024
ec5c7a7
Add placeholders for network tests.
danielbloy Sep 9, 2024
204d2cf
Added some tests.
danielbloy-fs Sep 10, 2024
6d317ce
Added some tests.
danielbloy-fs Sep 10, 2024
0be6506
Added some tests.
danielbloy-fs Sep 10, 2024
02d7bde
Added some tests.
danielbloy-fs Sep 10, 2024
a1f5c83
Added some tests.
danielbloy-fs Sep 10, 2024
e83e50f
Added some tests.
danielbloy-fs Sep 10, 2024
52b9c06
Add placeholders for network tests.
danielbloy Sep 11, 2024
194c509
Add placeholders for network tests.
danielbloy Sep 11, 2024
341a0e5
Added some tests.
danielbloy-fs Sep 11, 2024
58c515e
A bit of a rearrangement.
danielbloy Sep 11, 2024
d519f74
A bit of a rearrangement.
danielbloy Sep 11, 2024
91edbef
Minor update
danielbloy Sep 11, 2024
8d24d0a
Fixup broken test.
danielbloy Sep 11, 2024
438d471
Fixed more issues.
danielbloy Sep 11, 2024
8105a47
Fixed more issues.
danielbloy Sep 12, 2024
ac88d59
Fixed more issues.
danielbloy Sep 12, 2024
e975685
Fixed more issues.
danielbloy Sep 12, 2024
67f2f2e
Fixed more issues.
danielbloy Sep 12, 2024
af4f47a
Added some tests.
danielbloy-fs Sep 12, 2024
e399900
Added some tests.
danielbloy-fs Sep 12, 2024
6f7cb9c
Fixed more issues.
danielbloy Sep 12, 2024
3abd04d
Fixed more issues.
danielbloy Sep 12, 2024
86c2c81
Fixed more issues.
danielbloy Sep 12, 2024
110d3b7
Fixed more issues.
danielbloy Sep 12, 2024
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion circuitpython/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

This directory contains a copy of all the CircuitPython images and libraries that
this project is tested against and supports. Currently, the project is being built
against CircuitPython 9.0.5.
against:

* CircuitPython 9.0.5 - confirmed
* CircuitPython 9.1.2 - testing in progress

The CircuitPython libraries that are required for the project have been extracted
out into the `lib` directory for easy access.
Expand Down
90 changes: 90 additions & 0 deletions halloween/2024/boards/single/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Test code for the single microcontroller board. Tests:
# * Button - triggers sound when pressed
# * Ultrasonic sensor - triggers sound when detects
# * Audio - plays lion.mp3

import time

from interactive.audio import AudioController
from interactive.button import ButtonController
from interactive.environment import are_pins_available
from interactive.log import set_log_level, INFO, info
from interactive.memory import report_memory_usage_and_free
from interactive.polyfills.audio import new_mp3_player
from interactive.polyfills.button import new_button
from interactive.polyfills.ultrasonic import new_ultrasonic
from interactive.runner import Runner
from interactive.ultrasonic import UltrasonicController

REPORT_RAM = are_pins_available()

BUTTON_PIN = None

AUDIO_PIN = None
AUDIO_FILE = "lion.mp3"

ULTRASONIC_TRIGGER_PIN = None
ULTRASONIC_ECHO_PIN = None

if are_pins_available():
# noinspection PyPackageRequirements
import board

BUTTON_PIN = board.GP26

ULTRASONIC_TRIGGER_PIN = board.GP16
ULTRASONIC_ECHO_PIN = board.GP17

AUDIO_PIN = board.GP22

if __name__ == '__main__':

set_log_level(INFO)

if REPORT_RAM:
report_memory_usage_and_free("Before creating Objects")

runner = Runner()

ultrasonic = new_ultrasonic(ULTRASONIC_TRIGGER_PIN, ULTRASONIC_ECHO_PIN)


async def trigger_handler(distance: float, actual: float) -> None:
info(f"Distance {distance} handler triggered: {actual}")
audio_controller.queue(AUDIO_FILE)


controller = UltrasonicController(ultrasonic)
controller.add_trigger(100, trigger_handler, 5)
controller.register(runner)


async def single_click_handler() -> None:
info(f"Distance: {ultrasonic.distance}")
audio_controller.queue(AUDIO_FILE)


button = new_button(BUTTON_PIN)
button_controller = ButtonController(button)
button_controller.add_single_click_handler(single_click_handler)
button_controller.register(runner)

audio = new_mp3_player(AUDIO_PIN, AUDIO_FILE)
audio_controller = AudioController(audio)
audio_controller.register(runner)

# Allow the application to only run for a defined number of seconds.
finish = time.monotonic() + 1200


async def callback() -> None:
runner.cancel = time.monotonic() > finish


if REPORT_RAM:
report_memory_usage_and_free("Before running Runner")

runner.run(callback)

if REPORT_RAM:
report_memory_usage_and_free("After running Runner")
2 changes: 2 additions & 0 deletions interactive/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class AudioController:
played through the Audio instance. Basic controls to pause, resume and
stop are provided along with a cancel option which stops the music and
clears the queue.

Instances of this class will need to register() with a Runner in order to work.
"""

def __init__(self, audio: Audio):
Expand Down
10 changes: 9 additions & 1 deletion interactive/buzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@


class BuzzerController:
"""
BuzzerController provides a trivial method to play tones through a simple buzzer;
such as a little piezo buzzer. BuzzerController works well with simply melodies
that can be provided with the Melody and MelodySequence classes. For more complex
audio through mp3 files, use the AudioController class.

Instances of this class will need to register() with a Runner in order to work.
"""

def __init__(self, buzzer: Buzzer):
if buzzer is None:
Expand Down Expand Up @@ -60,7 +68,7 @@ def __off(self) -> None:

def register(self, runner: Runner) -> None:
"""
Registers this Buzzercontroller instance as a task with the provided Runner.
Registers this BuzzerController instance as a task with the provided Runner.

:param runner: the runner to register with.
"""
Expand Down
19 changes: 18 additions & 1 deletion interactive/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
from interactive.log import set_log_level, INFO, log
from interactive.memory import report_memory_usage

FIELD_NAME = "name"
FIELD_ROLE = "role"
FIELD_COORDINATOR = "coordinator"

NODE_NAME = "<hostname>"
NODE_ROLE = "<host role>"
NODE_COORDINATOR = None # The I.P. Address of the coordinator node.

REPORT_RAM = False
REPORT_RAM_PERIOD = 5 # This is the period in seconds between each report.
Expand Down Expand Up @@ -57,7 +62,7 @@
class Config:
"""
Holds the configuration settings required for constructing an instance of
Interactive.
Interactive. It's here to avoid circular dependencies.
"""

def __init__(self):
Expand Down Expand Up @@ -141,3 +146,15 @@ def get_node_config(network=False, button=True, buzzer=True, audio=True, ultraso
config.trigger_duration = TRIGGER_DURATION

return config


def details() -> dict:
"""
Returns details of the node. This will include its name, role and coordinator
values. These are essentially the items not returned in the configuration.
"""
return {
FIELD_NAME: NODE_NAME,
FIELD_ROLE: NODE_ROLE,
FIELD_COORDINATOR: NODE_COORDINATOR
}
9 changes: 8 additions & 1 deletion interactive/control.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file contains common control values that are "hard-coded" and not expected
# to be changed by configuration.
# to be changed by configuration. The frequency values here are the number of times
# per second that is required.

NS_PER_SECOND = 1_000_000_000

Expand All @@ -19,3 +20,9 @@
BUTTON_SHORT_DURATION_MS = 200
# The timeframe to consider a button being pressed should register as a long press.
BUTTON_LONG_DURATION_MS = 2000

# * * * * * N E T W O R K * * * * *
NETWORK_PORT_MICROCONTROLLER = 80
NETWORK_PORT_DESKTOP = 5001
NETWORK_HOST_DESKTOP = "127.0.0.1"
NETWORK_HEARTBEAT_FREQUENCY = 1 / 60 # every 60 seconds.
Empty file removed interactive/display.py
Empty file.
Loading
Loading