public SensorManagerImplementation(IRepoManager repoManager, CMMotionManager motionManager, CLLocationManager locationManager, CMPedometer pedometer) { _repoManager = repoManager ?? throw new ArgumentNullException(nameof(repoManager)); _motionManager = motionManager ?? throw new ArgumentNullException(nameof(motionManager)); _locationManager = locationManager ?? throw new ArgumentNullException(nameof(locationManager)); _pedometer = pedometer ?? throw new ArgumentNullException(nameof(pedometer)); _queue = new NSOperationQueue(); _sensorMeasurementSessionRepository = _repoManager.SensorMeasurementSessionRepository; _accelerometerRepository = _repoManager.AccelerometerRepository; _gyroscoperRepository = _repoManager.GyroscopeRepository; _magnetometerRepository = _repoManager.MagnetometerRepository; _linearAccelerationRepository = _repoManager.LinearAccelerationRepository; _orientationRepository = _repoManager.OrientationRepository; _quaternionRepository = _repoManager.QuaternionRepository; _gravityRepository = _repoManager.GravityRepository; locationManager.DesiredAccuracy = CLLocation.AccuracyBest; locationManager.HeadingFilter = 1; locationManager.AllowsBackgroundLocationUpdates = true; motionManager.DeviceMotionUpdateInterval = 0.1; motionManager.AccelerometerUpdateInterval = 0.1; motionManager.GyroUpdateInterval = 0.1; motionManager.MagnetometerUpdateInterval = 0.1; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. //Delegate has to be called AppDelegate appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate; mManager = appDelegate.SharedManager; UpdateIntervalSlider.Value = 0.0f; if (graphDataSource != MotionDataType.DeviceMotion) { SegmentedControl.Hidden = true; } else { graphTitles = new List <string> { "Motion.Attitude", "Motion.RotationRate", "Motion.Gravity", "Motion.UserAcceleration" }; graphs = new List <GraphView> { primaryGraph, // attitudeGraph new GraphView(primaryGraph.Frame), // rotationRateGraph new GraphView(primaryGraph.Frame), // gravityGraph new GraphView(primaryGraph.Frame) // userAccelerationGraph }; } }
public AppleDeviceOrientationService(IMvxLifetime mvxLifetime, ILogger logger) : base(Common.CoordinateSystemOrientation.RightHanded, mvxLifetime, logger) { if (ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.DEVICE) { _motionManager = new CMMotionManager(); } }
public void Start () { mman = new CMMotionManager { ShowsDeviceMovementDisplay = true, }; mman.StartDeviceMotionUpdates ( // CMAttitudeReferenceFrame.XArbitraryZVertical, // CMAttitudeReferenceFrame.XArbitraryCorrectedZVertical, // CMAttitudeReferenceFrame.XMagneticNorthZVertical, CMAttitudeReferenceFrame.XTrueNorthZVertical, new NSOperationQueue (), (motion, error) => { if (error == null) { Orientation = ToMatrix4d (motion.Attitude.RotationMatrix); var roll = motion.Attitude.Roll; var p = motion.Attitude.Pitch; if (roll > 0) { p = (3 * Math.PI) / 2 + p; } else { p = Math.PI / 2 - p; } Pitch = p; OrientationReceived (this, EventArgs.Empty); } }); }
public override void Initialize(GameContext <iOSWindow> gameContext) { view = gameContext.Control.GameView; window = gameContext.Control.MainWindow; var gameController = gameContext.Control.GameViewController; window.UserInteractionEnabled = true; window.MultipleTouchEnabled = true; gameController.TouchesBeganDelegate += (touchesSet, _) => HandleTouches(touchesSet); gameController.TouchesMovedDelegate += (touchesSet, _) => HandleTouches(touchesSet); gameController.TouchesEndedDelegate += (touchesSet, _) => HandleTouches(touchesSet); gameController.TouchesCancelledDelegate += (touchesSet, _) => HandleTouches(touchesSet); view.Resize += OnResize; OnResize(null, EventArgs.Empty); // create sensor managers motionManager = new CMMotionManager(); locationManager = new CLLocationManager(); // set desired sampling intervals motionManager.AccelerometerUpdateInterval = 1 / DesiredSensorUpdateRate; motionManager.GyroUpdateInterval = 1 / DesiredSensorUpdateRate; motionManager.DeviceMotionUpdateInterval = 1 / DesiredSensorUpdateRate; // Determine supported sensors Accelerometer.IsSupported = motionManager.AccelerometerAvailable; Compass.IsSupported = CLLocationManager.HeadingAvailable; Gyroscope.IsSupported = motionManager.GyroAvailable; UserAcceleration.IsSupported = motionManager.DeviceMotionAvailable; Gravity.IsSupported = motionManager.DeviceMotionAvailable; Orientation.IsSupported = motionManager.DeviceMotionAvailable; }
public Gyroscope(double updateInterval) { this.manager = new CMMotionManager() { GyroUpdateInterval = updateInterval }; }
public void Start() { mman = new CMMotionManager { ShowsDeviceMovementDisplay = true, }; mman.StartDeviceMotionUpdates( // CMAttitudeReferenceFrame.XArbitraryZVertical, // CMAttitudeReferenceFrame.XArbitraryCorrectedZVertical, // CMAttitudeReferenceFrame.XMagneticNorthZVertical, CMAttitudeReferenceFrame.XTrueNorthZVertical, new NSOperationQueue(), (motion, error) => { if (error == null) { Orientation = ToMatrix4d(motion.Attitude.RotationMatrix); var roll = motion.Attitude.Roll; var p = motion.Attitude.Pitch; if (roll > 0) { p = (3 * Math.PI) / 2 + p; } else { p = Math.PI / 2 - p; } Pitch = p; OrientationReceived(this, EventArgs.Empty); } }); }
/// <summary> /// Initializes a new instance of the /// <see cref="T:DSAMobile.Sensors.iOSSensors"/> class. /// </summary> public iOSSensors() { motionManager = new CMMotionManager(); locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyBest; locationManager.HeadingFilter = 1; }
public override void ViewDidLoad() { base.ViewDidLoad(); motionManager = new CMMotionManager(); StartButton.TouchUpInside += (sender, e) => { gyroData = new ObservableCollection <double>(); motionManager.StartGyroUpdates(NSOperationQueue.CurrentQueue, (data, error) => { gyroData.Add(data.RotationRate.x); gyroData.Add(data.RotationRate.y); gyroData.Add(data.RotationRate.z); var shake = gyroData.Where(gyroData => Math.Abs(gyroData) > 3).Count(); if (shake > 3) { motionManager.StopGyroUpdates(); var alert = new UIAlertView("Gyroscope", "Shaked!", null, "OK"); alert.Show(); } this.xLabel.Text = data.RotationRate.x.ToString("0.0000"); this.yLabel.Text = data.RotationRate.y.ToString("0.0000"); this.zLabel.Text = data.RotationRate.z.ToString("0.0000"); }); }; StopButton.TouchUpInside += (sender, e) => { motionManager.StopGyroUpdates(); }; }
public void Stop() { if (_motionManager == null) { return; } _motionManager.StopDeviceMotionUpdates(); _motionManager = null; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. layoutW = View.Bounds.Width; layoutH = View.Bounds.Height; textW = layoutW / 2; textH = layoutH / 6; System.Diagnostics.Debug.WriteLine("Width: {0}, Height: {1}", layoutW, layoutH); var sensorText = new UILabel(new CGRect(layoutW / 2 - textW / 2, layoutH / 2 - textH / 2, textW, textH)); sensorText.BackgroundColor = UIColor.FromRGB(192, 192, 192); sensorText.Lines = 0; sensorText.TextAlignment = UITextAlignment.Center; sensorText.LineBreakMode = UILineBreakMode.TailTruncation; View.AddSubview(sensorText); var textLoc = sensorText.Frame; motionManager = new CMMotionManager(); if (motionManager.AccelerometerAvailable) { motionManager.AccelerometerUpdateInterval = 0.015; motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) => { sensorText.Text = string.Format("X = {0:N4}\nY = {1:N4}", data.Acceleration.X, data.Acceleration.Y); nowX = sensorText.Frame.X; nowY = sensorText.Frame.Y; Console.WriteLine("nowX: {0}, nowY: {1}", nowX, nowY); if (nowX + (nfloat)data.Acceleration.X * 10 > 0 && nowX + (nfloat)data.Acceleration.X * 10 < layoutW - textW) { textLoc.X = nowX + (nfloat)data.Acceleration.X * 10; } if (nowY - (nfloat)data.Acceleration.Y * 10 > 0 && nowY - (nfloat)data.Acceleration.Y * 10 < layoutH - textH) { textLoc.Y = nowY - (nfloat)data.Acceleration.Y * 10; } sensorText.Frame = textLoc; }); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Viewのサイズを取得 layoutW = View.Bounds.Width; layoutH = View.Bounds.Height; // Viewサイズを元にLabelサイズを指定 textW = layoutW / 2; textH = layoutH / 6; System.Diagnostics.Debug.WriteLine("Width: {0}, Height: {1}", layoutW, layoutH); // Label作成&配置 var sensorText = new UILabel(new CGRect(layoutW / 2 - textW / 2, layoutH / 2 - textH / 2, textW, textH)); sensorText.BackgroundColor = UIColor.FromRGB(192, 192, 192); sensorText.Lines = 0; sensorText.TextAlignment = UITextAlignment.Center; sensorText.LineBreakMode = UILineBreakMode.TailTruncation; View.AddSubview(sensorText); // Frameを取得して変数に var textLoc = sensorText.Frame; motionManager = new CMMotionManager(); if (motionManager.AccelerometerAvailable) { // Accelerometer Update間隔 motionManager.AccelerometerUpdateInterval = 0.015; // UpdateがQueueに入る度に処理を行う(多分) motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) => { sensorText.Text = string.Format("X = {0:N4}\nY = {1:N4}", data.Acceleration.X, data.Acceleration.Y); // 現在の位置を取得 nowX = sensorText.Frame.X; nowY = sensorText.Frame.Y; System.Diagnostics.Debug.WriteLine("nowX: {0}, nowY: {1}", nowX, nowY); // Viewをはみ出さないようにAccelerometerの値によってLabelを移動 if (nowX + (nfloat)data.Acceleration.X * 10 > 0 && nowX + (nfloat)data.Acceleration.X * 10 < layoutW - textW) { textLoc.X = nowX + (nfloat)data.Acceleration.X * 10; } if (nowY - (nfloat)data.Acceleration.Y * 10 > 0 && nowY - (nfloat)data.Acceleration.Y * 10 < layoutH - textH) { textLoc.Y = nowY - (nfloat)data.Acceleration.Y * 10; } sensorText.Frame = textLoc; }); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here motionManager = new CMMotionManager(); motionManager.DeviceMotionUpdateInterval = 1 / 60; motionManager.StartDeviceMotionUpdates(); base.Initialize(); }
private void ScreenReturnToMenu() { _motionManager = new CMMotionManager(); _motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) => { if (data.Acceleration.Z > 0.890) { PushMainMenuWhenRotating(); } }); }
public override void ViewDidLoad() { base.ViewDidLoad(); motionManager = new CMMotionManager(); motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) => { this.lblX.Text = data.Acceleration.X.ToString("0.00000000"); this.lblY.Text = data.Acceleration.Y.ToString("0.00000000"); this.lblZ.Text = data.Acceleration.Z.ToString("0.00000000"); }); }
CMPedometer pedometer; // since iOS 8.0 public MotionPrivacyManager () { if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) { pedometer = new CMPedometer (); motionStatus = CMPedometer.IsStepCountingAvailable ? "Available" : "Not available"; } else { stepCounter = new CMStepCounter (); motionManger = new CMMotionManager (); motionStatus = motionManger.DeviceMotionAvailable ? "Available" : "Not available"; } }
public override void ViewDidLoad() { base.ViewDidLoad (); motionManager = new CMMotionManager (); motionManager.StartAccelerometerUpdates (NSOperationQueue.CurrentQueue, (data, error) => { this.lblX.Text = data.Acceleration.X.ToString ("0.00000000"); this.lblY.Text = data.Acceleration.Y.ToString ("0.00000000"); this.lblZ.Text = data.Acceleration.Z.ToString ("0.00000000"); }); }
public override void ViewDidLoad() { isInitialXPosition = false; initialXPosition = 0; motionManager = new CMMotionManager(); motionManager.AccelerometerUpdateInterval = 0.1; payButton.TouchUpInside += (object sender, EventArgs e) => { payAction(); }; }
private void SetupAccelerometer() { motionManager = new CMMotionManager(); if (GCController.Controllers != null && GCController.Controllers.Length == 0 && motionManager.AccelerometerAvailable) { motionManager.AccelerometerUpdateInterval = 1.0 / 60.0; motionManager.StartAccelerometerUpdates(NSOperationQueue.MainQueue, (data, error) => { AccelerometerDidChange(data.Acceleration); }); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Viewのサイズを取得 layoutW = View.Bounds.Width; layoutH = View.Bounds.Height; // Viewサイズを元にLabelサイズを指定 textW = layoutW / 2; textH = layoutH / 6; System.Diagnostics.Debug.WriteLine("Width: {0}, Height: {1}", layoutW, layoutH); // Label作成&配置 var sensorText = new UILabel(new CGRect(layoutW / 2 - textW / 2, layoutH / 2 - textH / 2, textW, textH)); sensorText.BackgroundColor = UIColor.FromRGB(192, 192, 192); sensorText.Lines = 0; sensorText.TextAlignment = UITextAlignment.Center; sensorText.LineBreakMode = UILineBreakMode.TailTruncation; View.AddSubview(sensorText); // Frameを取得して変数に var textLoc = sensorText.Frame; motionManager = new CMMotionManager(); if (motionManager.AccelerometerAvailable) { // Accelerometer Update間隔 motionManager.AccelerometerUpdateInterval = 0.015; // UpdateがQueueに入る度に処理を行う(多分) motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) => { sensorText.Text = string.Format("X = {0:N4}\nY = {1:N4}", data.Acceleration.X, data.Acceleration.Y); // 現在の位置を取得 nowX = sensorText.Frame.X; nowY = sensorText.Frame.Y; System.Diagnostics.Debug.WriteLine("nowX: {0}, nowY: {1}", nowX, nowY); // Viewをはみ出さないようにAccelerometerの値によってLabelを移動 if (nowX + (nfloat)data.Acceleration.X * 10 > 0 && nowX + (nfloat)data.Acceleration.X * 10 < layoutW - textW) textLoc.X = nowX + (nfloat)data.Acceleration.X * 10; if (nowY - (nfloat)data.Acceleration.Y * 10 > 0 && nowY - (nfloat)data.Acceleration.Y * 10 < layoutH - textH) textLoc.Y = nowY - (nfloat)data.Acceleration.Y * 10; sensorText.Frame = textLoc; }); } }
public SensorPackIOS(Engine engine) : base(engine) { _locationManager = new CLLocationManager { DesiredAccuracy = DesiredAccuracy, PausesLocationUpdatesAutomatically = false }; _locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { if (_locationManager.Location.Coordinate.IsValid()) { ReportNewLocation( _locationManager.Location.Coordinate.Latitude, _locationManager.Location.Coordinate.Longitude, (float)_locationManager.Location.Speed, (float)_locationManager.Location.Course, (int)_locationManager.Location.HorizontalAccuracy ); } else { Log.Debug("LocationManager Coordinates are not valid."); } }; _locationManager.LocationUpdatesPaused += (object sender, EventArgs e) => { LocationSensorStatus = LocationSensorStatus.Disabled; }; _locationManager.LocationUpdatesResumed += (object sender, EventArgs e) => { LocationSensorStatus = LocationSensorStatus.Working; }; _locationManager.AuthorizationChanged += (object sender, CLAuthorizationChangedEventArgs e) => { switch (e.Status) { case CLAuthorizationStatus.Denied: LocationSensorStatus = LocationSensorStatus.Disabled; break; case CLAuthorizationStatus.NotDetermined: LocationSensorStatus = LocationSensorStatus.Disabled; break; case CLAuthorizationStatus.Restricted: LocationSensorStatus = LocationSensorStatus.Disabled; break; } }; _sensorManager = new CMMotionManager(); }
private void SetupAccelerometerReading() { // Movement of Pacman _lastUpdateTime = DateTime.Now; _currentPoint = new PointF(0, 144); _motionManager = new CMMotionManager(); _motionManager.AccelerometerUpdateInterval = UPDATE_INTERVAL; _motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) => { _acceleration = data.Acceleration; InvokeOnMainThread(UpdatePacman); }); }
public override void ViewDidLoad() { base.ViewDidLoad(); AddStepsMessage(); var cm = new CMMotionManager(); if (cm.DeviceMotionAvailable == false) { motionStatus = "Not available"; requestAccessButton.Enabled = false; } accessStatus.Text = motionStatus; }
CMPedometer pedometer; // since iOS 8.0 public MotionPrivacyManager() { if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { pedometer = new CMPedometer(); motionStatus = CMPedometer.IsStepCountingAvailable ? "Available" : "Not available"; } else { stepCounter = new CMStepCounter(); motionManger = new CMMotionManager(); motionStatus = motionManger.DeviceMotionAvailable ? "Available" : "Not available"; } }
/// <summary> /// Initializes a new instance of the DeviceMotionImplementation class. /// </summary> public DeviceMotionImplementation() { motionManager = new CMMotionManager(); locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyBest; locationManager.HeadingFilter = 1; sensorStatus = new Dictionary<MotionSensorType, bool>(){ { MotionSensorType.Accelerometer, false}, { MotionSensorType.Gyroscope, false}, { MotionSensorType.Magnetometer, false}, { MotionSensorType.Compass, false} }; }
public void StartListening() { _manager = new CMMotionManager(); _manager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) => { AccelerometerEvent e = new AccelerometerEvent { XAcc = (float)data.Acceleration.X, YAcc = (float)data.Acceleration.Y, ZAcc = -(float)data.Acceleration.Z, }; AccelerationChanged?.Invoke(this, e); }); }
public override void Initialize(InputManager inputManager) { var context = inputManager.Game.Context as GameContextiOS; var uiControl = context.Control; var gameController = context.Control.GameViewController; pointer = new PointeriOS(this, uiControl, gameController); RegisterDevice(pointer); // Create sensor managers motionManager = new CMMotionManager(); locationManager = new CLLocationManager(); // Set desired sensor sampling intervals double updateInterval = 1 / InputManager.DesiredSensorUpdateRate; motionManager.AccelerometerUpdateInterval = updateInterval; motionManager.GyroUpdateInterval = updateInterval; motionManager.DeviceMotionUpdateInterval = updateInterval; // Determine supported sensors if (motionManager.AccelerometerAvailable) { accelerometerSensor = new AccelerometerSensor(this, "iOS"); RegisterDevice(accelerometerSensor); } if (CLLocationManager.HeadingAvailable) { compassSensor = new CompassSensor(this, "iOS"); RegisterDevice(compassSensor); } if (motionManager.GyroAvailable) { gyroscopeSensor = new GyroscopeSensor(this, "iOS"); RegisterDevice(gyroscopeSensor); } if (motionManager.DeviceMotionAvailable) { gravitySensor = new GravitySensor(this, "iOS"); userAccelerationSensor = new UserAccelerationSensor(this, "iOS"); orientationSensor = new OrientationSensor(this, "iOS"); RegisterDevice(gravitySensor); RegisterDevice(userAccelerationSensor); RegisterDevice(orientationSensor); } }
/// <summary> /// Initializes a new instance of the DeviceMotionImplementation class. /// </summary> public DeviceMotionImplementation() { motionManager = new CMMotionManager(); locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyBest; locationManager.HeadingFilter = 1; sensorStatus = new Dictionary <MotionSensorType, bool>() { { MotionSensorType.Accelerometer, false }, { MotionSensorType.Gyroscope, false }, { MotionSensorType.Magnetometer, false }, { MotionSensorType.Compass, false } }; }
protected override void Initialize() { base.Initialize(); if (SensusServiceHelper.Get().ObtainPermission(Permission.Sensors) == PermissionStatus.Granted) _motionManager = new CMMotionManager(); else { // throw standard exception instead of NotSupportedException, since the user might decide to enable sensors in the future // and we'd like the probe to be restarted at that time. string error = "Motion sensors are not permitted on this device. Cannot start accelerometer probe."; SensusServiceHelper.Get().FlashNotificationAsync(error); throw new Exception(error); } }
private void GetOrientation() { _motionManager = new CMMotionManager(); if (_motionManager.DeviceMotionAvailable) // DeviceMotion is not available on all devices. iOS4+ { this.Log().ErrorIfEnabled(() => "DeviceMotion is available"); _motionManager.DeviceMotionUpdateInterval = _updateInterval; _motionManager.StartDeviceMotionUpdates(NSOperationQueue.CurrentQueue, (motion, error) => { OnMotionChanged(motion); }); } else // For iOS devices that don't support CoreMotion { this.Log().ErrorIfEnabled(() => "SimpleOrientationSensor failed to initialize because CoreMotion is not available"); } }
void StartDeviceMotion() { motionManager = new CMMotionManager { ShowsDeviceMovementDisplay = true, DeviceMotionUpdateInterval = 1.0 / 60.0 }; motionManager.StartDeviceMotionUpdates(CMAttitudeReferenceFrame.XTrueNorthZVertical, NSOperationQueue.CurrentQueue, (motion, error) => { if (motion != null) { cameraTransform = new float[16]; TransformFromCMRotationMatrix(ref cameraTransform, motion.Attitude.RotationMatrix); SetNeedsDisplay(); } }); }
protected override void Initialize() { base.Initialize(); if (SensusServiceHelper.Get().ObtainPermission(Permission.Sensors) == PermissionStatus.Granted) { _motionManager = new CMMotionManager(); } else { // throw standard exception instead of NotSupportedException, since the user might decide to enable sensors in the future // and we'd like the probe to be restarted at that time. string error = "This device does not contain an accelerometer, or the user has denied access to it. Cannot start accelerometer probe."; SensusServiceHelper.Get().FlashNotificationAsync(error); throw new Exception(error); } }
partial void Initialize() { _motionManager = new CMMotionManager(); if (_motionManager.DeviceMotionAvailable) // DeviceMotion is not available on all devices. iOS4+ { var operationQueue = (NSOperationQueue.CurrentQueue == null || NSOperationQueue.CurrentQueue == NSOperationQueue.MainQueue) ? new NSOperationQueue() : NSOperationQueue.CurrentQueue; this.Log().Error("DeviceMotion is available"); _motionManager.DeviceMotionUpdateInterval = _updateInterval; _motionManager.StartDeviceMotionUpdates(operationQueue, (motion, error) => { OnMotionChanged(motion); }); } else // For iOS devices that don't support CoreMotion { this.Log().Error("SimpleOrientationSensor failed to initialize because CoreMotion is not available"); } }
public override void ViewDidLoad() { base.ViewDidLoad(); context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); if (context == null) { Console.WriteLine("Failed to create ES context"); } var view = (GLKView)View; view.DrawInRect += Draw; view.Context = context; view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; // for planet positions generateRandomPermutation(); // for star positions for (int i = 0; i < NumStars; i++) { star [i].X = (float)(gen.NextDouble() - .5f) * FarZ; star [i].Y = (float)(gen.NextDouble() - .5f) * FarZ; star [i].Z = (float)gen.NextDouble() * (FarZ - MinStarHeight) + MinStarHeight; } setupGL(); motionManager = new CMMotionManager(); isDeviceMotionAvailable = motionManager.DeviceMotionAvailable; // the label for roll, pitch and yaw reading rpyLabel = new UILabel(new Rectangle(0, 0, (int)UIScreen.MainScreen.Bounds.Size.Width, 30)); rpyLabel.BackgroundColor = UIColor.Clear; rpyLabel.TextColor = UIColor.White; rpyLabel.TextAlignment = UITextAlignment.Center; rpyLabel.LineBreakMode = UILineBreakMode.WordWrap; rpyLabel.Font = UIFont.FromName("Helvetica-Bold", 20f); View.AddSubview(rpyLabel); }
private void reset() { foreach (var subview in Subviews) { subview.RemoveFromSuperview(); } motionManager?.Dispose(); gravity?.Dispose(); spiderAnimator?.Dispose(); spiderView?.Dispose(); spiderAnimator = null; motionManager = null; gravity = null; spiderView = null; IsVisible = false; }
protected override void Dispose(bool disposing) { if (!IsDisposed) { if (disposing) { if (started) { Stop(); } --instanceCount; if (instanceCount == 0) { Accelerometer.motionManager = null; } } } base.Dispose(disposing); }
public override void ViewDidLoad () { base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib. //Delegate has to be called AppDelegate appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate; mManager = appDelegate.SharedManager; UpdateIntervalSlider.Value = 0.0f; if (graphDataSource != MotionDataType.DeviceMotion) { SegmentedControl.Hidden = true; } else { graphTitles = new List<string> { "Motion.Attitude", "Motion.RotationRate", "Motion.Gravity", "Motion.UserAcceleration" }; graphs = new List<GraphView> { primaryGraph, // attitudeGraph new GraphView (primaryGraph.Frame), // rotationRateGraph new GraphView (primaryGraph.Frame), // gravityGraph new GraphView (primaryGraph.Frame) // userAccelerationGraph }; } }
public void Start() { _motionManager = new CMMotionManager(); _motionManager.StartDeviceMotionUpdates(NSOperationQueue.CurrentQueue, (data, error) => { var xMotion = new XMotion { Pitch = data.Attitude.Pitch, Roll = data.Attitude.Roll, Yaw = data.Attitude.Yaw }; CurrentMotion = xMotion; if (MotionUpdated != null) { MotionUpdated(this, EventArgs.Empty); } }); }
public override void Initialize() { base.Initialize(); view = Game.Context.GameView; window = Game.Context.MainWindow; var gameController = Game.Context.GameViewController; window.UserInteractionEnabled = true; window.MultipleTouchEnabled = true; gameController.TouchesBeganDelegate += (touchesSet, _) => HandleTouches(touchesSet); gameController.TouchesMovedDelegate += (touchesSet, _) => HandleTouches(touchesSet); gameController.TouchesEndedDelegate += (touchesSet, _) => HandleTouches(touchesSet); gameController.TouchesCancelledDelegate += (touchesSet, _) => HandleTouches(touchesSet); view.Resize += OnResize; OnResize(null, EventArgs.Empty); // create sensor managers motionManager = new CMMotionManager(); locationManager = new CLLocationManager(); // set desired sampling intervals motionManager.AccelerometerUpdateInterval = 1/DesiredSensorUpdateRate; motionManager.GyroUpdateInterval = 1/DesiredSensorUpdateRate; motionManager.DeviceMotionUpdateInterval = 1/DesiredSensorUpdateRate; // Determine supported sensors Accelerometer.IsSupported = motionManager.AccelerometerAvailable; Compass.IsSupported = CLLocationManager.HeadingAvailable; Gyroscope.IsSupported = motionManager.GyroAvailable; UserAcceleration.IsSupported = motionManager.DeviceMotionAvailable; Gravity.IsSupported = motionManager.DeviceMotionAvailable; Orientation.IsSupported = motionManager.DeviceMotionAvailable; }
public override void ViewDidLoad () { base.ViewDidLoad (); context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); if (context == null) Console.WriteLine ("Failed to create ES context"); var view = (GLKView) View; view.DrawInRect += Draw; view.Context = context; view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; // for planet positions generateRandomPermutation (); // for star positions for (int i = 0; i < NumStars; i++) { star [i].X = (float) (gen.NextDouble () - .5f) * FarZ; star [i].Y = (float) (gen.NextDouble () - .5f) * FarZ; star [i].Z = (float) gen.NextDouble () * (FarZ - MinStarHeight) + MinStarHeight; } setupGL (); motionManager = new CMMotionManager (); isDeviceMotionAvailable = motionManager.DeviceMotionAvailable; // the label for roll, pitch and yaw reading rpyLabel = new UILabel (new CGRect (0, 0, (int) UIScreen.MainScreen.Bounds.Size.Width, 30)); rpyLabel.BackgroundColor = UIColor.Clear; rpyLabel.TextColor = UIColor.White; rpyLabel.TextAlignment = UITextAlignment.Center; rpyLabel.LineBreakMode = UILineBreakMode.WordWrap; rpyLabel.Font = UIFont.FromName ("Helvetica-Bold", 20f); View.AddSubview (rpyLabel); }
void StepQueryContinuation(Task<nint> t) { if (t.IsFaulted) { var code = ((NSErrorException)t.Exception.InnerException).Code; if (code == (int)CMError.MotionActivityNotAuthorized) motionStatus = "Not Authorized"; return; } motionManger = new CMMotionManager (); steps = t.Result; }
partial void Start() { this.motionManager = new CMMotionManager(); this.motionManager.GyroUpdateInterval = (long)this.Interval / 1000; this.motionManager.StartGyroUpdates(NSOperationQueue.MainQueue, this.OnUpdate); }
partial void Stop() { this.motionManager.StopGyroUpdates(); this.motionManager = null; }
public Accelerometer() { _motionManager = new CMMotionManager(); }
public iOSAccelerometerProbe() { _motionManager = new CMMotionManager(); }
public override void ViewWillDisappear (bool animated) { motionManager.StopAccelerometerUpdates (); motionManager = null; }
public override void ViewDidLoad() { base.ViewDidLoad(); // For accelerometer readings motionManager = new CMMotionManager(); motionManager.AccelerometerUpdateInterval = 0.01; // 100Hz //To handle long presses and bring up path start/end menu var longPressManager = new UILongPressGestureRecognizer(); //Graph loading code //Graph loading code var assembly = Assembly.GetExecutingAssembly(); var asset = assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsfloorWideDoors.xml"); pf = new Pathfinding.Pathfinding(new Dictionary<int, Stream>() { {0,assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsfloorWideDoors.xml")}, {1,assembly.GetManifestResourceStream("Navigator.iOS.Resources.dcsFloor1.xml")} },assembly.GetManifestResourceStream("Navigator.iOS.Resources.Rooms.xml") ); pf.CurrentFloor = 0; while (true) { if (pf.Ready) break; Thread.Sleep(500); } //set up the search bar and prediction box var searchController = new CustomSearchController(this, SearchBar, SearchPredictionTable, pf.Rooms); floorPlanGraph = Graph.Load(asset); wallCollImg = UIImage.FromBundle("Images/dcsfloorWideDoors.png"); col = new Collision(floorPlanGraph, new StepDetector()); ((Collision)col).WallCol = new WallCollision ((x,y) => GetPixelColor(new PointF(x, y), wallCollImg)); wallColTest = new WallCollision ((x,y) => GetPixelColor(new PointF(x, y), wallCollImg)); pathView = new PathView (wallColTest); col.SetLocation(707.0f, 677.0f); col.PassHeading(90); col.PositionChanged += HandleStepsTaken; //Container for floorplan and any overlaid images var container = new UIView(); //Will contain floorplan images floorplanImageView = new UIImageView(); //Load floorplan images floorplanImageNoGrid = UIImage.FromBundle("Images/FinalDcsFloor1.png"); floorplanImageWithGrid = UIImage.FromBundle("Images/dcsFloorWideDoorsGrid.png"); //Initiate the location arrow locationArrow = new LocationArrowImageView(); locationArrow.ScaleFactor = floorplanView.ZoomScale; pathView.ScaleFactor = floorplanView.ZoomScale; setStartPoint(690.0f, 840.0f); //Set sizes for floorplan view and path view floorplanView.ContentSize = floorplanImageNoGrid.Size; pathView.Frame = new CGRect(new CGPoint(0, 0), floorplanImageNoGrid.Size); //Add subviews to the container (including pathview and floorplanview) container.AddSubview(floorplanImageView); container.AddSubview(locationArrow); floorplanImageView.AddSubview(pathView); changeFloorPlanImage(floorplanImageView, floorplanImageNoGrid); container.SizeToFit(); //Adjust scrolling and zooming properties for the floorplanView floorplanView.MaximumZoomScale = 1f; floorplanView.MinimumZoomScale = .25f; floorplanView.AddSubview(container); floorplanView.ViewForZoomingInScrollView += (UIScrollView sv) => { return floorplanImageView; }; //Variables needed to convert device acceleration to world z direction acceleration double accelX = 0, accelY = 0, accelZ = 0; //Scale location arrow and paths when zooming the floorplan floorplanView.DidZoom += (sender, e) => { locationArrow.ScaleFactor = floorplanView.ZoomScale; pathView.ScaleFactor = floorplanView.ZoomScale; }; //Pass acceleremoter values to the collision class motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, (data, error) => { accelX = data.Acceleration.X*9.8; accelY = data.Acceleration.Y*9.8; accelZ = Math.Sqrt(Math.Pow(accelX, 2) + Math.Pow(accelY, 2) + Math.Pow(data.Acceleration.Z*9.8, 2)); col.PassSensorReadings(CollisionSensorType.Accelometer, accelX, accelY, accelZ); //displayAccelVal((float)accelZ); }); /* motionManager.StartDeviceMotionUpdates(NSOperationQueue.CurrentQueue, (data, error) => { //data.Attitude.MultiplyByInverseOfAttitude(data.Attitude); var test = data.UserAcceleration.X; var accelRelZ = data.Attitude.RotationMatrix.m31 * accelX + data.Attitude.RotationMatrix.m32 * accelY + data.Attitude.RotationMatrix.m33 * accelZ; debugLabel.Text = "" + Math.Round(test, 2);//Math.Round(accelRelZ, 2); } ); */ //LongPressManager will cause the path input menu to appear after a stationary long press longPressManager.AllowableMovement = 0; longPressManager.AddTarget(() => handleLongPress(longPressManager, floorPlanGraph)); floorplanView.AddGestureRecognizer(longPressManager); //the location manager handles the phone heading locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyBest; locationManager.HeadingFilter = 1; locationManager.UpdatedHeading += HandleUpdatedHeading; locationManager.StartUpdatingHeading(); //Button currently used for testing purposes only //Another testing button simulationButton.TouchUpInside += delegate { col.StepTaken(false); }; returnButton.TouchUpInside += delegate{ returnToMenu(); }; }
/// <summary> /// Starts this instance. /// </summary> partial void Start() { _motionManager = new CMMotionManager(); _motionManager.GyroUpdateInterval = (long)Interval / 1000; _motionManager.StartGyroUpdates(NSOperationQueue.MainQueue, OnUpdate); }
/// <summary> /// Stops this instance. /// </summary> partial void Stop() { _motionManager.StopGyroUpdates(); _motionManager = null; }
public ImagePanViewController(CMMotionManager motionManager) : base(null, null) { this.motionManager = motionManager; MotionBasedPanEnabled = true; }
private void SetupAccelerometer () { motionManager = new CMMotionManager (); if (GCController.Controllers != null && GCController.Controllers.Length == 0 && motionManager.AccelerometerAvailable) { motionManager.AccelerometerUpdateInterval = 1.0 / 60.0; motionManager.StartAccelerometerUpdates (NSOperationQueue.MainQueue, (data, error) => { AccelerometerDidChange (data.Acceleration); }); } }