コード例 #1
0
        /// <summary>
        /// Adds the sensor from the service
        /// </summary>
        /// <param name="">.</param>
        private void AddNewSensor(object sender, SensorStateEventArgs e)
        {
            if (AppConfig.PostSensorUpdates)
            {
                BluetoothDevice dev = AppUtil.getDevice(e.Address, _adpt);

                // If the devie can found and is not already connected to
                if (dev != null)
                {
                    if (!sensorThreads.ContainsKey(e.Address))
                    {
                        // Starting the connection
                        connectToSensor(dev);
                    }
                    else
                    {
                        Log.Warn(LOG_TAG, String.Format("The sensor with address {0} was already added to the service.", e.Address));
                    }
                }
                else
                {
                    // Device could not be connected to
                    Log.Warn(LOG_TAG, String.Format("The sensor with address {0} could not be found.  Setting the sensor inactive.", e.Address));
                    sendDisconnectStateUpdate(e.Address, String.Format("The sensor with address {0} could not be found. Setting the sensor inactive.", e.Address));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Callback for spinner that holds all active connected devices
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            List <string> activeAddress = _connectedDeviceMap.Where(kvp => kvp.Value == true).Select(kvp => kvp.Key).ToList();

            if (activeAddress.Count > 0)
            {
                // parse address
                var    info    = (e.View as TextView).Text.ToString();
                string address = info.Substring(info.Length - 17);

                // get device
                selectedDevice = AppUtil.getDevice(address, _adpt);
            }
            resetLiveView();
        }
コード例 #3
0
        private void resetListViews()
        {
            ((MainActivity)Activity).RunOnUiThread(delegate
            {
                clearConnectionList();

                List <string> activeAddress   = _connectedDeviceMap.Where(kvp => kvp.Value == true).Select(kvp => kvp.Key).ToList();
                List <string> inactiveAddress = _connectedDeviceMap.Where(kvp => kvp.Value == false).Select(kvp => kvp.Key).ToList();

                if (_connectedDeviceMap.Count == 0)
                {
                    Log.Warn(TAG, "There are no connected devices");
                    _connectedDevicesArrayAdapter.Add(LE_SENSOR_WARNING_NO_CONNECT);

                    radioGroupList.Visibility = ViewStates.Gone;

                    // Hiding the sensor feedback
                    hideLiveView();

                    // Turn off sensor feedback if it was on
                    if (_scanSwitch.Checked)
                    {
                        _scanSwitch.Checked = false;
                    }
                }
                else if (activeAddress.Count == 0)
                {
                    Log.Warn(TAG, "There are no active devices");
                    _connectedDevicesArrayAdapter.Add("There are no active devices");

                    // Hiding the sensor feedback
                    hideLiveView();

                    // Turn off sensor feedback if it was on
                    if (_scanSwitch.Checked)
                    {
                        _scanSwitch.Checked = false;
                    }
                }

                if (activeAddress.Count > 0)
                {
                    radioGroupList.Visibility = ViewStates.Visible;

                    if (AppConfig.PostSensorUpdates)
                    {
                        showLiveView();
                    }

                    Log.Debug(TAG, "Active devices found, adding to list");

                    // Enabling click
                    enableConnectedListViewClick();

                    // Add the items
                    foreach (string a in activeAddress)
                    {
                        BluetoothDevice device = AppUtil.getDevice(a, _adpt);

                        if (device != null && (!string.IsNullOrEmpty(device.Name)))
                        {
                            _connectedDevicesArrayAdapter.Add(device.Name + "\n" + device.Address);
                            _spinnerDevicesArrayAdapter.Add(device.Name + "\n" + device.Address);
                        }
                        else
                        {
                            Log.Warn(TAG, System.String.Format("Sensor with address {0} was not available.  Getting name from cache", a));
                            _connectedDevicesArrayAdapter.Add(AppConfig.getDeviceName(a) + "\n" + a);
                            _spinnerDevicesArrayAdapter.Add(AppConfig.getDeviceName(a) + "\n" + a);
                        }
                    }

                    sensorChoice.SetSelection(0);
                    sensorChoice.Enabled = true;
                }

                if (inactiveAddress.Count > 0)
                {
                    Log.Debug(TAG, "Inactive devices found, adding to list");
                    radioGroupList.Visibility = ViewStates.Visible;

                    foreach (string a in inactiveAddress)
                    {
                        _disconnectedDevicesArrayAdapter.Add(AppConfig.getDeviceName(a) + "\n" + a);
                    }
                }
                else
                {
                    _disconnectedDevicesArrayAdapter.Add("There are no inactive devices");
                }

                _connectedDevicesArrayAdapter.NotifyDataSetChanged();
                _spinnerDevicesArrayAdapter.NotifyDataSetChanged();
                _disconnectedDevicesArrayAdapter.NotifyDataSetChanged();
            });
        }