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