修复Camera.cs和V8.cs中的问题:移除多余的.Value访问器和添加温补值全局保存功能
This commit is contained in:
@@ -169,29 +169,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 就绪条件下,根据用户要求不再显示温度数据
|
||||
}
|
||||
}
|
||||
|
||||
@@ -785,6 +763,51 @@ namespace JoyD.Windows.CS.Toprie
|
||||
g.DrawString("测试信息", font, textBrush, 10, 10);
|
||||
}
|
||||
}
|
||||
|
||||
// 步骤3:在就绪条件下,如果有温度数据(时间在最近3秒内),显示最高温度(居中显示)
|
||||
if (!_isPaused && IsDevicePingable && _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Connected)
|
||||
{
|
||||
TemperatureData temperatureData = _deviceManager.LastTemperature;
|
||||
if (temperatureData != null && temperatureData.Timestamp != null)
|
||||
{
|
||||
// 检查温度数据时间是否在最近3秒内
|
||||
TimeSpan timeDiff = DateTime.Now - temperatureData.Timestamp;
|
||||
if (timeDiff.TotalSeconds <= 3)
|
||||
{
|
||||
// 有有效温度数据,居中显示最高温度
|
||||
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,
|
||||
LineAlignment = StringAlignment.Center
|
||||
};
|
||||
|
||||
// 计算文本位置,确保居中显示
|
||||
RectangleF textRect = new RectangleF(0, 0, BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
|
||||
// 添加半透明背景以提高可读性
|
||||
SizeF textSize = g.MeasureString(tempText, font);
|
||||
RectangleF bgRect = new RectangleF(
|
||||
(BUFFER_WIDTH - textSize.Width - 20) / 2,
|
||||
(BUFFER_HEIGHT - textSize.Height - 20) / 2,
|
||||
textSize.Width + 20,
|
||||
textSize.Height + 20
|
||||
);
|
||||
using (SolidBrush bgBrush = new SolidBrush(Color.FromArgb(128, 0, 0, 0)))
|
||||
{
|
||||
g.FillRectangle(bgBrush, bgRect);
|
||||
}
|
||||
|
||||
// 居中绘制温度信息
|
||||
g.DrawString(tempText, font, textBrush, textRect, format);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 在同一个锁内创建缓冲区的副本,避免重复锁定
|
||||
|
||||
@@ -13,18 +13,18 @@
|
||||
1. 暂停或恢复时,设置暂停状态,调用更新Info
|
||||
2. 断开或连接时,设置连接状态,调用更新Info
|
||||
3. Ping通状态变化时,修改Ping状态,调用更新Info
|
||||
4. 图像更新时,保存LastImage,调用更新Info
|
||||
4. 图像更新时,保存LastImage,调用更新UI
|
||||
5. 2-4 只在非暂停状态下调用更新,暂停状态下不更新Info和UI
|
||||
|
||||
### 更新Info
|
||||
1. 以透明色清空Info
|
||||
2. 如果暂停,显示暂停信息,否则如果Ping不通或断开,显示重连信息 否则满足就绪条件
|
||||
3. 在就绪条件下,如果有温度数据,显示最高温度
|
||||
4. 最后调用更新UI
|
||||
3. 最后调用更新UI
|
||||
|
||||
### 更新UI
|
||||
1. 先将LastImage绘制到全局缓冲
|
||||
2. 再将InfoImage绘制到缓冲
|
||||
3. 在就绪条件下,如果有温度数据(时间在最近3秒内),显示最高温度(居中显示)
|
||||
3. 最后一次性绘制到图像框的bitmap
|
||||
|
||||
## TCP温度数据接收
|
||||
|
||||
@@ -2324,6 +2324,9 @@ namespace JoyD.Windows.CS.Toprie
|
||||
}
|
||||
}
|
||||
|
||||
// 私有字段,用于存储最后一次成功获取的温补值
|
||||
private int _lastSuccessfulCompTemp = 0;
|
||||
|
||||
public int Comp_temp
|
||||
{
|
||||
get
|
||||
@@ -2347,16 +2350,22 @@ namespace JoyD.Windows.CS.Toprie
|
||||
}
|
||||
if (int.TryParse(valueStr, out int result))
|
||||
{
|
||||
// 查询成功,更新并返回温补值
|
||||
_lastSuccessfulCompTemp = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 查询失败但有上一次成功的值,则返回上一次的值
|
||||
Console.WriteLine("温补查询失败,使用上一次成功的温补值");
|
||||
return _lastSuccessfulCompTemp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"获取补偿温度失败: {ex.Message}");
|
||||
Console.WriteLine($"获取补偿温度失败: {ex.Message},使用上一次成功的温补值");
|
||||
// 异常情况下也返回上一次成功的值
|
||||
return _lastSuccessfulCompTemp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user