public void SensorDataUpdated(SensorData data) { if (_initialPoint == null) { _initialPoint = new Point(data.Cog.X, data.Cog.Y); _start = DateTime.Now; } else if (_moved) { if (!inArea(data.Cog.X, data.Cog.Y)) { _countOutArea++; } else { _countInArea++; } _count++; if (_count > _pointsToAnalyse) { if (_countOutArea > _countInArea) { _movesCount++; _initialPoint = new Point(data.Cog.X, data.Cog.Y); _count = 0; _countOutArea = 0; _countInArea = 0; } _moved = false; } } else if (!inArea(data.Cog.X, data.Cog.Y)) { _moved = true; } //TODO: if ((DateTime.Now - _start).TotalSeconds > 30) { if (_movesCount < _minMovesCount) { //MainController.GetInstance.NavigationController.Navigate(MainController.GetInstance.NavigationController._marbleTab) MainController.GetInstance.EnqueNotificationMessage(new gui.controls.popup.NotifyMessage(System.AppDomain.CurrentDomain.BaseDirectory + "images/BlueSkin.png", "Bewege dich!", "Mit einem Spiel? Klick mich", () => MainController.GetInstance.NavigationController._marbleTab.IsSelected = true)); } _start = DateTime.Now; _movesCount = 0; } }
private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs e) { if (_firstValue == true && e.WiimoteState.BalanceBoardState.SensorValuesKg.TopLeft != 0 && e.WiimoteState.BalanceBoardState.SensorValuesKg.TopRight != 0 && e.WiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft != 0 && e.WiimoteState.BalanceBoardState.SensorValuesKg.BottomRight != 0) { _firstState = e.WiimoteState.BalanceBoardState; _firstValue = false; } //Sensorwerte normieren float bl = e.WiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft - _firstState.SensorValuesKg.BottomLeft; float br = e.WiimoteState.BalanceBoardState.SensorValuesKg.BottomRight - _firstState.SensorValuesKg.BottomRight; float tl = e.WiimoteState.BalanceBoardState.SensorValuesKg.TopLeft - _firstState.SensorValuesKg.TopLeft; float tr = e.WiimoteState.BalanceBoardState.SensorValuesKg.TopRight - _firstState.SensorValuesKg.TopRight; //float wkg = e.WiimoteState.BalanceBoardState.WeightKg; //NEuberechnug des Gewichts und des SChwerpunktes float wkg = (tl + tr + bl + br) / 4.0f; float x = 0, y = 0; if (tr != 0 && br != 0 && bl != 0 && tl != 0) { float Kx = (tl + bl) / (tr + br); float Ky = (tl + tr) / (bl + br); x = ((float)(Kx - 1) / (float)(Kx + 1)) * (float)(-BSL / 2); y = ((float)(Ky - 1) / (float)(Ky + 1)) * (float)(-BSW / 2); } //float x = e.WiimoteState.BalanceBoardState.CenterOfGravity.X; //float y = e.WiimoteState.BalanceBoardState.CenterOfGravity.Y; SensorData data = new SensorData(bl, br, tl, tr, wkg, new SensorData.CenterOfGravity(x, y)); SendSensorData(data); float battery = e.WiimoteState.Battery; SendBatteryStat(battery); }
public void SendSensorData(SensorData data) { lock (_lock) { foreach (SensorDataListener listener in _sensorDataListeners) { listener.SensorDataUpdated(data); } } }