Exemplo n.º 1
0
        /****************************************************************
         * Public Functionalities
         **/
        public void Trigger(EBTEvent p_event, ObserverInfo p_info = null)
        {
            switch (p_event)
            {
            case EBTEvent.BTE_OnFetchedDevices:
            case EBTEvent.BTE_OnDeviceConnected:
            case EBTEvent.BTE_OnDeviceDisconnected:
            case EBTEvent.BTE_OnTodaysActivity:
            case EBTEvent.BTE_OnOverallActivity:
            case EBTEvent.BTE_OnReadySportsMode:
            case EBTEvent.BTE_OnStartSportsMode:
            case EBTEvent.BTE_OnFinishSportsMode:
            {
                //~~~Do something you need to handle before triggering the event
            }
            break;
            }

            //~~~trigger event
            if (this.OnReceivedEvent == null)
            {
                return;
            }
            this.OnReceivedEvent(p_info);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sports Mode is done.
        /// </summary>
        /// <param name="data"></param>
        private void OnActivityDataEnd(byte[] data)
        {
            KreyosUtils.Log("BluetoothManager::OnActivityDataEnd", "data:" + data);
            ObserverInfo info = new ObserverInfo();

            info.Command = EBTEvent.BTE_OnFinishSportsMode;
            BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnFinishSportsMode, info);
        }
Exemplo n.º 3
0
        private void OnTodayActivityReceived(TodayActivity ta)
        {
            KreyosUtils.Log("BluetoothManager::OnTodayActivityReceived", "");
            ObserverInfo info = new ObserverInfo();

            info.Command    = EBTEvent.BTE_OnTodaysActivity;
            info.TodaysData = ta;
            BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnTodaysActivity, info);
        }
Exemplo n.º 4
0
        private void OnOverallActivitiesReceived(ActivityDataDoc doc)
        {
            KreyosUtils.Log("BluetoothManager::OnOverallActivitiesReceived", "");

            //~~~Display overall data
            ObserverInfo info = new ObserverInfo();

            info.Command     = EBTEvent.BTE_OnOverallActivity;
            info.OverallData = doc;
            BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnOverallActivity, info);
        }
Exemplo n.º 5
0
        /****************************************************************
         * Bluetooth Functionalities
         *  Note: p_delegate should never be null
         **/
        public async void GetKreyosDevices()
        {
            // Get List of devices from BluetoothAgent
            var devices = await BluetoothAgent.GetPairedDevices();

            List <string> kreyosDevices = new List <string>();

            foreach (var device in devices)
            {
                kreyosDevices.Add((string)device);
            }

            ObserverInfo info = new ObserverInfo();

            info.Command = EBTEvent.BTE_OnFetchedDevices;
            info.Devices = kreyosDevices;
            BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnFetchedDevices, info);
        }
Exemplo n.º 6
0
        private void OnSportsDataReceived(SportsDataRow sport)
        {
            KreyosUtils.Log("BluetoothManager::OnSportsDataReceived", "");
            //* Logs
            KreyosUtils.Log("Mode:", "" + sport.sports_mode);
            KreyosUtils.Log("Time:", "" + sport.seconds_elapse);
            foreach (KeyValuePair <SportsDataRow.DataType, double> pair in sport.data)
            {
                KreyosUtils.Log("Data", "" + pair.Key + ":" + pair.Value);
            }
            //*/

            ObserverInfo info = new ObserverInfo();

            info.Command    = EBTEvent.BTE_OnStartSportsMode;
            info.SportsData = sport;
            BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnStartSportsMode, info);
        }
        /****************************************************************
         * Bluetooth Delegate Methods
         **/
        private void HandleCommand (ObserverInfo p_command)
        {
            switch (p_command.Command)
            {
                case EBTEvent.BTE_OnFetchedDevices:
                {
                    this.OnFetchedKreyosDevices(p_command.Devices);
                }
                break;

                case EBTEvent.BTE_OnDeviceConnected:
                {
                    this.OnDeviceConnected(p_command.Device);
                }
                break;

                case EBTEvent.BTE_OnDeviceDisconnected:
                {
                    this.OnDeviceDisconnected(p_command.Error);
                }
                break;
            }
        }
        /****************************************************************
         * Public Functionalities
         **/
        public void Trigger (EBTEvent p_event, ObserverInfo p_info = null)
        {
            switch (p_event)
            {
                case EBTEvent.BTE_OnFetchedDevices:
                case EBTEvent.BTE_OnDeviceConnected:
                case EBTEvent.BTE_OnDeviceDisconnected:
                case EBTEvent.BTE_OnTodaysActivity:
                case EBTEvent.BTE_OnOverallActivity:
                case EBTEvent.BTE_OnReadySportsMode:
                case EBTEvent.BTE_OnStartSportsMode:
                case EBTEvent.BTE_OnFinishSportsMode:
                {
                    //~~~Do something you need to handle before triggering the event
                }
                break;
            }

            //~~~trigger event
            if (this.OnReceivedEvent == null) { return; }
            this.OnReceivedEvent(p_info);
        }
