Commit c2b96bb8 by liulongfei

1. 添加光标键控制中心轴移动

parent d46b8ca0
...@@ -17,14 +17,14 @@ CLIENT_CONSOLE_LOG_MAX_LINE=500 ...@@ -17,14 +17,14 @@ CLIENT_CONSOLE_LOG_MAX_LINE=500
; ============================================================ ; ============================================================
[UDP] [UDP]
;客户端UDP绑定IP ;客户端UDP绑定IP
;CLIENT_BINDING_IP=192.168.88.163 CLIENT_BINDING_IP=192.168.0.124
CLIENT_BINDING_IP=127.0.0.1 ;CLIENT_BINDING_IP=127.0.0.1
;CLIENT_BINDING_IP=192.168.88.242 ;CLIENT_BINDING_IP=192.168.88.242
;客户端UDP绑定端口 ;客户端UDP绑定端口
CLIENT_BINDING_PORT=8000 CLIENT_BINDING_PORT=8000
;算法UDP绑定IP ;算法UDP绑定IP
;ALGORITHM_BINDING_IP=192.168.88.241 ALGORITHM_BINDING_IP=192.168.0.117
ALGORITHM_BINDING_IP=127.0.0.1 ;ALGORITHM_BINDING_IP=127.0.0.1
;算法UDP绑定端口 ;算法UDP绑定端口
ALGORITHM_BINDING_PORT=8001 ALGORITHM_BINDING_PORT=8001
;云台UDP绑定IP ;云台UDP绑定IP
...@@ -55,7 +55,7 @@ ALGORITHM_CMD_WINDOW_STYLE=Minimized ...@@ -55,7 +55,7 @@ ALGORITHM_CMD_WINDOW_STYLE=Minimized
; ============================================================ ; ============================================================
[Gimbal] [Gimbal]
;云台中心轴移动速度 ;云台中心轴移动速度
GIMBAL_CENTER_AXIS_SPEED=1 GIMBAL_CENTER_AXIS_SPEED=2
;云台中心轴X值 ;云台中心轴X值
GIMBAL_CENTER_AXIS_X=960 GIMBAL_CENTER_AXIS_X=960
;云台中心轴Y值 ;云台中心轴Y值
......
...@@ -26,8 +26,12 @@ namespace VIZ.GimbalAI.Connection ...@@ -26,8 +26,12 @@ namespace VIZ.GimbalAI.Connection
/// <param name="packageInfo">包信息</param> /// <param name="packageInfo">包信息</param>
public void Execute(ConnSingleJsonInfo packageInfo) public void Execute(ConnSingleJsonInfo packageInfo)
{ {
AlgorithmInitCompleteMessage msg = new AlgorithmInitCompleteMessage(); // 向算法发送最新的中心轴位置
UdpEndpointManager manager = ConnectionManager.UdpConnection.GetEndpointManager(UdpEndpointKeys.algorithm);
AlgorithmSender.CenterAxis(manager);
// 通知界面初始化完成
AlgorithmInitCompleteMessage msg = new AlgorithmInitCompleteMessage();
ApplicationDomainEx.MessageManager.Send(msg); ApplicationDomainEx.MessageManager.Send(msg);
} }
} }
......
...@@ -15,11 +15,11 @@ namespace VIZ.GimbalAI.Domain ...@@ -15,11 +15,11 @@ namespace VIZ.GimbalAI.Domain
/// <summary> /// <summary>
/// 中心轴X坐标 /// 中心轴X坐标
/// </summary> /// </summary>
public double CenterAxisX { get; set; } public double CenterAxisX { get; set; } = 1920 / 2;
/// <summary> /// <summary>
/// 中心轴Y坐标 /// 中心轴Y坐标
/// </summary> /// </summary>
public double CenterAxisY { get; set; } public double CenterAxisY { get; set; } = 1080 / 2;
} }
} }
...@@ -90,8 +90,9 @@ namespace VIZ.GimbalAI.Module ...@@ -90,8 +90,9 @@ namespace VIZ.GimbalAI.Module
Process proc = new Process(); Process proc = new Process();
proc.StartInfo.UseShellExecute = true; proc.StartInfo.UseShellExecute = true;
proc.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(fullPath);
proc.StartInfo.FileName = this.ALGORITHM_PYTHON_PATH; proc.StartInfo.FileName = this.ALGORITHM_PYTHON_PATH;
proc.StartInfo.Arguments = $"\"{fullPath}\""; proc.StartInfo.Arguments = System.IO.Path.GetFileName(fullPath); ;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal; proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
if (!proc.Start()) if (!proc.Start())
......
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VIZ.Framework.Connection;
using VIZ.Framework.Core;
using VIZ.GimbalAI.Connection;
using VIZ.GimbalAI.Domain;
using VIZ.GimbalAI.Storage;
namespace VIZ.GimbalAI.Module
{
/// <summary>
/// 热键控制器
/// </summary>
public class HotkeyController
{
/// <summary>
/// 日志
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(HotkeyController));
/// <summary>
/// 云台中心轴移动速度
/// </summary>
private static readonly double GIMBAL_CENTER_AXIS_SPEED = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, double>(p => p.GIMBAL_CENTER_AXIS_SPEED);
/// <summary>
/// 热键控制器
/// </summary>
/// <param name="support">支持</param>
public HotkeyController(IHotkeySupport support)
{
this.Support = support;
}
/// <summary>
/// 支持
/// </summary>
public IHotkeySupport Support { get; private set; }
/// <summary>
/// 移动中心轴
/// </summary>
/// <param name="e">事件参数</param>
public void MoveCenterAxis(KeyEventArgs e)
{
double x = ApplicationDomainEx.GimbalControlModel.CenterAxisX;
double y = ApplicationDomainEx.GimbalControlModel.CenterAxisY;
if (e.KeyCode == Keys.Left)
{
x -= GIMBAL_CENTER_AXIS_SPEED;
}
if (e.KeyCode == Keys.Right)
{
x += GIMBAL_CENTER_AXIS_SPEED;
}
if (e.KeyCode == Keys.Up)
{
y -= GIMBAL_CENTER_AXIS_SPEED;
}
if (e.KeyCode == Keys.Down)
{
y += GIMBAL_CENTER_AXIS_SPEED;
}
x = MathHelper.Clip(0, 1920, x);
y = MathHelper.Clip(0, 1080, y);
ApplicationDomainEx.GimbalControlModel.CenterAxisX = x;
ApplicationDomainEx.GimbalControlModel.CenterAxisY = y;
// 向算法发送最新的中心轴位置
UdpEndpointManager manager = ConnectionManager.UdpConnection.GetEndpointManager(UdpEndpointKeys.algorithm);
AlgorithmSender.CenterAxis(manager);
// 向界面发送更新轴信息消息
GimbalCenterAxisMessage message = new GimbalCenterAxisMessage();
message.X = x;
message.Y = y;
ApplicationDomainEx.MessageManager.Send(message);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.GimbalAI.Module
{
/// <summary>
/// 热键支持
/// </summary>
public interface IHotkeySupport
{
}
}
...@@ -12,14 +12,22 @@ using VIZ.GimbalAI.Domain.Message; ...@@ -12,14 +12,22 @@ using VIZ.GimbalAI.Domain.Message;
using VIZ.GimbalAI.Common; using VIZ.GimbalAI.Common;
using VIZ.Framework.Module; using VIZ.Framework.Module;
using VIZ.Framework.Common; using VIZ.Framework.Common;
using Gma.System.MouseKeyHook;
using VIZ.GimbalAI.Storage;
using log4net;
namespace VIZ.GimbalAI.Module namespace VIZ.GimbalAI.Module
{ {
/// <summary> /// <summary>
/// 主视图模型 /// 主视图模型
/// </summary> /// </summary>
public class MainViewModel : ViewModelBase, IAlgorithmSupport public class MainViewModel : ViewModelBase, IAlgorithmSupport, IHotkeySupport
{ {
/// <summary>
/// 日志
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(MainViewModel));
public MainViewModel() public MainViewModel()
{ {
// 初始化命令 // 初始化命令
...@@ -33,6 +41,9 @@ namespace VIZ.GimbalAI.Module ...@@ -33,6 +41,9 @@ namespace VIZ.GimbalAI.Module
// 初始化FPS // 初始化FPS
this.InitFPS(); this.InitFPS();
// 初始化热键
this.InitHotkey();
} }
/// <summary> /// <summary>
...@@ -72,6 +83,17 @@ namespace VIZ.GimbalAI.Module ...@@ -72,6 +83,17 @@ namespace VIZ.GimbalAI.Module
private void InitController() private void InitController()
{ {
this.AlgorithmController = new AlgorithmController(this); this.AlgorithmController = new AlgorithmController(this);
this.HotkeyController = new HotkeyController(this);
}
/// <summary>
/// 初始化热键
/// </summary>
private void InitHotkey()
{
this.keyboardMouseEvents = Hook.AppEvents();
this.keyboardMouseEvents.KeyDown -= KeyboardMouseEvents_KeyDown;
this.keyboardMouseEvents.KeyDown += KeyboardMouseEvents_KeyDown;
} }
// ====================================================================================== // ======================================================================================
...@@ -83,6 +105,20 @@ namespace VIZ.GimbalAI.Module ...@@ -83,6 +105,20 @@ namespace VIZ.GimbalAI.Module
/// </summary> /// </summary>
private AlgorithmController AlgorithmController; private AlgorithmController AlgorithmController;
/// <summary>
/// 热键控制器
/// </summary>
private HotkeyController HotkeyController;
// ======================================================================================
// === Field ===
// ======================================================================================
/// <summary>
/// 鼠标键盘事件
/// </summary>
private IKeyboardMouseEvents keyboardMouseEvents;
// ====================================================================================== // ======================================================================================
// === Property === // === Property ===
// ====================================================================================== // ======================================================================================
...@@ -348,5 +384,30 @@ namespace VIZ.GimbalAI.Module ...@@ -348,5 +384,30 @@ namespace VIZ.GimbalAI.Module
} }
#endregion #endregion
// ======================================================================================
// === Private Function ===
// ======================================================================================
/// <summary>
/// 处理快捷键
/// </summary>
private void KeyboardMouseEvents_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// 窗口在最小化、未激活时不处理
try
{
Window window = this.GetWindow();
if (window == null || !window.IsActive || window.WindowState == WindowState.Minimized)
return;
// 处理中心轴移动事件
this.HotkeyController.MoveCenterAxis(e);
}
catch (Exception ex)
{
log.Error(ex);
}
}
} }
} }
...@@ -68,6 +68,9 @@ ...@@ -68,6 +68,9 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Gma.System.MouseKeyHook, Version=5.6.130.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MouseKeyHook.5.6.0\lib\net40\Gma.System.MouseKeyHook.dll</HintPath>
</Reference>
<Reference Include="LiteDB, Version=5.0.11.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL"> <Reference Include="LiteDB, Version=5.0.11.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
<HintPath>..\packages\LiteDB.5.0.11\lib\net45\LiteDB.dll</HintPath> <HintPath>..\packages\LiteDB.5.0.11\lib\net45\LiteDB.dll</HintPath>
</Reference> </Reference>
...@@ -119,6 +122,7 @@ ...@@ -119,6 +122,7 @@
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath> <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Web" /> <Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
...@@ -186,6 +190,8 @@ ...@@ -186,6 +190,8 @@
</Compile> </Compile>
<Compile Include="MainView\Controller\Algorithm\AlgorithmController.cs" /> <Compile Include="MainView\Controller\Algorithm\AlgorithmController.cs" />
<Compile Include="MainView\Controller\Algorithm\IAlgorithmSupport.cs" /> <Compile Include="MainView\Controller\Algorithm\IAlgorithmSupport.cs" />
<Compile Include="MainView\Controller\Hotkey\HotkeyController.cs" />
<Compile Include="MainView\Controller\Hotkey\IHotkeySupport.cs" />
<Compile Include="MainView\ViewModel\MainViewModel.cs" /> <Compile Include="MainView\ViewModel\MainViewModel.cs" />
<Compile Include="MainView\View\MainView.xaml.cs"> <Compile Include="MainView\View\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon> <DependentUpon>MainView.xaml</DependentUpon>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<package id="LiteDB" version="5.0.11" targetFramework="net48" /> <package id="LiteDB" version="5.0.11" targetFramework="net48" />
<package id="log4net" version="2.0.14" targetFramework="net48" /> <package id="log4net" version="2.0.14" targetFramework="net48" />
<package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.39" targetFramework="net48" /> <package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.39" targetFramework="net48" />
<package id="MouseKeyHook" version="5.6.0" targetFramework="net48" />
<package id="OpenCvSharp4" version="4.6.0.20220608" targetFramework="net48" /> <package id="OpenCvSharp4" version="4.6.0.20220608" targetFramework="net48" />
<package id="OpenCvSharp4.Extensions" version="4.6.0.20220608" targetFramework="net48" /> <package id="OpenCvSharp4.Extensions" version="4.6.0.20220608" targetFramework="net48" />
<package id="OpenCvSharp4.WpfExtensions" version="4.6.0.20220608" targetFramework="net48" /> <package id="OpenCvSharp4.WpfExtensions" version="4.6.0.20220608" targetFramework="net48" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment