scaleKeep a percentage of a native input

fn scale(&self, target: impl Into<LockTarget>, direction: Direction, scale: i16) -> Result<()>

Fire-and-forget

ParameterTypeDescription
targetimpl Into<LockTarget>An Axis (X, Y, wheel, or pan) or any Usage (button, key, or media).
directionDirectionA fixed sign or edge, or With / Against relative to the bearing. A relative direction on anything but an axis returns Error::RelativeDirection. Media has no edges, so an edge on it is sent as Both.
scalei16Percent of the native value kept. LOCK_SCALE_BLOCK (0) blocks and LOCK_SCALE_PASS (100) passes untouched. Above 100 amplifies, up to LOCK_SCALE_MAX (255). Below 0 reverses, down to LOCK_SCALE_MIN (-255). Outside that range returns Error::LockScaleRange.

A delta is weighed by one fixed-direction scale times one relative scale, so a block in either zeroes it. With and Against need a live bearing (set_bearing). A momentary usage is one bit: any scale <100 locks it, and a negative returns Error::LockScaleUsage.

The delta's sign before weighing picks which direction's scale applies: Positive at -100 turns rightward motion leftward and leaves leftward motion alone.

Direction::Both writes the scale to the two fixed signs and a full pass to the relative pair, so Both of 50 means 50% whether or not a bearing is live.

EXAMPLE
use medius::{Device, Axis, Direction};

let device = Device::find()?;
device.scale(Axis::X, Direction::Against, 40)?;  // 40% of native motion opposing the injection
device.scale(Axis::X, Direction::With, 130)?;    // 130% of it along the injection
device.scale(Axis::Y, Direction::Negative, 60)?; // 60% of upward motion, always
device.scale(Axis::Y, Direction::Both, -100)?;   // Y inverted

lockBlock a native input

fn lock(&self, target: impl Into<LockTarget>, direction: Direction) -> Result<()>

Fire-and-forget

scale at LOCK_SCALE_BLOCK. On a usage, Positive and Negative are also spelled Direction::PRESS and Direction::RELEASE.

ParameterTypeDescription
targetimpl Into<LockTarget>An Axis (X, Y, wheel, or pan) or any Usage (button, key, or media).
directionDirectionWhich sign or edge to block. An axis also takes the bearing-relative With / Against.

A lock holds until unlock, control-PC silence, reset, inter-chip link loss, or the real device detaching. The wire layout is on the native LOCK command.

EXAMPLE
use medius::{Device, Axis, Button, Key, MediaKey, Direction};

let device = Device::find()?;
device.lock(Axis::X, Direction::Both)?;           // block horizontal motion
device.lock(Button::LEFT, Direction::Positive)?;  // block left-click press
device.lock(Key::LEFT_GUI, Direction::Both)?;     // block the GUI/Windows key
device.lock(MediaKey::PLAY_PAUSE, Direction::Both)?; // media has no edges
device.move_rel(50, 0)?;                          // injection still moves X

unlockClear a block

fn unlock(&self, target: impl Into<LockTarget>, direction: Direction) -> Result<()>

Fire-and-forget

scale at LOCK_SCALE_PASS for the same target and direction. Direction::Both clears every direction of the target, the bearing-relative pair included.

EXAMPLE
use medius::{Device, Axis, Direction};

let device = Device::find()?;
device.unlock(Axis::X, Direction::Both)?;   // X passes untouched again

lock_axis / unlock_axis / scale_axisWeigh a relative axis by sign

fn lock_axis(&self, axis: Axis, direction: Direction) -> Result<()>
fn unlock_axis(&self, axis: Axis, direction: Direction) -> Result<()>
fn scale_axis(&self, axis: Axis, direction: Direction, scale: i16) -> Result<()>

Fire-and-forget

lock / unlock / scale for an Axis, with a sign as the direction.

EXAMPLE
use medius::{Device, Axis, Direction};

let device = Device::find()?;
device.lock_axis(Axis::Wheel, Direction::Positive)?; // block scroll up, keep scroll down
device.unlock_axis(Axis::Wheel, Direction::Positive)?;

lock_all / unlock_all / scale_allWeigh a whole class at once

fn lock_all(&self, what: Blanket, direction: Direction) -> Result<()>
fn unlock_all(&self, what: Blanket, direction: Direction) -> Result<()>
fn scale_all(&self, what: Blanket, direction: Direction, scale: i16) -> Result<()>

Fire-and-forget

A Blanket weighs a whole input group. direction applies to every member as it would to one. Keys takes an edge; Media has no edges, so it sends Both.

Blanket::Aim addresses X and Y together in BearingMode::Vector, which reads X and Y as one vector.

EXAMPLE
use medius::{Device, Blanket, Direction};

let device = Device::find()?;
device.lock_all(Blanket::Keys, Direction::Both)?;        // every key, both edges
device.lock_all(Blanket::Keys, Direction::Positive)?;    // press edges only: a held key still releases
device.unlock_all(Blanket::Keys, Direction::Both)?;
device.scale_all(Blanket::Aim, Direction::Against, 40)?; // 40% of motion opposing the injection, X and Y

On AsyncDevicelocks fire, query_locks awaits

AsyncDevice keeps every lock call synchronous, with no reply to await: scale, lock/unlock, scale_axis, and scale_all with their lock and unlock pairs. query_locks is a future.

EXAMPLE
use futures::executor::block_on;
use medius::{AsyncDevice, Axis, Direction};

let device = AsyncDevice::open("/dev/ttyACM0")?;
device.lock(Axis::Y, Direction::Both)?;       // sync, no await
let locks = block_on(device.query_locks())?;  // query awaits