Exemplo n.º 1
0
        public Accessory(string DisplayName, string UUID)
        {
            if (DisplayName.Length == 0)
            {
                throw new InvalidOperationException("Accessories must be created with a non-empty displayName.");
            }
            if (UUID.Length == 0)
            {
                throw new InvalidOperationException("Accessories must be created with a valid UUID.");
            }
            if (!UUIDHelper.IsValid(UUID))
            {
                throw new InvalidOperationException("UUID is not a valid UUID. Try using the provided 'generateUUID' function to create a valid UUID from any arbitrary string, like a serial number.");
            }


            this.DisplayName          = DisplayName;
            this.UUID                 = UUID;
            this.Aid                  = null; // assigned by us in assignIDs()
            this.Reachable            = true;
            this.Category             = (int)Categories.OTHER;
            this.CameraSource         = null;
            this.Services             = new List <int>();
            this.ShouldPurgeUnusedIDs = true; // Purge unused ids by default

            // create our initial "Accessory Information" Service that all Accessories are expected to have
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads GATT services information in list and attaches to CapSense and RGB led custom services if available.
        /// </summary>
        private void LoadGattServices()
        {
            if (currentCapSenseCharacteristic != null)
            {
                currentCapSenseCharacteristic.ValueChanged -= currentCapSenseCharacteristic_ValueChanged;
            }
            currentCapSenseCharacteristic = null;
            currentRGBLedCharacteristic   = null;
            lstGattServices.Items.Clear();
            lstCharacteristics.Items.Clear();

            string description = string.Empty;

            foreach (var service in currentDevice.GattServices)
            {
                description = UUIDHelper.GetUUIDDescription(service.Uuid.ToString());
                lstGattServices.Items.Add(new MyGattService(description, service));

                foreach (var characteristic in service.GetAllCharacteristics())
                {
                    if (characteristic.Uuid == Guid.Parse("0000caa2-0000-1000-8000-00805f9b34fb"))
                    {
                        AttachToCapSense(characteristic);
                    }
                    else if (characteristic.Uuid == Guid.Parse("0000cbb1-0000-1000-8000-00805f9b34fb"))
                    {
                        AttachToRGBLed(characteristic);
                    }
                }
            }
        }