partial void StartAccelerometerClick (UIButton sender)
		{
			if (client != null && client.IsDeviceConnected) {
				// create the sensor once
				if (accelerometer == null) {
					accelerometer = client.SensorManager.CreateAccelerometerSensor ();
					accelerometer.ReadingChanged += (_, e) => {
						var data = e.SensorReading;
						AccelerometerDataText.Text = string.Format ("Accel Data: X={0:+0.00} Y={0:+0.00} Z={0:+0.00}", data.X, data.Y, data.Z);
					};
				}
				if (sensorStarted) {
					Output ("Stopping Accelerometer updates...");
					try {
						accelerometer.StopReadings ();
						sensorStarted = false;
					} catch (BandException ex) {
						Output ("Error: " + ex.Message);
					}
				} else {
					Output ("Starting Accelerometer updates...");
					try {
						accelerometer.StartReadings ();
						sensorStarted = true;
					} catch (BandException ex) {
						Output ("Error: " + ex.Message);
					}
				}
			} else {
				Output ("Band is not connected. Please wait....");
			}
		}
		public AccelerometerSensor GetAccelerometer()
		{
			if (accelerometer == null) {
				accelerometer = GetSensorManager ().CreateAccelerometerSensor ();
			}
			return accelerometer;
		}
        /// <summary>
        /// Stops this instance.
        /// </summary>
        partial void Stop()
        {
            var accelerometer = AccelerometerSensor.GetDefault();

            if (accelerometer != null)
            {
                accelerometer.ReadingChanged -= AccelerometerOnReadingChanged;
            }
        }
Beispiel #4
0
        public void ProcessSensorData()
        {
            var data = new AccelerometerSensor();

            if (UpdateInputData(ref data.LastUpdateTime, ref data.Acceleration))
            {
                SetSensorData <AccelerometerSensor>(data);
            }
        }
Beispiel #5
0
        private void EnsureSensorsCreated()
        {
            IBandSensorManager sensorMgr = Model.Instance.Client.SensorManager;

            if (accelerometerSensor == null)
            {
                accelerometerSensor = sensorMgr.CreateAccelerometerSensor();
                accelerometerSensor.ReadingChanged += async(sender, e) =>
                {
                    var accelerometerEvent = e.SensorReading;

                    //if(Math.Abs(accelerometerEvent.AccelerationX) > 3) xCount++;
                    if (Math.Abs(accelerometerEvent.AccelerationY) > 3)
                    {
                        yCount++;
                    }
                    if (Math.Abs(accelerometerEvent.AccelerationZ) > 3)
                    {
                        zCount++;
                    }

                    // rudimentary shake detection
                    //if (xCount > 2
                    if (yCount > 2 &&
                        zCount > 2)
                    {
                        // wait 20 seconds below allowing a new answer
                        if (DateTime.Now.Subtract(lastAnswered).TotalSeconds > 20)
                        {
                            xCount       = yCount = zCount = 0;
                            lastAnswered = DateTime.Now;
                            lastAnswer   = Get8BallPrediction();

                            await Model.Instance.Client.NotificationManager.SendMessageTaskAsync(
                                uuid,
                                "8Ball says...",
                                lastAnswer,
                                DateTime.Now,
                                MessageFlags.ShowDialog);
                        }
                    }
                    this.RunOnUiThread(() =>
                    {
//							accelX.Text = string.Format("{0:F3}", accelerometerEvent.AccelerationX);
//							accelY.Text = string.Format("{0:F3}", accelerometerEvent.AccelerationY);
//							accelZ.Text = string.Format("{0:F3}", accelerometerEvent.AccelerationZ);

                        accelZ.Text = xCount + " " + yCount + " " + zCount + " (x,y,x) only (y,z) count";

                        resultText.Text = lastAnswer;
                    });
                };
            }
        }
        /// <summary>
        /// Starts this instance.
        /// </summary>
        partial void Start()
        {
            var accelerometer = AccelerometerSensor.GetDefault();

            if (accelerometer == null)
            {
                return;
            }

            accelerometer.ReportInterval = (uint)this.Interval;

            accelerometer.ReadingChanged += AccelerometerOnReadingChanged;
        }
