コード例 #1
0
        public void GetAndSendAccelero(Windows.Devices.Sensors.Accelerometer accel)
        {
            var read = accel.GetCurrentReading();
            var str  = "IMU: " + read.Timestamp.TimeOfDay.ToString() + " " /*+ "X "*/ + read.AccelerationX.ToString("0.0") + " " + /* "Y " +*/ read.AccelerationY.ToString("0.0") + " " /* + "Z " */ + read.AccelerationZ.ToString("0.0") + "\n";

            Send(str);
        }
コード例 #2
0
        public override void Initialize()
        {
            base.Initialize();

            var windowHandle = Game.Window.NativeWindow;

            switch (windowHandle.Context)
            {
            case AppContextType.WindowsRuntime:
                InitializeFromFrameworkElement((FrameworkElement)windowHandle.NativeHandle);
                break;

            default:
                throw new ArgumentException(string.Format("WindowContext [{0}] not supported", Game.Context.ContextType));
            }

            // Scan all registered inputs
            Scan();

            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            windowsCompass       = WindowsCompass.GetDefault();
            windowsGyroscope     = WindowsGyroscope.GetDefault();
            windowsOrientation   = WindowsOrientation.GetDefault();

            // determine which sensors are available
            Accelerometer.IsSupported    = windowsAccelerometer != null;
            Compass.IsSupported          = windowsCompass != null;
            Gyroscope.IsSupported        = windowsGyroscope != null;
            Orientation.IsSupported      = windowsOrientation != null;
            Gravity.IsSupported          = Orientation.IsSupported && Accelerometer.IsSupported;
            UserAcceleration.IsSupported = Gravity.IsSupported;
        }
コード例 #3
0
        public void init_safe()
        {
            // Init accelerometer
            accelerometer = Windows.Devices.Sensors.Accelerometer.GetDefault();

            // set sampling frequency and set array to hold incoming data
            uint requestedReportInterval = 10;              // in ms

            // Check if accelerometer is found
            if (accelerometer != null)
            {
                // Retrieve the minimum interval supported by the device and compares it to a requested interval
                // If the minimum supported interval is greater than the requested interval, the code sets the
                // value to the minimum. Otherwise, it sets the value to the requested interval.
                minReportInterval            = accelerometer.MinimumReportInterval;
                reportInterval               = minReportInterval > requestedReportInterval ? minReportInterval : requestedReportInterval;
                accelerometer.ReportInterval = reportInterval;

                // new meter values anonymous callback
                accelerometer.ReadingChanged += new Windows.Foundation.TypedEventHandler <Windows.Devices.Sensors.Accelerometer, Windows.Devices.Sensors.AccelerometerReadingChangedEventArgs>(delegate(Windows.Devices.Sensors.Accelerometer sender, Windows.Devices.Sensors.AccelerometerReadingChangedEventArgs e) {
                    // log the data
                    acceleration[0] = e.Reading.AccelerationX;
                    acceleration[1] = e.Reading.AccelerationY;
                    acceleration[2] = e.Reading.AccelerationZ;
                });

                // flag sensor as enabled
                sensorAvailable = true;
            }
            else
            {
                // flas sensor as disabled
                sensorAvailable = false;
            }
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: runceel/metroapps
        /// <summary>
        /// このページがフレームに表示されるときに呼び出されます。
        /// </summary>
        /// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter 
        /// プロパティは、通常、ページを構成するために使用します。</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // マリモの情報がない場合はMarimoクラスのインスタンス生成をおこなう
            if (marimo == null)
            {
                marimo = new Marimo();
            }

            // marimoEllipseとマリモの情報をデータバインディングする
            marimoEllipse.DataContext = marimo;

            // マリモを動かすためのタイマー(約30fpsで動くことを想定)
            timer = new Windows.UI.Xaml.DispatcherTimer();
            timer.Interval = System.TimeSpan.FromMilliseconds(33);
            timer.Tick += timer_Tick;
            timer.Start();

            // デフォルトの加速度センサーを取得する
            accelerometer = Windows.Devices.Sensors.Accelerometer.GetDefault();
            // デフォルトの加速度センサーが取得できなければnullを返します
            if (accelerometer != null)
            {
                // ReadingChangedイベントハンドラを設定する
                accelerometer.ReadingChanged += accelerometer_ReadingChanged;

                // 加速度センサーが搭載されているのでtrue
                marimo.IsAccelerometer = true;
            }
            else
            {
                // 加速度センサーが搭載されていないのでfalse
                marimo.IsAccelerometer = false;
            }
        }
