Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 21 additions & 28 deletions ControlPad/Arduino/ArduinoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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(() =>
Expand All @@ -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++)
Expand All @@ -223,4 +216,4 @@ private static void UpdateValues(string[] inputs)
DataHandler.ButtonValues[i] = (DataHandler.ButtonValues[i].button, int.Parse(inputs[i + DataHandler.SliderValues.Count]));
}
}
}
}
9 changes: 9 additions & 0 deletions ControlPad/BoardType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ControlPad
{
public enum BoardType
{
None = -1,
Left,
Right,
}
}
2 changes: 1 addition & 1 deletion ControlPad/UI Elements/HomeUserControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
</UserControl.Resources>
<!-- ===== Layout ===== -->
<Border Padding="5">
<Grid>
<Grid x:Name="MainGrid">
<!-- 6 Slider Columns + 1 Button Column -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
Expand Down
11 changes: 5 additions & 6 deletions ControlPad/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

<DockPanel>
<tray:NotifyIcon
x:Name="NotifyIcon"
FocusOnLeftClick="True"
MenuOnRightClick="True"
Icon="pack://application:,,,/Resources/logo.ico"
TooltipText="Control Pad"
>
x:Name="NotifyIcon"
FocusOnLeftClick="True"
MenuOnRightClick="True"
Icon="pack://application:,,,/Resources/logo.ico"
TooltipText="Control Pad">
<tray:NotifyIcon.Menu>
<ContextMenu>
<MenuItem Header="Open" Click="MI_Open_Click" />
Expand Down
31 changes: 17 additions & 14 deletions ControlPad/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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())
Expand Down
Loading