Example #1
0
        private async void StartStreams()
        {
            this.sensorClient = new ClientSensor();

            var streamTasks = new List <Task>
            {
                this.StartAccelerometerStream(),
                this.StartHeartRateStream(),
                this.StartSkinTemperatureStream(),
                this.StartContactStream(),
                this.StartPedometerStream(),
                this.StartUVIndexStream(),
                this.StartCaloriesStream(),
                this.StartGSRStream(),
                this.StartAmbientLightStream(),
                this.StartAltimeterStream(),
                this.StartBarometerStream(),
                this.StartRRIntervalStream()
            };

            try
            {
                await Task.WhenAll(streamTasks);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                await c.saveStringToLocalFile("DebugLogs.txt", "TimeStamp: " + BandController.CurrentDate() + " Debug: " + "Connecting to the Sensors - " + ex.Message);
            }
        }
Example #2
0
        private async void RemoveTile()
        {
            try
            {
                // get the current set of tiles
                IEnumerable <BandTile> tiles = await bandClient.TileManager.GetTilesAsync();

                foreach (var t in tiles)
                {
                    // remove the tile from the Band
                    if (await bandClient.TileManager.RemoveTileAsync(t))
                    {
                        // do work if the tile was successfully removed

                        MessageDialog msg = new MessageDialog("Tile removed.");
                        await msg.ShowAsync();
                    }
                    else
                    {
                        MessageDialog msg = new MessageDialog("Failure at removing the tile.");
                        await msg.ShowAsync();
                    }
                }
            }
            catch (BandException ex)
            {
                Debug.WriteLine(ex.Message);
                await c.saveStringToLocalFile("DebugLogs.txt", "TimeStamp: " + BandController.CurrentDate() + " Debug: " + "Removing Tile - " + ex.Message);
            }
        }
Example #3
0
        private async Task <bool> AddTile()
        {
            try
            {
                // Create the small and tile icons from writable bitmaps.
                // Small icons are 24x24 pixels.
                //WriteableBitmap smallIconBitmap = new WriteableBitmap(24, 24);
                //BandIcon smallIcon = smallIconBitmap.ToBandIcon();
                //// Tile icons are 46x46 pixels for Microsoft Band 1, and 48x48 pixels
                //// for Microsoft Band 2.
                //WriteableBitmap tileIconBitmap = new WriteableBitmap(46, 46);
                //BandIcon tileIcon = tileIconBitmap.ToBandIcon();

                int version = Convert.ToInt32(bandVersion);

                if (version <= 19)
                {
                    BandIcon tileIcon = await ConvertIMG("ms-appx:///Assets/46x46.png");

                    BandIcon smallIcon = await ConvertIMG("ms-appx:///Assets/24x24.png");
                }
                else
                {
                    BandIcon tileIcon = await ConvertIMG("ms-appx:///Assets/48x48.png");

                    BandIcon smallIcon = await ConvertIMG("ms-appx:///Assets/24x24.png");
                }



                var myTile = new BandTile(myTileId)
                {
                    IsBadgingEnabled = true,
                    Name             = "MS Band Data Collection",
                    //TileIcon = tileIcon,
                    //SmallIcon = smallIcon
                    TileIcon  = tileIcon,
                    SmallIcon = smallIcon
                };

                // Remove the Tile from the Band, if present. An application won't need to do this everytime it runs.
                // But in case you modify this sample code and run it again, let's make sure to start fresh.
                //await bandClient.TileManager.RemoveTileAsync(myTileId);

                // Create the Tile on the Band.
                await bandClient.TileManager.AddTileAsync(myTile);

                // Subscribe to Tile events.
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error on adding a tile to the band:  " + ex);
                await c.saveStringToLocalFile("DebugLogs.txt", "TimeStamp: " + BandController.CurrentDate() + " Debug: " + " Error on adding a tile to the band - " + ex);
            }
            return(false);
        }
