Преглед на файлове

支持多个点阵屏显示

linjpxc преди 5 години
родител
ревизия
3b7954ca25
променени са 1 файла, в които са добавени 39 реда и са изтрити 16 реда
  1. 39 16
      LatticeScreenServer/Hards/LedControl.cs

+ 39 - 16
LatticeScreenServer/Hards/LedControl.cs

@@ -27,6 +27,8 @@ namespace HNWD.LatticeScreen
 
 
         private static FileSystemWatcher fileWatcher = null;
         private static FileSystemWatcher fileWatcher = null;
 
 
+        private static int randomPtr = 1;
+
         public static string ConfigFile
         public static string ConfigFile
         {
         {
             get => configFile;
             get => configFile;
@@ -229,7 +231,8 @@ namespace HNWD.LatticeScreen
 
 
         public static int JHCreateInst(ref IntPtr hdl, ushort serverid)
         public static int JHCreateInst(ref IntPtr hdl, ushort serverid)
         {
         {
-            var tmp = new IntPtr(new Random().Next(100, 1000000));
+            //var tmp = new IntPtr(new Random().Next(100, 1000000));
+            var tmp = new IntPtr(Interlocked.Increment(ref randomPtr));
 
 
             hdl = tmp;
             hdl = tmp;
 
 
@@ -259,7 +262,8 @@ namespace HNWD.LatticeScreen
 
 
         public static int JHCommGetNetArgStruct(ref IntPtr pargs, string ipordomain, ushort port, uint timeout)
         public static int JHCommGetNetArgStruct(ref IntPtr pargs, string ipordomain, ushort port, uint timeout)
         {
         {
-            var tmp = new IntPtr(new Random().Next(100, 1000000));
+            //var tmp = new IntPtr(new Random().Next(100, 1000000));
+            var tmp = new IntPtr(Interlocked.Increment(ref randomPtr));
 
 
             pargs = tmp;
             pargs = tmp;
 
 
@@ -313,9 +317,13 @@ namespace HNWD.LatticeScreen
             return 0;
             return 0;
         }
         }
 
 
-        private static string lastText = string.Empty;
+        //private static string lastText = string.Empty;
+
+        //private static DrawText? lastDateTime;
 
 
-        private static DrawText? lastDateTime;
+        private static ConcurrentDictionary<string, string> lastTextDic = new ConcurrentDictionary<string, string>();
+
+        private static ConcurrentDictionary<string, DrawText?> lastDateTimeDic = new ConcurrentDictionary<string, DrawText?>();
 
 
         public static int JHDrawText(IntPtr hdl, short x, short y, ushort width, ushort height, uint format, string ptext)
         public static int JHDrawText(IntPtr hdl, short x, short y, ushort width, ushort height, uint format, string ptext)
         {
         {
@@ -331,29 +339,33 @@ namespace HNWD.LatticeScreen
 
 
             lock (domain.Sync)
             lock (domain.Sync)
             {
             {
-                if (lastText == ptext)
-                {
-                    return 0;
-                }
+                var lastTextTmp = "";
+                DrawText? lastDateTimeTmp = null;
+
+                var hasLastTextTmp = lastTextDic.TryGetValue(domain.Address, out lastTextTmp);
+                lastDateTimeDic.TryGetValue(domain.Address, out lastDateTimeTmp);
 
 
                 var isDateTime = IsDateTimeText(ptext, out var dateStyle, out var timeStyle);
                 var isDateTime = IsDateTimeText(ptext, out var dateStyle, out var timeStyle);
                 if (isDateTime)
                 if (isDateTime)
                 {
                 {
                     if (width < domain.Size.Width || height < domain.Size.Height)
                     if (width < domain.Size.Width || height < domain.Size.Height)
                     {
                     {
-                        if (!lastDateTime.HasValue)
+                        if (!lastDateTimeTmp.HasValue)
                         {
                         {
-                            lastDateTime = new DrawText()
+                            lastDateTimeTmp = new DrawText()
                             {
                             {
                                 Format = format,
                                 Format = format,
                                 Location = new Point(x, y),
                                 Location = new Point(x, y),
                                 Size = new Size(width, height),
                                 Size = new Size(width, height),
                                 Text = ptext
                                 Text = ptext
                             };
                             };
+
+                            lastDateTimeDic.AddOrUpdate(domain.Address, lastDateTimeTmp, (key, value) => lastDateTimeTmp);
+
                             return 0;
                             return 0;
                         }
                         }
 
 
-                        var tmpText = lastDateTime.Value.Text;
+                        var tmpText = lastDateTimeTmp.Value.Text;
                         if (IsDateTimeText(tmpText, out var dateStyleTmp, out var timeStyleTmp))
                         if (IsDateTimeText(tmpText, out var dateStyleTmp, out var timeStyleTmp))
                         {
                         {
                             if (dateStyle == dateStyleTmp && timeStyle == timeStyleTmp)
                             if (dateStyle == dateStyleTmp && timeStyle == timeStyleTmp)
@@ -375,10 +387,11 @@ namespace HNWD.LatticeScreen
                     }
                     }
                     else
                     else
                     {
                     {
-                        lastDateTime = null;
+                        //lastDateTimeTmp = null;
+                        lastDateTimeDic.TryRemove(domain.Address, out _);
                     }
                     }
 
 
-                    if (IsDateTimeText(lastText, out var tmpDateStyle, out var tmpTimeStyle))
+                    if (IsDateTimeText(lastTextTmp, out var tmpDateStyle, out var tmpTimeStyle))
                     {
                     {
                         if (dateStyle == tmpDateStyle && timeStyle == tmpTimeStyle)
                         if (dateStyle == tmpDateStyle && timeStyle == tmpTimeStyle)
                         {
                         {
@@ -386,6 +399,13 @@ namespace HNWD.LatticeScreen
                         }
                         }
                     }
                     }
                 }
                 }
+                else
+                {
+                    if (hasLastTextTmp && lastTextTmp == ptext)
+                    {
+                        return 0;
+                    }
+                }
 
 
                 bx_sdk_dual.EQprogramHeader_G6 header;
                 bx_sdk_dual.EQprogramHeader_G6 header;
                 header.FileType = 0x00;
                 header.FileType = 0x00;
@@ -459,10 +479,11 @@ namespace HNWD.LatticeScreen
                         }
                         }
                     }
                     }
 
 
-                    if (lastDateTime.HasValue)
+                    if (lastDateTimeTmp.HasValue)
                     {
                     {
                         timeData.linestyle = bx_sdk_dual.E_arrMode.eMULTILINE;
                         timeData.linestyle = bx_sdk_dual.E_arrMode.eMULTILINE;
-                        lastDateTime = null;
+                        //lastDateTime = null;
+                        lastDateTimeDic.TryRemove(domain.Address, out _);
                     }
                     }
                     else
                     else
                     {
                     {
@@ -600,7 +621,9 @@ namespace HNWD.LatticeScreen
 
 
                 bx_sdk_dual.program_deleteProgram_G6();
                 bx_sdk_dual.program_deleteProgram_G6();
 
 
-                lastText = ptext;
+                //lastText = ptext;
+
+                lastTextDic.AddOrUpdate(domain.Address, ptext, (key, value) => ptext);
 
 
                 return 0;
                 return 0;
             }
             }