Ejemplo n.º 1
0
        private static void DecodeKaiConnected(JObject input)
        {
            var kaiID           = input[Constants.KaiID].ToObject <int>();
            var hand            = input[Constants.Hand]?.ToObject <string>(); // will not be optional in future
            var defaultKai      = input[Constants.DefaultKai]?.ToObject <bool>();
            var defaultLeftKai  = input[Constants.DefaultLeftKai]?.ToObject <bool>();
            var defaultRightKai = input[Constants.DefaultRightKai]?.ToObject <bool>();
            var kaiSerialNumber = input[Constants.KaiSerialNumber]?.ToObject <bool>();            // will not be optional in future

            //var kaiParsed = KaiObjectParsed.Parse(input);
            if (!Enum.TryParse(hand, true, out Hand handEnum))
            {
                handEnum = Hand.Left;
            }

            if (defaultKai == true)
            {
                DefaultKai.KaiID = kaiID;
                DefaultKai.Hand  = handEnum;
            }

            if (defaultLeftKai == true)
            {
                DefaultLeftKai.KaiID = kaiID;
                DefaultLeftKai.Hand  = Hand.Left;
            }

            if (defaultRightKai == true)
            {
                DefaultRightKai.KaiID = kaiID;
                DefaultRightKai.Hand  = Hand.Right;
            }

            connectedKais[kaiID] = new Kai
            {
                KaiID = kaiID,
                Hand  = handEnum
            };

            if (defaultKai == true || defaultLeftKai == true || defaultRightKai == true)
            {
                ResetDefaultCapabilities();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Unset the Kai's capabilities and subscribes to that data
        /// </summary>
        /// <param name="capabilities">The capabilities to set the Kai to</param>
        /// <param name="kai">The kai to set the capabilities to</param>
        public static void UnsetCapabilities(Kai kai, KaiCapabilities capabilities)
        {
            kai.Capabilities &= ~capabilities;             // value = value AND NOT parameter. This will unset the parameter from the value
            if (!Authenticated)
            {
                return;
            }

            var json = new JObject
            {
                [Constants.Type] = Constants.SetCapabilities
            };

            if (ReferenceEquals(kai, DefaultKai))
            {
                json.Add(Constants.KaiID, Constants.Default);
            }
            else if (ReferenceEquals(kai, DefaultLeftKai))
            {
                json.Add(Constants.KaiID, Constants.DefaultLeft);
            }
            else if (ReferenceEquals(kai, DefaultRightKai))
            {
                json.Add(Constants.KaiID, Constants.DefaultRight);
            }
            else
            {
                json.Add(Constants.KaiID, kai.KaiID);
            }

            if (capabilities.HasFlag(KaiCapabilities.GestureData))
            {
                json.Add(Constants.GestureData, false);
            }

            if (capabilities.HasFlag(KaiCapabilities.LinearFlickData))
            {
                json.Add(Constants.LinearFlickData, false);
            }

            if (capabilities.HasFlag(KaiCapabilities.FingerShortcutData))
            {
                json.Add(Constants.FingerShortcutData, false);
            }

            if (capabilities.HasFlag(KaiCapabilities.FingerPositionalData))
            {
                json.Add(Constants.FingerPositionalData, false);
            }

            if (capabilities.HasFlag(KaiCapabilities.PYRData))
            {
                json.Add(Constants.PYRData, false);
            }

            if (capabilities.HasFlag(KaiCapabilities.QuaternionData))
            {
                json.Add(Constants.QuaternionData, false);
            }

            if (capabilities.HasFlag(KaiCapabilities.AccelerometerData))
            {
                json.Add(Constants.AccelerometerData, false);
            }

            if (capabilities.HasFlag(KaiCapabilities.GyroscopeData))
            {
                json.Add(Constants.GyroscopeData, false);
            }

            if (capabilities.HasFlag(KaiCapabilities.MagnetometerData))
            {
                json.Add(Constants.MagnetometerData, false);
            }

            Send(json.ToString(Formatting.None));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Set the Kai's capabilities and subscribes to that data
        /// </summary>
        /// <param name="capabilities">The capabilities to set the Kai to</param>
        /// <param name="kai">The kai to set the capabilities to</param>
        public static void SetCapabilities(Kai kai, KaiCapabilities capabilities)
        {
            var newCapabilities = kai.Capabilities | capabilities;

            kai.Capabilities = newCapabilities;
            if (kai.Capabilities == 0)
            {
                return;
            }
            if (!Authenticated)
            {
                return;
            }

            var json = new JObject
            {
                [Constants.Type] = Constants.SetCapabilities
            };

            if (ReferenceEquals(kai, DefaultKai))
            {
                json.Add(Constants.KaiID, Constants.Default);
            }
            else if (ReferenceEquals(kai, DefaultLeftKai))
            {
                json.Add(Constants.KaiID, Constants.DefaultLeft);
            }
            else if (ReferenceEquals(kai, DefaultRightKai))
            {
                json.Add(Constants.KaiID, Constants.DefaultRight);
            }
            else
            {
                json.Add(Constants.KaiID, kai.KaiID);
            }

            if (capabilities.HasFlag(KaiCapabilities.GestureData))
            {
                json.Add(Constants.GestureData, true);
            }

            if (capabilities.HasFlag(KaiCapabilities.LinearFlickData))
            {
                json.Add(Constants.LinearFlickData, true);
            }

            if (capabilities.HasFlag(KaiCapabilities.FingerShortcutData))
            {
                json.Add(Constants.FingerShortcutData, true);
            }

            if (capabilities.HasFlag(KaiCapabilities.FingerPositionalData))
            {
                json.Add(Constants.FingerPositionalData, true);
            }

            if (capabilities.HasFlag(KaiCapabilities.PYRData))
            {
                json.Add(Constants.PYRData, true);
            }

            if (capabilities.HasFlag(KaiCapabilities.QuaternionData))
            {
                json.Add(Constants.QuaternionData, true);
            }

            if (capabilities.HasFlag(KaiCapabilities.AccelerometerData))
            {
                json.Add(Constants.AccelerometerData, true);
            }

            if (capabilities.HasFlag(KaiCapabilities.GyroscopeData))
            {
                json.Add(Constants.GyroscopeData, true);
            }

            if (capabilities.HasFlag(KaiCapabilities.MagnetometerData))
            {
                json.Add(Constants.MagnetometerData, true);
            }

            Send(json.ToString(Formatting.None));
        }