Example #4
0
        private async Task InitAsync()
        {
            try
            {
                this.selectedBand = await this.FindDevicesAsync();

                if (this.selectedBand == null)
                {
                    return;
                }

                this.bandClient = await this.ConnectAsync();

                if (this.bandClient == null)
                {
                    return;
                }

                //await this.LoadBandRegistrySensor();
                //if (this.bandRegistrySensor == null)
                //{
                //    return;
                //}

                //RemoveTile();

                bandVersion = await this.bandClient.GetHardwareVersionAsync();

                AddingTile();

                this.StartStreams();

                StartConnectionChecker();
            }
            catch (Exception x)
            {
                Debug.WriteLine(x.Message);
                await c.saveStringToLocalFile("DebugLogs.txt", "TimeStamp: " + BandController.CurrentDate() + " Debug: " + "Connecting to the Band - " + x.Message);
            }
            finally
            {
                this.initializingTask = null;
            }
        }
Example #5
0
        //private async Task LoadBandRegistrySensor()
        //{
        //    var client = new ClientRegistryPeople();

        //    try
        //    {
        //        var personalSensors = await client.ListPersonalSensorsAsync(this.currentCredentials);

        //        this.bandRegistrySensor =
        //            personalSensors.FirstOrDefault(
        //                registrySensor => registrySensor.ExtraData["HardwareAddress"] == this.selectedBand.Name);

        //        if (this.bandRegistrySensor == null)
        //        {
        //            return;
        //        }

        //        foreach (string channelCode in this.bandRegistrySensor.ExtraData["DataChannels"])
        //        {
        //            string channelName;
        //            if (!FHIRDefinitions.Instance.FHIRToSensorTypes.TryGetValue(channelCode, out channelName))
        //            {
        //                continue;
        //            }

        //            this.channels.Add(channelName, channelCode);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Debug.WriteLine(ex);
        //    }
        //    finally
        //    {
        //        client.Dispose();
        //    }
        //}

        private async void AddingTile()
        {
            try
            {
                IEnumerable <BandTile> tile = await GetTiles();

                var capacity = await bandClient.TileManager.GetRemainingTileCapacityAsync();

                if (tile != null)
                {
                    if (capacity != 0)
                    {
                        await AddTile();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                await c.saveStringToLocalFile("DebugLogs.txt", "TimeStamp: " + BandController.CurrentDate() + " Debug: " + "Adding Tile - " + ex.Message);
            }
        }
Example #6
0
        public async void SendMessage(string message)
        {
            var notifictionManager = bandClient.NotificationManager;

            //IEnumerable<BandTile> tiles = await GetTiles();

            //var tileId = tiles.GetEnumerator().Current.TileId;
            try
            {
                await notifictionManager.VibrateAsync(VibrationType.ThreeToneHigh);

                await notifictionManager.ShowDialogAsync(
                    myTileId,
                    "WBA Alert - High HR",
                    "Please take a break"
                    );

                await notifictionManager.SendMessageAsync(
                    myTileId,
                    "WBA Alert - High HR",
                    "Average HR: " + message,
                    DateTimeOffset.Now);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                await c.saveStringToLocalFile("DebugLogs.txt", "TimeStamp: " + BandController.CurrentDate() + " Debug: " + "Tile Send Message feature - " + ex.Message);
            }

            // send a notification to the Band with a dialog as well as a page
            //await notifictionManager.SendMessageAsync(
            //    tileId,
            //    "Message Title",
            //    "This is the message body...",
            //    DateTime.Now,
            //    true);
        }
Example #7
0
        private async void StartLogs()
        {
            await c.saveStringToLocalFile("BandHRLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandSkinTempLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandContactLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandPedometerLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandUVLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandCaloriesLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandGsrLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandAmbientLightLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandAltimeterLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandBarometerLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");

            await c.saveStringToLocalFile("BandRRIntervalLogs.txt", "----- Application started at " + BandController.CurrentDate() + " ---");
        }