コード例 #5
0
        public async void RateSensorInit()
        {
            Debug.WriteLine("RateSensorInit start");

#if true  // Ammore Add - check Acc_resource
            Windows.Devices.Sensors.Accelerometer _accelerometer = Windows.Devices.Sensors.Accelerometer.GetDefault();

            if (_accelerometer != null)
            {
                Debug.WriteLine("AS7000HRM: PCA6800 using Sensor BMC156");
                Acc_resource = 1;
            }
            else
            {
                Debug.WriteLine("AS7000HRM: PCA6801 using Sensor Hub BHI160");
                Acc_resource = 2;
            }
#endif

            //linda 2018.0803
            if (Acc_resource == 1)
            {
                await BMC156_I2C_Init();

                await Task.Delay(300);

                BMC156_Init();
            }
            else if (Acc_resource == 2)
            {
                await BHI160_I2C_Init();

                await Task.Delay(300);

                BHI160_Init();
            }
            AS7000_GPIO_Init();
            AS7000_PWR_ON();

            await Task.Delay(1000); // If we do not sleep, we will have the FallingEdge event.

            //AS7000_INT_ON();

            await AS7000_I2C_Init();

            await Task.Delay(300);

            AS7000_Get_Protocol_Version();
            AS7000_Get_SW_Version();
            AS7000_Get_HW_Version();
            AS7000_Get_App_ID();



            return;
        }
コード例 #6
0
        private static Vector3 GetAcceleration(WindowsAccelerometer accelerometer)
        {
            var currentReading = accelerometer.GetCurrentReading();

            if (currentReading == null)
            {
                return(Vector3.Zero);
            }

            return(G * new Vector3((float)currentReading.AccelerationX, (float)currentReading.AccelerationZ, -(float)currentReading.AccelerationY));
        }
コード例 #7
0
ファイル: DataModel.cs プロジェクト: mickey23a/TN154W2DemoApp
        public void checkSensorHub()
        {
            Windows.Devices.Sensors.Accelerometer _accelerometer = Windows.Devices.Sensors.Accelerometer.GetDefault();

            if (_accelerometer != null)
            {
                Debug.WriteLine("DataModel: PCA6800 using Sensor BMC156");
                _SensorHub = false;
            }
            else
            {
                Debug.WriteLine("DataModel: PCA6801 using Sensor Hub BHI160");
                _SensorHub = true;
            }
        }
コード例 #8
0
        public override void Initialize()
        {
            base.Initialize();

            var windowHandle = Game.Window.NativeWindow;

            switch (windowHandle.Context)
            {
            case AppContextType.UWP:
                InitializeFromFrameworkElement((FrameworkElement)windowHandle.NativeWindow);
                break;

            default:
                throw new ArgumentException(string.Format("WindowContext [{0}] not supported", Game.Context.ContextType));
            }

            // Scan all registered inputs
            Scan();

            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            windowsCompass       = WindowsCompass.GetDefault();
            windowsGyroscope     = WindowsGyroscope.GetDefault();
            windowsOrientation   = WindowsOrientation.GetDefault();

            // determine which sensors are available
            Accelerometer.IsSupported    = windowsAccelerometer != null;
            Compass.IsSupported          = windowsCompass != null;
            Gyroscope.IsSupported        = windowsGyroscope != null;
            Orientation.IsSupported      = windowsOrientation != null;
            Gravity.IsSupported          = Orientation.IsSupported && Accelerometer.IsSupported;
            UserAcceleration.IsSupported = Gravity.IsSupported;

            if (mouseCapabilities.MousePresent > 0)
            {
                MouseDevice.GetForCurrentView().MouseMoved += (_, y) => HandleRelativeOnMouseMoved(y);
            }
        }
