Button and serial state improvements
parent
5ed6ff8917
commit
9f2c44f279
|
@ -7,6 +7,7 @@ internal class MaiTouchComConnector
|
||||||
private static SerialPort? serialPort;
|
private static SerialPort? serialPort;
|
||||||
private bool isActiveMode;
|
private bool isActiveMode;
|
||||||
private bool _connected;
|
private bool _connected;
|
||||||
|
private bool _shouldReconnect = true;
|
||||||
private readonly MaiTouchSensorButtonStateManager _buttonState;
|
private readonly MaiTouchSensorButtonStateManager _buttonState;
|
||||||
|
|
||||||
public Action<string> OnConnectStatusChange
|
public Action<string> OnConnectStatusChange
|
||||||
|
@ -37,7 +38,7 @@ internal class MaiTouchComConnector
|
||||||
|
|
||||||
public async Task StartTouchSensorPolling()
|
public async Task StartTouchSensorPolling()
|
||||||
{
|
{
|
||||||
if (!_connected)
|
if (!_connected && _shouldReconnect)
|
||||||
{
|
{
|
||||||
var virtualPort = "COM23"; // Adjust as needed
|
var virtualPort = "COM23"; // Adjust as needed
|
||||||
try
|
try
|
||||||
|
@ -85,6 +86,17 @@ internal class MaiTouchComConnector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async void Disconnect()
|
||||||
|
{
|
||||||
|
_shouldReconnect = false;
|
||||||
|
if (serialPort?.IsOpen == true)
|
||||||
|
{
|
||||||
|
serialPort.Close();
|
||||||
|
serialPort.Dispose();
|
||||||
|
}
|
||||||
|
_connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
var recievedData = serialPort.ReadExisting();
|
var recievedData = serialPort.ReadExisting();
|
||||||
|
|
|
@ -26,8 +26,6 @@ public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
var dataContext = (MainWindowViewModel)DataContext;
|
var dataContext = (MainWindowViewModel)DataContext;
|
||||||
dataContext.IsAutomaticPortConnectingEnabled = false;
|
dataContext.IsAutomaticPortConnectingEnabled = false;
|
||||||
Properties.Settings.Default.IsAutomaticPortConnectingEnabled = false;
|
|
||||||
Properties.Settings.Default.Save();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
connector.OnDataSent = (data) =>
|
connector.OnDataSent = (data) =>
|
||||||
|
@ -71,7 +69,7 @@ public partial class MainWindow : Window
|
||||||
var dataContext = (MainWindowViewModel)DataContext;
|
var dataContext = (MainWindowViewModel)DataContext;
|
||||||
_touchPanel.SetDebugMode(dataContext.IsDebugEnabled);
|
_touchPanel.SetDebugMode(dataContext.IsDebugEnabled);
|
||||||
AutomaticTouchPanelPositioningLoop();
|
AutomaticTouchPanelPositioningLoop();
|
||||||
AutomaticcPortConnectingLoop();
|
AutomaticPortConnectingLoop();
|
||||||
ExitWithSinmaiLoop();
|
ExitWithSinmaiLoop();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -103,6 +101,7 @@ public partial class MainWindow : Window
|
||||||
var dataContext = (MainWindowViewModel)DataContext;
|
var dataContext = (MainWindowViewModel)DataContext;
|
||||||
if (dataContext.IsExitWithSinmaiEnabled)
|
if (dataContext.IsExitWithSinmaiEnabled)
|
||||||
{
|
{
|
||||||
|
connector.Disconnect();
|
||||||
Application.Current.Shutdown();
|
Application.Current.Shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,11 +115,12 @@ public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
_touchPanel.PositionTouchPanel();
|
_touchPanel.PositionTouchPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void AutomaticcPortConnectingLoop()
|
private async void AutomaticPortConnectingLoop()
|
||||||
{
|
{
|
||||||
var dataContext = (MainWindowViewModel)DataContext;
|
var dataContext = (MainWindowViewModel)DataContext;
|
||||||
while (true)
|
while (true)
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
namespace WpfMaiTouchEmulator;
|
namespace WpfMaiTouchEmulator;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -35,6 +36,24 @@ public partial class TouchPanel : Window
|
||||||
Topmost = true;
|
Topmost = true;
|
||||||
_positionManager = new TouchPanelPositionManager();
|
_positionManager = new TouchPanelPositionManager();
|
||||||
Loaded += Window_Loaded;
|
Loaded += Window_Loaded;
|
||||||
|
|
||||||
|
StateCheckLoop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void StateCheckLoop()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (activeTouches.Any() && !TouchesOver.Any())
|
||||||
|
{
|
||||||
|
await Task.Delay(100);
|
||||||
|
if (activeTouches.Any() && !TouchesOver.Any())
|
||||||
|
{
|
||||||
|
DeselectAllItems();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Task.Delay(100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
@ -118,12 +137,6 @@ public partial class TouchPanel : Window
|
||||||
activeTouches[e.TouchDevice.Id] = newElement;
|
activeTouches[e.TouchDevice.Id] = newElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsTouchInsideWindow(touchPoint))
|
|
||||||
{
|
|
||||||
// Touch is outside the window, act accordingly
|
|
||||||
DeselectAllItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +168,7 @@ public partial class TouchPanel : Window
|
||||||
foreach (var element in activeTouches.Values)
|
foreach (var element in activeTouches.Values)
|
||||||
{
|
{
|
||||||
HighlightElement(element, false);
|
HighlightElement(element, false);
|
||||||
|
onRelease((TouchValue)element.Tag);
|
||||||
}
|
}
|
||||||
activeTouches.Clear();
|
activeTouches.Clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue