linjpxc 5 năm trước cách đây
mục cha
commit
50ba5171a9
2 tập tin đã thay đổi với 129 bổ sung157 xóa
  1. 1 1
      IPCALLServicePro/comGlobalVars.vb
  2. 128 156
      LatticeScreenServer/Hards/LedControl.cs

+ 1 - 1
IPCALLServicePro/comGlobalVars.vb

@@ -605,7 +605,7 @@ Module comGlobalVars
                 If Val(Temp(1)) = 0 Then
                     Temp(1) = Temp(2)
                 End If
-                'SysLedContrl.DeleteCallingProgram(Temp(1) + "W")
+                SysLedContrl.DeleteCallingProgram(Temp(1) + "W", Temp(10))
                 TempStr = ParseStr(SpeechWCCalling, Temp)
                 SpeechDelStr(TempStr)
                 SpeechPause(False)

+ 128 - 156
LatticeScreenServer/Hards/LedControl.cs

@@ -315,9 +315,7 @@ namespace HNWD.LatticeScreen
 
         private static string lastText = string.Empty;
 
-        private static ConcurrentDictionary<IntPtr, List<DrawText>> drawList = new ConcurrentDictionary<IntPtr, List<DrawText>>();
-
-        private static DrawText[] lastDraw = new DrawText[0];
+        private static DrawText? lastDateTime;
 
         public static int JHDrawText(IntPtr hdl, short x, short y, ushort width, ushort height, uint format, string ptext)
         {
@@ -330,50 +328,63 @@ namespace HNWD.LatticeScreen
             {
                 return -1;
             }
+
             lock (domain.Sync)
             {
-                var list = drawList.AddOrUpdate(hdl,
-                    new List<DrawText>()
-                    {
-                        new DrawText()
-                            {Format = format, Location = new Point(x, y), Size = new Size(width, height), Text = ptext}
-                    }, (key, value) =>
+                if (lastText == ptext)
+                {
+                    return 0;
+                }
+
+                var isDateTime = IsDateTimeText(ptext, out var dateStyle, out var timeStyle);
+                if (isDateTime)
+                {
+                    if (width < domain.Size.Width || height < domain.Size.Height)
                     {
-                        if (value == null)
+                        if (!lastDateTime.HasValue)
                         {
-                            value = new List<DrawText>();
+                            lastDateTime = new DrawText()
+                            {
+                                Format = format,
+                                Location = new Point(x, y),
+                                Size = new Size(width, height),
+                                Text = ptext
+                            };
+                            return 0;
                         }
 
-                        var tmp = new DrawText()
+                        var tmpText = lastDateTime.Value.Text;
+                        if (IsDateTimeText(tmpText, out var dateStyleTmp, out var timeStyleTmp))
                         {
-                            Format = format,
-                            Location = new Point(x, y),
-                            Size = new Size(width, height),
-                            Text = ptext
-                        };
-                        if (!value.Contains(tmp))
-                        {
-                            value.Add(tmp);
+                            if (dateStyle == dateStyleTmp && timeStyle == timeStyleTmp)
+                            {
+                                return 0;
+                            }
                         }
 
-                        return value;
-                    });
-
-                var allWidth = list.Sum(item => item.Size.Width);
-                if (allWidth > 0 && allWidth < domain.Size.Width)
-                {
-                    return 0;
-                }
+                        if (tmpText.EndsWith(" "))
+                        {
+                            ptext = tmpText + ptext;
+                        }
+                        else
+                        {
+                            ptext = tmpText + " " + ptext;
+                        }
 
-                var allHeight = list.Sum(item => item.Size.Height);
-                if (allHeight > 0 && allHeight < domain.Size.Height)
-                {
-                    return 0;
-                }
+                        IsDateTimeText(ptext, out dateStyle, out timeStyle);
+                    }
+                    else
+                    {
+                        lastDateTime = null;
+                    }
 
-                if (StructuralComparisons.StructuralEqualityComparer.Equals(list.ToArray(), lastDraw))
-                {
-                    return 0;
+                    if (IsDateTimeText(lastText, out var tmpDateStyle, out var tmpTimeStyle))
+                    {
+                        if (dateStyle == tmpDateStyle && timeStyle == tmpTimeStyle)
+                        {
+                            return 0;
+                        }
+                    }
                 }
 
                 bx_sdk_dual.EQprogramHeader_G6 header;
@@ -409,137 +420,82 @@ namespace HNWD.LatticeScreen
 
                 ushort areaId = 0;
 
-                var empty = list.FirstOrDefault(item => string.IsNullOrEmpty(item.Text) && item.Size.Width >= domain.Size.Width && item.Size.Height >= domain.Size.Height);
-                var isEmpty = empty.Equals(default(DrawText));
-
-                if (isEmpty)
+                if (isDateTime)
                 {
-                    StopEraseThreead();
-                    foreach (var item in list)
+                    var aheader = new bx_sdk_dual.EQareaHeader_G6();
+                    aheader.AreaX = 0;
+                    aheader.AreaY = 0;
+                    aheader.AreaWidth = (ushort)domain.Size.Width;
+                    aheader.AreaHeight = (ushort)domain.Size.Height;
+                    aheader.Transparency = 101;
+                    aheader.AreaType = (byte)bx_sdk_dual.AreaType.DateTime;
+
+                    ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQareaHeader_G6)));
+                    Marshal.StructureToPtr(aheader, ptr, false);
+
+                    err = bx_sdk_dual.program_addArea_G6(areaId, ptr);
+                    if (err != 0)
                     {
-                        var aheader = new bx_sdk_dual.EQareaHeader_G6();
-                        aheader.AreaX = (ushort)item.Location.X;
-                        aheader.AreaY = (ushort)item.Location.Y;
-                        aheader.AreaWidth = (ushort)item.Size.Width;
-                        aheader.AreaHeight = (ushort)item.Size.Height;
-                        aheader.BackGroundFlag = 0x00;
-                        aheader.Transparency = 101;
-
-                        var isDateTime = IsDateTimeText(item.Text, out var dateStyle, out var timeStyle);
-                        if (isDateTime)
-                        {
-                            aheader.AreaType = (byte)bx_sdk_dual.AreaType.DateTime;
-                        }
+                        return err;
+                    }
 
-                        ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQareaHeader_G6)));
-                        Marshal.StructureToPtr(aheader, ptr, false);
+                    var timeData = new bx_sdk_dual.EQtimeAreaData_G56();
 
-                        err = bx_sdk_dual.program_addArea_G6(areaId, ptr);
-                        if (err != 0)
+                    if (timeData.date_enable == 0)
+                    {
+                        if (dateStyle.HasValue)
                         {
-                            return err;
+                            timeData.date_enable = 1;
+                            timeData.datestyle = dateStyle.Value;
                         }
+                    }
 
-                        if (isDateTime)
+                    if (timeData.time_enable == 0)
+                    {
+                        if (timeStyle.HasValue)
                         {
-                            var timeData = new bx_sdk_dual.EQtimeAreaData_G56();
-                            timeData.linestyle = bx_sdk_dual.E_arrMode.eSINGLELINE;
-                            timeData.color = (uint)bx_sdk_dual.E_Color_G56.eRED;
-                            timeData.fontName = Font;
-                            timeData.fontSize = (ushort)FontSize;
-                            timeData.fontBold = 0;
-                            timeData.fontItalic = 0;
-                            timeData.fontUnderline = 0;
-                            timeData.fontAlign = GetHalign(format);
-                            if (timeData.fontAlign > 0)
-                            {
-                                timeData.fontAlign--;
-                            }
-
-                            if (dateStyle.HasValue)
-                            {
-                                timeData.date_enable = 1;
-                                timeData.datestyle = dateStyle.Value;
-                            }
-
-                            if (timeStyle.HasValue)
-                            {
-                                timeData.time_enable = 1;
-                                timeData.timestyle = timeStyle.Value;
-                            }
+                            timeData.time_enable = 1;
+                            timeData.timestyle = timeStyle.Value;
+                        }
+                    }
 
-                            ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQtimeAreaData_G56)));
-                            Marshal.StructureToPtr(timeData, ptr, false);
+                    if (lastDateTime.HasValue)
+                    {
+                        timeData.linestyle = bx_sdk_dual.E_arrMode.eMULTILINE;
+                        lastDateTime = null;
+                    }
+                    else
+                    {
+                        timeData.linestyle = bx_sdk_dual.E_arrMode.eSINGLELINE;
+                    }
 
-                            err = bx_sdk_dual.program_timeAreaAddContent_G6(areaId, ptr);
-                            if (err != 0)
-                            {
-                                return err;
-                            }
-                        }
-                        else
-                        {
-                            var str = Encoding.GetEncoding("GBK").GetBytes(item.Text);
-                            if (ControlType.HasVoiceModule(domain.ControllerType) && IsPlaySound)
-                            {
-                                var sound = new bx_sdk_dual.EQPicAreaSoundHeader_G6();
-                                sound.SoundPerson = SoundPerson;
-                                sound.SoundVolum = SoundVolume;
-                                sound.SoundSpeed = SoundSpeed;
-                                sound.SoundDataMode = 0;
-                                sound.SoundReplayTimes = 0;
-                                sound.SoundReplayDelay = 1000;
-                                sound.SoundReservedParaLen = 3;
-                                sound.Soundnumdeal = 0;
-                                sound.Soundlanguages = 0;
-                                sound.Soundwordstyle = 0;
-
-                                bx_sdk_dual.program_pictureAreaEnableSound_G6(0, sound, str);
-                            }
+                    timeData.color = (uint)bx_sdk_dual.E_Color_G56.eRED;
+                    timeData.fontName = Font;
+                    timeData.fontSize = (ushort)FontSize;
+                    timeData.fontAlign = GetHalign(format);
+                    if (timeData.fontAlign > 0)
+                    {
+                        timeData.fontAlign--;
+                    }
 
-                            var font = Encoding.Default.GetBytes(Font);
-
-                            bx_sdk_dual.EQpageHeader_G6 pheader = new bx_sdk_dual.EQpageHeader_G6();
-                            pheader.PageStyle = 0x00;
-                            pheader.DisplayMode = 0x01; //移动模式
-                            pheader.ClearMode = 0x01;
-                            pheader.Speed = 15; //速度
-                            pheader.StayTime = 0; //停留时间
-                            pheader.RepeatTime = 1;
-                            pheader.ValidLen = 0;
-                            pheader.CartoonFrameRate = 0x00;
-                            pheader.BackNotValidFlag = 0x00;
-                            pheader.arrMode = bx_sdk_dual.E_arrMode.eSINGLELINE;
-                            pheader.fontSize = (ushort)FontSize;
-                            pheader.color = (uint)0x01;
-                            pheader.fontBold = 0;
-                            pheader.fontItalic = 0;
-                            pheader.tdirection = bx_sdk_dual.E_txtDirection.pNORMAL;
-                            pheader.txtSpace = 0;
-                            pheader.Valign = GetValign(item.Format);
-                            pheader.Halign = GetHalign(item.Format);
-
-                            ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQpageHeader_G6)));
-                            Marshal.StructureToPtr(pheader, ptr, false);
-                            err = bx_sdk_dual.program_picturesAreaAddTxt_G6(areaId, str, font, ptr);
-                            if (err != 0)
-                            {
-                                return err;
-                            }
-                        }
+                    ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQtimeAreaData_G56)));
+                    Marshal.StructureToPtr(timeData, ptr, false);
 