Beispiel #7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_game);
            Window.AddFlags(WindowManagerFlags.Fullscreen);
            Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
            rlGame  = FindViewById <RelativeLayout>(Resource.Id.rl_game);
            webView = FindViewById <WebView>(Resource.Id.wv_game);

            webView.Settings.JavaScriptEnabled = true;
            webView.SetWebViewClient(new MyWebViewClient(this, webView));
            webView.SetRendererPriorityPolicy(RendererPriority.Bound, true);

            WebSettings webSettings = webView.Settings;

            webSettings.JavaScriptEnabled    = true;
            webSettings.DomStorageEnabled    = true;
            webSettings.LoadWithOverviewMode = true;
            webSettings.UseWideViewPort      = true;

            webView.AddJavascriptInterface(new WebViewJavascriptInterface(this), "AndroidJSHandler");

            var intent = Intent;

            if (intent.HasExtra("Game"))
            {
                var game = intent.GetIntExtra("Game", -1);
                if (game != -1)
                {
                    switch (game)
                    {
                    case 1:
                        sensorAcc = new AccelerometerSensor(this);
                        sensorAcc.SetListener(this);
                        break;
                    }
                    Log.Error("GameActivity", "game: " + game);
                    webView.LoadUrl("file:///android_asset/joc" + game + "/index.html");
                }
                else
                {
                    Log.Error("GameActivity", " no game available ");
                    Toast.MakeText(this, "Jocul nu este valabil", ToastLength.Short).Show();
                }
            }
            else
            {
                Log.Error("GameActivity", " no extra ");
                Toast.MakeText(this, "No extra ", ToastLength.Short).Show();
            }
        }
