-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start on plans for controlling backlight
- Loading branch information
1 parent
09986db
commit 29838e6
Showing
3 changed files
with
95 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import bluesky.plan_stubs as bps | ||
from bluesky.utils import MsgGenerator | ||
from ophyd_async.fastcs.panda import HDFPanda | ||
|
||
|
||
def set_backlight_intensity( | ||
panda: HDFPanda, | ||
intensity: float, | ||
wait: bool = True, | ||
group: str | None = None, | ||
) -> MsgGenerator[None]: | ||
if 0.0 <= intensity <= 1.0: | ||
duty_cycle = int(round(intensity * 100.0)) | ||
if duty_cycle == 0: | ||
port = "ZERO" | ||
elif duty_cycle == 100: | ||
port = "ONE" | ||
else: | ||
port = yield from create_pwm(panda, duty_cycle, wait, group) | ||
|
||
yield from set_backlight_control_port(panda, port, wait, group) | ||
else: | ||
raise ValueError(f"Given intensity {intensity} should be between 0.0 and 1.0") | ||
|
||
|
||
def set_backlight_control_port( | ||
panda: HDFPanda, | ||
port: str, | ||
wait: bool = True, | ||
group: str | None = None, | ||
) -> MsgGenerator[None]: | ||
ttl_out_2 = panda.ttlout[2] | ||
yield from bps.abs_set( | ||
ttl_out_2.val, | ||
port, | ||
wait=wait, | ||
group=group, | ||
) | ||
|
||
|
||
def create_pwm( | ||
panda: HDFPanda, | ||
duty_cycle: int, | ||
wait: bool = True, | ||
group: str | None = None, | ||
) -> MsgGenerator[str]: | ||
return NotImplemented | ||
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,44 @@ | ||
import pytest | ||
from bluesky import RunEngine | ||
from dodal.beamlines import training_rig as training_rig | ||
from ophyd_async.core import ( | ||
Device, | ||
DeviceVector, | ||
) | ||
from ophyd_async.epics.core import epics_signal_rw | ||
from ophyd_async.fastcs.panda import HDFPanda | ||
from ophyd_async.plan_stubs import ensure_connected | ||
|
||
from htss_rig_bluesky.plans.backlight import ( | ||
set_backlight_control_port, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def run_engine() -> RunEngine: | ||
return RunEngine() | ||
|
||
|
||
@pytest.fixture | ||
async def mock_panda( | ||
run_engine: RunEngine, | ||
): | ||
class TtlOutBlock(Device): | ||
def __init__(self, name: str = ""): | ||
self.val = epics_signal_rw(str, "VAL") | ||
super().__init__(name) | ||
|
||
mock_panda = training_rig.panda() | ||
mock_panda.phase_1_signal_units = epics_signal_rw(int, "") | ||
mock_panda.ttlout = DeviceVector({i: TtlOutBlock() for i in range(1, 5)}) | ||
|
||
run_engine(ensure_connected(mock_panda, mock=True)) | ||
yield mock_panda | ||
|
||
|
||
async def test_set_control_port_sets_control_port( | ||
run_engine: RunEngine, mock_panda: HDFPanda | ||
): | ||
assert (await mock_panda.ttlout[2].val.get_value()) == "" | ||
run_engine(set_backlight_control_port(mock_panda, "FOO"), wait=True) | ||
assert (await mock_panda.ttlout[2].val.get_value()) == "FOO" |