Esempio n. 1
0
        public override void OnCreate()
        {
            if (dev.GamingInput is IDiscoverable)
            {
                _discoveryProvider = (IDiscoverable)dev.GamingInput;
                _discoveryProvider.ScanFinished += _discoveryProvider_ScanFinished;
            }
            if (dev.GamingInput is IEmgSensorInput)
            {
                _emgInput = dev.GamingInput as IEmgSensorInput;
                _emgInput.MuscleActivationChanged += _emgInput_MuscleActivationChanged;
            }

            _emgConfiguredAndReady = false;
            base.OnCreate();
            if (dev != null && !dev.IsLoaded)
            {
                dev.LoadDriver(new Dictionary <string, string>());
                if (_discoveryProvider != null)
                {
                    _discoveryProvider.ScanFinished += (object sender, ScanResultsEventArgs e)
                                                       => {
                        _scanButton.Visible    = true;
                        _scanningLabel.Visible = false;
                        UpdateSensors(e.Devices);
                    };
                    _discoveryProvider.ConnectionEstablished += _discoveryProvider_ConnectionEstablished;
                    _discoveryProvider.ConnectionFailed      += _discoveryProvider_ConnectionFailed;
                }
            }


            ScanForSensors();
        }
Esempio n. 2
0
        public CalibrationActivity(UIEngine engine, IEmgSensorInput emgInput) : base(engine)
        {
            _emgInput = emgInput;

            Image backgroundImage = new Image(_engine.Content.LoadTexture("textures/ghostly/menu_background"));

            backgroundImage.Size     = new Vector2(engine.Screen.ScreenWidth, engine.Screen.ScreenHeight);
            backgroundImage.Position = Vector2.Zero;
            Components.Add(backgroundImage);


            counterLabel          = new Label("Rest your muscles in", engine.Content.LoadFont("Fonts/Ubuntu" + GhostlyGame.MENU_BUTTON_FONT_SIZE), GhostlyGame.MENU_FONT_COLOR);
            counterLabel.Position = (engine.Screen.ScreenMiddle - counterLabel.Size / 2) - new Vector2(0, counterLabel.Size.Y);
            Components.Add(counterLabel);

            instructionLabel          = new Label("5", engine.Content.LoadFont("Fonts/Ubuntu" + GhostlyGame.MENU_BUTTON_FONT_SIZE), GhostlyGame.MENU_FONT_COLOR);
            instructionLabel.Position = (engine.Screen.ScreenMiddle - instructionLabel.Size / 2) + new Vector2(0, instructionLabel.Size.Y);
            Components.Add(instructionLabel);

            infoLabel          = new Label("Calibrating ... ", engine.Content.LoadFont("Fonts/Ubuntu" + GhostlyGame.MENU_BUTTON_FONT_SIZE), GhostlyGame.MENU_FONT_COLOR);
            infoLabel.Position = engine.Screen.ScreenMiddle - infoLabel.Size / 2;
            Components.Add(infoLabel);

            _fpsLabel          = new Label("Sensor data: - fps", engine.Content.LoadFont("Fonts/Ubuntu12"), GhostlyGame.MENU_FONT_COLOR);
            _fpsLabel.Position = new Vector2(0, engine.Screen.ScreenHeight - _fpsLabel.Size.Y) + new Vector2(10, -10);
            Components.Add(_fpsLabel);

            _emgInput.CalibrationChanged += _emgInput_CalibrationChanged;
        }
