修改断连更新逻辑
This commit is contained in:
@@ -1528,6 +1528,10 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
if (!_isPaused)
|
if (!_isPaused)
|
||||||
{
|
{
|
||||||
UpdateInfo();
|
UpdateInfo();
|
||||||
|
// 连接成功时,更新实时温度信息,确保测温区立即显示
|
||||||
|
UpdateRealTimeInfoOnUI();
|
||||||
|
// 直接调用UpdateImageOnUI(),确保界面立即刷新
|
||||||
|
UpdateImageOnUI();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ConnectionStatus.Disconnected:
|
case ConnectionStatus.Disconnected:
|
||||||
@@ -1550,7 +1554,17 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 连接断开时,清空_displayImage,不显示测温区
|
||||||
|
lock (_displayImageLock)
|
||||||
|
{
|
||||||
|
if (_displayImage != null)
|
||||||
|
{
|
||||||
|
using (Graphics g = Graphics.FromImage(_displayImage))
|
||||||
|
{
|
||||||
|
g.Clear(Color.Transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 按照README中要求的修改流程第2点和第5点:断开或连接时,设置连接状态,只在非暂停状态下调用更新Info
|
// 按照README中要求的修改流程第2点和第5点:断开或连接时,设置连接状态,只在非暂停状态下调用更新Info
|
||||||
if (!_isPaused)
|
if (!_isPaused)
|
||||||
@@ -1579,6 +1593,18 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
WriteLog($"正在重新连接设备...{(!string.IsNullOrEmpty(e.DeviceInfo) ? " " + e.DeviceInfo : "")}");
|
WriteLog($"正在重新连接设备...{(!string.IsNullOrEmpty(e.DeviceInfo) ? " " + e.DeviceInfo : "")}");
|
||||||
ShowError(string.Empty); // 清除之前的错误信息
|
ShowError(string.Empty); // 清除之前的错误信息
|
||||||
|
|
||||||
|
// 正在重连时,清空_displayImage,不显示测温区
|
||||||
|
lock (_displayImageLock)
|
||||||
|
{
|
||||||
|
if (_displayImage != null)
|
||||||
|
{
|
||||||
|
using (Graphics g = Graphics.FromImage(_displayImage))
|
||||||
|
{
|
||||||
|
g.Clear(Color.Transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 按照README中要求的修改流程第2点和第6点:连接状态变化时,只在非暂停状态下调用更新Info
|
// 按照README中要求的修改流程第2点和第6点:连接状态变化时,只在非暂停状态下调用更新Info
|
||||||
if (_isFirst || !_isPaused)
|
if (_isFirst || !_isPaused)
|
||||||
{
|
{
|
||||||
@@ -3173,144 +3199,149 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
|
|
||||||
if (_deviceManager.CurrentImageMode == ImageMode.Infrared)
|
if (_deviceManager.CurrentImageMode == ImageMode.Infrared)
|
||||||
{
|
{
|
||||||
// 1. 先绘制区域框线,不受温度数据影响,只受显示设置影响
|
// 只有在设备连接状态下才绘制测温区
|
||||||
if (_showAreaTemperature)
|
if (_deviceManager.ConnectionStatus == ConnectionStatus.Connected)
|
||||||
{
|
{
|
||||||
try
|
// 1. 先绘制区域框线,不受温度数据影响,只受显示设置影响
|
||||||
|
if (_showAreaTemperature)
|
||||||
{
|
{
|
||||||
// 使用固定的字体和格式对象绘制区域编号
|
try
|
||||||
using (Font font = new Font("微软雅黑", 10, FontStyle.Bold))
|
|
||||||
{
|
{
|
||||||
// 遍历已加载的测温区列表,绘制每个区域的框线和编号
|
// 使用固定的字体和格式对象绘制区域编号
|
||||||
foreach (TemperatureZone zone in _loadedTemperatureZones)
|
using (Font font = new Font("微软雅黑", 10, FontStyle.Bold))
|
||||||
{
|
{
|
||||||
// 将相对坐标转换为绝对坐标
|
// 遍历已加载的测温区列表,绘制每个区域的框线和编号
|
||||||
int absoluteX = _detectionZone.X + zone.X;
|
foreach (TemperatureZone zone in _loadedTemperatureZones)
|
||||||
int absoluteY = _detectionZone.Y + zone.Y;
|
|
||||||
|
|
||||||
// 创建画笔,使用区域的颜色作为框线颜色
|
|
||||||
using (Pen pen = new Pen(zone.Color, 2))
|
|
||||||
{
|
{
|
||||||
// 绘制区域框线
|
// 将相对坐标转换为绝对坐标
|
||||||
g.DrawRectangle(pen, absoluteX, absoluteY, zone.Width, zone.Height);
|
int absoluteX = _detectionZone.X + zone.X;
|
||||||
}
|
int absoluteY = _detectionZone.Y + zone.Y;
|
||||||
|
|
||||||
// 创建画刷,使用区域的颜色作为文字颜色
|
// 创建画笔,使用区域的颜色作为框线颜色
|
||||||
using (Brush brush = new SolidBrush(zone.Color))
|
using (Pen pen = new Pen(zone.Color, 2))
|
||||||
{
|
{
|
||||||
// 绘制区域编号,编号显示在区域左上角
|
// 绘制区域框线
|
||||||
PointF numberPosition = new PointF(absoluteX + 5, absoluteY + 5);
|
g.DrawRectangle(pen, absoluteX, absoluteY, zone.Width, zone.Height);
|
||||||
g.DrawString(zone.Index.ToString(), font, brush, numberPosition);
|
}
|
||||||
|
|
||||||
|
// 创建画刷,使用区域的颜色作为文字颜色
|
||||||
|
using (Brush brush = new SolidBrush(zone.Color))
|
||||||
|
{
|
||||||
|
// 绘制区域编号,编号显示在区域左上角
|
||||||
|
PointF numberPosition = new PointF(absoluteX + 5, absoluteY + 5);
|
||||||
|
g.DrawString(zone.Index.ToString(), font, brush, numberPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
Console.WriteLine($"绘制区域框时发生异常: {ex.Message}");
|
||||||
Console.WriteLine($"绘制区域框时发生异常: {ex.Message}");
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 温度数据绘制逻辑,仍受温度数据有效性影响
|
// 只有在设备连接状态下才绘制温度数据
|
||||||
TemperatureData temperatureData = _deviceManager.LastTemperature;
|
if (_deviceManager.ConnectionStatus == ConnectionStatus.Connected)
|
||||||
if (temperatureData != null && temperatureData.Timestamp != null)
|
|
||||||
{
|
{
|
||||||
TimeSpan timeDiff = DateTime.Now - temperatureData.Timestamp;
|
// 2. 温度数据绘制逻辑,仍受温度数据有效性影响
|
||||||
if (timeDiff.TotalSeconds <= 3)
|
TemperatureData temperatureData = _deviceManager.LastTemperature;
|
||||||
|
if (temperatureData != null && temperatureData.Timestamp != null)
|
||||||
{
|
{
|
||||||
// 3. 温度显示菜单下如果未勾选区域温度和全局温度,则不显示任何温度信息
|
TimeSpan timeDiff = DateTime.Now - temperatureData.Timestamp;
|
||||||
if (!_showGlobalTemperature && !_showAreaTemperature)
|
if (timeDiff.TotalSeconds <= 3)
|
||||||
return;
|
|
||||||
|
|
||||||
// 4. 如果勾选了全局温度且未勾选区域温度,则显示全局温度(居中显示),否则显示区域温度(居中显示)
|
|
||||||
bool isGlobalTemperatureMode = _showGlobalTemperature && !_showAreaTemperature;
|
|
||||||
|
|
||||||
// 5. 根据温度模式显示温度数据
|
|
||||||
if (isGlobalTemperatureMode)
|
|
||||||
{
|
{
|
||||||
// 准备温度文本
|
// 3. 温度显示菜单下如果未勾选区域温度和全局温度,则不显示任何温度信息
|
||||||
List<string> temperatureTexts = new List<string>();
|
if (!_showGlobalTemperature && !_showAreaTemperature)
|
||||||
if (_showAverageTemperature)
|
|
||||||
{
|
|
||||||
temperatureTexts.Add($"平均: {temperatureData.AverageTemperature:F2} °C");
|
|
||||||
}
|
|
||||||
if (_showMinTemperature)
|
|
||||||
{
|
|
||||||
temperatureTexts.Add($"最低: {temperatureData.MinTemperature:F2} °C");
|
|
||||||
}
|
|
||||||
if (_showMaxTemperature)
|
|
||||||
{
|
|
||||||
temperatureTexts.Add($"最高: {temperatureData.MaxTemperature:F2} °C");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 记录温度数据日志
|
|
||||||
if (temperatureTexts.Count > 0)
|
|
||||||
{
|
|
||||||
WriteLog($"全局温度数据 - 平均: {temperatureData.AverageTemperature:F2} °C, 最低: {temperatureData.MinTemperature:F2} °C, 最高: {temperatureData.MaxTemperature:F2} °C");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果没有要显示的温度文本,直接返回
|
|
||||||
if (temperatureTexts.Count == 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 将List<string>转换为string[],以便传递给DrawTextInAreaCentered方法
|
// 4. 如果勾选了全局温度且未勾选区域温度,则显示全局温度(居中显示),否则显示区域温度(居中显示)
|
||||||
string[] textsArray = temperatureTexts.ToArray();
|
bool isGlobalTemperatureMode = _showGlobalTemperature && !_showAreaTemperature;
|
||||||
|
|
||||||
// 调用DrawTextInAreaCentered方法绘制温度文本
|
// 5. 根据温度模式显示温度数据
|
||||||
DrawTextInAreaCentered(g, textsArray);
|
if (isGlobalTemperatureMode)
|
||||||
}
|
|
||||||
else if (_showAreaTemperature)
|
|
||||||
{
|
|
||||||
// 区域温度模式:为每个区域计算并显示温度数据
|
|
||||||
foreach (TemperatureZone zone in _loadedTemperatureZones)
|
|
||||||
{
|
{
|
||||||
// 准备温度文本
|
// 准备温度文本
|
||||||
List<string> areaTemperatureTexts = new List<string>();
|
List<string> temperatureTexts = new List<string>();
|
||||||
|
if (_showAverageTemperature)
|
||||||
// 直接从ZoneTemperatures字典获取已计算好的区域温度数据
|
|
||||||
if (temperatureData.ZoneTemperatures.TryGetValue(zone.Index, out var zoneTempData))
|
|
||||||
{
|
{
|
||||||
if (_showMaxTemperature)
|
temperatureTexts.Add($"平均: {temperatureData.AverageTemperature:F2} °C");
|
||||||
{
|
}
|
||||||
areaTemperatureTexts.Add($"最高: {zoneTempData.MaxTemperature:F2} °C");
|
if (_showMinTemperature)
|
||||||
}
|
{
|
||||||
if (_showMinTemperature)
|
temperatureTexts.Add($"最低: {temperatureData.MinTemperature:F2} °C");
|
||||||
{
|
}
|
||||||
areaTemperatureTexts.Add($"最低: {zoneTempData.MinTemperature:F2} °C");
|
if (_showMaxTemperature)
|
||||||
}
|
{
|
||||||
if (_showAverageTemperature)
|
temperatureTexts.Add($"最高: {temperatureData.MaxTemperature:F2} °C");
|
||||||
{
|
|
||||||
areaTemperatureTexts.Add($"平均: {zoneTempData.AverageTemperature:F2} °C");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将相对坐标转换为绝对坐标
|
// 记录温度数据日志
|
||||||
int absoluteX = _detectionZone.X + zone.X;
|
if (temperatureTexts.Count > 0)
|
||||||
int absoluteY = _detectionZone.Y + zone.Y;
|
|
||||||
|
|
||||||
// 如果有温度文本需要绘制
|
|
||||||
if (areaTemperatureTexts.Count > 0)
|
|
||||||
{
|
{
|
||||||
// 创建表示测温区的矩形区域
|
WriteLog($"全局温度数据 - 平均: {temperatureData.AverageTemperature:F2} °C, 最低: {temperatureData.MinTemperature:F2} °C, 最高: {temperatureData.MaxTemperature:F2} °C");
|
||||||
RectangleF zoneArea = new RectangleF(absoluteX, absoluteY, zone.Width, zone.Height);
|
}
|
||||||
|
|
||||||
// 将List<string>转换为string[],以便传递给DrawTextInAreaCentered方法
|
// 如果没有要显示的温度文本,直接返回
|
||||||
string[] textsArray = areaTemperatureTexts.ToArray();
|
if (temperatureTexts.Count == 0)
|
||||||
|
return;
|
||||||
// 调用DrawTextInAreaCentered方法绘制温度文本,文本会在区域内垂直居中
|
|
||||||
DrawTextInAreaCentered(g, textsArray, zone.Color, zoneArea);
|
// 将List<string>转换为string[],以便传递给DrawTextInAreaCentered方法
|
||||||
|
string[] textsArray = temperatureTexts.ToArray();
|
||||||
|
|
||||||
|
// 调用DrawTextInAreaCentered方法绘制温度文本
|
||||||
|
DrawTextInAreaCentered(g, textsArray);
|
||||||
|
}
|
||||||
|
else if (_showAreaTemperature)
|
||||||
|
{
|
||||||
|
// 区域温度模式:为每个区域计算并显示温度数据
|
||||||
|
foreach (TemperatureZone zone in _loadedTemperatureZones)
|
||||||
|
{
|
||||||
|
// 准备温度文本
|
||||||
|
List<string> areaTemperatureTexts = new List<string>();
|
||||||
|
|
||||||
|
// 直接从ZoneTemperatures字典获取已计算好的区域温度数据
|
||||||
|
if (temperatureData.ZoneTemperatures.TryGetValue(zone.Index, out var zoneTempData))
|
||||||
|
{
|
||||||
|
if (_showMaxTemperature)
|
||||||
|
{
|
||||||
|
areaTemperatureTexts.Add($"最高: {zoneTempData.MaxTemperature:F2} °C");
|
||||||
|
}
|
||||||
|
if (_showMinTemperature)
|
||||||
|
{
|
||||||
|
areaTemperatureTexts.Add($"最低: {zoneTempData.MinTemperature:F2} °C");
|
||||||
|
}
|
||||||
|
if (_showAverageTemperature)
|
||||||
|
{
|
||||||
|
areaTemperatureTexts.Add($"平均: {zoneTempData.AverageTemperature:F2} °C");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将相对坐标转换为绝对坐标
|
||||||
|
int absoluteX = _detectionZone.X + zone.X;
|
||||||
|
int absoluteY = _detectionZone.Y + zone.Y;
|
||||||
|
|
||||||
|
// 如果有温度文本需要绘制
|
||||||
|
if (areaTemperatureTexts.Count > 0)
|
||||||
|
{
|
||||||
|
// 创建表示测温区的矩形区域
|
||||||
|
RectangleF zoneArea = new RectangleF(absoluteX, absoluteY, zone.Width, zone.Height);
|
||||||
|
|
||||||
|
// 将List<string>转换为string[],以便传递给DrawTextInAreaCentered方法
|
||||||
|
string[] textsArray = areaTemperatureTexts.ToArray();
|
||||||
|
|
||||||
|
// 调用DrawTextInAreaCentered方法绘制温度文本,文本会在区域内垂直居中
|
||||||
|
DrawTextInAreaCentered(g, textsArray, zone.Color, zoneArea);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置显示状态标志
|
||||||
|
_isDisplayingInfo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置显示状态标志
|
|
||||||
_isDisplayingInfo = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 标记信息正在显示
|
|
||||||
_isDisplayingInfo = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,6 @@ using System.Runtime.InteropServices;
|
|||||||
//通过使用 "*",如下所示:
|
//通过使用 "*",如下所示:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.2.5")]
|
[assembly: AssemblyVersion("1.0.2.5")]
|
||||||
[assembly: AssemblyFileVersion("1.0.2.6")]
|
[assembly: AssemblyFileVersion("1.0.2.7")]
|
||||||
|
|
||||||
// NuGet包相关信息已在项目文件中配置
|
// NuGet包相关信息已在项目文件中配置
|
||||||
|
|||||||
Reference in New Issue
Block a user