From b02d934a3ff0d852bafa7f44f7d724c2a3c7b1c9 Mon Sep 17 00:00:00 2001 From: Sprinter31 Date: Sun, 8 Mar 2026 16:37:43 +0100 Subject: [PATCH 1/3] add: board type detection and ui updating --- ControlPad/Arduino/ArduinoController.cs | 19 +++++++++++-- ControlPad/BoardType.cs | 9 ++++++ ControlPad/UI Elements/HomeUserControl.xaml | 2 +- ControlPad/Windows/MainWindow.xaml | 11 ++++---- ControlPad/Windows/MainWindow.xaml.cs | 31 +++++++++++---------- 5 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 ControlPad/BoardType.cs diff --git a/ControlPad/Arduino/ArduinoController.cs b/ControlPad/Arduino/ArduinoController.cs index e65f081..e261380 100644 --- a/ControlPad/Arduino/ArduinoController.cs +++ b/ControlPad/Arduino/ArduinoController.cs @@ -22,6 +22,7 @@ public static class ArduinoController public static bool IsConnected = false; private static CancellationTokenSource? _readCts; private static readonly StringBuilder _lineBuf = new(); + private static BoardType _lastBoardType = BoardType.None; public static void Initialize(MainWindow mainWindow, EventHandler eventHandler) { @@ -162,7 +163,19 @@ private static void ProcessLine(string line) try { var inputs = Regex.Split(line, ","); - if (inputs.Length < 16) return; + if (inputs.Length < 17) return; + + if (int.TryParse(inputs[0], out int boardType)) + { + if (_lastBoardType != (BoardType)boardType) + { + _mainWindow.Dispatcher.BeginInvoke(() => + { + _mainWindow.UpdateBoardType(_lastBoardType, (BoardType)boardType); + }); + _lastBoardType = (BoardType)boardType; + } + } UpdateValues(inputs); @@ -190,7 +203,7 @@ public static void Dispose() catch { } } - private static void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) + /*private static void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (_serialPort == null || !_serialPort.IsOpen) return; @@ -213,7 +226,7 @@ private static void SerialPort_DataReceived(object sender, SerialDataReceivedEve { Debug.WriteLine($"EX: {ex}"); } - } + }*/ private static void UpdateValues(string[] inputs) { diff --git a/ControlPad/BoardType.cs b/ControlPad/BoardType.cs new file mode 100644 index 0000000..7c211eb --- /dev/null +++ b/ControlPad/BoardType.cs @@ -0,0 +1,9 @@ +namespace ControlPad +{ + public enum BoardType + { + None = -1, + Left, + Right, + } +} diff --git a/ControlPad/UI Elements/HomeUserControl.xaml b/ControlPad/UI Elements/HomeUserControl.xaml index e6a02b3..0460631 100644 --- a/ControlPad/UI Elements/HomeUserControl.xaml +++ b/ControlPad/UI Elements/HomeUserControl.xaml @@ -127,7 +127,7 @@ - + diff --git a/ControlPad/Windows/MainWindow.xaml b/ControlPad/Windows/MainWindow.xaml index 0553391..20943ca 100644 --- a/ControlPad/Windows/MainWindow.xaml +++ b/ControlPad/Windows/MainWindow.xaml @@ -20,12 +20,11 @@ + x:Name="NotifyIcon" + FocusOnLeftClick="True" + MenuOnRightClick="True" + Icon="pack://application:,,,/Resources/logo.ico" + TooltipText="Control Pad"> diff --git a/ControlPad/Windows/MainWindow.xaml.cs b/ControlPad/Windows/MainWindow.xaml.cs index 4aaf15f..6cee4d2 100644 --- a/ControlPad/Windows/MainWindow.xaml.cs +++ b/ControlPad/Windows/MainWindow.xaml.cs @@ -1,22 +1,9 @@ -using ControlPad; -using Microsoft.Toolkit.Uwp.Notifications; -using Microsoft.Win32; -using NAudio.SoundFont; -using System.Collections.ObjectModel; -using System.Configuration; +using Microsoft.Toolkit.Uwp.Notifications; using System.Diagnostics; -using System.Drawing; using System.IO; -using System.Runtime.InteropServices; -using System.Threading; using System.Windows; using System.Windows.Controls; -using System.Windows.Forms; -using System.Windows.Input; -using System.Windows.Interop; -using System.Windows.Media.Imaging; using Wpf.Ui.Controls; -using Wpf.Ui.Tray; namespace ControlPad { @@ -47,6 +34,22 @@ public MainWindow(Mutex mutex) _manageButtonCategoriesUserControl = new ManageButtonCategoriesUserControl(this); } + public void UpdateBoardType(BoardType curBoardType, BoardType newBoardType) + { + if (MainContentFrame.Content is HomeUserControl homeControl) + { + int count = homeControl.MainGrid.ColumnDefinitions.Count; + foreach (UIElement child in homeControl.MainGrid.Children) + { + if (curBoardType == BoardType.Right && newBoardType == BoardType.Left) + Grid.SetColumn(child, (Grid.GetColumn(child) + 1) % count); + + else if (curBoardType == BoardType.Left && newBoardType == BoardType.Right) + Grid.SetColumn(child, (Grid.GetColumn(child) - 1 + count) % count); + } + } + } + private Preset GetCurrentPreset() { foreach (Preset preset in DataHandler.GetPresets()) From 4b88d864bbba6ccaa8d79e97e718d1ea6a1cde7f Mon Sep 17 00:00:00 2001 From: Sprinter31 Date: Sun, 8 Mar 2026 17:23:41 +0100 Subject: [PATCH 2/3] update --- ControlPad/Arduino/ArduinoController.cs | 15 ++++++++++----- ControlPad/Windows/MainWindow.xaml.cs | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ControlPad/Arduino/ArduinoController.cs b/ControlPad/Arduino/ArduinoController.cs index e261380..3234f98 100644 --- a/ControlPad/Arduino/ArduinoController.cs +++ b/ControlPad/Arduino/ArduinoController.cs @@ -163,21 +163,26 @@ private static void ProcessLine(string line) try { var inputs = Regex.Split(line, ","); - if (inputs.Length < 17) return; + if (inputs.Length < 19) return; if (int.TryParse(inputs[0], out int boardType)) { - if (_lastBoardType != (BoardType)boardType) + var newBoardType = (BoardType)boardType; + var oldBoardType = _lastBoardType; + + if (oldBoardType != newBoardType) { _mainWindow.Dispatcher.BeginInvoke(() => { - _mainWindow.UpdateBoardType(_lastBoardType, (BoardType)boardType); + _mainWindow.UpdateBoardType(oldBoardType, newBoardType); }); - _lastBoardType = (BoardType)boardType; + _lastBoardType = newBoardType; } } - UpdateValues(inputs); + int subscribtionTier = int.Parse(inputs[1]); + + UpdateValues(inputs[2..]); // UI-Updates ggf. drosseln _mainWindow._homeUserControl.Dispatcher.BeginInvoke(() => diff --git a/ControlPad/Windows/MainWindow.xaml.cs b/ControlPad/Windows/MainWindow.xaml.cs index 6cee4d2..2edf19c 100644 --- a/ControlPad/Windows/MainWindow.xaml.cs +++ b/ControlPad/Windows/MainWindow.xaml.cs @@ -41,7 +41,7 @@ public void UpdateBoardType(BoardType curBoardType, BoardType newBoardType) int count = homeControl.MainGrid.ColumnDefinitions.Count; foreach (UIElement child in homeControl.MainGrid.Children) { - if (curBoardType == BoardType.Right && newBoardType == BoardType.Left) + if ((curBoardType == BoardType.Right || curBoardType == BoardType.None) && newBoardType == BoardType.Left) Grid.SetColumn(child, (Grid.GetColumn(child) + 1) % count); else if (curBoardType == BoardType.Left && newBoardType == BoardType.Right) From f133b5ab5a69b93701e8c6c2d5608d915acbf228 Mon Sep 17 00:00:00 2001 From: PalmarHealer Date: Sun, 8 Mar 2026 17:26:34 +0100 Subject: [PATCH 3/3] Remove unused SerialPort_DataReceived method Removed the unused SerialPort_DataReceived method to clean up the code. --- ControlPad/Arduino/ArduinoController.cs | 27 +------------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/ControlPad/Arduino/ArduinoController.cs b/ControlPad/Arduino/ArduinoController.cs index 3234f98..e9568cc 100644 --- a/ControlPad/Arduino/ArduinoController.cs +++ b/ControlPad/Arduino/ArduinoController.cs @@ -208,31 +208,6 @@ public static void Dispose() catch { } } - /*private static void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) - { - if (_serialPort == null || !_serialPort.IsOpen) return; - - try - { - string line = _serialPort.ReadLine().Replace("\r", ""); - string[] inputs = Regex.Split(line, ","); - - if (inputs.Length < 17) return; - - UpdateValues(inputs); - - _mainWindow._homeUserControl.Dispatcher.BeginInvoke(() => _eventHandler.Update(DataHandler.SliderValues, DataHandler.ButtonValues)); - } - catch (IOException) - { - return; - } - catch (Exception ex) - { - Debug.WriteLine($"EX: {ex}"); - } - }*/ - private static void UpdateValues(string[] inputs) { for (int i = 0; i < DataHandler.SliderValues.Count; i++) @@ -241,4 +216,4 @@ private static void UpdateValues(string[] inputs) DataHandler.ButtonValues[i] = (DataHandler.ButtonValues[i].button, int.Parse(inputs[i + DataHandler.SliderValues.Count])); } } -} \ No newline at end of file +}