Skip to content

Commit

Permalink
Optimize software startup speed, add multi-line support for the text …
Browse files Browse the repository at this point in the history
…sending box, fix bugs, and optimize layout.
  • Loading branch information
SQc04 committed Jul 8, 2024
1 parent ddafd07 commit d5e2f90
Show file tree
Hide file tree
Showing 10 changed files with 798 additions and 590 deletions.
3 changes: 2 additions & 1 deletion FSGaryityTool_Win11.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.0.240109" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.TokenizingTextBox" Version="8.0.240109" />
<PackageReference Include="MICA" Version="2.4.3" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.2.0" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240404000" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down Expand Up @@ -257,7 +258,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>0.2.35</VersionPrefix>
<VersionPrefix>0.2.37</VersionPrefix>
</PropertyGroup>


Expand Down
2 changes: 1 addition & 1 deletion MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<FontIcon Glyph="&#xE962;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem x:Name="FanTest" Content="FanTest" Tag="Page5" >
<NavigationViewItem x:Name="FanControl" Content="FanControl" Tag="Page5" >
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE770;" />
</NavigationViewItem.Icon>
Expand Down
530 changes: 280 additions & 250 deletions MainWindow.xaml.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity
Name="8153eea4-0701-4df3-b478-ccfc268ddd1b"
Publisher="CN=FAIRING STUDIO"
Version="0.2.35.0" />
Version="0.2.37.0" />

<Properties>
<DisplayName>FSGaryityTool</DisplayName>
Expand Down
576 changes: 305 additions & 271 deletions Page1.xaml

Large diffs are not rendered by default.

59 changes: 44 additions & 15 deletions Page1.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
using FSGaryityTool_Win11.McuToolpage;
using System.Timers;
using System.Text.RegularExpressions;
using Windows.System;
using Microsoft.UI.Input;


// To learn more about WinUI, the WinUI project structure,
Expand Down Expand Up @@ -1185,10 +1187,11 @@ private void UpdateItemsRepeater(LinkedList<DataItem> items)
private DateTime lastReceivedTime = DateTime.Now; // 添加这一行来声明lastReceivedTime变量
StringBuilder buffer = new StringBuilder();

private async void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
private void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// 在另一个线程中处理串口数据
await Task.Run(() =>

Task.Run(() =>
{
string Timesr = current_time.ToString("yyyy-MM-dd HH:mm:ss:ff "); //显示时间
Expand Down Expand Up @@ -1250,12 +1253,12 @@ await Task.Run(() =>
lastReceivedTime = DateTime.Now; // 更新最后接收数据的时间
}
DispatcherQueue.TryEnqueue(() =>
{
UpdateItemsRepeater(tempDataList);
});
});

}

