Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-24fa
project03
Commits
34cdd0b3
Commit
34cdd0b3
authored
6 months ago
by
Philippe des Boscs
Browse files
Options
Download
Email Patches
Plain Diff
update docstrings
parent
b4892e62
master
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
code.py
+14
-25
code.py
src/interact.py
+8
-0
src/interact.py
src/morse_code.py
+22
-5
src/morse_code.py
src/morse_engine.py
+23
-9
src/morse_engine.py
src/prox_pulse.py
+15
-3
src/prox_pulse.py
src/pulse.py
+14
-3
src/pulse.py
with
96 additions
and
45 deletions
+96
-45
code.py
View file @
34cdd0b3
try
:
import
board
import
neopixel
from
adafruit_apds9960.apds9960
import
APDS9960
import
touchio
from
src.interact
import
run
import
board
import
neopixel
from
adafruit_apds9960.apds9960
import
APDS9960
import
touchio
# Setup board
i2c
=
board
.
I2C
()
apds
=
APDS9960
(
i2c
)
pixels
=
neopixel
.
NeoPixel
(
board
.
NEOPIXEL
,
2
)
touch
=
touchio
.
TouchIn
(
board
.
TOUCH2
)
apds
.
enable_proximity
=
True
print
(
"Loaded Trinkey..."
)
from
src.interact
import
run
# Try/except is unnecessary in this case, but when code is controlling physical systems
# it is good practice to catch all exceptions and handle shutdown gracefully
try
:
# Run engine
run
(
pixels
,
adps
,
touch
)
except
Exception
as
e
:
pixels
.
fill
((
0
,
0
,
0
))
print
(
"Exception has occurred! Shutting down..."
)
raise
(
e
)
# Setup board
i2c
=
board
.
I2C
()
apds
=
APDS9960
(
i2c
)
pixels
=
neopixel
.
NeoPixel
(
board
.
NEOPIXEL
,
2
)
touch
=
touchio
.
TouchIn
(
board
.
TOUCH2
)
apds
.
enable_proximity
=
True
print
(
"Loaded Trinkey..."
)
# Outer try/except clause so code can be tested outside the Trinkey.
except
ModuleNotFoundError
:
pass
# Call our run function
run
(
apds
,
pixels
,
touch
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/interact.py
View file @
34cdd0b3
...
...
@@ -4,6 +4,14 @@ from .morse_engine import run_morse_engine
def
run
(
apds
,
pixels
,
touch
):
"""
Runs the selected demo on the Trinkey.
Args:
apds: proximity sensor.
pixels: LED controller object.
touch: touch sensor.
"""
run_simple_pulse
(
pixels
)
# run_prox_pulse(apds, pixels)
# run_morse_engine(apds, pixels, touch)
This diff is collapsed.
Click to expand it.
src/morse_code.py
View file @
34cdd0b3
...
...
@@ -3,18 +3,35 @@ from .symbols import MORSE_SYMBOL_TO_LETTER, InvalidSymbolError
def
translate_complete_morse_symbol
(
message
,
symbol
):
"""
Decodes a character according to a modified international morse code standard.
Decodes a Morse code symbol and appends the corresponding character to the
message.
Raises an InvalidSymbolError if the morse symbol is not found.
Args:
message (str): current message string being built.
symbol (str): morse code symbol to be translated
(e.g., ".-", ".----", "del").
Returns:
str: The updated message with the translated symbol appended, or with
the last character removed if the symbol is "del".
Raises:
InvalidSymbolError: If the symbol is not a valid Morse code character.
"""
raise
InvalidSymbolError
()
def
translate_message
(
morse
):
"""
Decodes a message from modified morse code to English.
Translates a Morse code message into an English string.
Args:
morse (str): A series of Morse code symbols separated by "/". Each
symbol can represent a letter, number, or space.
Spaces signify the end of a character. The "del" character deletes the
previous character in the message.
Returns:
str: The translated English message. If any invalid symbols are
encountered, they are ignored. If the last potential symbol is not
valid, it is appended as is (i.e., as dots and dashes).
"""
return
None
This diff is collapsed.
Click to expand it.
src/morse_engine.py
View file @
34cdd0b3
...
...
@@ -16,25 +16,39 @@ GREEN = (0, 255, 0)
def
set_color
(
elapsed_t
,
px
):
"""Lights the LEDs on the trinkey depending on length of input.
The LED should be lit red (255, 0, 0) if the input is shorter than UNIT_TIME.
The LED should be lit yellow (220, 160, 0) if the input is between 1 and 3 times UNIT_TIME.
The LED should be lit green (0, 255, 0) if the input is longer than 3 times UNIT_TIME.
"""
Lights the LEDs on the trinkey depending on the length of input.
Args:
elapsed_t (float): duration of proximity detection.
px : LED controller object.
"""
pass
def
add_mark
(
elapsed_t
):
"""Determines if input is a dot (.) or dash (-) depending on length of input.
Returns an empty string if the input is less than UNIT_TIME.
Returns a dot if the input is between 1 and 3 times UNIT_TIME.
Returns a dash if the input is greater than 3 times UNIT_TIME.
"""
Determines if input is a dot (.), dash (-), or nothing ("") based
on the length of input.
Args:
elapsed_t (float): duration of proximity detection.
Returns:
str: dot (.), dash (-), or empty ("").
"""
pass
def
run_morse_engine
(
apds
,
pixels
,
touch
):
"""A Tests Demo on Trinkey"""
"""
Runs Morse code translation based on proximity input.
Args:
apds: proximity sensor.
pixels: LED controller object.
touch: touch sensor for confirming input.
"""
down
=
None
# Time when proximity sensor was first triggered
elapsed
=
0
# Duration proximity sensor has been triggered
message
=
""
# Translated part of message
...
...
This diff is collapsed.
Click to expand it.
src/prox_pulse.py
View file @
34cdd0b3
...
...
@@ -8,13 +8,25 @@ GREEN = (30, 100, 10)
def
prox_pulse
(
px
,
color
,
prox
):
"""Map the THRESHOLD-255 proximity value to 1000-50 ms pulse
duration and call pulse."""
"""
Maps proximity value to pulse duration and calls pulse.
Args:
px: LED controller object.
color (tuple): color to pulse.
prox (int): proximity value.
"""
pass
# Delete this line when you start coding!
def
run_prox_pulse
(
apds
,
pixels
):
"""C Tests Demo on Trinkey"""
"""
Runs proximity-based pulsing demo.
Args:
apds: proximity sensor.
pixels: LED controller object.
"""
# Main loop
while
True
:
print
(
apds
.
proximity
)
This diff is collapsed.
Click to expand it.
src/pulse.py
View file @
34cdd0b3
...
...
@@ -6,13 +6,24 @@ TIME = 1
def
pulse
(
px
,
color
,
duration
):
"""Fills the pixels with the given color for a duration, then turns them off
for that duration."""
"""
Fills pixels with a color for a duration, then turns them off.
Args:
px (): LED controller object.
color (tuple): Color to display.
duration (float): time in seconds to keep the color on/off.
"""
pass
# Delete this line when you start coding!
def
run_simple_pulse
(
pixels
):
"""D Tests Demo on Trinkey."""
"""
Runs a simple pulse demo.
Args:
pixels: LED controller object.
"""
# Main loop
while
True
:
pulse
(
pixels
,
BLUE
,
TIME
)
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help