示例#1
0
        public Splitter(LedData ld, int srcWidth, int srcHeight)
        {
            LogUtil.Write("Initializing splitter, using LED Data: " + JsonConvert.SerializeObject(ld));
            // Set some defaults, this should probably just not be null
            if (ld != null)
            {
                _vCount = ld.VCount;
                _hCount = ld.HCount;
            }

            sourceWidth  = srcWidth;
            sourceHeight = srcHeight;
            // Set desired width of capture region to 15% total image
            _borderWidth  = sourceWidth * .05f;
            _borderHeight = sourceHeight * .05f;
            // Set default box mode to zero, no boxing
            _boxMode = 0;
            // Set brightness boost, min brightness, sat boost...
            _brightBoost     = 0;
            _minBrightness   = 90;
            _saturationBoost = .2f;
            // Get sectors
            _fullCoords    = DrawGrid();
            _fullSectors   = DrawSectors();
            _fullSectorsV2 = DrawSectors(0, 0, true);
            _frameCount    = 0;
            _colorsWled    = new Dictionary <string, List <Color> >();
            WLModules      = new Dictionary <string, List <int> >();
            WLSectors      = new Dictionary <string, List <Rectangle> >();
            LogUtil.Write("Splitter init complete.");
        }
示例#2
0
        public IActionResult StripType([FromBody] int type)
        {
            LedData ledData = DataUtil.GetCollection <LedData>("ledData").First();

            ledData.StripType = type;
            DataUtil.SetObject("LedData", ledData);
            NotifyClients();
            ResetMode();
            return(Ok(type));
        }
示例#3
0
    /// <summary>
    /// 设置Led(1-8)的状态.
    /// </summary>
    void SetLedInfo(out byte ledKeyOut, out byte ledValOut, LedData ledDt)
    {
        byte indexLed = (byte)ledDt.IndexLed;

        indexLed -= 1;
        if (indexLed < 0 || indexLed > 7)
        {
            Debug.LogError("SetLedInfo -> indexLed was wrong! indexLed " + indexLed);
            ledKeyOut = ledDt.LedKey;
            ledValOut = ledDt.LedVal;
            return;
        }

        byte ledKey    = ledDt.LedKey;
        byte ledVal    = ledDt.LedVal;
        byte ledKey01  = ledDt.LedKey01; //有效检验数1
        byte ledKey02  = ledDt.LedKey02; //有效检验数2
        byte ledVal01  = ledDt.LedVal01; //有效数据1
        byte ledVal02  = ledDt.LedVal02; //有效数据2
        bool isOpenLed = LedState[indexLed];

        if (Random.Range(0, 100) % 2 == 0)
        {
            ledKey |= ledKey01;
            ledKey  = (byte)(ledKey & (~(ledKey02)));
            if (isOpenLed)
            {
                ledVal = (byte)(ledVal & (~(ledVal01)));
            }
            else
            {
                ledVal |= ledVal01;
            }
        }
        else
        {
            ledKey |= ledKey02;
            ledKey  = (byte)(ledKey & (~(ledKey01)));
            if (isOpenLed)
            {
                ledVal = (byte)(ledVal & (~(ledVal02)));
            }
            else
            {
                ledVal |= ledVal02;
            }
        }

        ledKeyOut = ledKey;
        ledValOut = ledVal;
    }
示例#4
0
        public WLedData(string id)
        {
            Id           = id;
            ControlStrip = false;
            AutoDisable  = true;
            Sectors      = new List <int>();
            SubSectors   = new Dictionary <int, int>();
            LedData ld = new LedData(true);

            try {
                ld = DataUtil.GetObject <LedData>("LedData");
            } catch (KeyNotFoundException e) {
            }

            var capMode = DataUtil.GetItem <int>("captureMode");

            if (capMode == 0)
            {
                VCount = ld.VCountDs;
                HCount = ld.HCountDs;
            }
            else
            {
                VCount = ld.VCount;
                HCount = ld.HCount;
            }

            try {
                var dns = Dns.GetHostEntry(Id + ".local");
                if (dns.AddressList.Length > 0)
                {
                    IpAddress = dns.AddressList[0].ToString();
                }
            } catch (Exception e) {
                LogUtil.Write("DNS Res ex: " + e.Message);
            }

            using var webClient = new WebClient();
            try {
                var url      = "http://" + Id + ".local/json";
                var jsonData = webClient.DownloadString(url);
                var jsonObj  = JsonConvert.DeserializeObject <WLedStateData>(jsonData);
                State      = jsonObj;
                LedCount   = jsonObj.info.leds.count;
                Brightness = jsonObj.state.bri;
            } catch (Exception) {
            }
        }
示例#5
0
        private void UnpackLightingInfo(byte[] data)
        {
            var num_light_channels      = data[14]; //the 15th byte (index 14) is # of light channels
            var accessories_per_channel = 6;        //each lighting channel supports up to 6 accessories
            var light_accessory_index   = 15;       //offset in msg of info about first light accessory

            LedData ledData = new LedData();

            for (byte i = 0; i < num_light_channels; i++)
            {
                List <LedAccessory> accessories = new List <LedAccessory>();
                for (byte j = 0; j < accessories_per_channel; j++)
                {
                    LedAccessoryType accessoryType = (LedAccessoryType)data[light_accessory_index++];
                    if (accessoryType != LedAccessoryType.NotConnected)
                    {
                        LedAccessory ledAccessory = new LedAccessory();
                        ledAccessory.LedAccessoryType    = accessoryType;
                        ledAccessory.LedAccessoryIndex   = j;
                        ledAccessory.LedAccessoryChannel = i;
                        accessories.Add(ledAccessory);
                    }
                }
                switch (i)
                {
                case 0:
                    ledData.ExternalLedAccessories = accessories.ToArray();
                    break;

                case 1:
                    ledData.PumpRingLedAccessories = accessories.ToArray();
                    break;

                case 2:
                    ledData.PumpLogoLedAccessories = accessories.ToArray();
                    break;
                }
            }

            RgbInfo.Value = (ledData);
        }
示例#6
0
        public static void DbDefaults(LifxClient lc)
        {
            var db = GetDb();
            // Check to see if we have our system data object
            var defaultSet = GetItem("DefaultSet");

            if (defaultSet == null || defaultSet == false)
            {
                LogUtil.Write("Starting to create defaults.");
                // If not, create it
                var sd = new SystemData(true);
                foreach (var v in sd.GetType().GetProperties())
                {
                    LogUtil.Write("Setting: " + v.Name);
                    SetItem(v.Name, v.GetValue(sd));
                }

                var dsIp     = GetItem("DsIp");
                var ledData  = new LedData(true);
                var myDevice = new DreamScreen4K(dsIp);
                myDevice.SetDefaults();
                myDevice.Id = dsIp;
                SetObject("LedData", ledData);
                SetObject("MyDevice", myDevice);
                LogUtil.Write("Loading first...");
                // Get/create our collection of Dream devices
                var d = db.GetCollection <BaseDevice>("devices");
                // Create our default device
                // Save it
                d.Upsert(myDevice.Id, myDevice);
                d.EnsureIndex(x => x.Id);
                db.Commit();
                // Scan for devices
                ScanDevices(lc).ConfigureAwait(false);
            }
            else
            {
                LogUtil.Write("Defaults are already set.");
            }
        }
示例#7
0
        // Starts our capture service and initializes our LEDs
        private void StartCaptureServices(CancellationToken ct)
        {
            if (CaptureMode == 0)
            {
                return;
            }
            LedData ledData = DataUtil.GetObject <LedData>("LedData") ?? new LedData(true);

            try {
                _strip = new LedStrip(ledData);
                LogUtil.Write("Initialized LED strip...");
            } catch (TypeInitializationException e) {
                LogUtil.Write("Type init error: " + e.Message);
            }

            _grabber = new StreamCapture(_camTokenSource.Token);
            if (_grabber == null)
            {
                return;
            }
            Task.Run(() => SubscribeBroadcast(ct), ct);
        }
示例#8
0
        public IActionResult Hcount([FromBody] int count)
        {
            LedData ledData = DataUtil.GetCollection <LedData>("ledData").First();
            var     capMode = DataUtil.GetItem <int>("CaptureMode");
            int     vCount;

            if (capMode == 0)
            {
                vCount           = ledData.VCountDs;
                ledData.HCountDs = count;
            }
            else
            {
                vCount         = ledData.VCount;
                ledData.HCount = count;
            }

            ledData.LedCount = vCount * 2 + count * 2;
            DataUtil.SetObject("LedData", ledData);
            NotifyClients();
            ResetMode();
            return(Ok(count));
        }
示例#9
0
        private void SetCapVars()
        {
            _ledData     = DataUtil.GetObject <LedData>("LedData");
            _captureMode = DataUtil.GetItem <int>("CaptureMode");
            _camType     = DataUtil.GetItem <int>("CamType");
            LogUtil.Write("Capture mode is " + _captureMode);
            switch (_captureMode)
            {
            // If camera mode
            case 1: {
                _camWidth    = DataUtil.GetItem <int>("CamWidth") ?? 1920;
                _camHeight   = DataUtil.GetItem <int>("CamHeight") ?? 1080;
                _scaleFactor = DataUtil.GetItem <float>("ScaleFactor") ?? .5f;
                _scaleWidth  = Convert.ToInt32(_camWidth * _scaleFactor);
                _scaleHeight = Convert.ToInt32(_camHeight * _scaleFactor);
                _srcArea     = _scaleWidth * _scaleHeight;
                _scaleSize   = new Size(_scaleWidth, _scaleHeight);

                // If we have a pi cam, we can attempt to calibrate for warping
                if (_camType == 0)
                {
                    var kStr = DataUtil.GetItem("K");
                    if (kStr == null)
                    {
                        LogUtil.Write("Running static camera calibration.");
                        Calibrate.ProcessFrames();
                    }
                    else
                    {
                        LogUtil.Write("Camera calibration settings loaded.");
                    }

                    LogUtil.Write("calibration vars deserialized.");
                }

                // If it is an actual cam, versus USB video capture, get a lock target
                try {
                    var lt = DataUtil.GetItem <PointF[]>("LockTarget");
                    LogUtil.Write("LT Grabbed? " + JsonConvert.SerializeObject(lt));
                    if (lt != null)
                    {
                        _lockTarget = new VectorOfPointF(lt);
                        var lC = 0;
                        while (lC < 20)
                        {
                            _targets.Add(VPointFToVPoint(_lockTarget));
                            lC++;
                        }
                    }
                } catch (Exception e) {
                    LogUtil.Write("Exception: " + e.Message);
                }

                break;
            }

            // If capturing HDMI input or screen
            case 2:
            case 3:
                _camWidth    = 640;
                _camHeight   = 480;
                _scaleFactor = 1;
                _scaleWidth  = Convert.ToInt32(_camWidth * _scaleFactor);
                _scaleHeight = Convert.ToInt32(_camHeight * _scaleFactor);
                _srcArea     = _scaleWidth * _scaleHeight;
                _scaleSize   = new Size(_scaleWidth, _scaleHeight);
                break;
            }

            var tl = new Point(0, 0);
            var tr = new Point(_scaleWidth, 0);
            var br = new Point(_scaleWidth, _scaleHeight);
            var bl = new Point(0, _scaleHeight);

            // Debugging vars...
            _showSource = DataUtil.GetItem <bool>("ShowSource") ?? false;
            _showEdged  = DataUtil.GetItem <bool>("ShowEdged") ?? false;
            _showWarped = DataUtil.GetItem <bool>("ShowWarped") ?? false;
            _vectors    = new PointF[] { tl, tr, br, bl };
            LogUtil.Write("Start Capture should be running...");
        }
示例#10
0
    /// <summary>
    /// 发送串口数据信息.
    /// </summary>
    void SendMessage()
    {
        if (!MyCOMDevice.GetInstance().IsFindDeviceDt)
        {
            return;
        }

        int writeCount = MyCOMDevice.ComThreadClass.WriteCountLock;

        if (WriteMsgCount == writeCount)
        {
            return;
        }
        WriteMsgCount = writeCount;

        int bufLenWrite = MyCOMDevice.ComThreadClass.BufLenWrite;

        byte[] buffer = new byte[bufLenWrite];
        for (int i = 5; i < (bufLenWrite - 2); i++)
        {
            buffer[i] = (byte)Random.Range(0x00, 0xff);
        }
        buffer[0] = WriteHead_1;
        buffer[1] = WriteHead_2;
        //buffer[bufLenWrite - 2] = WriteEnd_1;
        //buffer[bufLenWrite - 1] = WriteEnd_2;
        buffer[bufLenWrite - 3] = WriteEnd_1;
        buffer[bufLenWrite - 2] = WriteEnd_2;

        //减币控制.
        if (!IsCleanHidCoinArray[0] && !IsCleanHidCoinArray[1] && !IsCleanHidCoinArray[2] && !IsCleanHidCoinArray[3])
        {
            buffer[4] = 0x00;
        }
        else
        {
            if (IsCleanHidCoinArray[0] || IsCleanHidCoinArray[1])
            {
                buffer[4] = 0x04;
                if (IsCleanHidCoinArray[0] && IsCleanHidCoinArray[1])
                {
                    buffer[2] = 0x11;
                }
                else if (IsCleanHidCoinArray[0])
                {
                    buffer[2] = 0x01;
                }
                else if (IsCleanHidCoinArray[1])
                {
                    buffer[2] = 0x10;
                }
            }

            if (IsCleanHidCoinArray[2] || IsCleanHidCoinArray[3])
            {
                buffer[4] = 0x04;
                if (IsCleanHidCoinArray[2] && IsCleanHidCoinArray[3])
                {
                    buffer[3] = 0x11;
                }
                else if (IsCleanHidCoinArray[2])
                {
                    buffer[3] = 0x01;
                }
                else if (IsCleanHidCoinArray[3])
                {
                    buffer[3] = 0x10;
                }
            }
        }

        //加密芯片校验控制.
        if (IsJiaoYanHid)
        {
            //校验允许1
            buffer[29] = 0x42;
            //校验允许2
            buffer[31] = 0x12;

            //密码指示---由第3、5、8位确定
            buffer[33] = mJiaMiPWDCmd[JiaMiPWDCmdIndex].Cmd;
            //密码1
            buffer[34] = JiaoYanMiMa[mJiaMiPWDCmd[JiaMiPWDCmdIndex].Index01];
            //密码2
            buffer[38] = JiaoYanMiMa[mJiaMiPWDCmd[JiaMiPWDCmdIndex].Index02];
            //密码3
            buffer[45] = JiaoYanMiMa[mJiaMiPWDCmd[JiaMiPWDCmdIndex].Index03];

            //加密运算标记(指示数据1、2、3)---位6、3、2
            buffer[37] = mJiaMiDtCmd[JiaMiDtCmdIndex].Cmd;
            //加密校验数据1
            buffer[40] = JiaoYanDt[mJiaMiDtCmd[JiaMiDtCmdIndex].Index01];
            //加密校验数据2
            buffer[41] = JiaoYanDt[mJiaMiDtCmd[JiaMiDtCmdIndex].Index02];
            //加密校验数据3
            buffer[35] = JiaoYanDt[mJiaMiDtCmd[JiaMiDtCmdIndex].Index03];
            if (IsJiaoYanJiaMiCoreDt)
            {
                Debug.Log("buffer_29 " + buffer[29].ToString("X2") + ", buffer_31 " + buffer[31].ToString("X2"));
                Debug.Log("miMa:: buffer_33 " + buffer[33].ToString("X2") + ", buffer_34 " + buffer[34].ToString("X2") + ", buffer_38 " + buffer[38].ToString("X2") + ", buffer_45 " + buffer[45].ToString("X2") + ", JiaMiPWDCmdIndex " + JiaMiPWDCmdIndex);
                Debug.Log("dtVal:: buffer_37 " + buffer[37].ToString("X2") + ", buffer_40 " + buffer[40].ToString("X2") + ", buffer_41 " + buffer[41].ToString("X2") + ", buffer_35 " + buffer[35].ToString("X2") + ", JiaMiDtCmdIndex " + JiaMiDtCmdIndex);
            }
        }
        else
        {
            //不进行加密芯片校验.
            buffer[29] = 0x00;
            buffer[31] = 0x00;
            buffer[33] = 0x00;
            buffer[37] = 0x00;
        }

        //彩票打印控制.
        buffer[19] = (byte)CaiPiaoPrintCmdVal[(int)CaiPiaoJi.Num01];
        buffer[20] = (byte)CaiPiaoPrintCmdVal[(int)CaiPiaoJi.Num02];

        //灯1控制
        LedData ledDt = new LedData(LedIndexEnum.Led01, buffer[13], buffer[12], 0x02, 0x04, 0x40, 0x08);

        SetLedInfo(out buffer[13], out buffer[12], ledDt);

        //灯2控制
        ledDt = new LedData(LedIndexEnum.Led02, buffer[27], buffer[15], 0x04, 0x10, 0x40, 0x08);
        SetLedInfo(out buffer[27], out buffer[15], ledDt);

        //灯3控制
        ledDt = new LedData(LedIndexEnum.Led03, buffer[14], buffer[16], 0x04, 0x10, 0x04, 0x10);
        SetLedInfo(out buffer[14], out buffer[16], ledDt);

        //灯4控制
        ledDt = new LedData(LedIndexEnum.Led04, buffer[6], buffer[17], 0x04, 0x10, 0x04, 0x10);
        SetLedInfo(out buffer[6], out buffer[17], ledDt);

        //灯5控制
        ledDt = new LedData(LedIndexEnum.Led05, buffer[11], buffer[7], 0x04, 0x40, 0x80, 0x04);
        SetLedInfo(out buffer[11], out buffer[7], ledDt);

        //灯6控制
        ledDt = new LedData(LedIndexEnum.Led06, buffer[24], buffer[10], 0x02, 0x10, 0x04, 0x40);
        SetLedInfo(out buffer[24], out buffer[10], ledDt);

        //灯7控制
        ledDt = new LedData(LedIndexEnum.Led07, buffer[30], buffer[8], 0x40, 0x10, 0x20, 0x10);
        SetLedInfo(out buffer[30], out buffer[8], ledDt);

        //灯8控制
        ledDt = new LedData(LedIndexEnum.Led08, buffer[9], buffer[5], 0x02, 0x20, 0x20, 0x10);
        SetLedInfo(out buffer[9], out buffer[5], ledDt);

        //灯9控制
        SetLedState(LedIndexEnum.Led09, buffer[21], out buffer[21]);

        //灯10控制
        SetLedState(LedIndexEnum.Led10, buffer[21], out buffer[21]);

        //灯11控制
        SetLedState(LedIndexEnum.Led11, buffer[21], out buffer[21]);

        //灯12控制
        SetLedState(LedIndexEnum.Led12, buffer[21], out buffer[21]);

        //灯13控制
        SetLedState(LedIndexEnum.Led13, buffer[21], out buffer[21]);

        //灯14控制
        SetLedState(LedIndexEnum.Led14, buffer[21], out buffer[21]);

        //灯15控制
        SetLedState(LedIndexEnum.Led15, buffer[21], out buffer[21]);

        //灯16控制
        SetLedState(LedIndexEnum.Led16, buffer[21], out buffer[21]);

        //灯17控制
        SetLedState(LedIndexEnum.Led17, buffer[22], out buffer[22]);

        //灯18控制
        SetLedState(LedIndexEnum.Led18, buffer[22], out buffer[22]);

        //灯19控制
        SetLedState(LedIndexEnum.Led19, buffer[22], out buffer[22]);

        //灯20控制
        SetLedState(LedIndexEnum.Led20, buffer[22], out buffer[22]);

        //灯21控制
        SetLedState(LedIndexEnum.Led21, buffer[22], out buffer[22]);

        //灯22控制
        SetLedState(LedIndexEnum.Led22, buffer[22], out buffer[22]);

        //灯23控制
        SetLedState(LedIndexEnum.Led23, buffer[22], out buffer[22]);

        //灯24控制
        SetLedState(LedIndexEnum.Led24, buffer[22], out buffer[22]);

        //灯25控制
        SetLedState(LedIndexEnum.Led25, buffer[26], out buffer[26]);

        //灯26控制
        SetLedState(LedIndexEnum.Led26, buffer[26], out buffer[26]);

        //灯27控制
        SetLedState(LedIndexEnum.Led27, buffer[26], out buffer[26]);

        //灯28控制
        SetLedState(LedIndexEnum.Led28, buffer[26], out buffer[26]);

        //灯29控制
        SetLedState(LedIndexEnum.Led29, buffer[26], out buffer[26]);

        //灯30控制
        SetLedState(LedIndexEnum.Led30, buffer[26], out buffer[26]);

        //灯31控制
        SetLedState(LedIndexEnum.Led31, buffer[26], out buffer[26]);

        //灯32控制
        SetLedState(LedIndexEnum.Led32, buffer[26], out buffer[26]);

        //Led灯总控.
        SetLedZongKongInfo(out buffer[18], buffer[18]);

        //继电器控制.
        buffer[23] = GetJiDianQiCmd();

        //数据校验位 26~44的异或校验、起始值为0x58(不包含自身) 第一步.
        buffer[32] = 0x58;
        for (int i = 26; i <= 44; i++)
        {
            if (i == 32)
            {
                continue;
            }
            buffer[32] ^= buffer[i];
        }

        //校验位,2~45的异或校验、起始值为0x85(不包含自身) 第二步.
        buffer[25] = 0x85;
        for (int i = 2; i <= 45; i++)
        {
            if (i == 25)
            {
                continue;
            }
            buffer[25] ^= buffer[i];
        }

        //数据校验 3~49的数据异或、异或初始值为0xba(不包含自身) 最后一步.
        buffer[46] = 0xba;
        for (int i = 3; i <= 49; i++)
        {
            if (i == 46)
            {
                continue;
            }
            buffer[46] ^= buffer[i];
        }

        buffer[bufLenWrite - 1] = (byte)(TestSendDt % 256); //test
        TestSendDt++;                                       //test
        MyCOMDevice.ComThreadClass.WriteByteMsg = buffer;
    }