249 lines
11 KiB
C#
249 lines
11 KiB
C#
/*
|
|
* Copyright (c) 2022 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora;
|
|
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace AuroraUIComponent.UserControls
|
|
{
|
|
/// <summary>
|
|
/// JogButtonPanel.xaml에 대한 상호 작용 논리
|
|
/// </summary>
|
|
public partial class JogButtonPanel : UserControl, INotifyPropertyChanged
|
|
{
|
|
protected readonly Logger Log = new Logger("JogButtonPanel");
|
|
public JogButtonPanel() {
|
|
InitializeComponent();
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
protected void OnPropertyChage([CallerMemberName] string name = null) {
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
}
|
|
|
|
private bool useStep;
|
|
public bool UseStep { get => useStep; set { useStep = value; OnPropertyChage(); } }
|
|
|
|
//public double JogVelocityVal {
|
|
// get { return (double)GetValue(JogVelocityValProperty); }
|
|
// set { SetValue(JogVelocityValProperty, value); }
|
|
//}
|
|
//public static readonly DependencyProperty JogVelocityValProperty =
|
|
// DependencyProperty.Register("JogVelocityVal", typeof(double), typeof(JogButtonPanel), new UIPropertyMetadata(1D));
|
|
|
|
public double LowVelocity {
|
|
get => (double)GetValue(LowVelocityProperty);
|
|
set => SetValue(LowVelocityProperty, value);
|
|
}
|
|
public static readonly DependencyProperty LowVelocityProperty =
|
|
DependencyProperty.Register("LowVelocity", typeof(double), typeof(JogButtonPanel), new UIPropertyMetadata(0.0D));
|
|
|
|
public double MidVelocity {
|
|
get => (double)GetValue(MidVelocityProperty);
|
|
set => SetValue(MidVelocityProperty, value);
|
|
}
|
|
public static readonly DependencyProperty MidVelocityProperty =
|
|
DependencyProperty.Register("MidVelocity", typeof(double), typeof(JogButtonPanel), new UIPropertyMetadata(0.0D));
|
|
|
|
public double HighVelocity {
|
|
get => (double)GetValue(HighVelocityProperty);
|
|
set => SetValue(HighVelocityProperty, value);
|
|
}
|
|
public static readonly DependencyProperty HighVelocityProperty =
|
|
DependencyProperty.Register("HighVelocity", typeof(double), typeof(JogButtonPanel), new UIPropertyMetadata(0.0D));
|
|
|
|
public double JogVelocity {
|
|
get => (double)GetValue(JogVelocityProperty);
|
|
set => SetValue(JogVelocityProperty, value);
|
|
}
|
|
public static readonly DependencyProperty JogVelocityProperty =
|
|
DependencyProperty.Register("JogVelocity", typeof(double), typeof(JogButtonPanel), new UIPropertyMetadata(double.NaN));
|
|
|
|
public JogVelIndex JogVelHMLIndex {
|
|
get => (JogVelIndex)GetValue(JogVelHMLIndexProperty);
|
|
set => SetValue(JogVelHMLIndexProperty, value);
|
|
}
|
|
public static readonly DependencyProperty JogVelHMLIndexProperty =
|
|
DependencyProperty.Register("JogVelHMLIndex", typeof(JogVelIndex), typeof(JogButtonPanel), new UIPropertyMetadata(JogVelIndex.Low));
|
|
|
|
public bool UseMotorConfig {
|
|
get => (bool)GetValue(UseMotorConfigProperty);
|
|
set => SetValue(UseMotorConfigProperty, value);
|
|
}
|
|
public static readonly DependencyProperty UseMotorConfigProperty =
|
|
DependencyProperty.Register("UseMotorConfig", typeof(bool), typeof(JogButtonPanel), new UIPropertyMetadata(false));
|
|
|
|
|
|
public double JogStep {
|
|
get { return (double)GetValue(JogStepProperty); }
|
|
set { SetValue(JogStepProperty, value); }
|
|
}
|
|
public static readonly DependencyProperty JogStepProperty =
|
|
DependencyProperty.Register("JogStep", typeof(double), typeof(JogButtonPanel), new UIPropertyMetadata(1D));
|
|
|
|
public Motor Motor {
|
|
get { return (Motor)GetValue(MotorProperty); }
|
|
set { SetValue(MotorProperty, value); }
|
|
}
|
|
public static readonly DependencyProperty MotorProperty =
|
|
DependencyProperty.Register("Motor", typeof(Motor), typeof(JogButtonPanel), new UIPropertyMetadata(null));
|
|
|
|
public JogImageType JogImageType {
|
|
get { return (JogImageType)GetValue(JogImageTypeProperty); }
|
|
set { SetValue(JogImageTypeProperty, value); }
|
|
}
|
|
public static readonly DependencyProperty JogImageTypeProperty =
|
|
DependencyProperty.Register("JogImageType", typeof(JogImageType), typeof(JogButtonPanel), new UIPropertyMetadata(JogImageType.Default, JogImgeTypeChanged));
|
|
|
|
private static void JogImgeTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
|
((JogButtonPanel)d).UpdateImage((JogImageType)e.NewValue);
|
|
}
|
|
|
|
public string Title {
|
|
get { return (string)GetValue(TitleProperty); }
|
|
set { SetValue(TitleProperty, value); }
|
|
}
|
|
public static readonly DependencyProperty TitleProperty =
|
|
DependencyProperty.Register("Title", typeof(string), typeof(JogButtonPanel), new UIPropertyMetadata(""));
|
|
|
|
public string DirectionMinus {
|
|
get { return (string)GetValue(DirectionMinusProperty); }
|
|
set { SetValue(DirectionMinusProperty, value); }
|
|
}
|
|
public static readonly DependencyProperty DirectionMinusProperty =
|
|
DependencyProperty.Register("DirectionMinus", typeof(string), typeof(JogButtonPanel), new UIPropertyMetadata(""));
|
|
|
|
public string DirectionPlus {
|
|
get { return (string)GetValue(DirectionPlusProperty); }
|
|
set { SetValue(DirectionPlusProperty, value); }
|
|
}
|
|
public static readonly DependencyProperty DirectionPlusProperty =
|
|
DependencyProperty.Register("DirectionPlus", typeof(string), typeof(JogButtonPanel), new UIPropertyMetadata(""));
|
|
|
|
|
|
private void DirectionMinusButton_Down(object sender, System.Windows.Input.MouseButtonEventArgs e) {
|
|
if (Motor == null)
|
|
return;
|
|
|
|
if (!UseStep) {
|
|
var config = (Motor.BaseConfig)Application.Current.AuroraEnv().DeviceManager.GetDeviceConfig(Motor.DeviceId);
|
|
double vel = JogVelocity == double.NaN ? config.DefaultVelocity : JogVelocity;
|
|
Motor?.Jog(-1, vel);
|
|
((Button)sender).CaptureMouse();
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
|
|
private void DirectionPlusButton_Down(object sender, System.Windows.Input.MouseButtonEventArgs e) {
|
|
if (Motor == null)
|
|
return;
|
|
|
|
if (!UseStep) {
|
|
var config = (Motor.BaseConfig)Application.Current.AuroraEnv().DeviceManager.GetDeviceConfig(Motor.DeviceId);
|
|
double vel = JogVelocity == double.NaN ? config.DefaultVelocity : JogVelocity;
|
|
Motor?.Jog(1, vel);
|
|
((Button)sender).CaptureMouse();
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
|
|
private void Button_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) {
|
|
if (Motor == null)
|
|
return;
|
|
|
|
if (!UseStep) {
|
|
Motor?.Stop();
|
|
((Button)sender).ReleaseMouseCapture();
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
|
|
private void DirectionMinusButton_Click(object sender, RoutedEventArgs e) {
|
|
if (Motor == null)
|
|
return;
|
|
|
|
if (UseStep) {
|
|
PerformCmdRelMove(JogStep * -1);
|
|
}
|
|
}
|
|
|
|
private void DirectionPlusButton_Click(object sender, RoutedEventArgs e) {
|
|
if (Motor == null)
|
|
return;
|
|
|
|
if (UseStep) {
|
|
PerformCmdRelMove(JogStep);
|
|
}
|
|
}
|
|
|
|
private void UpdateImage(JogImageType jogImageType) {
|
|
|
|
switch (jogImageType) {
|
|
case JogImageType.LeftRight:
|
|
imgLeft.Source = (ImageSource)FindResource("img_arrow_leftDrawingImage");
|
|
imgRight.Source = (ImageSource)FindResource("img_arrow_rightDrawingImage");
|
|
break;
|
|
case JogImageType.UpDown:
|
|
imgLeft.Source = (ImageSource)FindResource("img_arrow_upDrawingImage");
|
|
imgRight.Source = (ImageSource)FindResource("img_arrow_downDrawingImage");
|
|
break;
|
|
case JogImageType.DownUp:
|
|
imgLeft.Source = (ImageSource)FindResource("img_arrow_downDrawingImage");
|
|
imgRight.Source = (ImageSource)FindResource("img_arrow_upDrawingImage");
|
|
break;
|
|
|
|
case JogImageType.CwCcw:
|
|
imgLeft.Source = (ImageSource)FindResource("img_arrow_clockwiseDrawingImage");
|
|
imgRight.Source = (ImageSource)FindResource("img_arrow_counterclockwiseDrawingImage");
|
|
break;
|
|
case JogImageType.CcwCw:
|
|
imgLeft.Source = (ImageSource)FindResource("img_arrow_counterclockwiseDrawingImage");
|
|
imgRight.Source = (ImageSource)FindResource("img_arrow_clockwiseDrawingImage");
|
|
break;
|
|
case JogImageType.Custom:
|
|
case JogImageType.Default:
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void PerformCmdRelMove(double step) {
|
|
try {
|
|
var config = (Motor.BaseConfig)Application.Current.AuroraEnv().DeviceManager.GetDeviceConfig(Motor.DeviceId);
|
|
double vel = JogVelocity == double.NaN ? config.DefaultVelocity : JogVelocity;
|
|
Motor?.SetTargetPosition(step, TargetPosType.REL);
|
|
Motor?.SetVelocity((uint)vel);
|
|
// SetOthers()라도 만들어야 하나?
|
|
//Motor?.SetAccelerationImm(config.AxisVelInfo.Acc);
|
|
//Motor?.SetDecelerationImm(config.AxisVelInfo.Dec);
|
|
//Motor?.SetJerkImm(config.AxisVelInfo.Jerk);
|
|
Motor?.Move();
|
|
|
|
Log.D(string.Format($"{Motor.DeviceId}|{Motor.DeviceId} RelMove"));
|
|
} catch (Exception exc) {
|
|
Log.E(exc.Message);
|
|
}
|
|
}
|
|
}
|
|
public enum JogImageType { Default, LeftRight, UpDown, DownUp, CwCcw, CcwCw, Custom }
|
|
public enum JogVelIndex { Low, Mid, High }
|
|
}
|