private void UpdateItemsRepeater(LinkedList<DataItem> items)
Expand Down Expand Up @@ -1455,7 +1458,7 @@ private void SendStringData()
// 如果需要在每条消息后添加换行符
AppendNewLineIfRequired();
// 更新接收文本框的内容
RXTextBox.Text += $"TX: {str}\r\n";
RXTextBox.Text += $"TX: {str}" + "\r\n";
}
catch
{
Expand All @@ -1473,14 +1476,23 @@ private void SendHexData()
{
// 获取要发送的十六进制字符串,并进行必要的预处理
string input = PrepareHexString();
// 将十六进制字符串转换为字节数组
byte[] bytes = ConvertHexStringToByteArray(input);
// 通过串口发送字节数组
CommonRes._serialPort.Write(bytes, 0, bytes.Length);
// 如果需要在每条消息后添加换行符
AppendNewLineIfRequired();
// 更新接收文本框的内容
RXTextBox.Text += $"TX: 0x {string.Join(" ", bytes.Select(b => b.ToString("X2")))}\r\n";
Task.Run(() =>
{
// 将十六进制字符串转换为字节数组
byte[] bytes = ConvertHexStringToByteArray(input);
// 通过串口发送字节数组
CommonRes._serialPort.Write(bytes, 0, bytes.Length);
// 如果需要在每条消息后添加换行符
AppendNewLineIfRequired();
DispatcherQueue.TryEnqueue(() =>
{
// 更新接收文本框的内容
RXTextBox.Text += $"TX: 0x {string.Join(" ", bytes.Select(b => b.ToString("X2")))}\r\n";
});
input = "";
});

}
catch (FormatException)
{
Expand All @@ -1496,6 +1508,7 @@ private string PrepareHexString()
{
// 获取要发送的十六进制字符串,并去除所有空格
string input = TXTextBox.Text.Trim().Replace(" ", "");
input = input.Replace("\r", "").Replace("\t", "");
// 如果长度为奇数,前面添加一个 '0'
if (input.Length % 2 != 0)
{
Expand All @@ -1504,6 +1517,7 @@ private string PrepareHexString()
return input;
}


// 将十六进制字符串转换为字节数组
private byte[] ConvertHexStringToByteArray(string input)
{
Expand Down Expand Up @@ -1765,9 +1779,9 @@ private void DTRButton_Click(object sender, RoutedEventArgs e) //DTR信号
}
}

public static async void RSTButtonRes()
public static void RSTButtonRes()
{
await Task.Run(() =>
Task.Run(() =>
{
CommonRes._serialPort.BaudRate = 74880;// BANDComboBox.SelectedItem = "74880";//ESP12F
Expand Down Expand Up @@ -1925,14 +1939,29 @@ private Task RXDATA_ClickAsync(object sender, RoutedEventArgs e)
return Task.CompletedTask;
}

public bool isCtrlDown = false;
private void TXTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Control)
{
isCtrlDown = true;
}
}

private void TXTextBox_KeyUp(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
if (e.Key == Windows.System.VirtualKey.Enter && isCtrlDown)
{
TXButton_Click(this, new RoutedEventArgs());
}
if (e.Key == Windows.System.VirtualKey.Control)
{
isCtrlDown = false;
}
}



private void SaveSetButton_Click(object sender, RoutedEventArgs e)
{
if (autosaveset == 0)
Expand Down
148 changes: 103 additions & 45 deletions Page5.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,114 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:Toolkit="using:CommunityToolkit.WinUI.Controls"
xmlns:win2d="using:Microsoft.Graphics.Canvas.UI.Xaml"
NavigationCacheMode="Enabled">

<Grid>
<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Grid Margin="-67,0,0,0">
<TextBlock Text="RPM" Margin="-60,198,0,0"/>
<TextBlock Text="%" Margin="-68,225,0,0"/>
</Grid>
</StackPanel>
</StackPanel>
<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Grid Margin="105,0,0,0">
<TextBlock Text="RPM" Margin="280,198,0,0"/>
<TextBlock Text="%" Margin="270,225,0,0"/>
</Grid>
</StackPanel>
</StackPanel>
<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Toolkit:RadialGauge x:Name="CPUFanRpmRadialGauge" Width="220" Maximum="8000" TickSpacing="500" IsInteractive="False"
ScaleWidth="8" TickWidth="0" NeedleLength="0" Margin="42,-31,42,0"/>
<Toolkit:RadialGauge x:Name="GPUFanRpmRadialGauge" Width="220" Maximum="6000" TickSpacing="500" IsInteractive="False"
ScaleWidth="8" TickWidth="0" NeedleLength="0" Margin="42,-31,42,0"/>
</StackPanel>
</StackPanel>
<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<Slider x:Name="CpuTemp" Height="240" Orientation="Vertical"
TickFrequency="10" TickPlacement="Outside" Maximum="120" Minimum="0"/>
<TextBlock x:Name="CpuTempText" FontSize="20"
HorizontalAlignment="Center" Margin="-5,0,0,0"/>
</StackPanel>
<ScrollViewer Margin="60,0,0,0">
<StackPanel VerticalAlignment="Top" Orientation="Vertical" Margin="0,0,60,0">
<StackPanel Margin="0,48,0,0"/>
<TextBlock Text="CPU FAN" Margin="0"/>
<Border x:Name="CpuFanControlRadialGauge" CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Height="300" Margin="0,3,0,3">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="*" MinWidth="90" MaxWidth="150"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Border Grid.Column="0" CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Margin="6">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Toolkit:RadialGauge x:Name="CPUFanRpmRadialGauge" Maximum="8000" TickSpacing="500" IsInteractive="False"
ScaleWidth="8" TickWidth="0" NeedleLength="0" Margin="39"/>
<Toolkit:RadialGauge x:Name="CPUFanRadialGauge" TickPadding="21" Maximum="100" TickSpacing="5" Margin="12"/>
<TextBlock Text="RPM" FontSize="12" Margin="168,232,0,0"/>
<TextBlock Text="%" Margin="163,254,0,0"/>
</Grid>
</Border>
<Border Grid.Column="1" CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Margin="6">
<Grid HorizontalAlignment="Center" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="36"/>
</Grid.RowDefinitions>

<Slider x:Name="CpuTemp" Grid.Row="0" Orientation="Vertical" Margin="0,12,0,6"
TickFrequency="10" TickPlacement="Outside" Maximum="120" Minimum="0"/>
<TextBlock x:Name="CpuTempText" Grid.Row="1" FontSize="20"
HorizontalAlignment="Center" Margin="0,0,0,12"/>

</Grid>
</Border>
<Border Grid.Column="2" CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Margin="6">
<Grid>

</Grid>
</Border>

</Grid>
</Border>
<TextBlock Text="GPU FAN" Margin="0"/>
<Border x:Name="GpuFanControlRadialGauge" CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Height="300" Margin="0,3,0,3">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="*" MinWidth="90" MaxWidth="150"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Toolkit:RadialGauge x:Name="CPUFanRadialGauge" Width="280" TickPadding="21" Maximum="100" TickSpacing="5" Margin="12"/>
<Toolkit:RadialGauge x:Name="GPUFanRadialGauge" Width="280" TickPadding="21" Maximum="100" TickSpacing="5" Margin="12"/>

<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<Slider x:Name="GpuTemp" Height="240" Orientation="Vertical"
TickFrequency="10" TickPlacement="Outside" Maximum="120" Minimum="0"/>
<TextBlock x:Name="GpuTempText" FontSize="20"
HorizontalAlignment="Center" Margin="-5,0,0,0"/>
<Border Grid.Column="0" CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Margin="6">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Toolkit:RadialGauge x:Name="GPUFanRpmRadialGauge" Maximum="6000" TickSpacing="500" IsInteractive="False"
ScaleWidth="8" TickWidth="0" NeedleLength="0" Margin="39"/>
<Toolkit:RadialGauge x:Name="GPUFanRadialGauge" TickPadding="21" Maximum="100" TickSpacing="5" Margin="12"/>
<TextBlock Text="RPM" FontSize="12" Margin="168,232,0,0"/>
<TextBlock Text="%" Margin="163,254,0,0"/>
</Grid>
</Border>
<Border Grid.Column="1" CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Margin="6">
<Grid HorizontalAlignment="Center" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="36"/>
</Grid.RowDefinitions>

<Slider x:Name="GpuTemp" Grid.Row="0" Orientation="Vertical" Margin="0,12,0,6"
TickFrequency="10" TickPlacement="Outside" Maximum="120" Minimum="0"/>
<TextBlock x:Name="GpuTempText" Grid.Row="1" FontSize="20"
HorizontalAlignment="Center" Margin="0,0,0,12"/>

</Grid>
</Border>
<Border Grid.Column="2" CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Margin="6">
<Grid>

</Grid>
</Border>

</Grid>
</Border>

<StackPanel Margin="0,48,0,0"/>

<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Margin="6">
<Button x:Name="ClevoGetFaninfo" Click="ClevoGetFaninfo_Click" Content="GetFaninfo" IsEnabled="False"></Button>
<Button x:Name="Clevoinfo" Click="Clevoinfo_Click" Content="Getinfo"></Button>
<Button x:Name="WatchDogStart" Click="WatchDogStart_Click" Content="WatchDogStart"></Button>
<Button x:Name="WatchDogClose" Click="WatchDogClose_Click" Content="WatchDogClose"></Button>
</StackPanel>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Margin="6">
<Border CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Width="324" Height="224" Margin="6">
<win2d:CanvasControl x:Name="canvasControl" Draw="OnDraw" Margin="12"/>
</Border>
</StackPanel>
</StackPanel>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button x:Name="ClevoGetFaninfo" Click="ClevoGetFaninfo_Click" Content="GetFaninfo" IsEnabled="False"></Button>
<Button x:Name="Clevoinfo" Click="Clevoinfo_Click" Content="Getinfo"></Button>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Grid>
</Page>
Loading

0 comments on commit d5e2f90

Please sign in to comment.