Beispiel #8
0
        public void Stop()
        {
            if (this.sensor != null)
            {
                try
                {
                    this.sensor.Stop();
                }
                catch (Exception) { };

                this.sensor.ReadingChanged -= this.HandleSensorReadingChanged;
                this.sensor = null;
            }
        }
 partial void StartAccelerometerClick(UIButton sender)
 {
     if (client != null && client.IsDeviceConnected)
     {
         // create the sensor once
         if (accelerometer == null)
         {
             accelerometer = client.SensorManager.CreateAccelerometerSensor();
             accelerometer.ReadingChanged += (_, e) => {
                 var data = e.SensorReading;
                 AccelerometerDataText.Text = string.Format(
                     "Accel Data: X={0:+0.00} Y={1:+0.00} Z={2:+0.00}",
                     data.AccelerationX, data.AccelerationY, data.AccelerationZ);
             };
         }
         if (sensorStarted)
         {
             Output("Stopping Accelerometer updates...");
             try {
                 accelerometer.StopReadings();
                 sensorStarted = false;
             } catch (BandException ex) {
                 Output("Error: " + ex.Message);
             }
         }
         else
         {
             Output("Starting Accelerometer updates...");
             try {
                 accelerometer.StartReadings();
                 sensorStarted = true;
             } catch (BandException ex) {
                 Output("Error: " + ex.Message);
             }
         }
     }
     else
     {
         Output("Band is not connected. Please wait....");
     }
 }
        //
        // Sensor event handlers
        //
        private void EnsureSensorsCreated()
        {
            IBandSensorManager sensorMgr = Model.Instance.Client.SensorManager;

            if (accelerometerSensor == null)
            {
                accelerometerSensor = sensorMgr.CreateAccelerometerSensor();
                accelerometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var accelerometerEvent = e.SensorReading;
                        mTextAccX.Text = string.Format("{0:F3}", accelerometerEvent.AccelerationX);
                        mTextAccY.Text = string.Format("{0:F3}", accelerometerEvent.AccelerationY);
                        mTextAccZ.Text = string.Format("{0:F3}", accelerometerEvent.AccelerationZ);
                    });
                };
            }

            if (contactSensor == null)
            {
                contactSensor = sensorMgr.CreateContactSensor();
                contactSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var contactEvent = e.SensorReading;
                        mTextContact.Text = contactEvent.ContactState.ToString();
                    });
                };
            }

            if (distanceSensor == null)
            {
                distanceSensor = sensorMgr.CreateDistanceSensor();
                distanceSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var distanceEvent = e.SensorReading;
                        mTextTotalDistance.Text = string.Format("{0:D} cm", distanceEvent.TotalDistance);
                        mTextSpeed.Text = string.Format("{0:F2} cm/s", distanceEvent.Speed);
                        mTextPace.Text = string.Format("{0:F2} ms/m", distanceEvent.Pace);
                        mTextPedometerMode.Text = distanceEvent.MotionType.ToString();
                    });
                };
            }

            if (gyroscopeSensor == null)
            {
                gyroscopeSensor = sensorMgr.CreateGyroscopeSensor();
                gyroscopeSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var gyroscopeEvent = e.SensorReading;
                        mTextGyroAccX.Text = string.Format("{0:F3}", gyroscopeEvent.AccelerationX);
                        mTextGyroAccY.Text = string.Format("{0:F3}", gyroscopeEvent.AccelerationY);
                        mTextGyroAccZ.Text = string.Format("{0:F3}", gyroscopeEvent.AccelerationZ);
                        mTextGyroAngX.Text = string.Format("{0:F2}", gyroscopeEvent.AngularVelocityX);
                        mTextGyroAngY.Text = string.Format("{0:F2}", gyroscopeEvent.AngularVelocityY);
                        mTextGyroAngZ.Text = string.Format("{0:F2}", gyroscopeEvent.AngularVelocityZ);
                    });
                };
            }

            if (heartRateSensor == null)
            {
                heartRateSensor = sensorMgr.CreateHeartRateSensor();
                heartRateSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var heartRateEvent = e.SensorReading;
                        mTextHeartRate.Text = Convert.ToString(heartRateEvent.HeartRate);
                        mTextHeartRateQuality.Text = heartRateEvent.Quality.ToString();
                    });
                };
            }

            if (pedometerSensor == null)
            {
                pedometerSensor = sensorMgr.CreatePedometerSensor();
                pedometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var pedometerEvent = e.SensorReading;
                        mTextTotalSteps.Text = string.Format("{0:D}", pedometerEvent.TotalSteps);
                    });
                };
            }

            if (skinTemperatureSensor == null)
            {
                skinTemperatureSensor = sensorMgr.CreateSkinTemperatureSensor();
                skinTemperatureSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var skinTemperatureEvent = e.SensorReading;
                        mTextSkinTemperature.Text = string.Format("{0:F1}", skinTemperatureEvent.Temperature);
                    });
                };
            }

            if (uvSensor == null)
            {
                uvSensor = sensorMgr.CreateUVSensor();
                uvSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var uvEvent = e.SensorReading;
                        mTextUltraviolet.Text = uvEvent.UVIndexLevel.ToString();
                    });
                };
            }
        }
        //
        // Sensor event handlers
        //
        private void EnsureSensorsCreated()
        {
            IBandSensorManager sensorMgr = Model.Instance.Client.SensorManager;

            if (accelerometerSensor == null)
            {
                accelerometerSensor = sensorMgr.CreateAccelerometerSensor();
                accelerometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var accelerometerEvent = e.SensorReading;
                        mTextAccX.Text         = string.Format("{0:F3} m/s/s", accelerometerEvent.AccelerationX);
                        mTextAccY.Text         = string.Format("{0:F3} m/s/s", accelerometerEvent.AccelerationY);
                        mTextAccZ.Text         = string.Format("{0:F3} m/s/s", accelerometerEvent.AccelerationZ);
                    });
                };
            }

            if (contactSensor == null)
            {
                contactSensor = sensorMgr.CreateContactSensor();
                contactSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var contactEvent  = e.SensorReading;
                        mTextContact.Text = contactEvent.ContactState.ToString();
                    });
                };
            }

            if (distanceSensor == null)
            {
                distanceSensor = sensorMgr.CreateDistanceSensor();
                distanceSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var distanceEvent       = e.SensorReading;
                        mTextTotalDistance.Text = string.Format("{0:D} cm", distanceEvent.TotalDistance);
                        mTextSpeed.Text         = string.Format("{0:F2} cm/s", distanceEvent.Speed);
                        mTextPace.Text          = string.Format("{0:F2} ms/m", distanceEvent.Pace);
                        mTextPedometerMode.Text = distanceEvent.MotionType.ToString();
                    });
                };
            }

            if (gyroscopeSensor == null)
            {
                gyroscopeSensor = sensorMgr.CreateGyroscopeSensor();
                gyroscopeSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var gyroscopeEvent = e.SensorReading;
                        mTextGyroAccX.Text = string.Format("{0:F3} m/s/s", gyroscopeEvent.AccelerationX);
                        mTextGyroAccY.Text = string.Format("{0:F3} m/s/s", gyroscopeEvent.AccelerationY);
                        mTextGyroAccZ.Text = string.Format("{0:F3} m/s/s", gyroscopeEvent.AccelerationZ);
                        mTextGyroAngX.Text = string.Format("{0:F2} deg/s", gyroscopeEvent.AngularVelocityX);
                        mTextGyroAngY.Text = string.Format("{0:F2} deg/s", gyroscopeEvent.AngularVelocityY);
                        mTextGyroAngZ.Text = string.Format("{0:F2} deg/s", gyroscopeEvent.AngularVelocityZ);
                    });
                };
            }

            if (heartRateSensor == null)
            {
                heartRateSensor = sensorMgr.CreateHeartRateSensor();
                heartRateSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var heartRateEvent         = e.SensorReading;
                        mTextHeartRate.Text        = string.Format("{0:D} beats/min", heartRateEvent.HeartRate);
                        mTextHeartRateQuality.Text = heartRateEvent.Quality.ToString();
                    });
                };
            }

            if (pedometerSensor == null)
            {
                pedometerSensor = sensorMgr.CreatePedometerSensor();
                pedometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var pedometerEvent   = e.SensorReading;
                        mTextTotalSteps.Text = string.Format("{0:D} steps", pedometerEvent.TotalSteps);
                    });
                };
            }

            if (skinTemperatureSensor == null)
            {
                skinTemperatureSensor = sensorMgr.CreateSkinTemperatureSensor();
                skinTemperatureSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var skinTemperatureEvent  = e.SensorReading;
                        mTextSkinTemperature.Text = string.Format("{0:F1} (C)", skinTemperatureEvent.Temperature);
                    });
                };
            }

            if (uvSensor == null)
            {
                uvSensor = sensorMgr.CreateUVSensor();
                uvSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var uvEvent           = e.SensorReading;
                        mTextUltraviolet.Text = uvEvent.UVIndexLevel.ToString();
                    });
                };
            }

            if (altimeterSensor == null)
            {
                altimeterSensor = sensorMgr.CreateAltimeterSensor();
                altimeterSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var altimeterEvent         = e.SensorReading;
                        mTextFlightsAscended.Text  = string.Format("{0:D} floors", altimeterEvent.FlightsAscended);
                        mTextFlightsDescended.Text = string.Format("{0:D} floors", altimeterEvent.FlightsDescended);
                        mTextRate.Text             = string.Format("{0:F2} cm/s", altimeterEvent.Rate);
                        mTextSteppingGain.Text     = string.Format("{0:D} cm", altimeterEvent.SteppingGain);
                        mTextSteppingLoss.Text     = string.Format("{0:D} cm", altimeterEvent.SteppingLoss);
                        mTextStepsAscended.Text    = string.Format("{0:D} steps", altimeterEvent.StepsAscended);
                        mTextStepsDescended.Text   = string.Format("{0:D} steps", altimeterEvent.StepsDescended);
                        mTextTotalGain.Text        = string.Format("{0:D} cm", altimeterEvent.TotalGain);
                        mTextTotalLoss.Text        = string.Format("{0:D} cm", altimeterEvent.TotalLoss);
                    });
                };
            }

            if (ambientLightSensor == null)
            {
                ambientLightSensor = sensorMgr.CreateAmbientLightSensor();
                ambientLightSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var ambientLightEvent = e.SensorReading;
                        mTextBrightness.Text  = string.Format("{0:D} lux", ambientLightEvent.Brightness);
                    });
                };
            }

            if (barometerSensor == null)
            {
                barometerSensor = sensorMgr.CreateBarometerSensor();
                barometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var barometerEvent    = e.SensorReading;
                        mTextAirPressure.Text = string.Format("{0:D} hPa", barometerEvent.AirPressure);
                        mTextTemperature.Text = string.Format("{0:D} (C)", barometerEvent.Temperature);
                    });
                };
            }

            if (caloriesSensor == null)
            {
                caloriesSensor = sensorMgr.CreateCaloriesSensor();
                caloriesSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var caloriesEvent  = e.SensorReading;
                        mTextCalories.Text = string.Format("{0:D} kcals", caloriesEvent.Calories);
                    });
                };
            }

            if (gsrSensor == null)
            {
                gsrSensor = sensorMgr.CreateGsrSensor();
                gsrSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var gsrEvent         = e.SensorReading;
                        mTextResistance.Text = string.Format("{0:D} kohms", gsrEvent.Resistance);
                    });
                };
            }

            if (rrIntervalSensor == null)
            {
                rrIntervalSensor = sensorMgr.CreateRRIntervalSensor();
                rrIntervalSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var rrIntervalEvent = e.SensorReading;
                        mTextInterval.Text  = string.Format("{0:2F} s", rrIntervalEvent.Interval);
                    });
                };
            }
        }
 protected override void Initialize()
 {
     GameRoot.BoxingViewport = new BoxingViewportAdapter(Window, GraphicsDevice, (int)VirtualSize.X, (int)VirtualSize.Y, 0, 0);
     AccelerometerSensor.Start();
     base.Initialize();
 }
		public GestureRecognizer (AccelerometerSensor accelerometerSensor)
		{
			_accelerometerSensor = accelerometerSensor;
		}
 private void AccelerometerOnReadingChanged(AccelerometerSensor sender, AccelerometerReadingChangedEventArgs args)
 {
     LatestReading = args.Reading.AsVector3();
     readingAvailable.Invoke(sender, LatestReading);
 }
		private void EnsureSensorsCreated()
		{
			IBandSensorManager sensorMgr = Model.Instance.Client.SensorManager;

			if (accelerometerSensor == null)
			{
				accelerometerSensor = sensorMgr.CreateAccelerometerSensor();
				accelerometerSensor.ReadingChanged += async (sender, e) =>
				{
					var accelerometerEvent = e.SensorReading;

					//if(Math.Abs(accelerometerEvent.AccelerationX) > 3) xCount++;
					if(Math.Abs(accelerometerEvent.AccelerationY) > 3) yCount++;
					if(Math.Abs(accelerometerEvent.AccelerationZ) > 3) zCount++;

					// rudimentary shake detection
					//if (xCount > 2
					if (yCount > 2
						&& zCount > 2) {

						// wait 20 seconds below allowing a new answer
						if (DateTime.Now.Subtract(lastAnswered).TotalSeconds > 20) {
							xCount = yCount = zCount = 0;
							lastAnswered = DateTime.Now;
							lastAnswer = Get8BallPrediction();

							await Model.Instance.Client.NotificationManager.SendMessageTaskAsync(
								uuid, 
								"8Ball says...", 
								lastAnswer, 
								DateTime.Now,
								MessageFlags.ShowDialog);
						}
					}
					this.RunOnUiThread(() =>
						{
//							accelX.Text = string.Format("{0:F3}", accelerometerEvent.AccelerationX);
//							accelY.Text = string.Format("{0:F3}", accelerometerEvent.AccelerationY);
//							accelZ.Text = string.Format("{0:F3}", accelerometerEvent.AccelerationZ);

							accelZ.Text = xCount + " " + yCount + " " + zCount + " (x,y,x) only (y,z) count";

							resultText.Text = lastAnswer;
						});
				};
			}
		}
        //
        // Sensor event handlers
        //
        private void EnsureSensorsCreated()
        {
            IBandSensorManager sensorMgr = Model.Instance.Client.SensorManager;

            if (accelerometerSensor == null)
            {
                accelerometerSensor = sensorMgr.CreateAccelerometerSensor();
                accelerometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var accelerometerEvent = e.SensorReading;
                        mTextAccX.Text = string.Format("{0:F3} m/s/s", accelerometerEvent.AccelerationX);
                        mTextAccY.Text = string.Format("{0:F3} m/s/s", accelerometerEvent.AccelerationY);
                        mTextAccZ.Text = string.Format("{0:F3} m/s/s", accelerometerEvent.AccelerationZ);
                    });
                };
            }

            if (contactSensor == null)
            {
                contactSensor = sensorMgr.CreateContactSensor();
                contactSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var contactEvent = e.SensorReading;
                        mTextContact.Text = contactEvent.ContactState.ToString();
                    });
                };
            }

            if (distanceSensor == null)
            {
                distanceSensor = sensorMgr.CreateDistanceSensor();
                distanceSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var distanceEvent = e.SensorReading;
                        mTextTotalDistance.Text = string.Format("{0:D} cm", distanceEvent.TotalDistance);
                        mTextSpeed.Text = string.Format("{0:F2} cm/s", distanceEvent.Speed);
                        mTextPace.Text = string.Format("{0:F2} ms/m", distanceEvent.Pace);
                        mTextPedometerMode.Text = distanceEvent.MotionType.ToString();
                    });
                };
            }

            if (gyroscopeSensor == null)
            {
                gyroscopeSensor = sensorMgr.CreateGyroscopeSensor();
                gyroscopeSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var gyroscopeEvent = e.SensorReading;
                        mTextGyroAccX.Text = string.Format("{0:F3} m/s/s", gyroscopeEvent.AccelerationX);
                        mTextGyroAccY.Text = string.Format("{0:F3} m/s/s", gyroscopeEvent.AccelerationY);
                        mTextGyroAccZ.Text = string.Format("{0:F3} m/s/s", gyroscopeEvent.AccelerationZ);
                        mTextGyroAngX.Text = string.Format("{0:F2} deg/s", gyroscopeEvent.AngularVelocityX);
                        mTextGyroAngY.Text = string.Format("{0:F2} deg/s", gyroscopeEvent.AngularVelocityY);
                        mTextGyroAngZ.Text = string.Format("{0:F2} deg/s", gyroscopeEvent.AngularVelocityZ);
                    });
                };
            }

            if (heartRateSensor == null)
            {
                heartRateSensor = sensorMgr.CreateHeartRateSensor();
                heartRateSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var heartRateEvent = e.SensorReading;
                        mTextHeartRate.Text = string.Format("{0:D} beats/min", heartRateEvent.HeartRate);
                        mTextHeartRateQuality.Text = heartRateEvent.Quality.ToString();
                    });
                };
            }

            if (pedometerSensor == null)
            {
                pedometerSensor = sensorMgr.CreatePedometerSensor();
                pedometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var pedometerEvent = e.SensorReading;
                        mTextTotalSteps.Text = string.Format("{0:D} steps", pedometerEvent.TotalSteps);
                    });
                };
            }

            if (skinTemperatureSensor == null)
            {
                skinTemperatureSensor = sensorMgr.CreateSkinTemperatureSensor();
                skinTemperatureSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var skinTemperatureEvent = e.SensorReading;
                        mTextSkinTemperature.Text = string.Format("{0:F1} (C)", skinTemperatureEvent.Temperature);
                    });
                };
            }

            if (uvSensor == null)
            {
                uvSensor = sensorMgr.CreateUVSensor();
                uvSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var uvEvent = e.SensorReading;
                        mTextUltraviolet.Text = uvEvent.UVIndexLevel.ToString();
                    });
                };
            }
            
            if (altimeterSensor == null)
            {
                altimeterSensor = sensorMgr.CreateAltimeterSensor();
                altimeterSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var altimeterEvent = e.SensorReading;
                        mTextFlightsAscended.Text = string.Format("{0:D} floors", altimeterEvent.FlightsAscended);
                        mTextFlightsDescended.Text = string.Format("{0:D} floors", altimeterEvent.FlightsDescended);
                        mTextRate.Text = string.Format("{0:F2} cm/s", altimeterEvent.Rate);
                        mTextSteppingGain.Text = string.Format("{0:D} cm", altimeterEvent.SteppingGain);
                        mTextSteppingLoss.Text = string.Format("{0:D} cm", altimeterEvent.SteppingLoss);
                        mTextStepsAscended.Text = string.Format("{0:D} steps", altimeterEvent.StepsAscended);
                        mTextStepsDescended.Text = string.Format("{0:D} steps", altimeterEvent.StepsDescended);
                        mTextTotalGain.Text = string.Format("{0:D} cm", altimeterEvent.TotalGain);
                        mTextTotalLoss.Text = string.Format("{0:D} cm", altimeterEvent.TotalLoss);
                    });
                };
            }

            if (ambientLightSensor == null)
            {
                ambientLightSensor = sensorMgr.CreateAmbientLightSensor();
                ambientLightSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var ambientLightEvent = e.SensorReading;
                        mTextBrightness.Text = string.Format("{0:D} lux", ambientLightEvent.Brightness);
                    });
                };
            }
            
            if (barometerSensor == null)
            {
                barometerSensor = sensorMgr.CreateBarometerSensor();
                barometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var barometerEvent = e.SensorReading;
                        mTextAirPressure.Text = string.Format("{0:D} hPa", barometerEvent.AirPressure);
                        mTextTemperature.Text = string.Format("{0:D} (C)", barometerEvent.Temperature);
                    });
                };
            }
            
            if (caloriesSensor == null)
            {
                caloriesSensor = sensorMgr.CreateCaloriesSensor();
                caloriesSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var caloriesEvent = e.SensorReading;
                        mTextCalories.Text = string.Format("{0:D} kcals", caloriesEvent.Calories);
                    });
                };
            }
            
            if (gsrSensor == null)
            {
                gsrSensor = sensorMgr.CreateGsrSensor();
                gsrSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var gsrEvent = e.SensorReading;
                        mTextResistance.Text = string.Format("{0:D} kohms", gsrEvent.Resistance);
                    });
                };
            }
            
            if (rrIntervalSensor == null)
            {
                rrIntervalSensor = sensorMgr.CreateRRIntervalSensor();
                rrIntervalSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var rrIntervalEvent = e.SensorReading;
                        mTextInterval.Text = string.Format("{0:2F} s", rrIntervalEvent.Interval);
                    });
                };
            }
        }
 private void AccelerometerOnReadingChanged(AccelerometerSensor sender, AccelerometerReadingChangedEventArgs args)
 {
     LatestReading = args.Reading.AsVector3();
     readingAvailable.Invoke(sender, LatestReading);
 }
