Beispiel #1
0
 private void AuthBLE()
 {
     // 기기 인증
     device = new MiBand(_deviceManager);
     device.Authenticate(OnAuth);
     button3.Enabled = false;
 }
Beispiel #2
0
        private async void finishSetup()
        {
            if (band != null)
            {
                var  loader = new Windows.ApplicationModel.Resources.ResourceLoader();
                bool authed = await band.Authenticate();

                if (!authed)
                {
                    Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        MessageDialog dialog = new MessageDialog(loader.GetString("AuthErrorText"), loader.GetString("ErrorTitle"));
                        await dialog.ShowAsync();
                    });
                }
                #region notifications
                int notificationsRet = await band.TurnOnNotifications();

                if (notificationsRet > 0)
                {
                    if ((notificationsRet & 0x01) > 0)
                    {
                        band.onNotificationCallback = properties.notificationValueChanged;
                    }
                    else
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            MessageDialog dialog = new MessageDialog(loader.GetString("NotifError1"), loader.GetString("ErrorTitle"));
                            await dialog.ShowAsync();
                        });
                    }
                    if ((notificationsRet & 0x02) > 0)
                    {
                        band.onRealtimeStepsCallback = properties.realtimeStepsValueChanged;
                    }
                    else
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            MessageDialog dialog = new MessageDialog(loader.GetString("NotifError2"), loader.GetString("ErrorTitle"));
                            await dialog.ShowAsync();
                        });
                    }
                    if ((notificationsRet & 0x04) > 0)
                    {
                        band.onBatteryCallback = properties.batteryValueChanged;
                    }
                    else
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            MessageDialog dialog = new MessageDialog(loader.GetString("NotifError3"), loader.GetString("ErrorTitle"));
                            await dialog.ShowAsync();
                        });
                    }
                    if ((notificationsRet & 0x08) > 0)
                    {
                        band.onActivityDataCallback = properties.activityDataValueChanged;
                    }
                    else
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            MessageDialog dialog = new MessageDialog(loader.GetString("NotifError4"), loader.GetString("ErrorTitle"));
                            await dialog.ShowAsync();
                        });
                    }

                    /*
                     * if ((notificationsRet & 0x10) > 0)
                     * { band.onSensorDataCallback = properties.sensorDataValueChanged; }
                     * else
                     * {
                     * Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => {
                     *  MessageDialog dialog = new MessageDialog(loader.GetString("NotifError5"), loader.GetString("ErrorTitle"));
                     *  await dialog.ShowAsync();
                     * });
                     * }
                     */
                }
                else
                {
                    Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        MessageDialog dialog = new MessageDialog("error al activar las notificaciones", loader.GetString("ErrorTitle"));
                        await dialog.ShowAsync();
                    });
                }
                #endregion
                bool ret = await band.SetUnconfigurables();

                updateInfoFromBand();
                await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    properties.BGLoading  = false;
                    properties.BGLoadingV = Visibility.Collapsed;
                });

                MiBand.Ready = true;
            }
        }