Skip to content
Snippets Groups Projects
Commit e5407fad authored by whuie2's avatar whuie2
Browse files

function arg adjustments; add Computer.rerun and Sequence.from_digital1_data

parent 430095a2
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,8 @@ class SuperSequence:
"""
def __init__(self, outdir: pathlib.Path, name: str,
sequences: dict[str, Sequence]=None, defaults: ConnectionLayout=None):
sequences: dict[str, Sequence]=None,
defaults: ConnectionLayout=None):
"""
Constructor.
......@@ -62,7 +63,7 @@ class SuperSequence:
assert isinstance(seq, Sequence)
self.sequences[key] = seq
def get(self, key, default) -> Sequence:
def get(self, key, default=None) -> Sequence:
return self.sequences.get(key, default)
def keys(self):
......@@ -216,7 +217,7 @@ class SuperSequence:
# set up background lines and histories on each connection
# each history is a list of matplotlib line objects for each sequence
conn_history = dict()
for k, (conn_label, conn) in enumerate(_connections):
for k, (conn_label, conn) in enumerate(reversed(_connections)):
if isinstance(conn, DigitalConnection):
P.ax.axhline(
hk * k + 1, color="0.85", linestyle="-", linewidth=0.4,
......@@ -260,7 +261,7 @@ class SuperSequence:
t0 = seq.min_time()
P.ax.axvline(
t0, color="k", linestyle="--", linewidth=0.4, zorder=102)
for k, (conn_label, conn) in enumerate(_connections):
for k, (conn_label, conn) in enumerate(reversed(_connections)):
ts = seq._get_states(**conn)
if len(ts) > 0:
_t = [conn_history[conn][-1].get_xdata()[-1]]
......
......@@ -374,9 +374,35 @@ class Sequence:
board=board,
connector=connector,
mask=mask,
state=S[i],
time=T[i]
) for i in range(len(T))
state=s,
time=t
) for t, s in zip(T, S)
])
@staticmethod
def from_digital1_data(T: list[float], S: list[int], board: int,
connector: int, channel: int) -> Sequence:
"""
Construct a Sequence of digital events on `board`, `connector`,
`channel` from lists of times and states.
Parameters
----------
T : list[float]
S : list[int]
board : int
connector : int
channel : int
"""
assert len(T) == len(S)
return Sequence([
Event(EventType.Digital,
board=board,
connector=connector,
mask=1 << channel,
state=int(bool(s)) << channel,
time=t
) for t, s in zip(T, S)
])
@staticmethod
......@@ -401,9 +427,9 @@ class Sequence:
Event(EventType.Analog,
board=board,
channel=channel,
state=V[i],
time=T[i]
) for i in range(len(T))
state=v,
time=t
) for t, v in zip(T, V)
])
def to_primitives(self) -> dict[str, ...]:
......@@ -557,8 +583,8 @@ class Sequence:
return seq
@staticmethod
def analog_ramp_lin(channel: int, V0: float, V1: float, t0: float,
t1: float) -> Sequence:
def analog_ramp_lin(channel: int, t0: float, t1: float, V0: float,
V1: float) -> Sequence:
"""
Construct a Sequence of events for a linear analog ramp beginning at
(t0, V0) and ending at (t1, V1) on the specified channel at maximum
......@@ -578,8 +604,8 @@ class Sequence:
*ewm.linear_ramp(V0, V1, t0, t1), 0, channel)
@staticmethod
def analog_ramp_exp(channel: int, V0: float, V1: float, t0: float,
t1: float, rate: float) -> Sequence:
def analog_ramp_exp(channel: int, t0: float, t1: float, V0: float,
V1: float, rate: float) -> Sequence:
"""
Construct a Sequence of events for an exponential ramp beginning at
(t0, V0) and ending at (t1, V1) on the specified channel at maximum
......@@ -600,8 +626,8 @@ class Sequence:
*ewm.exponential_ramp(V0, V1, t0, t1, rate), 0, channel)
@staticmethod
def analog_sin(channel: int, amp: float, dc: float, freq: float,
phase: float, t0: float, t1: float) -> Sequence:
def analog_sin(channel: int, t0: float, t1: float, amp: float, dc: float,
freq: float, phase: float) -> Sequence:
"""
Construct a Sequence of events for a a sine wave beginning at `t0` and
ending at `t1` with amplitude `amp`, DC offset `dc`, frequency `freq`,
......@@ -621,8 +647,8 @@ class Sequence:
*ewm.sin(amp, dc, freq, phase, t0, t1), 0, channel)
@staticmethod
def analog_cos(channel: int, amp: float, dc: float, freq: float,
phase: float, t0: float, t1: float) -> Sequence:
def analog_cos(channel: int, t0: float, t1: float, amp: float, dc: float,
freq: float, phase: float) -> Sequence:
"""
Construct a Sequence of events for a a sine wave beginning at `t0` and
ending at `t1` with amplitude `amp`, DC offset `dc`, frequency `freq`,
......@@ -1055,6 +1081,14 @@ class Computer:
ew.run_sequence()
return self
def rerun(self):
"""
Re-run the last-loaded sequence.
"""
assert self._connected, "Must be connected"
ew.rerun_last_sequence()
return self
def stop(self):
"""
Halt execution of the current sequence.
......@@ -1093,18 +1127,18 @@ def ch(*ch_nums: int, num_channels: int=32) -> int:
return acc
# set_digital_state(
# seqtime: f64, // time of state change
# board: u8, // board number, only have one
# connector: u8, // connector on board, 0-3
# channel_mask: u32, // bitmask for channels to be changed
# output_enable_state: u32, // bitmask for which channels drive their outputs
# output_state: u32 // state of channels
# seqtime: f64, // time of state change
# board: u8, // board number, only have one
# connector: u8, // connector on board, 0-3
# channel_mask: u32, // bitmask for channels to be changed
# output_enable_state: u32, // bitmask for which channels drive their outputs
# output_state: u32 // state of channels
# )
# set_analog_state(
# seqtime: f64, // time of state change
# board: u8, // board number, only have one
# channel: u8, // 0-31
# value: f42 // -10 - +10
# seqtime: f64, // time of state change
# board: u8, // board number, only have one
# channel: u8, // 0-31
# value: f42 // [-10, +10]
# )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment