Exemple #1
0
        // Intent function factory cache
        // static storage
        //private static Dictionary<string, Func<IIntent>> InstanceCreateCache = new Dictionary<string, Func<IIntent>>();

        public MainPage()
        {
            context.IsIoTCore = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.IoT";
            // Test for UWP on IOT Core or Windows PC

            if (context.IsIoTCore == true)
            {
                host_language = new Language("en-US"); // US for Pi, GB for Laptop;
                tft           = new AdaFruitTFT();
            }
            else
            {
                host_language = new Language("en-US"); // should be en-GB
            }
            this.InitializeComponent();

            AllJoynBusAttachment switchBusAttachment = new AllJoynBusAttachment();
            SwitchWatcher        switchWatcher       = new SwitchWatcher(switchBusAttachment);

            switchWatcher.Added += SwitchWatcher_Added;
            switchWatcher.Start();

            System.Diagnostics.Debug.WriteLine("1");
            SetupMicrophone();
            System.Diagnostics.Debug.WriteLine("2");
            InitRecogAndSyn();
            System.Diagnostics.Debug.WriteLine("3");
            ListenForPatrick();
            System.Diagnostics.Debug.WriteLine("4");
            //InitializeCameraAsync(); // Need to work out how to get the video stream seperate from the video so can control individually for speech and face.
            System.Diagnostics.Debug.WriteLine("5");
        }
Exemple #2
0
        public MainPage()
        {
            // Test for UWP on IOT Core or Windows PC
            var api = "Windows.Devices.I2c.I2cDevice";

            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent(api))
            {
                host_language = new Language("en-US"); // US for Pi, GB for Laptop;
            }
            else
            {
                host_language = new Language("en-GB");
            }


            this.InitializeComponent();

            AllJoynBusAttachment switchBusAttachment = new AllJoynBusAttachment();
            SwitchWatcher        switchWatcher       = new SwitchWatcher(switchBusAttachment);

            switchWatcher.Added += SwitchWatcher_Added;
            switchWatcher.Start();

            SetupMicrophone();

            InitRecogAndSyn();

            ListenForPatrick();
        }
Exemple #3
0
        public MainPage()
        {
            this.InitializeComponent();
            AllJoynBusAttachment switchBusAttachment = new AllJoynBusAttachment();
            SwitchWatcher        switchWatcher       = new SwitchWatcher(switchBusAttachment);

            switchWatcher.Added += SwitchWatcher_Added;
            switchWatcher.Start();
        }
Exemple #4
0
        private async void SwitchWatcher_Added(SwitchWatcher sender, AllJoynServiceInfo args)
        {
            SwitchJoinSessionResult joinSessionResult = await SwitchConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                switchConsumer           = joinSessionResult.Consumer;
                btnLightSwitch.IsEnabled = true;
            }
        }
Exemple #5
0
        // searches for the class, initiates it (calls factory method) and returns the instance
        // TODO: add a lot of error handling!
        //IIntent CreateCachableIIntent(string className)
        //{
        //    if (!InstanceCreateCache.ContainsKey(className))
        //    {
        //        try
        //        {
        //            // get the type (several ways exist, this is an eays one)
        //            Type type = Type.GetType(className);

        //            // NOTE: this can be tempting, but do NOT use the following, because you cannot
        //            // create a delegate from a ctor and will loose many performance benefits
        //            //ConstructorInfo constructorInfo = type.GetConstructor(Type.EmptyTypes);

        //            // works with public instance/static methods
        //            MethodInfo mi = type.GetMethod("Create");
        //            // the "magic", turn it into a delegate
        //            var createInstanceDelegate = (Func<IIntent>)mi.CreateDelegate(typeof(Func<IIntent>),mi);
        //            // store for future reference
        //            InstanceCreateCache.Add(className, createInstanceDelegate);
        //        }
        //        catch (Exception e)
        //        {
        //            ShowDeadEyes();
        //            Debug.WriteLine(e.Message);
        //        }
        //    }

        //    return InstanceCreateCache[className].Invoke();

        //}

        private async void SwitchWatcher_Added(SwitchWatcher sender, AllJoynServiceInfo args)
        {
            SwitchJoinSessionResult joinSessionResult = await SwitchConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                context.switchConsumer  = joinSessionResult.Consumer;
                context.lightsAvailable = true;

                SwitchGetValueResult x = await context.switchConsumer.GetValueAsync();

                context.lightStatus = (bool)x.Value;

                Speak("Things network online");
                // Wink Left
                WinkLeft.Begin();
            }
        }
Exemple #6
0
        private async void powerSwitchWatcher_Added(SwitchWatcher sender, AllJoynServiceInfo args)
        {
            var joinResult = await SwitchConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _powerSwitchConsumer              = joinResult.Consumer;
                _powerSwitchConsumer.SessionLost += this.Consumer_SessionLost;

                // subscribe to value changes
                _powerSwitchConsumer.ValueChanged += this.powerSwitchConsumer_ValueChanged;

                // populate initial values
                var result = await _powerSwitchConsumer.GetValueAsync();

                if (result.Status != AllJoynStatus.Ok)
                {
                    return;
                }
                this.IsOn = result.Value;

                this.IsConnected = true;
            }
        }
Exemple #7
0
 protected override void OnStart()
 {
     _powerSwitchWatcher        = new SwitchWatcher(this.CreateBusAttachment(ref _powerSwitchBusAttachment));
     _powerSwitchWatcher.Added += this.powerSwitchWatcher_Added;
     _powerSwitchWatcher.Start();
 }