Esempio n. 3
0
        public StartCalibrationActivity(UIEngine engine, IEmgSensorInput emgInput) : base(engine)
        {
            _emgInput = emgInput;

            Image backgroundImage = new Image(_engine.Content.LoadTexture("textures/ghostly/menu_background"));

            backgroundImage.Size     = new Vector2(engine.Screen.ScreenWidth, engine.Screen.ScreenHeight);
            backgroundImage.Position = Vector2.Zero;
            Components.Add(backgroundImage);

            Label infoLabel1 = new Label("Rest your muscles for calibrating sensors,", engine.Content.LoadFont("Fonts/Ubuntu48"), GhostlyGame.MENU_FONT_COLOR);

            infoLabel1.Position = engine.Screen.ScreenMiddle - infoLabel1.Size / 2 - new Vector2(0, 150);
            Components.Add(infoLabel1);

            Label infoLabel2 = new Label("click on the button the start the calibration", engine.Content.LoadFont("Fonts/Ubuntu48"), GhostlyGame.MENU_FONT_COLOR);

            infoLabel2.Position = engine.Screen.ScreenMiddle - infoLabel2.Size / 2 - new Vector2(0, 75);
            Components.Add(infoLabel2);

            _fpsLabel          = new Label("Sensor data: - fps", engine.Content.LoadFont("Fonts/Ubuntu12"), GhostlyGame.MENU_FONT_COLOR);
            _fpsLabel.Position = new Vector2(0, engine.Screen.ScreenHeight - _fpsLabel.Size.Y) + new Vector2(10, -10);
            Components.Add(_fpsLabel);


            TextButton s1 = new TextButton("Start calibration", engine.Content.LoadFont("Fonts/Ubuntu48"), engine.Device);

            s1.Clicked += (object sender, TextButton.ClickedEventArgs e) => {
                StartActivity(new CalibrationActivity(engine, emgInput));
            };
            s1.Position = engine.Screen.ScreenMiddle - s1.Size / 2 + new Vector2(0, 100);

            Components.Add(s1);
        }
Esempio n. 4
0
        public EmgBinding(IEmgSensorInput input, Configuration.InputValueHandle handle, int channel) : base(handle, 0, 1)
        {
            this._input   = input;
            this._channel = channel;

            _event_handler = new EventHandler <MuscleActivationChangedEventArgs>(_event_handle);
            _input.MuscleActivationChanged += _event_handler;

            _analyzer_handler              = new EventHandler <MuscleActivationChangedEventArgs>(_analyzer_handle);
            input.MuscleActivationChanged += _analyzer_handler;
        }
        public CalibrationActivity(UIEngine engine, IEmgSensorInput emgInput) : base(engine)
        {
            _emgInput = emgInput;

            Image backgroundImage = new Image(_engine.Content.LoadTexture("Textures/menu_background"));

            backgroundImage.Size     = new Vector2(engine.Screen.ScreenWidth, engine.Screen.ScreenHeight);
            backgroundImage.Position = Vector2.Zero;
            Components.Add(backgroundImage);

            Label l = new Label("Calibrating ... ", engine.Content.LoadFont("Fonts/Ubuntu" + LoopGame.MENU_BUTTON_FONT_SIZE), LoopGame.MENU_FONT_COLOR);

            l.Position = engine.Screen.ScreenMiddle - l.Size / 2;
            Components.Add(l);

            _fpsLabel          = new Label("Sensor data: - fps", engine.Content.LoadFont("Fonts/Ubuntu12"), LoopGame.MENU_FONT_COLOR);
            _fpsLabel.Position = new Vector2(0, engine.Screen.ScreenHeight - _fpsLabel.Size.Y) + new Vector2(10, -10);
            Components.Add(_fpsLabel);

            _emgInput.CalibrationChanged += _emgInput_CalibrationChanged;
        }
Esempio n. 6
0
        private InputBinding ConfigureEmgSensor(XPathNavigator navigator, XPathNodeIterator bindingIt, IEmgSensorInput input)
        {
            string point = bindingIt.Current.GetAttribute("point", "");
            //float zeroAngle = float.Parse(bindingIt.Current.GetAttribute("zeroAngle", ""), CultureInfo.InvariantCulture);
            float sensitivity = float.Parse(bindingIt.Current.GetAttribute("sensitivity", ""), CultureInfo.InvariantCulture);

            XPathNodeIterator acc = bindingIt.Current.Select("emgSensor");

            if (acc.Count > 0)
            {
                acc.MoveNext();
                string device  = acc.Current.GetAttribute("device", "");
                int    channel = Int32.Parse(acc.Current.GetAttribute("channel", ""));
                return(new EmgBinding(input, Configuration.GetHandle(point), channel));
            }
            return(null);
        }
