Example #1
0
        public uint Initialize()
        {
            AdapterDevice myDevice = new AdapterDevice(DeviceName, VENDOR, MODEL, VERSION, SERIAL_NUMBER, DESCRIPTION);

            AdapterProperty robotProperty = new AdapterProperty("Robot", "");

            robotProperty.Attributes.Add(NewAttribute("Mode", "manual", E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Direction", 0, E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Speed", 5, E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(robotProperty);

            AdapterProperty speechProperty = new AdapterProperty("Speech", "");

            speechProperty.Attributes.Add(NewAttribute("Message", "Tell me a joke", E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(speechProperty);


            myDevice.Methods.Add(new AdapterMethod("stop", "Stop", 0));
            myDevice.Methods.Add(new AdapterMethod("forward", "Forward", 0));
            myDevice.Methods.Add(new AdapterMethod("left", "Turn left", 0));
            myDevice.Methods.Add(new AdapterMethod("right", "Turn right", 0));
            myDevice.Methods.Add(new AdapterMethod("backward", "Backwards", 0));
            myDevice.Methods.Add(new AdapterMethod("manual", "manual", 0));
            myDevice.Methods.Add(new AdapterMethod("autonomous", "autonomous", 0));
            myDevice.Methods.Add(new AdapterMethod("speak", "speak", 0));


            devices.Add(myDevice);

            return(ERROR_SUCCESS);
        }
Example #2
0
        public HueBridgeDevice(Q42.HueApi.HueClient client, HueBridgeDescription desc, Adapter bridge) : base("PhilipsHue",
                                                                                                              desc.Manufacturer, desc.ModelName, "", desc.SerialNumber, $"{desc.FriendlyName}\n{desc.ModelDescription} ({desc.ModelNumber})")
        {
            _client      = client;
            _description = desc;
            _bridge      = bridge;

            _enableJoinMethod = new AdapterMethod("Link", "Puts the adapter into join mode", 0);
            _enableJoinMethod.InvokeAction = Link;
            _enableJoinMethod.OutputParams.Add(new AdapterValue("Result", "")
            {
                Data = ""
            });
            Methods.Add(_enableJoinMethod);


            //var UpdateMethod = new AdapterMethod("Update", "Looks for any removed or added lights", 0);
            //UpdateMethod.InvokeAction = UpdateDeviceList;
            //Methods.Add(UpdateMethod);

            //Check if bridge is already linked and registered
            bool isLinked  = false;
            var  container = ApplicationData.Current.LocalSettings.CreateContainer("RegisteredHueBridges", ApplicationDataCreateDisposition.Always);

            if (container.Values.ContainsKey(desc.SerialNumber))
            {
                var key = container.Values[desc.SerialNumber] as string;
                if (key != null)
                {
                    (client as Q42.HueApi.LocalHueClient)?.Initialize(key);
                    isLinked = true;
                    UpdateDeviceList();
                }
            }

            _isLinkedProperty = new AdapterProperty("Link", "com.dotMorten.PhilipsHueDSB.PhilipsHue");
            _isLinkedProperty.Attributes.Add(new AdapterAttribute("IsLinked", isLinked, E_ACCESS_TYPE.ACCESS_READ)
            {
                COVBehavior = SignalBehavior.Always
            });
            this.Properties.Add(_isLinkedProperty);

            if (desc.ModelName.EndsWith(" 2012")) //V1 bridge
            {
                Icon = new AdapterIcon("ms-appx:///AdapterLib/Icons/HueBridge1.png");
            }
            else if (desc.ModelName.EndsWith(" 2015")) //V2 bridge
            {
                Icon = new AdapterIcon("ms-appx:///AdapterLib/Icons/HueBridge2.png");
            }
            else //Fallback - use uri from descriptor
            {
                Icon = new AdapterIcon(desc.IconUri.OriginalString);
            }
            // change of value signal
            CreateSignals();
        }
        internal AdapterProperty(AdapterProperty Other)
        {
            this.Name = Other.Name;
            this.InterfaceHint = Other.InterfaceHint;

            try
            {
                this.Attributes = new List<IAdapterAttribute>(Other.Attributes);
            }
            catch (OutOfMemoryException ex)
            {
                throw;
            }
        }
Example #4
0
        internal AdapterProperty(AdapterProperty Other)
        {
            this.Name          = Other.Name;
            this.InterfaceHint = Other.InterfaceHint;

            try
            {
                this.Attributes = new List <IAdapterAttribute>(Other.Attributes);
            }
            catch (OutOfMemoryException ex)
            {
                throw;
            }
        }
Example #5
0
        internal AdapterProperty(AdapterProperty Other)
        {
            this.Name          = Other.Name;
            this.InterfaceHint = Other.InterfaceHint;

            try
            {
                this.Attributes = new List <IAdapterAttribute>(Other.Attributes);
            }
            catch (OutOfMemoryException ex)
            {
                Debug.WriteLine("Out of memory while trying to allocate adapter property parameter containers." + ex.Message);
                throw;
            }
        }
        public uint Initialize()
        {
            AdapterDevice myDevice = new AdapterDevice(DeviceName, VENDOR, MODEL, VERSION, SERIAL_NUMBER, DESCRIPTION);

            AdapterProperty robotProperty = new AdapterProperty("Robot", "");
            robotProperty.Attributes.Add(NewAttribute("Mode", "manual", E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Direction", 0, E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Speed", 5, E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(robotProperty);

            myDevice.Methods.Add(new AdapterMethod("stop", "Stop", 0));
            myDevice.Methods.Add(new AdapterMethod("forward", "Forward", 0));
            myDevice.Methods.Add(new AdapterMethod("left", "Turn left", 0));
            myDevice.Methods.Add(new AdapterMethod("right", "Turn right", 0));
            myDevice.Methods.Add(new AdapterMethod("backward", "Backwards", 0));
            myDevice.Methods.Add(new AdapterMethod("joke", "Tell me a joke", 0));
            myDevice.Methods.Add(new AdapterMethod("banner", "Banner Control", 0));

            AdapterProperty lightProperty = new AdapterProperty("Light", "");
            lightProperty.Attributes.Add(NewAttribute("Mode", "off", E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(lightProperty);

            AdapterProperty speechProperty = new AdapterProperty("Speech", "");
            speechProperty.Attributes.Add(NewAttribute("Volume", 4, E_ACCESS_TYPE.ACCESS_READWRITE));
            speechProperty.Attributes.Add(NewAttribute("Message", "Tell me a joke", E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(speechProperty);

            AdapterProperty bannerProperty = new AdapterProperty("Banner", "");
            bannerProperty.Attributes.Add(NewAttribute("Pre", "Maker Den", E_ACCESS_TYPE.ACCESS_READWRITE));
            bannerProperty.Attributes.Add(NewAttribute("Post", "Data Den", E_ACCESS_TYPE.ACCESS_READWRITE));
            bannerProperty.Attributes.Add(NewAttribute("Calibration", 0, E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(bannerProperty);

            devices.Add(myDevice);

            return ERROR_SUCCESS;
        }
        public HueBridgeDevice(Q42.HueApi.HueClient client, HueBridgeDescription desc, Adapter bridge) : base("PhilipsHue",
            desc.Manufacturer, desc.ModelName, "", desc.SerialNumber, $"{desc.FriendlyName}\n{desc.ModelDescription} ({desc.ModelNumber})")
        {
            _client = client;
            _description = desc;
            _bridge = bridge;

            _enableJoinMethod = new AdapterMethod("Link", "Puts the adapter into join mode", 0);
            _enableJoinMethod.InvokeAction = Link;
            _enableJoinMethod.OutputParams.Add(new AdapterValue("Result", "") { Data = "" });
            Methods.Add(_enableJoinMethod);

           
            //var UpdateMethod = new AdapterMethod("Update", "Looks for any removed or added lights", 0);
            //UpdateMethod.InvokeAction = UpdateDeviceList;
            //Methods.Add(UpdateMethod);

            //Check if bridge is already linked and registered
            bool isLinked = false;
            var container = ApplicationData.Current.LocalSettings.CreateContainer("RegisteredHueBridges", ApplicationDataCreateDisposition.Always);
            if(container.Values.ContainsKey(desc.SerialNumber))
            {
                var key = container.Values[desc.SerialNumber] as string;
                if (key != null)
                {
                    (client as Q42.HueApi.LocalHueClient)?.Initialize(key);
                    isLinked = true;
                    UpdateDeviceList();
                }
            }
            else
            {
                Link();
            }

            _isLinkedProperty = new AdapterProperty("Link", "com.dotMorten.PhilipsHueDSB.PhilipsHue");
            _isLinkedProperty.Attributes.Add(new AdapterAttribute("IsLinked", isLinked, E_ACCESS_TYPE.ACCESS_READ) { COVBehavior = SignalBehavior.Always });
            this.Properties.Add(_isLinkedProperty);


            //if (desc.IconUri != null)
            //    Icon = new AdapterIcon(desc.IconUri.OriginalString);
            Icon = new AdapterIcon("ms-appx:///AdapterLib/Icons/PhilipsHueIcon.png");

            // change of value signal
            CreateSignals();
        }
        public uint Initialize()
        {
            AdapterDevice myDevice = new AdapterDevice(DeviceName, VENDOR, MODEL, VERSION, SERIAL_NUMBER, DESCRIPTION);

            AdapterProperty robotProperty = new AdapterProperty("Robot", "");
            robotProperty.Attributes.Add(NewAttribute("Mode", "manual", E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Direction", 0, E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Speed", 5, E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(robotProperty);

            AdapterProperty speechProperty = new AdapterProperty("Speech", "");
            speechProperty.Attributes.Add(NewAttribute("Message", "Tell me a joke", E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(speechProperty);

            myDevice.Methods.Add(new AdapterMethod("stop", "Stop", 0));
            myDevice.Methods.Add(new AdapterMethod("forward", "Forward", 0));
            myDevice.Methods.Add(new AdapterMethod("left", "Turn left", 0));
            myDevice.Methods.Add(new AdapterMethod("right", "Turn right", 0));
            myDevice.Methods.Add(new AdapterMethod("backward", "Backwards", 0));
            myDevice.Methods.Add(new AdapterMethod("manual", "manual", 0));
            myDevice.Methods.Add(new AdapterMethod("autonomous", "autonomous", 0));
            myDevice.Methods.Add(new AdapterMethod("speak", "speak", 0));

            devices.Add(myDevice);

            return ERROR_SUCCESS;
        }
Example #9
0
        public uint Initialize()
        {
            AdapterDevice devicePin5 = new AdapterDevice("Switch 1", "Rohit Narayan", "Testing Model", "0.0.1", "000000001", "Controls Pin 5");
            AdapterDevice devicePin6 = new AdapterDevice("Switch 2", "Rohit Narayan", "Testing Model", "0.0.1", "000000001", "Controls Pin 6");
            AdapterDevice devicePin12 = new AdapterDevice("Switch 3", "Rohit Narayan", "Testing Model", "0.0.1", "000000001", "Controls Pin 12");
            AdapterDevice devicePin16 = new AdapterDevice("Switch 4", "Rohit Narayan", "Testing Model", "0.0.1", "000000001", "Controls Pin 16");

            // Define GPIO Pin-5 as device property. Device contains properties
            AdapterProperty gpioPin_Property5 = new AdapterProperty(PIN_NAME5, PIN_INTERFACE_HINT5);
            // Define and set GPIO Pin-5 value. Device contains properties that have one or more attributes.
            pinValueData5 = (int)pin5.Read();
            AdapterValue pinValueAttr5 = new AdapterValue(PIN_VALUE_NAME5, pinValueData5);
            gpioPin_Property5.Attributes.Add(pinValueAttr5);

            // Define GPIO Pin-6 as device property. Device contains properties
            AdapterProperty gpioPin_Property6 = new AdapterProperty(PIN_NAME6, PIN_INTERFACE_HINT6);
            // Define and set GPIO Pin-6 value. Device contains properties that have one or more attributes.
            pinValueData6 = (int)pin6.Read();
            AdapterValue pinValueAttr6 = new AdapterValue(PIN_VALUE_NAME6, pinValueData6);
            gpioPin_Property6.Attributes.Add(pinValueAttr6);

            // Define GPIO Pin-12 as device property. Device contains properties
            AdapterProperty gpioPin_Property12 = new AdapterProperty(PIN_NAME12, PIN_INTERFACE_HINT12);
            // Define and set GPIO Pin-12 value. Device contains properties that have one or more attributes.
            pinValueData12 = (int)pin12.Read();
            AdapterValue pinValueAttr12 = new AdapterValue(PIN_VALUE_NAME12, pinValueData12);
            gpioPin_Property12.Attributes.Add(pinValueAttr12);

            // Define GPIO Pin-16 as device property. Device contains properties
            AdapterProperty gpioPin_Property16 = new AdapterProperty(PIN_NAME16, PIN_INTERFACE_HINT16);
            // Define and set GPIO Pin-16 value. Device contains properties that have one or more attributes.
            pinValueData16 = (int)pin16.Read();
            AdapterValue pinValueAttr16 = new AdapterValue(PIN_VALUE_NAME16, pinValueData16);
            gpioPin_Property16.Attributes.Add(pinValueAttr16);

            devicePin5.Properties.Add(gpioPin_Property5);

            devicePin6.Properties.Add(gpioPin_Property6);

            devicePin12.Properties.Add(gpioPin_Property12);

            devicePin16.Properties.Add(gpioPin_Property16);

            devices.Add(devicePin5);

            devices.Add(devicePin6);

            devices.Add(devicePin12);

            devices.Add(devicePin16);

            return ERROR_SUCCESS;
        }
Example #10
0
        public void AddDevice(Device device, bool isNew)
        {
            var           deviceId      = device.deviceId;
            var           friendlyId    = device.friendlyId;
            var           manufacturer  = device.manufacturer != null ? device.manufacturer : "Manufacturer";
            AdapterDevice adapterDevice = null;

            Task <HttpResponseMessage> response = httpClient.GetAsync(new Uri(DCGWUrl + "devices/" + deviceId)).AsTask();
            string body = response.Result.Content.ReadAsStringAsync().AsTask().Result;

            //DeviceProfiles deviceProifles = JsonConvert.DeserializeObject<DeviceProfiles>(JObject.Parse(body).ToString());
            foreach (var eep in device.eeps)
            {
                var eepName = eep.eep;
                response = httpClient.GetAsync(new Uri(DCGWUrl + "profiles/" + eepName)).AsTask();
                body     = response.Result.Content.ReadAsStringAsync().AsTask().Result;

                ProfileDefination profileInfo = JsonConvert.DeserializeObject <ProfileDefination>(JObject.Parse(body).ToString());
                var profile        = profileInfo.profile;
                var functionGroups = profile.functionGroups;
                var title          = profile.title != null ? profile.title : "TitleDesciption";


                if (isLampProfile(eepName))
                {
                    adapterDevice = new Lamp(friendlyId, manufacturer, eepName, "0", deviceId, title);
                    ((Lamp)adapterDevice).Adapter = this;
                }
                else
                {
                    adapterDevice = new AdapterDevice(friendlyId, manufacturer, eepName, "0", deviceId, title);
                    foreach (var functionGroup in functionGroups)
                    {
                        string titleFG   = functionGroup.title != null ? functionGroup.title : "Property";
                        string direction = direction = functionGroup.direction;;
                        var    functions = functionGroup.functions;

                        var property = new AdapterProperty(titleFG, "");
                        foreach (var function in functions)
                        {
                            var key          = function.key;
                            var description  = function.description;
                            var defaultValue = function.defaultValue;

                            var    values  = function.values;
                            string meaning = null;
                            Range  range   = null;

                            double min  = 0.0;
                            double max  = 0.0;
                            double step = 0.0;
                            string unit = null;

                            if (defaultValue == null)
                            {
                                var valueTk = values.First <Value>();
                                meaning      = valueTk.meaning;
                                range        = valueTk.range;
                                defaultValue = valueTk.value;
                                if (range != null)
                                {
                                    min          = range.min;
                                    max          = range.max;
                                    step         = range.step;
                                    unit         = range.unit;
                                    defaultValue = range.min;
                                }
                            }

                            object defaultData = Windows.Foundation.PropertyValue.CreateString(defaultValue.ToString());
                            var    valueAttr   = new AdapterAttribute(key, defaultData, deviceId, E_ACCESS_TYPE.ACCESS_READWRITE);

                            if (range != null)
                            {
                                valueAttr.Annotations.Add("min", defaultValue.ToString());
                                valueAttr.Annotations.Add("max", max.ToString());
                                valueAttr.Annotations.Add("range", step.ToString());
                                valueAttr.Annotations.Add("unit", unit);
                            }

                            if (direction.Equals("from"))
                            {
                                valueAttr = new AdapterAttribute(key, defaultData, deviceId, E_ACCESS_TYPE.ACCESS_READ);
                            }
                            else if (direction.Equals("both"))
                            {
                                object valueDataTest = Windows.Foundation.PropertyValue.CreateString("");

                                //This is a workaround to know if device supports both functionality
                                //500 is response status for read only property and 400 for device that support both direct,
                                //status is 400 because we are sending no value (valueDataTest is emplty string)
                                uint status = SetHttpValue("devices/" + deviceId + "/state", valueDataTest, key);
                                if (status == 500)
                                {
                                    valueAttr = new AdapterAttribute(key, defaultData, deviceId, E_ACCESS_TYPE.ACCESS_READ);
                                }
                            }

                            valueAttr.COVBehavior = SignalBehavior.Always;
                            adapterDevice.AddChangeOfValueSignal(property, valueAttr.Value);

                            property.Attributes.Add(valueAttr);
                        }
                        adapterDevice.Properties.Add(property);
                    }
                }
            }

            IAdapterMethod Delete = new AdapterMethod("Delete", "Delete EO device", 0, "devices/" + deviceId);

            adapterDevice.Methods.Add(Delete);

            AdapterDevice AddedDevice = (AdapterDevice)GetObject(devicesDict, deviceId);

            if (AddedDevice == null)

            {
                this.devicesDict.Add(deviceId, adapterDevice);

                //update device list in the bridge if device is added when bridge is running
                if (isNew)
                {
                    dsbBridge.UpdateDeviceCustome(adapterDevice, false);
                }
                this.NotifyDeviceArrival(adapterDevice);
            }
        }