移除温度数据更新时调用UpdateInfo的逻辑,清理相关不再使用的变量和代码
This commit is contained in:
@@ -32,9 +32,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
private Image _infoImage = null;
|
private Image _infoImage = null;
|
||||||
|
|
||||||
// 最近一次获取到的温度数据
|
// 最近一次获取到的温度数据
|
||||||
private TemperatureData _lastTemperatureData = null;
|
|
||||||
// 用于保护_lastTemperatureData的线程锁
|
|
||||||
private readonly object _lastTemperatureDataLock = new object();
|
|
||||||
|
|
||||||
// 用于保护_lastImage的线程锁
|
// 用于保护_lastImage的线程锁
|
||||||
private readonly object _lastImageLock = new object();
|
private readonly object _lastImageLock = new object();
|
||||||
@@ -78,16 +76,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取最近一次接收到的温度数据
|
/// 获取最近一次接收到的温度数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TemperatureData LastTemperatureData
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
lock (_lastTemperatureDataLock)
|
|
||||||
{
|
|
||||||
return _lastTemperatureData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备管理器温度数据接收事件处理
|
/// 设备管理器温度数据接收事件处理
|
||||||
@@ -105,19 +94,8 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新最近一次温度数据
|
|
||||||
lock (_lastTemperatureDataLock)
|
|
||||||
{
|
|
||||||
_lastTemperatureData = e.TemperatureData;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("温度数据已更新");
|
Console.WriteLine("温度数据已更新");
|
||||||
|
// 不再更新Info,根据新要求移除更新Info的逻辑
|
||||||
// 按照README中要求的修改流程第4点和第6点:温度数据更新时,只在非暂停状态下调用更新Info
|
|
||||||
if (!_isPaused)
|
|
||||||
{
|
|
||||||
UpdateInfo();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -142,10 +120,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
/// 更新InfoImage显示
|
/// 更新InfoImage显示
|
||||||
/// 1. 如果暂停,显示暂停信息
|
/// 1. 如果暂停,显示暂停信息
|
||||||
/// 2. 否则如果Ping不通或断开,显示重连信息
|
/// 2. 否则如果Ping不通或断开,显示重连信息
|
||||||
/// 3. 否则满足就绪条件
|
/// 3. 最后调用更新UI
|
||||||
/// - 在就绪条件下,如果有温度数据,显示最高温度
|
|
||||||
/// - 否则清空Info
|
|
||||||
/// 4. 最后调用更新UI
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateInfo()
|
private void UpdateInfo()
|
||||||
{
|
{
|
||||||
@@ -163,13 +138,6 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
bool isPaused = _isPaused; // 使用_isPaused标志判断暂停状态
|
bool isPaused = _isPaused; // 使用_isPaused标志判断暂停状态
|
||||||
bool isPingFailed = !IsDevicePingable;
|
bool isPingFailed = !IsDevicePingable;
|
||||||
|
|
||||||
// 获取温度数据
|
|
||||||
TemperatureData temperatureData = null;
|
|
||||||
lock (_lastTemperatureDataLock)
|
|
||||||
{
|
|
||||||
temperatureData = _lastTemperatureData;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据用户要求的优先级显示信息:先检查暂停状态,然后再检查Ping状态和连接状态
|
// 根据用户要求的优先级显示信息:先检查暂停状态,然后再检查Ping状态和连接状态
|
||||||
|
|
||||||
using (Graphics g = Graphics.FromImage(_infoImage))
|
using (Graphics g = Graphics.FromImage(_infoImage))
|
||||||
@@ -230,36 +198,10 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
format);
|
format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// 就绪条件:非暂停、Ping可通、连接正常
|
|
||||||
if (temperatureData != null)
|
|
||||||
{
|
|
||||||
// 有温度数据,显示最高温度
|
|
||||||
string text = $"最高温度: {temperatureData.MaxTemperature:F2}°C";
|
|
||||||
Color textColor = Color.White;
|
|
||||||
|
|
||||||
using (Font font = new Font("Arial", 24, FontStyle.Bold))
|
|
||||||
using (SolidBrush textBrush = new SolidBrush(textColor))
|
|
||||||
{
|
|
||||||
StringFormat format = new StringFormat() { Alignment = StringAlignment.Center };
|
|
||||||
|
|
||||||
// 将最高温度文本居中显示
|
|
||||||
g.DrawString(text, font, textBrush,
|
|
||||||
new RectangleF(0, BUFFER_HEIGHT / 2 - 24, BUFFER_WIDTH, 48),
|
|
||||||
format);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 没有温度数据,清空Info
|
|
||||||
g.Clear(Color.Transparent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置显示标志
|
// 设置显示标志
|
||||||
_isDisplayingInfo = (isPaused || isDisconnected || isReconnecting || (temperatureData != null));
|
_isDisplayingInfo = (isPaused || isDisconnected || isReconnecting);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用更新UI
|
// 调用更新UI
|
||||||
@@ -1086,12 +1028,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当TCP连接断开时,将最近一次温度数据实例设为null
|
|
||||||
lock (_lastTemperatureDataLock)
|
|
||||||
{
|
|
||||||
_lastTemperatureData = null;
|
|
||||||
Console.WriteLine("温度数据实例已清空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 按照README中要求的修改流程第2点和第6点:连接状态变化时,只在非暂停状态下调用更新Info
|
// 按照README中要求的修改流程第2点和第6点:连接状态变化时,只在非暂停状态下调用更新Info
|
||||||
if (!_isPaused)
|
if (!_isPaused)
|
||||||
@@ -1747,12 +1684,6 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
_deviceManager.ConnectionStatusChanged -= DeviceManager_ConnectionStatusChanged;
|
_deviceManager.ConnectionStatusChanged -= DeviceManager_ConnectionStatusChanged;
|
||||||
_deviceManager.ConnectionException -= DeviceManager_ConnectionException;
|
_deviceManager.ConnectionException -= DeviceManager_ConnectionException;
|
||||||
_deviceManager.TemperatureReceived -= DeviceManager_TemperatureReceived;
|
_deviceManager.TemperatureReceived -= DeviceManager_TemperatureReceived;
|
||||||
|
|
||||||
// 释放温度数据资源
|
|
||||||
lock (_lastTemperatureDataLock)
|
|
||||||
{
|
|
||||||
_lastTemperatureData = null;
|
|
||||||
}
|
|
||||||
// 释放设备管理器资源
|
// 释放设备管理器资源
|
||||||
_deviceManager.Dispose();
|
_deviceManager.Dispose();
|
||||||
_deviceManager = null;
|
_deviceManager = null;
|
||||||
@@ -1887,18 +1818,13 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
// 如果用户选择了文件路径
|
// 如果用户选择了文件路径
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
// 使用已缓存的温度数据
|
// 现在直接从设备管理器获取温度数据,不再使用缓存的温度数据
|
||||||
TemperatureData temperatureData;
|
// 调用设备管理器的方法获取最新的温度数据
|
||||||
lock (_lastTemperatureDataLock)
|
if (!_deviceManager.GetTemperatureData())
|
||||||
{
|
{
|
||||||
temperatureData = _lastTemperatureData;
|
MessageBox.Show("获取温度数据失败,请确保设备已连接且正在接收数据。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if (temperatureData == null)
|
|
||||||
{
|
|
||||||
MessageBox.Show("没有可用的温度数据,请确保设备已连接且正在接收数据。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存温度数据到CSV文件
|
// 保存温度数据到CSV文件
|
||||||
using (StreamWriter writer = new StreamWriter(saveFileDialog.FileName))
|
using (StreamWriter writer = new StreamWriter(saveFileDialog.FileName))
|
||||||
|
|||||||
Reference in New Issue
Block a user