protected virtual void RegisterShortcuts(IShortcutManager s) { #region AutoConnectEnabled s.RegisterAction($"{Name}::AutoConnectEnabled::Set", b => b.WithSetting <bool>(s => s.WithLabel("Enable auto connect")).WithCallback((_, enabled) => AutoConnectEnabled = enabled)); s.RegisterAction($"{Name}::AutoConnectEnabled::Toggle", b => b.WithCallback(_ => AutoConnectEnabled = !AutoConnectEnabled)); #endregion }
private void RegisterActions(IShortcutManager s, IOutputTarget target) { var token = _cancellationSource.Token; target.RegisterActions(s); #region Connection s.RegisterAction($"{target.Identifier}::Connection::Toggle", b => b.WithCallback(async(_) => await ToggleConnectAsync(target))); s.RegisterAction($"{target.Identifier}::Connection::Connect", b => b.WithCallback(async(_) => { await _semaphores[target].WaitAsync(token); if (target.Status == ConnectionStatus.Disconnected) { await target.ConnectAsync(); await target.WaitForIdle(token); } _semaphores[target].Release(); })); s.RegisterAction($"{target.Identifier}::Connection::Disconnect", b => b.WithCallback(async(_) => { await _semaphores[target].WaitAsync(token); if (target.Status == ConnectionStatus.Connected) { await target.DisconnectAsync(); await target.WaitForDisconnect(token); } _semaphores[target].Release(); })); #endregion }
private void RegisterShortcuts(IShortcutManager s) { var token = _cancellationSource.Token; foreach (var source in Items) { s.RegisterAction($"{source.Name}::Connection::Toggle", b => b.WithCallback(async(_) => await ToggleConnectAsync(source))); s.RegisterAction($"{source.Name}::Connection::Connect", b => b.WithCallback(async(_) => { await _semaphore.WaitAsync(token); if (_currentSource != source) { await ConnectAndSetAsCurrentSourceAsync(source, token); } _semaphore.Release(); })); s.RegisterAction($"{source.Name}::Connection::Disconnect", b => b.WithCallback(async(_) => { await _semaphore.WaitAsync(token); if (_currentSource == source) { await DisconnectCurrentSourceAsync(token); } _semaphore.Release(); })); } }
public override void RegisterActions(IShortcutManager s) { base.RegisterActions(s); #region PipeName s.RegisterAction($"{Identifier}::PipeName::Set", b => b.WithSetting <string>(s => s.WithLabel("Pipe name")).WithCallback((_, pipeName) => PipeName = pipeName)); #endregion }
protected override void RegisterShortcuts(IShortcutManager s) { base.RegisterShortcuts(s); #region Arguments s.RegisterAction($"{Name}::Arguments::Set", b => b.WithSetting <string>(s => s.WithLabel("Arguments")).WithCallback((_, arguments) => Arguments = arguments)); #endregion }
public override void RegisterActions(IShortcutManager s) { base.RegisterActions(s); #region ComPort s.RegisterAction($"{Identifier}::SerialPort::Set", b => b.WithSetting <string>(s => s.WithLabel("Device ID")).WithCallback((_, deviceId) => SelectSerialPortByDeviceId(deviceId))); #endregion }
protected override void RegisterShortcuts(IShortcutManager s) { base.RegisterShortcuts(s); #region Endpoint s.RegisterAction($"{Name}::Endpoint::Set", b => b.WithSetting <string>(s => s.WithLabel("Endpoint").WithDescription("ip:port")).WithCallback((_, endpointString) => { if (IPEndPoint.TryParse(endpointString, out var endpoint)) { Endpoint = endpoint; } })); #endregion }
public override void RegisterActions(IShortcutManager s) { base.RegisterActions(s); #region Uri s.RegisterAction($"{Identifier}::Uri::Set", b => b.WithSetting <string>(s => s.WithLabel("Uri").WithDescription("websocket uri")).WithCallback((_, uriString) => { if (Uri.TryCreate(uriString, UriKind.Absolute, out var uri)) { Uri = uri; } })); #endregion }
public override void RegisterActions(IShortcutManager s) { base.RegisterActions(s); #region Endpoint s.RegisterAction($"{Identifier}::Endpoint::Set", b => b.WithSetting <string>(s => s.WithLabel("Endpoint").WithDescription("ip:port")).WithCallback((_, endpointString) => { if (IPEndPoint.TryParse(endpointString, out var endpoint)) { Endpoint = endpoint; } })); #endregion #region Protocol s.RegisterAction($"{Identifier}::Protocol::Set", b => b.WithSetting <ProtocolType?>(s => s.WithLabel("Protocol").WithItemsSource(EnumUtils.GetValues <ProtocolType?>())).WithCallback((_, protocol) => { if (protocol.HasValue) { Protocol = protocol.Value; } })); #endregion }
public void RegisterShortcuts(IShortcutManager s) { foreach (var name in MotionProviderNames) { #region MotionProvider::Speed s.RegisterAction($"MotionProvider::{name}::Speed::Offset", b => b.WithSetting <DeviceAxis>(p => p.WithLabel("Target axis").WithItemsSource(DeviceAxis.All)) .WithSetting <float>(p => p.WithLabel("Value offset").WithStringFormat("{}{0}%")) .WithCallback((_, axis, offset) => { var motionProvider = GetMotionProvider(axis, name); if (motionProvider == null) { return; } motionProvider.Speed = MathF.Max(0.01f, motionProvider.Speed + offset / 100); })); s.RegisterAction($"MotionProvider::{name}::Speed::Set", b => b.WithSetting <DeviceAxis>(p => p.WithLabel("Target axis").WithItemsSource(DeviceAxis.All)) .WithSetting <float>(p => p.WithLabel("Value").WithStringFormat("{}{0}%")) .WithCallback((_, axis, value) => { var motionProvider = GetMotionProvider(axis, name); if (motionProvider == null) { return; } motionProvider.Speed = MathF.Max(0.01f, value / 100); })); s.RegisterAction($"MotionProvider::{name}::Speed::Drive", b => b.WithSetting <DeviceAxis>(p => p.WithLabel("Target axis").WithItemsSource(DeviceAxis.All)) .WithCallback((gesture, axis) => { if (gesture is not IAxisInputGesture axisGesture) { return; } var motionProvider = GetMotionProvider(axis, name); if (motionProvider == null) { return; } motionProvider.Speed = MathF.Max(0.01f, motionProvider.Speed + axisGesture.Delta); }), ShortcutActionDescriptorFlags.AcceptsAxisGesture); #endregion #region MotionProvider::Minimum s.RegisterAction($"MotionProvider::{name}::Minimum::Offset", b => b.WithSetting <DeviceAxis>(p => p.WithLabel("Target axis").WithItemsSource(DeviceAxis.All)) .WithSetting <float>(p => p.WithLabel("Value offset").WithStringFormat("{}{0}%")) .WithCallback((_, axis, offset) => { var motionProvider = GetMotionProvider(axis, name); if (motionProvider == null) { return; } motionProvider.Minimum = MathUtils.Clamp(motionProvider.Minimum + offset, 0, 100); })); s.RegisterAction($"MotionProvider::{name}::Minimum::Set", b => b.WithSetting <DeviceAxis>(p => p.WithLabel("Target axis").WithItemsSource(DeviceAxis.All)) .WithSetting <float>(p => p.WithLabel("Value").WithStringFormat("{}{0}%")) .WithCallback((_, axis, value) => { var motionProvider = GetMotionProvider(axis, name); if (motionProvider == null) { return; } motionProvider.Minimum = MathUtils.Clamp(value, 0, 100); })); s.RegisterAction($"MotionProvider::{name}::Minimum::Drive", b => b.WithSetting <DeviceAxis>(p => p.WithLabel("Target axis").WithItemsSource(DeviceAxis.All)) .WithCallback((gesture, axis) => { if (gesture is not IAxisInputGesture axisGesture) { return; } var motionProvider = GetMotionProvider(axis, name); if (motionProvider == null) { return; } motionProvider.Minimum = MathUtils.Clamp(motionProvider.Minimum + axisGesture.Delta, 0, 100); }), ShortcutActionDescriptorFlags.AcceptsAxisGesture); #endregion #region MotionProvider::Maximum s.RegisterAction($"MotionProvider::{name}::Maximum::Offset", b => b.WithSetting <DeviceAxis>(p => p.WithLabel("Target axis").WithItemsSource(DeviceAxis.All)) .WithSetting <float>(p => p.WithLabel("Value offset").WithStringFormat("{}{0}%")) .WithCallback((_, axis, offset) => { var motionProvider = GetMotionProvider(axis, name); if (motionProvider == null) { return; } motionProvider.Maximum = MathUtils.Clamp(motionProvider.Maximum + offset, 0, 100); })); s.RegisterAction($"MotionProvider::{name}::Maximum::Set", b => b.WithSetting <DeviceAxis>(p => p.WithLabel("Target axis").WithItemsSource(DeviceAxis.All)) .WithSetting <float>(p => p.WithLabel("Value").WithStringFormat("{}{0}%")) .WithCallback((_, axis, value) => { var motionProvider = GetMotionProvider(axis, name); if (motionProvider == null) { return; } motionProvider.Maximum = MathUtils.Clamp(value, 0, 100); })); s.RegisterAction($"MotionProvider::{name}::Maximum::Drive", b => b.WithSetting <DeviceAxis>(p => p.WithLabel("Target axis").WithItemsSource(DeviceAxis.All)) .WithCallback((gesture, axis) => { if (gesture is not IAxisInputGesture axisGesture) { return; } var motionProvider = GetMotionProvider(axis, name); if (motionProvider == null) { return; } motionProvider.Maximum = MathUtils.Clamp(motionProvider.Maximum + axisGesture.Delta, 0, 100); }), ShortcutActionDescriptorFlags.AcceptsAxisGesture); #endregion } }