private void ToggleSensors(SensorMessage sensorsMessage) { this.Sensors.SensorSwitches.Id = sensorsMessage.Id; foreach (var sensorItem in sensorsMessage.Sensors) { if (sensorItem.A != null) { sensorsMessage.Type = 'A'; if (Accelerometer.GetDefault() == null) { throw new UnsupportedSensorException("Accelerometer does not exist"); } App.Telemetry.TrackEvent( "Sensor", new Dictionary<string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.A.Value.ToString() } }); this.Sensors.SensorSwitches.A = sensorItem.A.Value; } else if (sensorItem.G != null) { sensorsMessage.Type = 'G'; if (Gyrometer.GetDefault() == null) { throw new UnsupportedSensorException("Gyrometer does not exist"); } App.Telemetry.TrackEvent( "Sensor", new Dictionary<string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.G.Value.ToString() } }); this.Sensors.SensorSwitches.G = sensorItem.G.Value; } else if (sensorItem.M != null) { sensorsMessage.Type = 'M'; if (Compass.GetDefault() == null) { throw new UnsupportedSensorException("Compass does not exist"); } this.Sensors.SensorSwitches.M = sensorItem.M.Value; App.Telemetry.TrackEvent( "Sensor", new Dictionary<string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.M.Value.ToString() } }); this.Sensors.SensorSwitches.M = sensorItem.M.Value; } else if (sensorItem.L != null) { sensorsMessage.Type = 'L'; this.Sensors.SensorSwitches.L = sensorItem.L.Value; App.Telemetry.TrackEvent( "Sensor", new Dictionary<string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.L.Value.ToString() } }); } else if (sensorItem.Q != null) { sensorsMessage.Type = 'Q'; if (OrientationSensor.GetDefault() == null) { throw new UnsupportedSensorException("OrientationSensor does not exist"); } App.Telemetry.TrackEvent( "Sensor", new Dictionary<string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.Q.Value.ToString() } }); this.Sensors.SensorSwitches.Q = sensorItem.Q.Value; } else if (sensorItem.P != null) { sensorsMessage.Type = 'P'; if (LightSensor.GetDefault() == null) { throw new UnsupportedSensorException("LightSensor does not exist"); } App.Telemetry.TrackEvent( "Sensor", new Dictionary<string, string> { { "sensor.type", sensorsMessage.Type.ToString() }, { "sensor.value", sensorItem.P.Value.ToString() } }); this.Sensors.SensorSwitches.P = sensorItem.P.Value; } // outside of scope - applies to last only this.Sensors.SensorSwitches.Delta = sensorItem.Delta; this.Sensors.SensorSwitches.Interval = sensorItem.Interval; } this.Sensors.Start(); }
private void ToggleSensors(SensorMessage sensorsMessage) { Sensors.SensorSwitches.Id = sensorsMessage.Id; foreach (var sensorItem in sensorsMessage.Sensors) { if (sensorItem.A != null) { sensorsMessage.Type = 'A'; if (Accelerometer.GetDefault() == null) { throw new UnsupportedSensorException(); } Sensors.SensorSwitches.A = sensorItem.A.Value; } else if (sensorItem.G != null) { sensorsMessage.Type = 'G'; if (Gyrometer.GetDefault() == null) { throw new UnsupportedSensorException(); } Sensors.SensorSwitches.G = sensorItem.G.Value; } else if (sensorItem.M != null) { sensorsMessage.Type = 'M'; if (Compass.GetDefault() == null) { throw new UnsupportedSensorException(); } Sensors.SensorSwitches.M = sensorItem.M.Value; } else if (sensorItem.L != null) { sensorsMessage.Type = 'L'; Sensors.SensorSwitches.L = sensorItem.L.Value; } else if (sensorItem.Q != null) { sensorsMessage.Type = 'Q'; if (OrientationSensor.GetDefault() == null) { throw new UnsupportedSensorException(); } Sensors.SensorSwitches.Q = sensorItem.Q.Value; } else if (sensorItem.P != null) { sensorsMessage.Type = 'P'; if (LightSensor.GetDefault() == null) { throw new UnsupportedSensorException(); } Sensors.SensorSwitches.P = sensorItem.P.Value; } //outside of scope - applies to last only Sensors.SensorSwitches.Delta = sensorItem.Delta; Sensors.SensorSwitches.Interval = sensorItem.Interval; } Sensors.Start(); }