-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Migrating Ultrasonic into Interactive and hooking up the path node.
- Loading branch information
1 parent
3b39962
commit aa15a40
Showing
10 changed files
with
498 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,82 @@ | ||
# Entry point for a path node. This supports both path nodes that are on either | ||
# side of the path. One will be the primary node and the other the secondary. | ||
import asyncio | ||
|
||
import board | ||
|
||
from interactive.animation import Flicker | ||
from interactive.environment import are_pins_available | ||
from interactive.interactive import Interactive | ||
from interactive.log import set_log_level, info, INFO | ||
from interactive.log import info | ||
from interactive.polyfills.animation import ORANGE, BLACK | ||
from interactive.polyfills.pixel import new_pixels | ||
|
||
PRIMARY = True | ||
BUTTON_PIN = None | ||
BUZZER_PIN = None | ||
BUZZER_VOLUME = 0.1 | ||
SKULL_BRIGHTNESS = 1.0 | ||
SKULL_OFF = 0.0 | ||
SKULL_SPEED = 0.1 | ||
SKULL_COLOUR = ORANGE | ||
SKULL_PINS = [None, None, None, None, None, None] | ||
SKULL_PINS = [board.GP10, board.GP11, board.GP12, board.GP13, board.GP14, board.GP15] | ||
|
||
# Perform import of configuration here to allow for overrides from the config file. | ||
from interactive.configuration import * | ||
|
||
pixels = [new_pixels(pin, 8, brightness=SKULL_BRIGHTNESS) for pin in SKULL_PINS if pin is not None] | ||
animations = [Flicker(pixel, speed=SKULL_SPEED, color=SKULL_COLOUR) for pixel in pixels] | ||
|
||
# Default settings | ||
if are_pins_available(): | ||
# noinspection PyPackageRequirements | ||
import board | ||
|
||
BUTTON_PIN = board.GP27 | ||
BUZZER_PIN = board.GP2 | ||
async def cancel() -> None: | ||
# TODO: This could probable just call stop_display() | ||
for animation in animations: | ||
animation.freeze() | ||
|
||
SKULL_PINS = [board.GP10, board.GP11, board.GP12, board.GP13, board.GP14, board.GP15] | ||
for pixel in pixels: | ||
pixel.fill(BLACK) | ||
pixel.write() | ||
|
||
if __name__ == '__main__': | ||
|
||
set_log_level(INFO) | ||
async def stop_display() -> None: | ||
for pixel in pixels: | ||
pixel.brightness = SKULL_OFF | ||
pixel.show() | ||
|
||
# Try loading local device settings as overrides. | ||
try: | ||
# noinspection PyPackageRequirements | ||
from config import * | ||
|
||
info("Config file loaded") | ||
async def start_display() -> None: | ||
for pixel in pixels: | ||
pixel.brightness = SKULL_BRIGHTNESS | ||
|
||
except ImportError: | ||
info("No config file was found") | ||
t1 = asyncio.create_task(test_task_1()) | ||
t2 = asyncio.create_task(test_task_2()) | ||
|
||
config = Interactive.Config() | ||
config.buzzer_pin = BUZZER_PIN | ||
config.button_pin = BUTTON_PIN | ||
config.buzzer_volume = BUZZER_VOLUME | ||
|
||
interactive = Interactive(config) | ||
async def run_display() -> None: | ||
for animation in animations: | ||
animation.animate() | ||
|
||
# Construct the pixels and animate them. | ||
pixels = [new_pixels(pin, 8, brightness=SKULL_BRIGHTNESS) for pin in SKULL_PINS if pin is not None] | ||
animations = [Flicker(pixel, speed=SKULL_SPEED, color=SKULL_COLOUR) for pixel in pixels] | ||
|
||
async def test_task_1() -> None: | ||
info("Start test task 1") | ||
await asyncio.sleep(2) | ||
for pixel in pixels: | ||
pixel.brightness = SKULL_OFF | ||
pixel.show() | ||
info("End test task 1") | ||
|
||
async def animate_skulls() -> None: | ||
for animation in animations: | ||
animation.animate() | ||
|
||
async def test_task_2() -> None: | ||
info("Start test task 2") | ||
await asyncio.sleep(1) | ||
info("End test task 2") | ||
|
||
interactive.runner.add_loop_task(animate_skulls) | ||
|
||
config = get_node_config() | ||
config.trigger_start = start_display | ||
config.trigger_run = run_display | ||
config.trigger_stop = stop_display | ||
|
||
# TODO: Control how the skulls are enabled/disabled. | ||
interactive = Interactive(config) | ||
|
||
async def callback() -> None: | ||
if interactive.cancel: | ||
for animation in animations: | ||
animation.freeze() | ||
|
||
for pixel in pixels: | ||
pixel.fill(BLACK) | ||
pixel.write() | ||
async def callback() -> None: | ||
if interactive.cancel: | ||
await cancel() | ||
|
||
|
||
interactive.run(callback) | ||
interactive.run(callback) |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# This file is used to setup the default configuration for a typical node. | ||
# Using it removes some boilerplate from the node code. It also sets up | ||
# the logging level. | ||
from interactive.environment import are_pins_available | ||
from interactive.interactive import Interactive | ||
from interactive.log import set_log_level, INFO | ||
|
||
LOG_LEVEL = INFO | ||
|
||
BUTTON_PIN = None | ||
|
||
BUZZER_PIN = None | ||
BUZZER_VOLUME = 0.1 | ||
|
||
ULTRASONIC_TRIGGER_PIN = None | ||
ULTRASONIC_ECHO_PIN = None | ||
|
||
TRIGGER_DISTANCE = 100 | ||
TRIGGER_DURATION = 60 | ||
|
||
if are_pins_available(): | ||
# noinspection PyPackageRequirements | ||
import board | ||
|
||
# Default settings | ||
BUTTON_PIN = board.GP27 | ||
BUZZER_PIN = board.GP2 | ||
ULTRASONIC_TRIGGER_PIN = board.GP7 | ||
ULTRASONIC_ECHO_PIN = board.GP6 | ||
|
||
# Try loading local device settings as overrides. | ||
try: | ||
# noinspection PyPackageRequirements | ||
from config import * | ||
|
||
print("Config file loaded") | ||
|
||
except ImportError: | ||
print("No config file was found") | ||
|
||
set_log_level(LOG_LEVEL) | ||
|
||
|
||
def get_node_config() -> Interactive.Config: | ||
config = Interactive.Config() | ||
config.buzzer_pin = BUZZER_PIN | ||
config.button_pin = BUTTON_PIN | ||
config.buzzer_volume = BUZZER_VOLUME | ||
config.ultrasonic_trigger_pin = ULTRASONIC_TRIGGER_PIN | ||
config.ultrasonic_echo_pin = ULTRASONIC_ECHO_PIN | ||
config.trigger_distance = TRIGGER_DISTANCE | ||
config.trigger_duration = TRIGGER_DURATION | ||
|
||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
TEST_VALUE = 123.456 | ||
|
||
TEST_STRING = "Hello world!" | ||
|
||
TRIGGER_DISTANCE = 99999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from interactive import configuration | ||
|
||
|
||
class TestNode: | ||
def test_config_is_returned(self) -> None: | ||
""" | ||
Tests that configuration defaults are loaded as well as the local overrides | ||
contained in config.py. | ||
""" | ||
config = configuration.get_node_config() | ||
|
||
assert config is not None | ||
assert config.trigger_distance == 99999 | ||
|
||
# These are just random configuration values from the config. | ||
assert configuration.TEST_VALUE == 123.456 | ||
assert configuration.TEST_STRING == "Hello world!" |
Oops, something went wrong.