コード例 #9
0
ファイル: InputSourceUWP.cs プロジェクト: vvvv/stride
        public override void Initialize(InputManager inputManager)
        {
            var mouseCapabilities = new MouseCapabilities();

            if (mouseCapabilities.MousePresent > 0)
            {
                pointer = new MouseUWP(this, coreWindow);
                RegisterDevice(pointer);
            }

            var keyboardCapabilities = new KeyboardCapabilities();

            if (keyboardCapabilities.KeyboardPresent > 0)
            {
                keyboard = new KeyboardUWP(this, coreWindow);
                RegisterDevice(keyboard);
            }

            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            if (windowsAccelerometer != null)
            {
                accelerometer = new AccelerometerSensor(this, "UWP");
                RegisterDevice(accelerometer);
            }

            windowsCompass = WindowsCompass.GetDefault();
            if (windowsCompass != null)
            {
                compass = new CompassSensor(this, "UWP");
                RegisterDevice(compass);
            }

            windowsGyroscope = WindowsGyroscope.GetDefault();
            if (windowsGyroscope != null)
            {
                gyroscope = new GyroscopeSensor(this, "UWP");
                RegisterDevice(gyroscope);
            }

            windowsOrientation = WindowsOrientation.GetDefault();
            if (windowsOrientation != null)
            {
                orientation = new OrientationSensor(this, "UWP");
                RegisterDevice(orientation);
            }

            // Virtual sensors
            if (windowsOrientation != null && windowsAccelerometer != null)
            {
                gravity          = new GravitySensor(this, "UWP");
                userAcceleration = new UserAccelerationSensor(this, "UWP");
                RegisterDevice(gravity);
                RegisterDevice(userAcceleration);
            }

            Gamepad.GamepadAdded   += GamepadOnGamepadAdded;
            Gamepad.GamepadRemoved += GamepadOnGamepadRemoved;

            Scan();
        }
コード例 #10
0
ファイル: Accelerometer.cs プロジェクト: baskren/Pontoon
 private Accelerometer(Tizen.Sensor.Accelerometer accelerometer)
 {
     _accelerometer = accelerometer;
 }
コード例 #11
0
ファイル: Accelerometer.cs プロジェクト: baskren/Pontoon
 private Accelerometer(Windows.Devices.Sensors.Accelerometer accelerometer)
 {
     _accelerometer = accelerometer;
 }
コード例 #12
0
ファイル: InputSourceUWP.cs プロジェクト: Aggror/Stride
        public override void Initialize(InputManager inputManager)
        {
            var nativeWindow = inputManager.Game.Window.NativeWindow;

            CoreWindow coreWindow;

            if (nativeWindow.Context == AppContextType.UWPCoreWindow)
            {
                coreWindow = (CoreWindow)nativeWindow.NativeWindow;
            }
            else if (nativeWindow.Context == AppContextType.UWPXaml)
            {
                coreWindow = Window.Current.CoreWindow;
            }
            else
            {
                throw new ArgumentException(string.Format("WindowContext [{0}] not supported", nativeWindow.Context));
            }

            var mouseCapabilities = new MouseCapabilities();

            if (mouseCapabilities.MousePresent > 0)
            {
                pointer = new MouseUWP(this, coreWindow);
                RegisterDevice(pointer);
            }

            var keyboardCapabilities = new KeyboardCapabilities();

            if (keyboardCapabilities.KeyboardPresent > 0)
            {
                keyboard = new KeyboardUWP(this, coreWindow);
                RegisterDevice(keyboard);
            }

            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            if (windowsAccelerometer != null)
            {
                accelerometer = new AccelerometerSensor(this, "UWP");
                RegisterDevice(accelerometer);
            }

            windowsCompass = WindowsCompass.GetDefault();
            if (windowsCompass != null)
            {
                compass = new CompassSensor(this, "UWP");
                RegisterDevice(compass);
            }

            windowsGyroscope = WindowsGyroscope.GetDefault();
            if (windowsGyroscope != null)
            {
                gyroscope = new GyroscopeSensor(this, "UWP");
                RegisterDevice(gyroscope);
            }

            windowsOrientation = WindowsOrientation.GetDefault();
            if (windowsOrientation != null)
            {
                orientation = new OrientationSensor(this, "UWP");
                RegisterDevice(orientation);
            }

            // Virtual sensors
            if (windowsOrientation != null && windowsAccelerometer != null)
            {
                gravity          = new GravitySensor(this, "UWP");
                userAcceleration = new UserAccelerationSensor(this, "UWP");
                RegisterDevice(gravity);
                RegisterDevice(userAcceleration);
            }

            Gamepad.GamepadAdded   += GamepadOnGamepadAdded;
            Gamepad.GamepadRemoved += GamepadOnGamepadRemoved;

            Scan();
        }
