Skip to content

Commit

Permalink
Restructured lib directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Nov 8, 2023
1 parent 3664565 commit d963802
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/modules/dual_motor/single_stepper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pimoroni_yukon import Yukon
from pimoroni_yukon import SLOT1 as SLOT
from pimoroni_yukon.modules import DualMotorModule
from pimoroni_yukon.extras.stepper import OkayStepper
from pimoroni_yukon.devices.stepper import OkayStepper

"""
Drive a stepper motor from a Dual Motor Module connected to Slot1.
Expand Down
3 changes: 1 addition & 2 deletions firmware/PIMORONI_YUKON/uf2-manifest.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
../*.py
../lib/*.py
../lib/pimoroni_yukon/*.py
../lib/pimoroni_yukon/extras/*.py
../lib/pimoroni_yukon/devices/*.py
../lib/pimoroni_yukon/modules/*.py
../lib/pimoroni_yukon/protocols/*.py
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
import pimoroni_yukon.logging as logging
from ucollections import namedtuple

"""
Classes and functions for controlling LewanSoul/HiWonder
LX servos (tested on LX-16A and LX-224HV) via Yukon's
Serial Bus Servo module.
"""


Command = namedtuple("Command", ("value", "length"))

# LX Servo Protocol
Expand Down Expand Up @@ -69,7 +76,7 @@ def checksum(buffer):
def send(id, uart, duplexer, command, fmt="", *data):
# Create a buffer of the correct length
buffer = bytearray(FRAME_HEADER_LENGTH + command.length)

# Populate the buffer with the required header values and command data
struct.pack_into("<BBBBB" + fmt + "B", buffer, 0, # fmt, buffer, offset
FRAME_HEADER,
Expand Down Expand Up @@ -119,7 +126,7 @@ def handle_receive(uart):
# Only look for header bytes
if rx_byte == FRAME_HEADER:
header_count += 1

# Have to header bytes been received?
if header_count == 2:
header_count = 0
Expand All @@ -133,7 +140,7 @@ def handle_receive(uart):
# Are we inside the frame?
if frame_started:
rx_buffer[data_count] = rx_byte # Add the byte to the buffer

# Extract the frame length from the data, exiting if it contradicts
if data_count == 3:
data_length = rx_buffer[data_count]
Expand All @@ -142,7 +149,7 @@ def handle_receive(uart):
frame_started = False

data_count += 1

# Have we reached the expected end of the received data?
if data_count == data_length + 3:
# Does the checksum we calculate match what was received?
Expand All @@ -167,20 +174,20 @@ def receive(id, uart, duplexer, timeout, fmt=""):
# Wait for data to start coming in
while uart.any() == 0:
remaining_ms = ticks_diff(end_ms, ticks_ms())

# Has the timeout been reached?
if remaining_ms <= 0:
duplexer.send_on_data() # Switch back to send mode before throwing the error
raise TimeoutError(f"Serial servo #{id} did not reply within the expected time")

# Handle the received data
data_buffer = handle_receive(uart)

# Was valid data received?
data = None
if data_buffer is not None:
data = struct.unpack("<" + fmt, data_buffer)

# If there is only one piece of data expected, extract it
if len(fmt) == 1:
data = data[0]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/pimoroni_yukon/modules/audio_amp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ucollections import OrderedDict
from .common import YukonModule, ADC_FLOAT, IO_LOW, IO_HIGH
from pimoroni_yukon.errors import OverTemperatureError
from pimoroni_yukon.extras.player import WavPlayer
from pimoroni_yukon.devices.audio import WavPlayer

# PAGE 0 Regs
PAGE = 0x00 # Device Page Section 8.9.5
Expand Down

0 comments on commit d963802

Please sign in to comment.