Before update to NET 7
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Timers;
|
||||
using BITFactory;
|
||||
using BITKit;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
namespace BITFactory;
|
||||
public partial class IDIS_THService : Node
|
||||
@@ -12,14 +18,38 @@ public partial class IDIS_THService : Node
|
||||
|
||||
[ExportCategory("UI 绑定")]
|
||||
[Export] private Button submitButton;
|
||||
[Export] private CheckButton autoUpdateButton;
|
||||
[Export] private LineEdit handleEdit;
|
||||
[Export] private LineEdit temperatureEdit;
|
||||
[Export] private LineEdit humidityEdit;
|
||||
[Export] private RichTextLabel hintsLabel;
|
||||
[Export] private RichTextLabel autoUpdateLabel;
|
||||
|
||||
private Timer autoUpdateTimer;
|
||||
public override void _Ready()
|
||||
{
|
||||
submitButton.Pressed += Submit;
|
||||
autoUpdateButton.Toggled += toggle =>
|
||||
{
|
||||
submitButton.Disabled = toggle;
|
||||
handleEdit.Editable = !toggle;
|
||||
temperatureEdit.Editable = !toggle;
|
||||
humidityEdit.Editable = !toggle;
|
||||
autoUpdateTimer.Enabled = toggle;
|
||||
};
|
||||
|
||||
autoUpdateTimer = new Timer();
|
||||
autoUpdateTimer.AutoReset = true;
|
||||
autoUpdateTimer.Interval = 1000;
|
||||
autoUpdateTimer.Elapsed += AutoUpdate;
|
||||
}
|
||||
|
||||
private async void AutoUpdate(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
|
||||
UpdateByReader();
|
||||
}
|
||||
|
||||
private void Submit()
|
||||
{
|
||||
switch (handleEdit.Text, temperatureEdit.Text, humidityEdit.Text)
|
||||
@@ -57,6 +87,21 @@ public partial class IDIS_THService : Node
|
||||
|
||||
private void UpdateByReader()
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(handleEdit.Text))
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("空的标识码");
|
||||
return;
|
||||
}
|
||||
if (service.Update(handleEdit.Text, "温度", thReader.temperature.ToString(CultureInfo.InvariantCulture)) is false)
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("温度更新失败,未知异常");
|
||||
return;
|
||||
}
|
||||
if (service.Update(handleEdit.Text, "湿度", thReader.humidity.ToString(CultureInfo.InvariantCulture)) is false)
|
||||
{
|
||||
autoUpdateLabel.SetTextAsync("湿度更新失败,未知异常");
|
||||
return;
|
||||
}
|
||||
autoUpdateLabel.SetTextAsync($"温湿度已自动更新:{DateTime.Now}");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user