Ejemplo n.º 1
0
 public CompassDataChangedEventArgs(CompassData compassData)
 {
     if (compassData == null)
     {
         throw new ArgumentNullException("compassData");
     }
     CompassData = compassData;
 }
        public MockCompass()
        {
            _worker         = new BackgroundWorker();
            _worker.DoWork += OnDoWork;

            _random = new Random();

            this._dispatcherTimer       = new DispatcherTimer();
            this._dispatcherTimer.Tick += OnTick;

            _timeBetweenUpdates = new TimeSpan(0, 0, 0, 0, 500);

            _currentValue = new CompassData(new DateTimeOffset(), 0, 0, 0, new Vector3());
        }
        private void OnDoWork(object sender, DoWorkEventArgs e)
        {
            _currentValue = new CompassData(
                new DateTimeOffset(DateTime.UtcNow),
                _random.NextDouble() * 25,
                (_currentValue.TrueHeading + 0.1) % 360,
                (_currentValue.MagneticHeading + 0.1) % 360,
                _currentValue.MagnetometerReading
                );

            _isDataValid = true;

            var handler = CurrentValueChanged;

            if (handler != null)
            {
                handler(this, new CompassDataChangedEventArgs(_currentValue));
            }
        }