-                        areaId++;
+                    err = bx_sdk_dual.program_timeAreaAddContent_G6(areaId, ptr);
+                    if (err != 0)
+                    {
+                        return err;
                     }
                 }
                 else
                 {
                     var aheader = new bx_sdk_dual.EQareaHeader_G6();
-                    aheader.AreaX = (ushort)empty.Location.X;
-                    aheader.AreaY = (ushort)empty.Location.Y;
-                    aheader.AreaWidth = (ushort)empty.Size.Width;
-                    aheader.AreaHeight = (ushort)empty.Size.Height;
-                    aheader.BackGroundFlag = 0x00;
+                    aheader.AreaX = (ushort)x;
+                    aheader.AreaY = (ushort)y;
+                    aheader.AreaWidth = width;
+                    aheader.AreaHeight = height;
                     aheader.Transparency = 101;
+
                     ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQareaHeader_G6)));
                     Marshal.StructureToPtr(aheader, ptr, false);
 
@@ -549,9 +505,27 @@ namespace HNWD.LatticeScreen
                         return err;
                     }
 
+                    var str = Encoding.GetEncoding("GBK").GetBytes(ptext);
+                    if (ControlType.HasVoiceModule(domain.ControllerType) && IsPlaySound)
+                    {
+                        var sound = new bx_sdk_dual.EQPicAreaSoundHeader_G6();
+                        sound.SoundPerson = SoundPerson;
+                        sound.SoundVolum = SoundVolume;
+                        sound.SoundSpeed = SoundSpeed;
+                        sound.SoundDataMode = 0;
+                        sound.SoundReplayTimes = 0;
+                        sound.SoundReplayDelay = 1000;
+                        sound.SoundReservedParaLen = 3;
+                        sound.Soundnumdeal = 0;
+                        sound.Soundlanguages = 0;
+                        sound.Soundwordstyle = 0;
+
+                        bx_sdk_dual.program_pictureAreaEnableSound_G6(0, sound, str);
+                    }
+
                     var font = Encoding.Default.GetBytes(Font);
 
-                    bx_sdk_dual.EQpageHeader_G6 pheader;
+                    bx_sdk_dual.EQpageHeader_G6 pheader = new bx_sdk_dual.EQpageHeader_G6();
                     pheader.PageStyle = 0x00;
                     pheader.DisplayMode = 0x01; //移动模式
                     pheader.ClearMode = 0x01;
@@ -568,12 +542,12 @@ namespace HNWD.LatticeScreen
                     pheader.fontItalic = 0;
                     pheader.tdirection = bx_sdk_dual.E_txtDirection.pNORMAL;
                     pheader.txtSpace = 0;
-                    pheader.Valign = GetValign(empty.Format);
-                    pheader.Halign = GetHalign(empty.Format);
+                    pheader.Valign = GetValign(format);
+                    pheader.Halign = GetHalign(format);
 
                     ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(bx_sdk_dual.EQpageHeader_G6)));
                     Marshal.StructureToPtr(pheader, ptr, false);
-                    err = bx_sdk_dual.program_picturesAreaAddTxt_G6(areaId, Encoding.GetEncoding("GBK").GetBytes(empty.Text), font, ptr);
+                    err = bx_sdk_dual.program_picturesAreaAddTxt_G6(areaId, str, font, ptr);
                     if (err != 0)
                     {
                         return err;
@@ -626,9 +600,7 @@ namespace HNWD.LatticeScreen
 
                 bx_sdk_dual.program_deleteProgram_G6();
 
-                //lastText = ptext;
-                drawList.AddOrUpdate(hdl, new List<DrawText>(), (key, value) => new List<DrawText>());
-                lastDraw = list.ToArray();
+                lastText = ptext;
 
                 return 0;
             }