Exemplo n.º 9
0
        public async void ConnectKreyosDevice (string p_device)
        {
            if (string.IsNullOrWhiteSpace(p_device))
            {
                ObserverInfo info = new ObserverInfo();
                info.Command = EBTEvent.BTE_OnDeviceDisconnected;
                info.Error = "Error! Invalid device name!";
                BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnDeviceDisconnected, info);
                return;
            }

            var succ = await BluetoothAgent.Instance.Start(p_device);

            if (succ)
            {
                BluetoothAgent.Instance.InnerProtocol.OnElementParsed               += OnElementParsed;
                BluetoothAgent.Instance.InnerProtocol.OnFileReceived                += OnFileReceived;
                BluetoothAgent.Instance.InnerProtocol.OnDeviceIDRead                += OnDeviceIDRead;
                BluetoothAgent.Instance.InnerProtocol.OnActivityDataRead            += OnActivityDataRead;
                BluetoothAgent.Instance.InnerProtocol.OnSportsGridRead              += OnSportsGridRead;
                BluetoothAgent.Instance.InnerProtocol.OnActivityDataEnd             += OnActivityDataEnd;
                BluetoothAgent.Instance.InnerProtocol.OnActivityDataPrepared        += OnActivityDataPrepared;
                BluetoothAgent.Instance.InnerProtocol.OnActivityDataSync            += OnActivityDataSync;
                BluetoothAgent.Instance.InnerProtocol.OnFirmwareVersionRequest      += OnFirmwareVersionRequest;

                BluetoothAgent.Instance.InnerProtocol.OnOverallActivitiesReceived   += OnOverallActivitiesReceived;
                BluetoothAgent.Instance.InnerProtocol.OnTodayActivityReceived       += OnTodayActivityReceived;
                BluetoothAgent.Instance.InnerProtocol.OnSportsDataReceived          += OnSportsDataReceived;

                ObserverInfo info = new ObserverInfo();
                info.Command = EBTEvent.BTE_OnDeviceConnected;
                info.Device = p_device;
                BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnDeviceConnected, info);
                return;
            }
            else
            {
                switch (BluetoothAgent.Instance.ConnectInfo)
                {
                    case EBTConnect.BluetoothIsOff:
                    {
                        var result = MessageBox.Show("Bluetooth is turned off. To see the current Bluetooth settings tap 'ok'", "Bluetooth Off", MessageBoxButton.OKCancel);
                        if (result == MessageBoxResult.OK)
                        {
                            // TODO: Show the bluetooth control panel here
                            ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
                            connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Bluetooth;
                            connectionSettingsTask.Show();
                        }
                    }
                    break;

                    case EBTConnect.CapPermission:
                    {
                        MessageBox.Show("To run this app, you must have ID_CAP_PROXIMITY enabled in WMAppManifest.xaml");
                    }
                    break;
                }

                ObserverInfo info = new ObserverInfo();
                info.Command = EBTEvent.BTE_OnDeviceDisconnected;
                info.Error = BluetoothAgent.Instance.ErrorMessage;
                BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnDeviceDisconnected, info);
            }
        }
Exemplo n.º 10
0
        /****************************************************************
         * Bluetooth Functionalities
         *  Note: p_delegate should never be null
         **/
        public async void GetKreyosDevices ()
        {
            // Get List of devices from BluetoothAgent
            var devices = await BluetoothAgent.GetPairedDevices();
            List<string> kreyosDevices = new List<string>();

            foreach (var device in devices)
            {
                kreyosDevices.Add((string)device);
            }

            ObserverInfo info = new ObserverInfo();
            info.Command = EBTEvent.BTE_OnFetchedDevices;
            info.Devices = kreyosDevices;
            BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnFetchedDevices, info);
        }
Exemplo n.º 11
0
        private void OnSportsDataReceived(SportsDataRow sport)
        {
            KreyosUtils.Log("BluetoothManager::OnSportsDataReceived", "");
            //* Logs
            KreyosUtils.Log("Mode:", "" + sport.sports_mode);
            KreyosUtils.Log("Time:", "" + sport.seconds_elapse);
            foreach (KeyValuePair<SportsDataRow.DataType, double> pair in sport.data)
            {
                KreyosUtils.Log("Data", "" + pair.Key + ":" + pair.Value);
            }
            //*/

            ObserverInfo info = new ObserverInfo();
            info.Command = EBTEvent.BTE_OnStartSportsMode;
            info.SportsData = sport;
            BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnStartSportsMode, info);
        }
