Exemplo n.º 1
0
        /// <summary>
        /// Suscribe all sensors asynchronously
        /// </summary>
        /// <returns></returns>
        public async Task SuscribeSensors()
        {
            // Get band info
            SuscribeBandInfo();

            // Contact sensor
            SuscribeContactSensor();

            //Heart rate sensor
            await SuscribeHeartRateSensor();

            // RR Interval
            SuscribeRRInterval();

            // GSR
            SuscribeGSRSensor();

            // Skin temperature
            SuscribeSkinTemperatureSensor();

            // Accelerometer
            SuscribeAccelerometerSensor();

            // Gyroscope
            SuscribeGyroscopeSensor();

            // Give the user a feedback when the suscribing process has finished
            await bandClient.NotificationManager.VibrateAsync(Microsoft.Band.Notifications.VibrationType.NotificationOneTone);

            status = BandSyncStatus.SYNCED;
        }
Exemplo n.º 2
0
 /// <summary>
 /// If we had a previous sync, just reset the status and recycle the same object
 /// </summary>
 public void Reconnect()
 {
     if (status == BandSyncStatus.SYNCED_TERMINATED)
     {
         status = BandSyncStatus.SYNCED_SUSCRIBING;
     }
 }
Exemplo n.º 3
0
        public Band()
        {
            data   = new SensorData();
            status = BandSyncStatus.UNKNOWN;
            SessionTrackInterval = 1000; // in milliseconds

            sessionData = new Dictionary <DateTime, SensorData>();

            sessionTrackIntervalTimer = new Timer(sessionTrackIntervalTimer_Callback, null, Timeout.Infinite, SessionTrackInterval);
        }
