更新Camera类的显示逻辑和温度数据处理
This commit is contained in:
@@ -83,10 +83,11 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新InfoImage显示
|
/// 更新InfoImage显示 - 按照用户要求的详细步骤:
|
||||||
/// 1. 如果暂停,显示暂停信息
|
/// 1. 以透明色清空Info
|
||||||
/// 2. 否则如果Ping不通或断开,显示重连信息
|
/// 2. 如果暂停,显示暂停信息,否则如果Ping不通或断开,显示重连信息,否则满足就绪条件
|
||||||
/// 3. 最后调用更新UI
|
/// 3. 在就绪条件下,如果有温度数据,显示最高温度
|
||||||
|
/// 4. 最后调用更新UI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateInfo()
|
private void UpdateInfo()
|
||||||
{
|
{
|
||||||
@@ -101,17 +102,19 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
// 检查连接状态
|
// 检查连接状态
|
||||||
bool isDisconnected = _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Disconnected;
|
bool isDisconnected = _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Disconnected;
|
||||||
bool isReconnecting = _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Reconnecting;
|
bool isReconnecting = _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Reconnecting;
|
||||||
|
bool isConnected = _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Connected;
|
||||||
bool isPaused = _isPaused; // 使用_isPaused标志判断暂停状态
|
bool isPaused = _isPaused; // 使用_isPaused标志判断暂停状态
|
||||||
bool isPingFailed = !IsDevicePingable;
|
bool isPingFailed = !IsDevicePingable;
|
||||||
|
bool isReady = !isPaused && !isPingFailed && isConnected; // 就绪条件:非暂停、可Ping通、已连接
|
||||||
// 根据用户要求的优先级显示信息:先检查暂停状态,然后再检查Ping状态和连接状态
|
|
||||||
|
|
||||||
using (Graphics g = Graphics.FromImage(_infoImage))
|
using (Graphics g = Graphics.FromImage(_infoImage))
|
||||||
{
|
{
|
||||||
// 以透明色清空Info
|
// 步骤1:以透明色清空Info
|
||||||
g.Clear(Color.Transparent);
|
g.Clear(Color.Transparent);
|
||||||
|
|
||||||
|
// 步骤2:检查暂停状态、Ping状态和连接状态
|
||||||
if (isPaused)
|
if (isPaused)
|
||||||
{
|
{
|
||||||
// 暂停状态 - 最高优先级
|
// 暂停状态 - 最高优先级
|
||||||
// 绘制暂停文本
|
// 绘制暂停文本
|
||||||
string text = "暂停";
|
string text = "暂停";
|
||||||
@@ -129,7 +132,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isPingFailed || isDisconnected || isReconnecting)
|
else if (isPingFailed || isDisconnected || isReconnecting)
|
||||||
{
|
{
|
||||||
// 非暂停状态下,检查Ping状态和连接状态
|
// 非暂停状态下,检查Ping状态和连接状态
|
||||||
|
|
||||||
// 确定显示的文本和颜色
|
// 确定显示的文本和颜色
|
||||||
@@ -164,17 +167,43 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
format);
|
format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (isReady)
|
||||||
|
{
|
||||||
|
// 步骤3:就绪条件下,如果有温度数据,显示最高温度
|
||||||
|
// 从DeviceManager获取最新的温度数据
|
||||||
|
if (_deviceManager != null)
|
||||||
|
{
|
||||||
|
TemperatureData temperatureData = _deviceManager.LastTemperature;
|
||||||
|
if (temperatureData != null)
|
||||||
|
{
|
||||||
|
// 有有效温度数据,显示最高温度
|
||||||
|
string tempText = $"最高温度: {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(tempText, font, textBrush,
|
||||||
|
new RectangleF(0, BUFFER_HEIGHT - 40, BUFFER_WIDTH, 40),
|
||||||
|
format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置显示标志
|
// 设置显示标志
|
||||||
_isDisplayingInfo = (isPaused || isDisconnected || isReconnecting);
|
_isDisplayingInfo = (isPaused || isDisconnected || isReconnecting);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用更新UI
|
// 步骤4:最后调用更新UI(注意:在DeviceManager_ImageReceived中已处理非暂停状态下的UI更新)
|
||||||
UpdateImageOnUI();
|
// 这里不再直接调用UpdateImageOnUI,避免重复更新
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"更新Info显示时出错: {ex.Message}");
|
Console.WriteLine($"更新Info显示时出错: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +277,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
Console.WriteLine($"[PauseDetection] 检测已恢复 - DeviceManager状态更新完成,连接状态: {_deviceManager?.ConnectionStatus}, 当前时间: {DateTime.Now.ToString("HH:mm:ss.fff")}");
|
Console.WriteLine($"[PauseDetection] 检测已恢复 - DeviceManager状态更新完成,连接状态: {_deviceManager?.ConnectionStatus}, 当前时间: {DateTime.Now.ToString("HH:mm:ss.fff")}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按照用户要求:暂停或恢复时,设置暂停状态,调用更新Info
|
// 修改流程第1点和第5点:暂停或恢复时,设置暂停状态,调用更新Info(在暂停状态下会显示暂停信息)
|
||||||
UpdateInfo();
|
UpdateInfo();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -566,8 +595,11 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
{
|
{
|
||||||
_isDevicePingable = value;
|
_isDevicePingable = value;
|
||||||
Console.WriteLine($"设备Ping状态变更: {(_isDevicePingable ? "可Ping通" : "不可Ping通")}");
|
Console.WriteLine($"设备Ping状态变更: {(_isDevicePingable ? "可Ping通" : "不可Ping通")}");
|
||||||
// 状态变化时调用更新Info
|
// 按照README中要求的修改流程第3点和第6点:Ping通状态变化时,只在非暂停状态下调用更新Info
|
||||||
UpdateInfo();
|
if (!_isPaused)
|
||||||
|
{
|
||||||
|
UpdateInfo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -618,14 +650,15 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按照README中要求的修改流程第5点和第6点:图像更新时,保存LastImage,只在非暂停状态下调用更新到UI
|
// 按照README中要求的修改流程第4点和第5点:图像更新时,保存LastImage,只在非暂停状态下调用更新Info和UI
|
||||||
this.BeginInvoke(new Action(() =>
|
this.BeginInvoke(new Action(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!_isPaused)
|
if (!_isPaused)
|
||||||
{
|
{
|
||||||
UpdateImageOnUI();
|
UpdateInfo(); // 先更新Info
|
||||||
|
UpdateImageOnUI(); // 然后更新UI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -953,7 +986,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按照README中要求的修改流程第2点和第6点:连接状态变化时,只在非暂停状态下调用更新Info
|
// 按照README中要求的修改流程第2点和第5点:断开或连接时,设置连接状态,只在非暂停状态下调用更新Info
|
||||||
if (!_isPaused)
|
if (!_isPaused)
|
||||||
{
|
{
|
||||||
UpdateInfo();
|
UpdateInfo();
|
||||||
@@ -979,7 +1012,7 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 按照README中要求的修改流程第2点和第6点:连接状态变化时,只在非暂停状态下调用更新Info
|
// 按照README中要求的修改流程第2点和第5点:断开或连接时,设置连接状态,只在非暂停状态下调用更新Info
|
||||||
if (!_isPaused)
|
if (!_isPaused)
|
||||||
{
|
{
|
||||||
UpdateInfo();
|
UpdateInfo();
|
||||||
@@ -1555,12 +1588,9 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
/// <param name="isPingable">是否可Ping通</param>
|
/// <param name="isPingable">是否可Ping通</param>
|
||||||
private void UpdatePingState(bool isPingable)
|
private void UpdatePingState(bool isPingable)
|
||||||
{
|
{
|
||||||
// 按照README中要求的修改流程第3点和第6点:Ping通状态变化时,修改Ping状态,只在非暂停状态下调用更新Info
|
// 按照README中要求的修改流程第3点:Ping通状态变化时,修改Ping状态
|
||||||
|
// 注意:UpdateInfo的调用已在IsDevicePingable的setter中实现(只在非暂停状态下)
|
||||||
IsDevicePingable = isPingable;
|
IsDevicePingable = isPingable;
|
||||||
if (!_isPaused)
|
|
||||||
{
|
|
||||||
UpdateInfo();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user