protected void InitAllJoyn()
        {
            try
            {
                adapter = new Adapter();
                dsbBridge = new DsbBridge(adapter);

                var initResult = dsbBridge.Initialize();
                if (initResult != 0)
                {
                    throw new Exception("DSB Bridge initialization failed!");
                }
            }
            catch (Exception ex)
            {
                if (dsbBridge != null)
                {
                    dsbBridge.Shutdown();
                }

                if (adapter != null)
                {
                    adapter.Shutdown();
                }

                throw;
            }
        }
Exemplo n.º 2
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            Adapter adapter = null;
            deferral = taskInstance.GetDeferral();

            try
            {
                adapter = new Adapter();
                dsbBridge = new DsbBridge(adapter);

                var initResult = dsbBridge.Initialize();
                if (initResult != 0)
                {
                    throw new Exception("DSB Bridge initialization failed!");
                }
            }
            catch (Exception ex)
            {
                if (dsbBridge != null)
                {
                    dsbBridge.Shutdown();
                }

                if (adapter != null)
                {
                    adapter.Shutdown();
                }

                throw;
            }
        }
        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();
        }
        private AllJoynDeviceManager()
        {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            StartupTask = ThreadPool.RunAsync(new WorkItemHandler((IAsyncAction action) =>
            {
                try
                {
                    adapter = new Adapter();
                    dsbBridge = new DsbBridge(adapter);

                    var initResult = dsbBridge.Initialize();
                    if (initResult != 0)
                    {
                        throw new Exception("DSB Bridge initialization failed!");
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            })).AsTask();
            InitializeNotification();  
        }
Exemplo n.º 5
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            #if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
            #endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;

            #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                startupTask = ThreadPool.RunAsync(new WorkItemHandler((IAsyncAction action) =>
                {
                    try
                    {
                        var adapter = new Adapter();
                        dsbBridge = new DsbBridge(adapter);

                        var initResult = dsbBridge.Initialize();
                        if (initResult != 0)
                        {
                            throw new Exception("DSB Bridge initialization failed!");
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                })).AsTask();

            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
                if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily.Equals("Windows.IoT",StringComparison.OrdinalIgnoreCase))
                {
                    var op = ThreadPool.RunAsync(new WorkItemHandler((source) =>
                    {
                    // Check if we hav GPIO on board or just run client side
                    try
                        {
                            var adapter = new Adapter();

                            dsbBrifge = new DsbBridge(adapter);

                            if (dsbBrifge != null)
                                dsbBrifge.Initialize();
                        }
                        catch (Exception ex) {                           
                            Debug.WriteLine("Error loding local sensors: " + ex.Message);
                        }

                    }));

                    op.Completed = delegate (IAsyncAction asyncAction, AsyncStatus asyncStatus)
                    {
                        var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
                        var opp = dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, delegate
                        {
                            if (dsbBrifge != null && OnBridgeInitialized != null)
                                OnBridgeInitialized.Invoke(asyncAction, asyncStatus);
                        });
                    };
                }

            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
Exemplo n.º 7
0
        public bool AddClusterToEndPoint(bool isInCluster, byte endPointId, UInt16 profileId, UInt16 deviceId, UInt16 clusterId, Adapter adapter)
        {
            bool newEndPoint = false;

            // sanity check
            if (adapter == null &&
                m_adapter == null)
            {
                // can't do anything without XBeeModule
                return(false);
            }

            // save away XBeeModule if necessary
            if (m_adapter == null)
            {
                m_adapter = adapter;
            }

            // find relevant end point (create if if necessary)
            ZigBeeEndPoint endPoint = null;

            if (!m_endPointList.TryGetValue(endPointId, out endPoint))
            {
                endPoint = new ZigBeeEndPoint(endPointId, profileId, deviceId);
                endPoint.Initialize(this);
                newEndPoint = true;
            }

            // add cluster to end point
            if (!endPoint.AddCluster(clusterId, isInCluster))
            {
                return(false);
            }

            // add new end point to end point list
            if (newEndPoint)
            {
                m_endPointList.Add(endPoint.Id, endPoint);
            }
            return(true);
        }
Exemplo n.º 8
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();
        }