Esempio n. 7
0
        public AdaptCalibrationActivity(UIEngine engine, IEmgSensorInput emgInput) : base(engine)
        {
            _emgInput = emgInput;
            float cell = engine.Screen.ScreenHeight / 16;



            Image backgroundImage = new Image(_engine.Content.LoadTexture("textures/ghostly/menu_background"));

            backgroundImage.Size     = new Vector2(engine.Screen.ScreenWidth, engine.Screen.ScreenHeight);
            backgroundImage.Position = Vector2.Zero;
            Components.Add(backgroundImage);

            emgTexture = new Texture2D(engine.Device, 2000, 500);
            Color[] pixelData = new Color[emgTexture.Width * emgTexture.Height];
            emgTexture.GetData <Color>(pixelData);
            for (int i = 0; i < pixelData.Length; i++)
            {
                pixelData[i] = Color.Transparent;
            }
            emgTexture.SetData <Color>(pixelData);

            emgImage          = new Image(emgTexture);
            emgImage.Size     = new Vector2((int)(engine.Screen.ScreenWidth * 0.6), (int)(engine.Screen.ScreenHeight * 0.6));
            emgImage.Position = new Vector2(engine.Screen.ScreenMiddle.X - (emgImage.Size.X / 2), cell * 2);
            Components.Add(emgImage);

            TextButton jumpingButton = new TextButton("Jumping", engine.Content.LoadFont(GhostlyGame.MENU_BUTTON_FONT + GhostlyGame.MENU_BUTTON_FONT_SIZE), engine.Device);

            jumpingButton.Clicked += (object sender, TextButton.ClickedEventArgs e) => {  };

            jumpingButton.Position = new Vector2(engine.Screen.ScreenMiddle.X, cell * 2 + emgImage.Size.Y / 4) - jumpingButton.Size / 2;
            Components.Add(jumpingButton);

            TextButton shootingButton = new TextButton("Shooting", engine.Content.LoadFont(GhostlyGame.MENU_BUTTON_FONT + GhostlyGame.MENU_BUTTON_FONT_SIZE), engine.Device);

            shootingButton.Clicked += (object sender, TextButton.ClickedEventArgs e) => {  };
            shootingButton.Position = new Vector2(engine.Screen.ScreenMiddle.X, cell * 2 + emgImage.Size.Y / 2 + emgImage.Size.Y / 4) - shootingButton.Size / 2;
            Components.Add(shootingButton);

            TextButton nextButton = new TextButton("Next", engine.Content.LoadFont(GhostlyGame.MENU_BUTTON_FONT + GhostlyGame.MENU_BUTTON_FONT_SIZE), engine.Device);

            nextButton.Clicked += (object sender, TextButton.ClickedEventArgs e) => { StartActivity(new MainMenuActivity(_engine)); };
            nextButton.Position = new Vector2(engine.Screen.ScreenMiddle.X + nextButton.Size.X, cell * 14) - nextButton.Size / 2;
            Components.Add(nextButton);

            TextButton recalibrateButton = new TextButton("Recalibrate", engine.Content.LoadFont(GhostlyGame.MENU_BUTTON_FONT + GhostlyGame.MENU_BUTTON_FONT_SIZE), engine.Device);

            recalibrateButton.Clicked += (object sender, TextButton.ClickedEventArgs e) => { StartActivity(new CalibrationActivity(_engine, emgInput)); };
            recalibrateButton.Position = new Vector2(engine.Screen.ScreenMiddle.X - recalibrateButton.Size.X / 2, cell * 14) - recalibrateButton.Size / 2;
            Components.Add(recalibrateButton);


            character          = new TestCharacter(engine.MusicPlayer, _engine.Content.LoadTexture("Textures\\Ghostly\\character\\walk0001"), ImagesAndAnimations.Instance.CharacterJumping);
            character.Position = new Vector2(engine.Screen.ScreenMiddle.X / 5 - (character.Size.X / 2), (int)(engine.Screen.ScreenMiddle.Y * 1.2));
            Components.Add(character);

            _fpsLabel          = new Label("Sensor data: - fps", engine.Content.LoadFont("Fonts/Ubuntu12"), GhostlyGame.MENU_FONT_COLOR);
            _fpsLabel.Position = new Vector2(0, engine.Screen.ScreenHeight - _fpsLabel.Size.Y) + new Vector2(10, -10);
            Components.Add(_fpsLabel);



            emgInput.CalibrationChanged += EmgInput_CalibrationChanged;
        }