Exemplo n.º 12
0
 private void OnTodayActivityReceived (TodayActivity ta)
 {
     KreyosUtils.Log("BluetoothManager::OnTodayActivityReceived", "");
     ObserverInfo info = new ObserverInfo();
     info.Command = EBTEvent.BTE_OnTodaysActivity;
     info.TodaysData = ta;
     BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnTodaysActivity, info);
 }
Exemplo n.º 13
0
 private void OnOverallActivitiesReceived (ActivityDataDoc doc)
 {
     KreyosUtils.Log("BluetoothManager::OnOverallActivitiesReceived", "");
     
     //~~~Display overall data
     ObserverInfo info = new ObserverInfo();
     info.Command = EBTEvent.BTE_OnOverallActivity;
     info.OverallData = doc;
     BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnOverallActivity, info);
 }
Exemplo n.º 14
0
 public void AddCommand (ObserverInfo p_info)
 {
     m_commands.Add(p_info);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Handle commands
 /// </summary>
 private void HandleCommand (ObserverInfo p_command)
 {
     this.AddCommand (p_command);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Sports Mode is done.
 /// </summary>
 /// <param name="data"></param>
 private void OnActivityDataEnd(byte[] data)
 {
     KreyosUtils.Log("BluetoothManager::OnActivityDataEnd", "data:" + data);
     ObserverInfo info = new ObserverInfo();
     info.Command = EBTEvent.BTE_OnFinishSportsMode;
     BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnFinishSportsMode, info);
 }
Exemplo n.º 17
0
        public async void ConnectKreyosDevice(string p_device)
        {
            if (string.IsNullOrWhiteSpace(p_device))
            {
                ObserverInfo info = new ObserverInfo();
                info.Command = EBTEvent.BTE_OnDeviceDisconnected;
                info.Error   = "Error! Invalid device name!";
                BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnDeviceDisconnected, info);
                return;
            }

            var succ = await BluetoothAgent.Instance.Start(p_device);

            if (succ)
            {
                BluetoothAgent.Instance.InnerProtocol.OnElementParsed          += OnElementParsed;
                BluetoothAgent.Instance.InnerProtocol.OnFileReceived           += OnFileReceived;
                BluetoothAgent.Instance.InnerProtocol.OnDeviceIDRead           += OnDeviceIDRead;
                BluetoothAgent.Instance.InnerProtocol.OnActivityDataRead       += OnActivityDataRead;
                BluetoothAgent.Instance.InnerProtocol.OnSportsGridRead         += OnSportsGridRead;
                BluetoothAgent.Instance.InnerProtocol.OnActivityDataEnd        += OnActivityDataEnd;
                BluetoothAgent.Instance.InnerProtocol.OnActivityDataPrepared   += OnActivityDataPrepared;
                BluetoothAgent.Instance.InnerProtocol.OnActivityDataSync       += OnActivityDataSync;
                BluetoothAgent.Instance.InnerProtocol.OnFirmwareVersionRequest += OnFirmwareVersionRequest;

                BluetoothAgent.Instance.InnerProtocol.OnOverallActivitiesReceived += OnOverallActivitiesReceived;
                BluetoothAgent.Instance.InnerProtocol.OnTodayActivityReceived     += OnTodayActivityReceived;
                BluetoothAgent.Instance.InnerProtocol.OnSportsDataReceived        += OnSportsDataReceived;

                ObserverInfo info = new ObserverInfo();
                info.Command = EBTEvent.BTE_OnDeviceConnected;
                info.Device  = p_device;
                BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnDeviceConnected, info);
                return;
            }
            else
            {
                switch (BluetoothAgent.Instance.ConnectInfo)
                {
                case EBTConnect.BluetoothIsOff:
                {
                    var result = MessageBox.Show("Bluetooth is turned off. To see the current Bluetooth settings tap 'ok'", "Bluetooth Off", MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.OK)
                    {
                        // TODO: Show the bluetooth control panel here
                        ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
                        connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Bluetooth;
                        connectionSettingsTask.Show();
                    }
                }
                break;

                case EBTConnect.CapPermission:
                {
                    MessageBox.Show("To run this app, you must have ID_CAP_PROXIMITY enabled in WMAppManifest.xaml");
                }
                break;
                }

                ObserverInfo info = new ObserverInfo();
                info.Command = EBTEvent.BTE_OnDeviceDisconnected;
                info.Error   = BluetoothAgent.Instance.ErrorMessage;
                BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnDeviceDisconnected, info);
            }
        }