Exemplo n.º 1
0
        public MainPage()
        {
            this.InitializeComponent();
            IHubProxy DoorHubProxy = _HubConnection.CreateHubProxy("DoorHub");

            DoorHubProxy.On("GetMessage", async() =>
            {
                _Sensor.IsActive = false;
                MotorController.PWM(26);
                await Task.Delay(20000);
                _Sensor.IsActive = true;
            });
        }
Exemplo n.º 2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // await _HubConnection.Start();

            var cam = new MediaCapture();

            await cam.InitializeAsync(new MediaCaptureInitializationSettings()
            {
                MediaCategory        = MediaCategory.Media,
                StreamingCaptureMode = StreamingCaptureMode.Video
            });

            _Sensor.MotionDetected += async(int pinNum) =>
            {
                await Task.Factory.StartNew(async() =>
                {
                    _Sensor.IsActive = false;
                    var stream       = new InMemoryRandomAccessStream();
                    await cam.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
                    stream.Seek(0);
                    var imageStream = stream.AsStream();
                    imageStream.Seek(0, SeekOrigin.Begin);
                    string imageUrl = await NotificationHelper.UploadImageAsync(imageStream);

                    switch (await OxfordHelper.IdentifyAsync(imageUrl))
                    {
                    case AuthenticationResult.IsOwner:
                        // open the door
                        MotorController.PWM(26);
                        break;

                    case AuthenticationResult.Unkown:
                        // send notification to the owner
                        await NotificationHelper.NotifyOwnerAsync(imageUrl);
                        break;

                    case AuthenticationResult.None:
                    default:
                        break;
                    }
                    _Sensor.IsActive = true;
                });
            };
        }