コード例 #13
0
 private void accel_ReadingChanged(Windows.Devices.Sensors.Accelerometer sender, Windows.Devices.Sensors.AccelerometerReadingChangedEventArgs args)
 {
     GetAndSendAccelero(sender);
 }
コード例 #14
0
ファイル: Accelerometer.cs プロジェクト: baskren/Pontoon
 private void _accelerometer_ReadingChanged(Windows.Devices.Sensors.Accelerometer sender, Windows.Devices.Sensors.AccelerometerReadingChangedEventArgs args)
 {
     _readingChanged?.Invoke(this, args);
 }
コード例 #15
0
        public override void Initialize()
        {
            base.Initialize();

            var windowHandle = Game.Window.NativeWindow;
            switch (windowHandle.Context)
            {
                case AppContextType.WindowsRuntime:
                    InitializeFromFrameworkElement((FrameworkElement)windowHandle.NativeHandle);
                    break;
                default:
                    throw new ArgumentException(string.Format("WindowContext [{0}] not supported", Game.Context.ContextType));
            }

            // Scan all registered inputs
            Scan();
            
            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            windowsCompass = WindowsCompass.GetDefault();
            windowsGyroscope = WindowsGyroscope.GetDefault();
            windowsOrientation = WindowsOrientation.GetDefault();

            // determine which sensors are available
            Accelerometer.IsSupported = windowsAccelerometer != null;
            Compass.IsSupported = windowsCompass != null;
            Gyroscope.IsSupported = windowsGyroscope != null;
            Orientation.IsSupported = windowsOrientation != null;
            Gravity.IsSupported = Orientation.IsSupported && Accelerometer.IsSupported;
            UserAcceleration.IsSupported = Gravity.IsSupported;
        }
コード例 #16
0
        private static Vector3 GetAcceleration(WindowsAccelerometer accelerometer)
        {
            var currentReading = accelerometer.GetCurrentReading();
            if(currentReading == null)
                return Vector3.Zero;

            return G * new Vector3((float)currentReading.AccelerationX, (float)currentReading.AccelerationZ, -(float)currentReading.AccelerationY);
        }
コード例 #17
0
        public override void Initialize()
        {
            base.Initialize();

            var windowHandle = Game.Window.NativeWindow;
            switch (windowHandle.Context)
            {
                case AppContextType.UWP:
                    InitializeFromFrameworkElement((FrameworkElement)windowHandle.NativeWindow);
                    break;
                default:
                    throw new ArgumentException(string.Format("WindowContext [{0}] not supported", Game.Context.ContextType));
            }

            // Scan all registered inputs
            Scan();
            
            // get sensor default instances
            windowsAccelerometer = WindowsAccelerometer.GetDefault();
            windowsCompass = WindowsCompass.GetDefault();
            windowsGyroscope = WindowsGyroscope.GetDefault();
            windowsOrientation = WindowsOrientation.GetDefault();

            // determine which sensors are available
            Accelerometer.IsSupported = windowsAccelerometer != null;
            Compass.IsSupported = windowsCompass != null;
            Gyroscope.IsSupported = windowsGyroscope != null;
            Orientation.IsSupported = windowsOrientation != null;
            Gravity.IsSupported = Orientation.IsSupported && Accelerometer.IsSupported;
            UserAcceleration.IsSupported = Gravity.IsSupported;

            if (mouseCapabilities.MousePresent > 0)
                MouseDevice.GetForCurrentView().MouseMoved += (_,y) => HandleRelativeOnMouseMoved(y);
        }