Beispiel #18
0
 protected override void OnStart()
 {
     AccelerometerSensor.ToggleAccelerometer();
 }
Beispiel #19
0
 private void AccelerometerOnReadingChanged(AccelerometerSensor sender, AccelerometerReadingChangedEventArgs args)
 {
     LatestReading = args.Reading.AsVector3();
     EventExtensions.Invoke <Vector3>(readingAvailable, sender, LatestReading);
 }
        public static void Init()
        {
            mGyros = new GyroSensor[3];
            mAccs = new AccelerometerSensor[3];
            mMotors = new MotorESC[4];


            for (int i = 0; i < 4; ++i)
            {
                mMotors[i] = new MotorESC();
            }


            for (int i = 0; i < 3; ++i)
            {
                mGyros[i] = new GyroSensor();
            }

            for (int i = 0; i < 3; ++i)
            {
                mAccs[i] = new AccelerometerSensor();
            }
        }
        //
        // Sensor event handlers
        //
        private void EnsureSensorsCreated()
        {
            IBandSensorManager sensorMgr = Model.Instance.Client.SensorManager;

            if (accelerometerSensor == null)
            {
                accelerometerSensor = sensorMgr.CreateAccelerometerSensor();
                accelerometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var accelerometerEvent = e.SensorReading;
                        mTextAccX.Text         = string.Format("{0:F3}", accelerometerEvent.AccelerationX);
                        mTextAccY.Text         = string.Format("{0:F3}", accelerometerEvent.AccelerationY);
                        mTextAccZ.Text         = string.Format("{0:F3}", accelerometerEvent.AccelerationZ);
                    });
                };
            }

            if (contactSensor == null)
            {
                contactSensor = sensorMgr.CreateContactSensor();
                contactSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var contactEvent  = e.SensorReading;
                        mTextContact.Text = contactEvent.ContactStatus.ToString();
                    });
                };
            }

            if (distanceSensor == null)
            {
                distanceSensor = sensorMgr.CreateDistanceSensor();
                distanceSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var distanceEvent       = e.SensorReading;
                        mTextTotalDistance.Text = string.Format("{0:D} cm", distanceEvent.TotalDistance);
                        mTextSpeed.Text         = string.Format("{0:F2} cm/s", distanceEvent.Speed);
                        mTextPace.Text          = string.Format("{0:F2} ms/m", distanceEvent.Pace);
                        mTextPedometerMode.Text = distanceEvent.PedometerMode.ToString();
                    });
                };
            }

            if (gyroscopeSensor == null)
            {
                gyroscopeSensor = sensorMgr.CreateGyroscopeSensor();
                gyroscopeSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var gyroscopeEvent = e.SensorReading;
                        mTextGyroAccX.Text = string.Format("{0:F3}", gyroscopeEvent.AccelerationX);
                        mTextGyroAccY.Text = string.Format("{0:F3}", gyroscopeEvent.AccelerationY);
                        mTextGyroAccZ.Text = string.Format("{0:F3}", gyroscopeEvent.AccelerationZ);
                        mTextGyroAngX.Text = string.Format("{0:F2}", gyroscopeEvent.AngularVelocityX);
                        mTextGyroAngY.Text = string.Format("{0:F2}", gyroscopeEvent.AngularVelocityY);
                        mTextGyroAngZ.Text = string.Format("{0:F2}", gyroscopeEvent.AngularVelocityZ);
                    });
                };
            }

            if (heartRateSensor == null)
            {
                heartRateSensor = sensorMgr.CreateHeartRateSensor();
                heartRateSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var heartRateEvent         = e.SensorReading;
                        mTextHeartRate.Text        = Convert.ToString(heartRateEvent.HeartRate);
                        mTextHeartRateQuality.Text = heartRateEvent.Quality.ToString();
                    });
                };
            }

            if (pedometerSensor == null)
            {
                pedometerSensor = sensorMgr.CreatePedometerSensor();
                pedometerSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var pedometerEvent   = e.SensorReading;
                        mTextTotalSteps.Text = string.Format("{0:D}", pedometerEvent.TotalSteps);
                    });
                };
            }

            if (skinTemperatureSensor == null)
            {
                skinTemperatureSensor = sensorMgr.CreateSkinTemperatureSensor();
                skinTemperatureSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var skinTemperatureEvent  = e.SensorReading;
                        mTextSkinTemperature.Text = string.Format("{0:F1}", skinTemperatureEvent.Temperature);
                    });
                };
            }

            if (uvSensor == null)
            {
                uvSensor = sensorMgr.CreateUVSensor();
                uvSensor.ReadingChanged += (sender, e) =>
                {
                    Activity.RunOnUiThread(() =>
                    {
                        var uvEvent           = e.SensorReading;
                        mTextUltraviolet.Text = uvEvent.UVIndexLevel.ToString();
                    });
                };
            }
        }