/// <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)); } } }
/// <summary> /// Removes all the sensors from the service /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void onReportingPaused(object sender, SensorStateEventArgs e) { foreach (string key in sensorThreads.Keys.ToList()) { removeSensorFromService(key); } Log.Debug(LOG_TAG, "Sensor Reporting was turned off"); }
/// <summary> /// Handles Sensor Connect Event /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void SensorConnect(Object sender, SensorStateEventArgs e) { Log.Debug(TAG, String.Format("Sensor with address {0} is now active", e.Address)); Toast.MakeText(this, String.Format("{0} Has Connected Successfully", AppConfig.getDeviceName(e.Address)), ToastLength.Short).Show(); if (!_connectedDeviceMap.ContainsKey(e.Address)) { Log.Error(TAG, String.Format("Sensor with address {0} was not in the list of connected devices", e.Address)); } }
/// <summary> /// Removes the sensor from the service /// </summary> /// <param name="">.</param> private void RemoveSensor(object sender, SensorStateEventArgs e) { if (sensorThreads.ContainsKey(e.Address)) { removeSensorFromService(e.Address); } else { Log.Warn(LOG_TAG, "Sensor was not connected to the service"); } }
/// <summary> /// Handles Sensor Removed Event /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void SensorRemoved(Object sender, SensorStateEventArgs e) { if (_connectedDeviceMap.ContainsKey(e.Address)) { Log.Debug(TAG, String.Format("Sensor with address {0} was removed", e.Address)); _connectedDeviceMap.Remove(e.Address); } else { Log.Warn(TAG, String.Format("Sensor with address {0} was not in the list of connected devices", e.Address)); } if (AppConfig.SavedSensorDictionary.ContainsKey(e.Address)) { AppConfig.removeFromSavedSensorDictionary(e.Address); } }
/// <summary> /// Handles Sensor Disconnect Event /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void SensorDisconnect(Object sender, SensorStateEventArgs e) { Snackbar.Make( FindViewById(Resource.Id.content_main), String.Format("{0} has become inactive", AppConfig.getDeviceName(e.Address)), Snackbar.LengthLong ).Show(); if (_connectedDeviceMap.ContainsKey(e.Address)) { _connectedDeviceMap[e.Address] = false; Log.Debug(TAG, String.Format("Sensor with address {0} is now inactive", e.Address)); } else { Log.Error(TAG, String.Format("Sensor with address {0} was not in the list of connected devices", e.Address)); } }
/// <summary> /// Handles Sensor Added Event /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void SensorAdded(Object sender, SensorStateEventArgs e) { if (!_connectedDeviceMap.ContainsKey(e.Address)) { Log.Debug(TAG, String.Format("Sensor with address {0} was added", e.Address)); _connectedDeviceMap.Add(e.Address, true); } else { Log.Debug(TAG, String.Format("Sensor with address {0} is now active", e.Address)); _connectedDeviceMap[e.Address] = true; } if (!AppConfig.SavedSensorDictionary.ContainsKey(e.Address)) { AppConfig.addToSavedSensorDictionary(e.Address, e.DeviceName); } }
private void SensorPause(Object sender, SensorStateEventArgs e) { }
private void PauseSensor(object sender, SensorStateEventArgs e) { }
private void ConnectSensor(object sender, SensorStateEventArgs e) { }
private void RemoveSensor(object sender, SensorStateEventArgs e) { ResetSensor(); }
private void DisconnectSensor(object sender, SensorStateEventArgs e) { ResetSensor(); }
public override void OnReceive(Context context, Intent intent) { // Getting Bundle Bundle intentBundle = intent.Extras; // Getting action for this intent string action = intent.Action; // Will hold desc for action string desc = ""; if (intentBundle != null) { string address = ""; string name = ""; address = intentBundle.GetString(AppUtil.ADDRESS_KEY); name = intentBundle.GetString(AppUtil.NAME_KEY); SensorStateEventArgs args = new SensorStateEventArgs(address, name); try { if (action == AppUtil.SENSOR_DISCONNECT_ACTION) { Log.Debug(TAG, String.Format("Sensor with address: {0} disonnected", address)); SensorDisconnect(this, args); } else if (action == AppUtil.SENSOR_CONNECT_ACTION) { Log.Debug(TAG, String.Format("Sensor with address: {0} connected successfully ", address)); SensorConnect(this, args); } else if (action == AppUtil.SENSOR_ADDED_ACTION) { Log.Debug(TAG, String.Format("Sensor with address: {0} was added", address)); SensorAdded(this, args); } else if (action == AppUtil.SENSOR_REMOVED_ACTION) { Log.Debug(TAG, String.Format("Sensor with address: {0} was removed", address)); SensorRemoved(this, args); } } catch (NullReferenceException e) { // Nothing was listening to this Event Log.Debug(TAG, "Nothing is currently listening to this Event"); } } else if (action == AppUtil.SENSOR_PAUSE_ACTION) { SensorStateEventArgs args = new SensorStateEventArgs("", ""); Log.Debug(TAG, String.Format("Sensor reporting was paused")); try { SensorReportingPaused(this, args); } catch (NullReferenceException e) { } } }
private void OnSensorDisconnect(object sender, SensorStateEventArgs e) { removeSensorFromService(e.Address); }