Exemplo n.º 4
0
        public Band()
        {
            data = new SensorData();
            status = BandSyncStatus.UNKNOWN;
            SessionTrackInterval = 1000; // in milliseconds

            sessionData = new Dictionary<DateTime, SensorData>();

            sessionTrackIntervalTimer = new Timer(sessionTrackIntervalTimer_Callback, null, Timeout.Infinite, SessionTrackInterval);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sync to a band
        /// </summary>
        /// <param name="bandIndex">The band to sync to. '0' is the first paired band found on the system</param>
        /// <returns></returns>
        public async Task SyncBand(int bandIndex = 1)
        {
            pairedBandIndex = (bandIndex <= 0) ? 0 : bandIndex - 1;

            try
            {
                // Get the list of all Microsoft Bands paired to the device
                pairedBands = await BandClientManager.Instance.GetBandsAsync();

                if (pairedBands.Length < 1)
                {
                    status = BandSyncStatus.NO_PAIR_BAND_FOUND;
                }
                else
                {
                    pairedBandIndex = (pairedBandIndex >= pairedBands.Length) ? 0 : pairedBandIndex;

                    // Get the band's name with the bluetooth address removed
                    string[] bandName = pairedBands[pairedBandIndex].Name.Split(':');

                    BandName = bandName[0].Remove(bandName[0].LastIndexOf(' '));

                    // Connect to the band
                    bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[pairedBandIndex]);

                    status = BandSyncStatus.SYNCED_SUSCRIBING;
                }
            }
            catch (BandAccessDeniedException)
            {
                status = BandSyncStatus.NO_SYNC_PERMISSION;

                throw;
            }
            catch (BandIOException)
            {
                status = BandSyncStatus.BAND_IO_EXCEPTION;

                throw;
            }
            catch (Exception)
            {
                status = BandSyncStatus.SYNC_ERROR;

                throw;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Unsuscribe all sensors and remove their events
        /// </summary>
        /// <param name="unsuscribeContact">If there is no need to know if the user is wearing the band anymore, then unscribe contact sensor too</param>
        /// <param name="updateStatus">Update the band sync status</param>
        /// <param name="dispose">Dispose the bandclient object. Necessary when switching to another Page</param>
        public void UnsuscribeSensors(bool unsuscribeContact = false, bool updateStatus = false, bool dispose = false)
        {
            if (updateStatus)
            {
                status = BandSyncStatus.SYNCED_TERMINATED;
            }

            if (bandClient != null)
            {
                bandClient.SensorManager.HeartRate.ReadingChanged -= HeartRate_ReadingChanged;
                bandClient.SensorManager.HeartRate.StopReadingsAsync();

                bandClient.SensorManager.RRInterval.ReadingChanged -= RRInterval_ReadingChanged;
                bandClient.SensorManager.RRInterval.StopReadingsAsync();

                bandClient.SensorManager.SkinTemperature.ReadingChanged -= SkinTemperature_ReadingChanged;
                bandClient.SensorManager.SkinTemperature.StopReadingsAsync();

                bandClient.SensorManager.Gsr.ReadingChanged -= Gsr_ReadingChanged;
                bandClient.SensorManager.Gsr.StopReadingsAsync();

                bandClient.SensorManager.Accelerometer.ReadingChanged -= Accelerometer_ReadingChanged;
                bandClient.SensorManager.Accelerometer.StopReadingsAsync();

                bandClient.SensorManager.Gyroscope.ReadingChanged -= Gyroscope_ReadingChanged;
                bandClient.SensorManager.Gyroscope.StopReadingsAsync();

                if (unsuscribeContact)
                {
                    bandClient.SensorManager.Contact.ReadingChanged -= Contact_ReadingChanged;
                    bandClient.SensorManager.Contact.StopReadingsAsync();
                }

                // Necessary to dispose explicitly in case we want to reload the dashboard along an app session
                if (dispose)
                {
                    bandClient.Dispose();
                }
            }
        }
Exemplo n.º 7
0
        private async void SuscribeRRInterval()
        {
            // We need the user consent for this sensor. Actually we need the Heart Rate sensor consent only
            if (bandClient.SensorManager.RRInterval.GetCurrentUserConsent() == UserConsent.Granted)
            {
                sensorRRUserConsent = true;
            }
            else
            {
                sensorRRUserConsent = await bandClient.SensorManager.RRInterval.RequestUserConsentAsync();
            }

            if (!sensorRRUserConsent)
            {
                status = BandSyncStatus.SYNCED_LIMITED_ACCESS;

                return;
            }

            bandClient.SensorManager.RRInterval.ReadingChanged += RRInterval_ReadingChanged;
            await bandClient.SensorManager.RRInterval.StartReadingsAsync();
        }
Exemplo n.º 8
0
        private async Task SuscribeHeartRateSensor()
        {
            // We need the user consent for using this sensor
            if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() == UserConsent.Granted)
            {
                sensorHRUserConsent = true;
            }
            else
            {
                sensorHRUserConsent = await bandClient.SensorManager.HeartRate.RequestUserConsentAsync();
            }

            if (!sensorHRUserConsent)
            {
                status = BandSyncStatus.SYNCED_LIMITED_ACCESS;

                return;
            }

            // Subscribe to HeartRate sensor
            bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;
            await bandClient.SensorManager.HeartRate.StartReadingsAsync();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Sync to a band
        /// </summary>
        /// <param name="bandIndex">The band to sync to. '0' is the first paired band found on the system</param>
        /// <returns></returns>
        public async Task SyncBand(int bandIndex = 1)
        {
            pairedBandIndex = (bandIndex <= 0) ? 0 : bandIndex - 1;

            try
            {
                // Get the list of all Microsoft Bands paired to the device
                pairedBands = await BandClientManager.Instance.GetBandsAsync();

                if (pairedBands.Length < 1)
                {
                    status = BandSyncStatus.NO_PAIR_BAND_FOUND;
                }
                else
                {
                    pairedBandIndex = (pairedBandIndex >= pairedBands.Length) ? 0 : pairedBandIndex;

                    // Get the band's name with the bluetooth address removed
                    string[] bandName = pairedBands[pairedBandIndex].Name.Split(':');

                    BandName = bandName[0].Remove(bandName[0].LastIndexOf(' '));

                    // Connect to the band
                    bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[pairedBandIndex]);

                    status = BandSyncStatus.SYNCED_SUSCRIBING;
                }
            }
            catch (BandAccessDeniedException)
            {
                status = BandSyncStatus.NO_SYNC_PERMISSION;

                throw;
            }
            catch (BandIOException)
            {
                status = BandSyncStatus.BAND_IO_EXCEPTION;

                throw;
            }
            catch (Exception)
            {
                status = BandSyncStatus.SYNC_ERROR;

                throw;
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// If we had a previous sync, just reset the status and recycle the same object
 /// </summary>
 public void Reconnect()
 {
     if (status == BandSyncStatus.SYNCED_TERMINATED)
     {
         status = BandSyncStatus.SYNCED_SUSCRIBING;
     }
 }
Exemplo n.º 11
0
        private async void SuscribeRRInterval()
        {
            // We need the user consent for this sensor. Actually we need the Heart Rate sensor consent only
            if (bandClient.SensorManager.RRInterval.GetCurrentUserConsent() == UserConsent.Granted)
            {
                sensorRRUserConsent = true;
            }
            else
            {
                sensorRRUserConsent = await bandClient.SensorManager.RRInterval.RequestUserConsentAsync();
            }

            if (!sensorRRUserConsent)
            {
                status = BandSyncStatus.SYNCED_LIMITED_ACCESS;

                return;
            }

            bandClient.SensorManager.RRInterval.ReadingChanged += RRInterval_ReadingChanged;
            await bandClient.SensorManager.RRInterval.StartReadingsAsync();
        }
Exemplo n.º 12
0
        private async Task SuscribeHeartRateSensor()
        {
            // We need the user consent for using this sensor
            if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() == UserConsent.Granted)
            {
                sensorHRUserConsent = true;
            }
            else
            {
                sensorHRUserConsent = await bandClient.SensorManager.HeartRate.RequestUserConsentAsync();
            }

            if (!sensorHRUserConsent)
            {
                status = BandSyncStatus.SYNCED_LIMITED_ACCESS;

                return;
            }

            // Subscribe to HeartRate sensor
            bandClient.SensorManager.HeartRate.ReadingChanged += HeartRate_ReadingChanged;
            await bandClient.SensorManager.HeartRate.StartReadingsAsync();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Unsuscribe all sensors and remove their events
        /// </summary>
        /// <param name="unsuscribeContact">If there is no need to know if the user is wearing the band anymore, then unscribe contact sensor too</param>
        /// <param name="updateStatus">Update the band sync status</param>
        /// <param name="dispose">Dispose the bandclient object. Necessary when switching to another Page</param>
        public void UnsuscribeSensors(bool unsuscribeContact = false, bool updateStatus = false, bool dispose = false)
        {
            if (updateStatus)
            {
                status = BandSyncStatus.SYNCED_TERMINATED;
            }

            if (bandClient != null)
            {
                bandClient.SensorManager.HeartRate.ReadingChanged -= HeartRate_ReadingChanged;
                bandClient.SensorManager.HeartRate.StopReadingsAsync();

                bandClient.SensorManager.RRInterval.ReadingChanged -= RRInterval_ReadingChanged;
                bandClient.SensorManager.RRInterval.StopReadingsAsync();

                bandClient.SensorManager.SkinTemperature.ReadingChanged -= SkinTemperature_ReadingChanged;
                bandClient.SensorManager.SkinTemperature.StopReadingsAsync();

                bandClient.SensorManager.Gsr.ReadingChanged -= Gsr_ReadingChanged;
                bandClient.SensorManager.Gsr.StopReadingsAsync();

                bandClient.SensorManager.Accelerometer.ReadingChanged -= Accelerometer_ReadingChanged;
                bandClient.SensorManager.Accelerometer.StopReadingsAsync();

                bandClient.SensorManager.Gyroscope.ReadingChanged -= Gyroscope_ReadingChanged;
                bandClient.SensorManager.Gyroscope.StopReadingsAsync();

                if (unsuscribeContact)
                {
                    bandClient.SensorManager.Contact.ReadingChanged -= Contact_ReadingChanged;
                    bandClient.SensorManager.Contact.StopReadingsAsync();
                }

                // Necessary to dispose explicitly in case we want to reload the dashboard along an app session
                if (dispose)
                {
                    bandClient.Dispose();
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Suscribe all sensors asynchronously
        /// </summary>
        /// <returns></returns>
        public async Task SuscribeSensors()
        {
            // Get band info
            SuscribeBandInfo();

            // Contact sensor
            SuscribeContactSensor();

            //Heart rate sensor
            await SuscribeHeartRateSensor();

            // RR Interval
            SuscribeRRInterval();

            // GSR
            SuscribeGSRSensor();

            // Skin temperature
            SuscribeSkinTemperatureSensor();

            // Accelerometer
            SuscribeAccelerometerSensor();

            // Gyroscope
            SuscribeGyroscopeSensor();

            // Give the user a feedback when the suscribing process has finished
            await bandClient.NotificationManager.VibrateAsync(Microsoft.Band.Notifications.VibrationType.NotificationOneTone);

            status = BandSyncStatus.SYNCED;
        }