diff --git a/ControlPad/Arduino/ArduinoController.cs b/ControlPad/Arduino/ArduinoController.cs index e65f081..e9568cc 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,9 +163,26 @@ private static void ProcessLine(string line) try { var inputs = Regex.Split(line, ","); - if (inputs.Length < 16) return; + if (inputs.Length < 19) return; - UpdateValues(inputs); + if (int.TryParse(inputs[0], out int boardType)) + { + var newBoardType = (BoardType)boardType; + var oldBoardType = _lastBoardType; + + if (oldBoardType != newBoardType) + { + _mainWindow.Dispatcher.BeginInvoke(() => + { + _mainWindow.UpdateBoardType(oldBoardType, newBoardType); + }); + _lastBoardType = newBoardType; + } + } + + int subscribtionTier = int.Parse(inputs[1]); + + UpdateValues(inputs[2..]); // UI-Updates ggf. drosseln _mainWindow._homeUserControl.Dispatcher.BeginInvoke(() => @@ -190,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++) @@ -223,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 +} 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..2edf19c 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 || curBoardType == BoardType.None) && 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())