Skip to content

Commit

Permalink
Fixed the bug that the baud rate input field could input non-integers
Browse files Browse the repository at this point in the history
  • Loading branch information
SQc04 committed Jul 2, 2024
1 parent 6754d4f commit ddafd07
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion FSGaryityTool_Win11.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>0.2.34</VersionPrefix>
<VersionPrefix>0.2.35</VersionPrefix>
</PropertyGroup>


Expand Down
2 changes: 1 addition & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace FSGaryityTool_Win11
public sealed partial class MainWindow : Window
{

public static string FSSoftVersion = "0.2.34";
public static string FSSoftVersion = "0.2.35";
public static int FsPage = 0;
public static bool defWindowBackGround = true;
public static TomlTable settingstomlSp;
Expand Down
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.34.0" />
Version="0.2.35.0" />

<Properties>
<DisplayName>FSGaryityTool</DisplayName>
Expand Down
2 changes: 1 addition & 1 deletion Page1.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<Border x:Name="BorderBack1" CornerRadius="4" Background="{ThemeResource LayerOnAcrylicFillColorDefaultBrush}" Margin="6">
<TextBlock x:Name="BaudTextBlock" TextAlignment="Center" VerticalAlignment="Center" Width="120" Margin="0">BAUDRATE</TextBlock>
</Border>
<ComboBox x:Name="BANDComboBox" IsEditable="True" SelectionChanged="BANDComboBox_SelectionChanged" Width="108" Margin="6"></ComboBox>
<ComboBox x:Name="BANDComboBox" IsEditable="True" SelectionChanged="BANDComboBox_SelectionChanged" Width="108" Margin="6"></ComboBox>
<StackPanel.Transitions>
<TransitionCollection>
<RepositionThemeTransition />
Expand Down
68 changes: 50 additions & 18 deletions Page1.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
using Microsoft.Windows.ApplicationModel.Resources;
using FSGaryityTool_Win11.McuToolpage;
using System.Timers;
using System.Text.RegularExpressions;


// To learn more about WinUI, the WinUI project structure,
Expand Down Expand Up @@ -927,27 +928,44 @@ private void COMButtonIcon_Rotation(object name)

}

private void Settings_ColorValuesChanged(Windows.UI.ViewManagement.UISettings sender, object args)
private void OnThemeChanged(DependencyObject sender, DependencyProperty dp)
{
var color = sender.GetColorValue(Windows.UI.ViewManagement.UIColorType.Accent);
CONTButton.Background = new SolidColorBrush(color);
var darkaccentColor = (Windows.UI.Color)Application.Current.Resources["SystemAccentColorLight2"];
var ligtaccentColor = (Windows.UI.Color)Application.Current.Resources["SystemAccentColorDark1"];
// 当主题改变时,此函数会被调用
var theme = Application.Current.RequestedTheme;

if (Con == 1)
{
if (theme == ApplicationTheme.Dark) //设置连接按钮背景颜色
{
// 当前处于深色模式
CONTButton.Background = new SolidColorBrush(darkaccentColor);
CONTButton.Foreground = new SolidColorBrush(Colors.Black);
}
else if (theme == ApplicationTheme.Light)
{
// 当前处于浅色模式
CONTButton.Background = new SolidColorBrush(ligtaccentColor);
CONTButton.Foreground = new SolidColorBrush(Colors.White);
}
}
}



private void CONTButton_Click(object sender, RoutedEventArgs e)
{
var settings = new Windows.UI.ViewManagement.UISettings();
var color = settings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Accent);


var foregroundColor = COMButton.Foreground as SolidColorBrush;
var backgroundColor = COMButton.Background as SolidColorBrush;
var darkaccentColor = (Windows.UI.Color)Application.Current.Resources["SystemAccentColorLight2"];
var ligtaccentColor = (Windows.UI.Color)Application.Current.Resources["SystemAccentColorDark1"];
var theme = Application.Current.RequestedTheme;


settings.ColorValuesChanged += Settings_ColorValuesChanged;

// 获取当前窗口的句柄

if (Con == 0)
Expand Down Expand Up @@ -1525,28 +1543,42 @@ private void RXTextBox_TextChanged(object sender, TextChangedEventArgs e)
}
private void BANDComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (autosaveset == 1)
// 检查输入的是否为数字
if (!int.TryParse((string)BANDComboBox.SelectedItem, out int baudRate) || baudRate == 0)
{
// 如果输入的不是数字,使用设置文件中的数字覆盖它
using (StreamReader reader = File.OpenText(FSSetToml)) //打开TOML文件
{
settingstomlr = TOML.Parse(reader);

settingstomlr["SerialPortSettings"]["DefaultBAUD"] = (string)BANDComboBox.SelectedItem;
BANDComboBox.SelectedItem = ((Tommy.TomlString)settingstomlr["SerialPortSettings"]["DefaultBAUD"]).Value;
}
}
else
{
if (autosaveset == 1)
{
using (StreamReader reader = File.OpenText(FSSetToml)) //打开TOML文件
{
settingstomlr = TOML.Parse(reader);

using (StreamWriter writer = File.CreateText(FSSetToml)) //将设置写入TOML文件
settingstomlr["SerialPortSettings"]["DefaultBAUD"] = (string)BANDComboBox.SelectedItem;
}

using (StreamWriter writer = File.CreateText(FSSetToml)) //将设置写入TOML文件
{
settingstomlr.WriteTo(writer);
writer.Flush();
}
}
if (Con == 1)
{
settingstomlr.WriteTo(writer);
writer.Flush();
CommonRes._serialPort.BaudRate = Convert.ToInt32(BANDComboBox.SelectedItem);
RXTextBox.Text = RXTextBox.Text + "BaudRate = " + Convert.ToInt32(BANDComboBox.SelectedItem) + "\r\n";
}
baudrate = Convert.ToInt32(BANDComboBox.SelectedItem);
}
if (Con == 1)
{
CommonRes._serialPort.BaudRate = Convert.ToInt32(BANDComboBox.SelectedItem);
RXTextBox.Text = RXTextBox.Text + "BaudRate = " + Convert.ToInt32(BANDComboBox.SelectedItem) + "\r\n";
}
baudrate = Convert.ToInt32(BANDComboBox.SelectedItem);
}

private void PARComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (autosaveset == 1)
Expand Down
2 changes: 1 addition & 1 deletion Resources/zh_CN/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/zh_CN/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<comment>Settings Page text</comment>
</data>
<data name="base" xml:space="preserve">
<value>基础亚克力</value>
<value>亚克力</value>
<comment>Settings Page text</comment>
</data>
<data name="baudRatel" xml:space="preserve">
Expand Down

0 comments on commit ddafd07

Please sign in to comment.