Tidy up files
parent
a0cfa9c0c6
commit
3b7aa9c11e
|
@ -1,5 +1,6 @@
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using WpfMaiTouchEmulator.Managers;
|
||||||
|
|
||||||
namespace WpfMaiTouchEmulator;
|
namespace WpfMaiTouchEmulator;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace WpfMaiTouchEmulator;
|
namespace WpfMaiTouchEmulator.Managers;
|
||||||
internal class MaiTouchComConnector(MaiTouchSensorButtonStateManager buttonState, MainWindowViewModel viewModel)
|
internal class MaiTouchComConnector(MaiTouchSensorButtonStateManager buttonState, MainWindowViewModel viewModel)
|
||||||
{
|
{
|
||||||
private static SerialPort? serialPort;
|
private static SerialPort? serialPort;
|
||||||
|
@ -187,7 +187,8 @@ internal class MaiTouchComConnector(MaiTouchSensorButtonStateManager buttonState
|
||||||
{
|
{
|
||||||
serialPort?.Write(currentState, 0, currentState.Length);
|
serialPort?.Write(currentState, 0, currentState.Length);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex)
|
||||||
|
{
|
||||||
if (Properties.Settings.Default.IsDebugEnabled)
|
if (Properties.Settings.Default.IsDebugEnabled)
|
||||||
{
|
{
|
||||||
Logger.Error("Error when writing to serial port on button update", ex);
|
Logger.Error("Error when writing to serial port on button update", ex);
|
|
@ -1,9 +1,9 @@
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
namespace WpfMaiTouchEmulator;
|
namespace WpfMaiTouchEmulator.Managers;
|
||||||
|
|
||||||
public enum TouchValue: long
|
public enum TouchValue : long
|
||||||
{
|
{
|
||||||
A1 = 1 << 0, // 2^0
|
A1 = 1 << 0, // 2^0
|
||||||
A2 = 1 << 1, // 2^1
|
A2 = 1 << 1, // 2^1
|
||||||
|
@ -77,12 +77,12 @@ internal class MaiTouchSensorButtonStateManager
|
||||||
|
|
||||||
public void PressButton(TouchValue button)
|
public void PressButton(TouchValue button)
|
||||||
{
|
{
|
||||||
buttonState |= ((long)button);
|
buttonState |= (long)button;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReleaseButton(TouchValue button)
|
public void ReleaseButton(TouchValue button)
|
||||||
{
|
{
|
||||||
buttonState &= ~((long)button);
|
buttonState &= ~(long)button;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] GetCurrentState()
|
public byte[] GetCurrentState()
|
|
@ -5,12 +5,12 @@ using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace WpfMaiTouchEmulator;
|
namespace WpfMaiTouchEmulator.Managers;
|
||||||
public partial class RingButtonEmulator
|
public partial class RingButtonEmulator
|
||||||
{
|
{
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
|
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, nuint dwExtraInfo);
|
||||||
|
|
||||||
private static readonly IDictionary<TouchValue, byte> touchRingMapping = new Dictionary<TouchValue, byte>()
|
private static readonly IDictionary<TouchValue, byte> touchRingMapping = new Dictionary<TouchValue, byte>()
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@ public partial class RingButtonEmulator
|
||||||
{
|
{
|
||||||
if (touchRingMapping.TryGetValue(touchValue, out var vk))
|
if (touchRingMapping.TryGetValue(touchValue, out var vk))
|
||||||
{
|
{
|
||||||
keybd_event(vk, 0, 0, UIntPtr.Zero);
|
keybd_event(vk, 0, 0, nuint.Zero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public partial class RingButtonEmulator
|
||||||
{
|
{
|
||||||
if (touchRingMapping.TryGetValue(touchValue, out var vk))
|
if (touchRingMapping.TryGetValue(touchValue, out var vk))
|
||||||
{
|
{
|
||||||
keybd_event(vk, 0, KEYEVENTF_KEYUP, UIntPtr.Zero);
|
keybd_event(vk, 0, KEYEVENTF_KEYUP, nuint.Zero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public partial class RingButtonEmulator
|
||||||
{
|
{
|
||||||
foreach (var vk in touchRingMapping.Values)
|
foreach (var vk in touchRingMapping.Values)
|
||||||
{
|
{
|
||||||
keybd_event(vk, 0, KEYEVENTF_KEYUP, UIntPtr.Zero);
|
keybd_event(vk, 0, KEYEVENTF_KEYUP, nuint.Zero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,16 +1,16 @@
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace WpfMaiTouchEmulator;
|
namespace WpfMaiTouchEmulator.Managers;
|
||||||
|
|
||||||
class TouchPanelPositionManager
|
class TouchPanelPositionManager
|
||||||
{
|
{
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
static extern IntPtr FindWindow(string? lpClassName, string lpWindowName);
|
static extern nint FindWindow(string? lpClassName, string lpWindowName);
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
static extern bool GetWindowRect(nint hWnd, out RECT lpRect);
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct RECT
|
public struct RECT
|
||||||
|
@ -29,7 +29,7 @@ class TouchPanelPositionManager
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var hWnd = FindWindow(null, "Sinmai");
|
var hWnd = FindWindow(null, "Sinmai");
|
||||||
if (hWnd != IntPtr.Zero)
|
if (hWnd != nint.Zero)
|
||||||
{
|
{
|
||||||
RECT rect;
|
RECT rect;
|
||||||
if (GetWindowRect(hWnd, out rect))
|
if (GetWindowRect(hWnd, out rect))
|
||||||
|
@ -37,7 +37,7 @@ class TouchPanelPositionManager
|
||||||
// Calculate the desired size and position based on the other application's window
|
// Calculate the desired size and position based on the other application's window
|
||||||
var renderRect = GetLargest916Rect(rect);
|
var renderRect = GetLargest916Rect(rect);
|
||||||
var height = renderRect.Width;
|
var height = renderRect.Width;
|
||||||
var left = rect.Left + ((rect.Right - rect.Left) - renderRect.Width) / 2; // Center horizontally
|
var left = rect.Left + (rect.Right - rect.Left - renderRect.Width) / 2; // Center horizontally
|
||||||
var top = rect.Bottom - height;
|
var top = rect.Bottom - height;
|
||||||
return new Rect(left, top, renderRect.Width, height);
|
return new Rect(left, top, renderRect.Width, height);
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,8 @@ class TouchPanelPositionManager
|
||||||
var originalWidth = original.Width;
|
var originalWidth = original.Width;
|
||||||
var originalHeight = original.Height;
|
var originalHeight = original.Height;
|
||||||
|
|
||||||
var widthBasedHeight = (originalWidth * 16) / 9;
|
var widthBasedHeight = originalWidth * 16 / 9;
|
||||||
var heightBasedWidth = (originalHeight * 9) / 16;
|
var heightBasedWidth = originalHeight * 9 / 16;
|
||||||
|
|
||||||
if (widthBasedHeight <= originalHeight)
|
if (widthBasedHeight <= originalHeight)
|
||||||
{
|
{
|
|
@ -2,7 +2,7 @@
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace WpfMaiTouchEmulator;
|
namespace WpfMaiTouchEmulator.Managers;
|
||||||
|
|
||||||
internal class VirtualComPortManager
|
internal class VirtualComPortManager
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ internal class VirtualComPortManager
|
||||||
public async Task<bool> CheckIfPortInstalled(string port, bool expectToExist)
|
public async Task<bool> CheckIfPortInstalled(string port, bool expectToExist)
|
||||||
{
|
{
|
||||||
var installed = false;
|
var installed = false;
|
||||||
for (var i = 0; i< 3; i++)
|
for (var i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
installed = GetInstalledPorts().Any(x => x == port);
|
installed = GetInstalledPorts().Any(x => x == port);
|
||||||
if (installed && expectToExist)
|
if (installed && expectToExist)
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:WpfMaiTouchEmulator"
|
xmlns:local="clr-namespace:WpfMaiTouchEmulator.Managers"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="TouchPanel" Height="800" Width="800"
|
Title="TouchPanel" Height="800" Width="800"
|
||||||
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
|
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using WpfMaiTouchEmulator.Managers;
|
||||||
|
|
||||||
namespace WpfMaiTouchEmulator;
|
namespace WpfMaiTouchEmulator;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue