-
-
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.
Merge pull request #235 from vkottler/dev/controls
Dev/controls
- Loading branch information
Showing
46 changed files
with
656 additions
and
136 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
major: 4 | ||
minor: 6 | ||
patch: 1 | ||
major: 5 | ||
minor: 0 | ||
patch: 0 | ||
entry: runtimepy |
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
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,56 @@ | ||
""" | ||
A module implementing runtime-environment registration routines for commonly | ||
used control channel types. | ||
""" | ||
|
||
# built-in | ||
from typing import TypeVar | ||
|
||
# internal | ||
from runtimepy.channel.environment import ChannelEnvironment | ||
from runtimepy.primitives import AnyPrimitive | ||
from runtimepy.ui.controls import Controlslike | ||
|
||
T = TypeVar("T", bound=AnyPrimitive) | ||
|
||
|
||
def phase_angle( | ||
env: ChannelEnvironment, | ||
primitive: type[T], | ||
name: str = "phase_angle", | ||
controls: Controlslike = "phase", | ||
**kwargs, | ||
) -> T: | ||
"""Create a phase-angle channel.""" | ||
|
||
prim = primitive() | ||
env.channel(name, prim, commandable=True, controls=controls, **kwargs) | ||
return prim # type: ignore | ||
|
||
|
||
def amplitude( | ||
env: ChannelEnvironment, | ||
primitive: type[T], | ||
name: str = "amplitude", | ||
controls: Controlslike = "amplitude", | ||
**kwargs, | ||
) -> T: | ||
"""Create an amplitude channel.""" | ||
|
||
prim = primitive() | ||
env.channel(name, prim, commandable=True, controls=controls, **kwargs) | ||
return prim # type: ignore | ||
|
||
|
||
def steps( | ||
env: ChannelEnvironment, | ||
primitive: type[T], | ||
name: str = "steps", | ||
controls: Controlslike = "steps", | ||
**kwargs, | ||
) -> T: | ||
"""Create a steps channel.""" | ||
|
||
prim = primitive() | ||
env.channel(name, prim, commandable=True, controls=controls, **kwargs) | ||
return prim # type: ignore |
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,68 @@ | ||
""" | ||
A module implementing signal source structs. | ||
""" | ||
|
||
# built-in | ||
from abc import abstractmethod | ||
from typing import Any, Generic, cast | ||
|
||
# internal | ||
from runtimepy.control.env import amplitude | ||
from runtimepy.net.arbiter.info import RuntimeStruct | ||
from runtimepy.primitives import Double, T | ||
|
||
|
||
class PrimitiveSource(RuntimeStruct, Generic[T]): | ||
"""A simple output-source struct.""" | ||
|
||
kind: type[T] | ||
|
||
outputs: list[T] | ||
amplitudes: list[Double] | ||
|
||
length: int | ||
|
||
def init_source(self) -> None: | ||
"""Initialize this value source.""" | ||
|
||
@abstractmethod | ||
def source(self, index: int) -> float | int | bool: | ||
"""Provide the next value.""" | ||
|
||
def init_env(self) -> None: | ||
"""Initialize this double-source environment.""" | ||
|
||
self.outputs = [] | ||
self.amplitudes = [] | ||
|
||
# Load 'count' from config. | ||
count: int = self.config.get("count", 1) # type: ignore | ||
|
||
for idx in range(count): | ||
# Output channel. | ||
output = self.kind() | ||
self.outputs.append(output) | ||
self.env.channel(f"{idx}.output", output) | ||
|
||
# Amplitude channel. | ||
self.amplitudes.append( | ||
amplitude(self.env, Double, name=f"{idx}.amplitude") | ||
) | ||
|
||
self.init_source() | ||
self.length = len(self.outputs) | ||
|
||
def poll(self) -> None: | ||
"""Update the outputs.""" | ||
|
||
for idx in range(self.length): | ||
# Difficult to avoid cast. | ||
self.outputs[idx].value = cast( | ||
Any, self.amplitudes[idx].value * self.source(idx) | ||
) | ||
|
||
|
||
class DoubleSource(PrimitiveSource[Double]): | ||
"""A simple double output source.""" | ||
|
||
kind = Double |
Oops, something went wrong.